本文整理匯總了Java中javax.swing.plaf.TextUI.modelToView方法的典型用法代碼示例。如果您正苦於以下問題:Java TextUI.modelToView方法的具體用法?Java TextUI.modelToView怎麽用?Java TextUI.modelToView使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.plaf.TextUI
的用法示例。
在下文中一共展示了TextUI.modelToView方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: computeBounds
import javax.swing.plaf.TextUI; //導入方法依賴的package包/類
public void computeBounds(JTextPane textPane, BoundsTranslator translator) {
Rectangle tpBounds = textPane.getBounds();
TextUI tui = textPane.getUI();
this.bounds = new Rectangle[length];
for (int i = 0; i < length; i++) {
try {
Rectangle startr = tui.modelToView(textPane, docstart[i], Position.Bias.Forward);
Rectangle endr = tui.modelToView(textPane, docend[i], Position.Bias.Backward);
if (startr == null || endr == null) {
continue;
}
startr = startr.getBounds();
endr = endr.getBounds();
this.bounds[i] = new Rectangle(tpBounds.x + startr.x, startr.y, endr.x - startr.x, startr.height);
//NOTE the textPane is positioned within a parent panel so the origin has to be modified too
if (null != translator) {
translator.correctTranslation(textPane, this.bounds[i]);
}
} catch (BadLocationException ex) { }
}
}
示例2: getCloserDifference
import javax.swing.plaf.TextUI; //導入方法依賴的package包/類
/**
* In case of two neighboring DELETE differences which meet on the same line, this method returns a difference
* which' annotation is closer (in y-axis) to the click-point
* @param event event with the click-point
* @param previous a difference reaching out from the previous line
* @param next a difference reaching out from the next line
* @return
*/
private Difference getCloserDifference(MouseEvent event, Difference previous, Difference next) {
Difference returnedDiff = next;
JTextComponent component = textComponent;
if (component != null) {
TextUI textUI = component.getUI();
try {
Rectangle rec = textUI.modelToView(component, textUI.viewToModel(component, new Point(0, event.getY())));
if (rec != null && event.getY() < rec.getY() + rec.getHeight() / 2) {
// previous difference is closer to the click
returnedDiff = previous;
}
} catch (BadLocationException ex) {
// not interested, default next is returned
}
}
return returnedDiff;
}
示例3: paint
import javax.swing.plaf.TextUI; //導入方法依賴的package包/類
@Override
public void paint(Graphics g, int offs0, int offs1, Shape bounds, JTextComponent c) {
try {
TextUI mapper = c.getUI();
Rectangle p0 = mapper.modelToView(c, offs0);
Rectangle p1 = mapper.modelToView(c, offs1);
Color color = getColor();
if (color == null)
g.setColor(c.getSelectionColor());
else
g.setColor(color);
if (sameLine(p0, p1)) {
Rectangle r = p0.union(p1);
underline(g, r);
}
} catch (BadLocationException e) {
}
}
示例4: paint
import javax.swing.plaf.TextUI; //導入方法依賴的package包/類
@Override
public void paint(Graphics g, int offs0, int offs1, Shape bounds, JTextComponent c) {
try {
// --- determine locations ---
TextUI mapper = c.getUI();
Color col = getColor();
if (col == null) {
col = Color.black;
}
g.setColor(col);
for (int i = offs0; i < offs1; i++) {
Rectangle r = mapper.modelToView(c, i, Position.Bias.Forward);
Rectangle r1 = mapper.modelToView(c, i + 1, Position.Bias.Forward);
if (r1.y == r.y) {
g.drawLine(r.x, r.y + r.height - 3, r1.x, r.y + r.height - 3);
}
}
} catch (BadLocationException e) {
// can't render
}
}
示例5: init
import javax.swing.plaf.TextUI; //導入方法依賴的package包/類
public void init() {
try {
r1 = jta.modelToView(6);
r2 = jta.modelToView(10);
r3 = jta.modelToView(15);
r4 = jta.modelToView(2);
TextUI textUI = jta.getUI();
r5 = textUI.modelToView(jta, 5, Position.Bias.Backward);
r6 = textUI.modelToView(jta, 7, Position.Bias.Forward);
assertNotNull(r1);
assertNotNull(r2);
assertNotNull(r3);
assertNotNull(r4);
} catch (BadLocationException e) {
bWasException = true;
s = e.getMessage();
}
assertFalse("Unexpected exception " + s, bWasException);
}
示例6: modelToView
import javax.swing.plaf.TextUI; //導入方法依賴的package包/類
public Shape modelToView(DocumentView docView, int offset, Position.Bias bias) {
if (docView != null) {
return docView.modelToViewNeedsLock(offset, docView.getAllocation(), bias);
} else {
TextUI ui = textComponent.getUI();
try {
return (ui != null) ? ui.modelToView(textComponent, offset, bias) : null;
} catch (BadLocationException ex) {
return null;
}
}
}
示例7: getPosFromY
import javax.swing.plaf.TextUI; //導入方法依賴的package包/類
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;
}
}
示例8: paint
import javax.swing.plaf.TextUI; //導入方法依賴的package包/類
@Override
public void paint(Graphics g) {
JTextComponent component = textView;
if(isVisible() && y >= 0) {
try {
TextUI mapper = component.getUI();
Rectangle r = mapper.modelToView(component, getDot(), Position.Bias.Forward);
if ((r == null) || ((r.width == 0) && (r.height == 0))) {
return;
}
if (width > 0 && height > 0 &&
!this._contains(r.x, r.y, r.width, r.height)) {
// We seem to have gotten out of sync and no longer
// contain the right location, adjust accordingly.
Rectangle clip = g.getClipBounds();
if (clip != null && !clip.contains(this)) {
// Clip doesn't contain the old location, force it
// to be repainted lest we leave a caret around.
repaint();
}
// System.err.println("WRONG! Caret dot m2v = " + r + " but my bounds are " + x + "," + y + "," + width + "," + height);
// This will potentially cause a repaint of something
// we're already repainting, but without changing the
// semantics of damage we can't really get around this.
damage(r);
}
g.setColor(component.getCaretColor());
g.drawLine(r.x, r.y, r.x, r.y + r.height - 1);
g.drawLine(r.x+1, r.y, r.x+1, r.y + r.height - 1);
} catch (BadLocationException e) {
// can't render I guess
// System.err.println("Can't render cursor");
}
}
}
示例9: getMapHREF
import javax.swing.plaf.TextUI; //導入方法依賴的package包/類
/**
* 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;
}
示例10: doesElementContainLocation
import javax.swing.plaf.TextUI; //導入方法依賴的package包/類
/**
* 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: paint
import javax.swing.plaf.TextUI; //導入方法依賴的package包/類
/**
* 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
}
}
示例12: getMapHREF
import javax.swing.plaf.TextUI; //導入方法依賴的package包/類
/**
* 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;
}
示例13: doesElementContainLocation
import javax.swing.plaf.TextUI; //導入方法依賴的package包/類
/**
* 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;
}
示例14: paint
import javax.swing.plaf.TextUI; //導入方法依賴的package包/類
/**
* 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
}
}
示例15: paint
import javax.swing.plaf.TextUI; //導入方法依賴的package包/類
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 ---
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
}
}