Browse Source

work on issue 1027: New Actions Editor UI

git-svn-id: http://svn.dmdirc.com/trunk@4028 00569f92-eb28-0410-84fd-f71c24880f
tags/0.6
Gregory Holmes 16 years ago
parent
commit
e610a5419f

+ 34
- 0
src/com/dmdirc/ui/swing/dialogs/actioneditor/ActionTriggerRemovalListener.java View File

1
+/*
2
+ * Copyright (c) 2006-2008 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.ui.swing.dialogs.actioneditor;
24
+
25
+import com.dmdirc.actions.interfaces.ActionType;
26
+
27
+/**
28
+ * Action trigger removal listener.
29
+ */
30
+public interface ActionTriggerRemovalListener {
31
+
32
+    /** A trigger was removed from the list. */
33
+    void triggerRemoved(ActionType trigger);
34
+}

+ 47
- 1
src/com/dmdirc/ui/swing/dialogs/actioneditor/ActionTriggersListPanel.java View File

27
 import com.dmdirc.ui.swing.components.ImageButton;
27
 import com.dmdirc.ui.swing.components.ImageButton;
28
 import com.dmdirc.ui.swing.components.TextLabel;
28
 import com.dmdirc.ui.swing.components.TextLabel;
29
 
29
 
30
+import com.dmdirc.util.ListenerList;
30
 import java.awt.event.ActionEvent;
31
 import java.awt.event.ActionEvent;
31
 import java.awt.event.ActionListener;
32
 import java.awt.event.ActionListener;
32
 import java.util.ArrayList;
33
 import java.util.ArrayList;
50
      */
51
      */
51
     private static final long serialVersionUID = 1;
52
     private static final long serialVersionUID = 1;
52
     private List<ActionType> triggers;
53
     private List<ActionType> triggers;
54
+    private final ListenerList listeners = new ListenerList();
53
 
55
 
54
     /** Instantiates the panel. */
56
     /** Instantiates the panel. */
55
     public ActionTriggersListPanel() {
57
     public ActionTriggersListPanel() {
69
 
71
 
70
     /** Initialises the components. */
72
     /** Initialises the components. */
71
     private void initComponents() {
73
     private void initComponents() {
72
-        setLayout(new MigLayout("fillx, wrap 2, debug"));
74
+        setLayout(new MigLayout("fillx, wrap 2"));
73
     }
75
     }
74
 
76
 
75
     /** Adds the listeners. */
77
     /** Adds the listeners. */
131
             public void run() {
133
             public void run() {
132
                 synchronized (triggers) {
134
                 synchronized (triggers) {
133
                     triggers.remove(trigger);
135
                     triggers.remove(trigger);
136
+                    fireTriggerRemoved(trigger);
134
 
137
 
135
                     layoutComponents();
138
                     layoutComponents();
136
                 }
139
                 }
143
             return triggers;
146
             return triggers;
144
         }
147
         }
145
     }
148
     }
149
+    
150
+    public ActionType getTrigger(final int index) {
151
+        return triggers.get(index);
152
+    }
153
+    
154
+    public int getTriggerCount() {
155
+        synchronized (triggers) {
156
+            return triggers.size();
157
+        }
158
+    }
159
+
160
+    /**
161
+     * Adds an ActionTriggerRemovalListener to the listener list.
162
+     *
163
+     * @param listener Listener to add
164
+     */
165
+    public void addErrorListener(final ActionTriggerRemovalListener listener) {
166
+        if (listener == null) {
167
+            return;
168
+        }
169
+
170
+        listeners.add(ActionTriggerRemovalListener.class, listener);
171
+    }
172
+
173
+    /**
174
+     * Removes an ActionTriggerRemovalListener from the listener list.
175
+     *
176
+     * @param listener Listener to remove
177
+     */
178
+    public void removeErrorListener(final ActionTriggerRemovalListener listener) {
179
+        listeners.remove(ActionTriggerRemovalListener.class, listener);
180
+    }
181
+
182
+    /**
183
+     * Fired when the an action trigger is removed.
184
+     *
185
+     * @param type Removed trigger
186
+     */
187
+    protected void fireTriggerRemoved(final ActionType type) {
188
+        for (ActionTriggerRemovalListener listener : listeners.get(ActionTriggerRemovalListener.class)) {
189
+            listener.triggerRemoved(type);
190
+        }
191
+    }
146
 }
192
 }

+ 80
- 2
src/com/dmdirc/ui/swing/dialogs/actioneditor/ActionTriggersPanel.java View File

22
 
22
 
23
 package com.dmdirc.ui.swing.dialogs.actioneditor;
23
 package com.dmdirc.ui.swing.dialogs.actioneditor;
24
 
24
 
25
+import com.dmdirc.actions.ActionManager;
26
+import com.dmdirc.actions.interfaces.ActionType;
27
+import com.dmdirc.ui.swing.components.TextLabel;
28
+import com.dmdirc.ui.swing.components.renderers.ActionTypeRenderer;
29
+
30
+import java.awt.event.ActionEvent;
31
+import java.awt.event.ActionListener;
32
+
33
+import javax.swing.BorderFactory;
34
+import javax.swing.JButton;
35
+import javax.swing.JComboBox;
25
 import javax.swing.JPanel;
36
 import javax.swing.JPanel;
37
+import javax.swing.SwingUtilities;
38
+
39
+import net.miginfocom.swing.MigLayout;
26
 
40
 
27
 /**
41
 /**
28
  * Action triggers panel.
42
  * Action triggers panel.
29
  */
43
  */
30
-public class ActionTriggersPanel extends JPanel {
44
+public class ActionTriggersPanel extends JPanel implements ActionListener,
45
+        ActionTriggerRemovalListener {
31
 
46
 
32
     /**
47
     /**
33
      * A version number for this class. It should be changed whenever the class
48
      * A version number for this class. It should be changed whenever the class
35
      * objects being unserialized with the new class).
50
      * objects being unserialized with the new class).
36
      */
51
      */
37
     private static final long serialVersionUID = 1;
52
     private static final long serialVersionUID = 1;
53
+    private JComboBox trigger;
54
+    private JButton add;
55
+    private ActionTriggersListPanel triggerList;
38
 
56
 
39
     /** Instantiates the panel. */
57
     /** Instantiates the panel. */
40
     public ActionTriggersPanel() {
58
     public ActionTriggersPanel() {
41
         super();
59
         super();
42
-        
60
+
43
         initComponents();
61
         initComponents();
44
         addListeners();
62
         addListeners();
45
         layoutComponents();
63
         layoutComponents();
47
 
65
 
48
     /** Initialises the components. */
66
     /** Initialises the components. */
49
     private void initComponents() {
67
     private void initComponents() {
68
+        setBorder(BorderFactory.createTitledBorder(getBorder(), "Triggers"));
69
+
70
+        trigger =
71
+                new JComboBox(new ActionTypeModel(ActionManager.getTypeGroups()));
72
+        //Only fire events on selection not on highlight
73
+        trigger.putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE);
74
+        trigger.setRenderer(new ActionTypeRenderer());
75
+
76
+        add = new JButton("Add");
77
+        add.setEnabled(trigger.getSelectedIndex() != -1);
78
+
79
+        triggerList = new ActionTriggersListPanel();
50
     }
80
     }
51
 
81
 
52
     /** Adds the listeners. */
82
     /** Adds the listeners. */
53
     private void addListeners() {
83
     private void addListeners() {
84
+        add.addActionListener(this);
85
+        trigger.addActionListener(this);
54
     }
86
     }
55
 
87
 
56
     /** Lays out the components. */
88
     /** Lays out the components. */
57
     private void layoutComponents() {
89
     private void layoutComponents() {
90
+        setLayout(new MigLayout("fill, pack"));
91
+
92
+        add(new TextLabel("This action will be triggered when any of these events occurs: "),
93
+                "growx, wrap, spanx");
94
+        add(triggerList, "grow, wrap, spanx");
95
+        add(trigger, "growx");
96
+        add(add, "right");
97
+    }
98
+
99
+    /** {@inheritDoc} */
100
+    @Override
101
+    public void actionPerformed(final ActionEvent e) {
102
+        if (e.getSource() == trigger) {
103
+            add.setEnabled(trigger.getSelectedIndex() != -1);
104
+        } else {
105
+            triggerList.addTrigger((ActionType) trigger.getSelectedItem());
106
+            repopulateTriggers();
107
+        }
108
+    }
109
+
110
+    /** {@inheritDoc} */
111
+    @Override
112
+    public void triggerRemoved(final ActionType trigger) {
113
+        repopulateTriggers();
114
+    }
115
+
116
+    private void repopulateTriggers() {
117
+        SwingUtilities.invokeLater(new Runnable() {
118
+
119
+            /** {@inheritDoc} */
120
+            @Override
121
+            public void run() {
122
+                ((ActionTypeModel) trigger.getModel()).removeAllElements();
123
+
124
+                if (triggerList.getTriggerCount() == 0) {
125
+                    System.out.println("all");
126
+                    ((ActionTypeModel) trigger.getModel()).setTypeGroup(ActionManager.getTypeGroups());
127
+                    return;
128
+                }
129
+
130
+                System.out.println("typed");
131
+                for (ActionType thisType : ActionManager.getCompatibleTypes(triggerList.getTrigger(0))) {
132
+                    ((ActionTypeModel) trigger.getModel()).addElement(thisType);
133
+                }
134
+            }
135
+        });
58
     }
136
     }
59
 }
137
 }

+ 15
- 0
src/com/dmdirc/ui/swing/dialogs/actioneditor/ActionTypeModel.java View File

72
             super.setSelectedItem(anObject);
72
             super.setSelectedItem(anObject);
73
         }
73
         }
74
     }
74
     }
75
+    
76
+    public void setTypeGroup(final MapList<String, ActionType> typeGroups) {
77
+        removeAllElements();
78
+        
79
+        for (Map.Entry<String, List<ActionType>> entry : typeGroups.entrySet()) {
80
+            addElement(entry.getKey());
81
+            
82
+            final List<ActionType> types = entry.getValue();
83
+            Collections.sort(types, new ActionTypeComparator());
84
+            
85
+            for (ActionType type : types) {
86
+                addElement(type);
87
+            }
88
+        }
89
+    }
75
 }
90
 }

Loading…
Cancel
Save