Source Code Cross Referenced for FormDebugUtils.java in  » Swing-Library » abeille-forms-designer » com » jgoodies » forms » debug » 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 » Swing Library » abeille forms designer » com.jgoodies.forms.debug 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2002-2004 JGoodies Karsten Lentzsch. All Rights Reserved.
003:         *
004:         * Redistribution and use in source and binary forms, with or without 
005:         * modification, are permitted provided that the following conditions are met:
006:         * 
007:         *  o Redistributions of source code must retain the above copyright notice, 
008:         *    this list of conditions and the following disclaimer. 
009:         *     
010:         *  o Redistributions in binary form must reproduce the above copyright notice, 
011:         *    this list of conditions and the following disclaimer in the documentation 
012:         *    and/or other materials provided with the distribution. 
013:         *     
014:         *  o Neither the name of JGoodies Karsten Lentzsch nor the names of 
015:         *    its contributors may be used to endorse or promote products derived 
016:         *    from this software without specific prior written permission. 
017:         *     
018:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
019:         * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
020:         * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
021:         * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 
022:         * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
023:         * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
024:         * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
025:         * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
026:         * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
027:         * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 
028:         * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
029:         */
030:
031:        package com.jgoodies.forms.debug;
032:
033:        import java.awt.Component;
034:        import java.awt.Container;
035:
036:        import javax.swing.JLabel;
037:
038:        import com.jgoodies.forms.layout.CellConstraints;
039:        import com.jgoodies.forms.layout.ColumnSpec;
040:        import com.jgoodies.forms.layout.FormLayout;
041:        import com.jgoodies.forms.layout.RowSpec;
042:
043:        /**
044:         * Provides static methods that help you understand and fix layout problems when
045:         * using the {@link FormLayout}. Dumps information about the layout grid,
046:         * layout groups and cell constraints to the console.
047:         * <p>
048:         * 
049:         * Implicit values are mapped to concrete. For example, implicit alignments in
050:         * column and row specifications will be visible. And cell constraint alignments
051:         * that use or override the column and row defaults are visible too.
052:         * 
053:         * <pre>
054:         * ColumnSpec(&quot;p&quot;)   -&gt; ColumnSpec(&quot;fill:pref:0&quot;);
055:         * ColumnSpec(&quot;p:1&quot;) -&gt; ColumnSpec(&quot;fill:pref:1&quot;);
056:         * 
057:         * RowSpec(&quot;p&quot;)      -&gt; RowSpec(&quot;center:pref:0&quot;);
058:         * RowSpec(&quot;p:1&quot;)    -&gt; RowSpec(&quot;center:pref:1&quot;);
059:         * </pre>
060:         * 
061:         * @author Karsten Lentzsch
062:         * @version $Revision: 1.2 $
063:         * 
064:         * @see FormDebugPanel
065:         */
066:        public final class FormDebugUtils {
067:
068:            // Console Dump *********************************************************
069:
070:            /**
071:             * Dumps all layout state to the console: column and row specifications,
072:             * column and row groups, grid bounds and cell constraints.
073:             * 
074:             * @param container
075:             *            the layout container
076:             */
077:            public static void dumpAll(Container container) {
078:                if (!(container.getLayout() instanceof  FormLayout)) {
079:                    System.out
080:                            .println("The container's layout is not a FormLayout.");
081:                    return;
082:                }
083:                FormLayout layout = (FormLayout) container.getLayout();
084:                dumpColumnSpecs(layout);
085:                dumpRowSpecs(layout);
086:                System.out.println();
087:                dumpColumnGroups(layout);
088:                dumpRowGroups(layout);
089:                System.out.println();
090:                dumpConstraints(container);
091:                dumpGridBounds(container);
092:            }
093:
094:            /**
095:             * Dumps the layout's column specifications to the console.
096:             * 
097:             * @param layout
098:             *            the <code>FormLayout</code> to inspect
099:             */
100:            public static void dumpColumnSpecs(FormLayout layout) {
101:                System.out.print("COLUMN SPECS:");
102:                for (int col = 1; col <= layout.getColumnCount(); col++) {
103:                    ColumnSpec colSpec = layout.getColumnSpec(col);
104:                    System.out.print(colSpec.toShortString());
105:                    if (col < layout.getColumnCount())
106:                        System.out.print(", ");
107:                }
108:                System.out.println();
109:            }
110:
111:            /**
112:             * Dumps the layout's row specifications to the console.
113:             * 
114:             * @param layout
115:             *            the <code>FormLayout</code> to inspect
116:             */
117:            public static void dumpRowSpecs(FormLayout layout) {
118:                System.out.print("ROW SPECS:   ");
119:                for (int row = 1; row <= layout.getRowCount(); row++) {
120:                    RowSpec rowSpec = layout.getRowSpec(row);
121:                    System.out.print(rowSpec.toShortString());
122:                    if (row < layout.getRowCount())
123:                        System.out.print(", ");
124:                }
125:                System.out.println();
126:            }
127:
128:            /**
129:             * Dumps the layout's column groups to the console.
130:             * 
131:             * @param layout
132:             *            the <code>FormLayout</code> to inspect
133:             */
134:            public static void dumpColumnGroups(FormLayout layout) {
135:                dumpGroups("COLUMN GROUPS: ", layout.getColumnGroups());
136:            }
137:
138:            /**
139:             * Dumps the layout's row groups to the console.
140:             * 
141:             * @param layout
142:             *            the <code>FormLayout</code> to inspect
143:             */
144:            public static void dumpRowGroups(FormLayout layout) {
145:                dumpGroups("ROW GROUPS:    ", layout.getRowGroups());
146:            }
147:
148:            /**
149:             * Dumps the container's grid info to the console if and only if the
150:             * container's layout is a <code>FormLayout</code>.
151:             * 
152:             * @param container
153:             *            the container to inspect
154:             * @throws IllegalArgumentException
155:             *             if the layout is not FormLayout
156:             */
157:            public static void dumpGridBounds(Container container) {
158:                System.out.println("GRID BOUNDS");
159:                dumpGridBounds(getLayoutInfo(container));
160:            }
161:
162:            /**
163:             * Dumps the grid layout info to the console.
164:             * 
165:             * @param layoutInfo
166:             *            provides the column and row origins
167:             */
168:            public static void dumpGridBounds(FormLayout.LayoutInfo layoutInfo) {
169:                System.out.print("COLUMN ORIGINS: ");
170:                for (int col = 0; col < layoutInfo.columnOrigins.length; col++) {
171:                    System.out.print(layoutInfo.columnOrigins[col] + " ");
172:                }
173:                System.out.println();
174:
175:                System.out.print("ROW ORIGINS:    ");
176:                for (int row = 0; row < layoutInfo.rowOrigins.length; row++) {
177:                    System.out.print(layoutInfo.rowOrigins[row] + " ");
178:                }
179:                System.out.println();
180:            }
181:
182:            /**
183:             * Dumps the component constraints to the console.
184:             * 
185:             * @param container
186:             *            the layout container to inspect
187:             */
188:            public static void dumpConstraints(Container container) {
189:                System.out.println("COMPONENT CONSTRAINTS");
190:                if (!(container.getLayout() instanceof  FormLayout)) {
191:                    System.out
192:                            .println("The container's layout is not a FormLayout.");
193:                    return;
194:                }
195:                FormLayout layout = (FormLayout) container.getLayout();
196:                int childCount = container.getComponentCount();
197:                for (int i = 0; i < childCount; i++) {
198:                    Component child = container.getComponent(i);
199:                    CellConstraints cc = layout.getConstraints(child);
200:                    String ccString = cc == null ? "no constraints" : cc
201:                            .toShortString(layout);
202:                    System.out.print(ccString);
203:                    System.out.print("; ");
204:                    String childType = child.getClass().getName();
205:                    System.out.print(childType);
206:                    if (child instanceof  JLabel) {
207:                        JLabel label = (JLabel) child;
208:                        System.out.print("      \"" + label.getText() + "\"");
209:                    }
210:                    if (child.getName() != null) {
211:                        System.out.print("; name=");
212:                        System.out.print(child.getName());
213:                    }
214:                    System.out.println();
215:                }
216:                System.out.println();
217:            }
218:
219:            // Helper Code **********************************************************
220:
221:            /**
222:             * Dumps the given groups to the console.
223:             * 
224:             * @param title
225:             *            a string title for the dump
226:             * @param allGroups
227:             *            a two-dimensional array with all groups
228:             */
229:            private static void dumpGroups(String title, int[][] allGroups) {
230:                System.out.print(title + " {");
231:                for (int group = 0; group < allGroups.length; group++) {
232:                    int[] groupIndices = allGroups[group];
233:                    System.out.print(" {");
234:                    for (int i = 0; i < groupIndices.length; i++) {
235:                        System.out.print(groupIndices[i]);
236:                        if (i < groupIndices.length - 1) {
237:                            System.out.print(", ");
238:                        }
239:                    }
240:                    System.out.print("} ");
241:                    if (group < allGroups.length - 1) {
242:                        System.out.print(", ");
243:                    }
244:                }
245:                System.out.println("}");
246:            }
247:
248:            /**
249:             * Computes and returns the layout's grid origins.
250:             * 
251:             * @param container
252:             *            the layout container to inspect
253:             * @return an object that comprises the cell origins and extents
254:             * @throws IllegalArgumentException
255:             *             if the layout is not FormLayout
256:             */
257:            public static FormLayout.LayoutInfo getLayoutInfo(
258:                    Container container) {
259:                if (!(container.getLayout() instanceof  FormLayout)) {
260:                    throw new IllegalArgumentException(
261:                            "The container must use an instance of FormLayout.");
262:                }
263:                FormLayout layout = (FormLayout) container.getLayout();
264:                return layout.getLayoutInfo(container);
265:            }
266:
267:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.