Java Code Examples for javax.swing.plaf.TextUI#modelToView()
The following examples show how to use
javax.swing.plaf.TextUI#modelToView() .
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: DiffSidebar.java From netbeans with Apache License 2.0 | 5 votes |
private int getPosFromY(JTextComponent component, TextUI textUI, int y) throws BadLocationException { if(textUI instanceof BaseTextUI) { return ((BaseTextUI) textUI).getPosFromY(y); } else { // fallback to ( less otimized than ((BaseTextUI) textUI).getPosFromY(y) ) return textUI.modelToView(component, textUI.viewToModel(component, new Point(0, y))).y; } }
Example 2
Source File: HTMLEditorKit.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * Returns a string anchor if the passed in element has a * USEMAP that contains the passed in location. */ private String getMapHREF(JEditorPane html, HTMLDocument hdoc, Element elem, AttributeSet attr, int offset, int x, int y) { Object useMap = attr.getAttribute(HTML.Attribute.USEMAP); if (useMap != null && (useMap instanceof String)) { Map m = hdoc.getMap((String)useMap); if (m != null && offset < hdoc.getLength()) { Rectangle bounds; TextUI ui = html.getUI(); try { Shape lBounds = ui.modelToView(html, offset, Position.Bias.Forward); Shape rBounds = ui.modelToView(html, offset + 1, Position.Bias.Backward); bounds = lBounds.getBounds(); bounds.add((rBounds instanceof Rectangle) ? (Rectangle)rBounds : rBounds.getBounds()); } catch (BadLocationException ble) { bounds = null; } if (bounds != null) { AttributeSet area = m.getArea(x - bounds.x, y - bounds.y, bounds.width, bounds.height); if (area != null) { return (String)area.getAttribute(HTML.Attribute. HREF); } } } } return null; }
Example 3
Source File: HTMLEditorKit.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * Returns a string anchor if the passed in element has a * USEMAP that contains the passed in location. */ private String getMapHREF(JEditorPane html, HTMLDocument hdoc, Element elem, AttributeSet attr, int offset, int x, int y) { Object useMap = attr.getAttribute(HTML.Attribute.USEMAP); if (useMap != null && (useMap instanceof String)) { Map m = hdoc.getMap((String)useMap); if (m != null && offset < hdoc.getLength()) { Rectangle bounds; TextUI ui = html.getUI(); try { Shape lBounds = ui.modelToView(html, offset, Position.Bias.Forward); Shape rBounds = ui.modelToView(html, offset + 1, Position.Bias.Backward); bounds = lBounds.getBounds(); bounds.add((rBounds instanceof Rectangle) ? (Rectangle)rBounds : rBounds.getBounds()); } catch (BadLocationException ble) { bounds = null; } if (bounds != null) { AttributeSet area = m.getArea(x - bounds.x, y - bounds.y, bounds.width, bounds.height); if (area != null) { return (String)area.getAttribute(HTML.Attribute. HREF); } } } } return null; }
Example 4
Source File: HTMLEditorKit.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
/** * Returns true if the View representing <code>e</code> contains * the location <code>x</code>, <code>y</code>. <code>offset</code> * gives the offset into the Document to check for. */ private boolean doesElementContainLocation(JEditorPane editor, Element e, int offset, int x, int y) { if (e != null && offset > 0 && e.getStartOffset() == offset) { try { TextUI ui = editor.getUI(); Shape s1 = ui.modelToView(editor, offset, Position.Bias.Forward); if (s1 == null) { return false; } Rectangle r1 = (s1 instanceof Rectangle) ? (Rectangle)s1 : s1.getBounds(); Shape s2 = ui.modelToView(editor, e.getEndOffset(), Position.Bias.Backward); if (s2 != null) { Rectangle r2 = (s2 instanceof Rectangle) ? (Rectangle)s2 : s2.getBounds(); r1.add(r2); } return r1.contains(x, y); } catch (BadLocationException ble) { } } return true; }
Example 5
Source File: HTMLEditorKit.java From Bytecoder with Apache License 2.0 | 5 votes |
/** * Returns true if the View representing <code>e</code> contains * the location <code>x</code>, <code>y</code>. <code>offset</code> * gives the offset into the Document to check for. */ @SuppressWarnings("deprecation") private boolean doesElementContainLocation(JEditorPane editor, Element e, int offset, int x, int y) { if (e != null && offset > 0 && e.getStartOffset() == offset) { try { TextUI ui = editor.getUI(); Shape s1 = ui.modelToView(editor, offset, Position.Bias.Forward); if (s1 == null) { return false; } Rectangle r1 = (s1 instanceof Rectangle) ? (Rectangle)s1 : s1.getBounds(); Shape s2 = ui.modelToView(editor, e.getEndOffset(), Position.Bias.Backward); if (s2 != null) { Rectangle r2 = (s2 instanceof Rectangle) ? (Rectangle)s2 : s2.getBounds(); r1.add(r2); } return r1.contains(x, y); } catch (BadLocationException ble) { } } return true; }
Example 6
Source File: HTMLEditorKit.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** * Returns true if the View representing <code>e</code> contains * the location <code>x</code>, <code>y</code>. <code>offset</code> * gives the offset into the Document to check for. */ private boolean doesElementContainLocation(JEditorPane editor, Element e, int offset, int x, int y) { if (e != null && offset > 0 && e.getStartOffset() == offset) { try { TextUI ui = editor.getUI(); Shape s1 = ui.modelToView(editor, offset, Position.Bias.Forward); if (s1 == null) { return false; } Rectangle r1 = (s1 instanceof Rectangle) ? (Rectangle)s1 : s1.getBounds(); Shape s2 = ui.modelToView(editor, e.getEndOffset(), Position.Bias.Backward); if (s2 != null) { Rectangle r2 = (s2 instanceof Rectangle) ? (Rectangle)s2 : s2.getBounds(); r1.add(r2); } return r1.contains(x, y); } catch (BadLocationException ble) { } } return true; }
Example 7
Source File: HTMLEditorKit.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Returns true if the View representing <code>e</code> contains * the location <code>x</code>, <code>y</code>. <code>offset</code> * gives the offset into the Document to check for. */ private boolean doesElementContainLocation(JEditorPane editor, Element e, int offset, int x, int y) { if (e != null && offset > 0 && e.getStartOffset() == offset) { try { TextUI ui = editor.getUI(); Shape s1 = ui.modelToView(editor, offset, Position.Bias.Forward); if (s1 == null) { return false; } Rectangle r1 = (s1 instanceof Rectangle) ? (Rectangle)s1 : s1.getBounds(); Shape s2 = ui.modelToView(editor, e.getEndOffset(), Position.Bias.Backward); if (s2 != null) { Rectangle r2 = (s2 instanceof Rectangle) ? (Rectangle)s2 : s2.getBounds(); r1.add(r2); } return r1.contains(x, y); } catch (BadLocationException ble) { } } return true; }
Example 8
Source File: HTMLEditorKit.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
/** * Returns a string anchor if the passed in element has a * USEMAP that contains the passed in location. */ private String getMapHREF(JEditorPane html, HTMLDocument hdoc, Element elem, AttributeSet attr, int offset, int x, int y) { Object useMap = attr.getAttribute(HTML.Attribute.USEMAP); if (useMap != null && (useMap instanceof String)) { Map m = hdoc.getMap((String)useMap); if (m != null && offset < hdoc.getLength()) { Rectangle bounds; TextUI ui = html.getUI(); try { Shape lBounds = ui.modelToView(html, offset, Position.Bias.Forward); Shape rBounds = ui.modelToView(html, offset + 1, Position.Bias.Backward); bounds = lBounds.getBounds(); bounds.add((rBounds instanceof Rectangle) ? (Rectangle)rBounds : rBounds.getBounds()); } catch (BadLocationException ble) { bounds = null; } if (bounds != null) { AttributeSet area = m.getArea(x - bounds.x, y - bounds.y, bounds.width, bounds.height); if (area != null) { return (String)area.getAttribute(HTML.Attribute. HREF); } } } } return null; }
Example 9
Source File: HTMLEditorKit.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * Returns a string anchor if the passed in element has a * USEMAP that contains the passed in location. */ private String getMapHREF(JEditorPane html, HTMLDocument hdoc, Element elem, AttributeSet attr, int offset, int x, int y) { Object useMap = attr.getAttribute(HTML.Attribute.USEMAP); if (useMap != null && (useMap instanceof String)) { Map m = hdoc.getMap((String)useMap); if (m != null && offset < hdoc.getLength()) { Rectangle bounds; TextUI ui = html.getUI(); try { Shape lBounds = ui.modelToView(html, offset, Position.Bias.Forward); Shape rBounds = ui.modelToView(html, offset + 1, Position.Bias.Backward); bounds = lBounds.getBounds(); bounds.add((rBounds instanceof Rectangle) ? (Rectangle)rBounds : rBounds.getBounds()); } catch (BadLocationException ble) { bounds = null; } if (bounds != null) { AttributeSet area = m.getArea(x - bounds.x, y - bounds.y, bounds.width, bounds.height); if (area != null) { return (String)area.getAttribute(HTML.Attribute. HREF); } } } } return null; }
Example 10
Source File: SnippetHighlighter.java From beautyeye with Apache License 2.0 | 5 votes |
/** * Paints a highlight. * * @param g the graphics context * @param offs0 the starting model offset >= 0 * @param offs1 the ending model offset >= offs1 * @param bounds the bounding box for the highlight * @param c the editor */ public void paint(Graphics g, int offs0, int offs1, Shape bounds, JTextComponent c) { Rectangle alloc = bounds.getBounds(); try { // --- determine locations --- TextUI mapper = c.getUI(); Rectangle p0 = mapper.modelToView(c, offs0); Rectangle p1 = mapper.modelToView(c, offs1); // --- render --- Color color = getColor(); if (color == null) { g.setColor(c.getSelectionColor()); } else { g.setColor(color); } if (p0.y == p1.y) { // same line, render a rectangle Rectangle r = p0.union(p1); g.fillRect(r.x, r.y, r.width, r.height); } else { // different lines int p0ToMarginWidth = alloc.x + alloc.width - p0.x; g.fillRect(p0.x, p0.y, p0ToMarginWidth, p0.height); if ((p0.y + p0.height) != p1.y) { g.fillRect(alloc.x, p0.y + p0.height, alloc.width, p1.y - (p0.y + p0.height)); } g.fillRect(alloc.x, p1.y, (p1.x - alloc.x), p1.height); } } catch (BadLocationException e) { // can't render } }
Example 11
Source File: HTMLEditorKit.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** * Returns a string anchor if the passed in element has a * USEMAP that contains the passed in location. */ private String getMapHREF(JEditorPane html, HTMLDocument hdoc, Element elem, AttributeSet attr, int offset, int x, int y) { Object useMap = attr.getAttribute(HTML.Attribute.USEMAP); if (useMap != null && (useMap instanceof String)) { Map m = hdoc.getMap((String)useMap); if (m != null && offset < hdoc.getLength()) { Rectangle bounds; TextUI ui = html.getUI(); try { Shape lBounds = ui.modelToView(html, offset, Position.Bias.Forward); Shape rBounds = ui.modelToView(html, offset + 1, Position.Bias.Backward); bounds = lBounds.getBounds(); bounds.add((rBounds instanceof Rectangle) ? (Rectangle)rBounds : rBounds.getBounds()); } catch (BadLocationException ble) { bounds = null; } if (bounds != null) { AttributeSet area = m.getArea(x - bounds.x, y - bounds.y, bounds.width, bounds.height); if (area != null) { return (String)area.getAttribute(HTML.Attribute. HREF); } } } } return null; }
Example 12
Source File: HTMLEditorKit.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Returns a string anchor if the passed in element has a * USEMAP that contains the passed in location. */ @SuppressWarnings("deprecation") private String getMapHREF(JEditorPane html, HTMLDocument hdoc, Element elem, AttributeSet attr, int offset, int x, int y) { Object useMap = attr.getAttribute(HTML.Attribute.USEMAP); if (useMap != null && (useMap instanceof String)) { Map m = hdoc.getMap((String)useMap); if (m != null && offset < hdoc.getLength()) { Rectangle bounds; TextUI ui = html.getUI(); try { Shape lBounds = ui.modelToView(html, offset, Position.Bias.Forward); Shape rBounds = ui.modelToView(html, offset + 1, Position.Bias.Backward); bounds = lBounds.getBounds(); bounds.add((rBounds instanceof Rectangle) ? (Rectangle)rBounds : rBounds.getBounds()); } catch (BadLocationException ble) { bounds = null; } if (bounds != null) { AttributeSet area = m.getArea(x - bounds.x, y - bounds.y, bounds.width, bounds.height); if (area != null) { return (String)area.getAttribute(HTML.Attribute. HREF); } } } } return null; }
Example 13
Source File: HTMLEditorKit.java From JDKSourceCode1.8 with MIT License | 5 votes |
/** * Returns true if the View representing <code>e</code> contains * the location <code>x</code>, <code>y</code>. <code>offset</code> * gives the offset into the Document to check for. */ private boolean doesElementContainLocation(JEditorPane editor, Element e, int offset, int x, int y) { if (e != null && offset > 0 && e.getStartOffset() == offset) { try { TextUI ui = editor.getUI(); Shape s1 = ui.modelToView(editor, offset, Position.Bias.Forward); if (s1 == null) { return false; } Rectangle r1 = (s1 instanceof Rectangle) ? (Rectangle)s1 : s1.getBounds(); Shape s2 = ui.modelToView(editor, e.getEndOffset(), Position.Bias.Backward); if (s2 != null) { Rectangle r2 = (s2 instanceof Rectangle) ? (Rectangle)s2 : s2.getBounds(); r1.add(r2); } return r1.contains(x, y); } catch (BadLocationException ble) { } } return true; }
Example 14
Source File: HTMLEditorKit.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
/** * Returns a string anchor if the passed in element has a * USEMAP that contains the passed in location. */ private String getMapHREF(JEditorPane html, HTMLDocument hdoc, Element elem, AttributeSet attr, int offset, int x, int y) { Object useMap = attr.getAttribute(HTML.Attribute.USEMAP); if (useMap != null && (useMap instanceof String)) { Map m = hdoc.getMap((String)useMap); if (m != null && offset < hdoc.getLength()) { Rectangle bounds; TextUI ui = html.getUI(); try { Shape lBounds = ui.modelToView(html, offset, Position.Bias.Forward); Shape rBounds = ui.modelToView(html, offset + 1, Position.Bias.Backward); bounds = lBounds.getBounds(); bounds.add((rBounds instanceof Rectangle) ? (Rectangle)rBounds : rBounds.getBounds()); } catch (BadLocationException ble) { bounds = null; } if (bounds != null) { AttributeSet area = m.getArea(x - bounds.x, y - bounds.y, bounds.width, bounds.height); if (area != null) { return (String)area.getAttribute(HTML.Attribute. HREF); } } } } return null; }
Example 15
Source File: WindowsTextUI.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
/** * Paints a highlight. * * @param g the graphics context * @param offs0 the starting model offset >= 0 * @param offs1 the ending model offset >= offs1 * @param bounds the bounding box for the highlight * @param c the editor */ public void paint(Graphics g, int offs0, int offs1, Shape bounds, JTextComponent c) { Rectangle alloc = bounds.getBounds(); try { // --- determine locations --- TextUI mapper = c.getUI(); Rectangle p0 = mapper.modelToView(c, offs0); Rectangle p1 = mapper.modelToView(c, offs1); // --- render --- Color color = getColor(); if (color == null) { g.setColor(c.getSelectionColor()); } else { g.setColor(color); } boolean firstIsDot = false; boolean secondIsDot = false; if (c.isEditable()) { int dot = c.getCaretPosition(); firstIsDot = (offs0 == dot); secondIsDot = (offs1 == dot); } if (p0.y == p1.y) { // same line, render a rectangle Rectangle r = p0.union(p1); if (r.width > 0) { if (firstIsDot) { r.x++; r.width--; } else if (secondIsDot) { r.width--; } } g.fillRect(r.x, r.y, r.width, r.height); } else { // different lines int p0ToMarginWidth = alloc.x + alloc.width - p0.x; if (firstIsDot && p0ToMarginWidth > 0) { p0.x++; p0ToMarginWidth--; } g.fillRect(p0.x, p0.y, p0ToMarginWidth, p0.height); if ((p0.y + p0.height) != p1.y) { g.fillRect(alloc.x, p0.y + p0.height, alloc.width, p1.y - (p0.y + p0.height)); } if (secondIsDot && p1.x > alloc.x) { p1.x--; } g.fillRect(alloc.x, p1.y, (p1.x - alloc.x), p1.height); } } catch (BadLocationException e) { // can't render } }
Example 16
Source File: WindowsTextUI.java From jdk1.8-source-analysis with Apache License 2.0 | 4 votes |
/** * Paints a highlight. * * @param g the graphics context * @param offs0 the starting model offset >= 0 * @param offs1 the ending model offset >= offs1 * @param bounds the bounding box for the highlight * @param c the editor */ public void paint(Graphics g, int offs0, int offs1, Shape bounds, JTextComponent c) { Rectangle alloc = bounds.getBounds(); try { // --- determine locations --- TextUI mapper = c.getUI(); Rectangle p0 = mapper.modelToView(c, offs0); Rectangle p1 = mapper.modelToView(c, offs1); // --- render --- Color color = getColor(); if (color == null) { g.setColor(c.getSelectionColor()); } else { g.setColor(color); } boolean firstIsDot = false; boolean secondIsDot = false; if (c.isEditable()) { int dot = c.getCaretPosition(); firstIsDot = (offs0 == dot); secondIsDot = (offs1 == dot); } if (p0.y == p1.y) { // same line, render a rectangle Rectangle r = p0.union(p1); if (r.width > 0) { if (firstIsDot) { r.x++; r.width--; } else if (secondIsDot) { r.width--; } } g.fillRect(r.x, r.y, r.width, r.height); } else { // different lines int p0ToMarginWidth = alloc.x + alloc.width - p0.x; if (firstIsDot && p0ToMarginWidth > 0) { p0.x++; p0ToMarginWidth--; } g.fillRect(p0.x, p0.y, p0ToMarginWidth, p0.height); if ((p0.y + p0.height) != p1.y) { g.fillRect(alloc.x, p0.y + p0.height, alloc.width, p1.y - (p0.y + p0.height)); } if (secondIsDot && p1.x > alloc.x) { p1.x--; } g.fillRect(alloc.x, p1.y, (p1.x - alloc.x), p1.height); } } catch (BadLocationException e) { // can't render } }
Example 17
Source File: WindowsTextUI.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
/** * Paints a highlight. * * @param g the graphics context * @param offs0 the starting model offset >= 0 * @param offs1 the ending model offset >= offs1 * @param bounds the bounding box for the highlight * @param c the editor */ public void paint(Graphics g, int offs0, int offs1, Shape bounds, JTextComponent c) { Rectangle alloc = bounds.getBounds(); try { // --- determine locations --- TextUI mapper = c.getUI(); Rectangle p0 = mapper.modelToView(c, offs0); Rectangle p1 = mapper.modelToView(c, offs1); // --- render --- Color color = getColor(); if (color == null) { g.setColor(c.getSelectionColor()); } else { g.setColor(color); } boolean firstIsDot = false; boolean secondIsDot = false; if (c.isEditable()) { int dot = c.getCaretPosition(); firstIsDot = (offs0 == dot); secondIsDot = (offs1 == dot); } if (p0.y == p1.y) { // same line, render a rectangle Rectangle r = p0.union(p1); if (r.width > 0) { if (firstIsDot) { r.x++; r.width--; } else if (secondIsDot) { r.width--; } } g.fillRect(r.x, r.y, r.width, r.height); } else { // different lines int p0ToMarginWidth = alloc.x + alloc.width - p0.x; if (firstIsDot && p0ToMarginWidth > 0) { p0.x++; p0ToMarginWidth--; } g.fillRect(p0.x, p0.y, p0ToMarginWidth, p0.height); if ((p0.y + p0.height) != p1.y) { g.fillRect(alloc.x, p0.y + p0.height, alloc.width, p1.y - (p0.y + p0.height)); } if (secondIsDot && p1.x > alloc.x) { p1.x--; } g.fillRect(alloc.x, p1.y, (p1.x - alloc.x), p1.height); } } catch (BadLocationException e) { // can't render } }
Example 18
Source File: WindowsTextUI.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** * Paints a highlight. * * @param g the graphics context * @param offs0 the starting model offset >= 0 * @param offs1 the ending model offset >= offs1 * @param bounds the bounding box for the highlight * @param c the editor */ public void paint(Graphics g, int offs0, int offs1, Shape bounds, JTextComponent c) { Rectangle alloc = bounds.getBounds(); try { // --- determine locations --- TextUI mapper = c.getUI(); Rectangle p0 = mapper.modelToView(c, offs0); Rectangle p1 = mapper.modelToView(c, offs1); // --- render --- Color color = getColor(); if (color == null) { g.setColor(c.getSelectionColor()); } else { g.setColor(color); } boolean firstIsDot = false; boolean secondIsDot = false; if (c.isEditable()) { int dot = c.getCaretPosition(); firstIsDot = (offs0 == dot); secondIsDot = (offs1 == dot); } if (p0.y == p1.y) { // same line, render a rectangle Rectangle r = p0.union(p1); if (r.width > 0) { if (firstIsDot) { r.x++; r.width--; } else if (secondIsDot) { r.width--; } } g.fillRect(r.x, r.y, r.width, r.height); } else { // different lines int p0ToMarginWidth = alloc.x + alloc.width - p0.x; if (firstIsDot && p0ToMarginWidth > 0) { p0.x++; p0ToMarginWidth--; } g.fillRect(p0.x, p0.y, p0ToMarginWidth, p0.height); if ((p0.y + p0.height) != p1.y) { g.fillRect(alloc.x, p0.y + p0.height, alloc.width, p1.y - (p0.y + p0.height)); } if (secondIsDot && p1.x > alloc.x) { p1.x--; } g.fillRect(alloc.x, p1.y, (p1.x - alloc.x), p1.height); } } catch (BadLocationException e) { // can't render } }
Example 19
Source File: WindowsTextUI.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
/** * Paints a highlight. * * @param g the graphics context * @param offs0 the starting model offset >= 0 * @param offs1 the ending model offset >= offs1 * @param bounds the bounding box for the highlight * @param c the editor */ public void paint(Graphics g, int offs0, int offs1, Shape bounds, JTextComponent c) { Rectangle alloc = bounds.getBounds(); try { // --- determine locations --- TextUI mapper = c.getUI(); Rectangle p0 = mapper.modelToView(c, offs0); Rectangle p1 = mapper.modelToView(c, offs1); // --- render --- Color color = getColor(); if (color == null) { g.setColor(c.getSelectionColor()); } else { g.setColor(color); } boolean firstIsDot = false; boolean secondIsDot = false; if (c.isEditable()) { int dot = c.getCaretPosition(); firstIsDot = (offs0 == dot); secondIsDot = (offs1 == dot); } if (p0.y == p1.y) { // same line, render a rectangle Rectangle r = p0.union(p1); if (r.width > 0) { if (firstIsDot) { r.x++; r.width--; } else if (secondIsDot) { r.width--; } } g.fillRect(r.x, r.y, r.width, r.height); } else { // different lines int p0ToMarginWidth = alloc.x + alloc.width - p0.x; if (firstIsDot && p0ToMarginWidth > 0) { p0.x++; p0ToMarginWidth--; } g.fillRect(p0.x, p0.y, p0ToMarginWidth, p0.height); if ((p0.y + p0.height) != p1.y) { g.fillRect(alloc.x, p0.y + p0.height, alloc.width, p1.y - (p0.y + p0.height)); } if (secondIsDot && p1.x > alloc.x) { p1.x--; } g.fillRect(alloc.x, p1.y, (p1.x - alloc.x), p1.height); } } catch (BadLocationException e) { // can't render } }
Example 20
Source File: WindowsTextUI.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
/** * Paints a highlight. * * @param g the graphics context * @param offs0 the starting model offset >= 0 * @param offs1 the ending model offset >= offs1 * @param bounds the bounding box for the highlight * @param c the editor */ public void paint(Graphics g, int offs0, int offs1, Shape bounds, JTextComponent c) { Rectangle alloc = bounds.getBounds(); try { // --- determine locations --- TextUI mapper = c.getUI(); Rectangle p0 = mapper.modelToView(c, offs0); Rectangle p1 = mapper.modelToView(c, offs1); // --- render --- Color color = getColor(); if (color == null) { g.setColor(c.getSelectionColor()); } else { g.setColor(color); } boolean firstIsDot = false; boolean secondIsDot = false; if (c.isEditable()) { int dot = c.getCaretPosition(); firstIsDot = (offs0 == dot); secondIsDot = (offs1 == dot); } if (p0.y == p1.y) { // same line, render a rectangle Rectangle r = p0.union(p1); if (r.width > 0) { if (firstIsDot) { r.x++; r.width--; } else if (secondIsDot) { r.width--; } } g.fillRect(r.x, r.y, r.width, r.height); } else { // different lines int p0ToMarginWidth = alloc.x + alloc.width - p0.x; if (firstIsDot && p0ToMarginWidth > 0) { p0.x++; p0ToMarginWidth--; } g.fillRect(p0.x, p0.y, p0ToMarginWidth, p0.height); if ((p0.y + p0.height) != p1.y) { g.fillRect(alloc.x, p0.y + p0.height, alloc.width, p1.y - (p0.y + p0.height)); } if (secondIsDot && p1.x > alloc.x) { p1.x--; } g.fillRect(alloc.x, p1.y, (p1.x - alloc.x), p1.height); } } catch (BadLocationException e) { // can't render } }