Example usage for javax.swing JTabbedPane isEnabled

List of usage examples for javax.swing JTabbedPane isEnabled

Introduction

In this page you can find the example usage for javax.swing JTabbedPane isEnabled.

Prototype

public boolean isEnabled() 

Source Link

Document

Determines whether this component is enabled.

Usage

From source file:com.net2plan.gui.tools.GUINetworkDesign.java

@Override
public void configure(JPanel contentPane) {
    this.currentNetPlan = new NetPlan();

    BidiMap<NetworkLayer, Integer> mapLayer2VisualizationOrder = new DualHashBidiMap<>();
    Map<NetworkLayer, Boolean> layerVisibilityMap = new HashMap<>();
    for (NetworkLayer layer : currentNetPlan.getNetworkLayers()) {
        mapLayer2VisualizationOrder.put(layer, mapLayer2VisualizationOrder.size());
        layerVisibilityMap.put(layer, true);
    }//from   ww  w  . j  a v a 2 s  .c o  m
    this.vs = new VisualizationState(currentNetPlan, mapLayer2VisualizationOrder, layerVisibilityMap,
            MAXSIZEUNDOLISTPICK);

    topologyPanel = new TopologyPanel(this, JUNGCanvas.class);

    JPanel leftPane = new JPanel(new BorderLayout());
    JPanel logSection = configureLeftBottomPanel();
    if (logSection == null) {
        leftPane.add(topologyPanel, BorderLayout.CENTER);
    } else {
        JSplitPane splitPaneTopology = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
        splitPaneTopology.setTopComponent(topologyPanel);
        splitPaneTopology.setBottomComponent(logSection);
        splitPaneTopology.addPropertyChangeListener(new ProportionalResizeJSplitPaneListener());
        splitPaneTopology.setBorder(new LineBorder(contentPane.getBackground()));
        splitPaneTopology.setOneTouchExpandable(true);
        splitPaneTopology.setDividerSize(7);
        leftPane.add(splitPaneTopology, BorderLayout.CENTER);
    }
    contentPane.add(leftPane, "grow");

    viewEditTopTables = new ViewEditTopologyTablesPane(GUINetworkDesign.this, new BorderLayout());

    reportPane = new ViewReportPane(GUINetworkDesign.this, JSplitPane.VERTICAL_SPLIT);

    setCurrentNetPlanDoNotUpdateVisualization(currentNetPlan);
    Pair<BidiMap<NetworkLayer, Integer>, Map<NetworkLayer, Boolean>> res = VisualizationState
            .generateCanvasDefaultVisualizationLayerInfo(getDesign());
    vs.setCanvasLayerVisibilityAndOrder(getDesign(), res.getFirst(), res.getSecond());

    /* Initialize the undo/redo manager, and set its initial design */
    this.undoRedoManager = new UndoRedoManager(this, MAXSIZEUNDOLISTCHANGES);
    this.undoRedoManager.addNetPlanChange();

    onlineSimulationPane = new OnlineSimulationPane(this);
    executionPane = new OfflineExecutionPanel(this);
    whatIfAnalysisPane = new WhatIfAnalysisPane(this);

    // Closing windows
    WindowUtils.clearFloatingWindows();

    final JTabbedPane tabPane = new JTabbedPane();
    tabPane.add(WindowController.WindowToTab.getTabName(WindowController.WindowToTab.network),
            viewEditTopTables);
    tabPane.add(WindowController.WindowToTab.getTabName(WindowController.WindowToTab.offline), executionPane);
    tabPane.add(WindowController.WindowToTab.getTabName(WindowController.WindowToTab.online),
            onlineSimulationPane);
    tabPane.add(WindowController.WindowToTab.getTabName(WindowController.WindowToTab.whatif),
            whatIfAnalysisPane);
    tabPane.add(WindowController.WindowToTab.getTabName(WindowController.WindowToTab.report), reportPane);

    // Installing customized mouse listener
    MouseListener[] ml = tabPane.getListeners(MouseListener.class);

    for (int i = 0; i < ml.length; i++) {
        tabPane.removeMouseListener(ml[i]);
    }

    // Left click works as usual, right click brings up a pop-up menu.
    tabPane.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            JTabbedPane tabPane = (JTabbedPane) e.getSource();

            int tabIndex = tabPane.getUI().tabForCoordinate(tabPane, e.getX(), e.getY());

            if (tabIndex >= 0 && tabPane.isEnabledAt(tabIndex)) {
                if (tabIndex == tabPane.getSelectedIndex()) {
                    if (tabPane.isRequestFocusEnabled()) {
                        tabPane.requestFocus();

                        tabPane.repaint(tabPane.getUI().getTabBounds(tabPane, tabIndex));
                    }
                } else {
                    tabPane.setSelectedIndex(tabIndex);
                }

                if (!tabPane.isEnabled() || SwingUtilities.isRightMouseButton(e)) {
                    final JPopupMenu popupMenu = new JPopupMenu();

                    final JMenuItem popWindow = new JMenuItem("Pop window out");
                    popWindow.addActionListener(e1 -> {
                        final int selectedIndex = tabPane.getSelectedIndex();
                        final String tabName = tabPane.getTitleAt(selectedIndex);
                        final JComponent selectedComponent = (JComponent) tabPane.getSelectedComponent();

                        // Pops up the selected tab.
                        final WindowController.WindowToTab windowToTab = WindowController.WindowToTab
                                .parseString(tabName);

                        if (windowToTab != null) {
                            switch (windowToTab) {
                            case offline:
                                WindowController.buildOfflineWindow(selectedComponent);
                                WindowController.showOfflineWindow(true);
                                break;
                            case online:
                                WindowController.buildOnlineWindow(selectedComponent);
                                WindowController.showOnlineWindow(true);
                                break;
                            case whatif:
                                WindowController.buildWhatifWindow(selectedComponent);
                                WindowController.showWhatifWindow(true);
                                break;
                            case report:
                                WindowController.buildReportWindow(selectedComponent);
                                WindowController.showReportWindow(true);
                                break;
                            default:
                                return;
                            }
                        }

                        tabPane.setSelectedIndex(0);
                    });

                    // Disabling the pop up button for the network state tab.
                    if (WindowController.WindowToTab.parseString(tabPane
                            .getTitleAt(tabPane.getSelectedIndex())) == WindowController.WindowToTab.network) {
                        popWindow.setEnabled(false);
                    }

                    popupMenu.add(popWindow);

                    popupMenu.show(e.getComponent(), e.getX(), e.getY());
                }
            }
        }
    });

    // Building windows
    WindowController.buildTableControlWindow(tabPane);
    WindowController.showTablesWindow(false);

    addAllKeyCombinationActions();
    updateVisualizationAfterNewTopology();
}