Search in sources :

Example 16 with JViewport

use of javax.swing.JViewport in project gephi by gephi.

the class UIUtils method createGeneralComponentScreenshot.

private static BufferedImage createGeneralComponentScreenshot(Component component) {
    Component source;
    Dimension sourceSize;
    if (component instanceof JViewport) {
        JViewport viewport = (JViewport) component;
        Component contents = viewport.getView();
        if (contents.getSize().height > viewport.getSize().height) {
            source = component;
            sourceSize = component.getSize();
        } else {
            source = contents;
            sourceSize = contents.getSize();
        }
    } else {
        source = component;
        sourceSize = component.getSize();
    }
    BufferedImage componentScreenshot = new BufferedImage(sourceSize.width, sourceSize.height, BufferedImage.TYPE_INT_RGB);
    Graphics componentScreenshotGraphics = componentScreenshot.getGraphics();
    source.printAll(componentScreenshotGraphics);
    return componentScreenshot;
}
Also used : Graphics(java.awt.Graphics) JViewport(javax.swing.JViewport) Dimension(java.awt.Dimension) Component(java.awt.Component) BufferedImage(java.awt.image.BufferedImage)

Example 17 with JViewport

use of javax.swing.JViewport in project zaproxy by zaproxy.

the class ZapTable method getEnclosingScrollPane.

/**
     * {@inheritDoc}
     * <p>
     * Overridden to take into account for possible parent {@code JLayer}s.
     * </p>
     * 
     * @see javax.swing.JLayer
     */
// Note: Same implementation as in JXTable#getEnclosingScrollPane() but changed to get the parent and viewport view using
// the methods SwingUtilities#getUnwrappedParent(Component) and SwingUtilities#getUnwrappedView(JViewport) respectively.
@Override
protected JScrollPane getEnclosingScrollPane() {
    Container p = SwingUtilities.getUnwrappedParent(this);
    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 || SwingUtilities.getUnwrappedView(viewport) != this) {
                return null;
            }
            return scrollPane;
        }
    }
    return null;
}
Also used : JScrollPane(javax.swing.JScrollPane) Container(java.awt.Container) JViewport(javax.swing.JViewport)

Example 18 with JViewport

use of javax.swing.JViewport in project jdk8u_jdk by JetBrains.

the class InsetsEncapsulation method run.

@Override
public void run() {
    runTest(new JLabel("hi"));
    runTest(new JMenu());
    runTest(new JTree());
    runTest(new JTable());
    runTest(new JMenuItem());
    runTest(new JCheckBoxMenuItem());
    runTest(new JToggleButton());
    runTest(new JSpinner());
    runTest(new JSlider());
    runTest(Box.createVerticalBox());
    runTest(Box.createHorizontalBox());
    runTest(new JTextField());
    runTest(new JTextArea());
    runTest(new JTextPane());
    runTest(new JPasswordField());
    runTest(new JFormattedTextField());
    runTest(new JEditorPane());
    runTest(new JButton());
    runTest(new JColorChooser());
    runTest(new JFileChooser());
    runTest(new JCheckBox());
    runTest(new JInternalFrame());
    runTest(new JDesktopPane());
    runTest(new JTableHeader());
    runTest(new JLayeredPane());
    runTest(new JRootPane());
    runTest(new JMenuBar());
    runTest(new JOptionPane());
    runTest(new JRadioButton());
    runTest(new JRadioButtonMenuItem());
    runTest(new JPopupMenu());
    runTest(new JScrollBar());
    runTest(new JScrollPane());
    runTest(new JViewport());
    runTest(new JSplitPane());
    runTest(new JTabbedPane());
    runTest(new JToolBar());
    runTest(new JSeparator());
    runTest(new JProgressBar());
    if (!failures.isEmpty()) {
        System.out.println("These classes failed");
        for (final Component failure : failures) {
            System.out.println(failure.getClass());
        }
        throw new RuntimeException("Test failed");
    }
}
Also used : JDesktopPane(javax.swing.JDesktopPane) JTextArea(javax.swing.JTextArea) JRadioButton(javax.swing.JRadioButton) JLayeredPane(javax.swing.JLayeredPane) JTabbedPane(javax.swing.JTabbedPane) JButton(javax.swing.JButton) JProgressBar(javax.swing.JProgressBar) JTableHeader(javax.swing.table.JTableHeader) JTextField(javax.swing.JTextField) JSeparator(javax.swing.JSeparator) JScrollBar(javax.swing.JScrollBar) JTextPane(javax.swing.JTextPane) JToggleButton(javax.swing.JToggleButton) JSlider(javax.swing.JSlider) JMenuItem(javax.swing.JMenuItem) JComponent(javax.swing.JComponent) Component(java.awt.Component) JScrollPane(javax.swing.JScrollPane) JViewport(javax.swing.JViewport) JFormattedTextField(javax.swing.JFormattedTextField) JLabel(javax.swing.JLabel) JRadioButtonMenuItem(javax.swing.JRadioButtonMenuItem) JToolBar(javax.swing.JToolBar) JOptionPane(javax.swing.JOptionPane) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem) JPopupMenu(javax.swing.JPopupMenu) JCheckBox(javax.swing.JCheckBox) JTree(javax.swing.JTree) JFileChooser(javax.swing.JFileChooser) JPasswordField(javax.swing.JPasswordField) JTable(javax.swing.JTable) JEditorPane(javax.swing.JEditorPane) JSpinner(javax.swing.JSpinner) JRootPane(javax.swing.JRootPane) JSplitPane(javax.swing.JSplitPane) JColorChooser(javax.swing.JColorChooser) JInternalFrame(javax.swing.JInternalFrame) JMenu(javax.swing.JMenu) JMenuBar(javax.swing.JMenuBar)

Example 19 with JViewport

use of javax.swing.JViewport in project jdk8u_jdk by JetBrains.

the class Test6526631 method validateThird.

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");
    }
}
Also used : JViewport(javax.swing.JViewport) JScrollBar(javax.swing.JScrollBar)

Example 20 with JViewport

use of javax.swing.JViewport in project JMRI by JMRI.

the class ControlPanelEditor method zoomToFit.

private void zoomToFit() {
    double minX = 1000.0;
    double maxX = 0.0;
    double minY = 1000.0;
    double maxY = 0.0;
    List<Positionable> contents = getContents();
    for (Positionable p : contents) {
        minX = Math.min(p.getX(), minX);
        minY = Math.min(p.getY(), minY);
        maxX = Math.max(p.getX() + p.getWidth(), maxX);
        maxY = Math.max(p.getY() + p.getHeight(), maxY);
    }
    _fitX = (int) Math.floor(minX);
    _fitY = (int) Math.floor(minY);
    JFrame frame = getTargetFrame();
    Container contentPane = getTargetFrame().getContentPane();
    Dimension dim = contentPane.getSize();
    Dimension d = getTargetPanel().getSize();
    getTargetPanel().setSize((int) Math.ceil(maxX - minX), (int) Math.ceil(maxY - minY));
    JScrollPane scrollPane = getPanelScrollPane();
    scrollPane.getHorizontalScrollBar().setValue(0);
    scrollPane.getVerticalScrollBar().setValue(0);
    JViewport viewPort = scrollPane.getViewport();
    Dimension dv = viewPort.getExtentSize();
    int dX = frame.getWidth() - dv.width;
    int dY = frame.getHeight() - dv.height;
    log.debug("zoomToFit: layoutWidth= {}, layoutHeight= {}\n\tframeWidth= {}, frameHeight= {}, viewWidth= {}, viewHeight= {}\n\tconWidth= {}, conHeight= {}, panelWidth= {}, panelHeight= {}", (maxX - minX), (maxY - minY), frame.getWidth(), frame.getHeight(), dv.width, dv.height, dim.width, dim.height, d.width, d.height);
    double ratioX = dv.width / (maxX - minX);
    double ratioY = dv.height / (maxY - minY);
    double ratio = Math.min(ratioX, ratioY);
    /*
         if (ratioX<ratioY) {
         if (ratioX>1.0) {
         ratio = ratioX;
         } else {
         ratio = ratioY;
         }
         } else {
         if (ratioY<1.0) {
         ratio = ratioX;
         } else {
         ratio = ratioY;
         }
         } */
    _fitX = (int) Math.floor(minX);
    _fitY = (int) Math.floor(minY);
    for (Positionable p : contents) {
        p.setLocation(p.getX() - _fitX, p.getY() - _fitY);
    }
    setScroll(SCROLL_BOTH);
    setPaintScale(ratio);
    setScroll(SCROLL_NONE);
    scrollNone.setSelected(true);
    //getTargetPanel().setSize((int)Math.ceil(maxX), (int)Math.ceil(maxY));
    frame.setSize((int) Math.ceil((maxX - minX) * ratio) + dX, (int) Math.ceil((maxY - minY) * ratio) + dY);
    scrollPane.getHorizontalScrollBar().setValue(0);
    scrollPane.getVerticalScrollBar().setValue(0);
    log.debug("zoomToFit: ratio= {}, w= {}, h= {}, frameWidth= {}, frameHeight= {}", ratio, (maxX - minX), (maxY - minY), frame.getWidth(), frame.getHeight());
}
Also used : JScrollPane(javax.swing.JScrollPane) Container(java.awt.Container) JFrame(javax.swing.JFrame) JViewport(javax.swing.JViewport) Positionable(jmri.jmrit.display.Positionable) Dimension(java.awt.Dimension) Point(java.awt.Point)

Aggregations

JViewport (javax.swing.JViewport)33 JScrollPane (javax.swing.JScrollPane)12 Component (java.awt.Component)9 Container (java.awt.Container)8 Dimension (java.awt.Dimension)7 Point (java.awt.Point)5 Rectangle (java.awt.Rectangle)5 RTextScrollPane (org.fife.ui.rtextarea.RTextScrollPane)3 Graphics (java.awt.Graphics)2 BufferedImage (java.awt.image.BufferedImage)2 JButton (javax.swing.JButton)2 JCheckBox (javax.swing.JCheckBox)2 JCheckBoxMenuItem (javax.swing.JCheckBoxMenuItem)2 JColorChooser (javax.swing.JColorChooser)2 JComponent (javax.swing.JComponent)2 JDesktopPane (javax.swing.JDesktopPane)2 JScrollBar (javax.swing.JScrollBar)2 JTabbedPane (javax.swing.JTabbedPane)2 JTable (javax.swing.JTable)2 ChangeListener (javax.swing.event.ChangeListener)2