List of usage examples for javax.swing.text JTextComponent getSelectionColor
public Color getSelectionColor()
From source file:Main.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 */// w ww . ja va 2 s . co m 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; }
From source file:Main.java
@Override public Shape paintLayer(Graphics g, int offs0, int offs1, Shape bounds, JTextComponent c, View view) { g.setColor(color == null ? c.getSelectionColor() : color); Rectangle rect = null;// w ww . j av a2 s.c o m if (offs0 == view.getStartOffset() && offs1 == view.getEndOffset()) { if (bounds instanceof Rectangle) { rect = (Rectangle) bounds; } else { rect = bounds.getBounds(); } } else { try { Shape shape = view.modelToView(offs0, Position.Bias.Forward, offs1, Position.Bias.Backward, bounds); rect = (shape instanceof Rectangle) ? (Rectangle) shape : shape.getBounds(); } catch (BadLocationException e) { return null; } } FontMetrics fm = c.getFontMetrics(c.getFont()); int baseline = rect.y + rect.height - fm.getDescent() + 1; g.drawLine(rect.x, baseline, rect.x + rect.width, baseline); g.drawLine(rect.x, baseline + 1, rect.x + rect.width, baseline + 1); return rect; }
From source file:LineHighlightPainter.java
public void paint(Graphics g, int p0, int p1, Shape bounds, JTextComponent c) { Rectangle r0 = null, r1 = null, rbounds = bounds.getBounds(); int xmax = rbounds.x + rbounds.width; try {//from w w w . jav a 2 s . c o m r0 = c.modelToView(p0); r1 = c.modelToView(p1); } catch (BadLocationException ex) { return; } if ((r0 == null) || (r1 == null)) return; g.setColor(c.getSelectionColor()); // special case if p0 and p1 are on the same line if (r0.y == r1.y) { paintLine(g, r0, r1.x); return; } // first line, from p1 to end-of-line paintLine(g, r0, xmax); // all the full lines in between, if any (assumes that all lines have // the same height--not a good assumption with JEditorPane/JTextPane) r0.y += r0.height; // move r0 to next line r0.x = rbounds.x; // move r0 to left edge while (r0.y < r1.y) { paintLine(g, r0, xmax); r0.y += r0.height; // move r0 to next line } // last line, from beginning-of-line to p1 paintLine(g, r0, r1.x); }
From source file:LineHighlightPainter.java
public void paint(Graphics g, int p0, int p1, Shape bounds, JTextComponent c) { Rectangle r0 = null, r1 = null, rbounds = bounds.getBounds(); int xmax = rbounds.x + rbounds.width; // x coordinate of right edge try { // convert positions to pixel coordinates r0 = c.modelToView(p0);/*from w w w.ja v a2 s.c om*/ r1 = c.modelToView(p1); } catch (BadLocationException ex) { return; } if ((r0 == null) || (r1 == null)) return; g.setColor(c.getSelectionColor()); // special case if p0 and p1 are on the same line if (r0.y == r1.y) { paintLine(g, r0, r1.x); return; } // first line, from p1 to end-of-line paintLine(g, r0, xmax); // all the full lines in between, if any (assumes that all lines have // the same height--not a good assumption with JEditorPane/JTextPane) r0.y += r0.height; // move r0 to next line r0.x = rbounds.x; // move r0 to left edge while (r0.y < r1.y) { paintLine(g, r0, xmax); r0.y += r0.height; // move r0 to next line } // last line, from beginning-of-line to p1 paintLine(g, r0, r1.x); }
From source file:com.hexidec.ekit.component.RelativeImageView.java
/** Returns the text editor's highlight color. *//*from w w w . j a va 2s. c om*/ protected Color getHighlightColor() { JTextComponent textComp = (JTextComponent) fContainer; return textComp.getSelectionColor(); }
From source file:org.pmedv.core.components.RelativeImageView.java
/** * @return returns the text editor's highlight color. *///w ww .j a v a 2 s.co m protected Color getHighlightColor() { JTextComponent textComp = (JTextComponent) fContainer; return textComp.getSelectionColor(); }