Ejemplo n.º 1
0
  public void actionPerformed(ActionEvent event) {
    JMenuItem source = (JMenuItem) (event.getSource());

    for (GraphView v : gp.getGraphViewList()) {
      if (v.getMenuText().equals(source.getText())) {
        v.view();
        repaint();
        return;
      }
    }

    for (GraphDrawer d : gp.getGraphDrawerList()) {
      if (d.getMenuText().equals(source.getText())) {
        d.layout();
        repaint();
        return;
      }
    }

    for (GraphUtility u : gp.getGraphUtilityList()) {
      if (u.getMenuText().equals(source.getText())) {
        u.apply();
        repaint();
        return;
      }
    }

    for (GraphExperiment ge : gp.getGraphExperimentList()) {
      if (ge.getMenuText().equals(source.getText())) {
        ge.experiment();
        repaint();
        return;
      }
    }
  }
Ejemplo n.º 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);
    }
  }