Procházet zdrojové kódy

fixes issue 2544

tags/0.6.3m1rc1
Gregory Holmes před 15 roky
rodič
revize
9a44370fa6

+ 17
- 9
src/com/dmdirc/addons/ui_swing/SwingController.java Zobrazit soubor

@@ -19,6 +19,7 @@
19 19
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 20
  * SOFTWARE.
21 21
  */
22
+
22 23
 package com.dmdirc.addons.ui_swing;
23 24
 
24 25
 import com.dmdirc.addons.ui_swing.components.frames.ServerFrame;
@@ -85,9 +86,8 @@ import net.miginfocom.layout.PlatformDefaults;
85 86
 public final class SwingController extends Plugin implements UIController {
86 87
 
87 88
     /** Logger to use. */
88
-    private static final java.util.logging.Logger LOGGER = java.util.logging
89
-            .Logger.getLogger(SwingController.class.getName());
90
-
89
+    private static final java.util.logging.Logger LOGGER =
90
+            java.util.logging.Logger.getLogger(SwingController.class.getName());
91 91
     /** Singleton instance of MainFrame. */
92 92
     private MainFrame me;
93 93
     /** Status bar. */
@@ -205,7 +205,8 @@ public final class SwingController extends Plugin implements UIController {
205 205
             @Override
206 206
             public void run() {
207 207
                 LOGGER.finest("getInputWindow(): run");
208
-                setObject(new CustomInputFrame(owner, commandParser, SwingController.this));
208
+                setObject(new CustomInputFrame(owner, commandParser,
209
+                        SwingController.this));
209 210
                 LOGGER.finest("getInputWindow(): object set: " + getObject());
210 211
             }
211 212
         });
@@ -302,7 +303,8 @@ public final class SwingController extends Plugin implements UIController {
302 303
      */
303 304
     void updateLookAndFeel() {
304 305
         try {
305
-            UIManager.setLookAndFeel(UIUtilities.getLookAndFeel(IdentityManager.getGlobalConfig().getOption("ui", "lookandfeel")));
306
+            UIManager.setLookAndFeel(UIUtilities.getLookAndFeel(IdentityManager.
307
+                    getGlobalConfig().getOption("ui", "lookandfeel")));
306 308
             final int state = UIUtilities.invokeAndWait(new ReturnableThread<Integer>() {
307 309
 
308 310
                 /** {@inheritDoc} */
@@ -385,7 +387,8 @@ public final class SwingController extends Plugin implements UIController {
385 387
 
386 388
         try {
387 389
             UIUtilities.initUISettings();
388
-            UIManager.setLookAndFeel(UIUtilities.getLookAndFeel(IdentityManager.getGlobalConfig().getOption("ui", "lookandfeel")));
390
+            UIManager.setLookAndFeel(UIUtilities.getLookAndFeel(IdentityManager.
391
+                    getGlobalConfig().getOption("ui", "lookandfeel")));
389 392
 
390 393
         } catch (UnsupportedOperationException ex) {
391 394
             Logger.userError(ErrorLevel.LOW, "Unable to set UI Settings");
@@ -405,6 +408,8 @@ public final class SwingController extends Plugin implements UIController {
405 408
 
406 409
         Toolkit.getDefaultToolkit().getSystemEventQueue().
407 410
                 push(new DMDircEventQueue(this));
411
+        //Toolkit.getDefaultToolkit().getSystemEventQueue().
412
+        //        push(new TracingEventQueue());
408 413
     }
409 414
 
410 415
     /** {@inheritDoc} */
@@ -525,8 +530,10 @@ public final class SwingController extends Plugin implements UIController {
525 530
     @Override
526 531
     public void onLoad() {
527 532
         if (GraphicsEnvironment.isHeadless()) {
528
-            throw new IllegalStateException("Swing UI can't be run in a headless environment");
533
+            throw new IllegalStateException(
534
+                    "Swing UI can't be run in a headless environment");
529 535
         }
536
+
530 537
         UIUtilities.invokeAndWait(new Runnable() {
531 538
 
532 539
             /** {@inheritDoc} */
@@ -539,8 +546,9 @@ public final class SwingController extends Plugin implements UIController {
539 546
             }
540 547
         });
541 548
 
542
-        if(!mainFrameCreated.get()) {
543
-            throw new IllegalStateException("Main frame not created. Unable to continue.");
549
+        if (!mainFrameCreated.get()) {
550
+            throw new IllegalStateException(
551
+                    "Main frame not created. Unable to continue.");
544 552
         }
545 553
 
546 554
         Main.setUI(this);

+ 158
- 0
src/com/dmdirc/addons/ui_swing/dialogs/prefs/CategoryLabel.java Zobrazit soubor

@@ -0,0 +1,158 @@
1
+/*
2
+ * 
3
+ * Copyright (c) 2006-2008 Chris Smith, Shane Mc Cormack, Gregory Holmes
4
+ * 
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ * 
12
+ * The above copyright notice and this permission notice shall be included in
13
+ * all copies or substantial portions of the Software.
14
+ * 
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ * SOFTWARE.
22
+ */
23
+
24
+package com.dmdirc.addons.ui_swing.dialogs.prefs;
25
+
26
+import com.dmdirc.config.prefs.PreferencesCategory;
27
+import com.dmdirc.logger.ErrorLevel;
28
+import com.dmdirc.logger.Logger;
29
+import com.dmdirc.ui.IconManager;
30
+import java.awt.Color;
31
+import java.awt.Dimension;
32
+import java.util.concurrent.ExecutionException;
33
+import javax.swing.BorderFactory;
34
+import javax.swing.Icon;
35
+import javax.swing.JLabel;
36
+import javax.swing.JList;
37
+import javax.swing.SwingUtilities;
38
+import javax.swing.SwingWorker;
39
+import net.miginfocom.layout.PlatformDefaults;
40
+
41
+/**
42
+ * Category Label.
43
+ */
44
+public class CategoryLabel extends JLabel {
45
+
46
+    /**
47
+     * A version number for this class. It should be changed whenever the
48
+     * class structure is changed (or anything else that would prevent
49
+     * serialized objects being unserialized with the new class).
50
+     */
51
+    private static final long serialVersionUID = -1659415238166842265L;
52
+    /** Panel gap. */
53
+    private final int padding = (int) (1.5 * PlatformDefaults.getUnitValueX(
54
+            "related").getValue());
55
+    private PreferencesCategory category;
56
+    private JList parentList;
57
+    private int index;
58
+
59
+    /**
60
+     * 
61
+     * @param parentList
62
+     * @param category
63
+     * @param index 
64
+     */
65
+    public CategoryLabel(final JList parentList,
66
+            final PreferencesCategory category, final int index) {
67
+        this.parentList = parentList;
68
+        this.category = category;
69
+        this.index = index;
70
+
71
+        setText(category.getTitle());
72
+        new IconLoader(this, category.getIcon()).execute();
73
+
74
+        int level = 0;
75
+        PreferencesCategory temp = category;
76
+        while (temp.getParent() != null) {
77
+            temp = temp.getParent();
78
+            level++;
79
+        }
80
+
81
+        setPreferredSize(new Dimension(100000, Math.max(16,
82
+                getFont().getSize()) + padding));
83
+        setBorder(BorderFactory.createEmptyBorder(padding / 2, padding + level *
84
+                18, padding / 2,
85
+                padding));
86
+        setBackground(parentList.getBackground());
87
+        setForeground(parentList.getForeground());
88
+        setOpaque(true);
89
+        setToolTipText(null);
90
+
91
+        if (category.getPath().equals(category.getTitle())) {
92
+            boolean hasChildren = false;
93
+            for (PreferencesCategory child : category.getSubcats()) {
94
+                if (!child.isInline()) {
95
+                    hasChildren = true;
96
+                    break;
97
+                }
98
+            }
99
+
100
+            hasChildren = hasChildren || index + 1 == parentList.getModel().
101
+                    getSize();
102
+
103
+            setBackground(Color.LIGHT_GRAY);
104
+            setBorder(BorderFactory.createCompoundBorder(
105
+                    BorderFactory.createMatteBorder(1, 0, hasChildren ? 1 : 0, 0,
106
+                    Color.GRAY),
107
+                    getBorder()));
108
+        }
109
+
110
+
111
+    }
112
+
113
+    /**
114
+     * {@inheritDoc}
115
+     *
116
+     * @param icon New icon
117
+     */
118
+    @Override
119
+    public void setIcon(Icon icon) {
120
+        super.setIcon(icon);
121
+
122
+        if (parentList != null) {
123
+            parentList.repaint();
124
+        }
125
+    }
126
+
127
+    private class IconLoader extends SwingWorker<Icon, Void> {
128
+
129
+        private CategoryLabel label;
130
+        private String icon;
131
+
132
+        public IconLoader(final CategoryLabel label, final String icon) {
133
+            this.label = label;
134
+            this.icon = icon;
135
+        }
136
+
137
+        /** {@inheritDoc} */
138
+        @Override
139
+        protected Icon doInBackground() throws Exception {
140
+            return IconManager.getIconManager().getIcon(icon);
141
+        }
142
+
143
+        /** {@inheritDoc} */
144
+        @Override
145
+        protected void done() {
146
+            try {
147
+                label.setIcon(get());
148
+            } catch (InterruptedException ex) {
149
+                Logger.appError(ErrorLevel.LOW,
150
+                        "Unable to set icon for prefs cell", ex);
151
+            } catch (ExecutionException ex) {
152
+                Logger.appError(ErrorLevel.LOW, ex.getMessage(), ex);
153
+            }
154
+
155
+        }
156
+    }
157
+
158
+}

+ 1
- 58
src/com/dmdirc/addons/ui_swing/dialogs/prefs/PreferencesListCellRenderer.java Zobrazit soubor

@@ -77,66 +77,9 @@ public class PreferencesListCellRenderer extends JLabel implements ListCellRende
77 77
             final boolean cellHasFocus) {
78 78
         final PreferencesCategory cat = (PreferencesCategory) value;
79 79
         if (!labelMap.containsKey(cat)) {
80
-            labelMap.put(cat, new JLabel());
80
+            labelMap.put(cat, new CategoryLabel(list, cat, index));
81 81
         }
82 82
         final JLabel label = labelMap.get(cat);
83
-        label.setText(cat.getTitle());
84
-        
85
-        new LoggingSwingWorker<Icon, Void>() {
86
-
87
-            /** {@inheritDoc} */
88
-            @Override
89
-            protected Icon doInBackground() throws Exception {
90
-                return IconManager.getIconManager().getIcon(cat.getIcon());
91
-            }
92
-
93
-            /** {@inheritDoc} */
94
-            @Override
95
-            protected void done() {
96
-                try {
97
-                    label.setIcon(get());
98
-                    list.repaint();
99
-                } catch (InterruptedException ex) {
100
-                    Logger.appError(ErrorLevel.LOW, "Unable to set icon for prefs cell", ex);
101
-                } catch (ExecutionException ex) {
102
-                    Logger.appError(ErrorLevel.LOW, ex.getMessage(), ex);
103
-                }
104
-                
105
-            }
106
-        }.execute();
107
-
108
-        int level = 0;
109
-        PreferencesCategory temp = cat;
110
-        while (temp.getParent() != null) {
111
-            temp = temp.getParent();
112
-            level++;
113
-        }
114
-
115
-        label.setPreferredSize(new Dimension(100000, Math.max(16,
116
-                getFont().getSize()) + padding));
117
-        label.setBorder(BorderFactory.createEmptyBorder(padding / 2, padding + level * 18, padding / 2,
118
-                padding));
119
-        label.setBackground(list.getBackground());
120
-        label.setForeground(list.getForeground());
121
-        label.setOpaque(true);
122
-        label.setToolTipText(null);
123
-
124
-        if (cat.getPath().equals(cat.getTitle())) {
125
-            boolean hasChildren = false;
126
-            for (PreferencesCategory child : cat.getSubcats()) {
127
-                if (!child.isInline()) {
128
-                    hasChildren = true;
129
-                    break;
130
-                }
131
-            }
132
-
133
-            hasChildren = hasChildren || index + 1 == list.getModel().getSize();
134
-
135
-            label.setBackground(Color.LIGHT_GRAY);
136
-            label.setBorder(BorderFactory.createCompoundBorder(
137
-                    BorderFactory.createMatteBorder(1, 0, hasChildren ? 1 : 0, 0, Color.GRAY),
138
-                    getBorder()));
139
-        }
140 83
 
141 84
         if (isSelected) {
142 85
             label.setFont(getFont().deriveFont(Font.BOLD));

+ 1
- 23
src/com/dmdirc/ui/IconManager.java Zobrazit soubor

@@ -24,20 +24,16 @@ package com.dmdirc.ui;
24 24
 
25 25
 import com.dmdirc.config.IdentityManager;
26 26
 import com.dmdirc.interfaces.ConfigChangeListener;
27
-import com.dmdirc.logger.ErrorLevel;
28
-import com.dmdirc.logger.Logger;
29 27
 import com.dmdirc.util.URLBuilder;
30 28
 
31 29
 import java.awt.Image;
32 30
 import java.awt.Toolkit;
33
-import java.lang.reflect.InvocationTargetException;
34 31
 import java.net.URL;
35 32
 import java.util.HashMap;
36 33
 import java.util.Map;
37 34
 
38 35
 import javax.swing.Icon;
39 36
 import javax.swing.ImageIcon;
40
-import javax.swing.SwingUtilities;
41 37
 
42 38
 /**
43 39
  * The icon manager provides a standard way to access icons for use in DMDirc.
@@ -86,26 +82,8 @@ public final class IconManager implements ConfigChangeListener {
86 82
         final URL iconURL = getIconURL(type);
87 83
         final Image iconImage = Toolkit.getDefaultToolkit().getImage(iconURL);
88 84
         final Image scaledIconImage = getScaledImage(iconImage, 16, 16);
89
-        final Runnable runnable = new Runnable() {
90
-
91
-            @Override
92
-            public void run() {
93
-                icons.put(type, new ImageIcon(scaledIconImage));
94
-            }
95
-        };
96
-        final ImageIcon icon;
97 85
         if (!icons.containsKey(type)) {
98
-            if (SwingUtilities.isEventDispatchThread()) {
99
-                runnable.run();
100
-            } else {
101
-                try {
102
-                    SwingUtilities.invokeAndWait(runnable);
103
-                } catch (InterruptedException ex) {
104
-                    Logger.appError(ErrorLevel.HIGH, "Unable to execute thread.", ex);
105
-                } catch (InvocationTargetException ex) {
106
-                    Logger.appError(ErrorLevel.HIGH, "Unable to execute thread.", ex);
107
-                }
108
-            }
86
+            icons.put(type, new ImageIcon(scaledIconImage));
109 87
         }
110 88
         return icons.get(type);
111 89
     }

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