Java Code Examples for javax.swing.text.Highlighter#HighlightPainter

The following examples show how to use javax.swing.text.Highlighter#HighlightPainter . 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: SwingUtilities2.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Determines whether the SelectedTextColor should be used for painting text
 * foreground for the specified highlight.
 *
 * Returns true only if the highlight painter for the specified highlight
 * is the swing painter (whether inner class of javax.swing.text.DefaultHighlighter
 * or com.sun.java.swing.plaf.windows.WindowsTextUI) and its background color
 * is null or equals to the selection color of the text component.
 *
 * This is a hack for fixing both bugs 4761990 and 5003294
 */
public static boolean useSelectedTextColor(Highlighter.Highlight h, JTextComponent c) {
    Highlighter.HighlightPainter painter = h.getPainter();
    String painterClass = painter.getClass().getName();
    if (painterClass.indexOf("javax.swing.text.DefaultHighlighter") != 0 &&
            painterClass.indexOf("com.sun.java.swing.plaf.windows.WindowsTextUI") != 0) {
        return false;
    }
    try {
        DefaultHighlighter.DefaultHighlightPainter defPainter =
                (DefaultHighlighter.DefaultHighlightPainter) painter;
        if (defPainter.getColor() != null &&
                !defPainter.getColor().equals(c.getSelectionColor())) {
            return false;
        }
    } catch (ClassCastException e) {
        return false;
    }
    return true;
}
 
Example 2
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 3
Source File: SnippetHighlighter.java    From littleluck with Apache License 2.0 6 votes vote down vote up
/**
    * Renders the highlights.
    *
    * @param g the graphics context
    */
   public void paint(Graphics g) {
       // PENDING(prinz) - should cull ranges not visible
       int len = highlights.size();
       for (int i = 0; i < len; i++) {
    HighlightInfo info = highlights.elementAt(i);
    if (!(info instanceof LayeredHighlightInfo)) {
	// Avoid allocing unless we need it.
	Rectangle a = component.getBounds();
	Insets insets = component.getInsets();
	a.x = insets.left;
	a.y = insets.top;
	a.width -= insets.left + insets.right;
	a.height -= insets.top + insets.bottom;
	for (; i < len; i++) {
	    info = highlights.elementAt(i);
	    if (!(info instanceof LayeredHighlightInfo)) {
		Highlighter.HighlightPainter p = info.getPainter();
		p.paint(g, info.getStartOffset(), info.getEndOffset(),
			a, component);
	    }
	}
    }
}
   }
 
Example 4
Source File: CaretFloatingPointAPITest.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
private void updateSelection() {
    Highlighter h = component.getHighlighter();
    if (h != null) {
        int p0 = Math.min(dot, mark);
        int p1 = Math.max(dot, mark);

        if (p0 == p1 || !selectionVisible) {
            if (selectionTag != null) {
                h.removeHighlight(selectionTag);
                selectionTag = null;
            }
        } else {
            try {
                if (selectionTag != null) {
                    h.changeHighlight(selectionTag, p0, p1);
                } else {
                    Highlighter.HighlightPainter p = getSelectionPainter();
                    selectionTag = h.addHighlight(p0, p1, p);
                }
            } catch (BadLocationException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
 
Example 5
Source File: SwingUtilities2.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Determines whether the SelectedTextColor should be used for painting text
 * foreground for the specified highlight.
 *
 * Returns true only if the highlight painter for the specified highlight
 * is the swing painter (whether inner class of javax.swing.text.DefaultHighlighter
 * or com.sun.java.swing.plaf.windows.WindowsTextUI) and its background color
 * is null or equals to the selection color of the text component.
 *
 * This is a hack for fixing both bugs 4761990 and 5003294
 */
public static boolean useSelectedTextColor(Highlighter.Highlight h, JTextComponent c) {
    Highlighter.HighlightPainter painter = h.getPainter();
    String painterClass = painter.getClass().getName();
    if (painterClass.indexOf("javax.swing.text.DefaultHighlighter") != 0 &&
            painterClass.indexOf("com.sun.java.swing.plaf.windows.WindowsTextUI") != 0) {
        return false;
    }
    try {
        DefaultHighlighter.DefaultHighlightPainter defPainter =
                (DefaultHighlighter.DefaultHighlightPainter) painter;
        if (defPainter.getColor() != null &&
                !defPainter.getColor().equals(c.getSelectionColor())) {
            return false;
        }
    } catch (ClassCastException e) {
        return false;
    }
    return true;
}
 
Example 6
Source File: SwingUtilities2.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Determines whether the SelectedTextColor should be used for painting text
 * foreground for the specified highlight.
 *
 * Returns true only if the highlight painter for the specified highlight
 * is the swing painter (whether inner class of javax.swing.text.DefaultHighlighter
 * or com.sun.java.swing.plaf.windows.WindowsTextUI) and its background color
 * is null or equals to the selection color of the text component.
 *
 * This is a hack for fixing both bugs 4761990 and 5003294
 */
public static boolean useSelectedTextColor(Highlighter.Highlight h, JTextComponent c) {
    Highlighter.HighlightPainter painter = h.getPainter();
    String painterClass = painter.getClass().getName();
    if (painterClass.indexOf("javax.swing.text.DefaultHighlighter") != 0 &&
            painterClass.indexOf("com.sun.java.swing.plaf.windows.WindowsTextUI") != 0) {
        return false;
    }
    try {
        DefaultHighlighter.DefaultHighlightPainter defPainter =
                (DefaultHighlighter.DefaultHighlightPainter) painter;
        if (defPainter.getColor() != null &&
                !defPainter.getColor().equals(c.getSelectionColor())) {
            return false;
        }
    } catch (ClassCastException e) {
        return false;
    }
    return true;
}
 
Example 7
Source File: CaretFloatingPointAPITest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private void updateSelection() {
    Highlighter h = component.getHighlighter();
    if (h != null) {
        int p0 = Math.min(dot, mark);
        int p1 = Math.max(dot, mark);

        if (p0 == p1 || !selectionVisible) {
            if (selectionTag != null) {
                h.removeHighlight(selectionTag);
                selectionTag = null;
            }
        } else {
            try {
                if (selectionTag != null) {
                    h.changeHighlight(selectionTag, p0, p1);
                } else {
                    Highlighter.HighlightPainter p = getSelectionPainter();
                    selectionTag = h.addHighlight(p0, p1, p);
                }
            } catch (BadLocationException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
 
Example 8
Source File: SwingUtilities2.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Determines whether the SelectedTextColor should be used for painting text
 * foreground for the specified highlight.
 *
 * Returns true only if the highlight painter for the specified highlight
 * is the swing painter (whether inner class of javax.swing.text.DefaultHighlighter
 * or com.sun.java.swing.plaf.windows.WindowsTextUI) and its background color
 * is null or equals to the selection color of the text component.
 *
 * This is a hack for fixing both bugs 4761990 and 5003294
 */
public static boolean useSelectedTextColor(Highlighter.Highlight h, JTextComponent c) {
    Highlighter.HighlightPainter painter = h.getPainter();
    String painterClass = painter.getClass().getName();
    if (painterClass.indexOf("javax.swing.text.DefaultHighlighter") != 0 &&
            painterClass.indexOf("com.sun.java.swing.plaf.windows.WindowsTextUI") != 0) {
        return false;
    }
    try {
        DefaultHighlighter.DefaultHighlightPainter defPainter =
                (DefaultHighlighter.DefaultHighlightPainter) painter;
        if (defPainter.getColor() != null &&
                !defPainter.getColor().equals(c.getSelectionColor())) {
            return false;
        }
    } catch (ClassCastException e) {
        return false;
    }
    return true;
}
 
Example 9
Source File: SwingUtilities2.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Determines whether the SelectedTextColor should be used for painting text
 * foreground for the specified highlight.
 *
 * Returns true only if the highlight painter for the specified highlight
 * is the swing painter (whether inner class of javax.swing.text.DefaultHighlighter
 * or com.sun.java.swing.plaf.windows.WindowsTextUI) and its background color
 * is null or equals to the selection color of the text component.
 *
 * This is a hack for fixing both bugs 4761990 and 5003294
 */
public static boolean useSelectedTextColor(Highlighter.Highlight h, JTextComponent c) {
    Highlighter.HighlightPainter painter = h.getPainter();
    String painterClass = painter.getClass().getName();
    if (painterClass.indexOf("javax.swing.text.DefaultHighlighter") != 0 &&
            painterClass.indexOf("com.sun.java.swing.plaf.windows.WindowsTextUI") != 0) {
        return false;
    }
    try {
        DefaultHighlighter.DefaultHighlightPainter defPainter =
                (DefaultHighlighter.DefaultHighlightPainter) painter;
        if (defPainter.getColor() != null &&
                !defPainter.getColor().equals(c.getSelectionColor())) {
            return false;
        }
    } catch (ClassCastException e) {
        return false;
    }
    return true;
}
 
Example 10
Source File: SwingUtilities2.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Determines whether the SelectedTextColor should be used for painting text
 * foreground for the specified highlight.
 *
 * Returns true only if the highlight painter for the specified highlight
 * is the swing painter (whether inner class of javax.swing.text.DefaultHighlighter
 * or com.sun.java.swing.plaf.windows.WindowsTextUI) and its background color
 * is null or equals to the selection color of the text component.
 *
 * This is a hack for fixing both bugs 4761990 and 5003294
 */
public static boolean useSelectedTextColor(Highlighter.Highlight h, JTextComponent c) {
    Highlighter.HighlightPainter painter = h.getPainter();
    String painterClass = painter.getClass().getName();
    if (painterClass.indexOf("javax.swing.text.DefaultHighlighter") != 0 &&
            painterClass.indexOf("com.sun.java.swing.plaf.windows.WindowsTextUI") != 0) {
        return false;
    }
    try {
        DefaultHighlighter.DefaultHighlightPainter defPainter =
                (DefaultHighlighter.DefaultHighlightPainter) painter;
        if (defPainter.getColor() != null &&
                !defPainter.getColor().equals(c.getSelectionColor())) {
            return false;
        }
    } catch (ClassCastException e) {
        return false;
    }
    return true;
}
 
Example 11
Source File: HighlightHelper.java    From r2m-plugin-android with Apache License 2.0 5 votes vote down vote up
private static void setHighlight(JTextArea highlight, JSONError error) {
    Highlighter.HighlightPainter errorHighlighter =
            new DefaultHighlighter.DefaultHighlightPainter(PINK);
    try {
        highlight.getHighlighter().addHighlight(error.getStartIndex(),
                error.getEndIndex(),
                errorHighlighter);
    } catch (Exception ble) {
        ble.printStackTrace();
    }
}
 
Example 12
Source File: MaeMainController.java    From mae-annotation with GNU General Public License v3.0 5 votes vote down vote up
public void addBGColorOver(int[] spans, Highlighter.HighlightPainter painter) {
    try {
        getTextPanel().addBGColorOver(spans, painter);
    } catch (MaeControlException e) {
        showError(e);
    }
}
 
Example 13
Source File: ColorHandler.java    From mae-annotation with GNU General Public License v3.0 4 votes vote down vote up
public static Highlighter.HighlightPainter getDefaultHighlighter() {
    return DefaultHighlighter.DefaultPainter;
}
 
Example 14
Source File: CaretFloatingPointAPITest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
protected Highlighter.HighlightPainter getSelectionPainter() {
    return DefaultHighlighter.DefaultPainter;
}
 
Example 15
Source File: ColorHandler.java    From mae-annotation with GNU General Public License v3.0 4 votes vote down vote up
public static Highlighter.HighlightPainter getFadingHighlighter() {
    return new DefaultHighlighter.DefaultHighlightPainter(getFadingForeground());
}
 
Example 16
Source File: SnippetHighlighter.java    From beautyeye with Apache License 2.0 4 votes vote down vote up
public Highlighter.HighlightPainter getPainter() {
    return painter;
}
 
Example 17
Source File: SnippetHighlighter.java    From littleluck with Apache License 2.0 4 votes vote down vote up
public Highlighter.HighlightPainter getPainter() {
    return painter;
}
 
Example 18
Source File: EditorTopComponent.java    From Open-LaTeX-Studio with MIT License 4 votes vote down vote up
public Highlighter.HighlightPainter getPainter() {
    return painter;
}
 
Example 19
Source File: MaeMainController.java    From mae-annotation with GNU General Public License v3.0 2 votes vote down vote up
public void addBGColorOver(List<Integer> spans, Highlighter.HighlightPainter painter) {
    addBGColorOver(SpanHandler.convertIntegerlistToIntegerarray(spans), painter);

}
 
Example 20
Source File: LinkHandler.java    From jpexs-decompiler with GNU General Public License v3.0 votes vote down vote up
public Highlighter.HighlightPainter linkPainter();