Source Code Cross Referenced for PropertiesDialog.java in  » J2EE » Sofia » com » salmonllc » ideTools » 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 » J2EE » Sofia » com.salmonllc.ideTools 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        //** Copyright Statement ***************************************************
002:        //The Salmon Open Framework for Internet Applications (SOFIA)
003:        // Copyright (C) 1999 - 2002, Salmon LLC
004:        //
005:        // This program is free software; you can redistribute it and/or
006:        // modify it under the terms of the GNU General Public License version 2
007:        // as published by the Free Software Foundation;
008:        //
009:        // This program is distributed in the hope that it will be useful,
010:        // but WITHOUT ANY WARRANTY; without even the implied warranty of
011:        // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012:        // GNU General Public License for more details.
013:        //
014:        // You should have received a copy of the GNU General Public License
015:        // along with this program; if not, write to the Free Software
016:        // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
017:        //
018:        // For more information please visit http://www.salmonllc.com
019:        //** End Copyright Statement ***************************************************
020:        package com.salmonllc.ideTools;
021:
022:        /////////////////////////
023:        //$Archive: /SOFIA/SourceCode/com/salmonllc/ideTools/PropertiesDialog.java $
024:        //$Author: Dan $
025:        //$Revision: 18 $
026:        //$Modtime: 9/24/04 1:04p $
027:        /////////////////////////
028:
029:        import java.awt.*;
030:        import java.awt.event.*;
031:        import java.io.File;
032:        import java.util.*;
033:
034:        import javax.swing.*;
035:
036:        import com.salmonllc.properties.Props;
037:
038:        public class PropertiesDialog extends JDialog implements 
039:                ActionListener, WindowListener {
040:
041:            boolean _cancelClicked = true;
042:            JButton _save;
043:            JButton _cancel;
044:            JFrame _owner;
045:            Props _props;
046:            int _fieldIndex = 0;
047:            int _noFields = 17;
048:            Field _fields[];
049:            Box _mainGrid;
050:            Hashtable _changedValues = new Hashtable();
051:
052:            public static final int TYPE_TEXT = 0;
053:            public static final int TYPE_PW = 1;
054:            public static final int TYPE_FILE = 2;
055:            public static final int TYPE_DIR = 3;
056:            public static final int TYPE_DD = 4;
057:            public static final int TYPE_TF = 5;
058:
059:            private class Field {
060:                public JLabel caption;
061:                public JComponent field;
062:                public String property;
063:                public JComponent lookup;
064:                public int type;
065:            }
066:
067:            public PropertiesDialog(JFrame owner, Props p) {
068:                super (owner, "Set Properties", true);
069:                _owner = owner;
070:                _props = p;
071:
072:                if (IDETool.getProject() != null)
073:                    setTitle("Set Properties (Project:" + IDETool.getProject()
074:                            + ")");
075:
076:                Vector browserProps = new Vector();
077:                Enumeration en = p.getKeys();
078:                while (en.hasMoreElements()) {
079:                    String key = (String) en.nextElement();
080:                    if (key.startsWith(Props.IDE_BROWSER_PATH + ".")) {
081:                        browserProps.add(key);
082:                        _noFields++;
083:                    }
084:                }
085:
086:                int width = 600;
087:                int height = 516 + (28 * browserProps.size());
088:                Dimension frameBounds = Toolkit.getDefaultToolkit()
089:                        .getScreenSize();
090:                int x = (frameBounds.width - width) / 2;
091:                int y = (frameBounds.height - height) / 2;
092:                setBounds(x, y, width, height);
093:
094:                _fields = new Field[_noFields];
095:                _mainGrid = Box.createVerticalBox();
096:
097:                addFieldToGrid(IDETool.getProjectProperty(Props.IDE_WEB_APP),
098:                        "Default Web Application", TYPE_TEXT);
099:                addFieldToGrid(IDETool
100:                        .getProjectProperty(Props.IDE_DEFAULT_FRAMEWORK_APP),
101:                        "Default Framework Application", TYPE_TEXT);
102:                addFieldToGrid(IDETool
103:                        .getProjectProperty(Props.IDE_DEFAULT_RUN_URL),
104:                        "Default URL or JSP to Run", TYPE_FILE);
105:                addFieldToGrid(Props.IDE_USE_APP_PROPERTIES,
106:                        "Use Prop Files from Application", TYPE_TF);
107:                addFieldToGrid(IDETool
108:                        .getProjectProperty(Props.IDE_APP_PROPS_PATH),
109:                        "Properties File Path", TYPE_DIR);
110:
111:                addFieldToGrid(Props.IDE_SERVER_TYPE, "Server Type", TYPE_DD);
112:                addFieldToGrid(Props.IDE_DEFAULT_HOST, "Test Server Host:Port",
113:                        TYPE_TEXT);
114:
115:                addFieldToGrid(Props.IDE_BROWSER_PATH, "Default Browser Path",
116:                        TYPE_FILE);
117:                for (int i = 0; i < browserProps.size(); i++) {
118:                    String key = (String) browserProps.elementAt(i);
119:                    String label = key.substring(Props.IDE_BROWSER_PATH
120:                            .length() + 1)
121:                            + " Browser Path";
122:                    addFieldToGrid(key, label, TYPE_FILE);
123:                }
124:                addFieldToGrid(Props.IDE_DREAMWEAVER_PATH, "Dreamweaver Path",
125:                        TYPE_FILE);
126:                addFieldToGrid(IDETool
127:                        .getProjectProperty(Props.IDE_DEFAULT_SOURCE_PATH),
128:                        "Source Code Path", TYPE_DIR);
129:                addFieldToGrid(Props.IDE_FRAMEWORK_RESOURCES_PATH,
130:                        "Resources Path", TYPE_DIR);
131:                addFieldToGrid(Props.IDE_FRAMEWORK_SOURCE_PATH,
132:                        "Framework Source Path", TYPE_DIR);
133:                addFieldToGrid(Props.IDE_INTELLIJ_PATH, "IntelliJ Path",
134:                        TYPE_DIR);
135:                addFieldToGrid(Props.IDE_TOMCAT_PATH, "Tomcat Path", TYPE_DIR);
136:                addFieldToGrid(Props.IDE_TOMCAT_MANAGER_APP,
137:                        "Tomcat Manager Web App", TYPE_TEXT);
138:                addFieldToGrid(Props.IDE_SERVER_MANAGER_ID,
139:                        "Tomcat Manager User ID", TYPE_TEXT);
140:                addFieldToGrid(Props.IDE_SERVER_MANAGER_PW,
141:                        "Tomcat Manager Password", TYPE_PW);
142:
143:                _save = new JButton("Save");
144:                _save.addActionListener(this );
145:                _cancel = new JButton("Cancel");
146:                _cancel.addActionListener(this );
147:                JPanel buttonBar = new JPanel(new FlowLayout());
148:                buttonBar.add(_save);
149:                buttonBar.add(_cancel);
150:                buttonBar.setAlignmentX(Component.CENTER_ALIGNMENT);
151:                Box box = Box.createVerticalBox();
152:
153:                box.add(Box.createRigidArea(new Dimension(100, 10)));
154:                box.add(_mainGrid);
155:                box.add(Box.createRigidArea(new Dimension(100, 5)));
156:                box.add(buttonBar);
157:
158:                getContentPane().add(box);
159:
160:                addWindowListener(this );
161:                setVisible(true);
162:            }
163:
164:            public void actionPerformed(ActionEvent e) {
165:                if (e.getSource() == _cancel) {
166:                    _cancelClicked = true;
167:                    setVisible(false);
168:                } else if (e.getSource() == _save) {
169:                    for (int i = 0; i < _noFields; i++) {
170:                        Field f = _fields[i];
171:                        String origProp = _props.getProperty(f.property);
172:                        String currentProp = null;
173:                        if (f.field instanceof  JTextField)
174:                            currentProp = ((JTextField) f.field).getText();
175:                        else if (f.field instanceof  JComboBox)
176:                            currentProp = (String) ((JComboBox) f.field)
177:                                    .getSelectedItem();
178:                        if (currentProp != null
179:                                && currentProp.trim().length() == 0)
180:                            currentProp = null;
181:                        if (!equals(origProp, currentProp)) {
182:                            if (currentProp == null)
183:                                currentProp = "";
184:                            _changedValues.put(f.property, currentProp);
185:                        }
186:                    }
187:                    _cancelClicked = false;
188:                    setVisible(false);
189:                } else {
190:                    Field f = null;
191:                    for (int i = 0; i < _noFields; i++) {
192:                        if (_fields[i].lookup != null
193:                                && _fields[i].lookup == e.getSource()) {
194:                            f = _fields[i];
195:                            break;
196:                        }
197:                    }
198:                    if (f != null) {
199:                        String fileName = ((JTextField) f.field).getText();
200:                        JFileChooser c = new JFileChooser();
201:                        if (f.type == TYPE_FILE)
202:                            c.setFileSelectionMode(JFileChooser.FILES_ONLY);
203:                        else
204:                            c
205:                                    .setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
206:                        c.setCurrentDirectory(new File(fileName));
207:                        if (c.showOpenDialog(this ) == JFileChooser.APPROVE_OPTION)
208:                            ((JTextField) f.field).setText(c.getSelectedFile()
209:                                    .getAbsolutePath());
210:                    }
211:                }
212:            }
213:
214:            private void addFieldToGrid(String property, String label, int type) {
215:                Field f = new Field();
216:                f.property = property;
217:                Dimension capSize = new Dimension(180, 25);
218:                Dimension fieldSize = new Dimension(350, 25);
219:                Dimension buttonSize = new Dimension(30, 25);
220:                Dimension lookupSize = new Dimension(320, 25);
221:
222:                f.caption = DialogComponentFactory.makeLabel(label + ":");
223:                f.caption.setMaximumSize(capSize);
224:                f.caption.setMinimumSize(capSize);
225:                f.type = type;
226:                Box b = Box.createHorizontalBox();
227:                b.add(f.caption);
228:
229:                if (type == TYPE_TEXT) {
230:                    f.field = new JTextField(_props.getProperty(property));
231:                    f.field.setMaximumSize(fieldSize);
232:                    f.field.setMinimumSize(fieldSize);
233:                    b.add(f.field);
234:                    _mainGrid.add(b);
235:                    _mainGrid.add(Box.createRigidArea(new Dimension(255, 3)));
236:                } else if (type == TYPE_PW) {
237:                    f.field = new JPasswordField(_props.getProperty(property));
238:                    f.field.setMaximumSize(fieldSize);
239:                    f.field.setMinimumSize(fieldSize);
240:                    b.add(f.field);
241:                    _mainGrid.add(b);
242:                    _mainGrid.add(Box.createRigidArea(new Dimension(255, 3)));
243:                } else if (type == TYPE_FILE || type == TYPE_DIR) {
244:                    f.field = new JTextField(_props.getProperty(property));
245:                    f.field.setMaximumSize(lookupSize);
246:                    f.field.setMinimumSize(lookupSize);
247:
248:                    JButton btn = new JButton("..");
249:                    btn.addActionListener(this );
250:                    btn.setMaximumSize(buttonSize);
251:                    btn.setMinimumSize(buttonSize);
252:                    f.lookup = btn;
253:                    b.add(f.field);
254:                    b.add(f.lookup);
255:                    _mainGrid.add(b);
256:                } else if (type == TYPE_DD && property == Props.IDE_SERVER_TYPE) {
257:                    String items[] = { IDETool.SERVER_TOMCAT40,
258:                            IDETool.SERVER_TOMCAT41, IDETool.SERVER_TOMCAT50 };
259:                    JComboBox box = new JComboBox(items);
260:                    String prop = _props.getProperty(property);
261:                    if (prop != null)
262:                        box.setSelectedItem(prop);
263:                    f.field = box;
264:                    f.field.setMaximumSize(fieldSize);
265:                    f.field.setMinimumSize(fieldSize);
266:                    b.add(f.field);
267:                    _mainGrid.add(b);
268:                    _mainGrid.add(Box.createRigidArea(new Dimension(255, 3)));
269:                } else if (type == TYPE_TF) {
270:                    String items[] = { "false", "true" };
271:                    JComboBox box = new JComboBox(items);
272:                    String prop = _props.getProperty(property);
273:                    if (prop != null)
274:                        box.setSelectedItem(prop);
275:                    f.field = box;
276:                    f.field.setMaximumSize(fieldSize);
277:                    f.field.setMinimumSize(fieldSize);
278:                    b.add(f.field);
279:                    _mainGrid.add(b);
280:                    _mainGrid.add(Box.createRigidArea(new Dimension(255, 3)));
281:                }
282:
283:                _fields[_fieldIndex++] = f;
284:            }
285:
286:            private boolean equals(String val1, String val2) {
287:                if (val1 == null && val2 == null)
288:                    return true;
289:                else if (val1 == null && val2 != null)
290:                    return false;
291:                else if (val2 == null && val1 != null)
292:                    return false;
293:                else
294:                    return val1.equals(val2);
295:            }
296:
297:            /**
298:             * Returns true if the user clicked the cancel button to exit the dialog
299:             */
300:            public boolean getCancel() {
301:                return _cancelClicked;
302:            }
303:
304:            /**
305:             * Returns a Hashtable of items changed by the user
306:             */
307:            public Hashtable getChangedValues() {
308:                return _changedValues;
309:            }
310:
311:            public void windowActivated(WindowEvent e) {
312:
313:            }
314:
315:            public void windowClosed(WindowEvent e) {
316:            }
317:
318:            public void windowClosing(WindowEvent e) {
319:            }
320:
321:            public void windowDeactivated(WindowEvent e) {
322:            }
323:
324:            public void windowDeiconified(WindowEvent e) {
325:            }
326:
327:            public void windowIconified(WindowEvent e) {
328:            }
329:
330:            public void windowOpened(WindowEvent e) {
331:            }
332:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.