Example usage for javax.swing JToolBar.Separator JToolBar.Separator

List of usage examples for javax.swing JToolBar.Separator JToolBar.Separator

Introduction

In this page you can find the example usage for javax.swing JToolBar.Separator JToolBar.Separator.

Prototype

JToolBar.Separator

Source Link

Usage

From source file:com.net2plan.gui.utils.topologyPane.TopologyPanel.java

/**
 * Default constructor./*w w w.j  a  v  a2  s  .  c o m*/
 *
 * @param callback               Topology callback listening plugin events
 * @param defaultDesignDirectory Default location for design {@code .n2p} files (it may be null, then default is equal to {@code net2planFolder/workspace/data/networkTopologies})
 * @param defaultDemandDirectory Default location for design {@code .n2p} files (it may be null, then default is equal to {@code net2planFolder/workspace/data/trafficMatrices})
 * @param canvasType             Canvas type (i.e. JUNG)
 * @param plugins                List of plugins to be included (it may be null)
 */
public TopologyPanel(final IVisualizationCallback callback, File defaultDesignDirectory,
        File defaultDemandDirectory, Class<? extends ITopologyCanvas> canvasType,
        List<ITopologyCanvasPlugin> plugins) {
    File currentDir = SystemUtils.getCurrentDir();

    this.callback = callback;
    this.defaultDesignDirectory = defaultDesignDirectory == null ? new File(
            currentDir + SystemUtils.getDirectorySeparator() + "workspace" + SystemUtils.getDirectorySeparator()
                    + "data" + SystemUtils.getDirectorySeparator() + "networkTopologies")
            : defaultDesignDirectory;
    this.defaultDemandDirectory = defaultDemandDirectory == null ? new File(
            currentDir + SystemUtils.getDirectorySeparator() + "workspace" + SystemUtils.getDirectorySeparator()
                    + "data" + SystemUtils.getDirectorySeparator() + "trafficMatrices")
            : defaultDemandDirectory;
    this.multilayerControlPanel = new MultiLayerControlPanel(callback);

    try {
        canvas = canvasType.getDeclaredConstructor(IVisualizationCallback.class, TopologyPanel.class)
                .newInstance(callback, this);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    if (plugins != null)
        for (ITopologyCanvasPlugin plugin : plugins)
            addPlugin(plugin);

    setLayout(new BorderLayout());

    JToolBar toolbar = new JToolBar();
    toolbar.setRollover(true);
    toolbar.setFloatable(false);
    toolbar.setOpaque(false);
    toolbar.setBorderPainted(false);

    JPanel topPanel = new JPanel(new BorderLayout());
    topPanel.add(toolbar, BorderLayout.NORTH);

    add(topPanel, BorderLayout.NORTH);

    JComponent canvasComponent = canvas.getCanvasComponent();

    canvasPanel = new JPanel(new BorderLayout());
    canvasComponent.setBorder(LineBorder.createBlackLineBorder());

    JToolBar multiLayerToolbar = new JToolBar(JToolBar.VERTICAL);
    multiLayerToolbar.setRollover(true);
    multiLayerToolbar.setFloatable(false);
    multiLayerToolbar.setOpaque(false);

    canvasPanel.add(canvasComponent, BorderLayout.CENTER);
    canvasPanel.add(multiLayerToolbar, BorderLayout.WEST);
    add(canvasPanel, BorderLayout.CENTER);

    btn_load = new JButton();
    btn_load.setToolTipText("Load a network design");
    btn_loadDemand = new JButton();
    btn_loadDemand.setToolTipText("Load a traffic demand set");
    btn_save = new JButton();
    btn_save.setToolTipText("Save current state to a file");
    btn_zoomIn = new JButton();
    btn_zoomIn.setToolTipText("Zoom in");
    btn_zoomOut = new JButton();
    btn_zoomOut.setToolTipText("Zoom out");
    btn_zoomAll = new JButton();
    btn_zoomAll.setToolTipText("Zoom all");
    btn_takeSnapshot = new JButton();
    btn_takeSnapshot.setToolTipText("Take a snapshot of the canvas");
    btn_showNodeNames = new JToggleButton();
    btn_showNodeNames.setToolTipText("Show/hide node names");
    btn_showLinkIds = new JToggleButton();
    btn_showLinkIds.setToolTipText(
            "Show/hide link utilization, measured as the ratio between the total traffic in the link (including that in protection segments) and total link capacity (including that reserved by protection segments)");
    btn_showNonConnectedNodes = new JToggleButton();
    btn_showNonConnectedNodes.setToolTipText("Show/hide non-connected nodes");
    btn_increaseNodeSize = new JButton();
    btn_increaseNodeSize.setToolTipText("Increase node size");
    btn_decreaseNodeSize = new JButton();
    btn_decreaseNodeSize.setToolTipText("Decrease node size");
    btn_increaseFontSize = new JButton();
    btn_increaseFontSize.setToolTipText("Increase font size");
    btn_decreaseFontSize = new JButton();
    btn_decreaseFontSize.setToolTipText("Decrease font size");
    /* Multilayer buttons */
    btn_increaseInterLayerDistance = new JButton();
    btn_increaseInterLayerDistance
            .setToolTipText("Increase the distance between layers (when more than one layer is visible)");
    btn_decreaseInterLayerDistance = new JButton();
    btn_decreaseInterLayerDistance
            .setToolTipText("Decrease the distance between layers (when more than one layer is visible)");
    btn_showLowerLayerInfo = new JToggleButton();
    btn_showLowerLayerInfo
            .setToolTipText("Shows the links in lower layers that carry traffic of the picked element");
    btn_showLowerLayerInfo.setSelected(getVisualizationState().isShowInCanvasLowerLayerPropagation());
    btn_showUpperLayerInfo = new JToggleButton();
    btn_showUpperLayerInfo.setToolTipText(
            "Shows the links in upper layers that carry traffic that appears in the picked element");
    btn_showUpperLayerInfo.setSelected(getVisualizationState().isShowInCanvasUpperLayerPropagation());
    btn_showThisLayerInfo = new JToggleButton();
    btn_showThisLayerInfo.setToolTipText(
            "Shows the links in the same layer as the picked element, that carry traffic that appears in the picked element");
    btn_showThisLayerInfo.setSelected(getVisualizationState().isShowInCanvasThisLayerPropagation());
    btn_npChangeUndo = new JButton();
    btn_npChangeUndo.setToolTipText(
            "Navigate back to the previous state of the network (last time the network design was changed)");
    btn_npChangeRedo = new JButton();
    btn_npChangeRedo.setToolTipText(
            "Navigate forward to the next state of the network (when network design was changed");

    btn_osmMap = new JToggleButton();
    btn_osmMap.setToolTipText(
            "Toggle between on/off the OSM support. An internet connection is required in order for this to work.");
    btn_tableControlWindow = new JButton();
    btn_tableControlWindow.setToolTipText("Show the network topology control window.");

    // MultiLayer control window
    JPopupMenu multiLayerPopUp = new JPopupMenu();
    multiLayerPopUp.add(multilayerControlPanel);
    JPopUpButton btn_multilayer = new JPopUpButton("", multiLayerPopUp);

    btn_reset = new JButton("Reset");
    btn_reset.setToolTipText("Reset the user interface");
    btn_reset.setMnemonic(KeyEvent.VK_R);

    btn_load.setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/loadDesign.png")));
    btn_loadDemand.setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/loadDemand.png")));
    btn_save.setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/saveDesign.png")));
    btn_showNodeNames
            .setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/showNodeName.png")));
    btn_showLinkIds
            .setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/showLinkUtilization.png")));
    btn_showNonConnectedNodes.setIcon(
            new ImageIcon(TopologyPanel.class.getResource("/resources/gui/showNonConnectedNodes.png")));
    //btn_whatIfActivated.setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/showNonConnectedNodes.png")));
    btn_zoomIn.setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/zoomIn.png")));
    btn_zoomOut.setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/zoomOut.png")));
    btn_zoomAll.setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/zoomAll.png")));
    btn_takeSnapshot.setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/takeSnapshot.png")));
    btn_increaseNodeSize
            .setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/increaseNode.png")));
    btn_decreaseNodeSize
            .setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/decreaseNode.png")));
    btn_increaseFontSize
            .setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/increaseFont.png")));
    btn_decreaseFontSize
            .setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/decreaseFont.png")));
    btn_increaseInterLayerDistance.setIcon(
            new ImageIcon(TopologyPanel.class.getResource("/resources/gui/increaseLayerDistance.png")));
    btn_decreaseInterLayerDistance.setIcon(
            new ImageIcon(TopologyPanel.class.getResource("/resources/gui/decreaseLayerDistance.png")));
    btn_multilayer
            .setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/showLayerControl.png")));
    btn_showThisLayerInfo
            .setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/showLayerPropagation.png")));
    btn_showUpperLayerInfo.setIcon(
            new ImageIcon(TopologyPanel.class.getResource("/resources/gui/showLayerUpperPropagation.png")));
    btn_showLowerLayerInfo.setIcon(
            new ImageIcon(TopologyPanel.class.getResource("/resources/gui/showLayerLowerPropagation.png")));
    btn_tableControlWindow
            .setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/showControl.png")));
    btn_osmMap.setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/showOSM.png")));
    btn_npChangeUndo.setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/undoButton.png")));
    btn_npChangeRedo.setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/redoButton.png")));

    btn_load.addActionListener(this);
    btn_loadDemand.addActionListener(this);
    btn_save.addActionListener(this);
    btn_showNodeNames.addActionListener(this);
    btn_showLinkIds.addActionListener(this);
    btn_showNonConnectedNodes.addActionListener(this);
    btn_zoomIn.addActionListener(this);
    btn_zoomOut.addActionListener(this);
    btn_zoomAll.addActionListener(this);
    btn_takeSnapshot.addActionListener(this);
    btn_reset.addActionListener(this);
    btn_increaseInterLayerDistance.addActionListener(this);
    btn_decreaseInterLayerDistance.addActionListener(this);
    btn_showLowerLayerInfo.addActionListener(this);
    btn_showUpperLayerInfo.addActionListener(this);
    btn_showThisLayerInfo.addActionListener(this);
    btn_increaseNodeSize.addActionListener(this);
    btn_decreaseNodeSize.addActionListener(this);
    btn_increaseFontSize.addActionListener(this);
    btn_decreaseFontSize.addActionListener(this);
    btn_npChangeUndo.addActionListener(this);
    btn_npChangeRedo.addActionListener(this);
    btn_osmMap.addActionListener(this);
    btn_tableControlWindow.addActionListener(this);

    toolbar.add(btn_load);
    toolbar.add(btn_loadDemand);
    toolbar.add(btn_save);
    toolbar.add(new JToolBar.Separator());
    toolbar.add(btn_zoomIn);
    toolbar.add(btn_zoomOut);
    toolbar.add(btn_zoomAll);
    toolbar.add(btn_takeSnapshot);
    toolbar.add(new JToolBar.Separator());
    toolbar.add(btn_showNodeNames);
    toolbar.add(btn_showLinkIds);
    toolbar.add(btn_showNonConnectedNodes);
    toolbar.add(new JToolBar.Separator());
    toolbar.add(btn_increaseNodeSize);
    toolbar.add(btn_decreaseNodeSize);
    toolbar.add(btn_increaseFontSize);
    toolbar.add(btn_decreaseFontSize);
    toolbar.add(new JToolBar.Separator());
    toolbar.add(Box.createHorizontalGlue());
    toolbar.add(btn_osmMap);
    toolbar.add(btn_tableControlWindow);
    toolbar.add(btn_reset);

    multiLayerToolbar.add(new JToolBar.Separator());
    multiLayerToolbar.add(btn_multilayer);
    multiLayerToolbar.add(btn_increaseInterLayerDistance);
    multiLayerToolbar.add(btn_decreaseInterLayerDistance);
    multiLayerToolbar.add(btn_showLowerLayerInfo);
    multiLayerToolbar.add(btn_showUpperLayerInfo);
    multiLayerToolbar.add(btn_showThisLayerInfo);
    multiLayerToolbar.add(Box.createVerticalGlue());
    multiLayerToolbar.add(btn_npChangeUndo);
    multiLayerToolbar.add(btn_npChangeRedo);

    this.addComponentListener(new ComponentAdapter() {
        @Override
        public void componentResized(ComponentEvent e) {
            if (e.getComponent().getSize().getHeight() != 0 && e.getComponent().getSize().getWidth() != 0) {
                canvas.zoomAll();
            }
        }
    });

    List<Component> children = SwingUtils.getAllComponents(this);
    for (Component component : children)
        if (component instanceof AbstractButton)
            component.setFocusable(false);

    if (ErrorHandling.isDebugEnabled()) {
        canvas.getCanvasComponent().addMouseMotionListener(new MouseMotionAdapter() {
            @Override
            public void mouseMoved(MouseEvent e) {
                Point point = e.getPoint();
                position.setText("view = " + point + ", NetPlan coord = "
                        + canvas.getCanvasPointFromNetPlanPoint(point));
            }
        });

        position = new JLabel();
        add(position, BorderLayout.SOUTH);
    } else {
        position = null;
    }

    new FileDrop(canvasComponent, new LineBorder(Color.BLACK), new FileDrop.Listener() {
        @Override
        public void filesDropped(File[] files) {
            for (File file : files) {
                try {
                    if (!file.getName().toLowerCase(Locale.getDefault()).endsWith(".n2p"))
                        return;
                    loadDesignFromFile(file);
                    break;
                } catch (Throwable e) {
                    break;
                }
            }
        }
    });

    btn_showNodeNames.setSelected(getVisualizationState().isCanvasShowNodeNames());
    btn_showLinkIds.setSelected(getVisualizationState().isCanvasShowLinkLabels());
    btn_showNonConnectedNodes.setSelected(getVisualizationState().isCanvasShowNonConnectedNodes());

    final ITopologyCanvasPlugin popupPlugin = new PopupMenuPlugin(callback, this.canvas);
    addPlugin(new PanGraphPlugin(callback, canvas, MouseEvent.BUTTON1_MASK));
    if (callback.getVisualizationState().isNetPlanEditable() && getCanvas() instanceof JUNGCanvas)
        addPlugin(new AddLinkGraphPlugin(callback, canvas, MouseEvent.BUTTON1_MASK,
                MouseEvent.BUTTON1_MASK | MouseEvent.SHIFT_MASK));
    addPlugin(popupPlugin);
    if (callback.getVisualizationState().isNetPlanEditable())
        addPlugin(new MoveNodePlugin(callback, canvas, MouseEvent.BUTTON1_MASK | MouseEvent.CTRL_MASK));

    setBorder(BorderFactory.createTitledBorder(new LineBorder(Color.BLACK), "Network topology"));
    //        setAllowLoadTrafficDemand(callback.allowLoadTrafficDemands());
}