package org.leumasjaffe.charsheet.view.magic; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; import org.leumasjaffe.charsheet.model.Ability; import org.leumasjaffe.charsheet.model.magic.DDSpellbook; import org.leumasjaffe.charsheet.model.observable.IntValue; import java.awt.Dimension; class SpellsPerDayHeader extends JPanel { /** * */ private static final long serialVersionUID = 1L; private JTextField textFieldRemaining; public SpellsPerDayHeader(int level, DDSpellbook model, IntValue ability) { setPreferredSize(new Dimension(350, 20)); GridBagLayout gridBagLayout = new GridBagLayout(); gridBagLayout.columnWidths = new int[]{0, 30, 0, 30, 0, 30, 0, 30, 0, 0}; gridBagLayout.rowHeights = new int[]{0, 0}; gridBagLayout.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE}; gridBagLayout.rowWeights = new double[]{0.0, Double.MIN_VALUE}; setLayout(gridBagLayout); JLabel lblSpellLevel = new JLabel("Spell Level:"); GridBagConstraints gbc_lblSpellLevel = new GridBagConstraints(); gbc_lblSpellLevel.insets = new Insets(0, 0, 0, 5); gbc_lblSpellLevel.anchor = GridBagConstraints.EAST; gbc_lblSpellLevel.gridx = 0; gbc_lblSpellLevel.gridy = 0; add(lblSpellLevel, gbc_lblSpellLevel); JTextField textFieldLevel = new JTextField(Integer.toString(level)); textFieldLevel.setEditable(false); GridBagConstraints gbc_textFieldLevel = new GridBagConstraints(); gbc_textFieldLevel.fill = GridBagConstraints.HORIZONTAL; gbc_textFieldLevel.insets = new Insets(0, 0, 0, 5); gbc_textFieldLevel.gridx = 1; gbc_textFieldLevel.gridy = 0; add(textFieldLevel, gbc_textFieldLevel); textFieldLevel.setColumns(10); JLabel lblSaveDc = new JLabel("Save DC:"); GridBagConstraints gbc_lblSaveDc = new GridBagConstraints(); gbc_lblSaveDc.anchor = GridBagConstraints.EAST; gbc_lblSaveDc.insets = new Insets(0, 0, 0, 5); gbc_lblSaveDc.gridx = 2; gbc_lblSaveDc.gridy = 0; add(lblSaveDc, gbc_lblSaveDc); JTextField textFieldSpellSave = new JTextField(Integer.toString(10 + level + Ability.modifier(ability.value()))); textFieldSpellSave.setEditable(false); textFieldSpellSave.setColumns(10); GridBagConstraints gbc_textFieldSpellSave = new GridBagConstraints(); gbc_textFieldSpellSave.fill = GridBagConstraints.HORIZONTAL; gbc_textFieldSpellSave.insets = new Insets(0, 0, 0, 5); gbc_textFieldSpellSave.gridx = 3; gbc_textFieldSpellSave.gridy = 0; add(textFieldSpellSave, gbc_textFieldSpellSave); JLabel lblSpellsPerDay = new JLabel("Spells Per Day:"); GridBagConstraints gbc_lblSpellsPerDay = new GridBagConstraints(); gbc_lblSpellsPerDay.insets = new Insets(0, 0, 0, 5); gbc_lblSpellsPerDay.gridx = 4; gbc_lblSpellsPerDay.gridy = 0; add(lblSpellsPerDay, gbc_lblSpellsPerDay); textFieldRemaining = new JTextField(Integer.toString(model.numSpellsPerDayRemainingAtLevel(level))); GridBagConstraints gbc_textFieldRemaining = new GridBagConstraints(); gbc_textFieldRemaining.fill = GridBagConstraints.HORIZONTAL; gbc_textFieldRemaining.insets = new Insets(0, 0, 0, 5); gbc_textFieldRemaining.gridx = 5; gbc_textFieldRemaining.gridy = 0; add(textFieldRemaining, gbc_textFieldRemaining); textFieldRemaining.setEditable(false); textFieldRemaining.setColumns(10); JLabel label = new JLabel("/"); GridBagConstraints gbc_label = new GridBagConstraints(); gbc_label.insets = new Insets(0, 0, 0, 5); gbc_label.gridx = 6; gbc_label.gridy = 0; add(label, gbc_label); JTextField textFieldOutOf = new JTextField(Integer.toString(model.numSpellsPerDayAtLevel(level))); GridBagConstraints gbc_textFieldOutOf = new GridBagConstraints(); gbc_textFieldOutOf.insets = new Insets(0, 0, 0, 5); gbc_textFieldOutOf.fill = GridBagConstraints.HORIZONTAL; gbc_textFieldOutOf.gridx = 7; gbc_textFieldOutOf.gridy = 0; add(textFieldOutOf, gbc_textFieldOutOf); textFieldOutOf.setEditable(false); textFieldOutOf.setColumns(10); } // Technically unsafe, but since this should only get called when a spell is cast, the number will not drop below 0 public void reload() { textFieldRemaining.setText(Integer.toString(Integer.parseInt(textFieldRemaining.getText())-1)); } }