Source Code Cross Referenced for SwingWebContext.java in  » Web-Framework » swingweb » org » onemind » swingweb » 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 » Web Framework » swingweb » org.onemind.swingweb 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (C) 2004 TiongHiang Lee
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:         * Email: thlee@onemindsoft.org
019:         */
020:
021:        package org.onemind.swingweb;
022:
023:        import java.awt.*;
024:        import java.awt.image.*;
025:        import java.io.*;
026:        import java.net.MalformedURLException;
027:        import java.net.URL;
028:        import java.util.Map;
029:        import java.util.logging.Logger;
030:        import javax.imageio.ImageIO;
031:        import javax.swing.RepaintManager;
032:        import org.onemind.awtbridge.BridgeContext;
033:        import org.onemind.awtbridge.BridgeToolkit;
034:        import org.onemind.commons.java.lang.ConfigurationException;
035:        import org.onemind.swingweb.awt.SwingWebRepaintManager;
036:        import org.onemind.swingweb.image.DummyImageProducer;
037:        import org.onemind.swingweb.image.EmptyImage;
038:        import org.onemind.swingweb.resource.*;
039:        import org.onemind.swingweb.session.SwingWebSession;
040:
041:        /**
042:         * SwingWeb context
043:         * @author TiongHiang Lee (thlee@onemindsoft.org)
044:         * 
045:         */
046:        public class SwingWebContext extends BridgeContext {
047:
048:            /** the logger * */
049:            private static final Logger _logger = Logger
050:                    .getLogger(SwingWebContext.class.getName());
051:
052:            private static final SwingWebRepaintManager DEFAULT_REPAINT_MANGER = new SwingWebRepaintManager();
053:
054:            /** the environments * */
055:            private Map _environment;
056:
057:            /** the url prefix **/
058:            private String _urlPrefix = "";
059:
060:            /** the resource cache **/
061:            private ResourceCache _resCache = new ResourceCache();
062:
063:            private boolean _useSessionCache = false;
064:
065:            /**
066:             * Constructor a thinkient tcontext with given environment
067:             * @param tk the toolkit
068:             * @throws ConfigurationException if there's render config problem
069:             */
070:            public SwingWebContext() {
071:                super ((BridgeToolkit) Toolkit.getDefaultToolkit());
072:                RepaintManager.setCurrentManager(DEFAULT_REPAINT_MANGER);
073:            }
074:
075:            /**
076:             * Set the environment
077:             * @param prop the environment 
078:             */
079:            public final void setEnvironment(Map prop) {
080:                _environment = prop;
081:            }
082:
083:            /**
084:             * Get the environments
085:             * @return the environments
086:             */
087:            public final Map getEnvironment() {
088:                return _environment;
089:            }
090:
091:            /** 
092:             * {@inheritDoc}
093:             */
094:            public int checkImage(Image image, int width, int height,
095:                    ImageObserver observer) {
096:                return ImageObserver.ALLBITS; //always done
097:            }
098:
099:            /** 
100:             * {@inheritDoc}
101:             */
102:            public Image createImage(byte[] imagedata, int imageoffset,
103:                    int imagelength) {
104:                //TODO: improve this
105:                try {
106:                    return ImageIO.read(new ByteArrayInputStream(imagedata,
107:                            imageoffset, imagelength));
108:                } catch (Exception e) {
109:                    _logger.throwing(getClass().getName(), "createImage", e);
110:                    return new EmptyImage(getGraphics());
111:                    //return new BufferedByteImage(getGraphics(), imagedata, imageoffset, imagelength);//_logger.error(e.getMessage(), e);
112:                }
113:            }
114:
115:            /**
116:             * Register a resource 
117:             * @param image the image
118:             * @return the URI for the resource
119:             */
120:            public String registerImageAsResource(Image image) {
121:                String uri = "#";
122:                /*
123:                if (image instanceof URLImage)
124:                {
125:                    URLImage img = (URLImage) image;
126:                    uri = registerResource(new URLResource("image", img.getURL()));
127:                } else if (image instanceof BufferedByteImage)
128:                {
129:                    BufferedByteImage img = (BufferedByteImage) image;
130:                    uri = registerResource(new BufferedByteResource("image", img.getBytes()));
131:                } else 
132:                 */
133:                if (image instanceof  BufferedImage) {
134:                    uri = registerResource(new BufferedImageResource(image
135:                            .toString(), "image", (BufferedImage) image));
136:                }
137:                return uri;
138:            }
139:
140:            private ResourceCache getResourceCache() {
141:                if (_useSessionCache) {
142:                    return ((SwingWebSession) getSession()).getResourceCache();
143:                } else {
144:                    return _resCache;
145:                }
146:            }
147:
148:            /**
149:             * Register the url
150:             * @param image the image
151:             * @return the uri
152:             */
153:            public String registerResource(Resource res) {
154:                String id = _resCache.cacheResource(res);
155:                return _urlPrefix + "?swresource=" + id;
156:            }
157:
158:            /**
159:             * Get the URL object identified by uri 
160:             * @param uri the uri
161:             * @return the URL object
162:             */
163:            public Resource getResource(String uri) {
164:                return (Resource) _resCache.getResource(uri);
165:            }
166:
167:            /** 
168:             * {@inheritDoc}
169:             */
170:            public Image createImage(ImageProducer producer) {
171:                if (producer instanceof  DummyImageProducer) {
172:                    return ((DummyImageProducer) producer).getImage();
173:                } else {
174:                    _logger.warning("Cannot create image with producer "
175:                            + producer + ". Use empty image.");
176:                    return new EmptyImage(getGraphics());
177:                }
178:            }
179:
180:            /** 
181:             * {@inheritDoc}
182:             */
183:            public Image createImage(String filename) {
184:                File f = new File(filename);
185:                if (f.exists()) {
186:                    try {
187:                        return createImage(f.toURL());
188:                    } catch (MalformedURLException e) {
189:                        _logger
190:                                .throwing(getClass().getName(), "createImage",
191:                                        e);
192:                    }
193:                }
194:                _logger.warning("Cannot create image with filename " + filename
195:                        + ". Use empty image.");
196:                return new EmptyImage(getGraphics());
197:            }
198:
199:            /** 
200:             * {@inheritDoc}
201:             */
202:            public Image createImage(URL url) {
203:                try {
204:                    String resId = "image:" + url.toString();
205:                    Resource res = getResourceCache().getResourceByKey(resId);
206:                    if (res != null) {
207:                        return (Image) res.getResourceObject();
208:                    } else {
209:                        BufferedImage buffImg = ImageIO.read(url.openStream());
210:                        if (buffImg != null) {
211:                            registerResource(new BufferedImageResource(resId,
212:                                    "image", buffImg));
213:                        }
214:                        return buffImg;
215:                    }
216:                } catch (IOException e) {
217:                    e.printStackTrace();
218:                    return new EmptyImage(getGraphics());
219:                    //return new URLImage(getGraphics(), url);
220:                }
221:
222:            }
223:
224:            /** 
225:             * {@inheritDoc}
226:             */
227:            public Image getImage(String filename) {
228:                return createImage(filename);
229:            }
230:
231:            /** 
232:             * {@inheritDoc}
233:             */
234:            public Image getImage(URL url) {
235:                return createImage(url);
236:            }
237:
238:            /** 
239:             * {@inheritDoc}
240:             */
241:            public int getScreenResolution() throws HeadlessException {
242:                // TODO: TBI
243:                return 0;
244:            }
245:
246:            /** 
247:             * {@inheritDoc}
248:             */
249:            public Dimension getScreenSize() throws HeadlessException {
250:                // TODO: TBI
251:                return new Dimension(1024, 768);
252:            }
253:
254:            /** 
255:             * {@inheritDoc}
256:             */
257:            public boolean prepareImage(Image image, int width, int height,
258:                    ImageObserver observer) {
259:                //TODO: implement scaling
260:                //always true
261:                return true;
262:            }
263:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.