Source Code Cross Referenced for UserPathSelectionPanel.java in  » Installer » IzPack » com » izforge » izpack » 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 » Installer » IzPack » com.izforge.izpack.panels 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
003:         * 
004:         * http://izpack.org/
005:         * http://izpack.codehaus.org/
006:         * 
007:         * Copyright 2004 Klaus Bartz
008:         * 
009:         * Licensed under the Apache License, Version 2.0 (the "License");
010:         * you may not use this file except in compliance with the License.
011:         * You may obtain a copy of the License at
012:         * 
013:         *     http://www.apache.org/licenses/LICENSE-2.0
014:         *     
015:         * Unless required by applicable law or agreed to in writing, software
016:         * distributed under the License is distributed on an "AS IS" BASIS,
017:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018:         * See the License for the specific language governing permissions and
019:         * limitations under the License.
020:         */
021:        package com.izforge.izpack.panels;
022:
023:        import java.awt.Dimension;
024:        import java.awt.event.ActionEvent;
025:        import java.awt.event.ActionListener;
026:        import java.io.File;
027:
028:        import javax.swing.JButton;
029:        import javax.swing.JFileChooser;
030:        import javax.swing.JPanel;
031:        import javax.swing.JTextField;
032:
033:        import com.izforge.izpack.gui.ButtonFactory;
034:        import com.izforge.izpack.gui.IzPanelConstraints;
035:        import com.izforge.izpack.gui.IzPanelLayout;
036:        import com.izforge.izpack.gui.LayoutConstants;
037:        import com.izforge.izpack.installer.InstallData;
038:        import com.izforge.izpack.installer.IzPanel;
039:        import com.izforge.izpack.installer.LayoutHelper;
040:
041:        /**
042:         * This is a sub panel which contains a text field and a browse button for path selection. This is
043:         * NOT an IzPanel, else it is made to use in an IzPanel for any path selection. If the IzPanel
044:         * parent implements ActionListener, the ActionPerformed method will be called, if
045:         * PathSelectionPanel.ActionPerformed was called with a source other than the browse button. This
046:         * can be used to perform parentFrame.navigateNext in the IzPanel parent. An example implementation
047:         * is done in com.izforge.izpack.panels.PathInputPanel.
048:         * 
049:         * @author Klaus Bartz
050:         * @author Jeff Gordon
051:         * 
052:         */
053:        public class UserPathSelectionPanel extends JPanel implements 
054:                ActionListener, LayoutConstants {
055:
056:            /**
057:             * 
058:             */
059:            private static final long serialVersionUID = 3618700794577105718L;
060:            /** The text field for the path. */
061:            private JTextField textField;
062:            /** The 'browse' button. */
063:            private JButton browseButton;
064:            /** IzPanel parent (not the InstallerFrame). */
065:            private IzPanel parent;
066:            /**
067:             * The installer internal data.
068:             */
069:            private InstallData idata;
070:            private String targetPanel;
071:            private String variableName;
072:            private String defaultPanelName = "TargetPanel";
073:
074:            /**
075:             * The constructor. Be aware, parent is the parent IzPanel, not the installer frame.
076:             * 
077:             * @param parent The parent IzPanel.
078:             * @param idata The installer internal data.
079:             */
080:            public UserPathSelectionPanel(IzPanel parent, InstallData idata,
081:                    String targetPanel, String variableName) {
082:                super ();
083:                this .parent = parent;
084:                this .idata = idata;
085:                this .variableName = variableName;
086:                this .targetPanel = targetPanel;
087:                createLayout();
088:            }
089:
090:            /**
091:             * Creates the layout for this sub panel.
092:             */
093:            protected void createLayout() {
094:                // We woulduse the IzPanelLayout also in this "sub"panel.
095:                // In an IzPanel there are support of this layout manager at
096:                // more than one places. In this panel not, therefore we have
097:                // to make all things needed.
098:                // First create a layout helper.
099:                LayoutHelper layoutHelper = new LayoutHelper(this );
100:                // Start the layout.
101:                layoutHelper.startLayout(new IzPanelLayout());
102:                // One of the rare points we need explicit a constraints.
103:                IzPanelConstraints ipc = IzPanelLayout
104:                        .getDefaultConstraint(TEXT_CONSTRAINT);
105:                // The text field should be stretched.
106:                ipc.setXStretch(1.0);
107:                textField = new JTextField(idata.getVariable(variableName), 35);
108:                textField.addActionListener(this );
109:                parent.setInitialFocus(textField);
110:                add(textField, ipc);
111:                // We would have place between text field and button.
112:                add(IzPanelLayout.createHorizontalFiller(3));
113:                // No explicit constraints for the button (else implicit) because
114:                // defaults are OK.
115:                String buttonText = parent.getInstallerFrame().langpack
116:                        .getString(targetPanel + ".browse");
117:                if (buttonText == null) {
118:                    buttonText = parent.getInstallerFrame().langpack
119:                            .getString(defaultPanelName + ".browse");
120:                }
121:                browseButton = ButtonFactory.createButton(buttonText, parent
122:                        .getInstallerFrame().icons.getImageIcon("open"),
123:                        idata.buttonsHColor);
124:                browseButton.addActionListener(this );
125:                add(browseButton);
126:            }
127:
128:            // There are problems with the size if no other component needs the
129:            // full size. Sometimes directly, somtimes only after a back step.
130:            public Dimension getMinimumSize() {
131:                Dimension ss = super .getPreferredSize();
132:                Dimension retval = parent.getSize();
133:                retval.height = ss.height;
134:                return (retval);
135:            }
136:
137:            /**
138:             * Actions-handling method.
139:             * 
140:             * @param e The event.
141:             */
142:            public void actionPerformed(ActionEvent e) {
143:                Object source = e.getSource();
144:
145:                if (source == browseButton) {
146:                    // The user wants to browse its filesystem
147:
148:                    // Prepares the file chooser
149:                    JFileChooser fc = new JFileChooser();
150:                    fc.setCurrentDirectory(new File(textField.getText()));
151:                    fc.setMultiSelectionEnabled(false);
152:                    fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
153:                    fc.addChoosableFileFilter(fc.getAcceptAllFileFilter());
154:
155:                    // Shows it
156:                    if (fc.showOpenDialog(this ) == JFileChooser.APPROVE_OPTION) {
157:                        String path = fc.getSelectedFile().getAbsolutePath();
158:                        textField.setText(path);
159:                    }
160:
161:                } else {
162:                    if (parent instanceof  ActionListener) {
163:                        ((ActionListener) parent).actionPerformed(e);
164:                    }
165:                }
166:            }
167:
168:            /**
169:             * Returns the chosen path.
170:             * 
171:             * @return the chosen path
172:             */
173:            public String getPath() {
174:                return (textField.getText());
175:            }
176:
177:            /**
178:             * Sets the contents of the text field to the given path.
179:             * 
180:             * @param path the path to be set
181:             */
182:            public void setPath(String path) {
183:                textField.setText(path);
184:            }
185:
186:            /**
187:             * Returns the text input field for the path. This methode can be used to differ in a
188:             * ActionPerformed method of the parent between the browse button and the text field.
189:             * 
190:             * @return the text input field for the path
191:             */
192:            public JTextField getPathInputField() {
193:                return textField;
194:            }
195:
196:            /**
197:             * Returns the browse button object for modification or for use with a different ActionListener.
198:             * 
199:             * @return the browse button to open the JFileChooser
200:             */
201:            public JButton getBrowseButton() {
202:                return browseButton;
203:            }
204:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.