Subversion Repositories public

Rev

Rev 93 | Rev 96 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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