Source Code Cross Referenced for SpringUtilities.java in  » Workflow-Engines » obe-1.0 » org » obe » util » 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 » Workflow Engines » obe 1.0 » org.obe.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.obe.util;
002:
003:        import javax.swing.*;
004:        import java.awt.*;
005:
006:        /**
007:         * Spring layout utilities, courtesy of Sun Microsystems.
008:         */
009:        public final class SpringUtilities {
010:            /**
011:             * A debugging utility that prints to stdout the component's minimum,
012:             * preferred, and maximum sizes.
013:             */
014:            public static void printSizes(Component comp) {
015:                System.out.println("minimumSize = " + comp.getMinimumSize());
016:                System.out
017:                        .println("preferredSize = " + comp.getPreferredSize());
018:                System.out.println("maximumSize = " + comp.getMaximumSize());
019:            }
020:
021:            /**
022:             * Aligns the first <code>rows</code> * <code>cols</code> components of
023:             * <code>parent</code> in a grid. Each component is as big as the maximum
024:             * preferred width and height of the components. The parent is made just big
025:             * enough to fit them all.
026:             *
027:             * @param rows     number of rows
028:             * @param cols     number of columns
029:             * @param initialX x location to start the grid at
030:             * @param initialY y location to start the grid at
031:             * @param xPad     x padding between cells
032:             * @param yPad     y padding between cells
033:             */
034:            public static void makeGrid(Container parent, int rows, int cols,
035:                    int initialX, int initialY, int xPad, int yPad) {
036:
037:                SpringLayout layout;
038:                try {
039:                    layout = (SpringLayout) parent.getLayout();
040:                } catch (ClassCastException exc) {
041:                    System.err
042:                            .println("The first argument to makeGrid must use SpringLayout.");
043:                    return;
044:                }
045:
046:                Spring xPadSpring = Spring.constant(xPad);
047:                Spring yPadSpring = Spring.constant(yPad);
048:                Spring initialXSpring = Spring.constant(initialX);
049:                Spring initialYSpring = Spring.constant(initialY);
050:                int max = rows * cols;
051:
052:                // Calculate Springs that are the max of the width/height so that all
053:                // cells have the same size.
054:                Spring maxWidthSpring = layout.getConstraints(
055:                        parent.getComponent(0)).getWidth();
056:                Spring maxHeightSpring = layout.getConstraints(
057:                        parent.getComponent(0)).getWidth();
058:                for (int i = 1; i < max; i++) {
059:                    SpringLayout.Constraints cons = layout
060:                            .getConstraints(parent.getComponent(i));
061:
062:                    maxWidthSpring = Spring
063:                            .max(maxWidthSpring, cons.getWidth());
064:                    maxHeightSpring = Spring.max(maxHeightSpring, cons
065:                            .getHeight());
066:                }
067:
068:                // Apply the new width/height Spring. This forces all the components to
069:                // have the same size.
070:                for (int i = 0; i < max; i++) {
071:                    SpringLayout.Constraints cons = layout
072:                            .getConstraints(parent.getComponent(i));
073:
074:                    cons.setWidth(maxWidthSpring);
075:                    cons.setHeight(maxHeightSpring);
076:                }
077:
078:                // Then adjust the x/y constraints of all the cells so that they are
079:                // aligned in a grid.
080:                SpringLayout.Constraints lastCons = null;
081:                SpringLayout.Constraints lastRowCons = null;
082:                for (int i = 0; i < max; i++) {
083:                    SpringLayout.Constraints cons = layout
084:                            .getConstraints(parent.getComponent(i));
085:                    if (i % cols == 0) { //start of new row
086:                        lastRowCons = lastCons;
087:                        cons.setX(initialXSpring);
088:                    } else { //x position depends on previous component
089:                        cons.setX(Spring.sum(lastCons
090:                                .getConstraint(SpringLayout.EAST), xPadSpring));
091:                    }
092:
093:                    if (i / cols == 0) { //first row
094:                        cons.setY(initialYSpring);
095:                    } else { //y position depends on previous row
096:                        cons
097:                                .setY(Spring.sum(lastRowCons
098:                                        .getConstraint(SpringLayout.SOUTH),
099:                                        yPadSpring));
100:                    }
101:                    lastCons = cons;
102:                }
103:
104:                // Set the parent's size.
105:                SpringLayout.Constraints pCons = layout.getConstraints(parent);
106:                pCons.setConstraint(SpringLayout.SOUTH, Spring.sum(Spring
107:                        .constant(yPad), lastCons
108:                        .getConstraint(SpringLayout.SOUTH)));
109:                pCons.setConstraint(SpringLayout.EAST, Spring.sum(Spring
110:                        .constant(xPad), lastCons
111:                        .getConstraint(SpringLayout.EAST)));
112:            }
113:
114:            /* Used by makeCompactGrid. */
115:            private static SpringLayout.Constraints getConstraintsForCell(
116:                    int row, int col, Container parent, int cols) {
117:
118:                SpringLayout layout = (SpringLayout) parent.getLayout();
119:                Component comp = parent.getComponent(row * cols + col);
120:                return layout.getConstraints(comp);
121:            }
122:
123:            /**
124:             * Aligns the first <code>rows</code> * <code>cols</code> components of
125:             * <code>parent</code> in a grid. Each component in a column is as wide as
126:             * the maximum preferred width of the components in that column; height is
127:             * similarly determined for each row. The parent is made just big enough to
128:             * fit them all.
129:             *
130:             * @param rows     number of rows
131:             * @param cols     number of columns
132:             * @param initialX x location to start the grid at
133:             * @param initialY y location to start the grid at
134:             * @param xPad     x padding between cells
135:             * @param yPad     y padding between cells
136:             */
137:            public static void makeCompactGrid(Container parent, int rows,
138:                    int cols, int initialX, int initialY, int xPad, int yPad) {
139:
140:                SpringLayout layout;
141:                try {
142:                    layout = (SpringLayout) parent.getLayout();
143:                } catch (ClassCastException exc) {
144:                    System.err
145:                            .println("The first argument to makeCompactGrid must use SpringLayout.");
146:                    return;
147:                }
148:
149:                // Align all cells in each column and make them the same width.
150:                Spring x = Spring.constant(initialX);
151:                for (int col = 0; col < cols; col++) {
152:                    Spring width = Spring.constant(0);
153:                    for (int r = 0; r < rows; r++) {
154:                        width = Spring.max(width, getConstraintsForCell(r, col,
155:                                parent, cols).getWidth());
156:                    }
157:                    for (int r = 0; r < rows; r++) {
158:                        SpringLayout.Constraints constraints = getConstraintsForCell(
159:                                r, col, parent, cols);
160:                        constraints.setX(x);
161:                        constraints.setWidth(width);
162:                    }
163:                    x = Spring.sum(x, Spring.sum(width, Spring.constant(xPad)));
164:                }
165:
166:                // Align all cells in each row and make them the same height.
167:                Spring y = Spring.constant(initialY);
168:                for (int row = 0; row < rows; row++) {
169:                    Spring height = Spring.constant(0);
170:                    for (int col = 0; col < cols; col++) {
171:                        height = Spring.max(height, getConstraintsForCell(row,
172:                                col, parent, cols).getHeight());
173:                    }
174:                    for (int col = 0; col < cols; col++) {
175:                        SpringLayout.Constraints constraints = getConstraintsForCell(
176:                                row, col, parent, cols);
177:                        constraints.setY(y);
178:                        constraints.setHeight(height);
179:                    }
180:                    y = Spring
181:                            .sum(y, Spring.sum(height, Spring.constant(yPad)));
182:                }
183:
184:                // Set the parent's size.
185:                SpringLayout.Constraints pCons = layout.getConstraints(parent);
186:                pCons.setConstraint(SpringLayout.SOUTH, y);
187:                pCons.setConstraint(SpringLayout.EAST, x);
188:            }
189:
190:            private SpringUtilities() {
191:            }
192:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.