Source Code Cross Referenced for CacheWrapper.java in  » IDE-Eclipse » ui-workbench » org » eclipse » ui » internal » layout » 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 » IDE Eclipse » ui workbench » org.eclipse.ui.internal.layout 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2004, 2006 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *******************************************************************************/package org.eclipse.ui.internal.layout;
011:
012:        import org.eclipse.swt.SWT;
013:        import org.eclipse.swt.graphics.Point;
014:        import org.eclipse.swt.graphics.Rectangle;
015:        import org.eclipse.swt.widgets.Composite;
016:        import org.eclipse.swt.widgets.Control;
017:        import org.eclipse.swt.widgets.Layout;
018:
019:        /**
020:         * This class wraps a control with a complex computeSize method. It uses caching
021:         * to reduce the number of times the control's computeSize method is called. This
022:         * allows controls (such as Coolbars and wrapping text) with slow computeSize
023:         * operations to be used inside layouts and composites that use inefficient caching.
024:         * <p>
025:         * For example, you want to use Coolbar A inside composite B. Rather than making A
026:         * a direct child of B, place it inside a CacheWrapper and insert the CacheWrapper
027:         * into B. Any layout data that would normally be attached to the control itself
028:         * should be attached to the wrapper instead:
029:         * </p>
030:         * <code>
031:         * 
032:         *   // Unoptimized code
033:         *   Toolbar myToolbar = new Toolbar(someParent, SWT.WRAP);
034:         *   myToolbar.setLayoutData(someLayoutData);
035:         * </code>
036:         * <code>
037:         * 
038:         *   // Optimized code
039:         *   CacheWrapper myWrapper = new CacheWrapper(someParent);
040:         *   Toolbar myToolbar = new Toolbar(myWrapper.getControl(), SWT.WRAP);
041:         *   myWrapper.getControl().setLayoutData(someLayoutData);
042:         * </code>
043:         * <p>
044:         * CacheWrapper creates a Composite which should have exactly one child: the control
045:         * whose size should be cached. Note that CacheWrapper does NOT respect the flushCache
046:         * argument to layout() and computeSize(). This is intentional, since the whole point of
047:         * this class is to workaround layouts with poor caching, and such layouts will typically
048:         * be too eager about flushing the caches of their children. However, this means that you
049:         * MUST manually call flushCache() whenver the child's preferred size changes (and before
050:         * the parent is layed out).  
051:         * </p>
052:         * 
053:         * @since 3.0
054:         */
055:        public class CacheWrapper {
056:            private Composite proxy;
057:
058:            private SizeCache cache = new SizeCache();
059:
060:            private Rectangle lastBounds = new Rectangle(0, 0, 0, 0);
061:
062:            private class WrapperLayout extends Layout implements 
063:                    ICachingLayout {
064:                protected Point computeSize(Composite composite, int wHint,
065:                        int hHint, boolean flushCache) {
066:                    Control[] children = composite.getChildren();
067:                    if (children.length != 1) {
068:                        return new Point(0, 0);
069:                    }
070:
071:                    cache.setControl(children[0]);
072:
073:                    return cache.computeSize(wHint, hHint);
074:                }
075:
076:                protected void layout(Composite composite, boolean flushCache) {
077:                    Control[] children = composite.getChildren();
078:                    if (children.length != 1) {
079:                        return;
080:                    }
081:
082:                    Control child = children[0];
083:                    Rectangle newBounds = composite.getClientArea();
084:                    if (!newBounds.equals(lastBounds)) {
085:                        child.setBounds(newBounds);
086:                        lastBounds = newBounds;
087:                    }
088:
089:                }
090:
091:                /* (non-Javadoc)
092:                 * @see org.eclipse.ui.internal.layout.ICachingLayout#flush(org.eclipse.swt.widgets.Control)
093:                 */
094:                public void flush(Control dirtyControl) {
095:                    CacheWrapper.this .flushCache();
096:                }
097:            }
098:
099:            /**
100:             * Creates a <code>CacheWrapper</code> with the given parent
101:             * 
102:             * @param parent
103:             */
104:            public CacheWrapper(Composite parent) {
105:                proxy = new Composite(parent, SWT.NONE);
106:
107:                proxy.setLayout(new WrapperLayout());
108:            }
109:
110:            /**
111:             * Flush the cache. Call this when the child has changed in order to force
112:             * the size to be recomputed in the next resize event.
113:             */
114:            public void flushCache() {
115:                cache.flush();
116:            }
117:
118:            /**
119:             * Use this as the parent of the real control.
120:             * 
121:             * @return the proxy contol. It should be given exactly one child.
122:             */
123:            public Composite getControl() {
124:                return proxy;
125:            }
126:
127:            /**
128:             * Dispose of any widgets created by this wrapper.
129:             */
130:            public void dispose() {
131:                if (proxy != null) {
132:                    proxy.dispose();
133:                    proxy = null;
134:                }
135:            }
136:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.