Source Code Cross Referenced for AppletStarterEditor.java in  » Testing » jacareto » jacareto » editor » 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 » jacareto » jacareto.editor 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Jacareto Copyright (c) 2002-2005
003:         * Applied Computer Science Research Group, Darmstadt University of
004:         * Technology, Institute of Mathematics & Computer Science,
005:         * Ludwigsburg University of Education, and Computer Based
006:         * Learning Research Group, Aachen University. All rights reserved.
007:         *
008:         * Jacareto is free software; you can redistribute it and/or
009:         * modify it under the terms of the GNU General Public
010:         * License as published by the Free Software Foundation; either
011:         * version 2 of the License, or (at your option) any later version.
012:         *
013:         * Jacareto is distributed in the hope that it will be useful,
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
016:         * General Public License for more details.
017:         *
018:         * You should have received a copy of the GNU General Public
019:         * License along with Jacareto; if not, write to the Free
020:         * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021:         *
022:         */
023:
024:        package jacareto.editor;
025:
026:        import jacareto.starter.AppletStarter;
027:        import jacareto.struct.StructureElement;
028:        import jacareto.system.Environment;
029:        import jacareto.system.Language;
030:        import jacareto.toolkit.event.TextValueListener;
031:        import jacareto.toolkit.swing.IntegerTextField;
032:
033:        import java.awt.BorderLayout;
034:        import java.awt.Component;
035:        import java.awt.Container;
036:        import java.awt.Dialog;
037:        import java.awt.Dimension;
038:        import java.awt.FlowLayout;
039:        import java.awt.Frame;
040:        import java.awt.GridBagConstraints;
041:        import java.awt.GridBagLayout;
042:        import java.awt.Insets;
043:        import java.awt.Point;
044:        import java.awt.Window;
045:        import java.awt.event.ActionEvent;
046:        import java.awt.event.ActionListener;
047:
048:        import java.util.Enumeration;
049:        import java.util.Hashtable;
050:
051:        import javax.swing.JButton;
052:        import javax.swing.JComponent;
053:        import javax.swing.JDialog;
054:        import javax.swing.JLabel;
055:        import javax.swing.JPanel;
056:        import javax.swing.JScrollPane;
057:        import javax.swing.JTabbedPane;
058:        import javax.swing.JTable;
059:        import javax.swing.JTextField;
060:        import javax.swing.ListSelectionModel;
061:        import javax.swing.SwingUtilities;
062:        import javax.swing.event.DocumentEvent;
063:        import javax.swing.event.ListSelectionEvent;
064:        import javax.swing.event.ListSelectionListener;
065:        import javax.swing.table.DefaultTableModel;
066:
067:        /**
068:         * An editor for applet starters.
069:         *
070:         * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
071:         * @version 1.03
072:         */
073:        public class AppletStarterEditor extends StarterEditor implements 
074:                ActionListener, ListSelectionListener {
075:            /** The editor component. */
076:            private JTabbedPane editorComponent;
077:
078:            /** The text field for the applet's width. */
079:            private IntegerTextField widthField;
080:
081:            /** The text field for the applet's height. */
082:            private IntegerTextField heightField;
083:
084:            /** The text field for the code base. */
085:            private JTextField codeBaseField;
086:
087:            /** The text field for the document base. */
088:            private JTextField documentBaseField;
089:
090:            /** The component for the parameters. */
091:            private JComponent paramComponent;
092:
093:            /** The table of the parameters. */
094:            private JTable paramTable;
095:
096:            /** The button for a new parameter. */
097:            private JButton newButton;
098:
099:            /** The button for editing a parameter. */
100:            private JButton editButton;
101:
102:            /** The delete button. */
103:            private JButton deleteButton;
104:
105:            /** The model of the parameters table. */
106:            private DefaultTableModel tableModel;
107:
108:            /** The cursor images panel. */
109:            private CursorImagesPanel cursorImagesPanel;
110:
111:            /** The system properties panel. */
112:            private SystemPropertiesPanel systemPropertiesPanel;
113:
114:            /**
115:             * Create a new applet starter editor.
116:             *
117:             * @param env the environment
118:             */
119:            public AppletStarterEditor(Environment env) {
120:                super (env);
121:
122:                Language language = getLanguage();
123:
124:                // The width field label
125:                c.gridx = 0;
126:                c.gridy = 6;
127:
128:                JLabel widthFieldLabel = new JLabel(language
129:                        .getString("Starters.AppletStarter.Attributes.Width")
130:                        + ":");
131:                editorPanel.add(widthFieldLabel, c);
132:
133:                // The width field
134:                c.gridx = 1;
135:                widthField = new IntegerTextField(4);
136:                widthField.getDocument().addDocumentListener(
137:                        new TextValueListener() {
138:                            public void textValueChanged(DocumentEvent e) {
139:                                if (isUpdateOnChange && (getElement() != null)) {
140:                                    ((AppletStarter) getElement())
141:                                            .setWidth(widthField.getValue());
142:                                }
143:                            }
144:                        });
145:                editorPanel.add(widthField, c);
146:                widthFieldLabel.setLabelFor(widthField);
147:
148:                // The height field label
149:                c.gridx = 0;
150:                c.gridy = 7;
151:
152:                JLabel heightFieldLabel = new JLabel(language
153:                        .getString("Starters.AppletStarter.Attributes.Height")
154:                        + ":");
155:                editorPanel.add(heightFieldLabel, c);
156:
157:                // The height field
158:                c.gridx = 1;
159:                heightField = new IntegerTextField(4);
160:                heightField.getDocument().addDocumentListener(
161:                        new TextValueListener() {
162:                            public void textValueChanged(DocumentEvent e) {
163:                                if (isUpdateOnChange && (getElement() != null)) {
164:                                    ((AppletStarter) getElement())
165:                                            .setHeight(heightField.getValue());
166:                                }
167:                            }
168:                        });
169:                editorPanel.add(heightField, c);
170:                heightFieldLabel.setLabelFor(heightField);
171:
172:                // The codebase field label
173:                c.gridx = 0;
174:                c.gridy = 8;
175:
176:                JLabel codeBaseFieldLabel = new JLabel(
177:                        language
178:                                .getString("Starters.AppletStarter.Attributes.CodeBase")
179:                                + ":");
180:                editorPanel.add(codeBaseFieldLabel, c);
181:
182:                // The codebase field
183:                c.gridx = 1;
184:                codeBaseField = new JTextField(20);
185:                codeBaseField.getDocument().addDocumentListener(
186:                        new TextValueListener() {
187:                            public void textValueChanged(DocumentEvent e) {
188:                                if (isUpdateOnChange && (getElement() != null)) {
189:                                    ((AppletStarter) getElement())
190:                                            .setCodeBase(codeBaseField
191:                                                    .getText());
192:                                }
193:                            }
194:                        });
195:                editorPanel.add(codeBaseField, c);
196:                codeBaseFieldLabel.setLabelFor(codeBaseField);
197:
198:                // The documentbase field label
199:                c.gridx = 0;
200:                c.gridy = 9;
201:
202:                JLabel documentBaseFieldLabel = new JLabel(
203:                        language
204:                                .getString("Starters.AppletStarter.Attributes.DocumentBase")
205:                                + ":");
206:                editorPanel.add(documentBaseFieldLabel, c);
207:
208:                // The documentbase field
209:                c.gridx = 1;
210:                documentBaseField = new JTextField(20);
211:                documentBaseField.getDocument().addDocumentListener(
212:                        new TextValueListener() {
213:                            public void textValueChanged(DocumentEvent e) {
214:                                if (isUpdateOnChange && (getElement() != null)) {
215:                                    ((AppletStarter) getElement())
216:                                            .setDocumentBase(documentBaseField
217:                                                    .getText());
218:                                }
219:                            }
220:                        });
221:                editorPanel.add(documentBaseField, c);
222:                documentBaseFieldLabel.setLabelFor(documentBaseField);
223:
224:                // Creation of the parameter component
225:                paramComponent = new JPanel();
226:                paramComponent.setLayout(new BorderLayout());
227:
228:                paramTable = new JTable(0, 2) {
229:                    public boolean isCellEditable(int row, int column) {
230:                        return false;
231:                    }
232:                };
233:
234:                ListSelectionModel selectionModel = paramTable
235:                        .getSelectionModel();
236:                selectionModel
237:                        .setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
238:                selectionModel.addListSelectionListener(this );
239:
240:                JScrollPane tablePane = new JScrollPane(paramTable) {
241:                    public Insets getInsets() {
242:                        return new Insets(10, 10, 10, 10);
243:                    }
244:                };
245:
246:                tablePane.setPreferredSize(new Dimension(400, 300));
247:                tableModel = (DefaultTableModel) paramTable.getModel();
248:
249:                Object[] columnNames = new Object[2];
250:                columnNames[0] = getLanguage().getString(
251:                        "Starters.AppletStarter.Parameters.Name");
252:                columnNames[1] = getLanguage().getString(
253:                        "Starters.AppletStarter.Parameters.Value");
254:                tableModel.setColumnIdentifiers(columnNames);
255:
256:                if (getElement() != null) {
257:                    Hashtable params = ((AppletStarter) getElement())
258:                            .getParameters();
259:                    Enumeration enumeration = params.keys();
260:
261:                    while (enumeration.hasMoreElements()) {
262:                        String[] rowData = new String[2];
263:                        rowData[0] = (String) enumeration.nextElement();
264:                        rowData[1] = (String) params.get(rowData[0]);
265:                        tableModel.addRow(rowData);
266:                    }
267:                }
268:
269:                JPanel buttonPane = new JPanel(new FlowLayout(FlowLayout.RIGHT));
270:                newButton = new JButton(language.getString("General.New"));
271:                newButton.addActionListener(this );
272:                buttonPane.add(newButton);
273:                editButton = new JButton(language.getString("General.Edit"));
274:                editButton.addActionListener(this );
275:                editButton.setEnabled(false);
276:                buttonPane.add(editButton);
277:                deleteButton = new JButton(language.getString("General.Delete"));
278:                deleteButton.addActionListener(this );
279:                deleteButton.setEnabled(false);
280:                buttonPane.add(deleteButton);
281:
282:                paramComponent.add(tablePane, BorderLayout.CENTER);
283:                paramComponent.add(buttonPane, BorderLayout.SOUTH);
284:
285:                // The other panels
286:                cursorImagesPanel = new CursorImagesPanel(env, this ,
287:                        isUpdateOnChange);
288:                systemPropertiesPanel = new SystemPropertiesPanel(env, this ,
289:                        isUpdateOnChange);
290:            }
291:
292:            /**
293:             * Returns whether this editor is responsible for a given structure element. This editor is
294:             * responsible for applet starters.
295:             *
296:             * @param element thr structure element
297:             *
298:             * @return <code>true</code> if <i>element</i> is an application starter and not
299:             *         <code>null</code>, otherwise <code>false</code>
300:             */
301:            public boolean handlesElement(StructureElement element) {
302:                return (element != null) && (element instanceof  AppletStarter);
303:            }
304:
305:            /**
306:             * Sets the element to edit.
307:             *
308:             * @param element DOCUMENT ME!
309:             */
310:            public void setElement(StructureElement element) {
311:                super .setElement(element);
312:
313:                AppletStarter starter = (AppletStarter) element;
314:                widthField.setValue(starter.getWidth());
315:                heightField.setValue(starter.getHeight());
316:                codeBaseField.setText(starter.getCodeBase());
317:                documentBaseField.setText(starter.getDocumentBase());
318:
319:                int rowCount = tableModel.getRowCount();
320:
321:                for (int i = rowCount - 1; i >= 0; i--) {
322:                    tableModel.removeRow(i);
323:                }
324:
325:                Hashtable params = starter.getParameters();
326:                Enumeration enumeration = params.keys();
327:
328:                while (enumeration.hasMoreElements()) {
329:                    String[] rowData = new String[2];
330:                    rowData[0] = (String) enumeration.nextElement();
331:                    rowData[1] = (String) params.get(rowData[0]);
332:                    tableModel.addRow(rowData);
333:                }
334:
335:                Hashtable cImages = starter.getCursorImages();
336:                Enumeration enum2 = cImages.keys();
337:
338:                while (enum2.hasMoreElements()) {
339:                    String[] rowData = new String[2];
340:                    rowData[0] = (String) enum2.nextElement();
341:                    rowData[1] = (String) cImages.get(rowData[0]);
342:                    cursorImagesPanel.addRow(rowData);
343:                }
344:            }
345:
346:            /**
347:             * Returns the editor component.
348:             *
349:             * @return DOCUMENT ME!
350:             */
351:            public Component getComponent() {
352:                if (editorComponent == null) {
353:                    editorComponent = new JTabbedPane();
354:
355:                    JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
356:                    panel.add(super .getComponent());
357:                    editorComponent
358:                            .addTab(
359:                                    language
360:                                            .getString("Starters.AppletStarter.TabTitles.General"),
361:                                    panel);
362:                    editorComponent
363:                            .addTab(
364:                                    language
365:                                            .getString("Starters.AppletStarter.TabTitles.Parameters"),
366:                                    paramComponent);
367:                    editorComponent.addTab(language
368:                            .getString("Starters.Starter.System.System"),
369:                            systemPropertiesPanel);
370:                    editorComponent
371:                            .addTab(
372:                                    language
373:                                            .getString("Starters.Starter.TabTitles.CursorImages"),
374:                                    cursorImagesPanel);
375:                }
376:
377:                return editorComponent;
378:            }
379:
380:            /**
381:             * Called when a button has been pressed.
382:             *
383:             * @param event the action event representing the button action
384:             */
385:            public void actionPerformed(ActionEvent event) {
386:                Window window = SwingUtilities
387:                        .getWindowAncestor(getComponent());
388:
389:                if (event.getSource() == newButton) {
390:                    ParameterEditorDialog dialog = null;
391:
392:                    if (window instanceof  Frame) {
393:                        dialog = new ParameterEditorDialog((Frame) window);
394:                    } else if (window instanceof  Dialog) {
395:                        dialog = new ParameterEditorDialog((Dialog) window);
396:                    }
397:
398:                    String key = dialog.getKey();
399:                    String value = dialog.getValue();
400:
401:                    if ((key != null) && (!key.equals(""))) {
402:                        Object[] rowData = new Object[2];
403:                        rowData[0] = key;
404:                        rowData[1] = value;
405:                        tableModel.addRow(rowData);
406:
407:                        if (isUpdateOnChange && (getElement() != null)) {
408:                            ((AppletStarter) getElement()).setParameter(key,
409:                                    value);
410:                        }
411:                    }
412:                } else if (event.getSource() == editButton) {
413:                    int selectedRow = paramTable.getSelectedRow();
414:
415:                    if (selectedRow >= 0) {
416:                        String key = (String) tableModel.getValueAt(
417:                                selectedRow, 0);
418:                        String value = (String) tableModel.getValueAt(
419:                                selectedRow, 1);
420:                        ParameterEditorDialog dialog = null;
421:
422:                        if (window instanceof  Frame) {
423:                            dialog = new ParameterEditorDialog((Frame) window,
424:                                    key, value);
425:                        } else if (window instanceof  Dialog) {
426:                            dialog = new ParameterEditorDialog((Dialog) window,
427:                                    key, value);
428:                        }
429:
430:                        key = dialog.getKey();
431:                        value = dialog.getValue();
432:
433:                        if ((key != null) && (!key.equals(""))) {
434:                            tableModel.setValueAt(key, selectedRow, 0);
435:                            tableModel.setValueAt(value, selectedRow, 1);
436:
437:                            if (isUpdateOnChange && (getElement() != null)) {
438:                                ((AppletStarter) getElement()).setParameter(
439:                                        key, value);
440:                            }
441:                        }
442:                    }
443:                } else if (event.getSource() == deleteButton) {
444:                    int selectedRow = paramTable.getSelectedRow();
445:
446:                    if (selectedRow >= 0) {
447:                        String key = (String) tableModel.getValueAt(
448:                                selectedRow, 0);
449:                        tableModel.removeRow(selectedRow);
450:
451:                        if (isUpdateOnChange && (getElement() != null)) {
452:                            ((AppletStarter) getElement()).removeParameter(key);
453:                        }
454:
455:                        deleteButton.setEnabled(false);
456:                        editButton.setEnabled(false);
457:                    }
458:                }
459:            }
460:
461:            /**
462:             * Called when the list selection has changed.
463:             *
464:             * @param event DOCUMENT ME!
465:             */
466:            public void valueChanged(ListSelectionEvent event) {
467:                editButton.setEnabled(true);
468:                deleteButton.setEnabled(true);
469:            }
470:
471:            //
472:            // The parameter editor
473:            //
474:
475:            /**
476:             * The editor dialog for parameters.
477:             */
478:            class ParameterEditorDialog extends JDialog implements 
479:                    ActionListener {
480:                //~ Instance fields ------------------------------------------------------------------------
481:
482:                private String key;
483:                private String value;
484:                private JButton okButton;
485:                private JButton cancelButton;
486:                private JTextField valueField;
487:                private JTextField nameField;
488:
489:                //~ Constructors ---------------------------------------------------------------------------
490:
491:                ParameterEditorDialog(Frame frame) {
492:                    this (frame, "", "");
493:                }
494:
495:                ParameterEditorDialog(Frame frame, String key, String value) {
496:                    super (frame, true);
497:
498:                    Point frameLocation = frame.getLocationOnScreen();
499:                    create(key, value, frameLocation.x, frameLocation.y, frame
500:                            .getWidth(), frame.getHeight());
501:                }
502:
503:                ParameterEditorDialog(Dialog dialog) {
504:                    this (dialog, "", "");
505:                }
506:
507:                ParameterEditorDialog(Dialog dialog, String key, String value) {
508:                    super (dialog, true);
509:
510:                    Point dialogLocation = dialog.getLocationOnScreen();
511:                    create(key, value, dialogLocation.x, dialogLocation.y,
512:                            dialog.getWidth(), dialog.getHeight());
513:                }
514:
515:                //~ Methods --------------------------------------------------------------------------------
516:
517:                private void create(String key, String value, int frameX,
518:                        int frameY, int frameWidth, int frameHeight) {
519:                    this .key = key;
520:                    this .value = value;
521:
522:                    Container content = getContentPane();
523:                    content.setLayout(new GridBagLayout());
524:
525:                    GridBagConstraints c = new GridBagConstraints();
526:                    c.fill = GridBagConstraints.NONE;
527:                    c.anchor = GridBagConstraints.CENTER;
528:                    c.insets = new Insets(5, 5, 5, 5);
529:
530:                    // Row for the name
531:                    c.gridx = 0;
532:                    c.gridy = 0;
533:                    c.weightx = 30;
534:                    c.weighty = 30;
535:
536:                    JLabel nameLabel = new JLabel(
537:                            language
538:                                    .getString("Starters.AppletStarter.ParamEditor.Name"));
539:                    content.add(nameLabel, c);
540:
541:                    c.gridx = 1;
542:                    c.weightx = 70;
543:                    nameField = new JTextField(key, 20);
544:                    nameLabel.setLabelFor(nameField);
545:                    content.add(nameField, c);
546:
547:                    // Row for the value
548:                    c.gridx = 0;
549:                    c.gridy = 1;
550:
551:                    JLabel valueLabel = new JLabel(
552:                            language
553:                                    .getString("Starters.AppletStarter.ParamEditor.Value"));
554:                    content.add(valueLabel, c);
555:
556:                    c.gridx = 1;
557:                    valueField = new JTextField(value, 20);
558:                    valueLabel.setLabelFor(valueField);
559:                    content.add(valueField, c);
560:
561:                    // Row for the buttons
562:                    c.gridwidth = 2;
563:                    c.gridx = 0;
564:                    c.gridy = 2;
565:                    c.weighty = 40;
566:
567:                    JPanel buttonRow = new JPanel(new FlowLayout(
568:                            FlowLayout.CENTER));
569:                    okButton = new JButton(language.getString("General.Ok"));
570:                    okButton.addActionListener(this );
571:                    cancelButton = new JButton(language
572:                            .getString("General.Cancel"));
573:                    cancelButton.addActionListener(this );
574:                    buttonRow.add(okButton);
575:                    buttonRow.add(cancelButton);
576:                    content.add(buttonRow, c);
577:
578:                    pack();
579:
580:                    int x = frameX + ((frameWidth - getWidth()) / 2);
581:                    int y = frameY + ((frameHeight - getHeight()) / 2);
582:                    setLocation(x, y);
583:
584:                    setVisible(true);
585:                }
586:
587:                public void actionPerformed(ActionEvent event) {
588:                    if (event.getSource() == okButton) {
589:                        this .key = nameField.getText();
590:                        this .value = valueField.getText();
591:                    } else {
592:                        this .key = null;
593:                        this .value = null;
594:                    }
595:
596:                    dispose();
597:                }
598:
599:                /**
600:                 * Returns the key, or <code>null</code> when the user has canceled.
601:                 *
602:                 * @return DOCUMENT ME!
603:                 */
604:                public String getKey() {
605:                    return key;
606:                }
607:
608:                /**
609:                 * Returns the value, or <code>null</code> when the user has canceled.
610:                 *
611:                 * @return DOCUMENT ME!
612:                 */
613:                public String getValue() {
614:                    return value;
615:                }
616:            }
617:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.