Java Code Examples for javax.swing.JViewport#getExtentSize()

The following examples show how to use javax.swing.JViewport#getExtentSize() . 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: Test6526631.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public void validateThird() {
    JViewport viewport = this.pane.getViewport();
    JScrollBar scroller = this.pane.getHorizontalScrollBar();
    if (!scroller.getComponentOrientation().equals(ComponentOrientation.RIGHT_TO_LEFT)) {
        throw new Error("unexpected component orientation");
    }
    int value = scroller.getValue();
    if (value != 0) {
        throw new Error("unexpected scroll value");
    }
    int extent = viewport.getExtentSize().width;
    if (extent != scroller.getVisibleAmount()) {
        throw new Error("unexpected visible amount");
    }
    int size = viewport.getViewSize().width;
    if (size != scroller.getMaximum()) {
        throw new Error("unexpected maximum");
    }
    int pos = size - extent - value;
    if (pos != viewport.getViewPosition().x) {
        throw new Error("unexpected position");
    }
}
 
Example 2
Source File: Test6526631.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public void validateThird() {
    JViewport viewport = this.pane.getViewport();
    JScrollBar scroller = this.pane.getHorizontalScrollBar();
    if (!scroller.getComponentOrientation().equals(ComponentOrientation.RIGHT_TO_LEFT)) {
        throw new Error("unexpected component orientation");
    }
    int value = scroller.getValue();
    if (value != 0) {
        throw new Error("unexpected scroll value");
    }
    int extent = viewport.getExtentSize().width;
    if (extent != scroller.getVisibleAmount()) {
        throw new Error("unexpected visible amount");
    }
    int size = viewport.getViewSize().width;
    if (size != scroller.getMaximum()) {
        throw new Error("unexpected maximum");
    }
    int pos = size - extent - value;
    if (pos != viewport.getViewPosition().x) {
        throw new Error("unexpected position");
    }
}
 
Example 3
Source File: Test6526631.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
public void validateThird() {
    JViewport viewport = this.pane.getViewport();
    JScrollBar scroller = this.pane.getHorizontalScrollBar();
    if (!scroller.getComponentOrientation().equals(ComponentOrientation.RIGHT_TO_LEFT)) {
        throw new Error("unexpected component orientation");
    }
    int value = scroller.getValue();
    if (value != 0) {
        throw new Error("unexpected scroll value");
    }
    int extent = viewport.getExtentSize().width;
    if (extent != scroller.getVisibleAmount()) {
        throw new Error("unexpected visible amount");
    }
    int size = viewport.getViewSize().width;
    if (size != scroller.getMaximum()) {
        throw new Error("unexpected maximum");
    }
    int pos = size - extent - value;
    if (pos != viewport.getViewPosition().x) {
        throw new Error("unexpected position");
    }
}
 
Example 4
Source File: Test6526631.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public void validateThird() {
    JViewport viewport = this.pane.getViewport();
    JScrollBar scroller = this.pane.getHorizontalScrollBar();
    if (!scroller.getComponentOrientation().equals(ComponentOrientation.RIGHT_TO_LEFT)) {
        throw new Error("unexpected component orientation");
    }
    int value = scroller.getValue();
    if (value != 0) {
        throw new Error("unexpected scroll value");
    }
    int extent = viewport.getExtentSize().width;
    if (extent != scroller.getVisibleAmount()) {
        throw new Error("unexpected visible amount");
    }
    int size = viewport.getViewSize().width;
    if (size != scroller.getMaximum()) {
        throw new Error("unexpected maximum");
    }
    int pos = size - extent - value;
    if (pos != viewport.getViewPosition().x) {
        throw new Error("unexpected position");
    }
}
 
Example 5
Source File: Test6526631.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
public void validateThird() {
    JViewport viewport = this.pane.getViewport();
    JScrollBar scroller = this.pane.getHorizontalScrollBar();
    if (!scroller.getComponentOrientation().equals(ComponentOrientation.RIGHT_TO_LEFT)) {
        throw new Error("unexpected component orientation");
    }
    int value = scroller.getValue();
    if (value != 0) {
        throw new Error("unexpected scroll value");
    }
    int extent = viewport.getExtentSize().width;
    if (extent != scroller.getVisibleAmount()) {
        throw new Error("unexpected visible amount");
    }
    int size = viewport.getViewSize().width;
    if (size != scroller.getMaximum()) {
        throw new Error("unexpected maximum");
    }
    int pos = size - extent - value;
    if (pos != viewport.getViewPosition().x) {
        throw new Error("unexpected position");
    }
}
 
Example 6
Source File: Test6526631.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public void validateThird() {
    JViewport viewport = this.pane.getViewport();
    JScrollBar scroller = this.pane.getHorizontalScrollBar();
    if (!scroller.getComponentOrientation().equals(ComponentOrientation.RIGHT_TO_LEFT)) {
        throw new Error("unexpected component orientation");
    }
    int value = scroller.getValue();
    if (value != 0) {
        throw new Error("unexpected scroll value");
    }
    int extent = viewport.getExtentSize().width;
    if (extent != scroller.getVisibleAmount()) {
        throw new Error("unexpected visible amount");
    }
    int size = viewport.getViewSize().width;
    if (size != scroller.getMaximum()) {
        throw new Error("unexpected maximum");
    }
    int pos = size - extent - value;
    if (pos != viewport.getViewPosition().x) {
        throw new Error("unexpected position");
    }
}
 
Example 7
Source File: Utilities.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void changed() {
    JViewport viewport = sp.getViewport();
    Point viewPosition = viewport.getViewPosition();
    if (viewPosition.x > 0) {
        try {
            Rectangle textRect = editorPane.getUI().modelToView(editorPane, editorPane.getDocument().getLength());
            int textLength = textRect.x + textRect.width;
            int viewLength = viewport.getExtentSize().width;
            //System.out.println("Utilities.createSingleLineEditor(): spLength = "+sp.getSize().width+", viewLength = "+viewLength+", textLength = "+textLength+", viewPosition = "+viewPosition);
            if (textLength < (viewPosition.x + viewLength)) {
                viewPosition.x = Math.max(textLength - viewLength, 0);
                viewport.setViewPosition(viewPosition);
                //System.out.println("Utilities.createSingleLineEditor(): setting new view position = "+viewPosition);
            }
        } catch (BadLocationException blex) {
            Exceptions.printStackTrace(blex);
        }
    }
}
 
Example 8
Source File: ComponentPeer.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private int[] computeVisibleSpan() {
    Component parent = pane.getParent();
    
    if (parent instanceof JLayeredPane) {
        parent = parent.getParent();
    }

    if (parent instanceof JViewport) {
        JViewport vp = (JViewport) parent;

        Point start = vp.getViewPosition();
        Dimension size = vp.getExtentSize();
        Point end = new Point((int) (start.getX() + size.getWidth()), (int) (start.getY() + size.getHeight()));

        int startPosition = pane.viewToModel(start);
        int endPosition = pane.viewToModel(end);

        if (parentWithListener != vp) {
            vp.addChangeListener(WeakListeners.change(this, vp));
            parentWithListener = vp;
        }
        return new int[] {startPosition, endPosition};
    }

    return new int[] {0, pane.getDocument().getLength()};
}
 
Example 9
Source File: Test6526631.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public void validateThird() {
    JViewport viewport = this.pane.getViewport();
    JScrollBar scroller = this.pane.getHorizontalScrollBar();
    if (!scroller.getComponentOrientation().equals(ComponentOrientation.RIGHT_TO_LEFT)) {
        throw new Error("unexpected component orientation");
    }
    int value = scroller.getValue();
    if (value != 0) {
        throw new Error("unexpected scroll value");
    }
    int extent = viewport.getExtentSize().width;
    if (extent != scroller.getVisibleAmount()) {
        throw new Error("unexpected visible amount");
    }
    int size = viewport.getViewSize().width;
    if (size != scroller.getMaximum()) {
        throw new Error("unexpected maximum");
    }
    int pos = size - extent - value;
    if (pos != viewport.getViewPosition().x) {
        throw new Error("unexpected position");
    }
}
 
Example 10
Source File: GuiUtil.java    From CQL with GNU Affero General Public License v3.0 6 votes vote down vote up
public static void centerLineInScrollPane(JTextComponent component) {
	Container container = SwingUtilities.getAncestorOfClass(JViewport.class, component);

	if (container == null)
		return;

	try {
		Rectangle r = component.modelToView(component.getCaretPosition());
		// Rectangle2D r = component.modelToView2D(component.getCaretPosition());
		JViewport viewport = (JViewport) container;
		if (r == null) { // || viewport == null) {
			return;
		}
		int extentHeight = viewport.getExtentSize().height;
		int viewHeight = viewport.getViewSize().height;

		int y = Math.max(0, r.y - ((extentHeight - r.height) / 2));
		// double y = Math.max(0, r.getY() - ((extentHeight - r.getHeight()) / 2));
		y = Math.min(y, viewHeight - extentHeight);

		viewport.setViewPosition(new Point(0, y));
		// viewport.setViewPosition(new Point(0, (int) y));
	} catch (BadLocationException ble) {
	}
}
 
Example 11
Source File: Test6526631.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public void validateThird() {
    JViewport viewport = this.pane.getViewport();
    JScrollBar scroller = this.pane.getHorizontalScrollBar();
    if (!scroller.getComponentOrientation().equals(ComponentOrientation.RIGHT_TO_LEFT)) {
        throw new Error("unexpected component orientation");
    }
    int value = scroller.getValue();
    if (value != 0) {
        throw new Error("unexpected scroll value");
    }
    int extent = viewport.getExtentSize().width;
    if (extent != scroller.getVisibleAmount()) {
        throw new Error("unexpected visible amount");
    }
    int size = viewport.getViewSize().width;
    if (size != scroller.getMaximum()) {
        throw new Error("unexpected maximum");
    }
    int pos = size - extent - value;
    if (pos != viewport.getViewPosition().x) {
        throw new Error("unexpected position");
    }
}
 
Example 12
Source File: Test6526631.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public void validateThird() {
    JViewport viewport = this.pane.getViewport();
    JScrollBar scroller = this.pane.getHorizontalScrollBar();
    if (!scroller.getComponentOrientation().equals(ComponentOrientation.RIGHT_TO_LEFT)) {
        throw new Error("unexpected component orientation");
    }
    int value = scroller.getValue();
    if (value != 0) {
        throw new Error("unexpected scroll value");
    }
    int extent = viewport.getExtentSize().width;
    if (extent != scroller.getVisibleAmount()) {
        throw new Error("unexpected visible amount");
    }
    int size = viewport.getViewSize().width;
    if (size != scroller.getMaximum()) {
        throw new Error("unexpected maximum");
    }
    int pos = size - extent - value;
    if (pos != viewport.getViewPosition().x) {
        throw new Error("unexpected position");
    }
}
 
Example 13
Source File: Test6526631.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public void validateThird() {
    JViewport viewport = this.pane.getViewport();
    JScrollBar scroller = this.pane.getHorizontalScrollBar();
    if (!scroller.getComponentOrientation().equals(ComponentOrientation.RIGHT_TO_LEFT)) {
        throw new Error("unexpected component orientation");
    }
    int value = scroller.getValue();
    if (value != 0) {
        throw new Error("unexpected scroll value");
    }
    int extent = viewport.getExtentSize().width;
    if (extent != scroller.getVisibleAmount()) {
        throw new Error("unexpected visible amount");
    }
    int size = viewport.getViewSize().width;
    if (size != scroller.getMaximum()) {
        throw new Error("unexpected maximum");
    }
    int pos = size - extent - value;
    if (pos != viewport.getViewPosition().x) {
        throw new Error("unexpected position");
    }
}
 
Example 14
Source File: DebuggingViewComponent.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void adjustTreeScrollBar(int treeViewWidth) {
    DebugTreeView tView = getTreeView();
    if (tView == null) {
        scrollBarPanel.setVisible(false);
        return;
    }
    JViewport viewport = tView.getViewport();
    Point point = viewport.getViewPosition();
    if (point.y < 0) {
        viewport.setViewPosition(new Point(point.x, 0));
    }
    Dimension viewSize = viewport.getExtentSize();
    Dimension treeSize = viewport.getViewSize();
    if (treeViewWidth < 0) {
        treeViewWidth = treeSize.width;
    }
    int unitHeight = tView.getUnitHeight();
    if (unitHeight > 0) {
        JScrollBar sbar = mainScrollPane.getVerticalScrollBar();
        if (sbar.getUnitIncrement() != unitHeight) {
            sbar.setUnitIncrement(unitHeight);
        }
    }
    if (treeViewWidth <= viewSize.width) {
        scrollBarPanel.setVisible(false);
    } else {
        treeScrollBar.setMaximum(treeViewWidth);
        treeScrollBar.setVisibleAmount(viewSize.width);
        if (unitHeight > 0) {
            treeScrollBar.setUnitIncrement(unitHeight / 2);
        }
        treeScrollBar.setBlockIncrement(viewSize.width);
        scrollBarPanel.setVisible(true);
    } // else
}
 
Example 15
Source File: J2DNiftyView.java    From niftyeditor with Apache License 2.0 5 votes vote down vote up
@Override
public void stateChanged(ChangeEvent e) {
   JViewport temp = (JViewport) e.getSource();
   int h = temp.getExtentSize().height > this.graphWrap.h ? this.graphWrap.h : temp.getExtentSize().height; 
   int w = temp.getExtentSize().width > this.graphWrap.w ? this.graphWrap.w : temp.getExtentSize().width;
   this.clipView.setBounds(temp.getViewPosition().x, temp.getViewPosition().y, w, h);
}
 
Example 16
Source File: AutoscrollSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Performs autoscroll operation.
*/
public void autoscroll(Point cursorLoc) {
    JViewport viewport = getViewport();

    if (viewport == null) {
        return;
    }

    Point viewPos = viewport.getViewPosition();
    int viewHeight = viewport.getExtentSize().height;
    int viewWidth = viewport.getExtentSize().width;

    // perform scrolling
    if ((cursorLoc.y - viewPos.y) < insets.top) {
        // scroll up
        viewport.setViewPosition(new Point(viewPos.x, Math.max(viewPos.y - scrollUnits.top, 0)));
    } else if (((viewPos.y + viewHeight) - cursorLoc.y) < insets.bottom) {
        // scroll down
        viewport.setViewPosition(
            new Point(viewPos.x, Math.min(viewPos.y + scrollUnits.bottom, comp.getHeight() - viewHeight))
        );
    } else if ((cursorLoc.x - viewPos.x) < insets.left) {
        // scroll left
        viewport.setViewPosition(new Point(Math.max(viewPos.x - scrollUnits.left, 0), viewPos.y));
    } else if (((viewPos.x + viewWidth) - cursorLoc.x) < insets.right) {
        // scroll right
        viewport.setViewPosition(
            new Point(Math.min(viewPos.x + scrollUnits.right, comp.getWidth() - viewWidth), viewPos.y)
        );
    }
}
 
Example 17
Source File: SeaGlassScrollPaneUI.java    From seaglass with Apache License 2.0 5 votes vote down vote up
private void sbPropertyChange(PropertyChangeEvent e) {
    String propertyName = e.getPropertyName();
    Object source = e.getSource();

    if ("model" == propertyName) {
        JScrollBar sb = scrollpane.getVerticalScrollBar();
        BoundedRangeModel oldModel = (BoundedRangeModel) e.getOldValue();
        ChangeListener cl = null;

        if (source == sb) {
            cl = vsbChangeListener;
        } else if (source == scrollpane.getHorizontalScrollBar()) {
            sb = scrollpane.getHorizontalScrollBar();
            cl = hsbChangeListener;
        }
        if (cl != null) {
            if (oldModel != null) {
                oldModel.removeChangeListener(cl);
            }
            if (sb.getModel() != null) {
                sb.getModel().addChangeListener(cl);
            }
        }
    } else if ("componentOrientation" == propertyName) {
        if (source == scrollpane.getHorizontalScrollBar()) {
            JScrollBar hsb = scrollpane.getHorizontalScrollBar();
            JViewport viewport = scrollpane.getViewport();
            Point p = viewport.getViewPosition();
            if (scrollpane.getComponentOrientation().isLeftToRight()) {
                p.x = hsb.getValue();
            } else {
                p.x = viewport.getViewSize().width - viewport.getExtentSize().width - hsb.getValue();
            }
            viewport.setViewPosition(p);
        }
    }
}
 
Example 18
Source File: AutoscrollSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Performs autoscroll operation.
*/
public void autoscroll(Point cursorLoc) {
    JViewport viewport = getViewport();

    if (viewport == null) {
        return;
    }

    Point viewPos = viewport.getViewPosition();
    int viewHeight = viewport.getExtentSize().height;
    int viewWidth = viewport.getExtentSize().width;

    // perform scrolling
    if ((cursorLoc.y - viewPos.y) < insets.top) {
        // scroll up
        viewport.setViewPosition(new Point(viewPos.x, Math.max(viewPos.y - scrollUnits.top, 0)));
    } else if (((viewPos.y + viewHeight) - cursorLoc.y) < insets.bottom) {
        // scroll down
        viewport.setViewPosition(
            new Point(viewPos.x, Math.min(viewPos.y + scrollUnits.bottom, comp.getHeight() - viewHeight))
        );
    } else if ((cursorLoc.x - viewPos.x) < insets.left) {
        // scroll left
        viewport.setViewPosition(new Point(Math.max(viewPos.x - scrollUnits.left, 0), viewPos.y));
    } else if (((viewPos.x + viewWidth) - cursorLoc.x) < insets.right) {
        // scroll right
        viewport.setViewPosition(
            new Point(Math.min(viewPos.x + scrollUnits.right, comp.getWidth() - viewWidth), viewPos.y)
        );
    }
}
 
Example 19
Source File: MMDEditor.java    From netbeans-mmd-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public void onScaledByMouse(
        @Nonnull final MindMapPanel source,
        @Nonnull final Point mousePoint,
        final double oldScale,
        final double newScale,
        @Nonnull final Dimension oldSize,
        @Nonnull final Dimension newSize
) {
  if (Double.compare(oldScale, newScale) != 0) {
    this.scrollPane.setViewportView(source);
    final JViewport viewport = this.scrollPane.getViewport();

    final Rectangle viewPos = viewport.getViewRect();

    final Dimension size = source.getSize();
    final Dimension extentSize = viewport.getExtentSize();

    if (extentSize.width < size.width || extentSize.height < size.height) {

      final int dx = mousePoint.x - viewPos.x;
      final int dy = mousePoint.y - viewPos.y;

      final double scaleX = newSize.getWidth() / oldSize.getWidth();
      final double scaleY = newSize.getHeight() / oldSize.getHeight();

      final int newMouseX = (int) (Math.round(mousePoint.x * scaleX));
      final int newMouseY = (int) (Math.round(mousePoint.y * scaleY));

      viewPos.x = Math.max(0, newMouseX - dx);
      viewPos.y = Math.max(0, newMouseY - dy);
      viewport.setView(source);

      source.scrollRectToVisible(viewPos);
    } else {
      viewPos.x = 0;
      viewPos.y = 0;
      source.scrollRectToVisible(viewPos);
    }
    this.scrollPane.repaint();
  }
}
 
Example 20
Source File: MindMapDocumentEditor.java    From netbeans-mmd-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public void onScaledByMouse(
    @Nonnull final MindMapPanel source,
    @Nonnull final Point mousePoint,
    final double oldScale,
    final double newScale,
    @Nonnull final Dimension oldSize,
    @Nonnull final Dimension newSize
) {
  if (Double.compare(oldScale, newScale) != 0) {
    this.mainScrollPane.setViewportView(source);

    final JViewport viewport = this.mainScrollPane.getViewport();

    final Rectangle viewPos = viewport.getViewRect();

    final Dimension size = source.getSize();
    final Dimension extentSize = viewport.getExtentSize();

    if (extentSize.width < size.width || extentSize.height < size.height) {

      final int dx = mousePoint.x - viewPos.x;
      final int dy = mousePoint.y - viewPos.y;

      final double scaleX = newSize.getWidth() / oldSize.getWidth();
      final double scaleY = newSize.getHeight() / oldSize.getHeight();

      final int newMouseX = (int) (Math.round(mousePoint.x * scaleX));
      final int newMouseY = (int) (Math.round(mousePoint.y * scaleY));

      viewPos.x = Math.max(0, newMouseX - dx);
      viewPos.y = Math.max(0, newMouseY - dy);

      source.scrollRectToVisible(viewPos);
    } else {
      viewPos.x = 0;
      viewPos.y = 0;
      source.scrollRectToVisible(viewPos);
    }

    this.mainScrollPane.repaint();
  }
}