File Source: AddonCellRenderer.java
/*
P/P * Method: com.dmdirc.addons.ui_swing.components.renderers.AddonCellRenderer__static_init
*/
1 /*
2 * Copyright (c) 2006-2009 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.addons.ui_swing.components.pluginpanel.PluginInfoToggle;
26 import com.dmdirc.addons.ui_swing.components.themepanel.ThemeToggle;
27 import static com.dmdirc.addons.ui_swing.UIUtilities.SMALL_BORDER;
28
29 import java.awt.Color;
30 import java.awt.Component;
31 import java.awt.Font;
32
33 import javax.swing.BorderFactory;
34 import javax.swing.JLabel;
35 import javax.swing.JList;
36 import javax.swing.JPanel;
37 import javax.swing.JSeparator;
38 import javax.swing.ListCellRenderer;
39
40 import net.miginfocom.swing.MigLayout;
41
42 /**
43 * Handles the rendering of the JList used for plugin and theme management.
44 * @author chris
45 */
46 public final class AddonCellRenderer extends JPanel implements ListCellRenderer {
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 = 1;
54
55 /** Creates a new instance of AddonCellRenderer. */
56 public AddonCellRenderer() {
/*
P/P * Method: void com.dmdirc.addons.ui_swing.components.renderers.AddonCellRenderer()
*/
57 super();
58 }
59
60 /** {@inheritDoc} */
61 @Override
62 public Component getListCellRendererComponent(final JList list,
63 final Object value, final int index, final boolean isSelected,
64 final boolean cellHasFocus) {
65
/*
P/P * Method: Component getListCellRendererComponent(JList, Object, int, bool, bool)
*
* Preconditions:
* list != null
* (soft) init'ed(value.enable)
* (soft) value.pi != null
* (soft) value.theme != null
* (soft) init'ed(value.toggle)
*
* Presumptions:
* init'ed(java.awt.Color.BLACK)
* init'ed(java.awt.Color.GRAY)
* javax.swing.JLabel:getFont(...)@104 != null
*
* Postconditions:
* return_value == this
* return_value != null
*
* Test Vectors:
* isSelected: {0}, {1}
* value.enable: {1}, {0}
* value.toggle ^ com.dmdirc.plugins.PluginInfo:isLoaded(...)@65: {1}, {0}
*/
66 removeAll();
67 setLayout(new MigLayout("fill, ins 3 0 0 0"));
68
69 if (isSelected) {
70 setBackground(list.getSelectionBackground());
71 } else {
72 setBackground(list.getBackground());
73 }
74
75 Color foreground = Color.BLACK;
76 final JLabel name = new JLabel(), version = new JLabel(),
77 author = new JLabel(), desc = new JLabel();
78
79 if (value instanceof PluginInfoToggle) {
80 final PluginInfoToggle plugin = (PluginInfoToggle) value;
81
82 if (!plugin.getState()) {
83 foreground = Color.GRAY;
84 }
85
86 name.setText(plugin.getPluginInfo().getNiceName());
87 version.setText(plugin.getPluginInfo().getFriendlyVersion());
88 author.setText(plugin.getPluginInfo().getAuthor());
89 desc.setText(plugin.getPluginInfo().getDescription());
90 } else if (value instanceof ThemeToggle) {
91 final ThemeToggle theme = (ThemeToggle) value;
92
93 if (!theme.getState()) {
94 foreground = Color.GRAY;
95 }
96
97 name.setText(theme.getTheme().getName());
98 version.setText(theme.getTheme().getVersion());
99 author.setText(theme.getTheme().getAuthor());
100 desc.setText(theme.getTheme().getDescription());
101 }
102
103 name.setForeground(foreground);
104 name.setFont(name.getFont().deriveFont(Font.BOLD));
105 version.setForeground(foreground);
106 version.setHorizontalAlignment(JLabel.CENTER);
107 author.setForeground(foreground);
108 desc.setForeground(foreground);
109 desc.setBorder(BorderFactory.createEmptyBorder(SMALL_BORDER, 0, 0, 0));
110
111 add(name, "gapleft 3");
112 add(version, "pushx");
113 add(author, "wrap, gapright 3");
114 add(desc, "span 3, growx, pushx, wrap, gapleft 3, gapright 3");
115 add(new JSeparator(), "span 3, growx, pushx");
116
117 return this;
118 }
119
120 }
SofCheck Inspector Build Version : 2.17854
| AddonCellRenderer.java |
2009-Jun-25 01:54:24 |
| AddonCellRenderer.class |
2009-Sep-02 17:04:15 |