NumberDialog.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 
00032 package gui;
00033 
00034 import java.lang.*;    // Java language classes 
00035 import java.awt.*;     // User Interface components
00036 import java.io.*;      // IO specific classes (File, Stream,..)
00037 import java.awt.event.*;   // Event handling
00038 import java.util.*;
00039 
00040 public class NumberDialog extends InputDialog
00041 {
00042   // Instance variables ...
00043 
00044   protected boolean integer = false;
00045 
00046   // Instance creation
00047 
00048   public NumberDialog(Frame dw, String label)
00049   {
00050     super(dw,label);
00051   }
00052 
00053   // Action handling
00054 
00055 
00056   public void okPressed()
00057   {
00058     result = textHolder.getText();
00059 
00060     if (integer) {
00061       Integer i;
00062       try {
00063         i = new Integer(result);
00064       } catch (Exception e) {
00065         return;
00066       }
00067       result = i.toString();
00068     } else {
00069       Double d;
00070       try {
00071         d = Double.valueOf(result);
00072       } catch (Exception e) {
00073         return;
00074       }
00075       result = d.toString();
00076     }
00077     closeDialog();
00078   }
00079 
00080   public void cancelPressed()
00081   {
00082     result = null;
00083     closeDialog();
00084   }
00085 
00086   public void closeDialog()
00087   {
00088     setVisible(false);
00089     dispose();
00090   }
00091 
00092   // Accessing
00093 
00094   public void integer(boolean b)
00095   {
00096     integer = b;
00097   }
00098 
00099   public Number resultAsNumber() {
00100     if (result != null) {
00101       if (integer) {
00102         Integer i;
00103         try {
00104           i = new Integer(result);
00105         } catch (Exception e) {
00106           return null;
00107         }
00108         return i;
00109       } else {
00110         Double d;
00111         try {
00112           d = Double.valueOf(result);
00113         } catch (Exception e) {
00114           return null;
00115         }
00116         return d;
00117       }    
00118     }
00119     return null;
00120   }
00121 }
00122 


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