예제 #1
0
  // Method to refresh entire display
  public static void refresh() {
    if (!SwingUtilities.isEventDispatchThread()) return;

    worldDraw.display();
  }
예제 #2
0
  // Main program -- create and start GUI
  public Mesh(boolean debug) {
    // Create drawing area for shape
    worldDraw = new WorldView(this, shape, debug);
    worldDraw.setSize(500, 500);

    // Create menubar
    JMenuBar menubar = new JMenuBar();
    setJMenuBar(menubar);

    JMenu menu = new JMenu("File");
    menu.getPopupMenu().setLightWeightPopupEnabled(false);
    menubar.add(menu);

    // Exit when quit selected
    JMenuItem resetm = menu.add("Reset");
    resetm.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            Parameter.blockAction(true);

            // Reset all parameters
            shape.reset();

            Parameter.blockAction(false);

            Parameter.onUserAction();
          }
        });

    // Exit when quit selected
    JMenuItem quitm = menu.add("Quit");
    quitm.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            System.exit(0);
          }
        });

    // ------------------------------------------------------

    // Lay out main window
    GridBagLayout layout = new GridBagLayout();
    GridBagConstraints con = new GridBagConstraints();

    Container c = getContentPane();
    c.setLayout(layout);

    // World viewport
    con.gridwidth = 1;
    con.weightx = 0.2;
    con.weighty = 1.0;
    con.fill = GridBagConstraints.BOTH;
    con.insets = new Insets(4, 4, 4, 2);
    layout.setConstraints(worldDraw, con);
    c.add(worldDraw);

    // -- Parameter controls

    // Make container for controls
    Container cc = new Container();

    con.gridwidth = GridBagConstraints.REMAINDER;
    con.weightx = 0.2;
    con.weighty = 1.0;
    con.fill = GridBagConstraints.HORIZONTAL;

    layout.setConstraints(cc, con);
    c.add(cc);

    // Fill compartment
    GridBagLayout clayout = new GridBagLayout();
    cc.setLayout(clayout);
    GridBagConstraints ccon = new GridBagConstraints();

    ccon.weightx = 1.0;
    ccon.weighty = 1.0;
    ccon.anchor = GridBagConstraints.NORTH;
    ccon.insets = new Insets(10, 10, 0, 10);
    ccon.fill = GridBagConstraints.BOTH;
    ccon.gridwidth = GridBagConstraints.REMAINDER;
    makeControls(cc, clayout, ccon, shape.getParams(), shape.getOptions(), "Object parameters");

    // ------------------------------------------------------

    // Exit when window closes
    addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
          }
        });

    // Placement of window on screen
    setLocation(100, 50);

    pack();
    setVisible(true);
  }