Subversion Repositories public

Rev

Rev 94 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
93 luk 1
/*
2
 * TaskPropetiesDialog.java
3
 *
4
 * Created on 3. květen 2008, 20:16
5
 */
6
 
7
package cz.aiken.util.lwtt;
8
 
9
import javax.swing.JOptionPane;
10
 
11
/**
12
 *
13
 * @author  luk
14
 */
15
public class TaskPropetiesDialog extends javax.swing.JDialog {
16
    /** A return status code - returned if Cancel button has been pressed */
17
    public static final int RET_CANCEL = 0;
18
    /** A return status code - returned if OK button has been pressed */
19
    public static final int RET_OK = 1;
20
 
21
    private double price = 1;
22
 
23
    /** Creates new form TaskPropetiesDialog */
24
    public TaskPropetiesDialog(java.awt.Frame parent, boolean modal) {
25
        super(parent, modal);
26
        initComponents();
27
        priceText.setText(Double.toString(price));
28
    }
29
 
30
    /** @return the return status of this dialog - one of RET_OK or RET_CANCEL */
31
    public int getReturnStatus() {
32
        return returnStatus;
33
    }
34
 
35
    public void setPrice(double price) {
36
        this.price = price;
37
        priceText.setText(Double.toString(price));
38
    }
39
 
40
    public double getPrice() {
41
        return price;
42
    }
43
 
44
 
45
    /** This method is called from within the constructor to
46
     * initialize the form.
47
     * WARNING: Do NOT modify this code. The content of this method is
48
     * always regenerated by the Form Editor.
49
     */
50
    @SuppressWarnings("unchecked")
51
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
52
    private void initComponents() {
53
 
54
        okButton = new javax.swing.JButton();
55
        cancelButton = new javax.swing.JButton();
56
        priceLabel = new javax.swing.JLabel();
57
        priceText = new javax.swing.JTextField();
58
 
59
        setTitle("Properties");
60
        setLocationByPlatform(true);
61
        setResizable(false);
62
        addWindowListener(new java.awt.event.WindowAdapter() {
63
            public void windowClosing(java.awt.event.WindowEvent evt) {
64
                closeDialog(evt);
65
            }
66
        });
67
 
68
        okButton.setText("OK");
69
        okButton.addActionListener(new java.awt.event.ActionListener() {
70
            public void actionPerformed(java.awt.event.ActionEvent evt) {
71
                okButtonActionPerformed(evt);
72
            }
73
        });
74
 
75
        cancelButton.setText("Cancel");
76
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
77
            public void actionPerformed(java.awt.event.ActionEvent evt) {
78
                cancelButtonActionPerformed(evt);
79
            }
80
        });
81
 
82
        priceLabel.setText("Price per hour");
83
 
84
        priceText.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
85
 
86
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
87
        getContentPane().setLayout(layout);
88
        layout.setHorizontalGroup(
89
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
90
            .addGroup(layout.createSequentialGroup()
91
                .addContainerGap()
92
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
93
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
94
                        .addComponent(okButton, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
95
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
96
                        .addComponent(cancelButton))
97
                    .addGroup(layout.createSequentialGroup()
98
                        .addComponent(priceLabel)
99
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
100
                        .addComponent(priceText, javax.swing.GroupLayout.DEFAULT_SIZE, 69, Short.MAX_VALUE)))
101
                .addContainerGap())
102
        );
103
 
104
        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {cancelButton, okButton});
105
 
106
        layout.setVerticalGroup(
107
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
108
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
109
                .addContainerGap()
110
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
111
                    .addComponent(priceLabel)
112
                    .addComponent(priceText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
113
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 22, Short.MAX_VALUE)
114
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
115
                    .addComponent(cancelButton)
116
                    .addComponent(okButton))
117
                .addContainerGap())
118
        );
119
 
120
        pack();
121
    }// </editor-fold>//GEN-END:initComponents
122
 
123
    private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
124
        try {
125
            double p = Double.parseDouble(priceText.getText());
126
            if (p < 0)
127
                throw new NumberFormatException("price value must not be negative");
128
            price = p;
129
            doClose(RET_OK);
130
        } catch (NumberFormatException ex) {
131
            JOptionPane.showMessageDialog(this, "Price per hour has invalid format.\nPlease use a non-negative number.", "Invalid format", JOptionPane.ERROR_MESSAGE);
132
        }        
133
    }//GEN-LAST:event_okButtonActionPerformed
134
 
135
    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
136
        doClose(RET_CANCEL);
137
    }//GEN-LAST:event_cancelButtonActionPerformed
138
 
139
    /** Closes the dialog */
140
    private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
141
        doClose(RET_CANCEL);
142
    }//GEN-LAST:event_closeDialog
143
 
144
    private void doClose(int retStatus) {
145
        returnStatus = retStatus;
146
        setVisible(false);
147
        dispose();
148
    }
149
 
150
    /**
151
    * @param args the command line arguments
152
    */
153
    public static void main(String args[]) {
154
        java.awt.EventQueue.invokeLater(new Runnable() {
155
            public void run() {
156
                TaskPropetiesDialog dialog = new TaskPropetiesDialog(new javax.swing.JFrame(), true);
157
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
158
                    public void windowClosing(java.awt.event.WindowEvent e) {
159
                        System.exit(0);
160
                    }
161
                });
162
                dialog.setVisible(true);
163
            }
164
        });
165
    }
166
 
167
    // Variables declaration - do not modify//GEN-BEGIN:variables
168
    private javax.swing.JButton cancelButton;
169
    private javax.swing.JButton okButton;
170
    private javax.swing.JLabel priceLabel;
171
    private javax.swing.JTextField priceText;
172
    // End of variables declaration//GEN-END:variables
173
 
174
    private int returnStatus = RET_CANCEL;
175
}