Source Code Cross Referenced for XuiEditor.java in  » XML-UI » XUI » net » xoetrope » builder » 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 » XML UI » XUI » net.xoetrope.builder.editor 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        package net.xoetrope.builder.editor;
0002:
0003:        import java.io.BufferedReader;
0004:        import java.io.IOException;
0005:        import java.io.StringReader;
0006:        import java.io.StringWriter;
0007:        import java.net.URL;
0008:        import java.util.ArrayList;
0009:        import java.util.Vector;
0010:        import java.util.prefs.Preferences;
0011:        import javax.help.CSH;
0012:        import javax.help.HelpBroker;
0013:        import javax.help.HelpSet;
0014:
0015:        import java.awt.AWTEvent;
0016:        import java.awt.BorderLayout;
0017:        import java.awt.Color;
0018:        import java.awt.Component;
0019:        import java.awt.Dimension;
0020:        import java.awt.Insets;
0021:        import java.awt.event.ActionEvent;
0022:        import java.awt.event.WindowAdapter;
0023:        import java.awt.event.WindowEvent;
0024:        import javax.swing.BorderFactory;
0025:        import javax.swing.JFileChooser;
0026:        import javax.swing.JFrame;
0027:        import javax.swing.JMenu;
0028:        import javax.swing.JOptionPane;
0029:        import javax.swing.JPanel;
0030:        import javax.swing.JScrollPane;
0031:        import javax.swing.JSplitPane;
0032:        import javax.swing.JTabbedPane;
0033:        import javax.swing.SwingUtilities;
0034:        import javax.swing.UIManager;
0035:        import javax.swing.event.ChangeEvent;
0036:        import javax.swing.event.ChangeListener;
0037:        import javax.swing.event.MenuListener;
0038:        import javax.swing.plaf.metal.MetalLookAndFeel;
0039:
0040:        import net.xoetrope.builder.editor.components.ComponentHelper;
0041:        import net.xoetrope.builder.editor.components.awt.AwtComponentHelper;
0042:        import net.xoetrope.builder.editor.components.swing.SwingComponentHelper;
0043:        import net.xoetrope.builder.editor.dialog.InputDialog;
0044:        import net.xoetrope.builder.editor.dialog.XAboutDialog;
0045:        import net.xoetrope.builder.editor.dialog.XNewProjectDialog;
0046:        import net.xoetrope.builder.editor.dialog.XPluginListDialog;
0047:        import net.xoetrope.builder.editor.events.CommandListener;
0048:        import net.xoetrope.builder.editor.events.ComponentSelectListener;
0049:        import net.xoetrope.builder.editor.events.EditorComponentListener;
0050:        import net.xoetrope.builder.editor.events.EventHandlerEditor;
0051:        import net.xoetrope.builder.editor.events.ProjectListener;
0052:        import net.xoetrope.builder.editor.events.PropertiesListener;
0053:        import net.xoetrope.builder.editor.events.StyleListener;
0054:        import net.xoetrope.builder.editor.events.ToolbarListener;
0055:        import net.xoetrope.builder.editor.events.XPageListListener;
0056:        import net.xoetrope.builder.editor.helper.AFileFilter;
0057:        import net.xoetrope.builder.editor.helper.CodeHelper;
0058:        import net.xoetrope.builder.editor.helper.XCodeHelpers;
0059:        import net.xoetrope.builder.editor.plugin.XEditorPlugin;
0060:        import net.xoetrope.builder.editor.plugin.XPluginTab;
0061:        import net.xoetrope.builder.editor.syntaxhighlight.TextAreaDefaults;
0062:        import net.xoetrope.debug.DebugLogger;
0063:        import net.xoetrope.xml.XmlElement;
0064:        import net.xoetrope.xml.XmlSource;
0065:        import net.xoetrope.xml.nanoxml.NanoXmlWriter;
0066:        import net.xoetrope.xui.XPage;
0067:        import net.xoetrope.xui.XProjectManager;
0068:        import net.xoetrope.xui.style.XStyle;
0069:        import java.io.File;
0070:
0071:        /**
0072:         * The main editor class, responsible for constucting the editor, menus, toolbars etc...
0073:         * <p> Copyright (c) Xoetrope Ltd., 2002-2003</p>
0074:         * <p> $Revision: 1.20 $</p>
0075:         * <p> License: see license.txt</p>
0076:         */
0077:        public class XuiEditor extends JPanel implements  CommandListener,
0078:                ProjectListener, XPageListListener, ComponentSelectListener,
0079:                StyleListener, EventHandlerEditor, ToolbarListener,
0080:                EditorComponentListener, ChangeListener {
0081:            protected JScrollPane pageScroller;
0082:            protected int pendingComponent = -1;
0083:
0084:            protected XPageHolder pageHolder;
0085:            protected JTabbedPane tabbar;
0086:            protected XMessageArea messageArea;
0087:            protected XSourceEditor sourceEditor;
0088:            protected XSourceEditor xmlEditor, validationEditor,
0089:                    staticDataEditor;
0090:
0091:            private XToolPalette toolbar;
0092:            private XStyleEditor styleEditor;
0093:            private XPageList pageList;
0094:            private XPropertiesEditor propertiesEditor;
0095:            private XComponentTree componentTree;
0096:            private JTabbedPane propertyPane;
0097:            private XEditorMenu editorMenu;
0098:            private JSplitPane splitMain, splitLeft, splitLeft2, splitRight;
0099:            private static JFrame applicationFrame;
0100:            private static XuiEditor editor;
0101:
0102:            private XEditorProjectManager projectManager;
0103:            private XEditorProject currentProject;
0104:
0105:            private int xmlEditorHash = 0;
0106:
0107:            // Defaults for Main Help
0108:            static final String helpsetName = "XuiEditorHelp";
0109:            static final String helpsetLabel = "XuiEditor - Help";
0110:
0111:            // Main HelpSet & Broker
0112:            private HelpSet mainHS = null;
0113:            private HelpBroker mainHB;
0114:
0115:            private static int pluginTabColor = 0;
0116:            private static Color[] pluginColors = { new Color(92, 0, 128),
0117:                    new Color(92, 92, 0), new Color(0, 92, 92),
0118:                    new Color(92, 128, 92), new Color(0, 128, 128),
0119:                    new Color(128, 0, 128), new Color(128, 128, 0),
0120:                    new Color(128, 0, 92) };
0121:
0122:            /**
0123:             * The main entry point to the editor
0124:             * @param args the project takes no arguments so far and is not used
0125:             */
0126:            public static void main(String args[]) {
0127:                final JFrame frame = new JFrame(XuiDefaults.ApplicationName);
0128:
0129:                try {
0130:                    final XSplashScreen splash = new XSplashScreen(frame);
0131:                    splash.pack();
0132:                    splash.show();
0133:                    new Thread(new Runnable() {
0134:                        public void run() {
0135:                            try {
0136:                                Thread.currentThread().sleep(10000);
0137:                                splash.hide();
0138:                            } catch (InterruptedException ex) {
0139:                            }
0140:                        }
0141:                    }).start();
0142:                } catch (Exception ex) {
0143:                    DebugLogger
0144:                            .logWarning("Sorry, no splash screen available. The application is loading and will be ready soon");
0145:                }
0146:
0147:                applicationFrame = frame;
0148:                frame.addWindowListener(new WindowAdapter() {
0149:                    public void windowClosing(WindowEvent e) {
0150:                        editor.exitProject(false);
0151:                    }
0152:
0153:                });
0154:                frame.getContentPane().setLayout(new BorderLayout());
0155:                editor = new XuiEditor(frame);
0156:
0157:                //Center the window
0158:                Dimension windowSize = new Dimension(1200, 800);
0159:                XEditorUtilities.centreWindow(applicationFrame, windowSize);
0160:
0161:                try {
0162:                    Runnable r = new Runnable() {
0163:                        public void run() {
0164:                            SwingUtilities.updateComponentTreeUI(frame);
0165:                        }
0166:                    };
0167:                    SwingUtilities.invokeLater(r);
0168:                } catch (Exception e) {
0169:                    e.printStackTrace();
0170:                }
0171:                frame.show();
0172:            }
0173:
0174:            public XuiEditor(JFrame frame) {
0175:                projectManager = new XEditorProjectManager(this );
0176:                currentProject = (XEditorProject) projectManager
0177:                        .getCurrentProject();
0178:                currentProject.initialise(null);
0179:
0180:                MetalLookAndFeel.setCurrentTheme(new XuiEditorTheme());
0181:                try {
0182:                    MetalLookAndFeel.setCurrentTheme(new XuiEditorTheme());
0183:                    //      UIManager.setLookAndFeel( "javax.swing.plaf.metal.MetalLookAndFeel" );
0184:                    UIManager.setLookAndFeel(UIManager
0185:                            .getSystemLookAndFeelClassName());
0186:                    //      UIManager.put( "TabbedPane.tabInsets", new Insets(1,1,1,1));
0187:                    //      UIManager.put( "TabbedPane.selectedTabPadInsets", new Insets(1,1,1,1));
0188:                    //      UIManager.put( "TabbedPane.tabAreaInsets", new Insets(0,0,0,0));
0189:                    UIManager.put("TabbedPane.contentBorderInsets", new Insets(
0190:                            1, 1, 1, 1));
0191:                } catch (Exception e2) {
0192:                    DebugLogger.logError("Error setting look and feel");
0193:                }
0194:
0195:                setLayout(new BorderLayout());
0196:                setBorder(BorderFactory.createEmptyBorder());
0197:
0198:                tabbar = new JTabbedPane();
0199:                tabbar.setBorder(BorderFactory.createEmptyBorder());
0200:                tabbar.setVisible(false);
0201:                tabbar.setFont(XuiDefaults.defaultFont);
0202:
0203:                setupGuiEditor();
0204:                add(tabbar, BorderLayout.CENTER);
0205:
0206:                editorMenu = new XEditorMenu(this );
0207:                editorMenu.setCommandListener(this );
0208:                frame.setJMenuBar(editorMenu);
0209:
0210:                toolbar = new XToolPalette("Tool palette");
0211:                toolbar.setCommandListener(this );
0212:                styleEditor = new XStyleEditor("Style editor", null);
0213:                pageList = new XPageList();
0214:                propertiesEditor = new XPropertiesEditor("Properties editor");
0215:                propertyPane = new JTabbedPane();
0216:                propertyPane.setTabPlacement(JTabbedPane.BOTTOM);
0217:                propertyPane.add("Properties", propertiesEditor);
0218:                propertyPane.add("Components", componentTree);
0219:                propertyPane.addChangeListener(this );
0220:
0221:                styleEditor.setStyleListener(propertiesEditor);
0222:                propertiesEditor.setStyleListener(styleEditor);
0223:
0224:                frame.getContentPane().add(toolbar, BorderLayout.NORTH);
0225:
0226:                pageList.addPageListListener(this );
0227:                pageHolder.addComponentSelectionListener(this );
0228:                pageHolder.setEditorComponentListener(this );
0229:                pageHolder.setEventHandlerEditor(this );
0230:                propertiesEditor.setEventHandlerEditor(this );
0231:                toolbar.setToolbarListener(this );
0232:                tabbar.addChangeListener(this );
0233:
0234:                editorMenu.setMenuListener((MenuListener) pageHolder);
0235:
0236:                createSplitPane(frame);
0237:
0238:                registerHelpers();
0239:                ((XEditorProject) XProjectManager.getCurrentProject())
0240:                        .getPluginManager().loadPlugins(applicationFrame,
0241:                                getMenu());
0242:                setupHelp();
0243:
0244:                doLayout();
0245:            }
0246:
0247:            public static XPageHolder getPageHolder() {
0248:                return editor.pageHolder;
0249:            }
0250:
0251:            private void createSplitPane(JFrame frame) {
0252:                splitLeft = new JSplitPane(JSplitPane.VERTICAL_SPLIT, pageList,
0253:                        propertyPane);
0254:                splitLeft2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
0255:                        splitLeft, styleEditor);
0256:                splitLeft2.setDividerLocation(0.5);
0257:
0258:                splitMain = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
0259:                        splitLeft2, this );
0260:                splitMain.setBorder(BorderFactory.createEmptyBorder());
0261:
0262:                splitLeft.setBorder(BorderFactory.createEmptyBorder());
0263:                splitLeft.setDividerSize(6);
0264:
0265:                splitLeft2.setBorder(BorderFactory.createEmptyBorder());
0266:                splitLeft2.setDividerSize(6);
0267:
0268:                splitMain.setVisible(false);
0269:                splitMain.setBorder(BorderFactory.createEmptyBorder());
0270:                splitMain.setOneTouchExpandable(true);
0271:                splitMain.setDividerSize(6);
0272:                splitMain.doLayout();
0273:
0274:                frame.getContentPane().add(splitMain, BorderLayout.CENTER);
0275:                frame.doLayout();
0276:            }
0277:
0278:            private void checkSplitLayout() {
0279:                splitLeft.setVisible(pageList.isVisible()
0280:                        || propertiesEditor.isVisible());
0281:                splitLeft.doLayout();
0282:                splitLeft2.doLayout();
0283:            }
0284:
0285:            /**
0286:             * Process menu and toolbar commands
0287:             * @param command the command id
0288:             * @param evt the original event
0289:             * @param selected the selected state of the toolbar or menu item or false if no state exists
0290:             */
0291:            public void processCommand(String command, ActionEvent evt,
0292:                    boolean selected) {
0293:                pageHolder.toolbarClicked(command);
0294:            }
0295:
0296:            /**
0297:             * Process menu and toolbar commands
0298:             * @param command the command id
0299:             * @param evt the original event
0300:             * @param selected the selected state of the toolbar or menu item or false if no state exists
0301:             */
0302:            public void processCommand(int command, ActionEvent evt,
0303:                    boolean selected) {
0304:                if (command >= 0) {
0305:                    if (command >= XEditorMenu.ID_MENU_PLUGIN_0)
0306:                        processPluginCommand(command, evt, selected);
0307:                } else {
0308:                    switch (command) {
0309:                    case XEditorMenu.ID_MENU_NEW_PROJECT:
0310:                        newProject();
0311:                        break;
0312:
0313:                    case XEditorMenu.ID_MENU_OPEN_PROJECT:
0314:                        openProject();
0315:                        break;
0316:
0317:                    case XEditorMenu.ID_MENU_NEW_PAGE:
0318:                        newPage();
0319:                        break;
0320:
0321:                    case XEditorMenu.ID_MENU_HELP_ABOUT: {
0322:                        XAboutDialog about = new XAboutDialog(applicationFrame);
0323:                        about.show();
0324:                    }
0325:                        break;
0326:
0327:                    case XEditorMenu.ID_MENU_CUT:
0328:                        editCut();
0329:                        break;
0330:                    case XEditorMenu.ID_MENU_COPY:
0331:                        editCopy();
0332:                        break;
0333:                    case XEditorMenu.ID_MENU_PASTE:
0334:                        editPaste();
0335:                        break;
0336:
0337:                    case XEditorMenu.ID_MENU_DELETE:
0338:                        editDelete();
0339:                        break;
0340:
0341:                    case XEditorMenu.ID_MENU_HELP_CONTENTS:
0342:                        new CSH.DisplayHelpFromSource(mainHB)
0343:                                .actionPerformed(evt);
0344:                        break;
0345:
0346:                    case XEditorMenu.ID_MENU_SAVE_PROJECT:
0347:                        saveProject();
0348:                        break;
0349:
0350:                    case XEditorMenu.ID_MENU_EXIT_IDE:
0351:                        exitProject(false);
0352:                        break;
0353:
0354:                    case XEditorMenu.ID_MENU_VIEW_PROJECT:
0355:                        pageList.setVisible(!pageList.isVisible());
0356:                        checkSplitLayout();
0357:                        break;
0358:
0359:                    case XEditorMenu.ID_MENU_VIEW_STYLES:
0360:                        styleEditor.setVisible(!styleEditor.isVisible());
0361:                        checkSplitLayout();
0362:                        break;
0363:
0364:                    case XEditorMenu.ID_MENU_VIEW_TOOLBOX:
0365:                        toolbar.setVisible(!toolbar.isVisible());
0366:                        break;
0367:
0368:                    case XEditorMenu.ID_MENU_VIEW_PROPERTIES:
0369:                        propertiesEditor.setVisible(!propertiesEditor
0370:                                .isVisible());
0371:                        checkSplitLayout();
0372:                        break;
0373:
0374:                    case XEditorMenu.ID_MENU_VIEW_DESIGN:
0375:                        tabbar.setSelectedIndex(0);
0376:                        break;
0377:                    case XEditorMenu.ID_MENU_VIEW_SOURCE:
0378:                        tabbar.setSelectedIndex(1);
0379:                        break;
0380:                    case XEditorMenu.ID_MENU_VIEW_XML:
0381:                        setXml(XEditorMenu.ID_MENU_VIEW_XML);
0382:                        tabbar.setSelectedIndex(2);
0383:                        break;
0384:                    case XEditorMenu.ID_MENU_VIEW_VALIDATIONS:
0385:                        setXml(XEditorMenu.ID_MENU_VIEW_VALIDATIONS);
0386:                        tabbar.setSelectedIndex((tabbar.getTitleAt(3)
0387:                                .compareTo("Validations") == 0) ? 3 : 4);
0388:                        break;
0389:                    case XEditorMenu.ID_MENU_VIEW_DATA:
0390:                        setXml(XEditorMenu.ID_MENU_VIEW_DATA);
0391:                        tabbar.setSelectedIndex((tabbar.getTitleAt(3)
0392:                                .compareTo("Validations") == 0) ? 4 : 3);
0393:                        break;
0394:                    case XEditorMenu.ID_MENU_VIEW_MESSAGES:
0395:                        showMessageArea(false);
0396:                        break;
0397:
0398:                    case XEditorMenu.ID_MENU_VIEW_FRAMES:
0399:                        pageHolder.loadFrames(selected);
0400:                        break;
0401:                    case XEditorMenu.ID_MENU_VIEW_PAGE_BORDER:
0402:                        pageHolder.showPages(selected);
0403:                        break;
0404:                    case XEditorMenu.ID_MENU_VIEW_GRID:
0405:                        pageHolder.showGuides(selected);
0406:                        break;
0407:                    case XEditorMenu.ID_MENU_VIEW_LAF:
0408:                        pageHolder.showLaf(selected);
0409:                        break;
0410:
0411:                    case XEditorMenu.ID_VIEW_DEVMODE:
0412:                        currentProject.setMode(currentProject.DEVELOPER_MODE);
0413:                        break;
0414:                    case XEditorMenu.ID_VIEW_EXPERTMODE:
0415:                        currentProject.setMode(currentProject.EXPERT_MODE);
0416:                        break;
0417:                    case XEditorMenu.ID_VIEW_NOVICEMODE:
0418:                        currentProject.setMode(currentProject.NOVICE_MODE);
0419:                        break;
0420:
0421:                    case XEditorMenu.ID_MENU_TEST_PREVIEW:
0422:                        pageHolder.togglePreview();
0423:                        break;
0424:
0425:                    case XEditorMenu.ID_MENU_TEST_BUILD:
0426:                        compileProject();
0427:                        break;
0428:
0429:                    case XEditorMenu.ID_MENU_TEST_BUNDLE:
0430:                        bundleProject();
0431:                        break;
0432:
0433:                    case XEditorMenu.ID_MENU_ALIGN_LEFT:
0434:                    case XEditorMenu.ID_MENU_ALIGN_RIGHT:
0435:                    case XEditorMenu.ID_MENU_ALIGN_TOP:
0436:                    case XEditorMenu.ID_MENU_ALIGN_BOTTOM:
0437:                    case XEditorMenu.ID_MENU_ALIGN_CENTER:
0438:                    case XEditorMenu.ID_MENU_JUSTIFY_HORZ:
0439:                    case XEditorMenu.ID_MENU_JUSTIFY_VERT:
0440:                        pageHolder.alignSelectedComponents(command);
0441:                        break;
0442:
0443:                    case XEditorMenu.ID_MENU_PLUGIN_ADD:
0444:                        addPlugin();
0445:                        break;
0446:
0447:                    case XEditorMenu.ID_MENU_PLUGIN_REMOVE:
0448:                        removePlugin();
0449:                        break;
0450:                    }
0451:                }
0452:            }
0453:
0454:            protected void registerHelpers() {
0455:                ComponentHelper componentHelper = ComponentHelper
0456:                        .getComponentHelpers();
0457:                new AwtComponentHelper().registerHelpers(componentHelper);
0458:                new SwingComponentHelper().registerHelpers(componentHelper);
0459:
0460:                // Register the code helpers.
0461:                ArrayList resourceArray = XEditorProjectManager
0462:                        .getStaticResources();
0463:                XCodeHelpers.register(resourceArray);
0464:                Preferences prefs = Preferences
0465:                        .userNodeForPackage(XuiEditor.class);
0466:                int numHelpers = new Integer(prefs.get("NumCodeHelpers", "0"))
0467:                        .intValue();
0468:                for (int i = 0; i < numHelpers; i++) {
0469:                    String className = prefs.get("CodeHelper_" + i, null);
0470:                    if (className != null) {
0471:                        try {
0472:                            Class cl = Class.forName(className);
0473:                            CodeHelper ch = (CodeHelper) cl.newInstance();
0474:                            ch.register(resourceArray);
0475:                        } catch (Exception ex) {
0476:                        }
0477:                    }
0478:                }
0479:            }
0480:
0481:            /**
0482:             * Set the name of the component selected for addition
0483:             * @param name the component name
0484:             */
0485:            public void setPendingComponentName(String name) {
0486:                pageHolder.toolbarClicked(name);
0487:            }
0488:
0489:            public void openProject(String fileName) {
0490:                String projectPath = fileName;
0491:                setupProject(projectPath);
0492:                editorMenu.setRecentFile(projectPath);
0493:            }
0494:
0495:            /**
0496:             * Show the open dialog and open the selected project
0497:             */
0498:            protected void openProject() {
0499:                Preferences prefs = Preferences
0500:                        .userNodeForPackage(XuiEditor.class);
0501:
0502:                JFileChooser chooser = new JFileChooser(prefs.get(
0503:                        "ProjectPath", XuiDefaults.ProjectPath));
0504:                XEditorUtilities.setDefaultFont(chooser);
0505:                chooser.setFileFilter(new AFileFilter("xui",
0506:                        "XUI project files"));
0507:                int i = chooser.showOpenDialog(this );
0508:                if (i == 0)
0509:                    openProject(chooser.getSelectedFile().getParent());
0510:            }
0511:
0512:            protected void newProject() {
0513:                XNewProjectDialog dlg = new XNewProjectDialog(currentProject);
0514:                dlg.setLocationRelativeTo(this );
0515:                boolean create = dlg.showDlg();
0516:                if (create)
0517:                    setupProject(dlg.getProjectPath());
0518:            }
0519:
0520:            protected void setupProject(String projectPath) {
0521:                currentProject.addProjectListener(editorMenu);
0522:                currentProject.addProjectListener(this );
0523:                currentProject.addProjectListener(pageList);
0524:                currentProject.addProjectListener(propertiesEditor);
0525:                currentProject.addProjectListener(styleEditor);
0526:
0527:                currentProject.openProject(projectPath);
0528:
0529:                Preferences prefs = Preferences
0530:                        .userNodeForPackage(XuiEditor.class);
0531:                prefs.put("ProjectPath", projectPath);
0532:            }
0533:
0534:            protected void compileProject() {
0535:                sourceEditor.updateSource(null);
0536:                showMessageArea(true);
0537:                editorMenu.initViewMenu(pageHolder.hasFrames(), pageHolder
0538:                        .hasGuides(), pageHolder.hasPageBorders(),
0539:                        messageArea != null);
0540:                currentProject.doCompile(messageArea);
0541:                pageHolder.resetListeners();
0542:            }
0543:
0544:            /**
0545:             * Bundle the current project into a jar file for distribution.
0546:             */
0547:            protected void bundleProject() {
0548:                currentProject.bundleProject();
0549:            }
0550:
0551:            /**
0552:             * Save the project
0553:             */
0554:            protected void saveProject() {
0555:                sourceEditor.updateSource(null);
0556:                currentProject.save();
0557:                editorMenu.save();
0558:            }
0559:
0560:            /**
0561:             * Shutdown the project
0562:             * @param allowCancel on system exit there is no way to prevent the application window from disappearing, so cancel is inappropriate
0563:             */
0564:            protected void exitProject(boolean allowCancel) {
0565:                if (currentProject != null) {
0566:                    editorMenu.save();
0567:
0568:                    int option = JOptionPane.showConfirmDialog(this ,
0569:                            "Do you want to save before closing",
0570:                            "Save project",
0571:                            allowCancel ? JOptionPane.YES_NO_CANCEL_OPTION
0572:                                    : JOptionPane.YES_NO_OPTION);
0573:                    if (option == JOptionPane.YES_OPTION)
0574:                        saveProject();
0575:
0576:                    currentProject.shutDown();
0577:                }
0578:                System.exit(0);
0579:            }
0580:
0581:            /**
0582:             * Respond to the project loading by updating the UI components - menus, toolbars etc...
0583:             * @param project
0584:             */
0585:            public void projectLoaded(XEditorProject project) {
0586:                currentProject = project;
0587:                pageHolder.projectLoaded(project);
0588:
0589:                setupTextEditor();
0590:                setupXmlEditor(XEditorMenu.ID_MENU_VIEW_SOURCE);
0591:                tabbar.setEnabledAt(1, false);
0592:
0593:                toolbar.setVisible(true);
0594:                styleEditor.setVisible(true);
0595:                pageList.setVisible(true);
0596:                propertiesEditor.setVisible(true);
0597:                splitMain.setVisible(true);
0598:
0599:                pageHolder.loadFrames(project.hasFrames());
0600:                editorMenu.initViewMenu(pageHolder.hasFrames(), pageHolder
0601:                        .hasGuides(), pageHolder.hasPageBorders(),
0602:                        messageArea != null);
0603:
0604:                XPageResource contentPage = pageHolder.getContentPage();
0605:                if (contentPage != null)
0606:                    pageList.setSelectedPage(contentPage);
0607:            }
0608:
0609:            /**
0610:             * The project has been updated
0611:             */
0612:            public void projectUpdated() {
0613:                editorMenu.initViewMenu(pageHolder.hasFrames(), pageHolder
0614:                        .hasGuides(), pageHolder.hasPageBorders(),
0615:                        messageArea != null);
0616:                toolbar.initEditTools(false, false, false);
0617:                toolbar.initAlignmentTools(false);
0618:            }
0619:
0620:            /**
0621:             * Create a new screen by popping up a dialog
0622:             */
0623:            protected void newPage() {
0624:                InputDialog newpage = new InputDialog("Enter the page name",
0625:                        "Enter the name of the new page");
0626:                newpage.setModal(true);
0627:                String pageName = newpage.getInputValue();
0628:                if (pageName != null) {
0629:                    XEditorUtilities.copyFile("WelcomeTemplate.xml",
0630:                            currentProject.getPath() + File.separatorChar
0631:                                    + "pages" + File.separatorChar + pageName
0632:                                    + ".xml");
0633:                    currentProject.loadPageResources();
0634:                    componentTree.refresh();
0635:                    if (pageList != null)
0636:                        pageList.projectUpdated();
0637:                }
0638:            }
0639:
0640:            /**
0641:             * Update the displayed XML
0642:             * @param view <UL><LI>XEditorMenu.ID_MENU_VIEW_SOURCE to view the page xml</LI>
0643:             * <LI>XEditorMenu.ID_MENU_VIEW_VALIDATIONS to view the validations xml</LI>
0644:             * <LI>XEditorMenu.ID_MENU_VIEW_DATA to view the static data xml</LI></UL>
0645:             */
0646:            protected void setXml(int view) {
0647:                try {
0648:                    if (view == XEditorMenu.ID_MENU_VIEW_VALIDATIONS) {
0649:                        String contents = "";
0650:                        String validationsFile = "";
0651:                        try {
0652:                            validationsFile = currentProject
0653:                                    .getStartupParam("Validations");
0654:                            if (validationsFile == null)
0655:                                validationsFile = "validations.xml";
0656:                            contents = readXmlFile(validationsFile);
0657:                        } catch (Exception ex1) {
0658:                            DebugLogger
0659:                                    .logError("Could not read the validations file: "
0660:                                            + validationsFile);
0661:                        }
0662:                        setupXmlEditor(XEditorMenu.ID_MENU_VIEW_VALIDATIONS);
0663:                        validationEditor.setXml(contents);
0664:                    } else if (view == XEditorMenu.ID_MENU_VIEW_DATA) {
0665:                        String contents = "";
0666:                        String dataFile = "";
0667:                        try {
0668:                            dataFile = currentProject
0669:                                    .getStartupParam("ModelData");
0670:                            if (dataFile == null)
0671:                                dataFile = "data.xml";
0672:                            contents = readXmlFile(dataFile);
0673:                        } catch (Exception ex1) {
0674:                            DebugLogger
0675:                                    .logError("Could not read the model data file: "
0676:                                            + dataFile);
0677:                        }
0678:                        setupXmlEditor(XEditorMenu.ID_MENU_VIEW_DATA);
0679:                        staticDataEditor.setXml(contents);
0680:                    } else { //ID_MENU_VIEW_XML
0681:                        XPageResource currentPage = pageHolder.getCurrentPage();
0682:                        if (currentPage != null) {
0683:                            XuiWriter xuiWriter = new XuiWriter(currentProject,
0684:                                    currentPage);
0685:                            String xmlText = xuiWriter.getXml();
0686:                            xmlEditorHash = xmlText.hashCode();
0687:                            xmlEditor.setXml(xmlText);
0688:                        }
0689:                    }
0690:                } catch (IOException ex) {
0691:                    ex.printStackTrace();
0692:                }
0693:            }
0694:
0695:            /**
0696:             * Coordinate the response to a component selection
0697:             * @param selectedComponents the list of selected components
0698:             */
0699:            public void setSelectedComponents(Vector selectedComponents) {
0700:                Component comp = tabbar.getSelectedComponent();
0701:                if (comp instanceof  JScrollPane) {
0702:                    boolean hasSelection = selectedComponents.size() > 0;
0703:                    boolean multipleSelection = selectedComponents.size() > 1;
0704:                    boolean hasPasteItems = pageHolder.hasPasteContent();
0705:
0706:                    editorMenu.initAlignmentMenu(multipleSelection);
0707:                    editorMenu.initEditMenu(true, true, hasPasteItems, true);
0708:                    toolbar.initEditTools(hasSelection, hasSelection,
0709:                            hasPasteItems);
0710:                    toolbar.initAlignmentTools(multipleSelection);
0711:
0712:                    if (propertyPane.getSelectedIndex() == 1)
0713:                        componentTree.setSelectedComponents(selectedComponents);
0714:                    else
0715:                        propertiesEditor
0716:                                .setSelectedComponents(selectedComponents);
0717:
0718:                    styleEditor.setSelectedComponents(selectedComponents);
0719:                    currentProject.getPluginManager().setSelectedComponents(
0720:                            selectedComponents);
0721:
0722:                    propertiesEditor.doLayout();
0723:                }
0724:            }
0725:
0726:            public void styleChanged(String name, XStyle style) {
0727:                pageHolder.resetStyles();
0728:            }
0729:
0730:            /**
0731:             * Show the Java source code at the point of the specified method
0732:             * @param page the page resource that owns the method
0733:             * @param source the component that initiates the event
0734:             * @param methodName the response method name
0735:             * @param mask the event mask
0736:             */
0737:            public void showEventHandler(XPageResource page, Component source,
0738:                    String methodName, long mask) {
0739:                try {
0740:                    String[] args = null;
0741:                    if ((source == null) || (methodName == null)
0742:                            || (methodName.length() == 0)) {
0743:                        page.removeCtlEvent(source, mask);
0744:                        return;
0745:                    }
0746:
0747:                    page.addCtlEvent(source, mask, methodName);
0748:                    showPageEventHandler(page, methodName);
0749:                } catch (Exception ex1) {
0750:                    ex1.printStackTrace();
0751:                }
0752:            }
0753:
0754:            public void showPageEventHandler(XPageResource page,
0755:                    String methodName) {
0756:                try {
0757:                    String[] args = null;
0758:                    String pageName = page.getName();
0759:                    sourceEditor.setScreen(pageName, true);
0760:                    sourceEditor.locateMethod(methodName, true);
0761:                    tabbar.setEnabledAt(1, true);
0762:                    tabbar.setSelectedIndex(1);
0763:                } catch (Exception ex1) {
0764:                    ex1.printStackTrace();
0765:                }
0766:            }
0767:
0768:            public void toolbarClicked(String c) {
0769:                pageHolder.toolbarClicked(c);
0770:            }
0771:
0772:            public void componentAdded() {
0773:                toolbar.componentAdded();
0774:            }
0775:
0776:            public void setNewComponent(Component c) {
0777:                propertiesEditor.setNewComponent(c);
0778:            }
0779:
0780:            public void editCut() {
0781:                Component comp = tabbar.getSelectedComponent();
0782:                if (comp instanceof  JScrollPane) {
0783:                    editorMenu.initAlignmentMenu(false);
0784:                    toolbar.initEditTools(false, false, true);
0785:                    toolbar.initAlignmentTools(false);
0786:
0787:                    pageHolder.cut();
0788:                    pageHolder.repaint();
0789:                } else if (comp instanceof  XSourceEditor)
0790:                    ((XSourceEditor) comp).cut();
0791:                else if (comp instanceof  XPluginTab)
0792:                    ((XPluginTab) comp).getPlugin().cut();
0793:            }
0794:
0795:            public void editCopy() {
0796:                Component comp = tabbar.getSelectedComponent();
0797:                if (comp instanceof  JScrollPane) {
0798:                    editorMenu.initAlignmentMenu(false);
0799:                    toolbar.initEditTools(true, true, true);
0800:                    toolbar.initAlignmentTools(false);
0801:
0802:                    pageHolder.copy();
0803:                    pageHolder.repaint();
0804:                } else if (comp instanceof  XSourceEditor)
0805:                    ((XSourceEditor) comp).copy();
0806:                else if (comp instanceof  XPluginTab)
0807:                    ((XPluginTab) comp).getPlugin().copy();
0808:            }
0809:
0810:            public void editPaste() {
0811:                Component comp = tabbar.getSelectedComponent();
0812:                if (comp instanceof  JScrollPane) {
0813:                    editorMenu.initAlignmentMenu(false);
0814:                    toolbar.initEditTools(true, true, true);
0815:                    toolbar.initAlignmentTools(false);
0816:
0817:                    pageHolder.paste();
0818:                    pageHolder.repaint();
0819:                } else if (comp instanceof  XSourceEditor)
0820:                    ((XSourceEditor) comp).paste();
0821:            }
0822:
0823:            public void editDelete() {
0824:                Component comp = tabbar.getSelectedComponent();
0825:                if (comp instanceof  JScrollPane) {
0826:                    editorMenu.initAlignmentMenu(false);
0827:                    toolbar.initEditTools(false, false, false);
0828:                    toolbar.initAlignmentTools(false);
0829:
0830:                    pageHolder.deleteSelection();
0831:                    pageHolder.repaint();
0832:                } else if (comp instanceof  XSourceEditor)
0833:                    ((XSourceEditor) comp).setSelectedText("");
0834:                else if (comp instanceof  XPluginTab)
0835:                    ((XPluginTab) comp).getPlugin().paste();
0836:            }
0837:
0838:            /**
0839:             * The tabbar selection has changed
0840:             * @param e the change event
0841:             */
0842:            public void stateChanged(ChangeEvent e) {
0843:                pluginPanelDeactivated();
0844:
0845:                int selIdx = tabbar.getSelectedIndex();
0846:                Object source = e.getSource();
0847:                if (source == propertyPane) {
0848:                    if (propertyPane.getSelectedIndex() == 1)
0849:                        componentTree.refresh();
0850:                    else
0851:                        propertiesEditor.refresh();
0852:                } else {
0853:                    boolean hasPasteItems = true;
0854:                    Component comp = tabbar.getSelectedComponent();
0855:                    if (comp instanceof  JScrollPane)
0856:                        editorMenu.setMenuListener((MenuListener) pageHolder);
0857:                    else
0858:                        editorMenu.setMenuListener((MenuListener) comp);
0859:
0860:                    if (selIdx == 0) {
0861:                        propertyPane.setSelectedIndex(0);
0862:                        reparsePageXml();
0863:                        styleEditor.setVisible(true);
0864:                        splitLeft2.setDividerLocation(0.5);
0865:                        splitLeft2.doLayout();
0866:                    } else if (selIdx == 1) {
0867:                        propertyPane.setSelectedIndex(1);
0868:                        styleEditor.setVisible(false);
0869:                    } else if (selIdx > 2) {
0870:                        if ((source != validationEditor)
0871:                                && (source != staticDataEditor)) {
0872:                            pluginPanelActivated();
0873:                            return;
0874:                        }
0875:                    } else if (selIdx == 2)
0876:                        setXml(XEditorMenu.ID_MENU_VIEW_XML);
0877:                }
0878:            }
0879:
0880:            /**
0881:             * Setup the Java Help environement
0882:             */
0883:            private void setupHelp() {
0884:                try {
0885:                    ClassLoader cl = XuiEditor.class.getClassLoader();
0886:                    URL url = HelpSet.findHelpSet(cl, helpsetName);
0887:                    mainHS = new HelpSet(cl, url);
0888:                    mainHB = mainHS.createHelpBroker();
0889:                } catch (Exception ee) {
0890:                    DebugLogger.logWarning("Help Set " + helpsetName
0891:                            + " not found");
0892:                    return;
0893:                } catch (ExceptionInInitializerError ex) {
0894:                    System.err.println("initialization error:");
0895:                    ex.getException().printStackTrace();
0896:                }
0897:            }
0898:
0899:            /**
0900:             * Read an XML file and format it for display.
0901:             * @param fileName the file to read
0902:             * @return the contents or an empty string
0903:             */
0904:            private String readXmlFile(String fileName) {
0905:                try {
0906:                    BufferedReader br = XEditorResourceManager
0907:                            .getBufferedReader(fileName, null);
0908:                    XmlElement src = XmlSource.read(br);
0909:                    StringWriter sr = new StringWriter();
0910:                    NanoXmlWriter writer = new NanoXmlWriter(sr);
0911:                    writer.write(src, true, 4);
0912:                    return sr.toString();
0913:                } catch (Exception ex) {
0914:                    DebugLogger.logError("Unable to read file: " + fileName);
0915:                    return "";
0916:                }
0917:            }
0918:
0919:            /**
0920:             * Reparse the page XML if it has changed.
0921:             */
0922:            public void reparsePageXml() {
0923:                if (currentProject.getMode() == currentProject.DEVELOPER_MODE) {
0924:                    String xmlText = xmlEditor.getText();
0925:                    int newHash = xmlText.hashCode();
0926:                    if (xmlEditorHash != newHash) {
0927:                        xmlEditorHash = newHash;
0928:                        XPageResource currentPage = pageHolder.getCurrentPage();
0929:                        String pageName = currentPage.getName();
0930:                        XEditorXuiBuilder pl = (XEditorXuiBuilder) ((XEditorPageManager) currentProject
0931:                                .getPageManager()).getSecondaryLoader();
0932:                        StringReader r = new StringReader(xmlText);
0933:                        XPage updatedPage = pl.readPage(r, pageName, false);
0934:                        pageHolder.removeListeners(currentPage, currentPage
0935:                                .getEditorEventHandler());
0936:                        currentProject.replacePage(pageName, updatedPage);
0937:                        pageHolder.loadPage(pageName, null, updatedPage
0938:                                .getWidth(), updatedPage.getHeight());
0939:                        pageHolder.resetListeners();
0940:                    }
0941:                }
0942:            }
0943:
0944:            // Methods originally in the base class
0945:            /**
0946:             * Show or hide the message area.
0947:             * @param forceDisplay true to force disply, false to toggle display on or off
0948:             */
0949:            public void showMessageArea(boolean forceDisplay) {
0950:                if (messageArea == null) {
0951:                    messageArea = new XMessageArea();
0952:                    add(messageArea, BorderLayout.SOUTH);
0953:                } else if (!forceDisplay) {
0954:                    remove(messageArea);
0955:                    messageArea = null;
0956:                }
0957:                if (messageArea != null)
0958:                    messageArea.clear();
0959:
0960:                validate();
0961:                repaint();
0962:            }
0963:
0964:            /**
0965:             * Get a reference to the message area
0966:             */
0967:            public XMessageArea getMessageArea() {
0968:                return messageArea;
0969:            }
0970:
0971:            /**
0972:             * Get a reference to the message area
0973:             */
0974:            public JFrame getFrame() {
0975:                return applicationFrame;
0976:            }
0977:
0978:            /**
0979:             * Get the toolbar/palette
0980:             * @return a reference to th toolbar
0981:             */
0982:            public XToolPalette getToolPalette() {
0983:                return toolbar;
0984:            }
0985:
0986:            public XGuidePane getGuidePane() {
0987:                return pageHolder.getGuidePane();
0988:            }
0989:
0990:            public XEditorMenu getMenu() {
0991:                return editorMenu;
0992:            }
0993:
0994:            protected void setupTextEditor() {
0995:                TextAreaDefaults defs = TextAreaDefaults.getDefaults();
0996:                sourceEditor = new XSourceEditor(currentProject, defs,
0997:                        XSourceEditor.JAVA_FILE);
0998:                tabbar.add("Code Editor", sourceEditor);
0999:                tabbar.setForegroundAt(0, new Color(0, 0, 128));
1000:                tabbar.setBackgroundAt(0, new Color(255, 255, 0));
1001:            }
1002:
1003:            /**
1004:             * Add another tab for XML display
1005:             * @param type <UL><LI>XEditorMenu.ID_MENU_VIEW_SOURCE to view the page xml</LI>
1006:             * <LI>XEditorMenu.ID_MENU_VIEW_VALIDATIONS to view the validations xml</LI>
1007:             * <LI>XEditorMenu.ID_MENU_VIEW_DATA to view the static data xml</LI></UL>
1008:             */
1009:            protected void setupXmlEditor(int type) {
1010:                if (type == XEditorMenu.ID_MENU_VIEW_SOURCE) {
1011:                    if (xmlEditor == null) {
1012:                        TextAreaDefaults defs = TextAreaDefaults.getDefaults();
1013:                        xmlEditor = new XSourceEditor(currentProject, defs,
1014:                                XSourceEditor.XML_FILE);
1015:                        tabbar.add("XML", xmlEditor);
1016:
1017:                        tabbar.setBackgroundAt(tabbar.getComponentCount() - 1,
1018:                                new Color(0, 128, 0));
1019:                        tabbar.setOpaque(true);
1020:                    }
1021:                } else if (type == XEditorMenu.ID_MENU_VIEW_VALIDATIONS) {
1022:                    if (validationEditor == null) {
1023:                        TextAreaDefaults defs = TextAreaDefaults.getDefaults();
1024:                        validationEditor = new XSourceEditor(currentProject,
1025:                                defs, XSourceEditor.XML_FILE);
1026:                        tabbar.add("Validations", validationEditor);
1027:                        tabbar.setBackgroundAt(tabbar.getComponentCount() - 1,
1028:                                new Color(128, 0, 0));
1029:                    }
1030:                } else if (type == XEditorMenu.ID_MENU_VIEW_DATA) {
1031:                    if (staticDataEditor == null) {
1032:                        TextAreaDefaults defs = TextAreaDefaults.getDefaults();
1033:                        staticDataEditor = new XSourceEditor(currentProject,
1034:                                defs, XSourceEditor.XML_FILE);
1035:                        tabbar.add("Data", staticDataEditor);
1036:                        tabbar.setBackgroundAt(tabbar.getComponentCount() - 1,
1037:                                new Color(92, 92, 0));
1038:                    }
1039:                }
1040:                tabbar.setForegroundAt(tabbar.getComponentCount() - 1,
1041:                        new Color(0, 0, 128));
1042:            }
1043:
1044:            /**
1045:             * Setup the RHS of the editor
1046:             */
1047:            protected void setupGuiEditor() {
1048:                componentTree = new XComponentTree();
1049:                pageHolder = new XPageHolder(componentTree);
1050:                componentTree.setPageHolder(pageHolder);
1051:
1052:                pageScroller = new JScrollPane(pageHolder);
1053:                pageScroller.setPreferredSize(new Dimension(1000, 1000));
1054:                pageHolder.setBorder(BorderFactory.createEmptyBorder());
1055:                componentTree.setBorder(BorderFactory.createEmptyBorder());
1056:                tabbar.add("Screen Designer", pageScroller);
1057:                tabbar.setForegroundAt(tabbar.getComponentCount() - 1,
1058:                        new Color(0, 0, 128));
1059:                tabbar.setBackgroundAt(tabbar.getComponentCount() - 1,
1060:                        new Color(0, 255, 255));
1061:            }
1062:
1063:            public void loadPage(String pageName, String target, int pageWidth,
1064:                    int pageHeight) {
1065:                getGuidePane().clear();
1066:                pageHolder.clearSelectedComponents();
1067:
1068:                editorMenu.initAlignmentMenu(false);
1069:                toolbar.initEditTools(true, true, true);
1070:                toolbar.initAlignmentTools(false);
1071:                tabbar.setVisible(true);
1072:
1073:                pageHolder.loadPage(pageName, target, pageWidth, pageHeight);
1074:                sourceEditor.updateSource(pageName);
1075:
1076:                String src = currentProject.getPageResource(pageName)
1077:                        .getJavaSource();
1078:                if (src.length() == 0)
1079:                    tabbar.setEnabledAt(1, false);
1080:                else
1081:                    tabbar.setEnabledAt(1, true);
1082:                tabbar.setSelectedIndex(0);
1083:                editorMenu.setMenuListener((MenuListener) pageHolder);
1084:                pageHolder.repaint();
1085:
1086:                editorMenu.initViewMenu(pageHolder.hasFrames(), pageHolder
1087:                        .hasGuides(), pageHolder.hasPageBorders(),
1088:                        messageArea != null);
1089:                try {
1090:                    componentTree.refresh();
1091:                } catch (Exception ex) {
1092:                    DebugLogger
1093:                            .logWarning("Error refreshing the component tree!");
1094:                }
1095:            }
1096:
1097:            /**
1098:             * Load a frameset
1099:             * @param showFrames true to show the frames
1100:             */
1101:            public void loadFrames(boolean showFrames) {
1102:                tabbar.setVisible(true);
1103:            }
1104:
1105:            //--Plugin support------------------------------------------------------------
1106:            /**
1107:             * Process a menu commands for a plugin
1108:             * @param command the command id
1109:             * @param evt the original event
1110:             * @param selected the selected state of the toolbar or menu item or false if no state exists
1111:             */
1112:            public void processPluginCommand(int command, AWTEvent evt,
1113:                    boolean selected) {
1114:                currentProject.getPluginManager().processPluginCommand(command,
1115:                        evt, selected);
1116:            }
1117:
1118:            /**
1119:             * Add a plugin and setup its components
1120:             */
1121:            public void addPlugin() {
1122:                XEditorPlugin plugin = currentProject.getPluginManager()
1123:                        .addPlugin(applicationFrame);
1124:
1125:                if (plugin != null) {
1126:                    // Setup the plugin menus
1127:                    editorMenu.resetPluginsMenu();
1128:                    editorMenu.pluginsLoaded();
1129:
1130:                    // Add the plugin toolbar
1131:                    addPluginToolbar(plugin);
1132:                }
1133:            }
1134:
1135:            /**
1136:             * Remove a plugin and setup its components
1137:             */
1138:            public void removePlugin() {
1139:                XEditorPlugin selectedPlugin;
1140:                XPluginListDialog pluginList = new XPluginListDialog(
1141:                        applicationFrame, currentProject.getPluginManager());
1142:                pluginList.show();
1143:                int selectedIdx = pluginList.getSelection();
1144:                if (selectedIdx > -1) {
1145:                    selectedPlugin = currentProject.getPluginManager()
1146:                            .getPlugin(selectedIdx);
1147:                    currentProject.getPluginManager().removePlugin(
1148:                            selectedPlugin);
1149:
1150:                    // Setup the plugin menus
1151:                    editorMenu.resetPluginsMenu();
1152:                    editorMenu.pluginsLoaded();
1153:
1154:                    editorMenu.remove(selectedPlugin.getMenu());
1155:
1156:                    removePluginPanel(selectedPlugin);
1157:
1158:                    // Remove the plugin menu if any
1159:                    removePluginMenu(selectedPlugin);
1160:
1161:                    // Remove the plugin properties pane
1162:                    removePluginEditor();
1163:
1164:                    // Add the plugin toolbar
1165:                    removePluginToolbar(selectedPlugin);
1166:                }
1167:            }
1168:
1169:            /**
1170:             * Add the plugin menu
1171:             */
1172:            public void addPluginMenu(XEditorPlugin plugin) {
1173:                if (plugin != null) {
1174:                    JMenu pluginMenu = plugin.getMenu();
1175:                    if (pluginMenu != null) {
1176:                        if (!removePluginMenu(plugin)) {
1177:                            editorMenu.insertMenu(pluginMenu);
1178:                            editorMenu.repaint();
1179:                        }
1180:                    }
1181:                }
1182:            }
1183:
1184:            /**
1185:             * Add the plugin toolbar
1186:             */
1187:            public void addPluginToolbar(XEditorPlugin plugin) {
1188:                if (plugin != null)
1189:                    toolbar.insertComponents(plugin.getToolbarName(), plugin
1190:                            .getToolbarComponents());
1191:            }
1192:
1193:            /**
1194:             * Remove the plugin toolbar
1195:             */
1196:            public void removePluginToolbar(XEditorPlugin plugin) {
1197:                if (plugin != null)
1198:                    toolbar.removeComponents(plugin.getToolbarName());
1199:            }
1200:
1201:            /**
1202:             * Remove the plugin's menu
1203:             */
1204:            public boolean removePluginMenu(XEditorPlugin plugin) {
1205:                if (plugin != null) {
1206:                    JMenu pluginMenu = plugin.getMenu();
1207:                    if (pluginMenu != null) {
1208:                        int count = editorMenu.getComponentCount();
1209:                        editorMenu.remove(plugin.getMenu());
1210:                        editorMenu.repaint();
1211:                        return (count != editorMenu.getComponentCount());
1212:                    }
1213:                }
1214:                return false;
1215:            }
1216:
1217:            /**
1218:             * A tabbar belonging to a plugin has been activated
1219:             */
1220:            public void pluginPanelActivated() {
1221:                if (tabbar.getSelectedComponent() instanceof  XPluginTab) {
1222:                    XEditorPlugin activePlugin = ((XPluginTab) tabbar
1223:                            .getSelectedComponent()).getPlugin();
1224:                    activePlugin.setState(XEditorPlugin.ACTIVATED);
1225:
1226:                    // Add the plugin menu if any
1227:                    addPluginMenu(activePlugin);
1228:                }
1229:            }
1230:
1231:            /**
1232:             * The plugin pane has been deactivated
1233:             */
1234:            public void pluginPanelDeactivated() {
1235:                // Remove the plugin menu if any
1236:                int numTabs = tabbar.getComponentCount();
1237:                for (int i = 0; i < numTabs; i++) {
1238:                    if (tabbar.getComponent(i) instanceof  XPluginTab) {
1239:                        ((XPluginTab) tabbar.getComponent(i)).getPlugin()
1240:                                .setState(XEditorPlugin.DEACTIVATED);
1241:                        removePluginMenu(((XPluginTab) tabbar.getComponent(i))
1242:                                .getPlugin());
1243:                    }
1244:                }
1245:            }
1246:
1247:            /**
1248:             * Add a tab panel for the plugin
1249:             * @param plugin the new plugin
1250:             */
1251:            public void addPluginPanel(XEditorPlugin plugin) {
1252:                if (plugin.getMainPanel() != null) {
1253:                    if (!removePluginPanel(plugin)) {
1254:                        XPluginTab pluginTab = new XPluginTab(plugin);
1255:                        tabbar.add(plugin.getName(), pluginTab);
1256:                        plugin.setTabColor(true, pluginColors[pluginTabColor++
1257:                                % pluginColors.length]);
1258:                        tabbar.setForegroundAt(tabbar.getComponentCount() - 1,
1259:                                new Color(0, 0, 128));
1260:                        tabbar.setBackgroundAt(tabbar.getComponentCount() - 1,
1261:                                plugin.getTabColor(true));
1262:                        tabbar.setSelectedComponent(pluginTab);
1263:                        plugin.setState(plugin.LOADED);
1264:                    }
1265:                }
1266:            }
1267:
1268:            public boolean removePluginPanel(XEditorPlugin plugin) {
1269:                // Setup the plugin Window
1270:                int numTabs = tabbar.getComponentCount();
1271:                for (int i = 0; i < numTabs; i++) {
1272:                    if (tabbar.getComponent(i) instanceof  XPluginTab) {
1273:                        if (((XPluginTab) tabbar.getComponent(i))
1274:                                .getComponent(0) == plugin.getMainPanel()) {
1275:                            tabbar.remove(i);
1276:                            return true;
1277:                        }
1278:                    }
1279:                }
1280:                return false;
1281:            }
1282:
1283:            public void addPluginEditor(XEditorPlugin plugin) {
1284:                if (splitRight == null) {
1285:                    removePluginEditor();
1286:                    splitMain.remove(this );
1287:                    splitRight = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
1288:                            this , plugin.getPropertiesPanel());
1289:                    splitRight.setBorder(BorderFactory.createEmptyBorder());
1290:                    splitRight.setOneTouchExpandable(true);
1291:                    splitRight.setDividerSize(6);
1292:                    splitMain.add(splitRight);
1293:                } else
1294:                    removePluginEditor();
1295:
1296:                doLayout();
1297:            }
1298:
1299:            public Dimension getMinimumSize() {
1300:                if (pageHolder.getCurrentPage() != null) {
1301:                    Dimension size = pageHolder.getCurrentPage().getSize();
1302:                    return new Dimension(size.width + 30, size.height);
1303:                } else {
1304:                    return super .getMinimumSize();
1305:                }
1306:            }
1307:
1308:            protected void removePluginEditor() {
1309:                if (splitRight != null) {
1310:                    splitMain.remove(splitRight);
1311:                    splitMain.add(this );
1312:                    splitRight = null;
1313:                }
1314:                doLayout();
1315:            }
1316:
1317:            public void addPropertiesListener(PropertiesListener listener) {
1318:                propertiesEditor.addPropertiesListener(listener);
1319:            }
1320:            //--End of Plugin support-----------------------------------------------------
1321:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.