javax.swing.text.LayeredHighlighter Java Examples

The following examples show how to use javax.swing.text.LayeredHighlighter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SnippetHighlighter.java    From littleluck with Apache License 2.0 6 votes vote down vote up
/**
    * 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;
   }
 
Example #2
Source File: SnippetHighlighter.java    From beautyeye with Apache License 2.0 6 votes vote down vote up
/**
    * 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;
   }
 
Example #3
Source File: ImageView.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
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);
        }
    }
}
 
Example #4
Source File: ImageView.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
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);
        }
    }
}
 
Example #5
Source File: SnippetHighlighter.java    From littleluck with Apache License 2.0 5 votes vote down vote up
/**
 * 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));
}
 
Example #6
Source File: SnippetHighlighter.java    From beautyeye with Apache License 2.0 5 votes vote down vote up
/**
 * 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));
}
 
Example #7
Source File: BlockReplacedBoxView.java    From SwingBox with GNU Lesser General Public License v3.0 5 votes vote down vote up
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);
        }
    }
}
 
Example #8
Source File: InlineReplacedBoxView.java    From SwingBox with GNU Lesser General Public License v3.0 5 votes vote down vote up
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);
        }
    }
}
 
Example #9
Source File: TextBoxView.java    From SwingBox with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 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);

}