Example usage for java.awt Container addHierarchyBoundsListener

List of usage examples for java.awt Container addHierarchyBoundsListener

Introduction

In this page you can find the example usage for java.awt Container addHierarchyBoundsListener.

Prototype

public void addHierarchyBoundsListener(HierarchyBoundsListener l) 

Source Link

Document

Adds the specified hierarchy bounds listener to receive hierarchy bounds events from this component when the hierarchy to which this container belongs changes.

Usage

From source file:org.openmicroscopy.shoola.agents.imviewer.view.ImViewerUI.java

/** Builds and lays out the GUI. */
private void buildGUI() {
    Browser browser = model.getBrowser();
    int sizeX = model.getTiledImageSizeX();
    int sizeY = model.getTiledImageSizeY();

    browser.setComponentsSize(sizeX, sizeY);
    tabs = new ClosableTabbedPane(JTabbedPane.TOP, JTabbedPane.WRAP_TAB_LAYOUT);
    tabs.setAlignmentX(LEFT_ALIGNMENT);/*from   w ww.  j  a v  a 2s .c  o m*/

    viewPanel = new ClosableTabbedPaneComponent(ImViewer.VIEW_INDEX, browser.getTitle(), browser.getIcon(), "");
    viewPanel.setClosable(false);
    double[][] tl = { { TableLayout.PREFERRED, TableLayout.FILL },
            { TableLayout.FILL, TableLayout.PREFERRED, TableLayout.PREFERRED } };
    viewPanel.setLayout(new TableLayout(tl));
    viewPanel.add(controlPane, "0, 0");
    viewPanel.add(browser.getUI(), "1, 0");
    viewPanel.add(controlPane.getTimeSliderPane(ImViewer.VIEW_INDEX), "1, 1");
    if (model.isLifetimeImage()) {
        viewPanel.add(controlPane.getLifetimeSliderPane(ImViewer.VIEW_INDEX), "1, 2");
    }
    tabbedIconHeight = browser.getIcon().getIconHeight() + ICON_EXTRA;

    tabs.insertTab(browser.getTitle(), browser.getIcon(), viewPanel, "", ImViewer.VIEW_INDEX);
    gridViewPanel = new ClosableTabbedPaneComponent(ImViewer.GRID_INDEX, browser.getGridViewTitle(),
            browser.getGridViewIcon(), "");
    gridViewPanel.setLayout(new TableLayout(tl));

    gridViewPanel.add(controlPane.buildGridComponent(), "0, 0");
    gridViewPanel.add(browser.getGridView(), "1, 0");
    gridViewPanel.add(controlPane.getTimeSliderPane(ImViewer.GRID_INDEX), "1, 1");
    if (model.isLifetimeImage()) {
        gridViewPanel.add(controlPane.getLifetimeSliderPane(ImViewer.GRID_INDEX), "1, 2");
    }
    if (model.allowSplitView() && !model.isBigImage()) {
        tabs.insertTab(browser.getGridViewTitle(), browser.getGridViewIcon(), gridViewPanel, "",
                ImViewer.GRID_INDEX);
    }

    double[][] tl2 = { { TableLayout.PREFERRED, TableLayout.FILL },
            { TableLayout.PREFERRED, TableLayout.FILL, TableLayout.PREFERRED } };

    projectionViewPanel = new ClosableTabbedPaneComponent(ImViewer.PROJECTION_INDEX,
            browser.getProjectionViewTitle(), browser.getProjectionViewIcon(), "");

    projectionViewPanel.setLayout(new TableLayout(tl2));
    projectionViewPanel.add(controlPane.buildProjectionToolBar(), "0, 0, 1, 0");
    projectionViewPanel.add(controlPane.buildProjectionComponent(), "0, 1");
    projectionViewPanel.add(browser.getProjectionView(), "1, 1");
    projectionViewPanel.add(controlPane.getTimeSliderPane(ImViewer.PROJECTION_INDEX), "1, 2");
    if (model.getMaxZ() > 0 && !model.isBigImage()) {
        tabs.insertTab(browser.getProjectionViewTitle(), browser.getProjectionViewIcon(), projectionViewPanel,
                "", ImViewer.PROJECTION_INDEX);
    }

    tabs.addChangeListener(controller);

    //mainComponent = tabs;
    rendererSplit.setLeftComponent(tabs);
    mainComponent = rendererSplit;

    Container container = getContentPane();
    container.setLayout(new BorderLayout(0, 0));
    container.add(toolBar, BorderLayout.NORTH);
    container.add(mainComponent, BorderLayout.CENTER);
    container.add(statusBar, BorderLayout.SOUTH);

    //attach listener to the frame border
    boundsAdapter = new HierarchyBoundsAdapter() {

        /**
         * Stores the size of the tab pane when the frame is resized.
         * @see HierarchyBoundsListener#ancestorResized(HierarchyEvent)
         */
        public void ancestorResized(HierarchyEvent e) {
            if (tabs != null)
                restoreSize = tabs.getSize();
        }
    };
    container.addHierarchyBoundsListener(boundsAdapter);
    //restoreSize = new Dimension(0, 0);
    //layoutComponents(false);
}

From source file:org.openmicroscopy.shoola.agents.imviewer.view.ImViewerUI.java

/** 
 * Lays out the components composing main panel. 
 * /* www .  j  ava 2 s  .c o  m*/
 * @param fromPreferences   Pass <code>true</code> to indicate that the 
 *                      method is invoked while setting the user 
 *                      preferences, <code>false</code> otherwise.
 */
private void layoutComponents(boolean fromPreferences) {
    //initSplitPanes();
    Dimension d;
    int diff;
    Container container = getContentPane();
    container.removeHierarchyBoundsListener(boundsAdapter);
    int width = 0, height = 0;
    JComponent rightComponent;
    //int divider = 0;
    int vExtra = 2;
    int addition;
    switch (displayMode) {
    case RENDERER:
        rightComponent = model.getMetadataViewer().getEditorUI();
        rendererSplit.setRightComponent(rightComponent);
        if (restoreSize == null) {
            rendererSplit.setResizeWeight(1.0);
            return;
        }
        d = model.getMetadataViewer().getIdealRendererSize();
        rightComponent.setMinimumSize(d);
        tabs.setMinimumSize(restoreSize);
        height = restoreSize.height;
        diff = d.height - restoreSize.height;
        if (diff > 0)
            height += diff;
        else
            height += vExtra;
        addition = rendererSplit.getDividerSize() + 2 * (refInsets.left + refInsets.right);

        width = restoreSize.width + d.width;
        width += 4 * addition;
        break;
    case HISTORY:
        container.remove(mainComponent);
        historyUI.doGridLayout();
        addComponents(historySplit, tabs, historyUI);
        mainComponent = historySplit;
        container.add(mainComponent, BorderLayout.CENTER);
        container.validate();
        container.repaint();
        height = restoreSize.height;
        width = restoreSize.width;
        d = historyUI.getIdealSize();
        addition = historySplit.getDividerSize() + 2 * (refInsets.top + refInsets.bottom);
        height += d.height;
        historySplit.setResizeWeight(0.49);
        height += addition;
        break;
    case HISTORY_AND_RENDERER:
        historySplit.setResizeWeight(0.49);
        container.remove(mainComponent);
        historyUI.doGridLayout();
        rightComponent = model.getMetadataViewer().getEditorUI();
        addComponents(rendererSplit, tabs, rightComponent);
        addComponents(historySplit, rendererSplit, historyUI);
        mainComponent = historySplit;
        container.add(mainComponent, BorderLayout.CENTER);
        container.validate();
        container.repaint();

        d = model.getMetadataViewer().getIdealRendererSize();
        height = restoreSize.height;
        diff = d.height - restoreSize.height;
        if (diff > 0)
            height += diff;
        else
            height += vExtra;
        addition = rendererSplit.getDividerSize() + 2 * (refInsets.left + refInsets.right);

        width = restoreSize.width + d.width;
        width += 4 * addition;
        d = historyUI.getPreferredSize();
        addition = historySplit.getDividerSize() + 2 * (refInsets.top + refInsets.bottom);
        height += d.height;
        height += addition;
        break;
    case NEUTRAL:
        rightComponent = model.getMetadataViewer().getEditorUI();
        rendererSplit.remove(rightComponent);
        if (restoreSize == null)
            return;
        width = restoreSize.width;
        height = restoreSize.height;
        break;
    default:
    }
    //rendererSplit.setDividerLocation(-1);
    //rendererSplit.setResizeWeight(1.0);
    //historySplit.setDividerLocation(-1);
    d = getIdealSize(width, height);

    /* Need to review that code.
     * Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
    int w = (int) (screen.width*SCREEN_RATIO);
    int h = (int) (screen.height*SCREEN_RATIO);
    if (d.width > w || d.height > h) {
       setSize(width, height);
    } else setSize(d);
    */
    setSize(d);
    setPreferredSize(d);
    pack();
    container.addHierarchyBoundsListener(boundsAdapter);
}