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

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

源代码1 项目: dragonwell8_jdk   文件: SwingUtilities2.java
/**
 * 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;
}
 
源代码2 项目: TencentKona-8   文件: TreePosTest.java
/** Add a highlighted region based on the positions in an Info object. */
private void addHighlight(Highlighter h, Info info, Color c) {
    int start = info.start;
    int end = info.end;
    if (start == -1 && end == -1)
        return;
    if (start == -1)
        start = end;
    if (end == -1)
        end = start;
    try {
        h.addHighlight(info.start, info.end,
                new DefaultHighlighter.DefaultHighlightPainter(c));
        if (info.pos != -1) {
            Color c2 = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int)(.4f * 255)); // 40%
            h.addHighlight(info.pos, info.pos + 1,
                new DefaultHighlighter.DefaultHighlightPainter(c2));
        }
    } catch (BadLocationException e) {
        e.printStackTrace();
    }
}
 
源代码3 项目: TencentKona-8   文件: CheckAttributedTree.java
/** Add a highlighted region based on the positions in an Info object. */
private void addHighlight(Highlighter h, Info info, Color c) {
    int start = info.start;
    int end = info.end;
    if (start == -1 && end == -1)
        return;
    if (start == -1)
        start = end;
    if (end == -1)
        end = start;
    try {
        h.addHighlight(info.start, info.end,
                new DefaultHighlighter.DefaultHighlightPainter(c));
        if (info.pos != -1) {
            Color c2 = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int)(.4f * 255)); // 40%
            h.addHighlight(info.pos, info.pos + 1,
                new DefaultHighlighter.DefaultHighlightPainter(c2));
        }
    } catch (BadLocationException e) {
        e.printStackTrace();
    }
}
 
源代码4 项目: TencentKona-8   文件: SwingUtilities2.java
/**
 * 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;
}
 
源代码5 项目: jdk8u60   文件: TreePosTest.java
/** Add a highlighted region based on the positions in an Info object. */
private void addHighlight(Highlighter h, Info info, Color c) {
    int start = info.start;
    int end = info.end;
    if (start == -1 && end == -1)
        return;
    if (start == -1)
        start = end;
    if (end == -1)
        end = start;
    try {
        h.addHighlight(info.start, info.end,
                new DefaultHighlighter.DefaultHighlightPainter(c));
        if (info.pos != -1) {
            Color c2 = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int)(.4f * 255)); // 40%
            h.addHighlight(info.pos, info.pos + 1,
                new DefaultHighlighter.DefaultHighlightPainter(c2));
        }
    } catch (BadLocationException e) {
        e.printStackTrace();
    }
}
 
源代码6 项目: jdk8u60   文件: CheckAttributedTree.java
/** Add a highlighted region based on the positions in an Info object. */
private void addHighlight(Highlighter h, Info info, Color c) {
    int start = info.start;
    int end = info.end;
    if (start == -1 && end == -1)
        return;
    if (start == -1)
        start = end;
    if (end == -1)
        end = start;
    try {
        h.addHighlight(info.start, info.end,
                new DefaultHighlighter.DefaultHighlightPainter(c));
        if (info.pos != -1) {
            Color c2 = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int)(.4f * 255)); // 40%
            h.addHighlight(info.pos, info.pos + 1,
                new DefaultHighlighter.DefaultHighlightPainter(c2));
        }
    } catch (BadLocationException e) {
        e.printStackTrace();
    }
}
 
源代码7 项目: jdk8u60   文件: SwingUtilities2.java
/**
 * 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;
}
 
源代码8 项目: openjdk-jdk8u   文件: TreePosTest.java
/** Add a highlighted region based on the positions in an Info object. */
private void addHighlight(Highlighter h, Info info, Color c) {
    int start = info.start;
    int end = info.end;
    if (start == -1 && end == -1)
        return;
    if (start == -1)
        start = end;
    if (end == -1)
        end = start;
    try {
        h.addHighlight(info.start, info.end,
                new DefaultHighlighter.DefaultHighlightPainter(c));
        if (info.pos != -1) {
            Color c2 = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int)(.4f * 255)); // 40%
            h.addHighlight(info.pos, info.pos + 1,
                new DefaultHighlighter.DefaultHighlightPainter(c2));
        }
    } catch (BadLocationException e) {
        e.printStackTrace();
    }
}
 
源代码9 项目: openjdk-jdk8u   文件: CheckAttributedTree.java
/** Add a highlighted region based on the positions in an Info object. */
private void addHighlight(Highlighter h, Info info, Color c) {
    int start = info.start;
    int end = info.end;
    if (start == -1 && end == -1)
        return;
    if (start == -1)
        start = end;
    if (end == -1)
        end = start;
    try {
        h.addHighlight(info.start, info.end,
                new DefaultHighlighter.DefaultHighlightPainter(c));
        if (info.pos != -1) {
            Color c2 = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int)(.4f * 255)); // 40%
            h.addHighlight(info.pos, info.pos + 1,
                new DefaultHighlighter.DefaultHighlightPainter(c2));
        }
    } catch (BadLocationException e) {
        e.printStackTrace();
    }
}
 
源代码10 项目: openjdk-jdk8u   文件: SwingUtilities2.java
/**
 * 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;
}
 
源代码11 项目: netbeans   文件: FindSupport.java
private FindSupport(TopComponent tc) {
    this.tc = tc;
    bar = new FindBar(this);
    ActionMap actionMap = tc.getActionMap();
    CallbackSystemAction a = SystemAction.get(org.openide.actions.FindAction.class);
    actionMap.put(a.getActionMapKey(), new FindAction(true));
    actionMap.put(FIND_NEXT_ACTION, new FindAction(true));
    actionMap.put(FIND_PREVIOUS_ACTION, new FindAction(false));
    // Hack ensuring the same shortcuts as editor
    JEditorPane pane = new JEditorPane();
    for (Action action : pane.getEditorKitForContentType("text/x-java").getActions()) { // NOI18N
        Object name = action.getValue(Action.NAME);
        if (FIND_NEXT_ACTION.equals(name) || FIND_PREVIOUS_ACTION.equals(name)) {
            reuseShortcut(action);
        }
    }
    // PENDING the colors below should not be hardcoded
    highlighterAll = new DefaultHighlighter.DefaultHighlightPainter(new Color(255,180,66));
    highlighterCurrent = new DefaultHighlighter.DefaultHighlightPainter(new Color(176,197,227));
    pattern = Pattern.compile("$^"); // NOI18N
}
 
源代码12 项目: openjdk-jdk8u-backup   文件: TreePosTest.java
/** Add a highlighted region based on the positions in an Info object. */
private void addHighlight(Highlighter h, Info info, Color c) {
    int start = info.start;
    int end = info.end;
    if (start == -1 && end == -1)
        return;
    if (start == -1)
        start = end;
    if (end == -1)
        end = start;
    try {
        h.addHighlight(info.start, info.end,
                new DefaultHighlighter.DefaultHighlightPainter(c));
        if (info.pos != -1) {
            Color c2 = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int)(.4f * 255)); // 40%
            h.addHighlight(info.pos, info.pos + 1,
                new DefaultHighlighter.DefaultHighlightPainter(c2));
        }
    } catch (BadLocationException e) {
        e.printStackTrace();
    }
}
 
源代码13 项目: openjdk-jdk8u-backup   文件: CheckAttributedTree.java
/** Add a highlighted region based on the positions in an Info object. */
private void addHighlight(Highlighter h, Info info, Color c) {
    int start = info.start;
    int end = info.end;
    if (start == -1 && end == -1)
        return;
    if (start == -1)
        start = end;
    if (end == -1)
        end = start;
    try {
        h.addHighlight(info.start, info.end,
                new DefaultHighlighter.DefaultHighlightPainter(c));
        if (info.pos != -1) {
            Color c2 = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int)(.4f * 255)); // 40%
            h.addHighlight(info.pos, info.pos + 1,
                new DefaultHighlighter.DefaultHighlightPainter(c2));
        }
    } catch (BadLocationException e) {
        e.printStackTrace();
    }
}
 
源代码14 项目: openjdk-jdk8u-backup   文件: SwingUtilities2.java
/**
 * 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;
}
 
源代码15 项目: Bytecoder   文件: SwingUtilities2.java
/**
 * 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;
}
 
源代码16 项目: openjdk-jdk9   文件: TreePosTest.java
/** Add a highlighted region based on the positions in an Info object. */
private void addHighlight(Highlighter h, Info info, Color c) {
    int start = info.start;
    int end = info.end;
    if (start == -1 && end == -1)
        return;
    if (start == -1)
        start = end;
    if (end == -1)
        end = start;
    try {
        h.addHighlight(info.start, info.end,
                new DefaultHighlighter.DefaultHighlightPainter(c));
        if (info.pos != -1) {
            Color c2 = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int)(.4f * 255)); // 40%
            h.addHighlight(info.pos, info.pos + 1,
                new DefaultHighlighter.DefaultHighlightPainter(c2));
        }
    } catch (BadLocationException e) {
        e.printStackTrace();
    }
}
 
源代码17 项目: openjdk-jdk9   文件: CheckAttributedTree.java
/** Add a highlighted region based on the positions in an Info object. */
private void addHighlight(Highlighter h, Info info, Color c) {
    int start = info.start;
    int end = info.end;
    if (start == -1 && end == -1)
        return;
    if (start == -1)
        start = end;
    if (end == -1)
        end = start;
    try {
        h.addHighlight(info.start, info.end,
                new DefaultHighlighter.DefaultHighlightPainter(c));
        if (info.pos != -1) {
            Color c2 = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int)(.4f * 255)); // 40%
            h.addHighlight(info.pos, info.pos + 1,
                new DefaultHighlighter.DefaultHighlightPainter(c2));
        }
    } catch (BadLocationException e) {
        e.printStackTrace();
    }
}
 
源代码18 项目: openjdk-jdk9   文件: SwingUtilities2.java
/**
 * 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;
}
 
源代码19 项目: jdk8u-jdk   文件: SwingUtilities2.java
/**
 * 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;
}
 
源代码20 项目: hottub   文件: TreePosTest.java
/** Add a highlighted region based on the positions in an Info object. */
private void addHighlight(Highlighter h, Info info, Color c) {
    int start = info.start;
    int end = info.end;
    if (start == -1 && end == -1)
        return;
    if (start == -1)
        start = end;
    if (end == -1)
        end = start;
    try {
        h.addHighlight(info.start, info.end,
                new DefaultHighlighter.DefaultHighlightPainter(c));
        if (info.pos != -1) {
            Color c2 = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int)(.4f * 255)); // 40%
            h.addHighlight(info.pos, info.pos + 1,
                new DefaultHighlighter.DefaultHighlightPainter(c2));
        }
    } catch (BadLocationException e) {
        e.printStackTrace();
    }
}
 
源代码21 项目: hottub   文件: CheckAttributedTree.java
/** Add a highlighted region based on the positions in an Info object. */
private void addHighlight(Highlighter h, Info info, Color c) {
    int start = info.start;
    int end = info.end;
    if (start == -1 && end == -1)
        return;
    if (start == -1)
        start = end;
    if (end == -1)
        end = start;
    try {
        h.addHighlight(info.start, info.end,
                new DefaultHighlighter.DefaultHighlightPainter(c));
        if (info.pos != -1) {
            Color c2 = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int)(.4f * 255)); // 40%
            h.addHighlight(info.pos, info.pos + 1,
                new DefaultHighlighter.DefaultHighlightPainter(c2));
        }
    } catch (BadLocationException e) {
        e.printStackTrace();
    }
}
 
源代码22 项目: hottub   文件: SwingUtilities2.java
/**
 * 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;
}
 
源代码23 项目: openjdk-8-source   文件: TreePosTest.java
/** Add a highlighted region based on the positions in an Info object. */
private void addHighlight(Highlighter h, Info info, Color c) {
    int start = info.start;
    int end = info.end;
    if (start == -1 && end == -1)
        return;
    if (start == -1)
        start = end;
    if (end == -1)
        end = start;
    try {
        h.addHighlight(info.start, info.end,
                new DefaultHighlighter.DefaultHighlightPainter(c));
        if (info.pos != -1) {
            Color c2 = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int)(.4f * 255)); // 40%
            h.addHighlight(info.pos, info.pos + 1,
                new DefaultHighlighter.DefaultHighlightPainter(c2));
        }
    } catch (BadLocationException e) {
        e.printStackTrace();
    }
}
 
源代码24 项目: openjdk-8-source   文件: CheckAttributedTree.java
/** Add a highlighted region based on the positions in an Info object. */
private void addHighlight(Highlighter h, Info info, Color c) {
    int start = info.start;
    int end = info.end;
    if (start == -1 && end == -1)
        return;
    if (start == -1)
        start = end;
    if (end == -1)
        end = start;
    try {
        h.addHighlight(info.start, info.end,
                new DefaultHighlighter.DefaultHighlightPainter(c));
        if (info.pos != -1) {
            Color c2 = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int)(.4f * 255)); // 40%
            h.addHighlight(info.pos, info.pos + 1,
                new DefaultHighlighter.DefaultHighlightPainter(c2));
        }
    } catch (BadLocationException e) {
        e.printStackTrace();
    }
}
 
源代码25 项目: openjdk-8-source   文件: SwingUtilities2.java
/**
 * 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;
}
 
源代码26 项目: workcraft   文件: GuiUtils.java
private static Object highlightText(JTextComponent textComponent, int fromPos, int toPos, Color color,
        boolean drawsLayeredHighlights) {

    if ((color != null) && (textComponent != null) && (toPos > fromPos)) {
        DefaultHighlighter highlighter = (DefaultHighlighter) textComponent.getHighlighter();
        highlighter.setDrawsLayeredHighlights(drawsLayeredHighlights);
        Highlighter.HighlightPainter painter = new DefaultHighlighter.DefaultHighlightPainter(color);
        try {
            return highlighter.addHighlight(
                    Math.max(fromPos, 0),
                    Math.min(toPos, textComponent.getText().length()),
                    painter);
        } catch (BadLocationException e) {
        }
    }
    return null;
}
 
源代码27 项目: openjdk-8   文件: TreePosTest.java
/** Add a highlighted region based on the positions in an Info object. */
private void addHighlight(Highlighter h, Info info, Color c) {
    int start = info.start;
    int end = info.end;
    if (start == -1 && end == -1)
        return;
    if (start == -1)
        start = end;
    if (end == -1)
        end = start;
    try {
        h.addHighlight(info.start, info.end,
                new DefaultHighlighter.DefaultHighlightPainter(c));
        if (info.pos != -1) {
            Color c2 = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int)(.4f * 255)); // 40%
            h.addHighlight(info.pos, info.pos + 1,
                new DefaultHighlighter.DefaultHighlightPainter(c2));
        }
    } catch (BadLocationException e) {
        e.printStackTrace();
    }
}
 
源代码28 项目: openjdk-8   文件: CheckAttributedTree.java
/** Add a highlighted region based on the positions in an Info object. */
private void addHighlight(Highlighter h, Info info, Color c) {
    int start = info.start;
    int end = info.end;
    if (start == -1 && end == -1)
        return;
    if (start == -1)
        start = end;
    if (end == -1)
        end = start;
    try {
        h.addHighlight(info.start, info.end,
                new DefaultHighlighter.DefaultHighlightPainter(c));
        if (info.pos != -1) {
            Color c2 = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int)(.4f * 255)); // 40%
            h.addHighlight(info.pos, info.pos + 1,
                new DefaultHighlighter.DefaultHighlightPainter(c2));
        }
    } catch (BadLocationException e) {
        e.printStackTrace();
    }
}
 
源代码29 项目: openjdk-8   文件: SwingUtilities2.java
/**
 * 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;
}
 
源代码30 项目: BowlerStudio   文件: LocalFileScriptTab.java
public void setHighlight(int lineNumber, Color color) throws BadLocationException {
	if (textArea == null) {
		return;
	}
	painter = new DefaultHighlighter.DefaultHighlightPainter(color);
	int startIndex = textArea.getLineStartOffset(lineNumber - 1);
	int endIndex = textArea.getLineEndOffset(lineNumber - 1);

	try {

		SwingUtilities.invokeLater(() -> {
			textArea.moveCaretPosition(startIndex);
		});
	} catch (Error | Exception ex) {
		ex.printStackTrace();
	}
	SwingUtilities.invokeLater(() -> {
		try {
			textArea.getHighlighter().addHighlight(startIndex, endIndex, painter);
		} catch (BadLocationException e) {
			ISSUE_REPORTING_EXCEPTION_HANDLER.uncaughtException(Thread.currentThread(), e);

		}
	});

}
 
 类所在包
 同包方法