AttackLine.java 10 KB

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