javax.swing.JViewport Java Examples

The following examples show how to use javax.swing.JViewport. 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: JDynamicTable.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
protected void unconfigureEnclosingScrollPane()
{
	super.unconfigureEnclosingScrollPane();
	Container p = getParent();
	if (p instanceof JViewport)
	{
		Container gp = p.getParent();
		if (gp instanceof JScrollPane)
		{
			JScrollPane scrollPane = (JScrollPane) gp;
			// Make certain we are the viewPort's view and not, for
			// example, the rowHeaderView of the scrollPane -
			// an implementor of fixed columns might do this.
			JViewport viewport = scrollPane.getViewport();
			if (viewport == null || viewport.getView() != this)
			{
				return;
			}
			scrollPane.setCorner(ScrollPaneConstants.UPPER_RIGHT_CORNER, null);
		}
	}
}
 
Example #2
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 #3
Source File: ETable.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * This method update mouse listener on the scrollPane if it is needed.
 * It also recomputes the model of searchCombo. Both actions are needed after
 * the set of visible columns is changed.
 */
void updateColumnSelectionMouseListener() {
    Container p = getParent();
    if (p instanceof JViewport) {
        Container gp = p.getParent();
        if (gp instanceof JScrollPane) {
            JScrollPane scrollPane = (JScrollPane)gp;
            // Make certain we are the viewPort's view and not, for
            // example, the rowHeaderView of the scrollPane -
            // an implementor of fixed columns might do this.
            JViewport viewport = scrollPane.getViewport();
            if (viewport == null || viewport.getView() != this) {
                return;
            }
            scrollPane.removeMouseListener(columnSelectionMouseListener);
            if (getColumnModel().getColumnCount() == 0) {
                scrollPane.addMouseListener(columnSelectionMouseListener);
            }
        }
    }
    if (searchCombo != null) {
        searchCombo.setModel(getSearchComboModel());
    }
}
 
Example #4
Source File: ViewDragScrollListener.java    From openAGV with Apache License 2.0 6 votes vote down vote up
@Override
public void mousePressed(MouseEvent evt) {
  final OpenTCSDrawingView drawingView = scrollPane.getDrawingView();
  if (dragIsSelected()) {
    drawingView.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
  }
  Container c = drawingView.getParent();
  if (c instanceof JViewport) {
    JViewport viewPort = (JViewport) c;
    Point cp = SwingUtilities.convertPoint(drawingView, evt.getPoint(), viewPort);
    startPoint.setLocation(cp);
  }
  pressedFigure = drawingView.findFigure(evt.getPoint());
  fMouseCurrentPoint.setLocation(drawingView.viewToDrawing(evt.getPoint()));
  fMouseStartPoint.setLocation(drawingView.viewToDrawing(evt.getPoint()));
  showPositionStatus(false);
}
 
Example #5
Source File: JViewPortBackingStoreImageTest.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static JComponent createComponent() {
    createStyles();
    for (int i = 0; i < data.length; i++) {
        Paragraph p = data[i];
        addParagraph(p);
    }

    JTextPane textPane = new JTextPane(doc);

    JScrollPane scroller = new JScrollPane();
    JViewport port = scroller.getViewport();
    port.setScrollMode(JViewport.BACKINGSTORE_SCROLL_MODE);
    port.add(textPane);

    return scroller;
}
 
Example #6
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 #7
Source File: ZoomManager.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void actionPerformed(ActionEvent e) {
    Scene scene = manager.getScene();
    JScrollPane pane = (JScrollPane) SwingUtilities.getAncestorOfClass(
            JScrollPane.class, scene.getView());
    if (pane == null) {
        // Unlikely, but we cannot assume it exists.
        return;
    }
    JViewport viewport = pane.getViewport();
    Rectangle visRect = viewport.getViewRect();
    Rectangle compRect = scene.getPreferredBounds();
    int zoomX = visRect.width * 100 / compRect.width;
    int zoomY = visRect.height * 100 / compRect.height;
    int zoom = Math.min(zoomX, zoomY);
    manager.setZoom(zoom);
}
 
Example #8
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 #9
Source File: ScrollablePanel.java    From mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean getScrollableTracksViewportWidth() {
  if (scrollableWidth == ScrollableSizeHint.NONE)
    return false;

  if (scrollableWidth == ScrollableSizeHint.FIT)
    return true;

  // STRETCH sizing, use the greater of the panel or viewport width

  if (getParent() instanceof JViewport) {
    return (((JViewport) getParent()).getWidth() > getPreferredSize().width);
  }

  return false;
}
 
Example #10
Source File: GraphViewer.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/** Repaint this component. */
public void alloyRepaint() {
    Container c = getParent();
    while (c != null) {
        if (c instanceof JViewport)
            break;
        else
            c = c.getParent();
    }
    setSize((int) (graph.getTotalWidth() * scale), (int) (graph.getTotalHeight() * scale));
    if (c != null) {
        c.invalidate();
        c.repaint();
        c.validate();
    } else {
        invalidate();
        repaint();
        validate();
    }
}
 
Example #11
Source File: JTreeViewTable.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
protected void unconfigureEnclosingScrollPane()
{
	super.unconfigureEnclosingScrollPane();
	Container p = getParent();
	if (p instanceof JViewport)
	{
		Container gp = p.getParent();
		if (gp instanceof JScrollPane)
		{
			JScrollPane scrollPane = (JScrollPane) gp;
			// Make certain we are the viewPort's view and not, for
			// example, the rowHeaderView of the scrollPane -
			// an implementor of fixed columns might do this.
			JViewport viewport = scrollPane.getViewport();
			if (viewport == null || viewport.getView() != this)
			{
				return;
			}
			scrollPane.setCorner(ScrollPaneConstants.UPPER_RIGHT_CORNER, null);
		}
	}
}
 
Example #12
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 #13
Source File: ScrollablePanel.java    From magarena with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean getScrollableTracksViewportHeight() {
    if (scrollableHeight == ScrollableSizeHint.NONE) {
        return false;
    }

    if (scrollableHeight == ScrollableSizeHint.FIT) {
        return true;
    }

    //  STRETCH sizing, use the greater of the panel or viewport height
    if (getParent() instanceof JViewport) {
        return (((JViewport) getParent()).getHeight() > getPreferredSize().height);
    }

    return false;
}
 
Example #14
Source File: MBasicTable.java    From javamelody with Apache License 2.0 6 votes vote down vote up
@Override
protected void configureEnclosingScrollPane() {
	// Si cette table est la viewportView d'un JScrollPane (la situation habituelle),
	// configure ce ScrollPane en positionnant la barre verticale à "always"
	// (et en installant le tableHeader comme columnHeaderView).
	super.configureEnclosingScrollPane();

	final Container parent = getParent();
	if (parent instanceof JViewport && parent.getParent() instanceof JScrollPane) {
		final JScrollPane scrollPane = (JScrollPane) parent.getParent();
		if (scrollPane.getVerticalScrollBar() != null) {
			scrollPane.getVerticalScrollBar().setFocusable(false);
		}
		if (scrollPane.getHorizontalScrollBar() != null) {
			scrollPane.getHorizontalScrollBar().setFocusable(false);
		}

		final JViewport viewport = scrollPane.getViewport();
		if (viewport == null || viewport.getView() != this) {
			return;
		}

		scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
	}
}
 
Example #15
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 #16
Source File: GtpShell.java    From FancyBing with GNU General Public License v3.0 6 votes vote down vote up
private void scrollPage(boolean up)
{
    JViewport viewport = m_scrollPane.getViewport();
    Point position = viewport.getViewPosition();
    int delta = m_scrollPane.getSize().height
        - m_gtpShellText.getFont().getSize();
    if (up)
    {
        position.y -= delta;
        if (position.y < 0)
            position.y = 0;
    }
    else
    {
        position.y += delta;
        int max = viewport.getViewSize().height
            - m_scrollPane.getSize().height;
        if (position.y > max)
            position.y = max;
    }
    viewport.setViewPosition(position);
}
 
Example #17
Source File: SimpleTextPaneResizeable.java    From wandora with GNU General Public License v3.0 6 votes vote down vote up
private Polygon getTriangle() {
    JViewport viewport = getScrollPane().getViewport();
 
    // Get bounds of viewport
    Rectangle bounds = viewport.getBounds();
 
    // Position of viewport relative to text area.
    Point viewportPosition = viewport.getViewPosition();
 
    int w = viewportPosition.x + bounds.width;
    int h = viewportPosition.y + bounds.height;
 
    int[] xs = {w,w,w-triangleSize};
    int[] ys = {h-triangleSize,h,h};
 
    Polygon polygon = new Polygon(xs, ys, 3);
    return polygon;
}
 
Example #18
Source File: SeaGlassTableUI.java    From seaglass with Apache License 2.0 5 votes vote down vote up
/**
 * DOCUMENT ME!
 *
 * @param  table DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 */
private static PropertyChangeListener createAncestorPropertyChangeListener(final JTable table) {
    return new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent event) {
            if (table.getParent() instanceof JViewport && table.getParent().getParent() instanceof JScrollPane) {
                table.getParent().repaint();
            }
        }
    };
}
 
Example #19
Source File: LogTopComponent.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
private void tabPaneStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_tabPaneStateChanged

        JScrollPane sPane = (JScrollPane) tabPane.getSelectedComponent();
        if (sPane != null) {

            JViewport view = (JViewport) sPane.getComponent(0);
            selectedTable = (JTable) view.getView();

            // re-apply the filter to the current tab
            if (selectedTable.getRowSorter() != null) {
                ((TableRowSorter) selectedTable.getRowSorter()).sort();
            }

            if (tabManagers != null) {

                // Remove all toggle button listeners
                for (ChangeListener l : autoScrollToggleButton.getChangeListeners()) {

                    autoScrollToggleButton.removeChangeListener(l);
                }

                LogTableManager manager = tabManagers.get(tabPane.getSelectedIndex());

                // Add current listener
                autoScrollToggleButton.addChangeListener(manager);

                // Refresh buttons
                autoScrollToggleButton.setSelected(manager.isAutoFollowScroll());
            }
        }
    }
 
Example #20
Source File: PSheet.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private JScrollPane createScrollPane(Component inner) {
    JScrollPane result = new JScrollPane(inner);
    JViewport vp = result.getViewport();
    vp.addMouseListener(this);

    MarginViewportUI ui = (MarginViewportUI) MarginViewportUI.createUI(vp);
    vp.setUI(ui);
    ui.setMarginPainted(marginPainted);
    ui.setMarginColor(marginColor);
    ui.setEmptyString(emptyString);
    result.setBorder(BorderFactory.createEmptyBorder());
    result.setViewportBorder(result.getBorder());

    return result;
}
 
Example #21
Source File: MarginViewportUI.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Overridden to draw "no properties" if necessary */
public void paint(Graphics g, JComponent c) {
    Component view = ((JViewport) c).getView();

    if (view != null) {
        lastKnownSize = view.getSize();
    }

    if (stringWidth == -1) {
        calcStringSizes(c.getFont(), g);
    }

    //Update will have set paintNoProps to the correct value
    if (shouldPaintEmptyMessage()) {
        //We need to paint centered "<No Properties>" text
        g.setFont(c.getFont());
        g.setColor(c.getForeground());

        Rectangle r = getEmptyMessageBounds();

        //See if we really need to do any painting
        if (g.hitClip(r.x, r.y, r.width, r.height)) {
            //Paint the string
            g.drawString(emptyString, r.x, r.y + ascent);
        }
    }
}
 
Example #22
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 #23
Source File: XTextAreaPeer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static Point toViewportChildLocalSpace( JViewport v, Point inViewportParentSpace )
{
    Point l = toLocalSpace(v, inViewportParentSpace);
    Point p = v.getViewPosition();
    l.x += p.x;
    l.y += p.y;
    return l;
}
 
Example #24
Source File: XTextAreaPeer.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static Point toViewportChildLocalSpace( JViewport v, Point inViewportParentSpace )
{
    Point l = toLocalSpace(v, inViewportParentSpace);
    Point p = v.getViewPosition();
    l.x += p.x;
    l.y += p.y;
    return l;
}
 
Example #25
Source File: EditorCaret.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private JViewport getViewport() {
    Component parent = component.getParent();
    if (parent instanceof JLayeredPane) {
        parent = parent.getParent();
    }
    return (parent instanceof JViewport) ? (JViewport) parent : null;
}
 
Example #26
Source File: CustomTreeUI.java    From JPPF with Apache License 2.0 5 votes vote down vote up
@Override
protected AbstractLayoutCache.NodeDimensions createNodeDimensions() {
  return new NodeDimensionsHandler() {
    @Override
    public Rectangle getNodeDimensions(final Object value, final int row, final int depth, final boolean expanded, final Rectangle size) {
      final JViewport port = (JViewport) treeTable.getParent();
      final Rectangle dimensions = super.getNodeDimensions(value, row, depth, expanded, size);
      if (port != null) dimensions.width = port.getWidth();
      return dimensions;
    }
  };
}
 
Example #27
Source File: Preview.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void scrollTo() {
//out("Scroll to: " + myPaperNumber);
        Paper paper = myPapers.get(myPaperNumber - 1);
        int gap = getGap();
        int x = paper.getX() - gap;
        int y = paper.getY() - gap;
        int w = paper.getWidth();
        int h = paper.getHeight();
        JViewport view = myScrollPane.getViewport();

        if ( !view.getViewRect().contains(x, y, w, h)) {
            view.setViewPosition(new Point(x, y));
            updatePaperPanel();
        }
    }
 
Example #28
Source File: PeriodicTasksService.java    From Open-LaTeX-Studio with MIT License 5 votes vote down vote up
private void drawPreview() {
    JPanel pdfImagePanel = pdfDisplay.drawPreviewOnJPanel();
   
    if (pdfImagePanel != null) {
        JViewport vp = jScrollPane.getViewport();
        Point p = vp.getViewPosition();
        vp.setView(pdfImagePanel);
        vp.setViewPosition(p);

    }
    
    jLabel.setText("of " + pdfDisplay.getTotalPages());
}
 
Example #29
Source File: SmoothScrollPaneUI.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void mouseWheelMoved(MouseWheelEvent e) {
    /* The code in this method is taken directly from Pavel Fatin's original IntelliJ patch.
    Some formatting changes have been applied. */
    /* The shift modifier will be enabled for horizontal touchbar scroll events, even when the
    actual shift key is not pressed, on both Windows and MacOS (though not on Java 8 on
    Windows). */
    JScrollBar scrollbar = e.isShiftDown()
            ? scrollpane.getHorizontalScrollBar() : scrollpane.getVerticalScrollBar();
    int orientation = scrollbar.getOrientation();
    JViewport viewport = scrollpane.getViewport();
    if (viewport == null || !(viewport.getView() instanceof Scrollable)) {
        return;
    }
    Scrollable view = (Scrollable) viewport.getView();
    double rotation = e.getPreciseWheelRotation();
    /* Use (0, 0) view position to obtain constant unit increment (which might otherwise be
    variable on smaller-than-unit scrolling). */
    Rectangle r = new Rectangle(new Point(0, 0), viewport.getViewSize());
    int unitIncrement = view.getScrollableUnitIncrement(r, orientation, 1);
    double delta = rotation * e.getScrollAmount() * unitIncrement;
    boolean limitDelta = Math.abs(rotation) < 1.0d + EPSILON;
    int blockIncrement = view.getScrollableBlockIncrement(r, orientation, 1);
    double adjustedDelta = limitDelta
            ? Math.max(-(double) blockIncrement, Math.min(delta, (double) blockIncrement))
            : delta;
    int value = scrollbar.getValue();
    int newValue = Math.max(scrollbar.getMinimum(),
            Math.min((int) Math.round(value + adjustedDelta), scrollbar.getMaximum()));
    if (newValue != value) {
        scrollbar.setValue(newValue);
    }
}
 
Example #30
Source File: UIUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static JViewport getViewport(Container c) {
    if(c == null) {
        return null;
    }
    if(c instanceof JScrollPane) {
        return ((JScrollPane) c).getViewport();
    }
    return getViewport(c.getParent());
}