|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JScrollPane
edu.princeton.swing.PHighlightedTextArea
public class PHighlightedTextArea
PHighlightedTextArea is a multi-purpose text area which supports syntax highlighting, line highlighting, and column markers. It's important to note that the PHighlightedTextArea is a JScrollPane, so it is unnecessary (and probably undesireable) to put it in a JScrollPane.
Nested Class Summary | |
---|---|
protected class |
PHighlightedTextArea.InternalNumberedArea
InternalNumberedArea is the subcomponent of PHighlightedTextArea which shows the line numbers. |
protected class |
PHighlightedTextArea.InternalTextArea
InternalTextArea is the subcomponent of PHighlightedTextArea which shows the editable program code. |
Nested classes/interfaces inherited from class javax.swing.JScrollPane |
---|
JScrollPane.AccessibleJScrollPane, JScrollPane.ScrollBar |
Nested classes/interfaces inherited from class javax.swing.JComponent |
---|
JComponent.AccessibleJComponent |
Nested classes/interfaces inherited from class java.awt.Container |
---|
Container.AccessibleAWTContainer |
Nested classes/interfaces inherited from class java.awt.Component |
---|
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy |
Field Summary | |
---|---|
static AutoCompleter |
DEFAULT_AUTO_COMPLETER
A static instance of DefaultAutoCompleter for general usage. |
static Color |
DEFAULT_BACKGROUND
The default background color. |
static Color |
DEFAULT_FOREGROUND
The default foreground color. |
static int |
FOLLOW_CARET
The value that highlightedLine should take so that the line highlight will follow the caret. |
static int |
NEVER_HIGHLIGHT
The value that highlightedLine should take so that no line is highlighted. |
static int |
NO_CHANGE
The value to pass to select(int, int, int) which will be interpreted as the command not to change a specified value. |
static int |
NO_HIGHLIGHT
The value that highlightedLine should take so that no line is highlighted. |
Fields inherited from class javax.swing.JScrollPane |
---|
columnHeader, horizontalScrollBar, horizontalScrollBarPolicy, lowerLeft, lowerRight, rowHeader, upperLeft, upperRight, verticalScrollBar, verticalScrollBarPolicy, viewport |
Fields inherited from class javax.swing.JComponent |
---|
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
Fields inherited from class java.awt.Component |
---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
Fields inherited from interface java.awt.image.ImageObserver |
---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
---|---|
PHighlightedTextArea()
Constructs a new PHighlightedTextArea. |
|
PHighlightedTextArea(HighlightedDocument document)
Constructs a new PHighlightedTextArea. |
|
PHighlightedTextArea(HighlightedDocument document,
int rows,
int columns)
Constructs a new PHighlightedTextArea. |
|
PHighlightedTextArea(int rows,
int columns)
Constructs a new PHighlightedTextArea. |
Method Summary | |
---|---|
boolean |
canCopy()
Returns wheter or not the copy operation can be performed on this ClipboardTarget. |
boolean |
canCut()
Returns wheter or not the cut operation can be performed on this ClipboardTarget. |
boolean |
canPaste()
Returns wheter or not the paste operation can be performed on this ClipboardTarget. |
boolean |
canSelectAll()
Returns wheter or not the selectAll operation can be performed on this ClipboardTarget. |
void |
copy()
Performs the copy operation on the selected text. |
void |
cut()
Performs the cut operation on the selected text. |
void |
finalize()
Stops the caret-blinking thread. |
AutoCompleter |
getAutoCompleter()
Returns the AutoCompleter for this PHighlightedTextArea. |
Color |
getCaretColor()
Gets the color of the caret. |
int |
getCaretPosition()
Returns the location of the caret. |
int[] |
getColumnMarkers()
Gets the location of the column markers. |
Color |
getDisabledTextColor()
Gets the color for the text if this component is disabled. |
HighlightedDocument |
getDocument()
Returns the document that this PHighlightedTextArea represents. |
Color |
getHighlightColor()
Gets the color for the background in a line which is highlighted. |
int |
getHighlightedLine()
Gets the line which is to be highlighted. |
Color |
getHighlightedTextColor()
Gets the color for the text in a line which is highlighted. |
boolean |
getInsertMode()
Returns wheter or not this component is in insert mode. |
Color |
getLineNumberColor()
Gets the color of the line numbers. |
Color |
getMarkerColor()
Gets the color for the column marker. |
JPopupMenu |
getPopupMenu()
Gets the popup menu for this component. |
String |
getSelectedText()
Returns the selected text. |
Color |
getSelectedTextColor()
Gets the color for the text which is in the selected range. |
Color |
getSelectionColor()
Gets the color for the background which is in the selected range. |
int |
getSelectionDot()
Gets the end of the selection which is supposed to 'move'. |
int |
getSelectionEnd()
Gets the end of the selection. |
int |
getSelectionMark()
Gets the end of the selection which is supposed to be 'anchored'. |
int |
getSelectionStart()
Gets the start of the selection. |
boolean |
getShowLineNumbers()
Indicates wheter or not the lines are numbered. |
HighlightStyle |
getStyle(int index)
Gets the style for a specified index. |
int |
getStyleCount()
Returns the number of styles represented in this JHighlightTextArea. |
String |
getText()
Returns the text of the document. |
boolean |
isEditable()
Returns wheter or not this component is editable by the user. |
Point |
modelToView(int column,
int line)
Converts a (column, line) coordinate in the text to an actual pixel coordinate in the PHighlightedTextArea. |
Point |
modelToView(Point p)
Converts a (column, line) coordinate in the text to an actual pixel coordinate in the PHighlightedTextArea. |
void |
paste()
Performs the paste operation on the selected text. |
void |
recalculateSizes()
Recalculates the preferred/minimum sizes of the InternalNumberedArea and InternalTextArea. |
void |
scrollToCaret()
If this PHighlightedTextArea is in a JViewport, the viewport's viewPosition will be changed so that the caret (or the highlighted line, if the caret is not visible) is showing. |
void |
select(int selectionDot,
int selectionMark)
Selects the specified range of text. |
void |
select(int selectionDot,
int selectionMark,
int caretPosition)
Selects the specified range of text and moves the caret to a specified location. |
void |
selectAll()
Selects all of the text. |
void |
setAutoCompleter(AutoCompleter autoCompleter)
Sets the AutoCompleter for this PHighlightedTextArea. |
void |
setCaretColor(Color caretColor)
Sets the color of the caret. |
void |
setCaretPosition(int caretPosition)
Sets the location of the caret. |
void |
setColumnMarkers(int[] columnMarkers)
Sets the location of the column markers. |
void |
setDisabledTextColor(Color disabledTextColor)
Sets the color for the text if this component is disabled. |
void |
setDocument(HighlightedDocument document)
Sets the document that this PHighlightedTextArea represents. |
void |
setEditable(boolean editable)
Sets wheter or not this component is editable by the user. |
void |
setEnabled(boolean enabled)
Override the setEnabled() method to intercept any changes concerning the enabled status of the component. |
void |
setFont(Font font)
Override the setFont function to capture changes in the font. |
void |
setHighlightColor(Color highlightColor)
Sets the color for the background in a line which is highlighted. |
void |
setHighlightedLine(int highlightedLine)
Sets the line which is to be highlighted. |
void |
setHighlightedTextColor(Color highlightedTextColor)
Sets the color for the text in a line which is highlighted. |
void |
setInsertMode(boolean insertMode)
Sets wheter or not this component is in insert mode. |
void |
setLineNumberColor(Color lineNumberColor)
Sets the color of the line numbers. |
void |
setMarkerColor(Color markerColor)
Sets the color for the column marker. |
void |
setPopupMenu(JPopupMenu popupMenu)
Sets the popup menu for this component. |
void |
setSelectedTextColor(Color selectedTextColor)
Sets the color for the text which is in the selected range. |
void |
setSelectionColor(Color selectionColor)
Sets the color for the background which is in the selected range. |
void |
setShowLineNumbers(boolean showLineNumbers)
Sets wheter or not the lines should be numbered. |
void |
setStyle(HighlightStyle style,
int index)
Gets the style for a specified index. |
void |
setText(String text)
Sets the text of the document. |
void |
textValueChanged(TextEvent e)
Implement TextListener to recalculate things whenever the document is edited. |
Point |
viewToModel(int x,
int y)
Converts an actual pixel coordinate in the PHighlightedTextArea to a (column, line) coordinate in the text. |
Point |
viewToModel(Point p)
Converts an actual pixel coordinate in the PHighlightedTextArea to a (column, line) coordinate in the text. |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int FOLLOW_CARET
public static final int NEVER_HIGHLIGHT
public static final int NO_HIGHLIGHT
public static final int NO_CHANGE
public static final AutoCompleter DEFAULT_AUTO_COMPLETER
public static final Color DEFAULT_FOREGROUND
public static final Color DEFAULT_BACKGROUND
Constructor Detail |
---|
public PHighlightedTextArea()
public PHighlightedTextArea(HighlightedDocument document)
public PHighlightedTextArea(int rows, int columns)
public PHighlightedTextArea(HighlightedDocument document, int rows, int columns)
Method Detail |
---|
public void finalize() throws Throwable
finalize
in class Object
Throwable
public Point modelToView(Point p)
p
- The point in the text (where x is the column and y is the line).
public Point modelToView(int column, int line)
column
- The column of the text coordinate.line
- The line of the text coordinate.
public Point viewToModel(Point p)
p
- The point in the PHighlightedTextArea.
public Point viewToModel(int x, int y)
x
- The x component of the pixel coordinate.y
- The y component of the pixel coordinate.
public JPopupMenu getPopupMenu()
public void setPopupMenu(JPopupMenu popupMenu)
popupMenu
- The popup menu for the component. A null value indicates that this
component should not have a popup menu.public void setEnabled(boolean enabled)
setEnabled
in class JComponent
public Color getCaretColor()
public void setCaretColor(Color caretColor)
caretColor
- The new color of the caret.public Color getLineNumberColor()
public void setLineNumberColor(Color lineNumberColor)
lineNumberColor
- The color of the line numbers.public Color getDisabledTextColor()
public void setDisabledTextColor(Color disabledTextColor)
disabledTextColor
- The color for the text if this component is disabled.public boolean getShowLineNumbers()
public void setShowLineNumbers(boolean showLineNumbers)
showLineNumbers
- True iff the lines should be numbered.public boolean isEditable()
public void setEditable(boolean editable)
editable
- The new value for editable.public boolean getInsertMode()
public void setInsertMode(boolean insertMode)
insertMode
- The new value for insertMode.public Color getMarkerColor()
public void setMarkerColor(Color markerColor)
markerColor
- The color for the column marker.public int[] getColumnMarkers()
public void setColumnMarkers(int[] columnMarkers)
columnMarkers
- The columns at which to put markers.public int getCaretPosition()
public void setCaretPosition(int caretPosition)
caretPosition
- The new offset of the caret with respect to the start of the text.
A NO_CHANGE value will cause the entire selection to move to the caret's current position.public Color getSelectedTextColor()
public void setSelectedTextColor(Color selectedTextColor)
selectedTextColor
- The color for the text which is selected.public Color getSelectionColor()
public void setSelectionColor(Color selectionColor)
selectionColor
- The color for the background which is selected.public int getSelectionStart()
public int getSelectionEnd()
public int getSelectionDot()
public int getSelectionMark()
public String getSelectedText()
public boolean canSelectAll()
canSelectAll
in interface ClipboardTarget
public void selectAll()
selectAll
in interface ClipboardTarget
public void select(int selectionDot, int selectionMark)
selectionDot
- The new position of the selection's dot. A value of NO_CHANGE will just
move the caret to the dot's current position.selectionMark
- The new position of the selection's mark.public void select(int selectionDot, int selectionMark, int caretPosition)
selectionDot
- The new position of the selection's dot.selectionMark
- The new position of the selection's mark.caretPosition
- The new position of the caret.public Color getHighlightedTextColor()
public void setHighlightedTextColor(Color highlightedTextColor)
highlightedTextColor
- The color for the text in a line which is highlighted.public Color getHighlightColor()
public void setHighlightColor(Color highlightColor)
highlightColor
- The color for the background in a line which is highlighted.public int getHighlightedLine()
public void setHighlightedLine(int highlightedLine)
highlightedLine
- The line which is to be highlighted. If the specified line is neither
FOLLOW_CARET nor a line that exists in the text, then no line will be highlighted.public boolean canCut()
canCut
in interface ClipboardTarget
public void cut()
cut
in interface ClipboardTarget
public boolean canCopy()
canCopy
in interface ClipboardTarget
public void copy()
copy
in interface ClipboardTarget
public boolean canPaste()
canPaste
in interface ClipboardTarget
public void paste()
paste
in interface ClipboardTarget
public String getText()
public void setText(String text)
text
- The new text of the document.public HighlightedDocument getDocument()
public void setDocument(HighlightedDocument document)
document
- The new document that this PHighlightedTextArea should represent.public void setFont(Font font)
setFont
in class JComponent
public int getStyleCount()
public HighlightStyle getStyle(int index)
index
- The index of the style.
public void setStyle(HighlightStyle style, int index)
style
- The new style for that index.index
- The index of the style.public AutoCompleter getAutoCompleter()
public void setAutoCompleter(AutoCompleter autoCompleter)
autoCompleter
- The new AutoCompleter for this PHighlightedTextArea.public void recalculateSizes()
public void scrollToCaret()
public void textValueChanged(TextEvent e)
textValueChanged
in interface TextListener
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |