SpellInfoPanel.java 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. package org.leumasjaffe.charsheet.view.magic;
  2. import javax.swing.JPanel;
  3. import java.awt.GridBagLayout;
  4. import java.awt.GridBagConstraints;
  5. import java.awt.Insets;
  6. import java.util.Set;
  7. import javax.swing.JTextArea;
  8. import org.leumasjaffe.charsheet.model.magic.DDSpell;
  9. import org.leumasjaffe.charsheet.model.magic.DDSpell.Component;
  10. import javax.swing.JScrollPane;
  11. import javax.swing.JLabel;
  12. import javax.swing.JTextField;
  13. import java.awt.Font;
  14. import java.awt.FlowLayout;
  15. import javax.swing.JCheckBox;
  16. public class SpellInfoPanel extends JPanel {
  17. /**
  18. *
  19. */
  20. private static final long serialVersionUID = 1L;
  21. private JTextField name;
  22. private JTextField school;
  23. private JTextField keywords;
  24. private JTextField action;
  25. private JTextField range;
  26. public SpellInfoPanel(final DDSpell spell) {
  27. GridBagLayout gridBagLayout = new GridBagLayout();
  28. gridBagLayout.columnWidths = new int[]{0, 0};
  29. gridBagLayout.rowHeights = new int[]{0, 0, 0};
  30. gridBagLayout.columnWeights = new double[]{1.0, Double.MIN_VALUE};
  31. gridBagLayout.rowWeights = new double[]{1.0, 1.0, Double.MIN_VALUE};
  32. setLayout(gridBagLayout);
  33. JPanel panel = new JPanel();
  34. GridBagConstraints gbc_panel = new GridBagConstraints();
  35. gbc_panel.insets = new Insets(0, 0, 5, 0);
  36. gbc_panel.fill = GridBagConstraints.BOTH;
  37. gbc_panel.gridx = 0;
  38. gbc_panel.gridy = 0;
  39. add(panel, gbc_panel);
  40. GridBagLayout gbl_panel = new GridBagLayout();
  41. gbl_panel.columnWidths = new int[]{0, 0, 0, 0, 0};
  42. gbl_panel.rowHeights = new int[]{0, 0, 0, 0, 0, 0};
  43. gbl_panel.columnWeights = new double[]{0.0, 1.0, 0.0, 1.0, Double.MIN_VALUE};
  44. gbl_panel.rowWeights = new double[]{0.0, 0.0, 1.0, 0.0, 1.0, Double.MIN_VALUE};
  45. panel.setLayout(gbl_panel);
  46. JLabel lblName = new JLabel("Name:");
  47. lblName.setFont(new Font("Tahoma", Font.BOLD, 14));
  48. GridBagConstraints gbc_lblName = new GridBagConstraints();
  49. gbc_lblName.insets = new Insets(0, 0, 5, 5);
  50. gbc_lblName.anchor = GridBagConstraints.EAST;
  51. gbc_lblName.gridx = 0;
  52. gbc_lblName.gridy = 0;
  53. panel.add(lblName, gbc_lblName);
  54. name = new JTextField(spell.getName());
  55. name.setEditable(false);
  56. GridBagConstraints gbc_name = new GridBagConstraints();
  57. gbc_name.insets = new Insets(0, 0, 5, 5);
  58. gbc_name.fill = GridBagConstraints.HORIZONTAL;
  59. gbc_name.gridx = 1;
  60. gbc_name.gridy = 0;
  61. panel.add(name, gbc_name);
  62. name.setColumns(10);
  63. JLabel lblSpellSchool = new JLabel("Spell School:");
  64. lblSpellSchool.setFont(new Font("Tahoma", Font.BOLD, 14));
  65. GridBagConstraints gbc_lblSpellSchool = new GridBagConstraints();
  66. gbc_lblSpellSchool.anchor = GridBagConstraints.EAST;
  67. gbc_lblSpellSchool.insets = new Insets(0, 0, 5, 5);
  68. gbc_lblSpellSchool.gridx = 2;
  69. gbc_lblSpellSchool.gridy = 0;
  70. panel.add(lblSpellSchool, gbc_lblSpellSchool);
  71. school = new JTextField(spell.getSpellSchool());
  72. school.setEditable(false);
  73. school.setColumns(10);
  74. GridBagConstraints gbc_school = new GridBagConstraints();
  75. gbc_school.insets = new Insets(0, 0, 5, 0);
  76. gbc_school.fill = GridBagConstraints.HORIZONTAL;
  77. gbc_school.gridx = 3;
  78. gbc_school.gridy = 0;
  79. panel.add(school, gbc_school);
  80. JLabel lblKeywords = new JLabel("Keywords:");
  81. lblKeywords.setFont(new Font("Tahoma", Font.BOLD, 14));
  82. GridBagConstraints gbc_lblKeywords = new GridBagConstraints();
  83. gbc_lblKeywords.anchor = GridBagConstraints.EAST;
  84. gbc_lblKeywords.insets = new Insets(0, 0, 5, 5);
  85. gbc_lblKeywords.gridx = 0;
  86. gbc_lblKeywords.gridy = 1;
  87. panel.add(lblKeywords, gbc_lblKeywords);
  88. keywords = new JTextField(spell.getKeywords().isEmpty() ? "<none>" : asString(spell.getKeywords()));
  89. keywords.setEditable(false);
  90. keywords.setColumns(10);
  91. GridBagConstraints gbc_keywords = new GridBagConstraints();
  92. gbc_keywords.gridwidth = 3;
  93. gbc_keywords.insets = new Insets(0, 0, 5, 0);
  94. gbc_keywords.fill = GridBagConstraints.HORIZONTAL;
  95. gbc_keywords.gridx = 1;
  96. gbc_keywords.gridy = 1;
  97. panel.add(keywords, gbc_keywords);
  98. JLabel lblComponents = new JLabel("Components:");
  99. lblComponents.setFont(new Font("Tahoma", Font.BOLD, 14));
  100. GridBagConstraints gbc_lblComponents = new GridBagConstraints();
  101. gbc_lblComponents.anchor = GridBagConstraints.EAST;
  102. gbc_lblComponents.insets = new Insets(0, 0, 5, 5);
  103. gbc_lblComponents.gridx = 0;
  104. gbc_lblComponents.gridy = 2;
  105. panel.add(lblComponents, gbc_lblComponents);
  106. JPanel panel_1 = new JPanel();
  107. GridBagConstraints gbc_panel_1 = new GridBagConstraints();
  108. gbc_panel_1.insets = new Insets(0, 0, 5, 0);
  109. gbc_panel_1.gridwidth = 3;
  110. gbc_panel_1.fill = GridBagConstraints.BOTH;
  111. gbc_panel_1.gridx = 1;
  112. gbc_panel_1.gridy = 2;
  113. panel.add(panel_1, gbc_panel_1);
  114. panel_1.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
  115. JCheckBox chckbxVerbal = new JCheckBox("Verbal");
  116. chckbxVerbal.setEnabled(false);
  117. chckbxVerbal.setSelected(spell.getComponents().contains(Component.V));
  118. panel_1.add(chckbxVerbal);
  119. JCheckBox chckbxSomatic = new JCheckBox("Somatic");
  120. chckbxSomatic.setEnabled(false);
  121. chckbxSomatic.setSelected(spell.getComponents().contains(Component.S));
  122. panel_1.add(chckbxSomatic);
  123. JCheckBox chckbxMaterial = new JCheckBox("Material");
  124. chckbxMaterial.setEnabled(false);
  125. chckbxMaterial.setSelected(spell.getComponents().contains(Component.M));
  126. panel_1.add(chckbxMaterial);
  127. JCheckBox chckbxFocus = new JCheckBox("Focus");
  128. chckbxFocus.setEnabled(false);
  129. chckbxFocus.setSelected(spell.getComponents().contains(Component.F));
  130. panel_1.add(chckbxFocus);
  131. JCheckBox chckbxDivineFocus = new JCheckBox("Divine Focus");
  132. chckbxDivineFocus.setEnabled(false);
  133. chckbxDivineFocus.setSelected(spell.getComponents().contains(Component.DF));
  134. panel_1.add(chckbxDivineFocus);
  135. JCheckBox chckbxExperience = new JCheckBox("Experience");
  136. chckbxExperience.setEnabled(false);
  137. chckbxExperience.setSelected(spell.getComponents().contains(Component.XP));
  138. panel_1.add(chckbxExperience);
  139. JLabel lblCastingTime = new JLabel("Casting Time:");
  140. lblCastingTime.setFont(new Font("Tahoma", Font.BOLD, 14));
  141. GridBagConstraints gbc_lblCastingTime = new GridBagConstraints();
  142. gbc_lblCastingTime.anchor = GridBagConstraints.EAST;
  143. gbc_lblCastingTime.insets = new Insets(0, 0, 5, 5);
  144. gbc_lblCastingTime.gridx = 0;
  145. gbc_lblCastingTime.gridy = 3;
  146. panel.add(lblCastingTime, gbc_lblCastingTime);
  147. action = new JTextField(spell.getCastingTime().name());
  148. action.setEditable(false);
  149. action.setColumns(10);
  150. GridBagConstraints gbc_action = new GridBagConstraints();
  151. gbc_action.insets = new Insets(0, 0, 5, 5);
  152. gbc_action.fill = GridBagConstraints.HORIZONTAL;
  153. gbc_action.gridx = 1;
  154. gbc_action.gridy = 3;
  155. panel.add(action, gbc_action);
  156. JLabel lblRange = new JLabel("Range:");
  157. lblRange.setFont(new Font("Tahoma", Font.BOLD, 14));
  158. GridBagConstraints gbc_lblRange = new GridBagConstraints();
  159. gbc_lblRange.anchor = GridBagConstraints.EAST;
  160. gbc_lblRange.insets = new Insets(0, 0, 5, 5);
  161. gbc_lblRange.gridx = 2;
  162. gbc_lblRange.gridy = 3;
  163. panel.add(lblRange, gbc_lblRange);
  164. range = new JTextField(spell.getRange().toString());
  165. range.setEditable(false);
  166. range.setColumns(10);
  167. GridBagConstraints gbc_range = new GridBagConstraints();
  168. gbc_range.insets = new Insets(0, 0, 5, 0);
  169. gbc_range.fill = GridBagConstraints.HORIZONTAL;
  170. gbc_range.gridx = 3;
  171. gbc_range.gridy = 3;
  172. panel.add(range, gbc_range);
  173. JScrollPane scrollPane = new JScrollPane();
  174. GridBagConstraints gbc_scrollPane = new GridBagConstraints();
  175. gbc_scrollPane.fill = GridBagConstraints.BOTH;
  176. gbc_scrollPane.gridx = 0;
  177. gbc_scrollPane.gridy = 1;
  178. add(scrollPane, gbc_scrollPane);
  179. JTextArea description = new JTextArea(spell.getDescription());
  180. description.setEditable(false);
  181. description.setWrapStyleWord(true);
  182. description.setRows(10);
  183. scrollPane.setViewportView(description);
  184. description.setColumns(30);
  185. description.setLineWrap(true);
  186. }
  187. private static String asString(Set<String> keys) {
  188. String str = keys.toString();
  189. return str.substring(1, str.length()-1);
  190. }
  191. }