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

下面列出了怎么用javax.swing.text.LayeredHighlighter的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: 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;
   }
 
源代码2 项目: 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;
   }
 
源代码3 项目: Bytecoder   文件: ImageView.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);
        }
    }
}
 
源代码4 项目: jdk8u_jdk   文件: ImageView.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);
        }
    }
}
 
源代码5 项目: 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));
}
 
源代码6 项目: 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));
}
 
源代码7 项目: 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);
        }
    }
}
 
源代码8 项目: 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);
        }
    }
}
 
源代码9 项目: 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);

}
 
 类所在包
 类方法
 同包方法