Subversion Repositories public

Rev

Rev 93 | Details | Compare with Previous | Last modification | View Log | RSS feed

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