Przeglądaj źródła

Add highlights to the PMD.

Adding highlights seems broken, but so does nicknames and
that hasn't changed, so likely a bug elsewhere we didn't
notice.  Will fix that soon.
pull/250/head
Greg Holmes 9 lat temu
rodzic
commit
4dc770b613

+ 67
- 2
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/profile/ProfileManagerController.java Wyświetl plik

@@ -75,6 +75,10 @@ public class ProfileManagerController implements ProfilesDialogModelListener {
75 75
         setupProfileNicknames(dialog.getProfileNicknames());
76 76
         setupProfileRealname(dialog.getProfileRealname());
77 77
         setupProfileIdent(dialog.getProfileIdent());
78
+        setupProfileHighlights(dialog.getProfileHighlights());
79
+        setupAddHighlight(dialog.getProfileAddHighlight());
80
+        setupEditHighlight(dialog.getProfileEditHighlight());
81
+        setupDeleteHighlight(dialog.getProfileDeleteHighlight());
78 82
         model.addListener(this);
79 83
     }
80 84
 
@@ -150,6 +154,32 @@ public class ProfileManagerController implements ProfilesDialogModelListener {
150 154
                 .ifPresent(model::removeSelectedProfileNickname));
151 155
     }
152 156
 
157
+    private void setupAddHighlight(final JButton addHighlight) {
158
+        addHighlight.setEnabled(!model.getProfileList().isEmpty());
159
+        addHighlight.addActionListener(e ->
160
+                new StandardInputDialog(dialog, Dialog.ModalityType.DOCUMENT_MODAL,
161
+                        iconManager, "Profile Manager: Add Highlight", "Enter highlight to add",
162
+                        model.getSelectedProfileAddHighlightValidator(),
163
+                        model::addSelectedProfileHighlight).display());
164
+    }
165
+
166
+    private void setupEditHighlight(final JButton editHighlight) {
167
+        editHighlight.setEnabled(model.getSelectedProfileSelectedHighlight().isPresent());
168
+        editHighlight.addActionListener(l -> model.getSelectedProfileSelectedHighlight().ifPresent(
169
+                (String oldName) -> new StandardInputDialog(dialog,
170
+                        Dialog.ModalityType.DOCUMENT_MODAL, iconManager,
171
+                        "Profile Manager: Edit Highlight", "Enter new highlight",
172
+                        model.getSelectedProfileEditHighlightValidator(),
173
+                        (String newName) -> model.editSelectedProfileHighlight(oldName, newName))
174
+                        .display()));
175
+    }
176
+
177
+    private void setupDeleteHighlight(final JButton deleteHighlight) {
178
+        deleteHighlight.setEnabled(model.getSelectedProfileSelectedHighlight().isPresent());
179
+        deleteHighlight.addActionListener(l -> model.getSelectedProfileSelectedHighlight()
180
+                .ifPresent(model::removeSelectedProfileHighlight));
181
+    }
182
+
153 183
     private void setupProfileName(final JTextField name) {
154 184
         name.setEnabled(model.getSelectedProfileName().isPresent());
155 185
         name.setText(model.getSelectedProfileName().orElse(""));
@@ -160,6 +190,13 @@ public class ProfileManagerController implements ProfilesDialogModelListener {
160 190
         }));
161 191
     }
162 192
 
193
+    private void setupProfileHighlights(final ReorderableJList<String> highlights) {
194
+        highlights.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
195
+        highlights.setEnabled(model.getSelectedProfileHighlights().isPresent());
196
+        highlights.addListSelectionListener(l -> model.setSelectedProfileSelectedHighlight(
197
+                Optional.ofNullable(highlights.getSelectedValue())));
198
+    }
199
+
163 200
     private void setupProfileNicknames(final ReorderableJList<String> nicknames) {
164 201
         nicknames.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
165 202
         nicknames.setEnabled(model.getSelectedProfileNicknames().isPresent());
@@ -242,8 +279,8 @@ public class ProfileManagerController implements ProfilesDialogModelListener {
242 279
     @Override
243 280
     public void selectedProfileNicknameEdited(final String oldNickname, final String newNickname) {
244 281
         dialog.getOkButton().setEnabled(model.isSaveAllowed());
245
-        dialog.getProfileNicknames().getModel()
246
-                .setElementAt(newNickname, dialog.getProfileNicknames().getModel().indexOf(oldNickname));
282
+        dialog.getProfileNicknames().getModel().setElementAt(newNickname,
283
+                dialog.getProfileNicknames().getModel().indexOf(oldNickname));
247 284
     }
248 285
 
249 286
     @Override
@@ -258,4 +295,32 @@ public class ProfileManagerController implements ProfilesDialogModelListener {
258 295
         dialog.getProfileNicknames().getModel().removeElement(nickname);
259 296
     }
260 297
 
298
+    @Override
299
+    public void selectedHighlightChanged(final Optional<String> highlight) {
300
+        dialog.getOkButton().setEnabled(model.isSaveAllowed());
301
+        dialog.getProfileDeleteHighlight()
302
+                .setEnabled(model.getSelectedProfileSelectedHighlight().isPresent());
303
+        dialog.getProfileEditHighlight()
304
+                .setEnabled(model.getSelectedProfileSelectedHighlight().isPresent());
305
+    }
306
+
307
+    @Override
308
+    public void selectedProfileHighlightEdited(final String oldHighlight, final String newHighlight) {
309
+        dialog.getOkButton().setEnabled(model.isSaveAllowed());
310
+        dialog.getProfileHighlights().getModel().setElementAt(newHighlight,
311
+                dialog.getProfileHighlights().getModel().indexOf(oldHighlight));
312
+    }
313
+
314
+    @Override
315
+    public void selectedProfileHighlightAdded(final String highlight) {
316
+        dialog.getOkButton().setEnabled(model.isSaveAllowed());
317
+        dialog.getProfileHighlights().getModel().addElement(highlight);
318
+    }
319
+
320
+    @Override
321
+    public void selectedProfileHighlightRemoved(final String highlight) {
322
+        dialog.getOkButton().setEnabled(model.isSaveAllowed());
323
+        dialog.getProfileHighlights().getModel().removeElement(highlight);
324
+    }
325
+
261 326
 }

+ 36
- 3
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/profile/ProfileManagerDialog.java Wyświetl plik

@@ -58,12 +58,20 @@ public class ProfileManagerDialog extends StandardDialog {
58 58
     private final JList<MutableProfile> profileList = new JList<>(new DefaultListModel<>());
59 59
     /** List of nicknames for a profile. */
60 60
     private final ReorderableJList<String> nicknames = new ReorderableJList<>();
61
+    /** List of highlights for a profile. */
62
+    private final ReorderableJList<String> highlights = new ReorderableJList<>();
61 63
     /** Adds a new nickname to the active profile. */
62 64
     private final JButton addNickname = new JButton("Add");
63 65
     /** Edits the active nickname in the active profile. */
64 66
     private final JButton editNickname = new JButton("Edit");
65 67
     /** Deletes the selected nickname from the active profile. */
66 68
     private final JButton deleteNickname = new JButton("Delete");
69
+    /** Adds a new highlight to the active profile. */
70
+    private final JButton addHighlight = new JButton("Add");
71
+    /** Edits the active highlight in the active profile. */
72
+    private final JButton editHighlight = new JButton("Edit");
73
+    /** Deletes the selected highlight from the active profile. */
74
+    private final JButton deleteHighlight = new JButton("Delete");
67 75
     /** Edits the name of the active profile. */
68 76
     private final JTextField name = new JTextField();
69 77
     /** Edits the realname for the active profile. */
@@ -101,9 +109,10 @@ public class ProfileManagerDialog extends StandardDialog {
101 109
         add(new TextLabel("Profiles describe the information needed to connect " +
102 110
                 "to a server.  You can use a different profile for each " + "connection."),
103 111
                 "spanx 3");
104
-        add(new JScrollPane(profileList), "spany 3, growy, " + "wmin 200, wmax 200");
105
-        add(addProfile, "grow");
106
-        add(deleteProfile, "grow, wrap");
112
+        add(new JScrollPane(profileList), "spany 7, split 3, growy, pushy, "
113
+                + "wmin 200, wmax 200");
114
+        add(addProfile, "growx");
115
+        add(deleteProfile, "growx, wrap");
107 116
         add(new JLabel("Name: "), "align label, span 2, split 2, flowx, sgx label");
108 117
         add(ValidationFactory
109 118
                 .getValidatorPanel(name, model.getSelectedProfileNameValidator(), iconManager),
@@ -123,6 +132,14 @@ public class ProfileManagerDialog extends StandardDialog {
123 132
         add(new JLabel("Ident: "), "align label, span 2, split 2, flowx, sgx label");
124 133
         add(ValidationFactory.getValidatorPanel(ident, model.getIdentValidator(), iconManager),
125 134
                 "growx, pushx, sgx textinput");
135
+        add(new JLabel("Highlight: "),
136
+                "align label, span 2, split 2, flowx, sgx label, aligny 50%");
137
+        add(ValidationFactory.getValidatorPanel(new JScrollPane(highlights), highlights,
138
+                model.getHighlightsValidator(), iconManager), "grow, push");
139
+        add(Box.createGlue(), "flowx, span 4, split 4, sgx label");
140
+        add(addHighlight, "grow");
141
+        add(editHighlight, "grow");
142
+        add(deleteHighlight, "grow");
126 143
         add(getLeftButton(), "flowx, split 2, right, sg button");
127 144
         add(getRightButton(), "right, sg button");
128 145
     }
@@ -172,4 +189,20 @@ public class ProfileManagerDialog extends StandardDialog {
172 189
     public JButton getDeleteProfile() {
173 190
         return deleteProfile;
174 191
     }
192
+
193
+    public ReorderableJList<String> getProfileHighlights() {
194
+        return highlights;
195
+    }
196
+
197
+    public JButton getProfileAddHighlight() {
198
+        return addHighlight;
199
+    }
200
+
201
+    public JButton getProfileEditHighlight() {
202
+        return editHighlight;
203
+    }
204
+
205
+    public JButton getProfileDeleteHighlight() {
206
+        return deleteHighlight;
207
+    }
175 208
 }

Ładowanie…
Anuluj
Zapisz