src/java.desktop/share/classes/javax/swing/GroupLayout.java

Print this page
rev 10520 : 8055723[client]: Replace concat String to append in StringBuilder parameters
Contributed-by: Otavio Santana <otaviojava@java.net>


1196         return false;
1197     }
1198 
1199     private boolean isLeftToRight() {
1200         return host.getComponentOrientation().isLeftToRight();
1201     }
1202 
1203     /**
1204      * Returns a string representation of this {@code GroupLayout}.
1205      * This method is intended to be used for debugging purposes,
1206      * and the content and format of the returned string may vary
1207      * between implementations.
1208      *
1209      * @return a string representation of this {@code GroupLayout}
1210      **/
1211     public String toString() {
1212         if (springsChanged) {
1213             registerComponents(horizontalGroup, HORIZONTAL);
1214             registerComponents(verticalGroup, VERTICAL);
1215         }
1216         StringBuffer buffer = new StringBuffer();
1217         buffer.append("HORIZONTAL\n");
1218         createSpringDescription(buffer, horizontalGroup, "  ", HORIZONTAL);
1219         buffer.append("\nVERTICAL\n");
1220         createSpringDescription(buffer, verticalGroup, "  ", VERTICAL);
1221         return buffer.toString();
1222     }
1223 
1224     private void createSpringDescription(StringBuffer buffer, Spring spring,
1225             String indent, int axis) {
1226         String origin = "";
1227         String padding = "";
1228         if (spring instanceof ComponentSpring) {
1229             ComponentSpring cSpring = (ComponentSpring)spring;
1230             origin = Integer.toString(cSpring.getOrigin()) + " ";
1231             String name = cSpring.getComponent().getName();
1232             if (name != null) {
1233                 origin = "name=" + name + ", ";
1234             }
1235         }
1236         if (spring instanceof AutoPreferredGapSpring) {
1237             AutoPreferredGapSpring paddingSpring =
1238                     (AutoPreferredGapSpring)spring;
1239             padding = ", userCreated=" + paddingSpring.getUserCreated() +
1240                     ", matches=" + paddingSpring.getMatchDescription();
1241         }
1242         buffer.append(indent + spring.getClass().getName() + " " +
1243                 Integer.toHexString(spring.hashCode()) + " " +
1244                 origin +
1245                 ", size=" + spring.getSize() +
1246                 ", alignment=" + spring.getAlignment() +
1247                 " prefs=[" + spring.getMinimumSize(axis) +
1248                 " " + spring.getPreferredSize(axis) +
1249                 " " + spring.getMaximumSize(axis) +
1250                 padding + "]\n");
1251         if (spring instanceof Group) {
1252             List<Spring> springs = ((Group)spring).springs;
1253             indent += "  ";
1254             for (int counter = 0; counter < springs.size(); counter++) {
1255                 createSpringDescription(buffer, springs.get(counter), indent,
1256                         axis);
1257             }
1258         }
1259     }
1260 
1261 
1262     /**
1263      * Spring consists of a range: min, pref and max, a value some where in
1264      * the middle of that, and a location. Spring caches the
1265      * min/max/pref.  If the min/pref/max has internally changes, or needs
1266      * to be updated you must invoke clear.
1267      */
1268     private abstract class Spring {
1269         private int size;
1270         private int min;
1271         private int max;
1272         private int pref;
1273         private Spring parent;
1274 
1275         private Alignment alignment;




1196         return false;
1197     }
1198 
1199     private boolean isLeftToRight() {
1200         return host.getComponentOrientation().isLeftToRight();
1201     }
1202 
1203     /**
1204      * Returns a string representation of this {@code GroupLayout}.
1205      * This method is intended to be used for debugging purposes,
1206      * and the content and format of the returned string may vary
1207      * between implementations.
1208      *
1209      * @return a string representation of this {@code GroupLayout}
1210      **/
1211     public String toString() {
1212         if (springsChanged) {
1213             registerComponents(horizontalGroup, HORIZONTAL);
1214             registerComponents(verticalGroup, VERTICAL);
1215         }
1216         StringBuilder sb = new StringBuilder();
1217         sb.append("HORIZONTAL\n");
1218         createSpringDescription(sb, horizontalGroup, "  ", HORIZONTAL);
1219         sb.append("\nVERTICAL\n");
1220         createSpringDescription(sb, verticalGroup, "  ", VERTICAL);
1221         return sb.toString();
1222     }
1223 
1224     private void createSpringDescription(StringBuilder sb, Spring spring,
1225             String indent, int axis) {
1226         String origin = "";
1227         String padding = "";
1228         if (spring instanceof ComponentSpring) {
1229             ComponentSpring cSpring = (ComponentSpring)spring;
1230             origin = Integer.toString(cSpring.getOrigin()) + " ";
1231             String name = cSpring.getComponent().getName();
1232             if (name != null) {
1233                 origin = "name=" + name + ", ";
1234             }
1235         }
1236         if (spring instanceof AutoPreferredGapSpring) {
1237             AutoPreferredGapSpring paddingSpring =
1238                     (AutoPreferredGapSpring)spring;
1239             padding = ", userCreated=" + paddingSpring.getUserCreated() +
1240                     ", matches=" + paddingSpring.getMatchDescription();
1241         }
1242         sb.append(indent).append(spring.getClass().getName()).append(' ')
1243                 .append(Integer.toHexString(spring.hashCode())).append(' ')
1244                 .append(origin).append(", size=").append(spring.getSize())
1245                 .append(", alignment=").append(spring.getAlignment())
1246                 .append(" prefs=[").append(spring.getMinimumSize(axis))
1247                 .append(' ').append(spring.getPreferredSize(axis)).append(' ')
1248                 .append(spring.getMaximumSize(axis)).append(padding)
1249                 .append("]\n");

1250         if (spring instanceof Group) {
1251             List<Spring> springs = ((Group)spring).springs;
1252             indent += "  ";
1253             for (int counter = 0; counter < springs.size(); counter++) {
1254                 createSpringDescription(sb, springs.get(counter), indent,
1255                         axis);
1256             }
1257         }
1258     }
1259 
1260 
1261     /**
1262      * Spring consists of a range: min, pref and max, a value some where in
1263      * the middle of that, and a location. Spring caches the
1264      * min/max/pref.  If the min/pref/max has internally changes, or needs
1265      * to be updated you must invoke clear.
1266      */
1267     private abstract class Spring {
1268         private int size;
1269         private int min;
1270         private int max;
1271         private int pref;
1272         private Spring parent;
1273 
1274         private Alignment alignment;