Source Code Cross Referenced for HeclBuilderGui.java in  » Scripting » hecl » HeclBuilder » 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 » Scripting » hecl » HeclBuilder 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Copyright 2006-2007 David N. Welton
002:
003:           Licensed under the Apache License, Version 2.0 (the "License");
004:           you may not use this file except in compliance with the License.
005:           You may obtain a copy of the License at
006:
007:           	http://www.apache.org/licenses/LICENSE-2.0
008:
009:           Unless required by applicable law or agreed to in writing, software
010:           distributed under the License is distributed on an "AS IS" BASIS,
011:           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012:           See the License for the specific language governing permissions and
013:           limitations under the License.
014:         */
015:
016:        package heclbuilder;
017:
018:        import jarhack.JarHack;
019:
020:        import java.io.File;
021:        import java.io.FileInputStream;
022:        import java.io.InputStream;
023:        import javax.swing.JFileChooser;
024:        import javax.swing.JOptionPane;
025:
026:        import org.jdesktop.layout.GroupLayout;
027:        import org.jdesktop.layout.GroupLayout;
028:        import org.jdesktop.layout.LayoutStyle;
029:
030:        /**
031:         * <code>HeclBuilderGui</code> -- a gui for the creation of J2ME Hecl
032:         * apps.  Utilizes an internal copy of the relevant (MIDP 1.0 or 2.0)
033:         * Hecl.jar as a sort of "template" that is combined with a
034:         * user-supplied script.
035:         *
036:         * @author <a href="mailto:davidw@dedasys.com">David N. Welton</a>
037:         * @version 1.0
038:         */
039:        public class HeclBuilderGui extends javax.swing.JFrame {
040:
041:            private javax.swing.JLabel createLabel;
042:            private javax.swing.JButton editButton;
043:            private javax.swing.JLabel outputLabel;
044:            private javax.swing.JMenu mainMenu;
045:            private javax.swing.JMenuBar mainMenuBar;
046:            private javax.swing.JMenuItem menuQuit;
047:            private javax.swing.JLabel midletLabel;
048:            private javax.swing.JTextField midletTextField;
049:            private javax.swing.JButton outputSelectButton;
050:            private javax.swing.JTextField outputTextField;
051:            private javax.swing.JButton runButton;
052:            private javax.swing.JFileChooser scriptFileChooser;
053:            private javax.swing.JFileChooser outputDirChooser;
054:            private javax.swing.JTextField scriptTextField;
055:            private javax.swing.JButton selectScriptButton;
056:            private javax.swing.JLabel selectLabel;
057:
058:            private javax.swing.JRadioButton selectMidp10;
059:            private javax.swing.JRadioButton selectMidp20;
060:            private javax.swing.ButtonGroup selectMidp;
061:
062:            /**
063:             * Creates a new <code>HeclBuilderGui</code> instance.
064:             *
065:             */
066:            public HeclBuilderGui() {
067:                initComponents();
068:            }
069:
070:            /**
071:             * The <code>initComponents</code> method creates all the GUI
072:             * elements.
073:             *
074:             */
075:            private void initComponents() {
076:                selectLabel = new javax.swing.JLabel();
077:                midletLabel = new javax.swing.JLabel();
078:                outputLabel = new javax.swing.JLabel();
079:                createLabel = new javax.swing.JLabel();
080:                scriptTextField = new javax.swing.JTextField();
081:                midletTextField = new javax.swing.JTextField();
082:                selectScriptButton = new javax.swing.JButton();
083:                runButton = new javax.swing.JButton();
084:                editButton = new javax.swing.JButton();
085:                outputTextField = new javax.swing.JTextField();
086:                outputSelectButton = new javax.swing.JButton();
087:                mainMenuBar = new javax.swing.JMenuBar();
088:                mainMenu = new javax.swing.JMenu();
089:                menuQuit = new javax.swing.JMenuItem();
090:
091:                setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
092:                setTitle("HeclBuilder");
093:                selectLabel.setText("Select a script");
094:
095:                midletLabel.setText("MIDlet name");
096:
097:                createLabel.setText("Create .jar and .jad files");
098:
099:                scriptTextField.setColumns(40);
100:                scriptTextField
101:                        .addCaretListener(new javax.swing.event.CaretListener() {
102:                            public void caretUpdate(
103:                                    javax.swing.event.CaretEvent evt) {
104:                                scriptTextFieldCaretUpdate(evt);
105:                            }
106:                        });
107:
108:                midletTextField
109:                        .addCaretListener(new javax.swing.event.CaretListener() {
110:                            public void caretUpdate(
111:                                    javax.swing.event.CaretEvent evt) {
112:                                midletTextFieldCaretUpdate(evt);
113:                            }
114:                        });
115:
116:                selectScriptButton.setText("...");
117:                selectScriptButton
118:                        .addActionListener(new java.awt.event.ActionListener() {
119:                            public void actionPerformed(
120:                                    java.awt.event.ActionEvent evt) {
121:                                selectScriptButtonActionPerformed(evt);
122:                            }
123:                        });
124:
125:                selectMidp10 = new javax.swing.JRadioButton("MIDP 1.0", true);
126:                selectMidp20 = new javax.swing.JRadioButton("MIDP 2.0");
127:                selectMidp = new javax.swing.ButtonGroup();
128:                selectMidp.add(selectMidp10);
129:                selectMidp.add(selectMidp20);
130:
131:                runButton.setText("Create .jar/.jad files");
132:                runButton
133:                        .setToolTipText("Select a script and MIDlet name to activate this button");
134:                runButton.setEnabled(false);
135:                runButton
136:                        .addActionListener(new java.awt.event.ActionListener() {
137:                            public void actionPerformed(
138:                                    java.awt.event.ActionEvent evt) {
139:                                runButtonActionPerformed(evt);
140:                            }
141:                        });
142:
143:                runButton.getAccessibleContext().setAccessibleDescription("");
144:
145:                editButton.setText("View/Edit");
146:                editButton
147:                        .addActionListener(new java.awt.event.ActionListener() {
148:                            public void actionPerformed(
149:                                    java.awt.event.ActionEvent evt) {
150:                                editButtonActionPerformed(evt);
151:                            }
152:                        });
153:
154:                outputLabel.setText("Output directory");
155:
156:                outputTextField.setText(System.getProperty("user.home"));
157:
158:                outputSelectButton.setText("...");
159:                outputSelectButton
160:                        .addActionListener(new java.awt.event.ActionListener() {
161:                            public void actionPerformed(
162:                                    java.awt.event.ActionEvent evt) {
163:                                outputSelectActionPerformed(evt);
164:                            }
165:                        });
166:
167:                mainMenu.setText("File");
168:                menuQuit.setText("Quit");
169:                menuQuit.addActionListener(new java.awt.event.ActionListener() {
170:                    public void actionPerformed(java.awt.event.ActionEvent evt) {
171:                        menuQuitActionPerformed(evt);
172:                    }
173:                });
174:
175:                mainMenu.add(menuQuit);
176:
177:                mainMenuBar.add(mainMenu);
178:
179:                setJMenuBar(mainMenuBar);
180:
181:                /* This layout manager comes from here:
182:                 * https://swing-layout.dev.java.net/ */
183:
184:                GroupLayout layout = new GroupLayout(getContentPane());
185:                getContentPane().setLayout(layout);
186:
187:                layout.setAutocreateGaps(true);
188:                layout.setAutocreateContainerGaps(true);
189:
190:                GroupLayout.SequentialGroup hGroup = layout
191:                        .createSequentialGroup();
192:                hGroup.add(layout.createParallelGroup().add(selectLabel).add(
193:                        midletLabel).add(outputLabel).add(createLabel));
194:                hGroup.add(layout.createParallelGroup().add(scriptTextField)
195:                        .add(midletTextField).add(outputTextField).add(
196:                                layout.createSequentialGroup()
197:                                        .add(selectMidp10).add(selectMidp20)));
198:
199:                hGroup.add(layout.createParallelGroup().add(
200:                        layout.createSequentialGroup().add(selectScriptButton)
201:                                .add(editButton)).add(outputSelectButton).add(
202:                        runButton));
203:
204:                layout.setHorizontalGroup(hGroup);
205:
206:                GroupLayout.SequentialGroup vGroup = layout
207:                        .createSequentialGroup();
208:                vGroup.add(layout.createParallelGroup(GroupLayout.BASELINE)
209:                        .add(selectLabel).add(scriptTextField).add(
210:                                selectScriptButton).add(editButton));
211:                vGroup.add(layout.createParallelGroup(GroupLayout.BASELINE)
212:                        .add(midletLabel).add(midletTextField));
213:                vGroup.add(layout.createParallelGroup(GroupLayout.BASELINE)
214:                        .add(outputLabel).add(outputTextField).add(
215:                                outputSelectButton));
216:                vGroup.add(layout.createParallelGroup(GroupLayout.BASELINE)
217:                        .add(createLabel).add(selectMidp10).add(selectMidp20)
218:                        .add(runButton));
219:                layout.setVerticalGroup(vGroup);
220:
221:                pack();
222:            }
223:
224:            /**
225:             * The <code>runButtonActionPerformed</code> method runs JarHack
226:             * to actually create the jar/jad files where they are supposed to
227:             * be.
228:             *
229:             * @param evt a <code>java.awt.event.ActionEvent</code> value
230:             */
231:            private void runButtonActionPerformed(java.awt.event.ActionEvent evt) {
232:                String hecljar = null;
233:                if (selectMidp10.isSelected()) {
234:                    hecljar = "/jars/cldc1.0-midp1.0/Hecl.jar";
235:                } else {
236:                    hecljar = "/jars/cldc1.1-midp2.0/Hecl.jar";
237:                }
238:                InputStream in = this .getClass().getResourceAsStream(hecljar);
239:                String scriptfile = scriptTextField.getText();
240:                String newname = midletTextField.getText();
241:                String outfile = outputTextField.getText() + File.separatorChar
242:                        + newname + ".jar";
243:                try {
244:                    JarHack.substHecl(in, outfile, newname, scriptfile);
245:                    JarHack.createJadForJar(outfile, newname);
246:                } catch (Exception e) {
247:                    JOptionPane.showMessageDialog(this , "Problem creating "
248:                            + outfile + "\n" + e.toString(),
249:                            "Hecl Builder Error", JOptionPane.ERROR_MESSAGE);
250:                }
251:            }
252:
253:            private void scriptTextFieldCaretUpdate(
254:                    javax.swing.event.CaretEvent evt) {
255:                midletTextFieldCaretUpdate(evt);
256:            }
257:
258:            private void midletTextFieldCaretUpdate(
259:                    javax.swing.event.CaretEvent evt) {
260:                String midletName = midletTextField.getText();
261:                String scriptName = scriptTextField.getText();
262:                if (midletName.length() > 0 && scriptName.length() > 0) {
263:                    runButton.setEnabled(true);
264:                }
265:            }
266:
267:            private void menuQuitActionPerformed(java.awt.event.ActionEvent evt) {
268:                System.exit(1);
269:            }
270:
271:            private void selectScriptButtonActionPerformed(
272:                    java.awt.event.ActionEvent evt) {
273:                scriptFileChooser = new JFileChooser(System
274:                        .getProperty("user.dir"));
275:                scriptFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
276:                int retval = scriptFileChooser.showOpenDialog(this );
277:                if (retval == JFileChooser.APPROVE_OPTION) {
278:                    File file = scriptFileChooser.getSelectedFile();
279:                    scriptTextField.setText(file.toString());
280:                }
281:            }
282:
283:            private void editButtonActionPerformed(
284:                    java.awt.event.ActionEvent evt) {
285:                String filename = null;
286:                File fl = new File(scriptTextField.getText());
287:
288:                if (fl.exists()) {
289:                    filename = fl.toString();
290:                } else {
291:                    if (JOptionPane.showConfirmDialog(this , "The file " + fl
292:                            + " does not exist.  Create it?") != JOptionPane.YES_OPTION) {
293:                        return;
294:                    }
295:                    filename = fl.toString();
296:                }
297:                HeclEditor he = new HeclEditor(filename);
298:                he.setVisible(true);
299:            }
300:
301:            private void outputSelectActionPerformed(
302:                    java.awt.event.ActionEvent evt) {
303:                outputDirChooser = new JFileChooser(outputTextField.getText());
304:                outputDirChooser
305:                        .setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
306:                int retval = outputDirChooser.showOpenDialog(this );
307:                if (retval == JFileChooser.APPROVE_OPTION) {
308:                    File file = outputDirChooser.getSelectedFile();
309:                    outputTextField.setText(file.toString());
310:                }
311:            }
312:
313:            public static void main(String args[]) {
314:                java.awt.EventQueue.invokeLater(new Runnable() {
315:                    public void run() {
316:                        new HeclBuilderGui().setVisible(true);
317:                    }
318:                });
319:            }
320:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.