Search in sources :

Example 11 with JViewport

use of javax.swing.JViewport in project jmeter by apache.

the class ArgumentsPanel method scrollToRowIfNotVisible.

/**
     * ensure that a row is visible in the viewport
     * @param rowIndx row index
     */
private void scrollToRowIfNotVisible(int rowIndx) {
    if (table.getParent() instanceof JViewport) {
        Rectangle visibleRect = table.getVisibleRect();
        final int cellIndex = 0;
        Rectangle cellRect = table.getCellRect(rowIndx, cellIndex, false);
        if (visibleRect.y > cellRect.y) {
            table.scrollRectToVisible(cellRect);
        } else {
            Rectangle rect2 = table.getCellRect(rowIndx + getNumberOfVisibleRows(table), cellIndex, true);
            int width = rect2.y - cellRect.y;
            table.scrollRectToVisible(new Rectangle(cellRect.x, cellRect.y, cellRect.width, cellRect.height + width));
        }
    }
}
Also used : JViewport(javax.swing.JViewport) Rectangle(java.awt.Rectangle)

Example 12 with JViewport

use of javax.swing.JViewport in project jgnash by ccavanaugh.

the class JideScrollPane method setRowFooter.

/**
     * Removes the old rowFooter, if it exists.  If the new rowFooter isn't {@code null}, syncs the y coordinate of
     * its viewPosition with the viewport (if there is one) and then adds it to the scrollpane.
     *
     * @param rowFooter the new row footer to be used; if {@code null} the old row footer is still removed and the
     *                  new rowFooter is set to {@code null}
     * @see #getRowFooter
     * @see #setRowFooterView(java.awt.Component)
     */
private void setRowFooter(JViewport rowFooter) {
    JViewport old = getRowFooter();
    _rowFooter = rowFooter;
    if (null != rowFooter) {
        add(rowFooter, ROW_FOOTER);
    } else if (null != old) {
        remove(old);
    }
    firePropertyChange("rowFooter", old, rowFooter);
    revalidate();
    repaint();
    if (old != null) {
        JideSwingUtilities.unsynchronizeView(old, getViewport());
        JideSwingUtilities.unsynchronizeView(getViewport(), old);
    }
    if (rowFooter != null) {
        JideSwingUtilities.synchronizeView(rowFooter, getViewport(), SwingConstants.VERTICAL);
        JideSwingUtilities.synchronizeView(getViewport(), rowFooter, SwingConstants.VERTICAL);
    }
}
Also used : JViewport(javax.swing.JViewport)

Example 13 with JViewport

use of javax.swing.JViewport in project jgnash by ccavanaugh.

the class JideScrollPane method setColumnHeader.

/**
     * Overrides to make column header viewport synchronizing with the main viewport.
     *
     * @param columnHeader the column header
     */
@Override
public void setColumnHeader(JViewport columnHeader) {
    JViewport old = getColumnHeader();
    super.setColumnHeader(columnHeader);
    if (old != null) {
        JideSwingUtilities.unsynchronizeView(old, getViewport());
    }
    if (getColumnHeader() != null) {
        JideSwingUtilities.synchronizeView(getColumnHeader(), getViewport(), SwingConstants.HORIZONTAL);
    }
}
Also used : JViewport(javax.swing.JViewport)

Example 14 with JViewport

use of javax.swing.JViewport in project jgnash by ccavanaugh.

the class JideSwingUtilities method synchronizeView.

/**
     * Synchronizes the two viewports. The view position changes in the master view, the slave view's view position will
     * change too. Generally speaking, if you want the two viewports to synchronize vertically, they should have the
     * same height. If horizontally, the same width.
     * <p>
     * It's OK if you call this method with the same master viewport and slave viewport duplicate times. It won't cause
     * multiple events fired.
     *
     * @param masterViewport the master viewport
     * @param slaveViewport  the slave viewport
     * @param orientation    the orientation. It could be either SwingConstants.HORIZONTAL or SwingConstants.VERTICAL.
     */
@SuppressWarnings({ "unchecked", "rawtypes" })
public static void synchronizeView(final JViewport masterViewport, final JViewport slaveViewport, final int orientation) {
    if (masterViewport == null || slaveViewport == null) {
        return;
    }
    ChangeListener[] changeListeners = masterViewport.getChangeListeners();
    int i = 0;
    for (; i < changeListeners.length; i++) {
        if (changeListeners[i] == getViewportSynchronizationChangeListener()) {
            break;
        }
    }
    if (i >= changeListeners.length) {
        masterViewport.addChangeListener(getViewportSynchronizationChangeListener());
    }
    Object property = masterViewport.getClientProperty(JideScrollPane.CLIENT_PROPERTY_SLAVE_VIEWPORT);
    if (!(property instanceof Map)) {
        property = new HashMap<JViewport, Integer>();
    }
    Map<JViewport, Integer> slaveViewportMap = (Map) property;
    slaveViewportMap.put(slaveViewport, orientation);
    masterViewport.putClientProperty(JideScrollPane.CLIENT_PROPERTY_SLAVE_VIEWPORT, slaveViewportMap);
    property = slaveViewport.getClientProperty(JideScrollPane.CLIENT_PROPERTY_MASTER_VIEWPORT);
    if (!(property instanceof Map)) {
        property = new HashMap<JViewport, Integer>();
    }
    Map<JViewport, Integer> masterViewportMap = (Map) property;
    masterViewportMap.put(masterViewport, orientation);
    slaveViewport.putClientProperty(JideScrollPane.CLIENT_PROPERTY_MASTER_VIEWPORT, masterViewportMap);
}
Also used : JViewport(javax.swing.JViewport) ChangeListener(javax.swing.event.ChangeListener) Map(java.util.Map) HashMap(java.util.HashMap) Point(java.awt.Point)

Example 15 with JViewport

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

the class UIUtils method createTableScreenshot.

private static BufferedImage createTableScreenshot(Component component) {
    Component source;
    Dimension sourceSize;
    JTable table;
    if (component instanceof JTable) {
        table = (JTable) component;
        if ((table.getTableHeader() == null) || !table.getTableHeader().isVisible()) {
            return createGeneralComponentScreenshot(component);
        }
        source = table;
        sourceSize = table.getSize();
    } else if (component instanceof JViewport && ((JViewport) component).getView() instanceof JTable) {
        JViewport viewport = (JViewport) component;
        table = (JTable) viewport.getView();
        if ((table.getTableHeader() == null) || !table.getTableHeader().isVisible()) {
            return createGeneralComponentScreenshot(component);
        }
        if (table.getSize().height > viewport.getSize().height) {
            source = viewport;
            sourceSize = viewport.getSize();
        } else {
            source = table;
            sourceSize = table.getSize();
        }
    } else {
        // NOI18N
        throw new IllegalArgumentException("Component can only be JTable or JViewport holding JTable");
    }
    final JTableHeader tableHeader = table.getTableHeader();
    Dimension tableHeaderSize = tableHeader.getSize();
    BufferedImage tableScreenshot = new BufferedImage(sourceSize.width, tableHeaderSize.height + sourceSize.height, BufferedImage.TYPE_INT_RGB);
    final Graphics tableScreenshotGraphics = tableScreenshot.getGraphics();
    // Component.printAll has to run in AWT Thread to print component contents correctly
    if (SwingUtilities.isEventDispatchThread()) {
        tableHeader.printAll(tableScreenshotGraphics);
    } else {
        try {
            SwingUtilities.invokeAndWait(new Runnable() {

                @Override
                public void run() {
                    tableHeader.printAll(tableScreenshotGraphics);
                }
            });
        } catch (Exception e) {
        }
    }
    tableScreenshotGraphics.translate(0, tableHeaderSize.height);
    final Component printSrc = source;
    // Component.printAll has to run in AWT Thread to print component contents correctly
    if (SwingUtilities.isEventDispatchThread()) {
        printSrc.printAll(tableScreenshotGraphics);
    } else {
        try {
            SwingUtilities.invokeAndWait(new Runnable() {

                @Override
                public void run() {
                    printSrc.printAll(tableScreenshotGraphics);
                }
            });
        } catch (Exception e) {
        }
    }
    return tableScreenshot;
}
Also used : Graphics(java.awt.Graphics) JViewport(javax.swing.JViewport) JTable(javax.swing.JTable) JTableHeader(javax.swing.table.JTableHeader) Dimension(java.awt.Dimension) Component(java.awt.Component) BufferedImage(java.awt.image.BufferedImage) InvocationTargetException(java.lang.reflect.InvocationTargetException)

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