Source Code Cross Referenced for DefaultProjectManager.java in  » Swing-Library » abeille-forms-designer » com » jeta » swingbuilder » project » 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 » Swing Library » abeille forms designer » com.jeta.swingbuilder.project 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (C) 2005 Jeff Tassin
003:         *
004:         * This library is free software; you can redistribute it and/or
005:         * modify it under the terms of the GNU Lesser General Public
006:         * License as published by the Free Software Foundation; either
007:         * version 2.1 of the License, or (at your option) any later version.
008:         *
009:         * This library is distributed in the hope that it will be useful,
010:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
012:         * Lesser General Public License for more details.
013:         *
014:         * You should have received a copy of the GNU Lesser General Public
015:         * License along with this library; if not, write to the Free Software
016:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
017:         */
018:
019:        package com.jeta.swingbuilder.project;
020:
021:        import java.awt.Toolkit;
022:        import java.awt.image.BufferedImage;
023:        import java.io.File;
024:        import java.util.Collection;
025:        import java.util.Hashtable;
026:        import java.util.Iterator;
027:        import java.util.LinkedList;
028:
029:        import javax.swing.ImageIcon;
030:
031:        import com.jeta.forms.gui.common.FormUtils;
032:        import com.jeta.forms.logger.FormsLogger;
033:        import com.jeta.forms.project.ProjectManager;
034:        import com.jeta.forms.project.RuntimeProjectManager;
035:        import com.jeta.swingbuilder.gui.project.UserPreferencesNames;
036:        import com.jeta.swingbuilder.interfaces.userprops.TSUserPropertiesUtils;
037:        import com.jeta.swingbuilder.store.ProjectModel;
038:
039:        /**
040:         * Concrete implementation of ProjectManager
041:         * 
042:         * @author Jeff Tassin
043:         */
044:        public class DefaultProjectManager implements  ProjectManager {
045:            /**
046:             * A list of source directories for this project. We use source directories
047:             * to locate forms when given a relative path.
048:             */
049:            private LinkedList m_source_dirs = new LinkedList();
050:
051:            /** an empty icon if a resource cannot be loaded */
052:            private static ImageIcon m_empty_icon;
053:
054:            /** cache of images */
055:            private Hashtable m_image_cache = new Hashtable();
056:
057:            /**
058:             * This is used to locate resources for forms used by the Abeille Form
059:             * Builder itself.
060:             */
061:            private RuntimeProjectManager m_runtime = new RuntimeProjectManager();
062:
063:            /**
064:             * The current project
065:             */
066:            private ProjectModel m_project;
067:
068:            /**
069:             * ctor
070:             */
071:            public DefaultProjectManager() {
072:
073:            }
074:
075:            /**
076:             * ctor
077:             */
078:            public DefaultProjectManager(ProjectModel pmodel) {
079:                setProject(pmodel);
080:            }
081:
082:            /**
083:             * Clears any cached resources
084:             */
085:            public void clearResourceCache() {
086:                m_image_cache.clear();
087:            }
088:
089:            /**
090:             * @return a valid absolute path given a relative path. Searches the
091:             *         registered source paths and determines if the relativePath
092:             *         (includes filename) exists within one of the source paths.
093:             */
094:            public String getAbsolutePath(String relativePath) {
095:                // FormsLogger.debug( "DefaultProjectManager.getAbsoultePath: " +
096:                // relativePath );
097:                if (relativePath == null)
098:                    relativePath = "";
099:
100:                relativePath = FormUtils.fixPath(relativePath);
101:
102:                if (isJETAResource(relativePath))
103:                    return m_runtime.getAbsolutePath(relativePath);
104:
105:                Iterator iter = m_source_dirs.iterator();
106:                while (iter.hasNext()) {
107:                    String path = (String) iter.next();
108:                    File f = new File(path + File.separatorChar + relativePath);
109:                    if (f.exists()) {
110:                        if (f.isFile()) {
111:                            return f.getPath();
112:                        } else {
113:                            // should never happen
114:                            assert (false);
115:                        }
116:                    }
117:                }
118:                return null;
119:            }
120:
121:            /**
122:             * @return the current project
123:             */
124:            public ProjectModel getProject() {
125:                return m_project;
126:            }
127:
128:            /**
129:             * @return a valid relative package/filename given an absolute path. The
130:             *         relative path is determined using the source directories. If the
131:             *         path does not lie within a source directory, null is returned.
132:             */
133:            public String getRelativePath(String absPath) {
134:                if (isJETAResource(absPath))
135:                    return m_runtime.getRelativePath(absPath);
136:
137:                if (absPath == null)
138:                    return null;
139:
140:                Iterator iter = m_source_dirs.iterator();
141:                while (iter.hasNext()) {
142:                    String src_path = (String) iter.next();
143:                    if (absPath.indexOf(src_path) == 0) {
144:                        return absPath.substring(src_path.length() + 1, absPath
145:                                .length());
146:                    }
147:                }
148:                return null;
149:            }
150:
151:            /**
152:             * @return true if the given resource is a JETA resource for the Abeille
153:             *         Forms Builder. JETA resources begin with "com.jeta" or
154:             *         "jeta.resources".
155:             */
156:            private boolean isJETAResource(String resource) {
157:                if (FormUtils.isDesignMode())
158:                    return false;
159:                else if (resource == null)
160:                    return false;
161:                else if (resource.indexOf("com/jeta") >= 0)
162:                    return true;
163:                else if (resource.indexOf("jeta.resources") >= 0)
164:                    return true;
165:                else
166:                    return false;
167:            }
168:
169:            /**
170:             * @return true if the given absolute path lies within one of the source
171:             *         directories.
172:             */
173:            public boolean isValidAbsolutePath(String path) {
174:                if (isJETAResource(path))
175:                    return m_runtime.isValidAbsolutePath(path);
176:
177:                Iterator iter = m_source_dirs.iterator();
178:                while (iter.hasNext()) {
179:                    String src_path = (String) iter.next();
180:                    if (path.indexOf(src_path) == 0) {
181:                        return true;
182:                    }
183:                }
184:                return false;
185:            }
186:
187:            /**
188:             * @return true if the given relative resource exists and is a file
189:             */
190:            public boolean isValidResource(String relpath) {
191:                // System.out.println( "DefaultProjectmanager.isValidResource: " +
192:                // relpath
193:                // );
194:                if (relpath == null)
195:                    return false;
196:
197:                if (relpath.length() > 0) {
198:                    if (relpath.charAt(0) == '\\' || relpath.charAt(0) == '/') {
199:                        relpath = relpath.substring(1, relpath.length());
200:                    }
201:                }
202:
203:                Iterator iter = m_source_dirs.iterator();
204:                while (iter.hasNext()) {
205:                    String src_path = (String) iter.next();
206:                    String full_path = src_path + File.separatorChar + relpath;
207:
208:                    // System.out.println( "DefaultProjectmanager.isValidResource:
209:                    // full_path: " + full_path );
210:
211:                    File f = new File(full_path);
212:                    if (f.isFile())
213:                        return true;
214:                }
215:                return false;
216:            }
217:
218:            /**
219:             * Utility method that loads an image from the CLASSPATH.
220:             * 
221:             * @param imageName
222:             *            the subdirectory and name of image file (i.e.
223:             *            images/edit16.gif )
224:             */
225:            public ImageIcon loadImage(String imageName) {
226:                ImageIcon result = null;
227:                boolean cache_images = TSUserPropertiesUtils.getBoolean(
228:                        UserPreferencesNames.ID_CACHE_IMAGES, true);
229:                if (cache_images) {
230:                    synchronized (this ) {
231:                        result = (ImageIcon) m_image_cache.get(imageName);
232:                        if (result != null)
233:                            return result;
234:                    }
235:                }
236:
237:                if (isJETAResource(imageName)) {
238:                    result = m_runtime.loadImage(imageName);
239:                } else {
240:                    try {
241:                        String path = getAbsolutePath(imageName);
242:                        if (path != null) {
243:                            /**
244:                             * The toolkit should be used to create the image, otherwise
245:                             * it may be pulled from the toolkit image cache.
246:                             */
247:                            Toolkit toolkit = Toolkit.getDefaultToolkit();
248:                            ImageIcon image = new ImageIcon(toolkit
249:                                    .createImage(path));
250:                            result = image;
251:                        }
252:                    } catch (Exception e) {
253:                        e.printStackTrace();
254:                    }
255:
256:                    if (result == null && m_empty_icon == null) {
257:                        int width = 16;
258:                        int height = 16;
259:                        BufferedImage img = new BufferedImage(width, height,
260:                                BufferedImage.TYPE_INT_RGB);
261:                        java.awt.Graphics2D bg = img.createGraphics();
262:                        bg.setColor(javax.swing.UIManager.getColor("control"));
263:                        bg.fillRect(0, 0, width, height);
264:                        bg.setColor(java.awt.Color.red);
265:                        bg.drawRect(0, 0, width - 1, height - 1);
266:                        bg.drawLine(0, 0, width - 1, height - 1);
267:                        bg.drawLine(0, height - 1, width - 1, 0);
268:                        bg.dispose();
269:                        m_empty_icon = new ImageIcon(img);
270:                    }
271:                }
272:
273:                if (result == null)
274:                    result = m_empty_icon;
275:                else {
276:                    if (cache_images) {
277:                        synchronized (this ) {
278:                            m_image_cache.put(imageName, result);
279:                        }
280:                    }
281:                }
282:                return result;
283:            }
284:
285:            /**
286:             * Sets the current project
287:             */
288:            public void setProject(ProjectModel pmodel) {
289:                m_project = pmodel;
290:                m_source_dirs.clear();
291:                if (pmodel != null) {
292:                    File rootDir = pmodel.getProjectRootDir();
293:
294:                    Collection src_paths = pmodel.getSourcePaths();
295:                    Iterator iter = src_paths.iterator();
296:                    while (iter.hasNext()) {
297:                        String src_path = (String) iter.next();
298:                        if (src_path.equals("."))
299:                            src_path = rootDir.getPath();
300:
301:                        if (File.separatorChar == '/')
302:                            src_path = src_path.replace('\\',
303:                                    File.separatorChar);
304:                        else if (File.separatorChar == '\\')
305:                            src_path = src_path
306:                                    .replace('/', File.separatorChar);
307:
308:                        File f = new File(rootDir, src_path);
309:                        try {
310:                            if (f.isDirectory()) {
311:                                FormsLogger
312:                                        .debug("DefaultProjectManager loading (rel)project path: "
313:                                                + f.getCanonicalPath());
314:                                m_source_dirs.add(f.getCanonicalPath());
315:                            } else {
316:                                f = new File(src_path);
317:                                if (f.isDirectory()) {
318:                                    FormsLogger
319:                                            .debug("DefaultProjectManager loading (abs)project path: "
320:                                                    + src_path);
321:                                    m_source_dirs.add(src_path);
322:                                } else {
323:                                    System.err
324:                                            .println("unable to load project directory: "
325:                                                    + src_path);
326:                                }
327:                            }
328:                        } catch (Exception e) {
329:                            FormsLogger.severe(e);
330:                        }
331:                    }
332:                }
333:            }
334:
335:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.