Gregory Holmes před 16 roky
rodič
revize
1d45c39ef6

+ 10
- 1
src/com/dmdirc/ui/swing/dialogs/actioneditor/ActionConditionDisplayPanel.java Zobrazit soubor

@@ -33,6 +33,8 @@ import com.dmdirc.util.ListenerList;
33 33
 import java.awt.event.ActionEvent;
34 34
 import java.awt.event.ActionListener;
35 35
 
36
+import java.beans.PropertyChangeEvent;
37
+import java.beans.PropertyChangeListener;
36 38
 import javax.swing.JPanel;
37 39
 import javax.swing.JToggleButton;
38 40
 
@@ -41,7 +43,7 @@ import net.miginfocom.swing.MigLayout;
41 43
 /**
42 44
  * Action condition display panel.
43 45
  */
44
-public class ActionConditionDisplayPanel extends JPanel implements ActionListener {
46
+public class ActionConditionDisplayPanel extends JPanel implements ActionListener, PropertyChangeListener {
45 47
 
46 48
     /**
47 49
      * A version number for this class. It should be changed whenever the class
@@ -103,6 +105,7 @@ public class ActionConditionDisplayPanel extends JPanel implements ActionListene
103 105
     private void addListeners() {
104 106
         editButton.addActionListener(this);
105 107
         deleteButton.addActionListener(this);
108
+        editPanel.addPropertyChangeListener("edit", this);
106 109
     }
107 110
 
108 111
     /** Lays out the components. */
@@ -214,4 +217,10 @@ public class ActionConditionDisplayPanel extends JPanel implements ActionListene
214 217
     public ActionCondition getCondition() {
215 218
         return condition;
216 219
     }
220
+
221
+    /** {@inheritDoc} */
222
+    @Override
223
+    public void propertyChange(final PropertyChangeEvent evt) {
224
+        setCondition(trigger, condition);
225
+    }
217 226
 }

+ 5
- 2
src/com/dmdirc/ui/swing/dialogs/actioneditor/ActionConditionEditorPanel.java Zobrazit soubor

@@ -237,18 +237,21 @@ public class ActionConditionEditorPanel extends JPanel implements ActionListener
237 237
             }
238 238
             populateComparisons();
239 239
         }
240
+        firePropertyChange("edit", null, null);
240 241
     }
241 242
 
242 243
     /** {@inheritDoc} */
243 244
     @Override
244 245
     public void insertUpdate(final DocumentEvent e) {
245
-    //Ignore
246
+        condition.setTarget(target.getText());
247
+        firePropertyChange("edit", null, null);
246 248
     }
247 249
 
248 250
     /** {@inheritDoc} */
249 251
     @Override
250 252
     public void removeUpdate(final DocumentEvent e) {
251
-    //Ignore
253
+        condition.setTarget(target.getText());
254
+        firePropertyChange("edit", null, null);
252 255
     }
253 256
 
254 257
     /** {@inheritDoc} */

+ 24
- 31
src/com/dmdirc/ui/swing/dialogs/actioneditor/ActionConditionsListPanel.java Zobrazit soubor

@@ -23,14 +23,12 @@
23 23
 package com.dmdirc.ui.swing.dialogs.actioneditor;
24 24
 
25 25
 import com.dmdirc.actions.ActionCondition;
26
+import com.dmdirc.actions.ActionManager;
26 27
 import com.dmdirc.actions.interfaces.ActionType;
27 28
 
28
-import java.awt.event.ActionEvent;
29
-import java.awt.event.ActionListener;
30 29
 import java.util.ArrayList;
31 30
 import java.util.List;
32 31
 
33
-import javax.swing.JButton;
34 32
 import javax.swing.JLabel;
35 33
 import javax.swing.JPanel;
36 34
 
@@ -39,8 +37,7 @@ import net.miginfocom.swing.MigLayout;
39 37
 /**
40 38
  * Action conditions list panel.
41 39
  */
42
-public class ActionConditionsListPanel extends JPanel implements ActionConditionRemovalListener,
43
-        ActionListener {
40
+public class ActionConditionsListPanel extends JPanel implements ActionConditionRemovalListener {
44 41
 
45 42
     /**
46 43
      * A version number for this class. It should be changed whenever the class
@@ -52,8 +49,6 @@ public class ActionConditionsListPanel extends JPanel implements ActionCondition
52 49
     private ActionType trigger;
53 50
     /** Conditions list. */
54 51
     private List<ActionConditionDisplayPanel> conditions;
55
-    /** Add button. */
56
-    private JButton add;
57 52
 
58 53
     /** Instantiates the panel. */
59 54
     public ActionConditionsListPanel() {
@@ -89,9 +84,8 @@ public class ActionConditionsListPanel extends JPanel implements ActionCondition
89 84
 
90 85
     /** Initialises the components. */
91 86
     private void initComponents() {
92
-        setLayout(new MigLayout("fill, wrap 2"));
87
+        setLayout(new MigLayout("fillx, wrap 2"));
93 88
 
94
-        add = new JButton("Add");
95 89
         if (trigger == null) {
96 90
             setEnabled(false);
97 91
         }
@@ -102,7 +96,6 @@ public class ActionConditionsListPanel extends JPanel implements ActionCondition
102 96
         for (ActionConditionDisplayPanel condition : conditions) {
103 97
             condition.addConditionListener(this);
104 98
         }
105
-        add.addActionListener(this);
106 99
     }
107 100
 
108 101
     /** Lays out the components. */
@@ -110,17 +103,22 @@ public class ActionConditionsListPanel extends JPanel implements ActionCondition
110 103
         setVisible(false);
111 104
         removeAll();
112 105
         int index = 0;
113
-        synchronized (conditions) {
114
-            for (ActionConditionDisplayPanel condition : conditions) {
115
-                index++;
116
-                add(new JLabel(index + "."), "aligny top");
117
-                add(condition, "growx");
106
+        if (trigger == null) {
107
+            add(new JLabel("You must add at least one trigger before you can add conditions."),
108
+                    "alignx center, aligny top, growx");
109
+        } else {
110
+            synchronized (conditions) {
111
+                for (ActionConditionDisplayPanel condition : conditions) {
112
+                    index++;
113
+                    add(new JLabel(index + "."), "aligny top");
114
+                    add(condition, "growx, aligny top");
115
+                }
116
+            }
117
+            if (index == 0) {
118
+                add(new JLabel("No conditions."),
119
+                        "alignx center, aligny top, growx");
118 120
             }
119 121
         }
120
-        if (index == 0) {
121
-            add(new JLabel("No conditions."), "alignx center, aligny top, growx");
122
-        }
123
-        add(add, "gaptop push, newline, right, aligny bottom");
124 122
         setVisible(true);
125 123
 
126 124
     }
@@ -168,8 +166,11 @@ public class ActionConditionsListPanel extends JPanel implements ActionCondition
168 166
      * @param trigger Action trigger
169 167
      */
170 168
     public void setTrigger(final ActionType trigger) {
169
+        if (this.trigger != null || ActionManager.getCompatibleTypes(trigger).contains(this.trigger)) {
170
+            conditions.clear();
171
+        }
171 172
         this.trigger = trigger;
172
-        add.setEnabled(trigger != null);
173
+        layoutComponents();
173 174
     }
174 175
 
175 176
     /** {@inheritDoc} */
@@ -181,19 +182,11 @@ public class ActionConditionsListPanel extends JPanel implements ActionCondition
181 182
         layoutComponents();
182 183
     }
183 184
 
184
-    /** 
185
-     * {@inheritDoc}
186
-     * 
187
-     * @param e Action event
188
-     */
189
-    @Override
190
-    public void actionPerformed(final ActionEvent e) {
191
-        addCondition(new ActionCondition(-1, null, null, null));
192
-    }
193
-    
194 185
     /** {@inheritDoc} */
195 186
     @Override
196 187
     public void setEnabled(final boolean enabled) {
197
-        add.setEnabled(false);
188
+        for (ActionConditionDisplayPanel condition : conditions) {
189
+            condition.setEnabled(false);
190
+        }
198 191
     }
199 192
 }

+ 29
- 2
src/com/dmdirc/ui/swing/dialogs/actioneditor/ActionConditionsPanel.java Zobrazit soubor

@@ -22,10 +22,16 @@
22 22
 
23 23
 package com.dmdirc.ui.swing.dialogs.actioneditor;
24 24
 
25
+import com.dmdirc.actions.ActionCondition;
25 26
 import com.dmdirc.actions.interfaces.ActionType;
26 27
 
28
+import java.awt.event.ActionEvent;
29
+import java.awt.event.ActionListener;
30
+
27 31
 import javax.swing.BorderFactory;
32
+import javax.swing.JButton;
28 33
 import javax.swing.JPanel;
34
+import javax.swing.JScrollPane;
29 35
 import javax.swing.JSeparator;
30 36
 
31 37
 import net.miginfocom.swing.MigLayout;
@@ -33,7 +39,7 @@ import net.miginfocom.swing.MigLayout;
33 39
 /**
34 40
  * Action conditions panel.
35 41
  */
36
-public class ActionConditionsPanel extends JPanel {
42
+public class ActionConditionsPanel extends JPanel implements ActionListener {
37 43
 
38 44
     /**
39 45
      * A version number for this class. It should be changed whenever the class
@@ -47,6 +53,8 @@ public class ActionConditionsPanel extends JPanel {
47 53
     private ActionConditionsTreePanel tree;
48 54
     /** List Panel. */
49 55
     private ActionConditionsListPanel list;
56
+    /** Add button. */
57
+    private JButton add;
50 58
 
51 59
     /** Instantiates the panel. */
52 60
     public ActionConditionsPanel() {
@@ -69,6 +77,7 @@ public class ActionConditionsPanel extends JPanel {
69 77
         
70 78
         if (trigger == null) {
71 79
             setEnabled(false);
80
+            add.setEnabled(false);
72 81
         }
73 82
     }
74 83
 
@@ -76,10 +85,12 @@ public class ActionConditionsPanel extends JPanel {
76 85
     private void initComponents() {
77 86
         tree = new ActionConditionsTreePanel();
78 87
         list = new ActionConditionsListPanel();
88
+        add = new JButton("Add");
79 89
     }
80 90
 
81 91
     /** Adds the listeners. */
82 92
     private void addListeners() {
93
+        add.addActionListener(this);
83 94
     }
84 95
 
85 96
     /** Lays out the components. */
@@ -88,9 +99,14 @@ public class ActionConditionsPanel extends JPanel {
88 99
         
89 100
         setBorder(BorderFactory.createTitledBorder(getBorder(), "Conditions"));
90 101
         
102
+        final JScrollPane sp = new JScrollPane(list);
103
+        sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
104
+        sp.getVerticalScrollBar().setUnitIncrement(10);
105
+        
91 106
         add(tree, "growx, pushx");
92 107
         add(new JSeparator(JSeparator.HORIZONTAL), "growx, pushx");
93
-        add(list, "grow");
108
+        add(sp, "grow");
109
+        add(add, "right, gaptop push");
94 110
     }
95 111
 
96 112
     /**
@@ -101,6 +117,7 @@ public class ActionConditionsPanel extends JPanel {
101 117
     public void setActionTrigger(final ActionType trigger) {
102 118
         this.trigger = trigger;
103 119
         list.setTrigger(trigger);
120
+        add.setEnabled(trigger != null);
104 121
     }
105 122
     
106 123
     /** {@inheritDoc} */
@@ -109,4 +126,14 @@ public class ActionConditionsPanel extends JPanel {
109 126
         tree.setEnabled(enabled);
110 127
         list.setEnabled(enabled);
111 128
     }
129
+    
130
+    /** 
131
+     * {@inheritDoc}
132
+     * 
133
+     * @param e Action event
134
+     */
135
+    @Override
136
+    public void actionPerformed(final ActionEvent e) {
137
+        list.addCondition(new ActionCondition(-1, null, null, null));
138
+    }
112 139
 }

+ 24
- 11
src/com/dmdirc/ui/swing/dialogs/actioneditor/ActionEditorDialog.java Zobrazit soubor

@@ -27,13 +27,14 @@ import com.dmdirc.config.IdentityManager;
27 27
 import com.dmdirc.ui.swing.UIUtilities;
28 28
 import com.dmdirc.ui.swing.components.StandardDialog;
29 29
 
30
+import java.awt.Window;
30 31
 import java.awt.event.ActionEvent;
31 32
 import java.awt.event.ActionListener;
32 33
 import java.awt.event.WindowAdapter;
33 34
 import java.awt.event.WindowEvent;
34
-
35 35
 import java.beans.PropertyChangeEvent;
36 36
 import java.beans.PropertyChangeListener;
37
+
37 38
 import javax.swing.JButton;
38 39
 import javax.swing.JFrame;
39 40
 
@@ -62,14 +63,22 @@ public class ActionEditorDialog extends StandardDialog implements ActionListener
62 63
     private ActionSubstitutionsPanel substitutions;
63 64
     /** Show substitutions button. */
64 65
     private JButton showSubstitutions;
66
+    /** Is the name valid? */
65 67
     private boolean nameValid = false;
68
+    /** Are the triggers valid? */
66 69
     private boolean triggersValid = false;
70
+    /** Is the response valid? */
67 71
     private boolean responseValid = false;
72
+    /** Are the conditions valid? */
68 73
     private boolean conditionsValid = false;
69 74
 
70
-    /** Instantiates the panel. */
71
-    public ActionEditorDialog() {
72
-        super(new JFrame(), false);
75
+    /** 
76
+     * Instantiates the panel.
77
+     * 
78
+     * @param window Parent window
79
+     */
80
+    public ActionEditorDialog(final Window window) {
81
+        super(window, ModalityType.MODELESS);
73 82
 
74 83
         initComponents();
75 84
         addListeners();
@@ -104,13 +113,13 @@ public class ActionEditorDialog extends StandardDialog implements ActionListener
104 113
 
105 114
     /** Lays out the components. */
106 115
     private void layoutComponents() {
107
-        setLayout(new MigLayout("fill, hidemode 3, wrap 2, pack"));
116
+        setLayout(new MigLayout("fill, hidemode 3, wrap 2, pack, hmax 80sp"));
108 117
 
109
-        add(name, "grow, wmax 225");
110
-        add(conditions, "spany 3, grow, wmin 400, wmax 400");
111
-        add(triggers, "grow, wmax 225");
112
-        add(response, "grow, wmax 225");
113
-        add(substitutions, "spanx 2, grow, wmax 625");
118
+        add(name, "grow, wmax 250");
119
+        add(conditions, "spany 3, grow, wmin 410, wmax 410");
120
+        add(triggers, "grow, wmax 250");
121
+        add(response, "grow, wmax 250");
122
+        add(substitutions, "spanx 2, grow, wmax 660");
114 123
         add(showSubstitutions, "left, sgx button, split 3, spanx 2");
115 124
         add(getLeftButton(), "right, sgx button, gapleft push");
116 125
         add(getRightButton(), "right, sgx button");
@@ -125,7 +134,9 @@ public class ActionEditorDialog extends StandardDialog implements ActionListener
125 134
         UIUtilities.initUISettings();
126 135
         IdentityManager.load();
127 136
         ActionManager.init();
128
-        ActionEditorDialog dialog = new ActionEditorDialog();
137
+        ActionManager.loadActions();
138
+        System.out.println(ActionManager.getGroups().values().iterator().next().getActions().get(0));
139
+        ActionEditorDialog dialog = new ActionEditorDialog(new JFrame());
129 140
         dialog.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
130 141
 
131 142
         dialog.addWindowListener(new WindowAdapter() {
@@ -166,7 +177,9 @@ public class ActionEditorDialog extends StandardDialog implements ActionListener
166 177
             
167 178
             response.setEnabled((Boolean) evt.getNewValue());
168 179
             conditions.setEnabled((Boolean) evt.getNewValue());
180
+            substitutions.setEnabled((Boolean) evt.getNewValue());
169 181
             
182
+            substitutions.setActionType(triggers.getPrimaryTrigger());
170 183
             conditions.setActionTrigger(triggers.getPrimaryTrigger());
171 184
         }
172 185
         

+ 12
- 3
src/com/dmdirc/ui/swing/dialogs/actioneditor/ActionSubstitution.java Zobrazit soubor

@@ -44,14 +44,23 @@ public final class ActionSubstitution {
44 44
     }
45 45
     
46 46
     /**
47
-     * Returns the value of this substitution.
47
+     * Returns the name of this substitution.
48 48
      *
49
-     * @return Substitution value   
49
+     * @return Substitution name   
50 50
      */
51
-    public String getValue() {
51
+    public String getName() {
52 52
         return name;
53 53
     }
54 54
     
55
+    /**
56
+     * Returns the value of this substitution.
57
+     * 
58
+     * @return Substitution value
59
+     */
60
+    public String getValue() {
61
+        return value;
62
+    }
63
+    
55 64
     /** {@inheritDoc} */
56 65
     @Override
57 66
     public String toString() {

+ 1
- 1
src/com/dmdirc/ui/swing/dialogs/actioneditor/ActionSubstitutionLabel.java Zobrazit soubor

@@ -81,7 +81,7 @@ public class ActionSubstitutionLabel extends JButton implements MouseListener,
81 81
         dragSource.createDefaultDragGestureRecognizer(this,
82 82
                 DnDConstants.ACTION_COPY, this);
83 83
 
84
-        setText(substition.getValue());
84
+        setText(substition.getName());
85 85
         setFont(getFont().deriveFont(getFont().getSize() - 2f));
86 86
         
87 87
         setBorder(

+ 4
- 4
src/com/dmdirc/ui/swing/dialogs/actioneditor/ActionSubstitutionsPanel.java Zobrazit soubor

@@ -75,7 +75,7 @@ public class ActionSubstitutionsPanel extends JPanel {
75 75
     /** Initialises the components. */
76 76
     private void initComponents() {
77 77
         setBorder(BorderFactory.createTitledBorder(getBorder(), "Substitutions"));
78
-        setLayout(new MigLayout("fill, wrap 5"));
78
+        setLayout(new MigLayout("fillx, wrap 5"));
79 79
     }
80 80
 
81 81
     /** Adds the listeners. */
@@ -89,14 +89,14 @@ public class ActionSubstitutionsPanel extends JPanel {
89 89
         add(new TextLabel("Substitutions may be used in the response and " +
90 90
                 "target fields. Drag and drop, or click on an item when " +
91 91
                 "editing the field, to insert it."), "spany, aligny top, wmin 225, wmax 225");
92
-        add(new JSeparator(JSeparator.VERTICAL), "growy");
92
+        add(new JSeparator(JSeparator.VERTICAL), "growy, spany");
93 93
 
94 94
         for (ActionSubstitutionLabel label : substitutions) {
95
-            add(label, "sgx subslabel, aligny top");
95
+            add(label, "sgx subslabel, aligny top, growx");
96 96
         }
97 97
         
98 98
         if (getComponentCount() == 2) {
99
-            add(new JLabel("No substitutions."), "growx, aligny top");
99
+            add(new JLabel("No substitutions."), "growx, aligny top, align center");
100 100
         }
101 101
     }
102 102
 

+ 15
- 7
src/com/dmdirc/ui/swing/dialogs/actioneditor/ActionTriggersPanel.java Zobrazit soubor

@@ -40,6 +40,7 @@ import javax.swing.JComboBox;
40 40
 import javax.swing.JComponent;
41 41
 import javax.swing.JPanel;
42 42
 import javax.swing.JPopupMenu;
43
+import javax.swing.JScrollPane;
43 44
 import javax.swing.SwingUtilities;
44 45
 import javax.swing.event.PopupMenuEvent;
45 46
 import javax.swing.event.PopupMenuListener;
@@ -79,7 +80,8 @@ public class ActionTriggersPanel extends JPanel implements ActionListener,
79 80
         setBorder(BorderFactory.createTitledBorder(getBorder(), "Triggers"));
80 81
 
81 82
         trigger =
82
-                new JComboBox(new ActionTypeModel(ActionManager.getTypeGroups()));
83
+                new JComboBox(new ActionTypeModel(getFontMetrics(getFont()),
84
+                ActionManager.getTypeGroups()));
83 85
         //Only fire events on selection not on highlight
84 86
         trigger.putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE);
85 87
         trigger.setRenderer(new ActionTypeRenderer());
@@ -93,10 +95,15 @@ public class ActionTriggersPanel extends JPanel implements ActionListener,
93 95
                 if (!(comp instanceof JPopupMenu)) {
94 96
                     return;
95 97
                 }
96
-                JComponent scrollPane =
97
-                        (JComponent) ((JPopupMenu) comp).getComponent(0);
98
+                JComponent scrollPane = (JComponent) ((JPopupMenu) comp).getComponent(0);
98 99
                 Dimension size = scrollPane.getPreferredSize();
99
-                size.width = size.width * 2;
100
+                if (scrollPane instanceof JScrollPane) {
101
+                    size.width = ((ActionTypeModel) trigger.getModel()).
102
+                            getMaxWidth() + (int) ((JScrollPane) scrollPane).
103
+                            getVerticalScrollBar().getPreferredSize().getWidth();
104
+                } else {
105
+                    size.width = ((ActionTypeModel) trigger.getModel()).getMaxWidth();
106
+                }
100 107
                 scrollPane.setPreferredSize(size);
101 108
                 scrollPane.setMaximumSize(size);
102 109
             }
@@ -122,7 +129,7 @@ public class ActionTriggersPanel extends JPanel implements ActionListener,
122 129
         add.addActionListener(this);
123 130
         trigger.addActionListener(this);
124 131
         triggerList.addTriggerListener(this);
125
-        
132
+
126 133
         triggerList.addPropertyChangeListener("triggerCount", this);
127 134
     }
128 135
 
@@ -136,7 +143,7 @@ public class ActionTriggersPanel extends JPanel implements ActionListener,
136 143
         add(trigger, "growx");
137 144
         add(add, "right");
138 145
     }
139
-    
146
+
140 147
     /**
141 148
      * Returns the primary trigger for this panel.
142 149
      * 
@@ -183,6 +190,7 @@ public class ActionTriggersPanel extends JPanel implements ActionListener,
183 190
 
184 191
                 if (triggerList.getTriggerCount() == 0) {
185 192
                     ((ActionTypeModel) trigger.getModel()).setTypeGroup(ActionManager.getTypeGroups());
193
+                    trigger.setEnabled((trigger.getModel().getSize() > 0));
186 194
                     return;
187 195
                 }
188 196
                 for (ActionType thisType : ActionManager.getCompatibleTypes(triggerList.getTrigger(0))) {
@@ -191,7 +199,7 @@ public class ActionTriggersPanel extends JPanel implements ActionListener,
191 199
                         ((ActionTypeModel) trigger.getModel()).addElement(thisType);
192 200
                     }
193 201
                 }
194
-                 trigger.setEnabled((trigger.getModel().getSize() > 0));
202
+                trigger.setEnabled((trigger.getModel().getSize() > 0));
195 203
             }
196 204
         });
197 205
     }

+ 37
- 1
src/com/dmdirc/ui/swing/dialogs/actioneditor/ActionTypeModel.java Zobrazit soubor

@@ -26,11 +26,14 @@ import com.dmdirc.actions.ActionTypeComparator;
26 26
 import com.dmdirc.actions.interfaces.ActionType;
27 27
 import com.dmdirc.util.MapList;
28 28
 
29
+import java.awt.FontMetrics;
29 30
 import java.util.Collections;
30 31
 import java.util.List;
31 32
 import java.util.Map;
32 33
 
33 34
 import javax.swing.DefaultComboBoxModel;
35
+import javax.swing.SwingUtilities;
36
+import sun.swing.SwingUtilities2;
34 37
 
35 38
 /**
36 39
  * Model for the "trigger" list of the actions editor. Adds type group headers,
@@ -44,15 +47,22 @@ public final class ActionTypeModel extends DefaultComboBoxModel {
44 47
      * objects being unserialized with the new class).
45 48
      */
46 49
     private static final long serialVersionUID = 1;    
50
+    /** Max Width. */
51
+    private int maxWidth = -1;
52
+    /** Font metrics. */
53
+    private FontMetrics fm;
47 54
     
48 55
     /**
49 56
      * Creates a new instance of ActionTypeModel.
50 57
      * 
58
+     * @param fm Font metrics
51 59
      * @param typeGroups The action type groups to use
52 60
      */
53
-    public ActionTypeModel(final MapList<String, ActionType> typeGroups) {
61
+    public ActionTypeModel(final FontMetrics fm, final MapList<String, ActionType> typeGroups) {
54 62
         super();
55 63
         
64
+        this.fm = fm;
65
+        
56 66
         for (Map.Entry<String, List<ActionType>> entry : typeGroups.entrySet()) {
57 67
             addElement(entry.getKey());
58 68
             
@@ -65,6 +75,23 @@ public final class ActionTypeModel extends DefaultComboBoxModel {
65 75
         }
66 76
     }
67 77
 
78
+    /** 
79
+     * {@inheritDoc}
80
+     * 
81
+     * @param anObject Objerct to add
82
+     */
83
+    @Override
84
+    public void addElement(final Object anObject) {
85
+        super.addElement(anObject);
86
+        int width = maxWidth;
87
+        if (anObject instanceof String) {
88
+            width = SwingUtilities.computeStringWidth(fm, (String) anObject);
89
+        } else if (anObject instanceof ActionType) {
90
+            width = SwingUtilities.computeStringWidth(fm, ((ActionType) anObject).getName());
91
+        }
92
+        maxWidth = Math.max(width, maxWidth);
93
+    }
94
+
68 95
     /** {@inheritDoc} */
69 96
     @Override
70 97
     public void setSelectedItem(final Object anObject) {
@@ -92,4 +119,13 @@ public final class ActionTypeModel extends DefaultComboBoxModel {
92 119
             }
93 120
         }
94 121
     }
122
+    
123
+    /**
124
+     * Returns the maximum width of a string in this model.
125
+     * 
126
+     * @return String max width
127
+     */
128
+    public int getMaxWidth() {
129
+        return maxWidth;
130
+    }
95 131
 }

Načítá se…
Zrušit
Uložit