Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

userPrompt.java

00001 package guiUtilities;
00002 import javax.swing.JOptionPane;
00003 import javax.swing.JDialog;
00004 //import javax.swing.JPasswordField;
00005 import javax.swing.JTextField;
00006 import java.beans.*; //Property change stuff
00007 import java.awt.*;
00008 import java.awt.event.*;
00009 import java.util.Vector;
00010 import javax.swing.JComboBox;
00011 
00012 public class userPrompt extends JDialog {
00013 
00014     private JOptionPane optionPane;
00015     private JComboBox iMenu;
00016     private boolean menuIsValid;
00017 
00018     public String getValidatedText() {
00019         String returnString="None";
00020         if(menuIsValid) returnString = (String)iMenu.getSelectedItem();
00021         return returnString;
00022     }
00023 
00024 
00025     public int getValidatedIndex() {
00026         int returnValue=-1;
00027         if(menuIsValid) returnValue = iMenu.getSelectedIndex();
00028         return returnValue;
00029     }    
00030   public userPrompt(Frame aFrame,String iName, String type, Vector menuItems) {
00031 // iName is supplied institute name or supplied username
00032 // type is 'Institute' or 'Username' depending on context
00033         super(aFrame, true);
00034 
00035         setBackground(java.awt.Color.white);
00036 //        final String msgString1 = "Enter "+type
00037         final String msgString2 = "Select "+type+":";
00038         iMenu = new JComboBox(menuItems);
00039         iMenu.setSelectedItem(iName);
00040         Object[] array = {msgString2, iMenu};
00041 
00042         final String btnString1 = "Enter";
00043         final String btnString2 = "Cancel";
00044         Object[] options = {btnString1, btnString2};
00045 
00046         optionPane = new JOptionPane(array, 
00047                                     JOptionPane.QUESTION_MESSAGE,
00048                                     JOptionPane.YES_NO_OPTION,
00049                                     null,
00050                                     options,
00051                                     options[0]);
00052         setContentPane(optionPane);
00053         setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
00054         addWindowListener(new WindowAdapter() {
00055                 public void windowClosing(WindowEvent we) {
00056                 /*
00057                  * Instead of directly closing the window,
00058                  * we're going to change the JOptionPane's
00059                  * value property.
00060                  */
00061                     optionPane.setValue(new Integer(
00062                                         JOptionPane.CLOSED_OPTION));
00063             }
00064         });
00065 
00066 
00067         optionPane.addPropertyChangeListener(new PropertyChangeListener() {
00068             public void propertyChange(PropertyChangeEvent e) {
00069                 String prop = e.getPropertyName();
00070 
00071                 if (isVisible() 
00072                  && (e.getSource() == optionPane)
00073                  && (prop.equals(JOptionPane.VALUE_PROPERTY) ||
00074                      prop.equals(JOptionPane.INPUT_VALUE_PROPERTY))) {
00075                     Object value = optionPane.getValue();
00076 
00077                     if (value == JOptionPane.UNINITIALIZED_VALUE) {
00078                         //ignore reset
00079                         return;
00080                     }
00081 
00082                     // Reset the JOptionPane's value.
00083                     // If you don't do this, then if the user
00084                     // presses the same button next time, no
00085                     // property change event will be fired.
00086                     optionPane.setValue(
00087                             JOptionPane.UNINITIALIZED_VALUE);
00088 
00089                     if (value.equals(btnString1)) {
00090                         menuIsValid=true; 
00091                     } else { // user closed dialog or clicked cancel
00092                         menuIsValid=false;
00093                     }
00094                    setVisible(false);
00095                 }
00096             }
00097         });
00098     }
00099 }

Generated on Thu Jul 15 09:55:51 2004 for SCT DAQ/DCS Software - Java by doxygen 1.3.5