Source Code Cross Referenced for XEditorProject.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.BufferedInputStream;
0004:        import java.io.BufferedOutputStream;
0005:        import java.io.File;
0006:        import java.io.FileInputStream;
0007:        import java.io.FileOutputStream;
0008:        import java.io.FileWriter;
0009:        import java.io.IOException;
0010:        import java.util.Enumeration;
0011:        import java.util.Hashtable;
0012:        import java.util.Properties;
0013:        import java.util.StringTokenizer;
0014:        import java.util.Vector;
0015:
0016:        import javax.swing.JFrame;
0017:        import javax.swing.JOptionPane;
0018:        import javax.swing.SwingUtilities;
0019:
0020:        import net.xoetrope.builder.editor.ant.JarBuilder;
0021:        import net.xoetrope.builder.editor.ant.taskdefs.Javac;
0022:        import net.xoetrope.builder.editor.events.ProjectListener;
0023:        import net.xoetrope.builder.editor.events.PropertiesListener;
0024:        import net.xoetrope.builder.editor.plugin.XEditorPlugin;
0025:        import net.xoetrope.builder.editor.plugin.XPluginManager;
0026:        import net.xoetrope.debug.DebugLogger;
0027:        import net.xoetrope.xml.XmlElement;
0028:        import net.xoetrope.xml.XmlParserFactory;
0029:        import net.xoetrope.xml.XmlSource;
0030:        import net.xoetrope.xml.jaxp.JaxpXmlParser;
0031:        import net.xoetrope.xml.jaxp.JaxpXmlWriter;
0032:        import net.xoetrope.xml.nanoxml.NanoXmlWriter;
0033:        import net.xoetrope.xui.XPage;
0034:        import net.xoetrope.xui.XProject;
0035:        import net.xoetrope.xui.XProjectManager;
0036:        import net.xoetrope.xui.XResourceManager;
0037:        import net.xoetrope.xui.build.BuildProperties;
0038:        import net.xoetrope.xui.style.XStyleFactory;
0039:        import net.xoetrope.xui.style.XStyleManager;
0040:
0041:        /**
0042:         * Maintains project information
0043:         * <p>Copyright: Copyright (c) Xoetrope Ltd., 1998-2003</p>
0044:         * $Revision: 1.19 $
0045:         * License: license.txt
0046:         */
0047:        public class XEditorProject extends XProject implements  Runnable {
0048:            private String path;
0049:            private String packageName;
0050:            private String framesetName;
0051:            private String projectName;
0052:
0053:            private Hashtable pages;
0054:            private XPluginManager pluginManager;
0055:
0056:            private Vector projectListeners;
0057:
0058:            private XStyleFactory styleFactory;
0059:            private XEditorValidationFactory validationFactory;
0060:
0061:            private XMessageArea messageArea;
0062:            private XuiEditor xuiEditor;
0063:            private XEditorClassLoader projectClassLoader;
0064:
0065:            private Properties projectProperties;
0066:            private boolean swingClient;
0067:            private int mode;
0068:
0069:            public static final int NOVICE_MODE = 0;
0070:            public static final int EXPERT_MODE = 1;
0071:            public static final int DEVELOPER_MODE = 2;
0072:
0073:            /**
0074:             * Create a new projects
0075:             * @param editor the main editor object
0076:             */
0077:            public XEditorProject(XuiEditor editor) {
0078:                xuiEditor = editor;
0079:                pages = new Hashtable(5);
0080:                packageName = "";
0081:                projectName = "Project";
0082:                path = null;
0083:                projectListeners = new Vector();
0084:                swingClient = true;
0085:                pluginManager = new XPluginManager(this );
0086:                mode = DEVELOPER_MODE;
0087:                XmlParserFactory.getInstance().registerXmlParser(
0088:                        new JaxpXmlParser());
0089:                XmlParserFactory.getInstance().registerXmlWriter(
0090:                        new JaxpXmlWriter());
0091:                JaxpXmlParser.setErrorHandler(new XEditorXmlErrorHandler());
0092:
0093:                resourceManager = new XEditorResourceManager();
0094:                projectClassLoader = new XEditorClassLoader(getClass()
0095:                        .getClassLoader());
0096:                ((XEditorResourceManager) resourceManager)
0097:                        .addCustomClassLoader(projectClassLoader);
0098:            }
0099:
0100:            /**
0101:             * Setup the project
0102:             * @param path the path to the new project's root directory
0103:             */
0104:            public void initialise(String path) {
0105:                if (path != null) {
0106:                    String paths[] = new String[6];
0107:                    if (path != null) {
0108:                        paths[0] = new String(path);
0109:                        paths[1] = new String(path + File.separatorChar
0110:                                + "resources");
0111:                        paths[2] = new String(path + File.separatorChar
0112:                                + "pages");
0113:                        paths[3] = new String(path + File.separatorChar + "src");
0114:                        paths[4] = new String(path + File.separatorChar
0115:                                + "classes");
0116:                        paths[5] = new String(path + File.separatorChar
0117:                                + "lang");
0118:                        projectClassLoader.setSources(paths);
0119:                    }
0120:                    setStartupFile(XuiDefaults.StartupFile);
0121:                }
0122:
0123:                styleManager = new XEditorStyleManager(10);
0124:                pages = new Hashtable(5);
0125:                pageManager = new XEditorPageManager();
0126:            }
0127:
0128:            /**
0129:             * Shut down the project. Notifies the plugins of the shutdown.
0130:             */
0131:            public void shutDown() {
0132:                pluginManager.shutDown();
0133:            }
0134:
0135:            public void addProjectListener(ProjectListener listener) {
0136:                projectListeners.add(listener);
0137:            }
0138:
0139:            public XuiEditor getEditor() {
0140:                return xuiEditor;
0141:            }
0142:
0143:            public JFrame getFrame() {
0144:                return xuiEditor.getFrame();
0145:            }
0146:
0147:            /**
0148:             * Gets the Screen object stored in the Hashtable under the 'name' parameter
0149:             * @param name the name of the screen we're looking up
0150:             * @return the Screen associated with the 'name' parameter
0151:             */
0152:            public XPageResource getPageResource(String name) {
0153:                XPageResource scr = (XPageResource) pages.get(name);
0154:                if (scr == null) {
0155:                    scr = new XPageResource(name, path, packageName);
0156:                    pages.put(name, scr);
0157:                }
0158:                return scr;
0159:            }
0160:
0161:            /**
0162:             * Has the project got a frameset
0163:             * @return true if frames are in use, otherwise returns false
0164:             */
0165:            public boolean hasFrames() {
0166:                framesetName = getStartupParam("Frames");
0167:                if (framesetName != null)
0168:                    return true;
0169:                return false;
0170:            }
0171:
0172:            /**
0173:             * Set the frameset name for the project
0174:             * @param framesSet
0175:             */
0176:            public void setFrameset(String framesSet) {
0177:                framesetName = framesSet;
0178:                setStartupProperty("Frames", framesetName);
0179:
0180:                for (int i = 0; i < projectListeners.size(); i++) {
0181:                    ProjectListener listener = (ProjectListener) projectListeners
0182:                            .elementAt(i);
0183:                    listener.projectLoaded(this );
0184:                }
0185:            }
0186:
0187:            /**
0188:             * Add a new Screen to the Hashtable with the key of the name parameter
0189:             * @param name
0190:             */
0191:            public void addPage(String name) {
0192:                pages.put(name, new XPageResource(name, path, packageName));
0193:            }
0194:
0195:            /**
0196:             * Get the pages Hashtable
0197:             * @return the pages Hashtable
0198:             */
0199:            public Hashtable getPageResources() {
0200:                return pages;
0201:            }
0202:
0203:            /**
0204:             * Remove a page resource from the project
0205:             * @param pageName
0206:             */
0207:            public void removePage(String pageName) {
0208:                XPageResource pageRes = getPageResource(pageName);
0209:                pages.remove(pageRes);
0210:                File file = new File(path + "/pages/" + pageRes.getName()
0211:                        + ".xml");
0212:                file.delete();
0213:            }
0214:
0215:            /**
0216:             * Replace a page resource from the project with an updated version
0217:             * @param pageName the page name
0218:             * @param updatedPage the updated version of this page
0219:             */
0220:            public void replacePage(String pageName, XPage updatedPage) {
0221:                XPageResource pageRes = getPageResource(pageName);
0222:                pageRes.setPage(updatedPage);
0223:            }
0224:
0225:            /**
0226:             * Remove all page resources from the project
0227:             */
0228:            public void removeAllPages()
0229:  {
0230:    Enumeration enum = pages.keys();
0231:    while ( enum.hasMoreElements()) {
0232:      XPageResource pageRes = (XPageResource)pages.get( (String)enum.nextElement());
0233:      File file = new File( path + "/pages/" + pageRes.getName() + ".xml" );
0234:      file.delete();
0235:    }
0236:    pages.clear();
0237:  }
0238:
0239:            /**
0240:             * Set the path of the Project
0241:             * @param p the path of the Project
0242:             */
0243:            public void setPath(String p) {
0244:                path = p;
0245:            }
0246:
0247:            /**
0248:             * Called when the create button on the NewProject dialog is clicked. A file
0249:             * with the extension '.xui' is written to the project path.
0250:             */
0251:            public void createProjectFile() {
0252:                saveProject();
0253:            }
0254:
0255:            /**
0256:             * Read the project file.
0257:             * Create a new EditorClassLoader and set the relevant project paths. Set the
0258:             * XEditorResourceManager customClassLoader to the new ClassLoader. Call
0259:             * loadpages to refresh the Project pages.
0260:             * @param path the path to the new project
0261:             */
0262:            public void openProject(String newPath) {
0263:                path = newPath;
0264:                final XEditorProject this Project = this ;
0265:
0266:                new Thread(new Runnable() {
0267:                    public void run() {
0268:                        File projectFile = new File(path + File.separatorChar
0269:                                + "project.xui");
0270:                        if (!projectFile.exists()) {
0271:                            JOptionPane
0272:                                    .showMessageDialog(this Project.getEditor(),
0273:                                            "Sorry, the selected project doesn't exist or cannot be loaded");
0274:                            return;
0275:                        }
0276:
0277:                        initialise(path);
0278:
0279:                        try {
0280:                            XmlElement src = XmlSource.read(XResourceManager
0281:                                    .getBufferedReader(path
0282:                                            + File.separatorChar
0283:                                            + "project.xui", null));
0284:                            Vector children = src.getChildren();
0285:                            int numChildren = children.size();
0286:                            for (int i = 0; i < numChildren; i++) {
0287:                                XmlElement child = (XmlElement) children
0288:                                        .elementAt(i);
0289:                                if (child.getName().equals("packageName"))
0290:                                    packageName = child.getAttribute("name");
0291:                                else if (child.getName().equals("swingClient"))
0292:                                    swingClient = child.getAttribute("value")
0293:                                            .equals("true");
0294:                                else if (child.getName().equals("vertGuides")) {
0295:                                    Vector guides = xuiEditor.getGuidePane()
0296:                                            .getGuideCoords(true);
0297:                                    guides.clear();
0298:
0299:                                    child.getAttribute("name"); // "pageName" );
0300:                                    String values = child
0301:                                            .getAttribute("coords");
0302:                                    StringTokenizer tokens = new StringTokenizer(
0303:                                            values, ",");
0304:                                    while (tokens.hasMoreTokens())
0305:                                        guides.addElement(new Integer(tokens
0306:                                                .nextToken()));
0307:                                } else if (child.getName().equals("horzGuides")) {
0308:                                    Vector guides = xuiEditor.getGuidePane()
0309:                                            .getGuideCoords(false);
0310:                                    guides.clear();
0311:
0312:                                    child.getAttribute("name"); // "pageName" );
0313:                                    String values = child
0314:                                            .getAttribute("coords");
0315:                                    StringTokenizer tokens = new StringTokenizer(
0316:                                            values, ",");
0317:                                    while (tokens.hasMoreTokens())
0318:                                        guides.addElement(new Integer(tokens
0319:                                                .nextToken()));
0320:                                }
0321:                            }
0322:                        } catch (Exception ex) {
0323:                            ex.printStackTrace();
0324:                        }
0325:
0326:                        buildDirectories(packageName.replace('.',
0327:                                File.separatorChar));
0328:
0329:                        styleFactory = new XEditorComponentFactory(
0330:                                XPage.XUI_SWING_PACKAGE);
0331:                        XProjectManager.getPageManager()
0332:                                .setSecondaryLoader(
0333:                                        new XEditorXuiBuilder(this Project,
0334:                                                styleFactory, XuiEditor
0335:                                                        .getPageHolder()));
0336:                        XProjectManager.getPageManager().setPackageName(
0337:                                packageName);
0338:
0339:                        pluginManager.setActiveProject(this Project);
0340:
0341:                        setValidationFactory();
0342:                        loadPageResources();
0343:
0344:                        fireProjectLoaded();
0345:                    }
0346:                }).start();
0347:            }
0348:
0349:            public boolean hasProject() {
0350:                return (path != null);
0351:            }
0352:
0353:            public void fireProjectLoaded() {
0354:                final XEditorProject this Project = this ;
0355:
0356:                for (int i = 0; i < projectListeners.size(); i++) {
0357:                    final ProjectListener listener = (ProjectListener) projectListeners
0358:                            .elementAt(i);
0359:                    SwingUtilities.invokeLater(new Runnable() {
0360:                        public void run() {
0361:                            listener.projectLoaded(this Project);
0362:                        }
0363:                    });
0364:                }
0365:            }
0366:
0367:            public void fireProjectUpdated() {
0368:                final XEditorProject this Project = this ;
0369:
0370:                for (int i = 0; i < projectListeners.size(); i++) {
0371:                    final ProjectListener listener = (ProjectListener) projectListeners
0372:                            .elementAt(i);
0373:                    SwingUtilities.invokeLater(new Runnable() {
0374:                        public void run() {
0375:                            listener.projectUpdated();
0376:                        }
0377:                    });
0378:                }
0379:            }
0380:
0381:            /**
0382:             * Open the Project path and iterate the 'pages' folder. Call the addScreen
0383:             * function for each file found. Then call the openSourceFile method to store
0384:             * the source content with the parameter false so as not to create the file if
0385:             * it doesn't already exist.
0386:             */
0387:            public void loadPageResources() {
0388:                File f = new File(path + File.separatorChar + "pages");
0389:                File[] files = f.listFiles();
0390:                framesetName = getStartupParam("Frames");
0391:                String framesetFileName = framesetName + ".xml";
0392:
0393:                for (int i = 0; i < files.length; i++) {
0394:                    String fileName = files[i].getName();
0395:                    int len = fileName.length();
0396:                    if (fileName.indexOf(".xml") == len - 4) {
0397:                        String screenName = fileName.substring(0, len - 4);
0398:                        if ((framesetName == null)
0399:                                || !(framesetFileName
0400:                                        .equals(files[i].getName()))) {
0401:                            addPage(screenName);
0402:                        }
0403:                    }
0404:                }
0405:            }
0406:
0407:            /**
0408:             * Reopen the loaded pages
0409:             */
0410:            public void reloadPageResources() {
0411:                // Force all the pages to be dumped
0412:                XProjectManager.getPageManager().reset();
0413:
0414:                Enumeration keys = pages.keys();
0415:                while (keys.hasMoreElements()) {
0416:                    ((XPageResource) pages.get(keys.nextElement()))
0417:                            .reloadPage();
0418:                }
0419:            }
0420:
0421:            public void createNewProject(String newPath, String newPackageName,
0422:                    String width, String height, String[] frameSizes,
0423:                    String initScreen, String appTitle, boolean useFrames,
0424:                    boolean isSwing, String[] frameNames) {
0425:                pages = new Hashtable(5);
0426:
0427:                path = newPath;
0428:                swingClient = isSwing;
0429:                createProjectFile();
0430:
0431:                int pWidth = Integer.parseInt(width);
0432:                int pHeight = Integer.parseInt(height);
0433:
0434:                packageName = newPackageName;
0435:                String packagePath = newPackageName.replace('.',
0436:                        File.separatorChar);
0437:
0438:                initialise(path);
0439:
0440:                buildDirectories(packagePath);
0441:
0442:                if (swingClient) {
0443:                    XEditorUtilities.copyFile("XuiCoreSwing.jar", path
0444:                            + File.separatorChar + "lib" + File.separatorChar
0445:                            + "XuiCoreSwing.jar");
0446:                    XEditorUtilities.copyFile("startswingtemplate.bat", path
0447:                            + File.separatorChar + "start.bat");
0448:                } else {
0449:                    XEditorUtilities.copyFile("XuiCore.jar", path
0450:                            + File.separatorChar + "lib" + File.separatorChar
0451:                            + "XuiCore.jar");
0452:                    XEditorUtilities.copyFile("starttemplate.bat", path
0453:                            + File.separatorChar + "start.bat");
0454:                }
0455:                XEditorUtilities.copyFile("startuptemplate.properties", path
0456:                        + File.separator + "resources" + File.separator
0457:                        + XuiDefaults.StartupFile);
0458:                changePropertiesFile(width, height, initScreen, appTitle,
0459:                        useFrames, newPackageName);
0460:                XEditorUtilities.copyFile("stylestemplate.xml", path
0461:                        + File.separatorChar + "resources" + File.separatorChar
0462:                        + "styles.xml");
0463:                XEditorUtilities.copyFile("WelcomeTemplate.xml", path
0464:                        + File.separatorChar + "pages" + File.separatorChar
0465:                        + initScreen + ".xml");
0466:
0467:                if (useFrames) {
0468:                    try {
0469:                        FileOutputStream fos = new FileOutputStream(path
0470:                                + File.separatorChar + "pages"
0471:                                + File.separatorChar + "frames.xml");
0472:                        BufferedOutputStream bos = new BufferedOutputStream(fos);
0473:                        NanoXmlWriter writer = new NanoXmlWriter(bos);
0474:
0475:                        XmlElement framesetElement = XProjectManager
0476:                                .getXmlParserFactory().createXmlElement(
0477:                                        "FrameSet");
0478:
0479:                        XmlElement childXml;
0480:                        if (frameNames[0].length() > 0) {
0481:                            childXml = framesetElement.createElement("Frame");
0482:                            childXml.setAttribute("name", frameNames[0]);
0483:                            childXml.setAttribute("constraint", "NORTH");
0484:                            childXml.setAttribute("content", frameNames[0]);
0485:                            childXml.setAttribute("width", width);
0486:                            childXml.setAttribute("height",
0487:                                    frameSizes == null ? Integer
0488:                                            .toString(pHeight / 5)
0489:                                            : frameSizes[1]);
0490:                            framesetElement.addChild(childXml);
0491:                        }
0492:
0493:                        if (frameNames[1].length() > 0) {
0494:                            childXml = framesetElement.createElement("Frame");
0495:                            childXml.setAttribute("name", frameNames[1]);
0496:                            childXml.setAttribute("constraint", "WEST");
0497:                            childXml.setAttribute("content", frameNames[1]);
0498:                            childXml.setAttribute("width",
0499:                                    frameSizes == null ? Integer
0500:                                            .toString(pWidth / 5)
0501:                                            : frameSizes[2]);
0502:                            childXml.setAttribute("height",
0503:                                    frameSizes == null ? Integer
0504:                                            .toString(3 * (pHeight / 5))
0505:                                            : frameSizes[3]);
0506:                            framesetElement.addChild(childXml);
0507:                        }
0508:
0509:                        childXml = framesetElement.createElement("Frame");
0510:                        childXml.setAttribute("name", "content");
0511:                        childXml.setAttribute("constraint", "CENTER");
0512:                        childXml.setAttribute("content", frameNames[2]);
0513:                        childXml.setAttribute("width",
0514:                                frameSizes == null ? Integer
0515:                                        .toString(pWidth / 5) : frameSizes[4]);
0516:                        childXml.setAttribute("height",
0517:                                frameSizes == null ? Integer
0518:                                        .toString(3 * (pHeight / 5))
0519:                                        : frameSizes[5]);
0520:                        framesetElement.addChild(childXml);
0521:
0522:                        if (frameNames[3].length() > 0) {
0523:                            childXml = framesetElement.createElement("Frame");
0524:                            childXml.setAttribute("name", frameNames[3]);
0525:                            childXml.setAttribute("constraint", "EAST");
0526:                            childXml.setAttribute("content", frameNames[3]);
0527:                            childXml.setAttribute("width",
0528:                                    frameSizes == null ? Integer
0529:                                            .toString(pWidth / 5)
0530:                                            : frameSizes[6]);
0531:                            childXml.setAttribute("height",
0532:                                    frameSizes == null ? Integer
0533:                                            .toString(3 * (pHeight / 5))
0534:                                            : frameSizes[7]);
0535:                            framesetElement.addChild(childXml);
0536:                        }
0537:
0538:                        if (frameNames[4].length() > 0) {
0539:                            childXml = framesetElement.createElement("Frame");
0540:                            childXml.setAttribute("name", frameNames[4]);
0541:                            childXml.setAttribute("constraint", "SOUTH");
0542:                            childXml.setAttribute("content", frameNames[4]);
0543:                            childXml.setAttribute("width", width);
0544:                            childXml.setAttribute("height",
0545:                                    frameSizes == null ? Integer
0546:                                            .toString(pHeight / 5)
0547:                                            : frameSizes[9]);
0548:                            framesetElement.addChild(childXml);
0549:                        }
0550:                        writer.write(framesetElement, true, 4);
0551:                        fos.flush();
0552:                        fos.close();
0553:                    } catch (IOException ex) {
0554:                    }
0555:
0556:                    if (frameNames[0].length() > 0)
0557:                        XEditorUtilities.copyFile("bannertemplate.xml", path
0558:                                + File.separatorChar + "pages"
0559:                                + File.separatorChar + frameNames[0] + ".xml");
0560:                    if (frameNames[1].length() > 0)
0561:                        XEditorUtilities.copyFile("menutemplate.xml", path
0562:                                + File.separatorChar + "pages"
0563:                                + File.separatorChar + frameNames[1] + ".xml");
0564:                    if (frameNames[2].length() > 0)
0565:                        XEditorUtilities.copyFile("contenttemplate.xml", path
0566:                                + File.separatorChar + "pages"
0567:                                + File.separatorChar + frameNames[2] + ".xml");
0568:                    if (frameNames[3].length() > 0)
0569:                        XEditorUtilities.copyFile("sidebartemplate.xml", path
0570:                                + File.separatorChar + "pages"
0571:                                + File.separatorChar + frameNames[3] + ".xml");
0572:                    if (frameNames[4].length() > 0)
0573:                        XEditorUtilities.copyFile("footertemplate.xml", path
0574:                                + File.separatorChar + "pages"
0575:                                + File.separatorChar + frameNames[4] + ".xml");
0576:                }
0577:                xuiEditor.getMenu().setRecentFile(path);
0578:                saveProject();
0579:
0580:                loadPageResources();
0581:
0582:                styleFactory = new XEditorComponentFactory(
0583:                        XPage.XUI_SWING_PACKAGE);
0584:                setStartupFile(path + File.separator + "resources"
0585:                        + File.separator + XuiDefaults.StartupFile);
0586:                XProjectManager.getPageManager().setSecondaryLoader(
0587:                        new XEditorXuiBuilder(this , styleFactory, XuiEditor
0588:                                .getPageHolder()));
0589:                XProjectManager.getPageManager().setPackageName(packageName);
0590:                try {
0591:                    XProjectManager.getStyleManager().load(
0592:                            getStartupParam("StyleFile"));
0593:                } catch (Exception ex) {
0594:                    ex.printStackTrace();
0595:                }
0596:
0597:                setValidationFactory();
0598:
0599:                for (int i = 0; i < projectListeners.size(); i++) {
0600:                    ProjectListener listener = (ProjectListener) projectListeners
0601:                            .elementAt(i);
0602:                    listener.projectLoaded(this );
0603:                }
0604:            }
0605:
0606:            protected void buildDirectories(String packagePath) {
0607:                XEditorUtilities.createDir(path + File.separatorChar
0608:                        + "resources");
0609:                XEditorUtilities.createDir(path + File.separatorChar + "pages");
0610:                XEditorUtilities.createDir(path + File.separatorChar + "lang");
0611:                XEditorUtilities.createDir(path + File.separatorChar + "lib");
0612:                XEditorUtilities.createDir(path + File.separatorChar + "src");
0613:                XEditorUtilities.createDir(path + File.separatorChar + "src"
0614:                        + File.separatorChar + packagePath);
0615:                XEditorUtilities.createDir(path + File.separatorChar
0616:                        + "classes");
0617:            }
0618:
0619:            /**
0620:             * Add a new page to the project
0621:             * @param newPageName the new page name
0622:             * @param className the base class name or null if the default is to be used
0623:             * @return the new page
0624:             */
0625:            public XPageResource addPage(String newPageName, String className) {
0626:                XPage newPage = null;
0627:                XPageResource pageResource = null;
0628:
0629:                if (className != null) {
0630:                    try {
0631:                        newPage = (XPage) Class.forName(className)
0632:                                .newInstance();
0633:                    } catch (InstantiationException ex1) {
0634:                        DebugLogger
0635:                                .logError("The specified class could not be instantiated: "
0636:                                        + className);
0637:                    } catch (IllegalAccessException ex1) {
0638:                        DebugLogger
0639:                                .logError("The specified class could not be accessed: "
0640:                                        + className);
0641:                    } catch (ClassNotFoundException ex1) {
0642:                        DebugLogger
0643:                                .logError("The specified class could not be found: "
0644:                                        + className);
0645:                    } catch (ClassCastException ex1) {
0646:                        DebugLogger
0647:                                .logError("The specified class is not of a suitable type: "
0648:                                        + className);
0649:                    }
0650:                }
0651:                if (newPage == null) {
0652:                    if (className != null)
0653:                        DebugLogger.logWarning("Using the default class");
0654:                    newPage = new XPage();
0655:                }
0656:
0657:                pageResource = new XPageResource(newPageName, path, packageName);
0658:                pageResource.setPage(newPage);
0659:                pages.put(newPageName, pageResource);
0660:
0661:                pageResource.save(this , path);
0662:
0663:                return pageResource;
0664:            }
0665:
0666:            private void setValidationFactory() {
0667:                String validationFile = "";
0668:                try {
0669:                    validationFile = getStartupParam("Validations");
0670:                    if (validationFile == null)
0671:                        validationFile = "validations.xml";
0672:                    validationFactory = new XEditorValidationFactory(
0673:                            XEditorResourceManager
0674:                                    .getBufferedReader(validationFile));
0675:                } catch (Exception ex) {
0676:                    if (BuildProperties.DEBUG)
0677:                        DebugLogger.logError("Unable to load the validations: "
0678:                                + validationFile);
0679:                }
0680:            }
0681:
0682:            public String[] getValidations() {
0683:                if (validationFactory != null)
0684:                    return validationFactory.getValidations();
0685:
0686:                return null;
0687:            }
0688:
0689:            public boolean getValidationExists(String validationName) {
0690:                XmlElement ele = validationFactory
0691:                        .getValidation(validationName);
0692:                return ele == null ? false : true;
0693:            }
0694:
0695:            public XmlElement getValidation(String validationName) {
0696:                return (XmlElement) validationFactory
0697:                        .getValidation(validationName);
0698:            }
0699:
0700:            /**
0701:             * Change the necessary values of the properties file.
0702:             * @param path The path to the properties file.
0703:             */
0704:            protected void changePropertiesFile(String width, String height,
0705:                    String initScreen, String appTitle, boolean useFrames,
0706:                    String newPackageName) {
0707:                projectProperties = new Properties();
0708:                try {
0709:                    projectProperties.load(new BufferedInputStream(
0710:                            new FileInputStream(path + File.separator
0711:                                    + "resources" + File.separator
0712:                                    + XuiDefaults.StartupFile)));
0713:                    projectProperties.setProperty("ClientWidth", width);
0714:                    projectProperties.setProperty("ClientHeight", height);
0715:                    projectProperties.setProperty("StartClass", initScreen);
0716:                    projectProperties.setProperty("Title", appTitle);
0717:                    projectProperties.setProperty("StartPackage",
0718:                            newPackageName);
0719:                    if (useFrames)
0720:                        projectProperties.setProperty("Frames", "frames");
0721:
0722:                    projectProperties.store(new BufferedOutputStream(
0723:                            new FileOutputStream(path + File.separator
0724:                                    + "resources" + File.separator
0725:                                    + XuiDefaults.StartupFile)),
0726:                            "XUI startup properties");
0727:                } catch (IOException ex) {
0728:                    ex.printStackTrace();
0729:                }
0730:            }
0731:
0732:            /**
0733:             * Change the startup property, the associated properties file is saved on
0734:             * each change
0735:             * @param fieldName the name or key of the property to change.
0736:             * @param fieldValue the value to place in the file.
0737:             */
0738:            public void setStartupProperty(String fieldName, String fieldValue) {
0739:                ((XEditorResourceManager) XProjectManager.getResourceManager())
0740:                        .setStartupParam(fieldName, fieldValue);
0741:                try {
0742:                    if (projectProperties == null) {
0743:                        projectProperties = new Properties();
0744:                        FileInputStream fis = new FileInputStream(path
0745:                                + File.separator + "resources" + File.separator
0746:                                + XuiDefaults.StartupFile);
0747:                        projectProperties.load(fis);
0748:                        fis.close();
0749:                    }
0750:                    projectProperties.setProperty(fieldName, fieldValue);
0751:                    FileOutputStream fos = new FileOutputStream(path
0752:                            + File.separator + "resources" + File.separator
0753:                            + XuiDefaults.StartupFile);
0754:                    projectProperties.store(fos, "XUI startup properties");
0755:                    fos.flush();
0756:                    fos.close();
0757:                } catch (IOException ex) {
0758:                    ex.printStackTrace();
0759:                }
0760:            }
0761:
0762:            /**
0763:             * Get the Project path
0764:             * @return the Project path
0765:             */
0766:            public String getPath() {
0767:                return path;
0768:            }
0769:
0770:            /**
0771:             * Get the path for compiled classes
0772:             * @return
0773:             */
0774:            public String getClassPath() {
0775:                return path + File.separatorChar + "classes"
0776:                        + File.separatorChar;
0777:            }
0778:
0779:            /**
0780:             * Save the current project.
0781:             */
0782:            public void save() {
0783:                saveProject();
0784:                saveStartupFiles();
0785:
0786:                ((XEditorStyleManager) XEditorProjectManager.getStyleManager())
0787:                        .saveStyles(path + File.separatorChar + "resources"
0788:                                + File.separatorChar + "styles.xml");
0789:                Enumeration keys = pages.keys();
0790:                while (keys.hasMoreElements()) {
0791:                    String screenName = (String) keys.nextElement();
0792:                    XPageResource pageRes = ((XPageResource) pages
0793:                            .get(screenName));
0794:                    pageRes.save(this , path);
0795:                }
0796:
0797:                pluginManager.save();
0798:            }
0799:
0800:            /**
0801:             * Save the project configuration information
0802:             */
0803:            private void saveProject() {
0804:                try {
0805:                    FileOutputStream fos = new FileOutputStream(path
0806:                            + File.separatorChar + "project.xui");
0807:                    BufferedOutputStream bos = new BufferedOutputStream(fos);
0808:                    NanoXmlWriter writer = new NanoXmlWriter(bos);
0809:
0810:                    XmlElement projectElement = XProjectManager
0811:                            .getXmlParserFactory().createXmlElement("project");
0812:
0813:                    XmlElement childXml = projectElement
0814:                            .createElement("packageName");
0815:                    childXml.setAttribute("name", packageName);
0816:                    projectElement.addChild(childXml);
0817:
0818:                    childXml = projectElement.createElement("swingClient");
0819:                    childXml.setAttribute("value", swingClient ? "true"
0820:                            : "false");
0821:                    projectElement.addChild(childXml);
0822:
0823:                    // So far saved under a single tag but perhaps should be saved on a page by
0824:                    // page basis so that guides can be page specific.
0825:                    // Refactor this code to the guides class!
0826:                    childXml = projectElement.createElement("vertGuides");
0827:                    childXml.setAttribute("name", "pageName");
0828:                    Vector guides = xuiEditor.getGuidePane().getGuideCoords(
0829:                            true);
0830:                    int numGuides = guides.size();
0831:                    String coords = "";
0832:                    for (int i = 0; i < numGuides; i++)
0833:                        coords += ((Integer) guides.elementAt(i)).toString()
0834:                                + ",";
0835:                    childXml.setAttribute("coords", coords);
0836:                    projectElement.addChild(childXml);
0837:
0838:                    childXml = projectElement.createElement("horzGuides");
0839:                    childXml.setAttribute("name", "pageName");
0840:                    guides = xuiEditor.getGuidePane().getGuideCoords(false);
0841:                    numGuides = guides.size();
0842:                    coords = "";
0843:                    for (int i = 0; i < numGuides; i++)
0844:                        coords += ((Integer) guides.elementAt(i)).toString()
0845:                                + ",";
0846:                    childXml.setAttribute("coords", coords);
0847:                    projectElement.addChild(childXml);
0848:
0849:                    writer.write(projectElement, true, 4);
0850:                    bos.close();
0851:                    fos.close();
0852:                } catch (Exception ex) {
0853:                    if (BuildProperties.DEBUG)
0854:                        DebugLogger.logError("Unable to save the project file");
0855:                }
0856:            }
0857:
0858:            protected void saveStartupFiles() {
0859:                try {
0860:                    File htmlFile = new File(path + File.separatorChar
0861:                            + "start.html");
0862:                    FileWriter writer = new FileWriter(htmlFile);
0863:
0864:                    String eol = "\n";
0865:                    writer.write("<HTML>" + eol);
0866:                    writer
0867:                            .write("<APPLET height=480 width=640 archive=\"lib/XuiCore.jar,build/distrib.jar\" code=net.xoetrope.awt.XApplet>"
0868:                                    + eol);
0869:                    writer
0870:                            .write("<PARAM NAME=\"startfile\" VALUE=\"startup.properties\">"
0871:                                    + eol);
0872:                    writer
0873:                            .write("<PARAM NAME=\"StartPackage\" VALUE=\"net.xoetrope.awt\">"
0874:                                    + eol);
0875:                    writer.write("</APPLET>" + eol);
0876:                    writer.write("</HTML>" + eol);
0877:                    writer.flush();
0878:                    writer.close();
0879:
0880:                    File jnlpFile = new File(path + File.separatorChar
0881:                            + "start.jnlp");
0882:                    writer = new FileWriter(jnlpFile);
0883:
0884:                    writer.write("<?xml version=\"1.0\" encoding=\"UTF - 8\"?>"
0885:                            + eol);
0886:                    writer.write("" + eol);
0887:                    writer.write("<!--   created by XuiEditor   -->" + eol);
0888:                    writer
0889:                            .write("<jnlp spec=\"1.0+\" codebase=\"http : //myserver/mydeploymentfolder/\" >"
0890:                                    + eol);
0891:                    writer.write("<information>" + eol);
0892:                    writer.write("  <title>XuiEditor 1.0</title>" + eol);
0893:                    writer.write("  <vendor>My Company</vendor>" + eol);
0894:                    writer
0895:                            .write("  <homepage href=\"http://localhost/mywebfolder\" />"
0896:                                    + eol);
0897:                    writer
0898:                            .write("  <description kind=\"\">MyApplication by Me</description>"
0899:                                    + eol);
0900:                    writer
0901:                            .write("  <description kind=\"tooltip\">XuiEditor 1.0</description>"
0902:                                    + eol);
0903:                    writer.write("  <offline-allowed />" + eol);
0904:                    writer.write("</information>" + eol);
0905:                    writer.write("<resources>" + eol);
0906:                    writer.write("  <j2se version=\"1.1.4+\" />" + eol);
0907:                    writer
0908:                            .write("  <jar href=\"/"
0909:                                    + projectName
0910:                                    + ".jar\" main=\"false\" download=\"eager\" size=\"100131\" />"
0911:                                    + eol);
0912:                    writer
0913:                            .write("  <jar href=\"lib/xuicore.jar\" main=\"true\" download=\"eager\" size=\"100131\" />"
0914:                                    + eol);
0915:                    writer.write("</resources>" + eol);
0916:                    writer
0917:                            .write("<application-desc main-class=\"net.xoetrope.builder.awt.XuiBuilderApplet\" />"
0918:                                    + eol);
0919:                    writer.write("<security>" + eol);
0920:                    writer.write("<all-permissions />" + eol);
0921:                    writer.write("</security>" + eol);
0922:                    writer.write("</jnlp>" + eol);
0923:                    writer.flush();
0924:                    writer.close();
0925:                } catch (IOException ex) {
0926:                    DebugLogger.logError("Unable to save the startup files");
0927:                }
0928:            }
0929:
0930:            protected void savePlugins() {
0931:            }
0932:
0933:            public void setJavaSource(String screenName, String src) {
0934:                XPageResource screen = (XPageResource) pages.get(screenName);
0935:                screen.setJavaSource(src);
0936:            }
0937:
0938:            /**
0939:             * Get the default package name
0940:             * @return the package name
0941:             */
0942:            public String getPackageName() {
0943:                return packageName;
0944:            }
0945:
0946:            public XStyleFactory getStyleFactory() {
0947:                return styleFactory;
0948:            }
0949:
0950:            /**
0951:             * Compile the project
0952:             */
0953:            public void doCompile(XMessageArea msgArea) {
0954:                messageArea = msgArea;
0955:                new Thread(this ).start();
0956:            }
0957:
0958:            public void bundleProject() {
0959:                for (int i = 0; i < pluginManager.getNumPlugins(); i++) {
0960:                    XEditorPlugin plugin = pluginManager.getPlugin(i);
0961:                    String[] jarFilenames = plugin.getDeploymentJarNames();
0962:                    if (jarFilenames != null)
0963:                        for (int j = 0; j < jarFilenames.length; j++) {
0964:                            XEditorUtilities.copyFile(jarFilenames[j], path
0965:                                    + File.separatorChar + "lib"
0966:                                    + File.separatorChar + jarFilenames[j]);
0967:
0968:                        }
0969:                }
0970:                JarBuilder builder = new JarBuilder();
0971:                builder.buildJar("distrib.jar", getPath());
0972:            }
0973:
0974:            public void run() {
0975:                try {
0976:                    save();
0977:
0978:                    Javac javac = new Javac();
0979:                    javac.setBaseDir(path);
0980:                    javac.setDestDir(path + File.separatorChar + "classes");
0981:                    javac.setSrcDir(path + File.separatorChar + "src");
0982:                    javac.execute();
0983:
0984:                    DebugLogger.log("Build/Compilation complete");
0985:
0986:                    // Reload the pages
0987:                    reloadPageResources();
0988:                    XuiEditor.getPageHolder().resetListeners();
0989:                    DebugLogger.log("Pages reloaded");
0990:                } catch (Exception ex) {
0991:                    DebugLogger.logError("Build/Compilation failed: "
0992:                            + ex.getMessage());
0993:                }
0994:            }
0995:
0996:            //--Plugin support------------------------------------------------------------
0997:            public XPluginManager getPluginManager() {
0998:                return pluginManager;
0999:            }
1000:
1001:            public void addPropertiesListener(PropertiesListener listener) {
1002:                xuiEditor.addPropertiesListener(listener);
1003:            }
1004:
1005:            //--End of Plugin support-----------------------------------------------------
1006:
1007:            /**
1008:             * Gets an instance of the resource manager. A new instance is created if required
1009:             * @return the XResourceManager instance
1010:             */
1011:            public XResourceManager getResourceManager() {
1012:                if (resourceManager == null) {
1013:                    throw new java.lang.UnsupportedOperationException(
1014:                            "No XResourceManager instantiated, please check the startup sequence");
1015:                }
1016:
1017:                return resourceManager;
1018:            }
1019:
1020:            /**
1021:             * Get a reference to the XStyleManager. A new instance is created if required
1022:             * @return the style manager
1023:             * @since 1.03
1024:             */
1025:            public XStyleManager getStyleManager() {
1026:                if (styleManager == null) {
1027:                    int i = 0; // Deliberately throw an exception
1028:                    i = 10 / i;
1029:                }
1030:
1031:                return styleManager;
1032:            }
1033:
1034:            /**
1035:             * Check if the application is swing application
1036:             * @return true if this is a swing application
1037:             */
1038:            public boolean isSwingClient() {
1039:                return swingClient;
1040:            }
1041:
1042:            /**
1043:             * Returns the path to the startup file so that plugins can set project info
1044:             * @return String containing the path to the project file
1045:             */
1046:            public String getStartupFilePath() {
1047:                return path + File.separatorChar + "project.xui";
1048:            }
1049:
1050:            /**
1051:             * Gets the editor mode. The mode controls what features are available in the
1052:             * editor
1053:             * @return a constant value indicating the mode
1054:             */
1055:            public int getMode() {
1056:                return mode;
1057:            }
1058:
1059:            /**
1060:             * Sets the editor mode. The mode controls what features are available in the
1061:             * editor
1062:             * @param newMode this can be one of the following values <UL>
1063:             * <LI>NOVICE_MODE - for a minimal user interface and only simple operations</LI>
1064:             * <LI>EXPERT_MODE - for a fulll user interface and all operations</LI>
1065:             * <LI>DEVELOPER_MODE - for the expert interface plus experimental options and possibly unstable features</LI></UL>
1066:             */
1067:            public void setMode(int newMode) {
1068:                mode = newMode;
1069:            }
1070:
1071:            //--Startup file support------------------------------------------------------
1072:            /**
1073:             * Change or add a startup property
1074:             * @param key the object key
1075:             * @param value the object value
1076:             */
1077:            public void setStartupParam(String key, String value) {
1078:                startSettings.remove(key);
1079:                startSettings.put(key, value);
1080:            }
1081:            //--End of Startup file support-----------------------------------------------
1082:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.