1 19 20 package org.netbeans.editor.ext; 21 22 import java.awt.Component ; 23 import java.awt.Dialog ; 24 import java.awt.event.*; 25 import java.beans.PropertyChangeEvent ; 26 import java.beans.PropertyChangeListener ; 27 import java.util.ArrayList ; 28 import java.util.List ; 29 import java.util.Map ; 30 import java.util.HashMap ; 31 import java.util.Collections ; 32 import java.util.ResourceBundle ; 33 import java.util.Vector ; 34 import javax.swing.*; 35 import javax.swing.JComponent ; 36 import javax.swing.text.JTextComponent ; 37 import javax.swing.text.BadLocationException ; 38 import javax.swing.text.Position ; 39 import org.netbeans.editor.BaseKit; 40 import org.netbeans.editor.BaseTextUI; 41 import org.netbeans.editor.DrawLayerFactory; 42 import org.netbeans.editor.EditorUI; 43 import org.netbeans.editor.FindSupport.SearchPatternWrapper; 44 import org.netbeans.editor.SettingsNames; 45 import org.netbeans.editor.SettingsUtil; 46 import org.netbeans.editor.FindSupport; 47 import org.netbeans.editor.DialogSupport; 48 import org.netbeans.editor.GuardedException; 49 import org.netbeans.editor.Utilities; 50 import org.netbeans.editor.BaseCaret; 51 import java.util.Iterator ; 52 import javax.swing.text.Caret ; 53 import javax.swing.text.DefaultEditorKit ; 54 import javax.swing.text.Document ; 55 import org.netbeans.editor.BaseDocument; 56 import org.openide.util.NbBundle; 57 58 65 66 public class FindDialogSupport extends WindowAdapter implements ActionListener { 67 68 74 private static Object dialogLock = new Object (); 75 76 77 private static boolean isReplaceDialog = false; 78 79 80 private static JButton findButtons[]; 81 82 private static JButton findDialogButtons[]; 83 private static JButton replaceDialogButtons[]; 84 85 86 private static FindPanel findPanel; 87 88 89 private static Dialog findDialog = null; 90 91 private int caretPosition; 92 93 private static FindDialogSupport singleton = null; 94 private static PropertyChangeListener historyChangeListener; 95 96 private boolean findPerformed = false; 97 98 private static int xPos = Integer.MIN_VALUE; 99 private static int yPos = Integer.MIN_VALUE; 100 101 106 private static boolean dialogInvokedViaKeystroke; 107 108 public static FindDialogSupport getFindDialogSupport() { 109 if (singleton == null) { 110 singleton = new FindDialogSupport(); 111 } 112 return singleton; 113 } 114 115 private FindDialogSupport() { 116 } 117 118 private void createFindButtons() { 119 if (findButtons == null) { 120 ResourceBundle bundle = NbBundle.getBundle(BaseKit.class); 121 findButtons = new JButton[] { 122 new JButton(bundle.getString("find-button-find")), new JButton(bundle.getString("find-button-replace")), new JButton(bundle.getString("find-button-replace-all")), new JButton(bundle.getString("find-button-cancel")) }; 127 128 findButtons[0].setMnemonic(bundle.getString("find-button-find-mnemonic").charAt(0)); findButtons[1].setMnemonic(bundle.getString("find-button-replace-mnemonic").charAt(0)); findButtons[2].setMnemonic(bundle.getString("find-button-replace-all-mnemonic").charAt(0)); 132 findButtons[0].getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_find-button-find")); findButtons[1].getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_find-button-replace")); findButtons[2].getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_find-button-replace-all")); findButtons[3].getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_find-button-cancel")); 137 findDialogButtons = new JButton[2]; 138 findDialogButtons[0] = findButtons[0]; 139 findDialogButtons[1] = findButtons[3]; 140 141 replaceDialogButtons = new JButton[4]; 142 replaceDialogButtons[0] = findButtons[0]; 143 replaceDialogButtons[1] = findButtons[1]; 144 replaceDialogButtons[2] = findButtons[2]; 145 replaceDialogButtons[3] = findButtons[3]; 146 } 147 } 148 149 private void createFindPanel() { 150 if (findPanel == null) { 151 findPanel = new FindPanel(); 152 } 153 } 154 155 private Dialog createFindDialog(JPanel findPanel, final JButton[] buttons, 156 final ActionListener l) { 157 Dialog d = DialogSupport.createDialog( 158 isReplaceDialog 159 ? NbBundle.getBundle(BaseKit.class).getString ("replace-title") 160 : NbBundle.getBundle(BaseKit.class).getString ("find-title" ), findPanel, false, buttons, true, 0, isReplaceDialog ? 3 : 1, l ); 167 168 return d; 169 } 170 171 private void showFindDialogImpl( boolean isReplace, KeyEventBlocker blocker) { 172 dialogInvokedViaKeystroke = true; 173 synchronized( dialogLock ) { 174 if (findDialog != null && isReplaceDialog != isReplace ) { 175 xPos = findDialog.getLocation().x; 176 yPos = findDialog.getLocation().y; 177 findDialog.dispose(); 178 findDialog = null; 179 } 180 if (findDialog == null) { isReplaceDialog = isReplace; 182 createFindButtons(); 183 createFindPanel(); 184 findPanel.changeVisibility(isReplace); 185 186 findDialog = createFindDialog( findPanel, isReplace ? replaceDialogButtons : findDialogButtons, this ); 187 findDialog.addWindowListener( this ); 188 ((JDialog)findDialog).getRootPane().setFocusable(false); 189 if(xPos > Integer.MIN_VALUE){ 190 findDialog.setLocation(xPos, yPos); 191 } 192 } 193 } 195 findDialog.pack(); 196 findPanel.init(isReplace, blocker); 197 findDialog.setVisible(true); 198 findPanel.showNotify(); 199 updateCaretPosition(); 200 } 201 202 private void updateCaretPosition() { 203 JTextComponent c = Utilities.getLastActiveComponent(); 204 if (c != null) { 205 caretPosition = c.getCaret().getDot(); 206 } 207 } 208 209 public void windowActivated(WindowEvent evt) { 210 findPerformed = false; 211 createFindPanel(); 212 findPanel.initBlockSearch(); 213 updateCaretPosition(); 214 } 215 216 public void windowDeactivated(WindowEvent evt) { 217 Map findProps = findPanel.getFindProps(); 218 JTextComponent c = Utilities.getLastActiveComponent(); 219 if (c != null) { 220 boolean blockSearch = getBooleanProp(SettingsNames.FIND_BLOCK_SEARCH, findProps); 221 if (blockSearch && !findPerformed){ 222 Integer bsStartInt = (Integer )findProps.get(SettingsNames.FIND_BLOCK_SEARCH_START); 223 int bsStart = (bsStartInt == null) ? -1 : bsStartInt.intValue(); 224 Position pos = (Position ) findProps.get(SettingsNames.FIND_BLOCK_SEARCH_END); 225 int bsEnd = (pos != null) ? pos.getOffset() : -1; 226 if (bsStart >=0 && bsEnd > 0){ 227 c.select(bsStart, bsEnd); 228 } 229 }else{ 230 } 244 } 245 FindSupport.getFindSupport().incSearchReset(); 246 findPanel.resetBlockSearch(); 247 KeyEventBlocker blocker = findPanel.getBlocker(); 248 if (blocker!=null){ 249 blocker.stopBlocking(false); 250 } 251 } 252 253 public void windowClosing(WindowEvent e) { 254 hideDialog(); 255 } 256 257 public void windowClosed(WindowEvent e) { 258 synchronized (dialogLock) { 259 if (findDialog != null){ 260 xPos = findDialog.getLocation().x; 261 yPos = findDialog.getLocation().y; 262 } 263 } 264 Map findProps = findPanel.getFindProps(); 265 FindSupport.getFindSupport().incSearchReset(); 266 findPanel.resetBlockSearch(); 267 FindSupport.getFindSupport().setBlockSearchHighlight(0, 0); 268 findProps.put(SettingsNames.FIND_BLOCK_SEARCH, Boolean.FALSE); 269 findProps.put(SettingsNames.FIND_BLOCK_SEARCH_START, new Integer (0)); 270 findProps.put(SettingsNames.FIND_BLOCK_SEARCH_END, null); 271 FindSupport.getFindSupport().putFindProperties(findProps); 272 KeyEventBlocker blocker = findPanel.getBlocker(); 273 if (blocker!=null){ 274 blocker.stopBlocking(false); 275 } 276 findPanel.reset(); 277 278 Utilities.returnFocus(); 279 } 280 281 public void showFindDialog(KeyEventBlocker blocker) { 282 showFindDialogImpl(false, blocker); 283 } 284 285 public void showReplaceDialog(KeyEventBlocker blocker) { 286 showFindDialogImpl(true, blocker); 287 } 288 289 public void hideDialog() { 290 synchronized (dialogLock) { 291 if (findDialog != null){ 292 xPos = findDialog.getLocation().x; 293 yPos = findDialog.getLocation().y; 294 findDialog.dispose(); 295 } 296 findDialog = null; 297 } 298 } 299 300 private Vector getHistoryVector(){ 301 List histList = (List )FindSupport.getFindSupport().getHistory(); 302 if (histList == null) histList = new ArrayList (); 303 boolean isRegExpChecked = ((Boolean )findPanel.getFindProps().get(SettingsNames.FIND_REG_EXP)).booleanValue(); 304 Vector vec = new Vector (); 305 for (int i=0; i<histList.size(); i++){ 306 SearchPatternWrapper spw = (SearchPatternWrapper)histList.get(i); 307 String searchExpression = spw.getSearchExpression(); 308 if (isRegExpChecked == spw.isRegExp() && !vec.contains(searchExpression)){ 309 vec.add(searchExpression); 310 } 311 } 312 return vec; 313 } 314 315 private boolean getBooleanProp(String propName, Map map){ 316 Boolean b = (Boolean ) map.get(propName); 317 return (b!=null) ? b.booleanValue() : false; 318 } 319 320 public void actionPerformed(ActionEvent evt) { 321 if( findButtons == null ) return; 322 323 Object src = evt.getSource(); 324 FindSupport fSup = FindSupport.getFindSupport(); 325 Map findPanelMap = findPanel.getFindProps(); 326 327 SearchPatternWrapper spw = new SearchPatternWrapper((String )findPanelMap.get(SettingsNames.FIND_WHAT), 328 getBooleanProp(SettingsNames.FIND_WHOLE_WORDS, findPanelMap), 329 getBooleanProp(SettingsNames.FIND_MATCH_CASE, findPanelMap), 330 getBooleanProp(SettingsNames.FIND_REG_EXP, findPanelMap)); 331 332 if (src == findButtons[0]) { fSup.addToHistory(spw); 334 fSup.putFindProperties(findPanelMap); 335 fSup.find(null, false); 336 updateCaretPosition(); 337 findPerformed = true; 338 } else if (src == findButtons[1]) { fSup.addToHistory(spw); 340 findPanel.updateReplaceHistory(); 341 fSup.putFindProperties(findPanelMap); 342 try { 343 if (fSup.replace(null, false)) { fSup.find(null, false); 345 } 346 } catch (GuardedException e) { 347 } catch (BadLocationException e) { 349 e.printStackTrace(); 350 } 351 updateCaretPosition(); 352 findPerformed = true; 353 } else if (src == findButtons[2]) { fSup.addToHistory(spw); 355 findPanel.updateReplaceHistory(); 356 fSup.putFindProperties(findPanelMap); 357 fSup.replaceAll(null); 358 findPerformed = true; 359 } else if (src == findButtons[3]) { hideDialog(); 361 } 362 } 363 364 private int getBlockEndOffset(){ 365 Position pos = (Position ) FindSupport.getFindSupport().getFindProperties().get(SettingsNames.FIND_BLOCK_SEARCH_END); 366 return (pos != null) ? pos.getOffset() : -1; 367 } 368 369 370 private class FindPanel extends FindDialogPanel 371 implements ItemListener, KeyListener, ActionListener, FocusListener { 372 373 private Map findProps = Collections.synchronizedMap(new HashMap (20)); 374 private Map objToProps = Collections.synchronizedMap(new HashMap (20)); 375 376 private javax.swing.DefaultComboBoxModel findHistory = new javax.swing.DefaultComboBoxModel (); 377 private javax.swing.DefaultComboBoxModel replaceHistory = new javax.swing.DefaultComboBoxModel (); 378 379 private KeyEventBlocker blocker; 380 381 private int blockSearchStartPos = 0; 382 private int blockSearchEndPos = 0; 383 384 FindPanel() { 385 objToProps.put(findWhat, SettingsNames.FIND_WHAT); 386 objToProps.put(replaceWith, SettingsNames.FIND_REPLACE_WITH); 387 objToProps.put(highlightSearch, SettingsNames.FIND_HIGHLIGHT_SEARCH); 388 objToProps.put(incSearch, SettingsNames.FIND_INC_SEARCH); 389 objToProps.put(matchCase, SettingsNames.FIND_MATCH_CASE); 390 objToProps.put(wholeWords, SettingsNames.FIND_WHOLE_WORDS); 392 objToProps.put(regExp, SettingsNames.FIND_REG_EXP); 393 objToProps.put(bwdSearch, SettingsNames.FIND_BACKWARD_SEARCH); 394 objToProps.put(wrapSearch, SettingsNames.FIND_WRAP_SEARCH); 395 objToProps.put(blockSearch, SettingsNames.FIND_BLOCK_SEARCH); 396 397 findProps.putAll(FindSupport.getFindSupport().getFindProperties()); 398 revertMap(); 399 400 findWhat.setModel(findHistory); 401 findWhat.getEditor().setItem(getProperty(findWhat)); 402 Component editorC = findWhat.getEditor().getEditorComponent(); 403 if (editorC instanceof JComponent ) { 404 InputMap inputMap = ((JComponent )editorC).getInputMap(); 405 inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, InputEvent.SHIFT_MASK), 406 DefaultEditorKit.pasteAction); 407 inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, InputEvent.CTRL_MASK), 408 DefaultEditorKit.copyAction); 409 } 410 replaceWith.setModel(replaceHistory); 411 replaceWith.getEditor().setItem(getProperty(replaceWith)); 412 highlightSearch.setSelected(getBooleanProperty(highlightSearch)); 413 incSearch.setSelected(getBooleanProperty(incSearch)); 414 matchCase.setSelected(getBooleanProperty(matchCase)); 415 wholeWords.setSelected(getBooleanProperty(wholeWords)); 417 regExp.setSelected(getBooleanProperty(regExp)); 418 bwdSearch.setSelected(getBooleanProperty(bwdSearch)); 419 wrapSearch.setSelected(getBooleanProperty(wrapSearch)); 420 421 findWhat.getEditor().getEditorComponent().addKeyListener(this); 422 findWhat.addActionListener(this); 423 replaceWith.getEditor().getEditorComponent().addKeyListener(this); 424 replaceWith.addActionListener(this); 425 highlightSearch.addItemListener(this); 426 incSearch.addItemListener(this); 427 matchCase.addItemListener(this); 428 wholeWords.addItemListener(this); 430 regExp.addItemListener(this); 431 bwdSearch.addItemListener(this); 432 wrapSearch.addItemListener(this); 433 blockSearch.addItemListener(this); 434 historyChangeListener = new PropertyChangeListener (){ 435 public void propertyChange(PropertyChangeEvent evt){ 436 if (evt == null || !FindSupport.FIND_HISTORY_CHANGED_PROP.equals(evt.getPropertyName())){ 437 return; 438 } 439 updateFindHistory(); 440 } 441 }; 442 FindSupport.getFindSupport().addPropertyChangeListener(historyChangeListener); 443 } 444 445 protected Map getFindProps() { 446 return findProps; 447 } 448 449 private KeyEventBlocker getBlocker(){ 450 return blocker; 451 } 452 453 private void putProperty(Object component, Object value) { 454 String prop = (String )objToProps.get(component); 455 if (prop != null) { 456 findProps.put(prop, value); 457 } 458 } 459 460 private Object getProperty(Object component) { 461 String prop = (String )objToProps.get(component); 462 return (prop != null) ? findProps.get(prop) : null; 463 } 464 465 private boolean getBooleanProperty(Object component) { 466 Object prop = getProperty(component); 467 return (prop != null) ? ((Boolean )prop).booleanValue() : false; 468 } 469 470 protected void changeVisibility(boolean v) { 471 replaceWith.setVisible(v); 472 replaceWithLabel.setVisible(v); 473 } 474 475 public void resetBlockSearch(){ 476 blockSearch.setSelected(false); 477 blockSearch.setEnabled(false); 478 findProps.put(SettingsNames.FIND_BLOCK_SEARCH, Boolean.FALSE); 479 findProps.put(SettingsNames.FIND_BLOCK_SEARCH_START, new Integer (0)); 480 findProps.put(SettingsNames.FIND_BLOCK_SEARCH_END, null); 481 blockSearchStartPos = 0; 482 blockSearchEndPos = 0; 483 FindSupport.getFindSupport().setBlockSearchHighlight(0,0); 484 FindSupport.getFindSupport().putFindProperties(findProps); 485 } 486 487 private void initBlockSearch(){ 488 JTextComponent c = Utilities.getLastActiveComponent(); 489 String selText = null; 490 int startSelection = 0; 491 int endSelection = 0; 492 boolean blockSearchVisible = false; 493 494 if (c != null) { 495 startSelection = c.getSelectionStart(); 496 endSelection = c.getSelectionEnd(); 497 498 Document doc = c.getDocument(); 499 if (doc instanceof BaseDocument){ 500 BaseDocument bdoc = (BaseDocument) doc; 501 try{ 502 int startLine = Utilities.getLineOffset(bdoc, startSelection); 503 int endLine = Utilities.getLineOffset(bdoc, endSelection); 504 if (endLine > startLine) { 505 blockSearchVisible = true; 506 } 507 } catch (BadLocationException ble){ 508 } 509 } 510 511 caretPosition = bwdSearch.isSelected() ? c.getSelectionEnd() : c.getSelectionStart(); 512 513 if (blockSearchVisible == false && dialogInvokedViaKeystroke){ 514 dialogInvokedViaKeystroke = false; 515 selText = c.getSelectedText(); 516 if (selText != null) { 517 int n = selText.indexOf( '\n' ); 518 if (n >= 0 ) selText = selText.substring(0, n); 519 findWhat.getEditor().setItem(selText); 520 changeFindWhat(true); 521 } 522 } 523 524 blockSearchStartPos = blockSearchVisible ? startSelection : 0; 525 blockSearchEndPos = blockSearchVisible ? endSelection : 0; 526 527 try{ 528 blockSearch.setEnabled(blockSearchVisible); 529 blockSearch.setSelected(blockSearchVisible); 530 findProps.put(SettingsNames.FIND_BLOCK_SEARCH, Boolean.valueOf(blockSearchVisible)); 531 findProps.put(SettingsNames.FIND_BLOCK_SEARCH_START, new Integer (blockSearchStartPos)); 532 int be = getBlockEndOffset(); 533 if (be < 0){ 534 findProps.put(SettingsNames.FIND_BLOCK_SEARCH_END, doc.createPosition(blockSearchEndPos)); 535 }else{ 536 blockSearchEndPos = be; 537 } 538 FindSupport.getFindSupport().setBlockSearchHighlight(blockSearchStartPos, blockSearchEndPos); 539 }catch(BadLocationException ble){ 540 blockSearch.setSelected(false); 541 findProps.put(SettingsNames.FIND_BLOCK_SEARCH, Boolean.FALSE); 542 findProps.put(SettingsNames.FIND_BLOCK_SEARCH_START, null); 543 } 544 } 545 546 } 547 548 protected void init(boolean isReplace, KeyEventBlocker blocker) { 549 this.blocker = blocker; 550 findHistory.setSelectedItem(null); 551 replaceHistory.setSelectedItem(null); 552 findWhat.getEditor().getEditorComponent().addFocusListener(this); 553 if (isReplace) { 554 replaceWith.getEditor().getEditorComponent().addFocusListener(this); 555 } 556 557 findProps.putAll(FindSupport.getFindSupport().getFindProperties()); 558 revertMap(); 559 560 highlightSearch.setSelected(getBooleanProperty(highlightSearch)); 561 incSearch.setSelected(getBooleanProperty(incSearch)); 562 matchCase.setSelected(getBooleanProperty(matchCase)); 563 wholeWords.setSelected(getBooleanProperty(wholeWords)); 565 boolean regExpValue = getBooleanProperty(regExp); 566 regExp.setSelected(regExpValue); 567 wholeWords.setEnabled(!regExpValue); 568 incSearch.setEnabled(!regExpValue); 569 bwdSearch.setSelected(getBooleanProperty(bwdSearch)); 570 wrapSearch.setSelected(getBooleanProperty(wrapSearch)); 571 findHistory = new DefaultComboBoxModel(getHistoryVector()); 572 findWhat.setModel(findHistory); 573 } 574 575 protected void reset() { 576 this.blocker = null; 577 } 578 579 protected void showNotify() { 580 boolean focused = findWhat.getEditor().getEditorComponent().requestFocusInWindow(); 582 if (focused == false){ 583 SwingUtilities.invokeLater(new Runnable (){ 584 public void run(){ 585 findWhat.getEditor().getEditorComponent().requestFocusInWindow(); 586 } 587 }); 588 } 589 } 590 591 private void updateHistory(JComboBox c, javax.swing.DefaultComboBoxModel history) { 592 Object item = c.getEditor().getItem(); 593 if( item != null && !item.equals("")) { history.removeElement(item); 595 history.insertElementAt(item, 0); 596 history.setSelectedItem(null); 597 } 598 c.getEditor().setItem(item); 599 } 600 601 protected void updateFindHistory() { 602 611 Object obj = findWhat.getEditor().getItem(); 612 findHistory = new DefaultComboBoxModel(getHistoryVector()); 613 findWhat.setModel(findHistory); 614 if (obj != null){ 615 findWhat.getEditor().setItem(obj); 616 } 617 } 618 619 protected void updateReplaceHistory() { 620 updateHistory(replaceWith, replaceHistory); 621 } 622 623 private void revertMap(){ 624 Object prop = findProps.get(FindSupport.REVERT_MAP); 625 if (!(prop instanceof Map )) return; 626 Map revertMap = (Map )prop; 627 628 for( Iterator i = revertMap.keySet().iterator(); i.hasNext(); ) { 629 String key = (String )i.next(); 630 631 Object obj = findProps.get(key); 632 boolean value = ( obj != null ) ? ((Boolean )obj).booleanValue() : false; 633 if (value != ((Boolean )revertMap.get(key)).booleanValue()); 634 findProps.put(key, value ? Boolean.FALSE : Boolean.TRUE); 635 } 636 637 findProps.put(FindSupport.REVERT_MAP, null); 638 } 639 640 private void changeFindWhat(boolean performIncSearch) { 641 Object old = getProperty(findWhat); 642 Object cur = findWhat.getEditor().getItem(); 643 if ((old == null && cur != null && !cur.equals("")) || (old != null && !old.equals(cur))) { putProperty(findWhat, cur); 645 if (performIncSearch){ 646 findPerformed = FindSupport.getFindSupport().incSearch(getFindProps(), caretPosition); 647 } 648 } 649 } 650 651 private void changeReplaceWith() { 652 Object old = getProperty(replaceWith); 653 Object cur = replaceWith.getEditor().getItem(); 654 if ((old == null && cur != null && !cur.equals("")) || (old != null && !old.equals(cur))) { putProperty(replaceWith, cur); 656 } 657 } 658 659 private void postChangeCombos(final boolean performIncSearch) { 660 SwingUtilities.invokeLater( 661 new Runnable () { 662 public void run() { 663 changeFindWhat(performIncSearch); 664 changeReplaceWith(); 665 } 666 } 667 ); 668 } 669 670 public void keyPressed(KeyEvent evt) { 671 if (evt.getKeyChar() == '\n') { 672 evt.consume(); 673 } 674 } 675 676 public void keyReleased(KeyEvent evt) { 677 if (evt.getKeyChar() == '\n') { 678 evt.consume(); 679 } else if (evt.getKeyCode() == KeyEvent.VK_INSERT){ 680 postChangeCombos(true); 681 } 682 } 683 684 public void keyTyped(KeyEvent evt) { 685 if (evt.getKeyChar() == '\n') { 686 findButtons[0].doClick(20); 687 evt.consume(); 688 ((JComboBox)((JTextField)evt.getSource()).getParent()).hidePopup(); 689 } else { 690 postChangeCombos(true); 691 } 692 } 693 694 public void itemStateChanged(ItemEvent evt) { 695 Boolean val = (evt.getStateChange() == ItemEvent.SELECTED) ? Boolean.TRUE 696 : Boolean.FALSE; 697 if (evt.getItem() == bwdSearch){ 698 if (blockSearch.isEnabled() && blockSearch.isSelected()) { 699 boolean value = val.booleanValue(); 700 JTextComponent c = Utilities.getLastActiveComponent(); 701 if (c!=null){ 702 c.getCaret().setDot(value ? blockSearchEndPos : blockSearchStartPos); 703 updateCaretPosition(); 704 } 705 706 } 707 } 708 if (evt.getItem() == regExp){ 709 boolean value = !val.booleanValue(); 710 incSearch.setEnabled(value); 711 wholeWords.setEnabled(value); 712 } 713 if (evt.getItem() == blockSearch){ 714 boolean value = val.booleanValue(); 715 if (value){ 716 if (blockSearchStartPos <= 0 && blockSearchEndPos <= 0 ) { 717 initBlockSearch(); 718 }else{ 719 JTextComponent c = Utilities.getLastActiveComponent(); 720 if (c!=null){ 721 c.getCaret().setDot(bwdSearch.isSelected() ? blockSearchEndPos : blockSearchStartPos); 722 updateCaretPosition(); 723 } 724 } 725 FindSupport.getFindSupport().setBlockSearchHighlight(blockSearchStartPos, blockSearchEndPos); 726 } else { 727 FindSupport.getFindSupport().putFindProperty(SettingsNames.FIND_BLOCK_SEARCH, Boolean.FALSE); 728 FindSupport.getFindSupport().setBlockSearchHighlight(0, 0); 729 } 730 } 731 732 putProperty(evt.getSource(), val); 733 734 if (evt.getItem() == regExp){ 735 updateFindHistory(); 736 } 737 } 738 739 public void actionPerformed(ActionEvent evt) { 740 postChangeCombos(false); 741 } 742 743 public void focusGained(FocusEvent e) { 744 if (e.getSource() instanceof JTextField) { 745 ((JTextField)e.getSource()).selectAll(); 746 if (blocker != null){ 747 blocker.stopBlocking(); 748 } 749 } 750 ((JComponent )e.getSource()).removeFocusListener(this); 751 } 752 753 public void focusLost(FocusEvent e) { 754 755 } 756 757 758 759 } 760 761 } 762 | Popular Tags |