Coverage details for net.sourceforge.demetrix.properties.DemetrixPropertyCreationDialog

LineHitsSource
1 /*******************************************************************************
2  * Demetrix process modelling system
3  *
4  * Copyright (c) 2003, 2004 Dimitri A. Pissarenko
5  *
6  * This file is part of Demetrix.
7  *
8  * Demetrix is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2.1 of the License, or
11  * (at your option) any later version.
12  *
13  * Demetrix is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with Demetrix; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21  *
22  * For further information you may
23  *
24  * - send an e-mail in Russian, German or English to dimitri.pissarenko@gmx.net
25  * - look at http://sourceforge.net/projects/demetrix/
26  * - look at http://demetrix.sourceforge.net/
27  * - look at http://members.inode.at/d.pissarenko/
28  *
29  *****************************************************************************/
30  
31 package net.sourceforge.demetrix.properties;
32  
33 import java.awt.event.ActionEvent;
34  
35 import java.util.Hashtable;
36  
37 import javax.swing.AbstractAction;
38  
39 import javax.swing.Action;
40  
41 import javax.swing.JDialog;
42  
43 import javax.swing.JOptionPane;
44  
45 import javax.swing.JRadioButton;
46  
47 import javax.swing.JTextField;
48  
49 import org.apache.log4j.Logger;
50  
51 import org.swixml.SwingEngine;
52  
53 /**
54  * @author Dimitri Pissarenko
55  *
56  */
57  
580public class DemetrixPropertyCreationDialog {
59  
60     private Logger logger = Logger.getLogger(getClass());
61  
62     private JDialog dialog;
63  
64     private boolean closedWithOk;
65  
66     private Hashtable forbiddenPropertyNames;
67  
68     public JTextField propertyNameTextField;
69  
70     public JRadioButton doublePropertyRadioButton;
71  
72     public JRadioButton stringPropertyRadioButton;
73  
74     public JRadioButton booleanPropertyRadioButton;
75  
761    public Action okButtonAction = new AbstractAction() {
77  
78         public void actionPerformed(ActionEvent event) {
79  
80             okButtonPressed();
81  
82         }
83  
84     };
85  
861    public Action cancelButtonAction = new AbstractAction() {
87  
88         public void actionPerformed(ActionEvent event) {
89  
90             cancelButtonPressed();
91  
92         }
93  
94     };
95     public final static String UI_DEF_FILE_NAME="net/sourceforge/demetrix/properties/DemetrixPropertyCreationDialog.xml";
961    public DemetrixPropertyCreationDialog(Hashtable forbiddenPropertyNames) {
971        this.forbiddenPropertyNames = forbiddenPropertyNames;
98  
99         try {
100  
1011            this.dialog =
102                 (JDialog) (new SwingEngine(this)).render(
103             ClassLoader.getSystemClassLoader().getResource(UI_DEF_FILE_NAME));
104  
1051            this.dialog.pack();
106  
1070        } catch (Exception exception) {
108  
109             this.logger.error("", exception);
110  
1111        }
112  
1131        this.setClosedWithOk(false);
114  
1151    }
116  
117     private void okButtonPressed() {
118  
1190        if (propertyNameTextField.getText().trim().length() < 1) {
120  
1210            JOptionPane.showMessageDialog(
122                 this.dialog,
123                 "Please enter the property name (it must not be empty).",
124                 this.dialog.getTitle(),
125                 JOptionPane.ERROR_MESSAGE);
126  
1270        } else if (
128             this.forbiddenPropertyNames.containsKey(
129                 propertyNameTextField.getText().trim())) {
130  
1310            JOptionPane.showMessageDialog(
132                 this.dialog,
133                 "Invalid name, there is already a property with this name in the selected object. Please enter another property name.",
134                 this.dialog.getTitle(),
135                 JOptionPane.ERROR_MESSAGE);
136  
137         } else {
138  
1390            this.setClosedWithOk(true);
140  
1410            this.dialog.hide();
142  
143         }
144  
1450    }
146  
147     public void show() {
148  
1490        this.dialog.show();
150  
1510    }
152  
153     private void cancelButtonPressed() {
154  
1550        this.setClosedWithOk(false);
156  
1570        this.dialog.hide();
158  
1590    }
160  
161     public boolean isClosedWithOk() {
162  
1630        return this.closedWithOk;
164  
165     }
166  
167     public void setClosedWithOk(boolean newValue) {
168  
1691        this.closedWithOk = newValue;
170  
1711    }
172  
173     public String getPropertyName() {
174  
1750        return this.propertyNameTextField.getText();
176  
177     }
178  
179     public DemetrixProperty getProperty() {
180  
1810        if (this.doublePropertyRadioButton.isSelected()) {
182  
1830            return new DoubleProperty();
184  
1850        } else if (this.booleanPropertyRadioButton.isSelected()) {
186  
1870            return new BooleanProperty();
188  
1890        } else if (this.stringPropertyRadioButton.isSelected()) {
190  
1910            return new StringProperty();
192  
193         }
194  
1950        return null;
196  
197     }
198  
199 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.