Source Code Cross Referenced for InstallationPathChooser.java in  » Testing » KeY » de » uka » ilkd » key » util » install » 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 » Testing » KeY » de.uka.ilkd.key.util.install 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // This file is part of KeY - Integrated Deductive Software Design
002:        // Copyright (C) 2001-2007 Universitaet Karlsruhe, Germany
003:        //                         Universitaet Koblenz-Landau, Germany
004:        //                         Chalmers University of Technology, Sweden
005:        //
006:        // The KeY system is protected by the GNU General Public License. 
007:        // See LICENSE.TXT for details.
008:        //
009:        //
010:        package de.uka.ilkd.key.util.install;
011:
012:        import java.awt.GridLayout;
013:        import java.awt.event.ActionEvent;
014:        import java.awt.event.ActionListener;
015:        import java.awt.event.FocusEvent;
016:        import java.awt.event.FocusListener;
017:        import java.io.File;
018:
019:        import javax.swing.*;
020:
021:        /**
022:         *   This class creates the GUI element below. The element is used to
023:         *   enter a path, e.g. where to install or find a program.
024:         *    -------------------------------------
025:         *    | text     |======Path======| |...| |
026:         *    -------------------------------------
027:         *   The component exists of a leading 'text' followed by a text field
028:         *   where to enter the path and a button '...'. If it is cliecked on
029:         *   the button a file choser windows comes up that helps to select
030:         *   the right directory/file. 
031:         */
032:        public class InstallationPathChooser extends JPanel {
033:
034:            private JButton fileSelectionButton;
035:            private JTextField pathEntryField;
036:            private File file;
037:
038:            /** event listener */
039:            private InstallationPathListener ipListener = new InstallationPathListener();
040:            /** file selection mode */
041:            private int fileSelectionMode;
042:
043:            private String label = "";
044:
045:            /** creates an installation path chooser
046:             * starts with text followed by a textfield
047:             * @param text a String 
048:             * @param defaultPath the default path of the file
049:             * @param mode an int describing the file chooser mode
050:             */
051:            public InstallationPathChooser(String text, String defaultPath,
052:                    int mode) {
053:                this .fileSelectionMode = mode;
054:                this .file = new File(defaultPath);
055:                this .label = text;
056:                setup(text, defaultPath);
057:            }
058:
059:            private void setup(String text, String defaultPath) {
060:                setLayout(new GridLayout(1, 1));
061:
062:                Box slots = Box.createHorizontalBox();
063:                JPanel firstSecond = new JPanel(new GridLayout(1, 2));
064:
065:                firstSecond.add(new JLabel(text));
066:                pathEntryField = new JTextField(defaultPath, 15);
067:                pathEntryField.addActionListener(ipListener);
068:                pathEntryField.addFocusListener(ipListener);
069:                firstSecond.add(pathEntryField);
070:                slots.add(firstSecond);
071:                fileSelectionButton = new JButton("...");
072:
073:                fileSelectionButton.addActionListener(new ActionListener() {
074:                    public void actionPerformed(ActionEvent e) {
075:                        if (e.getSource() == fileSelectionButton) {
076:                            JFileChooser chooser = new JFileChooser(
077:                                    pathEntryField.getText());
078:                            chooser.setFileSelectionMode(fileSelectionMode);
079:                            int returnVal = chooser.showOpenDialog(null);
080:                            if (returnVal == JFileChooser.APPROVE_OPTION) {
081:                                pathEntryField.setText(chooser
082:                                        .getSelectedFile().getAbsolutePath());
083:                            }
084:                        }
085:                    }
086:                });
087:                slots.add(fileSelectionButton);
088:                add(slots);
089:            }
090:
091:            public boolean isFile() {
092:                return file.isFile();
093:            }
094:
095:            public boolean isDirectory() {
096:                return file.isDirectory();
097:            }
098:
099:            public String getPath() {
100:                return file.getPath();
101:            }
102:
103:            public String getFile() {
104:                return isFile() ? file.getName() : "";
105:            }
106:
107:            public boolean updateModel() {
108:                File nf = new File(pathEntryField.getText());
109:                if (nf.exists()
110:                        && (fileSelectionMode == JFileChooser.FILES_ONLY
111:                                && !nf.isFile() || (fileSelectionMode == JFileChooser.DIRECTORIES_ONLY && !nf
112:                                .isDirectory()))) {
113:                    pathEntryField.selectAll();
114:                    return false;
115:                } else {
116:                    file = nf;
117:                    return true;
118:                }
119:            }
120:
121:            public String setPath(String path) {
122:                String oldPath = pathEntryField.getText();
123:                pathEntryField.setText(path);
124:                return oldPath;
125:            }
126:
127:            public void setEnabled(boolean state) {
128:                pathEntryField.setEnabled(state);
129:                fileSelectionButton.setEnabled(state);
130:            }
131:
132:            public String label() {
133:                return label;
134:            }
135:
136:            // static main method
137:            public static void main(String[] args) {
138:                JFrame testFrame = new JFrame();
139:                testFrame.setSize(400, 300);
140:                testFrame.getContentPane().add(
141:                        new InstallationPathChooser("Install Path",
142:                                "/home/bubel/", JFileChooser.FILES_ONLY));
143:                testFrame.setVisible(true);
144:            }
145:
146:            // inner listener class
147:            private class InstallationPathListener implements  ActionListener,
148:                    FocusListener {
149:
150:                public void actionPerformed(ActionEvent e) {
151:                    updateModel();
152:                }
153:
154:                public void focusLost(FocusEvent e) {
155:                    updateModel();
156:                }
157:
158:                public void focusGained(FocusEvent e) {
159:                }
160:            }
161:
162:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.