public void newDay(Campaign campaign) {
    ArrayList<IAcquisitionWork> newShoppingList = new ArrayList<IAcquisitionWork>();
    boolean noStaff = false;
    for (IAcquisitionWork shoppingItem : shoppingList) {
      shoppingItem.decrementDaysToWait();

      if (shoppingItem.getDaysToWait() <= 0 && !noStaff) {
        boolean canAfford = true;
        if (campaign.getFunds() < getTrueBuyCost(shoppingItem, campaign)) {
          campaign.addReport(
              "<font color='red'><b>You cannot afford to purchase "
                  + shoppingItem.getAcquisitionName()
                  + "</b></font>");
          canAfford = false;
        }
        while (canAfford
            && shoppingItem.getQuantity() > 0
            && campaign.acquireEquipment(shoppingItem)) {
          shoppingItem.decrementQuantity();
          if (shoppingItem.getQuantity() > 0
              && campaign.getFunds() < getTrueBuyCost(shoppingItem, campaign)) {
            canAfford = false;
            campaign.addReport(
                "<font color='red'><b>You cannot afford to purchase "
                    + shoppingItem.getAcquisitionName()
                    + "</b></font>");
          }
        }
      }
      if (shoppingItem.getQuantity() > 0 || shoppingItem.getDaysToWait() > 0) {
        newShoppingList.add(shoppingItem);
      }
    }
    shoppingList = newShoppingList;
  }
  private void refreshRanksCombo() {
    // Clear everything and start over! Wee!
    rankModel.removeAllElements();

    // Determine correct profession to pass into the loop
    int profession = Person.getProfessionFromPrimaryRole((choiceType.getSelectedIndex() + 1));
    while (campaign.getRanks().isEmptyProfession(profession) && profession != Ranks.RPROF_MW) {
      profession = campaign.getRanks().getAlternateProfession(profession);
    }

    for (Rank rank : campaign.getRanks().getAllRanks()) {
      int p = profession;
      // Grab rank from correct profession as needed
      while (rank.getName(p).startsWith("--") && p != Ranks.RPROF_MW) {
        if (rank.getName(p).equals("--")) {
          p = campaign.getRanks().getAlternateProfession(p);
        } else if (rank.getName(p).startsWith("--")) {
          p = campaign.getRanks().getAlternateProfession(rank.getName(p));
        }
      }
      if (rank.getName(p).equals("-")) {
        continue;
      }

      rankModel.addElement(rank.getName(p));
    }
    choiceRanks.setModel(rankModel);
    choiceRanks.setSelectedIndex(0);
  }
 private long getTrueBuyCost(IAcquisitionWork item, Campaign campaign) {
   long cost = Long.MIN_VALUE;
   if ((item instanceof UnitOrder && campaign.getCampaignOptions().payForUnits())
       || (item instanceof Part && campaign.getCampaignOptions().payForParts())) {
     cost = item.getBuyCost();
   }
   return cost;
 }
示例#4
0
  private void addPart(boolean purchase, boolean bulk, boolean bonus) {
    int row = partsTable.getSelectedRow();
    if (row < 0) {
      return;
    }
    Part selectedPart = partsModel.getPartAt(partsTable.convertRowIndexToModel(row));
    int quantity = 1;
    if (bulk) {
      PopupValueChoiceDialog pcd =
          new PopupValueChoiceDialog(
              campaignGUI.getFrame(), true, "How Many " + selectedPart.getName(), quantity, 1, 100);
      pcd.setVisible(true);
      quantity = pcd.getValue();
    }

    if (bonus) {
      String report = selectedPart.getAcquisitionWork().find(0);
      if (report.endsWith("0 days.")) {
        AtBContract contract = null;
        for (Mission m : campaign.getMissions()) {
          if (m.isActive()
              && m instanceof AtBContract
              && ((AtBContract) m).getNumBonusParts() > 0) {
            contract = (AtBContract) m;
            break;
          }
        }
        if (null == contract) {
          MekHQ.logError("AtB: used bonus part but no contract has bonus parts available.");
        } else {
          contract.useBonusPart();
        }
      }
    } else if (purchase) {
      campaign
          .getShoppingList()
          .addShoppingItem(selectedPart.getAcquisitionWork(), quantity, campaign);
    } else {
      while (quantity > 0) {
        campaign.addPart(selectedPart.clone(), 0);
        quantity--;
      }
    }
    campaignGUI.refreshReport();
    campaignGUI.refreshAcquireList();
    campaignGUI.refreshPartsList();
    campaignGUI.refreshFinancialTransactions();
    campaignGUI.refreshOverview();
  }
  protected void spendXP() {
    String skillName = (String) choiceSkill.getSelectedItem();
    if (choiceNoSkill.equals(skillName)) {
      // This shouldn't happen, but guard against it anyway.
      return;
    }
    int rows = personnelTable.getRowCount();
    int improvedPersonnelCount = rows;
    while (rows > 0) {
      for (int i = 0; i < rows; ++i) {
        Person p = personnelModel.getPerson(personnelTable.convertRowIndexToModel(i));
        int cost = 0;
        if (p.hasSkill(skillName)) {
          cost = p.getCostToImprove(skillName);
        } else {
          cost = SkillType.getType(skillName).getCost(0);
        }
        int experience = p.getExperienceLevel(false);

        // Improve the skill and deduce the cost
        p.improveSkill(skillName);
        campaign.personUpdated(p);
        p.setXp(p.getXp() - cost);

        // The next part is bollocks and doesn't belong here, but as long as we hardcode AtB ...
        if (campaign.getCampaignOptions().getUseAtB()) {
          if ((p.getPrimaryRole() > Person.T_NONE)
              && (p.getPrimaryRole() <= Person.T_CONV_PILOT)
              && (p.getExperienceLevel(false) > experience)
              && (experience >= SkillType.EXP_REGULAR)) {
            String spa = campaign.rollSPA(p.getPrimaryRole(), p);
            if (null == spa) {
              if (campaign.getCampaignOptions().useEdge()) {
                p.acquireAbility(
                    PilotOptions.EDGE_ADVANTAGES, "edge", p.getEdge() + 1); // $NON-NLS-1$
                p.addLogEntry(
                    campaign.getDate(),
                    String.format(resourceMap.getString("gainedEdge.text"))); // $NON-NLS-1$
              }
            } else {
              p.addLogEntry(
                  campaign.getDate(),
                  String.format(resourceMap.getString("gained.format"), spa)); // $NON-NLS-1$
            }
          }
        }
      }
      // Refresh the filter and continue if we still have anyone available
      updatePersonnelTable();
      rows = personnelTable.getRowCount();
      dataChanged = true;
    }
    if (improvedPersonnelCount > 0) {
      campaign.addReport(
          String.format(
              resourceMap.getString("improvedSkills.format"),
              skillName,
              improvedPersonnelCount)); //$NON-NLS-1$
    }
  }
 private void hire() {
   int number = (Integer) spnNumber.getModel().getValue();
   while (number > 0) {
     Person p = campaign.newPerson(choiceType.getSelectedIndex() + 1);
     p.setRankNumeric(
         campaign
             .getRanks()
             .getRankNumericFromNameAndProfession(
                 p.getProfession(), (String) choiceRanks.getSelectedItem()));
     if (!campaign.recruitPerson(p)) {
       number = 0;
     } else {
       number--;
     }
   }
   hqView.refreshPersonnelList();
   hqView.refreshPatientList();
   hqView.refreshTechsList();
   hqView.refreshDoctorsList();
   hqView.refreshReport();
   hqView.refreshFinancialTransactions();
   hqView.refreshOverview();
 }
示例#7
0
 /** Creates new form PartsStoreDialog */
 public PartsStoreDialog(
     Frame frame, boolean modal, CampaignGUI gui, Campaign campaign, boolean add) {
   super(frame, modal);
   this.frame = frame;
   this.campaignGUI = gui;
   this.campaign = campaign;
   this.addToCampaign = add;
   formatter = new DecimalFormat();
   partsModel = new PartsTableModel(campaign.getPartsStore().getInventory());
   initComponents();
   filterParts();
   setLocationRelativeTo(frame);
   selectedPart = null;
 }
 public void addShoppingItem(IAcquisitionWork newWork, int quantity, Campaign campaign) {
   // ammo bins need a little extra work here
   if (newWork instanceof AmmoBin) {
     newWork = ((AmmoBin) newWork).getAcquisitionWork();
   }
   for (IAcquisitionWork shoppingItem : shoppingList) {
     if (isSameEquipment(shoppingItem.getNewEquipment(), newWork.getNewEquipment())) {
       campaign.addReport(newWork.getShoppingListReport(quantity));
       while (quantity > 0) {
         shoppingItem.incrementQuantity();
         quantity--;
       }
       return;
     }
   }
   boolean canAfford = true;
   if (campaign.getFunds() < getTrueBuyCost(newWork, campaign)) {
     campaign.addReport(
         "<font color='red'><b>You cannot afford to purchase "
             + newWork.getAcquisitionName()
             + "</b></font>");
     canAfford = false;
   }
   while (canAfford && quantity > 0 && campaign.acquireEquipment(newWork)) {
     quantity--;
     if (quantity > 0 && campaign.getFunds() < getTrueBuyCost(newWork, campaign)) {
       canAfford = false;
       campaign.addReport(
           "<font color='red'><b>You cannot afford to purchase "
               + newWork.getAcquisitionName()
               + "</b></font>");
     }
   }
   if (quantity > 0) {
     campaign.addReport(newWork.getShoppingListReport(quantity));
     while (quantity > 1) {
       newWork.incrementQuantity();
       quantity--;
     }
     shoppingList.add(newWork);
   }
 }
  private JComponent getButtonPanel() {
    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

    choiceType = new JComboBox<PersonTypeItem>();
    choiceType.setMaximumSize(
        new Dimension(Short.MAX_VALUE, (int) choiceType.getPreferredSize().getHeight()));
    DefaultComboBoxModel<PersonTypeItem> personTypeModel = new DefaultComboBoxModel<>();
    personTypeModel.addElement(
        new PersonTypeItem(resourceMap.getString("primaryRole.choice.text"), null)); // $NON-NLS-1$
    for (int i = 1; i < Person.T_NUM; ++i) {
      personTypeModel.addElement(
          new PersonTypeItem(Person.getRoleDesc(i, campaign.getFaction().isClan()), i));
    }
    personTypeModel.addElement(
        new PersonTypeItem(Person.getRoleDesc(0, campaign.getFaction().isClan()), 0));
    // Add "none" for generic AsTechs
    choiceType.setModel(personTypeModel);
    choiceType.setSelectedIndex(0);
    choiceType.addActionListener(
        e -> {
          personnelFilter.setPrimaryRole(((PersonTypeItem) choiceType.getSelectedItem()).id);
          updatePersonnelTable();
        });
    panel.add(choiceType);

    choiceExp = new JComboBox<PersonTypeItem>();
    choiceExp.setMaximumSize(
        new Dimension(Short.MAX_VALUE, (int) choiceType.getPreferredSize().getHeight()));
    DefaultComboBoxModel<PersonTypeItem> personExpModel = new DefaultComboBoxModel<>();
    personExpModel.addElement(
        new PersonTypeItem(resourceMap.getString("experience.choice.text"), null)); // $NON-NLS-1$
    for (int i = 0; i < 5; ++i) {
      personExpModel.addElement(new PersonTypeItem(SkillType.getExperienceLevelName(i), i));
    }
    choiceExp.setModel(personExpModel);
    choiceExp.setSelectedIndex(0);
    choiceExp.addActionListener(
        e -> {
          personnelFilter.setExpLevel(((PersonTypeItem) choiceExp.getSelectedItem()).id);
          updatePersonnelTable();
        });
    panel.add(choiceExp);

    choiceSkill = new JComboBox<String>();
    choiceSkill.setMaximumSize(
        new Dimension(Short.MAX_VALUE, (int) choiceSkill.getPreferredSize().getHeight()));
    DefaultComboBoxModel<String> personSkillModel = new DefaultComboBoxModel<>();
    personSkillModel.addElement(choiceNoSkill);
    for (String skill : SkillType.getSkillList()) {
      personSkillModel.addElement(skill);
    }
    choiceSkill.setModel(personSkillModel);
    choiceSkill.setSelectedIndex(0);
    choiceSkill.addActionListener(
        e -> {
          if (choiceNoSkill.equals(choiceSkill.getSelectedItem())) {
            personnelFilter.setSkill(null);
            ((SpinnerNumberModel) skillLevel.getModel()).setMaximum(10);
            buttonSpendXP.setEnabled(false);
          } else {
            String skillName = (String) choiceSkill.getSelectedItem();
            personnelFilter.setSkill(skillName);
            int maxSkillLevel = SkillType.getType(skillName).getMaxLevel();
            int currentLevel = (Integer) skillLevel.getModel().getValue();
            ((SpinnerNumberModel) skillLevel.getModel()).setMaximum(maxSkillLevel);
            if (currentLevel > maxSkillLevel) {
              skillLevel.getModel().setValue(Integer.valueOf(maxSkillLevel));
            }
            buttonSpendXP.setEnabled(true);
          }
          updatePersonnelTable();
        });
    panel.add(choiceSkill);

    panel.add(Box.createRigidArea(new Dimension(10, 10)));
    panel.add(new JLabel(resourceMap.getString("targetSkillLevel.text"))); // $NON-NLS-1$

    skillLevel = new JSpinner(new SpinnerNumberModel(10, 0, 10, 1));
    skillLevel.setMaximumSize(
        new Dimension(Short.MAX_VALUE, (int) skillLevel.getPreferredSize().getHeight()));
    skillLevel.addChangeListener(
        e -> {
          personnelFilter.setMaxSkillLevel((Integer) skillLevel.getModel().getValue());
          updatePersonnelTable();
        });
    panel.add(skillLevel);

    allowPrisoners = new JCheckBox(resourceMap.getString("allowPrisoners.text")); // $NON-NLS-1$
    allowPrisoners.setHorizontalAlignment(SwingConstants.LEFT);
    allowPrisoners.setMaximumSize(
        new Dimension(Short.MAX_VALUE, (int) allowPrisoners.getPreferredSize().getHeight()));
    allowPrisoners.addChangeListener(
        e -> {
          personnelFilter.setAllowPrisoners(allowPrisoners.isSelected());
          updatePersonnelTable();
        });
    JPanel allowPrisonersPanel = new JPanel(new GridLayout(1, 1));
    allowPrisonersPanel.setAlignmentY(JComponent.LEFT_ALIGNMENT);
    allowPrisonersPanel.add(allowPrisoners);
    allowPrisonersPanel.setMaximumSize(
        new Dimension(Short.MAX_VALUE, (int) allowPrisonersPanel.getPreferredSize().getHeight()));
    panel.add(allowPrisonersPanel);

    panel.add(Box.createVerticalGlue());

    matchedPersonnelLabel = new JLabel(""); // $NON-NLS-1$
    matchedPersonnelLabel.setMaximumSize(
        new Dimension(Short.MAX_VALUE, (int) matchedPersonnelLabel.getPreferredSize().getHeight()));
    panel.add(matchedPersonnelLabel);

    JPanel buttons = new JPanel(new FlowLayout());
    buttons.setMaximumSize(
        new Dimension(Short.MAX_VALUE, (int) buttons.getPreferredSize().getHeight()));

    buttonSpendXP = new JButton(resourceMap.getString("spendXP.text")); // $NON-NLS-1$
    buttonSpendXP.setEnabled(false);
    buttonSpendXP.addActionListener(e -> spendXP());
    buttons.add(buttonSpendXP);

    JButton button = new JButton(resourceMap.getString("close.text")); // $NON-NLS-1$
    button.addActionListener(e -> setVisible(false));
    buttons.add(button);

    panel.add(buttons);

    panel.setMaximumSize(new Dimension((int) panel.getPreferredSize().getWidth(), Short.MAX_VALUE));
    panel.setMinimumSize(new Dimension((int) panel.getPreferredSize().getWidth(), 300));

    return panel;
  }
  /**
   * This method is called from within the constructor to initialize the form. WARNING: Do NOT
   * modify this code. The content of this method is always regenerated by the Form Editor.
   */
  private void initComponents() {
    java.awt.GridBagConstraints gridBagConstraints;

    choiceType = new javax.swing.JComboBox<String>();
    choiceRanks = new javax.swing.JComboBox<String>();

    lblType = new javax.swing.JLabel(resourceMap.getString("lblType.text"));
    lblRank = new javax.swing.JLabel(resourceMap.getString("lblRank.text"));
    lblNumber = new javax.swing.JLabel(resourceMap.getString("lblNumber.text"));
    btnHire = new JButton(resourceMap.getString("btnHire.text"));
    btnClose = new JButton(resourceMap.getString("btnClose.text"));
    panButtons = new JPanel(new GridBagLayout());

    setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    setName("Form"); // NOI18N

    setTitle(resourceMap.getString("Form.title"));
    getContentPane().setLayout(new GridBagLayout());

    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
    gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
    getContentPane().add(lblType, gridBagConstraints);

    DefaultComboBoxModel<String> personTypeModel = new DefaultComboBoxModel<String>();
    for (int i = 1; i < Person.T_NUM; i++) {
      personTypeModel.addElement(Person.getRoleDesc(i, campaign.getFaction().isClan()));
    }
    choiceType.setModel(personTypeModel);
    choiceType.setName("choiceType"); // NOI18N
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
    gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
    gridBagConstraints.weightx = 1.0;
    choiceType.setSelectedIndex(0);
    choiceType.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            // If we change the type, we need to setup the ranks for that type
            refreshRanksCombo();
          }
        });
    getContentPane().add(choiceType, gridBagConstraints);

    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 1;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
    gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
    getContentPane().add(lblRank, gridBagConstraints);

    rankModel = new DefaultComboBoxModel<String>();
    choiceRanks.setModel(rankModel);
    choiceRanks.setName("choiceRanks"); // NOI18N
    refreshRanksCombo();
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 1;
    gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
    gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
    gridBagConstraints.weightx = 1.0;
    getContentPane().add(choiceRanks, gridBagConstraints);

    spnNumber = new JSpinner(new SpinnerNumberModel(1, 1, 100, 1));

    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 2;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
    gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
    getContentPane().add(lblNumber, gridBagConstraints);
    gridBagConstraints = new java.awt.GridBagConstraints();

    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 2;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
    gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
    gridBagConstraints.weightx = 1.0;
    getContentPane().add(spnNumber, gridBagConstraints);

    btnHire.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            hire();
          }
        });
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;

    panButtons.add(btnHire, gridBagConstraints);
    gridBagConstraints.gridx++;

    btnClose.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            setVisible(false);
          }
        });
    panButtons.add(btnClose, gridBagConstraints);

    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 3;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
    gridBagConstraints.gridwidth = 2;
    gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
    gridBagConstraints.weightx = 1.0;
    getContentPane().add(panButtons, gridBagConstraints);

    pack();
  } // </editor-fold>//GEN-END:initComponents
 public OptionsChangedEvent(Campaign campaign) {
   this(campaign, campaign.getCampaignOptions());
 }
示例#12
0
  private void initComponents() {

    ResourceBundle resourceMap = ResourceBundle.getBundle("mekhq.resources.PartsStoreDialog");
    setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    setName("Form"); // NOI18N
    setTitle(resourceMap.getString("Form.title"));

    getContentPane().setLayout(new BorderLayout());

    partsTable = new JTable(partsModel);
    partsTable.setName("partsTable"); // NOI18N
    partsSorter = new TableRowSorter<PartsTableModel>(partsModel);
    partsSorter.setComparator(PartsTableModel.COL_TARGET, new TargetSorter());
    partsSorter.setComparator(PartsTableModel.COL_COST, new FormattedNumberSorter());
    partsSorter.setComparator(PartsTableModel.COL_DETAIL, new PartsDetailSorter());
    partsTable.setRowSorter(partsSorter);
    TableColumn column = null;
    for (int i = 0; i < PartsTableModel.N_COL; i++) {
      column = partsTable.getColumnModel().getColumn(i);
      column.setPreferredWidth(partsModel.getColumnWidth(i));
      column.setCellRenderer(partsModel.getRenderer());
    }
    partsTable.setIntercellSpacing(new Dimension(0, 0));
    partsTable.setShowGrid(false);
    scrollPartsTable = new JScrollPane();
    scrollPartsTable.setName("scrollPartsTable"); // NOI18N
    scrollPartsTable.setViewportView(partsTable);
    getContentPane().add(scrollPartsTable, BorderLayout.CENTER);

    GridBagConstraints c = new GridBagConstraints();
    panFilter = new JPanel();
    lblPartsChoice = new JLabel(resourceMap.getString("lblPartsChoice.text")); // NOI18N
    DefaultComboBoxModel<String> partsGroupModel = new DefaultComboBoxModel<String>();
    for (int i = 0; i < SG_NUM; i++) {
      partsGroupModel.addElement(getPartsGroupName(i));
    }
    choiceParts = new JComboBox<String>(partsGroupModel);
    choiceParts.setName("choiceParts"); // NOI18N
    choiceParts.setSelectedIndex(0);
    choiceParts.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            filterParts();
          }
        });
    panFilter.setLayout(new GridBagLayout());
    c.gridx = 0;
    c.gridy = 0;
    c.weightx = 0.0;
    c.anchor = java.awt.GridBagConstraints.WEST;
    c.insets = new Insets(5, 5, 5, 5);
    panFilter.add(lblPartsChoice, c);
    c.gridx = 1;
    c.weightx = 1.0;
    panFilter.add(choiceParts, c);

    lblFilter = new JLabel(resourceMap.getString("lblFilter.text")); // NOI18N
    lblFilter.setName("lblFilter"); // NOI18N
    c.gridx = 0;
    c.gridy = 1;
    c.weightx = 0.0;
    panFilter.add(lblFilter, c);
    txtFilter = new javax.swing.JTextField();
    txtFilter.setText(""); // NOI18N
    txtFilter.setMinimumSize(new java.awt.Dimension(200, 28));
    txtFilter.setName("txtFilter"); // NOI18N
    txtFilter.setPreferredSize(new java.awt.Dimension(200, 28));
    txtFilter
        .getDocument()
        .addDocumentListener(
            new DocumentListener() {
              public void changedUpdate(DocumentEvent e) {
                filterParts();
              }

              public void insertUpdate(DocumentEvent e) {
                filterParts();
              }

              public void removeUpdate(DocumentEvent e) {
                filterParts();
              }
            });
    c.gridx = 1;
    c.gridy = 1;
    c.weightx = 1.0;
    panFilter.add(txtFilter, c);
    getContentPane().add(panFilter, BorderLayout.PAGE_START);

    panButtons = new JPanel();
    if (addToCampaign) {
      btnAdd = new JButton(resourceMap.getString("btnAdd.text"));
      btnAdd.addActionListener(
          new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
              addPart(false, false);
            }
          });
      btnAdd.setEnabled(campaign.isGM());
      btnBuyBulk = new JButton(resourceMap.getString("btnBuyBulk.text"));
      btnBuyBulk.addActionListener(
          new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
              addPart(true, true);
              partsModel.fireTableCellUpdated(
                  partsTable.convertRowIndexToModel(partsTable.getSelectedRow()),
                  PartsTableModel.COL_TARGET);
              partsModel.fireTableCellUpdated(
                  partsTable.convertRowIndexToModel(partsTable.getSelectedRow()),
                  PartsTableModel.COL_TRANSIT);
              partsModel.fireTableCellUpdated(
                  partsTable.convertRowIndexToModel(partsTable.getSelectedRow()),
                  PartsTableModel.COL_SUPPLY);
              partsModel.fireTableCellUpdated(
                  partsTable.convertRowIndexToModel(partsTable.getSelectedRow()),
                  PartsTableModel.COL_QUEUE);
            }
          });
      btnBuy = new JButton(resourceMap.getString("btnBuy.text"));
      btnBuy.addActionListener(
          new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
              addPart(true, false);
              partsModel.fireTableCellUpdated(
                  partsTable.convertRowIndexToModel(partsTable.getSelectedRow()),
                  PartsTableModel.COL_TARGET);
              partsModel.fireTableCellUpdated(
                  partsTable.convertRowIndexToModel(partsTable.getSelectedRow()),
                  PartsTableModel.COL_TRANSIT);
              partsModel.fireTableCellUpdated(
                  partsTable.convertRowIndexToModel(partsTable.getSelectedRow()),
                  PartsTableModel.COL_SUPPLY);
              partsModel.fireTableCellUpdated(
                  partsTable.convertRowIndexToModel(partsTable.getSelectedRow()),
                  PartsTableModel.COL_QUEUE);
            }
          });
      btnUseBonusPart = new JButton();
      if (campaign.getCampaignOptions().getUseAtB()) {
        int numBonusParts = campaign.totalBonusParts();
        btnUseBonusPart.setText("Use Bonus Part (" + numBonusParts + ")");
        btnUseBonusPart.addActionListener(
            new java.awt.event.ActionListener() {
              public void actionPerformed(java.awt.event.ActionEvent evt) {
                addPart(true, false, true);
                partsModel.fireTableCellUpdated(
                    partsTable.convertRowIndexToModel(partsTable.getSelectedRow()),
                    PartsTableModel.COL_TARGET);
                partsModel.fireTableCellUpdated(
                    partsTable.convertRowIndexToModel(partsTable.getSelectedRow()),
                    PartsTableModel.COL_TRANSIT);
                partsModel.fireTableCellUpdated(
                    partsTable.convertRowIndexToModel(partsTable.getSelectedRow()),
                    PartsTableModel.COL_SUPPLY);
                partsModel.fireTableCellUpdated(
                    partsTable.convertRowIndexToModel(partsTable.getSelectedRow()),
                    PartsTableModel.COL_QUEUE);
                int numBonusParts = campaign.totalBonusParts();
                btnUseBonusPart.setText("Use Bonus Part (" + numBonusParts + ")");
                btnUseBonusPart.setVisible(numBonusParts > 0);
              }
            });
        btnUseBonusPart.setVisible(numBonusParts > 0);
      }
      btnClose = new JButton(resourceMap.getString("btnClose.text"));
      btnClose.addActionListener(
          new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
              setVisible(false);
            }
          });
      panButtons.setLayout(new GridBagLayout());
      panButtons.add(btnBuyBulk, new GridBagConstraints());
      panButtons.add(btnBuy, new GridBagConstraints());
      if (campaign.getCampaignOptions().getUseAtB()) {
        panButtons.add(btnUseBonusPart, new GridBagConstraints());
      }
      panButtons.add(btnAdd, new GridBagConstraints());
      panButtons.add(btnClose, new GridBagConstraints());
    } else {
      // if we arent adding the unit to the campaign, then different buttons
      btnAdd = new JButton("Add");
      btnAdd.addActionListener(
          new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
              setSelectedPart();
              setVisible(false);
            }
          });
      panButtons.add(btnAdd, new GridBagConstraints());

      btnClose = new JButton("Cancel"); // NOI18N
      btnClose.addActionListener(
          new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
              selectedPart = null;
              setVisible(false);
            }
          });
      panButtons.add(btnClose, new GridBagConstraints());
    }
    getContentPane().add(panButtons, BorderLayout.PAGE_END);
    this.setPreferredSize(new Dimension(700, 600));
    pack();
  }