Source Code Cross Referenced for InputBox.java in  » Source-Control » sourcejammer » org » sourcejammer » client » gui » dialog » 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 » Source Control » sourcejammer » org.sourcejammer.client.gui.dialog 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Copyright (C) 2003 Robert MacGrogan
003:         *
004:         *  This library is free software; you can redistribute it and/or
005:         *  modify it under the terms of the GNU Lesser General Public
006:         *  License as published by the Free Software Foundation; either
007:         *  version 2.1 of the License, or (at your option) any later version.
008:         *
009:         *  This library 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 GNU
012:         *  Lesser General Public License for more details.
013:         *
014:         *  You should have received a copy of the GNU Lesser General Public
015:         *  License along with this library; if not, write to the Free Software
016:         *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017:         *
018:         *
019:         * $Archive: SourceJammer$
020:         * $FileName: InputBox.java$
021:         * $FileID: 4806$
022:         *
023:         * Last change:
024:         * $AuthorName: Rob MacGrogan$
025:         * $Date: 9/1/03 9:27 PM$
026:         * $Comment: Debug.$
027:         */
028:        package org.sourcejammer.client.gui.dialog;
029:
030:        import java.awt.BorderLayout;
031:        import java.awt.Component;
032:        import java.awt.Container;
033:        import java.awt.Dialog;
034:        import java.awt.Frame;
035:        import java.awt.GridLayout;
036:        import java.awt.event.ActionEvent;
037:        import java.awt.event.ActionListener;
038:
039:        import javax.swing.BorderFactory;
040:        import javax.swing.JButton;
041:        import javax.swing.JCheckBox;
042:        import javax.swing.JLabel;
043:        import javax.swing.JPanel;
044:        import javax.swing.JPasswordField;
045:        import javax.swing.JTextField;
046:
047:        import org.sourcejammer.client.DisplayTextLibrary;
048:        import org.sourcejammer.client.gui.CommandCentral;
049:        import org.sourcejammer.util.BadMethodArgumentException;
050:        import org.sourcejammer.util.EnumeratedType;
051:
052:        /**
053:         * Title:        $FileName: InputBox.java$
054:         * @author $AuthorName: Rob MacGrogan$
055:         * @version $VerNum: 2$<br><br>
056:         * 
057:         * $Description: Easily generates a small dialog containing
058:         *              input fields (text box, password, or checkbox).$
059:         * $KeyWordsOff: $<br><br>
060:         */
061:        public class InputBox {
062:
063:            private SJDialog inputDialog = null;
064:            private JPanel inputPanel = null;
065:
066:            private String[] inputLabels = null;
067:            private String[] defaultValues = null;
068:            private String title = null;
069:            private boolean modal = true;
070:            private String okButtonText = null;
071:            private FieldType[] fieldTypes = null;
072:
073:            private boolean showDefaults = false;
074:            private boolean useFieldTypes = false;
075:            private String[] inputValues = null;
076:
077:            public static final class FieldType extends EnumeratedType {
078:                public FieldType(String value) {
079:                    setValue(value);
080:                }
081:
082:                public static final FieldType TEXT = new FieldType("text");
083:                public static final FieldType PASSWORD = new FieldType(
084:                        "password");
085:                public static final FieldType CHECKBOX = new FieldType(
086:                        "checkbox");
087:            }
088:
089:            public InputBox() {
090:            }
091:
092:            public void showInputBox() {
093:                showInputBox(CommandCentral.getInstance().getRootAppFrame());
094:            }
095:
096:            public void showInputBox(Frame f) {
097:                validate();
098:                inputDialog = new SJDialog(f, title, modal);
099:                buildInputBox(f);
100:            }
101:
102:            public void showInputBox(Dialog d) {
103:                validate();
104:                inputDialog = new SJDialog(d, title, modal);
105:                buildInputBox(d);
106:            }
107:
108:            private JButton buildOKButton(String okButtonText) {
109:                JButton jbOKButton = new JButton(okButtonText);
110:                jbOKButton.addActionListener(new ActionListener() {
111:                    public void actionPerformed(ActionEvent ev) {
112:                        Component[] components = inputPanel.getComponents();
113:                        int iValueCounter = 0;
114:                        inputValues = new String[components.length];
115:                        for (int i = 0; i < components.length; i++) {
116:                            if (components[i] instanceof  JTextField) {
117:                                JTextField fld = (JTextField) components[i];
118:                                inputValues[iValueCounter] = fld.getText();
119:                                iValueCounter++;
120:                            } else if (components[i] instanceof  JCheckBox) {
121:                                JCheckBox chk = (JCheckBox) components[i];
122:                                boolean checked = chk.isSelected();
123:                                inputValues[iValueCounter] = Boolean
124:                                        .toString(checked);
125:                                iValueCounter++;
126:                            }
127:                        }
128:                        inputDialog.dispose();
129:                    }
130:                } //end anon class
131:                        );
132:                jbOKButton.setDefaultCapable(true);
133:                return jbOKButton;
134:            }
135:
136:            private JButton buildCancelButton() {
137:                JButton jbCancelButton = new JButton(DisplayTextLibrary
138:                        .displayText(DisplayTextLibrary.BTN_CANCEL));
139:                jbCancelButton.addActionListener(new ActionListener() {
140:                    public void actionPerformed(ActionEvent ev) {
141:                        inputValues = null;
142:                        inputDialog.dispose();
143:                    }
144:                } //end anon class
145:                        );
146:                return jbCancelButton;
147:            }
148:
149:            private void buildInputBox(Component c) {
150:                CommandCentral oCommand = CommandCentral.getInstance();
151:
152:                if (okButtonText == null) {
153:                    okButtonText = DisplayTextLibrary
154:                            .displayText(DisplayTextLibrary.BTN_OK);
155:                }
156:
157:                JButton okButton = buildOKButton(okButtonText);
158:
159:                JButton cancelButton = buildCancelButton();
160:
161:                JPanel buttonPanel = new JPanel();
162:                buttonPanel.add(okButton);
163:                buttonPanel.add(cancelButton);
164:
165:                int iNumInputs = inputLabels.length;
166:                inputPanel = new JPanel(new GridLayout(iNumInputs, 1));
167:                JPanel labelPanel = new JPanel(new GridLayout(iNumInputs, 1));
168:
169:                for (int i = 0; i < iNumInputs; i++) {
170:                    Component inputComponent = null;
171:                    if (useFieldTypes && fieldTypes[i] == FieldType.PASSWORD) {
172:                        labelPanel.add(new JLabel(inputLabels[i] + ": ",
173:                                JLabel.RIGHT));
174:                        JPasswordField fld = new JPasswordField();
175:                        if (showDefaults) {
176:                            fld.setText(defaultValues[i]);
177:                        }
178:                        inputPanel.add(fld);
179:                        inputComponent = fld;
180:                    } else if (useFieldTypes
181:                            && fieldTypes[i] == FieldType.CHECKBOX) {
182:                        JCheckBox chk = new JCheckBox(inputLabels[i]);
183:                        if (showDefaults) {
184:                            String defaultVal = defaultValues[i];
185:                            if (defaultVal.equals("1")
186:                                    || defaultVal.equalsIgnoreCase("true")) {
187:                                chk.setSelected(true);
188:                            }
189:                        }
190:                        labelPanel.add(new JLabel(" "));
191:                        inputPanel.add(chk);
192:                        inputComponent = chk;
193:                    } else {
194:                        labelPanel.add(new JLabel(inputLabels[i] + ": ",
195:                                JLabel.RIGHT));
196:                        JTextField fld = new JTextField();
197:                        if (showDefaults) {
198:                            fld.setText(defaultValues[i]);
199:                        }
200:                        inputPanel.add(fld);
201:                        inputComponent = fld;
202:                    }
203:
204:                    if (i == 0) {
205:                        inputDialog.getRootPane().setNextFocusableComponent(
206:                                inputComponent);
207:                    }
208:                }
209:
210:                JPanel content = new JPanel(new BorderLayout(3, 3));
211:                content.add(labelPanel, BorderLayout.WEST);
212:                content.add(inputPanel, BorderLayout.CENTER);
213:                content.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
214:
215:                Container dialogContentPane = inputDialog.getContentPane();
216:
217:                JPanel mainPanel = new JPanel(new BorderLayout(3, 3));
218:                mainPanel
219:                        .setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));
220:                mainPanel.add(content, BorderLayout.CENTER);
221:                mainPanel.add(buttonPanel, BorderLayout.SOUTH);
222:
223:                dialogContentPane.add(mainPanel, BorderLayout.CENTER);
224:
225:                dialogContentPane.add(buttonPanel, BorderLayout.SOUTH);
226:                inputDialog.getRootPane().setDefaultButton(okButton);
227:                inputDialog.pack();
228:
229:                inputDialog.setLocationRelativeTo(c);
230:                inputDialog.show();
231:            }
232:
233:            private void validate() {
234:                if (defaultValues != null) {
235:                    showDefaults = true;
236:                    if (defaultValues.length != inputLabels.length) {
237:                        throw new BadMethodArgumentException(
238:                                "Number of default values does not match number of labels.");
239:                    }
240:                }
241:                if (fieldTypes != null) {
242:                    useFieldTypes = true;
243:                    if (fieldTypes.length != inputLabels.length) {
244:                        throw new BadMethodArgumentException(
245:                                "Number of field types does not match number of labels.");
246:                    }
247:                }
248:            }
249:
250:            /**
251:             * Sets the defaultValues.
252:             * @param defaultValues The defaultValues to set
253:             */
254:            public void setDefaultValues(String[] defaultValues) {
255:                this .defaultValues = defaultValues;
256:            }
257:
258:            /**
259:             * Sets the fieldTypes.
260:             * @param fieldTypes The fieldTypes to set
261:             */
262:            public void setFieldTypes(FieldType[] fieldTypes) {
263:                this .fieldTypes = fieldTypes;
264:            }
265:
266:            /**
267:             * Sets the inputLabels.
268:             * @param inputLabels The inputLabels to set
269:             */
270:            public void setInputLabels(String[] inputLabels) {
271:                this .inputLabels = inputLabels;
272:            }
273:
274:            /**
275:             * Sets the modal.
276:             * @param modal The modal to set
277:             */
278:            public void setModal(boolean modal) {
279:                this .modal = modal;
280:            }
281:
282:            /**
283:             * Sets the okButtonText.
284:             * @param okButtonText The okButtonText to set
285:             */
286:            public void setOkButtonText(String okButtonText) {
287:                this .okButtonText = okButtonText;
288:            }
289:
290:            /**
291:             * Sets the title.
292:             * @param title The title to set
293:             */
294:            public void setTitle(String title) {
295:                this .title = title;
296:            }
297:
298:            /**
299:             * Returns the values the user entered in the generated dialog.
300:             * @return String[]
301:             */
302:            public String[] getInputValues() {
303:                return inputValues;
304:            }
305:
306:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.