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


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2007 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.forms.widgets;
011:
012:        import java.util.Hashtable;
013:        import org.eclipse.swt.SWT;
014:        import org.eclipse.swt.graphics.*;
015:        import org.eclipse.swt.layout.GridLayout;
016:        import org.eclipse.swt.widgets.*;
017:        import org.eclipse.ui.internal.forms.widgets.WrappedPageBook;
018:
019:        /**
020:         * ScrolledPageBook is a class that is capable of stacking several composites
021:         * (pages), while showing one at a time. The content is scrolled if there is
022:         * not enough space to fit it in the client area.
023:         * 
024:         * @since 3.0
025:         */
026:        public class ScrolledPageBook extends SharedScrolledComposite {
027:            private WrappedPageBook pageBook;
028:            private Hashtable pages;
029:            private Composite emptyPage;
030:            private Control currentPage;
031:
032:            /**
033:             * Creates a new instance in the provided parent
034:             * 
035:             * @param parent
036:             */
037:            public ScrolledPageBook(Composite parent) {
038:                this (parent, SWT.H_SCROLL | SWT.V_SCROLL);
039:            }
040:
041:            /**
042:             * Creates a new instance in the provided parent and with the provided
043:             * style.
044:             * 
045:             * @param parent
046:             *            the control parent
047:             * @param style
048:             *            the style to use
049:             */
050:            public ScrolledPageBook(Composite parent, int style) {
051:                super (parent, style);
052:                pageBook = new WrappedPageBook(this , SWT.NULL);
053:                setContent(pageBook);
054:                pages = new Hashtable();
055:                setExpandHorizontal(true);
056:                setExpandVertical(true);
057:                this .addListener(SWT.Traverse, new Listener() {
058:                    public void handleEvent(Event e) {
059:                        switch (e.detail) {
060:                        case SWT.TRAVERSE_ESCAPE:
061:                        case SWT.TRAVERSE_RETURN:
062:                        case SWT.TRAVERSE_TAB_NEXT:
063:                        case SWT.TRAVERSE_TAB_PREVIOUS:
064:                            e.doit = true;
065:                            break;
066:                        }
067:                    }
068:                });
069:            }
070:
071:            /**
072:             * Removes the default size of the composite, allowing the control to
073:             * shrink to the trim.
074:             * 
075:             * @param wHint
076:             *            the width hint
077:             * @param hHint
078:             *            the height hint
079:             * @param changed
080:             *            if <code>true</code>, do not use cached values
081:             */
082:            public Point computeSize(int wHint, int hHint, boolean changed) {
083:                Rectangle trim = computeTrim(0, 0, 10, 10);
084:                return new Point(trim.width, trim.height);
085:            }
086:
087:            /**
088:             * Tests if the page under the provided key is currently in the book.
089:             * 
090:             * @param key
091:             *            the page key
092:             * @return <code>true</code> if page exists, <code>false</code>
093:             *         otherwise.
094:             */
095:            public boolean hasPage(Object key) {
096:                return pages.containsKey(key);
097:            }
098:
099:            /**
100:             * Creates a new page for the provided key. Use the returned composite to
101:             * create children in it.
102:             * 
103:             * @param key
104:             *            the page key
105:             * @return the newly created page composite
106:             */
107:            public Composite createPage(Object key) {
108:                Composite page = createPage();
109:                pages.put(key, page);
110:                return page;
111:            }
112:
113:            /**
114:             * Returns the page book container.
115:             * 
116:             * @return the page book container
117:             */
118:            public Composite getContainer() {
119:                return pageBook;
120:            }
121:
122:            /**
123:             * Registers a page under the privided key to be managed by the page book.
124:             * The page must be a direct child of the page book container.
125:             * 
126:             * @param key
127:             *            the page key
128:             * @param page
129:             *            the page composite to register
130:             * @see #createPage(Object)
131:             * @see #getContainer
132:             */
133:            public void registerPage(Object key, Control page) {
134:                pages.put(key, page);
135:            }
136:
137:            /**
138:             * Removes the page under the provided key from the page book. Does nothing
139:             * if page with that key does not exist.
140:             * 
141:             * @param key
142:             *            the page key.
143:             */
144:            public void removePage(Object key) {
145:                removePage(key, true);
146:            }
147:
148:            /**
149:             * Removes the page under the provided key from the page book. Does nothing
150:             * if page with that key does not exist.
151:             * 
152:             * @param key
153:             *            the page key.
154:             * @param showEmptyPage
155:             * 			  if <code>true</code>, shows the empty page
156:             *            after page removal.
157:             */
158:            public void removePage(Object key, boolean showEmptyPage) {
159:                Control page = (Control) pages.get(key);
160:                if (page != null) {
161:                    pages.remove(key);
162:                    page.dispose();
163:                    if (showEmptyPage)
164:                        showEmptyPage();
165:                }
166:            }
167:
168:            /**
169:             * Shows the page with the provided key and hides the page previously
170:             * showing. Does nothing if the page with that key does not exist.
171:             * 
172:             * @param key
173:             *            the page key
174:             */
175:            public void showPage(Object key) {
176:                Control page = (Control) pages.get(key);
177:                if (page != null) {
178:                    pageBook.showPage(page);
179:                    if (currentPage != null && currentPage != page) {
180:                        // switching pages - force layout
181:                        if (page instanceof  Composite)
182:                            ((Composite) page).layout(false);
183:                    }
184:                    currentPage = page;
185:                } else {
186:                    showEmptyPage();
187:                }
188:                reflow(true);
189:            }
190:
191:            /**
192:             * Shows a page with no children to be used if the desire is to not show
193:             * any registered page.
194:             */
195:            public void showEmptyPage() {
196:                if (emptyPage == null) {
197:                    emptyPage = createPage();
198:                    emptyPage.setLayout(new GridLayout());
199:                }
200:                pageBook.showPage(emptyPage);
201:                currentPage = emptyPage;
202:                reflow(true);
203:            }
204:
205:            /**
206:             * Sets focus on the current page if shown.
207:             */
208:            public boolean setFocus() {
209:                if (currentPage != null)
210:                    return currentPage.setFocus();
211:                return super .setFocus();
212:            }
213:
214:            /**
215:             * Returns the page currently showing.
216:             * 
217:             * @return the current page
218:             */
219:            public Control getCurrentPage() {
220:                return currentPage;
221:            }
222:
223:            private Composite createPage() {
224:                Composite page = new LayoutComposite(pageBook, SWT.NULL);
225:                page.setBackground(getBackground());
226:                page.setForeground(getForeground());
227:                page.setMenu(pageBook.getMenu());
228:                return page;
229:            }
230:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.