|
|
@@ -0,0 +1,177 @@
|
|
|
+package org.leumasjaffe.charsheet.view.skills;
|
|
|
+
|
|
|
+import javax.swing.JPanel;
|
|
|
+
|
|
|
+import org.leumasjaffe.charsheet.model.Ability;
|
|
|
+import org.leumasjaffe.charsheet.model.DDCharacter;
|
|
|
+import org.leumasjaffe.charsheet.model.observable.IntValue;
|
|
|
+import org.leumasjaffe.charsheet.model.skill.DDSkill;
|
|
|
+import org.leumasjaffe.charsheet.util.StringHelper;
|
|
|
+import org.leumasjaffe.observer.IndirectObservableListener;
|
|
|
+import org.leumasjaffe.observer.ObservableListener;
|
|
|
+
|
|
|
+import lombok.AccessLevel;
|
|
|
+import lombok.experimental.FieldDefaults;
|
|
|
+
|
|
|
+import java.awt.GridBagLayout;
|
|
|
+import javax.swing.JCheckBox;
|
|
|
+import java.awt.GridBagConstraints;
|
|
|
+import javax.swing.JLabel;
|
|
|
+import java.awt.Insets;
|
|
|
+import java.awt.Dimension;
|
|
|
+import javax.swing.JTextField;
|
|
|
+import java.awt.Color;
|
|
|
+import javax.swing.border.MatteBorder;
|
|
|
+import javax.swing.SwingConstants;
|
|
|
+
|
|
|
+@FieldDefaults(level=AccessLevel.PRIVATE, makeFinal=true)
|
|
|
+public class SkillLine extends JPanel {
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ */
|
|
|
+ private static final long serialVersionUID = 1L;
|
|
|
+ ObservableListener<JTextField, IntValue> modifierListener;
|
|
|
+ IndirectObservableListener<JTextField, DDCharacter> totalListener;
|
|
|
+
|
|
|
+ public SkillLine(final DDCharacter chara, final DDSkill skill) {
|
|
|
+ setBorder(new MatteBorder(0, 0, 1, 0, (Color) new Color(0, 0, 0)));
|
|
|
+ setPreferredSize(new Dimension(550, 22));
|
|
|
+ GridBagLayout gridBagLayout = new GridBagLayout();
|
|
|
+ gridBagLayout.columnWidths = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0.0, 0.0, 1.0, Double.MIN_VALUE};
|
|
|
+ gridBagLayout.rowWeights = new double[]{0.0, Double.MIN_VALUE};
|
|
|
+ setLayout(gridBagLayout);
|
|
|
+
|
|
|
+ JCheckBox checkBoxIsClassSkill = new JCheckBox("");
|
|
|
+ checkBoxIsClassSkill.setToolTipText("Class Skill?");
|
|
|
+ checkBoxIsClassSkill.setSelected(skill.isClassSkill());
|
|
|
+ checkBoxIsClassSkill.setEnabled(false);
|
|
|
+ GridBagConstraints gbc_checkBoxIsClassSkill = new GridBagConstraints();
|
|
|
+ gbc_checkBoxIsClassSkill.insets = new Insets(1, 0, 0, 0);
|
|
|
+ gbc_checkBoxIsClassSkill.gridx = 0;
|
|
|
+ gbc_checkBoxIsClassSkill.gridy = 0;
|
|
|
+ add(checkBoxIsClassSkill, gbc_checkBoxIsClassSkill);
|
|
|
+
|
|
|
+ JLabel lblName = new JLabel(skill.getName());
|
|
|
+ lblName.setMaximumSize(new Dimension(150, 14));
|
|
|
+ lblName.setMinimumSize(new Dimension(150, 14));
|
|
|
+ lblName.setPreferredSize(new Dimension(150, 14));
|
|
|
+ GridBagConstraints gbc_lblName = new GridBagConstraints();
|
|
|
+ gbc_lblName.fill = GridBagConstraints.HORIZONTAL;
|
|
|
+ gbc_lblName.insets = new Insets(1, 0, 0, 0);
|
|
|
+ gbc_lblName.gridx = 1;
|
|
|
+ gbc_lblName.gridy = 0;
|
|
|
+ add(lblName, gbc_lblName);
|
|
|
+
|
|
|
+ JLabel lblAbil = new JLabel(skill.getAbility());
|
|
|
+ lblAbil.setMaximumSize(new Dimension(30, 14));
|
|
|
+ lblAbil.setMinimumSize(new Dimension(30, 14));
|
|
|
+ lblAbil.setPreferredSize(new Dimension(30, 14));
|
|
|
+ GridBagConstraints gbc_lblAbil = new GridBagConstraints();
|
|
|
+ gbc_lblAbil.insets = new Insets(1, 0, 0, 0);
|
|
|
+ gbc_lblAbil.anchor = GridBagConstraints.EAST;
|
|
|
+ gbc_lblAbil.gridx = 2;
|
|
|
+ gbc_lblAbil.gridy = 0;
|
|
|
+ add(lblAbil, gbc_lblAbil);
|
|
|
+
|
|
|
+ JTextField total = new JTextField();
|
|
|
+ total.setToolTipText("Skill Modifier");
|
|
|
+ total.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
+ total.setEditable(false);
|
|
|
+ total.setMinimumSize(new Dimension(30, 20));
|
|
|
+ total.setMaximumSize(new Dimension(30, 20));
|
|
|
+ total.setPreferredSize(new Dimension(30, 20));
|
|
|
+ GridBagConstraints gbc_total = new GridBagConstraints();
|
|
|
+ gbc_total.insets = new Insets(1, 0, 0, 0);
|
|
|
+ gbc_total.fill = GridBagConstraints.HORIZONTAL;
|
|
|
+ gbc_total.gridx = 3;
|
|
|
+ gbc_total.gridy = 0;
|
|
|
+ add(total, gbc_total);
|
|
|
+ total.setColumns(10);
|
|
|
+
|
|
|
+ JLabel label = new JLabel("=");
|
|
|
+ GridBagConstraints gbc_label = new GridBagConstraints();
|
|
|
+ gbc_label.anchor = GridBagConstraints.EAST;
|
|
|
+ gbc_label.insets = new Insets(1, 0, 0, 1);
|
|
|
+ gbc_label.gridx = 4;
|
|
|
+ gbc_label.gridy = 0;
|
|
|
+ add(label, gbc_label);
|
|
|
+
|
|
|
+ JTextField modifier = new JTextField();
|
|
|
+ modifier.setToolTipText("Ability Modifier");
|
|
|
+ modifier.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
+ modifier.setEditable(false);
|
|
|
+ modifier.setMinimumSize(new Dimension(30, 20));
|
|
|
+ modifier.setMaximumSize(new Dimension(30, 20));
|
|
|
+ modifier.setPreferredSize(new Dimension(30, 20));
|
|
|
+ GridBagConstraints gbc_modifier = new GridBagConstraints();
|
|
|
+ gbc_modifier.insets = new Insets(1, 0, 0, 0);
|
|
|
+ gbc_modifier.fill = GridBagConstraints.HORIZONTAL;
|
|
|
+ gbc_modifier.gridx = 5;
|
|
|
+ gbc_modifier.gridy = 0;
|
|
|
+ add(modifier, gbc_modifier);
|
|
|
+ modifier.setColumns(10);
|
|
|
+
|
|
|
+ JLabel label_1 = new JLabel("+");
|
|
|
+ GridBagConstraints gbc_label_1 = new GridBagConstraints();
|
|
|
+ gbc_label_1.anchor = GridBagConstraints.EAST;
|
|
|
+ gbc_label_1.insets = new Insets(1, 0, 0, 1);
|
|
|
+ gbc_label_1.gridx = 6;
|
|
|
+ gbc_label_1.gridy = 0;
|
|
|
+ add(label_1, gbc_label_1);
|
|
|
+
|
|
|
+ JTextField ranks = new JTextField(StringHelper.toString(skill.getRanks()));
|
|
|
+ ranks.setToolTipText("Ranks");
|
|
|
+ ranks.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
+ ranks.setEditable(false);
|
|
|
+ ranks.setMinimumSize(new Dimension(30, 20));
|
|
|
+ ranks.setMaximumSize(new Dimension(30, 20));
|
|
|
+ ranks.setPreferredSize(new Dimension(30, 20));
|
|
|
+ GridBagConstraints gbc_ranks = new GridBagConstraints();
|
|
|
+ gbc_ranks.insets = new Insets(1, 0, 0, 0);
|
|
|
+ gbc_ranks.fill = GridBagConstraints.HORIZONTAL;
|
|
|
+ gbc_ranks.gridx = 7;
|
|
|
+ gbc_ranks.gridy = 0;
|
|
|
+ add(ranks, gbc_ranks);
|
|
|
+ ranks.setColumns(10);
|
|
|
+
|
|
|
+ JLabel label_2 = new JLabel("+");
|
|
|
+ GridBagConstraints gbc_label_2 = new GridBagConstraints();
|
|
|
+ gbc_label_2.insets = new Insets(1, 0, 0, 1);
|
|
|
+ gbc_label_2.anchor = GridBagConstraints.EAST;
|
|
|
+ gbc_label_2.gridx = 8;
|
|
|
+ gbc_label_2.gridy = 0;
|
|
|
+ add(label_2, gbc_label_2);
|
|
|
+
|
|
|
+ JTextField misc = new JTextField();
|
|
|
+ misc.setToolTipText("Miscellaneous Modifier");
|
|
|
+ misc.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
+ misc.setMinimumSize(new Dimension(30, 20));
|
|
|
+ misc.setMaximumSize(new Dimension(30, 20));
|
|
|
+ misc.setPreferredSize(new Dimension(30, 20));
|
|
|
+ GridBagConstraints gbc_misc = new GridBagConstraints();
|
|
|
+ gbc_misc.insets = new Insets(1, 0, 0, 0);
|
|
|
+ gbc_misc.fill = GridBagConstraints.HORIZONTAL;
|
|
|
+ gbc_misc.gridx = 9;
|
|
|
+ gbc_misc.gridy = 0;
|
|
|
+ add(misc, gbc_misc);
|
|
|
+ misc.setColumns(10);
|
|
|
+
|
|
|
+ totalListener = new IndirectObservableListener<>(total,
|
|
|
+ (c, v) -> {
|
|
|
+ final float skillRanks = skill.getRanks();
|
|
|
+ final int mod = Ability.modifier(Ability.fields.get(skill.getAbility())
|
|
|
+ .apply(chara.getAbilities().getBase()).value());
|
|
|
+ c.setText(StringHelper.toString(skillRanks + mod));
|
|
|
+ });
|
|
|
+ modifierListener = new ObservableListener<>(modifier,
|
|
|
+ ( c, v ) -> c.setText(StringHelper.toString(Ability.modifier(v.value()))));
|
|
|
+
|
|
|
+ final IntValue abilScore = Ability.fields.get(skill.getAbility())
|
|
|
+ .apply(chara.getAbilities().getBase());
|
|
|
+ totalListener.setObserved(chara, abilScore);
|
|
|
+ modifierListener.setObserved(abilScore);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|