KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > sp > jedit > textarea > Gutter


1 /*
2  * Gutter.java
3  * :tabSize=8:indentSize=8:noTabs=false:
4  * :folding=explicit:collapseFolds=1:
5  *
6  * Copyright (C) 1999, 2000 mike dillon
7  * Portions copyright (C) 2001, 2002 Slava Pestov
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22  */

23
24 package org.gjt.sp.jedit.textarea;
25
26 //{{{ Imports
27
import java.awt.*;
28 import java.awt.event.*;
29 import javax.swing.*;
30 import javax.swing.border.*;
31 import javax.swing.event.*;
32 import org.gjt.sp.jedit.GUIUtilities;
33 import org.gjt.sp.jedit.buffer.JEditBuffer;
34 import org.gjt.sp.util.Log;
35 //}}}
36

37 /**
38  * The gutter is the component that displays folding triangles and line
39  * numbers to the left of the text area. The only methods in this class
40  * that should be called by plugins are those for adding and removing
41  * text area extensions.
42  *
43  * @see #addExtension(TextAreaExtension)
44  * @see #addExtension(int,TextAreaExtension)
45  * @see #removeExtension(TextAreaExtension)
46  * @see TextAreaExtension
47  * @see TextArea
48  *
49  * @author Mike Dillon and Slava Pestov
50  * @version $Id: Gutter.java 7156 2006-10-02 21:33:17Z kpouer $
51  */

52 public class Gutter extends JComponent implements SwingConstants
53 {
54     //{{{ Layers
55
/**
56      * The lowest possible layer.
57      * @see #addExtension(int,TextAreaExtension)
58      * @since jEdit 4.0pre4
59      */

60     public static final int LOWEST_LAYER = Integer.MIN_VALUE;
61
62     /**
63      * Default extension layer. This is above the wrap guide but below the
64      * bracket highlight.
65      * @since jEdit 4.0pre4
66      */

67     public static final int DEFAULT_LAYER = 0;
68
69     /**
70      * Highest possible layer.
71      * @since jEdit 4.0pre4
72      */

73     public static final int HIGHEST_LAYER = Integer.MAX_VALUE;
74     //}}}
75

76     //{{{ Gutter constructor
77
public Gutter(TextArea textArea)
78     {
79         this.textArea = textArea;
80
81         setAutoscrolls(true);
82         setOpaque(true);
83         setRequestFocusEnabled(false);
84
85         extensionMgr = new ExtensionManager();
86
87         mouseHandler = new MouseHandler();
88         addMouseListener(mouseHandler);
89         addMouseMotionListener(mouseHandler);
90
91         updateBorder();
92     } //}}}
93

94     //{{{ paintComponent() method
95
public void paintComponent(Graphics _gfx)
96     {
97         Graphics2D gfx = (Graphics2D)_gfx;
98
99         // fill the background
100
Rectangle clip = gfx.getClipBounds();
101         gfx.setColor(getBackground());
102         gfx.fillRect(clip.x, clip.y, clip.width, clip.height);
103
104         // if buffer is loading, don't paint anything
105
if (textArea.getBuffer().isLoading())
106             return;
107
108         int lineHeight = textArea.getPainter().getFontMetrics()
109             .getHeight();
110
111         if(lineHeight == 0)
112             return;
113
114         int firstLine = clip.y / lineHeight;
115         int lastLine = (clip.y + clip.height - 1) / lineHeight;
116
117         if(lastLine - firstLine > textArea.getVisibleLines())
118         {
119             Log.log(Log.ERROR,this,"BUG: firstLine=" + firstLine);
120             Log.log(Log.ERROR,this," lastLine=" + lastLine);
121             Log.log(Log.ERROR,this," visibleLines=" + textArea.getVisibleLines());
122             Log.log(Log.ERROR,this," height=" + getHeight());
123             Log.log(Log.ERROR,this," painter.height=" + textArea.getPainter().getHeight());
124             Log.log(Log.ERROR,this," clip.y=" + clip.y);
125             Log.log(Log.ERROR,this," clip.height=" + clip.height);
126             Log.log(Log.ERROR,this," lineHeight=" + lineHeight);
127         }
128     
129         int y = clip.y - clip.y % lineHeight;
130
131         extensionMgr.paintScreenLineRange(textArea,gfx,
132             firstLine,lastLine,y,lineHeight);
133
134         for (int line = firstLine; line <= lastLine;
135             line++, y += lineHeight)
136         {
137             paintLine(gfx,line,y);
138         }
139     } //}}}
140

141     //{{{ addExtension() method
142
/**
143      * Adds a text area extension, which can perform custom painting and
144      * tool tip handling.
145      * @param extension The extension
146      * @since jEdit 4.0pre4
147      */

148     public void addExtension(TextAreaExtension extension)
149     {
150         extensionMgr.addExtension(DEFAULT_LAYER,extension);
151         repaint();
152     } //}}}
153

154     //{{{ addExtension() method
155
/**
156      * Adds a text area extension, which can perform custom painting and
157      * tool tip handling.
158      * @param layer The layer to add the extension to. Note that more than
159      * extension can share the same layer.
160      * @param extension The extension
161      * @since jEdit 4.0pre4
162      */

163     public void addExtension(int layer, TextAreaExtension extension)
164     {
165         extensionMgr.addExtension(layer,extension);
166         repaint();
167     } //}}}
168

169     //{{{ removeExtension() method
170
/**
171      * Removes a text area extension. It will no longer be asked to
172      * perform custom painting and tool tip handling.
173      * @param extension The extension
174      * @since jEdit 4.0pre4
175      */

176     public void removeExtension(TextAreaExtension extension)
177     {
178         extensionMgr.removeExtension(extension);
179         repaint();
180     } //}}}
181

182     //{{{ getExtensions() method
183
/**
184      * Returns an array of registered text area extensions. Useful for
185      * debugging purposes.
186      * @since jEdit 4.1pre5
187      */

188     public TextAreaExtension[] getExtensions()
189     {
190         return extensionMgr.getExtensions();
191     } //}}}
192

193     //{{{ getToolTipText() method
194
/**
195      * Returns the tool tip to display at the specified location.
196      * @param evt The mouse event
197      */

198     public String JavaDoc getToolTipText(MouseEvent evt)
199     {
200         if(textArea.getBuffer().isLoading())
201             return null;
202
203         return extensionMgr.getToolTipText(evt.getX(),evt.getY());
204     } //}}}
205

206     //{{{ setBorder() method
207
/**
208      * Convenience method for setting a default matte border on the right
209      * with the specified border width and color
210      * @param width The border width (in pixels)
211      * @param color1 The focused border color
212      * @param color2 The unfocused border color
213      * @param color3 The gutter/text area gap color
214      */

215     public void setBorder(int width, Color color1, Color color2, Color color3)
216     {
217         borderWidth = width;
218
219         focusBorder = new CompoundBorder(new MatteBorder(0,0,0,width,color3),
220             new MatteBorder(0,0,0,width,color1));
221         noFocusBorder = new CompoundBorder(new MatteBorder(0,0,0,width,color3),
222             new MatteBorder(0,0,0,width,color2));
223         updateBorder();
224     } //}}}
225

226     //{{{ updateBorder() method
227
/**
228      * Sets the border differently if the text area has focus or not.
229      */

230     public void updateBorder()
231     {
232         if (textArea.hasFocus())
233             setBorder(focusBorder);
234         else
235             setBorder(noFocusBorder);
236     } //}}}
237

238     //{{{ setBorder() method
239
/*
240      * JComponent.setBorder(Border) is overridden here to cache the left
241      * inset of the border (if any) to avoid having to fetch it during every
242      * repaint.
243      */

244     public void setBorder(Border border)
245     {
246         super.setBorder(border);
247
248         if (border == null)
249         {
250             collapsedSize.width = 0;
251             collapsedSize.height = 0;
252         }
253         else
254         {
255             Insets insets = border.getBorderInsets(this);
256             collapsedSize.width = FOLD_MARKER_SIZE + insets.right;
257             collapsedSize.height = gutterSize.height
258                 = insets.top + insets.bottom;
259             gutterSize.width = FOLD_MARKER_SIZE + insets.right
260                 + fm.stringWidth("12345");
261         }
262
263         revalidate();
264     } //}}}
265

266     //{{{ setFont() method
267
/*
268      * JComponent.setFont(Font) is overridden here to cache the baseline for
269      * the font. This avoids having to get the font metrics during every
270      * repaint.
271      */

272     public void setFont(Font font)
273     {
274         super.setFont(font);
275
276         fm = getFontMetrics(font);
277
278         baseline = fm.getAscent();
279
280         Border border = getBorder();
281         if(border != null)
282         {
283             gutterSize.width = FOLD_MARKER_SIZE
284                 + border.getBorderInsets(this).right
285                 + fm.stringWidth("12345");
286             revalidate();
287         }
288     } //}}}
289

290     //{{{ Getters and setters
291

292     //{{{ getHighlightedForeground() method
293
/**
294      * Get the foreground color for highlighted line numbers
295      * @return The highlight color
296      */

297     public Color getHighlightedForeground()
298     {
299         return intervalHighlight;
300     } //}}}
301

302     //{{{ setHighlightedForeground() method
303
public void setHighlightedForeground(Color highlight)
304     {
305         intervalHighlight = highlight;
306     } //}}}
307

308     //{{{ getCurrentLineForeground() method
309
public Color getCurrentLineForeground()
310     {
311         return currentLineHighlight;
312     } //}}}
313

314     //{{{ setCurrentLineForeground() method
315
public void setCurrentLineForeground(Color highlight)
316     {
317         currentLineHighlight = highlight;
318     } //}}}
319

320     //{{{ getFoldColor() method
321
public Color getFoldColor()
322     {
323         return foldColor;
324     } //}}}
325

326     //{{{ setFoldColor() method
327
public void setFoldColor(Color foldColor)
328     {
329         this.foldColor = foldColor;
330     } //}}}
331

332     //{{{ getPreferredSize() method
333
/*
334      * Component.getPreferredSize() is overridden here to support the
335      * collapsing behavior.
336      */

337     public Dimension getPreferredSize()
338     {
339         if (expanded)
340             return gutterSize;
341         else
342             return collapsedSize;
343     } //}}}
344

345     //{{{ getMinimumSize() method
346
public Dimension getMinimumSize()
347     {
348         return getPreferredSize();
349     } //}}}
350

351     //{{{ getLineNumberAlignment() method
352
/**
353      * Identifies whether the horizontal alignment of the line numbers.
354      * @return Gutter.RIGHT, Gutter.CENTER, Gutter.LEFT
355      */

356     public int getLineNumberAlignment()
357     {
358         return alignment;
359     } //}}}
360

361     //{{{ setLineNumberAlignment() method
362
/**
363      * Sets the horizontal alignment of the line numbers.
364      * @param alignment Gutter.RIGHT, Gutter.CENTER, Gutter.LEFT
365      */

366     public void setLineNumberAlignment(int alignment)
367     {
368         if (this.alignment == alignment) return;
369
370         this.alignment = alignment;
371
372         repaint();
373     } //}}}
374

375     //{{{ isExpanded() method
376
/**
377      * Identifies whether the gutter is collapsed or expanded.
378      * @return true if the gutter is expanded, false if it is collapsed
379      */

380     public boolean isExpanded()
381     {
382         return expanded;
383     } //}}}
384

385     //{{{ setExpanded() method
386
/**
387      * Sets whether the gutter is collapsed or expanded and force the text
388      * area to update its layout if there is a change.
389      * @param expanded true if the gutter is expanded,
390      * false if it is collapsed
391      */

392     public void setExpanded(boolean expanded)
393     {
394         if (this.expanded == expanded) return;
395
396         this.expanded = expanded;
397
398         textArea.revalidate();
399     } //}}}
400

401     //{{{ toggleExpanded() method
402
/**
403      * Toggles whether the gutter is collapsed or expanded.
404      */

405     public void toggleExpanded()
406     {
407         setExpanded(!expanded);
408     } //}}}
409

410     //{{{ getHighlightInterval() method
411
/**
412      * Sets the number of lines between highlighted line numbers.
413      * @return The number of lines between highlighted line numbers or
414      * zero if highlighting is disabled
415      */

416     public int getHighlightInterval()
417     {
418         return interval;
419     } //}}}
420

421     //{{{ setHighlightInterval() method
422
/**
423      * Sets the number of lines between highlighted line numbers. Any value
424      * less than or equal to one will result in highlighting being disabled.
425      * @param interval The number of lines between highlighted line numbers
426      */

427     public void setHighlightInterval(int interval)
428     {
429         if (interval <= 1) interval = 0;
430         this.interval = interval;
431         repaint();
432     } //}}}
433

434     //{{{ isCurrentLineHighlightEnabled() method
435
public boolean isCurrentLineHighlightEnabled()
436     {
437         return currentLineHighlightEnabled;
438     } //}}}
439

440     //{{{ setCurrentLineHighlightEnabled() method
441
public void setCurrentLineHighlightEnabled(boolean enabled)
442     {
443         if (currentLineHighlightEnabled == enabled) return;
444
445         currentLineHighlightEnabled = enabled;
446
447         repaint();
448     } //}}}
449

450     //{{{ getStructureHighlightColor() method
451
/**
452      * Returns the structure highlight color.
453      * @since jEdit 4.2pre3
454      */

455     public final Color getStructureHighlightColor()
456     {
457         return structureHighlightColor;
458     } //}}}
459

460     //{{{ setStructureHighlightColor() method
461
/**
462      * Sets the structure highlight color.
463      * @param structureHighlightColor The structure highlight color
464      * @since jEdit 4.2pre3
465      */

466     public final void setStructureHighlightColor(Color structureHighlightColor)
467     {
468         this.structureHighlightColor = structureHighlightColor;
469         repaint();
470     } //}}}
471

472     //{{{ isStructureHighlightEnabled() method
473
/**
474      * Returns true if structure highlighting is enabled, false otherwise.
475      * @since jEdit 4.2pre3
476      */

477     public final boolean isStructureHighlightEnabled()
478     {
479         return structureHighlight;
480     } //}}}
481

482     //{{{ setStructureHighlightEnabled() method
483
/**
484      * Enables or disables structure highlighting.
485      * @param structureHighlight True if structure highlighting should be
486      * enabled, false otherwise
487      * @since jEdit 4.2pre3
488      */

489     public final void setStructureHighlightEnabled(boolean structureHighlight)
490     {
491         this.structureHighlight = structureHighlight;
492         repaint();
493     } //}}}
494

495     public void setMouseActionsProvider(MouseActionsProvider mouseActionsProvider)
496     {
497         mouseHandler.mouseActions = mouseActionsProvider;
498     }
499     //}}}
500

501     //{{{ Private members
502

503     //{{{ Instance variables
504
private static final int FOLD_MARKER_SIZE = 12;
505
506     private final TextArea textArea;
507     private MouseHandler mouseHandler;
508     private ExtensionManager extensionMgr;
509
510     private int baseline;
511
512     private Dimension gutterSize = new Dimension(0,0);
513     private Dimension collapsedSize = new Dimension(0,0);
514
515     private Color intervalHighlight;
516     private Color currentLineHighlight;
517     private Color foldColor;
518
519     private FontMetrics fm;
520
521     private int alignment;
522
523     private int interval;
524     private boolean currentLineHighlightEnabled;
525     private boolean expanded;
526
527     private boolean structureHighlight;
528     private Color structureHighlightColor;
529
530     private int borderWidth;
531     private Border focusBorder, noFocusBorder;
532     //}}}
533

534     //{{{ paintLine() method
535
private void paintLine(Graphics2D gfx, int line, int y)
536     {
537         JEditBuffer buffer = textArea.getBuffer();
538         if(buffer.isLoading())
539             return;
540
541         int lineHeight = textArea.getPainter().getFontMetrics()
542             .getHeight();
543
544         ChunkCache.LineInfo info = textArea.chunkCache.getLineInfo(line);
545         int physicalLine = info.physicalLine;
546
547         // Skip lines beyond EOF
548
if(physicalLine == -1)
549             return;
550
551         //{{{ Paint fold triangles
552
if(info.firstSubregion && buffer.isFoldStart(physicalLine))
553         {
554             int _y = y + lineHeight / 2;
555             gfx.setColor(foldColor);
556             if(textArea.displayManager
557                 .isLineVisible(physicalLine + 1))
558             {
559                 gfx.drawLine(1,_y - 3,10,_y - 3);
560                 gfx.drawLine(2,_y - 2,9,_y - 2);
561                 gfx.drawLine(3,_y - 1,8,_y - 1);
562                 gfx.drawLine(4,_y,7,_y);
563                 gfx.drawLine(5,_y + 1,6,_y + 1);
564             }
565             else
566             {
567                 gfx.drawLine(4,_y - 5,4,_y + 4);
568                 gfx.drawLine(5,_y - 4,5,_y + 3);
569                 gfx.drawLine(6,_y - 3,6,_y + 2);
570                 gfx.drawLine(7,_y - 2,7,_y + 1);
571                 gfx.drawLine(8,_y - 1,8,_y);
572             }
573         }
574         else if(info.lastSubregion && buffer.isFoldEnd(physicalLine))
575         {
576             gfx.setColor(foldColor);
577             int _y = y + lineHeight / 2;
578             gfx.drawLine(4,_y,4,_y + 3);
579             gfx.drawLine(4,_y + 3,7,_y + 3);
580         } //}}}
581
//{{{ Paint bracket scope
582
else if(structureHighlight)
583         {
584             StructureMatcher.Match match = textArea.getStructureMatch();
585             int caretLine = textArea.getCaretLine();
586
587             if(textArea.isStructureHighlightVisible()
588                 && physicalLine >= Math.min(caretLine,match.startLine)
589                 && physicalLine <= Math.max(caretLine,match.startLine))
590             {
591                 int caretScreenLine;
592                 if(caretLine > textArea.getLastPhysicalLine())
593                     caretScreenLine = Integer.MAX_VALUE;
594                 else if(textArea.displayManager.isLineVisible(
595                         textArea.getCaretLine()))
596                 {
597                     caretScreenLine = textArea
598                         .getScreenLineOfOffset(
599                         textArea.getCaretPosition());
600                 }
601                 else
602                 {
603                     caretScreenLine = -1;
604                 }
605
606                 int structScreenLine;
607                 if(match.startLine > textArea.getLastPhysicalLine())
608                     structScreenLine = Integer.MAX_VALUE;
609                 else if(textArea.displayManager.isLineVisible(
610                         match.startLine))
611                 {
612                     structScreenLine = textArea
613                         .getScreenLineOfOffset(
614                         match.start);
615                 }
616                 else
617                 {
618                     structScreenLine = -1;
619                 }
620
621                 if(caretScreenLine > structScreenLine)
622                 {
623                     int tmp = caretScreenLine;
624                     caretScreenLine = structScreenLine;
625                     structScreenLine = tmp;
626                 }
627
628                 gfx.setColor(structureHighlightColor);
629                 if(structScreenLine == caretScreenLine)
630                 {
631                     // do nothing
632
}
633                 // draw |^
634
else if(line == caretScreenLine)
635                 {
636                     gfx.fillRect(5,
637                         y
638                         + lineHeight / 2,
639                         5,
640                         2);
641                     gfx.fillRect(5,
642                         y
643                         + lineHeight / 2,
644                         2,
645                         lineHeight - lineHeight / 2);
646                 }
647                 // draw |_
648
else if(line == structScreenLine)
649                 {
650                     gfx.fillRect(5,
651                         y,
652                         2,
653                         lineHeight / 2);
654                     gfx.fillRect(5,
655                         y + lineHeight / 2,
656                         5,
657                         2);
658                 }
659                 // draw |
660
else if(line > caretScreenLine
661                     && line < structScreenLine)
662                 {
663                     gfx.fillRect(5,
664                         y,
665                         2,
666                         lineHeight);
667                 }
668             }
669         } //}}}
670

671         //{{{ Paint line numbers
672
if(info.firstSubregion && expanded)
673         {
674             String JavaDoc number = Integer.toString(physicalLine + 1);
675
676             int offset;
677             switch (alignment)
678             {
679             case RIGHT:
680                 offset = gutterSize.width - collapsedSize.width
681                     - (fm.stringWidth(number) + 1);
682                 break;
683             case CENTER:
684                 offset = ((gutterSize.width - collapsedSize.width)
685                     - fm.stringWidth(number)) / 2;
686                 break;
687             case LEFT: default:
688                 offset = 0;
689                 break;
690             }
691
692             if (physicalLine == textArea.getCaretLine() && currentLineHighlightEnabled)
693             {
694                 gfx.setColor(currentLineHighlight);
695             }
696             else if (interval > 1 && (line
697                 + textArea.getFirstLine() + 1)
698                 % interval == 0)
699                 gfx.setColor(intervalHighlight);
700             else
701                 gfx.setColor(getForeground());
702
703             gfx.drawString(number, FOLD_MARKER_SIZE + offset,
704                 baseline + y);
705         } //}}}
706
} //}}}
707

708     //}}}
709

710     //{{{ MouseHandler class
711
class MouseHandler extends MouseInputAdapter
712     {
713         MouseActionsProvider mouseActions;
714         boolean drag;
715         int toolTipInitialDelay, toolTipReshowDelay;
716
717         //{{{ mouseEntered() method
718
public void mouseEntered(MouseEvent e)
719         {
720             ToolTipManager ttm = ToolTipManager.sharedInstance();
721             toolTipInitialDelay = ttm.getInitialDelay();
722             toolTipReshowDelay = ttm.getReshowDelay();
723             ttm.setInitialDelay(0);
724             ttm.setReshowDelay(0);
725         } //}}}
726

727         //{{{ mouseExited() method
728
public void mouseExited(MouseEvent evt)
729         {
730             ToolTipManager ttm = ToolTipManager.sharedInstance();
731             ttm.setInitialDelay(toolTipInitialDelay);
732             ttm.setReshowDelay(toolTipReshowDelay);
733         } //}}}
734

735         //{{{ mousePressed() method
736
public void mousePressed(MouseEvent e)
737         {
738             textArea.requestFocus();
739
740             if(GUIUtilities.isPopupTrigger(e)
741                 || e.getX() >= getWidth() - borderWidth * 2)
742             {
743                 e.translatePoint(-getWidth(),0);
744                 textArea.mouseHandler.mousePressed(e);
745                 drag = true;
746             }
747             else
748             {
749                 JEditBuffer buffer = textArea.getBuffer();
750
751                 int screenLine = e.getY() / textArea.getPainter()
752                     .getFontMetrics().getHeight();
753
754                 int line = textArea.chunkCache.getLineInfo(screenLine)
755                     .physicalLine;
756
757                 if(line == -1)
758                     return;
759
760                 //{{{ Determine action
761
String JavaDoc defaultAction;
762                 String JavaDoc variant;
763                 if(buffer.isFoldStart(line))
764                 {
765                     defaultAction = "toggle-fold";
766                     variant = "fold";
767                 }
768                 else if(structureHighlight
769                     && textArea.isStructureHighlightVisible()
770                     && textArea.lineInStructureScope(line))
771                 {
772                     defaultAction = "match-struct";
773                     variant = "struct";
774                 }
775                 else
776                     return;
777
778                 String JavaDoc action = null;
779
780                 if (mouseActions != null)
781                     action = mouseActions.getActionForEvent(
782                         e,variant);
783
784                 if(action == null)
785                     action = defaultAction;
786                 //}}}
787

788                 //{{{ Handle actions
789
StructureMatcher.Match match = textArea
790                     .getStructureMatch();
791
792                 if(action.equals("select-fold"))
793                 {
794                     textArea.displayManager.expandFold(line,true);
795                     textArea.selectFold(line);
796                 }
797                 else if(action.equals("narrow-fold"))
798                 {
799                     int[] lines = buffer.getFoldAtLine(line);
800                     textArea.displayManager.narrow(lines[0],lines[1]);
801                 }
802                 else if(action.startsWith("toggle-fold"))
803                 {
804                     if(textArea.displayManager
805                         .isLineVisible(line + 1))
806                     {
807                         textArea.collapseFold(line);
808                     }
809                     else
810                     {
811                         if(action.endsWith("-fully"))
812                         {
813                             textArea.displayManager
814                                 .expandFold(line,
815                                 true);
816                         }
817                         else
818                         {
819                             textArea.displayManager
820                                 .expandFold(line,
821                                 false);
822                         }
823                     }
824                 }
825                 else if(action.equals("match-struct"))
826                 {
827                     if(match != null)
828                         textArea.setCaretPosition(match.end);
829                 }
830                 else if(action.equals("select-struct"))
831                 {
832                     if(match != null)
833                     {
834                         match.matcher.selectMatch(
835                             textArea);
836                     }
837                 }
838                 else if(action.equals("narrow-struct"))
839                 {
840                     if(match != null)
841                     {
842                         int start = Math.min(
843                             match.startLine,
844                             textArea.getCaretLine());
845                         int end = Math.max(
846                             match.endLine,
847                             textArea.getCaretLine());
848                         textArea.displayManager.narrow(start,end);
849                     }
850                 } //}}}
851
}
852         } //}}}
853

854         //{{{ mouseDragged() method
855
public void mouseDragged(MouseEvent e)
856         {
857             if(drag /* && e.getX() >= getWidth() - borderWidth * 2 */)
858             {
859                 e.translatePoint(-getWidth(),0);
860                 textArea.mouseHandler.mouseDragged(e);
861             }
862         } //}}}
863

864         //{{{ mouseReleased() method
865
public void mouseReleased(MouseEvent e)
866         {
867             if(drag && e.getX() >= getWidth() - borderWidth * 2)
868             {
869                 e.translatePoint(-getWidth(),0);
870                 textArea.mouseHandler.mouseReleased(e);
871             }
872
873             drag = false;
874         } //}}}
875
} //}}}
876
}
877
Popular Tags