Java Code Examples for javax.swing.JViewport

The following examples show how to use javax.swing.JViewport. These examples are extracted from open source projects. 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 Project: openjdk-jdk9   Source File: Test6526631.java    License: 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 Project: jdk8u-jdk   Source File: Test6526631.java    License: 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 Project: netbeans   Source File: Utilities.java    License: 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 4
Source Project: openAGV   Source File: ViewDragScrollListener.java    License: 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 Project: pcgen   Source File: JDynamicTable.java    License: 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 6
Source Project: jdk8u-dev-jdk   Source File: Test6526631.java    License: 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 Project: mzmine3   Source File: ScrollablePanel.java    License: 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 8
Source Project: org.alloytools.alloy   Source File: GraphViewer.java    License: 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 9
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 10
Source Project: FancyBing   Source File: GtpShell.java    License: 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 11
Source Project: javamelody   Source File: MBasicTable.java    License: 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 12
Source Project: magarena   Source File: ScrollablePanel.java    License: 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 13
Source Project: pcgen   Source File: JTreeViewTable.java    License: 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 14
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 15
Source Project: netbeans   Source File: ETable.java    License: 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 16
Source Project: openjdk-8   Source File: Test6526631.java    License: 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 17
Source Project: netbeans   Source File: ZoomManager.java    License: 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 18
Source Project: netbeans   Source File: NbEditorUI.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean getScrollableTracksViewportWidth() {
    Container parent = SwingUtilities.getUnwrappedParent(this);
    if (parent instanceof JViewport) {
        return parent.getWidth() > getPreferredSize().width;
    }
    return false;
}
 
Example 19
Source Project: seaglass   Source File: SeaGlassTableUI.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a {@link Border} that paints any empty space to the right of the
 * last column header in the given {@link JTable}'s {@link JTableHeader}.
 *
 * @param  table DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 */
private static Border createTableHeaderEmptyColumnPainter(final JTable table) {
    return new AbstractBorder() {
        @Override
        public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
            // if this JTableHeader is parented in a JViewport, then paint
            // the table header background to the right of the last column
            // if neccessary.
            Container viewport = table.getParent();

            if ((viewport instanceof JViewport) && table.getWidth() < viewport.getWidth()) {
                int startX           = table.getWidth();
                int emptyColumnWidth = viewport.getWidth() - table.getWidth();

                TableCellRenderer renderer  = table.getTableHeader().getDefaultRenderer();
                // Rossi: Fix for indexoutofbounds exception: A try catch might be good too?
                Component         component = renderer.getTableCellRendererComponent(table, "", false, false, 0, table.getColumnCount()-1);

                component.setBounds(0, 0, emptyColumnWidth, table.getTableHeader().getHeight());

                ((JComponent) component).setOpaque(true);
                CELL_RENDER_PANE.paintComponent(g, component, null, startX, 0, emptyColumnWidth + 1,
                                                table.getTableHeader().getHeight(), true);
            }
        }
    };
}
 
Example 20
Source Project: netbeans   Source File: DebuggingViewComponent.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void adjustmentValueChanged(AdjustmentEvent e) {
    DebugTreeView tView = getTreeView();
    if (tView == null) {
        return;
    }
    JViewport viewport = tView.getViewport();
    Point position = viewport.getViewPosition();
    viewport.setViewPosition(new Point(e.getValue(), position.y));
}
 
Example 21
Source Project: FlatLaf   Source File: FlatScrollPaneUI.java    License: Apache License 2.0 5 votes vote down vote up
private void addViewportListeners( JViewport viewport ) {
	if( viewport == null )
		return;

	viewport.addContainerListener( getHandler() );

	Component view = viewport.getView();
	if( view != null )
		view.addFocusListener( getHandler() );
}
 
Example 22
Source Project: gcs   Source File: UIUtilities.java    License: Mozilla Public License 2.0 5 votes vote down vote up
/**
 * @param comp The component to work with.
 * @return Whether the component should be expanded to fit.
 */
public static boolean shouldTrackViewportWidth(Component comp) {
    Container parent = comp.getParent();
    if (parent instanceof JViewport) {
        Dimension available = parent.getSize();
        Dimension prefSize  = comp.getPreferredSize();
        return prefSize.width < available.width;
    }
    return false;
}
 
Example 23
Source Project: jdk8u_jdk   Source File: XTextAreaPeer.java    License: 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
public void stateChanged(ChangeEvent e) {
	// Keep the scrolling of the row table in sync with main table

	JViewport viewport = (JViewport) e.getSource();
	JScrollPane scrollPane = (JScrollPane) viewport.getParent();
	scrollPane.getVerticalScrollBar()
			.setValue(viewport.getViewPosition().y);
}
 
Example 25
Source Project: swingsane   Source File: PreviewPanel.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public final void mouseDragged(MouseEvent e) {
  JViewport vport = ((JScrollPane) e.getSource()).getViewport();
  Point cp = e.getPoint();
  Point vp = vport.getViewPosition();
  vp.translate(pp.x - cp.x, pp.y - cp.y);
  imagePreviewLabel.scrollRectToVisible(new Rectangle(vp, vport.getSize()));
  pp.setLocation(cp);
}
 
Example 26
/**
 * Maps {@code JScrollPane.getRowHeader()} through queue
 */
public JViewport getRowHeader() {
    return (runMapping(new MapAction<JViewport>("getRowHeader") {
        @Override
        public JViewport map() {
            return ((JScrollPane) getSource()).getRowHeader();
        }
    }));
}
 
Example 27
Source Project: pumpernickel   Source File: TileLocationBrowserUI.java    License: MIT License 5 votes vote down vote up
private void updateRowCount() {
	// TODO: adjust the visible row(s)?
	// that is: emphasize the selection, or else cells that were
	// previously visible before changing the row count.
	int width = list.getWidth();
	if (list.getParent() instanceof JViewport) {
		JViewport p = (JViewport) list.getParent();
		width = p.getWidth();
	}
	list.updateVisibleRowCount(width);
}
 
Example 28
Source Project: netbeans   Source File: BraceMatchingSidebarComponent.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
public BraceMatchingSidebarComponent(JTextComponent editor) {
    this.editor = editor;
    this.mimeType = DocumentUtilities.getMimeType(editor);
    this.prefs = MimeLookup.getLookup(MimePath.EMPTY).lookup(Preferences.class);
    
    final Lookup.Result r = MimeLookup.getLookup(org.netbeans.lib.editor.util.swing.DocumentUtilities.getMimeType(editor)).lookupResult(
            FontColorSettings.class);
    prefListenerGC = new PrefListener();
    this.colorResult = r;
    r.addLookupListener(WeakListeners.create(LookupListener.class, this , r));
    prefs.addPreferenceChangeListener(WeakListeners.create(PreferenceChangeListener.class, prefListenerGC, prefs));
    loadPreferences();
    
    editorPane = findEditorPane(editor);
    Component parent = editor.getParent();
    if (parent instanceof JLayeredPane) {
        parent = parent.getParent();
    }
    if (parent instanceof JViewport) {
        this.viewport = (JViewport)parent;
        // see #219015; need to listen on viewport change to show/hide the tooltip
        viewport.addChangeListener(WeakListeners.change(this, viewport));
    }
    TextUI ui = editor.getUI();
    if (ui instanceof BaseTextUI) {
        baseUI = (BaseTextUI)ui;
        MasterMatcher.get(editor).addMatchListener(this);
    } else {
        baseUI = null;
    }
    setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));
    updatePreferredSize();
}
 
Example 29
Source Project: TencentKona-8   Source File: XTextAreaPeer.java    License: 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 30
Source Project: netbeans   Source File: DebuggingViewComponent.java    License: 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
}