Source Code Cross Referenced for LayoutCache.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.graphics.Point;
013:        import org.eclipse.swt.widgets.Control;
014:
015:        /**
016:         * Caches the preferred sizes of an array of controls
017:         * 
018:         * @since 3.0
019:         */
020:        public class LayoutCache {
021:            private SizeCache[] caches = new SizeCache[0];
022:
023:            /**
024:             * Creates an empty layout cache
025:             */
026:            public LayoutCache() {
027:            }
028:
029:            /**
030:             * Creates a cache for the given array of controls
031:             * 
032:             * @param controls
033:             */
034:            public LayoutCache(Control[] controls) {
035:                rebuildCache(controls);
036:            }
037:
038:            /**
039:             * Returns the size cache for the given control
040:             * 
041:             * @param idx
042:             * @return
043:             */
044:            public SizeCache getCache(int idx) {
045:                return caches[idx];
046:            }
047:
048:            /**
049:             * Sets the controls that are being cached here. If these are the same
050:             * controls that were used last time, this method does nothing. Otherwise,
051:             * the cache is flushed and a new cache is created for the new controls.
052:             * 
053:             * @param controls
054:             */
055:            public void setControls(Control[] controls) {
056:                // If the number of controls has changed, discard the entire cache
057:                if (controls.length != caches.length) {
058:                    rebuildCache(controls);
059:                    return;
060:                }
061:
062:                for (int idx = 0; idx < controls.length; idx++) {
063:                    caches[idx].setControl(controls[idx]);
064:                }
065:            }
066:
067:            /**
068:             * Creates a new size cache for the given set of controls, discarding any
069:             * existing cache.
070:             * 
071:             * @param controls the controls whose size is being cached
072:             */
073:            private void rebuildCache(Control[] controls) {
074:                SizeCache[] newCache = new SizeCache[controls.length];
075:
076:                for (int idx = 0; idx < controls.length; idx++) {
077:                    // Try to reuse existing caches if possible
078:                    if (idx < caches.length) {
079:                        newCache[idx] = caches[idx];
080:                        newCache[idx].setControl(controls[idx]);
081:                    } else {
082:                        newCache[idx] = new SizeCache(controls[idx]);
083:                    }
084:                }
085:
086:                caches = newCache;
087:            }
088:
089:            /**
090:             * Computes the preferred size of the nth control
091:             * 
092:             * @param controlIndex index of the control whose size will be computed
093:             * @param widthHint width of the control (or SWT.DEFAULT if unknown)
094:             * @param heightHint height of the control (or SWT.DEFAULT if unknown)
095:             * @return the preferred size of the control
096:             */
097:            public Point computeSize(int controlIndex, int widthHint,
098:                    int heightHint) {
099:                return caches[controlIndex].computeSize(widthHint, heightHint);
100:            }
101:
102:            /**
103:             * Flushes the cache for the given control. This should be called if exactly
104:             * one of the controls has changed but the remaining controls remain unmodified
105:             * 
106:             * @param controlIndex
107:             */
108:            public void flush(int controlIndex) {
109:                caches[controlIndex].flush();
110:            }
111:
112:            /**
113:             * Flushes the cache.
114:             */
115:            public void flush() {
116:                for (int idx = 0; idx < caches.length; idx++) {
117:                    caches[idx].flush();
118:                }
119:            }
120:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.