/* * EditAssetDialog.java * * Copyright (c) 2009 Jay Lawson <jaylawson39 at yahoo.com>. All rights reserved. * * This file is part of MekHQ. * * MekHQ is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * MekHQ is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with MekHQ. If not, see <http://www.gnu.org/licenses/>. */ package mekhq.gui.dialog; import java.awt.Frame; import javax.swing.DefaultComboBoxModel; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JTextField; import mekhq.campaign.finances.Asset; import mekhq.campaign.finances.Finances; /** * * @author Taharqa */ public class EditAssetDialog extends JDialog { private static final long serialVersionUID = -8038099101234445018L; @SuppressWarnings("unused") private Frame frame; // FIXME: Why is this here? private Asset asset; private JButton btnClose; private JButton btnOK; private JTextField txtName; private JTextField txtValue; private JTextField txtIncome; private JComboBox<String> choiceSchedule; boolean cancelled; public EditAssetDialog(Frame parent, Asset a) { super(parent, true); this.frame = parent; this.asset = a; cancelled = false; initComponents(); setLocationRelativeTo(parent); } private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; txtName = new JTextField(); txtValue = new JTextField(); txtIncome = new JTextField(); btnOK = new javax.swing.JButton(); btnClose = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setTitle("Edit Asset"); getContentPane().setLayout(new java.awt.GridBagLayout()); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.gridwidth = 1; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); getContentPane().add(new JLabel("Name:"), gridBagConstraints); txtName.setText(asset.getName()); txtName.setMinimumSize(new java.awt.Dimension(150, 28)); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 0; gridBagConstraints.gridwidth = 1; gridBagConstraints.weightx = 1.0; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); getContentPane().add(txtName, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.gridwidth = 1; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); getContentPane().add(new JLabel("Value of Asset:"), gridBagConstraints); txtValue.setText(Long.toString(asset.getValue())); txtValue.setMinimumSize(new java.awt.Dimension(150, 28)); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 1; gridBagConstraints.gridwidth = 1; gridBagConstraints.weightx = 1.0; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); getContentPane().add(txtValue, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 2; gridBagConstraints.gridwidth = 1; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); getContentPane().add(new JLabel("Income supplied:"), gridBagConstraints); txtIncome.setText(Long.toString(asset.getIncome())); txtIncome.setMinimumSize(new java.awt.Dimension(150, 28)); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 2; gridBagConstraints.gridwidth = 1; gridBagConstraints.weightx = 1.0; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); getContentPane().add(txtIncome, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 3; gridBagConstraints.gridwidth = 1; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); getContentPane().add(new JLabel("Income Schedule:"), gridBagConstraints); DefaultComboBoxModel<String> scheduleModel = new DefaultComboBoxModel<String>(); scheduleModel.addElement(Finances.getScheduleName(Finances.SCHEDULE_MONTHLY)); scheduleModel.addElement(Finances.getScheduleName(Finances.SCHEDULE_YEARLY)); choiceSchedule = new JComboBox<String>(scheduleModel); choiceSchedule.setSelectedIndex(0); if(asset.getSchedule() == Finances.SCHEDULE_YEARLY) { choiceSchedule.setSelectedIndex(1); } gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 3; gridBagConstraints.gridwidth = 1; gridBagConstraints.weightx = 1.0; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); getContentPane().add(choiceSchedule, gridBagConstraints); btnOK.setText("OK"); // NOI18N btnOK.setName("btnOK"); // NOI18N btnOK.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnOKActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 4; gridBagConstraints.gridwidth = 1; gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); getContentPane().add(btnOK, gridBagConstraints); btnClose.setText("Cancel"); // NOI18N btnClose.setName("btnClose"); // NOI18N btnClose.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnCloseActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 4; gridBagConstraints.gridwidth = 1; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); getContentPane().add(btnClose, gridBagConstraints); pack(); } private void btnOKActionPerformed(java.awt.event.ActionEvent evt) { asset.setName(txtName.getText()); try { asset.setValue(Long.parseLong(txtValue.getText())); } catch(NumberFormatException e) { } try { asset.setIncome(Long.parseLong(txtIncome.getText())); } catch(NumberFormatException e) { } if(choiceSchedule.getSelectedIndex() == 1) { asset.setSchedule(Finances.SCHEDULE_YEARLY); } else { asset.setSchedule(Finances.SCHEDULE_MONTHLY); } this.setVisible(false); } private void btnCloseActionPerformed(java.awt.event.ActionEvent evt) { cancelled = true; this.setVisible(false); } public boolean wasCancelled() { return cancelled; } }