コード例 #1
0
ファイル: WindowMain.java プロジェクト: alect/Puzzledice
  // Create a new document
  public void clear() {
    areaEditPanel.clear();
    puzzleEditPanel.clear();

    areaGraph = new mxGraph();
    areaGraph.setAutoSizeCells(true);
    areaGraphComponent.setGraph(areaGraph);
    areaGraphLayout =
        new mxOrganicLayout(
            areaGraph,
            new Rectangle(0, 0, graphPanel.getBounds().width, graphPanel.getBounds().height));
    areaGraph.setEnabled(false);

    puzzleGraph = new mxGraph();
    puzzleGraph.setAutoSizeCells(true);
    puzzleGraphComponent.setGraph(puzzleGraph);
    puzzleGraphOrganicLayout =
        new mxOrganicLayout(
            puzzleGraph,
            new Rectangle(0, 0, graphPanel.getBounds().width, graphPanel.getBounds().height));
    puzzleGraphHierLayout = new mxHierarchicalLayout(puzzleGraph, SwingConstants.WEST);
    hierarchyRoot = null;

    AreaEditPanel.reset();
    CombinePuzzleBlock.reset();
    InsertionPuzzleBlock.reset();
    DoorUnlockBlock.reset();
    FilterBlock.reset();
    InsertionPuzzleBlock.reset();
    ItemRequestPuzzleBlock.reset();
    PropertyChangePuzzleBlock.reset();
    SpawnPuzzleBlock.reset();
    OutputBlock.reset();
    ORBlock.reset();
  }
コード例 #2
0
  /**
   * Updates the location of <code>this</code> tab overview button.
   *
   * @param tabbedPane Tabbed pane.
   * @param tabAreaInsets Tab area insets.
   */
  public void updateLocation(JTabbedPane tabbedPane, Insets tabAreaInsets) {
    if (tabbedPane == null) return;

    // Lock the button for the bounds change
    this.putClientProperty(TabOverviewButton.OWN_BOUNDS, Boolean.TRUE);
    int buttonSize = LafWidgetRepository.getRepository().getLafSupport().getLookupButtonSize();

    switch (tabbedPane.getTabPlacement()) {
      case SwingConstants.TOP:
        if (tabbedPane.getComponentOrientation().isLeftToRight())
          this.setBounds(2, tabAreaInsets.top, buttonSize, buttonSize);
        else
          this.setBounds(
              tabbedPane.getBounds().width - tabAreaInsets.right - buttonSize - 2,
              tabAreaInsets.top,
              buttonSize,
              buttonSize);
        break;
      case SwingConstants.BOTTOM:
        if (tabbedPane.getComponentOrientation().isLeftToRight())
          this.setBounds(
              2,
              tabbedPane.getBounds().height - tabAreaInsets.bottom - buttonSize - 4,
              buttonSize,
              buttonSize);
        else
          this.setBounds(
              tabbedPane.getBounds().width - tabAreaInsets.right - buttonSize - 2,
              tabbedPane.getBounds().height - tabAreaInsets.bottom - buttonSize - 4,
              buttonSize,
              buttonSize);
        break;
      case SwingConstants.LEFT:
        this.setBounds(2, tabAreaInsets.top - 1, buttonSize, buttonSize);
        break;
      case SwingConstants.RIGHT:
        this.setBounds(
            tabbedPane.getBounds().width - tabAreaInsets.right - buttonSize - 2,
            tabAreaInsets.top - 1,
            buttonSize,
            buttonSize);
        break;
    }
    // Unlock the button for the bounds change
    this.putClientProperty(TabOverviewButton.OWN_BOUNDS, null);
  }
コード例 #3
0
ファイル: WindowMain.java プロジェクト: alect/Puzzledice
  /** 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();
  }