|
|
@@ -5,39 +5,91 @@ import javax.swing.JPanel;
|
|
|
import org.jdesktop.swingx.VerticalLayout;
|
|
|
import org.leumasjaffe.charsheet.model.DDCharacterClass;
|
|
|
import org.leumasjaffe.charsheet.model.magic.impl.Prepared;
|
|
|
+
|
|
|
+import lombok.AccessLevel;
|
|
|
+import lombok.experimental.FieldDefaults;
|
|
|
+
|
|
|
import java.awt.GridBagLayout;
|
|
|
import javax.swing.JScrollPane;
|
|
|
import java.awt.GridBagConstraints;
|
|
|
+import java.awt.Insets;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
|
|
|
+import javax.swing.JButton;
|
|
|
+import javax.swing.JDialog;
|
|
|
+
|
|
|
+@FieldDefaults(level=AccessLevel.PRIVATE, makeFinal=true)
|
|
|
public class PrepareSpellsDialog extends JPanel {
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
*/
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
+
|
|
|
+ int[] ready = {0};
|
|
|
+ int highestSpellLevel;
|
|
|
|
|
|
public PrepareSpellsDialog(DDCharacterClass dclass) {
|
|
|
+ highestSpellLevel = dclass.getHighestSpellLevel();
|
|
|
+ ready[0] = highestSpellLevel;
|
|
|
+
|
|
|
GridBagLayout gridBagLayout = new GridBagLayout();
|
|
|
gridBagLayout.columnWidths = new int[]{0, 0};
|
|
|
- gridBagLayout.rowHeights = new int[]{0, 0};
|
|
|
+ gridBagLayout.rowHeights = new int[]{0, 0, 0};
|
|
|
gridBagLayout.columnWeights = new double[]{1.0, Double.MIN_VALUE};
|
|
|
- gridBagLayout.rowWeights = new double[]{1.0, Double.MIN_VALUE};
|
|
|
+ gridBagLayout.rowWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
|
|
|
setLayout(gridBagLayout);
|
|
|
|
|
|
+ JPanel panel_1 = new JPanel();
|
|
|
+ GridBagConstraints gbc_panel_1 = new GridBagConstraints();
|
|
|
+ gbc_panel_1.insets = new Insets(0, 0, 5, 0);
|
|
|
+ gbc_panel_1.fill = GridBagConstraints.BOTH;
|
|
|
+ gbc_panel_1.gridx = 0;
|
|
|
+ gbc_panel_1.gridy = 0;
|
|
|
+ add(panel_1, gbc_panel_1);
|
|
|
+ GridBagLayout gbl_panel_1 = new GridBagLayout();
|
|
|
+ gbl_panel_1.columnWidths = new int[]{0, 0};
|
|
|
+ gbl_panel_1.rowHeights = new int[]{0, 0};
|
|
|
+ gbl_panel_1.columnWeights = new double[]{0.0, Double.MIN_VALUE};
|
|
|
+ gbl_panel_1.rowWeights = new double[]{0.0, Double.MIN_VALUE};
|
|
|
+ panel_1.setLayout(gbl_panel_1);
|
|
|
+
|
|
|
+ JButton btnPrepareTheseSpells = new JButton("Prepare These Spells");
|
|
|
+ GridBagConstraints gbc_btnPrepareTheseSpells = new GridBagConstraints();
|
|
|
+ gbc_btnPrepareTheseSpells.gridx = 0;
|
|
|
+ gbc_btnPrepareTheseSpells.gridy = 0;
|
|
|
+ panel_1.add(btnPrepareTheseSpells, gbc_btnPrepareTheseSpells);
|
|
|
+
|
|
|
JScrollPane scrollPane = new JScrollPane();
|
|
|
GridBagConstraints gbc_scrollPane = new GridBagConstraints();
|
|
|
gbc_scrollPane.fill = GridBagConstraints.BOTH;
|
|
|
gbc_scrollPane.gridx = 0;
|
|
|
- gbc_scrollPane.gridy = 0;
|
|
|
+ gbc_scrollPane.gridy = 1;
|
|
|
add(scrollPane, gbc_scrollPane);
|
|
|
|
|
|
JPanel panel = new JPanel(new VerticalLayout(5));
|
|
|
scrollPane.setViewportView(panel);
|
|
|
|
|
|
final Prepared spellBook = (Prepared) dclass.getSpellBook().get();
|
|
|
- for (int i = 0; i < dclass.getHighestSpellLevel(); ++i) {
|
|
|
- panel.add(new SelectPreparedSpellsPanel(spellBook.getSpellsPreparedPreviouslyForLevel(i), spellBook.spellsKnownAtLevel(i)));
|
|
|
+ List<SelectPreparedSpellsPanel> panels = new ArrayList<>();
|
|
|
+ for (int i = 0; i < highestSpellLevel; ++i) {
|
|
|
+ SelectPreparedSpellsPanel lvl = new SelectPreparedSpellsPanel(spellBook.getSpellsPreparedPreviouslyForLevel(i), spellBook.spellsKnownAtLevel(i));
|
|
|
+ panels.add(lvl);
|
|
|
+ lvl.addPropertyChangeListener(SelectPreparedSpellsPanel.READY, e -> {
|
|
|
+ if ((Boolean) e.getNewValue()) ++ready[0];
|
|
|
+ else --ready[0];
|
|
|
+ btnPrepareTheseSpells.setEnabled(ready[0] == highestSpellLevel);
|
|
|
+ });
|
|
|
+ panel.add(lvl);
|
|
|
}
|
|
|
+
|
|
|
+ btnPrepareTheseSpells.addActionListener(e -> {
|
|
|
+ ((JDialog) this.getParent().getParent().getParent()).dispose();
|
|
|
+ for (int i = 0; i < highestSpellLevel; ++i) {
|
|
|
+ spellBook.prepareSpells(i, panels.get(i).getPrepared());
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
}
|