Source Code Cross Referenced for NewAttributePanel.java in  » GIS » openjump » de » fho » jump » pirol » ui » panels » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » GIS » openjump » de.fho.jump.pirol.ui.panels 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Created on 20.06.2005
003:         *
004:         * CVS information:
005:         *  $Author: javamap $
006:         *  $Date: 2007-06-18 21:15:27 -0700 (Mon, 18 Jun 2007) $
007:         *  $ID$
008:         *  $Rev: 856 $
009:         *  $Id: NewAttributePanel.java 856 2007-06-19 04:15:27Z javamap $
010:         *  $Log$
011:         *  Revision 1.2  2007/02/03 14:19:29  mentaer
012:         *  modified debug output for pirol stuff
013:         *
014:         *  Revision 1.1  2006/11/23 18:53:51  mentaer
015:         *  added EditAttributeByFormula Plugin by Pirol including some parts of the baseclasses - note: plugin needs java 1.5
016:         *
017:         *  Revision 1.6  2005/08/23 11:57:17  orahn
018:         *  ... dezimaltrennzeichen in tabellen
019:         *
020:         *  Revision 1.5  2005/08/03 14:33:13  orahn
021:         *  +i18n
022:         *  -warnings
023:         *
024:         *  Revision 1.4  2005/08/03 09:51:10  orahn
025:         *  +i18n
026:         *
027:         *  Revision 1.3  2005/06/29 16:03:11  orahn
028:         *  +default Attribut-Name
029:         *  +Möglichkeit einen Attr. Namen vorzugeben
030:         *
031:         *  Revision 1.2  2005/06/28 15:46:17  orahn
032:         *  einstellbar, ob ein default-Wert für das neue Attribut abgefragt werden soll...
033:         *
034:         *  Revision 1.1  2005/06/20 18:18:23  orahn
035:         *  Vorbereitung für Formeleditor
036:         *
037:         */
038:        package de.fho.jump.pirol.ui.panels;
039:
040:        import java.awt.GridLayout;
041:        import java.awt.event.ActionEvent;
042:        import java.awt.event.ActionListener;
043:
044:        import javax.swing.JComboBox;
045:        import javax.swing.JLabel;
046:        import javax.swing.JPanel;
047:        import javax.swing.JTextField;
048:
049:        import com.vividsolutions.jump.I18N;
050:        import com.vividsolutions.jump.feature.AttributeType;
051:
052:        import de.fho.jump.pirol.utilities.apiTools.FeatureCollectionTools;
053:        import de.fho.jump.pirol.utilities.attributes.AttributeInfo;
054:        import de.fho.jump.pirol.utilities.debugOutput.DebugUserIds;
055:        import de.fho.jump.pirol.utilities.debugOutput.PersonalLogger;
056:
057:        //import de.fho.jump.pirol.utilities.i18n.PirolPlugInMessages;
058:
059:        /**
060:         * 
061:         * A Panel that contains controls to collect all information needed to create
062:         * a new attribute out of.
063:         * The following information will be collected:<br>
064:         * -name of the attribute<br>
065:         * -type of the attribute values<br>
066:         * -Default-value (will initially filled in all features)<br>
067:         *
068:         * @author Ole Rahn
069:         * <br>
070:         * <br>FH Osnabr&uuml;ck - University of Applied Sciences Osnabr&uuml;ck,
071:         * <br>Project: PIROL (2005),
072:         * <br>Subproject: Daten- und Wissensmanagement
073:         * 
074:         * @version $Rev: 856 $
075:         */
076:        public class NewAttributePanel extends JPanel implements  ActionListener {
077:
078:            private static final long serialVersionUID = -2577345752815728142L;
079:
080:            protected JTextField nameTextField = new JTextField();
081:            protected JTextField defValueTextField = new JTextField();
082:            protected JComboBox typeDropDown = new JComboBox();
083:            protected String drownActionCommand = "selectType";
084:            protected AttributeType[] onlyTypes = null;
085:
086:            protected PersonalLogger logger = new PersonalLogger(
087:                    DebugUserIds.ALL);
088:
089:            protected String typeLabelText = I18N
090:                    .get("pirol.ui.panels.type-of-new-attribute");
091:            protected String nameLabelText = I18N
092:                    .get("pirol.ui.panels.name-of-new-attribute");
093:            protected String defValLabelText = I18N
094:                    .get("pirol.ui.panels.default-value-for-new-attribute");
095:
096:            protected JLabel nameLabel = new JLabel();
097:            protected JLabel defValLabel = new JLabel();
098:            protected JLabel typeLabel = new JLabel();
099:
100:            protected boolean needDefaultValue = true;
101:
102:            /**
103:             * @param arg0 see JPanel for information
104:             * @param needDefaultValue a field for a default value will be shown or not
105:             */
106:            public NewAttributePanel(boolean arg0, boolean needDefaultValue) {
107:                super (arg0);
108:
109:                this .typeDropDown.setActionCommand(this .drownActionCommand);
110:                this .typeDropDown.addItem(AttributeType.DOUBLE);
111:                this .typeDropDown.addItem(AttributeType.INTEGER);
112:                this .typeDropDown.addItem(AttributeType.STRING);
113:                this .typeDropDown.setSelectedIndex(0);
114:                this .typeDropDown.addActionListener(this );
115:
116:                this .needDefaultValue = needDefaultValue;
117:
118:                this .setupUI();
119:            }
120:
121:            /**
122:             * @param arg0 see JPanel for information
123:             * @param onlyTypes array of attribute type, that are supposed to be chooseable
124:             * @param needDefaultValue a field for a default value will be shown or not
125:             */
126:            public NewAttributePanel(boolean arg0, AttributeType[] onlyTypes,
127:                    boolean needDefaultValue) {
128:                super (arg0);
129:
130:                this .onlyTypes = onlyTypes;
131:
132:                this .typeDropDown.setActionCommand(this .drownActionCommand);
133:                for (int i = 0; i < this .onlyTypes.length; i++) {
134:                    this .typeDropDown.addItem(this .onlyTypes[i]);
135:                }
136:                this .typeDropDown.setSelectedIndex(0);
137:                this .typeDropDown.addActionListener(this );
138:
139:                this .needDefaultValue = needDefaultValue;
140:
141:                this .setupUI();
142:            }
143:
144:            /**
145:             * Sets up GUI controlls.
146:             *
147:             */
148:            protected void setupUI() {
149:                this .setLayout(new GridLayout((this .needDefaultValue) ? 3 : 2,
150:                        2));
151:
152:                this .nameLabel = new JLabel(this .nameLabelText);
153:                this .add(this .nameLabel);
154:                this .add(this .nameTextField);
155:
156:                this .typeLabel = new JLabel(this .typeLabelText);
157:                this .add(this .typeLabel);
158:                this .add(this .typeDropDown);
159:
160:                if (this .needDefaultValue) {
161:                    this .defValLabel = new JLabel(this .defValLabelText);
162:                    this .add(this .defValLabel);
163:                    this .add(this .defValueTextField);
164:                }
165:            }
166:
167:            /**
168:             * Sets the text that will be displayed in the text field for the new attribute's name.
169:             *@param attrName  text that will be displayed in the name text field
170:             */
171:            public void setAttributeName(String attrName) {
172:                nameTextField.setText(attrName);
173:            }
174:
175:            /**
176:             * Returns the collected information on the new attribute. Since this method calls
177:             * getDefaultValue(), it may throw the same Exception...
178:             * @return the collected information
179:             */
180:            public AttributeInfo getAttributeInfo() {
181:
182:                String newAttrName = this .nameTextField.getText();
183:
184:                if (newAttrName == null || newAttrName.length() == 0)
185:                    newAttrName = "NEW_ATTRIBUTE";
186:
187:                AttributeInfo attrInfo = new AttributeInfo(
188:                        (AttributeType) this .typeDropDown.getSelectedItem(),
189:                        newAttrName);
190:
191:                if (this .needDefaultValue)
192:                    attrInfo.setNullValue(this .getDefaultValue());
193:
194:                return attrInfo;
195:            }
196:
197:            /**
198:             * checks and fixes the integrity of the values given, when the attribute
199:             * type is changed.
200:             * @param event the action event
201:             */
202:            public void actionPerformed(ActionEvent event) {
203:                if (JComboBox.class.isInstance(event.getSource())) {
204:                    if (this .needDefaultValue
205:                            && FeatureCollectionTools
206:                                    .isAttributeTypeNumeric((AttributeType) this .typeDropDown
207:                                            .getSelectedItem())) {
208:                        AttributeType at = (AttributeType) this .typeDropDown
209:                                .getSelectedItem();
210:
211:                        if (at.equals(AttributeType.INTEGER)) {
212:                            try {
213:                                Integer.parseInt(this .defValueTextField
214:                                        .getText());
215:                            } catch (Exception e) {
216:                                this .defValueTextField.setText("0");
217:                            }
218:                        } else {
219:                            try {
220:                                Double.parseDouble(this .defValueTextField
221:                                        .getText());
222:                            } catch (Exception e) {
223:                                this .defValueTextField.setText("0.0");
224:                            }
225:                        }
226:                    }
227:                }
228:
229:            }
230:
231:            /**
232:             * This allows you to check, if the data filled in by the user makes sense or not.
233:             * You may want enable/disable the ok-button, depending on the return value of this
234:             * function.
235:             * @return true if values are ok, else false
236:             */
237:            public boolean isDataValid() {
238:                boolean dataValid = true;
239:
240:                if (this .needDefaultValue) {
241:                    try {
242:                        this .getDefaultValue();
243:                    } catch (Exception e) {
244:                        dataValid = false;
245:                    }
246:                }
247:
248:                if (this .nameTextField.getText() == null
249:                        || this .nameTextField.getText().length() == 0)
250:                    dataValid = false;
251:
252:                return dataValid;
253:
254:            }
255:
256:            /**
257:             * Returns the default value for the attribute we want to create. This function may throw
258:             * a RuntimeException, if the value filled in for the default value can not be parsed!
259:             * @return default value
260:             */
261:            protected Object getDefaultValue() {
262:                if (FeatureCollectionTools
263:                        .isAttributeTypeNumeric((AttributeType) this .typeDropDown
264:                                .getSelectedItem())) {
265:                    AttributeType at = (AttributeType) this .typeDropDown
266:                            .getSelectedItem();
267:
268:                    if (at.equals(AttributeType.INTEGER)) {
269:                        int i = Integer.parseInt(this .defValueTextField
270:                                .getText());
271:                        return new Integer(i);
272:                    }
273:                    double d = Double.parseDouble(this .defValueTextField
274:                            .getText());
275:                    return new Double(d);
276:                }
277:                return this .defValueTextField.getText();
278:            }
279:
280:            public void addActionListenerToDefValueTextfield(ActionListener arg0) {
281:                defValueTextField.addActionListener(arg0);
282:            }
283:
284:            public void addActionListenerToNameTextfield(ActionListener arg0) {
285:                this .nameTextField.addActionListener(arg0);
286:            }
287:
288:            public void addActionListenerToTypeDropDown(ActionListener arg0) {
289:                this .typeDropDown.addActionListener(arg0);
290:            }
291:
292:            /**
293:             * Sets the label text for the default value field
294:             * @param defValLabel The defValLabel to set.
295:             */
296:            public void setDefValLabel(String defValLabel) {
297:                this .defValLabelText = defValLabel;
298:                this .defValLabel.setText(this .defValLabelText);
299:            }
300:
301:            /**
302:             * Sets the label text for the name field
303:             * @param nameLabel The nameLabel to set.
304:             */
305:            public void setNameLabel(String nameLabel) {
306:                this .nameLabelText = nameLabel;
307:                this .nameLabel.setText(this .nameLabelText);
308:            }
309:
310:            /**
311:             * Sets the label text for the type field
312:             * @param typeLabel The typeLabel to set.
313:             */
314:            public void setTypeLabel(String typeLabel) {
315:                this.typeLabelText = typeLabel;
316:                this.typeLabel.setText(this.typeLabelText);
317:            }
318:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.