Subversion Repositories public

Rev

Rev 96 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 96 Rev 97
1
/*
1
/*
2
 * TaskPropertiesDialog.java - task properties dialog
2
 * TaskPropertiesDialog.java - task properties dialog
3
 *
3
 *
4
 * Copyright (c) 2008 Lukas Jelinek, http://www.aiken.cz
4
 * Copyright (c) 2008 Lukas Jelinek, http://www.aiken.cz
5
 *
5
 *
6
 * ==========================================================================
6
 * ==========================================================================
7
 *
7
 *
8
 * This program is free software; you can redistribute it and/or modify
8
 * This program is free software; you can redistribute it and/or modify
9
 * it under the terms of the GNU General Public License Version 2 as
9
 * it under the terms of the GNU General Public License Version 2 as
10
 * published by the Free Software Foundation.
10
 * published by the Free Software Foundation.
11
 *
11
 *
12
 * This program is distributed in the hope that it will be useful,
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
15
 * GNU General Public License for more details.
16
 *
16
 *
17
 * You should have received a copy of the GNU General Public License
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program; if not, write to the Free Software
18
 * along with this program; if not, write to the Free Software
19
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
 *
20
 *
21
 * ==========================================================================
21
 * ==========================================================================
22
 */
22
 */
23
23
24
package cz.aiken.util.lwtt;
24
package cz.aiken.util.lwtt;
25
25
26
import javax.swing.JOptionPane;
26
import javax.swing.JOptionPane;
27
27
28
/**
28
/**
29
 * Task properties dialog class.
29
 * Task properties dialog class.
30
 *
30
 *
31
 * This class allows to set various properties of a task. Currently only
31
 * This class allows to set various properties of a task. Currently only
32
 * price per hour can be set.
32
 * price per hour can be set.
33
 *
33
 *
34
 * @author  luk
34
 * @author  luk
35
 */
35
 */
36
public class TaskPropetiesDialog extends javax.swing.JDialog {
36
public class TaskPropertiesDialog extends javax.swing.JDialog {
37
    /** A return status code - returned if Cancel button has been pressed */
37
    /** A return status code - returned if Cancel button has been pressed */
38
    public static final int RET_CANCEL = 0;
38
    public static final int RET_CANCEL = 0;
39
    /** A return status code - returned if OK button has been pressed */
39
    /** A return status code - returned if OK button has been pressed */
40
    public static final int RET_OK = 1;
40
    public static final int RET_OK = 1;
41
   
41
   
42
    private double price = 1;
42
    private double price = 1;
43
43
44
    /** Creates a new TaskPropetiesDialog.
44
    /** Creates a new TaskPropertiesDialog.
45
     * @param parent parent object for this dialog
45
     * @param parent parent object for this dialog
46
     * @param modal modal dialog yes/no
46
     * @param modal modal dialog yes/no
47
     */
47
     */
48
    public TaskPropetiesDialog(java.awt.Frame parent, boolean modal) {
48
    public TaskPropertiesDialog(java.awt.Frame parent, boolean modal) {
49
        super(parent, modal);
49
        super(parent, modal);
50
        initComponents();
50
        initComponents();
51
        priceText.setText(Double.toString(price));
51
        priceText.setText(Double.toString(price));
52
    }
52
    }
53
53
54
    /**
54
    /**
55
     * Returns the "return status" of this dialog - one of RET_OK or RET_CANCEL.
55
     * Returns the "return status" of this dialog - one of RET_OK or RET_CANCEL.
56
     *
56
     *
57
     * @return return status
57
     * @return return status
58
     */
58
     */
59
    public int getReturnStatus() {
59
    public int getReturnStatus() {
60
        return returnStatus;
60
        return returnStatus;
61
    }
61
    }
62
   
62
   
63
    /**
63
    /**
64
     * Sets the price per hour.
64
     * Sets the price per hour.
65
     *
65
     *
66
     * @param price new price per hour
66
     * @param price new price per hour
67
     */
67
     */
68
    public void setPrice(double price) {
68
    public void setPrice(double price) {
69
        this.price = price;
69
        this.price = price;
70
        priceText.setText(Double.toString(price));
70
        priceText.setText(Double.toString(price));
71
    }
71
    }
72
   
72
   
73
    /**
73
    /**
74
     * Returns the price per hour.
74
     * Returns the price per hour.
75
     *
75
     *
76
     * @return price per hour
76
     * @return price per hour
77
     */
77
     */
78
    public double getPrice() {
78
    public double getPrice() {
79
        return price;
79
        return price;
80
    }
80
    }
81
           
81
           
82
82
83
    /** This method is called from within the constructor to
83
    /** This method is called from within the constructor to
84
     * initialize the form.
84
     * initialize the form.
85
     * WARNING: Do NOT modify this code. The content of this method is
85
     * WARNING: Do NOT modify this code. The content of this method is
86
     * always regenerated by the Form Editor.
86
     * always regenerated by the Form Editor.
87
     */
87
     */
88
    @SuppressWarnings("unchecked")
88
    @SuppressWarnings("unchecked")
89
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
89
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
90
    private void initComponents() {
90
    private void initComponents() {
91
91
92
        okButton = new javax.swing.JButton();
92
        okButton = new javax.swing.JButton();
93
        cancelButton = new javax.swing.JButton();
93
        cancelButton = new javax.swing.JButton();
94
        priceLabel = new javax.swing.JLabel();
94
        priceLabel = new javax.swing.JLabel();
95
        priceText = new javax.swing.JTextField();
95
        priceText = new javax.swing.JTextField();
96
96
97
        setTitle("Properties");
97
        setTitle("Properties");
98
        setLocationByPlatform(true);
98
        setLocationByPlatform(true);
99
        setResizable(false);
99
        setResizable(false);
100
        addWindowListener(new java.awt.event.WindowAdapter() {
100
        addWindowListener(new java.awt.event.WindowAdapter() {
101
            public void windowClosing(java.awt.event.WindowEvent evt) {
101
            public void windowClosing(java.awt.event.WindowEvent evt) {
102
                closeDialog(evt);
102
                closeDialog(evt);
103
            }
103
            }
104
        });
104
        });
105
105
106
        okButton.setText("OK");
106
        okButton.setText("OK");
107
        okButton.addActionListener(new java.awt.event.ActionListener() {
107
        okButton.addActionListener(new java.awt.event.ActionListener() {
108
            public void actionPerformed(java.awt.event.ActionEvent evt) {
108
            public void actionPerformed(java.awt.event.ActionEvent evt) {
109
                okButtonActionPerformed(evt);
109
                okButtonActionPerformed(evt);
110
            }
110
            }
111
        });
111
        });
112
112
113
        cancelButton.setText("Cancel");
113
        cancelButton.setText("Cancel");
114
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
114
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
115
            public void actionPerformed(java.awt.event.ActionEvent evt) {
115
            public void actionPerformed(java.awt.event.ActionEvent evt) {
116
                cancelButtonActionPerformed(evt);
116
                cancelButtonActionPerformed(evt);
117
            }
117
            }
118
        });
118
        });
119
119
120
        priceLabel.setText("Price per hour");
120
        priceLabel.setText("Price per hour");
121
121
122
        priceText.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
122
        priceText.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
123
123
124
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
124
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
125
        getContentPane().setLayout(layout);
125
        getContentPane().setLayout(layout);
126
        layout.setHorizontalGroup(
126
        layout.setHorizontalGroup(
127
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
127
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
128
            .addGroup(layout.createSequentialGroup()
128
            .addGroup(layout.createSequentialGroup()
129
                .addContainerGap()
129
                .addContainerGap()
130
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
130
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
131
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
131
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
132
                        .addComponent(okButton, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
132
                        .addComponent(okButton, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
133
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
133
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
134
                        .addComponent(cancelButton))
134
                        .addComponent(cancelButton))
135
                    .addGroup(layout.createSequentialGroup()
135
                    .addGroup(layout.createSequentialGroup()
136
                        .addComponent(priceLabel)
136
                        .addComponent(priceLabel)
137
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
137
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
138
                        .addComponent(priceText, javax.swing.GroupLayout.DEFAULT_SIZE, 69, Short.MAX_VALUE)))
138
                        .addComponent(priceText, javax.swing.GroupLayout.DEFAULT_SIZE, 69, Short.MAX_VALUE)))
139
                .addContainerGap())
139
                .addContainerGap())
140
        );
140
        );
141
141
142
        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {cancelButton, okButton});
142
        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {cancelButton, okButton});
143
143
144
        layout.setVerticalGroup(
144
        layout.setVerticalGroup(
145
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
145
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
146
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
146
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
147
                .addContainerGap()
147
                .addContainerGap()
148
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
148
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
149
                    .addComponent(priceLabel)
149
                    .addComponent(priceLabel)
150
                    .addComponent(priceText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
150
                    .addComponent(priceText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
151
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 22, Short.MAX_VALUE)
151
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 22, Short.MAX_VALUE)
152
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
152
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
153
                    .addComponent(cancelButton)
153
                    .addComponent(cancelButton)
154
                    .addComponent(okButton))
154
                    .addComponent(okButton))
155
                .addContainerGap())
155
                .addContainerGap())
156
        );
156
        );
157
157
158
        pack();
158
        pack();
159
    }// </editor-fold>//GEN-END:initComponents
159
    }// </editor-fold>//GEN-END:initComponents
160
160
161
    private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
161
    private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
162
        try {
162
        try {
163
            double p = Double.parseDouble(priceText.getText());
163
            double p = Double.parseDouble(priceText.getText());
164
            if (p < 0)
164
            if (p < 0)
165
                throw new NumberFormatException("price value must not be negative");
165
                throw new NumberFormatException("price value must not be negative");
166
            price = p;
166
            price = p;
167
            doClose(RET_OK);
167
            doClose(RET_OK);
168
        } catch (NumberFormatException ex) {
168
        } catch (NumberFormatException ex) {
169
            JOptionPane.showMessageDialog(this, "Price per hour has invalid format.\nPlease use a non-negative number.", "Invalid format", JOptionPane.ERROR_MESSAGE);
169
            JOptionPane.showMessageDialog(this, "Price per hour has invalid format.\nPlease use a non-negative number.", "Invalid format", JOptionPane.ERROR_MESSAGE);
170
        }        
170
        }        
171
    }//GEN-LAST:event_okButtonActionPerformed
171
    }//GEN-LAST:event_okButtonActionPerformed
172
172
173
    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
173
    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
174
        doClose(RET_CANCEL);
174
        doClose(RET_CANCEL);
175
    }//GEN-LAST:event_cancelButtonActionPerformed
175
    }//GEN-LAST:event_cancelButtonActionPerformed
176
176
177
    /** Closes the dialog */
177
    /** Closes the dialog */
178
    private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
178
    private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
179
        doClose(RET_CANCEL);
179
        doClose(RET_CANCEL);
180
    }//GEN-LAST:event_closeDialog
180
    }//GEN-LAST:event_closeDialog
181
181
182
    private void doClose(int retStatus) {
182
    private void doClose(int retStatus) {
183
        returnStatus = retStatus;
183
        returnStatus = retStatus;
184
        setVisible(false);
184
        setVisible(false);
185
        dispose();
185
        dispose();
186
    }
186
    }
187
187
188
    /**
188
    /**
189
     * This method is only for testing purposes.
189
     * This method is only for testing purposes.
190
     *
190
     *
191
     * @param args the command line arguments
191
     * @param args the command line arguments
192
     */
192
     */
193
    public static void main(String args[]) {
193
    public static void main(String args[]) {
194
        java.awt.EventQueue.invokeLater(new Runnable() {
194
        java.awt.EventQueue.invokeLater(new Runnable() {
195
            public void run() {
195
            public void run() {
196
                TaskPropetiesDialog dialog = new TaskPropetiesDialog(new javax.swing.JFrame(), true);
196
                TaskPropertiesDialog dialog = new TaskPropertiesDialog(new javax.swing.JFrame(), true);
197
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
197
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
198
                    @Override
198
                    @Override
199
                    public void windowClosing(java.awt.event.WindowEvent e) {
199
                    public void windowClosing(java.awt.event.WindowEvent e) {
200
                        System.exit(0);
200
                        System.exit(0);
201
                    }
201
                    }
202
                });
202
                });
203
                dialog.setVisible(true);
203
                dialog.setVisible(true);
204
            }
204
            }
205
        });
205
        });
206
    }
206
    }
207
207
208
    // Variables declaration - do not modify//GEN-BEGIN:variables
208
    // Variables declaration - do not modify//GEN-BEGIN:variables
209
    private javax.swing.JButton cancelButton;
209
    private javax.swing.JButton cancelButton;
210
    private javax.swing.JButton okButton;
210
    private javax.swing.JButton okButton;
211
    private javax.swing.JLabel priceLabel;
211
    private javax.swing.JLabel priceLabel;
212
    private javax.swing.JTextField priceText;
212
    private javax.swing.JTextField priceText;
213
    // End of variables declaration//GEN-END:variables
213
    // End of variables declaration//GEN-END:variables
214
214
215
    private int returnStatus = RET_CANCEL;
215
    private int returnStatus = RET_CANCEL;
216
}
216
}
217
 
217