source: other-projects/rsyntax-textarea/src/java/org/fife/ui/rtextarea/AbstractGutterComponent.java@ 25584

Last change on this file since 25584 was 25584, checked in by davidb, 12 years ago

Initial cut an a text edit area for GLI that supports color syntax highlighting

File size: 2.9 KB
Line 
1/*
2 * 02/17/2009
3 *
4 * AbstractGutterComponent.java - A component that can be displayed in a Gutter.
5 *
6 * This library is distributed under a modified BSD license. See the included
7 * RSyntaxTextArea.License.txt file for details.
8 */
9package org.fife.ui.rtextarea;
10
11import java.awt.Container;
12import java.awt.Rectangle;
13import java.awt.Shape;
14import javax.swing.JPanel;
15import javax.swing.event.DocumentEvent;
16import javax.swing.text.View;
17
18
19/**
20 * A component that can be displayed in a {@link Gutter}.
21 *
22 * @author Robert Futrell
23 * @version 1.0
24 */
25abstract class AbstractGutterComponent extends JPanel {
26
27 /**
28 * The text area whose lines we are marking with icons.
29 */
30 protected RTextArea textArea;
31
32 /**
33 * The number of lines in the text area.
34 */
35 protected int currentLineCount;
36
37
38 /**
39 * Constructor.
40 *
41 * @param textArea The text area.
42 */
43 public AbstractGutterComponent(RTextArea textArea) {
44 setTextArea(textArea);
45 }
46
47
48 /**
49 * Returns the bounds of a child view as a rectangle, since
50 * <code>View</code>s tend to use <code>Shape</code>.
51 *
52 * @param parent The parent view of the child whose bounds we're getting.
53 * @param line The index of the child view.
54 * @param editorRect Returned from the text area's
55 * <code>getVisibleEditorRect</code> method.
56 * @return The child view's bounds.
57 */
58 protected static final Rectangle getChildViewBounds(View parent, int line,
59 Rectangle editorRect) {
60 Shape alloc = parent.getChildAllocation(line, editorRect);
61 if (alloc==null) {
62 // WrappedSyntaxView can have this when made so small it's
63 // no longer visible
64 return new Rectangle();
65 }
66 return alloc instanceof Rectangle ? (Rectangle)alloc :
67 alloc.getBounds();
68 }
69
70
71 /**
72 * Returns the parent <code>Gutter</code> component.
73 *
74 * @return The parent <code>Gutter</code>.
75 */
76 protected Gutter getGutter() {
77 Container parent = getParent();
78 return (parent instanceof Gutter) ? (Gutter)parent : null;
79 }
80
81
82 /**
83 * Called when text is inserted to or removed from the text area.
84 * Implementations can take this opportunity to repaint, revalidate, etc.
85 *
86 * @param e The document event.
87 */
88 abstract void handleDocumentEvent(DocumentEvent e);
89
90
91 /**
92 * Called when the line heights of the text area change. This is usually
93 * the result of one or more of the fonts in the editor changing.
94 */
95 abstract void lineHeightsChanged();
96
97
98 /**
99 * Sets the text area being displayed. Subclasses can override, but
100 * should call the super implementation.
101 *
102 * @param textArea The text area.
103 */
104 public void setTextArea(RTextArea textArea) {
105 this.textArea = textArea;
106 int lineCount = textArea==null ? 0 : textArea.getLineCount();
107 if (currentLineCount!=lineCount) {
108 currentLineCount = lineCount;
109 repaint();
110 }
111 }
112
113
114}
Note: See TracBrowser for help on using the repository browser.