InputDialog.java
Go to the documentation of this file.
00001 /*
00002  * (c) copyright 2008, Technische Universitaet Graz and Technische Universitaet Wien
00003  *
00004  * This file is part of jdiagengine.
00005  *
00006  * jdiagengine is free software: you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation, either version 3 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * jdiagengine is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  * You should have received a copy of the GNU General Public License
00016  * along with jdiagengine. If not, see <http://www.gnu.org/licenses/>.
00017  *
00018  * Authors: Joerg Weber, Franz Wotawa
00019  * Contact: jweber@ist.tugraz.at (preferred), or fwotawa@ist.tugraz.at
00020  *
00021  */
00022 
00023 
00036 package gui;
00037 
00038 import java.lang.*;    // Java language classes 
00039 import java.awt.*;     // User Interface components
00040 import java.io.*;      // IO specific classes (File, Stream,..)
00041 import java.awt.event.*;   // Event handling
00042 
00043 public class InputDialog extends Dialog
00044 {
00045   // Instance variables ...
00046 
00047   protected TextField textHolder;
00048   protected String result = null;
00049 
00050   // Instance creation
00051 
00052   public InputDialog(Frame dw, String label)
00053   {
00054     super(dw, "Dialog", true);
00055 
00056     Panel p1 = new Panel();
00057     p1.add(new Label(label));
00058 
00059     Panel p2 = new Panel();
00060     textHolder = new TextField(label.length());
00061     p2.add(textHolder);
00062 
00063     // Create buttons
00064 
00065     Panel p3 = new Panel();
00066     Button okButton = new Button("Ok");
00067     okButton.addActionListener(new ActionListener()
00068                                { public void actionPerformed(ActionEvent e)
00069                                    { okPressed();}});
00070     Button cancelButton = new Button("Cancel");
00071     cancelButton.addActionListener(new ActionListener()
00072                                    { public void 
00073                                        actionPerformed(ActionEvent e)
00074                                        { cancelPressed();}});
00075     p3.add(okButton);
00076     p3.add(cancelButton);
00077 
00078     add("North",p1);
00079     add("Center",p2);
00080     add("South",p3);
00081 
00082     // Initialize this dialog to its preferred size
00083     pack();
00084     setLocation(defaultLocation());
00085 
00086     /*    textHolder.requestFocus();
00087     textHolder.getCursor();
00088     textHolder.selectAll(); */
00089 
00090   }
00091 
00092   public Point defaultLocation()
00093   {
00094     Point newLoc;
00095     Toolkit tk = Toolkit.getDefaultToolkit();
00096     Dimension screenSize = tk.getScreenSize();
00097     int w = this.getBounds().width;
00098     int h = this.getBounds().height;
00099     if ((w < screenSize.width) && (h < screenSize.height)) {
00100       newLoc = new Point((screenSize.width-w)/2,
00101                   (screenSize.height-h)/2);
00102     } else {
00103       newLoc = new Point(0,0);
00104     }
00105     return newLoc;
00106   }
00107 
00108   // Action handling
00109 
00110   public void okPressed()
00111   {
00112     result = textHolder.getText();
00113     closeDialog();
00114   }
00115 
00116   public void cancelPressed()
00117   {
00118     result = null;
00119     closeDialog();
00120   }
00121 
00122   public void closeDialog()
00123   {
00124     setVisible(false);
00125     dispose();
00126   }
00127 
00128   // Accessing
00129 
00130   public String result()
00131   {
00132     return result;
00133   }
00134 
00135   public void setInitialValue(String txt)
00136   {
00137     textHolder.setText(txt);
00138   }
00139 
00140 }
00141 


tug_ist_diagnosis_engine
Author(s): Safdar Zaman, Gerald Steinbauer
autogenerated on Mon Jan 6 2014 11:51:16