edu.princeton.swing
public class PHighlightedTextArea extends javax.swing.JScrollPane implements java.awt.event.TextListener, ClipboardTarget
Modifier and Type | Class and Description |
---|---|
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.
|
javax.swing.JScrollPane.AccessibleJScrollPane, javax.swing.JScrollPane.ScrollBar
javax.swing.JComponent.AccessibleJComponent
Modifier and Type | Field and Description |
---|---|
static AutoCompleter |
DEFAULT_AUTO_COMPLETER
A static instance of DefaultAutoCompleter for general usage.
|
static java.awt.Color |
DEFAULT_BACKGROUND
The default background color.
|
static java.awt.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.
|
columnHeader, horizontalScrollBar, horizontalScrollBarPolicy, lowerLeft, lowerRight, rowHeader, upperLeft, upperRight, verticalScrollBar, verticalScrollBarPolicy, viewport
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
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
Constructor and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
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.
|
java.awt.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.
|
java.awt.Color |
getDisabledTextColor()
Gets the color for the text if this component is disabled.
|
HighlightedDocument |
getDocument()
Returns the document that this PHighlightedTextArea represents.
|
java.awt.Color |
getHighlightColor()
Gets the color for the background in a line which is highlighted.
|
int |
getHighlightedLine()
Gets the line which is to be highlighted.
|
java.awt.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.
|
java.awt.Color |
getLineNumberColor()
Gets the color of the line numbers.
|
java.awt.Color |
getMarkerColor()
Gets the color for the column marker.
|
javax.swing.JPopupMenu |
getPopupMenu()
Gets the popup menu for this component.
|
java.lang.String |
getSelectedText()
Returns the selected text.
|
java.awt.Color |
getSelectedTextColor()
Gets the color for the text which is in the selected range.
|
java.awt.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.
|
java.lang.String |
getText()
Returns the text of the document.
|
boolean |
isEditable()
Returns wheter or not this component is editable by the user.
|
java.awt.Point |
modelToView(int column,
int line)
Converts a (column, line) coordinate in the text to an actual pixel coordinate in the
PHighlightedTextArea.
|
java.awt.Point |
modelToView(java.awt.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(java.awt.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(java.awt.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(java.awt.Font font)
Override the setFont function to capture changes in the font.
|
void |
setHighlightColor(java.awt.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(java.awt.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(java.awt.Color lineNumberColor)
Sets the color of the line numbers.
|
void |
setMarkerColor(java.awt.Color markerColor)
Sets the color for the column marker.
|
void |
setPopupMenu(javax.swing.JPopupMenu popupMenu)
Sets the popup menu for this component.
|
void |
setSelectedTextColor(java.awt.Color selectedTextColor)
Sets the color for the text which is in the selected range.
|
void |
setSelectionColor(java.awt.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(java.lang.String text)
Sets the text of the document.
|
void |
textValueChanged(java.awt.event.TextEvent e)
Implement TextListener to recalculate things whenever the document is edited.
|
java.awt.Point |
viewToModel(int x,
int y)
Converts an actual pixel coordinate in the PHighlightedTextArea to a (column, line)
coordinate in the text.
|
java.awt.Point |
viewToModel(java.awt.Point p)
Converts an actual pixel coordinate in the PHighlightedTextArea to a (column, line)
coordinate in the text.
|
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
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
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, transferFocusDownCycle, validate, validateTree
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, transferFocusBackward, transferFocusUpCycle
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 java.awt.Color DEFAULT_FOREGROUND
public static final java.awt.Color DEFAULT_BACKGROUND
public PHighlightedTextArea()
public PHighlightedTextArea(HighlightedDocument document)
public PHighlightedTextArea(int rows, int columns)
public PHighlightedTextArea(HighlightedDocument document, int rows, int columns)
public void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
public java.awt.Point modelToView(java.awt.Point p)
p
- The point in the text (where x is the column and y is the line).public java.awt.Point modelToView(int column, int line)
column
- The column of the text coordinate.line
- The line of the text coordinate.public java.awt.Point viewToModel(java.awt.Point p)
p
- The point in the PHighlightedTextArea.public java.awt.Point viewToModel(int x, int y)
x
- The x component of the pixel coordinate.y
- The y component of the pixel coordinate.public javax.swing.JPopupMenu getPopupMenu()
public void setPopupMenu(javax.swing.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 javax.swing.JComponent
public java.awt.Color getCaretColor()
public void setCaretColor(java.awt.Color caretColor)
caretColor
- The new color of the caret.public java.awt.Color getLineNumberColor()
public void setLineNumberColor(java.awt.Color lineNumberColor)
lineNumberColor
- The color of the line numbers.public java.awt.Color getDisabledTextColor()
public void setDisabledTextColor(java.awt.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 java.awt.Color getMarkerColor()
public void setMarkerColor(java.awt.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 java.awt.Color getSelectedTextColor()
public void setSelectedTextColor(java.awt.Color selectedTextColor)
selectedTextColor
- The color for the text which is selected.public java.awt.Color getSelectionColor()
public void setSelectionColor(java.awt.Color selectionColor)
selectionColor
- The color for the background which is selected.public int getSelectionStart()
public int getSelectionEnd()
public int getSelectionDot()
public int getSelectionMark()
public java.lang.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 java.awt.Color getHighlightedTextColor()
public void setHighlightedTextColor(java.awt.Color highlightedTextColor)
highlightedTextColor
- The color for the text in a line which is highlighted.public java.awt.Color getHighlightColor()
public void setHighlightColor(java.awt.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 java.lang.String getText()
public void setText(java.lang.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(java.awt.Font font)
setFont
in class javax.swing.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(java.awt.event.TextEvent e)
textValueChanged
in interface java.awt.event.TextListener