|
What this is
Other links
The source code/*
* Sun Public License Notice
*
* The contents of this file are subject to the Sun Public License
* Version 1.0 (the "License"). You may not use this file except in
* compliance with the License. A copy of the License is available at
* http://www.sun.com/
*
* The Original Code is NetBeans. The Initial Developer of the Original
* Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
* Microsystems, Inc. All Rights Reserved.
*/
package org.netbeans.core.ui;
import javax.swing.UIManager;
import javax.swing.plaf.basic.BasicBorders;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.*;
import javax.swing.event.*;
import java.util.*;
import java.awt.*;
import java.awt.Font;
import java.awt.font.LineMetrics;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeEvent;
import org.openide.WizardDescriptor;
import org.openide.nodes.*;
import org.openide.util.NbBundle;
import org.openide.explorer.ExplorerManager;
import org.openide.cookies.InstanceCookie;
import java.io.IOException;
/** Module selection panel allows user to enable/disable modules in setup wizard
*
* @author cledantec, jrojcek, Jesse Glick
*/
public class ModuleSelectionPanel extends javax.swing.JPanel
implements PropertyChangeListener {
/** See org.openide.WizardDescriptor.PROP_CONTENT_SELECTED_INDEX
*/
private static final String PROP_CONTENT_SELECTED_INDEX = "WizardPanel_contentSelectedIndex"; // NOI18N
/** See org.openide.WizardDescriptor.PROP_CONTENT_DATA
*/
private static final String PROP_CONTENT_DATA = "WizardPanel_contentData"; // NOI18N
// SetupWizard has to load it eagerly too, so no harm here.
private final ModuleBean.AllModulesBean allModules = ModuleBean.AllModulesBean.getDefault();
/** default size values */
private static final int DEF_TREE_WIDTH = 320;
private static final int DEF_0_COL_WIDTH = 60;
private static final int DEF_1_COL_WIDTH = 150;
private static final int DEF_HEIGHT = 250;
/** Creates new form wizardFrame */
public ModuleSelectionPanel() {
putClientProperty(PROP_CONTENT_SELECTED_INDEX, new Integer(0));
String name = NbBundle.getMessage(ModuleSelectionPanel.class, "LBL_SetupWizardModuleInstallation");
putClientProperty(PROP_CONTENT_DATA, new String[] { name });
setName(name);
}
/** Avoid initializing GUI, and allModules, until needed. */
public void addNotify() {
super.addNotify();
if (treeTableView != null) return;
synchronized (getTreeLock()) {
initComponents();
treeTableView.setProperties(
new Node.Property[]{
new PropertySupport.ReadWrite (
"enabled", // NOI18N
Boolean.TYPE,
org.openide.util.NbBundle.getMessage (ModuleNode.class, "PROP_modules_enabled"),
org.openide.util.NbBundle.getMessage (ModuleNode.class, "HINT_modules_enabled")
) {
public Object getValue () {
return null;
}
public void setValue (Object o) {
}
},
new PropertySupport.ReadOnly (
"specificationVersion", // NOI18N
String.class,
org.openide.util.NbBundle.getMessage (ModuleNode.class, "PROP_modules_specversion"),
org.openide.util.NbBundle.getMessage (ModuleNode.class, "HINT_modules_specversion")
) {
public Object getValue () {
return null;
}
}
}
);
//Fix for NPE on WinXP L&F - either may be null - Tim
Font f = UIManager.getFont("controlFont");
Integer i = (Integer) UIManager.get("nbDefaultFontSize");
if (i == null) {
i = new Integer(11); //fudge the default if not present
}
if (f == null) {
f = getFont();
}
// perform additional preferred size computations for larger fonts
if (f.getSize() > i.intValue()) { // NOI18N
sizeTTVCarefully();
} else {
// direct sizing for default situation
treeTableView.setPreferredSize(
new Dimension (DEF_1_COL_WIDTH + DEF_0_COL_WIDTH + DEF_TREE_WIDTH,
DEF_HEIGHT)
);
treeTableView.setTreePreferredWidth(DEF_TREE_WIDTH);
treeTableView.setTableColumnPreferredWidth(0, DEF_0_COL_WIDTH);
treeTableView.setTableColumnPreferredWidth(1, DEF_1_COL_WIDTH);
}
treeTableView.setPopupAllowed(false);
treeTableView.setDefaultActionAllowed(false);
// install proper border
treeTableView.setBorder((Border)UIManager.get("Nb.ScrollPane.border")); // NOI18N
manager = explorerPanel.getExplorerManager();
ModuleNode node = new ModuleNode(true);
manager.setRootContext(node);
initAccessibility();
}
}
/** Computes and sets right preferred sizes of TTV columns.
* Sizes of columns are computed as maximum of default values and
* header text length. Size of tree is aproximate, grows linearly with
* font size.
*/
private void sizeTTVCarefully () {
Font headerFont = (Font)UIManager.getDefaults().get("TableHeader.font"); // NOI18N
Font tableFont = (Font)UIManager.getDefaults().get("Table.font"); // NOI18N
FontMetrics headerFm = getFontMetrics(headerFont);
int enabledColWidth = Math.max(DEF_0_COL_WIDTH, headerFm.stringWidth(
NbBundle.getMessage (ModuleNode.class, "PROP_modules_enabled")) + 20
);
int specColWidth = Math.max(DEF_1_COL_WIDTH, headerFm.stringWidth(
NbBundle.getMessage (ModuleNode.class, "PROP_modules_specversion")) + 20
);
int defFontSize = UIManager.getDefaults().getInt("nbDefaultFontSize");
int treeWidth = DEF_TREE_WIDTH + 10 * (tableFont.getSize() - defFontSize);
treeTableView.setPreferredSize(
new Dimension (treeWidth + enabledColWidth + specColWidth,
DEF_HEIGHT + 10 * (tableFont.getSize() - defFontSize))
);
treeTableView.setTreePreferredWidth(treeWidth);
treeTableView.setTableColumnPreferredWidth(0, enabledColWidth);
treeTableView.setTableColumnPreferredWidth(1, specColWidth);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
private void initComponents() {//GEN-BEGIN:initComponents
java.awt.GridBagConstraints gridBagConstraints;
tableLabel = new javax.swing.JLabel();
explorerPanel = new org.openide.explorer.ExplorerPanel();
treeTableView = new org.openide.explorer.view.TreeTableView();
descriptionLabel = new javax.swing.JLabel();
descriptionPane = new javax.swing.JScrollPane();
descriptionArea = new javax.swing.JTextArea();
setLayout(new java.awt.GridBagLayout());
setName(NbBundle.getMessage(ModuleSelectionPanel.class, "LBL_SetupWizardModuleInstallation"));
tableLabel.setLabelFor(treeTableView);
tableLabel.setText(NbBundle.getMessage(ModuleSelectionPanel.class, "LBL_SetupWizardCheckModules"));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.insets = new java.awt.Insets(0, 1, 5, 0);
add(tableLabel, gridBagConstraints);
explorerPanel.add(treeTableView, java.awt.BorderLayout.CENTER);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.weighty = 1.0;
gridBagConstraints.insets = new java.awt.Insets(0, 0, 11, 0);
add(explorerPanel, gridBagConstraints);
descriptionLabel.setLabelFor(descriptionArea);
descriptionLabel.setText(NbBundle.getMessage(ModuleSelectionPanel.class, "LBL_SetupWizardDescription"));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 2;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.insets = new java.awt.Insets(0, 1, 5, 0);
add(descriptionLabel, gridBagConstraints);
descriptionPane.setMinimumSize(new java.awt.Dimension(22, 80));
descriptionPane.setPreferredSize(new java.awt.Dimension(50, 80));
descriptionArea.setEditable(false);
descriptionArea.setLineWrap(true);
descriptionArea.setWrapStyleWord(true);
descriptionPane.setViewportView(descriptionArea);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 3;
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
add(descriptionPane, gridBagConstraints);
}//GEN-END:initComponents
private void prevButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_prevButtonActionPerformed
// Add your handling code here:
}//GEN-LAST:event_prevButtonActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JTextArea descriptionArea;
private javax.swing.JLabel descriptionLabel;
private javax.swing.JScrollPane descriptionPane;
private org.openide.explorer.ExplorerPanel explorerPanel;
private javax.swing.JLabel tableLabel;
private org.openide.explorer.view.TreeTableView treeTableView;
// End of variables declaration//GEN-END:variables
private ExplorerManager manager;
/** Handling of property changes in node structure and setup wizard descriptor
*/
public void propertyChange(PropertyChangeEvent evt) {
if ((evt.getSource() == manager)
&& (manager.PROP_SELECTED_NODES.equals(evt.getPropertyName()))) {
Node[] nodes = manager.getSelectedNodes();
String text = ""; // NOI18N
if (nodes.length == 1) {
InstanceCookie inst = (InstanceCookie)nodes[0].getCookie(InstanceCookie.class);
if (inst != null) {
try {
if (inst.instanceClass() == ModuleBean.class) {
ModuleBean bean = (ModuleBean)inst.instanceCreate();
text = bean.getLongDescription();
}
} catch (IOException ioe) {
// ignore
} catch (ClassNotFoundException cnfe) {
// ignore
}
}
}
descriptionArea.setText(text);
descriptionArea.setCaretPosition(0);
} else if ((evt.getSource() instanceof WizardDescriptor)
&& (WizardDescriptor.PROP_VALUE.equals(evt.getPropertyName()))) {
WizardDescriptor wd = (WizardDescriptor)evt.getSource();
if ((wd.getValue() == wd.CANCEL_OPTION) || (wd.getValue() == wd.CLOSED_OPTION)) {
wd.removePropertyChangeListener(this);
allModules.cancel();
} else if (wd.getValue() == wd.FINISH_OPTION) {
wd.removePropertyChangeListener(this);
allModules.resume();
}
}
}
/** Initialize accesibility
*/
public void initAccessibility(){
java.util.ResourceBundle b = NbBundle.getBundle(this.getClass());
this.getAccessibleContext().setAccessibleDescription(b.getString("ACSD_ModuleSelectionPanel"));
tableLabel.setDisplayedMnemonic(b.getString("LBL_SetupWizardCheckModules_MNE").charAt(0));
tableLabel.getAccessibleContext().setAccessibleDescription(b.getString("ACSD_tableLabel"));
descriptionLabel.setDisplayedMnemonic(b.getString("LBL_SetupWizardDescription_MNE").charAt(0));
descriptionLabel.getAccessibleContext().setAccessibleDescription(b.getString("ACSD_descriptionLabel"));
}
public void initFromSettings(Object settings) {
if (settings instanceof WizardDescriptor) {
((WizardDescriptor)settings).addPropertyChangeListener(this);
}
addNotify();
manager.addPropertyChangeListener(this);
allModules.pause();
}
/** Provides the wizard panel with the opportunity to update the
* settings with its current customized state.
* Rather than updating its settings with every change in the GUI, it should collect them,
* and then only save them when requested to by this method.
* Also, the original settings passed to {@link #readSettings} should not be modified (mutated);
* rather, the (copy) passed in here should be mutated according to the collected changes.
* This method can be called multiple times on one instance of
|
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.