Line | Hits | Source |
---|---|---|
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 | ||
58 | 0 | public 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 | ||
76 | 1 | public Action okButtonAction = new AbstractAction() { |
77 | ||
78 | public void actionPerformed(ActionEvent event) { | |
79 | ||
80 | okButtonPressed(); | |
81 | ||
82 | } | |
83 | ||
84 | }; | |
85 | ||
86 | 1 | 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"; | |
96 | 1 | public DemetrixPropertyCreationDialog(Hashtable forbiddenPropertyNames) { |
97 | 1 | this.forbiddenPropertyNames = forbiddenPropertyNames; |
98 | ||
99 | try { | |
100 | ||
101 | 1 | this.dialog = |
102 | (JDialog) (new SwingEngine(this)).render( | |
103 | ClassLoader.getSystemClassLoader().getResource(UI_DEF_FILE_NAME)); | |
104 | ||
105 | 1 | this.dialog.pack(); |
106 | ||
107 | 0 | } catch (Exception exception) { |
108 | ||
109 | this.logger.error("", exception); | |
110 | ||
111 | 1 | } |
112 | ||
113 | 1 | this.setClosedWithOk(false); |
114 | ||
115 | 1 | } |
116 | ||
117 | private void okButtonPressed() { | |
118 | ||
119 | 0 | if (propertyNameTextField.getText().trim().length() < 1) { |
120 | ||
121 | 0 | 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 | ||
127 | 0 | } else if ( |
128 | this.forbiddenPropertyNames.containsKey( | |
129 | propertyNameTextField.getText().trim())) { | |
130 | ||
131 | 0 | 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 | ||
139 | 0 | this.setClosedWithOk(true); |
140 | ||
141 | 0 | this.dialog.hide(); |
142 | ||
143 | } | |
144 | ||
145 | 0 | } |
146 | ||
147 | public void show() { | |
148 | ||
149 | 0 | this.dialog.show(); |
150 | ||
151 | 0 | } |
152 | ||
153 | private void cancelButtonPressed() { | |
154 | ||
155 | 0 | this.setClosedWithOk(false); |
156 | ||
157 | 0 | this.dialog.hide(); |
158 | ||
159 | 0 | } |
160 | ||
161 | public boolean isClosedWithOk() { | |
162 | ||
163 | 0 | return this.closedWithOk; |
164 | ||
165 | } | |
166 | ||
167 | public void setClosedWithOk(boolean newValue) { | |
168 | ||
169 | 1 | this.closedWithOk = newValue; |
170 | ||
171 | 1 | } |
172 | ||
173 | public String getPropertyName() { | |
174 | ||
175 | 0 | return this.propertyNameTextField.getText(); |
176 | ||
177 | } | |
178 | ||
179 | public DemetrixProperty getProperty() { | |
180 | ||
181 | 0 | if (this.doublePropertyRadioButton.isSelected()) { |
182 | ||
183 | 0 | return new DoubleProperty(); |
184 | ||
185 | 0 | } else if (this.booleanPropertyRadioButton.isSelected()) { |
186 | ||
187 | 0 | return new BooleanProperty(); |
188 | ||
189 | 0 | } else if (this.stringPropertyRadioButton.isSelected()) { |
190 | ||
191 | 0 | return new StringProperty(); |
192 | ||
193 | } | |
194 | ||
195 | 0 | return null; |
196 | ||
197 | } | |
198 | ||
199 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |