use of java.awt.Panel in project bioformats by openmicroscopy.
the class WindowTools method addScrollBars.
// -- Utility methods --
/**
* Adds AWT scroll bars to the given container.
*/
public static void addScrollBars(Container pane) {
GridBagLayout layout = (GridBagLayout) pane.getLayout();
// extract components
int count = pane.getComponentCount();
Component[] c = new Component[count];
GridBagConstraints[] gbc = new GridBagConstraints[count];
for (int i = 0; i < count; i++) {
c[i] = pane.getComponent(i);
gbc[i] = layout.getConstraints(c[i]);
}
// clear components
pane.removeAll();
layout.invalidateLayout(pane);
// create new container panel
Panel newPane = new Panel();
GridBagLayout newLayout = new GridBagLayout();
newPane.setLayout(newLayout);
for (int i = 0; i < count; i++) {
newLayout.setConstraints(c[i], gbc[i]);
newPane.add(c[i]);
}
// HACK - get preferred size for container panel
// NB: don't know a better way:
// - newPane.getPreferredSize() doesn't work
// - newLayout.preferredLayoutSize(newPane) doesn't work
Frame f = new Frame();
f.setLayout(new BorderLayout());
f.add(newPane, BorderLayout.CENTER);
f.pack();
final Dimension size = newPane.getSize();
f.remove(newPane);
f.dispose();
// compute best size for scrollable viewport
size.width += 25;
size.height += 15;
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
int maxWidth = 7 * screen.width / 8;
int maxHeight = 3 * screen.height / 4;
if (size.width > maxWidth)
size.width = maxWidth;
if (size.height > maxHeight)
size.height = maxHeight;
// create scroll pane
ScrollPane scroll = new ScrollPane() {
@Override
public Dimension getPreferredSize() {
return size;
}
};
scroll.add(newPane);
// add scroll pane to original container
GridBagConstraints constraints = new GridBagConstraints();
constraints.gridwidth = GridBagConstraints.REMAINDER;
constraints.fill = GridBagConstraints.BOTH;
constraints.weightx = 1.0;
constraints.weighty = 1.0;
layout.setConstraints(scroll, constraints);
pane.add(scroll);
}
use of java.awt.Panel in project bioformats by openmicroscopy.
the class DataBrowser method makeHeavyPanel.
/**
* Makes AWT play nicely with Swing components.
*/
protected static Panel makeHeavyPanel(Component c) {
Panel panel = new Panel();
panel.setLayout(new BorderLayout());
panel.add(c, BorderLayout.CENTER);
return panel;
}
use of java.awt.Panel in project bioformats by openmicroscopy.
the class SeriesDialog method constructDialog.
@Override
protected GenericDialog constructDialog() {
final int seriesCount = process.getSeriesCount();
// NB: Load thumbnails only when series count is modest.
if (seriesCount < MAX_SERIES_THUMBS) {
// construct thumbnail reader
thumbReader = new BufferedImageReader(process.getReader());
// set up the thumbnail panels
p = new Panel[seriesCount];
for (int i = 0; i < seriesCount; i++) {
thumbReader.setSeries(i);
// a little extra padding
int sx = thumbReader.getThumbSizeX() + 10;
int sy = thumbReader.getThumbSizeY();
p[i] = new Panel();
p[i].add(Box.createRigidArea(new Dimension(sx, sy)));
if (options.isForceThumbnails()) {
// load thumbnail immediately
ThumbLoader.loadThumb(thumbReader, i, p[i], options.isQuiet());
}
}
}
GenericDialog gd = new GenericDialog("Bio-Formats Series Options");
// NB: Provide individual checkboxes only when series count is manageable.
if (seriesCount < MAX_SERIES_TOGGLES) {
// NB: We need to add the checkboxes in groups, to prevent an
// exception from being thrown if there are more than 512 series.
// See also:
// http://dev.loci.wisc.edu/trac/java/ticket/408 and
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5107980
final int nGroups = (seriesCount + MAX_COMPONENTS - 1) / MAX_COMPONENTS;
int nextSeries = 0;
for (int i = 0; i < nGroups; i++) {
final int nRows = Math.min(MAX_COMPONENTS, seriesCount - nextSeries);
final String[] labels = new String[nRows];
final boolean[] defaultValues = new boolean[nRows];
for (int row = 0; row < nRows; row++) {
labels[row] = process.getSeriesLabel(nextSeries);
defaultValues[row] = options.isSeriesOn(nextSeries);
nextSeries++;
}
gd.addCheckboxGroup(nRows, 1, labels, defaultValues);
}
// extract checkboxes, for "Select All" and "Deselect All" functions
boxes = WindowTools.getCheckboxes(gd).toArray(new Checkbox[0]);
// rebuild dialog so that the thumbnails and checkboxes line up correctly
rebuildDialog(gd, nGroups);
} else {
// too many series; display a simple text field for specifying series
gd.addMessage("Please specify the image series you wish to import.\n" + "Use commas to list multiple series. You can also use\n" + "a dash to represent a range of series. For example,\n" + "to import series 1, 3, 4, 5, 7, 8, 9, 12, 15 & 16,\n" + "you could write: 1, 3-5, 7-9, 12, 15-16\n \n" + "There are " + seriesCount + " total series.");
gd.addStringField("Series_list: ", "1");
}
return gd;
}
use of java.awt.Panel in project BiglyBT by BiglySoftware.
the class UISWTViewImpl method initialize.
/* (non-Javadoc)
* @see com.biglybt.ui.swt.pifimpl.UISWTViewCore#initialize(org.eclipse.swt.widgets.Composite)
*/
@Override
public void initialize(Composite parent) {
this.masterComposite = parent;
if (iControlType == UISWTView.CONTROLTYPE_SWT) {
GridData gridData;
Layout parentLayout = parent.getLayout();
if (parentLayout instanceof FormLayout) {
composite = parent;
} else {
composite = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout(1, false);
layout.marginHeight = 0;
layout.marginWidth = 0;
composite.setLayout(layout);
gridData = new GridData(GridData.FILL_BOTH);
composite.setLayoutData(gridData);
}
Listener showListener = new Listener() {
@Override
public void handleEvent(Event event) {
if (composite == null || composite.isDisposed()) {
return;
}
Composite parent = composite.getParent();
if (parent instanceof CTabFolder) {
CTabFolder tabFolder = (CTabFolder) parent;
Control selectedControl = tabFolder.getSelection().getControl();
if (selectedControl != composite) {
return;
}
} else if (parent instanceof TabFolder) {
TabFolder tabFolder = (TabFolder) parent;
TabItem[] selectedControl = tabFolder.getSelection();
if (selectedControl != null && selectedControl.length == 1 && selectedControl[0].getControl() != composite) {
return;
}
}
// Delay trigger of FOCUSGAINED a bit, so that parent is visible
Utils.execSWTThreadLater(0, new AERunnable() {
@Override
public void runSupport() {
triggerEvent(UISWTViewEvent.TYPE_FOCUSGAINED, null);
}
});
}
};
composite.addListener(SWT.Show, showListener);
if (parent != composite) {
parent.addListener(SWT.Show, showListener);
}
if (composite.isVisible()) {
boolean focusGained = true;
if (parent instanceof CTabFolder || (parent instanceof TabFolder)) {
// can't be gaining the focus yet.. we just created it and
// it hasn't been assigned to TabFolder yet
focusGained = false;
}
if (focusGained) {
triggerEvent(UISWTViewEvent.TYPE_FOCUSGAINED, null);
}
}
if (delayInitializeToFirstActivate) {
return;
}
swt_triggerInitialize();
} else if (iControlType == UISWTView.CONTROLTYPE_AWT) {
composite = new Composite(parent, SWT.EMBEDDED);
FillLayout layout = new FillLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
composite.setLayout(layout);
GridData gridData = new GridData(GridData.FILL_BOTH);
composite.setLayoutData(gridData);
Frame f = SWT_AWT.new_Frame(composite);
Panel pan = new Panel();
f.add(pan);
triggerEvent(UISWTViewEvent.TYPE_INITIALIZE, pan);
} else if (iControlType == UISWTViewCore.CONTROLTYPE_SKINOBJECT) {
triggerEvent(UISWTViewEvent.TYPE_INITIALIZE, getPluginSkinObject());
}
}
use of java.awt.Panel in project imageio-ext by geosolutions-it.
the class ImageAssert method showImage.
public static void showImage(String title, long timeOut, final BufferedImage image) throws InterruptedException {
final String headless = System.getProperty("java.awt.headless", "false");
if (!headless.equalsIgnoreCase("true")) {
try {
Frame frame = new Frame(title);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
e.getWindow().dispose();
}
});
Panel p = new Panel() {
/**
* <code>serialVersionUID</code> field
*/
private static final long serialVersionUID = 1L;
{
setPreferredSize(new Dimension(image.getWidth(), image.getHeight()));
}
public void paint(Graphics g) {
g.drawImage(image, 0, 0, this);
}
};
frame.add(p);
frame.pack();
frame.setVisible(true);
Thread.sleep(timeOut);
frame.dispose();
} catch (HeadlessException exception) {
// The test is running on a machine without X11 display. Ignore.
}
}
}
Aggregations