1 19 20 package org.netbeans.modules.db.explorer.dlg; 21 22 import java.awt.*; 23 import java.awt.event.*; 24 import java.util.*; 25 import javax.swing.*; 26 import org.openide.util.NbBundle; 27 import javax.swing.border.EmptyBorder ; 28 import org.openide.DialogDescriptor; 29 import org.openide.DialogDisplayer; 30 import org.netbeans.modules.db.explorer.*; 31 import org.openide.awt.Mnemonics; 32 33 36 public class LabeledTextFieldDialog { 37 boolean result = false; 38 Dialog dialog = null; 39 Object combosel = null; 40 JTextField field; 41 JTextArea notesarea; 42 JButton edButton; 43 JLabel label; 44 final String original_notes; 45 private ResourceBundle bundle = NbBundle.getBundle("org.netbeans.modules.db.resources.Bundle"); 47 public LabeledTextFieldDialog(String notes) { 48 String title = bundle.getString("RecreateTableRenameTable"); 49 String lab = bundle.getString("RecreateTableNewName"); 50 original_notes = notes; 51 try { 52 JPanel pane = new JPanel(); 53 pane.setBorder(new EmptyBorder (new Insets(5,5,5,5))); 54 GridBagLayout layout = new GridBagLayout(); 55 GridBagConstraints con = new GridBagConstraints (); 56 pane.setLayout (layout); 57 58 60 label = new JLabel(); 61 Mnemonics.setLocalizedText(label, lab); 62 label.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_RecreateTableNewNameA11yDesc")); con.anchor = GridBagConstraints.WEST; 64 con.insets = new java.awt.Insets (2, 2, 2, 2); 65 con.gridx = 0; 66 con.gridy = 0; 67 layout.setConstraints(label, con); 68 pane.add(label); 69 70 72 con.fill = GridBagConstraints.HORIZONTAL; 73 con.weightx = 1.0; 74 con.gridx = 1; 75 con.gridy = 0; 76 con.insets = new java.awt.Insets (2, 2, 2, 2); 77 field = new JTextField(35); 78 field.getAccessibleContext().setAccessibleName(bundle.getString("ACS_RecreateTableNewNameTextFieldA11yName")); field.setToolTipText(bundle.getString("ACS_RecreateTableNewNameTextFieldA11yDesc")); label.setLabelFor(field); 81 layout.setConstraints(field, con); 82 pane.add(field); 83 84 86 JLabel desc = new JLabel(); 87 Mnemonics.setLocalizedText(desc, bundle.getString("RecreateTableRenameNotes")); 88 desc.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_RecreateTableRenameNotesA11yDesc")); con.anchor = GridBagConstraints.WEST; 90 con.gridx = 0; 91 con.gridy = 2; 92 con.weighty = 2.0; 93 layout.setConstraints(desc, con); 94 pane.add(desc); 95 96 98 notesarea = new JTextArea(notes, 10, 50); 99 notesarea.setEditable(false); 100 notesarea.setLineWrap(true); 101 notesarea.setWrapStyleWord(true); 102 notesarea.setFont(label.getFont()); 103 notesarea.setBackground(label.getBackground()); notesarea.setEnabled(false); 105 notesarea.setDisabledTextColor(javax.swing.UIManager.getColor("Label.foreground")); 106 notesarea.getAccessibleContext().setAccessibleName(bundle.getString("ACS_RecreateTableTableScriptTextAreaA11yName")); notesarea.setToolTipText(bundle.getString("ACS_RecreateTableTableScriptTextAreaA11yDesc")); desc.setLabelFor(notesarea); 109 con.weightx = 1.0; 110 con.weighty = 1.0; 111 con.gridwidth = 2; 112 con.fill = GridBagConstraints.BOTH; 113 con.insets = new java.awt.Insets (10, 0, 0, 0); 114 con.gridx = 0; 115 con.gridy = 3; 116 notesarea.setBorder(new EmptyBorder (new Insets(5,5,5,5))); 117 JScrollPane spane = new JScrollPane(notesarea); 118 layout.setConstraints(spane, con); 119 pane.add(spane); 120 121 edButton = new JButton(); 123 Mnemonics.setLocalizedText(edButton, bundle.getString("EditCommand")); edButton.setToolTipText(bundle.getString("ACS_EditCommandA11yDesc")); con.fill = GridBagConstraints.WEST; 126 con.weighty = 0.0; 127 con.weightx = 0.0; 128 con.gridx = 0; 129 con.gridy = 5; 130 layout.setConstraints(edButton, con); 131 pane.add(edButton); 132 133 edButton.addActionListener(new ActionListener() { 134 public void actionPerformed(ActionEvent event) { 135 if(edButton.getText().startsWith(bundle.getString("EditCommand"))) { Mnemonics.setLocalizedText(edButton, bundle.getString("ReloadCommand")); 138 edButton.setToolTipText(bundle.getString("ACS_ReloadCommandA11yDesc")); notesarea.setEditable( true ); 140 notesarea.setEnabled(true); 141 notesarea.setBackground(field.getBackground()); notesarea.requestFocus(); 143 field.setEditable( false ); 144 field.setBackground(label.getBackground()); } else { 146 Mnemonics.setLocalizedText(edButton, bundle.getString("EditCommand")); 148 edButton.setToolTipText(bundle.getString("ACS_EditCommandA11yDesc")); notesarea.setText(original_notes); 150 notesarea.setEditable( false ); 151 notesarea.setEnabled(false); 152 notesarea.setDisabledTextColor(javax.swing.UIManager.getColor("Label.foreground")); 153 field.setEditable( true ); 154 field.setBackground(notesarea.getBackground()); notesarea.setBackground(label.getBackground()); field.requestFocus(); 157 } 158 } 159 }); 160 161 ActionListener listener = new ActionListener() { 162 public void actionPerformed(ActionEvent event) { 163 if (event.getSource() == DialogDescriptor.OK_OPTION) 164 result = true; 165 else 166 result = false;; 167 } 168 }; 169 170 pane.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_RecreateTableDialogA11yDesc")); 171 172 DialogDescriptor descriptor = new DialogDescriptor(pane, title, true, listener); 173 dialog = DialogDisplayer.getDefault().createDialog(descriptor); 174 dialog.setResizable(true); 175 } catch (MissingResourceException ex) { 176 ex.printStackTrace(); 177 } 178 } 179 180 public boolean run() { 181 if (dialog != null) 182 dialog.setVisible(true); 183 184 return result; 185 } 186 187 public String getStringValue() { 188 return field.getText(); 189 } 190 191 public String getEditedCommand() { 192 return notesarea.getText(); 193 } 194 195 public boolean isEditable() { 196 return notesarea.isEditable(); 197 } 198 199 public void setStringValue(String val) { 200 field.setText(val); 201 } 202 } 203 | Popular Tags |