Browse Source

work on issue 1027: New Actions Editor UI

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

+ 0
- 1
src/com/dmdirc/ui/swing/SwingController.java View File

@@ -28,7 +28,6 @@ import com.dmdirc.ui.IconManager;
28 28
 import com.dmdirc.Query;
29 29
 import com.dmdirc.Server;
30 30
 import com.dmdirc.WritableFrameContainer;
31
-import com.dmdirc.actions.ActionManager;
32 31
 import com.dmdirc.commandparser.parsers.CommandParser;
33 32
 import com.dmdirc.config.IdentityManager;
34 33
 import com.dmdirc.logger.ErrorLevel;

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

@@ -88,4 +88,19 @@ public class ActionResponsePanel extends JPanel {
88 88
         add(new JLabel("Alter the event's formatter"));
89 89
         add(formatter, "growx");
90 90
     }
91
+    
92
+    public String getResponse() {
93
+        return response.getText();
94
+    }
95
+    
96
+    public String getFormatter() {
97
+        return (String) formatter.getSelectedItem();
98
+    }
99
+    
100
+    /** {@inheritDoc} */
101
+    @Override
102
+    public void setEnabled(final boolean enabled) {
103
+        response.setEnabled(enabled);
104
+        formatter.setEnabled(enabled);
105
+    }
91 106
 }

+ 42
- 25
src/com/dmdirc/ui/swing/dialogs/actioneditor/ActionSubstitutionsPanel.java View File

@@ -32,6 +32,7 @@ import java.util.Map.Entry;
32 32
 import javax.swing.BorderFactory;
33 33
 import javax.swing.JPanel;
34 34
 
35
+import javax.swing.SwingUtilities;
35 36
 import net.miginfocom.swing.MigLayout;
36 37
 
37 38
 /**
@@ -52,34 +53,15 @@ public class ActionSubstitutionsPanel extends JPanel {
52 53
     public ActionSubstitutionsPanel(final ActionType type) {
53 54
         super();
54 55
 
55
-        this.type = type;
56
-        substitutions = new ArrayList<ActionSubstitutionLabel>();
57
-
58 56
         initComponents();
59 57
         addListeners();
60
-        layoutComponents();
58
+        setActionType(type);
61 59
     }
62 60
 
63 61
     /** Initialises the components. */
64 62
     private void initComponents() {
65
-        final ActionSubstitutor sub = new ActionSubstitutor(type);
66
-
67
-        for (final Entry<String, String> entry : sub.getComponentSubstitutions().
68
-                entrySet()) {
69
-            substitutions.add(new ActionSubstitutionLabel(new ActionSubstitution(entry.getValue(),
70
-                    entry.getKey())));
71
-        }
72
-
73
-        for (final String entry : sub.getConfigSubstitutions()) {
74
-            substitutions.add(new ActionSubstitutionLabel(new ActionSubstitution(entry,
75
-                    entry)));
76
-        }
77
-
78
-        for (final Entry<String, String> entry : sub.getServerSubstitutions().
79
-                entrySet()) {
80
-            substitutions.add(new ActionSubstitutionLabel(new ActionSubstitution(entry.getValue(),
81
-                    entry.getKey())));
82
-        }
63
+        setBorder(BorderFactory.createTitledBorder(getBorder(), "Substitutions"));
64
+        setLayout(new MigLayout("fill, wrap 4"));
83 65
     }
84 66
 
85 67
     /** Adds the listeners. */
@@ -88,15 +70,50 @@ public class ActionSubstitutionsPanel extends JPanel {
88 70
 
89 71
     /** Lays out the components. */
90 72
     private void layoutComponents() {
91
-        setBorder(BorderFactory.createTitledBorder(getBorder(), "Substitutions"));
92
-        setLayout(new MigLayout("fill, wrap 4"));
73
+        removeAll();
93 74
 
94 75
         add(new TextLabel("Substitutions may be used in the response and " +
95 76
                 "target fields. Drag and drop, or click on an item when " +
96 77
                 "editing the field, to insert it."), "spany, aligny top");
97
-        
78
+
98 79
         for (ActionSubstitutionLabel label : substitutions) {
99 80
             add(label, "sgx subslabel, aligny top");
100 81
         }
101 82
     }
83
+
84
+    public void setActionType(final ActionType type) {
85
+        SwingUtilities.invokeLater(new Runnable() {
86
+
87
+            /** {@inheritDoc} */
88
+            @Override
89
+            public void run() {
90
+                ActionSubstitutionsPanel.this.type = type;
91
+
92
+                substitutions = new ArrayList<ActionSubstitutionLabel>();
93
+
94
+                if (type != null) {
95
+                    final ActionSubstitutor sub = new ActionSubstitutor(type);
96
+
97
+                    for (final Entry<String, String> entry : sub.getComponentSubstitutions().
98
+                            entrySet()) {
99
+                        substitutions.add(new ActionSubstitutionLabel(new ActionSubstitution(entry.getValue(),
100
+                                entry.getKey())));
101
+                    }
102
+
103
+                    for (final String entry : sub.getConfigSubstitutions()) {
104
+                        substitutions.add(new ActionSubstitutionLabel(new ActionSubstitution(entry,
105
+                                entry)));
106
+                    }
107
+
108
+                    for (final Entry<String, String> entry : sub.getServerSubstitutions().
109
+                            entrySet()) {
110
+                        substitutions.add(new ActionSubstitutionLabel(new ActionSubstitution(entry.getValue(),
111
+                                entry.getKey())));
112
+                    }
113
+                }
114
+
115
+                layoutComponents();
116
+            }
117
+        });
118
+    }
102 119
 }

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

@@ -22,7 +22,21 @@
22 22
 
23 23
 package com.dmdirc.ui.swing.dialogs.actioneditor;
24 24
 
25
+import com.dmdirc.actions.interfaces.ActionType;
26
+import com.dmdirc.ui.IconManager;
27
+import com.dmdirc.ui.swing.components.ImageButton;
28
+import com.dmdirc.ui.swing.components.TextLabel;
29
+
30
+import java.awt.event.ActionEvent;
31
+import java.awt.event.ActionListener;
32
+import java.util.ArrayList;
33
+import java.util.List;
34
+
35
+import javax.swing.JLabel;
25 36
 import javax.swing.JPanel;
37
+import javax.swing.SwingUtilities;
38
+
39
+import net.miginfocom.swing.MigLayout;
26 40
 
27 41
 /**
28 42
  * Action triggers list panel.
@@ -35,11 +49,19 @@ public class ActionTriggersListPanel extends JPanel {
35 49
      * objects being unserialized with the new class).
36 50
      */
37 51
     private static final long serialVersionUID = 1;
52
+    private List<ActionType> triggers;
38 53
 
39 54
     /** Instantiates the panel. */
40 55
     public ActionTriggersListPanel() {
56
+        this(new ArrayList<ActionType>());
57
+    }
58
+
59
+    /** Instantiates the panel. */
60
+    public ActionTriggersListPanel(final List<ActionType> triggers) {
41 61
         super();
42
-        
62
+
63
+        this.triggers = new ArrayList<ActionType>(triggers);
64
+
43 65
         initComponents();
44 66
         addListeners();
45 67
         layoutComponents();
@@ -47,6 +69,7 @@ public class ActionTriggersListPanel extends JPanel {
47 69
 
48 70
     /** Initialises the components. */
49 71
     private void initComponents() {
72
+        setLayout(new MigLayout("fillx, wrap 2, debug"));
50 73
     }
51 74
 
52 75
     /** Adds the listeners. */
@@ -55,5 +78,69 @@ public class ActionTriggersListPanel extends JPanel {
55 78
 
56 79
     /** Lays out the components. */
57 80
     private void layoutComponents() {
81
+        synchronized (triggers) {
82
+            setVisible(false);
83
+
84
+            removeAll();
85
+
86
+            for (final ActionType trigger : triggers) {
87
+                final ImageButton button = new ImageButton("delete",
88
+                        IconManager.getIconManager().getIcon("close-inactive"),
89
+                        IconManager.getIconManager().getIcon("close-active"));
90
+                button.addActionListener(new ActionListener() {
91
+
92
+                    /** {@inheritDoc} */
93
+                    @Override
94
+                    public void actionPerformed(ActionEvent e) {
95
+                        delTrigger(trigger);
96
+                    }
97
+                });
98
+
99
+                add(new JLabel(trigger.getName()), "growx");
100
+                add(button, "right");
101
+            }
102
+
103
+            if (getComponentCount() == 0) {
104
+                add(new TextLabel("No triggers."));
105
+            }
106
+            getLayout().layoutContainer(this);
107
+            setVisible(true);
108
+        }
109
+    }
110
+
111
+    public void addTrigger(final ActionType trigger) {
112
+        SwingUtilities.invokeLater(new Runnable() {
113
+
114
+            /** {@inheritDoc} */
115
+            @Override
116
+            public void run() {
117
+                synchronized (triggers) {
118
+                    triggers.add(trigger);
119
+
120
+                    layoutComponents();
121
+                }
122
+            }
123
+        });
124
+    }
125
+
126
+    public void delTrigger(final ActionType trigger) {
127
+        SwingUtilities.invokeLater(new Runnable() {
128
+
129
+            /** {@inheritDoc} */
130
+            @Override
131
+            public void run() {
132
+                synchronized (triggers) {
133
+                    triggers.remove(trigger);
134
+
135
+                    layoutComponents();
136
+                }
137
+            }
138
+        });
139
+    }
140
+
141
+    public List<ActionType> getTriggers() {
142
+        synchronized (triggers) {
143
+            return triggers;
144
+        }
58 145
     }
59 146
 }

Loading…
Cancel
Save