예제 #1
0
    public void makeSane() {
      descLbl.setText(desc);

      ImageIcon icon = null;
      if (race != null) {
        String imgRace = race;

        if (CrewType.HUMAN.getId().equals(race)) {
          // Human females have a distinct sprite (Other races look the same either way).
          if (!male) imgRace = "female";
        } else if (CrewType.GHOST.getId().equals(race)) {
          // Ghosts look like translucent humans.
          if (male) imgRace = "human";
          else imgRace = "female";
        }

        icon = getCrewIcon(imgRace);
      }
      nameLbl.setIcon(icon);

      if (name != null) nameLbl.setText(name);
      else nameLbl.setText("");

      scoreLbl.setText(Integer.toString(score));
    }
예제 #2
0
  public void actionPerformed(ActionEvent e) {
    Object source = e.getSource();
    if (editMap.containsKey(source)) {
      final StatRow row = getRow(editMap.get(source));

      JPanel popupPanel = new JPanel(new BorderLayout());

      final FieldEditorPanel editorPanel = new FieldEditorPanel(true);
      editorPanel.addRow(RACE, FieldEditorPanel.ContentType.COMBO);
      editorPanel.addRow(MALE, FieldEditorPanel.ContentType.BOOLEAN);
      editorPanel.addRow(NAME, FieldEditorPanel.ContentType.STRING);
      editorPanel.addRow(SCORE, FieldEditorPanel.ContentType.INTEGER);

      if (row.race != null) {
        editorPanel.getCombo(RACE).addItem(CrewType.CRYSTAL.getId());
        editorPanel.getCombo(RACE).addItem(CrewType.ENERGY.getId());
        editorPanel.getCombo(RACE).addItem(CrewType.ENGI.getId());
        editorPanel.getCombo(RACE).addItem(CrewType.GHOST.getId());
        editorPanel.getCombo(RACE).addItem(CrewType.HUMAN.getId());
        editorPanel.getCombo(RACE).addItem(CrewType.MANTIS.getId());
        editorPanel.getCombo(RACE).addItem(CrewType.ROCK.getId());
        editorPanel.getCombo(RACE).addItem(CrewType.SLUG.getId());
        editorPanel.getCombo(RACE).setSelectedItem(row.race);
        editorPanel.setBoolAndReminder(MALE, row.male);
      } else {
        editorPanel.getCombo(RACE).setEnabled(false);
        editorPanel.getBoolean(MALE).setEnabled(false);
      }

      if (row.name != null) {
        editorPanel.setStringAndReminder(NAME, row.name);
      } else {
        editorPanel.getString(NAME).setEnabled(false);
      }

      editorPanel.setIntAndReminder(SCORE, row.score);
      popupPanel.add(new JLabel(row.desc), BorderLayout.NORTH);
      popupPanel.add(editorPanel, BorderLayout.CENTER);

      JPanel ctrlPanel = new JPanel();
      ctrlPanel.setLayout(new BoxLayout(ctrlPanel, BoxLayout.X_AXIS));
      ctrlPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
      ctrlPanel.add(Box.createHorizontalGlue());
      JButton popupOkBtn = new JButton("OK");
      ctrlPanel.add(popupOkBtn);
      ctrlPanel.add(Box.createHorizontalGlue());
      JButton popupCancelBtn = new JButton("Cancel");
      ctrlPanel.add(popupCancelBtn);
      ctrlPanel.add(Box.createHorizontalGlue());
      popupPanel.add(ctrlPanel, BorderLayout.SOUTH);
      popupOkBtn.setPreferredSize(popupCancelBtn.getPreferredSize());

      final JDialog popup =
          new JDialog((java.awt.Frame) this.getTopLevelAncestor(), "Edit Score", true);
      popup.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
      popup.getContentPane().add(popupPanel);
      popup.pack();
      popup.setLocationRelativeTo(null);

      popupCancelBtn.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              popup.setVisible(false);
              popup.dispose();
            }
          });

      popupOkBtn.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              String newString = null;

              if (row.race != null) {
                newString = (String) editorPanel.getCombo(RACE).getSelectedItem();
                if (CrewType.findById(newString) != null) {
                  row.race = newString;
                  row.male = editorPanel.getBoolean(MALE).isSelected();
                }
              }
              if (row.name != null) row.name = editorPanel.getString(NAME).getText();

              newString = editorPanel.getInt(SCORE).getText();
              try {
                row.score = Integer.parseInt(newString);
              } catch (NumberFormatException f) {
              }

              row.makeSane();

              popup.setVisible(false);
              popup.dispose();
            }
          });

      popup.setVisible(true);
    }
  }