1 22 23 package org.gjt.sp.jedit; 24 25 import javax.swing.*; 27 import java.awt.event.*; 28 import java.awt.*; 29 import java.util.HashMap ; 30 import java.util.Map ; 31 32 import org.gjt.sp.jedit.gui.*; 33 import org.gjt.sp.jedit.io.VFSManager; 34 import org.gjt.sp.jedit.msg.*; 35 import org.gjt.sp.jedit.options.GlobalOptions; 36 import org.gjt.sp.jedit.syntax.SyntaxStyle; 37 import org.gjt.sp.jedit.textarea.*; 38 import org.gjt.sp.jedit.buffer.JEditBuffer; 39 41 69 public class EditPane extends JPanel implements EBComponent 70 { 71 76 public View getView() 77 { 78 return view; 79 } 81 86 public Buffer getBuffer() 87 { 88 return buffer; 89 } 91 97 public void setBuffer(Buffer buffer) 98 { 99 setBuffer(buffer, true); 100 } 102 109 public void setBuffer(final Buffer buffer, boolean requestFocus) 110 { 111 112 if(buffer == null) 113 throw new NullPointerException (); 114 115 if(this.buffer == buffer) 116 return; 117 118 EditBus.send(new BufferChanging(this, buffer)); 121 recentBuffer = this.buffer; 122 if(recentBuffer != null) 123 saveCaretInfo(); 124 this.buffer = buffer; 125 126 textArea.setBuffer(buffer); 127 128 if(!init) 129 { 130 view.updateTitle(); 131 132 if(bufferSwitcher != null) 133 { 134 if(bufferSwitcher.getSelectedItem() != buffer) 135 bufferSwitcher.setSelectedItem(buffer); 136 bufferSwitcher.setToolTipText(buffer.getPath()); 137 } 138 139 EditBus.send(new EditPaneUpdate(this,EditPaneUpdate 140 .BUFFER_CHANGED)); 141 } 142 143 if (requestFocus) 144 { 145 SwingUtilities.invokeLater(new Runnable () 146 { 147 public void run() 148 { 149 if(view.getEditPane() == EditPane.this 151 && (bufferSwitcher == null 152 || !bufferSwitcher.isPopupVisible())) 153 { 154 textArea.requestFocus(); 155 } 156 } 157 }); 158 } 159 160 Runnable runnable = new Runnable () 162 { 163 public void run() 164 { 165 if(buffer == getBuffer()) 168 loadCaretInfo(); 169 } 170 }; 171 172 if(buffer.isPerformingIO()) 173 VFSManager.runInAWTThread(runnable); 174 else 175 runnable.run(); 176 } 178 183 public void prevBuffer() 184 { 185 Buffer buffer = this.buffer.getPrev(); 186 if(buffer == null) 187 setBuffer(jEdit.getLastBuffer()); 188 else 189 setBuffer(buffer); 190 } 192 197 public void nextBuffer() 198 { 199 Buffer buffer = this.buffer.getNext(); 200 if(buffer == null) 201 setBuffer(jEdit.getFirstBuffer()); 202 else 203 setBuffer(buffer); 204 } 206 211 public void recentBuffer() 212 { 213 if(recentBuffer != null) 214 setBuffer(recentBuffer); 215 else 216 getToolkit().beep(); 217 } 219 224 public void focusOnTextArea() 225 { 226 SwingUtilities.invokeLater(new Runnable () 227 { 228 public void run() 229 { 230 textArea.requestFocus(); 231 } 232 }); 233 } 235 240 public JEditTextArea getTextArea() 241 { 242 return textArea; 243 } 245 250 public BufferSwitcher getBufferSwitcher() 251 { 252 return bufferSwitcher; 253 } 255 260 public void showBufferSwitcher() 261 { 262 if(bufferSwitcher == null) 263 getToolkit().beep(); 264 else 265 { 266 bufferSwitcher.requestFocus(); 267 bufferSwitcher.showPopup(); 268 } 269 } 271 276 public void saveCaretInfo() 277 { 278 if(!buffer.isLoaded()) 279 return; 280 281 buffer.setIntegerProperty(Buffer.CARET, 282 textArea.getCaretPosition()); 283 284 Map <String , CaretInfo> carets = (Map <String , CaretInfo>)getClientProperty(CARETS); 290 if (carets == null) 291 { 292 carets = new HashMap <String , CaretInfo>(); 293 putClientProperty(CARETS, carets); 294 } 295 CaretInfo caretInfo = carets.get(buffer.getPath()); 296 if (caretInfo == null) 297 { 298 caretInfo = new CaretInfo(); 299 carets.put(buffer.getPath(), caretInfo); 300 } 301 caretInfo.caret = textArea.getCaretPosition(); 302 303 304 Selection[] selection = textArea.getSelection(); 305 for(int i = 0; i < selection.length; i++) 306 selection[i] = (Selection)selection[i].clone(); 307 buffer.setProperty(Buffer.SELECTION,selection); 308 caretInfo.selection = selection; 309 310 caretInfo.rectangularSelection = textArea.isRectangularSelectionEnabled(); 311 caretInfo.multipleSelection = textArea.isMultipleSelectionEnabled(); 312 313 buffer.setIntegerProperty(Buffer.SCROLL_VERT, 314 textArea.getFirstPhysicalLine()); 315 caretInfo.scrollVert = textArea.getFirstPhysicalLine(); 316 buffer.setIntegerProperty(Buffer.SCROLL_HORIZ, 317 textArea.getHorizontalOffset()); 318 caretInfo.scrollHoriz = textArea.getHorizontalOffset(); 319 if (!buffer.isUntitled()) 320 { 321 BufferHistory.setEntry(buffer.getPath(), textArea.getCaretPosition(), 322 (Selection[])buffer.getProperty(Buffer.SELECTION), 323 buffer.getStringProperty(JEditBuffer.ENCODING)); 324 } 325 } 327 334 public void loadCaretInfo() 335 { 336 Map <String , CaretInfo> carets = (Map <String , CaretInfo>) getClientProperty(CARETS); 339 if (carets == null) 340 { 341 carets = new HashMap <String , CaretInfo>(); 342 putClientProperty(CARETS, carets); 343 } 344 CaretInfo caretInfo = carets.get(buffer.getPath()); 345 if (caretInfo == null) 346 { 347 caretInfo = new CaretInfo(); 348 } 349 350 int caret = caretInfo.caret; 356 if (caret == -1 || buffer.getBooleanProperty(Buffer.CARET_POSITIONED)) 357 { 358 Integer i = (Integer ) buffer.getProperty(Buffer.CARET); 359 caret = i == null ? -1 : i; 360 } 361 buffer.unsetProperty(Buffer.CARET_POSITIONED); 362 363 364 if(caret != -1) 365 textArea.setCaretPosition(Math.min(caret, 366 buffer.getLength())); 367 368 Selection[] selection = caretInfo.selection; 370 if ( selection == null ) { 371 selection = (Selection[])buffer.getProperty(Buffer.SELECTION); 372 } 373 if(selection != null) 374 { 375 for(int i = 0; i < selection.length; i++) 376 { 377 Selection s = selection[i]; 378 int max = buffer.getLength(); 379 if(s.getStart() > max || s.getEnd() > max) 380 selection[i] = null; 381 } 382 } 383 textArea.setSelection(selection); 384 textArea.setRectangularSelectionEnabled(caretInfo.rectangularSelection); 385 textArea.setMultipleSelectionEnabled(caretInfo.multipleSelection); 386 int firstLine = caretInfo.scrollVert; 388 if ( firstLine == -1 ) 389 { 390 Integer i = (Integer ) buffer.getProperty(Buffer.SCROLL_VERT); 391 firstLine = i == null ? -1 : i; 392 } 393 394 if(firstLine != -1) 395 textArea.setFirstPhysicalLine(firstLine); 396 397 int horizontalOffset = caretInfo.scrollHoriz; 399 if (horizontalOffset == -1) 400 { 401 Integer i = (Integer ) buffer.getProperty(Buffer.SCROLL_HORIZ); 402 horizontalOffset = i == null ? -1 : i; 403 } 404 405 if(horizontalOffset != -1) 406 textArea.setHorizontalOffset(horizontalOffset); 407 408 419 view.getStatus().setMessage(null); 420 } 422 428 void bufferRenamed(String oldPath, String newPath) 429 { 430 Map <String , CaretInfo> carets = (Map <String , CaretInfo>) getClientProperty(CARETS); 431 if (carets == null) 432 return; 433 CaretInfo caretInfo = carets.remove(oldPath); 434 if (caretInfo != null) 435 carets.put(newPath, caretInfo); 436 437 } 439 446 private static class CaretInfo 447 { 448 public int caret = -1; 449 public Selection[] selection; 450 public int scrollVert = -1; 451 public int scrollHoriz = -1; 452 public boolean rectangularSelection; 453 public boolean multipleSelection; 454 } 456 461 public void goToNextMarker(boolean select) 462 { 463 java.util.List <Marker> markers = buffer.getMarkers(); 464 if(markers.isEmpty()) 465 { 466 getToolkit().beep(); 467 return; 468 } 469 470 Marker marker = null; 471 472 int caret = textArea.getCaretPosition(); 473 474 for(int i = 0; i < markers.size(); i++) 475 { 476 Marker _marker = markers.get(i); 477 if(_marker.getPosition() > caret) 478 { 479 marker = _marker; 480 break; 481 } 482 } 483 if(marker == null) 485 marker = markers.get(0); 486 487 if(select) 488 textArea.extendSelection(caret,marker.getPosition()); 489 else if(!textArea.isMultipleSelectionEnabled()) 490 textArea.selectNone(); 491 textArea.moveCaretPosition(marker.getPosition()); 492 } 494 499 public void goToPrevMarker(boolean select) 500 { 501 java.util.List <Marker> markers = buffer.getMarkers(); 502 if(markers.isEmpty()) 503 { 504 getToolkit().beep(); 505 return; 506 } 507 508 int caret = textArea.getCaretPosition(); 509 510 Marker marker = null; 511 for(int i = markers.size() - 1; i >= 0; i--) 512 { 513 Marker _marker = markers.get(i); 514 if(_marker.getPosition() < caret) 515 { 516 marker = _marker; 517 break; 518 } 519 } 520 521 if(marker == null) 522 marker = markers.get(markers.size() - 1); 523 524 if(select) 525 textArea.extendSelection(caret,marker.getPosition()); 526 else if(!textArea.isMultipleSelectionEnabled()) 527 textArea.selectNone(); 528 textArea.moveCaretPosition(marker.getPosition()); 529 } 531 539 public void goToMarker(char shortcut, boolean select) 540 { 541 Marker marker = buffer.getMarker(shortcut); 542 if(marker == null) 543 { 544 getToolkit().beep(); 545 return; 546 } 547 548 int pos = marker.getPosition(); 549 550 if(select) 551 textArea.extendSelection(textArea.getCaretPosition(),pos); 552 else if(!textArea.isMultipleSelectionEnabled()) 553 textArea.selectNone(); 554 textArea.moveCaretPosition(pos); 555 } 557 562 public void addMarker() 563 { 564 int caretLine = textArea.getCaretLine(); 565 566 Selection[] selection = textArea.getSelection(); 568 for(int i = 0; i < selection.length; i++) 569 { 570 Selection s = selection[i]; 571 if(s.getStartLine() != s.getEndLine()) 572 { 573 if(s.getStartLine() != caretLine) 574 buffer.addMarker('\0',s.getStart()); 575 } 576 577 if(s.getEndLine() != caretLine) 578 buffer.addMarker('\0',s.getEnd()); 579 } 580 581 buffer.addOrRemoveMarker('\0',textArea.getCaretPosition()); 583 } 585 592 public void swapMarkerAndCaret(char shortcut) 593 { 594 Marker marker = buffer.getMarker(shortcut); 595 if(marker == null) 596 { 597 getToolkit().beep(); 598 return; 599 } 600 601 int caret = textArea.getCaretPosition(); 602 603 textArea.setCaretPosition(marker.getPosition()); 604 buffer.addMarker(shortcut,caret); 605 } 607 public void handleMessage(EBMessage msg) 609 { 610 if(msg instanceof PropertiesChanged) 611 { 612 propertiesChanged(); 613 loadBufferSwitcher(); 614 } 615 else if(msg instanceof BufferUpdate) 616 handleBufferUpdate((BufferUpdate)msg); 617 } 619 623 public final Dimension getMinimumSize() 624 { 625 return new Dimension(0,0); 626 } 628 public String toString() 630 { 631 return getClass().getName() + '[' 632 + (view.getEditPane() == this 633 ? "active" : "inactive") 634 + ']'; 635 } 637 639 EditPane(View view, Buffer buffer) 641 { 642 super(new BorderLayout()); 643 644 init = true; 645 646 this.view = view; 647 648 EditBus.addToBus(this); 649 650 textArea = new JEditTextArea(view); 651 textArea.getPainter().setAntiAlias(new AntiAlias(jEdit.getProperty("view.antiAlias"))); 652 textArea.setMouseHandler(new MouseHandler(textArea)); 653 textArea.setTransferHandler(new TextAreaTransferHandler()); 654 markerHighlight = new MarkerHighlight(); 655 textArea.getGutter().addExtension(markerHighlight); 656 textArea.addStatusListener(new StatusHandler()); 657 658 add(BorderLayout.CENTER,textArea); 659 660 propertiesChanged(); 661 662 if(buffer == null) 663 setBuffer(jEdit.getFirstBuffer()); 664 else 665 setBuffer(buffer); 666 667 loadBufferSwitcher(); 668 669 init = false; 670 } 672 void close() 674 { 675 saveCaretInfo(); 676 EditBus.send(new EditPaneUpdate(this,EditPaneUpdate.DESTROYED)); 677 EditBus.removeFromBus(this); 678 textArea.dispose(); 679 } 681 683 685 private boolean init; 687 688 private final View view; 689 690 private Buffer buffer; 691 private Buffer recentBuffer; 692 private BufferSwitcher bufferSwitcher; 693 694 private final JEditTextArea textArea; 695 private final MarkerHighlight markerHighlight; 696 697 private static final String CARETS = "Buffer->caret"; 698 699 701 private void propertiesChanged() 703 { 704 TextAreaPainter painter = textArea.getPainter(); 705 706 painter.setFont(jEdit.getFontProperty("view.font")); 707 painter.setStructureHighlightEnabled(jEdit.getBooleanProperty( 708 "view.structureHighlight")); 709 painter.setStructureHighlightColor( 710 jEdit.getColorProperty("view.structureHighlightColor")); 711 painter.setEOLMarkersPainted(jEdit.getBooleanProperty( 712 "view.eolMarkers")); 713 painter.setEOLMarkerColor( 714 jEdit.getColorProperty("view.eolMarkerColor")); 715 painter.setWrapGuidePainted(jEdit.getBooleanProperty( 716 "view.wrapGuide")); 717 painter.setWrapGuideColor( 718 jEdit.getColorProperty("view.wrapGuideColor")); 719 painter.setCaretColor( 720 jEdit.getColorProperty("view.caretColor")); 721 painter.setSelectionColor( 722 jEdit.getColorProperty("view.selectionColor")); 723 painter.setMultipleSelectionColor( 724 jEdit.getColorProperty("view.multipleSelectionColor")); 725 painter.setBackground( 726 jEdit.getColorProperty("view.bgColor")); 727 painter.setForeground( 728 jEdit.getColorProperty("view.fgColor")); 729 painter.setBlockCaretEnabled(jEdit.getBooleanProperty( 730 "view.blockCaret")); 731 painter.setLineHighlightEnabled(jEdit.getBooleanProperty( 732 "view.lineHighlight")); 733 painter.setLineHighlightColor( 734 jEdit.getColorProperty("view.lineHighlightColor")); 735 painter.setAntiAlias(new AntiAlias(jEdit.getProperty("view.antiAlias"))); 736 painter.setFractionalFontMetricsEnabled(jEdit.getBooleanProperty( 737 "view.fracFontMetrics")); 738 739 String defaultFont = jEdit.getProperty("view.font"); 740 int defaultFontSize = jEdit.getIntegerProperty("view.fontsize",12); 741 painter.setStyles(GUIUtilities.loadStyles(defaultFont,defaultFontSize)); 742 743 SyntaxStyle[] foldLineStyle = new SyntaxStyle[4]; 744 for(int i = 0; i <= 3; i++) 745 { 746 foldLineStyle[i] = GUIUtilities.parseStyle( 747 jEdit.getProperty("view.style.foldLine." + i), 748 defaultFont,defaultFontSize); 749 } 750 painter.setFoldLineStyle(foldLineStyle); 751 Gutter gutter = textArea.getGutter(); 752 gutter.setExpanded(jEdit.getBooleanProperty( 753 "view.gutter.lineNumbers")); 754 int interval = jEdit.getIntegerProperty( 755 "view.gutter.highlightInterval",5); 756 gutter.setHighlightInterval(interval); 757 gutter.setCurrentLineHighlightEnabled(jEdit.getBooleanProperty( 758 "view.gutter.highlightCurrentLine")); 759 gutter.setStructureHighlightEnabled(jEdit.getBooleanProperty( 760 "view.gutter.structureHighlight")); 761 gutter.setStructureHighlightColor( 762 jEdit.getColorProperty("view.gutter.structureHighlightColor")); 763 gutter.setBackground( 764 jEdit.getColorProperty("view.gutter.bgColor")); 765 gutter.setForeground( 766 jEdit.getColorProperty("view.gutter.fgColor")); 767 gutter.setHighlightedForeground( 768 jEdit.getColorProperty("view.gutter.highlightColor")); 769 gutter.setFoldColor( 770 jEdit.getColorProperty("view.gutter.foldColor")); 771 markerHighlight.setMarkerHighlightColor( 772 jEdit.getColorProperty("view.gutter.markerColor")); 773 markerHighlight.setMarkerHighlightEnabled(jEdit.getBooleanProperty( 774 "view.gutter.markerHighlight")); 775 gutter.setCurrentLineForeground( 776 jEdit.getColorProperty("view.gutter.currentLineColor")); 777 String alignment = jEdit.getProperty( 778 "view.gutter.numberAlignment"); 779 if ("right".equals(alignment)) 780 { 781 gutter.setLineNumberAlignment(Gutter.RIGHT); 782 } 783 else if ("center".equals(alignment)) 784 { 785 gutter.setLineNumberAlignment(Gutter.CENTER); 786 } 787 else { 789 gutter.setLineNumberAlignment(Gutter.LEFT); 790 } 791 792 gutter.setFont(jEdit.getFontProperty("view.gutter.font")); 793 794 int width = jEdit.getIntegerProperty( 795 "view.gutter.borderWidth",3); 796 gutter.setBorder(width, 797 jEdit.getColorProperty("view.gutter.focusBorderColor"), 798 jEdit.getColorProperty("view.gutter.noFocusBorderColor"), 799 textArea.getPainter().getBackground()); 800 801 textArea.setCaretBlinkEnabled(jEdit.getBooleanProperty( 802 "view.caretBlink")); 803 804 textArea.setElectricScroll(jEdit.getIntegerProperty( 805 "view.electricBorders",0)); 806 807 JPopupMenu popup = GUIUtilities.loadPopupMenu("view.context"); 809 JMenuItem customize = new JMenuItem(jEdit.getProperty( 810 "view.context.customize")); 811 customize.addActionListener(new ActionListener() 812 { 813 public void actionPerformed(ActionEvent evt) 814 { 815 new GlobalOptions(view,"context"); 816 } 817 }); 818 popup.addSeparator(); 819 popup.add(customize); 820 textArea.setRightClickPopup(popup); 821 822 textArea.setQuickCopyEnabled(jEdit.getBooleanProperty( 824 "view.middleMousePaste")); 825 826 textArea.setDragEnabled(jEdit.getBooleanProperty( 827 "view.dragAndDrop")); 828 829 textArea.setJoinNonWordChars(jEdit.getBooleanProperty( 830 "view.joinNonWordChars")); 831 832 textArea.propertiesChanged(); 833 } 835 private void loadBufferSwitcher() 837 { 838 if(jEdit.getBooleanProperty("view.showBufferSwitcher")) 839 { 840 if(bufferSwitcher == null) 841 { 842 bufferSwitcher = new BufferSwitcher(this); 843 add(BorderLayout.NORTH,bufferSwitcher); 844 bufferSwitcher.updateBufferList(); 845 revalidate(); 846 } 847 } 848 else if(bufferSwitcher != null) 849 { 850 remove(bufferSwitcher); 851 revalidate(); 852 bufferSwitcher = null; 853 } 854 } 856 private void handleBufferUpdate(BufferUpdate msg) 858 { 859 Buffer _buffer = msg.getBuffer(); 860 if(msg.getWhat() == BufferUpdate.CREATED) 861 { 862 if(bufferSwitcher != null) 863 bufferSwitcher.updateBufferList(); 864 865 869 if(buffer.isClosed()) 870 { 871 setBuffer(jEdit.getFirstBuffer(), msg.getView() == view); 872 recentBuffer = null; 875 } 876 } 877 else if(msg.getWhat() == BufferUpdate.CLOSED) 878 { 879 if(bufferSwitcher != null) 880 bufferSwitcher.updateBufferList(); 881 882 if(_buffer == buffer) 883 { 884 Buffer newBuffer = recentBuffer != null ? 886 recentBuffer : _buffer.getPrev(); 887 888 if(newBuffer != null && !newBuffer.isClosed()) 889 { 890 setBuffer(newBuffer); 891 recentBuffer = newBuffer.getPrev(); 892 } 893 else if(jEdit.getBufferCount() != 0) 894 { 895 setBuffer(jEdit.getFirstBuffer()); 896 recentBuffer = null; 897 } 898 } 899 else if(_buffer == recentBuffer) 900 recentBuffer = null; 901 902 Buffer closedBuffer = msg.getBuffer(); 903 if (closedBuffer.isUntitled()) 904 { 905 Map <String , CaretInfo> carets = (Map <String , CaretInfo>) getClientProperty(CARETS); 907 if (carets != null) 908 carets.remove(closedBuffer.getPath()); 909 } 910 } 911 else if(msg.getWhat() == BufferUpdate.LOAD_STARTED) 912 { 913 if(_buffer == buffer) 914 { 915 textArea.setCaretPosition(0); 916 textArea.getPainter().repaint(); 917 } 918 } 919 else if(msg.getWhat() == BufferUpdate.LOADED) 920 { 921 if(_buffer == buffer) 922 { 923 textArea.repaint(); 924 if(bufferSwitcher != null) 925 bufferSwitcher.updateBufferList(); 926 927 if(view.getEditPane() == this) 928 { 929 StatusBar status = view.getStatus(); 930 status.updateCaretStatus(); 931 status.updateBufferStatus(); 932 status.updateMiscStatus(); 933 } 934 935 loadCaretInfo(); 936 } 937 938 } 939 else if(msg.getWhat() == BufferUpdate.DIRTY_CHANGED) 940 { 941 if(_buffer == buffer) 942 { 943 if(bufferSwitcher != null) 944 { 945 if(buffer.isDirty()) 946 bufferSwitcher.repaint(); 947 else 948 bufferSwitcher.updateBufferList(); 949 } 950 } 951 } 952 else if(msg.getWhat() == BufferUpdate.MARKERS_CHANGED) 953 { 954 if(_buffer == buffer) 955 textArea.getGutter().repaint(); 956 } 957 else if(msg.getWhat() == BufferUpdate.PROPERTIES_CHANGED) 958 { 959 if(_buffer == buffer && buffer.isLoaded()) 960 { 961 textArea.propertiesChanged(); 962 if(view.getEditPane() == this) 963 view.getStatus().updateBufferStatus(); 964 } 965 } 966 else if(msg.getWhat() == BufferUpdate.SAVED) 967 { 968 if(_buffer == buffer) 969 textArea.propertiesChanged(); 970 } 971 } 973 975 class StatusHandler implements StatusListener 977 { 978 public void statusChanged(org.gjt.sp.jedit.textarea.TextArea textArea, int flag, boolean value) 979 { 980 StatusBar status = view.getStatus(); 981 if(status == null) 982 return; 983 984 switch(flag) 985 { 986 case OVERWRITE_CHANGED: 987 status.setMessageAndClear( 988 jEdit.getProperty("view.status.overwrite-changed", 989 new Integer [] { value ? 1 : 0 })); 990 break; 991 case MULTI_SELECT_CHANGED: 992 status.setMessageAndClear( 993 jEdit.getProperty("view.status.multi-changed", 994 new Integer [] { value ? 1 : 0 })); 995 break; 996 case RECT_SELECT_CHANGED: 997 status.setMessageAndClear( 998 jEdit.getProperty("view.status.rect-select-changed", 999 new Integer [] { value ? 1 : 0 })); 1000 break; 1001 } 1002 1003 status.updateMiscStatus(); 1004 } 1005 1006 public void bracketSelected(org.gjt.sp.jedit.textarea.TextArea textArea, int line, String text) 1007 { 1008 StatusBar status = view.getStatus(); 1009 if(status == null) 1010 return; 1011 1012 status.setMessageAndClear(jEdit.getProperty( 1013 "view.status.bracket",new Object [] { 1014 line, text })); 1015 } 1016 1017 public void narrowActive(org.gjt.sp.jedit.textarea.TextArea textArea) 1018 { 1019 StatusBar status = view.getStatus(); 1020 if(status == null) 1021 return; 1022 1023 status.setMessageAndClear( 1024 jEdit.getProperty("view.status.narrow")); 1025 } 1026 } 1028 class MarkerHighlight extends TextAreaExtension 1030 { 1031 private boolean markerHighlight; 1032 private Color markerHighlightColor; 1033 1034 public Color getMarkerHighlightColor() 1036 { 1037 return markerHighlightColor; 1038 } 1040 public void setMarkerHighlightColor(Color markerHighlightColor) 1042 { 1043 this.markerHighlightColor = markerHighlightColor; 1044 } 1046 public boolean isMarkerHighlightEnabled() 1048 { 1049 return markerHighlight; 1050 } 1052 public void setMarkerHighlightEnabled(boolean markerHighlight) 1054 { 1055 this.markerHighlight = markerHighlight; 1056 } 1058 public void paintValidLine(Graphics2D gfx, int screenLine, 1060 int physicalLine, int start, int end, int y) 1061 { 1062 if(isMarkerHighlightEnabled()) 1063 { 1064 Buffer buffer = (Buffer)textArea.getBuffer(); 1065 if(buffer.getMarkerInRange(start,end) != null) 1066 { 1067 gfx.setColor(getMarkerHighlightColor()); 1068 FontMetrics fm = textArea.getPainter().getFontMetrics(); 1069 gfx.fillRect(0,y,textArea.getGutter() 1070 .getWidth(),fm.getHeight()); 1071 } 1072 } 1073 } 1075 public String getToolTipText(int x, int y) 1077 { 1078 if(isMarkerHighlightEnabled()) 1079 { 1080 int lineHeight = textArea.getPainter().getFontMetrics().getHeight(); 1081 if(lineHeight == 0) 1082 return null; 1083 1084 int line = y / lineHeight; 1085 int start = textArea.getScreenLineStartOffset(line); 1086 int end = textArea.getScreenLineEndOffset(line); 1087 if(start == -1 || end == -1) 1088 return null; 1089 1090 Buffer buffer = (Buffer)textArea.getBuffer(); 1091 Marker marker = buffer.getMarkerInRange(start,end); 1092 if(marker != null) 1093 { 1094 char shortcut = marker.getShortcut(); 1095 if(shortcut == '\0') 1096 return jEdit.getProperty("view.gutter.marker.no-name"); 1097 else 1098 { 1099 String [] args = { String.valueOf(shortcut) }; 1100 return jEdit.getProperty("view.gutter.marker",args); 1101 } 1102 } 1103 } 1104 1105 return null; 1106 } } } 1109 | Popular Tags |