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