Java Code Examples for javax.swing.text.JTextComponent#getVisibleRect()
The following examples show how to use
javax.swing.text.JTextComponent#getVisibleRect() .
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: CAccessibleText.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
static int[] getVisibleCharacterRange(final Accessible a) { final Accessible sa = CAccessible.getSwingAccessible(a); if (!(sa instanceof JTextComponent)) return null; final JTextComponent jc = (JTextComponent) sa; final Rectangle rect = jc.getVisibleRect(); final Point topLeft = new Point(rect.x, rect.y); final Point topRight = new Point(rect.x + rect.width, rect.y); final Point bottomLeft = new Point(rect.x, rect.y + rect.height); final Point bottomRight = new Point(rect.x + rect.width, rect.y + rect.height); int start = Math.min(jc.viewToModel(topLeft), jc.viewToModel(topRight)); int end = Math.max(jc.viewToModel(bottomLeft), jc.viewToModel(bottomRight)); if (start < 0) start = 0; if (end < 0) end = 0; return new int[] { start, end }; }
Example 2
Source File: CAccessibleText.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
static int[] getVisibleCharacterRange(final Accessible a) { final Accessible sa = CAccessible.getSwingAccessible(a); if (!(sa instanceof JTextComponent)) return null; final JTextComponent jc = (JTextComponent) sa; final Rectangle rect = jc.getVisibleRect(); final Point topLeft = new Point(rect.x, rect.y); final Point topRight = new Point(rect.x + rect.width, rect.y); final Point bottomLeft = new Point(rect.x, rect.y + rect.height); final Point bottomRight = new Point(rect.x + rect.width, rect.y + rect.height); int start = Math.min(jc.viewToModel(topLeft), jc.viewToModel(topRight)); int end = Math.max(jc.viewToModel(bottomLeft), jc.viewToModel(bottomRight)); if (start < 0) start = 0; if (end < 0) end = 0; return new int[] { start, end }; }
Example 3
Source File: CAccessibleText.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
static int[] getVisibleCharacterRange(final Accessible a) { final Accessible sa = CAccessible.getSwingAccessible(a); if (!(sa instanceof JTextComponent)) return null; final JTextComponent jc = (JTextComponent) sa; final Rectangle rect = jc.getVisibleRect(); final Point topLeft = new Point(rect.x, rect.y); final Point topRight = new Point(rect.x + rect.width, rect.y); final Point bottomLeft = new Point(rect.x, rect.y + rect.height); final Point bottomRight = new Point(rect.x + rect.width, rect.y + rect.height); int start = Math.min(jc.viewToModel(topLeft), jc.viewToModel(topRight)); int end = Math.max(jc.viewToModel(bottomLeft), jc.viewToModel(bottomRight)); if (start < 0) start = 0; if (end < 0) end = 0; return new int[] { start, end }; }
Example 4
Source File: CAccessibleText.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
static int[] getVisibleCharacterRange(final Accessible a) { final Accessible sa = CAccessible.getSwingAccessible(a); if (!(sa instanceof JTextComponent)) return null; final JTextComponent jc = (JTextComponent) sa; final Rectangle rect = jc.getVisibleRect(); final Point topLeft = new Point(rect.x, rect.y); final Point topRight = new Point(rect.x + rect.width, rect.y); final Point bottomLeft = new Point(rect.x, rect.y + rect.height); final Point bottomRight = new Point(rect.x + rect.width, rect.y + rect.height); int start = Math.min(jc.viewToModel(topLeft), jc.viewToModel(topRight)); int end = Math.max(jc.viewToModel(bottomLeft), jc.viewToModel(bottomRight)); if (start < 0) start = 0; if (end < 0) end = 0; return new int[] { start, end }; }
Example 5
Source File: GlyphGutter.java From netbeans with Apache License 2.0 | 6 votes |
public @Override void preferenceChange(PreferenceChangeEvent evt) { EditorUI eui = editorUI; JTextComponent c = eui == null ? null : eui.getComponent(); Rectangle rect = c == null ? null : c.getVisibleRect(); if (rect != null && rect.width == 0) { if (SwingUtilities.isEventDispatchThread()) { resize(); } else { SwingUtilities.invokeLater( new Runnable() { public @Override void run() { resize(); } } ); } } }
Example 6
Source File: CAccessibleText.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
static int[] getVisibleCharacterRange(final Accessible a) { final Accessible sa = CAccessible.getSwingAccessible(a); if (!(sa instanceof JTextComponent)) return null; final JTextComponent jc = (JTextComponent) sa; final Rectangle rect = jc.getVisibleRect(); final Point topLeft = new Point(rect.x, rect.y); final Point topRight = new Point(rect.x + rect.width, rect.y); final Point bottomLeft = new Point(rect.x, rect.y + rect.height); final Point bottomRight = new Point(rect.x + rect.width, rect.y + rect.height); int start = Math.min(jc.viewToModel(topLeft), jc.viewToModel(topRight)); int end = Math.max(jc.viewToModel(bottomLeft), jc.viewToModel(bottomRight)); if (start < 0) start = 0; if (end < 0) end = 0; return new int[] { start, end }; }
Example 7
Source File: CAccessibleText.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@SuppressWarnings("deprecation") static int[] getVisibleCharacterRange(final Accessible a) { final Accessible sa = CAccessible.getSwingAccessible(a); if (!(sa instanceof JTextComponent)) return null; final JTextComponent jc = (JTextComponent) sa; final Rectangle rect = jc.getVisibleRect(); final Point topLeft = new Point(rect.x, rect.y); final Point topRight = new Point(rect.x + rect.width, rect.y); final Point bottomLeft = new Point(rect.x, rect.y + rect.height); final Point bottomRight = new Point(rect.x + rect.width, rect.y + rect.height); int start = Math.min(jc.viewToModel(topLeft), jc.viewToModel(topRight)); int end = Math.max(jc.viewToModel(bottomLeft), jc.viewToModel(bottomRight)); if (start < 0) start = 0; if (end < 0) end = 0; return new int[] { start, end }; }
Example 8
Source File: CAccessibleText.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
static int[] getVisibleCharacterRange(final Accessible a) { final Accessible sa = CAccessible.getSwingAccessible(a); if (!(sa instanceof JTextComponent)) return null; final JTextComponent jc = (JTextComponent) sa; final Rectangle rect = jc.getVisibleRect(); final Point topLeft = new Point(rect.x, rect.y); final Point topRight = new Point(rect.x + rect.width, rect.y); final Point bottomLeft = new Point(rect.x, rect.y + rect.height); final Point bottomRight = new Point(rect.x + rect.width, rect.y + rect.height); int start = Math.min(jc.viewToModel(topLeft), jc.viewToModel(topRight)); int end = Math.max(jc.viewToModel(bottomLeft), jc.viewToModel(bottomRight)); if (start < 0) start = 0; if (end < 0) end = 0; return new int[] { start, end }; }
Example 9
Source File: CAccessibleText.java From hottub with GNU General Public License v2.0 | 6 votes |
static int[] getVisibleCharacterRange(final Accessible a) { final Accessible sa = CAccessible.getSwingAccessible(a); if (!(sa instanceof JTextComponent)) return null; final JTextComponent jc = (JTextComponent) sa; final Rectangle rect = jc.getVisibleRect(); final Point topLeft = new Point(rect.x, rect.y); final Point topRight = new Point(rect.x + rect.width, rect.y); final Point bottomLeft = new Point(rect.x, rect.y + rect.height); final Point bottomRight = new Point(rect.x + rect.width, rect.y + rect.height); int start = Math.min(jc.viewToModel(topLeft), jc.viewToModel(topRight)); int end = Math.max(jc.viewToModel(bottomLeft), jc.viewToModel(bottomRight)); if (start < 0) start = 0; if (end < 0) end = 0; return new int[] { start, end }; }
Example 10
Source File: CAccessibleText.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
static int[] getVisibleCharacterRange(final Accessible a) { final Accessible sa = CAccessible.getSwingAccessible(a); if (!(sa instanceof JTextComponent)) return null; final JTextComponent jc = (JTextComponent) sa; final Rectangle rect = jc.getVisibleRect(); final Point topLeft = new Point(rect.x, rect.y); final Point topRight = new Point(rect.x + rect.width, rect.y); final Point bottomLeft = new Point(rect.x, rect.y + rect.height); final Point bottomRight = new Point(rect.x + rect.width, rect.y + rect.height); int start = Math.min(jc.viewToModel(topLeft), jc.viewToModel(topRight)); int end = Math.max(jc.viewToModel(bottomLeft), jc.viewToModel(bottomRight)); if (start < 0) start = 0; if (end < 0) end = 0; return new int[] { start, end }; }
Example 11
Source File: CAccessibleText.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
static int[] getVisibleCharacterRange(final Accessible a) { final Accessible sa = CAccessible.getSwingAccessible(a); if (!(sa instanceof JTextComponent)) return null; final JTextComponent jc = (JTextComponent) sa; final Rectangle rect = jc.getVisibleRect(); final Point topLeft = new Point(rect.x, rect.y); final Point topRight = new Point(rect.x + rect.width, rect.y); final Point bottomLeft = new Point(rect.x, rect.y + rect.height); final Point bottomRight = new Point(rect.x + rect.width, rect.y + rect.height); int start = Math.min(jc.viewToModel(topLeft), jc.viewToModel(topRight)); int end = Math.max(jc.viewToModel(bottomLeft), jc.viewToModel(bottomRight)); if (start < 0) start = 0; if (end < 0) end = 0; return new int[] { start, end }; }
Example 12
Source File: CAccessibleText.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
static int[] getVisibleCharacterRange(final Accessible a) { final Accessible sa = CAccessible.getSwingAccessible(a); if (!(sa instanceof JTextComponent)) return null; final JTextComponent jc = (JTextComponent) sa; final Rectangle rect = jc.getVisibleRect(); final Point topLeft = new Point(rect.x, rect.y); final Point topRight = new Point(rect.x + rect.width, rect.y); final Point bottomLeft = new Point(rect.x, rect.y + rect.height); final Point bottomRight = new Point(rect.x + rect.width, rect.y + rect.height); int start = Math.min(jc.viewToModel(topLeft), jc.viewToModel(topRight)); int end = Math.max(jc.viewToModel(bottomLeft), jc.viewToModel(bottomRight)); if (start < 0) start = 0; if (end < 0) end = 0; return new int[] { start, end }; }
Example 13
Source File: CAccessibleText.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
static int[] getVisibleCharacterRange(final Accessible a) { final Accessible sa = CAccessible.getSwingAccessible(a); if (!(sa instanceof JTextComponent)) return null; final JTextComponent jc = (JTextComponent) sa; final Rectangle rect = jc.getVisibleRect(); final Point topLeft = new Point(rect.x, rect.y); final Point topRight = new Point(rect.x + rect.width, rect.y); final Point bottomLeft = new Point(rect.x, rect.y + rect.height); final Point bottomRight = new Point(rect.x + rect.width, rect.y + rect.height); int start = Math.min(jc.viewToModel(topLeft), jc.viewToModel(topRight)); int end = Math.max(jc.viewToModel(bottomLeft), jc.viewToModel(bottomRight)); if (start < 0) start = 0; if (end < 0) end = 0; return new int[] { start, end }; }
Example 14
Source File: CAccessibleText.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
static int[] getVisibleCharacterRange(final Accessible a) { final Accessible sa = CAccessible.getSwingAccessible(a); if (!(sa instanceof JTextComponent)) return null; final JTextComponent jc = (JTextComponent) sa; final Rectangle rect = jc.getVisibleRect(); final Point topLeft = new Point(rect.x, rect.y); final Point topRight = new Point(rect.x + rect.width, rect.y); final Point bottomLeft = new Point(rect.x, rect.y + rect.height); final Point bottomRight = new Point(rect.x + rect.width, rect.y + rect.height); int start = Math.min(jc.viewToModel(topLeft), jc.viewToModel(topRight)); int end = Math.max(jc.viewToModel(bottomLeft), jc.viewToModel(bottomRight)); if (start < 0) start = 0; if (end < 0) end = 0; return new int[] { start, end }; }
Example 15
Source File: EditorFindSupport.java From netbeans with Apache License 2.0 | 5 votes |
/** * Ensure that the given region will be visible in the view * with the appropriate find insets. */ private void ensureVisible(JTextComponent c, int startOffset, int endOffset, Insets extraInsets) { try { Rectangle startBounds = c.modelToView(startOffset); Rectangle endBounds = c.modelToView(endOffset); if (startBounds != null && endBounds != null) { startBounds.add(endBounds); if (extraInsets != null) { Rectangle visibleBounds = c.getVisibleRect(); int extraTop = (extraInsets.top < 0) ? -extraInsets.top * visibleBounds.height / 100 // percentage : extraInsets.top * endBounds.height; // line count startBounds.y -= extraTop; startBounds.height += extraTop; startBounds.height += (extraInsets.bottom < 0) ? -extraInsets.bottom * visibleBounds.height / 100 // percentage : extraInsets.bottom * endBounds.height; // line count int extraLeft = (extraInsets.left < 0) ? -extraInsets.left * visibleBounds.width / 100 // percentage : extraInsets.left * endBounds.width; // char count startBounds.x -= extraLeft; startBounds.width += extraLeft; startBounds.width += (extraInsets.right < 0) ? -extraInsets.right * visibleBounds.width / 100 // percentage : extraInsets.right * endBounds.width; // char count } c.scrollRectToVisible(startBounds); } } catch (BadLocationException e) { // do not scroll } }
Example 16
Source File: OverrideEditorActions.java From netbeans with Apache License 2.0 | 4 votes |
public void actionPerformed(ActionEvent evt, JTextComponent target) { if (target != null) { Caret caret = target.getCaret(); BaseDocument doc = (BaseDocument)target.getDocument(); try { int dot = caret.getDot(); // #232675: if bounds are defined, use them rather than line start/end Object o = target.getClientProperty(PROP_NAVIGATE_BOUNDARIES); PositionRegion bounds = null; int lineStartPos = Utilities.getRowStart(target, dot); if (o instanceof PositionRegion) { bounds = (PositionRegion)o; int start = bounds.getStartOffset(); int end = bounds.getEndOffset(); int boundLineStart = Utilities.getRowStart(target, start); // refinement: only use the boundaries if the caret is at the same line // as boundary start; otherwise ignore the boundary and use document lines. if (boundLineStart == lineStartPos && dot > start && dot <= end) { // move to the region start dot = start; } else { bounds = null; } } if (bounds == null) { if (homeKeyColumnOne) { // to first column dot = lineStartPos; } else { // either to line start or text start int textStartPos = Utilities.getRowFirstNonWhite(doc, lineStartPos); if (textStartPos < 0) { // no text on the line textStartPos = Utilities.getRowEnd(target, lineStartPos); } if (dot == lineStartPos) { // go to the text start pos dot = textStartPos; } else if (dot <= textStartPos) { dot = lineStartPos; } else { dot = textStartPos; } } } // For partial view hierarchy check bounds dot = Math.max(dot, target.getUI().getRootView(target).getStartOffset()); String actionName = (String) getValue(Action.NAME); boolean select = selectionBeginLineAction.equals(actionName) || selectionLineFirstColumnAction.equals(actionName); // If possible scroll the view to its begining horizontally // to ease user's orientation in the code. Rectangle r = target.modelToView(dot); Rectangle visRect = target.getVisibleRect(); if (r.getMaxX() < visRect.getWidth()) { r.x = 0; target.scrollRectToVisible(r); } target.putClientProperty("navigational.action", SwingConstants.WEST); if (select) { caret.moveDot(dot); } else { caret.setDot(dot); } } catch (BadLocationException e) { target.getToolkit().beep(); } } }