Search in sources :

Example 26 with Panel

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);
}
Also used : Panel(java.awt.Panel) GridBagConstraints(java.awt.GridBagConstraints) Frame(java.awt.Frame) GridBagLayout(java.awt.GridBagLayout) BorderLayout(java.awt.BorderLayout) ScrollPane(java.awt.ScrollPane) Dimension(java.awt.Dimension) Component(java.awt.Component) Point(java.awt.Point)

Example 27 with Panel

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;
}
Also used : Panel(java.awt.Panel) BorderLayout(java.awt.BorderLayout)

Example 28 with 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;
}
Also used : Panel(java.awt.Panel) JPanel(javax.swing.JPanel) Checkbox(java.awt.Checkbox) GenericDialog(ij.gui.GenericDialog) BufferedImageReader(loci.formats.gui.BufferedImageReader) Dimension(java.awt.Dimension)

Example 29 with Panel

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());
    }
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) AERunnable(com.biglybt.core.util.AERunnable) Frame(java.awt.Frame) UISWTViewEventListener(com.biglybt.ui.swt.pif.UISWTViewEventListener) UIPluginViewToolBarListener(com.biglybt.pif.ui.UIPluginViewToolBarListener) CTabFolder(org.eclipse.swt.custom.CTabFolder) CTabFolder(org.eclipse.swt.custom.CTabFolder) FillLayout(org.eclipse.swt.layout.FillLayout) Panel(java.awt.Panel) GridLayout(org.eclipse.swt.layout.GridLayout) FillLayout(org.eclipse.swt.layout.FillLayout) FormLayout(org.eclipse.swt.layout.FormLayout) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) UISWTViewEvent(com.biglybt.ui.swt.pif.UISWTViewEvent) LogEvent(com.biglybt.core.logging.LogEvent)

Example 30 with Panel

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.
        }
    }
}
Also used : Graphics(java.awt.Graphics) Panel(java.awt.Panel) Frame(java.awt.Frame) HeadlessException(java.awt.HeadlessException) WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter) Dimension(java.awt.Dimension)

Aggregations

Panel (java.awt.Panel)70 BorderLayout (java.awt.BorderLayout)26 Button (java.awt.Button)25 Label (java.awt.Label)25 Frame (java.awt.Frame)18 GridBagLayout (java.awt.GridBagLayout)17 TextField (java.awt.TextField)17 GridBagConstraints (java.awt.GridBagConstraints)16 JPanel (javax.swing.JPanel)14 Dimension (java.awt.Dimension)13 Insets (java.awt.Insets)10 Point (java.awt.Point)10 Choice (java.awt.Choice)9 FlowLayout (java.awt.FlowLayout)9 Graphics (java.awt.Graphics)9 Checkbox (java.awt.Checkbox)7 GridLayout (java.awt.GridLayout)7 Font (java.awt.Font)6 JButton (javax.swing.JButton)6 Component (java.awt.Component)5