Removed
Link Here
|
1 |
/* |
2 |
* Sun Public License Notice |
3 |
* |
4 |
* The contents of this file are subject to the Sun Public License |
5 |
* Version 1.0 (the "License"). You may not use this file except in |
6 |
* compliance with the License. A copy of the License is available at |
7 |
* http://www.sun.com/ |
8 |
* |
9 |
* The Original Code is NetBeans. The Initial Developer of the Original |
10 |
* Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun |
11 |
* Microsystems, Inc. All Rights Reserved. |
12 |
*/ |
13 |
|
14 |
package org.netbeans.core.ui; |
15 |
|
16 |
import javax.swing.UIManager; |
17 |
import javax.swing.plaf.basic.BasicBorders; |
18 |
|
19 |
import javax.swing.UIManager; |
20 |
import javax.swing.border.Border; |
21 |
|
22 |
import javax.swing.*; |
23 |
import javax.swing.event.*; |
24 |
import java.util.*; |
25 |
import java.awt.*; |
26 |
import java.awt.Font; |
27 |
import java.awt.font.LineMetrics; |
28 |
import java.beans.PropertyChangeListener; |
29 |
import java.beans.PropertyChangeEvent; |
30 |
|
31 |
import org.openide.WizardDescriptor; |
32 |
import org.openide.nodes.*; |
33 |
import org.openide.util.NbBundle; |
34 |
import org.openide.explorer.ExplorerManager; |
35 |
import org.openide.cookies.InstanceCookie; |
36 |
import java.io.IOException; |
37 |
|
38 |
/** Module selection panel allows user to enable/disable modules in setup wizard |
39 |
* |
40 |
* @author cledantec, jrojcek, Jesse Glick |
41 |
*/ |
42 |
public class ModuleSelectionPanel extends javax.swing.JPanel |
43 |
implements PropertyChangeListener { |
44 |
|
45 |
/** See org.openide.WizardDescriptor.PROP_CONTENT_SELECTED_INDEX |
46 |
*/ |
47 |
private static final String PROP_CONTENT_SELECTED_INDEX = "WizardPanel_contentSelectedIndex"; // NOI18N |
48 |
/** See org.openide.WizardDescriptor.PROP_CONTENT_DATA |
49 |
*/ |
50 |
private static final String PROP_CONTENT_DATA = "WizardPanel_contentData"; // NOI18N |
51 |
|
52 |
// SetupWizard has to load it eagerly too, so no harm here. |
53 |
private final ModuleBean.AllModulesBean allModules = ModuleBean.AllModulesBean.getDefault(); |
54 |
|
55 |
/** default size values */ |
56 |
private static final int DEF_TREE_WIDTH = 320; |
57 |
private static final int DEF_0_COL_WIDTH = 60; |
58 |
private static final int DEF_1_COL_WIDTH = 150; |
59 |
private static final int DEF_HEIGHT = 250; |
60 |
|
61 |
/** Creates new form wizardFrame */ |
62 |
public ModuleSelectionPanel() { |
63 |
putClientProperty(PROP_CONTENT_SELECTED_INDEX, new Integer(0)); |
64 |
String name = NbBundle.getMessage(ModuleSelectionPanel.class, "LBL_SetupWizardModuleInstallation"); |
65 |
putClientProperty(PROP_CONTENT_DATA, new String[] { name }); |
66 |
setName(name); |
67 |
} |
68 |
|
69 |
|
70 |
|
71 |
/** Avoid initializing GUI, and allModules, until needed. */ |
72 |
public void addNotify() { |
73 |
super.addNotify(); |
74 |
if (treeTableView != null) return; |
75 |
synchronized (getTreeLock()) { |
76 |
|
77 |
initComponents(); |
78 |
|
79 |
treeTableView.setProperties( |
80 |
new Node.Property[]{ |
81 |
new PropertySupport.ReadWrite ( |
82 |
"enabled", // NOI18N |
83 |
Boolean.TYPE, |
84 |
org.openide.util.NbBundle.getMessage (ModuleNode.class, "PROP_modules_enabled"), |
85 |
org.openide.util.NbBundle.getMessage (ModuleNode.class, "HINT_modules_enabled") |
86 |
) { |
87 |
public Object getValue () { |
88 |
return null; |
89 |
} |
90 |
|
91 |
public void setValue (Object o) { |
92 |
} |
93 |
}, |
94 |
new PropertySupport.ReadOnly ( |
95 |
"specificationVersion", // NOI18N |
96 |
String.class, |
97 |
org.openide.util.NbBundle.getMessage (ModuleNode.class, "PROP_modules_specversion"), |
98 |
org.openide.util.NbBundle.getMessage (ModuleNode.class, "HINT_modules_specversion") |
99 |
) { |
100 |
public Object getValue () { |
101 |
return null; |
102 |
} |
103 |
} |
104 |
} |
105 |
); |
106 |
//Fix for NPE on WinXP L&F - either may be null - Tim |
107 |
Font f = UIManager.getFont("controlFont"); |
108 |
Integer i = (Integer) UIManager.get("nbDefaultFontSize"); |
109 |
if (i == null) { |
110 |
i = new Integer(11); //fudge the default if not present |
111 |
} |
112 |
if (f == null) { |
113 |
f = getFont(); |
114 |
} |
115 |
|
116 |
// perform additional preferred size computations for larger fonts |
117 |
if (f.getSize() > i.intValue()) { // NOI18N |
118 |
sizeTTVCarefully(); |
119 |
} else { |
120 |
// direct sizing for default situation |
121 |
treeTableView.setPreferredSize( |
122 |
new Dimension (DEF_1_COL_WIDTH + DEF_0_COL_WIDTH + DEF_TREE_WIDTH, |
123 |
DEF_HEIGHT) |
124 |
); |
125 |
treeTableView.setTreePreferredWidth(DEF_TREE_WIDTH); |
126 |
treeTableView.setTableColumnPreferredWidth(0, DEF_0_COL_WIDTH); |
127 |
treeTableView.setTableColumnPreferredWidth(1, DEF_1_COL_WIDTH); |
128 |
} |
129 |
treeTableView.setPopupAllowed(false); |
130 |
treeTableView.setDefaultActionAllowed(false); |
131 |
|
132 |
// install proper border |
133 |
treeTableView.setBorder((Border)UIManager.get("Nb.ScrollPane.border")); // NOI18N |
134 |
|
135 |
manager = explorerPanel.getExplorerManager(); |
136 |
ModuleNode node = new ModuleNode(true); |
137 |
manager.setRootContext(node); |
138 |
|
139 |
initAccessibility(); |
140 |
} |
141 |
} |
142 |
|
143 |
/** Computes and sets right preferred sizes of TTV columns. |
144 |
* Sizes of columns are computed as maximum of default values and |
145 |
* header text length. Size of tree is aproximate, grows linearly with |
146 |
* font size. |
147 |
*/ |
148 |
private void sizeTTVCarefully () { |
149 |
Font headerFont = (Font)UIManager.getDefaults().get("TableHeader.font"); // NOI18N |
150 |
Font tableFont = (Font)UIManager.getDefaults().get("Table.font"); // NOI18N |
151 |
FontMetrics headerFm = getFontMetrics(headerFont); |
152 |
|
153 |
int enabledColWidth = Math.max(DEF_0_COL_WIDTH, headerFm.stringWidth( |
154 |
NbBundle.getMessage (ModuleNode.class, "PROP_modules_enabled")) + 20 |
155 |
); |
156 |
int specColWidth = Math.max(DEF_1_COL_WIDTH, headerFm.stringWidth( |
157 |
NbBundle.getMessage (ModuleNode.class, "PROP_modules_specversion")) + 20 |
158 |
); |
159 |
int defFontSize = UIManager.getDefaults().getInt("nbDefaultFontSize"); |
160 |
int treeWidth = DEF_TREE_WIDTH + 10 * (tableFont.getSize() - defFontSize); |
161 |
|
162 |
treeTableView.setPreferredSize( |
163 |
new Dimension (treeWidth + enabledColWidth + specColWidth, |
164 |
DEF_HEIGHT + 10 * (tableFont.getSize() - defFontSize)) |
165 |
); |
166 |
treeTableView.setTreePreferredWidth(treeWidth); |
167 |
treeTableView.setTableColumnPreferredWidth(0, enabledColWidth); |
168 |
treeTableView.setTableColumnPreferredWidth(1, specColWidth); |
169 |
} |
170 |
|
171 |
/** This method is called from within the constructor to |
172 |
* initialize the form. |
173 |
* WARNING: Do NOT modify this code. The content of this method is |
174 |
* always regenerated by the Form Editor. |
175 |
*/ |
176 |
private void initComponents() {//GEN-BEGIN:initComponents |
177 |
java.awt.GridBagConstraints gridBagConstraints; |
178 |
|
179 |
tableLabel = new javax.swing.JLabel(); |
180 |
explorerPanel = new org.openide.explorer.ExplorerPanel(); |
181 |
treeTableView = new org.openide.explorer.view.TreeTableView(); |
182 |
descriptionLabel = new javax.swing.JLabel(); |
183 |
descriptionPane = new javax.swing.JScrollPane(); |
184 |
descriptionArea = new javax.swing.JTextArea(); |
185 |
|
186 |
setLayout(new java.awt.GridBagLayout()); |
187 |
|
188 |
setName(NbBundle.getMessage(ModuleSelectionPanel.class, "LBL_SetupWizardModuleInstallation")); |
189 |
tableLabel.setLabelFor(treeTableView); |
190 |
tableLabel.setText(NbBundle.getMessage(ModuleSelectionPanel.class, "LBL_SetupWizardCheckModules")); |
191 |
gridBagConstraints = new java.awt.GridBagConstraints(); |
192 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; |
193 |
gridBagConstraints.insets = new java.awt.Insets(0, 1, 5, 0); |
194 |
add(tableLabel, gridBagConstraints); |
195 |
|
196 |
explorerPanel.add(treeTableView, java.awt.BorderLayout.CENTER); |
197 |
|
198 |
gridBagConstraints = new java.awt.GridBagConstraints(); |
199 |
gridBagConstraints.gridx = 0; |
200 |
gridBagConstraints.gridy = 1; |
201 |
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; |
202 |
gridBagConstraints.weightx = 1.0; |
203 |
gridBagConstraints.weighty = 1.0; |
204 |
gridBagConstraints.insets = new java.awt.Insets(0, 0, 11, 0); |
205 |
add(explorerPanel, gridBagConstraints); |
206 |
|
207 |
descriptionLabel.setLabelFor(descriptionArea); |
208 |
descriptionLabel.setText(NbBundle.getMessage(ModuleSelectionPanel.class, "LBL_SetupWizardDescription")); |
209 |
gridBagConstraints = new java.awt.GridBagConstraints(); |
210 |
gridBagConstraints.gridx = 0; |
211 |
gridBagConstraints.gridy = 2; |
212 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; |
213 |
gridBagConstraints.insets = new java.awt.Insets(0, 1, 5, 0); |
214 |
add(descriptionLabel, gridBagConstraints); |
215 |
|
216 |
descriptionPane.setMinimumSize(new java.awt.Dimension(22, 80)); |
217 |
descriptionPane.setPreferredSize(new java.awt.Dimension(50, 80)); |
218 |
descriptionArea.setEditable(false); |
219 |
descriptionArea.setLineWrap(true); |
220 |
descriptionArea.setWrapStyleWord(true); |
221 |
descriptionPane.setViewportView(descriptionArea); |
222 |
|
223 |
gridBagConstraints = new java.awt.GridBagConstraints(); |
224 |
gridBagConstraints.gridx = 0; |
225 |
gridBagConstraints.gridy = 3; |
226 |
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; |
227 |
add(descriptionPane, gridBagConstraints); |
228 |
|
229 |
}//GEN-END:initComponents |
230 |
|
231 |
private void prevButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_prevButtonActionPerformed |
232 |
// Add your handling code here: |
233 |
}//GEN-LAST:event_prevButtonActionPerformed |
234 |
|
235 |
// Variables declaration - do not modify//GEN-BEGIN:variables |
236 |
private javax.swing.JTextArea descriptionArea; |
237 |
private javax.swing.JLabel descriptionLabel; |
238 |
private javax.swing.JScrollPane descriptionPane; |
239 |
private org.openide.explorer.ExplorerPanel explorerPanel; |
240 |
private javax.swing.JLabel tableLabel; |
241 |
private org.openide.explorer.view.TreeTableView treeTableView; |
242 |
// End of variables declaration//GEN-END:variables |
243 |
|
244 |
private ExplorerManager manager; |
245 |
|
246 |
/** Handling of property changes in node structure and setup wizard descriptor |
247 |
*/ |
248 |
public void propertyChange(PropertyChangeEvent evt) { |
249 |
if ((evt.getSource() == manager) |
250 |
&& (manager.PROP_SELECTED_NODES.equals(evt.getPropertyName()))) { |
251 |
|
252 |
Node[] nodes = manager.getSelectedNodes(); |
253 |
String text = ""; // NOI18N |
254 |
if (nodes.length == 1) { |
255 |
InstanceCookie inst = (InstanceCookie)nodes[0].getCookie(InstanceCookie.class); |
256 |
if (inst != null) { |
257 |
try { |
258 |
if (inst.instanceClass() == ModuleBean.class) { |
259 |
ModuleBean bean = (ModuleBean)inst.instanceCreate(); |
260 |
text = bean.getLongDescription(); |
261 |
} |
262 |
} catch (IOException ioe) { |
263 |
// ignore |
264 |
} catch (ClassNotFoundException cnfe) { |
265 |
// ignore |
266 |
} |
267 |
} |
268 |
} |
269 |
descriptionArea.setText(text); |
270 |
descriptionArea.setCaretPosition(0); |
271 |
} else if ((evt.getSource() instanceof WizardDescriptor) |
272 |
&& (WizardDescriptor.PROP_VALUE.equals(evt.getPropertyName()))) { |
273 |
|
274 |
WizardDescriptor wd = (WizardDescriptor)evt.getSource(); |
275 |
if ((wd.getValue() == wd.CANCEL_OPTION) || (wd.getValue() == wd.CLOSED_OPTION)) { |
276 |
wd.removePropertyChangeListener(this); |
277 |
allModules.cancel(); |
278 |
} else if (wd.getValue() == wd.FINISH_OPTION) { |
279 |
wd.removePropertyChangeListener(this); |
280 |
allModules.resume(); |
281 |
} |
282 |
} |
283 |
} |
284 |
|
285 |
|
286 |
/** Initialize accesibility |
287 |
*/ |
288 |
public void initAccessibility(){ |
289 |
|
290 |
java.util.ResourceBundle b = NbBundle.getBundle(this.getClass()); |
291 |
|
292 |
this.getAccessibleContext().setAccessibleDescription(b.getString("ACSD_ModuleSelectionPanel")); |
293 |
|
294 |
tableLabel.setDisplayedMnemonic(b.getString("LBL_SetupWizardCheckModules_MNE").charAt(0)); |
295 |
tableLabel.getAccessibleContext().setAccessibleDescription(b.getString("ACSD_tableLabel")); |
296 |
|
297 |
descriptionLabel.setDisplayedMnemonic(b.getString("LBL_SetupWizardDescription_MNE").charAt(0)); |
298 |
descriptionLabel.getAccessibleContext().setAccessibleDescription(b.getString("ACSD_descriptionLabel")); |
299 |
} |
300 |
|
301 |
public void initFromSettings(Object settings) { |
302 |
if (settings instanceof WizardDescriptor) { |
303 |
((WizardDescriptor)settings).addPropertyChangeListener(this); |
304 |
} |
305 |
addNotify(); |
306 |
manager.addPropertyChangeListener(this); |
307 |
allModules.pause(); |
308 |
|
309 |
} |
310 |
/** Provides the wizard panel with the opportunity to update the |
311 |
* settings with its current customized state. |
312 |
* Rather than updating its settings with every change in the GUI, it should collect them, |
313 |
* and then only save them when requested to by this method. |
314 |
* Also, the original settings passed to {@link #readSettings} should not be modified (mutated); |
315 |
* rather, the (copy) passed in here should be mutated according to the collected changes. |
316 |
* This method can be called multiple times on one instance of <code>WizardDescriptor.Panel</code>. |
317 |
* @param settings the object representing a settings of the wizard |
318 |
*/ |
319 |
public void storeSettings (Object settings) { |
320 |
manager.removePropertyChangeListener(this); |
321 |
} |
322 |
|
323 |
|
324 |
} |