Java 类javax.swing.text.LayeredHighlighter 实例源码

项目:powertext    文件:RTextAreaHighlighter.java   
/**
 * {@inheritDoc}
 */
@Override
public void paintLayeredHighlights(Graphics g, int p0, int p1,
                            Shape viewBounds, JTextComponent editor,
                            View view) {
    int start = getStartOffset();
    int end = getEndOffset();
    end++; // Workaround for Java highlight issues
    // Restrict the region to what we represent
    p0 = Math.max(start, p0);
    p1 = Math.min(end, p1);
    if (getColor()!=null &&
            getPainter() instanceof ChangeableHighlightPainter) {
        ((ChangeableHighlightPainter)getPainter()).setPaint(getColor());
    }
    // Paint the appropriate region using the painter and union
    // the effected region with our bounds.
    union(((LayeredHighlighter.LayerPainter)getPainter()).paintLayer(
                        g, p0, p1, viewBounds, editor, view));
}
项目:ftc    文件:RTextAreaHighlighter.java   
/**
 * {@inheritDoc}
 */
public void paintLayeredHighlights(Graphics g, int p0, int p1,
                            Shape viewBounds, JTextComponent editor,
                            View view) {
    int start = getStartOffset();
    int end = getEndOffset();
    end++; // Workaround for Java highlight issues
    // Restrict the region to what we represent
    p0 = Math.max(start, p0);
    p1 = Math.min(end, p1);
    if (getColor()!=null &&
            (getPainter() instanceof ChangeableHighlightPainter)) {
        ((ChangeableHighlightPainter)getPainter()).setPaint(getColor());
    }
    // Paint the appropriate region using the painter and union
    // the effected region with our bounds.
    union(((LayeredHighlighter.LayerPainter)getPainter()).paintLayer
                        (g, p0, p1, viewBounds, editor, view));
}
项目:littleluck    文件:SnippetHighlighter.java   
/**
    * Adds a highlight to the view.  Returns a tag that can be used 
    * to refer to the highlight.
    *
    * @param p0   the start offset of the range to highlight >= 0
    * @param p1   the end offset of the range to highlight >= p0
    * @param p    the painter to use to actually render the highlight
    * @return     an object that can be used as a tag
    *   to refer to the highlight
    * @exception BadLocationException if the specified location is invalid
    */
   public Object addHighlight(int p0, int p1, Highlighter.HighlightPainter p) throws BadLocationException {
Document doc = component.getDocument();
HighlightInfo i = (getDrawsLayeredHighlights() &&
           (p instanceof LayeredHighlighter.LayerPainter)) ?
                  new LayeredHighlightInfo() : new HighlightInfo();
i.painter = p;
i.p0 = doc.createPosition(p0);
i.p1 = doc.createPosition(p1);
       // For snippets, we want to make sure selection is layered ON TOP
       // since we add transparency to the selection color;  so rather
       // than append the highlight, we insert it in the front.
highlights.insertElementAt(i, 0);
       safeDamageRange(p0, p1);
       return i;
   }
项目:Tank    文件:RSyntaxTextAreaHighlighter.java   
/**
 * Restricts the region based on the receivers offsets and messages the painter to paint the region.
 */
void paintLayeredHighlights(Graphics g, int p0, int p1,
        Shape viewBounds, JTextComponent editor,
        View view) {
    int start = getStartOffset();
    int end = getEndOffset();
    // Restrict the region to what we represent
    p0 = Math.max(start, p0);
    p1 = Math.min(end, p1);
    if (getColor() != null &&
            (painter instanceof ChangeableColorHighlightPainter)) {
        ((ChangeableColorHighlightPainter) painter).setColor(getColor());
    }
    // Paint the appropriate region using the painter and union
    // the effected region with our bounds.
    union(((LayeredHighlighter.LayerPainter) painter).paintLayer
            (g, p0, p1, viewBounds, editor, view));
}
项目:Tank    文件:RSyntaxTextAreaHighlighter.java   
/**
 * Restricts the region based on the receivers offsets and messages the painter to paint the region.
 */
void paintLayeredHighlights(Graphics g, int p0, int p1,
        Shape viewBounds, JTextComponent editor,
        View view) {
    int start = getStartOffset();
    int end = getEndOffset();
    // Restrict the region to what we represent
    p0 = Math.max(start, p0);
    p1 = Math.min(end, p1);
    if (getColor() != null &&
            (painter instanceof ChangeableColorHighlightPainter)) {
        ((ChangeableColorHighlightPainter) painter).setColor(getColor());
    }
    // Paint the appropriate region using the painter and union
    // the effected region with our bounds.
    union(((LayeredHighlighter.LayerPainter) painter).paintLayer
            (g, p0, p1, viewBounds, editor, view));
}
项目:beautyeye    文件:SnippetHighlighter.java   
/**
    * Adds a highlight to the view.  Returns a tag that can be used 
    * to refer to the highlight.
    *
    * @param p0   the start offset of the range to highlight >= 0
    * @param p1   the end offset of the range to highlight >= p0
    * @param p    the painter to use to actually render the highlight
    * @return     an object that can be used as a tag
    *   to refer to the highlight
    * @exception BadLocationException if the specified location is invalid
    */
   public Object addHighlight(int p0, int p1, Highlighter.HighlightPainter p) throws BadLocationException {
Document doc = component.getDocument();
HighlightInfo i = (getDrawsLayeredHighlights() &&
           (p instanceof LayeredHighlighter.LayerPainter)) ?
                  new LayeredHighlightInfo() : new HighlightInfo();
i.painter = p;
i.p0 = doc.createPosition(p0);
i.p1 = doc.createPosition(p1);
       // For snippets, we want to make sure selection is layered ON TOP
       // since we add transparency to the selection color;  so rather
       // than append the highlight, we insert it in the front.
highlights.insertElementAt(i, 0);
       safeDamageRange(p0, p1);
       return i;
   }
项目:swingx    文件:SnippetHighlighter.java   
/**
    * Adds a highlight to the view.  Returns a tag that can be used 
    * to refer to the highlight.
    *
    * @param p0   the start offset of the range to highlight >= 0
    * @param p1   the end offset of the range to highlight >= p0
    * @param p    the painter to use to actually render the highlight
    * @return     an object that can be used as a tag
    *   to refer to the highlight
    * @exception BadLocationException if the specified location is invalid
    */
   public Object addHighlight(int p0, int p1, Highlighter.HighlightPainter p) throws BadLocationException {
Document doc = component.getDocument();
HighlightInfo i = (getDrawsLayeredHighlights() &&
           (p instanceof LayeredHighlighter.LayerPainter)) ?
                  new LayeredHighlightInfo() : new HighlightInfo();
i.painter = p;
i.p0 = doc.createPosition(p0);
i.p1 = doc.createPosition(p1);
       // For snippets, we want to make sure selection is layered ON TOP
       // since we add transparency to the selection color;  so rather
       // than append the highlight, we insert it in the front.
highlights.insertElementAt(i, 0);
       safeDamageRange(p0, p1);
       return i;
   }
项目:ESPlorer    文件:RTextAreaHighlighter.java   
/**
 * {@inheritDoc}
 */
public void paintLayeredHighlights(Graphics g, int p0, int p1,
                            Shape viewBounds, JTextComponent editor,
                            View view) {
    int start = getStartOffset();
    int end = getEndOffset();
    end++; // Workaround for Java highlight issues
    // Restrict the region to what we represent
    p0 = Math.max(start, p0);
    p1 = Math.min(end, p1);
    if (getColor()!=null &&
            (getPainter() instanceof ChangeableHighlightPainter)) {
        ((ChangeableHighlightPainter)getPainter()).setPaint(getColor());
    }
    // Paint the appropriate region using the painter and union
    // the effected region with our bounds.
    union(((LayeredHighlighter.LayerPainter)getPainter()).paintLayer
                        (g, p0, p1, viewBounds, editor, view));
}
项目:ESPlorer    文件:RTextAreaHighlighter.java   
/**
 * {@inheritDoc}
 */
public void paintLayeredHighlights(Graphics g, int p0, int p1,
                            Shape viewBounds, JTextComponent editor,
                            View view) {
    int start = getStartOffset();
    int end = getEndOffset();
    end++; // Workaround for Java highlight issues
    // Restrict the region to what we represent
    p0 = Math.max(start, p0);
    p1 = Math.min(end, p1);
    if (getColor()!=null &&
            (getPainter() instanceof ChangeableHighlightPainter)) {
        ((ChangeableHighlightPainter)getPainter()).setPaint(getColor());
    }
    // Paint the appropriate region using the painter and union
    // the effected region with our bounds.
    union(((LayeredHighlighter.LayerPainter)getPainter()).paintLayer
                        (g, p0, p1, viewBounds, editor, view));
}
项目:RSyntaxTextArea    文件:RSyntaxTextAreaHighlighter.java   
/**
 * Restricts the region based on the receivers offsets and messages
 * the painter to paint the region.
 */
void paintLayeredHighlights(Graphics g, int p0, int p1,
                            Shape viewBounds, JTextComponent editor,
                            View view) {
    int start = getStartOffset();
    int end = getEndOffset();
    // Restrict the region to what we represent
    p0 = Math.max(start, p0);
    p1 = Math.min(end, p1);
    if (getColor()!=null &&
            (painter instanceof ChangeableColorHighlightPainter)) {
        ((ChangeableColorHighlightPainter)painter).setColor(getColor());
    }
    // Paint the appropriate region using the painter and union
    // the effected region with our bounds.
    union(((LayeredHighlighter.LayerPainter)painter).paintLayer
                        (g, p0, p1, viewBounds, editor, view));
}
项目:littleluck    文件:SnippetHighlighter.java   
/**
 * Restricts the region based on the receivers offsets and messages
 * the painter to paint the region.
 */
void paintLayeredHighlights(Graphics g, int p0, int p1,
                Shape viewBounds, JTextComponent editor,
                View view) {
    int start = getStartOffset();
    int end = getEndOffset();
    // Restrict the region to what we represent
    p0 = Math.max(start, p0);
    p1 = Math.min(end, p1);
    // Paint the appropriate region using the painter and union
    // the effected region with our bounds.
    union(((LayeredHighlighter.LayerPainter)painter).paintLayer
      (g, p0, p1, viewBounds, editor, view));
}
项目:beautyeye    文件:SnippetHighlighter.java   
/**
 * Restricts the region based on the receivers offsets and messages
 * the painter to paint the region.
 */
void paintLayeredHighlights(Graphics g, int p0, int p1,
                Shape viewBounds, JTextComponent editor,
                View view) {
    int start = getStartOffset();
    int end = getEndOffset();
    // Restrict the region to what we represent
    p0 = Math.max(start, p0);
    p1 = Math.min(end, p1);
    // Paint the appropriate region using the painter and union
    // the effected region with our bounds.
    union(((LayeredHighlighter.LayerPainter)painter).paintLayer
      (g, p0, p1, viewBounds, editor, view));
}
项目:swingx    文件:SnippetHighlighter.java   
/**
 * Restricts the region based on the receivers offsets and messages
 * the painter to paint the region.
 */
void paintLayeredHighlights(Graphics g, int p0, int p1,
                Shape viewBounds, JTextComponent editor,
                View view) {
    int start = getStartOffset();
    int end = getEndOffset();
    // Restrict the region to what we represent
    p0 = Math.max(start, p0);
    p1 = Math.min(end, p1);
    // Paint the appropriate region using the painter and union
    // the effected region with our bounds.
    union(((LayeredHighlighter.LayerPainter)painter).paintLayer
      (g, p0, p1, viewBounds, editor, view));
}
项目:swingbox-javahelp-viewer    文件:BlockReplacedBoxView.java   
private void paintHighlights(Graphics g, Shape shape)
{
    if (container instanceof JTextComponent)
    {
        JTextComponent tc = (JTextComponent) container;
        Highlighter h = tc.getHighlighter();
        if (h instanceof LayeredHighlighter)
        {
            ((LayeredHighlighter) h).paintLayeredHighlights(g,
                    getStartOffset(), getEndOffset(), shape, tc, this);
        }
    }
}
项目:swingbox-javahelp-viewer    文件:InlineReplacedBoxView.java   
private void paintHighlights(Graphics g, Shape shape)
{
    if (container instanceof JTextComponent)
    {
        JTextComponent tc = (JTextComponent) container;
        Highlighter h = tc.getHighlighter();
        if (h instanceof LayeredHighlighter)
        {
            ((LayeredHighlighter) h).paintLayeredHighlights(g,
                    getStartOffset(), getEndOffset(), shape, tc, this);
        }
    }
}
项目:swingbox-javahelp-viewer    文件:TextBoxView.java   
/**
 * Process paint.
 * 
 * @param gg
 *            the graphics context
 * @param a
 *            the allocation
 */
protected void processPaint(Graphics gg, Shape a)
{
    Graphics2D g = (Graphics2D) gg;
    AffineTransform tmpTransform = g.getTransform();
    if (!tmpTransform.equals(transform))
    {
        transform = tmpTransform;
        invalidateTextLayout();
    }

    Component c = container;
    int p0 = getStartOffset();
    int p1 = getEndOffset();
    Color fg = getForeground();

    if (c instanceof JTextComponent)
    {
        JTextComponent tc = (JTextComponent) c;
        if (!tc.isEnabled())
        {
            fg = tc.getDisabledTextColor();
        }

        // javax.swing.plaf.basic.BasicTextUI $ BasicHighlighter
        // >> DefaultHighlighter
        // >> DefaultHighlightPainter

        Highlighter highLighter = tc.getHighlighter();
        if (highLighter instanceof LayeredHighlighter)
        {
            ((LayeredHighlighter) highLighter).paintLayeredHighlights(g, p0, p1, box.getAbsoluteContentBounds(), tc, this);
            // (g, p0, p1, a, tc, this);
        }
    }
    // nothing is selected
    if (!box.isEmpty() && !getText().isEmpty())
        renderContent(g, a, fg, p0, p1);

}
项目:SwingBox    文件:BlockReplacedBoxView.java   
private void paintHighlights(Graphics g, Shape shape)
{
    if (container instanceof JTextComponent)
    {
        JTextComponent tc = (JTextComponent) container;
        Highlighter h = tc.getHighlighter();
        if (h instanceof LayeredHighlighter)
        {
            ((LayeredHighlighter) h).paintLayeredHighlights(g,
                    getStartOffset(), getEndOffset(), shape, tc, this);
        }
    }
}
项目:SwingBox    文件:InlineReplacedBoxView.java   
private void paintHighlights(Graphics g, Shape shape)
{
    if (container instanceof JTextComponent)
    {
        JTextComponent tc = (JTextComponent) container;
        Highlighter h = tc.getHighlighter();
        if (h instanceof LayeredHighlighter)
        {
            ((LayeredHighlighter) h).paintLayeredHighlights(g,
                    getStartOffset(), getEndOffset(), shape, tc, this);
        }
    }
}
项目:SwingBox    文件:TextBoxView.java   
/**
 * Process paint.
 * 
 * @param gg
 *            the graphics context
 * @param a
 *            the allocation
 */
protected void processPaint(Graphics gg, Shape a)
{
    Graphics2D g = (Graphics2D) gg;
    AffineTransform tmpTransform = g.getTransform();
    if (!tmpTransform.equals(transform))
    {
        transform = tmpTransform;
        invalidateTextLayout();
    }

    Component c = container;
    int p0 = getStartOffset();
    int p1 = getEndOffset();
    Color fg = getForeground();

    if (c instanceof JTextComponent)
    {
        JTextComponent tc = (JTextComponent) c;
        if (!tc.isEnabled())
        {
            fg = tc.getDisabledTextColor();
        }

        // javax.swing.plaf.basic.BasicTextUI $ BasicHighlighter
        // >> DefaultHighlighter
        // >> DefaultHighlightPainter

        Highlighter highLighter = tc.getHighlighter();
        if (highLighter instanceof LayeredHighlighter)
        {
            ((LayeredHighlighter) highLighter).paintLayeredHighlights(g, p0, p1, box.getAbsoluteContentBounds(), tc, this);
            // (g, p0, p1, a, tc, this);
        }
    }
    // nothing is selected
    if (!box.isEmpty() && !getText().isEmpty())
        renderContent(g, a, fg, p0, p1);

}
项目:cn1    文件:ImageView.java   
@Override
public void paint(final Graphics g, final Shape shape) {

    Rectangle rc = shape.getBounds();
    rc.setSize(rc.width - 2*(hSpace + border), rc.height - 2*(vSpace + border));



    // TODO change layered highlight painting code
    JTextComponent tc = (JTextComponent)getContainer();
    Highlighter hl = tc.getHighlighter();
    if (hl instanceof LayeredHighlighter) {
        ((LayeredHighlighter)hl).paintLayeredHighlights(g,
                                                        getStartOffset(),
                                                        getEndOffset(),
                                                        shape, tc, this);
    }

    Color oldColor = g.getColor();
    if (border > 0) {
        g.setColor(color);
        g.fillRect(rc.x + hSpace, rc.y + vSpace, rc.width + 2 * border,
                rc.height + 2 * border);
        g.setColor(oldColor);
        g.fillRect(rc.x + hSpace + border, rc.y + vSpace + border,
                rc.width, rc.height);
    }

    if (loader.isError()) {

        g.setColor(color);

        getNoImageIcon().paintIcon(null, g, rc.x + hSpace + border, rc.y+vSpace + border);

        String alt = getAltText();
        if (alt != null) {
            Font oldFont = g.getFont();

            Font font = getStyleSheet().getFont(getAttributes());
            g.setFont(font);
            FontMetrics metrics = g.getFontMetrics();
            g.drawString(alt, rc.x + hSpace + border
                    + getNoImageIcon().getIconWidth(), rc.y + vSpace + border+ metrics.getAscent());

            g.setFont(oldFont);
        }

        g.setColor(oldColor);
        return;
    }

    if (!loader.isReady()) {
        if (!synchronous) {
            getLoadingImageIcon().paintIcon(null, g, rc.x, rc.y);
            return;
        }
    }

    g.drawImage(getImage(), rc.x + hSpace + border, rc.y + vSpace + border, rc.width, rc.height, loader);
}
项目:freeVM    文件:ImageView.java   
public void paint(final Graphics g, final Shape shape) {
    Rectangle rc = shape.getBounds();

    // TODO change layered highlight painting code
    JTextComponent tc = (JTextComponent)getContainer();
    Highlighter hl = tc.getHighlighter();
    if (hl instanceof LayeredHighlighter) {
        ((LayeredHighlighter)hl).paintLayeredHighlights(g,
                                                        getStartOffset(),
                                                        getEndOffset(),
                                                        shape, tc, this);
    }

    if (loader.isError()) {
        getNoImageIcon().paintIcon(null, g, rc.x, rc.y);
        Color oldColor = g.getColor();
        g.setColor(color);

        String alt = getAltText();
        if (alt != null) {
            Font oldFont = g.getFont();

            Font font = getStyleSheet().getFont(getAttributes());
            g.setFont(font);
            FontMetrics metrics = g.getFontMetrics();
            g.drawString(alt, rc.x + getNoImageIcon().getIconWidth(),
                         rc.y + metrics.getAscent());

            g.setFont(oldFont);
        }
        g.drawRect(rc.x, rc.y, rc.width - 1, rc.height - 1);
        g.setColor(oldColor);
        return;
    }

    if (!loader.isReady()) {
        if (!synchronous) {
            getLoadingImageIcon().paintIcon(null, g, rc.x, rc.y);
        } else {
            loader.waitForImage();
        }
        return;
    }

    g.drawImage(getImage(), rc.x, rc.y, rc.width, rc.height, loader);
}
项目:freeVM    文件:ImageView.java   
@Override
public void paint(final Graphics g, final Shape shape) {

    Rectangle rc = shape.getBounds();
    rc.setSize(rc.width - 2*(hSpace + border), rc.height - 2*(vSpace + border));



    // TODO change layered highlight painting code
    JTextComponent tc = (JTextComponent)getContainer();
    Highlighter hl = tc.getHighlighter();
    if (hl instanceof LayeredHighlighter) {
        ((LayeredHighlighter)hl).paintLayeredHighlights(g,
                                                        getStartOffset(),
                                                        getEndOffset(),
                                                        shape, tc, this);
    }

    Color oldColor = g.getColor();
    if (border > 0) {
        g.setColor(color);
        g.fillRect(rc.x + hSpace, rc.y + vSpace, rc.width + 2 * border,
                rc.height + 2 * border);
        g.setColor(oldColor);
        g.fillRect(rc.x + hSpace + border, rc.y + vSpace + border,
                rc.width, rc.height);
    }

    if (loader.isError()) {

        g.setColor(color);

        getNoImageIcon().paintIcon(null, g, rc.x + hSpace + border, rc.y+vSpace + border);

        String alt = getAltText();
        if (alt != null) {
            Font oldFont = g.getFont();

            Font font = getStyleSheet().getFont(getAttributes());
            g.setFont(font);
            FontMetrics metrics = g.getFontMetrics();
            g.drawString(alt, rc.x + hSpace + border
                    + getNoImageIcon().getIconWidth(), rc.y + vSpace + border+ metrics.getAscent());

            g.setFont(oldFont);
        }

        g.setColor(oldColor);
        return;
    }

    if (!loader.isReady()) {
        if (!synchronous) {
            getLoadingImageIcon().paintIcon(null, g, rc.x, rc.y);
            return;
        }
    }

    g.drawImage(getImage(), rc.x + hSpace + border, rc.y + vSpace + border, rc.width, rc.height, loader);
}