Source code: org/schooltool/client/gui/dialogs/SupplierSetupDialog.java
1 /*
2 * SupplierSetupDialog.java
3 *
4 * Created on November 9, 2001, 3:05 PM
5 */
6
7 package org.schooltool.client.gui.dialogs;
8
9 import javax.swing.*;
10 import java.awt.event.*;
11 import java.beans.*;
12 /**
13 *
14 * @author root
15 */
16 public class SupplierSetupDialog extends javax.swing.JDialog {
17
18 private JOptionPane optionPane;
19 private String typedText = null;
20
21 public String getValidatedText() {
22 return typedText;
23 }
24
25 /** Creates new form SupplierSetupDialog */
26 public SupplierSetupDialog(java.awt.Frame parent, boolean modal) {
27 super(parent, modal);
28 initComponents();
29 String message = "Enter the Supplier Name:";
30 final JTextField textField = new JTextField(20);
31 Object [] array = {message, textField};
32 Object [] options = {"Enter", "Cancel"};
33 optionPane = new JOptionPane(array,
34 JOptionPane.PLAIN_MESSAGE,
35 JOptionPane.YES_NO_OPTION,
36 null,
37 options,
38 options[0]);
39 setContentPane(optionPane);
40 setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
41
42 textField.addActionListener(new ActionListener() {
43 public void actionPerformed(ActionEvent e) {
44 optionPane.setValue("Enter");
45 }
46 });
47
48 optionPane.addPropertyChangeListener(new PropertyChangeListener() {
49 public void propertyChange(PropertyChangeEvent e) {
50 String prop = e.getPropertyName();
51
52 if (isVisible()
53 && (e.getSource() == optionPane)
54 && (prop.equals(JOptionPane.VALUE_PROPERTY) ||
55 prop.equals(JOptionPane.INPUT_VALUE_PROPERTY))) {
56 Object value = optionPane.getValue();
57
58 if (value == JOptionPane.UNINITIALIZED_VALUE) {
59 //ignore reset
60 return;
61 }
62
63 // Reset the JOptionPane's value.
64 // If you don't do this, then if the user
65 // presses the same button next time, no
66 // property change event will be fired.
67 optionPane.setValue(
68 JOptionPane.UNINITIALIZED_VALUE);
69
70 if (value.equals("Enter")) {
71 typedText = textField.getText();
72 if (!typedText.equals("")) {
73 // we're done; dismiss the dialog
74 setVisible(false);
75 } else {
76
77 JOptionPane.showMessageDialog(
78 SupplierSetupDialog.this,
79 "You didn't enter a Supplier Name.",
80 "Error",
81 JOptionPane.ERROR_MESSAGE);
82 typedText = null;
83 }
84 } else { // user closed dialog or clicked cancel
85 typedText = null;
86 setVisible(false);
87 }
88 }
89 }
90 });
91
92 }
93
94 /** This method is called from within the constructor to
95 * initialize the form.
96 * WARNING: Do NOT modify this code. The content of this method is
97 * always regenerated by the Form Editor.
98 */
99 private void initComponents() {//GEN-BEGIN:initComponents
100 addWindowListener(new java.awt.event.WindowAdapter() {
101 public void windowClosing(java.awt.event.WindowEvent evt) {
102 closeDialog(evt);
103 }
104 }
105 );
106 pack();
107 }//GEN-END:initComponents
108
109 /** Closes the dialog */
110 private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
111 optionPane.setValue(new Integer(JOptionPane.CLOSED_OPTION));
112 }//GEN-LAST:event_closeDialog
113
114 // Variables declaration - do not modify//GEN-BEGIN:variables
115 // End of variables declaration//GEN-END:variables
116
117 }