本文整理了Java中javax.swing.JTextPane.modelToView()
方法的一些代码示例,展示了JTextPane.modelToView()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JTextPane.modelToView()
方法的具体详情如下:
包路径:javax.swing.JTextPane
类名称:JTextPane
方法名:modelToView
暂无
代码示例来源:origin: chatty/chatty
Rectangle rect = text.modelToView(pos);
if (e.getX() < rect.x && e.getY() < rect.y + rect.height && pos > 0) {
pos--;
代码示例来源:origin: org.opentcs.thirdparty.jhotdraw/jhotdraw
/**
* Accessor for text area.
* This is used by Actions that need ot act on the text area of the View.
*/
public void select(int start, int end) {
editor.select(start, end);
try {
editor.scrollRectToVisible(editor.modelToView(start));
} catch (BadLocationException e) {
e.printStackTrace();
}
}
代码示例来源:origin: blurpy/kouchat
/**
* Shows the window if the text file was opened, and scrolls to the
* beginning of the text.
*
* {@inheritDoc}
*/
@Override
public void setVisible(final boolean visible) {
if (fileOpened) {
if (visible) {
try {
final Rectangle r = viewerTP.modelToView(0);
viewerScroll.getViewport().setViewPosition(new Point(r.x, r.y));
}
catch (final BadLocationException e) {
LOG.log(Level.SEVERE, e.toString());
}
}
super.setVisible(visible);
}
else {
errorHandler.showError(swingMessages.getMessage("swing.textViewerDialog.errorPopup.openFile", textFile));
}
}
代码示例来源:origin: protegeproject/protege
private void renderHyperlink(OWLEntity curEntity, int tokenStartIndex, int tokenLength, StyledDocument doc) {
try {
Rectangle startRect = textPane.modelToView(tokenStartIndex);
Rectangle endRect = textPane.modelToView(tokenStartIndex + tokenLength);
if (startRect != null && endRect != null) {
int width = endRect.x - startRect.x;
int heght = startRect.height;
Rectangle tokenRect = new Rectangle(startRect.x, startRect.y, width, heght);
tokenRect.grow(0, -2);
Point mouseCellLocation = linkedObjectComponent.getMouseCellLocation();
if (mouseCellLocation != null) {
mouseCellLocation = SwingUtilities.convertPoint(renderingComponent,
mouseCellLocation,
textPane);
if (tokenRect.contains(mouseCellLocation)) {
doc.setCharacterAttributes(tokenStartIndex, tokenLength, linkStyle, false);
linkedObjectComponent.setLinkedObject(curEntity);
linkRendered = true;
}
}
}
} catch (BadLocationException e) {
e.printStackTrace();
}
}
代码示例来源:origin: stackoverflow.com
static void updateMargin(JTextPane textPane) {
JViewport viewport = (JViewport)
SwingUtilities.getAncestorOfClass(JViewport.class, textPane);
if (viewport != null) {
Insets margin = textPane.getMargin();
int len = textPane.getDocument().getLength();
try {
Rectangle end = textPane.modelToView(len);
if (end != null) {
margin.bottom = viewport.getHeight() - end.height;
textPane.setMargin(margin);
}
} catch (BadLocationException e) {
throw new RuntimeException(e);
}
}
}
代码示例来源:origin: edu.stanford.protege/protege-editor-owl
private void renderHyperlink(OWLEntity curEntity, int tokenStartIndex, int tokenLength, StyledDocument doc) {
try {
Rectangle startRect = textPane.modelToView(tokenStartIndex);
Rectangle endRect = textPane.modelToView(tokenStartIndex + tokenLength);
if (startRect != null && endRect != null) {
int width = endRect.x - startRect.x;
int heght = startRect.height;
Rectangle tokenRect = new Rectangle(startRect.x, startRect.y, width, heght);
tokenRect.grow(0, -2);
if (linkedObjectComponent.getMouseCellLocation() != null) {
Point mouseCellLocation = linkedObjectComponent.getMouseCellLocation();
if (mouseCellLocation != null) {
mouseCellLocation = SwingUtilities.convertPoint(renderingComponent,
mouseCellLocation,
textPane);
if (tokenRect.contains(mouseCellLocation)) {
doc.setCharacterAttributes(tokenStartIndex, tokenLength, linkStyle, false);
linkedObjectComponent.setLinkedObject(curEntity);
linkRendered = true;
}
}
}
}
}
catch (BadLocationException e) {
e.printStackTrace();
}
}
代码示例来源:origin: stackoverflow.com
/**
* Return an int containing the wrapped line index at the given position
* @param component JTextPane
* @param int pos
* @return int
*/
public int getLineNumber(JTextPane component, int pos)
{
int posLine;
int y = 0;
try
{
Rectangle caretCoords = component.modelToView(pos);
y = (int) caretCoords.getY();
}
catch (BadLocationException ex)
{
}
int lineHeight = component.getFontMetrics(component.getFont()).getHeight();
posLine = (y / lineHeight) + 1;
return posLine;
}
代码示例来源:origin: org.protege/protege-editor-owl
private void renderHyperlink(OWLEntity curEntity, int tokenStartIndex, int tokenLength, StyledDocument doc) {
try {
Rectangle startRect = textPane.modelToView(tokenStartIndex);
Rectangle endRect = textPane.modelToView(tokenStartIndex + tokenLength);
if (startRect != null && endRect != null) {
int width = endRect.x - startRect.x;
int heght = startRect.height;
Rectangle tokenRect = new Rectangle(startRect.x, startRect.y, width, heght);
tokenRect.grow(0, -2);
if (linkedObjectComponent.getMouseCellLocation() != null) {
Point mouseCellLocation = linkedObjectComponent.getMouseCellLocation();
if (mouseCellLocation != null) {
mouseCellLocation = SwingUtilities.convertPoint(renderingComponent,
mouseCellLocation,
textPane);
if (tokenRect.contains(mouseCellLocation)) {
doc.setCharacterAttributes(tokenStartIndex, tokenLength, linkStyle, false);
linkedObjectComponent.setLinkedObject(curEntity);
linkRendered = true;
}
}
}
}
}
catch (BadLocationException e) {
e.printStackTrace();
}
}
代码示例来源:origin: edu.stanford.protege/org.protege.editor.owl
private void renderHyperlink(OWLEntity curEntity, int tokenStartIndex, int tokenLength, StyledDocument doc) {
try {
Rectangle startRect = textPane.modelToView(tokenStartIndex);
Rectangle endRect = textPane.modelToView(tokenStartIndex + tokenLength);
if (startRect != null && endRect != null) {
int width = endRect.x - startRect.x;
int heght = startRect.height;
Rectangle tokenRect = new Rectangle(startRect.x, startRect.y, width, heght);
tokenRect.grow(0, -2);
if (linkedObjectComponent.getMouseCellLocation() != null) {
Point mouseCellLocation = linkedObjectComponent.getMouseCellLocation();
if (mouseCellLocation != null) {
mouseCellLocation = SwingUtilities.convertPoint(renderingComponent,
mouseCellLocation,
textPane);
if (tokenRect.contains(mouseCellLocation)) {
doc.setCharacterAttributes(tokenStartIndex, tokenLength, linkStyle, false);
linkedObjectComponent.setLinkedObject(curEntity);
linkRendered = true;
}
}
}
}
}
catch (BadLocationException e) {
e.printStackTrace();
}
}
代码示例来源:origin: zzhang5/zooinspector
Rectangle viewRect = dataArea.modelToView(firstPos);
代码示例来源:origin: net.jradius/jradius-extended
Rectangle r = console.modelToView(length - 1);
if (r != null)
scrollRectToVisible(r);
代码示例来源:origin: coova/jradius
Rectangle r = console.modelToView(length - 1);
if (r != null)
scrollRectToVisible(r);
代码示例来源:origin: com.hynnet/jradius-extended
Rectangle r = console.modelToView(length - 1);
if (r != null)
scrollRectToVisible(r);
代码示例来源:origin: chatty/chatty
Rectangle r = textPane.modelToView(element.getStartOffset());
r.translate(0, - labelSize.height - 3);
r.translate(sourceWidth / 2 - labelSize.width / 2, 0);
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-team-commons
try {
Rectangle rectangle = new Rectangle(
pane.modelToView(elem.getStartOffset()).x,
pane.modelToView(elem.getStartOffset()).y,
fontMetrics.stringWidth(doc.getText(elem.getStartOffset(), elem.getEndOffset() - elem.getStartOffset())),
fontMetrics.getHeight());
代码示例来源:origin: org.antlr/stringtemplate
m.output.scrollRectToVisible(m.output.modelToView(e.outputStartChar));
内容来源于网络,如有侵权,请联系作者删除!