javax.swing.plaf.TextUI#modelToView ( )源码实例Demo

下面列出了javax.swing.plaf.TextUI#modelToView ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: netbeans   文件: DiffSidebar.java
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;
    }
}
 
源代码2 项目: openjdk-8   文件: HTMLEditorKit.java
/**
 * 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;
}
 
源代码3 项目: hottub   文件: HTMLEditorKit.java
/**
 * 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;
}
 
源代码4 项目: dragonwell8_jdk   文件: HTMLEditorKit.java
/**
 * 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;
}
 
源代码5 项目: openjdk-8-source   文件: HTMLEditorKit.java
/**
 * 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;
}
 
源代码6 项目: TencentKona-8   文件: HTMLEditorKit.java
/**
 * 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;
}
 
源代码7 项目: beautyeye   文件: SnippetHighlighter.java
/**
        * 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
    }
}
 
源代码8 项目: openjdk-8-source   文件: HTMLEditorKit.java
/**
 * 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;
}
 
源代码9 项目: openjdk-jdk9   文件: HTMLEditorKit.java
/**
 * 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;
}
 
源代码10 项目: JDKSourceCode1.8   文件: HTMLEditorKit.java
/**
 * 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;
}
 
源代码11 项目: jdk8u-jdk   文件: HTMLEditorKit.java
/**
 * 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;
}
 
源代码12 项目: openjdk-jdk8u   文件: HTMLEditorKit.java
/**
 * 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;
}
 
源代码13 项目: jdk8u-jdk   文件: HTMLEditorKit.java
/**
 * 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;
}
 
源代码14 项目: Bytecoder   文件: HTMLEditorKit.java
/**
 * 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;
}
 
源代码15 项目: jdk1.8-source-analysis   文件: WindowsTextUI.java
/**
 * 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
    }
}
 
源代码16 项目: dragonwell8_jdk   文件: WindowsTextUI.java
/**
 * 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
    }
}
 
源代码17 项目: TencentKona-8   文件: WindowsTextUI.java
/**
 * 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
    }
}
 
源代码18 项目: jdk8u60   文件: WindowsTextUI.java
/**
 * 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
    }
}
 
源代码19 项目: jdk8u_jdk   文件: WindowsTextUI.java
/**
 * 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
    }
}
 
源代码20 项目: jdk8u-dev-jdk   文件: WindowsTextUI.java
/**
 * 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
    }
}