Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/schooltool/client/gui/dialogs/NotesDialog.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 NotesDialog 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      public NotesDialog(java.awt.Frame parent, boolean modal) {
26          super(parent, modal);
27          initComponents();
28          String message = "Enter Note:";
29          final JTextArea textField = new JTextArea(5,50);
30          Object [] array = {message, textField};
31          Object [] options = {"Enter", "Cancel"};
32          optionPane = new JOptionPane(array, 
33                                      JOptionPane.PLAIN_MESSAGE,
34                                      JOptionPane.YES_NO_OPTION,
35                                      null,
36                                      options,
37                                      options[0]);
38          setContentPane(optionPane);
39          setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
40          
41  //        textField.addActionListener(new ActionListener() {
42  //            public void actionPerformed(ActionEvent e) {
43  //                optionPane.setValue("Enter");
44  //            }
45  //        });
46  
47          optionPane.addPropertyChangeListener(new PropertyChangeListener() {
48              public void propertyChange(PropertyChangeEvent e) {
49                  String prop = e.getPropertyName();
50  
51                  if (isVisible() 
52                   && (e.getSource() == optionPane)
53                   && (prop.equals(JOptionPane.VALUE_PROPERTY) ||
54                       prop.equals(JOptionPane.INPUT_VALUE_PROPERTY))) {
55                      Object value = optionPane.getValue();
56  
57                      if (value == JOptionPane.UNINITIALIZED_VALUE) {
58                          //ignore reset
59                          return;
60                      }
61  
62                      // Reset the JOptionPane's value.
63                      // If you don't do this, then if the user
64                      // presses the same button next time, no
65                      // property change event will be fired.
66                      optionPane.setValue(
67                              JOptionPane.UNINITIALIZED_VALUE);
68  
69                      if (value.equals("Enter")) {
70                          typedText = textField.getText();
71                          if (!typedText.equals("")) {
72                              // we're done; dismiss the dialog
73                              setVisible(false);
74                          } else { 
75  
76                              JOptionPane.showMessageDialog(
77                                              NotesDialog.this,
78                                              "You didn't enter a Note.",
79                                              "Error",
80                                              JOptionPane.ERROR_MESSAGE);
81                              typedText = null;
82                          }
83                      } else { // user closed dialog or clicked cancel
84                          typedText = null;
85                          setVisible(false);
86                      }
87                  }
88              }
89          });
90  
91      }
92  
93      /** This method is called from within the constructor to
94       * initialize the form.
95       * WARNING: Do NOT modify this code. The content of this method is
96       * always regenerated by the Form Editor.
97       */
98      private void initComponents() {//GEN-BEGIN:initComponents
99          
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 }