package GUI.dialogs; import java.awt.Frame; import javax.swing.JOptionPane; import main.error.VideothekException; import model.PriceCategory; /** * PriceCategoryDataDialog.java * @author Christopher Bertels (chbertel@uos.de) * 23.09.2008 * * Dialog zum Bearbeiten von Preiskategorien. */ public class PriceCategoryDataDialog extends javax.swing.JDialog { private static final long serialVersionUID = -2881989733786613372L; private PriceCategory priceCategory; /** Creates new form PriceCategoryDataDialog */ public PriceCategoryDataDialog(Frame parent, PriceCategory priceCategory) { super(parent, true); this.priceCategory = priceCategory; initComponents(); DialogHelper.setToCenterScreen(this); this.nameTextField.setText(this.priceCategory.getName()); int euros = (int)this.priceCategory.getPrice(); int cents = (int) ((this.priceCategory.getPrice() - euros) * 100); this.euroSpinner.setValue(new Integer(euros)); this.centSpinner.setValue(new Integer(cents)); } public PriceCategoryDataDialog(Frame parent) { super(parent, true); this.priceCategory = null; initComponents(); DialogHelper.setToCenterScreen(this); euroSpinner.setValue(new Integer(1)); } /** 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. */ // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { jLabel1 = new javax.swing.JLabel(); nameTextField = new javax.swing.JTextField(); jLabel2 = new javax.swing.JLabel(); okButton = new javax.swing.JButton(); cancelButton = new javax.swing.JButton(); euroSpinner = new javax.swing.JSpinner(); centSpinner = new javax.swing.JSpinner(); jLabel4 = new javax.swing.JLabel(); jLabel5 = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setTitle("Preiskategorie: Daten bearbeiten"); jLabel1.setText("Name"); jLabel2.setText("Preis"); okButton.setText("OK"); okButton.setMaximumSize(new java.awt.Dimension(85, 23)); okButton.setMinimumSize(new java.awt.Dimension(85, 23)); okButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { okButtonActionPerformed(evt); } }); cancelButton.setText("Abbrechen"); cancelButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cancelButtonActionPerformed(evt); } }); jLabel4.setText(","); jLabel5.setText("Euro"); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addComponent(cancelButton) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(okButton, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel1) .addComponent(jLabel2)) .addGap(14, 14, 14) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(nameTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 153, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup() .addComponent(euroSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel4) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(centSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel5))))) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1) .addComponent(nameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2) .addComponent(euroSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(centSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel4) .addComponent(jLabel5)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 20, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(cancelButton) .addComponent(okButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap()) ); pack(); } // </editor-fold> private void okButtonActionPerformed(java.awt.event.ActionEvent evt) { // neue kategorie erstellen und speichern try { Integer euros = (Integer) euroSpinner.getValue(); Integer cents = (Integer) centSpinner.getValue(); float price = (float) euros + ((float) cents / 100); if(this.priceCategory != null) { this.priceCategory.setName(this.nameTextField.getText()); this.priceCategory.setPrice(price); this.priceCategory.save(); } else { this.priceCategory = new PriceCategory(this.nameTextField.getText(), price); } this.dispose(); } catch (VideothekException e) { JOptionPane.showMessageDialog(this, e.getMessage(), "Fehler", JOptionPane.ERROR_MESSAGE); } } private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) { this.dispose(); } // Variables declaration - do not modify private javax.swing.JButton cancelButton; private javax.swing.JSpinner centSpinner; private javax.swing.JSpinner euroSpinner; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JTextField nameTextField; private javax.swing.JButton okButton; // End of variables declaration }