AttackLine.java 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. package org.leumasjaffe.charsheet.view.summary;
  2. import javax.swing.JPanel;
  3. import java.awt.GridBagLayout;
  4. import javax.swing.JLabel;
  5. import java.awt.GridBagConstraints;
  6. import java.awt.Color;
  7. import javax.swing.border.LineBorder;
  8. import org.leumasjaffe.charsheet.model.Ability;
  9. import org.leumasjaffe.charsheet.model.DDCharacter;
  10. import org.leumasjaffe.charsheet.observer.helper.AbilModStringify;
  11. import org.leumasjaffe.charsheet.util.StringHelper;
  12. import org.leumasjaffe.observer.IndirectObservableListener;
  13. import org.leumasjaffe.observer.ObservableListener;
  14. import lombok.AccessLevel;
  15. import lombok.experimental.FieldDefaults;
  16. import lombok.experimental.NonFinal;
  17. import java.awt.Font;
  18. import javax.swing.SwingConstants;
  19. import java.awt.Dimension;
  20. import java.awt.Insets;
  21. import javax.swing.JTextField;
  22. import java.awt.Component;
  23. import javax.swing.Box;
  24. @FieldDefaults(level=AccessLevel.PRIVATE, makeFinal=true)
  25. public class AttackLine extends JPanel {
  26. /**
  27. *
  28. */
  29. private static final long serialVersionUID = 1L;
  30. @NonFinal DDCharacter model;
  31. JTextField grappleMisc;
  32. JTextField grappleSize;
  33. JTextField baseAttack;
  34. IndirectObservableListener<JTextField, DDCharacter> gTtlObserver;
  35. ObservableListener<JTextField, Ability.Scores> gStrObserver;
  36. public AttackLine() {
  37. setPreferredSize(new Dimension(600, 25));
  38. setOpaque(false);
  39. GridBagLayout gridBagLayout = new GridBagLayout();
  40. gridBagLayout.columnWidths = new int[]{200, 0, 0, 120, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  41. gridBagLayout.rowHeights = new int[]{0, 0};
  42. 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};
  43. gridBagLayout.rowWeights = new double[]{0.0, Double.MIN_VALUE};
  44. setLayout(gridBagLayout);
  45. JLabel lblBaseAttackBonus = new JLabel("BASE ATTACK BONUS");
  46. lblBaseAttackBonus.setToolTipText("");
  47. lblBaseAttackBonus.setPreferredSize(new Dimension(200, 25));
  48. lblBaseAttackBonus.setOpaque(true);
  49. lblBaseAttackBonus.setMinimumSize(new Dimension(50, 25));
  50. lblBaseAttackBonus.setMaximumSize(new Dimension(50, 25));
  51. lblBaseAttackBonus.setHorizontalAlignment(SwingConstants.CENTER);
  52. lblBaseAttackBonus.setForeground(Color.WHITE);
  53. lblBaseAttackBonus.setFont(new Font("Tahoma", Font.BOLD, 18));
  54. lblBaseAttackBonus.setBorder(new LineBorder(Color.WHITE));
  55. lblBaseAttackBonus.setBackground(Color.BLACK);
  56. GridBagConstraints gbc_lblBaseAttackBonus = new GridBagConstraints();
  57. gbc_lblBaseAttackBonus.fill = GridBagConstraints.HORIZONTAL;
  58. gbc_lblBaseAttackBonus.insets = new Insets(0, 0, 0, 5);
  59. gbc_lblBaseAttackBonus.gridx = 0;
  60. gbc_lblBaseAttackBonus.gridy = 0;
  61. add(lblBaseAttackBonus, gbc_lblBaseAttackBonus);
  62. baseAttack = new JTextField();
  63. baseAttack.setToolTipText("");
  64. baseAttack.setPreferredSize(new Dimension(30, 20));
  65. baseAttack.setMinimumSize(new Dimension(30, 20));
  66. baseAttack.setMaximumSize(new Dimension(30, 20));
  67. baseAttack.setHorizontalAlignment(SwingConstants.CENTER);
  68. baseAttack.setEditable(false);
  69. baseAttack.setColumns(3);
  70. baseAttack.setBorder(new LineBorder(Color.BLACK));
  71. GridBagConstraints gbc_baseAttack = new GridBagConstraints();
  72. gbc_baseAttack.insets = new Insets(0, 0, 0, 5);
  73. gbc_baseAttack.fill = GridBagConstraints.HORIZONTAL;
  74. gbc_baseAttack.gridx = 1;
  75. gbc_baseAttack.gridy = 0;
  76. add(baseAttack, gbc_baseAttack);
  77. Component horizontalStrut = Box.createHorizontalStrut(20);
  78. horizontalStrut.setPreferredSize(new Dimension(60, 0));
  79. GridBagConstraints gbc_horizontalStrut = new GridBagConstraints();
  80. gbc_horizontalStrut.insets = new Insets(0, 0, 0, 5);
  81. gbc_horizontalStrut.gridx = 2;
  82. gbc_horizontalStrut.gridy = 0;
  83. add(horizontalStrut, gbc_horizontalStrut);
  84. JLabel lblGrapple = new JLabel("GRAPPLE");
  85. lblGrapple.setToolTipText("");
  86. lblGrapple.setPreferredSize(new Dimension(120, 25));
  87. lblGrapple.setOpaque(true);
  88. lblGrapple.setMinimumSize(new Dimension(50, 25));
  89. lblGrapple.setMaximumSize(new Dimension(50, 25));
  90. lblGrapple.setHorizontalAlignment(SwingConstants.CENTER);
  91. lblGrapple.setForeground(Color.WHITE);
  92. lblGrapple.setFont(new Font("Tahoma", Font.BOLD, 18));
  93. lblGrapple.setBorder(new LineBorder(Color.WHITE));
  94. lblGrapple.setBackground(Color.BLACK);
  95. GridBagConstraints gbc_lblGrapple = new GridBagConstraints();
  96. gbc_lblGrapple.fill = GridBagConstraints.HORIZONTAL;
  97. gbc_lblGrapple.insets = new Insets(0, 0, 0, 5);
  98. gbc_lblGrapple.gridx = 3;
  99. gbc_lblGrapple.gridy = 0;
  100. add(lblGrapple, gbc_lblGrapple);
  101. JTextField grappleTtl = new JTextField();
  102. grappleTtl.setToolTipText("Total Grapple");
  103. grappleTtl.setPreferredSize(new Dimension(30, 20));
  104. grappleTtl.setMinimumSize(new Dimension(30, 20));
  105. grappleTtl.setMaximumSize(new Dimension(30, 20));
  106. grappleTtl.setHorizontalAlignment(SwingConstants.CENTER);
  107. grappleTtl.setEditable(false);
  108. grappleTtl.setColumns(3);
  109. grappleTtl.setBorder(new LineBorder(Color.BLACK));
  110. GridBagConstraints gbc_grappleTtl = new GridBagConstraints();
  111. gbc_grappleTtl.insets = new Insets(0, 0, 0, 5);
  112. gbc_grappleTtl.fill = GridBagConstraints.HORIZONTAL;
  113. gbc_grappleTtl.gridx = 4;
  114. gbc_grappleTtl.gridy = 0;
  115. add(grappleTtl, gbc_grappleTtl);
  116. JLabel label = new JLabel("=");
  117. GridBagConstraints gbc_label = new GridBagConstraints();
  118. gbc_label.insets = new Insets(0, 0, 0, 5);
  119. gbc_label.anchor = GridBagConstraints.EAST;
  120. gbc_label.gridx = 5;
  121. gbc_label.gridy = 0;
  122. add(label, gbc_label);
  123. JTextField grappleBab = new JTextField();
  124. grappleBab.setDocument(baseAttack.getDocument());
  125. grappleBab.setToolTipText("Base Attack Bonus");
  126. grappleBab.setPreferredSize(new Dimension(30, 20));
  127. grappleBab.setMinimumSize(new Dimension(30, 20));
  128. grappleBab.setMaximumSize(new Dimension(30, 20));
  129. grappleBab.setHorizontalAlignment(SwingConstants.CENTER);
  130. grappleBab.setEditable(false);
  131. grappleBab.setColumns(3);
  132. grappleBab.setBorder(new LineBorder(Color.BLACK));
  133. GridBagConstraints gbc_grappleBab = new GridBagConstraints();
  134. gbc_grappleBab.insets = new Insets(0, 0, 0, 5);
  135. gbc_grappleBab.fill = GridBagConstraints.HORIZONTAL;
  136. gbc_grappleBab.gridx = 6;
  137. gbc_grappleBab.gridy = 0;
  138. add(grappleBab, gbc_grappleBab);
  139. JLabel label_1 = new JLabel("+");
  140. GridBagConstraints gbc_label_1 = new GridBagConstraints();
  141. gbc_label_1.insets = new Insets(0, 0, 0, 5);
  142. gbc_label_1.anchor = GridBagConstraints.EAST;
  143. gbc_label_1.gridx = 7;
  144. gbc_label_1.gridy = 0;
  145. add(label_1, gbc_label_1);
  146. JTextField grappleStrength = new JTextField();
  147. grappleStrength.setToolTipText("Strength Modifier");
  148. grappleStrength.setPreferredSize(new Dimension(30, 20));
  149. grappleStrength.setMinimumSize(new Dimension(30, 20));
  150. grappleStrength.setMaximumSize(new Dimension(30, 20));
  151. grappleStrength.setHorizontalAlignment(SwingConstants.CENTER);
  152. grappleStrength.setEditable(false);
  153. grappleStrength.setColumns(3);
  154. grappleStrength.setBorder(new LineBorder(Color.BLACK));
  155. GridBagConstraints gbc_grappleStrength = new GridBagConstraints();
  156. gbc_grappleStrength.insets = new Insets(0, 0, 0, 5);
  157. gbc_grappleStrength.fill = GridBagConstraints.HORIZONTAL;
  158. gbc_grappleStrength.gridx = 8;
  159. gbc_grappleStrength.gridy = 0;
  160. add(grappleStrength, gbc_grappleStrength);
  161. JLabel label_3 = new JLabel("+");
  162. GridBagConstraints gbc_label_3 = new GridBagConstraints();
  163. gbc_label_3.insets = new Insets(0, 0, 0, 5);
  164. gbc_label_3.anchor = GridBagConstraints.EAST;
  165. gbc_label_3.gridx = 9;
  166. gbc_label_3.gridy = 0;
  167. add(label_3, gbc_label_3);
  168. grappleSize = new JTextField();
  169. grappleSize.setToolTipText("Size Modifier");
  170. grappleSize.setPreferredSize(new Dimension(30, 20));
  171. grappleSize.setMinimumSize(new Dimension(30, 20));
  172. grappleSize.setMaximumSize(new Dimension(30, 20));
  173. grappleSize.setHorizontalAlignment(SwingConstants.CENTER);
  174. grappleSize.setEditable(false);
  175. grappleSize.setColumns(3);
  176. grappleSize.setBorder(new LineBorder(Color.BLACK));
  177. GridBagConstraints gbc_grappleSize = new GridBagConstraints();
  178. gbc_grappleSize.insets = new Insets(0, 0, 0, 5);
  179. gbc_grappleSize.fill = GridBagConstraints.HORIZONTAL;
  180. gbc_grappleSize.gridx = 10;
  181. gbc_grappleSize.gridy = 0;
  182. add(grappleSize, gbc_grappleSize);
  183. JLabel label_2 = new JLabel("+");
  184. GridBagConstraints gbc_label_2 = new GridBagConstraints();
  185. gbc_label_2.insets = new Insets(0, 0, 0, 5);
  186. gbc_label_2.anchor = GridBagConstraints.EAST;
  187. gbc_label_2.gridx = 11;
  188. gbc_label_2.gridy = 0;
  189. add(label_2, gbc_label_2);
  190. grappleMisc = new JTextField();
  191. grappleMisc.setToolTipText("Miscellaneous Modifier");
  192. grappleMisc.setPreferredSize(new Dimension(30, 20));
  193. grappleMisc.setMinimumSize(new Dimension(30, 20));
  194. grappleMisc.setMaximumSize(new Dimension(30, 20));
  195. grappleMisc.setHorizontalAlignment(SwingConstants.CENTER);
  196. grappleMisc.setEditable(false);
  197. grappleMisc.setColumns(3);
  198. grappleMisc.setBorder(new LineBorder(Color.BLACK));
  199. GridBagConstraints gbc_grappleMisc = new GridBagConstraints();
  200. gbc_grappleMisc.fill = GridBagConstraints.HORIZONTAL;
  201. gbc_grappleMisc.gridx = 12;
  202. gbc_grappleMisc.gridy = 0;
  203. add(grappleMisc, gbc_grappleMisc);
  204. gTtlObserver = new IndirectObservableListener<>(grappleTtl,
  205. (c, v) -> {
  206. final int bab = v.getBaseAttack();
  207. final int str = this.model.getAbilities().getStr().modifier();
  208. final int size = v.getSize().value().modifier;
  209. final int misc = 0;
  210. c.setText(StringHelper.toString(bab + str + size + misc));
  211. });
  212. gStrObserver = new ObservableListener<>(grappleStrength,
  213. new AbilModStringify());
  214. }
  215. public void setModel(DDCharacter model) {
  216. this.model = model;
  217. final int bab = this.model.getBaseAttack();
  218. final int size = this.model.getSize().value().modifier;
  219. final int misc = 0;
  220. this.baseAttack.setText(StringHelper.toString(bab));
  221. final Ability.Scores str = model.getAbilities().getStr();
  222. gTtlObserver.setObserved(model, str);
  223. gStrObserver.setObserved(str);
  224. this.grappleSize.setText(StringHelper.toString(size));
  225. this.grappleMisc.setText(StringHelper.toString(misc));
  226. }
  227. }