Source Code Cross Referenced for SpringUtilities.java in  » XML-UI » SwingML » org » swingml » task » monitoring » 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 » XML UI » SwingML » org.swingml.task.monitoring 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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