| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- package org.leumasjaffe.charsheet.view.summary;
- import javax.swing.JPanel;
- import java.awt.GridBagLayout;
- import javax.swing.JLabel;
- import java.awt.GridBagConstraints;
- import java.awt.Color;
- import javax.swing.border.LineBorder;
- import org.leumasjaffe.charsheet.model.AbilityScores;
- import org.leumasjaffe.charsheet.model.DDCharacter;
- import org.leumasjaffe.charsheet.model.observable.IntValue;
- import org.leumasjaffe.charsheet.observer.helper.AbilModStringify;
- import org.leumasjaffe.charsheet.view.StringHelper;
- import org.leumasjaffe.observer.IndirectObservableListener;
- import org.leumasjaffe.observer.ObservableListener;
- import lombok.AccessLevel;
- import lombok.experimental.FieldDefaults;
- import lombok.experimental.NonFinal;
- import java.awt.Font;
- import javax.swing.SwingConstants;
- import java.awt.Dimension;
- import java.awt.Insets;
- import javax.swing.JTextField;
- import java.awt.Component;
- import javax.swing.Box;
- @FieldDefaults(level=AccessLevel.PRIVATE, makeFinal=true)
- public class AttackLine extends JPanel {
- /**
- *
- */
- private static final long serialVersionUID = 1L;
- @NonFinal DDCharacter model;
-
- JTextField grappleTtl;
- JTextField grappleBab;
- JTextField grappleMisc;
- JTextField grappleSize;
- JTextField baseAttack;
- JTextField grappleStrength;
-
- IndirectObservableListener<DDCharacter> gTtlObserver;
- ObservableListener<IntValue> gStrObserver;
- public AttackLine() {
- setPreferredSize(new Dimension(600, 25));
- setOpaque(false);
- GridBagLayout gridBagLayout = new GridBagLayout();
- gridBagLayout.columnWidths = new int[]{200, 0, 0, 120, 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, 0.0, 0.0, 0.0, Double.MIN_VALUE};
- gridBagLayout.rowWeights = new double[]{0.0, Double.MIN_VALUE};
- setLayout(gridBagLayout);
-
- JLabel lblBaseAttackBonus = new JLabel("BASE ATTACK BONUS");
- lblBaseAttackBonus.setToolTipText("");
- lblBaseAttackBonus.setPreferredSize(new Dimension(200, 25));
- lblBaseAttackBonus.setOpaque(true);
- lblBaseAttackBonus.setMinimumSize(new Dimension(50, 25));
- lblBaseAttackBonus.setMaximumSize(new Dimension(50, 25));
- lblBaseAttackBonus.setHorizontalAlignment(SwingConstants.CENTER);
- lblBaseAttackBonus.setForeground(Color.WHITE);
- lblBaseAttackBonus.setFont(new Font("Tahoma", Font.BOLD, 18));
- lblBaseAttackBonus.setBorder(new LineBorder(Color.WHITE));
- lblBaseAttackBonus.setBackground(Color.BLACK);
- GridBagConstraints gbc_lblBaseAttackBonus = new GridBagConstraints();
- gbc_lblBaseAttackBonus.fill = GridBagConstraints.HORIZONTAL;
- gbc_lblBaseAttackBonus.insets = new Insets(0, 0, 0, 5);
- gbc_lblBaseAttackBonus.gridx = 0;
- gbc_lblBaseAttackBonus.gridy = 0;
- add(lblBaseAttackBonus, gbc_lblBaseAttackBonus);
-
- baseAttack = new JTextField();
- baseAttack.setToolTipText("");
- baseAttack.setPreferredSize(new Dimension(30, 20));
- baseAttack.setMinimumSize(new Dimension(30, 20));
- baseAttack.setMaximumSize(new Dimension(30, 20));
- baseAttack.setHorizontalAlignment(SwingConstants.CENTER);
- baseAttack.setEditable(false);
- baseAttack.setColumns(3);
- baseAttack.setBorder(new LineBorder(Color.BLACK));
- GridBagConstraints gbc_baseAttack = new GridBagConstraints();
- gbc_baseAttack.insets = new Insets(0, 0, 0, 5);
- gbc_baseAttack.fill = GridBagConstraints.HORIZONTAL;
- gbc_baseAttack.gridx = 1;
- gbc_baseAttack.gridy = 0;
- add(baseAttack, gbc_baseAttack);
-
- Component horizontalStrut = Box.createHorizontalStrut(20);
- horizontalStrut.setPreferredSize(new Dimension(60, 0));
- GridBagConstraints gbc_horizontalStrut = new GridBagConstraints();
- gbc_horizontalStrut.insets = new Insets(0, 0, 0, 5);
- gbc_horizontalStrut.gridx = 2;
- gbc_horizontalStrut.gridy = 0;
- add(horizontalStrut, gbc_horizontalStrut);
-
- JLabel lblGrapple = new JLabel("GRAPPLE");
- lblGrapple.setToolTipText("");
- lblGrapple.setPreferredSize(new Dimension(120, 25));
- lblGrapple.setOpaque(true);
- lblGrapple.setMinimumSize(new Dimension(50, 25));
- lblGrapple.setMaximumSize(new Dimension(50, 25));
- lblGrapple.setHorizontalAlignment(SwingConstants.CENTER);
- lblGrapple.setForeground(Color.WHITE);
- lblGrapple.setFont(new Font("Tahoma", Font.BOLD, 18));
- lblGrapple.setBorder(new LineBorder(Color.WHITE));
- lblGrapple.setBackground(Color.BLACK);
- GridBagConstraints gbc_lblGrapple = new GridBagConstraints();
- gbc_lblGrapple.fill = GridBagConstraints.HORIZONTAL;
- gbc_lblGrapple.insets = new Insets(0, 0, 0, 5);
- gbc_lblGrapple.gridx = 3;
- gbc_lblGrapple.gridy = 0;
- add(lblGrapple, gbc_lblGrapple);
-
- grappleTtl = new JTextField();
- grappleTtl.setToolTipText("Total Grapple");
- grappleTtl.setPreferredSize(new Dimension(30, 20));
- grappleTtl.setMinimumSize(new Dimension(30, 20));
- grappleTtl.setMaximumSize(new Dimension(30, 20));
- grappleTtl.setHorizontalAlignment(SwingConstants.CENTER);
- grappleTtl.setEditable(false);
- grappleTtl.setColumns(3);
- grappleTtl.setBorder(new LineBorder(Color.BLACK));
- GridBagConstraints gbc_grappleTtl = new GridBagConstraints();
- gbc_grappleTtl.insets = new Insets(0, 0, 0, 5);
- gbc_grappleTtl.fill = GridBagConstraints.HORIZONTAL;
- gbc_grappleTtl.gridx = 4;
- gbc_grappleTtl.gridy = 0;
- add(grappleTtl, gbc_grappleTtl);
-
- JLabel label = new JLabel("=");
- GridBagConstraints gbc_label = new GridBagConstraints();
- gbc_label.insets = new Insets(0, 0, 0, 5);
- gbc_label.anchor = GridBagConstraints.EAST;
- gbc_label.gridx = 5;
- gbc_label.gridy = 0;
- add(label, gbc_label);
-
- grappleBab = new JTextField();
- grappleBab.setDocument(baseAttack.getDocument());
- grappleBab.setToolTipText("Base Attack Bonus");
- grappleBab.setPreferredSize(new Dimension(30, 20));
- grappleBab.setMinimumSize(new Dimension(30, 20));
- grappleBab.setMaximumSize(new Dimension(30, 20));
- grappleBab.setHorizontalAlignment(SwingConstants.CENTER);
- grappleBab.setEditable(false);
- grappleBab.setColumns(3);
- grappleBab.setBorder(new LineBorder(Color.BLACK));
- GridBagConstraints gbc_grappleBab = new GridBagConstraints();
- gbc_grappleBab.insets = new Insets(0, 0, 0, 5);
- gbc_grappleBab.fill = GridBagConstraints.HORIZONTAL;
- gbc_grappleBab.gridx = 6;
- gbc_grappleBab.gridy = 0;
- add(grappleBab, gbc_grappleBab);
-
- JLabel label_1 = new JLabel("+");
- GridBagConstraints gbc_label_1 = new GridBagConstraints();
- gbc_label_1.insets = new Insets(0, 0, 0, 5);
- gbc_label_1.anchor = GridBagConstraints.EAST;
- gbc_label_1.gridx = 7;
- gbc_label_1.gridy = 0;
- add(label_1, gbc_label_1);
-
- grappleStrength = new JTextField();
- grappleStrength.setToolTipText("Strength Modifier");
- grappleStrength.setPreferredSize(new Dimension(30, 20));
- grappleStrength.setMinimumSize(new Dimension(30, 20));
- grappleStrength.setMaximumSize(new Dimension(30, 20));
- grappleStrength.setHorizontalAlignment(SwingConstants.CENTER);
- grappleStrength.setEditable(false);
- grappleStrength.setColumns(3);
- grappleStrength.setBorder(new LineBorder(Color.BLACK));
- GridBagConstraints gbc_grappleStrength = new GridBagConstraints();
- gbc_grappleStrength.insets = new Insets(0, 0, 0, 5);
- gbc_grappleStrength.fill = GridBagConstraints.HORIZONTAL;
- gbc_grappleStrength.gridx = 8;
- gbc_grappleStrength.gridy = 0;
- add(grappleStrength, gbc_grappleStrength);
-
- JLabel label_3 = new JLabel("+");
- GridBagConstraints gbc_label_3 = new GridBagConstraints();
- gbc_label_3.insets = new Insets(0, 0, 0, 5);
- gbc_label_3.anchor = GridBagConstraints.EAST;
- gbc_label_3.gridx = 9;
- gbc_label_3.gridy = 0;
- add(label_3, gbc_label_3);
-
- grappleSize = new JTextField();
- grappleSize.setToolTipText("Size Modifier");
- grappleSize.setPreferredSize(new Dimension(30, 20));
- grappleSize.setMinimumSize(new Dimension(30, 20));
- grappleSize.setMaximumSize(new Dimension(30, 20));
- grappleSize.setHorizontalAlignment(SwingConstants.CENTER);
- grappleSize.setEditable(false);
- grappleSize.setColumns(3);
- grappleSize.setBorder(new LineBorder(Color.BLACK));
- GridBagConstraints gbc_grappleSize = new GridBagConstraints();
- gbc_grappleSize.insets = new Insets(0, 0, 0, 5);
- gbc_grappleSize.fill = GridBagConstraints.HORIZONTAL;
- gbc_grappleSize.gridx = 10;
- gbc_grappleSize.gridy = 0;
- add(grappleSize, gbc_grappleSize);
-
- JLabel label_2 = new JLabel("+");
- GridBagConstraints gbc_label_2 = new GridBagConstraints();
- gbc_label_2.insets = new Insets(0, 0, 0, 5);
- gbc_label_2.anchor = GridBagConstraints.EAST;
- gbc_label_2.gridx = 11;
- gbc_label_2.gridy = 0;
- add(label_2, gbc_label_2);
-
- grappleMisc = new JTextField();
- grappleMisc.setToolTipText("Miscellaneous Modifier");
- grappleMisc.setPreferredSize(new Dimension(30, 20));
- grappleMisc.setMinimumSize(new Dimension(30, 20));
- grappleMisc.setMaximumSize(new Dimension(30, 20));
- grappleMisc.setHorizontalAlignment(SwingConstants.CENTER);
- grappleMisc.setEditable(false);
- grappleMisc.setColumns(3);
- grappleMisc.setBorder(new LineBorder(Color.BLACK));
- GridBagConstraints gbc_grappleMisc = new GridBagConstraints();
- gbc_grappleMisc.fill = GridBagConstraints.HORIZONTAL;
- gbc_grappleMisc.gridx = 12;
- gbc_grappleMisc.gridy = 0;
- add(grappleMisc, gbc_grappleMisc);
-
- gTtlObserver = new IndirectObservableListener<>(grappleTtl,
- (v) -> {
- final int bab = v.getBaseAttack();
- final int str = AbilityScores.modifier(this.model.getAbilities().getBase().getStr().value());
- final int size = v.getSize().value().modifier;
- final int misc = 0;
- return StringHelper.toString(bab + str + size + misc);
- });
- gStrObserver = new ObservableListener<>(grappleStrength,
- new AbilModStringify());
- }
- public void setModel(DDCharacter model) {
- this.model = model;
- final int bab = this.model.getBaseAttack();
- final int size = this.model.getSize().value().modifier;
- final int misc = 0;
- this.baseAttack.setText(StringHelper.toString(bab));
- final IntValue str = model.getAbilities().getBase().getStr();
- gTtlObserver.setObserved(model, str);
- gStrObserver.setObserved(str);
- this.grappleSize.setText(StringHelper.toString(size));
- this.grappleMisc.setText(StringHelper.toString(misc));
- }
- }
|