%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
ca.spaz.cron.summary.SwitchableSummaryPanel |
|
|
1 | /* |
|
2 | ******************************************************************************* |
|
3 | * Copyright (c) 2005 Chris Rose and AIMedia |
|
4 | * All rights reserved. SwitchableSummaryPanel and the accompanying materials |
|
5 | * are made available under the terms of the Common Public License v1.0 |
|
6 | * which accompanies this distribution, and is available at |
|
7 | * http://www.eclipse.org/legal/cpl-v10.html |
|
8 | * |
|
9 | * Contributors: |
|
10 | * Chris Rose |
|
11 | *******************************************************************************/ |
|
12 | package ca.spaz.cron.summary; |
|
13 | ||
14 | import java.util.*; |
|
15 | ||
16 | import javax.swing.*; |
|
17 | ||
18 | import com.aimedia.ui.IValueListUser; |
|
19 | ||
20 | /** |
|
21 | * This is a generic summaryPanel subclass that allows for multiple subpanels |
|
22 | * for viewing nutrient summary information. Subclasses of it can add and remove |
|
23 | * subpanels that will be displayed in a tabbed layout. |
|
24 | * |
|
25 | * @deprecated No longer needed for UI |
|
26 | * @author Chris Rose |
|
27 | */ |
|
28 | public abstract class SwitchableSummaryPanel extends SummaryPanel { |
|
29 | ||
30 | private Map panelMap; |
|
31 | private Map iconMap; |
|
32 | private JComponent currentContent; |
|
33 | private JTabbedPane tabbedPane; |
|
34 | ||
35 | /** |
|
36 | * Create a new instance. |
|
37 | */ |
|
38 | protected SwitchableSummaryPanel() { |
|
39 | 0 | this(null); |
40 | 0 | } |
41 | ||
42 | /** |
|
43 | * @param fieldOrdering |
|
44 | */ |
|
45 | protected SwitchableSummaryPanel(Comparator fieldOrdering) { |
|
46 | 0 | super(fieldOrdering); |
47 | 0 | this.iconMap = new HashMap(); |
48 | 0 | this.panelMap = new HashMap(); |
49 | 0 | } |
50 | ||
51 | /** |
|
52 | * @return Returns the tabbedPane. |
|
53 | */ |
|
54 | private JTabbedPane getTabbedPane() { |
|
55 | 0 | if (null == tabbedPane) { |
56 | 0 | tabbedPane = new JTabbedPane(JTabbedPane.LEFT, JTabbedPane.SCROLL_TAB_LAYOUT); |
57 | } |
|
58 | 0 | return tabbedPane; |
59 | } |
|
60 | ||
61 | /* (non-Javadoc) |
|
62 | * @see ca.spaz.cron.SummaryPanel#doValueUpdate(java.lang.String) |
|
63 | */ |
|
64 | protected void doValueUpdate(String valueName) { |
|
65 | 0 | List vl = getValueList(); |
66 | 0 | for (Iterator iter = panelMap.values().iterator(); iter.hasNext();) { |
67 | 0 | IValueListUser ivl = (IValueListUser) iter.next(); |
68 | 0 | ivl.setValueList(vl); |
69 | 0 | } |
70 | 0 | } |
71 | ||
72 | /** |
|
73 | * Add a new content panel to the summary panel. |
|
74 | * @param cpName the name (Human-usable) of the panel. Will be used for the label |
|
75 | * of the panel. |
|
76 | * @param content the panel to add. This <em>must</em> be a |
|
77 | * <code>JComponent</code> subclass. |
|
78 | * @throws IllegalArgumentException if the content argument does not descend from |
|
79 | * <code>JComponent</code>. |
|
80 | */ |
|
81 | protected final void addContentPane(String cpName, IValueListUser content) { |
|
82 | 0 | addContentPane(cpName, null, content); |
83 | 0 | } |
84 | ||
85 | /** |
|
86 | * Add a new content panel to the summary panel. |
|
87 | * @param cpName the name (Human-usable) of the panel. Will be used for the label |
|
88 | * of the panel. |
|
89 | * @param cpIcon an icon for display on the label of the component. If null, no icon |
|
90 | * will appear. |
|
91 | * @param content the panel to add. This <em>must</em> be a |
|
92 | * <code>JComponent</code> subclass. |
|
93 | * @throws IllegalArgumentException if the content argument does not descend from |
|
94 | * <code>JComponent</code>. |
|
95 | */ |
|
96 | protected final void addContentPane(String cpName, Icon cpIcon, IValueListUser content) { |
|
97 | 0 | if (!(content instanceof JComponent)) { |
98 | 0 | throw new IllegalArgumentException("Content must also be a Swing component"); |
99 | } |
|
100 | 0 | panelMap.put(cpName, content); |
101 | 0 | iconMap.put(cpName, cpIcon); |
102 | 0 | getTabbedPane().addTab(cpName, cpIcon, (JComponent) content); |
103 | 0 | } |
104 | ||
105 | /** |
|
106 | * Remove the named content pane from the summary panel. |
|
107 | * @param cpName the content pane to remove. |
|
108 | */ |
|
109 | protected final void removeContentPane(String cpName) { |
|
110 | 0 | getTabbedPane().remove((JComponent) panelMap.remove(cpName)); |
111 | 0 | iconMap.remove(cpName); |
112 | 0 | } |
113 | ||
114 | /** |
|
115 | * Get a list of available content panes. |
|
116 | * @return a <code>List</code> of content pane names (<code>String</code>s) |
|
117 | */ |
|
118 | protected final List getAvailableContentPanes() { |
|
119 | 0 | List ret = Collections.unmodifiableList(new ArrayList(panelMap.keySet())); |
120 | 0 | return ret; |
121 | } |
|
122 | ||
123 | /** |
|
124 | * Get the icon for a given content pane. |
|
125 | * @param cpName the pane to retrieve the icon for. |
|
126 | * @return an <code>Icon</code> for the content pane, or <code>null</code> if |
|
127 | * there is none. |
|
128 | */ |
|
129 | protected final Icon getIcon(String cpName) { |
|
130 | 0 | Icon ico = (Icon) iconMap.get(cpName); |
131 | 0 | return ico; |
132 | } |
|
133 | ||
134 | /** |
|
135 | * Bring the selected content pane to the front. |
|
136 | * @param cpName the pane to select. |
|
137 | */ |
|
138 | public void selectContentPane(String cpName) { |
|
139 | 0 | if (panelMap.size() > 1) { |
140 | 0 | JComponent cmp = (JComponent) panelMap.get(cpName); |
141 | 0 | if (cmp != null) { |
142 | 0 | getTabbedPane().setSelectedComponent(cmp); |
143 | } |
|
144 | } |
|
145 | 0 | } |
146 | ||
147 | /* (non-Javadoc) |
|
148 | * @see ca.spaz.cron.SummaryPanel#getContentPane(java.util.List) |
|
149 | */ |
|
150 | protected JComponent getContentPane(List contentValues) { |
|
151 | 0 | if (panelMap.size() == 0) { |
152 | 0 | return super.getContentPane(contentValues); |
153 | 0 | } else if (panelMap.size() == 1) { |
154 | 0 | JComponent c = (JComponent) getTabbedPane().getComponentAt(0); |
155 | 0 | ((IValueListUser)c).setValueList(contentValues); |
156 | 0 | return c; |
157 | } |
|
158 | 0 | for (Iterator iter = panelMap.values().iterator(); iter.hasNext();) { |
159 | 0 | IValueListUser vl = (IValueListUser) iter.next(); |
160 | 0 | vl.setValueList(contentValues); |
161 | 0 | } |
162 | 0 | return getTabbedPane(); |
163 | } |
|
164 | ||
165 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |