AttackLine.java 9.9 KB

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