|
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 java.awt.Color; import java.awt.Dimension; import java.awt.Font; import javax.swing.*; import java.beans.*; import org.openide.ErrorManager; import org.openide.WizardDescriptor; import org.openide.util.NbBundle; import org.netbeans.core.IDESettings; import org.openide.util.AsyncGUIJob; import org.openide.util.Utilities; import org.openide.windows.WindowManager; //import org.netbeans.core.windows.WindowManagerImpl; // TEMP /** Setup wizard panel UI component that represents general IDE settings, * such as www browser, proxy or window system mode. * Plays role of UI for IDESettingsWizardPanel. * * @author jrojcek */ class IDESettingsPanel 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 private java.util.ResourceBundle bundle = NbBundle.getBundle(IDESettingsPanel.class); /** Initialization data structure for passing data between background * initialization and UI update */ private static final class InitData { PropertyEditor editor; ComboBoxModel comboModel; Icon sdiIcon, mdiIcon; }; // end of InitData /** holds init data for async initialization */ private InitData initData; /** Creates new form IDESettingsPanel */ public IDESettingsPanel() { //XXX if we could kill the initComponents(); serverLabel.setDisplayedMnemonic(bundle.getString("LBL_Server_Name_Mnemonic").charAt(0)); portLabel.setDisplayedMnemonic(bundle.getString("LBL__Port_Mnemonic").charAt(0)); // inserting space character before radiobuttons and checkboxes String string = bundle.getString("LBL_UseProxyServer"); proxyCheckBox.setText(new StringBuffer(string.length() + 1).append(' ').append(string).toString()); string = bundle.getString("LBL_SDI"); sdiRadioButton.setText(new StringBuffer(string.length() + 1).append(' ').append(string).toString()); string = bundle.getString("LBL_MDI"); mdiRadioButton.setText(new StringBuffer(string.length() + 1).append(' ').append(string).toString()); proxyCheckBox.setMnemonic(bundle.getString("LBL_UseProxyServer_Mnemonic").charAt(0)); sdiRadioButton.setMnemonic(bundle.getString("LBL_SDI_Mnemonic").charAt(0)); mdiRadioButton.setMnemonic(bundle.getString("LBL_MDI_Mnemonic").charAt(0)); javax.swing.ButtonGroup bg = new javax.swing.ButtonGroup(); bg.add(mdiRadioButton); bg.add(sdiRadioButton); putClientProperty(PROP_CONTENT_SELECTED_INDEX, new Integer(0)); putClientProperty(PROP_CONTENT_DATA, new String[] {getName()}); initAccessibility(); // asycnhronous initialization Utilities.attachInitJob(this, new AsyncGUIJobImpl ()); } //A couple static methods to fix NPEs on GTK private static Font fetchFont(String key) { Font f = UIManager.getFont (key); if (f == null) { f = UIManager.getFont("controlFont"); //NOI18N if (f == null) { f = new Font ("Dialog", Font.PLAIN, 11); //NOI18N } } return f; } private static Color fetchColor (String key, Color fallback) { Color result = UIManager.getColor(key); if (result == null) { result = fallback; } return result; } private Dimension prefSize = null; public Dimension getPreferredSize() { //Performance - avoid the repaint penalty by having the second pane //force the dialog to resize - it will eliminate three repaints if (prefSize == null) { prefSize = new Dimension(super.getPreferredSize()); prefSize.width += 100; prefSize.height +=50; } return prefSize; } /** 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; proxyCheckBox = new javax.swing.JCheckBox(); serverField = new javax.swing.JTextField(); portField = new javax.swing.JTextField(); sdiRadioButton = new javax.swing.JRadioButton(); mdiRadioButton = new javax.swing.JRadioButton(); serverLabel = new javax.swing.JLabel(); portLabel = new javax.swing.JLabel(); windowLabel = new javax.swing.JLabel(); browserLabel = new javax.swing.JLabel(); browserComboBox = new javax.swing.JComboBox(); helpTextArea = new javax.swing.JTextArea(); sdiIcon = new javax.swing.JLabel(); mdiIcon = new javax.swing.JLabel(); jTextArea1 = new javax.swing.JTextArea(); proxyLabel = new javax.swing.JLabel(); jTextArea2 = new javax.swing.JTextArea(); setLayout(new java.awt.GridBagLayout()); setName(bundle.getString("LBL_IDEPanelName")); proxyCheckBox.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { changeProxyEnabled(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 7; gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(0, 12, 0, 0); add(proxyCheckBox, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 2; gridBagConstraints.gridy = 8; gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(0, 0, 5, 60); add(serverField, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 2; gridBagConstraints.gridy = 9; gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(0, 0, 5, 160); add(portField, gridBagConstraints); sdiRadioButton.setMargin(new java.awt.Insets(0, 2, 0, 2)); sdiRadioButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { changeWindowMode(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 3; gridBagConstraints.gridy = 2; gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(0, 72, 6, 0); add(sdiRadioButton, gridBagConstraints); mdiRadioButton.setMargin(new java.awt.Insets(0, 2, 0, 2)); mdiRadioButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { changeWindowMode(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 2; gridBagConstraints.gridwidth = 3; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(0, 12, 6, 0); add(mdiRadioButton, gridBagConstraints); serverLabel.setLabelFor(serverField); serverLabel.setText(bundle.getString("LBL_Server_Name")); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 8; gridBagConstraints.gridwidth = 2; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(0, 24, 5, 12); add(serverLabel, gridBagConstraints); portLabel.setLabelFor(portField); portLabel.setText(bundle.getString("LBL_Port")); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 9; gridBagConstraints.gridwidth = 2; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(0, 24, 5, 12); add(portLabel, gridBagConstraints); windowLabel.setLabelFor(sdiRadioButton); windowLabel.setText(bundle.getString("LBL_WindowMode")); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; add(windowLabel, gridBagConstraints); browserLabel.setLabelFor(browserComboBox); browserLabel.setText(org.openide.util.NbBundle.getMessage(IDESettingsPanel.class, "CTL_BrowserLabel")); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 4; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(0, 0, 5, 12); add(browserLabel, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 4; gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(0, 0, 5, 160); add(browserComboBox, gridBagConstraints); helpTextArea.setBackground(fetchColor("Panel.background", getBackground())); helpTextArea.setColumns(53); helpTextArea.setEditable(false); helpTextArea.setFont(fetchFont("Label.font")); helpTextArea.setLineWrap(true); helpTextArea.setRows(4); helpTextArea.setText(org.openide.util.NbBundle.getMessage(IDESettingsPanel.class, "CTL_HelpTextArea")); helpTextArea.setWrapStyleWord(true); helpTextArea.setDisabledTextColor(fetchColor("textText", Color.BLACK)); helpTextArea.setEnabled(false); helpTextArea.setOpaque(false); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 5; gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.insets = new java.awt.Insets(0, 12, 24, 0); add(helpTextArea, gridBagConstraints); sdiIcon.setMinimumSize(new java.awt.Dimension(99, 77)); sdiIcon.setPreferredSize(new java.awt.Dimension(99, 77)); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 3; gridBagConstraints.gridy = 3; gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(0, 96, 24, 0); add(sdiIcon, gridBagConstraints); mdiIcon.setMinimumSize(new java.awt.Dimension(99, 77)); mdiIcon.setPreferredSize(new java.awt.Dimension(99, 77)); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 3; gridBagConstraints.gridwidth = 3; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(0, 36, 24, 0); add(mdiIcon, gridBagConstraints); jTextArea1.setBackground(fetchColor("Panel.background", getBackground())); jTextArea1.setColumns(30); jTextArea1.setEditable(false); jTextArea1.setFont(fetchFont ("Label.font")); jTextArea1.setLineWrap(true); jTextArea1.setRows(1); jTextArea1.setText(org.openide.util.NbBundle.getMessage(IDESettingsPanel.class, "LBL_Head")); jTextArea1.setWrapStyleWord(true); jTextArea1.setDisabledTextColor(fetchColor("textText", Color.BLACK)); jTextArea1.setEnabled(false); jTextArea1.setOpaque(false); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 0); add(jTextArea1, gridBagConstraints); proxyLabel.setLabelFor(sdiRadioButton); proxyLabel.setText(bundle.getString("LBL_WebProxy")); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 6; gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; add(proxyLabel, gridBagConstraints); jTextArea2.setBackground(fetchColor("Panel.background", getBackground())); jTextArea2.setColumns(53); jTextArea2.setEditable(false); jTextArea2.setFont(fetchFont("Label.font")); jTextArea2.setLineWrap(true); jTextArea2.setRows(3); jTextArea2.setText(org.openide.util.NbBundle.getMessage(IDESettingsPanel.class, "LBL_ProxyDesc")); jTextArea2.setWrapStyleWord(true); jTextArea2.setDisabledTextColor(fetchColor("textText", Color.BLACK)); jTextArea2.setEnabled(false); jTextArea2.setOpaque(false); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 10; gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 2.0; gridBagConstraints.insets = new java.awt.Insets(0, 12, 12, 0); add(jTextArea2, gridBagConstraints); }//GEN-END:initComponents private void changeProxyEnabled(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_changeProxyEnabled setProxySettingEnabled(proxyCheckBox.isSelected()); }//GEN-LAST:event_changeProxyEnabled private void setProxySettingEnabled(boolean b) { serverLabel.setEnabled(b); portLabel.setEnabled(b); serverField.setEnabled(b); portField.setEnabled(b); if (b) { // automatically transfer the focus to the proxy hostname field // whenever "use proxy" is checked serverField.requestFocus(); } } private void changeWindowMode(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_changeWindowMode if (evt.getSource() == mdiRadioButton) { uiMode = 2; // mdi } else { uiMode = 1; // sdi } }//GEN-LAST:event_changeWindowMode // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JComboBox browserComboBox; private javax.swing.JLabel browserLabel; private javax.swing.JTextArea helpTextArea; private javax.swing.JTextArea jTextArea1; private javax.swing.JTextArea jTextArea2; private javax.swing.JLabel mdiIcon; private javax.swing.JRadioButton mdiRadioButton; private javax.swing.JTextField portField; private javax.swing.JLabel portLabel; private javax.swing.JCheckBox proxyCheckBox; private javax.swing.JLabel proxyLabel; private javax.swing.JLabel sdiIcon; private javax.swing.JRadioButton sdiRadioButton; private javax.swing.JTextField serverField; private javax.swing.JLabel serverLabel; private javax.swing.JLabel windowLabel; // End of variables declaration//GEN-END:variables private int uiMode; /** property editor for web browser customization */ private PropertyEditor editor; /** Initializes component from values stored in given descriptor. * Should be called only once, in AWT thread. * Called from aggregator IDESettingsWizardPanel */ public void initFromSettings(WizardDescriptor wd) { wd.addPropertyChangeListener(this); if (Boolean.TRUE.equals(wd.getProperty("initializePanel"))) { initializePanel(); } } /** Initialize panel from NB setting */ private void initializePanel() { // asycnhronous refresh Utilities.attachInitJob(this, new AsyncGUIJobImpl ()); IDESettings settings = (IDESettings)IDESettings.findObject (IDESettings.class, true); uiMode = settings.getUIMode(); sdiRadioButton.setSelected(uiMode == 1); // SDI mdiRadioButton.setSelected(uiMode == 2); // MDI // web browser, proxy init... browserLabel.setDisplayedMnemonic (bundle.getString ("CTL_BrowserLabel_mnemonic").charAt (0)); try { proxyCheckBox.setSelected(settings.getUseProxy()); serverField.setText(settings.getProxyHost()); portField.setText(settings.getProxyPort()); setProxySettingEnabled(settings.getUseProxy()); // install post init code putClientProperty("PostInit", this); } catch (RuntimeException ex) { ErrorManager.getDefault ().notify (ex); } } /** Handling of property changes in node structure and setup wizard descriptor */ public void propertyChange(PropertyChangeEvent evt) { if ((evt.getSource() instanceof WizardDescriptor) && (WizardDescriptor.PROP_VALUE.equals(evt.getPropertyName()))) { WizardDescriptor wd = (WizardDescriptor)evt.getSource(); if (wd.getValue() == wd.FINISH_OPTION) { wd.removePropertyChangeListener(this); // set proxy IDESettings settings = (IDESettings)IDESettings.findObject(IDESettings.class, true); settings.setProxyHost(serverField.getText()); settings.setProxyPort(portField.getText()); settings.setUseProxy(proxyCheckBox.isSelected()); // set ui mode settings.setUIMode(uiMode); // set web browser if (editor != null) { try { Object o = browserComboBox.getSelectedItem (); if (o instanceof String && (o != null)) { editor.setAsText ((String)o); settings.setWWWBrowser ((org.openide.awt.HtmlBrowser.Factory)editor.getValue ()); } } catch (RuntimeException ex) { ErrorManager.getDefault ().notify (ex); } } } } } /** Initilizes accessible contexts */ private void initAccessibility(){ this.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_IDESettingsPanel")); //NOI18N browserComboBox.getAccessibleContext().setAccessibleDescription(helpTextArea.getText()); proxyCheckBox.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_proxyCheckBox")); //NOI18N sdiRadioButton.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_sdiRadioButton")); //NOI18N mdiRadioButton.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_mdiRadioButton")); //NOI18N serverField.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_serverField")); portField.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_portField")); } private class AsyncGUIJobImpl implements AsyncGUIJob { PropertyEditor initEditor; ComboBoxModel initComboModel; Icon initSdiIcon, initMdiIcon; /** Loads images and prepares list of available browsers to fill combo box. * Executed in non event dispatch thread. */ public void construct () { initEditor = PropertyEditorManager.findEditor (org.openide.awt.HtmlBrowser.Factory.class); initEditor.setValue (((IDESettings)IDESettings.findObject (IDESettings.class, true)).getWWWBrowser ()); initComboModel = new DefaultComboBoxModel(initEditor.getTags()); initSdiIcon = new ImageIcon(Utilities.loadImage("org/netbeans/core/resources/sdi.gif")); initMdiIcon = new ImageIcon(Utilities.loadImage("org/netbeans/core/resources/mdi.gif")); } /** Show SDI, MDI images, fill combo box. Executed in event dispatch thread. */ public void finished () { editor = initEditor; sdiIcon.setIcon(initSdiIcon); mdiIcon.setIcon(initMdiIcon); browserComboBox.setModel(initComboModel); browserComboBox.setSelectedItem(initEditor.getAsText()); } } } |
... 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.