コード例 #1
0
  /**
   * Constructs the dialog window
   *
   * @param p Parent GUI
   */
  public RegionEditorDialog(MapEditorGUI p) {
    parent = p;
    setLayout(null);

    /*
     * Initialize naming field
     */
    JLabel l = new JLabel("Name");
    l.setSize(l.getPreferredSize());
    l.setLocation(10, 10);

    nameField = new JTextField("plains");
    nameField.setSize(200, 24);
    nameField.setLocation(10, 32);

    add(l);
    add(nameField);

    /*
     * Initialize encounter spinner
     */
    l = new JLabel("Encounter rate");
    l.setSize(l.getPreferredSize());
    l.setLocation(10, 64);

    eRateSpinner = new JSpinner(new SpinnerNumberModel(1, 1, 20, 1));
    eRateSpinner.setSize(eRateSpinner.getPreferredSize());
    eRateSpinner.setLocation(210 - eRateSpinner.getWidth(), 62);

    add(l);
    add(eRateSpinner);

    /*
     * Initialize Terrain selector
     */
    l = new JLabel("Terrain");
    l.setSize(l.getPreferredSize());
    l.setLocation(10, 96);

    terrain = new JComboBox(ToolKit.terrains);
    terrain.setSize(200, 24);
    terrain.setLocation(10, 120);

    add(l);
    add(terrain);

    /*
     * Initialize formation list
     */
    l = new JLabel("Formations");
    l.setSize(l.getPreferredSize());
    l.setLocation(10, 156);

    fList = new JList(formations);
    fPane = new JScrollPane(fList);
    fPane.setSize(200, 160);
    fPane.setLocation(10, 172);

    add(l);
    add(fPane);

    /*
     * Initialize buttons
     */
    okButton = new JButton("OK");
    okButton.setSize(80, 24);
    okButton.setLocation(20, 380);
    okButton.addActionListener(this);
    cancelButton = new JButton("Cancel");
    cancelButton.setSize(80, 24);
    cancelButton.setLocation(120, 380);
    cancelButton.addActionListener(this);

    add(okButton);
    add(cancelButton);

    fRemButton = new JButton("-");
    fRemButton.setSize(fRemButton.getPreferredSize());
    fRemButton.setLocation(210 - fRemButton.getWidth(), 335);

    fAddButton = new JButton("+");
    fAddButton.setSize(fAddButton.getPreferredSize());
    fAddButton.setLocation(fRemButton.getX() - fAddButton.getWidth(), 335);

    fEdtButton = new JButton("Edit");
    fEdtButton.setSize(100, 24);
    fEdtButton.setLocation(10, 335);

    fAddButton.addActionListener(this);
    fRemButton.addActionListener(this);
    fEdtButton.addActionListener(this);

    add(fAddButton);
    add(fRemButton);
    add(fEdtButton);

    /*
     * Initialize dialog window
     */
    setSize(230, 450);
    setVisible(true);
    setModal(true);
    setResizable(false);
    setTitle("Region Editor");
    setLocationRelativeTo(parent);
  }
コード例 #2
0
  /** performs the creation of the dialog and all its components. */
  protected void initGUI() {
    JPanel panel;
    SpinnerNumberModel model;
    JPanel panel2;

    getContentPane().setLayout(new BorderLayout());

    panel = new JPanel(new GridLayout(6, 1));
    panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    getContentPane().add(panel, BorderLayout.CENTER);

    // mean precision
    m_MeanPrecSpinner = new JSpinner();
    m_MeanPrecSpinner.addChangeListener(
        new ChangeListener() {
          public void stateChanged(ChangeEvent e) {
            getData();
          }
        });
    model = (SpinnerNumberModel) m_MeanPrecSpinner.getModel();
    model.setMaximum(new Integer(20));
    model.setMinimum(new Integer(0));
    m_MeanPrecLabel = new JLabel("Mean Precision");
    m_MeanPrecLabel.setDisplayedMnemonic('M');
    m_MeanPrecLabel.setLabelFor(m_MeanPrecSpinner);
    panel2 = new JPanel(new FlowLayout(FlowLayout.LEFT));
    panel2.add(m_MeanPrecLabel);
    panel2.add(m_MeanPrecSpinner);
    panel.add(panel2);

    // stddev precision
    m_StdDevPrecSpinner = new JSpinner();
    m_StdDevPrecSpinner.addChangeListener(
        new ChangeListener() {
          public void stateChanged(ChangeEvent e) {
            getData();
          }
        });
    model = (SpinnerNumberModel) m_StdDevPrecSpinner.getModel();
    model.setMaximum(new Integer(20));
    model.setMinimum(new Integer(0));
    m_StdDevPrecLabel = new JLabel("StdDev. Precision");
    m_StdDevPrecLabel.setDisplayedMnemonic('S');
    m_StdDevPrecLabel.setLabelFor(m_StdDevPrecSpinner);
    panel2 = new JPanel(new FlowLayout(FlowLayout.LEFT));
    panel2.add(m_StdDevPrecLabel);
    panel2.add(m_StdDevPrecSpinner);
    panel.add(panel2);

    // Format
    m_OutputFormatComboBox = new JComboBox(m_OutputFormatNames);
    m_OutputFormatComboBox.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            getData();
          }
        });
    m_OutputFormatLabel = new JLabel("Output Format");
    m_OutputFormatLabel.setDisplayedMnemonic('F');
    m_OutputFormatLabel.setLabelFor(m_OutputFormatComboBox);
    panel2 = new JPanel(new FlowLayout(FlowLayout.LEFT));
    panel2.add(m_OutputFormatLabel);
    panel2.add(m_OutputFormatComboBox);
    panel.add(panel2);

    // Average
    m_ShowAverageCheckBox = new JCheckBox("");
    m_ShowAverageCheckBox.addChangeListener(
        new ChangeListener() {
          public void stateChanged(ChangeEvent e) {
            getData();
          }
        });
    m_ShowAverageLabel = new JLabel("Show Average");
    m_ShowAverageLabel.setDisplayedMnemonic('A');
    m_ShowAverageLabel.setLabelFor(m_ShowAverageCheckBox);
    panel2 = new JPanel(new FlowLayout(FlowLayout.LEFT));
    panel2.add(m_ShowAverageLabel);
    panel2.add(m_ShowAverageCheckBox);
    panel.add(panel2);

    // Remove filter classname
    m_RemoveFilterNameCheckBox = new JCheckBox("");
    m_RemoveFilterNameCheckBox.addChangeListener(
        new ChangeListener() {
          public void stateChanged(ChangeEvent e) {
            getData();
          }
        });
    m_RemoveFilterNameLabel = new JLabel("Remove filter classnames");
    m_RemoveFilterNameLabel.setDisplayedMnemonic('R');
    m_RemoveFilterNameLabel.setLabelFor(m_RemoveFilterNameCheckBox);
    panel2 = new JPanel(new FlowLayout(FlowLayout.LEFT));
    panel2.add(m_RemoveFilterNameLabel);
    panel2.add(m_RemoveFilterNameCheckBox);
    panel.add(panel2);

    // Advanced setup
    m_ResultMatrix = ExperimenterDefaults.getOutputFormat();
    m_ResultMatrixEditor = new GenericObjectEditor(true);
    m_ResultMatrixEditor.setClassType(ResultMatrix.class);
    m_ResultMatrixEditor.setValue(m_ResultMatrix);
    m_ResultMatrixEditor.addPropertyChangeListener(
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent e) {
            // user selected different class?
            if (!m_ResultMatrix.getClass().equals(m_ResultMatrixEditor.getValue().getClass())) {
              // if it's the preferred class, then automaticallly use the Experimenter defaults
              if (m_ResultMatrixEditor
                  .getValue()
                  .getClass()
                  .equals(ExperimenterDefaults.getOutputFormat().getClass())) {
                m_ResultMatrix = ExperimenterDefaults.getOutputFormat();
                m_ResultMatrixEditor.setValue(ExperimenterDefaults.getOutputFormat());
              } else {
                m_ResultMatrix = (ResultMatrix) m_ResultMatrixEditor.getValue();
              }
              setData();
            }
            repaint();
          }
        });
    ((GenericObjectEditor.GOEPanel) m_ResultMatrixEditor.getCustomEditor())
        .addOkListener(
            new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                m_ResultMatrix = (ResultMatrix) m_ResultMatrixEditor.getValue();
                setData();
              }
            });
    m_ResultMatrixPanel = new PropertyPanel(m_ResultMatrixEditor, false);
    m_ResultMatrixLabel = new JLabel("Advanced setup");
    panel2 = new JPanel(new FlowLayout(FlowLayout.LEFT));
    panel2.add(m_ResultMatrixLabel);
    panel2.add(m_ResultMatrixPanel);
    panel.add(panel2);

    // Buttons
    panel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    getContentPane().add(panel, BorderLayout.SOUTH);
    m_CancelButton = new JButton("Cancel");
    m_CancelButton.setMnemonic('C');
    m_CancelButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            m_Result = CANCEL_OPTION;
            setVisible(false);
          }
        });
    m_OkButton = new JButton("OK");
    m_OkButton.setMnemonic('O');
    m_OkButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            getData();
            m_Result = APPROVE_OPTION;
            setVisible(false);
          }
        });
    panel.add(m_OkButton);
    panel.add(m_CancelButton);

    // default button
    getRootPane().setDefaultButton(m_OkButton);

    // initial layout (to get widths and heights)
    pack();

    // adjust dimensions
    m_MeanPrecLabel.setPreferredSize(
        new Dimension(m_RemoveFilterNameLabel.getWidth(), m_MeanPrecLabel.getHeight()));
    m_MeanPrecSpinner.setPreferredSize(
        new Dimension(m_MeanPrecSpinner.getWidth() * 3, m_MeanPrecSpinner.getHeight()));
    m_StdDevPrecLabel.setPreferredSize(
        new Dimension(m_RemoveFilterNameLabel.getWidth(), m_StdDevPrecLabel.getHeight()));
    m_StdDevPrecSpinner.setPreferredSize(
        new Dimension(m_StdDevPrecSpinner.getWidth() * 3, m_StdDevPrecSpinner.getHeight()));
    m_OutputFormatLabel.setPreferredSize(
        new Dimension(m_RemoveFilterNameLabel.getWidth(), m_OutputFormatLabel.getHeight()));
    m_ShowAverageLabel.setPreferredSize(
        new Dimension(m_RemoveFilterNameLabel.getWidth(), m_ShowAverageLabel.getHeight()));
    m_ResultMatrixLabel.setPreferredSize(
        new Dimension(m_RemoveFilterNameLabel.getWidth(), m_ResultMatrixLabel.getHeight()));
    m_ResultMatrixPanel.setPreferredSize(
        new Dimension(
            (int) (m_ResultMatrixPanel.getWidth() * 1.5), m_ResultMatrixPanel.getHeight()));

    // final layout
    pack();
  }