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