public class RTextArea
extends javax.swing.JTextArea
implements java.awt.print.Printable
JTextArea
that adds the following features:
RTextArea
is set to a color,
its opaque property is set to true
for performance reasons. If
the background is set to an image, then the opaque property is set to
false
. This slows things down a little, but if it didn't happen
then we would see garbage on-screen when the user scrolled through a document
using the arrow keys (not the page-up/down keys though). You should never
have to set the opaque property yourself; it is always done for you.限定符和类型 | 类和说明 |
---|---|
protected class |
RTextArea.RTextAreaMutableCaretEvent
Modified from
MutableCaretEvent in
JTextComponent so that mouse events get fired when the user
is selecting text with the mouse as well. |
限定符和类型 | 字段和说明 |
---|---|
static java.lang.String |
BACKGROUND_IMAGE_PROPERTY |
static int |
COPY_ACTION |
static java.lang.String |
CURRENT_LINE_HIGHLIGHT_COLOR_PROPERTY |
static java.lang.String |
CURRENT_LINE_HIGHLIGHT_FADE_PROPERTY |
static int |
CUT_ACTION |
static int |
DELETE_ACTION |
static java.lang.String |
HIGHLIGHT_CURRENT_LINE_PROPERTY |
static int |
INSERT_MODE
Constant representing insert mode.
|
static java.lang.String |
MARK_ALL_COLOR_PROPERTY
The property fired when the "mark all" color changes.
|
static java.lang.String |
MARK_ALL_OCCURRENCES_CHANGED_PROPERTY
The property fired when what ranges are labeled "mark all" changes.
|
static int |
OVERWRITE_MODE
Constant representing overwrite mode.
|
static int |
PASTE_ACTION |
static int |
REDO_ACTION |
static java.lang.String |
ROUNDED_SELECTION_PROPERTY |
static int |
SELECT_ALL_ACTION |
static int |
UNDO_ACTION |
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
构造器和说明 |
---|
RTextArea()
Constructor.
|
RTextArea(javax.swing.text.AbstractDocument doc)
Constructor.
|
RTextArea(javax.swing.text.AbstractDocument doc,
java.lang.String text,
int rows,
int cols)
Constructor.
|
RTextArea(int textMode)
Creates a new
RTextArea . |
RTextArea(int rows,
int cols)
Constructor.
|
RTextArea(java.lang.String text)
Constructor.
|
RTextArea(java.lang.String text,
int rows,
int cols)
Constructor.
|
限定符和类型 | 方法和说明 |
---|---|
java.lang.Object |
addLineHighlight(int line,
java.awt.Color color)
Adds a line highlight.
|
void |
beginAtomicEdit()
Begins an "atomic edit."
|
static void |
beginRecordingMacro()
Begins recording a macro.
|
boolean |
canRedo()
Tells whether a redo is possible
|
boolean |
canUndo()
Tells whether an undo is possible
|
protected void |
configurePopupMenu(javax.swing.JPopupMenu popupMenu)
Configures the popup menu for this text area.
|
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 javax.swing.text.Document |
createDefaultModel()
Creates the default implementation of the model to be used at
construction if one isn't explicitly given.
|
protected com.fr.design.gui.syntax.ui.rtextarea.RTextAreaBase.RTAMouseListener |
createMouseListener()
Returns the caret event/mouse listener for
RTextArea s. |
protected javax.swing.JPopupMenu |
createPopupMenu()
Creates the right-click popup menu.
|
protected javax.swing.JMenuItem |
createPopupMenuItem(javax.swing.Action a)
Creates and configures a menu item for used in the popup menu.
|
protected RTextAreaUI |
createRTextAreaUI()
Returns the a real UI to install on this text area.
|
protected RUndoManager |
createUndoManager()
Creates an undo manager for use in this text area.
|
void |
discardAllEdits()
Removes all undoable edits from this document's undo manager.
|
void |
endAtomicEdit()
Completes an "atomic" edit.
|
static void |
endRecordingMacro()
Ends recording a macro.
|
protected void |
fireCaretUpdate(javax.swing.event.CaretEvent e)
Notifies all listeners that a caret change has occurred.
|
protected void |
forceCurrentLineHighlightRepaint()
Forces the current line highlight to be repainted.
|
static RecordableTextAction |
getAction(int action)
Provides a way to gain access to the editor actions on the right-click
popup menu.
|
java.awt.Color |
getBackground()
Returns the
java.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 the
Object representing the background for all
documents in this tabbed pane; either a java.awt.Color or a
java.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.
|
java.awt.Color |
getCurrentLineHighlightColor()
Returns the color being used to highlight the current line.
|
static Macro |
getCurrentMacro()
Returns the macro currently stored in this
RTextArea . |
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 java.awt.Color |
getDefaultMarkAllHighlightColor()
Returns the default color used for "mark all."
|
static int |
getDefaultTabSize()
Returns the default tab size, in spaces.
|
boolean |
getFadeCurrentLineHighlight()
Returns whether the current line highlight is faded.
|
boolean |
getHighlightCurrentLine()
Returns whether or not the current line is highlighted.
|
static IconGroup |
getIconGroup()
Returns the icon group being used for the actions of this text area.
|
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).
|
java.awt.Color |
getMarkAllHighlightColor()
Returns the color used in "mark all."
|
int |
getMaxAscent()
Returns the maximum ascent of all fonts used in this text area.
|
javax.swing.JPopupMenu |
getPopupMenu()
Returns the popup menu for this component, lazily creating it if
necessary.
|
boolean |
getRoundedSelectionEdges()
Returns whether selection edges are rounded in this text area.
|
static java.lang.String |
getSelectedOccurrenceText()
Returns the text last selected and used in a Ctrl+K operation.
|
boolean |
getTabsEmulated()
Returns whether or not tabs are emulated with spaces (i.e., "soft"
tabs).
|
int |
getTextMode()
Returns the text mode this editor pane is currently in.
|
ToolTipSupplier |
getToolTipSupplier()
Returns the tool tip supplier.
|
java.lang.String |
getToolTipText(java.awt.event.MouseEvent e)
Returns the tooltip to display for a mouse event at the given
location.
|
protected void |
handleReplaceSelection(java.lang.String content)
Does the actual dirty-work of replacing the selected text in this
text area (i.e., in its document).
|
protected void |
init()
Initializes this text area.
|
boolean |
isMarginLineEnabled()
Returns whether or not the margin line is being painted.
|
static boolean |
isOSX()
Returns whether the OS we're running on is OS X.
|
static boolean |
isRecordingMacro()
Returns whether or not a macro is being recorded.
|
static void |
loadMacro(Macro macro)
Loads a macro to be used by all
RTextArea s in the current
application. |
protected void |
paintComponent(java.awt.Graphics g)
Paints the text area.
|
void |
paste() |
void |
playbackLastMacro()
"Plays back" the last recorded macro in this text area.
|
protected void |
possiblyUpdateCurrentLineHighlightLocation()
Updates the current line highlight location.
|
int |
print(java.awt.Graphics g,
java.awt.print.PageFormat pageFormat,
int pageIndex)
Method called when it's time to print this badboy (the old-school,
AWT way).
|
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 |
read(java.io.Reader in,
java.lang.Object desc)
We override this method because the super version gives us an entirely
new
Document , thus requiring us to re-attach our Undo
manager. |
void |
redoLastAction()
Attempt to redo the last action.
|
void |
removeAllLineHighlights()
Removes all line highlights.
|
void |
removeLineHighlight(java.lang.Object tag)
Removes a line highlight.
|
void |
replaceRange(java.lang.String str,
int start,
int end)
Replaces text from the indicated start to end position with the
new text specified.
|
void |
replaceSelection(java.lang.String text)
This method overrides
JTextComponent 's
replaceSelection , so that if textMode is
OVERWRITE_MODE , it actually overwrites. |
static void |
setActionProperties(int action,
java.lang.String name,
char mnemonic,
javax.swing.KeyStroke accelerator)
Sets the properties of one of the actions this text area owns.
|
static void |
setActionProperties(int action,
java.lang.String name,
java.lang.Integer mnemonic,
javax.swing.KeyStroke accelerator)
Sets the properties of one of the actions this text area owns.
|
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 this
Object . |
void |
setCaret(javax.swing.text.Caret caret)
Sets the caret to use in this text area.
|
void |
setCaretStyle(int mode,
int style)
Sets the style of caret used when in insert or overwrite mode.
|
void |
setCurrentLineHighlightColor(java.awt.Color color)
Sets the color to use to highlight the current line.
|
void |
setDocument(javax.swing.text.Document document)
Sets the document used by this text area.
|
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 or not the current line is highlighted.
|
static void |
setIconGroup(IconGroup group)
Sets the path in which to find images to associate with the editor's
actions.
|
void |
setLineWrap(boolean wrap)
Sets whether or not 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 |
setMarkAllHighlightColor(java.awt.Color color)
Sets the color used for "mark all."
|
void |
setPopupMenu(javax.swing.JPopupMenu popupMenu)
Sets the popup menu used by this text area.
|
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 this
RTextArea . |
static void |
setSelectedOccurrenceText(java.lang.String text)
Sets the text last selected/Ctrl+K'd in an
RTextArea . |
void |
setTabsEmulated(boolean areEmulated)
Changes whether or not tabs should be emulated with spaces (i.e., soft
tabs).
|
void |
setTabSize(int size)
Workaround, since in JDK1.4 it appears that
setTabSize()
doesn't work for a JTextArea unless you use the constructor
specifying the number of rows and columns... |
void |
setTextMode(int mode)
Sets the text mode for this editor pane.
|
void |
setToolTipSupplier(ToolTipSupplier supplier)
Sets the tool tip supplier.
|
void |
setUI(javax.swing.plaf.TextUI ui)
Sets the UI used by this text area.
|
void |
undoLastAction()
Attempt to undo an "action" done in this text area.
|
protected void |
updateMarginLineX()
This is here so subclasses such as
RSyntaxTextArea 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.
|
append, getAccessibleContext, getColumns, getColumnWidth, getLineCount, getLineEndOffset, getLineOfOffset, getLineStartOffset, getLineWrap, getPreferredScrollableViewportSize, getPreferredSize, getRowHeight, getRows, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getTabSize, getUIClassID, getWrapStyleWord, insert, paramString, setColumns, setRows, setWrapStyleWord
addCaretListener, addInputMethodListener, addKeymap, copy, cut, 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, getUI, isEditable, loadKeymap, modelToView, moveCaretPosition, print, print, print, processInputMethodEvent, removeCaretListener, removeKeymap, removeNotify, restoreComposedText, saveComposedText, select, selectAll, setCaretColor, setCaretPosition, setComponentOrientation, setDisabledTextColor, setDragEnabled, setDropMode, setEditable, setFocusAccelerator, setHighlighter, setKeymap, setNavigationFilter, setSelectedTextColor, setSelectionColor, setSelectionEnd, setSelectionStart, setText, updateUI, viewToModel, write
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, 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
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
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, getPeer, 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, 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 INSERT_MODE
setCaretStyle(int, int)
,
常量字段值public static final int OVERWRITE_MODE
setCaretStyle(int, int)
,
常量字段值public static final java.lang.String MARK_ALL_COLOR_PROPERTY
public static final java.lang.String MARK_ALL_OCCURRENCES_CHANGED_PROPERTY
public static final int COPY_ACTION
public static final int CUT_ACTION
public static final int DELETE_ACTION
public static final int PASTE_ACTION
public static final int REDO_ACTION
public static final int SELECT_ALL_ACTION
public static final int UNDO_ACTION
public static final java.lang.String BACKGROUND_IMAGE_PROPERTY
public static final java.lang.String CURRENT_LINE_HIGHLIGHT_COLOR_PROPERTY
public static final java.lang.String CURRENT_LINE_HIGHLIGHT_FADE_PROPERTY
public static final java.lang.String HIGHLIGHT_CURRENT_LINE_PROPERTY
public static final java.lang.String ROUNDED_SELECTION_PROPERTY
public RTextArea()
public RTextArea(javax.swing.text.AbstractDocument doc)
doc
- The document for the editor.public RTextArea(java.lang.String text)
text
- The initial text to display.public RTextArea(int rows, int cols)
rows
- The number of rows to display.cols
- The number of columns to display.java.lang.IllegalArgumentException
- If either rows
or
cols
is negative.public RTextArea(java.lang.String text, int rows, int cols)
text
- The initial text to display.rows
- The number of rows to display.cols
- The number of columns to display.java.lang.IllegalArgumentException
- If either rows
or
cols
is negative.public RTextArea(javax.swing.text.AbstractDocument doc, java.lang.String text, int rows, int cols)
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.java.lang.IllegalArgumentException
- If either rows
or
cols
is negative.public RTextArea(int textMode)
RTextArea
.textMode
- Either INSERT_MODE
or
OVERWRITE_MODE
.public java.lang.Object addLineHighlight(int line, java.awt.Color color) throws javax.swing.text.BadLocationException
line
- The line to highlight. This is zero-based.color
- The color to highlight the line with.javax.swing.text.BadLocationException
- If line
is an invalid line
number.removeLineHighlight(Object)
,
removeAllLineHighlights()
public void beginAtomicEdit()
Using this method should be done with great care. You should probably wrap the call to endAtomicEdit() in a finally block:
textArea.beginAtomicEdit(); try { // Do editing } finally { textArea.endAtomicEdit(); }
endAtomicEdit()
public static void beginRecordingMacro()
endMacroRecording
is
called. If this method is called but the text component is already
recording a macro, nothing happens (but the macro keeps recording).public boolean canUndo()
canRedo()
,
undoLastAction()
public boolean canRedo()
canUndo()
,
redoLastAction()
protected void configurePopupMenu(javax.swing.JPopupMenu popupMenu)
The default implementation does nothing.
If you set the popup menu via setPopupMenu(JPopupMenu)
, you
will want to override this method, especially if you removed any of the
menu items in the default popup menu.
popupMenu
- The popup menu. This will never be null
.createPopupMenu()
,
setPopupMenu(JPopupMenu)
protected javax.swing.text.Document createDefaultModel()
createDefaultModel
在类中 javax.swing.JTextArea
protected com.fr.design.gui.syntax.ui.rtextarea.RTextAreaBase.RTAMouseListener createMouseListener()
RTextArea
s.protected javax.swing.JPopupMenu createPopupMenu()
setPopupMenu(JPopupMenu)
,
configurePopupMenu(JPopupMenu)
,
createPopupMenuItem(Action)
protected javax.swing.JMenuItem createPopupMenuItem(javax.swing.Action a)
a
- The action for the menu item.createPopupMenu()
protected RTextAreaUI createRTextAreaUI()
protected RUndoManager createUndoManager()
public void discardAllEdits()
public void endAtomicEdit()
beginAtomicEdit()
public static void endRecordingMacro()
protected void fireCaretUpdate(javax.swing.event.CaretEvent e)
fireCaretUpdate
在类中 javax.swing.text.JTextComponent
e
- The caret event.public static RecordableTextAction getAction(int action)
RTextArea
s, so that icons stay
synchronized and you don't have to worry about enabling/disabling them
yourself.
Keep in mind that these actions are shared across all instances of
RTextArea
, so a change to any action returned by this
method is global across all RTextArea
editors in your
application.
action
- The action to retrieve, such as CUT_ACTION
.
If the action name is invalid, null
is returned.null
if an invalid action is
requested.public static Macro getCurrentMacro()
RTextArea
.
Since macros are shared, all RTextArea
s in the currently-
running application are using this macro.null
if no macro has been
recorded/loaded.loadMacro(Macro)
public static final java.awt.Color getDefaultMarkAllHighlightColor()
getMarkAllHighlightColor()
,
setMarkAllHighlightColor(Color)
public static IconGroup getIconGroup()
setIconGroup(IconGroup)
public java.awt.Color getMarkAllHighlightColor()
setMarkAllHighlightColor(Color)
public int getMaxAscent()
RTextArea
, this is simply the
ascent of the current font.This value could be useful, for example, to implement a line-numbering scheme.
public javax.swing.JPopupMenu getPopupMenu()
createPopupMenu()
,
setPopupMenu(JPopupMenu)
public static java.lang.String getSelectedOccurrenceText()
null
if none.setSelectedOccurrenceText(String)
public final int getTextMode()
INSERT_MODE
or OVERWRITE_MODE
.setTextMode(int)
public ToolTipSupplier getToolTipSupplier()
null
if one isn't
installed.setToolTipSupplier(ToolTipSupplier)
public java.lang.String getToolTipText(java.awt.event.MouseEvent e)
ToolTipSupplier
; if there is one installed, it is queried for
tool tip text before using the super class's implementation of this
method.getToolTipText
在类中 javax.swing.text.JTextComponent
e
- The mouse event.null
if none.getToolTipSupplier()
,
setToolTipSupplier(ToolTipSupplier)
protected void handleReplaceSelection(java.lang.String content)
content
- The content to add.protected void init()
public static boolean isRecordingMacro()
beginRecordingMacro()
,
endRecordingMacro()
public static void loadMacro(Macro macro)
RTextArea
s in the current
application.macro
- The macro to load.getCurrentMacro()
public void paste()
paste
在类中 javax.swing.text.JTextComponent
public void playbackLastMacro()
public int print(java.awt.Graphics g, java.awt.print.PageFormat pageFormat, int pageIndex)
print
在接口中 java.awt.print.Printable
g
- The context into which the page is drawn.pageFormat
- The size and orientation of the page being drawn.pageIndex
- The zero based index of the page to be drawn.public void read(java.io.Reader in, java.lang.Object desc) throws java.io.IOException
Document
, thus requiring us to re-attach our Undo
manager. With this version we just replace the text.read
在类中 javax.swing.text.JTextComponent
java.io.IOException
public void redoLastAction()
undoLastAction()
public void removeAllLineHighlights()
public void removeLineHighlight(java.lang.Object tag)
tag
- The tag of the line highlight to remove.removeAllLineHighlights()
,
addLineHighlight(int, Color)
public void replaceRange(java.lang.String str, int start, int end)
This method is thread safe, although most Swing methods are not.
This method is overridden so that our Undo manager remembers it as a
single operation (it has trouble with this, especially for
RSyntaxTextArea
and the "auto-indent" feature).
replaceRange
在类中 javax.swing.JTextArea
str
- the text to use as the replacementstart
- the start position >= 0end
- the end position >= startjava.lang.IllegalArgumentException
- if part of the range is an
invalid position in the modelJTextArea.insert(String, int)
,
replaceRange(String, int, int)
public void replaceSelection(java.lang.String text)
JTextComponent
's
replaceSelection
, so that if textMode
is
OVERWRITE_MODE
, it actually overwrites.replaceSelection
在类中 javax.swing.text.JTextComponent
text
- The content to replace the selection with.public static void setActionProperties(int action, java.lang.String name, char mnemonic, javax.swing.KeyStroke accelerator)
action
- The action to modify; for example, CUT_ACTION
.name
- The new name for the action.mnemonic
- The new mnemonic for the action.accelerator
- The new accelerator key for the action.public static void setActionProperties(int action, java.lang.String name, java.lang.Integer mnemonic, javax.swing.KeyStroke accelerator)
action
- The action to modify; for example, CUT_ACTION
.name
- The new name for the action.mnemonic
- The new mnemonic for the action.accelerator
- The new accelerator key for the action.public void setCaret(javax.swing.text.Caret caret)
ConfigurableCaret
s (which is used by default), or a
subclass, since they know how to render themselves differently when the
user toggles between insert and overwrite modes.setCaret
在类中 javax.swing.text.JTextComponent
caret
- The caret to use. If this is not an instance of
ConfigurableCaret
, an exception is thrown.java.lang.IllegalArgumentException
- If the specified caret is not an
ConfigurableCaret
.setCaretStyle(int, int)
public void setCaretStyle(int mode, int style)
mode
- Either INSERT_MODE
or OVERWRITE_MODE
.style
- The style for the caret (such as
ConfigurableCaret.VERTICAL_LINE_STYLE
).ConfigurableCaret
public void setDocument(javax.swing.text.Document document)
setDocument
在类中 javax.swing.text.JTextComponent
document
- The new document to use.java.lang.IllegalArgumentException
- If the document is not an instance of
RDocument
.public static void setIconGroup(IconGroup group)
group
- The icon group to load.getIconGroup()
public void setMarkAllHighlightColor(java.awt.Color color)
MARK_ALL_COLOR_PROPERTY
.color
- The color to use for "mark all."getMarkAllHighlightColor()
public void setPopupMenu(javax.swing.JPopupMenu popupMenu)
If you set the popup menu with this method, you'll want to consider also
overriding configurePopupMenu(JPopupMenu)
, especially if you
removed any of the default menu items.
popupMenu
- The popup menu. If this is null
, no
popup menu will be displayed.getPopupMenu()
,
configurePopupMenu(JPopupMenu)
public void setRoundedSelectionEdges(boolean rounded)
ROUNDED_SELECTION_PROPERTY
.rounded
- Whether selection edges should be rounded.getRoundedSelectionEdges()
public static void setSelectedOccurrenceText(java.lang.String text)
RTextArea
.
This text will be searched for in subsequent Ctrl+K/Ctrl+Shift+K
actions (Cmd+K on OS X).Since the selected occurrence actions are built into RTextArea, applications usually do not have to call this method directly, but can choose to do so if they wish (for example, if they wish to set this value when the user does a search via a Find dialog).
text
- The selected text.getSelectedOccurrenceText()
public void setTextMode(int mode)
ConfigurableCaret
, it will be
automatically updated to render itself appropriately for the new text
mode.mode
- Either INSERT_MODE
or OVERWRITE_MODE
.getTextMode()
public void setToolTipSupplier(ToolTipSupplier supplier)
supplier
- The new tool tip supplier, or null
if
there is to be no supplier.getToolTipSupplier()
public final void setUI(javax.swing.plaf.TextUI ui)
RTextArea
is independent of the Java Look and Feel, and so
this method does not change the text area itself. Subclasses (such as
RSyntaxTextArea
can call setRTextAreaUI
if
they wish to install a new UI.setUI
在类中 javax.swing.text.JTextComponent
ui
- This parameter is ignored.public void undoLastAction()
redoLastAction()
public void convertSpacesToTabs()
public void convertTabsToSpaces()
protected void forceCurrentLineHighlightRepaint()
RSyntaxTextArea
.public final java.awt.Color getBackground()
java.awt.Color
used as the background color for
this text area. If a java.awt.Image
image is currently
being used instead, null
is returned.getBackground
在类中 java.awt.Component
null
if an image
is currently the background.public final java.awt.Image getBackgroundImage()
java.awt.Color
and
not a java.awt.Image
, then null
is returned.java.awt.Image
used for the background, or
null
if the background is not an image.setBackgroundImage(java.awt.Image)
public final java.lang.Object getBackgroundObject()
Object
representing the background for all
documents in this tabbed pane; either a java.awt.Color
or a
java.lang.Image
containing the image used as the background
for this text area.Object
used for the background.setBackgroundObject(Object newBackground)
public final int getCaretLineNumber()
public final int getCaretOffsetFromLineStart()
public java.awt.Color getCurrentLineHighlightColor()
getHighlightCurrentLine()
,
setHighlightCurrentLine(boolean)
,
setCurrentLineHighlightColor(java.awt.Color)
public static final java.awt.Color getDefaultCaretColor()
public static final java.awt.Color getDefaultCurrentLineHighlightColor()
public static final java.awt.Font getDefaultFont()
public static final java.awt.Color getDefaultForeground()
public static final java.awt.Color getDefaultMarginLineColor()
getMarginLineColor()
,
setMarginLineColor(Color)
public static final int getDefaultMarginLinePosition()
getMarginLinePosition()
,
setMarginLinePosition(int)
public static final int getDefaultTabSize()
public boolean getFadeCurrentLineHighlight()
setFadeCurrentLineHighlight(boolean)
public boolean getHighlightCurrentLine()
setHighlightCurrentLine(boolean)
,
getCurrentLineHighlightColor()
,
setCurrentLineHighlightColor(java.awt.Color)
public final int getLineEndOffsetOfCurrentLine()
public int getLineHeight()
public final int getLineStartOffsetOfCurrentLine()
public java.awt.Color getMarginLineColor()
setMarginLineColor(Color)
public int getMarginLinePixelLocation()
getDefaultMarginLinePosition()
,
setMarginLinePosition(int)
public int getMarginLinePosition()
getDefaultMarginLinePosition()
,
setMarginLinePosition(int)
public boolean getRoundedSelectionEdges()
setRoundedSelectionEdges(boolean)
public boolean getTabsEmulated()
true
if tabs are emulated with spaces;
false
if they aren't.setTabsEmulated(boolean)
public boolean isMarginLineEnabled()
setMarginLineEnabled(boolean)
public static boolean isOSX()
protected void paintComponent(java.awt.Graphics g)
paintComponent
在类中 javax.swing.JComponent
g
- The graphics context with which to paint.protected void possiblyUpdateCurrentLineHighlightLocation()
protected void processComponentEvent(java.awt.event.ComponentEvent e)
processComponentEvent
在类中 java.awt.Component
e
- The component event about to be sent to all registered
ComponentListener
s.public void setBackground(java.awt.Color bg)
setBackgroundObject(bg)
.
NOTE: the opaque property is set to true
when the
background is set to a color (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.
setBackground
在类中 javax.swing.JComponent
bg
- The color to use as the background color.public void setBackgroundImage(java.awt.Image image)
BACKGROUND_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.
image
- The image to use as this text area's background.getBackgroundImage()
public void setBackgroundObject(java.lang.Object newBackground)
Object
.newBackground
- The java.awt.Color
or
java.awt.Image
object. If newBackground
is not either of these, the background is set to plain white.public void setCurrentLineHighlightColor(java.awt.Color color)
CURRENT_LINE_HIGHLIGHT_COLOR_PROPERTY
.color
- The color to use to highlight the current line.java.lang.NullPointerException
- if color
is null
.getHighlightCurrentLine()
,
setHighlightCurrentLine(boolean)
,
getCurrentLineHighlightColor()
public void setFadeCurrentLineHighlight(boolean fade)
CURRENT_LINE_HIGHLIGHT_FADE_PROPERTY
.fade
- Whether the fade effect should be enabled.getFadeCurrentLineHighlight()
public void setFont(java.awt.Font font)
setFont
在类中 javax.swing.JTextArea
font
- The font to use for this text component.public void setHighlightCurrentLine(boolean highlight)
HIGHLIGHT_CURRENT_LINE_PROPERTY
.highlight
- Whether or not to highlight the current line.getHighlightCurrentLine()
,
getCurrentLineHighlightColor()
,
setCurrentLineHighlightColor(java.awt.Color)
public void setLineWrap(boolean wrap)
setLineWrap
在类中 javax.swing.JTextArea
wrap
- Whether or not word wrap should be enabled.public void setMargin(java.awt.Insets insets)
setMargin
在类中 javax.swing.text.JTextComponent
insets
- The new insets.public void setMarginLineColor(java.awt.Color color)
color
- The new margin line color.getDefaultMarginLineColor()
,
getMarginLineColor()
public void setMarginLineEnabled(boolean enabled)
enabled
- Whether or not the margin line should be enabled.isMarginLineEnabled()
public void setMarginLinePosition(int size)
size
- The margin size.
#see #getDefaultMarginLinePositiongetMarginLinePosition()
protected void setRTextAreaUI(RTextAreaUI ui)
RTextArea
. Note that, for instances
of RTextArea
, setUI
only updates the popup
menu; this is because RTextArea
s' look and feels are
independent of the Java Look and Feel. This method is here so
subclasses can set a UI (subclass of RTextAreaUI
) if they
have to.ui
- The new UI.JTextComponent.setUI(javax.swing.plaf.TextUI)
public void setTabsEmulated(boolean areEmulated)
convertTabsToSpaces()
and convertSpacesToTabs()
.areEmulated
- Whether or not tabs should be emulated with spaces.convertSpacesToTabs()
,
convertTabsToSpaces()
,
getTabsEmulated()
public void setTabSize(int size)
setTabSize()
doesn't work for a JTextArea
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.
setTabSize
在类中 javax.swing.JTextArea
size
- Number of characters to expand to.protected void updateMarginLineX()
RSyntaxTextArea
that
have multiple fonts can define exactly what it means, for example, for
the margin line to be "80 characters" over.public int yForLine(int line) throws javax.swing.text.BadLocationException
line
- The line number.-1
if
this text area doesn't yet have a positive size or the line is
hidden (i.e. from folding).javax.swing.text.BadLocationException
- If line
isn't a valid line
number for this document.public int yForLineContaining(int offs) throws javax.swing.text.BadLocationException
offs
- The offset info the document.-1
if
this text area doesn't yet have a positive size or the line is
hidden (i.e. from folding).javax.swing.text.BadLocationException
- If offs
isn't a valid offset
into the document.