Class RTextAreaBase

    • Constructor Detail

      • RTextAreaBase

        public RTextAreaBase()
        Constructor.
      • RTextAreaBase

        public RTextAreaBase​(AbstractDocument doc)
        Constructor.
        Parameters:
        doc - The document for the editor.
      • RTextAreaBase

        public RTextAreaBase​(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:
        IllegalArgumentException - If either rows or cols is negative.
      • RTextAreaBase

        public RTextAreaBase​(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:
        IllegalArgumentException - If either rows or cols is negative.
      • RTextAreaBase

        public RTextAreaBase​(AbstractDocument doc,
                             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:
        IllegalArgumentException - If either rows or cols is negative.
    • Method Detail

      • createMouseListener

        protected abstract RTextAreaBase.RTAMouseListener createMouseListener()
        Returns the caret event/mouse listener for RTextAreas.
        Returns:
        The caret event/mouse listener.
      • createRTextAreaUI

        protected abstract RTextAreaUI createRTextAreaUI()
        Returns the a real UI to install on this text component. Subclasses can override this method to return an extended version of RTextAreaUI.
        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 an RSyntaxTextArea.
      • getBackground

        public final Color getBackground()
        Returns the 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.
        Overrides:
        getBackground in class Component
        Returns:
        The current background color, or null if an image is currently the background.
      • getBackgroundImage

        public final Image getBackgroundImage()
        Returns the image currently used for the background. If the current background is currently a java.awt.Color and not a java.awt.Image, then null is returned.
        Returns:
        A java.awt.Image used for the background, or null if the background is not an image.
        See Also:
        setBackgroundImage(java.awt.Image)
      • getBackgroundObject

        public final 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.
        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.
      • getDefaultCaretColor

        public static final Color getDefaultCaretColor()
        Returns the default caret color.
        Returns:
        The default caret color.
      • getDefaultCurrentLineHighlightColor

        public static final 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 final Font getDefaultFont()
        Returns the default font for text areas.
        Returns:
        The default font.
      • getDefaultForeground

        public static final Color getDefaultForeground()
        Returns the default foreground color for text in this text area.
        Returns:
        The default foreground color.
      • getDefaultTabSize

        public static final 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)
      • 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 Color getMarginLineColor()
        Returns the color used to paint the margin line.
        Returns:
        The margin line color.
        See Also:
        setMarginLineColor(Color)
      • 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 or not 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 or not the margin line is being painted.
        Returns:
        Whether or not 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​(Graphics g)
        Paints the text area.
        Overrides:
        paintComponent in class JComponent
        Parameters:
        g - The graphics context with which to paint.
      • possiblyUpdateCurrentLineHighlightLocation

        protected void possiblyUpdateCurrentLineHighlightLocation()
        Updates the current line highlight location.
      • processComponentEvent

        protected void processComponentEvent​(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 class Component
        Parameters:
        e - The component event about to be sent to all registered ComponentListeners.
      • setBackground

        public void setBackground​(Color bg)
        Sets the background color of this text editor. Note that this is equivalent to calling setBackgroundObject(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 class JComponent
        Parameters:
        bg - The color to use as the background color.
      • setBackgroundImage

        public void setBackgroundImage​(Image image)
        Sets this image as the background image. This method fires a property change event of type 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.

        Parameters:
        image - The image to use as this text area's background.
        See Also:
        getBackgroundImage()
      • setBackgroundObject

        public void setBackgroundObject​(Object newBackground)
        Makes the background into this Object.
        Parameters:
        newBackground - The java.awt.Color or java.awt.Image object. If newBackground is not either of these, the background is set to plain white.
      • 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 type CURRENT_LINE_HIGHLIGHT_FADE_PROPERTY.
        Parameters:
        fade - Whether the fade effect should be enabled.
        See Also:
        getFadeCurrentLineHighlight()
      • setFont

        public void setFont​(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 class JTextArea
        Parameters:
        font - The font to use for this text component.
      • setLineWrap

        public void setLineWrap​(boolean wrap)
        Sets whether or not word wrap is enabled. This is overridden so that the "current line highlight" gets updated if it needs to be.
        Overrides:
        setLineWrap in class JTextArea
        Parameters:
        wrap - Whether or not word wrap should be enabled.
      • setMargin

        public void setMargin​(Insets insets)
        Overridden to update the current line highlight location.
        Overrides:
        setMargin in class JTextComponent
        Parameters:
        insets - The new insets.
      • setMarginLineEnabled

        public void setMarginLineEnabled​(boolean enabled)
        Enables or disables the margin line.
        Parameters:
        enabled - Whether or not 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 #getDefaultMarginLinePosition
        See Also:
        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 type ROUNDED_SELECTION_PROPERTY.
        Parameters:
        rounded - Whether selection edges should be rounded.
        See Also:
        getRoundedSelectionEdges()
      • setRTextAreaUI

        protected void setRTextAreaUI​(RTextAreaUI ui)
        Sets the UI for this RTextArea. Note that, for instances of RTextArea, setUI only updates the popup menu; this is because RTextAreas' 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.
        Parameters:
        ui - The new UI.
        See Also:
        JTextComponent.setUI(javax.swing.plaf.TextUI)
      • setTabSize

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

        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 class JTextArea
        Parameters:
        size - Number of characters to expand to.
      • updateMarginLineX

        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.
      • yForLine

        public int yForLine​(int line)
                     throws 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:
        BadLocationException - If line isn't a valid line number for this document.
      • yForLineContaining

        public int yForLineContaining​(int offs)
                               throws 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:
        BadLocationException - If offs isn't a valid offset into the document.