Package editor

Class GosuStyleContext.GosuSourceView

  • All Implemented Interfaces:
    javax.swing.SwingConstants, javax.swing.text.TabExpander
    Enclosing class:
    GosuStyleContext

    class GosuStyleContext.GosuSourceView
    extends javax.swing.text.WrappedPlainView
    View that uses the lexical information to determine the style characteristics of the text that it renders. This simply colorizes the various tokens and assumes a constant font family and size.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) GosuDocument.Scanner _lexer  
      • Fields inherited from class javax.swing.text.View

        BadBreakWeight, ExcellentBreakWeight, ForcedBreakWeight, GoodBreakWeight, X_AXIS, Y_AXIS
      • Fields inherited from interface javax.swing.SwingConstants

        BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
    • Constructor Summary

      Constructors 
      Constructor Description
      GosuSourceView​(javax.swing.text.Element elem)
      Construct a simple syntax highlight view of gosu source.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected int drawSelectedText​(java.awt.Graphics g, int x, int y, int p0, int p1)
      Renders the given range in the model as normal unselected text.
      int drawTabbedText​(javax.swing.text.Segment s, javax.swing.text.Style style, java.awt.Font font, int x, int y, java.awt.Graphics2D g, javax.swing.text.TabExpander e, int startOffset)  
      void drawText​(java.awt.Graphics2D g2, javax.swing.text.Style style, java.awt.Font font, java.lang.String text, int x, int y)
      Draws text using a TextLayout.
      protected int drawUnselectedText​(java.awt.Graphics g, int x, int y, int p0, int p1)  
      void paint​(java.awt.Graphics g, java.awt.Shape a)
      Renders using the given rendering surface and area on that surface.
      (package private) void updateScanner​(int p)
      Update the scanner (if necessary) to point to the appropriate token for the given start position needed for rendering.
      • Methods inherited from class javax.swing.text.WrappedPlainView

        calculateBreakPosition, changedUpdate, drawLine, drawLine, drawSelectedText, drawUnselectedText, getLineBuffer, getMaximumSpan, getMinimumSpan, getPreferredSpan, getTabSize, insertUpdate, loadChildren, nextTabStop, removeUpdate, setSize
      • Methods inherited from class javax.swing.text.BoxView

        baselineLayout, baselineRequirements, calculateMajorAxisRequirements, calculateMinorAxisRequirements, childAllocation, flipEastAndWestAtEnds, forwardUpdate, getAlignment, getAxis, getChildAllocation, getHeight, getOffset, getResizeWeight, getSpan, getViewAtPoint, getWidth, isAfter, isAllocationValid, isBefore, isLayoutValid, layout, layoutChanged, layoutMajorAxis, layoutMinorAxis, modelToView, paintChild, preferenceChanged, replace, setAxis, viewToModel
      • Methods inherited from class javax.swing.text.CompositeView

        getBottomInset, getInsideAllocation, getLeftInset, getNextEastWestVisualPositionFrom, getNextNorthSouthVisualPositionFrom, getNextVisualPositionFrom, getRightInset, getTopInset, getView, getViewAtPosition, getViewCount, getViewIndex, getViewIndexAtPosition, modelToView, setInsets, setParagraphInsets, setParent
      • Methods inherited from class javax.swing.text.View

        append, breakView, createFragment, forwardUpdateToView, getAttributes, getBreakWeight, getContainer, getDocument, getElement, getEndOffset, getGraphics, getParent, getStartOffset, getToolTipText, getViewFactory, getViewIndex, insert, isVisible, modelToView, remove, removeAll, updateChildren, updateLayout, viewToModel
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • GosuSourceView

        GosuSourceView​(javax.swing.text.Element elem)
        Construct a simple syntax highlight view of gosu source.
    • Method Detail

      • paint

        public void paint​(java.awt.Graphics g,
                          java.awt.Shape a)
        Renders using the given rendering surface and area on that surface. This is implemented to invalidate the lexical scanner after rendering so that the next request to drawUnselectedText will set a new range for the scanner.
        Overrides:
        paint in class javax.swing.text.WrappedPlainView
        Parameters:
        g - The rendering surface to use
        a - The allocated region to render into
      • drawSelectedText

        protected int drawSelectedText​(java.awt.Graphics g,
                                       int x,
                                       int y,
                                       int p0,
                                       int p1)
                                throws javax.swing.text.BadLocationException
        Renders the given range in the model as normal unselected text. This is implemented to paint colors based upon the token-to-color translations. To reduce the number of calls to the Graphics object, text is batched up until a color change is detected or the entire requested range has been reached.
        Overrides:
        drawSelectedText in class javax.swing.text.WrappedPlainView
        Parameters:
        g - The graphics context
        x - The starting X coordinate
        y - The starting Y coordinate
        p0 - The beginning position in the model
        p1 - The ending position in the model
        Returns:
        The location of the end of the range
        Throws:
        javax.swing.text.BadLocationException - if the range is invalid
      • drawUnselectedText

        protected int drawUnselectedText​(java.awt.Graphics g,
                                         int x,
                                         int y,
                                         int p0,
                                         int p1)
                                  throws javax.swing.text.BadLocationException
        Overrides:
        drawUnselectedText in class javax.swing.text.WrappedPlainView
        Throws:
        javax.swing.text.BadLocationException
      • updateScanner

        void updateScanner​(int p)
        Update the scanner (if necessary) to point to the appropriate token for the given start position needed for rendering.
      • drawTabbedText

        public final int drawTabbedText​(javax.swing.text.Segment s,
                                        javax.swing.text.Style style,
                                        java.awt.Font font,
                                        int x,
                                        int y,
                                        java.awt.Graphics2D g,
                                        javax.swing.text.TabExpander e,
                                        int startOffset)
      • drawText

        public final void drawText​(java.awt.Graphics2D g2,
                                   javax.swing.text.Style style,
                                   java.awt.Font font,
                                   java.lang.String text,
                                   int x,
                                   int y)
        Draws text using a TextLayout. This method of drawing text is necessary to support certain attribute esp. TextAttribute.UNDERLINE and TextAttribute.STRIKETHROUGH .