Class RTextAreaBase
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.text.JTextComponent
-
- javax.swing.JTextArea
-
- org.fife.ui.rtextarea.RTextAreaBase
-
- All Implemented Interfaces:
java.awt.image.ImageObserver
,java.awt.MenuContainer
,java.io.Serializable
,javax.accessibility.Accessible
,javax.swing.Scrollable
- Direct Known Subclasses:
RTextArea
public abstract class RTextAreaBase extends javax.swing.JTextArea
This is the base class forRTextArea
; basically it's just an extension ofjavax.swing.JTextArea
adding a bunch of properties.This class is only supposed to be overridden by
RTextArea
.- Version:
- 0.8
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
RTextAreaBase.RTAMouseListener
Listens for mouse events in this component.-
Nested classes/interfaces inherited from class javax.swing.JTextArea
javax.swing.JTextArea.AccessibleJTextArea
-
Nested classes/interfaces inherited from class javax.swing.text.JTextComponent
javax.swing.text.JTextComponent.AccessibleJTextComponent, javax.swing.text.JTextComponent.DropLocation, javax.swing.text.JTextComponent.KeyBinding
-
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
-
-
Field Summary
-
Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
-
-
Constructor Summary
Constructors Constructor Description RTextAreaBase()
Constructor.RTextAreaBase(int rows, int cols)
Constructor.RTextAreaBase(java.lang.String text)
Constructor.RTextAreaBase(java.lang.String text, int rows, int cols)
Constructor.RTextAreaBase(javax.swing.text.AbstractDocument doc)
Constructor.RTextAreaBase(javax.swing.text.AbstractDocument doc, java.lang.String text, int rows, int cols)
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description private void
addCurrentLineHighlightListeners()
Adds listeners that listen for changes to the current line, so we can update our "current line highlight." This is needed only because of an apparent difference between the JRE 1.4.2 and 1.5.0 (needed on 1.4.2, not needed on 1.5.0).void
addNotify()
void
convertSpacesToTabs()
Converts all instances of a number of spaces equal to a tab size into a tab in this text area.void
convertTabsToSpaces()
Converts all instances of a tab into a number of spaces equivalent to a tab in this text area.protected abstract RTextAreaBase.RTAMouseListener
createMouseListener()
Returns the caret event/mouse listener forRTextArea
s.protected abstract RTextAreaUI
createRTextAreaUI()
Returns a real UI to install on this text component.protected void
forceCurrentLineHighlightRepaint()
Forces the current line highlight to be repainted.java.awt.Color
getBackground()
Returns thejava.awt.Color
used as the background color for this text area.java.awt.Image
getBackgroundImage()
Returns the image currently used for the background.java.lang.Object
getBackgroundObject()
Returns theObject
representing the background for all documents in this tabbed pane; either ajava.awt.Color
or ajava.lang.Image
containing the image used as the background for this text area.int
getCaretLineNumber()
Gets the line number that the caret is on.int
getCaretOffsetFromLineStart()
Gets the position from the beginning of the current line that the caret is on.protected int
getCurrentCaretY()
Returns the y-offset of the caret.java.awt.Color
getCurrentLineHighlightColor()
Returns the color being used to highlight the current line.static java.awt.Color
getDefaultCaretColor()
Returns the default caret color.static java.awt.Color
getDefaultCurrentLineHighlightColor()
Returns the "default" color for highlighting the current line.static java.awt.Font
getDefaultFont()
Returns the default font for text areas.static java.awt.Color
getDefaultForeground()
Returns the default foreground color for text in this text area.static java.awt.Color
getDefaultMarginLineColor()
Returns the default color for the margin line.static int
getDefaultMarginLinePosition()
Returns the default margin line position.static int
getDefaultTabSize()
Returns the default tab size, in spaces.boolean
getFadeCurrentLineHighlight()
Returns whether the current line highlight is faded.boolean
getHighlightCurrentLine()
Returns whether the current line is highlighted.int
getLineEndOffsetOfCurrentLine()
Returns the offset of the last character of the line that the caret is on.int
getLineHeight()
Returns the height of a line of text in this text area.int
getLineStartOffsetOfCurrentLine()
Returns the offset of the first character of the line that the caret is on.java.awt.Color
getMarginLineColor()
Returns the color used to paint the margin line.int
getMarginLinePixelLocation()
Returns the margin line position (in pixels) from the left-hand side of the text area.int
getMarginLinePosition()
Returns the margin line position (which is the number of 'm' widths in the current font the margin line is over).boolean
getRoundedSelectionEdges()
Returns whether selection edges are rounded in this text area.boolean
getTabsEmulated()
Returns whether tabs are emulated with spaces (i.e., "soft" tabs).protected void
init()
Initializes this text area.boolean
isMarginLineEnabled()
Returns whether the margin line is being painted.static boolean
isOSX()
Returns whether the OS we're running on is OS X.protected void
paintComponent(java.awt.Graphics g)
Paints the text area.protected void
possiblyUpdateCurrentLineHighlightLocation()
Updates the current line highlight location.protected void
processComponentEvent(java.awt.event.ComponentEvent e)
Overridden so we can tell when the text area is resized and update the current-line highlight, if necessary (i.e., if it is enabled and if lineWrap is enabled).void
setBackground(java.awt.Color bg)
Sets the background color of this text editor.void
setBackgroundImage(java.awt.Image image)
Sets this image as the background image.void
setBackgroundObject(java.lang.Object newBackground)
Makes the background into thisObject
.void
setCurrentLineHighlightColor(java.awt.Color color)
Sets the color to use to highlight the current line.void
setFadeCurrentLineHighlight(boolean fade)
Sets whether the current line highlight should have a "fade" effect.void
setFont(java.awt.Font font)
Sets the font for this text area.void
setHighlightCurrentLine(boolean highlight)
Sets whether the current line is highlighted.void
setLineWrap(boolean wrap)
Sets whether word wrap is enabled.void
setMargin(java.awt.Insets insets)
Overridden to update the current line highlight location.void
setMarginLineColor(java.awt.Color color)
Sets the color used to paint the margin line.void
setMarginLineEnabled(boolean enabled)
Enables or disables the margin line.void
setMarginLinePosition(int size)
Sets the number of 'm' widths the margin line is over.void
setRoundedSelectionEdges(boolean rounded)
Sets whether the edges of selections are rounded in this text area.protected void
setRTextAreaUI(RTextAreaUI ui)
Sets the UI for thisRTextArea
.void
setTabsEmulated(boolean areEmulated)
Changes whether tabs should be emulated with spaces (i.e., soft tabs).void
setTabSize(int size)
Workaround, since in JDK1.4 it appears thatsetTabSize()
doesn't work for aJTextArea
unless you use the constructor specifying the number of rows and columns...protected void
updateMarginLineX()
This is here so subclasses such asRSyntaxTextArea
that have multiple fonts can define exactly what it means, for example, for the margin line to be "80 characters" over.int
yForLine(int line)
Returns the y-coordinate of the specified line.int
yForLineContaining(int offs)
Returns the y-coordinate of the line containing an offset.-
Methods inherited from class javax.swing.JTextArea
append, createDefaultModel, getAccessibleContext, getColumns, getColumnWidth, getLineCount, getLineEndOffset, getLineOfOffset, getLineStartOffset, getLineWrap, getPreferredScrollableViewportSize, getPreferredSize, getRowHeight, getRows, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getTabSize, getUIClassID, getWrapStyleWord, insert, paramString, replaceRange, setColumns, setRows, setWrapStyleWord
-
Methods inherited from class javax.swing.text.JTextComponent
addCaretListener, addInputMethodListener, addKeymap, copy, cut, fireCaretUpdate, getActions, getCaret, getCaretColor, getCaretListeners, getCaretPosition, getDisabledTextColor, getDocument, getDragEnabled, getDropLocation, getDropMode, getFocusAccelerator, getHighlighter, getInputMethodRequests, getKeymap, getKeymap, getMargin, getNavigationFilter, getPrintable, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getSelectedText, getSelectedTextColor, getSelectionColor, getSelectionEnd, getSelectionStart, getText, getText, getToolTipText, getUI, isEditable, loadKeymap, modelToView, modelToView2D, moveCaretPosition, paste, print, print, print, processInputMethodEvent, read, removeCaretListener, removeKeymap, removeNotify, replaceSelection, restoreComposedText, saveComposedText, select, selectAll, setCaret, setCaretColor, setCaretPosition, setComponentOrientation, setDisabledTextColor, setDocument, setDragEnabled, setDropMode, setEditable, setFocusAccelerator, setHighlighter, setKeymap, setNavigationFilter, setSelectedTextColor, setSelectionColor, setSelectionEnd, setSelectionStart, setText, setUI, updateUI, viewToModel, viewToModel2D, write
-
Methods inherited from class javax.swing.JComponent
addAncestorListener, 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, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, 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, setLayout, transferFocusDownCycle, validate, validateTree
-
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, 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, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
-
-
-
Field Detail
-
BACKGROUND_IMAGE_PROPERTY
public static final java.lang.String BACKGROUND_IMAGE_PROPERTY
- See Also:
- Constant Field Values
-
CURRENT_LINE_HIGHLIGHT_COLOR_PROPERTY
public static final java.lang.String CURRENT_LINE_HIGHLIGHT_COLOR_PROPERTY
- See Also:
- Constant Field Values
-
CURRENT_LINE_HIGHLIGHT_FADE_PROPERTY
public static final java.lang.String CURRENT_LINE_HIGHLIGHT_FADE_PROPERTY
- See Also:
- Constant Field Values
-
HIGHLIGHT_CURRENT_LINE_PROPERTY
public static final java.lang.String HIGHLIGHT_CURRENT_LINE_PROPERTY
- See Also:
- Constant Field Values
-
ROUNDED_SELECTION_PROPERTY
public static final java.lang.String ROUNDED_SELECTION_PROPERTY
- See Also:
- Constant Field Values
-
tabsEmulatedWithSpaces
private boolean tabsEmulatedWithSpaces
-
highlightCurrentLine
private boolean highlightCurrentLine
-
currentLineColor
private java.awt.Color currentLineColor
-
marginLineEnabled
private boolean marginLineEnabled
-
marginLineColor
private java.awt.Color marginLineColor
-
marginLineX
private int marginLineX
-
marginSizeInChars
private int marginSizeInChars
-
fadeCurrentLineHighlight
private boolean fadeCurrentLineHighlight
-
roundedSelectionEdges
private boolean roundedSelectionEdges
-
previousCaretY
private int previousCaretY
-
currentCaretY
int currentCaretY
-
backgroundPainter
private BackgroundPainterStrategy backgroundPainter
-
mouseListener
private RTextAreaBase.RTAMouseListener mouseListener
-
DEFAULT_CARET_COLOR
private static final java.awt.Color DEFAULT_CARET_COLOR
-
DEFAULT_CURRENT_LINE_HIGHLIGHT_COLOR
private static final java.awt.Color DEFAULT_CURRENT_LINE_HIGHLIGHT_COLOR
-
DEFAULT_MARGIN_LINE_COLOR
private static final java.awt.Color DEFAULT_MARGIN_LINE_COLOR
-
DEFAULT_TAB_SIZE
private static final int DEFAULT_TAB_SIZE
- See Also:
- Constant Field Values
-
DEFAULT_MARGIN_LINE_POSITION
private static final int DEFAULT_MARGIN_LINE_POSITION
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
RTextAreaBase
public RTextAreaBase()
Constructor.
-
RTextAreaBase
public RTextAreaBase(javax.swing.text.AbstractDocument doc)
Constructor.- Parameters:
doc
- The document for the editor.
-
RTextAreaBase
public RTextAreaBase(java.lang.String text)
Constructor.- Parameters:
text
- The initial text to display.
-
RTextAreaBase
public RTextAreaBase(int rows, int cols)
Constructor.- Parameters:
rows
- The number of rows to display.cols
- The number of columns to display.- Throws:
java.lang.IllegalArgumentException
- If eitherrows
orcols
is negative.
-
RTextAreaBase
public RTextAreaBase(java.lang.String text, int rows, int cols)
Constructor.- Parameters:
text
- The initial text to display.rows
- The number of rows to display.cols
- The number of columns to display.- Throws:
java.lang.IllegalArgumentException
- If eitherrows
orcols
is negative.
-
RTextAreaBase
public RTextAreaBase(javax.swing.text.AbstractDocument doc, java.lang.String text, int rows, int cols)
Constructor.- Parameters:
doc
- The document for the editor.text
- The initial text to display.rows
- The number of rows to display.cols
- The number of columns to display.- Throws:
java.lang.IllegalArgumentException
- If eitherrows
orcols
is negative.
-
-
Method Detail
-
addCurrentLineHighlightListeners
private void addCurrentLineHighlightListeners()
Adds listeners that listen for changes to the current line, so we can update our "current line highlight." This is needed only because of an apparent difference between the JRE 1.4.2 and 1.5.0 (needed on 1.4.2, not needed on 1.5.0).
-
addNotify
public void addNotify()
- Overrides:
addNotify
in classjavax.swing.JComponent
-
convertSpacesToTabs
public void convertSpacesToTabs()
Converts all instances of a number of spaces equal to a tab size into a tab in this text area.
-
convertTabsToSpaces
public void convertTabsToSpaces()
Converts all instances of a tab into a number of spaces equivalent to a tab in this text area.
-
createMouseListener
protected abstract RTextAreaBase.RTAMouseListener createMouseListener()
Returns the caret event/mouse listener forRTextArea
s.- Returns:
- The caret event/mouse listener.
-
createRTextAreaUI
protected abstract RTextAreaUI createRTextAreaUI()
Returns a real UI to install on this text component. Subclasses can override this method to return an extended version ofRTextAreaUI
.- Returns:
- The UI.
-
forceCurrentLineHighlightRepaint
protected void forceCurrentLineHighlightRepaint()
Forces the current line highlight to be repainted. This hack is necessary for those situations when the view (appearance) changes but the caret's location hasn't (and thus the current line highlight coordinates won't get changed). Examples of this are when word wrap is toggled and when syntax styles are changed in anRSyntaxTextArea
.
-
getBackground
public final java.awt.Color getBackground()
Returns thejava.awt.Color
used as the background color for this text area. If ajava.awt.Image
image is currently being used instead,null
is returned.- Overrides:
getBackground
in classjava.awt.Component
- Returns:
- The current background color, or
null
if an image is currently the background.
-
getBackgroundImage
public final java.awt.Image getBackgroundImage()
Returns the image currently used for the background. If the current background is currently ajava.awt.Color
and not ajava.awt.Image
, thennull
is returned.- Returns:
- A
java.awt.Image
used for the background, ornull
if the background is not an image. - See Also:
setBackgroundImage(java.awt.Image)
-
getBackgroundObject
public final java.lang.Object getBackgroundObject()
Returns theObject
representing the background for all documents in this tabbed pane; either ajava.awt.Color
or ajava.lang.Image
containing the image used as the background for this text area.- Returns:
- The
Object
used for the background. - See Also:
setBackgroundObject(Object newBackground)
-
getCaretLineNumber
public final int getCaretLineNumber()
Gets the line number that the caret is on.- Returns:
- The zero-based line number that the caret is on.
-
getCaretOffsetFromLineStart
public final int getCaretOffsetFromLineStart()
Gets the position from the beginning of the current line that the caret is on.- Returns:
- The zero-based position from the beginning of the current line that the caret is on.
-
getCurrentCaretY
protected int getCurrentCaretY()
Returns the y-offset of the caret.- Returns:
- The y-offset of the caret.
-
getCurrentLineHighlightColor
public java.awt.Color getCurrentLineHighlightColor()
Returns the color being used to highlight the current line. Note that if highlighting the current line is turned off, you will not be seeing this highlight.- Returns:
- The color being used to highlight the current line.
- See Also:
getHighlightCurrentLine()
,setHighlightCurrentLine(boolean)
,setCurrentLineHighlightColor(java.awt.Color)
-
getDefaultCaretColor
public static java.awt.Color getDefaultCaretColor()
Returns the default caret color.- Returns:
- The default caret color.
-
getDefaultCurrentLineHighlightColor
public static java.awt.Color getDefaultCurrentLineHighlightColor()
Returns the "default" color for highlighting the current line. Note that this color was chosen only because it looks nice (to me) against a white background.- Returns:
- The default color for highlighting the current line.
-
getDefaultFont
public static java.awt.Font getDefaultFont()
Returns the default font for text areas.- Returns:
- The default font.
-
getDefaultForeground
public static java.awt.Color getDefaultForeground()
Returns the default foreground color for text in this text area.- Returns:
- The default foreground color.
-
getDefaultMarginLineColor
public static java.awt.Color getDefaultMarginLineColor()
Returns the default color for the margin line.- Returns:
- The default margin line color.
- See Also:
getMarginLineColor()
,setMarginLineColor(Color)
-
getDefaultMarginLinePosition
public static int getDefaultMarginLinePosition()
Returns the default margin line position.- Returns:
- The default margin line position.
- See Also:
getMarginLinePosition()
,setMarginLinePosition(int)
-
getDefaultTabSize
public static int getDefaultTabSize()
Returns the default tab size, in spaces.- Returns:
- The default tab size.
-
getFadeCurrentLineHighlight
public boolean getFadeCurrentLineHighlight()
Returns whether the current line highlight is faded.- Returns:
- Whether the current line highlight is faded.
- See Also:
setFadeCurrentLineHighlight(boolean)
-
getHighlightCurrentLine
public boolean getHighlightCurrentLine()
Returns whether the current line is highlighted.- Returns:
- Whether or the current line is highlighted.
- See Also:
setHighlightCurrentLine(boolean)
,getCurrentLineHighlightColor()
,setCurrentLineHighlightColor(java.awt.Color)
-
getLineEndOffsetOfCurrentLine
public final int getLineEndOffsetOfCurrentLine()
Returns the offset of the last character of the line that the caret is on.- Returns:
- The last offset of the line that the caret is currently on.
-
getLineHeight
public int getLineHeight()
Returns the height of a line of text in this text area.- Returns:
- The height of a line of text.
-
getLineStartOffsetOfCurrentLine
public final int getLineStartOffsetOfCurrentLine()
Returns the offset of the first character of the line that the caret is on.- Returns:
- The first offset of the line that the caret is currently on.
-
getMarginLineColor
public java.awt.Color getMarginLineColor()
Returns the color used to paint the margin line.- Returns:
- The margin line color.
- See Also:
setMarginLineColor(Color)
-
getMarginLinePixelLocation
public int getMarginLinePixelLocation()
Returns the margin line position (in pixels) from the left-hand side of the text area.- Returns:
- The margin line position.
- See Also:
getDefaultMarginLinePosition()
,setMarginLinePosition(int)
-
getMarginLinePosition
public int getMarginLinePosition()
Returns the margin line position (which is the number of 'm' widths in the current font the margin line is over).- Returns:
- The margin line position.
- See Also:
getDefaultMarginLinePosition()
,setMarginLinePosition(int)
-
getRoundedSelectionEdges
public boolean getRoundedSelectionEdges()
Returns whether selection edges are rounded in this text area.- Returns:
- Whether selection edges are rounded.
- See Also:
setRoundedSelectionEdges(boolean)
-
getTabsEmulated
public boolean getTabsEmulated()
Returns whether tabs are emulated with spaces (i.e., "soft" tabs).- Returns:
true
if tabs are emulated with spaces;false
if they aren't.- See Also:
setTabsEmulated(boolean)
-
init
protected void init()
Initializes this text area.
-
isMarginLineEnabled
public boolean isMarginLineEnabled()
Returns whether the margin line is being painted.- Returns:
- Whether the margin line is being painted.
- See Also:
setMarginLineEnabled(boolean)
-
isOSX
public static boolean isOSX()
Returns whether the OS we're running on is OS X.- Returns:
- Whether the OS we're running on is OS X.
-
paintComponent
protected void paintComponent(java.awt.Graphics g)
Paints the text area.- Overrides:
paintComponent
in classjavax.swing.JComponent
- Parameters:
g
- The graphics context with which to paint.
-
possiblyUpdateCurrentLineHighlightLocation
protected void possiblyUpdateCurrentLineHighlightLocation()
Updates the current line highlight location.
-
processComponentEvent
protected void processComponentEvent(java.awt.event.ComponentEvent e)
Overridden so we can tell when the text area is resized and update the current-line highlight, if necessary (i.e., if it is enabled and if lineWrap is enabled).- Overrides:
processComponentEvent
in classjava.awt.Component
- Parameters:
e
- The component event about to be sent to all registeredComponentListener
s.
-
setBackground
public void setBackground(java.awt.Color bg)
Sets the background color of this text editor. Note that this is equivalent to callingsetBackgroundObject(bg)
.NOTE: the opaque property is set to
true
when the background is set to a color with 1.0 alpha (by this method). When an image is used for the background, opaque is set to false. This is because we perform better when setOpaque is true, but if we use an image for the background when opaque is true, we get on-screen garbage when the user scrolls via the arrow keys. Thus we need setOpaque to be false in that case.You never have to change the opaque property yourself; it is always done for you.
- Overrides:
setBackground
in classjavax.swing.JComponent
- Parameters:
bg
- The color to use as the background color.
-
setBackgroundImage
public void setBackgroundImage(java.awt.Image image)
Sets this image as the background image. This method fires a property change event of typeBACKGROUND_IMAGE_PROPERTY
.NOTE: the opaque property is set to
true
when the background is set to a color. When an image is used for the background (by this method), opaque is set to false. This is because we perform better when setOpaque is true, but if we use an image for the background when opaque is true, we get on-screen garbage when the user scrolls via the arrow keys. Thus we need setOpaque to be false in that case.You never have to change the opaque property yourself; it is always done for you.
- Parameters:
image
- The image to use as this text area's background.- See Also:
getBackgroundImage()
-
setBackgroundObject
public void setBackgroundObject(java.lang.Object newBackground)
Makes the background into thisObject
.- Parameters:
newBackground
- Thejava.awt.Color
orjava.awt.Image
object. IfnewBackground
is not either of these, the background is set to plain white.
-
setCurrentLineHighlightColor
public void setCurrentLineHighlightColor(java.awt.Color color)
Sets the color to use to highlight the current line. Note that if highlighting the current line is turned off, you will not be able to see this highlight. This method fires a property change of typeCURRENT_LINE_HIGHLIGHT_COLOR_PROPERTY
.- Parameters:
color
- The color to use to highlight the current line.- Throws:
java.lang.NullPointerException
- ifcolor
isnull
.- See Also:
getHighlightCurrentLine()
,setHighlightCurrentLine(boolean)
,getCurrentLineHighlightColor()
-
setFadeCurrentLineHighlight
public void setFadeCurrentLineHighlight(boolean fade)
Sets whether the current line highlight should have a "fade" effect. This method fires a property change event of typeCURRENT_LINE_HIGHLIGHT_FADE_PROPERTY
.- Parameters:
fade
- Whether the fade effect should be enabled.- See Also:
getFadeCurrentLineHighlight()
-
setFont
public void setFont(java.awt.Font font)
Sets the font for this text area. This is overridden only so that we can update the size of the "current line highlight" and the location of the "margin line," if necessary.- Overrides:
setFont
in classjavax.swing.JTextArea
- Parameters:
font
- The font to use for this text component.
-
setHighlightCurrentLine
public void setHighlightCurrentLine(boolean highlight)
Sets whether the current line is highlighted. This method fires a property change of typeHIGHLIGHT_CURRENT_LINE_PROPERTY
.- Parameters:
highlight
- Whether to highlight the current line.- See Also:
getHighlightCurrentLine()
,getCurrentLineHighlightColor()
,setCurrentLineHighlightColor(java.awt.Color)
-
setLineWrap
public void setLineWrap(boolean wrap)
Sets whether word wrap is enabled. This is overridden so that the "current line highlight" gets updated if it needs to be.- Overrides:
setLineWrap
in classjavax.swing.JTextArea
- Parameters:
wrap
- Whether word wrap should be enabled.
-
setMargin
public void setMargin(java.awt.Insets insets)
Overridden to update the current line highlight location.- Overrides:
setMargin
in classjavax.swing.text.JTextComponent
- Parameters:
insets
- The new insets.
-
setMarginLineColor
public void setMarginLineColor(java.awt.Color color)
Sets the color used to paint the margin line.- Parameters:
color
- The new margin line color.- See Also:
getDefaultMarginLineColor()
,getMarginLineColor()
-
setMarginLineEnabled
public void setMarginLineEnabled(boolean enabled)
Enables or disables the margin line.- Parameters:
enabled
- Whether the margin line should be enabled.- See Also:
isMarginLineEnabled()
-
setMarginLinePosition
public void setMarginLinePosition(int size)
Sets the number of 'm' widths the margin line is over.- Parameters:
size
- The margin size.- See Also:
getDefaultMarginLinePosition()
,getMarginLinePosition()
-
setRoundedSelectionEdges
public void setRoundedSelectionEdges(boolean rounded)
Sets whether the edges of selections are rounded in this text area. This method fires a property change of typeROUNDED_SELECTION_PROPERTY
.- Parameters:
rounded
- Whether selection edges should be rounded.- See Also:
getRoundedSelectionEdges()
-
setRTextAreaUI
protected void setRTextAreaUI(RTextAreaUI ui)
Sets the UI for thisRTextArea
. Note that, for instances ofRTextArea
,setUI
only updates the popup menu; this is becauseRTextArea
s' look and feels are independent of the Java Look and Feel. This method is here so subclasses can set a UI (subclass ofRTextAreaUI
) if they have to.- Parameters:
ui
- The new UI.- See Also:
JTextComponent.setUI(javax.swing.plaf.TextUI)
-
setTabsEmulated
public void setTabsEmulated(boolean areEmulated)
Changes whether tabs should be emulated with spaces (i.e., soft tabs). Note that this affects all tabs inserted AFTER this call, not tabs already in the document. For that, seeconvertTabsToSpaces()
andconvertSpacesToTabs()
.- Parameters:
areEmulated
- Whether tabs should be emulated with spaces.- See Also:
convertSpacesToTabs()
,convertTabsToSpaces()
,getTabsEmulated()
-
setTabSize
public void setTabSize(int size)
Workaround, since in JDK1.4 it appears thatsetTabSize()
doesn't work for aJTextArea
unless you use the constructor specifying the number of rows and columns...Sets the number of characters to expand tabs to. This will be multiplied by the maximum advance for variable width fonts. A PropertyChange event ("tabSize") is fired when the tab size changes.
- Overrides:
setTabSize
in classjavax.swing.JTextArea
- Parameters:
size
- Number of characters to expand to.
-
updateMarginLineX
protected void updateMarginLineX()
This is here so subclasses such asRSyntaxTextArea
that have multiple fonts can define exactly what it means, for example, for the margin line to be "80 characters" over.
-
yForLine
public int yForLine(int line) throws javax.swing.text.BadLocationException
Returns the y-coordinate of the specified line.- Parameters:
line
- The line number.- Returns:
- The y-coordinate of the top of the line, or
-1
if this text area doesn't yet have a positive size or the line is hidden (i.e. from folding). - Throws:
javax.swing.text.BadLocationException
- Ifline
isn't a valid line number for this document.
-
yForLineContaining
public int yForLineContaining(int offs) throws javax.swing.text.BadLocationException
Returns the y-coordinate of the line containing an offset.- Parameters:
offs
- The offset info the document.- Returns:
- The y-coordinate of the top of the offset, or
-1
if this text area doesn't yet have a positive size or the line is hidden (i.e. from folding). - Throws:
javax.swing.text.BadLocationException
- Ifoffs
isn't a valid offset into the document.
-
-