edu.princeton.swing
Class PHighlightedTextArea

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JScrollPane
                  extended by edu.princeton.swing.PHighlightedTextArea
All Implemented Interfaces:
ClipboardTarget, TextListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, ScrollPaneConstants

public class PHighlightedTextArea
extends JScrollPane
implements TextListener, ClipboardTarget

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.

See Also:
Serialized Form

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 javax.swing.ScrollPaneConstants
COLUMN_HEADER, HORIZONTAL_SCROLLBAR, HORIZONTAL_SCROLLBAR_ALWAYS, HORIZONTAL_SCROLLBAR_AS_NEEDED, HORIZONTAL_SCROLLBAR_NEVER, HORIZONTAL_SCROLLBAR_POLICY, LOWER_LEADING_CORNER, LOWER_LEFT_CORNER, LOWER_RIGHT_CORNER, LOWER_TRAILING_CORNER, ROW_HEADER, UPPER_LEADING_CORNER, UPPER_LEFT_CORNER, UPPER_RIGHT_CORNER, UPPER_TRAILING_CORNER, VERTICAL_SCROLLBAR, VERTICAL_SCROLLBAR_ALWAYS, VERTICAL_SCROLLBAR_AS_NEEDED, VERTICAL_SCROLLBAR_NEVER, VERTICAL_SCROLLBAR_POLICY, VIEWPORT
 
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 javax.swing.JScrollPane
createHorizontalScrollBar, createVerticalScrollBar, createViewport, getAccessibleContext, getColumnHeader, getCorner, getHorizontalScrollBar, getHorizontalScrollBarPolicy, getRowHeader, getUI, getUIClassID, getVerticalScrollBar, getVerticalScrollBarPolicy, getViewport, getViewportBorder, getViewportBorderBounds, isValidateRoot, isWheelScrollingEnabled, paramString, setColumnHeader, setColumnHeaderView, setComponentOrientation, setCorner, setHorizontalScrollBar, setHorizontalScrollBarPolicy, setLayout, setRowHeader, setRowHeaderView, setUI, setVerticalScrollBar, setVerticalScrollBarPolicy, setViewport, setViewportBorder, setViewportView, setWheelScrollingEnabled, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setFocusTraversalKeys, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

FOLLOW_CARET

public static final int FOLLOW_CARET
The value that highlightedLine should take so that the line highlight will follow the caret. A TOptionFrame will change this to NO_HIGHLIGHT if it is called for.

See Also:
Constant Field Values

NEVER_HIGHLIGHT

public static final int NEVER_HIGHLIGHT
The value that highlightedLine should take so that no line is highlighted. A TOptionFrame will never change this value even if it is called for.

See Also:
Constant Field Values

NO_HIGHLIGHT

public static final int NO_HIGHLIGHT
The value that highlightedLine should take so that no line is highlighted. A TOptionFrame will change this to FOLLOW_CARET if it is called for.

See Also:
Constant Field Values

NO_CHANGE

public static final 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.

See Also:
Constant Field Values

DEFAULT_AUTO_COMPLETER

public static final AutoCompleter DEFAULT_AUTO_COMPLETER
A static instance of DefaultAutoCompleter for general usage.


DEFAULT_FOREGROUND

public static final Color DEFAULT_FOREGROUND
The default foreground color.


DEFAULT_BACKGROUND

public static final Color DEFAULT_BACKGROUND
The default background color.

Constructor Detail

PHighlightedTextArea

public PHighlightedTextArea()
Constructs a new PHighlightedTextArea.


PHighlightedTextArea

public PHighlightedTextArea(HighlightedDocument document)
Constructs a new PHighlightedTextArea.


PHighlightedTextArea

public PHighlightedTextArea(int rows,
                            int columns)
Constructs a new PHighlightedTextArea.


PHighlightedTextArea

public PHighlightedTextArea(HighlightedDocument document,
                            int rows,
                            int columns)
Constructs a new PHighlightedTextArea.

Method Detail

finalize

public void finalize()
              throws Throwable
Stops the caret-blinking thread.

Overrides:
finalize in class Object
Throws:
Throwable

modelToView

public Point modelToView(Point p)
Converts a (column, line) coordinate in the text to an actual pixel coordinate in the PHighlightedTextArea.

Parameters:
p - The point in the text (where x is the column and y is the line).
Returns:
The corresponding point in the PHighlightedTextArea.

modelToView

public Point modelToView(int column,
                         int line)
Converts a (column, line) coordinate in the text to an actual pixel coordinate in the PHighlightedTextArea.

Parameters:
column - The column of the text coordinate.
line - The line of the text coordinate.
Returns:
The corresponding point in the PHighlightedTextArea.

viewToModel

public Point viewToModel(Point p)
Converts an actual pixel coordinate in the PHighlightedTextArea to a (column, line) coordinate in the text.

Parameters:
p - The point in the PHighlightedTextArea.
Returns:
The corresponding point in the text (where x is the column and y is the line).

viewToModel

public Point viewToModel(int x,
                         int y)
Converts an actual pixel coordinate in the PHighlightedTextArea to a (column, line) coordinate in the text.

Parameters:
x - The x component of the pixel coordinate.
y - The y component of the pixel coordinate.
Returns:
The corresponding point in the text (where x is the column and y is the line).

getPopupMenu

public JPopupMenu getPopupMenu()
Gets the popup menu for this component.

Returns:
The popup menu for the component. Null is returned if this component does not have a popup menu.

setPopupMenu

public void setPopupMenu(JPopupMenu popupMenu)
Sets the popup menu for this component.

Parameters:
popupMenu - The popup menu for the component. A null value indicates that this component should not have a popup menu.

setEnabled

public void setEnabled(boolean enabled)
Override the setEnabled() method to intercept any changes concerning the enabled status of the component.

Overrides:
setEnabled in class JComponent

getCaretColor

public Color getCaretColor()
Gets the color of the caret. A null value indicates that the foreground color should be used to color the caret.

Returns:
The color of the caret.

setCaretColor

public void setCaretColor(Color caretColor)
Sets the color of the caret. A null value indicates that the foreground color should be used to color the caret.

Parameters:
caretColor - The new color of the caret.

getLineNumberColor

public Color getLineNumberColor()
Gets the color of the line numbers. A null value indicates that the numbers will take on the foreground color.

Returns:
The color of the line numbers.

setLineNumberColor

public void setLineNumberColor(Color lineNumberColor)
Sets the color of the line numbers. A null value indicates that the numbers should take on the foreground color.

Parameters:
lineNumberColor - The color of the line numbers.

getDisabledTextColor

public Color getDisabledTextColor()
Gets the color for the text if this component is disabled. A null value indicates that the text should be colored the same wheter or not this component is disabled.

Returns:
The color for the text if this component is disabled.

setDisabledTextColor

public void setDisabledTextColor(Color disabledTextColor)
Sets the color for the text if this component is disabled. A null value indicates that the text should be colored the same wheter or not this component is disabled.

Parameters:
disabledTextColor - The color for the text if this component is disabled.

getShowLineNumbers

public boolean getShowLineNumbers()
Indicates wheter or not the lines are numbered.

Returns:
True iff the line numbers are being shown.

setShowLineNumbers

public void setShowLineNumbers(boolean showLineNumbers)
Sets wheter or not the lines should be numbered.

Parameters:
showLineNumbers - True iff the lines should be numbered.

isEditable

public boolean isEditable()
Returns wheter or not this component is editable by the user.

Returns:
True iff the user can edit this component by clicking on it and typing.

setEditable

public void setEditable(boolean editable)
Sets wheter or not this component is editable by the user.

Parameters:
editable - The new value for editable.

getInsertMode

public boolean getInsertMode()
Returns wheter or not this component is in insert mode.

Returns:
True iff the user this component is in insert mode.

setInsertMode

public void setInsertMode(boolean insertMode)
Sets wheter or not this component is in insert mode.

Parameters:
insertMode - The new value for insertMode.

getMarkerColor

public Color getMarkerColor()
Gets the color for the column marker. A null value indicates that the marker should not be drawn.

Returns:
The color for the column marker.

setMarkerColor

public void setMarkerColor(Color markerColor)
Sets the color for the column marker. A null value indicates that the marker should not be drawn.

Parameters:
markerColor - The color for the column marker.

getColumnMarkers

public int[] getColumnMarkers()
Gets the location of the column markers.

Returns:
The columns at which markers are present. A copy of the internal array will be returned.

setColumnMarkers

public void setColumnMarkers(int[] columnMarkers)
Sets the location of the column markers. A null value will result in a NullPointerException. A negative column will result in an IllegalArgumentException.

Parameters:
columnMarkers - The columns at which to put markers.

getCaretPosition

public int getCaretPosition()
Returns the location of the caret.

Returns:
The offset of the caret with respect to the start of the text.

setCaretPosition

public void setCaretPosition(int caretPosition)
Sets the location of the caret. This will cause the current selection to be lost.

Parameters:
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.

getSelectedTextColor

public Color getSelectedTextColor()
Gets the color for the text which is in the selected range. A null value indicates that the text should be colored the same wheter or not it is selected.

Returns:
The color for the text which is selected.

setSelectedTextColor

public void setSelectedTextColor(Color selectedTextColor)
Sets the color for the text which is in the selected range. A null value indicates that the text should be colored the same wheter or not it is selected.

Parameters:
selectedTextColor - The color for the text which is selected.

getSelectionColor

public Color getSelectionColor()
Gets the color for the background which is in the selected range. A null value indicates that the background should be colored the same wheter or not it is selected.

Returns:
The color for the background which is selected.

setSelectionColor

public void setSelectionColor(Color selectionColor)
Sets the color for the background which is in the selected range. A null value indicates that the background should be colored the same wheter or not it is selected.

Parameters:
selectionColor - The color for the background which is selected.

getSelectionStart

public int getSelectionStart()
Gets the start of the selection. If nothing is selected, getSelectionStart() will return the same number as getSelectionEnd(), but they might not be the same as getCaretPosition().

Returns:
The offset at which the selection begins.

getSelectionEnd

public int getSelectionEnd()
Gets the end of the selection. If nothing is selected, getSelectionEnd() will return the same number as getSelectionStart(), but they might not be the same as getCaretPosition().

Returns:
The offset at which the selection ends.

getSelectionDot

public int getSelectionDot()
Gets the end of the selection which is supposed to 'move'. This is generally the same as the caret's position, but not necessarily so.

Returns:
The offset at which the selection begins.

getSelectionMark

public int getSelectionMark()
Gets the end of the selection which is supposed to be 'anchored'.

Returns:
The offset at which the selection ends.

getSelectedText

public String getSelectedText()
Returns the selected text.

Returns:
The text between the start of the selection and the end of the selection.

canSelectAll

public boolean canSelectAll()
Returns wheter or not the selectAll operation can be performed on this ClipboardTarget.

Specified by:
canSelectAll in interface ClipboardTarget
Returns:
True iff a call to selectAll() should be permitted.

selectAll

public void selectAll()
Selects all of the text.

Specified by:
selectAll in interface ClipboardTarget

select

public void select(int selectionDot,
                   int selectionMark)
Selects the specified range of text. The caret will be moved to the offset specified by selectionDot.

Parameters:
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.

select

public void select(int selectionDot,
                   int selectionMark,
                   int caretPosition)
Selects the specified range of text and moves the caret to a specified location.

Parameters:
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.

getHighlightedTextColor

public Color getHighlightedTextColor()
Gets the color for the text in a line which is highlighted. A null value indicates that the text should be colored the same wheter or not it is highlighted.

Returns:
The color for the text in a line which is highlighted.

setHighlightedTextColor

public void setHighlightedTextColor(Color highlightedTextColor)
Sets the color for the text in a line which is highlighted. A null value indicates that the text should be colored the same wheter or not it is highlighted.

Parameters:
highlightedTextColor - The color for the text in a line which is highlighted.

getHighlightColor

public Color getHighlightColor()
Gets the color for the background in a line which is highlighted. A null value indicates that the the background should be colored the same wheter or not it is highlighted.

Returns:
The color for the background in a line which is highlighted.

setHighlightColor

public void setHighlightColor(Color highlightColor)
Sets the color for the background in a line which is highlighted. A null value indicates that the the background should be colored the same wheter or not it is highlighted.

Parameters:
highlightColor - The color for the background in a line which is highlighted.

getHighlightedLine

public int getHighlightedLine()
Gets the line which is to be highlighted. Note that FOLLOW_CARET and NO_HIGHLIGHT are special values that this can take.

Returns:
The line which is to be highlighted.

setHighlightedLine

public void setHighlightedLine(int highlightedLine)
Sets the line which is to be highlighted. Note that FOLLOW_CARET and NO_HIGHLIGHT are special values that this can take.

Parameters:
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.

canCut

public boolean canCut()
Returns wheter or not the cut operation can be performed on this ClipboardTarget.

Specified by:
canCut in interface ClipboardTarget
Returns:
True iff a call to cut() should be permitted.

cut

public void cut()
Performs the cut operation on the selected text.

Specified by:
cut in interface ClipboardTarget

canCopy

public boolean canCopy()
Returns wheter or not the copy operation can be performed on this ClipboardTarget.

Specified by:
canCopy in interface ClipboardTarget
Returns:
True iff a call to copy() should be permitted.

copy

public void copy()
Performs the copy operation on the selected text.

Specified by:
copy in interface ClipboardTarget

canPaste

public boolean canPaste()
Returns wheter or not the paste operation can be performed on this ClipboardTarget.

Specified by:
canPaste in interface ClipboardTarget
Returns:
True iff a call to paste() should be permitted.

paste

public void paste()
Performs the paste operation on the selected text.

Specified by:
paste in interface ClipboardTarget

getText

public String getText()
Returns the text of the document.

Returns:
The text of the document.

setText

public void setText(String text)
Sets the text of the document.

Parameters:
text - The new text of the document.

getDocument

public HighlightedDocument getDocument()
Returns the document that this PHighlightedTextArea represents.

Returns:
The document of this component.

setDocument

public void setDocument(HighlightedDocument document)
Sets the document that this PHighlightedTextArea represents.

Parameters:
document - The new document that this PHighlightedTextArea should represent.

setFont

public void setFont(Font font)
Override the setFont function to capture changes in the font. Note that a null font is no longer acceptable.

Overrides:
setFont in class JComponent

getStyleCount

public int getStyleCount()
Returns the number of styles represented in this JHighlightTextArea.

Returns:
The number of styles in the document.

getStyle

public HighlightStyle getStyle(int index)
Gets the style for a specified index.

Parameters:
index - The index of the style.
Returns:
The style at that index.

setStyle

public void setStyle(HighlightStyle style,
                     int index)
Gets the style for a specified index.

Parameters:
style - The new style for that index.
index - The index of the style.

getAutoCompleter

public AutoCompleter getAutoCompleter()
Returns the AutoCompleter for this PHighlightedTextArea.

Returns:
The AutoCompleter for this PHighlightedTextArea.

setAutoCompleter

public void setAutoCompleter(AutoCompleter autoCompleter)
Sets the AutoCompleter for this PHighlightedTextArea.

Parameters:
autoCompleter - The new AutoCompleter for this PHighlightedTextArea.

recalculateSizes

public void recalculateSizes()
Recalculates the preferred/minimum sizes of the InternalNumberedArea and InternalTextArea.


scrollToCaret

public 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. If this PHighlightedTextArea is not in a viewport or if neither a caret nor a highlighted line is visible, then repaint() will be called and the method will terminate.


textValueChanged

public void textValueChanged(TextEvent e)
Implement TextListener to recalculate things whenever the document is edited.

Specified by:
textValueChanged in interface TextListener