package org.leumasjaffe.charsheet.view.inventory; import javax.swing.JPanel; import java.awt.GridBagLayout; import java.awt.GridBagConstraints; import java.awt.Insets; import javax.swing.JLabel; import javax.swing.JTextField; import java.awt.Dimension; import java.awt.Font; import java.awt.Color; import javax.swing.SwingConstants; import org.leumasjaffe.charsheet.model.equip.DDItem; import org.leumasjaffe.charsheet.model.equip.DDWeapon; import org.leumasjaffe.charsheet.view.StringHelper; import java.awt.Component; import javax.swing.Box; public class WeaponPanel extends JPanel { /** * */ private static final long serialVersionUID = 1L; private JTextField nameField; private JTextField attackBonusField; private JTextField damageField; private JTextField criticalField; private JTextField rangeField; private JTextField propField; private JTextField typeField; public WeaponPanel(final DDItem item) { final DDWeapon weapon = item.getWeapon(); setPreferredSize(new Dimension(280, 70)); GridBagLayout gridBagLayout = new GridBagLayout(); gridBagLayout.columnWidths = new int[]{0, 0}; gridBagLayout.rowHeights = new int[]{0, 0, 0}; gridBagLayout.columnWeights = new double[]{1.0, Double.MIN_VALUE}; gridBagLayout.rowWeights = new double[]{0.0, 0.0, Double.MIN_VALUE}; setLayout(gridBagLayout); JPanel panel = new JPanel(); GridBagConstraints gbc_panel = new GridBagConstraints(); gbc_panel.insets = new Insets(0, 0, 0, 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[]{100, 0, 0, 0, 0}; gbl_panel.rowHeights = new int[]{0, 0, 0, 0}; gbl_panel.columnWeights = new double[]{1.0, 1.0, 1.0, 1.0, Double.MIN_VALUE}; gbl_panel.rowWeights = new double[]{0.0, 0.0, 0.0, Double.MIN_VALUE}; panel.setLayout(gbl_panel); JLabel lblWeapon = new JLabel("WEAPON"); lblWeapon.setHorizontalAlignment(SwingConstants.CENTER); lblWeapon.setForeground(Color.WHITE); lblWeapon.setOpaque(true); lblWeapon.setBackground(Color.BLACK); lblWeapon.setFont(new Font("Tahoma", Font.BOLD, 10)); GridBagConstraints gbc_lblWeapon = new GridBagConstraints(); gbc_lblWeapon.fill = GridBagConstraints.BOTH; gbc_lblWeapon.insets = new Insets(0, 0, 0, 1); gbc_lblWeapon.gridheight = 2; gbc_lblWeapon.gridx = 0; gbc_lblWeapon.gridy = 0; panel.add(lblWeapon, gbc_lblWeapon); Component verticalStrut = Box.createVerticalStrut(20); verticalStrut.setMinimumSize(new Dimension(0, 10)); verticalStrut.setMaximumSize(new Dimension(32767, 10)); verticalStrut.setPreferredSize(new Dimension(0, 10)); GridBagConstraints gbc_verticalStrut = new GridBagConstraints(); gbc_verticalStrut.insets = new Insets(0, 0, 0, 0); gbc_verticalStrut.gridx = 2; gbc_verticalStrut.gridy = 0; panel.add(verticalStrut, gbc_verticalStrut); JLabel lblAtkBonus = new JLabel("ATTACK BONUS"); lblAtkBonus.setHorizontalAlignment(SwingConstants.CENTER); lblAtkBonus.setForeground(Color.WHITE); lblAtkBonus.setOpaque(true); lblAtkBonus.setBackground(Color.BLACK); lblAtkBonus.setFont(new Font("Tahoma", Font.BOLD, 8)); GridBagConstraints gbc_lblAtkBonus = new GridBagConstraints(); gbc_lblAtkBonus.fill = GridBagConstraints.HORIZONTAL; gbc_lblAtkBonus.insets = new Insets(0, 0, 0, 1); gbc_lblAtkBonus.gridx = 1; gbc_lblAtkBonus.gridy = 1; panel.add(lblAtkBonus, gbc_lblAtkBonus); JLabel lblDamage = new JLabel("DAMAGE"); lblDamage.setHorizontalAlignment(SwingConstants.CENTER); lblDamage.setForeground(Color.WHITE); lblDamage.setOpaque(true); lblDamage.setBackground(Color.BLACK); lblDamage.setFont(new Font("Tahoma", Font.BOLD, 8)); GridBagConstraints gbc_lblDamage = new GridBagConstraints(); gbc_lblDamage.fill = GridBagConstraints.HORIZONTAL; gbc_lblDamage.insets = new Insets(0, 0, 0, 1); gbc_lblDamage.gridx = 2; gbc_lblDamage.gridy = 1; panel.add(lblDamage, gbc_lblDamage); JLabel lblCritical = new JLabel("CRITICAL"); GridBagConstraints gbc_lblCritical = new GridBagConstraints(); gbc_lblCritical.fill = GridBagConstraints.HORIZONTAL; gbc_lblCritical.insets = new Insets(0, 0, 0, 1); gbc_lblCritical.gridx = 3; gbc_lblCritical.gridy = 1; panel.add(lblCritical, gbc_lblCritical); lblCritical.setHorizontalAlignment(SwingConstants.CENTER); lblCritical.setForeground(Color.WHITE); lblCritical.setOpaque(true); lblCritical.setBackground(Color.BLACK); lblCritical.setFont(new Font("Tahoma", Font.BOLD, 8)); nameField = new JTextField(item.getName()); GridBagConstraints gbc_nameField = new GridBagConstraints(); gbc_nameField.insets = new Insets(0, 0, 0, 0); gbc_nameField.fill = GridBagConstraints.HORIZONTAL; gbc_nameField.gridx = 0; gbc_nameField.gridy = 2; panel.add(nameField, gbc_nameField); nameField.setColumns(10); attackBonusField = new JTextField(StringHelper.toSignedString(weapon.getAttackBonus())); attackBonusField.setHorizontalAlignment(SwingConstants.CENTER); GridBagConstraints gbc_attackBonusField = new GridBagConstraints(); gbc_attackBonusField.insets = new Insets(0, 0, 0, 0); gbc_attackBonusField.fill = GridBagConstraints.HORIZONTAL; gbc_attackBonusField.gridx = 1; gbc_attackBonusField.gridy = 2; panel.add(attackBonusField, gbc_attackBonusField); attackBonusField.setColumns(10); damageField = new JTextField(weapon.getDamage() + StringHelper.toSignedString(weapon.getDamageBonus(), 0)); damageField.setHorizontalAlignment(SwingConstants.CENTER); GridBagConstraints gbc_damageField = new GridBagConstraints(); gbc_damageField.insets = new Insets(0, 0, 0, 0); gbc_damageField.fill = GridBagConstraints.HORIZONTAL; gbc_damageField.gridx = 2; gbc_damageField.gridy = 2; panel.add(damageField, gbc_damageField); damageField.setColumns(10); final StringBuilder critStr = new StringBuilder(); if (weapon.hasCriticalThreat()) { critStr.append(weapon.getCriticalThreat()).append("-20/"); } critStr.append('x').append(weapon.getCriticalDamage()); criticalField = new JTextField(critStr.toString()); criticalField.setHorizontalAlignment(SwingConstants.CENTER); GridBagConstraints gbc_criticalField = new GridBagConstraints(); gbc_criticalField.fill = GridBagConstraints.HORIZONTAL; gbc_criticalField.gridx = 3; gbc_criticalField.gridy = 2; panel.add(criticalField, gbc_criticalField); criticalField.setColumns(10); JPanel panel_1 = new JPanel(); GridBagConstraints gbc_panel_1 = new GridBagConstraints(); gbc_panel_1.fill = GridBagConstraints.BOTH; gbc_panel_1.gridx = 0; gbc_panel_1.gridy = 1; add(panel_1, gbc_panel_1); GridBagLayout gbl_panel_1 = new GridBagLayout(); gbl_panel_1.columnWidths = new int[]{0, 0, 0, 0}; gbl_panel_1.rowHeights = new int[]{0, 0, 0}; gbl_panel_1.columnWeights = new double[]{1.0, 1.0, 1.0, Double.MIN_VALUE}; gbl_panel_1.rowWeights = new double[]{0.0, 0.0, Double.MIN_VALUE}; panel_1.setLayout(gbl_panel_1); JLabel lblRange = new JLabel("RANGE"); lblRange.setHorizontalAlignment(SwingConstants.CENTER); lblRange.setForeground(Color.WHITE); lblRange.setOpaque(true); lblRange.setBackground(Color.BLACK); lblRange.setFont(new Font("Tahoma", Font.BOLD, 8)); GridBagConstraints gbc_lblRange = new GridBagConstraints(); gbc_lblRange.fill = GridBagConstraints.BOTH; gbc_lblRange.insets = new Insets(0, 0, 0, 1); gbc_lblRange.gridx = 0; gbc_lblRange.gridy = 0; panel_1.add(lblRange, gbc_lblRange); JLabel lblType = new JLabel("TYPE"); lblType.setOpaque(true); lblType.setHorizontalAlignment(SwingConstants.CENTER); lblType.setForeground(Color.WHITE); lblType.setFont(new Font("Tahoma", Font.BOLD, 8)); lblType.setBackground(Color.BLACK); GridBagConstraints gbc_lblType = new GridBagConstraints(); gbc_lblType.fill = GridBagConstraints.HORIZONTAL; gbc_lblType.insets = new Insets(0, 0, 0, 1); gbc_lblType.gridx = 1; gbc_lblType.gridy = 0; panel_1.add(lblType, gbc_lblType); JLabel lblSpecialProperties = new JLabel("SPECIAL PROPERTIES"); lblSpecialProperties.setHorizontalAlignment(SwingConstants.CENTER); lblSpecialProperties.setForeground(Color.WHITE); lblSpecialProperties.setOpaque(true); lblSpecialProperties.setBackground(Color.BLACK); lblSpecialProperties.setFont(new Font("Tahoma", Font.BOLD, 8)); GridBagConstraints gbc_lblSpecialProperties = new GridBagConstraints(); gbc_lblSpecialProperties.fill = GridBagConstraints.BOTH; gbc_lblSpecialProperties.insets = new Insets(0, 0, 0, 1); gbc_lblSpecialProperties.gridx = 2; gbc_lblSpecialProperties.gridy = 0; panel_1.add(lblSpecialProperties, gbc_lblSpecialProperties); rangeField = new JTextField(StringHelper.toString(weapon.getRange().toString())); rangeField.setHorizontalAlignment(SwingConstants.CENTER); GridBagConstraints gbc_rangeField = new GridBagConstraints(); gbc_rangeField.insets = new Insets(0, 0, 0, 0); gbc_rangeField.fill = GridBagConstraints.HORIZONTAL; gbc_rangeField.gridx = 0; gbc_rangeField.gridy = 1; panel_1.add(rangeField, gbc_rangeField); rangeField.setColumns(10); typeField = new JTextField(item.getWeapon().getType().toString()); typeField.setHorizontalAlignment(SwingConstants.CENTER); typeField.setColumns(10); GridBagConstraints gbc_typeField = new GridBagConstraints(); gbc_typeField.insets = new Insets(0, 0, 0, 0); gbc_typeField.fill = GridBagConstraints.HORIZONTAL; gbc_typeField.gridx = 1; gbc_typeField.gridy = 1; panel_1.add(typeField, gbc_typeField); propField = new JTextField(); GridBagConstraints gbc_propField = new GridBagConstraints(); gbc_propField.fill = GridBagConstraints.HORIZONTAL; gbc_propField.gridx = 2; gbc_propField.gridy = 1; panel_1.add(propField, gbc_propField); propField.setColumns(10); // TODO Auto-generated constructor stub } }