Browse Source

Merge pull request #125 from greboid/master

"Remove server lists.  They're half arsed and broken"
pull/126/head
Chris Smith 9 years ago
parent
commit
413a7df957
29 changed files with 0 additions and 3525 deletions
  1. 0
    4
      serverlistdialog/build.gradle
  2. 0
    26
      serverlistdialog/plugin.config
  3. 0
    229
      serverlistdialog/src/com/dmdirc/addons/serverlistdialog/AddEntryInputDialog.java
  4. 0
    236
      serverlistdialog/src/com/dmdirc/addons/serverlistdialog/AddGroupInputDialog.java
  5. 0
    48
      serverlistdialog/src/com/dmdirc/addons/serverlistdialog/Help.java
  6. 0
    155
      serverlistdialog/src/com/dmdirc/addons/serverlistdialog/Info.java
  7. 0
    125
      serverlistdialog/src/com/dmdirc/addons/serverlistdialog/Perform.java
  8. 0
    150
      serverlistdialog/src/com/dmdirc/addons/serverlistdialog/Profiles.java
  9. 0
    71
      serverlistdialog/src/com/dmdirc/addons/serverlistdialog/ServerGroupTreeRenderer.java
  10. 0
    79
      serverlistdialog/src/com/dmdirc/addons/serverlistdialog/ServerListController.java
  11. 0
    216
      serverlistdialog/src/com/dmdirc/addons/serverlistdialog/ServerListDialog.java
  12. 0
    58
      serverlistdialog/src/com/dmdirc/addons/serverlistdialog/ServerListDialogPlugin.java
  13. 0
    62
      serverlistdialog/src/com/dmdirc/addons/serverlistdialog/ServerListListener.java
  14. 0
    246
      serverlistdialog/src/com/dmdirc/addons/serverlistdialog/ServerListModel.java
  15. 0
    34
      serverlistdialog/src/com/dmdirc/addons/serverlistdialog/ServerListModule.java
  16. 0
    177
      serverlistdialog/src/com/dmdirc/addons/serverlistdialog/Settings.java
  17. 0
    209
      serverlistdialog/src/com/dmdirc/addons/serverlistdialog/Tree.java
  18. 0
    53
      serverlistdialog/src/com/dmdirc/addons/serverlistdialog/URIJTextField.java
  19. 0
    29
      serverlists/plugin.config
  20. 0
    108
      serverlists/src/com/dmdirc/addons/serverlists/ServerEntry.java
  21. 0
    220
      serverlists/src/com/dmdirc/addons/serverlists/ServerGroup.java
  22. 0
    107
      serverlists/src/com/dmdirc/addons/serverlists/ServerGroupItem.java
  23. 0
    119
      serverlists/src/com/dmdirc/addons/serverlists/ServerGroupItemBase.java
  24. 0
    182
      serverlists/src/com/dmdirc/addons/serverlists/ServerList.java
  25. 0
    29
      serverlists/src/com/dmdirc/addons/serverlists/ServerListPlugin.java
  26. 0
    81
      serverlists/src/com/dmdirc/addons/serverlists/io/ServerEntryReader.java
  27. 0
    152
      serverlists/src/com/dmdirc/addons/serverlists/io/ServerGroupReader.java
  28. 0
    165
      serverlists/src/com/dmdirc/addons/serverlists/io/ServerGroupWriter.java
  29. 0
    155
      serverlists/src/com/dmdirc/addons/serverlists/service/ServerListServiceProvider.java

+ 0
- 4
serverlistdialog/build.gradle View File

@@ -1,4 +0,0 @@
1
-dependencies {
2
-  compile plugin('ui_swing')
3
-  compile plugin('serverlists')
4
-}

+ 0
- 26
serverlistdialog/plugin.config View File

@@ -1,26 +0,0 @@
1
-# This is a DMDirc configuration file.
2
-
3
-# This section indicates which sections below take key/value
4
-# pairs, rather than a simple list. It should be placed above
5
-# any sections that take key/values.
6
-keysections:
7
-  metadata
8
-  updates
9
-  version
10
-  requires
11
-
12
-metadata:
13
-  author=Greg <greg@dmdirc.com>
14
-  mainclass=com.dmdirc.addons.serverlistdialog.ServerListDialogPlugin
15
-  description=Support for server lists
16
-  name=serverlistdialog
17
-  nicename=Server List Dialog
18
-
19
-updates:
20
-  id=74
21
-
22
-version:
23
-  friendly=0.2
24
-
25
-requires:
26
-  parent=ui_swing

+ 0
- 229
serverlistdialog/src/com/dmdirc/addons/serverlistdialog/AddEntryInputDialog.java View File

@@ -1,229 +0,0 @@
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.serverlistdialog;
24
-
25
-import com.dmdirc.addons.serverlists.ServerGroup;
26
-import com.dmdirc.addons.ui_swing.components.text.TextLabel;
27
-import com.dmdirc.addons.ui_swing.components.validating.ValidatingJTextField;
28
-import com.dmdirc.addons.ui_swing.dialogs.StandardDialog;
29
-import com.dmdirc.addons.ui_swing.dialogs.StandardInputDialog;
30
-import com.dmdirc.ui.IconManager;
31
-import com.dmdirc.util.validators.NotEmptyValidator;
32
-import com.dmdirc.util.validators.URIValidator;
33
-import com.dmdirc.util.validators.Validator;
34
-
35
-import java.awt.Window;
36
-import java.awt.event.ActionEvent;
37
-import java.awt.event.ActionListener;
38
-import java.awt.event.WindowAdapter;
39
-import java.awt.event.WindowEvent;
40
-import java.net.URI;
41
-
42
-import javax.swing.JButton;
43
-import javax.swing.JLabel;
44
-import javax.swing.JTree;
45
-import javax.swing.event.DocumentEvent;
46
-import javax.swing.event.DocumentListener;
47
-import javax.swing.tree.DefaultMutableTreeNode;
48
-
49
-import net.miginfocom.swing.MigLayout;
50
-
51
-/**
52
- * Standard input dialog.
53
- */
54
-public class AddEntryInputDialog extends StandardDialog {
55
-
56
-    /** Serial version UID. */
57
-    private static final long serialVersionUID = 1;
58
-    /** Entry name Validator. */
59
-    private final Validator<String> entryValidator;
60
-    /** URI Validator. */
61
-    private final Validator<String> uriValidator;
62
-    /** Group name. */
63
-    private ValidatingJTextField entryName;
64
-    /** Network name. */
65
-    private ValidatingJTextField uri;
66
-    /** Blurb label. */
67
-    private TextLabel blurb;
68
-    /** Message. */
69
-    private final String message;
70
-    /** Parent tree. */
71
-    private final JTree items;
72
-    /** Parent model. */
73
-    private final ServerListModel model;
74
-
75
-    /**
76
-     * Instantiates a new standard input dialog.
77
-     *
78
-     * @param iconManager Icon Manager
79
-     * @param items       Parent tree
80
-     * @param owner       Dialog owner
81
-     * @param model       Server list model
82
-     */
83
-    public AddEntryInputDialog(final IconManager iconManager,
84
-            final Window owner, final JTree items,
85
-            final ServerListModel model) {
86
-        super(owner, ModalityType.MODELESS);
87
-
88
-        this.items = items;
89
-        this.model = model;
90
-        this.entryValidator = new NotEmptyValidator();
91
-        this.uriValidator = new URIValidator();
92
-        this.message = "Please fill in the entry name and its address";
93
-
94
-        setTitle("Add new server entry");
95
-        setDefaultCloseOperation(StandardInputDialog.DISPOSE_ON_CLOSE);
96
-
97
-        initComponents(iconManager);
98
-        addListeners();
99
-        layoutComponents();
100
-    }
101
-
102
-    /**
103
-     * Called when the dialog's OK button is clicked.
104
-     *
105
-     * @return whether the dialog can close
106
-     */
107
-    public boolean save() {
108
-        DefaultMutableTreeNode groupNode = (DefaultMutableTreeNode) items.
109
-                getSelectionPath().getLastPathComponent();
110
-        while (!((groupNode.getUserObject()) instanceof ServerGroup)) {
111
-            groupNode = (DefaultMutableTreeNode) groupNode.getParent();
112
-        }
113
-        model.addEntry((ServerGroup) groupNode.getUserObject(), getEntryName(),
114
-                URI.create(getURI()));
115
-        return true;
116
-    }
117
-
118
-    /**
119
-     * Initialises the components.
120
-     */
121
-    private void initComponents(final IconManager iconManager) {
122
-        orderButtons(new JButton(), new JButton());
123
-        entryName = new ValidatingJTextField(iconManager, entryValidator);
124
-        uri = new URIJTextField(iconManager, "", uriValidator);
125
-        blurb = new TextLabel(message);
126
-        validateText();
127
-    }
128
-
129
-    /**
130
-     * Adds the listeners.
131
-     */
132
-    private void addListeners() {
133
-        getOkButton().addActionListener(new ActionListener() {
134
-
135
-            @Override
136
-            public void actionPerformed(final ActionEvent e) {
137
-                if (save()) {
138
-                    dispose();
139
-                }
140
-            }
141
-        });
142
-        getCancelButton().addActionListener(new ActionListener() {
143
-
144
-            @Override
145
-            public void actionPerformed(final ActionEvent e) {
146
-                dispose();
147
-            }
148
-        });
149
-        addWindowListener(new WindowAdapter() {
150
-
151
-            @Override
152
-            public void windowOpened(final WindowEvent e) {
153
-                entryName.requestFocusInWindow();
154
-            }
155
-
156
-            @Override
157
-            public void windowClosed(final WindowEvent e) {
158
-                //Ignore
159
-            }
160
-        });
161
-        final DocumentListener dl = new DocumentListener() {
162
-
163
-            @Override
164
-            public void insertUpdate(final DocumentEvent e) {
165
-                validateText();
166
-            }
167
-
168
-            @Override
169
-            public void removeUpdate(final DocumentEvent e) {
170
-                validateText();
171
-            }
172
-
173
-            @Override
174
-            public void changedUpdate(final DocumentEvent e) {
175
-                //Ignore
176
-            }
177
-        };
178
-        entryName.getDocument().addDocumentListener(dl);
179
-        uri.getDocument().addDocumentListener(dl);
180
-    }
181
-
182
-    @Override
183
-    public boolean enterPressed() {
184
-        executeAction(getOkButton());
185
-        return true;
186
-    }
187
-
188
-    /**
189
-     * Validates the change.
190
-     */
191
-    private void validateText() {
192
-        getOkButton().setEnabled(!entryValidator.validate(getEntryName())
193
-                .isFailure() && !uriValidator.validate(getURI()).isFailure());
194
-    }
195
-
196
-    /**
197
-     * Lays out the components.
198
-     */
199
-    private void layoutComponents() {
200
-        setLayout(new MigLayout("fill, wrap 2"));
201
-
202
-        add(blurb, "growx, spanx 2");
203
-        add(new JLabel("Item name: "));
204
-        add(entryName, "growx");
205
-        add(new JLabel("Server URI: "));
206
-        add(uri, "growx");
207
-        add(getLeftButton(), "split 3, skip, right");
208
-        add(getRightButton(), "right");
209
-    }
210
-
211
-    /**
212
-     * Returns the text in the entry name.
213
-     *
214
-     * @return Entry name
215
-     */
216
-    public String getEntryName() {
217
-        return entryName.getText();
218
-    }
219
-
220
-    /**
221
-     * Returns the URI in the URI field.
222
-     *
223
-     * @return server URI
224
-     */
225
-    public String getURI() {
226
-        return uri.getText();
227
-    }
228
-
229
-}

+ 0
- 236
serverlistdialog/src/com/dmdirc/addons/serverlistdialog/AddGroupInputDialog.java View File

@@ -1,236 +0,0 @@
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.serverlistdialog;
24
-
25
-import com.dmdirc.addons.serverlists.ServerGroup;
26
-import com.dmdirc.addons.ui_swing.components.text.TextLabel;
27
-import com.dmdirc.addons.ui_swing.components.validating.ValidatingJTextField;
28
-import com.dmdirc.addons.ui_swing.dialogs.StandardDialog;
29
-import com.dmdirc.addons.ui_swing.dialogs.StandardInputDialog;
30
-import com.dmdirc.ui.IconManager;
31
-import com.dmdirc.util.validators.NotEmptyValidator;
32
-import com.dmdirc.util.validators.Validator;
33
-
34
-import java.awt.Window;
35
-import java.awt.event.ActionEvent;
36
-import java.awt.event.ActionListener;
37
-import java.awt.event.WindowAdapter;
38
-import java.awt.event.WindowEvent;
39
-
40
-import javax.swing.JButton;
41
-import javax.swing.JLabel;
42
-import javax.swing.JTextField;
43
-import javax.swing.JTree;
44
-import javax.swing.event.DocumentEvent;
45
-import javax.swing.event.DocumentListener;
46
-import javax.swing.tree.DefaultMutableTreeNode;
47
-
48
-import net.miginfocom.swing.MigLayout;
49
-
50
-/**
51
- * Standard input dialog.
52
- */
53
-public class AddGroupInputDialog extends StandardDialog {
54
-
55
-    /** Serial version UID. */
56
-    private static final long serialVersionUID = 1;
57
-    /** Validator. */
58
-    private final Validator<String> validator;
59
-    /** Group name. */
60
-    private ValidatingJTextField groupName;
61
-    /** Network name. */
62
-    private JTextField networkName;
63
-    /** Blurb label. */
64
-    private TextLabel blurb;
65
-    /** Message. */
66
-    private final String message;
67
-    /** Parent tree. */
68
-    private final JTree tree;
69
-    /** Parent model. */
70
-    private final ServerListModel serverListModel;
71
-
72
-    /**
73
-     * Instantiates a new standard input dialog.
74
-     *
75
-     * @param iconManager Icon manager
76
-     * @param items       Parent tree
77
-     * @param owner       Dialog owner
78
-     * @param model       Server list model
79
-     */
80
-    public AddGroupInputDialog(final IconManager iconManager,
81
-            final Window owner, final JTree items,
82
-            final ServerListModel model) {
83
-        super(owner, ModalityType.MODELESS);
84
-
85
-        this.tree = items;
86
-        this.serverListModel = model;
87
-        this.validator = new NotEmptyValidator();
88
-        this.message = "Please fill in the group name and its network name";
89
-
90
-        setTitle("Add new server group");
91
-        setDefaultCloseOperation(StandardInputDialog.DISPOSE_ON_CLOSE);
92
-
93
-        initComponents(iconManager);
94
-        addListeners();
95
-        layoutComponents();
96
-    }
97
-
98
-    /**
99
-     * Called when the dialog's OK button is clicked.
100
-     *
101
-     * @return whether the dialog can close
102
-     */
103
-    public boolean save() {
104
-        DefaultMutableTreeNode groupNode = (DefaultMutableTreeNode) tree.
105
-                getSelectionPath().getLastPathComponent();
106
-        if (groupNode == null) {
107
-            groupNode = (DefaultMutableTreeNode) tree.getModel().getRoot();
108
-        } else {
109
-            while (!((groupNode.getUserObject()) instanceof ServerGroup)) {
110
-                if (groupNode.getParent() == null) {
111
-                    groupNode = (DefaultMutableTreeNode) tree.getModel().getRoot();
112
-                    break;
113
-                } else {
114
-                    groupNode = (DefaultMutableTreeNode) groupNode.getParent();
115
-                }
116
-            }
117
-        }
118
-        if (groupNode == tree.getModel().getRoot()) {
119
-            serverListModel.addGroup(null, getGroupName(), getNetworkName());
120
-        } else {
121
-            serverListModel.addGroup((ServerGroup) groupNode.getUserObject(),
122
-                    getGroupName(), getNetworkName());
123
-        }
124
-        return true;
125
-    }
126
-
127
-    /**
128
-     * Initialises the components.
129
-     */
130
-    private void initComponents(final IconManager iconManager) {
131
-        orderButtons(new JButton(), new JButton());
132
-        groupName = new ValidatingJTextField(iconManager, validator);
133
-        networkName = new JTextField();
134
-        blurb = new TextLabel(message);
135
-        validateText();
136
-    }
137
-
138
-    /**
139
-     * Adds the listeners.
140
-     */
141
-    private void addListeners() {
142
-        getOkButton().addActionListener(new ActionListener() {
143
-
144
-            @Override
145
-            public void actionPerformed(final ActionEvent e) {
146
-                if (save()) {
147
-                    dispose();
148
-                }
149
-            }
150
-        });
151
-        getCancelButton().addActionListener(new ActionListener() {
152
-
153
-            @Override
154
-            public void actionPerformed(final ActionEvent e) {
155
-                dispose();
156
-            }
157
-        });
158
-        addWindowListener(new WindowAdapter() {
159
-
160
-            @Override
161
-            public void windowOpened(final WindowEvent e) {
162
-                groupName.requestFocusInWindow();
163
-            }
164
-
165
-            @Override
166
-            public void windowClosed(final WindowEvent e) {
167
-                //Ignore
168
-            }
169
-        });
170
-        groupName.getDocument().addDocumentListener(new DocumentListener() {
171
-
172
-            @Override
173
-            public void insertUpdate(final DocumentEvent e) {
174
-                validateText();
175
-            }
176
-
177
-            @Override
178
-            public void removeUpdate(final DocumentEvent e) {
179
-                validateText();
180
-            }
181
-
182
-            @Override
183
-            public void changedUpdate(final DocumentEvent e) {
184
-                //Ignore
185
-            }
186
-        });
187
-    }
188
-
189
-    @Override
190
-    public boolean enterPressed() {
191
-        executeAction(getOkButton());
192
-        return true;
193
-    }
194
-
195
-    /**
196
-     * Validates the change.
197
-     */
198
-    private void validateText() {
199
-        getOkButton().setEnabled(!validator.validate(getGroupName())
200
-                .isFailure());
201
-    }
202
-
203
-    /**
204
-     * Lays out the components.
205
-     */
206
-    private void layoutComponents() {
207
-        setLayout(new MigLayout("fill, wrap 2"));
208
-
209
-        add(blurb, "growx, spanx 2");
210
-        add(new JLabel("Group name: "));
211
-        add(groupName, "growx");
212
-        add(new JLabel("Network name: "));
213
-        add(networkName, "growx");
214
-        add(getLeftButton(), "split 3, skip, right");
215
-        add(getRightButton(), "right");
216
-    }
217
-
218
-    /**
219
-     * Returns the text in the group name.
220
-     *
221
-     * @return Group name
222
-     */
223
-    public String getGroupName() {
224
-        return groupName.getText();
225
-    }
226
-
227
-    /**
228
-     * Returns the text in the network name.
229
-     *
230
-     * @return Network name
231
-     */
232
-    public String getNetworkName() {
233
-        return networkName.getText();
234
-    }
235
-
236
-}

+ 0
- 48
serverlistdialog/src/com/dmdirc/addons/serverlistdialog/Help.java View File

@@ -1,48 +0,0 @@
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.serverlistdialog;
24
-
25
-import com.dmdirc.addons.ui_swing.components.text.TextLabel;
26
-
27
-import javax.swing.JPanel;
28
-
29
-import net.miginfocom.swing.MigLayout;
30
-
31
-/**
32
- * Introductory panel for the Server list dialog.
33
- */
34
-public class Help extends JPanel {
35
-
36
-    /** A version number for this class. */
37
-    private static final long serialVersionUID = 2;
38
-
39
-    /**
40
-     * Creates a new help panel.
41
-     */
42
-    public Help() {
43
-        setLayout(new MigLayout("fill"));
44
-        add(new TextLabel("Please select an item from the left to start "
45
-                + "editing options and settings."), "grow, pushy");
46
-    }
47
-
48
-}

+ 0
- 155
serverlistdialog/src/com/dmdirc/addons/serverlistdialog/Info.java View File

@@ -1,155 +0,0 @@
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.serverlistdialog;
24
-
25
-import com.dmdirc.addons.serverlists.ServerGroupItem;
26
-import com.dmdirc.addons.ui_swing.UIUtilities;
27
-import com.dmdirc.addons.ui_swing.components.text.TextLabel;
28
-import com.dmdirc.ui.core.util.URLHandler;
29
-
30
-import java.net.URI;
31
-import java.util.Map.Entry;
32
-
33
-import javax.swing.JPanel;
34
-import javax.swing.JScrollPane;
35
-import javax.swing.event.HyperlinkEvent;
36
-import javax.swing.event.HyperlinkEvent.EventType;
37
-import javax.swing.event.HyperlinkListener;
38
-
39
-import net.miginfocom.swing.MigLayout;
40
-
41
-/**
42
- * Panel for showing server group item information.
43
- */
44
-public class Info extends JPanel implements HyperlinkListener,
45
-        ServerListListener {
46
-
47
-    /** A version number for this class. */
48
-    private static final long serialVersionUID = 2;
49
-    /** Info pane. */
50
-    private final TextLabel infoLabel;
51
-    /** Link label. */
52
-    private final TextLabel linkLabel;
53
-    /** Server list model. */
54
-    private final ServerListModel model;
55
-    /** Info scroll panel. */
56
-    private final JScrollPane sp;
57
-    /** URL Handler to use to open links. */
58
-    private final URLHandler urlHandler;
59
-
60
-    /**
61
-     * Creates a new info panel.
62
-     *
63
-     * @param model      Model to pull information from
64
-     * @param urlHandler A {@link URLHandler} to use to open links
65
-     */
66
-    public Info(final ServerListModel model, final URLHandler urlHandler) {
67
-
68
-        this.urlHandler = urlHandler;
69
-        this.model = model;
70
-
71
-        infoLabel = new TextLabel();
72
-        linkLabel = new TextLabel();
73
-        sp = new JScrollPane(infoLabel);
74
-
75
-        setLayout(new MigLayout("fill, ins 0"));
76
-        add(sp, "grow, push");
77
-        add(linkLabel, "grow");
78
-
79
-        addListeners();
80
-        serverGroupChanged(model.getSelectedItem());
81
-    }
82
-
83
-    /**
84
-     * Adds required listeners.
85
-     */
86
-    private void addListeners() {
87
-        linkLabel.addHyperlinkListener(this);
88
-        model.addServerListListener(this);
89
-    }
90
-
91
-    @Override
92
-    public void hyperlinkUpdate(final HyperlinkEvent e) {
93
-        if (e.getEventType() == EventType.ACTIVATED) {
94
-            urlHandler.launchApp(e.getURL());
95
-        }
96
-    }
97
-
98
-    @Override
99
-    public void serverGroupChanged(final ServerGroupItem item) {
100
-        setVisible(false);
101
-        infoLabel.setVisible(false);
102
-        linkLabel.setVisible(false);
103
-        if (item == null) {
104
-            infoLabel.setText("");
105
-            linkLabel.setText("");
106
-        } else {
107
-            final StringBuilder sb = new StringBuilder();
108
-            sb.append("<html><b>");
109
-            sb.append(item.getPath());
110
-            sb.append("</b><br>");
111
-            if (item.getGroup() == null) {
112
-                sb.append("");
113
-            } else {
114
-                sb.append(item.getGroup().getDescription());
115
-            }
116
-            sb.append("</html>");
117
-            infoLabel.setText(sb.toString());
118
-            sb.setLength(0);
119
-            for (Entry<String, URI> entry : item.getGroup().getLinks()
120
-                    .entrySet()) {
121
-                if (sb.length() != 0) {
122
-                    sb.append("<br>");
123
-                }
124
-                sb.append("<a href=\"");
125
-                sb.append(entry.getValue().toString());
126
-                sb.append("\">");
127
-                sb.append(entry.getKey());
128
-                sb.append("</a>");
129
-            }
130
-            linkLabel.setText(sb.toString());
131
-        }
132
-        UIUtilities.resetScrollPane(sp);
133
-        infoLabel.setVisible(true);
134
-        linkLabel.setVisible(true);
135
-        setVisible(true);
136
-    }
137
-
138
-    @Override
139
-    public void dialogClosed(final boolean save) {
140
-        //Ignore
141
-    }
142
-
143
-    @Override
144
-    public void serverGroupAdded(final ServerGroupItem parent,
145
-            final ServerGroupItem group) {
146
-        //Ignore
147
-    }
148
-
149
-    @Override
150
-    public void serverGroupRemoved(final ServerGroupItem parent,
151
-            final ServerGroupItem group) {
152
-        //Ignore
153
-    }
154
-
155
-}

+ 0
- 125
serverlistdialog/src/com/dmdirc/addons/serverlistdialog/Perform.java View File

@@ -1,125 +0,0 @@
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.serverlistdialog;
24
-
25
-import com.dmdirc.actions.wrappers.PerformWrapper;
26
-import com.dmdirc.addons.serverlists.ServerGroupItem;
27
-import com.dmdirc.addons.ui_swing.components.performpanel.PerformPanel;
28
-import com.dmdirc.interfaces.config.AggregateConfigProvider;
29
-import com.dmdirc.ui.IconManager;
30
-import com.dmdirc.ui.messages.ColourManagerFactory;
31
-
32
-import javax.swing.BorderFactory;
33
-import javax.swing.JPanel;
34
-import javax.swing.UIManager;
35
-import javax.swing.border.Border;
36
-
37
-import net.miginfocom.swing.MigLayout;
38
-
39
-/**
40
- * Panel to show and edit performs for a server group.
41
- */
42
-public class Perform extends JPanel implements ServerListListener {
43
-
44
-    /** Serial version UID. */
45
-    private static final long serialVersionUID = 2;
46
-    /** Perform panel. */
47
-    private final PerformPanel performPanel;
48
-    /** Server list model. */
49
-    private final ServerListModel model;
50
-    /** Platform border. */
51
-    private final Border border;
52
-
53
-    /**
54
-     * Creates a new perform panel backed by the specified model.
55
-     *
56
-     * @param iconManager  Icon Manager
57
-     * @param globalConfig Global configuration
58
-     * @param wrapper      Perform wrapper to read/write performs to.
59
-     * @param model        Backing model
60
-     */
61
-    public Perform(
62
-            final IconManager iconManager,
63
-            final AggregateConfigProvider globalConfig,
64
-            final PerformWrapper wrapper,
65
-            final ServerListModel model,
66
-            final ColourManagerFactory colourManagerFactory) {
67
-
68
-        this.model = model;
69
-        performPanel = new PerformPanel(iconManager, colourManagerFactory, globalConfig, wrapper);
70
-
71
-        addListeners();
72
-        if (model.getSelectedItemPerformDescription() != null) {
73
-            performPanel.switchPerform(model
74
-                    .getSelectedItemPerformDescription());
75
-        }
76
-
77
-        border = UIManager.getBorder("TitledBorder.border");
78
-        setBorder(BorderFactory.createTitledBorder(border, "Network perform"));
79
-        setLayout(new MigLayout("fill"));
80
-        add(performPanel, "grow");
81
-    }
82
-
83
-    /**
84
-     * Adds required listeners.
85
-     */
86
-    private void addListeners() {
87
-        model.addServerListListener(this);
88
-    }
89
-
90
-    @Override
91
-    public void serverGroupAdded(final ServerGroupItem parent,
92
-            final ServerGroupItem group) {
93
-        //Ignore
94
-    }
95
-
96
-    @Override
97
-    public void serverGroupRemoved(final ServerGroupItem parent,
98
-            final ServerGroupItem group) {
99
-        //Ignore
100
-    }
101
-
102
-    @Override
103
-    public void serverGroupChanged(final ServerGroupItem item) {
104
-        if (item == null) {
105
-            performPanel.switchPerform(null);
106
-            return;
107
-        }
108
-        if (item.getGroup() == item) {
109
-            setBorder(BorderFactory.createTitledBorder(border,
110
-                    "Network perform"));
111
-        } else {
112
-            setBorder(BorderFactory.createTitledBorder(border,
113
-                    "Server perform"));
114
-        }
115
-        performPanel.switchPerform(model.getSelectedItemPerformDescription());
116
-    }
117
-
118
-    @Override
119
-    public void dialogClosed(final boolean save) {
120
-        if (save) {
121
-            performPanel.savePerform();
122
-        }
123
-    }
124
-
125
-}

+ 0
- 150
serverlistdialog/src/com/dmdirc/addons/serverlistdialog/Profiles.java View File

@@ -1,150 +0,0 @@
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.serverlistdialog;
24
-
25
-import com.dmdirc.addons.serverlists.ServerGroupItem;
26
-import com.dmdirc.addons.ui_swing.components.vetoable.VetoableComboBoxModel;
27
-import com.dmdirc.interfaces.config.ConfigProvider;
28
-import com.dmdirc.interfaces.config.IdentityController;
29
-
30
-import java.util.HashMap;
31
-import java.util.Map;
32
-import java.util.Map.Entry;
33
-
34
-import javax.swing.BorderFactory;
35
-import javax.swing.DefaultComboBoxModel;
36
-import javax.swing.JComboBox;
37
-import javax.swing.JLabel;
38
-import javax.swing.JPanel;
39
-import javax.swing.UIManager;
40
-
41
-import net.miginfocom.swing.MigLayout;
42
-
43
-/**
44
- * Profile selection field for an associated server group item.
45
- */
46
-public class Profiles extends JPanel implements ServerListListener {
47
-
48
-    /** Serial version UID. */
49
-    private static final long serialVersionUID = 2;
50
-    /** Server list model. */
51
-    private final ServerListModel model;
52
-    /** Combo boxes. */
53
-    private final Map<ServerGroupItem, JComboBox<ConfigProvider>> combos = new HashMap<>();
54
-    /** Info label. */
55
-    private final JLabel label;
56
-    /** Controller to use to get profiles. */
57
-    private final IdentityController identityController;
58
-
59
-    /**
60
-     * Creates a new profile panel backed by the specified model.
61
-     *
62
-     * @param model              Backing server list model
63
-     * @param identityController Controller to use to get profiles.
64
-     */
65
-    public Profiles(final ServerListModel model, final IdentityController identityController) {
66
-
67
-        this.model = model;
68
-        this.identityController = identityController;
69
-
70
-        label = new JLabel("Use this profile on this network: ");
71
-        setBorder(BorderFactory.createTitledBorder(UIManager.getBorder(
72
-                "TitledBorder.border"), "Default profile"));
73
-        addListeners();
74
-
75
-        setLayout(new MigLayout("fill"));
76
-        add(label);
77
-        add(getComboBox(model.getSelectedItem()), "grow, push");
78
-    }
79
-
80
-    /**
81
-     * Adds required listeners.
82
-     */
83
-    private void addListeners() {
84
-        model.addServerListListener(this);
85
-    }
86
-
87
-    @Override
88
-    public void serverGroupChanged(final ServerGroupItem item) {
89
-        setVisible(false);
90
-        removeAll();
91
-        add(label);
92
-        add(getComboBox(item), "grow, push");
93
-        setVisible(true);
94
-    }
95
-
96
-    /**
97
-     * Gets or creates a combo box for selecting performs for the specified server group item.
98
-     *
99
-     * @param item Server group item requiring the profile selection
100
-     *
101
-     * @return The server group item's associated profile selection box
102
-     */
103
-    private JComboBox<ConfigProvider> getComboBox(final ServerGroupItem item) {
104
-        if (!combos.containsKey(item)) {
105
-            final DefaultComboBoxModel<ConfigProvider> comboModel = new VetoableComboBoxModel<>();
106
-
107
-            ConfigProvider selectedItem = null;
108
-            comboModel.addElement(null);
109
-            for (ConfigProvider profile : identityController.getProvidersByType("profile")) {
110
-                comboModel.addElement(profile);
111
-                if (item != null && profile.getName().equals(
112
-                        item.getProfile())) {
113
-                    selectedItem = profile;
114
-                }
115
-            }
116
-            comboModel.setSelectedItem(selectedItem);
117
-            combos.put(item, new JComboBox<>(comboModel));
118
-        }
119
-        return combos.get(item);
120
-    }
121
-
122
-    @Override
123
-    public void dialogClosed(final boolean save) {
124
-        if (save) {
125
-            for (Entry<ServerGroupItem, JComboBox<ConfigProvider>> entry : combos.entrySet()) {
126
-                if (entry.getKey() != null) {
127
-                    if (entry.getValue().getSelectedItem() == null) {
128
-                        entry.getKey().setProfile(null);
129
-                    } else {
130
-                        entry.getKey().setProfile(((ConfigProvider) entry.getValue().
131
-                                getSelectedItem()).getName());
132
-                    }
133
-                }
134
-            }
135
-        }
136
-    }
137
-
138
-    @Override
139
-    public void serverGroupAdded(final ServerGroupItem parent,
140
-            final ServerGroupItem group) {
141
-        //Ignore
142
-    }
143
-
144
-    @Override
145
-    public void serverGroupRemoved(final ServerGroupItem parent,
146
-            final ServerGroupItem group) {
147
-        //Ignore
148
-    }
149
-
150
-}

+ 0
- 71
serverlistdialog/src/com/dmdirc/addons/serverlistdialog/ServerGroupTreeRenderer.java View File

@@ -1,71 +0,0 @@
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.serverlistdialog;
24
-
25
-import com.dmdirc.addons.serverlists.ServerGroupItem;
26
-
27
-import java.awt.Color;
28
-import java.awt.Component;
29
-
30
-import javax.swing.JLabel;
31
-import javax.swing.JTree;
32
-import javax.swing.tree.DefaultMutableTreeNode;
33
-import javax.swing.tree.DefaultTreeCellRenderer;
34
-
35
-/**
36
- * Renders a server group item in a tree.
37
- */
38
-public class ServerGroupTreeRenderer extends DefaultTreeCellRenderer {
39
-
40
-    /** A version number for this class. */
41
-    private static final long serialVersionUID = 1;
42
-
43
-    @Override
44
-    public Component getTreeCellRendererComponent(final JTree tree,
45
-            final Object value, final boolean sel, final boolean expanded,
46
-            final boolean leaf, final int row, final boolean hasFocus) {
47
-        final JLabel label = (JLabel) super.getTreeCellRendererComponent(tree,
48
-                value, sel, expanded, leaf, row, hasFocus);
49
-        label.setIcon(null);
50
-        label.setOpaque(false);
51
-        if (((DefaultMutableTreeNode) value).getUserObject() instanceof ServerGroupItem) {
52
-            setText(((ServerGroupItem) ((DefaultMutableTreeNode) value).
53
-                    getUserObject()).getName());
54
-        } else {
55
-            setText(((DefaultMutableTreeNode) value).getUserObject()
56
-                    .toString());
57
-        }
58
-        return label;
59
-    }
60
-
61
-    @Override
62
-    public Color getBackgroundNonSelectionColor() {
63
-        return null;
64
-    }
65
-
66
-    @Override
67
-    public Color getBackground() {
68
-        return null;
69
-    }
70
-
71
-}

+ 0
- 79
serverlistdialog/src/com/dmdirc/addons/serverlistdialog/ServerListController.java View File

@@ -1,79 +0,0 @@
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.serverlistdialog;
24
-
25
-import com.dmdirc.addons.ui_swing.components.menubar.MenuBar;
26
-
27
-import java.awt.event.ActionEvent;
28
-import java.awt.event.ActionListener;
29
-
30
-import javax.inject.Inject;
31
-import javax.inject.Provider;
32
-import javax.swing.JMenuItem;
33
-
34
-/**
35
- * Handles registering of the server list menu items, and creation of the server list dialog.
36
- */
37
-public class ServerListController {
38
-
39
-    private final Provider<ServerListDialog> dialogProvider;
40
-    private final MenuBar menuBar;
41
-
42
-    @Inject
43
-    public ServerListController(
44
-            final Provider<ServerListDialog> dialogProvider,
45
-            final MenuBar menuBar) {
46
-        this.dialogProvider = dialogProvider;
47
-        this.menuBar = menuBar;
48
-    }
49
-
50
-    /**
51
-     * Adds the 'Server lists' menu item to the app's main menu.
52
-     */
53
-    public void addMenu() {
54
-        final JMenuItem item = new JMenuItem("Server lists");
55
-        item.setMnemonic('l');
56
-        item.addActionListener(new MenuActionListener());
57
-        menuBar.addMenuItem("Server", item);
58
-    }
59
-
60
-    /**
61
-     * Removes the 'Server lists' menu item from the app's main menu.
62
-     */
63
-    public void removeMenu() {
64
-        menuBar.removeMenuItem("Server", "Server lists");
65
-    }
66
-
67
-    /**
68
-     * Listener that gets and displays a server list dialog when an action is performed.
69
-     */
70
-    private class MenuActionListener implements ActionListener {
71
-
72
-        @Override
73
-        public void actionPerformed(final ActionEvent e) {
74
-            dialogProvider.get().display();
75
-        }
76
-
77
-    }
78
-
79
-}

+ 0
- 216
serverlistdialog/src/com/dmdirc/addons/serverlistdialog/ServerListDialog.java View File

@@ -1,216 +0,0 @@
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.serverlistdialog;
24
-
25
-import com.dmdirc.ClientModule.GlobalConfig;
26
-import com.dmdirc.actions.wrappers.PerformWrapper;
27
-import com.dmdirc.addons.serverlists.ServerGroupItem;
28
-import com.dmdirc.addons.ui_swing.components.LockedLayer;
29
-import com.dmdirc.addons.ui_swing.dialogs.StandardDialog;
30
-import com.dmdirc.addons.ui_swing.injection.MainWindow;
31
-import com.dmdirc.interfaces.config.AggregateConfigProvider;
32
-import com.dmdirc.interfaces.config.IdentityController;
33
-import com.dmdirc.ui.IconManager;
34
-import com.dmdirc.ui.core.util.URLHandler;
35
-import com.dmdirc.ui.messages.ColourManagerFactory;
36
-
37
-import java.awt.Window;
38
-import java.awt.color.ColorSpace;
39
-import java.awt.event.ActionEvent;
40
-import java.awt.event.ActionListener;
41
-import java.awt.image.ColorConvertOp;
42
-
43
-import javax.inject.Inject;
44
-import javax.swing.JButton;
45
-
46
-import net.miginfocom.swing.MigLayout;
47
-
48
-import org.jdesktop.jxlayer.JXLayer;
49
-import org.jdesktop.jxlayer.plaf.effect.BufferedImageOpEffect;
50
-
51
-/**
52
- * Dialog to show and edit server lists.
53
- */
54
-public class ServerListDialog extends StandardDialog implements
55
-        ActionListener, ServerListListener {
56
-
57
-    /** Serial version UID. */
58
-    private static final long serialVersionUID = 2;
59
-    /** Server list model. */
60
-    private final ServerListModel model;
61
-    /** Connect button. */
62
-    private final JButton connectButton;
63
-    /** Info lock. */
64
-    private final LockedLayer<Info> infoLock;
65
-    /** Perform lock. */
66
-    private final LockedLayer<Perform> performLock;
67
-    /** Profile lock. */
68
-    private final LockedLayer<Profiles> profileLock;
69
-    /** Settings lock. */
70
-    private final LockedLayer<Settings> settingsLock;
71
-    /** Info layer. */
72
-    private final JXLayer<Info> infoLayer;
73
-    /** Perform layer. */
74
-    private final JXLayer<Perform> performLayer;
75
-    /** Profile layer. */
76
-    private final JXLayer<Profiles> profileLayer;
77
-    /** Settings layer. */
78
-    private final JXLayer<Settings> settingsLayer;
79
-    /** Help panel. */
80
-    private final Help help;
81
-
82
-    /**
83
-     * Creates a new server list dialog.
84
-     *
85
-     * @param iconManager        Icon manager to get icons
86
-     * @param globalConfig       Global config to read settings from
87
-     * @param urlHandler         The URL Handler to use to handle clicked links
88
-     * @param performWrapper     The wrapper to use for the perform tab
89
-     * @param serverListModel    The model to use for the dialog.
90
-     * @param parentWindow       The window that owns this dialog.
91
-     * @param settingsPanel      The panel to use for settings.
92
-     * @param identityController Controller to use to get profiles.
93
-     */
94
-    @Inject
95
-    public ServerListDialog(
96
-            @GlobalConfig final IconManager iconManager,
97
-            @GlobalConfig final AggregateConfigProvider globalConfig,
98
-            final URLHandler urlHandler,
99
-            final PerformWrapper performWrapper,
100
-            final ServerListModel serverListModel,
101
-            @MainWindow final Window parentWindow,
102
-            final Settings settingsPanel,
103
-            final IdentityController identityController,
104
-            final ColourManagerFactory colourManagerFactory) {
105
-        super(parentWindow, ModalityType.MODELESS);
106
-
107
-        setTitle("Server List");
108
-        model = serverListModel;
109
-        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
110
-
111
-        connectButton = new JButton("Connect");
112
-
113
-        profileLock = new LockedLayer<>(new BufferedImageOpEffect(
114
-                new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY),
115
-                        null)));
116
-        performLock = new LockedLayer<>(new BufferedImageOpEffect(
117
-                new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY),
118
-                        null)));
119
-        settingsLock = new LockedLayer<>(new BufferedImageOpEffect(
120
-                new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY),
121
-                        null)));
122
-        infoLock = new LockedLayer<>(new BufferedImageOpEffect(
123
-                new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY),
124
-                        null)));
125
-        profileLayer = new JXLayer<>(new Profiles(model, identityController), profileLock);
126
-        performLayer = new JXLayer<>(new Perform(iconManager, globalConfig, performWrapper, model,
127
-                colourManagerFactory),
128
-                performLock);
129
-        settingsLayer = new JXLayer<>(settingsPanel, settingsLock);
130
-        infoLayer = new JXLayer<>(new Info(model, urlHandler), infoLock);
131
-        help = new Help();
132
-        lockLayers();
133
-
134
-        setLayout(new MigLayout("fill, wrap 2, wmin 600, wmax 600"));
135
-
136
-        add(new Tree(iconManager, model, this),
137
-                "grow, spany 4, wmax 150, wmin 150");
138
-        add(help, "pos 160 0.5al");
139
-        add(infoLayer, "growx, pushx");
140
-        add(settingsLayer, "grow, push, gaptop unrel, gapbottom unrel");
141
-        add(performLayer, "grow, push");
142
-        add(profileLayer, "growx, pushx");
143
-        add(connectButton, "skip 1, split 3, right, gapright unrel*2, "
144
-                + "sgx button");
145
-        add(getLeftButton(), "right, sgx button");
146
-        add(getRightButton(), "right, sgx button");
147
-
148
-        addListeners();
149
-    }
150
-
151
-    /**
152
-     * Adds requires listeners to objects.
153
-     */
154
-    private void addListeners() {
155
-        model.addServerListListener(this);
156
-        connectButton.addActionListener(this);
157
-        getOkButton().addActionListener(this);
158
-        getCancelButton().addActionListener(this);
159
-    }
160
-
161
-    @Override
162
-    public void actionPerformed(final ActionEvent e) {
163
-        if (e.getSource() == getOkButton()) {
164
-            model.dialogClosed(true);
165
-            dispose();
166
-        } else if (e.getSource() == getCancelButton()) {
167
-            model.dialogClosed(false);
168
-            dispose();
169
-        } else if (e.getSource() == connectButton) {
170
-            model.getSelectedItem().connect();
171
-        }
172
-    }
173
-
174
-    /**
175
-     * Lock or unlock layers.
176
-     */
177
-    private void lockLayers() {
178
-        final boolean lock = !model.hasItems()
179
-                || model.getSelectedItem() == null;
180
-        performLock.setLocked(lock);
181
-        settingsLock.setLocked(lock);
182
-        infoLock.setLocked(lock);
183
-        profileLock.setLocked(lock);
184
-        connectButton.setEnabled(!lock);
185
-        performLayer.setVisible(!lock);
186
-        settingsLayer.setVisible(!lock);
187
-        infoLayer.setVisible(!lock);
188
-        profileLayer.setVisible(!lock);
189
-        help.setVisible(lock);
190
-    }
191
-
192
-    @Override
193
-    public void serverGroupChanged(final ServerGroupItem item) {
194
-        lockLayers();
195
-    }
196
-
197
-    @Override
198
-    public void dialogClosed(final boolean save) {
199
-        if (save) {
200
-            model.save();
201
-        }
202
-    }
203
-
204
-    @Override
205
-    public void serverGroupAdded(final ServerGroupItem parent,
206
-            final ServerGroupItem group) {
207
-        lockLayers();
208
-    }
209
-
210
-    @Override
211
-    public void serverGroupRemoved(final ServerGroupItem parent,
212
-            final ServerGroupItem group) {
213
-        lockLayers();
214
-    }
215
-
216
-}

+ 0
- 58
serverlistdialog/src/com/dmdirc/addons/serverlistdialog/ServerListDialogPlugin.java View File

@@ -1,58 +0,0 @@
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.serverlistdialog;
24
-
25
-import com.dmdirc.plugins.PluginInfo;
26
-import com.dmdirc.plugins.implementations.BasePlugin;
27
-
28
-import dagger.ObjectGraph;
29
-
30
-/**
31
- * Server list dialog plugin.
32
- */
33
-public class ServerListDialogPlugin extends BasePlugin {
34
-
35
-    /** Controller that manages the server list. */
36
-    private ServerListController controller;
37
-
38
-    @Override
39
-    public void onUnload() {
40
-        super.onUnload();
41
-
42
-        controller.removeMenu();
43
-    }
44
-
45
-    @Override
46
-    public void onLoad() {
47
-        controller.addMenu();
48
-    }
49
-
50
-    @Override
51
-    public void load(final PluginInfo pluginInfo, final ObjectGraph graph) {
52
-        super.load(pluginInfo, graph);
53
-        setObjectGraph(graph.plus(new ServerListModule()));
54
-
55
-        controller = getObjectGraph().get(ServerListController.class);
56
-    }
57
-
58
-}

+ 0
- 62
serverlistdialog/src/com/dmdirc/addons/serverlistdialog/ServerListListener.java View File

@@ -1,62 +0,0 @@
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.serverlistdialog;
24
-
25
-import com.dmdirc.addons.serverlists.ServerGroupItem;
26
-
27
-/**
28
- * Server list listener.
29
- */
30
-public interface ServerListListener {
31
-
32
-    /**
33
-     * Called to indicate the selected server group has changed.
34
-     *
35
-     * @param item Currently selected item
36
-     */
37
-    void serverGroupChanged(ServerGroupItem item);
38
-
39
-    /**
40
-     * Called to indicate the dialog has been closed.
41
-     *
42
-     * @param save Do we need to save changes
43
-     */
44
-    void dialogClosed(final boolean save);
45
-
46
-    /**
47
-     * Called to indicate a server group has been added.
48
-     *
49
-     * @param parent Parent group
50
-     * @param group  New group
51
-     */
52
-    void serverGroupAdded(ServerGroupItem parent, ServerGroupItem group);
53
-
54
-    /**
55
-     * Called to indicate a server group has been removed.
56
-     *
57
-     * @param parent Parent group
58
-     * @param group  Removed group
59
-     */
60
-    void serverGroupRemoved(ServerGroupItem parent, ServerGroupItem group);
61
-
62
-}

+ 0
- 246
serverlistdialog/src/com/dmdirc/addons/serverlistdialog/ServerListModel.java View File

@@ -1,246 +0,0 @@
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.serverlistdialog;
24
-
25
-import com.dmdirc.actions.wrappers.PerformType;
26
-import com.dmdirc.actions.wrappers.PerformWrapper.PerformDescription;
27
-import com.dmdirc.addons.serverlists.ServerEntry;
28
-import com.dmdirc.addons.serverlists.ServerGroup;
29
-import com.dmdirc.addons.serverlists.ServerGroupItem;
30
-import com.dmdirc.addons.serverlists.ServerList;
31
-import com.dmdirc.config.profiles.ProfileManager;
32
-import com.dmdirc.interfaces.ConnectionManager;
33
-import com.dmdirc.util.collections.ListenerList;
34
-
35
-import java.net.URI;
36
-import java.util.List;
37
-
38
-import javax.inject.Inject;
39
-import javax.swing.tree.DefaultMutableTreeNode;
40
-import javax.swing.tree.DefaultTreeModel;
41
-
42
-/**
43
- * Model proxying requests from the core server list model to the swing ui.
44
- */
45
-public class ServerListModel {
46
-
47
-    /** Server list. */
48
-    private final ServerList list;
49
-    /** Listener list. */
50
-    private final ListenerList listeners;
51
-    /** Active server item. */
52
-    private ServerGroupItem activeItem;
53
-    /** ServerManager that ServerEntrys use to create servers */
54
-    private final ConnectionManager connectionManager;
55
-    /** The manager to retrieve settings from. */
56
-    private final ProfileManager profileManager;
57
-
58
-    /**
59
-     * Creates a new server list model.
60
-     *
61
-     * @param connectionManager  ServerManager currently in use.
62
-     * @param profileManager     The manager to retrieve settings from.
63
-     * @param serverList         The server list to use for the top-level entries.
64
-     */
65
-    @Inject
66
-    public ServerListModel(
67
-            final ConnectionManager connectionManager,
68
-            final ProfileManager profileManager,
69
-            final ServerList serverList) {
70
-        this.connectionManager = connectionManager;
71
-        this.profileManager = profileManager;
72
-        list = serverList;
73
-        listeners = new ListenerList();
74
-    }
75
-
76
-    /**
77
-     * Returns a populated tree model for this server list model.
78
-     *
79
-     * @return Populated tree model
80
-     */
81
-    public DefaultTreeModel getTreeModel() {
82
-        return populateModel(new DefaultTreeModel(
83
-                new DefaultMutableTreeNode("All Servers")));
84
-    }
85
-
86
-    /**
87
-     * Has this model got any groups?
88
-     *
89
-     * @return true iif there are server groups
90
-     */
91
-    public boolean hasItems() {
92
-        return !list.getServerGroups().isEmpty();
93
-    }
94
-
95
-    /**
96
-     * Populates a tree model for this server list model.
97
-     *
98
-     * @param model Un-populated tree model to populate
99
-     *
100
-     * @return Populated tree model
101
-     */
102
-    public DefaultTreeModel populateModel(final DefaultTreeModel model) {
103
-        for (ServerGroup group : list.getServerGroups()) {
104
-            final DefaultMutableTreeNode child = new DefaultMutableTreeNode(
105
-                    group);
106
-            model.insertNodeInto(child, (DefaultMutableTreeNode) model
107
-                    .getRoot(), model.getChildCount(model.getRoot()));
108
-            model.nodeStructureChanged((DefaultMutableTreeNode) model
109
-                    .getRoot());
110
-            addGroups(model, child, group.getItems());
111
-        }
112
-        return model;
113
-    }
114
-
115
-    /**
116
-     * Recursively adds groups to the specified tree model.
117
-     *
118
-     * @param model  Tree model
119
-     * @param parent Parent node to populate
120
-     * @param items  Items to add to parent node
121
-     */
122
-    private void addGroups(final DefaultTreeModel model,
123
-            final DefaultMutableTreeNode parent,
124
-            final List<ServerGroupItem> items) {
125
-        for (ServerGroupItem group : items) {
126
-            final DefaultMutableTreeNode child = new DefaultMutableTreeNode(
127
-                    group);
128
-            model.insertNodeInto(child, parent, model.getChildCount(parent));
129
-            if (group instanceof ServerGroup) {
130
-                addGroups(model, child, ((ServerGroup) group).getItems());
131
-            }
132
-        }
133
-    }
134
-
135
-    /**
136
-     * Adds a server list listener to be notified of changes.
137
-     *
138
-     * @param listener Listener to add
139
-     */
140
-    public void addServerListListener(final ServerListListener listener) {
141
-        listeners.add(ServerListListener.class, listener);
142
-    }
143
-
144
-    /**
145
-     * Sets the selected item in this model.
146
-     *
147
-     * @param item Newly selected item
148
-     */
149
-    public void setSelectedItem(final ServerGroupItem item) {
150
-        activeItem = item;
151
-        for (ServerListListener listener : listeners.get(
152
-                ServerListListener.class)) {
153
-            listener.serverGroupChanged(item);
154
-        }
155
-    }
156
-
157
-    /**
158
-     * Gets the perform description for the selected item.
159
-     *
160
-     * @return Perform description for the active sever group item
161
-     */
162
-    public PerformDescription getSelectedItemPerformDescription() {
163
-        final PerformDescription perform;
164
-        if (activeItem instanceof ServerEntry) {
165
-            perform = new PerformDescription(PerformType.SERVER, activeItem
166
-                    .getName());
167
-        } else if (activeItem instanceof ServerGroup
168
-                && ((ServerGroup) activeItem).getNetwork() != null) {
169
-            perform = new PerformDescription(PerformType.NETWORK,
170
-                    ((ServerGroup) activeItem).getNetwork());
171
-        } else {
172
-            perform = null;
173
-        }
174
-        return perform;
175
-    }
176
-
177
-    /**
178
-     * Gets the currently selected item.
179
-     *
180
-     * @return Currently selected item
181
-     */
182
-    public ServerGroupItem getSelectedItem() {
183
-        return activeItem;
184
-    }
185
-
186
-    /**
187
-     * Saves the changes.
188
-     *
189
-     * @param save Do we need to save changes
190
-     */
191
-    public void dialogClosed(final boolean save) {
192
-        for (ServerListListener listener : listeners.get(
193
-                ServerListListener.class)) {
194
-            listener.dialogClosed(save);
195
-        }
196
-    }
197
-
198
-    /**
199
-     * Adds a group to this model.
200
-     *
201
-     * @param parentGroup Parent group
202
-     * @param groupName   Group name (not null or empty)
203
-     * @param networkName Network name (may be null or empty)
204
-     */
205
-    public void addGroup(final ServerGroup parentGroup,
206
-            final String groupName, final String networkName) {
207
-        final ServerGroup sg = new ServerGroup(profileManager, groupName);
208
-        if (networkName != null && !networkName.isEmpty()) {
209
-            sg.setNetwork(networkName);
210
-        }
211
-        if (parentGroup == null) {
212
-            list.addServerGroup(sg);
213
-        } else {
214
-            parentGroup.addItem(sg);
215
-        }
216
-        for (ServerListListener listener : listeners.get(ServerListListener.class)) {
217
-            listener.serverGroupAdded(parentGroup, sg);
218
-        }
219
-    }
220
-
221
-    /**
222
-     * Adds a group to this model.
223
-     *
224
-     * @param parentGroup Parent group
225
-     * @param entryName   name (not null or empty)
226
-     * @param url         Valid URI
227
-     */
228
-    public void addEntry(final ServerGroup parentGroup, final String entryName,
229
-            final URI url) {
230
-        final ServerGroupItem sg = new ServerEntry(profileManager, connectionManager,
231
-                parentGroup, entryName, url, null);
232
-        parentGroup.addItem(sg);
233
-        for (ServerListListener listener : listeners.get(
234
-                ServerListListener.class)) {
235
-            listener.serverGroupAdded(parentGroup, sg);
236
-        }
237
-    }
238
-
239
-    /**
240
-     * Forces the server list to save all changes.
241
-     */
242
-    public void save() {
243
-        list.save();
244
-    }
245
-
246
-}

+ 0
- 34
serverlistdialog/src/com/dmdirc/addons/serverlistdialog/ServerListModule.java View File

@@ -1,34 +0,0 @@
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.serverlistdialog;
24
-
25
-import com.dmdirc.addons.ui_swing.injection.SwingModule;
26
-
27
-import dagger.Module;
28
-
29
-/**
30
- * DI module for the server list plugin.
31
- */
32
-@Module(injects = {ServerListController.class}, addsTo = SwingModule.class)
33
-public class ServerListModule {
34
-}

+ 0
- 177
serverlistdialog/src/com/dmdirc/addons/serverlistdialog/Settings.java View File

@@ -1,177 +0,0 @@
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.serverlistdialog;
24
-
25
-import com.dmdirc.ClientModule.GlobalConfig;
26
-import com.dmdirc.addons.serverlists.ServerGroup;
27
-import com.dmdirc.addons.serverlists.ServerGroupItem;
28
-import com.dmdirc.addons.ui_swing.PrefsComponentFactory;
29
-import com.dmdirc.addons.ui_swing.components.expandingsettings.SettingsPanel;
30
-import com.dmdirc.config.prefs.PreferencesManager;
31
-import com.dmdirc.interfaces.config.AggregateConfigProvider;
32
-import com.dmdirc.interfaces.config.ConfigProvider;
33
-import com.dmdirc.interfaces.config.IdentityFactory;
34
-import com.dmdirc.ui.IconManager;
35
-
36
-import java.util.HashMap;
37
-import java.util.Map;
38
-import java.util.Map.Entry;
39
-
40
-import javax.inject.Inject;
41
-import javax.swing.BorderFactory;
42
-import javax.swing.JPanel;
43
-import javax.swing.UIManager;
44
-import javax.swing.border.Border;
45
-
46
-import net.miginfocom.swing.MigLayout;
47
-
48
-/**
49
- * Panel for listing and adding settings to the group item.
50
- */
51
-public class Settings extends JPanel implements ServerListListener {
52
-
53
-    /** Serial version UID. */
54
-    private static final long serialVersionUID = 2;
55
-    /** Server list model. */
56
-    private final ServerListModel model;
57
-    /** Settings panel. */
58
-    private final Map<ServerGroupItem, SettingsPanel> panels = new HashMap<>();
59
-    /** Platform border. */
60
-    private final Border border;
61
-    /** Manager to use to retrieve icons. */
62
-    private final IconManager iconManager;
63
-    /** Factory to use to produce preference components. */
64
-    private final PrefsComponentFactory componentFactory;
65
-    /** Factory to use to produce identities. */
66
-    private final IdentityFactory identityFactory;
67
-    /** Preferences Manager to retrieve settings from. */
68
-    private final PreferencesManager preferencesManager;
69
-
70
-    /**
71
-     * Instantiates a new settings panel.
72
-     *
73
-     * @param model              Backing model
74
-     * @param iconManager        Manager to use to retrieve icons.
75
-     * @param componentFactory   Factory to use to produce preference components.
76
-     * @param identityFactory    Factory to use to produce identities.
77
-     * @param preferencesManager Preferences Manager to retrieve settings from.
78
-     */
79
-    @Inject
80
-    public Settings(
81
-            final ServerListModel model,
82
-            @GlobalConfig final IconManager iconManager,
83
-            final PrefsComponentFactory componentFactory,
84
-            final IdentityFactory identityFactory,
85
-            final PreferencesManager preferencesManager) {
86
-        this.model = model;
87
-        this.iconManager = iconManager;
88
-        this.componentFactory = componentFactory;
89
-        this.identityFactory = identityFactory;
90
-        this.preferencesManager = preferencesManager;
91
-        addListeners();
92
-        border = UIManager.getBorder("TitledBorder.border");
93
-        setBorder(BorderFactory.createTitledBorder(border, "Network Settings"));
94
-        setLayout(new MigLayout("fill, ins 0"));
95
-        add(getSettingsPanel(model.getSelectedItem()), "grow, push");
96
-    }
97
-
98
-    /**
99
-     * Adds required listeners.
100
-     */
101
-    private void addListeners() {
102
-        model.addServerListListener(this);
103
-    }
104
-
105
-    @Override
106
-    public void serverGroupChanged(final ServerGroupItem item) {
107
-        setVisible(false);
108
-        removeAll();
109
-        if (item != null) {
110
-            if (item.getGroup() == item) {
111
-                setBorder(BorderFactory.createTitledBorder(border,
112
-                        "Network settings"));
113
-            } else {
114
-                setBorder(BorderFactory.createTitledBorder(border,
115
-                        "Server settings"));
116
-            }
117
-        }
118
-        add(getSettingsPanel(item), "grow, push");
119
-        setVisible(true);
120
-    }
121
-
122
-    /**
123
-     * Gets a settings panel for the specified group item, creating it if required.
124
-     *
125
-     * @param item Group item panel
126
-     *
127
-     * @return Settings panel for group item
128
-     */
129
-    private SettingsPanel getSettingsPanel(final ServerGroupItem item) {
130
-        if (!panels.containsKey(item)) {
131
-            if (item instanceof ServerGroup) {
132
-                panels.put(item, new SettingsPanel(iconManager, componentFactory, "", false));
133
-                addSettings(panels.get(item),
134
-                        identityFactory.createAggregateConfig("irc", "", item.getGroup().
135
-                                getNetwork(), item.getName()),
136
-                        identityFactory.createServerConfig(item.getName()));
137
-            } else {
138
-                panels.put(item, new SettingsPanel(iconManager, componentFactory, "", false));
139
-            }
140
-        }
141
-        return panels.get(item);
142
-    }
143
-
144
-    @Override
145
-    public void dialogClosed(final boolean save) {
146
-        if (save) {
147
-            for (Entry<ServerGroupItem, SettingsPanel> entry : panels.entrySet()) {
148
-                entry.getValue().save();
149
-            }
150
-        }
151
-    }
152
-
153
-    @Override
154
-    public void serverGroupAdded(final ServerGroupItem parent,
155
-            final ServerGroupItem group) {
156
-        //Ignore
157
-    }
158
-
159
-    @Override
160
-    public void serverGroupRemoved(final ServerGroupItem parent,
161
-            final ServerGroupItem group) {
162
-        //Ignore
163
-    }
164
-
165
-    /**
166
-     * Adds the settings to the panel.
167
-     *
168
-     * @param settingsPanel Settings panel to add settings to
169
-     * @param manager       The config manager to read current settings from.
170
-     * @param identity      The provider to write settings to.
171
-     */
172
-    private void addSettings(final SettingsPanel settingsPanel,
173
-            final AggregateConfigProvider manager, final ConfigProvider identity) {
174
-        settingsPanel.addOption(preferencesManager.getServerSettings(manager, identity));
175
-    }
176
-
177
-}

+ 0
- 209
serverlistdialog/src/com/dmdirc/addons/serverlistdialog/Tree.java View File

@@ -1,209 +0,0 @@
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.serverlistdialog;
24
-
25
-import com.dmdirc.addons.serverlists.ServerGroupItem;
26
-import com.dmdirc.addons.ui_swing.components.TreeScroller;
27
-import com.dmdirc.ui.IconManager;
28
-
29
-import java.awt.Rectangle;
30
-import java.awt.Window;
31
-import java.awt.event.ActionEvent;
32
-import java.awt.event.ActionListener;
33
-import java.util.Enumeration;
34
-
35
-import javax.swing.JButton;
36
-import javax.swing.JComponent;
37
-import javax.swing.JPanel;
38
-import javax.swing.JScrollPane;
39
-import javax.swing.JTree;
40
-import javax.swing.event.TreeSelectionEvent;
41
-import javax.swing.event.TreeSelectionListener;
42
-import javax.swing.tree.DefaultMutableTreeNode;
43
-import javax.swing.tree.DefaultTreeModel;
44
-import javax.swing.tree.TreeSelectionModel;
45
-
46
-import net.miginfocom.swing.MigLayout;
47
-
48
-/**
49
- * Tree of server groups and items.
50
- */
51
-public class Tree extends JPanel implements TreeSelectionListener,
52
-        ServerListListener, ActionListener {
53
-
54
-    /** Serial version UID. */
55
-    private static final long serialVersionUID = 2;
56
-    /** Tree. */
57
-    private final JTree items;
58
-    /** Tree model. */
59
-    private final DefaultTreeModel treeModel;
60
-    /** Server list model. */
61
-    private final ServerListModel model;
62
-    /** Add group. */
63
-    private final JButton addGroupButton;
64
-    /** Add Item. */
65
-    private final JButton addItemButton;
66
-    /** Parent window. */
67
-    private final Window parentWindow;
68
-    /** Icon Manager. */
69
-    private final IconManager iconManager;
70
-
71
-    /**
72
-     * Instantiates a new tree of server groups.
73
-     *
74
-     * @param iconManager  Icon Manager
75
-     * @param model        Model backing this tree
76
-     * @param parentWindow Dialog's parent window
77
-     */
78
-    public Tree(final IconManager iconManager, final ServerListModel model,
79
-            final Window parentWindow) {
80
-
81
-        this.iconManager = iconManager;
82
-        this.model = model;
83
-        this.parentWindow = parentWindow;
84
-        addGroupButton = new JButton("Add group");
85
-        addItemButton = new JButton("Add item");
86
-        model.addServerListListener(this);
87
-        treeModel = model.getTreeModel();
88
-        items = new JTree(treeModel) {
89
-            /** Serial version UID. */
90
-            private static final long serialVersionUID = 2;
91
-
92
-            @Override
93
-            public void scrollRectToVisible(final Rectangle aRect) {
94
-                final Rectangle rect = new Rectangle(0, aRect.y,
95
-                        aRect.width, aRect.height);
96
-                super.scrollRectToVisible(rect);
97
-            }
98
-        };
99
-
100
-        items.putClientProperty("JTree.lineStyle", "Angled");
101
-        items.getInputMap().setParent(null);
102
-        items.getInputMap(JComponent.WHEN_FOCUSED).clear();
103
-        items.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
104
-                .clear();
105
-        items.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).clear();
106
-        items.getSelectionModel().setSelectionMode(
107
-                TreeSelectionModel.SINGLE_TREE_SELECTION);
108
-        items.setRootVisible(true);
109
-        items.setShowsRootHandles(true);
110
-        items.setOpaque(true);
111
-        items.setFocusable(false);
112
-        new TreeScroller(items);
113
-        items.setCellRenderer(new ServerGroupTreeRenderer());
114
-        items.scrollRectToVisible(new Rectangle(0, 0, 0, 0));
115
-        items.setSelectionRow(0);
116
-        valueChanged(null);
117
-        addListeners();
118
-
119
-        setLayout(new MigLayout("fill, ins 0, wrap 1"));
120
-
121
-        add(new JScrollPane(items), "grow, push");
122
-        add(addGroupButton, "growx, pushx");
123
-        add(addItemButton, "growx, pushx");
124
-    }
125
-
126
-    /**
127
-     * Adds required listeners.
128
-     */
129
-    private void addListeners() {
130
-        items.addTreeSelectionListener(this);
131
-        addGroupButton.addActionListener(this);
132
-        addItemButton.addActionListener(this);
133
-    }
134
-
135
-    @Override
136
-    public final void valueChanged(final TreeSelectionEvent e) {
137
-        if (items.getSelectionPath() == null) {
138
-            addItemButton.setEnabled(false);
139
-            return;
140
-        }
141
-        final DefaultMutableTreeNode itemNode = (DefaultMutableTreeNode) items.
142
-                getSelectionPath().getLastPathComponent();
143
-        if (itemNode.getUserObject() instanceof ServerGroupItem) {
144
-            addItemButton.setEnabled(true);
145
-            model.setSelectedItem((ServerGroupItem) itemNode.getUserObject());
146
-        } else {
147
-            addItemButton.setEnabled(false);
148
-            model.setSelectedItem(null);
149
-        }
150
-    }
151
-
152
-    @Override
153
-    public void serverGroupChanged(final ServerGroupItem item) {
154
-        //Ignore
155
-    }
156
-
157
-    @Override
158
-    public void dialogClosed(final boolean save) {
159
-        //Ignore
160
-    }
161
-
162
-    @Override
163
-    public void serverGroupAdded(final ServerGroupItem parent,
164
-            final ServerGroupItem group) {
165
-        final DefaultMutableTreeNode parentNode = getNodeForGroup(parent);
166
-        treeModel.insertNodeInto(new DefaultMutableTreeNode(group), parentNode,
167
-                parentNode.getChildCount());
168
-    }
169
-
170
-    @Override
171
-    public void serverGroupRemoved(final ServerGroupItem parent,
172
-            final ServerGroupItem group) {
173
-        //TODO when I let people remove groups...
174
-    }
175
-
176
-    @Override
177
-    public void actionPerformed(final ActionEvent e) {
178
-        if (e.getSource() == addGroupButton) {
179
-            new AddGroupInputDialog(iconManager, parentWindow, items, model).display();
180
-        } else {
181
-            new AddEntryInputDialog(iconManager, parentWindow, items, model).display();
182
-        }
183
-    }
184
-
185
-    /**
186
-     * Find the node for a specified server group item, will return root node if the group isn't
187
-     * found.
188
-     *
189
-     * @param item Item to search for in the tree
190
-     *
191
-     * @return Node for group, or null if not found
192
-     */
193
-    private DefaultMutableTreeNode getNodeForGroup(final ServerGroupItem item) {
194
-        DefaultMutableTreeNode node = (DefaultMutableTreeNode) items.getModel()
195
-                .getRoot();
196
-        final Enumeration<?> enumeration = ((DefaultMutableTreeNode) items
197
-                .getModel().getRoot()).breadthFirstEnumeration();
198
-        while (enumeration.hasMoreElements()) {
199
-            final DefaultMutableTreeNode current = (DefaultMutableTreeNode) enumeration.
200
-                    nextElement();
201
-            if (item == current.getUserObject()) {
202
-                node = current;
203
-                break;
204
-            }
205
-        }
206
-        return node;
207
-    }
208
-
209
-}

+ 0
- 53
serverlistdialog/src/com/dmdirc/addons/serverlistdialog/URIJTextField.java View File

@@ -1,53 +0,0 @@
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.serverlistdialog;
24
-
25
-import com.dmdirc.addons.ui_swing.components.validating.ValidatingJTextField;
26
-import com.dmdirc.ui.IconManager;
27
-import com.dmdirc.util.validators.Validator;
28
-
29
-/**
30
- * Simple extention of JTextField to return an URI usable string (defaulting to an irc scheme if
31
- * none specified).
32
- */
33
-public class URIJTextField extends ValidatingJTextField {
34
-
35
-    /** A version number for this class. */
36
-    private static final long serialVersionUID = 1;
37
-
38
-    public URIJTextField(final IconManager iconManager, final String text,
39
-            final Validator<String> validator) {
40
-        super(iconManager, text, validator);
41
-    }
42
-
43
-    @Override
44
-    public String getText() {
45
-        final String hostname = super.getText();
46
-        if (!hostname.contains("://")) {
47
-            return "irc://" + hostname;
48
-        } else {
49
-            return hostname;
50
-        }
51
-    }
52
-
53
-}

+ 0
- 29
serverlists/plugin.config View File

@@ -1,29 +0,0 @@
1
-# This is a DMDirc configuration file.
2
-
3
-# This section indicates which sections below take key/value
4
-# pairs, rather than a simple list. It should be placed above
5
-# any sections that take key/values.
6
-keysections:
7
-  metadata
8
-  updates
9
-  version
10
-  requires
11
-
12
-metadata:
13
-  author=Chris <chris@dmdirc.com>
14
-  mainclass=com.dmdirc.addons.serverlists.ServerListPlugin
15
-  description=Support for server lists
16
-  name=serverlists
17
-  nicename=Server List Support
18
-
19
-updates:
20
-  id=59
21
-
22
-version:
23
-  friendly=0.6
24
-
25
-provides:
26
-  serverlist feature
27
-
28
-persistent:
29
-  *

+ 0
- 108
serverlists/src/com/dmdirc/addons/serverlists/ServerEntry.java View File

@@ -1,108 +0,0 @@
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.serverlists;
24
-
25
-import com.dmdirc.config.profiles.ProfileManager;
26
-import com.dmdirc.interfaces.ConnectionManager;
27
-
28
-import java.net.URI;
29
-
30
-/**
31
- * Describes an entry for a server within a {@link ServerGroup}.
32
- *
33
- * @since 0.6.4
34
- */
35
-public class ServerEntry extends ServerGroupItemBase {
36
-
37
-    /** The address of the server in question. */
38
-    private URI address;
39
-    /** The group that owns this entry. */
40
-    private final ServerGroup group;
41
-    /** The manager to use to create new servers. */
42
-    private final ConnectionManager connectionManager;
43
-
44
-    /**
45
-     * Creates a new server entry.
46
-     *
47
-     * @param profileManager     The manager to retrieve profiles from.
48
-     * @param connectionManager  The server manager to connect to servers with.
49
-     * @param group              The group that owns this entry
50
-     * @param name               The name of this server
51
-     * @param address            The address of this server
52
-     * @param profile            The name of the profile to be used by this server
53
-     */
54
-    public ServerEntry(
55
-            final ProfileManager profileManager,
56
-            final ConnectionManager connectionManager,
57
-            final ServerGroup group, final String name,
58
-            final URI address, final String profile) {
59
-        super(profileManager);
60
-
61
-        this.connectionManager = connectionManager;
62
-        setName(name);
63
-        setProfile(profile);
64
-        this.address = address;
65
-        this.group = group;
66
-    }
67
-
68
-    @Override
69
-    public ServerGroup getGroup() {
70
-        return group;
71
-    }
72
-
73
-    @Override
74
-    protected ServerGroup getParent() {
75
-        return getGroup();
76
-    }
77
-
78
-    /**
79
-     * Retrieves the address used by this server.
80
-     *
81
-     * @return This server's address
82
-     */
83
-    @Override
84
-    public URI getAddress() {
85
-        return address;
86
-    }
87
-
88
-    /**
89
-     * Sets the address for this server entry.
90
-     *
91
-     * @param address The new address for this entry
92
-     */
93
-    public void setAddress(final URI address) {
94
-        setModified(true);
95
-        this.address = address;
96
-    }
97
-
98
-    @Override
99
-    public void connect() {
100
-        connectionManager.connectToAddress(address, getProfileIdentity());
101
-    }
102
-
103
-    @Override
104
-    public String toString() {
105
-        return "[" + getName() + ": address: " + getAddress() + "]";
106
-    }
107
-
108
-}

+ 0
- 220
serverlists/src/com/dmdirc/addons/serverlists/ServerGroup.java View File

@@ -1,220 +0,0 @@
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.serverlists;
24
-
25
-import com.dmdirc.config.profiles.ProfileManager;
26
-
27
-import java.net.URI;
28
-import java.util.ArrayList;
29
-import java.util.Collections;
30
-import java.util.HashMap;
31
-import java.util.List;
32
-import java.util.Map;
33
-
34
-/**
35
- * A server group contains an ordered collection of server entries or other server groups.
36
- *
37
- * @since 0.6.4
38
- */
39
-public class ServerGroup extends ServerGroupItemBase {
40
-
41
-    /** The name of the network for the group. */
42
-    private String network;
43
-    /** A description of this group. */
44
-    private String description = "";
45
-    /** This group's parent. */
46
-    private final ServerGroup parent;
47
-    /** A set of links relevant to this group (e.g. homepages). */
48
-    private final Map<String, URI> links = new HashMap<>();
49
-    /** The items contained within the group. */
50
-    private final List<ServerGroupItem> entries = new ArrayList<>();
51
-
52
-    /**
53
-     * Creates a new server group with the specified name and no parent.
54
-     *
55
-     * @param profileManager The manager to retrieve profiles from.
56
-     * @param name           The name to be used for this group
57
-     */
58
-    public ServerGroup(final ProfileManager profileManager, final String name) {
59
-        this(profileManager, null, name);
60
-    }
61
-
62
-    /**
63
-     * Creates a new server group with the specified name.
64
-     *
65
-     * @param profileManager     The manager to retrieve settings from
66
-     * @param parent             The parent of this group, or <code>null</code> for roots.
67
-     * @param name               The name to be used for this group
68
-     */
69
-    public ServerGroup(
70
-            final ProfileManager profileManager,
71
-            final ServerGroup parent,
72
-            final String name) {
73
-        super(profileManager);
74
-
75
-        this.parent = parent;
76
-        setName(name);
77
-    }
78
-
79
-    @Override
80
-    public ServerGroup getGroup() {
81
-        return this;
82
-    }
83
-
84
-    @Override
85
-    protected ServerGroup getParent() {
86
-        return parent;
87
-    }
88
-
89
-    /**
90
-     * Sets the network name of this group.
91
-     *
92
-     * @param network The new network name for the group
93
-     */
94
-    public void setNetwork(final String network) {
95
-        setModified(true);
96
-        this.network = network;
97
-    }
98
-
99
-    /**
100
-     * Adds a new item to this server group.
101
-     *
102
-     * @param item The item to be added
103
-     */
104
-    public void addItem(final ServerGroupItem item) {
105
-        setModified(true);
106
-        item.setModified(true);
107
-        entries.add(item);
108
-    }
109
-
110
-    /**
111
-     * Retrieves a list of items belonging to this group.
112
-     *
113
-     * @return An immutable list of items contained within this group
114
-     */
115
-    public List<ServerGroupItem> getItems() {
116
-        return Collections.unmodifiableList(entries);
117
-    }
118
-
119
-    /**
120
-     * Retrieves a ServerGroupItem with the specified name, if one exists. This method ignores the
121
-     * case of item's name when comparing.
122
-     *
123
-     * @param name The name of the item to be retrieved
124
-     *
125
-     * @return A correspondingly named item, or null if none exists
126
-     */
127
-    public ServerGroupItem getItemByName(final String name) {
128
-        for (ServerGroupItem item : getItems()) {
129
-            if (item.getName().equalsIgnoreCase(name)) {
130
-                return item;
131
-            }
132
-        }
133
-
134
-        return null;
135
-    }
136
-
137
-    /**
138
-     * Retrieves the description of this group.
139
-     *
140
-     * @return This group's description
141
-     */
142
-    public String getDescription() {
143
-        return description;
144
-    }
145
-
146
-    /**
147
-     * Retrieves the network that this group represents, if any.
148
-     *
149
-     * @return This group's network name, or null if the group does not correspond to a known
150
-     *         network.
151
-     */
152
-    public String getNetwork() {
153
-        return network;
154
-    }
155
-
156
-    /**
157
-     * Sets the description of this group.
158
-     *
159
-     * @param description The new description for this group.
160
-     */
161
-    public void setDescription(final String description) {
162
-        setModified(true);
163
-        this.description = description;
164
-    }
165
-
166
-    /**
167
-     * Retrieves a map of link titles to {@link URI}s which are associated with this server group.
168
-     * Links will typically include network homepages, forums, or support channels.
169
-     *
170
-     * @return An immutable map of links
171
-     */
172
-    public Map<String, URI> getLinks() {
173
-        return Collections.unmodifiableMap(links);
174
-    }
175
-
176
-    /**
177
-     * Adds a new link with the specified title and address. If a link with the same title existed
178
-     * previously, it will be replaced.
179
-     *
180
-     * @param title   The title of the new link
181
-     * @param address The address of the link
182
-     */
183
-    public void addLink(final String title, final URI address) {
184
-        setModified(true);
185
-        links.put(title, address);
186
-    }
187
-
188
-    /**
189
-     * {@inheritDoc}
190
-     *
191
-     * Current implementation just selects the first item in this group and asks for its URI.
192
-     */
193
-    @Override
194
-    public URI getAddress() {
195
-        if (!entries.isEmpty()) {
196
-            return entries.get(0).getAddress();
197
-        }
198
-
199
-        return null;
200
-    }
201
-
202
-    /**
203
-     * {@inheritDoc}
204
-     *
205
-     * Current implementation just selects the first item in this group and asks it to connect.
206
-     */
207
-    @Override
208
-    public void connect() {
209
-        if (!entries.isEmpty()) {
210
-            entries.get(0).connect();
211
-        }
212
-    }
213
-
214
-    @Override
215
-    public String toString() {
216
-        return "[" + getName() + ": links: " + getLinks() + "; desc: "
217
-                + getDescription() + "; content: " + getItems() + "]";
218
-    }
219
-
220
-}

+ 0
- 107
serverlists/src/com/dmdirc/addons/serverlists/ServerGroupItem.java View File

@@ -1,107 +0,0 @@
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.serverlists;
24
-
25
-import java.net.URI;
26
-
27
-/**
28
- * An item which is included in a server group.
29
- *
30
- * @since 0.6.4
31
- */
32
-public interface ServerGroupItem {
33
-
34
-    /**
35
-     * Retrieves a group that is either the same as this item, or contains this item.
36
-     *
37
-     * @return A group containing or equal to this item
38
-     */
39
-    ServerGroup getGroup();
40
-
41
-    /**
42
-     * Retrieves the name of this item.
43
-     *
44
-     * @return A string containing this item's name
45
-     */
46
-    String getName();
47
-
48
-    /**
49
-     * Sets the name of this group.
50
-     *
51
-     * @param name The new name for the group
52
-     */
53
-    void setName(final String name);
54
-
55
-    /**
56
-     * Retrieves the path and name of this item in textual format.
57
-     *
58
-     * @return A string containing the items path and name
59
-     */
60
-    String getPath();
61
-
62
-    /**
63
-     * Initiates a connection attempt for this item.
64
-     */
65
-    void connect();
66
-
67
-    /**
68
-     * Retrieves a URI for this item.
69
-     *
70
-     * @return A URI that represents this item or one of its children, or null if the item has no
71
-     *         URIs associated with it.
72
-     */
73
-    URI getAddress();
74
-
75
-    /**
76
-     * Determines whether this item has been modified since the last time
77
-     * {@link #setModified(boolean)} was called with a <code>false</code> argument (or since this
78
-     * item was created).
79
-     *
80
-     * @return True if the item has been modified, false otherwise
81
-     */
82
-    boolean isModified();
83
-
84
-    /**
85
-     * Sets the modified status of this item.
86
-     *
87
-     * @param isModified The new status of the 'modified' property of this item
88
-     */
89
-    void setModified(final boolean isModified);
90
-
91
-    /**
92
-     * Retrieves the name of the profile which should be used when connecting to this item.
93
-     *
94
-     * @return The profile name used by this entry, or <code>null</code> if the default or parent
95
-     *         group's profile should be used
96
-     */
97
-    String getProfile();
98
-
99
-    /**
100
-     * Sets the profile to be used for this server entry.
101
-     *
102
-     * @param profile The new profile name for this entry, or <code>null</code> if the default or
103
-     *                parent group's profile should be used
104
-     */
105
-    void setProfile(final String profile);
106
-
107
-}

+ 0
- 119
serverlists/src/com/dmdirc/addons/serverlists/ServerGroupItemBase.java View File

@@ -1,119 +0,0 @@
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.serverlists;
24
-
25
-import com.dmdirc.config.profiles.Profile;
26
-import com.dmdirc.config.profiles.ProfileManager;
27
-import com.dmdirc.interfaces.config.ConfigProvider;
28
-
29
-import com.google.common.collect.Iterables;
30
-
31
-/**
32
- * Abstract base class for {@link ServerGroupItem}s.
33
- *
34
- * @since 0.6.4
35
- */
36
-public abstract class ServerGroupItemBase implements ServerGroupItem {
37
-
38
-    /** Manager to get profiles from */
39
-    private final ProfileManager profileManager;
40
-    /** Whether or not this item has been modified. */
41
-    private boolean modified;
42
-    /** The name of the item. */
43
-    private String name;
44
-    /** The name of the profile to use. */
45
-    private String profile;
46
-
47
-    public ServerGroupItemBase(final ProfileManager profileManager) {
48
-        this.profileManager = profileManager;
49
-    }
50
-
51
-    @Override
52
-    public boolean isModified() {
53
-        return modified;
54
-    }
55
-
56
-    @Override
57
-    public void setModified(final boolean isModified) {
58
-        this.modified = isModified;
59
-    }
60
-
61
-    @Override
62
-    public String getName() {
63
-        return name;
64
-    }
65
-
66
-    @Override
67
-    public void setName(final String name) {
68
-        setModified(true);
69
-        this.name = name;
70
-    }
71
-
72
-    @Override
73
-    public String getPath() {
74
-        if (getParent() != null) {
75
-            return getParent().getPath() + " → " + getName();
76
-        }
77
-        return getName();
78
-    }
79
-
80
-    @Override
81
-    public String getProfile() {
82
-        return profile;
83
-    }
84
-
85
-    @Override
86
-    public void setProfile(final String profile) {
87
-        setModified(true);
88
-        this.profile = profile;
89
-    }
90
-
91
-    /**
92
-     * Returns the parent group of this item, or <code>null</code> if the item is a root group.
93
-     *
94
-     * @return This item's parent group
95
-     */
96
-    protected abstract ServerGroup getParent();
97
-
98
-    /**
99
-     * Returns the {@link ConfigProvider} which corresponds to this server's desired profile.
100
-     *
101
-     * @return This server's profile identity
102
-     */
103
-    protected Profile getProfileIdentity() {
104
-        if (profile != null) {
105
-            for (Profile identity : profileManager.getProfiles()) {
106
-                if (profile.equals(identity.getName())) {
107
-                    return identity;
108
-                }
109
-            }
110
-        }
111
-
112
-        if (getParent() == null) {
113
-            return profileManager.getDefault();
114
-        } else {
115
-            return getParent().getProfileIdentity();
116
-        }
117
-    }
118
-
119
-}

+ 0
- 182
serverlists/src/com/dmdirc/addons/serverlists/ServerList.java View File

@@ -1,182 +0,0 @@
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.serverlists;
24
-
25
-import com.dmdirc.DMDircMBassador;
26
-import com.dmdirc.Precondition;
27
-import com.dmdirc.addons.serverlists.io.ServerGroupReader;
28
-import com.dmdirc.addons.serverlists.io.ServerGroupWriter;
29
-import com.dmdirc.addons.serverlists.service.ServerListServiceProvider;
30
-import com.dmdirc.config.profiles.ProfileManager;
31
-import com.dmdirc.interfaces.ConnectionManager;
32
-import com.dmdirc.interfaces.config.ConfigProvider;
33
-import com.dmdirc.interfaces.config.ConfigProviderListener;
34
-import com.dmdirc.interfaces.config.IdentityController;
35
-import com.dmdirc.interfaces.config.IdentityFactory;
36
-import com.dmdirc.plugins.PluginManager;
37
-
38
-import java.util.Collection;
39
-import java.util.Collections;
40
-import java.util.HashMap;
41
-import java.util.Map;
42
-
43
-import javax.inject.Inject;
44
-
45
-/**
46
- * Maintains a list of top level {@link ServerGroup}s and handles reading and writing of the lists
47
- * to disk.
48
- *
49
- * @since 0.6.4
50
- */
51
-public class ServerList implements ConfigProviderListener {
52
-
53
-    /** A list of all known groups. */
54
-    private final Map<ServerGroup, ServerGroupWriter> groups = new HashMap<>();
55
-    /** ServerManager that ServerEntrys use to create servers */
56
-    private final ConnectionManager connectionManager;
57
-    /** The manager to retrieve profiles from. */
58
-    private final ProfileManager profileManager;
59
-    /** The factory to create new identities with. */
60
-    private final IdentityFactory identityFactory;
61
-
62
-    /**
63
-     * Creates a new ServerList and loads groups and servers.
64
-     *
65
-     * @param pluginManager      Plugin Manager to use.
66
-     * @param connectionManager      Server Manager to use.
67
-     * @param identityController The controller to read/write settings with.
68
-     * @param profileManager     The profile manager to retrieve profiles from.
69
-     * @param identityFactory    The factory to create new identities with.
70
-     * @param eventBus           The event bus to post errors to
71
-     */
72
-    @Inject
73
-    public ServerList(
74
-            final PluginManager pluginManager,
75
-            final ConnectionManager connectionManager,
76
-            final IdentityController identityController,
77
-            final ProfileManager profileManager,
78
-            final IdentityFactory identityFactory,
79
-            final DMDircMBassador eventBus) {
80
-        this.connectionManager = connectionManager;
81
-        this.profileManager = profileManager;
82
-        this.identityFactory = identityFactory;
83
-
84
-        identityController.registerIdentityListener("servergroup", this);
85
-
86
-        for (ConfigProvider identity : identityController.getProvidersByType("servergroup")) {
87
-            configProviderAdded(identity);
88
-        }
89
-
90
-        new ServerListServiceProvider(pluginManager, this, eventBus).register();
91
-    }
92
-
93
-    /**
94
-     * Adds a server group to the master server list.
95
-     *
96
-     * @param group  The group to be added
97
-     * @param writer The writer to use to write the group to disk
98
-     */
99
-    public void addServerGroup(final ServerGroup group, final ServerGroupWriter writer) {
100
-        groups.put(group, writer);
101
-    }
102
-
103
-    /**
104
-     * Adds a server group to the master server list, and creates a new writer which will write the
105
-     * group to an identity.
106
-     *
107
-     * @param group The group to be added
108
-     */
109
-    public void addServerGroup(final ServerGroup group) {
110
-        final ServerGroupWriter writer = new ServerGroupWriter(
111
-                identityFactory.createCustomConfig(group.getName(), "servergroup"));
112
-        group.setModified(true);
113
-        addServerGroup(group, writer);
114
-    }
115
-
116
-    /**
117
-     * Saves all entries in this list.
118
-     */
119
-    public void save() {
120
-        for (Map.Entry<ServerGroup, ServerGroupWriter> pair : groups.entrySet()) {
121
-            if (pair.getKey().isModified()) {
122
-                pair.getValue().write(pair.getKey());
123
-            }
124
-        }
125
-    }
126
-
127
-    /**
128
-     * Saves the specified group.
129
-     *
130
-     * @param group The group to be saved
131
-     */
132
-    @Precondition("Specified group is a known top-level group in this list")
133
-    public void save(final ServerGroup group) {
134
-        groups.get(group).write(group);
135
-    }
136
-
137
-    /**
138
-     * Retrieves a list of all known server groups.
139
-     *
140
-     * @return An immutable list of server groups.
141
-     */
142
-    public Collection<ServerGroup> getServerGroups() {
143
-        return Collections.unmodifiableCollection(groups.keySet());
144
-    }
145
-
146
-    /**
147
-     * Retrieves a ServerGroup with the specified name, if one exists. This method ignores the case
148
-     * of group's name when comparing.
149
-     *
150
-     * @param name The name of the group to be retrieved
151
-     *
152
-     * @return A correspondingly named server group, or null if none exists
153
-     */
154
-    public ServerGroup getGroupByName(final String name) {
155
-        for (ServerGroup group : getServerGroups()) {
156
-            if (group.getName().equalsIgnoreCase(name)) {
157
-                return group;
158
-            }
159
-        }
160
-
161
-        return null;
162
-    }
163
-
164
-    @Override
165
-    public void configProviderAdded(final ConfigProvider configProvider) {
166
-        try {
167
-            final ServerGroupReader reader
168
-                    = new ServerGroupReader(connectionManager, profileManager, configProvider);
169
-            addServerGroup(reader.read(), reader.getWriter());
170
-        } catch (IllegalArgumentException ex) {
171
-            // Silently ignore
172
-            // TODO: Raise error if the identity isn't a server group being
173
-            //       currently added by addServerGroup()
174
-        }
175
-    }
176
-
177
-    @Override
178
-    public void configProviderRemoved(final ConfigProvider configProvider) {
179
-        // TODO: Remove server group
180
-    }
181
-
182
-}

+ 0
- 29
serverlists/src/com/dmdirc/addons/serverlists/ServerListPlugin.java View File

@@ -1,29 +0,0 @@
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.serverlists;
24
-
25
-import com.dmdirc.plugins.implementations.BasePlugin;
26
-
27
-/** Dummy plugin for server lists. */
28
-public class ServerListPlugin extends BasePlugin {
29
-}

+ 0
- 81
serverlists/src/com/dmdirc/addons/serverlists/io/ServerEntryReader.java View File

@@ -1,81 +0,0 @@
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.serverlists.io;
24
-
25
-import com.dmdirc.addons.serverlists.ServerEntry;
26
-import com.dmdirc.addons.serverlists.ServerGroup;
27
-import com.dmdirc.config.profiles.ProfileManager;
28
-import com.dmdirc.interfaces.ConnectionManager;
29
-import com.dmdirc.interfaces.config.ConfigProvider;
30
-
31
-import java.net.URI;
32
-import java.net.URISyntaxException;
33
-
34
-/**
35
- * Facilitates loading of a {@link com.dmdirc.addons.serverlists.ServerEntry} from a DMDirc
36
- * {@link com.dmdirc.interfaces.config.ConfigProvider}.
37
- *
38
- * @since 0.6.4
39
- */
40
-public class ServerEntryReader {
41
-
42
-    /** ServerManager that ServerEntrys use to create servers */
43
-    private final ConnectionManager connectionManager;
44
-    /** The manager to retrieve profiles from. */
45
-    private final ProfileManager profileManager;
46
-    /** The identity to read entries from. */
47
-    private final ConfigProvider identity;
48
-
49
-    public ServerEntryReader(final ConnectionManager connectionManager,
50
-            final ProfileManager profileManager, final ConfigProvider identity) {
51
-        this.connectionManager = connectionManager;
52
-        this.profileManager = profileManager;
53
-        this.identity = identity;
54
-    }
55
-
56
-    /**
57
-     * Attempts to read the details of the specified server from this reader's identity.
58
-     *
59
-     * @param group The group that owns this server
60
-     * @param name  The name of the server to be read
61
-     *
62
-     * @return A corresponding ServerEntry
63
-     *
64
-     * @throws URISyntaxException       If the server doesn't specify a valid URI
65
-     * @throws IllegalArgumentException If the server doesn't define a name or address
66
-     */
67
-    public ServerEntry read(final ServerGroup group, final String name) throws URISyntaxException,
68
-            IllegalArgumentException {
69
-        if (!identity.hasOptionString(name, "name")
70
-                || !identity.hasOptionString(name, "address")) {
71
-            throw new IllegalArgumentException("Server does not specify name or address: "
72
-                    + name);
73
-        }
74
-
75
-        final String serverName = identity.getOption(name, "name");
76
-        final URI serverURI = new URI(identity.getOption(name, "address"));
77
-
78
-        return new ServerEntry(profileManager, connectionManager, group, serverName, serverURI, null);
79
-    }
80
-
81
-}

+ 0
- 152
serverlists/src/com/dmdirc/addons/serverlists/io/ServerGroupReader.java View File

@@ -1,152 +0,0 @@
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.serverlists.io;
24
-
25
-import com.dmdirc.addons.serverlists.ServerGroup;
26
-import com.dmdirc.config.profiles.ProfileManager;
27
-import com.dmdirc.interfaces.ConnectionManager;
28
-import com.dmdirc.interfaces.config.ConfigProvider;
29
-import com.dmdirc.interfaces.config.IdentityController;
30
-
31
-import java.net.URI;
32
-import java.net.URISyntaxException;
33
-import java.util.Map;
34
-
35
-/**
36
- * Facilitates loading of a {@link ServerGroup} from a DMDirc {@link ConfigProvider}.
37
- *
38
- * @since 0.6.4
39
- */
40
-public class ServerGroupReader {
41
-
42
-    /** The config provider this reader should read from. */
43
-    private final ConfigProvider identity;
44
-    /** The reader we'll use for individual servers. */
45
-    private final ServerEntryReader entryReader;
46
-    /** The manager to retrieve profiles from. */
47
-    private final ProfileManager profileManager;
48
-
49
-    /**
50
-     * Creates a new ServerGroupReader that will read from the specified identity.
51
-     *
52
-     * @param connectionManager  The server manager to use to connect to servers.
53
-     * @param profileManager     The manager to retrieve profiles from
54
-     * @param identity           The identity describing the server group
55
-     */
56
-    public ServerGroupReader(
57
-            final ConnectionManager connectionManager,
58
-            final ProfileManager profileManager,
59
-            final ConfigProvider identity) {
60
-        this.identity = identity;
61
-        this.profileManager = profileManager;
62
-        this.entryReader = new ServerEntryReader(connectionManager, profileManager, identity);
63
-    }
64
-
65
-    /**
66
-     * Reads the default server group from this reader's identity.
67
-     *
68
-     * @see #read(ServerGroup, java.lang.String)
69
-     * @return A ServerGroup corresponding to the identity's default group
70
-     *
71
-     * @throws IllegalArgumentException If the identity doesn't define a group
72
-     */
73
-    public ServerGroup read() {
74
-        if (identity.hasOptionString("identity", "name")) {
75
-            return read(null, identity.getOption("identity", "name"));
76
-        }
77
-
78
-        throw new IllegalArgumentException("Identity has no name");
79
-    }
80
-
81
-    /**
82
-     * Reads a named server group from this reader's identity.
83
-     *
84
-     * @param parent The parent of the group being read
85
-     * @param name   The name of the server group to read
86
-     *
87
-     * @return A corresponding ServerGroup
88
-     *
89
-     * @throws IllegalArgumentException If the server group doesn't define a name
90
-     */
91
-    public ServerGroup read(final ServerGroup parent, final String name)
92
-            throws IllegalArgumentException {
93
-        if (!identity.hasOptionString(name, "name")) {
94
-            throw new IllegalArgumentException("ServerGroup '" + name + "' not defined");
95
-        }
96
-
97
-        final ServerGroup group = new ServerGroup(profileManager, parent,
98
-                identity.getOption(name, "name"));
99
-
100
-        if (identity.hasOptionString(name, "description")) {
101
-            group.setDescription(identity.getOption(name, "description"));
102
-        }
103
-
104
-        if (identity.hasOptionString(name, "links")) {
105
-            readLinks(group, identity.getOption(name, "links"));
106
-        }
107
-
108
-        for (String item : identity.getOptionList(name, "contents", true)) {
109
-            if (item.endsWith(" servergroup")) {
110
-                try {
111
-                    group.addItem(read(group, item));
112
-                } catch (IllegalArgumentException ex) {
113
-                    // TODO: Raise an error about malformed group
114
-                }
115
-            } else if (item.endsWith(" server")) {
116
-                try {
117
-                    group.addItem(entryReader.read(group, item));
118
-                } catch (URISyntaxException | IllegalArgumentException ex) {
119
-                    // TODO: Raise an error about malformed server
120
-                }
121
-            }
122
-        }
123
-
124
-        return group;
125
-    }
126
-
127
-    /**
128
-     * Reads a set of links from the named domain and adds them to the specified group.
129
-     *
130
-     * @param group  The group to add links to
131
-     * @param domain The domain in the identity containing links
132
-     */
133
-    private void readLinks(final ServerGroup group, final String domain) {
134
-        for (Map.Entry<String, String> entry : identity.getOptions(domain).entrySet()) {
135
-            try {
136
-                group.addLink(entry.getKey(), new URI(entry.getValue()));
137
-            } catch (URISyntaxException ex) {
138
-                // TODO: Raise an error about illegal URI?
139
-            }
140
-        }
141
-    }
142
-
143
-    /**
144
-     * Returns a writer which may be used to write updated data.
145
-     *
146
-     * @return An appropriately configured {@link ServerGroupWriter}
147
-     */
148
-    public ServerGroupWriter getWriter() {
149
-        return new ServerGroupWriter(identity);
150
-    }
151
-
152
-}

+ 0
- 165
serverlists/src/com/dmdirc/addons/serverlists/io/ServerGroupWriter.java View File

@@ -1,165 +0,0 @@
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.serverlists.io;
24
-
25
-import com.dmdirc.addons.serverlists.ServerEntry;
26
-import com.dmdirc.addons.serverlists.ServerGroup;
27
-import com.dmdirc.addons.serverlists.ServerGroupItem;
28
-import com.dmdirc.interfaces.config.ConfigProvider;
29
-
30
-import java.net.URI;
31
-import java.util.ArrayList;
32
-import java.util.List;
33
-import java.util.Map;
34
-import java.util.Set;
35
-
36
-/**
37
- * Provides methods to instantiate a writer for a server group or entry.
38
- *
39
- * @since 0.6.4
40
- */
41
-public class ServerGroupWriter {
42
-
43
-    /** The identity which will be written to. */
44
-    private final ConfigProvider identity;
45
-
46
-    /**
47
-     * Creates a new writer which will write to the specified identity.
48
-     *
49
-     * @param identity The identity to write the server group to
50
-     */
51
-    public ServerGroupWriter(final ConfigProvider identity) {
52
-        this.identity = identity;
53
-    }
54
-
55
-    /**
56
-     * Writes the specified server group and all of its children to this writer's identity.
57
-     *
58
-     * @param group The group to be written
59
-     */
60
-    public void write(final ServerGroup group) {
61
-        final Set<String> sections = identity.getDomains();
62
-        sections.remove("identity");
63
-
64
-        identity.setOption("identity", "name", group.getName() + " servergroup");
65
-
66
-        writeGroup(group, sections);
67
-
68
-        for (String missing : sections) {
69
-            for (String setting : identity.getOptions(missing).keySet()) {
70
-                identity.unsetOption(missing, setting);
71
-            }
72
-        }
73
-    }
74
-
75
-    /**
76
-     * Appends the specified group to this writer's identity. Any keysections that are used will be
77
-     * removed from the sections set, so callers can track which sections in the identity have not
78
-     * been used.
79
-     *
80
-     * @param group    The group to be written
81
-     * @param sections A set of sections from which any new keysections should be removed
82
-     */
83
-    protected void writeGroup(final ServerGroup group, final Set<String> sections) {
84
-        final String domain = group.getName() + " servergroup";
85
-
86
-        final List<String> children = new ArrayList<>();
87
-
88
-        for (ServerGroupItem item : group.getItems()) {
89
-            if (item instanceof ServerGroup) {
90
-                writeGroup((ServerGroup) item, sections);
91
-                children.add(item.getName() + " servergroup");
92
-            } else if (item instanceof ServerEntry) {
93
-                writeEntry((ServerEntry) item, sections);
94
-                children.add(item.getName() + " server");
95
-            }
96
-        }
97
-
98
-        final boolean needsUpdating = group.isModified();
99
-        sections.remove(domain);
100
-        group.setModified(false);
101
-
102
-        if (!needsUpdating) {
103
-            return;
104
-        }
105
-
106
-        if (!group.getLinks().isEmpty()) {
107
-            writeLinks(group.getName(), group.getLinks());
108
-            sections.remove(group + " links");
109
-        }
110
-
111
-        if (group.getNetwork() == null) {
112
-            identity.unsetOption(domain, "network");
113
-        } else {
114
-            identity.setOption(domain, "network", group.getNetwork());
115
-        }
116
-
117
-        identity.setOption(domain, "description", group.getDescription());
118
-        identity.setOption(domain, "contents", children);
119
-        identity.setOption(domain, "name", group.getName());
120
-    }
121
-
122
-    /**
123
-     * Writes a map of links for the specified entry.
124
-     *
125
-     * @param name  The name of the entry for which to write the links
126
-     * @param links The links to be written
127
-     */
128
-    protected void writeLinks(final String name, final Map<String, URI> links) {
129
-        final String domain = name + " links";
130
-        final Set<String> existing = identity.getOptions(domain).keySet();
131
-        existing.removeAll(links.keySet());
132
-
133
-        for (String deleted : existing) {
134
-            identity.unsetOption(domain, deleted);
135
-        }
136
-
137
-        for (Map.Entry<String, URI> link : links.entrySet()) {
138
-            identity.setOption(domain, link.getKey(), link.getValue().toString());
139
-        }
140
-    }
141
-
142
-    /**
143
-     * Writes the specified entry to this writer's identity. Any keysections that are used will be
144
-     * removed from the sections set, so callers can track which sections in the identity have not
145
-     * been used.
146
-     *
147
-     * @param entry    The entry to be written
148
-     * @param sections A set of sections from which any new keysections should be removed
149
-     */
150
-    protected void writeEntry(final ServerEntry entry, final Set<String> sections) {
151
-        final String domain = entry.getName() + " server";
152
-        final boolean needsUpdating = entry.isModified();
153
-
154
-        sections.remove(domain);
155
-        entry.setModified(false);
156
-
157
-        if (!needsUpdating) {
158
-            return;
159
-        }
160
-
161
-        identity.setOption(domain, "name", entry.getName());
162
-        identity.setOption(domain, "address", entry.getAddress().toString());
163
-    }
164
-
165
-}

+ 0
- 155
serverlists/src/com/dmdirc/addons/serverlists/service/ServerListServiceProvider.java View File

@@ -1,155 +0,0 @@
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.serverlists.service;
24
-
25
-import com.dmdirc.DMDircMBassador;
26
-import com.dmdirc.ParserFactory;
27
-import com.dmdirc.addons.serverlists.ServerGroup;
28
-import com.dmdirc.addons.serverlists.ServerGroupItem;
29
-import com.dmdirc.addons.serverlists.ServerList;
30
-import com.dmdirc.parser.common.MyInfo;
31
-import com.dmdirc.parser.interfaces.Parser;
32
-import com.dmdirc.plugins.ExportedService;
33
-import com.dmdirc.plugins.PluginManager;
34
-import com.dmdirc.plugins.Service;
35
-import com.dmdirc.plugins.ServiceProvider;
36
-
37
-import java.net.URI;
38
-import java.util.Arrays;
39
-import java.util.List;
40
-
41
-/**
42
- * Provides a fake parser service which handles <code>serverlist://</code> URIs, and returns a
43
- * suitable parser for the corresponding server list.
44
- *
45
- * @since 0.6.4
46
- */
47
-public class ServerListServiceProvider implements ServiceProvider {
48
-
49
-    /** The server list that we're providing for. */
50
-    private final ServerList serverList;
51
-    /** The services that this provider providers. */
52
-    private final List<Service> services;
53
-    /** Plugin Manager */
54
-    private final PluginManager pluginManager;
55
-    /** The event bus to post errors to. */
56
-    private final DMDircMBassador eventBus;
57
-
58
-    /**
59
-     * Creates a new server list service provider.
60
-     *
61
-     * @param pluginManager The PluginManager to use.
62
-     * @param serverList    The {@link ServerList} to retrieve items from
63
-     * @param eventBus      The event bus to post errors to
64
-     */
65
-    public ServerListServiceProvider(final PluginManager pluginManager, final ServerList serverList,
66
-            final DMDircMBassador eventBus) {
67
-        this.serverList = serverList;
68
-        this.pluginManager = pluginManager;
69
-        this.eventBus = eventBus;
70
-        this.services = Arrays.asList(pluginManager.getService("parser", "serverlist", true));
71
-    }
72
-
73
-    /**
74
-     * Registers this service provider.
75
-     */
76
-    public void register() {
77
-        for (Service service : services) {
78
-            service.addProvider(this);
79
-        }
80
-    }
81
-
82
-    @Override
83
-    public boolean isActive() {
84
-        return true;
85
-    }
86
-
87
-    @Override
88
-    public void activateServices() {
89
-        // Do nothing
90
-    }
91
-
92
-    @Override
93
-    public List<Service> getServices() {
94
-        return services;
95
-    }
96
-
97
-    @Override
98
-    public String getProviderName() {
99
-        return "Serverlist service provider";
100
-    }
101
-
102
-    @Override
103
-    public ExportedService getExportedService(final String name) {
104
-        if ("getParser".equals(name)) {
105
-            return new ExportedService(ServerListServiceProvider.class, "getParser", this);
106
-        } else {
107
-            return null;
108
-        }
109
-    }
110
-
111
-    /**
112
-     * Retrieves a parser for the specified details.
113
-     *
114
-     * @param myInfo  The user-supplied client identification information
115
-     * @param address The address to connect to (a serverlist:// URI)
116
-     *
117
-     * @return A corresponding Parser instance, or null if none applicable
118
-     */
119
-    public Parser getParser(final MyInfo myInfo, final URI address) {
120
-        ServerGroup group = serverList.getGroupByName(address.getHost());
121
-
122
-        if (address.getPath() != null && !address.getPath().isEmpty()) {
123
-            for (String part : address.getPath().split("/")) {
124
-                if (part.isEmpty()) {
125
-                    continue;
126
-                }
127
-
128
-                final ServerGroupItem item = group.getItemByName(part);
129
-
130
-                if (item == null) {
131
-                    return null;
132
-                } else if (item instanceof ServerGroup) {
133
-                    group = (ServerGroup) item;
134
-                } else {
135
-                    return getParserForItem(myInfo, item);
136
-                }
137
-            }
138
-        }
139
-
140
-        return getParserForItem(myInfo, group);
141
-    }
142
-
143
-    /**
144
-     * Retrieves a parser for the specified item.
145
-     *
146
-     * @param myInfo The user-supplied client identification information
147
-     * @param item   The item to retrieve a URI from
148
-     *
149
-     * @return A corresponding parser instance
150
-     */
151
-    protected Parser getParserForItem(final MyInfo myInfo, final ServerGroupItem item) {
152
-        return new ParserFactory(pluginManager, eventBus).getParser(myInfo, item.getAddress());
153
-    }
154
-
155
-}

Loading…
Cancel
Save