Pārlūkot izejas kodu

Read only server list ui

issue 1461

Change-Id: I98fb7d21ddac68ce02a2eb6ffc2e08bcbc179a5f
Reviewed-on: http://gerrit.dmdirc.com/1341
Automatic-Compile: DMDirc Local Commits <dmdirc@googlemail.com>
Reviewed-by: Chris Smith <chris@dmdirc.com>
tags/0.6.4
Greg Holmes 14 gadus atpakaļ
vecāks
revīzija
8b227e4483

+ 1
- 0
src/com/dmdirc/addons/ui_swing/components/FontPicker.java Parādīt failu

@@ -49,6 +49,7 @@ public class FontPicker extends JComboBox {
49 49
      */
50 50
     public FontPicker(final String fontFamily) {
51 51
         super(new DefaultComboBoxModel());
52
+        setPrototypeDisplayValue("test");
52 53
         this.fontFamily = fontFamily;
53 54
 
54 55
         setRenderer(new FontListCellRenderer());

+ 31
- 16
src/com/dmdirc/addons/ui_swing/components/MenuBar.java Parādīt failu

@@ -1,16 +1,16 @@
1 1
 /*
2 2
  * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
- * 
3
+ *
4 4
  * Permission is hereby granted, free of charge, to any person obtaining a copy
5 5
  * of this software and associated documentation files (the "Software"), to deal
6 6
  * in the Software without restriction, including without limitation the rights
7 7
  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 8
  * copies of the Software, and to permit persons to whom the Software is
9 9
  * furnished to do so, subject to the following conditions:
10
- * 
10
+ *
11 11
  * The above copyright notice and this permission notice shall be included in
12 12
  * all copies or substantial portions of the Software.
13
- * 
13
+ *
14 14
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 15
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 16
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -37,6 +37,7 @@ import com.dmdirc.addons.ui_swing.dialogs.actionsmanager.ActionsManagerDialog;
37 37
 import com.dmdirc.addons.ui_swing.dialogs.aliases.AliasManagerDialog;
38 38
 import com.dmdirc.addons.ui_swing.dialogs.prefs.SwingPreferencesDialog;
39 39
 import com.dmdirc.addons.ui_swing.dialogs.profiles.ProfileManagerDialog;
40
+import com.dmdirc.addons.ui_swing.dialogs.serverlist.ServerListDialog;
40 41
 import com.dmdirc.addons.ui_swing.framemanager.windowmenu.WindowMenuFrameManager;
41 42
 import com.dmdirc.parser.common.ChannelJoinRequest;
42 43
 import com.dmdirc.ui.WindowManager;
@@ -75,21 +76,22 @@ public class MenuBar extends JMenuBar implements ActionListener, MenuListener {
75 76
     /** join. */
76 77
     private JMenuItem join;
77 78
     /** Swing controller. */
78
-    private SwingController controller;
79
+    private final SwingController controller;
79 80
     /** Main frame. */
80
-    private MainFrame mainFrame;
81
+    private final MainFrame mainFrame;
81 82
 
82 83
     /**
83 84
      * Instantiates a new menu bar.
84
-     * 
85
+     *
85 86
      * @param controller Swing controller
86 87
      * @param mainFrame Main frame
87 88
      */
88
-    public MenuBar(final SwingController controller, final MainFrame mainFrame) {
89
+    public MenuBar(final SwingController controller, 
90
+            final MainFrame mainFrame) {
89 91
         super();
90 92
         this.controller = controller;
91 93
         this.mainFrame = mainFrame;
92
-        
94
+
93 95
         setLayout(new MigLayout("ins 0, fillx"));
94 96
 
95 97
         initServerMenu();
@@ -99,7 +101,8 @@ public class MenuBar extends JMenuBar implements ActionListener, MenuListener {
99 101
         initHelpMenu();
100 102
         add(Box.createHorizontalGlue(), "growx, pushx");
101 103
         add(new MDIBar(controller, mainFrame));
102
-        add(Box.createHorizontalStrut(PlatformDefaults.getPanelInsets(1).getUnit()));
104
+        add(Box.createHorizontalStrut(PlatformDefaults.getPanelInsets(1)
105
+                .getUnit()));
103 106
 
104 107
         getActionMap().setParent(null);
105 108
         getActionMap().clear();
@@ -116,6 +119,13 @@ public class MenuBar extends JMenuBar implements ActionListener, MenuListener {
116 119
         menu.addMenuListener(this);
117 120
         add(menu);
118 121
 
122
+        menuItem = new JMenuItem();
123
+        menuItem.setText("Server list dialog");
124
+        menuItem.setMnemonic('l');
125
+        menuItem.setActionCommand("ServerList");
126
+        menuItem.addActionListener(this);
127
+        menu.add(menuItem);
128
+
119 129
         menuItem = new JMenuItem();
120 130
         menuItem.setText("New Server...");
121 131
         menuItem.setMnemonic('n');
@@ -245,14 +255,16 @@ public class MenuBar extends JMenuBar implements ActionListener, MenuListener {
245 255
         }
246 256
     }
247 257
 
248
-    /** 
258
+    /**
249 259
      * {@inheritDoc}
250
-     *  
251
-     * @param e Action event    
260
+     *
261
+     * @param e Action event
252 262
      */
253 263
     @Override
254 264
     public void actionPerformed(final ActionEvent e) {
255
-        if ("NewServer".equals(e.getActionCommand())) {
265
+        if ("ServerList".equals(e.getActionCommand())) {
266
+            ServerListDialog.showServerListDialog(mainFrame);
267
+        } else if ("NewServer".equals(e.getActionCommand())) {
256 268
             NewServerDialog.showNewServerDialog(mainFrame);
257 269
         } else if ("Preferences".equals(e.getActionCommand())) {
258 270
             SwingPreferencesDialog.showSwingPreferencesDialog(mainFrame);
@@ -263,7 +275,8 @@ public class MenuBar extends JMenuBar implements ActionListener, MenuListener {
263 275
         } else if (e.getActionCommand().equals("Exit")) {
264 276
             mainFrame.quit();
265 277
         } else if (e.getActionCommand().equals("Actions")) {
266
-            ActionsManagerDialog.showActionsManagerDialog(mainFrame, controller);
278
+            ActionsManagerDialog.showActionsManagerDialog(mainFrame,
279
+                    controller);
267 280
         } else if (e.getActionCommand().equals("Aliases")) {
268 281
             AliasManagerDialog.showAliasManagerDialog(mainFrame);
269 282
         } else if (e.getActionCommand().equals("JoinDevChat")) {
@@ -271,12 +284,14 @@ public class MenuBar extends JMenuBar implements ActionListener, MenuListener {
271 284
         } else if (e.getActionCommand().equals("feedback")) {
272 285
             FeedbackDialog.showFeedbackDialog(mainFrame);
273 286
         } else if (e.getActionCommand().equals("ChannelSettings")) {
274
-            final FrameContainer<?> activeWindow = WindowManager.getActiveWindow();
287
+            final FrameContainer<?> activeWindow = WindowManager
288
+                    .getActiveWindow();
275 289
             if (activeWindow instanceof Channel) {
276 290
                 controller.showChannelSettingsDialog(((Channel) activeWindow));
277 291
             }
278 292
         } else if (e.getActionCommand().equals("ServerSettings")) {
279
-            controller.showServerSettingsDialog(WindowManager.getActiveServer());
293
+            controller.showServerSettingsDialog(WindowManager
294
+                    .getActiveServer());
280 295
         } else if (e.getActionCommand().equals("Disconnect")) {
281 296
             WindowManager.getActiveServer().disconnect();
282 297
         } else if (e.getActionCommand().equals("JoinChannel")) {

+ 2
- 2
src/com/dmdirc/addons/ui_swing/components/expandingsettings/AddOptionPanel.java Parādīt failu

@@ -97,7 +97,7 @@ public class AddOptionPanel extends JPanel implements ActionListener {
97 97
         this.setOpaque(UIUtilities.getTabbedPaneOpaque());
98 98
         initComponents();
99 99
         initListeners();
100
-        setLayout(new MigLayout("ins 0"));
100
+        setLayout(new MigLayout("ins 0, wmax 100%"));
101 101
         layoutComponents();
102 102
     }
103 103
 
@@ -116,7 +116,7 @@ public class AddOptionPanel extends JPanel implements ActionListener {
116 116
         addInputNone = new JLabel("");
117 117
         addInputFontPicker = new FontPicker("Dialog");
118 118
         addInputComboBox = new JComboBox(new DefaultComboBoxModel());
119
-
119
+        addInputComboBox.setPrototypeDisplayValue("test");
120 120
         addInputCurrent = addInputNone;
121 121
 
122 122
         addOptionComboBox.setEnabled(false);

+ 2
- 1
src/com/dmdirc/addons/ui_swing/components/expandingsettings/SettingsPanel.java Parādīt failu

@@ -107,6 +107,7 @@ public class SettingsPanel extends JPanel {
107 107
         types = new LinkedHashMap<String, OptionType>();
108 108
 
109 109
         infoLabel = new TextLabel(infoText);
110
+        infoLabel.setVisible(!infoText.isEmpty());
110 111
 
111 112
         addOptionPanel =
112 113
                 new AddOptionPanel(this);
@@ -127,7 +128,7 @@ public class SettingsPanel extends JPanel {
127 128
      * Lays out the components.
128 129
      */
129 130
     private void layoutComponents() {
130
-        setLayout(new MigLayout("fill, wrap 1"));
131
+        setLayout(new MigLayout("fill, wrap 1, hidemode 3, ins 0"));
131 132
 
132 133
         add(infoLabel, "growx, pushx");
133 134
         add(scrollPane, "grow, push");

+ 79
- 0
src/com/dmdirc/addons/ui_swing/components/renderers/ServerGroupTreeRenderer.java Parādīt failu

@@ -0,0 +1,79 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.ui_swing.components.renderers;
24
+
25
+import com.dmdirc.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
+    /**
41
+     * A version number for this class. It should be changed whenever the class
42
+     * structure is changed (or anything else that would prevent serialized
43
+     * objects being unserialized with the new class).
44
+     */
45
+    private static final long serialVersionUID = 1;
46
+
47
+    /** {@inheritDoc} */
48
+    @Override
49
+    public Component getTreeCellRendererComponent(final JTree tree,
50
+            final Object value, final boolean sel, final boolean expanded,
51
+            final boolean leaf, final int row, final boolean hasFocus) {
52
+        final JLabel label = (JLabel) super.getTreeCellRendererComponent(tree,
53
+                value, sel, expanded, leaf, row, hasFocus);
54
+        label.setIcon(null);
55
+        label.setOpaque(false);
56
+        if (((DefaultMutableTreeNode) value).getUserObject()
57
+                instanceof ServerGroupItem) {
58
+            setText(((ServerGroupItem) ((DefaultMutableTreeNode) value).
59
+                    getUserObject()).getName());
60
+        }
61
+        return label;
62
+    }
63
+
64
+    /**
65
+     * {@inheritDoc}
66
+     *
67
+     * @return Background colour for non selected nodes
68
+     */
69
+    @Override
70
+    public Color getBackgroundNonSelectionColor() {
71
+        return null;
72
+    }
73
+
74
+    /** {@inheritDoc} */
75
+    @Override
76
+    public Color getBackground() {
77
+        return null;
78
+    }
79
+}

+ 134
- 0
src/com/dmdirc/addons/ui_swing/dialogs/serverlist/Info.java Parādīt failu

@@ -0,0 +1,134 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.ui_swing.dialogs.serverlist;
24
+
25
+import com.dmdirc.addons.ui_swing.components.text.HTMLLabel;
26
+import com.dmdirc.serverlists.ServerGroupItem;
27
+import com.dmdirc.ui.core.util.URLHandler;
28
+
29
+import java.net.URI;
30
+import java.util.Map.Entry;
31
+
32
+import javax.swing.JPanel;
33
+import javax.swing.event.HyperlinkEvent;
34
+import javax.swing.event.HyperlinkEvent.EventType;
35
+import javax.swing.event.HyperlinkListener;
36
+
37
+import net.miginfocom.swing.MigLayout;
38
+
39
+/**
40
+ * Panel for showing server group item information.
41
+ */
42
+public class Info extends JPanel implements HyperlinkListener,
43
+        ServerListListener {
44
+
45
+    /**
46
+     * A version number for this class. It should be changed whenever the class
47
+     * structure is changed (or anything else that would prevent serialized
48
+     * objects being unserialized with the new class).
49
+     */
50
+    private static final long serialVersionUID = 2;
51
+    /** Info pane. */
52
+    private final HTMLLabel infoLabel;
53
+    /** Link label. */
54
+    private final HTMLLabel linkLabel;
55
+    /** Server list model. */
56
+    private final ServerListModel model;
57
+
58
+    /**
59
+     * Creates a new info panel.
60
+     *
61
+     * @param model Model to pull information from
62
+     */
63
+    public Info(final ServerListModel model) {
64
+        super();
65
+
66
+        this.model = model;
67
+
68
+        infoLabel = new HTMLLabel();
69
+        linkLabel = new HTMLLabel();
70
+
71
+        setLayout(new MigLayout("fill, ins 0"));
72
+        add(infoLabel, "grow, push");
73
+        add(linkLabel, "grow");
74
+
75
+        addListeners();
76
+        serverGroupChanged(model.getSelectedItem());
77
+    }
78
+
79
+    /**
80
+     * Adds required listeners.
81
+     */
82
+    private void addListeners() {
83
+        linkLabel.addHyperlinkListener(this);
84
+        model.addServerListListener(this);
85
+    }
86
+
87
+    /** {@inheritDoc} */
88
+    @Override
89
+    public void hyperlinkUpdate(final HyperlinkEvent e) {
90
+        if (e.getEventType() == EventType.ACTIVATED) {
91
+            URLHandler.getURLHander().launchApp(e.getURL());
92
+        }
93
+    }
94
+
95
+    /** {@inheritDoc} */
96
+    @Override
97
+    public void serverGroupChanged(final ServerGroupItem item) {
98
+        setVisible(false);
99
+        infoLabel.setVisible(false);
100
+        linkLabel.setVisible(false);
101
+        if (item == null) {
102
+            infoLabel.setText("");
103
+            linkLabel.setText("");
104
+        } else {
105
+            final StringBuilder sb = new StringBuilder();
106
+            sb.append("<html><b>");
107
+            sb.append(item.getName());
108
+            sb.append("</b><br>");
109
+            if (item.getGroup() == null) {
110
+                sb.append("");
111
+            } else {
112
+                sb.append(item.getGroup().getDescription());
113
+            }
114
+            sb.append("</html>");
115
+            infoLabel.setText(sb.toString());
116
+            sb.setLength(0);
117
+            for (Entry<String, URI> entry : item.getGroup().getLinks()
118
+                    .entrySet()) {
119
+                if (sb.length() != 0) {
120
+                    sb.append("<br>");
121
+                }
122
+                sb.append("<a href=\"");
123
+                sb.append(entry.getValue().toString());
124
+                sb.append("\">");
125
+                sb.append(entry.getKey());
126
+                sb.append("</a>");
127
+            }
128
+            linkLabel.setText(sb.toString());
129
+        }
130
+        infoLabel.setVisible(true);
131
+        linkLabel.setVisible(true);
132
+        setVisible(true);
133
+    }
134
+}

+ 108
- 0
src/com/dmdirc/addons/ui_swing/dialogs/serverlist/Perform.java Parādīt failu

@@ -0,0 +1,108 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.ui_swing.dialogs.serverlist;
24
+
25
+import com.dmdirc.actions.wrappers.PerformWrapper;
26
+import com.dmdirc.serverlists.ServerGroupItem;
27
+
28
+import java.util.HashMap;
29
+import java.util.Map;
30
+
31
+import javax.swing.BorderFactory;
32
+import javax.swing.JPanel;
33
+import javax.swing.JScrollPane;
34
+import javax.swing.JTextArea;
35
+import javax.swing.UIManager;
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
+    /**
45
+     * A version number for this class. It should be changed whenever the class
46
+     * structure is changed (or anything else that would prevent serialized
47
+     * objects being unserialized with the new class).
48
+     */
49
+    private static final long serialVersionUID = 2;
50
+    /** Perform list. */
51
+    private final Map<ServerGroupItem, JTextArea> performs =
52
+            new HashMap<ServerGroupItem, JTextArea>();
53
+    /** Perform scroll pane. */
54
+    private final JScrollPane scrollPane;
55
+    /** Server list model. */
56
+    private final ServerListModel model;
57
+
58
+    /**
59
+     * Creates a new perform panel backed by the specified model.
60
+     *
61
+     * @param model Backing model
62
+     */
63
+    public Perform(final ServerListModel model) {
64
+        super();
65
+
66
+        this.model = model;
67
+
68
+        scrollPane = new JScrollPane();
69
+        addListeners();
70
+
71
+        scrollPane.setViewportView(getPerfom(model.getSelectedItem()));
72
+        setBorder(BorderFactory.createTitledBorder(UIManager.
73
+                        getBorder("TitledBorder.border"), "Network perform"));
74
+        setLayout(new MigLayout("fill"));
75
+        add(scrollPane, "grow");
76
+    }
77
+
78
+    /**
79
+     * Adds required listeners.
80
+     */
81
+    private void addListeners() {
82
+        model.addServerListListener(this);
83
+    }
84
+
85
+    /**
86
+     * Gets (and creates if required) the perform for a specified server group
87
+     * item.
88
+     *
89
+     * @param item Server group item to get perform for
90
+     *
91
+     * @return Perform text area for specified server group item
92
+     */
93
+    private JTextArea getPerfom(final ServerGroupItem item) {
94
+        if (!performs.containsKey(item)) {
95
+            final JTextArea text = new JTextArea();
96
+            text.setRows(5);
97
+            PerformWrapper.getPerformWrapper();
98
+            performs.put(item, text);
99
+        }
100
+        return performs.get(item);
101
+    }
102
+
103
+    /** {@inheritDoc} */
104
+    @Override
105
+    public void serverGroupChanged(final ServerGroupItem item) {
106
+        scrollPane.setViewportView(getPerfom(item));
107
+    }
108
+}

+ 120
- 0
src/com/dmdirc/addons/ui_swing/dialogs/serverlist/Profiles.java Parādīt failu

@@ -0,0 +1,120 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.ui_swing.dialogs.serverlist;
24
+
25
+import com.dmdirc.addons.ui_swing.components.vetoable.VetoableComboBoxModel;
26
+import com.dmdirc.config.Identity;
27
+import com.dmdirc.config.IdentityManager;
28
+import com.dmdirc.serverlists.ServerGroupItem;
29
+
30
+import java.util.HashMap;
31
+import java.util.List;
32
+import java.util.Map;
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
+    /**
49
+     * A version number for this class. It should be changed whenever the class
50
+     * structure is changed (or anything else that would prevent serialized
51
+     * objects being unserialized with the new class).
52
+     */
53
+    private static final long serialVersionUID = 2;
54
+    /** Server list model. */
55
+    private final ServerListModel model;
56
+    /** Combo boxes. */
57
+    private final Map<ServerGroupItem, JComboBox> combos =
58
+            new HashMap<ServerGroupItem, JComboBox>();
59
+    /** Info label. */
60
+    private final JLabel label;
61
+
62
+    /**
63
+     * Creates a new profile panel backed by the specified model.
64
+     *
65
+     * @param model Backing server list model
66
+     */
67
+    public Profiles(final ServerListModel model) {
68
+        super();
69
+
70
+        this.model = model;
71
+
72
+        label = new JLabel("Use this profile on this network: ");
73
+        setBorder(BorderFactory.createTitledBorder(UIManager.getBorder(
74
+                "TitledBorder.border"), "Default profile"));
75
+        addListeners();
76
+
77
+        setLayout(new MigLayout("fill"));
78
+        add(label);
79
+        add(getComboBox(model.getSelectedItem()), "grow, push");
80
+    }
81
+
82
+    /**
83
+     * Adds required listeners.
84
+     */
85
+    private void addListeners() {
86
+        model.addServerListListener(this);
87
+    }
88
+
89
+    /** {@inheritDoc} */
90
+    @Override
91
+    public void serverGroupChanged(final ServerGroupItem item) {
92
+        setVisible(false);
93
+        removeAll();
94
+        add(label);
95
+        add(getComboBox(item), "grow, push");
96
+        setVisible(true);
97
+    }
98
+
99
+    /**
100
+     * Gets or creates a combo box for selecting performs for the specified
101
+     * server group item.
102
+     *
103
+     * @param item Server group item requiring the profile selection
104
+     *
105
+     * @return The server group item's associated profile selection box
106
+     */
107
+    private JComboBox getComboBox(final ServerGroupItem item) {
108
+        if (!combos.containsKey(item)) {
109
+            final DefaultComboBoxModel comboModel = new VetoableComboBoxModel();
110
+
111
+            final List<Identity> profiles = IdentityManager.getCustomIdentities(
112
+                    "profile");
113
+            for (Identity profile : profiles) {
114
+                comboModel.addElement(profile);
115
+            }
116
+            combos.put(item, new JComboBox(comboModel));
117
+        }
118
+        return combos.get(item);
119
+    }
120
+}

+ 151
- 0
src/com/dmdirc/addons/ui_swing/dialogs/serverlist/ServerListDialog.java Parādīt failu

@@ -0,0 +1,151 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.ui_swing.dialogs.serverlist;
24
+
25
+import com.dmdirc.addons.ui_swing.dialogs.StandardDialog;
26
+
27
+import java.awt.Window;
28
+import java.awt.event.ActionEvent;
29
+import java.awt.event.ActionListener;
30
+
31
+import javax.swing.JButton;
32
+
33
+import net.miginfocom.swing.MigLayout;
34
+
35
+/**
36
+ * Dialog to show and edit server lists.
37
+ */
38
+public final class ServerListDialog extends StandardDialog implements
39
+        ActionListener {
40
+
41
+    /**
42
+     * A version number for this class. It should be changed whenever the class
43
+     * structure is changed (or anything else that would prevent serialized
44
+     * objects being unserialized with the new class).
45
+     */
46
+    private static final long serialVersionUID = 2;
47
+    /** Server list model. */
48
+    private final ServerListModel model;
49
+    /** Connect button. */
50
+    private final JButton connectButton;
51
+    /** Previously created instance of dialog. */
52
+    private static volatile ServerListDialog me = null;
53
+
54
+    /**
55
+     * Creates the dialog if one doesn't exist, and displays it.
56
+     *
57
+     * @param parentWindow Parent window
58
+     */
59
+    public static void showServerListDialog(final Window parentWindow) {
60
+        me = getServerListDialog(parentWindow);
61
+
62
+        me.display();
63
+        me.requestFocusInWindow();
64
+    }
65
+
66
+    /**
67
+     * Returns the current instance of the ServerListDialog.
68
+     *
69
+     * @param parentWindow Parent window
70
+     *
71
+     * @return The current ServerListDialog instance
72
+     */
73
+    public static ServerListDialog getServerListDialog(
74
+            final Window parentWindow) {
75
+        synchronized (ServerListDialog.class) {
76
+            if (me == null) {
77
+                me = new ServerListDialog(parentWindow, ModalityType.MODELESS);
78
+            }
79
+        }
80
+
81
+        return me;
82
+    }
83
+
84
+    /**
85
+     * Creates a new server list dialog.
86
+     *
87
+     * @param window Parent window
88
+     * @param modalityType Desired modality
89
+     */
90
+    private ServerListDialog(final Window window,
91
+            final ModalityType modalityType) {
92
+        super(window, modalityType);
93
+        setTitle("Server List");
94
+        model = new ServerListModel();
95
+        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
96
+
97
+        connectButton = new JButton("Connect");
98
+
99
+        setLayout(new MigLayout("fill, wrap 2, wmin 600, wmax 600"));
100
+
101
+        add(new Tree(model), "grow, spany 4, wmax 150, wmin 150");
102
+        add(new Info(model), "spanx 2, growx, pushx");
103
+        add(new Settings(model), "grow, push, gaptop unrel, gapbottom unrel");
104
+        add(new Perform(model), "grow, push");
105
+        add(new Profiles(model), "growx, pushx, spanx 2");
106
+        add(connectButton, "skip 1, split 3, right, gapright unrel*2, "
107
+                + "sgx button");
108
+        add(getLeftButton(), "right, sgx button");
109
+        add(getRightButton(), "right, sgx button");
110
+
111
+        addListeners();
112
+    }
113
+
114
+    /**
115
+     * Adds requires listeners to objects.
116
+     */
117
+    private void addListeners() {
118
+        connectButton.addActionListener(this);
119
+        getOkButton().addActionListener(this);
120
+        getCancelButton().addActionListener(this);
121
+    }
122
+
123
+    /**
124
+     * {@inheritDoc}
125
+     *
126
+     * @param e Action event
127
+     */
128
+    @Override
129
+    public void actionPerformed(final ActionEvent e) {
130
+        if (e.getSource() == getOkButton()) {
131
+            model.saveChanges();
132
+            dispose();
133
+        } else if (e.getSource() == getCancelButton()) {
134
+            dispose();
135
+        } else if (e.getSource() == connectButton) {
136
+            model.getSelectedItem().connect();
137
+        }
138
+    }
139
+
140
+    /** {@inheritDoc} */
141
+    @Override
142
+    public void dispose() {
143
+        synchronized (ServerListDialog.class) {
144
+            if (me == null) {
145
+                return;
146
+            }
147
+            super.dispose();
148
+            me = null;
149
+        }
150
+    }
151
+}

+ 38
- 0
src/com/dmdirc/addons/ui_swing/dialogs/serverlist/ServerListListener.java Parādīt failu

@@ -0,0 +1,38 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.ui_swing.dialogs.serverlist;
24
+
25
+import com.dmdirc.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
+}

+ 153
- 0
src/com/dmdirc/addons/ui_swing/dialogs/serverlist/ServerListModel.java Parādīt failu

@@ -0,0 +1,153 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.ui_swing.dialogs.serverlist;
24
+
25
+import com.dmdirc.serverlists.ServerGroup;
26
+import com.dmdirc.serverlists.ServerGroupItem;
27
+import com.dmdirc.serverlists.ServerList;
28
+import com.dmdirc.util.ListenerList;
29
+
30
+import java.util.List;
31
+
32
+import javax.swing.tree.DefaultMutableTreeNode;
33
+import javax.swing.tree.DefaultTreeModel;
34
+
35
+/**
36
+ * Model proxying requests from the core server list model to the swing ui.
37
+ */
38
+public class ServerListModel {
39
+
40
+    /** Server list. */
41
+    private final ServerList list = new ServerList();
42
+    /** Listener list. */
43
+    private final ListenerList listeners;
44
+    /** Active server group. */
45
+    private ServerGroup activeGroup;
46
+    /** Active server item. */
47
+    private ServerGroupItem activeItem;
48
+
49
+    /**
50
+     * Creates a new server list model.
51
+     */
52
+    public ServerListModel() {
53
+        listeners = new ListenerList();
54
+    }
55
+
56
+    /**
57
+     * Returns a populated tree model for this server list model.
58
+     *
59
+     * @return Populated tree model
60
+     */
61
+    public DefaultTreeModel getTreeModel() {
62
+        return populateModel(new DefaultTreeModel(
63
+                new DefaultMutableTreeNode()));
64
+    }
65
+
66
+    /**
67
+     * Populates a tree model for this server list model.
68
+     *
69
+     * @param model Un-populated tree model to populate
70
+     *
71
+     * @return Populated tree model
72
+     */
73
+    public DefaultTreeModel populateModel(final DefaultTreeModel model) {
74
+        for (ServerGroup group : list.getServerGroups()) {
75
+            final DefaultMutableTreeNode child = new DefaultMutableTreeNode(
76
+                    group);
77
+            model.insertNodeInto(child, (DefaultMutableTreeNode) model
78
+                    .getRoot(), model.getChildCount(model.getRoot()));
79
+            model.nodeStructureChanged((DefaultMutableTreeNode) model
80
+                    .getRoot());
81
+            addGroups(model, child, group.getItems());
82
+        }
83
+        return model;
84
+    }
85
+
86
+    /**
87
+     * Recursively adds groups to the specified tree model.
88
+     *
89
+     * @param model Tree model
90
+     * @param parent Parent node to populate
91
+     * @param items Items to add to parent node
92
+     */
93
+    private void addGroups(final DefaultTreeModel model,
94
+            final DefaultMutableTreeNode parent,
95
+            final List<ServerGroupItem> items) {
96
+        for (ServerGroupItem group : items) {
97
+            final DefaultMutableTreeNode child = new DefaultMutableTreeNode(
98
+                    group);
99
+            model.insertNodeInto(child, parent, model.getChildCount(parent));
100
+            if (group instanceof ServerGroup) {
101
+                addGroups(model, child, ((ServerGroup) group).getItems());
102
+            }
103
+        }
104
+    }
105
+
106
+    /**
107
+     * Adds a server list listener to be notified of changes.
108
+     *
109
+     * @param listener Listener to add
110
+     */
111
+    public void addServerListListener(final ServerListListener listener) {
112
+        listeners.add(ServerListListener.class, listener);
113
+    }
114
+
115
+    /**
116
+     * Sets the selected item in this model.
117
+     *
118
+     * @param item Newly selected item
119
+     */
120
+    public void setSelectedItem(final ServerGroupItem item) {
121
+        activeGroup = item.getGroup();
122
+        activeItem = item;
123
+        for (ServerListListener listener : listeners.get(
124
+                ServerListListener.class)) {
125
+            listener.serverGroupChanged(item);
126
+        }
127
+    }
128
+
129
+    /**
130
+     * Gets the currently selected group.
131
+     *
132
+     * @return Currently selected group
133
+     */
134
+    public ServerGroup getSelectedGroup() {
135
+        return activeGroup;
136
+    }
137
+
138
+    /**
139
+     * Gets the currently selected item.
140
+     *
141
+     * @return Currently selected item
142
+     */
143
+    public ServerGroupItem getSelectedItem() {
144
+        return activeItem;
145
+    }
146
+
147
+    /**
148
+     * Saves the changes.
149
+     */
150
+    public void saveChanges() {
151
+        //TODO
152
+    }
153
+}

+ 105
- 0
src/com/dmdirc/addons/ui_swing/dialogs/serverlist/Settings.java Parādīt failu

@@ -0,0 +1,105 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.ui_swing.dialogs.serverlist;
24
+
25
+import com.dmdirc.addons.ui_swing.components.expandingsettings.SettingsPanel;
26
+import com.dmdirc.config.IdentityManager;
27
+import com.dmdirc.serverlists.ServerGroup;
28
+import com.dmdirc.serverlists.ServerGroupItem;
29
+
30
+import java.util.HashMap;
31
+import java.util.Map;
32
+
33
+import javax.swing.JPanel;
34
+
35
+import net.miginfocom.swing.MigLayout;
36
+
37
+/**
38
+ * Panel for listing and adding settings to the group item.
39
+ */
40
+public class Settings extends JPanel implements ServerListListener {
41
+
42
+    /**
43
+     * A version number for this class. It should be changed whenever the class
44
+     * structure is changed (or anything else that would prevent serialized
45
+     * objects being unserialized with the new class).
46
+     */
47
+    private static final long serialVersionUID = 2;
48
+    /** Server list model. */
49
+    private final ServerListModel model;
50
+    /** Settings panel. */
51
+    private final Map<ServerGroupItem, SettingsPanel> panels =
52
+            new HashMap<ServerGroupItem, SettingsPanel>();
53
+
54
+    /**
55
+     * Instantiates a new settings panel.
56
+     *
57
+     * @param model Backing model
58
+     */
59
+    public Settings(final ServerListModel model) {
60
+        super();
61
+        this.model = model;
62
+        addListeners();
63
+        setLayout(new MigLayout("fill, ins 0"));
64
+        add(getSettingsPanel(model.getSelectedItem()), "grow, push");
65
+    }
66
+
67
+    /**
68
+     * Adds required listeners.
69
+     */
70
+    private void addListeners() {
71
+        model.addServerListListener(this);
72
+    }
73
+
74
+    /** {@inheritDoc} */
75
+    @Override
76
+    public void serverGroupChanged(final ServerGroupItem item) {
77
+        setVisible(false);
78
+        removeAll();
79
+        add(getSettingsPanel(item), "grow, push");
80
+        setVisible(true);
81
+    }
82
+
83
+    /**
84
+     * Gets a settings panel for the specified group item, creating it if
85
+     * required.
86
+     *
87
+     * @param item Group item panel
88
+     *
89
+     * @return Settings panel for group item
90
+     */
91
+    private SettingsPanel getSettingsPanel(final ServerGroupItem item) {
92
+        if (!panels.containsKey(item)) {
93
+            if (item instanceof ServerGroup) {
94
+                panels.put(item, new SettingsPanel(IdentityManager.
95
+                        getNetworkConfig(item.getName()), ""));
96
+            } else {
97
+                panels.put(item, new SettingsPanel(IdentityManager.
98
+                        getServerConfig(item.getName()), ""));
99
+            }
100
+            panels.get(item).addOption("ui.textPaneFontName", "Textpane Font",
101
+                    SettingsPanel.OptionType.FONT);
102
+        }
103
+        return panels.get(item);
104
+    }
105
+}

+ 137
- 0
src/com/dmdirc/addons/ui_swing/dialogs/serverlist/Tree.java Parādīt failu

@@ -0,0 +1,137 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.ui_swing.dialogs.serverlist;
24
+
25
+import com.dmdirc.addons.ui_swing.components.TreeScroller;
26
+import com.dmdirc.addons.ui_swing.components.renderers.ServerGroupTreeRenderer;
27
+import com.dmdirc.serverlists.ServerGroup;
28
+import com.dmdirc.serverlists.ServerGroupItem;
29
+
30
+import java.awt.Rectangle;
31
+
32
+import javax.swing.JComponent;
33
+import javax.swing.JPanel;
34
+import javax.swing.JScrollPane;
35
+import javax.swing.JTree;
36
+import javax.swing.event.TreeSelectionEvent;
37
+import javax.swing.event.TreeSelectionListener;
38
+import javax.swing.tree.DefaultMutableTreeNode;
39
+import javax.swing.tree.DefaultTreeModel;
40
+import javax.swing.tree.TreeSelectionModel;
41
+
42
+import net.miginfocom.swing.MigLayout;
43
+
44
+/**
45
+ * Tree of server groups and items.
46
+ */
47
+public class Tree extends JPanel implements TreeSelectionListener {
48
+
49
+    /**
50
+     * A version number for this class. It should be changed whenever the class
51
+     * structure is changed (or anything else that would prevent serialized
52
+     * objects being unserialized with the new class).
53
+     */
54
+    private static final long serialVersionUID = 2;
55
+    /** Tree. */
56
+    private final JTree items;
57
+    /** Tree model. */
58
+    private final DefaultTreeModel treeModel;
59
+    /** Server list model. */
60
+    private final ServerListModel model;
61
+
62
+    /**
63
+     * Instantiates a new tree of server groups.
64
+     *
65
+     * @param model Model backing this tree
66
+     */
67
+    public Tree(final ServerListModel model) {
68
+        super();
69
+
70
+        this.model = model;
71
+        items = new JTree(model.getTreeModel()) {
72
+
73
+            /**
74
+             * A version number for this class. It should be changed whenever
75
+             * the class structure is changed (or anything else that would
76
+             * prevent serialized objects being unserialized with the new
77
+             * class).
78
+             */
79
+            private static final long serialVersionUID = 2;
80
+
81
+            /** {@inheritDoc} */
82
+            @Override
83
+            public void scrollRectToVisible(final Rectangle aRect) {
84
+                final Rectangle rect = new Rectangle(0, aRect.y,
85
+                        aRect.width, aRect.height);
86
+                super.scrollRectToVisible(rect);
87
+            }
88
+        };
89
+
90
+        items.putClientProperty("JTree.lineStyle", "Angled");
91
+        items.getInputMap().setParent(null);
92
+        items.getInputMap(JComponent.WHEN_FOCUSED).clear();
93
+        items.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
94
+                .clear();
95
+        items.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).clear();
96
+        items.getSelectionModel().setSelectionMode(
97
+                TreeSelectionModel.SINGLE_TREE_SELECTION);
98
+        items.setRootVisible(false);
99
+        items.setRowHeight(0);
100
+        items.setShowsRootHandles(false);
101
+        items.setOpaque(true);
102
+        items.setFocusable(false);
103
+        items.setRootVisible(false);
104
+        items.setShowsRootHandles(true);
105
+        new TreeScroller(items);
106
+        items.setCellRenderer(new ServerGroupTreeRenderer());
107
+        treeModel = (DefaultTreeModel) items.getModel();
108
+        items.scrollRectToVisible(new Rectangle(0, 0, 0, 0));
109
+        items.setSelectionRow(0);
110
+        valueChanged(null);
111
+        addListeners();
112
+
113
+        setLayout(new MigLayout("fill, ins 0"));
114
+
115
+        add(new JScrollPane(items), "grow, push");
116
+    }
117
+
118
+    /**
119
+     * Adds required listeners.
120
+     */
121
+    private void addListeners() {
122
+        items.addTreeSelectionListener(this);
123
+    }
124
+
125
+    /** {@inheritDoc} */
126
+    @Override
127
+    public void valueChanged(final TreeSelectionEvent e) {
128
+        final DefaultMutableTreeNode itemNode = (DefaultMutableTreeNode) items.
129
+                getSelectionPath().getLastPathComponent();
130
+        DefaultMutableTreeNode groupNode = (DefaultMutableTreeNode) items.
131
+                getSelectionPath().getLastPathComponent();
132
+        while (!((groupNode.getUserObject()) instanceof ServerGroup)) {
133
+            groupNode = (DefaultMutableTreeNode) groupNode.getParent();
134
+        }
135
+        model.setSelectedItem((ServerGroupItem) itemNode.getUserObject());
136
+    }
137
+}

Notiek ielāde…
Atcelt
Saglabāt