1 30 31 package com.jgoodies.forms.debug; 32 33 import java.awt.Component ; 34 import java.awt.Container ; 35 36 import javax.swing.JLabel ; 37 38 import com.jgoodies.forms.layout.CellConstraints; 39 import com.jgoodies.forms.layout.ColumnSpec; 40 import com.jgoodies.forms.layout.FormLayout; 41 import com.jgoodies.forms.layout.RowSpec; 42 43 44 52 public final class FormDebugUtils { 53 54 56 60 public static void dumpAll(Container container) { 61 if (!(container.getLayout() instanceof FormLayout)) { 62 System.out.println("The container's layout is not a FormLayout."); 63 return; 64 } 65 FormLayout layout = (FormLayout) container.getLayout(); 66 dumpColumnSpecs(layout); 67 dumpRowSpecs(layout); 68 System.out.println(); 69 dumpColumnGroups(layout); 70 dumpRowGroups(layout); 71 System.out.println(); 72 dumpConstraints(container); 73 dumpGridBounds(container); 74 } 75 76 81 public static void dumpColumnSpecs(FormLayout layout) { 82 System.out.print("COLUMN SPECS:"); 83 for (int col = 1; col <= layout.getColumnCount(); col++) { 84 ColumnSpec colSpec = layout.getColumnSpec(col); 85 System.out.print(colSpec.toShortString()); 86 if (col < layout.getColumnCount()) 87 System.out.print(", "); 88 } 89 System.out.println(); 90 } 91 92 93 98 public static void dumpRowSpecs(FormLayout layout) { 99 System.out.print("ROW SPECS: "); 100 for (int row = 1; row <= layout.getRowCount(); row++) { 101 RowSpec rowSpec = layout.getRowSpec(row); 102 System.out.print(rowSpec.toShortString()); 103 if (row < layout.getRowCount()) 104 System.out.print(", "); 105 } 106 System.out.println(); 107 } 108 109 110 115 public static void dumpColumnGroups(FormLayout layout) { 116 dumpGroups("COLUMN GROUPS: ", layout.getColumnGroups()); 117 } 118 119 120 125 public static void dumpRowGroups(FormLayout layout) { 126 dumpGroups("ROW GROUPS: ", layout.getRowGroups()); 127 } 128 129 130 137 public static void dumpGridBounds(Container container) { 138 System.out.println("GRID BOUNDS"); 139 dumpGridBounds(getLayoutInfo(container)); 140 } 141 142 143 148 public static void dumpGridBounds(FormLayout.LayoutInfo layoutInfo) { 149 System.out.print("COLUMN ORIGINS: "); 150 for (int col = 0; col < layoutInfo.columnOrigins.length; col++) { 151 System.out.print(layoutInfo.columnOrigins[col] + " "); 152 } 153 System.out.println(); 154 155 System.out.print("ROW ORIGINS: "); 156 for (int row = 0; row < layoutInfo.rowOrigins.length; row++) { 157 System.out.print(layoutInfo.rowOrigins[row] + " "); 158 } 159 System.out.println(); 160 } 161 162 163 168 public static void dumpConstraints(Container container) { 169 System.out.println("COMPONENT CONSTRAINTS"); 170 if (!(container.getLayout() instanceof FormLayout)) { 171 System.out.println("The container's layout is not a FormLayout."); 172 return; 173 } 174 FormLayout layout = (FormLayout) container.getLayout(); 175 int childCount = container.getComponentCount(); 176 for (int i = 0; i < childCount; i++) { 177 Component child = container.getComponent(i); 178 CellConstraints cc = layout.getConstraints(child); 179 String ccString = cc == null 180 ? "no constraints" 181 : cc.toShortString(layout); 182 System.out.print(ccString); 183 System.out.print("; "); 184 String childType = child.getClass().getName(); 185 System.out.print(childType); 186 if (child instanceof JLabel ) { 187 JLabel label = (JLabel ) child; 188 System.out.print(" \"" + label.getText() + "\""); 189 } 190 if (child.getName() != null) { 191 System.out.print("; name="); 192 System.out.print(child.getName()); 193 } 194 System.out.println(); 195 } 196 System.out.println(); 197 } 198 199 200 202 208 private static void dumpGroups(String title, int[][] allGroups) { 209 System.out.print(title + " {"); 210 for (int group = 0; group < allGroups.length; group++) { 211 int[] groupIndices = allGroups[group]; 212 System.out.print(" {"); 213 for (int i = 0; i < groupIndices.length; i++) { 214 System.out.print(groupIndices[i]); 215 if (i < groupIndices.length - 1) { 216 System.out.print(", "); 217 } 218 } 219 System.out.print("} "); 220 if (group < allGroups.length - 1) { 221 System.out.print(", "); 222 } 223 } 224 System.out.println("}"); 225 } 226 227 234 public static FormLayout.LayoutInfo getLayoutInfo(Container container) { 235 if (!(container.getLayout() instanceof FormLayout)) { 236 throw new IllegalArgumentException ("The container must use an instance of FormLayout."); 237 } 238 FormLayout layout = (FormLayout) container.getLayout(); 239 return layout.getLayoutInfo(container); 240 } 241 242 } | Popular Tags |