File Source: CategoryLabel.java
/*
P/P * Method: com.dmdirc.addons.ui_swing.dialogs.prefs.CategoryLabel__static_init
*/
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.SwingWorker;
38 import net.miginfocom.layout.PlatformDefaults;
39
40 /**
41 * Category Label.
42 */
43 public class CategoryLabel extends JLabel {
44
45 /**
46 * A version number for this class. It should be changed whenever the
47 * class structure is changed (or anything else that would prevent
48 * serialized objects being unserialized with the new class).
49 */
50 private static final long serialVersionUID = -1659415238166842265L;
51 /** Panel gap. */
52 private final int padding = (int) (1.5 * PlatformDefaults.getUnitValueX(
53 "related").getValue());
54 private PreferencesCategory category;
55 private JList parentList;
56 private int index;
57
58 /**
59 *
60 * @param parentList
61 * @param category
62 * @param numCats
63 * @param index
64 */
65 public CategoryLabel(final JList parentList,
/*
P/P * Method: void com.dmdirc.addons.ui_swing.dialogs.prefs.CategoryLabel(JList, PreferencesCategory, int, int)
*
* Preconditions:
* category != null
* parentList != null
*
* Presumptions:
* (int) (net.miginfocom.layout.UnitValue:getValue(...)@52*3/2) in {-231..232-1}
* com.dmdirc.addons.ui_swing.dialogs.prefs.CategoryLabel:getFont(...)@81 != null
* com.dmdirc.config.prefs.PreferencesCategory:getPath(...)@91 != null
* com.dmdirc.config.prefs.PreferencesCategory:getSubcats(...)@93 != null
* init'ed(java.awt.Color.GRAY)
* ...
*
* Postconditions:
* this.category == category
* this.category != null
* this.index == index
* init'ed(this.index)
* init'ed(this.padding)
* this.parentList == parentList
* this.parentList != null
*
* Test Vectors:
* com.dmdirc.config.prefs.PreferencesCategory:getParent(...)@76: Addr_Set{null}, Inverse{null}
* com.dmdirc.config.prefs.PreferencesCategory:isInline(...)@94: {1}, {0}
* java.lang.String:equals(...)@91: {0}, {1}
* java.util.Iterator:hasNext(...)@93: {0}, {1}
*/
66 final PreferencesCategory category, final int numCats, 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 == numCats;
101
102 setBackground(Color.LIGHT_GRAY);
103 setBorder(BorderFactory.createCompoundBorder(
104 BorderFactory.createMatteBorder(1, 0, hasChildren ? 1 : 0, 0,
105 Color.GRAY),
106 getBorder()));
107 }
108 }
109
110 /**
111 * {@inheritDoc}
112 *
113 * @param icon New icon
114 */
115 @Override
116 public void setIcon(Icon icon) {
/*
P/P * Method: void setIcon(Icon)
*
* Preconditions:
* init'ed(this.parentList)
*
* Test Vectors:
* this.parentList: Addr_Set{null}, Inverse{null}
*/
117 super.setIcon(icon);
118
119 if (parentList != null) {
120 parentList.repaint();
121 }
122 }
123
/*
P/P * Method: Object doInBackground()
*
* Preconditions:
* init'ed(this.icon)
*
* Postconditions:
* init'ed(return_value)
*/
124 private class IconLoader extends SwingWorker<Icon, Void> {
125
126 private CategoryLabel label;
127 private String icon;
128
/*
P/P * Method: void com.dmdirc.addons.ui_swing.dialogs.prefs.CategoryLabel$IconLoader(CategoryLabel, CategoryLabel, String)
*
* Postconditions:
* this.icon == icon
* init'ed(this.icon)
* this.label == label
* init'ed(this.label)
*/
129 public IconLoader(final CategoryLabel label, final String icon) {
130 this.label = label;
131 this.icon = icon;
132 }
133
134 /** {@inheritDoc} */
135 @Override
136 protected Icon doInBackground() throws Exception {
/*
P/P * Method: Icon doInBackground()
*
* Preconditions:
* init'ed(this.icon)
*
* Presumptions:
* com.dmdirc.ui.IconManager:getIconManager(...)@137 != null
*
* Postconditions:
* init'ed(return_value)
*/
137 return IconManager.getIconManager().getIcon(icon);
138 }
139
140 /** {@inheritDoc} */
141 @Override
142 protected void done() {
143 try {
/*
P/P * Method: void done()
*
* Preconditions:
* (soft) this.label != null
* (soft) init'ed(this.label.parentList)
*
* Presumptions:
* init'ed(com.dmdirc.logger.ErrorLevel.LOW)
*/
144 label.setIcon(get());
145 } catch (InterruptedException ex) {
146 //Ignore
147 } catch (ExecutionException ex) {
148 Logger.appError(ErrorLevel.LOW, ex.getMessage(), ex);
149 }
150
151 }
152 }
153
154 }
SofCheck Inspector Build Version : 2.17854
| CategoryLabel.java |
2009-Jun-25 01:54:24 |
| CategoryLabel.class |
2009-Sep-02 17:04:16 |
| CategoryLabel$IconLoader.class |
2009-Sep-02 17:04:16 |