Example #1
0
 public myGraph() {
   graph = new mxGraph(); // graf "biblioteczny" na którym działamy
   component = new mxGraphComponent(graph); // component użyty w GUI,
   // zwracamy go przez
   // getComponent()
   layout = new mxHierarchicalLayout(graph); // layout dla grafu
   component.setEnabled(false); // defaultowo można klikać w wierzchołki i
   // krawędzie w GUI zaznaczając je, tutaj
   // blokuje wszystko
   //		 component.zoomTo(1, true); // początkowy zoom
   vertexWidth = 120; // wymiary prostokąta
   vertexHeight = 30;
   //		costFunction = new myCostFunction(); // funkcja potrzebna przy
   //												// findShortestPath()
   animation = null; // na razie jest null, jak będzie używana to się do
   // niej dołączy odpowiednią referencję
   animationIsPaused = false; // na początku animacja nie była jeszcze
   // pauzowana
   log = Logger.getLogger(this.getClass().getName());
 }
Example #2
0
  /** Initialize the contents of the frame. */
  private void initialize() {
    frmPuzzledicePuzzleEditor = new JFrame();
    frmPuzzledicePuzzleEditor.setTitle("Puzzledice Puzzle Map Editor");
    frmPuzzledicePuzzleEditor.setBounds(100, 100, 743, 585);
    frmPuzzledicePuzzleEditor.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    frmPuzzledicePuzzleEditor.getContentPane().setLayout(new BorderLayout(0, 0));
    frmPuzzledicePuzzleEditor.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent winEvt) {
            if (onExit()) System.exit(0);
          }
        });
    // Set up the program to catch OSX quit events
    try {
      OSXAdapter.setQuitHandler(this, this.getClass().getMethod("onExit", new Class[] {}));
    } catch (SecurityException e) {
      e.printStackTrace();
    } catch (NoSuchMethodException e) {
      e.printStackTrace();
    }

    JMenuBar menuBar = new JMenuBar();
    frmPuzzledicePuzzleEditor.setJMenuBar(menuBar);

    JMenu mnFile = new JMenu("File");
    menuBar.add(mnFile);

    JMenuItem mntmNew = new JMenuItem("New");
    mntmNew.setAccelerator(
        KeyStroke.getKeyStroke(
            KeyEvent.VK_N, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    mntmNew.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
            clear();
            _openFile = null;
          }
        });
    mnFile.add(mntmNew);

    JMenuItem mntmOpen = new JMenuItem("Open");
    mntmOpen.setAccelerator(
        KeyStroke.getKeyStroke(
            KeyEvent.VK_O, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    mntmOpen.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent evt) {

            // Run the file dialogue later since it's blocking
            SwingUtilities.invokeLater(
                new Runnable() {
                  public void run() {
                    FileDialog chooser =
                        new FileDialog(frmPuzzledicePuzzleEditor, "Open", FileDialog.LOAD);
                    chooser.setVisible(true);
                    if (chooser.getFile() != null) {
                      clear();
                      File file = new File(chooser.getDirectory(), chooser.getFile());
                      if (Loader.LoadFromXML(file)) {
                        areaEditPanel.justLoaded();
                        puzzleEditPanel.justLoaded();
                        _openFile = file;
                      } else {
                        JOptionPane.showMessageDialog(
                            frmPuzzledicePuzzleEditor,
                            "File failed to open!",
                            "Error",
                            JOptionPane.ERROR_MESSAGE);
                      }
                    }
                  }
                });
          }
        });
    mnFile.add(mntmOpen);

    JMenuItem mntmSave = new JMenuItem("Save");
    mntmSave.setAccelerator(
        KeyStroke.getKeyStroke(
            KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    mntmSave.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            // Invoke the save later since it's a blocking method
            SwingUtilities.invokeLater(
                new Runnable() {
                  public void run() {
                    save();
                  }
                });
          }
        });
    mnFile.add(mntmSave);

    JMenuItem mntmSaveAs = new JMenuItem("Save As");
    mntmSaveAs.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  public void run() {
                    String xml = xmlDigest();
                    saveAs(xml);
                  }
                });
          }
        });
    mnFile.add(mntmSaveAs);

    JMenuItem mntmExit = new JMenuItem("Exit");
    mntmExit.setAccelerator(
        KeyStroke.getKeyStroke(
            KeyEvent.VK_Q, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    mntmExit.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            if (onExit()) System.exit(0);
          }
        });
    mnFile.add(mntmExit);

    JMenu mnHelp = new JMenu("Help");
    menuBar.add(mnHelp);

    JPanel panel = new JPanel();
    frmPuzzledicePuzzleEditor.getContentPane().add(panel);
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

    JPanel editPanel = new JPanel();
    panel.add(editPanel);
    editPanel.setLayout(new BoxLayout(editPanel, BoxLayout.X_AXIS));

    JSeparator separator_2 = new JSeparator();
    separator_2.setMinimumSize(new Dimension(5, 0));
    separator_2.setMaximumSize(new Dimension(5, 0));
    separator_2.setPreferredSize(new Dimension(5, 0));
    editPanel.add(separator_2);

    areaEditPanel = new AreaEditPanel();
    editPanel.add(areaEditPanel);

    JSeparator separator = new JSeparator();
    separator.setMinimumSize(new Dimension(5, 0));
    separator.setMaximumSize(new Dimension(5, 0));
    separator.setPreferredSize(new Dimension(5, 0));
    editPanel.add(separator);

    puzzleEditPanel = new PuzzleEditPanel();
    editPanel.add(puzzleEditPanel);

    JSeparator separator_1 = new JSeparator();
    separator_1.setMinimumSize(new Dimension(5, 0));
    separator_1.setMaximumSize(new Dimension(5, 0));
    separator_1.setPreferredSize(new Dimension(5, 0));
    editPanel.add(separator_1);

    graphPanel = new JTabbedPane(JTabbedPane.TOP);
    graphPanel.setPreferredSize(
        new Dimension(
            frmPuzzledicePuzzleEditor.getBounds().width,
            frmPuzzledicePuzzleEditor.getBounds().height));
    panel.add(graphPanel);
    graphPanel.setAlignmentY(Component.TOP_ALIGNMENT);

    areaGraph = new mxGraph();

    areaGraph.setAutoSizeCells(true);
    areaGraphComponent = new mxGraphComponent(areaGraph);
    areaGraphComponent.addComponentListener(
        new ComponentAdapter() {
          @Override
          public void componentResized(ComponentEvent arg0) {
            areaGraphLayout =
                new mxOrganicLayout(
                    areaGraph,
                    new Rectangle(
                        0, 0, graphPanel.getBounds().width, graphPanel.getBounds().height));
            areaGraphLayout.execute(areaGraph.getDefaultParent());
          }
        });
    areaGraphComponent.setEnabled(false);
    areaGraphLayout =
        new mxOrganicLayout(
            areaGraph,
            new Rectangle(0, 0, graphPanel.getBounds().width, graphPanel.getBounds().height));

    areaGraph.setEnabled(false);

    graphPanel.addTab("Area Graph", null, areaGraphComponent, null);

    puzzleGraph = new mxGraph();

    puzzleGraph.setAutoSizeCells(true);

    puzzleGraphComponent = new mxGraphComponent(puzzleGraph);
    puzzleGraphComponent.addComponentListener(
        new ComponentAdapter() {
          @Override
          public void componentResized(ComponentEvent arg0) {}
        });
    puzzleGraphComponent.setEnabled(false);
    puzzleGraphOrganicLayout =
        new mxOrganicLayout(
            puzzleGraph,
            new Rectangle(0, 0, graphPanel.getBounds().width, graphPanel.getBounds().height));
    puzzleGraphHierLayout = new mxHierarchicalLayout(puzzleGraph, SwingConstants.WEST);

    graphPanel.addTab("Puzzle Graph", null, puzzleGraphComponent, null);
    txtTextPanel = new JTextArea("Textual description");
    panel.add(txtTextPanel);
    txtTextPanel.setLineWrap(true);
    txtTextPanel.setWrapStyleWord(true);
    txtTextPanel.setEditable(false);

    frmPuzzledicePuzzleEditor.addComponentListener(
        new ComponentAdapter() {
          @Override
          public void componentResized(ComponentEvent arg0) {
            graphPanel.setPreferredSize(
                new Dimension(
                    frmPuzzledicePuzzleEditor.getBounds().width,
                    frmPuzzledicePuzzleEditor.getBounds().height));
          }
        });

    _emptyXml = xmlDigest();
  }