protected void load() { nameField.setText(data.name); costField.setValue(data.cost); colorBox.setSelectedItem(data.color); charField.setValue(data.text); weightField.setValue(data.weight); spellBox.setSelectedItem(data.spell); }
protected void save() { data.name = nameField.getText(); try { costField.commitEdit(); data.cost = ((Long) costField.getValue()).intValue(); } catch (ParseException e) { data.cost = 0; } data.color = colorBox.getSelectedItem().toString(); data.text = charField.getText(); data.weight = Float.parseFloat(weightField.getText()); if (spellBox.getSelectedItem() != null) { data.spell = spellBox.getSelectedItem().toString(); } data.setPath(Editor.getStore().getActive().get("id")); }
public FoodEditor(JFrame parent, RItem data) { super(parent, "Scroll Editor: " + data.id); this.data = data; JPanel itemProps = new JPanel(); GroupLayout layout = new GroupLayout(itemProps); itemProps.setLayout(layout); layout.setAutoCreateGaps(true); JLabel nameLabel = new JLabel("Name: "); JLabel costLabel = new JLabel("Cost: "); JLabel colorLabel = new JLabel("Color: "); JLabel charLabel = new JLabel("Character: "); JLabel weightLabel = new JLabel("Weight: "); JLabel spellLabel = new JLabel("Spell: "); nameField = new JTextField(15); costField = new JFormattedTextField(NeonFormat.getIntegerInstance()); colorBox = new JComboBox<String>(ColorFactory.getColorNames()); colorBox.setBackground(Color.black); colorBox.setRenderer(new ColorCellRenderer()); colorBox.addActionListener(new ColorListener(colorBox)); charField = new JFormattedTextField(getMaskFormatter("*", 'X')); weightField = new JFormattedTextField(NeonFormat.getFloatInstance()); spellBox = new JComboBox<String>(loadSpells()); JLabel nameHelpLabel = HelpLabels.getNameHelpLabel(); JLabel costHelpLabel = HelpLabels.getCostHelpLabel(); JLabel colorHelpLabel = HelpLabels.getColorHelpLabel(); JLabel charHelpLabel = HelpLabels.getCharHelpLabel(); JLabel weightHelpLabel = HelpLabels.getWeightHelpLabel(); JLabel foodHelpLabel = HelpLabels.getFoodEffectHelpLabel(); layout.setVerticalGroup( layout .createSequentialGroup() .addGroup( layout .createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(nameLabel) .addComponent(nameField) .addComponent(nameHelpLabel)) .addGroup( layout .createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(costLabel) .addComponent(costField) .addComponent(costHelpLabel)) .addGroup( layout .createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(colorLabel) .addComponent(colorBox) .addComponent(colorHelpLabel)) .addGroup( layout .createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(charLabel) .addComponent(charField) .addComponent(charHelpLabel)) .addGroup( layout .createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(weightLabel) .addComponent(weightField) .addComponent(weightHelpLabel)) .addGroup( layout .createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(spellLabel) .addComponent(spellBox) .addComponent(foodHelpLabel))); layout.setHorizontalGroup( layout .createSequentialGroup() .addGroup( layout .createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(nameLabel) .addComponent(costLabel) .addComponent(colorLabel) .addComponent(charLabel) .addComponent(weightLabel) .addComponent(spellLabel)) .addGroup( layout .createParallelGroup(GroupLayout.Alignment.LEADING, false) .addComponent( nameField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(costField) .addComponent(colorBox) .addComponent(charField) .addComponent(weightField) .addComponent(spellBox)) .addGap(10) .addGroup( layout .createParallelGroup(GroupLayout.Alignment.LEADING, false) .addComponent(nameHelpLabel) .addComponent(costHelpLabel) .addComponent(colorHelpLabel) .addComponent(charHelpLabel) .addComponent(weightHelpLabel) .addComponent(foodHelpLabel))); JScrollPane propScroller = new JScrollPane(itemProps); propScroller.setBorder(new TitledBorder("Properties")); frame.add(propScroller, BorderLayout.CENTER); }