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));
}
}
}
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);
}
}
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);
}
}
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);
}
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;
}
Aggregations