Procházet zdrojové kódy

Adding Spell Resistance, making Target and Effect separate instead of sharing a zone.

Sam Jaffe před 8 roky
rodič
revize
53f20c08c2

+ 85 - 57
src/org/leumasjaffe/charsheet/view/magic/SpellInfoPanel.java

@@ -28,8 +28,6 @@ public class SpellInfoPanel extends JPanel {
 	 * 
 	 */
 	private static final long serialVersionUID = 1L;
-	private JTextField tgtOrEffect;
-	private JPanel panel;
 
 	public SpellInfoPanel(DDCharacterClass dclass, final DDSpell spell) {
 		GridBagLayout gridBagLayout = new GridBagLayout();
@@ -39,19 +37,19 @@ public class SpellInfoPanel extends JPanel {
 		gridBagLayout.rowWeights = new double[]{1.0, 1.0, Double.MIN_VALUE};
 		setLayout(gridBagLayout);
 		
-		panel = new JPanel();
-		GridBagConstraints gbc_panel_2 = new GridBagConstraints();
-		gbc_panel_2.insets = new Insets(0, 0, 5, 0);
-		gbc_panel_2.fill = GridBagConstraints.BOTH;
-		gbc_panel_2.gridx = 0;
-		gbc_panel_2.gridy = 0;
-		add(panel, gbc_panel_2);
-		GridBagLayout gbl_panel_2 = new GridBagLayout();
-		gbl_panel_2.columnWidths = new int[]{0, 0, 0, 0, 0};
-		gbl_panel_2.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0};
-		gbl_panel_2.columnWeights = new double[]{0.0, 1.0, 0.0, 1.0, Double.MIN_VALUE};
-		gbl_panel_2.rowWeights = new double[]{0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE};
-		panel.setLayout(gbl_panel_2);
+		JPanel panel = new JPanel();
+		GridBagConstraints gbc_panel = new GridBagConstraints();
+		gbc_panel.insets = new Insets(0, 0, 5, 0);
+		gbc_panel.fill = GridBagConstraints.BOTH;
+		gbc_panel.gridx = 0;
+		gbc_panel.gridy = 0;
+		add(panel, gbc_panel);
+		GridBagLayout gbl_panel = new GridBagLayout();
+		gbl_panel.columnWidths = new int[]{0, 0, 0, 0, 0};
+		gbl_panel.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0};
+		gbl_panel.columnWeights = new double[]{0.0, 1.0, 0.0, 1.0, Double.MIN_VALUE};
+		gbl_panel.rowWeights = new double[]{0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE};
+		panel.setLayout(gbl_panel);
 		
 		JLabel lblName = new JLabel("Name:");
 		lblName.setFont(new Font("Tahoma", Font.BOLD, 14));
@@ -201,26 +199,62 @@ public class SpellInfoPanel extends JPanel {
 		gbc_range.gridx = 3;
 		gbc_range.gridy = 3;
 		panel.add(range, gbc_range);
+				
+		JLabel lblTarget = new JLabel("Target:");
+		lblTarget.setFont(new Font("Tahoma", Font.BOLD, 14));
+		GridBagConstraints gbc_lblTarget = new GridBagConstraints();
+		gbc_lblTarget.anchor = GridBagConstraints.EAST;
+		gbc_lblTarget.insets = new Insets(0, 0, 5, 5);
+		gbc_lblTarget.gridx = 0;
+		gbc_lblTarget.gridy = 4;
+		panel.add(lblTarget, gbc_lblTarget);
+		
+		JTextField target = new JTextField(asString(spell.getTarget()));
+		target.setEditable(false);
+		target.setColumns(10);
+		GridBagConstraints gbc_target = new GridBagConstraints();
+		gbc_target.insets = new Insets(0, 0, 5, 5);
+		gbc_target.fill = GridBagConstraints.HORIZONTAL;
+		gbc_target.gridx = 1;
+		gbc_target.gridy = 4;
+		panel.add(target, gbc_target);
 		
-		initTargetOrEffect(spell);
+		JLabel lblEffect = new JLabel("Effect:");
+		lblEffect.setFont(new Font("Tahoma", Font.BOLD, 14));
+		GridBagConstraints gbc_lblEffect = new GridBagConstraints();
+		gbc_lblEffect.anchor = GridBagConstraints.EAST;
+		gbc_lblEffect.insets = new Insets(0, 0, 5, 5);
+		gbc_lblEffect.gridx = 2;
+		gbc_lblEffect.gridy = 4;
+		panel.add(lblEffect, gbc_lblEffect);
+		
+		JTextField effect = new JTextField(asString(spell.getEffect()));
+		effect.setEditable(false);
+		effect.setColumns(10);
+		GridBagConstraints gbc_effect = new GridBagConstraints();
+		gbc_effect.insets = new Insets(0, 0, 5, 0);
+		gbc_effect.fill = GridBagConstraints.HORIZONTAL;
+		gbc_effect.gridx = 3;
+		gbc_effect.gridy = 4;
+		panel.add(effect, gbc_effect);
 		
 		JLabel lblArea = new JLabel("Area:");
 		lblArea.setFont(new Font("Tahoma", Font.BOLD, 14));
 		GridBagConstraints gbc_lblArea = new GridBagConstraints();
 		gbc_lblArea.anchor = GridBagConstraints.EAST;
 		gbc_lblArea.insets = new Insets(0, 0, 5, 5);
-		gbc_lblArea.gridx = 2;
-		gbc_lblArea.gridy = 4;
+		gbc_lblArea.gridx = 0;
+		gbc_lblArea.gridy = 5;
 		panel.add(lblArea, gbc_lblArea);
 		
-		JTextField area = new JTextField(spell.getArea() != null ? spell.getArea().toString() : "");
+		JTextField area = new JTextField(asString(spell.getArea()));
 		area.setEditable(false);
 		area.setColumns(10);
 		GridBagConstraints gbc_area = new GridBagConstraints();
-		gbc_area.insets = new Insets(0, 0, 5, 0);
+		gbc_area.insets = new Insets(0, 0, 5, 5);
 		gbc_area.fill = GridBagConstraints.HORIZONTAL;
-		gbc_area.gridx = 3;
-		gbc_area.gridy = 4;
+		gbc_area.gridx = 1;
+		gbc_area.gridy = 5;
 		panel.add(area, gbc_area);
 		
 		JLabel lblDuration = new JLabel("Duration:");
@@ -228,7 +262,7 @@ public class SpellInfoPanel extends JPanel {
 		GridBagConstraints gbc_lblDuration = new GridBagConstraints();
 		gbc_lblDuration.anchor = GridBagConstraints.EAST;
 		gbc_lblDuration.insets = new Insets(0, 0, 5, 5);
-		gbc_lblDuration.gridx = 0;
+		gbc_lblDuration.gridx = 2;
 		gbc_lblDuration.gridy = 5;
 		panel.add(lblDuration, gbc_lblDuration);
 		
@@ -236,9 +270,9 @@ public class SpellInfoPanel extends JPanel {
 		duration.setEditable(false);
 		duration.setColumns(10);
 		GridBagConstraints gbc_duration = new GridBagConstraints();
-		gbc_duration.insets = new Insets(0, 0, 5, 5);
+		gbc_duration.insets = new Insets(0, 0, 5, 0);
 		gbc_duration.fill = GridBagConstraints.HORIZONTAL;
-		gbc_duration.gridx = 1;
+		gbc_duration.gridx = 3;
 		gbc_duration.gridy = 5;
 		panel.add(duration, gbc_duration);
 		
@@ -247,20 +281,39 @@ public class SpellInfoPanel extends JPanel {
 		GridBagConstraints gbc_lblSavingThrow = new GridBagConstraints();
 		gbc_lblSavingThrow.anchor = GridBagConstraints.EAST;
 		gbc_lblSavingThrow.insets = new Insets(0, 0, 5, 5);
-		gbc_lblSavingThrow.gridx = 2;
-		gbc_lblSavingThrow.gridy = 5;
+		gbc_lblSavingThrow.gridx = 0;
+		gbc_lblSavingThrow.gridy = 6;
 		panel.add(lblSavingThrow, gbc_lblSavingThrow);
 		
 		JTextField saving = new JTextField(spell.getSavingThrow());
 		saving.setEditable(false);
 		saving.setColumns(10);
 		GridBagConstraints gbc_saving = new GridBagConstraints();
-		gbc_saving.insets = new Insets(0, 0, 5, 0);
+		gbc_saving.insets = new Insets(0, 0, 5, 5);
 		gbc_saving.fill = GridBagConstraints.HORIZONTAL;
-		gbc_saving.gridx = 3;
-		gbc_saving.gridy = 5;
+		gbc_saving.gridx = 1;
+		gbc_saving.gridy = 6;
 		panel.add(saving, gbc_saving);
 		
+		JLabel lblSpellResistance = new JLabel("Spell Resistance:");
+		lblSpellResistance.setFont(new Font("Tahoma", Font.BOLD, 12));
+		GridBagConstraints gbc_lblSpellResistance = new GridBagConstraints();
+		gbc_lblSpellResistance.anchor = GridBagConstraints.EAST;
+		gbc_lblSpellResistance.insets = new Insets(0, 0, 5, 5);
+		gbc_lblSpellResistance.gridx = 2;
+		gbc_lblSpellResistance.gridy = 6;
+		panel.add(lblSpellResistance, gbc_lblSpellResistance);
+		
+		JTextField resist = new JTextField(spell.isAllowsSpellResistance() ? "Yes" : "No");
+		resist.setEditable(false);
+		resist.setColumns(10);
+		GridBagConstraints gbc_resist = new GridBagConstraints();
+		gbc_resist.insets = new Insets(0, 0, 5, 0);
+		gbc_resist.fill = GridBagConstraints.HORIZONTAL;
+		gbc_resist.gridx = 3;
+		gbc_resist.gridy = 6;
+		panel.add(resist, gbc_resist);
+		
 		JScrollPane scrollPane = new JScrollPane();
 		GridBagConstraints gbc_scrollPane = new GridBagConstraints();
 		gbc_scrollPane.fill = GridBagConstraints.BOTH;
@@ -277,33 +330,8 @@ public class SpellInfoPanel extends JPanel {
 		description.setLineWrap(true);
 	}
 
-	private void initTargetOrEffect(final DDSpell spell) {
-		if (spell.getTarget() == null) {
-			initTargetOrEffect("Target:", spell.getTarget());
-		} else {
-			initTargetOrEffect("Effect:", spell.getEffect());
-		}
-	}
-	
-	private void initTargetOrEffect(final String header, final String value) {
-		JLabel lblTarget = new JLabel(header);
-		lblTarget.setFont(new Font("Tahoma", Font.BOLD, 14));
-		GridBagConstraints gbc_lblTarget = new GridBagConstraints();
-		gbc_lblTarget.anchor = GridBagConstraints.EAST;
-		gbc_lblTarget.insets = new Insets(0, 0, 5, 5);
-		gbc_lblTarget.gridx = 0;
-		gbc_lblTarget.gridy = 4;
-		panel.add(lblTarget, gbc_lblTarget);
-		
-		tgtOrEffect = new JTextField(value);
-		tgtOrEffect.setEditable(false);
-		tgtOrEffect.setColumns(10);
-		GridBagConstraints gbc_tgtOrEffect = new GridBagConstraints();
-		gbc_tgtOrEffect.insets = new Insets(0, 0, 5, 5);
-		gbc_tgtOrEffect.fill = GridBagConstraints.HORIZONTAL;
-		gbc_tgtOrEffect.gridx = 1;
-		gbc_tgtOrEffect.gridy = 4;
-		panel.add(tgtOrEffect, gbc_tgtOrEffect);
+	private String asString(Object obj) {
+		return obj == null ? "" : obj.toString();
 	}
 
 	private static String asString(Set<String> keys) {