1 19 20 package org.netbeans.core.output; 21 22 import java.awt.event.KeyAdapter ; 23 import java.awt.event.KeyEvent ; 24 import java.util.Vector ; 25 import javax.swing.DefaultComboBoxModel ; 26 import javax.swing.JButton ; 27 import javax.swing.SwingUtilities ; 28 import org.openide.DialogDescriptor; 29 import org.openide.util.NbBundle; 30 31 36 public class FindDialogPanel extends javax.swing.JPanel { 37 38 static final long serialVersionUID =5048678953767663114L; 39 40 private static FindDialogPanel findPanel; 41 private static java.awt.Dialog dialog = null; 42 private static boolean accepted = false; 43 private static JButton acceptButton; 44 private Vector history = new Vector (); 45 46 47 public FindDialogPanel() { 48 initComponents (); 49 getAccessibleContext().setAccessibleName(NbBundle.getBundle(FindDialogPanel.class).getString("ACSN_Find")); 50 getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(FindDialogPanel.class).getString("ACSD_Find")); 51 findWhat.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(FindDialogPanel.class).getString("ACSD_Find_What")); 52 findWhat.getEditor().getEditorComponent().addKeyListener( new KeyAdapter () { 53 public void keyPressed(KeyEvent evt) { 54 if ( evt.getKeyCode() == KeyEvent.VK_ESCAPE ) { 55 findWhat.setPopupVisible( false ); 56 dialog.setVisible( false ); 57 } 58 } 59 }); 60 findWhat.getEditor().addActionListener( new java.awt.event.ActionListener () { 61 public void actionPerformed( java.awt.event.ActionEvent evt ) { 62 acceptButton.requestFocus(); 63 acceptButton.doClick(); 64 } 65 }); 66 bwdSearch.getAccessibleContext().setAccessibleDescription( 67 NbBundle.getMessage(FindDialogPanel.class, "ACSD_BackwardSearch")); 68 matchCase.getAccessibleContext().setAccessibleDescription( 69 NbBundle.getMessage(FindDialogPanel.class, "ACSD_MatchCase")); 70 wholeWords.getAccessibleContext().setAccessibleDescription( 71 NbBundle.getMessage(FindDialogPanel.class, "ACSD_MatchWhole")); 72 } 73 74 79 private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; 81 82 findWhatLabel = new javax.swing.JLabel (); 83 findWhat = new javax.swing.JComboBox (); 84 matchCase = new javax.swing.JCheckBox (); 85 wholeWords = new javax.swing.JCheckBox (); 86 bwdSearch = new javax.swing.JCheckBox (); 87 88 setLayout(new java.awt.GridBagLayout ()); 89 90 findWhatLabel.setDisplayedMnemonic(NbBundle.getBundle(FindDialogPanel.class).getString("LBL_Find_What_Mnemonic").charAt(0)); 91 findWhatLabel.setLabelFor(findWhat); 92 findWhatLabel.setText(org.openide.util.NbBundle.getBundle(FindDialogPanel.class).getString("LBL_Find_What")); 93 gridBagConstraints = new java.awt.GridBagConstraints (); 94 gridBagConstraints.gridx = 0; 95 gridBagConstraints.gridy = 1; 96 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 97 gridBagConstraints.insets = new java.awt.Insets (0, 12, 5, 0); 98 add(findWhatLabel, gridBagConstraints); 99 100 findWhat.setEditable(true); 101 gridBagConstraints = new java.awt.GridBagConstraints (); 102 gridBagConstraints.gridx = 1; 103 gridBagConstraints.gridy = 1; 104 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 105 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 106 gridBagConstraints.weightx = 1.0; 107 gridBagConstraints.insets = new java.awt.Insets (0, 11, 9, 10); 108 add(findWhat, gridBagConstraints); 109 110 matchCase.setMnemonic(NbBundle.getBundle(FindDialogPanel.class).getString("LBL_Find_Case_Mnemonic").charAt(0)); 111 matchCase.setText(org.openide.util.NbBundle.getBundle(FindDialogPanel.class).getString("LBL_Find_Case")); 112 matchCase.setBorder(new javax.swing.border.EmptyBorder (new java.awt.Insets (1, 1, 1, 1))); 113 gridBagConstraints = new java.awt.GridBagConstraints (); 114 gridBagConstraints.gridx = 1; 115 gridBagConstraints.gridy = 3; 116 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 117 gridBagConstraints.insets = new java.awt.Insets (0, 11, 0, 0); 118 add(matchCase, gridBagConstraints); 119 120 wholeWords.setMnemonic(NbBundle.getBundle(FindDialogPanel.class).getString("LBL_Find_Whole_Mnemonic").charAt(0)); 121 wholeWords.setText(org.openide.util.NbBundle.getBundle(FindDialogPanel.class).getString("LBL_Find_Whole")); 122 wholeWords.setBorder(new javax.swing.border.EmptyBorder (new java.awt.Insets (1, 1, 1, 1))); 123 gridBagConstraints = new java.awt.GridBagConstraints (); 124 gridBagConstraints.gridx = 1; 125 gridBagConstraints.gridy = 4; 126 gridBagConstraints.insets = new java.awt.Insets (0, 11, 0, 0); 127 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 128 add(wholeWords, gridBagConstraints); 129 130 bwdSearch.setMnemonic(NbBundle.getBundle(FindDialogPanel.class).getString("LBL_Find_Back_Mnemonic").charAt(0)); 131 bwdSearch.setText(org.openide.util.NbBundle.getBundle(FindDialogPanel.class).getString("LBL_Find_Back")); 132 bwdSearch.setBorder(new javax.swing.border.EmptyBorder (new java.awt.Insets (1, 1, 1, 1))); 133 gridBagConstraints = new java.awt.GridBagConstraints (); 134 gridBagConstraints.gridx = 2; 135 gridBagConstraints.gridy = 3; 136 gridBagConstraints.insets = new java.awt.Insets (0, 11, 0, 10); 137 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 138 add(bwdSearch, gridBagConstraints); 139 140 } 142 143 protected javax.swing.JComboBox findWhat; 145 protected javax.swing.JCheckBox bwdSearch; 146 protected javax.swing.JCheckBox matchCase; 147 protected javax.swing.JCheckBox wholeWords; 148 protected javax.swing.JLabel findWhatLabel; 149 151 152 static FindDialogPanel showFindDialog() { 153 if ( dialog == null ) 154 createDialog(); 155 156 accepted = false; 157 findPanel.init(); 158 dialog.show(); 159 160 return findPanel; 161 } 162 163 private void init() { 164 findWhat.setModel( new DefaultComboBoxModel ( history ) ); 165 166 SwingUtilities.invokeLater( new Runnable () { 167 public void run() { 168 findWhat.getEditor().getEditorComponent().requestFocus(); 169 findWhat.getEditor().selectAll(); 170 } 171 }); 172 } 173 174 boolean isAccepted() { 175 return accepted; 176 } 177 178 static String getPattern() { 179 return findPanel != null ? (String ) findPanel.findWhat.getSelectedItem() : null; 180 } 181 182 static boolean isMatchCase() { 183 return findPanel != null ? findPanel.matchCase.isSelected() : false; 184 } 185 186 static boolean isWholeWordsOnly() { 187 return findPanel != null ? findPanel.wholeWords.isSelected() : false; 188 } 189 190 static boolean isBackwardSearch() { 191 return findPanel != null ? findPanel.bwdSearch.isSelected() : false; 192 } 193 194 private void updateHistory() { 195 Object pattern = findWhat.getEditor().getItem(); 196 197 history.add( 0, pattern ); 198 for ( int i = history.size() - 1; i > 0; i-- ) { 199 if ( history.get( i ).equals( pattern ) ) { 200 history.remove( i ); 201 break; 202 } 203 } 204 } 205 206 private static void createDialog() { 207 findPanel = new FindDialogPanel(); 208 209 acceptButton = new JButton ( NbBundle.getBundle(FindDialogPanel.class).getString("BTN_Find") ); 210 acceptButton.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(FindDialogPanel.class).getString("ACSD_FindBTN")); 211 212 DialogDescriptor dialogDescriptor = new DialogDescriptor( 213 findPanel, 214 NbBundle.getBundle(FindDialogPanel.class).getString("LBL_Find_Title"), 215 true, new Object [] { acceptButton, DialogDescriptor.CANCEL_OPTION }, acceptButton, DialogDescriptor.RIGHT_ALIGN, null, new java.awt.event.ActionListener () { 221 public void actionPerformed( java.awt.event.ActionEvent evt ) { 222 if ( evt.getSource() == acceptButton ) { 223 accepted = true; 224 findPanel.updateHistory(); 225 } 226 else 227 accepted = false; 228 229 dialog.setVisible( false ); 230 } 231 }); 232 233 dialog = org.openide.DialogDisplayer.getDefault().createDialog( dialogDescriptor ); 234 dialog.getAccessibleContext().setAccessibleName( 235 NbBundle.getMessage(FindDialogPanel.class, "ACSN_Find")); dialog.getAccessibleContext().setAccessibleDescription( 237 NbBundle.getMessage(FindDialogPanel.class, "ACSD_Find")); } 239 240 } 241 | Popular Tags |