1 19 20 package org.netbeans.editor.ext; 21 22 import java.awt.Rectangle ; 23 import java.awt.event.ActionEvent ; 24 import java.io.IOException ; 25 import java.util.List ; 26 import java.util.Iterator ; 27 import javax.swing.Action ; 28 import javax.swing.JPopupMenu ; 29 import javax.swing.JMenuItem ; 30 import javax.swing.KeyStroke ; 31 import javax.swing.text.Caret ; 32 import javax.swing.text.Keymap ; 33 import javax.swing.text.JTextComponent ; 34 import javax.swing.text.TextAction ; 35 import javax.swing.text.BadLocationException ; 36 import org.netbeans.editor.BaseKit; 37 import org.netbeans.editor.EditorUI; 38 import org.netbeans.editor.BaseAction; 39 import org.netbeans.editor.Utilities; 40 import org.netbeans.editor.Settings; 41 import org.netbeans.editor.BaseDocument; 42 import org.netbeans.editor.SyntaxSupport; 43 import org.netbeans.editor.Formatter; 44 import org.netbeans.lib.editor.util.CharSequenceUtilities; 45 import org.netbeans.lib.editor.util.swing.DocumentUtilities; 46 import org.openide.util.NbBundle; 47 48 49 55 public class ExtKit extends BaseKit { 56 57 60 public static final String buildPopupMenuAction = "build-popup-menu"; 62 64 public static final String showPopupMenuAction = "show-popup-menu"; 66 69 public static final String buildToolTipAction = "build-tool-tip"; 71 74 public static final String findAction = "find"; 76 79 public static final String replaceAction = "replace"; 81 84 public static final String gotoAction = "goto"; 86 87 public static final String gotoDeclarationAction = "goto-declaration"; 89 90 public static final String gotoSourceAction = "goto-source"; 92 public static final String gotoSuperImplementationAction = "goto-super-implementation"; 94 95 public static final String gotoHelpAction = "goto-help"; 97 98 public static final String matchBraceAction = "match-brace"; 100 101 public static final String selectionMatchBraceAction = "selection-match-brace"; 103 104 public static final String toggleCaseIdentifierBeginAction = "toggle-case-identifier-begin"; 106 109 public static final String codeSelectAction = "code-select"; 111 114 public static final String escapeAction = "escape"; 116 117 public static final String completionShowAction = "completion-show"; public static final String allCompletionShowAction = "all-completion-show"; 120 121 public static final String documentationShowAction = "documentation-show"; 123 124 public static final String completionTooltipShowAction = "tooltip-show"; 126 127 public static final String commentAction = "comment"; 129 130 public static final String uncommentAction = "uncomment"; 132 133 public static final String toggleToolbarAction = "toggle-toolbar"; 135 136 public static final String TRIMMED_TEXT = "trimmed-text"; 138 139 private static FindDialogSupport findDialogSupport; 140 141 private static FindAction findActionDef = new FindAction(); 142 private static ReplaceAction replaceActionDef = new ReplaceAction(); 143 private static GotoAction gotoActionDef = new GotoAction(); 144 145 146 147 private static final boolean debugPopupMenu 148 = Boolean.getBoolean("netbeans.debug.editor.popup.menu"); 150 public ExtKit() { 151 } 152 153 154 public Caret createCaret() { 155 return new ExtCaret(); 156 } 157 158 public SyntaxSupport createSyntaxSupport(BaseDocument doc) { 159 return new ExtSyntaxSupport(doc); 160 } 161 162 public Completion createCompletion(ExtEditorUI extEditorUI) { 163 return null; 164 } 165 166 public CompletionJavaDoc createCompletionJavaDoc(ExtEditorUI extEditorUI) { 167 return null; 168 } 169 170 protected EditorUI createEditorUI() { 171 return new ExtEditorUI(); 172 } 173 174 protected Action [] createActions() { 175 Action [] extActions = new Action [] { 176 new BuildPopupMenuAction(), 177 new ShowPopupMenuAction(), 178 new BuildToolTipAction(), 179 findActionDef, 180 replaceActionDef, 181 gotoActionDef, 182 new ToggleCaseIdentifierBeginAction(), 184 new MatchBraceAction(matchBraceAction, false), 185 new MatchBraceAction(selectionMatchBraceAction, true), 186 new ExtDefaultKeyTypedAction(), 189 new CompletionShowAction(), 190 new AllCompletionShowAction(), 191 new DocumentationShowAction(), 192 new CompletionTooltipShowAction() 193 }; 194 return TextAction.augmentList(super.createActions(), extActions); 195 } 196 197 202 private abstract static class BaseKitLocalizedAction extends BaseAction { 203 204 public BaseKitLocalizedAction(String name) { 205 super(name); 206 } 207 208 public BaseKitLocalizedAction(String name, int updateMask) { 209 super(name, updateMask); 210 } 211 212 protected Class getShortDescriptionBundleClass() { 213 return BaseKit.class; 214 } 215 216 } 217 218 221 public static class BuildPopupMenuAction extends BaseKitLocalizedAction { 222 223 static final long serialVersionUID =4257043398248915291L; 224 225 public BuildPopupMenuAction() { 226 super(buildPopupMenuAction, NO_RECORDING); 227 putValue(BaseAction.NO_KEYBINDING, Boolean.TRUE); 228 } 229 230 public void actionPerformed(ActionEvent evt, JTextComponent target) { 231 if (target != null) { 232 if (debugPopupMenu) { 233 System.err.println("POPUP CREATION START <<<<<"); } 235 JPopupMenu pm = buildPopupMenu(target); 236 if (debugPopupMenu) { 237 System.err.println("POPUP CREATION END >>>>>"); } 239 ExtUtilities.getExtEditorUI(target).setPopupMenu(pm); 240 } 241 } 242 243 protected JPopupMenu createPopupMenu(JTextComponent target) { 244 return new JPopupMenu (); 245 } 246 247 protected JPopupMenu buildPopupMenu(JTextComponent target) { 248 JPopupMenu pm = createPopupMenu(target); 249 250 EditorUI ui = Utilities.getEditorUI(target); 251 List l = (List )Settings.getValue(Utilities.getKitClass(target), 252 (ui == null || ui.hasExtComponent()) 253 ? ExtSettingsNames.POPUP_MENU_ACTION_NAME_LIST 254 : ExtSettingsNames.DIALOG_POPUP_MENU_ACTION_NAME_LIST 255 ); 256 257 if (l != null) { 258 Iterator i = l.iterator(); 259 while (i.hasNext()) { 260 String an = (String )i.next(); 261 addAction(target, pm, an); 262 } 263 } 264 return pm; 265 } 266 267 277 protected void addAction(JTextComponent target, JPopupMenu popupMenu, 278 String actionName) { 279 Action a = Utilities.getKit(target).getActionByName(actionName); 280 if (a != null) { 281 JMenuItem item = null; 282 if (a instanceof BaseAction) { 283 item = ((BaseAction)a).getPopupMenuItem(target); 284 } 285 if (item == null) { 286 String itemText = getItemText(target, actionName, a); 287 if (itemText != null) { 288 item = new JMenuItem (itemText); 289 item.addActionListener(a); 290 Keymap km = target.getKeymap(); 292 if (km != null) { 293 KeyStroke [] keys = km.getKeyStrokesForAction(a); 294 if (keys != null && keys.length > 0) { 295 item.setAccelerator(keys[0]); 296 } 297 } 298 item.setEnabled(a.isEnabled()); 299 Object helpID = a.getValue ("helpID"); if (helpID != null && (helpID instanceof String )) 301 item.putClientProperty ("HelpID", helpID); } 303 } 304 305 if (item != null) { 306 debugPopupMenuItem(item, a); 307 popupMenu.add(item); 308 } 309 310 } else if (actionName == null){ if (popupMenu.getComponentCount()>0){ 312 debugPopupMenuItem(null, null); 313 popupMenu.addSeparator(); 314 } 315 } 316 } 317 318 protected final void debugPopupMenuItem(JMenuItem item, Action action) { 319 if (debugPopupMenu) { 320 StringBuffer sb = new StringBuffer ("POPUP: "); if (item != null) { 322 sb.append('"'); 323 sb.append(item.getText()); 324 sb.append('"');; 325 if (!item.isVisible()) { 326 sb.append(", INVISIBLE"); } 328 if (action != null) { 329 sb.append(", action="); sb.append(action.getClass().getName()); 331 } 332 333 } else { sb.append("--Separator--"); } 336 337 System.err.println(sb.toString()); 338 } 339 340 } 341 342 protected String getItemText(JTextComponent target, String actionName, Action a) { 343 String itemText; 344 if (a instanceof BaseAction) { 345 itemText = ((BaseAction)a).getPopupMenuText(target); 346 } else { 347 itemText = actionName; 348 } 349 return itemText; 350 } 351 352 } 353 354 356 public static class ShowPopupMenuAction extends BaseKitLocalizedAction { 357 358 static final long serialVersionUID =4257043398248915291L; 359 360 public ShowPopupMenuAction() { 361 super(showPopupMenuAction, NO_RECORDING); 362 } 363 364 public void actionPerformed(ActionEvent evt, JTextComponent target) { 365 if (target != null) { 366 try { 367 int dotPos = target.getCaret().getDot(); 368 Rectangle r = target.getUI().modelToView(target, dotPos); 369 if (r != null) { 370 ExtEditorUI eui = ExtUtilities.getExtEditorUI(target); 371 if (eui != null){ 372 eui.showPopupMenu(r.x, r.y + r.height); 373 } 374 } 375 } catch (BadLocationException e) { 376 target.getToolkit().beep(); 377 } 378 } 379 } 380 381 } 382 383 public static class BuildToolTipAction extends BaseAction { 384 385 static final long serialVersionUID =-2701131863705941250L; 386 387 public BuildToolTipAction() { 388 super(buildToolTipAction, NO_RECORDING); 389 putValue(BaseAction.NO_KEYBINDING, Boolean.TRUE); 390 putValue(Action.SHORT_DESCRIPTION, ""); } 392 393 protected String buildText(JTextComponent target) { 394 ToolTipSupport tts = ExtUtilities.getExtEditorUI(target).getToolTipSupport(); 395 return (tts != null) 396 ? target.getToolTipText(tts.getLastMouseEvent()) 397 : target.getToolTipText(); 398 } 399 400 public void actionPerformed(ActionEvent evt, JTextComponent target) { 401 if (target != null) { 402 ToolTipSupport tts = ExtUtilities.getExtEditorUI(target).getToolTipSupport(); 403 if (tts != null) { 404 tts.setToolTipText(buildText(target)); 405 } 406 } 407 } 408 409 } 410 411 public static class FindAction extends BaseKitLocalizedAction { 412 413 static final long serialVersionUID =719554648887497427L; 414 415 public FindAction() { 416 super(findAction, ABBREV_RESET 417 | MAGIC_POSITION_RESET | UNDO_MERGE_RESET | NO_RECORDING); 418 putValue(BaseAction.ICON_RESOURCE_PROPERTY, 419 "org/netbeans/modules/editor/resources/find"); } 421 422 public FindDialogSupport getSupport() { 423 return FindDialogSupport.getFindDialogSupport(); 424 } 425 426 public void actionPerformed(ActionEvent evt, JTextComponent target) { 427 if (target != null) { 428 getSupport().showFindDialog(new KeyEventBlocker(target, false)); 429 } 430 } 431 432 } 433 434 public static class ReplaceAction extends BaseKitLocalizedAction { 435 436 static final long serialVersionUID =1828017436079834384L; 437 438 public ReplaceAction() { 439 super(replaceAction, ABBREV_RESET 440 | MAGIC_POSITION_RESET | UNDO_MERGE_RESET | NO_RECORDING); 441 } 442 443 public FindDialogSupport getSupport() { 444 return FindDialogSupport.getFindDialogSupport(); 445 } 446 447 public void actionPerformed(ActionEvent evt, JTextComponent target) { 448 if (target != null) { 449 getSupport().showReplaceDialog(new KeyEventBlocker(target, true)); 452 } 453 } 454 455 } 456 457 public static class GotoAction extends BaseKitLocalizedAction { 458 459 static final long serialVersionUID =8425585413146373256L; 460 461 public GotoAction() { 462 super(gotoAction, ABBREV_RESET 463 | MAGIC_POSITION_RESET | UNDO_MERGE_RESET); 464 String name = NbBundle.getBundle(BaseKit.class).getString("goto_trimmed"); 465 putValue(TRIMMED_TEXT, name); 466 putValue(POPUP_MENU_TEXT, name); 467 } 468 469 470 478 protected int getOffsetFromLine(BaseDocument doc, int lineOffset) { 479 return Utilities.getRowStartFromLineOffset(doc, lineOffset); 480 } 481 482 public void actionPerformed(ActionEvent evt, JTextComponent target) { 483 if (target != null) { 484 new GotoDialogSupport().showGotoDialog(new KeyEventBlocker(target, false)); 485 } 486 } 487 488 } 489 490 492 public static class GotoDeclarationAction extends BaseKitLocalizedAction { 493 494 static final long serialVersionUID =-6440495023918097760L; 495 496 public GotoDeclarationAction() { 497 super(gotoDeclarationAction, 498 ABBREV_RESET | MAGIC_POSITION_RESET | UNDO_MERGE_RESET 499 | SAVE_POSITION 500 ); 501 String name = NbBundle.getBundle(BaseKit.class).getString("goto-declaration-trimmed"); 502 putValue(TRIMMED_TEXT, name); putValue(POPUP_MENU_TEXT, name); } 505 506 public boolean gotoDeclaration(JTextComponent target) { 507 try { 508 Caret caret = target.getCaret(); 509 int dotPos = caret.getDot(); 510 BaseDocument doc = (BaseDocument)target.getDocument(); 511 int[] idBlk = Utilities.getIdentifierBlock(doc, dotPos); 512 ExtSyntaxSupport extSup = (ExtSyntaxSupport)doc.getSyntaxSupport(); 513 if (idBlk != null) { 514 int decPos = extSup.findDeclarationPosition(doc.getText(idBlk), idBlk[1]); 515 if (decPos >= 0) { 516 caret.setDot(decPos); 517 return true; 518 } 519 } 520 } catch (BadLocationException e) { 521 } 522 return false; 523 } 524 525 public void actionPerformed(ActionEvent evt, JTextComponent target) { 526 if (target != null) { 527 gotoDeclaration(target); } 529 } 530 } 531 532 public static class ToggleCaseIdentifierBeginAction extends BaseKitLocalizedAction { 533 534 static final long serialVersionUID =584392193824931979L; 535 536 ToggleCaseIdentifierBeginAction() { 537 super(toggleCaseIdentifierBeginAction, ABBREV_RESET 538 | MAGIC_POSITION_RESET | UNDO_MERGE_RESET | WORD_MATCH_RESET); 539 } 540 541 public void actionPerformed(ActionEvent evt, JTextComponent target) { 542 if (target != null) { 543 if (!target.isEditable() || !target.isEnabled()) { 544 target.getToolkit().beep(); 545 return; 546 } 547 548 try { 549 Caret caret = target.getCaret(); 550 BaseDocument doc = (BaseDocument)target.getDocument(); 551 int[] idBlk = Utilities.getIdentifierBlock(doc, caret.getDot()); 552 if (idBlk != null) { 553 Utilities.changeCase(doc, idBlk[0], 1, Utilities.CASE_SWITCH); 554 } 555 } catch (BadLocationException e) { 556 target.getToolkit().beep(); 557 } 558 } 559 } 560 } 561 562 public static class MatchBraceAction extends BaseKitLocalizedAction { 563 564 boolean select; 565 566 static final long serialVersionUID =-184887499045886231L; 567 568 public MatchBraceAction(String name, boolean select) { 569 super(name, ABBREV_RESET 570 | MAGIC_POSITION_RESET | UNDO_MERGE_RESET); 571 this.select = select; 572 } 573 574 public void actionPerformed(ActionEvent evt, JTextComponent target) { 575 if (target != null) { 576 try { 577 Caret caret = target.getCaret(); 578 BaseDocument doc = Utilities.getDocument(target); 579 int dotPos = caret.getDot(); 580 ExtSyntaxSupport sup = (ExtSyntaxSupport)doc.getSyntaxSupport(); 581 if (dotPos > 0) { 582 int[] matchBlk = sup.findMatchingBlock(dotPos - 1, false); 583 if (matchBlk != null) { 584 if (select) { 585 caret.moveDot(matchBlk[1]); 586 } else { 587 caret.setDot(matchBlk[1]); 588 } 589 } 590 } 591 } catch (BadLocationException e) { 592 target.getToolkit().beep(); 593 } 594 } 595 } 596 } 597 598 601 public static class CodeSelectAction extends BaseKitLocalizedAction { 602 603 static final long serialVersionUID =4033474080778585860L; 604 605 public CodeSelectAction() { 606 super(codeSelectAction); 607 } 608 609 public void actionPerformed(ActionEvent evt, JTextComponent target) { 610 631 } 632 } 633 634 641 public static class PrefixMakerAction extends BaseKitLocalizedAction { 642 643 static final long serialVersionUID =-2305157963664484920L; 644 645 private String prefix; 646 647 private String [] prefixGroup; 648 649 public PrefixMakerAction(String name, String prefix, String [] prefixGroup) { 650 super(name); 651 this.prefix = prefix; 652 this.prefixGroup = prefixGroup; 653 654 String iconRes = null; 656 if ("get".equals(prefix)) { iconRes = "org/netbeans/modules/editor/resources/var_get.gif"; } else if ("set".equals(prefix)) { iconRes = "org/netbeans/modules/editor/resources/var_set.gif"; } else if ("is".equals(prefix)) { iconRes = "org/netbeans/modules/editor/resources/var_is.gif"; } 663 if (iconRes != null) { 664 putValue(BaseAction.ICON_RESOURCE_PROPERTY, iconRes); 665 } 666 } 667 668 public void actionPerformed(ActionEvent evt, JTextComponent target) { 669 if (target != null) { 670 if (!target.isEditable() || !target.isEnabled()) { 671 target.getToolkit().beep(); 672 return; 673 } 674 675 BaseDocument doc = (BaseDocument)target.getDocument(); 676 int dotPos = target.getCaret().getDot(); 677 try { 678 int[] block = org.netbeans.editor.Utilities.getIdentifierBlock(doc, dotPos); 680 681 if (block == null) { 683 target.getToolkit().beep(); 684 return; 685 } 686 687 CharSequence identifier = DocumentUtilities.getText(doc, block[0], block[1] - block[0]); 689 690 if (CharSequenceUtilities.startsWith(identifier, prefix) && 692 Character.isUpperCase(identifier.charAt(prefix.length()))) return; 693 694 for (int i=0; i<prefixGroup.length; i++) { 696 String actPref = prefixGroup[i]; 697 if (CharSequenceUtilities.startsWith(identifier, actPref) 698 && identifier.length() > actPref.length() 699 && Character.isUpperCase(identifier.charAt(actPref.length())) 700 ) { 701 doc.remove(block[0], actPref.length()); 702 doc.insertString(block[0], prefix, null); 703 return; 704 } 705 } 706 707 Utilities.changeCase(doc, block[0], 1, Utilities.CASE_UPPER); 709 doc.insertString(block[0], prefix, null); 711 } catch (BadLocationException e) { 712 target.getToolkit().beep(); 713 } 714 } 715 } 716 } 717 718 public static class CommentAction extends BaseKitLocalizedAction { 719 720 static final long serialVersionUID =-1422954906554289179L; 721 722 private String lineCommentString; 723 724 public CommentAction(String lineCommentString) { 725 super(commentAction); 726 this.lineCommentString = lineCommentString; 727 putValue(BaseAction.ICON_RESOURCE_PROPERTY, 728 "org/netbeans/modules/editor/resources/comment.png"); } 730 731 public void actionPerformed(ActionEvent evt, JTextComponent target) { 732 if (target != null) { 733 if (!target.isEditable() || !target.isEnabled()) { 734 target.getToolkit().beep(); 735 return; 736 } 737 Caret caret = target.getCaret(); 738 BaseDocument doc = (BaseDocument)target.getDocument(); 739 try { 740 if (caret.isSelectionVisible()) { 741 int startPos = Utilities.getRowStart(doc, target.getSelectionStart()); 742 int endPos = target.getSelectionEnd(); 743 doc.atomicLock(); 744 try { 745 746 if (endPos > 0 && Utilities.getRowStart(doc, endPos) == endPos) { 747 endPos--; 748 } 749 750 int pos = startPos; 751 for (int lineCnt = Utilities.getRowCount(doc, startPos, endPos); 752 lineCnt > 0; lineCnt-- 753 ) { 754 doc.insertString(pos, lineCommentString, null); pos = Utilities.getRowStart(doc, pos, +1); 756 } 757 } finally { 758 doc.atomicUnlock(); 759 } 760 } else { doc.insertString(Utilities.getRowStart(doc, target.getSelectionStart()), 762 lineCommentString, null); } 764 } catch (BadLocationException e) { 765 target.getToolkit().beep(); 766 } 767 } 768 } 769 } 770 771 public static class UncommentAction extends BaseKitLocalizedAction { 772 773 static final long serialVersionUID =-7005758666529862034L; 774 775 private String lineCommentString; 776 777 public UncommentAction(String lineCommentString) { 778 super(uncommentAction); 779 this.lineCommentString = lineCommentString; 780 putValue(BaseAction.ICON_RESOURCE_PROPERTY, 781 "org/netbeans/modules/editor/resources/uncomment.png"); } 783 784 public void actionPerformed(ActionEvent evt, JTextComponent target) { 785 if (target != null) { 786 if (!target.isEditable() || !target.isEnabled()) { 787 target.getToolkit().beep(); 788 return; 789 } 790 Caret caret = target.getCaret(); 791 BaseDocument doc = (BaseDocument)target.getDocument(); 792 int commentLen = lineCommentString.length(); 793 try { 794 doc.atomicLock(); 795 try { 796 int startPos = target.getSelectionStart(); 797 int endPos = target.getSelectionEnd(); 798 799 for (int pos = startPos, lineCnt = Utilities.getRowCount(doc, startPos, endPos); lineCnt > 0; lineCnt--) { 800 int firstNonWhitePos = Utilities.getRowFirstNonWhite(doc, pos); 802 803 if (firstNonWhitePos != -1) { 805 if (Utilities.getRowEnd(doc, firstNonWhitePos) - firstNonWhitePos >= commentLen) { 806 CharSequence maybeLineComment = DocumentUtilities.getText(doc, firstNonWhitePos, commentLen); 807 if (CharSequenceUtilities.textEquals(maybeLineComment, lineCommentString)) { 808 doc.remove(firstNonWhitePos, commentLen); 809 } 810 } 811 } 812 813 pos = Utilities.getRowStart(doc, pos, +1); 814 } 815 } finally { 816 doc.atomicUnlock(); 817 } 818 } catch (BadLocationException e) { 819 target.getToolkit().beep(); 820 } 821 } 822 } 823 } 824 825 826 827 830 public static class EscapeAction extends BaseKitLocalizedAction { 831 832 public EscapeAction() { 833 super(escapeAction); 834 } 835 836 public void actionPerformed(ActionEvent evt, JTextComponent target) { 837 if (target != null) { 838 ExtUtilities.getExtEditorUI(target).hidePopupMenu(); 839 } 840 } 841 } 842 843 844 public static class ExtDefaultKeyTypedAction extends DefaultKeyTypedAction { 846 847 static final long serialVersionUID =5273032708909044812L; 848 849 public void actionPerformed(ActionEvent evt, JTextComponent target) { 850 String cmd = evt.getActionCommand(); 851 int mod = evt.getModifiers(); 852 853 if (cmd != null && cmd.equals(" ") && (mod == ActionEvent.CTRL_MASK)) { } else { 857 Caret caret = target.getCaret(); 858 if (caret instanceof ExtCaret) { 859 ((ExtCaret)caret).requestMatchBraceUpdateSync(); } 861 super.actionPerformed(evt, target); 862 } 863 864 if ((target != null) && (evt != null)) { 865 if ((cmd != null) && (cmd.length() == 1) && 866 ((mod & ActionEvent.ALT_MASK) == 0 867 && (mod & ActionEvent.CTRL_MASK) == 0) 868 ) { 869 checkIndentHotChars(target, cmd); 871 872 checkCompletion(target, cmd); 874 } 875 } 876 } 877 878 879 protected void checkIndentHotChars(JTextComponent target, String typedText) { 880 BaseDocument doc = Utilities.getDocument(target); 881 if (doc != null) { 882 Caret caret = target.getCaret(); 883 Formatter f = doc.getFormatter(); 884 if (f instanceof ExtFormatter) { 885 ExtFormatter ef = (ExtFormatter)f; 886 int[] fmtBlk = ef.getReformatBlock(target, typedText); 887 888 if (fmtBlk != null) { 889 try { 890 fmtBlk[0] = Utilities.getRowStart(doc, fmtBlk[0]); 891 fmtBlk[1] = Utilities.getRowEnd(doc, fmtBlk[1]); 892 893 896 ef.reformat(doc, fmtBlk[0], fmtBlk[1], true); 898 899 } catch (BadLocationException e) { 900 } catch (IOException e) { 901 } 902 } 903 } 904 } 905 } 906 907 908 909 protected void checkCompletion(JTextComponent target, String typedText) { 910 Completion completion = ExtUtilities.getCompletion(target); 911 912 BaseDocument doc = (BaseDocument)target.getDocument(); 913 ExtSyntaxSupport extSup = (ExtSyntaxSupport)doc.getSyntaxSupport(); 914 915 if (completion != null && typedText.length() > 0) { 916 if( !completion.isPaneVisible() ) { 917 if (completion.isAutoPopupEnabled()) { 918 int result = extSup.checkCompletion( target, typedText, false ); 919 if ( result == ExtSyntaxSupport.COMPLETION_POPUP ) { 920 completion.popup(true); 921 } else if ( result == ExtSyntaxSupport.COMPLETION_CANCEL ) { 922 completion.cancelRequest(); 923 } 924 } 925 } else { 926 int result = extSup.checkCompletion( target, typedText, true ); 927 switch( result ) { 928 case ExtSyntaxSupport.COMPLETION_HIDE: 929 completion.setPaneVisible(false); 930 break; 931 case ExtSyntaxSupport.COMPLETION_REFRESH: 932 completion.refresh(false); 933 break; 934 case ExtSyntaxSupport.COMPLETION_POST_REFRESH: 935 completion.refresh(true); 936 break; 937 } 938 } 939 } 940 } 941 } 942 943 public static class CompletionShowAction extends BaseKitLocalizedAction { 944 945 static final long serialVersionUID =1050644925893851146L; 946 947 public CompletionShowAction() { 948 super(completionShowAction); 949 } 950 951 public void actionPerformed(ActionEvent evt, JTextComponent target) { 952 } 953 954 } 955 956 public static class AllCompletionShowAction extends BaseKitLocalizedAction { 957 958 public AllCompletionShowAction() { 959 super(allCompletionShowAction); 960 } 961 962 public void actionPerformed(ActionEvent evt, JTextComponent target) { 963 } 964 965 } 966 967 public static class DocumentationShowAction extends BaseKitLocalizedAction { 968 969 public DocumentationShowAction() { 970 super(documentationShowAction); 971 } 972 973 public void actionPerformed(ActionEvent evt, JTextComponent target) { 974 } 975 976 } 977 978 public static class CompletionTooltipShowAction extends BaseKitLocalizedAction { 979 980 public CompletionTooltipShowAction() { 981 super(completionTooltipShowAction); 982 } 983 984 public void actionPerformed(ActionEvent evt, JTextComponent target) { 985 } 986 987 } 988 989 public static class ExtDeleteCharAction extends DeleteCharAction { 990 991 public ExtDeleteCharAction(String nm, boolean nextChar) { 992 super(nm, nextChar); 993 } 994 995 } 996 997 998 } 999 | Popular Tags |