コード例 #1
0
  public APCircleWindow() {
    super("AP Circles");
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    String startDirectoryName = System.getProperty("user.dir");
    startDirectory = new File(startDirectoryName);
    // this for convenience, as the program normally starts in graph/display
    //		startDirectory = startDirectory.getParentFile();

    gw = this;

    generalXML = new GeneralXML(graph);

    gp = new APCirclePanel(this);
    getContentPane().add(gp);

    graph = gp.getGraph();

    initView();
    initExperiment();
    initUtility();
    initLayout();
    initMenu();

    setSize(width, height);

    Dimension frameDim = Toolkit.getDefaultToolkit().getScreenSize();
    int posX = (frameDim.width - getSize().width) / 2;
    int posY = (frameDim.height - getSize().height) / 2;
    setLocation(posX, posY);

    setVisible(true);

    gp.requestFocus();
  }
コード例 #2
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;
      }
    }
  }
コード例 #3
0
  private void initLayout() {

    PiercedAPForceModel fm =
        new PiercedAPForceModel(KeyEvent.VK_Q, "Pierced area-proportional", true);
    fm.setRandomize(false);
    fm.setAnimateFlag(true);
    gp.addGraphDrawer(fm);

    PiercedAPForceModel fm1 =
        new PiercedAPForceModel(KeyEvent.VK_W, "Pierced area-proportional single iteration", true);
    fm1.setIterations(1);
    fm1.setRandomize(false);
    fm1.setAnimateFlag(true);
    gp.addGraphDrawer(fm1);

    GeneralAPForceModel fm2 =
        new GeneralAPForceModel(KeyEvent.VK_D, "General area-proportional", true);
    fm2.setRandomize(false);
    fm2.setAnimateFlag(true);
    gp.addGraphDrawer(fm2);

    GeneralAPForceModel fm3 =
        new GeneralAPForceModel(KeyEvent.VK_F, "General area-proportional single iteration", true);
    fm3.setIterations(1);
    fm3.setRandomize(false);
    fm3.setAnimateFlag(true);
    gp.addGraphDrawer(fm3);

    StandardSpringEmbedder se =
        new StandardSpringEmbedder(KeyEvent.VK_S, "Standard Spring Embedder", true);
    se.setRandomize(false);
    se.setAnimateFlag(true);
    gp.addGraphDrawer(se);
  }
コード例 #4
0
 private void initView() {
   gp.addGraphView(new GraphViewShowEdgeLabel(KeyEvent.VK_L, "Toggle Edge Labels", KeyEvent.VK_L));
   gp.addGraphView(new GraphViewShowNodeLabel(KeyEvent.VK_K, "Toggle Node Labels", KeyEvent.VK_K));
   gp.addGraphView(new CircleViewAPToggleShow(KeyEvent.VK_C, "Toggle Circles", KeyEvent.VK_C));
   // toggle parallel edge separation
   //		gp.addGraphView(new GraphViewSeparateEdges(KeyEvent.VK_P, "Toggle Separate Parallel
   // Edges",KeyEvent.VK_P));
 }
コード例 #5
0
 protected void fileNew() {
   if (currentFile != null) {
     if (!currentFile.isDirectory()) {
       currentFile = currentFile.getParentFile();
     }
   }
   graph.clear();
   gp.update(gp.getGraphics());
 }
コード例 #6
0
 protected void fileSave() {
   if (currentFile == null) {
     fileSaveAs();
   } else {
     if (currentFile.isDirectory()) {
       fileSaveAs();
     } else {
       graph.saveAll(currentFile);
       gp.update(gp.getGraphics());
     }
   }
 }
コード例 #7
0
  protected void fileOpenXML() {
    JFileChooser chooser = null;
    if (currentFile == null) {
      chooser = new JFileChooser(startDirectory);
    } else {
      chooser = new JFileChooser(currentFile);
    }

    int returnVal = chooser.showOpenDialog(gw);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
      currentFile = chooser.getSelectedFile();
      generalXML.loadGraph(currentFile);
    }
    gp.update(gp.getGraphics());
  }
コード例 #8
0
  private void initUtility() {

    gp.addGraphUtility(new CircleUtilityTest());
    //		gp.addGraphUtility(new CreateRandomSpecificationByGraph());
    gp.addGraphUtility(new CreateRandomPiercedSpecificationByAbstractDescription());
    gp.addGraphUtility(new RectifyLengths());
    gp.addGraphUtility(new ReportPassingEdges());
    gp.addGraphUtility(new ReportAreaProportions());
    gp.addGraphUtility(new EnterPiercedSpecification());
    gp.addGraphUtility(new EnterGeneralSpecification());
  }
コード例 #9
0
 protected void editSelectAll() {
   gp.getSelection().addNodes(graph.getNodes());
   gp.getSelection().addEdges(graph.getEdges());
   gp.repaint();
 }
コード例 #10
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);
    }
  }