Пример #1
0
 // create the menu bar (changed to private)
 private static JMenuBar createMenuBar() {
   JMenuBar menuBar = new JMenuBar();
   JMenu menu = new JMenu("File");
   menuBar.add(menu);
   JMenuItem saveItem = new JMenuItem(" Save...   ");
   saveItem.addActionListener(std);
   saveItem.setAccelerator(
       KeyStroke.getKeyStroke(
           KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
   menu.add(saveItem);
   return menuBar;
 }
Пример #2
0
  private void initMenu() {

    JMenuBar menuBar = new JMenuBar();

    setJMenuBar(menuBar);

    // File Menu
    JMenu fileMenu = new JMenu("File");

    fileMenu.setMnemonic(KeyEvent.VK_F);
    menuBar.add(fileMenu);

    JMenuItem fileNewItem = new JMenuItem("New", KeyEvent.VK_N);
    fileNewItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK));
    fileMenu.add(fileNewItem);

    JMenuItem fileOpenItem = new JMenuItem("Open...", KeyEvent.VK_O);
    fileOpenItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK));
    fileMenu.add(fileOpenItem);

    JMenuItem fileOpenAdjacencyItem = new JMenuItem("Open Adjacency File...");
    fileMenu.add(fileOpenAdjacencyItem);

    JMenuItem fileOpenWeightedAdjacencyItem = new JMenuItem("Open Weighted Adjacency File...");
    fileMenu.add(fileOpenWeightedAdjacencyItem);

    JMenuItem fileOpenXMLItem = new JMenuItem("Open XML File...");
    fileMenu.add(fileOpenXMLItem);

    JMenuItem fileSaveItem = new JMenuItem("Save", KeyEvent.VK_S);
    fileSaveItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK));
    fileMenu.add(fileSaveItem);

    JMenuItem fileSaveAsItem = new JMenuItem("Save As...");
    fileMenu.add(fileSaveAsItem);

    JMenuItem fileSaveSimpleItem = new JMenuItem("Save Simple Graph...");
    fileMenu.add(fileSaveSimpleItem);

    JMenuItem fileSaveXMLItem = new JMenuItem("Save XML File...");
    fileMenu.add(fileSaveXMLItem);

    JMenuItem filePNGItem = new JMenuItem("Export to png");
    fileMenu.add(filePNGItem);

    JMenuItem fileExitItem = new JMenuItem("Exit", KeyEvent.VK_X);
    fileExitItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, ActionEvent.ALT_MASK));
    fileMenu.add(fileExitItem);

    fileExitItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            fileExit();
          }
        });

    fileNewItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            fileNew();
          }
        });

    fileOpenItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            fileOpen();
          }
        });

    fileOpenXMLItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            fileOpenXML();
          }
        });

    fileSaveItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            fileSave();
          }
        });

    fileSaveAsItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            fileSaveAs();
          }
        });

    fileSaveSimpleItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            fileSaveSimple();
          }
        });

    fileSaveXMLItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            fileSaveXML();
          }
        });

    filePNGItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            filePNG();
          }
        });

    // Edit Menu
    JMenu editMenu = new JMenu("Edit");

    editMenu.setMnemonic(KeyEvent.VK_E);
    menuBar.add(editMenu);

    JMenuItem editNodesItem = new JMenuItem("Edit Selected Nodes...", KeyEvent.VK_N);
    editNodesItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.SHIFT_MASK));
    editMenu.add(editNodesItem);

    JMenuItem editEdgesItem = new JMenuItem("Edit Selected Edges...", KeyEvent.VK_E);
    editEdgesItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, ActionEvent.SHIFT_MASK));
    editMenu.add(editEdgesItem);

    JMenuItem editEdgeTypesItem = new JMenuItem("Edit Edge Types...");
    editMenu.add(editEdgeTypesItem);

    JMenuItem editNodeTypesItem = new JMenuItem("Edit Node Types...");
    editMenu.add(editNodeTypesItem);

    JMenuItem editMoveGraphItem = new JMenuItem("Move Graph...");
    editMenu.add(editMoveGraphItem);

    JMenuItem editAddEdgeBendItem = new JMenuItem("Add Edge Bend");
    editMenu.add(editAddEdgeBendItem);

    JMenuItem editRemoveEdgeBendsItem = new JMenuItem("Remove Edge Bends");
    editMenu.add(editRemoveEdgeBendsItem);

    JMenuItem editSelectAllItem = new JMenuItem("Select All", KeyEvent.VK_A);
    editSelectAllItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.CTRL_MASK));
    editMenu.add(editSelectAllItem);

    editNodesItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            gp.editNodes(gp.getSelection().getNodes());
          }
        });

    editEdgesItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            gp.editEdges(gp.getSelection().getEdges());
          }
        });

    editEdgeTypesItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            gp.editEdgeTypes();
          }
        });

    editNodeTypesItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            gp.editNodeTypes();
          }
        });

    editMoveGraphItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            gp.moveGraph();
          }
        });

    editAddEdgeBendItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            gp.addEdgeBend();
          }
        });

    editRemoveEdgeBendsItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            gp.removeEdgeBends();
          }
        });

    editSelectAllItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            editSelectAll();
          }
        });

    // View Menu
    JMenu viewMenu = new JMenu("View");
    viewMenu.setMnemonic(KeyEvent.VK_V);
    menuBar.add(viewMenu);

    for (GraphView v : gp.getGraphViewList()) {
      JMenuItem menuItem = new JMenuItem(v.getMenuText(), v.getMnemonicKey());
      menuItem.setAccelerator(KeyStroke.getKeyStroke(v.getAcceleratorKey(), 0));
      menuItem.addActionListener(this);
      viewMenu.add(menuItem);
    }

    // Experiment Menu
    JMenu experimentsMenu = new JMenu("Experiments");
    experimentsMenu.setMnemonic(KeyEvent.VK_E);
    menuBar.add(experimentsMenu);

    for (GraphExperiment ge : gp.getGraphExperimentList()) {
      JMenuItem menuItem = new JMenuItem(ge.getMenuText(), ge.getMnemonicKey());
      menuItem.setAccelerator(KeyStroke.getKeyStroke(ge.getAcceleratorKey(), 0));
      menuItem.addActionListener(this);
      experimentsMenu.add(menuItem);
    }

    // Utilities Menu
    JMenu utilitiesMenu = new JMenu("Utilities");
    utilitiesMenu.setMnemonic(KeyEvent.VK_U);
    menuBar.add(utilitiesMenu);

    for (GraphUtility u : gp.getGraphUtilityList()) {
      JMenuItem menuItem = new JMenuItem(u.getMenuText(), u.getMnemonicKey());
      menuItem.setAccelerator(KeyStroke.getKeyStroke(u.getAcceleratorKey(), 0));
      menuItem.addActionListener(this);
      utilitiesMenu.add(menuItem);
    }

    JMenu layoutMenu = new JMenu("Layout");
    layoutMenu.setMnemonic(KeyEvent.VK_L);
    menuBar.add(layoutMenu);

    for (GraphDrawer d : gp.getGraphDrawerList()) {
      JMenuItem menuItem = new JMenuItem(d.getMenuText(), d.getMnemonicKey());
      menuItem.setAccelerator(KeyStroke.getKeyStroke(d.getAcceleratorKey(), 0));
      menuItem.addActionListener(this);
      layoutMenu.add(menuItem);
    }
  }