浏览代码

Add new profiles dialog.

pull/113/head
Greg Holmes 9 年前
父节点
当前提交
1632f828b1

+ 26
- 37
ui_swing/src/com/dmdirc/addons/ui_swing/components/menubar/SettingsMenu.java 查看文件

@@ -26,12 +26,9 @@ import com.dmdirc.addons.ui_swing.Apple;
26 26
 import com.dmdirc.addons.ui_swing.dialogs.actionsmanager.ActionsManagerDialog;
27 27
 import com.dmdirc.addons.ui_swing.dialogs.aliases.AliasManagerDialog;
28 28
 import com.dmdirc.addons.ui_swing.dialogs.prefs.SwingPreferencesDialog;
29
-import com.dmdirc.addons.ui_swing.dialogs.profiles.ProfileManagerDialog;
29
+import com.dmdirc.addons.ui_swing.dialogs.profile.ProfileManagerDialog;
30 30
 import com.dmdirc.addons.ui_swing.injection.DialogProvider;
31 31
 
32
-import java.awt.event.ActionEvent;
33
-import java.awt.event.ActionListener;
34
-
35 32
 import javax.inject.Inject;
36 33
 import javax.inject.Singleton;
37 34
 import javax.swing.JMenu;
@@ -41,12 +38,16 @@ import javax.swing.JMenuItem;
41 38
  * A menu to add settings related commands to the menu bar.
42 39
  */
43 40
 @Singleton
44
-public class SettingsMenu extends JMenu implements ActionListener {
41
+public class SettingsMenu extends JMenu {
45 42
 
46 43
     /** Serial version UID. */
47 44
     private static final long serialVersionUID = 1;
45
+    /** Old provider of profile manager dialogs. */
46
+    private final DialogProvider<com.dmdirc.addons.ui_swing.dialogs.profiles.ProfileManagerDialog>
47
+            oldProfileDialogProvider;
48 48
     /** Provider of profile manager dialogs. */
49
-    private final DialogProvider<ProfileManagerDialog> profileDialogProvider;
49
+    private final DialogProvider<ProfileManagerDialog>
50
+            newProfileDialogProvider;
50 51
     /** Provider of action manager dialogs. */
51 52
     private final DialogProvider<ActionsManagerDialog> actionsDialogProvider;
52 53
     /** Provider of preferences dialogs. */
@@ -56,12 +57,16 @@ public class SettingsMenu extends JMenu implements ActionListener {
56 57
 
57 58
     @Inject
58 59
     public SettingsMenu(
59
-            final DialogProvider<ProfileManagerDialog> profileDialogProvider,
60
+            final DialogProvider<com.dmdirc.addons.ui_swing.dialogs.profiles.ProfileManagerDialog>
61
+                    oldProfileDialogProvider,
62
+            final DialogProvider<ProfileManagerDialog>
63
+                    newProfileDialogProvider,
60 64
             final DialogProvider<ActionsManagerDialog> actionsDialogProvider,
61 65
             final DialogProvider<SwingPreferencesDialog> prefsDialogProvider,
62 66
             final DialogProvider<AliasManagerDialog> aliasDialogProvider) {
63 67
         super("Settings");
64
-        this.profileDialogProvider = profileDialogProvider;
68
+        this.oldProfileDialogProvider = oldProfileDialogProvider;
69
+        this.newProfileDialogProvider = newProfileDialogProvider;
65 70
         this.actionsDialogProvider = actionsDialogProvider;
66 71
         this.prefsDialogProvider = prefsDialogProvider;
67 72
         this.aliasDialogProvider = aliasDialogProvider;
@@ -78,51 +83,35 @@ public class SettingsMenu extends JMenu implements ActionListener {
78 83
 
79 84
         if (!Apple.isAppleUI()) {
80 85
             menuItem = new JMenuItem();
81
-            menuItem.setText("Preferences");
86
+            menuItem.setText("Settings");
82 87
             menuItem.setMnemonic('p');
83
-            menuItem.setActionCommand("Preferences");
84
-            menuItem.addActionListener(this);
88
+            menuItem.addActionListener(e -> prefsDialogProvider.displayOrRequestFocus());
85 89
             add(menuItem);
86 90
         }
87 91
 
88 92
         menuItem = new JMenuItem();
89
-        menuItem.setMnemonic('m');
90
-        menuItem.setText("Profile Manager");
91
-        menuItem.setActionCommand("Profile");
92
-        menuItem.addActionListener(this);
93
+        menuItem.setMnemonic('p');
94
+        menuItem.setText("Old Profile Manager");
95
+        menuItem.addActionListener(e -> oldProfileDialogProvider.displayOrRequestFocus());
96
+        add(menuItem);
97
+
98
+        menuItem = new JMenuItem();
99
+        menuItem.setMnemonic('p');
100
+        menuItem.setText("New Profile Manager");
101
+        menuItem.addActionListener(e -> newProfileDialogProvider.displayOrRequestFocus());
93 102
         add(menuItem);
94 103
 
95 104
         menuItem = new JMenuItem();
96 105
         menuItem.setMnemonic('a');
97 106
         menuItem.setText("Actions Manager");
98
-        menuItem.setActionCommand("Actions");
99
-        menuItem.addActionListener(this);
107
+        menuItem.addActionListener(e -> actionsDialogProvider.displayOrRequestFocus());
100 108
         add(menuItem);
101 109
 
102 110
         menuItem = new JMenuItem();
103 111
         menuItem.setMnemonic('l');
104 112
         menuItem.setText("Alias Manager");
105
-        menuItem.setActionCommand("Aliases");
106
-        menuItem.addActionListener(this);
113
+        menuItem.addActionListener(e -> aliasDialogProvider.displayOrRequestFocus());
107 114
         add(menuItem);
108 115
     }
109 116
 
110
-    @Override
111
-    public void actionPerformed(final ActionEvent e) {
112
-        switch (e.getActionCommand()) {
113
-            case "Preferences":
114
-                prefsDialogProvider.displayOrRequestFocus();
115
-                break;
116
-            case "Profile":
117
-                profileDialogProvider.displayOrRequestFocus();
118
-                break;
119
-            case "Actions":
120
-                actionsDialogProvider.displayOrRequestFocus();
121
-                break;
122
-            case "Aliases":
123
-                aliasDialogProvider.displayOrRequestFocus();
124
-                break;
125
-        }
126
-    }
127
-
128 117
 }

+ 66
- 0
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/profile/ProfileIdentDocumentListener.java 查看文件

@@ -0,0 +1,66 @@
1
+/*
2
+ * Copyright (c) 2006-2014 DMDirc Developers
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.addons.ui_swing.dialogs.profile;
24
+
25
+import com.dmdirc.interfaces.ui.ProfilesDialogModel;
26
+
27
+import java.util.Optional;
28
+
29
+import javax.swing.JTextField;
30
+import javax.swing.event.DocumentEvent;
31
+import javax.swing.event.DocumentListener;
32
+
33
+/**
34
+* Applies changes in the profile ident's document to the model.
35
+*/
36
+public class ProfileIdentDocumentListener implements DocumentListener {
37
+
38
+    private final JTextField ident;
39
+    private final ProfilesDialogModel model;
40
+
41
+    public ProfileIdentDocumentListener(final ProfilesDialogModel model, final JTextField ident) {
42
+        this.ident = ident;
43
+        this.model = model;
44
+    }
45
+
46
+    @Override
47
+    public void insertUpdate(final DocumentEvent e) {
48
+        changed();
49
+    }
50
+
51
+    @Override
52
+    public void removeUpdate(final DocumentEvent e) {
53
+        changed();
54
+    }
55
+
56
+    @Override
57
+    public void changedUpdate(final DocumentEvent e) {
58
+        changed();
59
+    }
60
+
61
+    private void changed() {
62
+        if (model.getSelectedProfile().isPresent()) {
63
+            model.setSelectedProfileIdent(Optional.of(ident.getText()));
64
+        }
65
+    }
66
+}

+ 249
- 0
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/profile/ProfileManagerController.java 查看文件

@@ -0,0 +1,249 @@
1
+/*
2
+ * Copyright (c) 2006-2014 DMDirc Developers
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.addons.ui_swing.dialogs.profile;
24
+
25
+import com.dmdirc.addons.ui_swing.components.reorderablelist.ReorderableJList;
26
+import com.dmdirc.addons.ui_swing.components.vetoable.VetoableListSelectionModel;
27
+import com.dmdirc.addons.ui_swing.dialogs.StandardInputDialog;
28
+import com.dmdirc.interfaces.ui.ProfilesDialogModel;
29
+import com.dmdirc.interfaces.ui.ProfilesDialogModelListener;
30
+import com.dmdirc.ui.IconManager;
31
+import com.dmdirc.ui.core.profiles.MutableProfile;
32
+
33
+import com.google.common.collect.Lists;
34
+
35
+import java.awt.Dialog;
36
+import java.beans.PropertyVetoException;
37
+import java.util.Optional;
38
+
39
+import javax.swing.DefaultListModel;
40
+import javax.swing.JButton;
41
+import javax.swing.JList;
42
+import javax.swing.JTextField;
43
+import javax.swing.ListSelectionModel;
44
+
45
+public class ProfileManagerController implements ProfilesDialogModelListener {
46
+
47
+    private final ProfileManagerDialog dialog;
48
+    private final ProfilesDialogModel model;
49
+    private final IconManager iconManager;
50
+    private final DefaultListModel<MutableProfile> listModel;
51
+    private final VetoableListSelectionModel selectionModel;
52
+
53
+    public ProfileManagerController(final ProfileManagerDialog dialog,
54
+            final ProfilesDialogModel model, final IconManager iconManager) {
55
+        this.dialog = dialog;
56
+        this.model = model;
57
+        this.iconManager = iconManager;
58
+
59
+        listModel = (DefaultListModel<MutableProfile>) dialog.getProfileList().getModel();
60
+        selectionModel = new VetoableListSelectionModel();
61
+    }
62
+
63
+    public void init() {
64
+        model.loadModel();
65
+        setupOKButton(dialog.getOkButton());
66
+        setupCancelButton(dialog.getCancelButton());
67
+        setupProfileList(dialog.getProfileList());
68
+        setupAddProfile(dialog.getAddProfile());
69
+        setupDeleteProfile(dialog.getDeleteProfile());
70
+        setupEditNickname(dialog.getProfileEditNickname());
71
+        setupAddNickname(dialog.getProfileAddNickname());
72
+        setupDeleteNickname(dialog.getProfileDeleteNickname());
73
+        setupProfileName(dialog.getProfileName());
74
+        setupProfileNicknames(dialog.getProfileNicknames());
75
+        setupProfileRealname(dialog.getProfileRealname());
76
+        setupProfileIdent(dialog.getProfileIdent());
77
+        model.addListener(this);
78
+    }
79
+
80
+    private void setupOKButton(final JButton okButton) {
81
+        okButton.setEnabled(model.isSaveAllowed());
82
+        okButton.addActionListener(l -> {
83
+            model.save();
84
+            dialog.dispose();
85
+        });
86
+    }
87
+
88
+    private void setupCancelButton(final JButton cancelButton) {
89
+        cancelButton.addActionListener(l -> dialog.dispose());
90
+    }
91
+
92
+    private void setupProfileList(final JList<MutableProfile> profileList) {
93
+        profileList.setSelectionModel(selectionModel);
94
+        model.getProfileList().forEach(listModel::addElement);
95
+        selectionModel.addVetoableSelectionListener(e -> {
96
+            if (!model.canSwitchProfiles()) {
97
+                throw new PropertyVetoException("Cannot switch with invalid profile", e);
98
+            }
99
+        });
100
+        profileList.addListSelectionListener(l -> {
101
+            if (!selectionModel.isSelectionEmpty()) {
102
+                model.setSelectedProfile(Optional.ofNullable(profileList.getSelectedValue()));
103
+            }
104
+        });
105
+        if (model.getSelectedProfileNicknames().isPresent()) {
106
+            model.getSelectedProfileNicknames().get().forEach(
107
+                    p -> dialog.getProfileNicknames().getModel().addElement(p));
108
+        }
109
+        if (!listModel.isEmpty()) {
110
+            selectionModel.setLeadSelectionIndex(0);
111
+        }
112
+    }
113
+
114
+    private void setupAddProfile(final JButton addProfile) {
115
+        addProfile.addActionListener(
116
+                e -> new StandardInputDialog(dialog, Dialog.ModalityType.DOCUMENT_MODAL,
117
+                        iconManager, "Profile Manager: Add Profile", "Enter the new profile's name",
118
+                        model.getNewProfileNameValidator(),
119
+                        (String s) -> model.addProfile(s, s, s, Lists.newArrayList(s))).display());
120
+    }
121
+
122
+    private void setupDeleteProfile(final JButton deleteProfile) {
123
+        deleteProfile.setEnabled(model.getSelectedProfile().isPresent());
124
+        deleteProfile.addActionListener(l -> model.getSelectedProfile()
125
+                .ifPresent(p -> model.removeProfile(p.getName())));
126
+    }
127
+
128
+    private void setupEditNickname(final JButton editNickname) {
129
+        editNickname.setEnabled(model.getSelectedProfileSelectedNickname().isPresent());
130
+        editNickname.addActionListener(l -> model.getSelectedProfileSelectedNickname().ifPresent(
131
+                (String oldName) -> new StandardInputDialog(dialog,
132
+                        Dialog.ModalityType.DOCUMENT_MODAL, iconManager,
133
+                        "Profile Manager: Edit Nickname", "Enter new nickname",
134
+                        (String newName) -> model.editSelectedProfileNickname(oldName, newName))
135
+                        .display()));
136
+    }
137
+
138
+    private void setupAddNickname(final JButton addNickname) {
139
+        addNickname.setEnabled(!model.getProfileList().isEmpty());
140
+        addNickname.addActionListener(
141
+                e -> new StandardInputDialog(dialog, Dialog.ModalityType.DOCUMENT_MODAL,
142
+                        iconManager, "Profile Manager: Add Nickname", "Enter nickname to add",
143
+                        model::addSelectedProfileNickname).display());
144
+    }
145
+
146
+    private void setupDeleteNickname(final JButton deleteNickname) {
147
+        deleteNickname.setEnabled(model.getSelectedProfileSelectedNickname().isPresent());
148
+        deleteNickname.addActionListener(l -> model.getSelectedProfileSelectedNickname()
149
+                .ifPresent(model::removeSelectedProfileNickname));
150
+    }
151
+
152
+    private void setupProfileName(final JTextField name) {
153
+        name.setEnabled(model.getSelectedProfileName().isPresent());
154
+        name.setText(model.getSelectedProfileName().orElse(""));
155
+        name.getDocument().addDocumentListener(new ProfileNameDocumentListener(model, name));
156
+    }
157
+
158
+    private void setupProfileNicknames(final ReorderableJList<String> nicknames) {
159
+        nicknames.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
160
+        nicknames.setEnabled(model.getSelectedProfileNicknames().isPresent());
161
+        nicknames.addListSelectionListener(l -> model.setSelectedProfileSelectedNickname(
162
+                Optional.ofNullable(nicknames.getSelectedValue())));
163
+    }
164
+
165
+    private void setupProfileRealname(final JTextField realname) {
166
+        realname.setEnabled(model.getSelectedProfileRealname().isPresent());
167
+        realname.setText(model.getSelectedProfileRealname().orElse(""));
168
+        realname.getDocument().addDocumentListener(
169
+                new ProfileRealnameDocumentListener(model, realname));
170
+    }
171
+
172
+    private void setupProfileIdent(final JTextField ident) {
173
+        ident.setEnabled(model.getSelectedProfileIdent().isPresent());
174
+        ident.setText(model.getSelectedProfileIdent().orElse(""));
175
+        ident.getDocument().addDocumentListener(new ProfileIdentDocumentListener(model, ident));
176
+    }
177
+
178
+    @Override
179
+    public void profileAdded(final MutableProfile profile) {
180
+        dialog.getProfileAddNickname().setEnabled(model.isProfileListValid());
181
+        dialog.getOkButton().setEnabled(model.isSaveAllowed());
182
+        listModel.addElement(profile);
183
+    }
184
+
185
+    @Override
186
+    public void profileRemoved(final MutableProfile profile) {
187
+        dialog.getProfileAddNickname().setEnabled(model.isProfileListValid());
188
+        dialog.getOkButton().setEnabled(model.isSaveAllowed());
189
+        listModel.removeElement(profile);
190
+    }
191
+
192
+    @Override
193
+    public void profileEdited(final MutableProfile profile) {
194
+        dialog.getOkButton().setEnabled(model.isSaveAllowed());
195
+    }
196
+
197
+    @Override
198
+    public void profileSelectionChanged(final Optional<MutableProfile> profile) {
199
+        dialog.getOkButton().setEnabled(model.isSaveAllowed());
200
+        dialog.getDeleteProfile().setEnabled(model.getSelectedProfile().isPresent());
201
+        if (profile.isPresent()) {
202
+            final int index = listModel.indexOf(profile.get());
203
+            selectionModel.setLeadSelectionIndex(index);
204
+        } else {
205
+            selectionModel.setLeadSelectionIndex(-1);
206
+        }
207
+        dialog.getProfileName().setEnabled(model.getSelectedProfileIdent().isPresent());
208
+        dialog.getProfileName().setText(model.getSelectedProfileName().orElse(""));
209
+        dialog.getProfileNicknames().setEnabled(model.getSelectedProfileNicknames().isPresent());
210
+        dialog.getProfileNicknames().getModel().clear();
211
+        if (model.getSelectedProfileNicknames().isPresent()) {
212
+            model.getSelectedProfileNicknames().get().forEach(
213
+                    p -> dialog.getProfileNicknames().getModel().addElement(p));
214
+        }
215
+        dialog.getProfileRealname().setEnabled(model.getSelectedProfileRealname().isPresent());
216
+        dialog.getProfileRealname().setText(model.getSelectedProfileRealname().orElse(""));
217
+        dialog.getProfileIdent().setEnabled(model.getSelectedProfile().isPresent());
218
+        dialog.getProfileIdent().setText(model.getSelectedProfileIdent().orElse(""));
219
+    }
220
+
221
+    @Override
222
+    public void selectedNicknameChanged(final Optional<String> nickname) {
223
+        dialog.getOkButton().setEnabled(model.isSaveAllowed());
224
+        dialog.getProfileDeleteNickname()
225
+                .setEnabled(model.getSelectedProfileSelectedNickname().isPresent());
226
+        dialog.getProfileEditNickname()
227
+                .setEnabled(model.getSelectedProfileSelectedNickname().isPresent());
228
+    }
229
+
230
+    @Override
231
+    public void selectedProfileNicknameEdited(final String oldNickname, final String newNickname) {
232
+        dialog.getOkButton().setEnabled(model.isSaveAllowed());
233
+        dialog.getProfileNicknames().getModel()
234
+                .setElementAt(newNickname, dialog.getProfileNicknames().getModel().indexOf(oldNickname));
235
+    }
236
+
237
+    @Override
238
+    public void selectedProfileNicknameAdded(final String nickname) {
239
+        dialog.getOkButton().setEnabled(model.isSaveAllowed());
240
+        dialog.getProfileNicknames().getModel().addElement(nickname);
241
+    }
242
+
243
+    @Override
244
+    public void selectedProfileNicknameRemoved(final String nickname) {
245
+        dialog.getOkButton().setEnabled(model.isSaveAllowed());
246
+        dialog.getProfileNicknames().getModel().removeElement(nickname);
247
+    }
248
+
249
+}

+ 175
- 0
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/profile/ProfileManagerDialog.java 查看文件

@@ -0,0 +1,175 @@
1
+/*
2
+ * Copyright (c) 2006-2014 DMDirc Developers
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.addons.ui_swing.dialogs.profile;
24
+
25
+import com.dmdirc.ClientModule.GlobalConfig;
26
+import com.dmdirc.addons.ui_swing.components.renderers.PropertyListCellRenderer;
27
+import com.dmdirc.addons.ui_swing.components.reorderablelist.ReorderableJList;
28
+import com.dmdirc.addons.ui_swing.components.text.TextLabel;
29
+import com.dmdirc.addons.ui_swing.components.validating.ValidationFactory;
30
+import com.dmdirc.addons.ui_swing.dialogs.StandardDialog;
31
+import com.dmdirc.addons.ui_swing.injection.MainWindow;
32
+import com.dmdirc.interfaces.ui.ProfilesDialogModel;
33
+import com.dmdirc.ui.IconManager;
34
+import com.dmdirc.ui.core.profiles.MutableProfile;
35
+
36
+import java.awt.Window;
37
+
38
+import javax.inject.Inject;
39
+import javax.swing.Box;
40
+import javax.swing.DefaultListModel;
41
+import javax.swing.JButton;
42
+import javax.swing.JLabel;
43
+import javax.swing.JList;
44
+import javax.swing.JScrollPane;
45
+import javax.swing.JTextField;
46
+
47
+import net.miginfocom.swing.MigLayout;
48
+
49
+public class ProfileManagerDialog extends StandardDialog {
50
+
51
+    /** Serial version UID. */
52
+    private static final long serialVersionUID = 3;
53
+    /** Model used to store state. */
54
+    private final ProfilesDialogModel model;
55
+    /** Icon manager. */
56
+    private final IconManager iconManager;
57
+    /** List of profiles. */
58
+    private final JList<MutableProfile> profileList = new JList<>(new DefaultListModel<>());
59
+    /** List of nicknames for a profile. */
60
+    private final ReorderableJList<String> nicknames = new ReorderableJList<>();
61
+    /** Adds a new nickname to the active profile. */
62
+    private final JButton addNickname = new JButton("Add");
63
+    /** Edits the active nickname in the active profile. */
64
+    private final JButton editNickname = new JButton("Edit");
65
+    /** Deletes the selected nickname from the active profile. */
66
+    private final JButton deleteNickname = new JButton("Delete");
67
+    /** Edits the name of the active profile. */
68
+    private final JTextField name = new JTextField();
69
+    /** Edits the realname for the active profile. */
70
+    private final JTextField realname = new JTextField();
71
+    /** Edits the ident for the active profile. */
72
+    private final JTextField ident = new JTextField();
73
+    /** Adds a new profile to the list. */
74
+    private final JButton addProfile = new JButton("Add");
75
+    /** Deletes the active profile. */
76
+    private final JButton deleteProfile = new JButton("Delete");
77
+
78
+    /**
79
+     * Creates a new instance of ProfileEditorDialog.
80
+     *
81
+     * @param mainFrame   Main frame
82
+     * @param model       Profiles model
83
+     * @param iconManager Icon manager to retrieve icons
84
+     */
85
+    @Inject
86
+    public ProfileManagerDialog(@MainWindow final Window mainFrame, final ProfilesDialogModel model,
87
+            @GlobalConfig final IconManager iconManager) {
88
+        super(mainFrame, ModalityType.DOCUMENT_MODAL);
89
+        setTitle("Profile Manager");
90
+        this.model = model;
91
+        this.iconManager = iconManager;
92
+        initComponents();
93
+    }
94
+
95
+    /** Initialises the components. */
96
+    private void initComponents() {
97
+        profileList.setCellRenderer(new PropertyListCellRenderer<>(profileList.getCellRenderer(),
98
+                MutableProfile.class, "name"));
99
+        setLayout(new MigLayout("fill, wmin 700, wmax 700, flowy"));
100
+
101
+        add(new TextLabel("Profiles describe the information needed to connect " +
102
+                "to a server.  You can use a different profile for each " + "connection."),
103
+                "spanx 3");
104
+        add(new JScrollPane(profileList), "spany 3, growy, " + "wmin 200, wmax 200");
105
+        add(addProfile, "grow");
106
+        add(deleteProfile, "grow, wrap");
107
+        add(new JLabel("Name: "), "align label, span 2, split 2, flowx, sgx label");
108
+        add(ValidationFactory
109
+                .getValidatorPanel(name, model.getSelectedProfileNameValidator(), iconManager),
110
+                "growx, pushx, sgx textinput");
111
+        add(new JLabel("Nicknames: "),
112
+                "align label, span 2, split 2, flowx, sgx label, aligny 50%");
113
+        add(ValidationFactory.getValidatorPanel(new JScrollPane(nicknames), nicknames,
114
+                model.getNicknamesValidator(), iconManager), "grow, push");
115
+        add(Box.createGlue(), "flowx, span 4, split 4, sgx label");
116
+        add(addNickname, "grow");
117
+        add(editNickname, "grow");
118
+        add(deleteNickname, "grow");
119
+        add(new JLabel("Realname: "), "align label, span 2, split 2, flowx, sgx label");
120
+        add(ValidationFactory
121
+                .getValidatorPanel(realname, model.getRealnameValidator(), iconManager),
122
+                "growx, pushx, sgx textinput");
123
+        add(new JLabel("Ident: "), "align label, span 2, split 2, flowx, sgx label");
124
+        add(ValidationFactory.getValidatorPanel(ident, model.getIdentValidator(), iconManager),
125
+                "growx, pushx, sgx textinput");
126
+        add(getLeftButton(), "flowx, split 2, right, sg button");
127
+        add(getRightButton(), "right, sg button");
128
+    }
129
+
130
+    @Override
131
+    public void display() {
132
+        new ProfileManagerController(this, model, iconManager).init();
133
+        super.display();
134
+    }
135
+
136
+    public JList<MutableProfile> getProfileList() {
137
+        return profileList;
138
+    }
139
+
140
+    public ReorderableJList<String> getProfileNicknames() {
141
+        return nicknames;
142
+    }
143
+
144
+    public JButton getProfileAddNickname() {
145
+        return addNickname;
146
+    }
147
+
148
+    public JButton getProfileEditNickname() {
149
+        return editNickname;
150
+    }
151
+
152
+    public JButton getProfileDeleteNickname() {
153
+        return deleteNickname;
154
+    }
155
+
156
+    public JTextField getProfileName() {
157
+        return name;
158
+    }
159
+
160
+    public JTextField getProfileIdent() {
161
+        return ident;
162
+    }
163
+
164
+    public JTextField getProfileRealname() {
165
+        return realname;
166
+    }
167
+
168
+    public JButton getAddProfile() {
169
+        return addProfile;
170
+    }
171
+
172
+    public JButton getDeleteProfile() {
173
+        return deleteProfile;
174
+    }
175
+}

+ 362
- 0
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/profile/ProfileManagerDialogLinker.java 查看文件

@@ -0,0 +1,362 @@
1
+/*
2
+ * Copyright (c) 2006-2014 DMDirc Developers
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.addons.ui_swing.dialogs.profile;
24
+
25
+import com.dmdirc.addons.ui_swing.components.reorderablelist.ReorderableJList;
26
+import com.dmdirc.addons.ui_swing.components.vetoable.VetoableListSelectionModel;
27
+import com.dmdirc.addons.ui_swing.dialogs.StandardInputDialog;
28
+import com.dmdirc.interfaces.ui.ProfilesDialogModel;
29
+import com.dmdirc.ui.IconManager;
30
+import com.dmdirc.ui.core.profiles.MutableProfile;
31
+import com.dmdirc.ui.core.profiles.ProfilesDialogModelAdapter;
32
+
33
+import com.google.common.collect.Lists;
34
+
35
+import java.awt.Dialog;
36
+import java.beans.PropertyVetoException;
37
+import java.util.Optional;
38
+
39
+import javax.swing.DefaultListModel;
40
+import javax.swing.JButton;
41
+import javax.swing.JList;
42
+import javax.swing.JTextField;
43
+import javax.swing.ListSelectionModel;
44
+import javax.swing.event.DocumentEvent;
45
+import javax.swing.event.DocumentListener;
46
+
47
+public class ProfileManagerDialogLinker {
48
+
49
+    private final ProfileManagerDialog dialog;
50
+    private final ProfilesDialogModel model;
51
+    private final IconManager iconManager;
52
+
53
+    public ProfileManagerDialogLinker(final ProfileManagerDialog dialog,
54
+            final ProfilesDialogModel model,
55
+            final IconManager iconManager) {
56
+        this.dialog = dialog;
57
+        this.model = model;
58
+        this.iconManager = iconManager;
59
+    }
60
+
61
+    public void bindAddNickname(final JButton addNickname) {
62
+        addNickname.setEnabled(!model.getProfileList().isEmpty());
63
+        model.addListener(new ProfilesDialogModelAdapter() {
64
+
65
+            @Override
66
+            public void profileRemoved(final MutableProfile profile) {
67
+                addNickname.setEnabled(model.isProfileListValid());
68
+            }
69
+
70
+            @Override
71
+            public void profileAdded(final MutableProfile profile) {
72
+                addNickname.setEnabled(model.isProfileListValid());
73
+            }
74
+        });
75
+        addNickname.addActionListener(e -> new StandardInputDialog(dialog,
76
+                Dialog.ModalityType.DOCUMENT_MODAL, iconManager, "Profile Manager: Add Nickname",
77
+                "Enter nickname to add", model::addSelectedProfileNickname
78
+        ).display());
79
+    }
80
+
81
+    public void bindAddProfile(final JButton addProfile) {
82
+        addProfile.addActionListener(e -> new StandardInputDialog(dialog,
83
+                Dialog.ModalityType.DOCUMENT_MODAL, iconManager, "Profile Manager: Add Profile",
84
+                "Enter the new profile's name",
85
+                (String s) -> model.addProfile(s, s, s, Lists.newArrayList(s))
86
+        ).display());
87
+    }
88
+
89
+    public void bindCancelButton(final JButton cancelButton) {
90
+        cancelButton.addActionListener(l -> dialog.dispose());
91
+    }
92
+
93
+    public void bindOKButton(final JButton okButton) {
94
+        okButton.setEnabled(model.isSaveAllowed());
95
+        model.addListener(new ProfilesDialogModelAdapter() {
96
+
97
+            @Override
98
+            public void profileAdded(final MutableProfile profile) {
99
+                okButton.setEnabled(model.isSaveAllowed());
100
+            }
101
+
102
+            @Override
103
+            public void profileRemoved(final MutableProfile profile) {
104
+                okButton.setEnabled(model.isSaveAllowed());
105
+            }
106
+
107
+            @Override
108
+            public void profileEdited(final MutableProfile profile) {
109
+                okButton.setEnabled(model.isSaveAllowed());
110
+            }
111
+
112
+            @Override
113
+            public void profileSelectionChanged(final Optional<MutableProfile> profile) {
114
+                okButton.setEnabled(model.isSaveAllowed());
115
+            }
116
+
117
+            @Override
118
+            public void selectedNicknameChanged(final Optional<String> nickname) {
119
+                okButton.setEnabled(model.isSaveAllowed());
120
+            }
121
+
122
+            @Override
123
+            public void selectedProfileNicknameEdited(final String oldNickname,
124
+                    final String newNickname) {
125
+                okButton.setEnabled(model.isSaveAllowed());
126
+            }
127
+
128
+            @Override
129
+            public void selectedProfileNicknameAdded(final String nickname) {
130
+                okButton.setEnabled(model.isSaveAllowed());
131
+            }
132
+
133
+            @Override
134
+            public void selectedProfileNicknameRemoved(final String nickname) {
135
+                okButton.setEnabled(model.isSaveAllowed());
136
+            }
137
+        });
138
+        okButton.addActionListener(l -> {
139
+            model.save();
140
+            dialog.dispose();
141
+        });
142
+    }
143
+
144
+    public void bindDeleteNickname(final JButton deleteNickname) {
145
+        deleteNickname.setEnabled(model.getSelectedProfileSelectedNickname().isPresent());
146
+        deleteNickname.addActionListener(l -> model.getSelectedProfileSelectedNickname()
147
+                .ifPresent(model::removeSelectedProfileNickname));
148
+        model.addListener(new ProfilesDialogModelAdapter() {
149
+            @Override
150
+            public void selectedNicknameChanged(final Optional<String> nickname) {
151
+                deleteNickname.setEnabled(model.getSelectedProfileSelectedNickname().isPresent());
152
+            }
153
+        });
154
+    }
155
+
156
+    public void bindDeleteProfile(final JButton deleteProfile) {
157
+        deleteProfile.setEnabled(model.getSelectedProfile().isPresent());
158
+        deleteProfile.addActionListener(l -> model.getSelectedProfile()
159
+                .ifPresent(p -> model.removeProfile(p.getName())));
160
+        model.addListener(new ProfilesDialogModelAdapter() {
161
+            @Override
162
+            public void profileSelectionChanged(final Optional<MutableProfile> profile) {
163
+                deleteProfile.setEnabled(model.getSelectedProfile().isPresent());
164
+            }
165
+        });
166
+    }
167
+
168
+    public void bindEditNickname(final JButton editNickname) {
169
+        editNickname.setEnabled(model.getSelectedProfileSelectedNickname().isPresent());
170
+        editNickname.addActionListener(l -> model.getSelectedProfileSelectedNickname().ifPresent(
171
+                (String oldName) -> new StandardInputDialog(dialog,
172
+                        Dialog.ModalityType.DOCUMENT_MODAL, iconManager,
173
+                        "Profile Manager: Edit Nickname", "Enter new nickname",
174
+                        (String newName) -> model.editSelectedProfileNickname(oldName, newName))
175
+                        .display()));
176
+        model.addListener(new ProfilesDialogModelAdapter() {
177
+            @Override
178
+            public void selectedNicknameChanged(final Optional<String> nickname) {
179
+                editNickname.setEnabled(model.getSelectedProfileSelectedNickname().isPresent());
180
+            }
181
+        });
182
+    }
183
+
184
+    public void bindProfileList(final JList<MutableProfile> profileList) {
185
+        final DefaultListModel<MutableProfile> listModel
186
+                = (DefaultListModel<MutableProfile>) profileList.getModel();
187
+        final VetoableListSelectionModel selectionModel = new VetoableListSelectionModel();
188
+        profileList.setSelectionModel(selectionModel);
189
+        model.getProfileList().forEach(listModel::addElement);
190
+        model.addListener(new ProfilesDialogModelAdapter() {
191
+
192
+            @Override
193
+            public void profileRemoved(final MutableProfile profile) {
194
+                listModel.removeElement(profile);
195
+            }
196
+
197
+            @Override
198
+            public void profileAdded(final MutableProfile profile) {
199
+                listModel.addElement(profile);
200
+            }
201
+
202
+            @Override
203
+            public void profileSelectionChanged(final Optional<MutableProfile> profile) {
204
+                if (profile.isPresent()) {
205
+                    final int index = listModel.indexOf(profile.get());
206
+                    selectionModel.setLeadSelectionIndex(index);
207
+                } else {
208
+                    selectionModel.setLeadSelectionIndex(-1);
209
+                }
210
+            }
211
+        });
212
+        selectionModel.addVetoableSelectionListener(e -> {
213
+            if (!model.canSwitchProfiles()) {
214
+                throw new PropertyVetoException("Cannot switch with invalid profile", e);
215
+            }
216
+        });
217
+        profileList.addListSelectionListener(l -> model.setSelectedProfile(
218
+                Optional.ofNullable(profileList.getSelectedValue())));
219
+    }
220
+
221
+    public void bindProfileIdent(final JTextField ident) {
222
+        ident.setEnabled(model.getSelectedProfileIdent().isPresent());
223
+        model.addListener(new ProfilesDialogModelAdapter() {
224
+
225
+            @Override
226
+            public void profileSelectionChanged(final Optional<MutableProfile> profile) {
227
+                ident.setEnabled(model.getSelectedProfile().isPresent());
228
+                ident.setText(model.getSelectedProfileIdent().orElse(""));
229
+            }
230
+        });
231
+        ident.getDocument().addDocumentListener(new DocumentListener() {
232
+
233
+            @Override
234
+            public void insertUpdate(final DocumentEvent e) {
235
+                changed();
236
+            }
237
+
238
+            @Override
239
+            public void removeUpdate(final DocumentEvent e) {
240
+                changed();
241
+            }
242
+
243
+            @Override
244
+            public void changedUpdate(final DocumentEvent e) {
245
+                changed();
246
+            }
247
+
248
+            private void changed() {
249
+                if (model.getSelectedProfile().isPresent()) {
250
+                    model.setSelectedProfileIdent(Optional.of(ident.getText()));
251
+                }
252
+            }
253
+        });
254
+    }
255
+
256
+    public void bindProfileName(final JTextField name) {
257
+        name.setEnabled(model.getSelectedProfileName().isPresent());
258
+        model.addListener(new ProfilesDialogModelAdapter() {
259
+
260
+            @Override
261
+            public void profileSelectionChanged(final Optional<MutableProfile> profile) {
262
+                name.setEnabled(model.getSelectedProfileIdent().isPresent());
263
+                name.setText(model.getSelectedProfileName().orElse(""));
264
+            }
265
+        });
266
+        name.getDocument().addDocumentListener(new DocumentListener() {
267
+
268
+            @Override
269
+            public void insertUpdate(final DocumentEvent e) {
270
+                changed();
271
+            }
272
+
273
+            @Override
274
+            public void removeUpdate(final DocumentEvent e) {
275
+                changed();
276
+            }
277
+
278
+            @Override
279
+            public void changedUpdate(final DocumentEvent e) {
280
+                changed();
281
+            }
282
+
283
+            private void changed() {
284
+                if (model.getSelectedProfile().isPresent()) {
285
+                    model.setSelectedProfileName(Optional.ofNullable(name.getText()));
286
+                }
287
+            }
288
+        });
289
+    }
290
+
291
+    public void bindProfileNicknames(final ReorderableJList<String> nicknames) {
292
+        nicknames.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
293
+        nicknames.setEnabled(model.getSelectedProfileNicknames().isPresent());
294
+        model.addListener(new ProfilesDialogModelAdapter() {
295
+
296
+            @Override
297
+            public void profileSelectionChanged(final Optional<MutableProfile> profile) {
298
+                nicknames.setEnabled(model.getSelectedProfileNicknames().isPresent());
299
+                nicknames.getModel().clear();
300
+                if (model.getSelectedProfileNicknames().isPresent()) {
301
+                    model.getSelectedProfileNicknames().get().forEach(p ->
302
+                            nicknames.getModel().addElement(p)
303
+                    );
304
+                }
305
+            }
306
+
307
+            @Override
308
+            public void selectedProfileNicknameAdded(final String nickname) {
309
+                nicknames.getModel().addElement(nickname);
310
+            }
311
+
312
+            @Override
313
+            public void selectedProfileNicknameRemoved(final String nickname) {
314
+                nicknames.getModel().removeElement(nickname);
315
+            }
316
+
317
+            @Override
318
+            public void selectedProfileNicknameEdited(final String oldNickname,
319
+                    final String newNickname) {
320
+                nicknames.getModel().setElementAt(newNickname,
321
+                        nicknames.getModel().indexOf(oldNickname));
322
+            }
323
+        });
324
+        nicknames.addListSelectionListener(l -> model.setSelectedProfileSelectedNickname(
325
+                Optional.ofNullable(nicknames.getSelectedValue())));
326
+    }
327
+
328
+    public void bindProfileRealnames(final JTextField realname) {
329
+        realname.setEnabled(model.getSelectedProfileRealname().isPresent());
330
+        model.addListener(new ProfilesDialogModelAdapter() {
331
+
332
+            @Override
333
+            public void profileSelectionChanged(final Optional<MutableProfile> profile) {
334
+                realname.setEnabled(model.getSelectedProfileRealname().isPresent());
335
+                realname.setText(model.getSelectedProfileRealname().orElse(""));
336
+            }
337
+        });
338
+        realname.getDocument().addDocumentListener(new DocumentListener() {
339
+
340
+            @Override
341
+            public void insertUpdate(final DocumentEvent e) {
342
+                changed();
343
+            }
344
+
345
+            @Override
346
+            public void removeUpdate(final DocumentEvent e) {
347
+                changed();
348
+            }
349
+
350
+            @Override
351
+            public void changedUpdate(final DocumentEvent e) {
352
+                changed();
353
+            }
354
+
355
+            private void changed() {
356
+                if (model.getSelectedProfile().isPresent()) {
357
+                    model.setSelectedProfileRealname(Optional.of(realname.getText()));
358
+                }
359
+            }
360
+        });
361
+    }
362
+}

+ 66
- 0
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/profile/ProfileNameDocumentListener.java 查看文件

@@ -0,0 +1,66 @@
1
+/*
2
+ * Copyright (c) 2006-2014 DMDirc Developers
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.addons.ui_swing.dialogs.profile;
24
+
25
+import com.dmdirc.interfaces.ui.ProfilesDialogModel;
26
+
27
+import java.util.Optional;
28
+
29
+import javax.swing.JTextField;
30
+import javax.swing.event.DocumentEvent;
31
+import javax.swing.event.DocumentListener;
32
+
33
+/**
34
+* Applies changes in the profile name's document to the model.
35
+*/
36
+public class ProfileNameDocumentListener implements DocumentListener {
37
+
38
+    private final JTextField name;
39
+    private final ProfilesDialogModel model;
40
+
41
+    public ProfileNameDocumentListener(final ProfilesDialogModel model, final JTextField name) {
42
+        this.name = name;
43
+        this.model = model;
44
+    }
45
+
46
+    @Override
47
+    public void insertUpdate(final DocumentEvent e) {
48
+        changed();
49
+    }
50
+
51
+    @Override
52
+    public void removeUpdate(final DocumentEvent e) {
53
+        changed();
54
+    }
55
+
56
+    @Override
57
+    public void changedUpdate(final DocumentEvent e) {
58
+        changed();
59
+    }
60
+
61
+    private void changed() {
62
+        if (model.isSelectedProfileNameValid()) {
63
+            model.setSelectedProfileName(Optional.ofNullable(name.getText()));
64
+        }
65
+    }
66
+}

+ 67
- 0
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/profile/ProfileRealnameDocumentListener.java 查看文件

@@ -0,0 +1,67 @@
1
+/*
2
+ * Copyright (c) 2006-2014 DMDirc Developers
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.addons.ui_swing.dialogs.profile;
24
+
25
+import com.dmdirc.interfaces.ui.ProfilesDialogModel;
26
+
27
+import java.util.Optional;
28
+
29
+import javax.swing.JTextField;
30
+import javax.swing.event.DocumentEvent;
31
+import javax.swing.event.DocumentListener;
32
+
33
+/**
34
+* Applies changes in the profile realname's document to the model.
35
+*/
36
+public class ProfileRealnameDocumentListener implements DocumentListener {
37
+
38
+    private final JTextField realname;
39
+    private final ProfilesDialogModel model;
40
+
41
+    public ProfileRealnameDocumentListener(final ProfilesDialogModel model,
42
+            final JTextField realname) {
43
+        this.realname = realname;
44
+        this.model = model;
45
+    }
46
+
47
+    @Override
48
+    public void insertUpdate(final DocumentEvent e) {
49
+        changed();
50
+    }
51
+
52
+    @Override
53
+    public void removeUpdate(final DocumentEvent e) {
54
+        changed();
55
+    }
56
+
57
+    @Override
58
+    public void changedUpdate(final DocumentEvent e) {
59
+        changed();
60
+    }
61
+
62
+    private void changed() {
63
+        if (model.getSelectedProfile().isPresent()) {
64
+            model.setSelectedProfileRealname(Optional.of(realname.getText()));
65
+        }
66
+    }
67
+}

+ 16
- 2
ui_swing/src/com/dmdirc/addons/ui_swing/injection/DialogModule.java 查看文件

@@ -38,7 +38,7 @@ import com.dmdirc.addons.ui_swing.dialogs.error.ErrorListDialog;
38 38
 import com.dmdirc.addons.ui_swing.dialogs.feedback.FeedbackDialog;
39 39
 import com.dmdirc.addons.ui_swing.dialogs.newserver.NewServerDialog;
40 40
 import com.dmdirc.addons.ui_swing.dialogs.prefs.SwingPreferencesDialog;
41
-import com.dmdirc.addons.ui_swing.dialogs.profiles.ProfileManagerDialog;
41
+import com.dmdirc.addons.ui_swing.dialogs.profile.ProfileManagerDialog;
42 42
 import com.dmdirc.addons.ui_swing.dialogs.serversetting.ServerSettingsDialog;
43 43
 import com.dmdirc.addons.ui_swing.dialogs.updater.SwingRestartDialog;
44 44
 import com.dmdirc.addons.ui_swing.dialogs.updater.SwingUpdaterDialog;
@@ -51,10 +51,12 @@ import com.dmdirc.interfaces.config.IdentityFactory;
51 51
 import com.dmdirc.interfaces.ui.AliasDialogModel;
52 52
 import com.dmdirc.interfaces.ui.FeedbackDialogModel;
53 53
 import com.dmdirc.interfaces.ui.NewServerDialogModel;
54
+import com.dmdirc.interfaces.ui.ProfilesDialogModel;
54 55
 import com.dmdirc.plugins.ServiceManager;
55 56
 import com.dmdirc.ui.core.aliases.CoreAliasDialogModel;
56 57
 import com.dmdirc.ui.core.feedback.CoreFeedbackDialogModel;
57 58
 import com.dmdirc.ui.core.newserver.CoreNewServerDialogModel;
59
+import com.dmdirc.ui.core.profiles.CoreProfilesDialogModel;
58 60
 import com.dmdirc.ui.input.TabCompleterUtils;
59 61
 import com.dmdirc.ui.messages.ColourManagerFactory;
60 62
 
@@ -103,6 +105,11 @@ public class DialogModule {
103 105
         return model;
104 106
     }
105 107
 
108
+    @Provides
109
+    public ProfilesDialogModel getProfileDialogModel(final CoreProfilesDialogModel model) {
110
+        return model;
111
+    }
112
+
106 113
     @Provides
107 114
     @Singleton
108 115
     public DialogProvider<NewServerDialog> getNewServerDialogProvider(
@@ -112,7 +119,14 @@ public class DialogModule {
112 119
 
113 120
     @Provides
114 121
     @Singleton
115
-    public DialogProvider<ProfileManagerDialog> getProfileManagerDialogProvider(
122
+    public DialogProvider<com.dmdirc.addons.ui_swing.dialogs.profiles.ProfileManagerDialog> getOldProfileManagerDialogProvider(
123
+            final Provider<com.dmdirc.addons.ui_swing.dialogs.profiles.ProfileManagerDialog> provider) {
124
+        return new DialogProvider<>(provider);
125
+    }
126
+
127
+    @Provides
128
+    @Singleton
129
+    public DialogProvider<ProfileManagerDialog> getNewProfileManagerDialogProvider(
116 130
             final Provider<ProfileManagerDialog> provider) {
117 131
         return new DialogProvider<>(provider);
118 132
     }

正在加载...
取消
保存