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


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 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.swt.custom;
011:
012:        import org.eclipse.swt.*;
013:        import org.eclipse.swt.graphics.*;
014:        import org.eclipse.swt.widgets.*;
015:
016:        /**
017:         * This Layout stacks all the controls one on top of the other and resizes all controls
018:         * to have the same size and location.
019:         * The control specified in topControl is visible and all other controls are not visible.
020:         * Users must set the topControl value to flip between the visible items and then call 
021:         * layout() on the composite which has the StackLayout.
022:         * 
023:         * <p> Here is an example which places ten buttons in a stack layout and 
024:         * flips between them:
025:         * 
026:         * <pre><code>
027:         * 	public static void main(String[] args) {
028:         * 		Display display = new Display();
029:         * 		Shell shell = new Shell(display);
030:         * 		shell.setLayout(new GridLayout());
031:         * 	
032:         * 		final Composite parent = new Composite(shell, SWT.NONE);
033:         * 		parent.setLayoutData(new GridData(GridData.FILL_BOTH));
034:         * 		final StackLayout layout = new StackLayout();
035:         * 		parent.setLayout(layout);
036:         * 		final Button[] bArray = new Button[10];
037:         * 		for (int i = 0; i &lt; 10; i++) {
038:         * 			bArray[i] = new Button(parent, SWT.PUSH);
039:         * 			bArray[i].setText("Button "+i);
040:         * 		}
041:         * 		layout.topControl = bArray[0];
042:         * 	
043:         * 		Button b = new Button(shell, SWT.PUSH);
044:         * 		b.setText("Show Next Button");
045:         * 		final int[] index = new int[1];
046:         * 		b.addListener(SWT.Selection, new Listener(){
047:         * 			public void handleEvent(Event e) {
048:         * 				index[0] = (index[0] + 1) % 10;
049:         * 				layout.topControl = bArray[index[0]];
050:         * 				parent.layout();
051:         * 			}
052:         * 		});
053:         * 	
054:         * 		shell.open();
055:         * 		while (shell != null && !shell.isDisposed()) {
056:         * 			if (!display.readAndDispatch())
057:         * 				display.sleep(); 
058:         * 		} 	
059:         * 	}
060:         * </code></pre>
061:         */
062:
063:        public class StackLayout extends Layout {
064:
065:            /**
066:             * marginWidth specifies the number of pixels of horizontal margin
067:             * that will be placed along the left and right edges of the layout.
068:             *
069:             * The default value is 0.
070:             */
071:            public int marginWidth = 0;
072:            /**
073:             * marginHeight specifies the number of pixels of vertical margin
074:             * that will be placed along the top and bottom edges of the layout.
075:             *
076:             * The default value is 0.
077:             */
078:            public int marginHeight = 0;
079:
080:            /**
081:             * topControl the Control that is displayed at the top of the stack.
082:             * All other controls that are children of the parent composite will not be visible.
083:             */
084:            public Control topControl;
085:
086:            protected Point computeSize(Composite composite, int wHint,
087:                    int hHint, boolean flushCache) {
088:                Control children[] = composite.getChildren();
089:                int maxWidth = 0;
090:                int maxHeight = 0;
091:                for (int i = 0; i < children.length; i++) {
092:                    Point size = children[i].computeSize(wHint, hHint,
093:                            flushCache);
094:                    maxWidth = Math.max(size.x, maxWidth);
095:                    maxHeight = Math.max(size.y, maxHeight);
096:                }
097:                int width = maxWidth + 2 * marginWidth;
098:                int height = maxHeight + 2 * marginHeight;
099:                if (wHint != SWT.DEFAULT)
100:                    width = wHint;
101:                if (hHint != SWT.DEFAULT)
102:                    height = hHint;
103:                return new Point(width, height);
104:            }
105:
106:            protected boolean flushCache(Control control) {
107:                return true;
108:            }
109:
110:            protected void layout(Composite composite, boolean flushCache) {
111:                Control children[] = composite.getChildren();
112:                Rectangle rect = composite.getClientArea();
113:                rect.x += marginWidth;
114:                rect.y += marginHeight;
115:                rect.width -= 2 * marginWidth;
116:                rect.height -= 2 * marginHeight;
117:                for (int i = 0; i < children.length; i++) {
118:                    children[i].setBounds(rect);
119:                    children[i].setVisible(children[i] == topControl);
120:
121:                }
122:            }
123:
124:            String getName() {
125:                String string = getClass().getName();
126:                int index = string.lastIndexOf('.');
127:                if (index == -1)
128:                    return string;
129:                return string.substring(index + 1, string.length());
130:            }
131:
132:            /**
133:             * Returns a string containing a concise, human-readable
134:             * description of the receiver.
135:             *
136:             * @return a string representation of the layout
137:             */
138:            public String toString() {
139:                String string = getName() + " {";
140:                if (marginWidth != 0)
141:                    string += "marginWidth=" + marginWidth + " ";
142:                if (marginHeight != 0)
143:                    string += "marginHeight=" + marginHeight + " ";
144:                if (topControl != null)
145:                    string += "topControl=" + topControl + " ";
146:                string = string.trim();
147:                string += "}";
148:                return string;
149:            }
150:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.