Source Code Cross Referenced for SpringUtilities.java in  » Code-Analyzer » findbugs » edu » umd » cs » findbugs » gui2 » 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 » Code Analyzer » findbugs » edu.umd.cs.findbugs.gui2 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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