1 19 20 package org.openide.loaders; 21 22 import java.awt.event.KeyEvent ; 23 import javax.swing.KeyStroke ; 24 import javax.swing.SwingUtilities ; 25 import javax.swing.event.ChangeEvent ; 26 import javax.swing.event.ChangeListener ; 27 import javax.swing.event.DocumentListener ; 28 import org.openide.awt.Mnemonics; 29 import org.openide.util.Utilities; 30 31 35 final class NewObjectPanel extends javax.swing.JPanel implements DocumentListener { 36 37 38 private ChangeListener listener; 39 40 41 public NewObjectPanel() { 42 initComponents (); 43 44 setName(getString("LAB_NewObjectPanelName")); 46 setBorder (new javax.swing.border.EmptyBorder (new java.awt.Insets (8, 8, 8, 8))); 47 48 newObjectName.getDocument().addDocumentListener(this); 50 newObjectName.unregisterKeyboardAction(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0)); 51 52 java.util.ResourceBundle bundle = org.openide.util.NbBundle.getBundle(NewObjectPanel.class); 53 54 setNewObjectName(""); 56 putClientProperty("WizardPanel_contentData", new String [] { getName() }); putClientProperty("WizardPanel_contentSelectedIndex", new Integer (0)); 59 newObjectName.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_NewObjectName")); getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_NewObjectPanel")); } 62 63 64 public java.awt.Dimension getPreferredSize() { 65 return TemplateWizard.PREF_DIM; 66 } 67 68 73 private void initComponents() { 75 java.awt.GridBagConstraints gridBagConstraints; 76 77 namePanel = new javax.swing.JPanel (); 78 jLabel1 = new javax.swing.JLabel (); 79 newObjectName = new javax.swing.JTextField (); 80 81 FormListener formListener = new FormListener(); 82 83 setPreferredSize(new java.awt.Dimension (560, 520)); 84 setLayout(new java.awt.BorderLayout (0, 8)); 85 86 namePanel.setPreferredSize(new java.awt.Dimension (0, 0)); 87 namePanel.setLayout(new java.awt.GridBagLayout ()); 88 89 jLabel1.setLabelFor(newObjectName); 90 java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/openide/loaders/Bundle"); org.openide.awt.Mnemonics.setLocalizedText(jLabel1, bundle.getString("CTL_NewObjectName")); gridBagConstraints = new java.awt.GridBagConstraints (); 93 gridBagConstraints.gridx = 0; 94 gridBagConstraints.gridy = 0; 95 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 96 gridBagConstraints.insets = new java.awt.Insets (0, 0, 0, 12); 97 namePanel.add(jLabel1, gridBagConstraints); 98 99 newObjectName.addFocusListener(formListener); 100 gridBagConstraints = new java.awt.GridBagConstraints (); 101 gridBagConstraints.gridx = 1; 102 gridBagConstraints.gridy = 0; 103 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 104 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 105 gridBagConstraints.weightx = 1.0; 106 gridBagConstraints.weighty = 1.0; 107 namePanel.add(newObjectName, gridBagConstraints); 108 109 add(namePanel, java.awt.BorderLayout.CENTER); 110 } 111 112 114 private class FormListener implements java.awt.event.FocusListener { 115 FormListener() {} 116 public void focusGained(java.awt.event.FocusEvent evt) { 117 if (evt.getSource() == newObjectName) { 118 NewObjectPanel.this.newObjectNameFocusGained(evt); 119 } 120 } 121 122 public void focusLost(java.awt.event.FocusEvent evt) { 123 } 124 } 126 private void packageNameFocusGained (java.awt.event.FocusEvent evt) { 128 } 130 private void packageModelChanged (javax.swing.event.ListDataEvent evt) { } 133 private void newObjectNameFocusGained(java.awt.event.FocusEvent evt) { if ( 135 Utilities.getOperatingSystem() == Utilities.OS_SOLARIS || 136 Utilities.getOperatingSystem() == Utilities.OS_SUNOS 137 ) { 138 return; 140 } 141 142 newObjectName.selectAll (); 143 } 145 private void templatesTreeValueChanged (javax.swing.event.TreeSelectionEvent evt) { } 148 149 private javax.swing.JLabel jLabel1; 151 private javax.swing.JPanel namePanel; 152 private javax.swing.JTextField newObjectName; 153 155 156 public void changedUpdate(final javax.swing.event.DocumentEvent p1) { 157 if (p1.getDocument () == newObjectName.getDocument ()) { 158 SwingUtilities.invokeLater (new Runnable () { 159 public void run () { 160 if (newObjectName.getText().equals ("")) { setNewObjectName (""); } 163 fireStateChanged(); 164 } 165 }); 166 } 167 } 168 169 public void removeUpdate(final javax.swing.event.DocumentEvent p1) { 170 changedUpdate (p1); 171 } 172 173 public void insertUpdate(final javax.swing.event.DocumentEvent p1) { 174 changedUpdate (p1); 175 } 176 177 public void addNotify () { 178 super.addNotify (); 179 newObjectName.requestFocus (); 180 } 181 182 186 void addChangeListener (ChangeListener l) { 187 if (listener != null) { 188 throw new IllegalStateException (); 189 } 190 listener = l; 191 } 192 193 196 void removeChangeListener (ChangeListener l) { 197 listener = null; 198 } 199 200 202 private void fireStateChanged () { 203 if (listener != null) { 204 listener.stateChanged (new ChangeEvent (this)); 205 } 206 } 207 208 211 private void setNewObjectName (String name) { 212 String n = name; 213 if (name == null || name.length () == 0) { 214 n = defaultNewObjectName (); 215 } 216 217 newObjectName.getDocument().removeDocumentListener(this); 218 newObjectName.setText (n); 219 newObjectName.getDocument().addDocumentListener(this); 220 221 if (name == null || name.length () == 0) { 222 newObjectName.selectAll (); 223 } 224 } 225 226 227 public String getNewObjectName() { 228 return newObjectName.getText(); 229 } 230 231 234 static String defaultNewObjectName () { 235 return getString("FMT_DefaultNewObjectName"); } 237 238 private static String getString(String key) { 239 return org.openide.util.NbBundle.getBundle(NewObjectPanel.class).getString(key); 240 } 241 } 242 | Popular Tags |