Example usage for javax.swing JMenuBar getComponents

List of usage examples for javax.swing JMenuBar getComponents

Introduction

In this page you can find the example usage for javax.swing JMenuBar getComponents.

Prototype

public Component[] getComponents() 

Source Link

Document

Gets all the components in this container.

Usage

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

/** 
 * Sets the selected pane.//from  ww w. j  ava2s  .c  o  m
 * 
 * @param index The index of the selected tab pane.
 */
void setSelectedPane(int index) {
    JMenuBar menuBar = getJMenuBar();
    Component[] items = menuBar.getComponents();
    Component item;
    int j = -1;
    for (int i = 0; i < items.length; i++) {
        item = items[i];
        if (item == zoomGridMenu || item == zoomMenu)
            j = i;
    }
    if (j != -1)
        menuBar.remove(j);
    double f;
    switch (index) {
    case ImViewer.GRID_INDEX:
        if (j != -1)
            menuBar.add(zoomGridMenu, j);
        f = model.getBrowser().getGridRatio();
        setMagnificationStatus(f, ZoomAction.getIndex(f));
        break;
    case ImViewer.PROJECTION_INDEX:
    case ImViewer.VIEW_INDEX:
    default:
        if (j != -1)
            menuBar.add(zoomMenu, j);
        f = model.getZoomFactor();
        setMagnificationStatus(f, ZoomAction.getIndex(f));
    }
    int oldIndex = model.getTabbedIndex();
    model.setTabbedIndex(index);
    tabs.removeChangeListener(controller);
    int n = tabs.getTabCount();
    Component c;
    int tabbedIndex;
    for (int i = 0; i < n; i++) {
        c = tabs.getComponentAt(i);
        if (c instanceof ClosableTabbedPaneComponent) {
            tabbedIndex = ((ClosableTabbedPaneComponent) c).getIndex();
            if (tabbedIndex == index)
                tabs.setSelectedIndex(i);
        }
    }

    tabs.addChangeListener(controller);
    setLeftStatus();
    setPlaneInfoStatus();
    model.getBrowser().setSelectedPane(index);
    setLensVisible(isLensVisible(), oldIndex);
    maximizeWindow();
}