Source Code Cross Referenced for VerticalLayout.java in  » Testing » jakarta-jmeter » org » apache » jorphan » gui » 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 » Testing » jakarta jmeter » org.apache.jorphan.gui.layout 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *   http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         * 
017:         */
018:
019:        package org.apache.jorphan.gui.layout;
020:
021:        import java.awt.Component;
022:        import java.awt.Container;
023:        import java.awt.Dimension;
024:        import java.awt.Insets;
025:        import java.awt.LayoutManager;
026:        import java.io.Serializable;
027:
028:        /**
029:         * A vertical layout manager similar to java.awt.FlowLayout. Like FlowLayout
030:         * components do not expand to fill available space except when the horizontal
031:         * alignment is <code>BOTH</code> in which case components are stretched
032:         * horizontally. Unlike FlowLayout, components will not wrap to form another
033:         * column if there isn't enough space vertically. VerticalLayout can optionally
034:         * anchor components to the top or bottom of the display area or center them
035:         * between the top and bottom. Revision date 04 April 1999
036:         * 
037:         * @author Colin Mummery e-mail:equitysoft@iname.com
038:         *         Homepage:www.kagi.com/equitysoft - Based on 'FlexLayout' in Java
039:         *         class libraries Vol 2 Chan/Lee Addison-Wesley 1998
040:         * @version $Revision: 493784 $
041:         */
042:        public class VerticalLayout implements  LayoutManager, Serializable {
043:            /**
044:             * The horizontal alignment constant that designates centering. Also used to
045:             * designate center anchoring.
046:             */
047:            public final static int CENTER = 0;
048:
049:            /**
050:             * The horizontal alignment constant that designates right justification.
051:             */
052:            public final static int RIGHT = 1;
053:
054:            /**
055:             * The horizontal alignment constant that designates left justification.
056:             */
057:            public final static int LEFT = 2;
058:
059:            /**
060:             * The horizontal alignment constant that designates stretching the
061:             * component horizontally.
062:             */
063:            public final static int BOTH = 3;
064:
065:            /**
066:             * The anchoring constant that designates anchoring to the top of the
067:             * display area.
068:             */
069:            public final static int TOP = 1;
070:
071:            /**
072:             * The anchoring constant that designates anchoring to the bottom of the
073:             * display area.
074:             */
075:            public final static int BOTTOM = 2;
076:
077:            /** The vertical vgap between components...defaults to 5. */
078:            private int vgap;
079:
080:            /** LEFT, RIGHT, CENTER or BOTH...how the components are justified. */
081:            private int alignment;
082:
083:            /**
084:             * TOP, BOTTOM or CENTER ...where are the components positioned in an
085:             * overlarge space.
086:             */
087:            private int anchor;
088:
089:            // Constructors
090:            /**
091:             * Constructs an instance of VerticalLayout with a vertical vgap of 5
092:             * pixels, horizontal centering and anchored to the top of the display area.
093:             */
094:            public VerticalLayout() {
095:                this (5, CENTER, TOP);
096:            }
097:
098:            /**
099:             * Constructs a VerticalLayout instance with horizontal centering, anchored
100:             * to the top with the specified vgap.
101:             * 
102:             * @param vgap
103:             *            an int value indicating the vertical seperation of the
104:             *            components
105:             */
106:            public VerticalLayout(int vgap) {
107:                this (vgap, CENTER, TOP);
108:            }
109:
110:            /**
111:             * Constructs a VerticalLayout instance anchored to the top with the
112:             * specified vgap and horizontal alignment.
113:             * 
114:             * @param vgap
115:             *            an int value indicating the vertical seperation of the
116:             *            components
117:             * @param alignment
118:             *            an int value which is one of <code>RIGHT, LEFT,
119:             *                   CENTER, BOTH</code>
120:             *            for the horizontal alignment.
121:             */
122:            public VerticalLayout(int vgap, int alignment) {
123:                this (vgap, alignment, TOP);
124:            }
125:
126:            /**
127:             * Constructs a VerticalLayout instance with the specified vgap, horizontal
128:             * alignment and anchoring
129:             * 
130:             * @param vgap
131:             *            an int value indicating the vertical seperation of the
132:             *            components
133:             * @param alignment
134:             *            an int value which is one of <code>RIGHT, LEFT, CENTER,
135:             *                  BOTH</code>
136:             *            for the horizontal alignment.
137:             * @param anchor
138:             *            an int value which is one of <code>TOP, BOTTOM,
139:             *                  CENTER</code>
140:             *            indicating where the components are to appear if the display
141:             *            area exceeds the minimum necessary.
142:             */
143:            public VerticalLayout(int vgap, int alignment, int anchor) {
144:                this .vgap = vgap;
145:                this .alignment = alignment;
146:                this .anchor = anchor;
147:            }
148:
149:            /**
150:             * Lays out the container.
151:             */
152:            public void layoutContainer(Container parent) {
153:                Insets insets = parent.getInsets();
154:                // NOTUSED Dimension dim = layoutSize(parent, false);
155:                synchronized (parent.getTreeLock()) {
156:                    int n = parent.getComponentCount();
157:                    Dimension pd = parent.getSize();
158:                    int y = 0;
159:                    // work out the total size
160:                    for (int i = 0; i < n; i++) {
161:                        Component c = parent.getComponent(i);
162:                        Dimension d = c.getPreferredSize();
163:                        y += d.height + vgap;
164:                    }
165:                    y -= vgap; // otherwise there's a vgap too many
166:                    // Work out the anchor paint
167:                    if (anchor == TOP) {
168:                        y = insets.top;
169:                    } else if (anchor == CENTER) {
170:                        y = (pd.height - y) / 2;
171:                    } else {
172:                        y = pd.height - y - insets.bottom;
173:                    }
174:                    // do layout
175:                    for (int i = 0; i < n; i++) {
176:                        Component c = parent.getComponent(i);
177:                        Dimension d = c.getPreferredSize();
178:                        int x = insets.left;
179:                        int wid = d.width;
180:                        if (alignment == CENTER) {
181:                            x = (pd.width - d.width) / 2;
182:                        } else if (alignment == RIGHT) {
183:                            x = pd.width - d.width - insets.right;
184:                        } else if (alignment == BOTH) {
185:                            wid = pd.width - insets.left - insets.right;
186:                        }
187:                        c.setBounds(x, y, wid, d.height);
188:                        y += d.height + vgap;
189:                    }
190:                }
191:            }
192:
193:            public Dimension minimumLayoutSize(Container parent) {
194:                return layoutSize(parent, true);
195:            }
196:
197:            public Dimension preferredLayoutSize(Container parent) {
198:                return layoutSize(parent, false);
199:            }
200:
201:            /**
202:             * Not used by this class.
203:             */
204:            public void addLayoutComponent(String name, Component comp) {
205:            }
206:
207:            /**
208:             * Not used by this class.
209:             */
210:            public void removeLayoutComponent(Component comp) {
211:            }
212:
213:            public String toString() {
214:                return getClass().getName() + "[vgap=" + vgap + " align="
215:                        + alignment + " anchor=" + anchor + "]";
216:            }
217:
218:            private Dimension layoutSize(Container parent, boolean minimum) {
219:                Dimension dim = new Dimension(0, 0);
220:                Dimension d;
221:                synchronized (parent.getTreeLock()) {
222:                    int n = parent.getComponentCount();
223:                    for (int i = 0; i < n; i++) {
224:                        Component c = parent.getComponent(i);
225:                        if (c.isVisible()) {
226:                            d = minimum ? c.getMinimumSize() : c
227:                                    .getPreferredSize();
228:                            dim.width = Math.max(dim.width, d.width);
229:                            dim.height += d.height;
230:                            if (i > 0) {
231:                                dim.height += vgap;
232:                            }
233:                        }
234:                    }
235:                }
236:                Insets insets = parent.getInsets();
237:                dim.width += insets.left + insets.right;
238:                dim.height += insets.top + insets.bottom + vgap + vgap;
239:                return dim;
240:            }
241:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.