1 19 20 package org.netbeans.modules.form.layoutsupport.delegates; 21 22 import java.awt.*; 23 import java.beans.*; 24 import java.util.*; 25 import java.util.List ; 26 import java.lang.ref.*; 27 import java.lang.reflect.*; 28 29 import org.openide.nodes.Node; 30 import org.openide.util.NbBundle; 31 32 import org.netbeans.modules.form.layoutsupport.*; 33 import org.netbeans.modules.form.codestructure.*; 34 import org.netbeans.modules.form.FormProperty; 35 36 44 45 public class GridBagLayoutSupport extends AbstractLayoutSupport 46 { 47 private static Reference customizerRef; 48 49 52 public Class getSupportedClass() { 53 return GridBagLayout.class; 54 } 55 56 59 public Class getCustomizerClass() { 60 return GridBagCustomizer.Window.class; 61 } 62 63 66 public Component getSupportCustomizer() { 67 GridBagCustomizer.Window customizer = null; 68 if (customizerRef != null) 69 customizer = (GridBagCustomizer.Window) customizerRef.get(); 70 if (customizer == null) { 71 customizer = new GridBagCustomizer.Window(); 72 customizerRef = new WeakReference(customizer); 73 } 74 customizer.setObject(this); 75 return customizer; 76 } 77 78 89 public void convertConstraints(LayoutConstraints[] previousConstraints, 90 LayoutConstraints[] currentConstraints, 91 Component[] components) 92 { 93 if (currentConstraints == null || components == null 94 || components.length > currentConstraints.length 95 || components.length == 0 96 || !(previousConstraints[0] 97 instanceof AbsoluteLayoutSupport.AbsoluteLayoutConstraints)) 98 return; 99 100 List xlines = new ArrayList(); 101 List ylines = new ArrayList(); 102 103 Rectangle parentbound; 104 Container con = components[0].getParent(); 105 if (con == null) { 106 parentbound = components[0].getBounds(); 107 } else { 108 parentbound = con.getBounds(); 109 } 110 111 insertLines(0, xlines); 113 insertLines(0, ylines); 114 115 for (int i=0; i < components.length; i++) { 116 Rectangle ibounds = components[i].getBounds(); 117 118 if (ibounds.width > 0) { 119 insertLines(ibounds.x + ibounds.width, xlines); 120 } else { 121 insertLines(ibounds.x + 1, xlines); 122 } 123 124 if (ibounds.height > 0) { 125 insertLines(ibounds.y + ibounds.height, ylines); 126 } else { 127 insertLines(ibounds.y + 1, ylines); 128 } 129 } 130 131 LayoutInfo[] layouts = new LayoutInfo[components.length]; 133 for (int i=0; i < layouts.length; i++) 134 layouts[i] = new LayoutInfo(); 135 136 for (int i=0; i < xlines.size() - 1; i++) { 137 int x1 = ((Integer )xlines.get(i)).intValue(); 138 int x2 = ((Integer )xlines.get(i+1)).intValue(); 139 140 for (int j=0; j < components.length; j++) { 141 Rectangle jbounds = components[j].getBounds(); 142 if (jbounds.width <= 0) { 143 jbounds.width = 1; 144 } 145 if (isOverlapped(x1, x2, jbounds.x, jbounds.x + jbounds.width - 1)) 146 layouts[j].incGridWidth(i); 147 } 148 } 149 150 for (int i=0; i < ylines.size() - 1; i++) { 152 int y1 = ((Integer )ylines.get(i)).intValue(); 153 int y2 = ((Integer )ylines.get(i+1)).intValue(); 154 155 for (int j=0; j < components.length; j++) { 156 Rectangle jbounds = components[j].getBounds(); 157 if (jbounds.height <= 0) { 158 jbounds.height = 1; 159 } 160 if (isOverlapped(y1, y2, jbounds.y, jbounds.y + jbounds.height - 1)) 161 layouts[j].incGridHeight(i); 162 } 163 } 164 165 for (int i=0; i < components.length; i++) { 167 Rectangle curbounds = components[i].getBounds(); 168 int lastleft = 0; 169 int lasttop = 0; 170 171 for (int j = 0; j < components.length; j++) { 172 Rectangle jbounds = components[j].getBounds(); 173 int width = jbounds.width; 174 if(width < 0) width = 0; 175 if(jbounds.x + width - 1 < curbounds.x){ 176 if(jbounds.x + width > lastleft){ 177 lastleft = jbounds.x + width; 178 } 179 } 180 int height = jbounds.height; 181 if (height < 0) height = 0; 182 if (jbounds.y + height - 1 < curbounds.y) { 183 if(jbounds.y + height > lasttop){ 184 lasttop = jbounds.y + height; 185 } 186 } 187 } 188 189 layouts[i].setLeft(curbounds.x - lastleft); 190 layouts[i].setTop(curbounds.y - lasttop); 191 192 int width = (curbounds.width < 0) ? 0 : curbounds.width; 193 int height = (curbounds.height < 0) ? 0 : curbounds.height; 194 195 if (layouts[i].getLastGridX() == xlines.size() - 2) { 196 layouts[i].setRight(parentbound.width - curbounds.x - width); 197 } 198 if (layouts[i].getLastGridY() == ylines.size() - 2) { 199 layouts[i].setBottom(parentbound.height - curbounds.y - height); 200 } 201 } 202 203 212 LayoutInfoComparator comp = new LayoutInfoComparator(LayoutInfoComparator.XAXIS); 213 LayoutInfo [] layoutsX = (LayoutInfo []) layouts.clone(); 214 LayoutInfo [] layoutsY = (LayoutInfo []) layouts.clone(); 215 Arrays.sort(layoutsX, comp); 216 comp.cord = LayoutInfoComparator.YAXIS; 217 Arrays.sort(layoutsY, comp); 218 219 for (int i = 0; i < components.length; i++) { 220 int expand = 0; 221 int lastgrid = layoutsX[i].getLastGridX(); 222 for (int j = i + 1; j < components.length; j++) { 223 if (layoutsX[j].containsGridX(lastgrid) && (layoutsX[j].getLastGridX() > lastgrid) 224 && (layoutsX[i].gridwidth >= layoutsX[j].gridwidth) 225 && (expand < layoutsX[i].gridwidth - layoutsX[j].gridwidth + 1)) { 226 expand = layoutsX[i].gridwidth - layoutsX[j].gridwidth + 1; 227 } 228 } 229 if (expand > 0) { 230 for (int j = i + 1; j < components.length; j++) { 231 if (layoutsX[j].containsGridX(lastgrid) && layoutsX[j].getLastGridX() > lastgrid) { 232 layoutsX[j].expandGridWidth(expand); 233 } else if (layoutsX[j].gridx > lastgrid) { 234 layoutsX[j].moveGridX(expand); 235 } 236 } 237 } 238 239 expand = 0; 240 lastgrid = layoutsY[i].getLastGridY(); 241 for (int j = i + 1; j < components.length; j++) { 242 if (layoutsY[j].containsGridY(lastgrid) && (layoutsY[j].getLastGridY() > lastgrid) 243 && (layoutsY[i].gridheight >= layoutsY[j].gridheight) 244 && (expand < layoutsY[i].gridheight - layoutsY[j].gridheight + 1)) { 245 expand = layoutsY[i].gridheight - layoutsY[j].gridheight + 1; 246 } 247 } 248 if (expand > 0) { 249 for (int j = i + 1; j < components.length; j++) { 250 if (layoutsY[j].containsGridY(lastgrid) && layoutsY[j].getLastGridY() > lastgrid) { 251 layoutsY[j].expandGridHeight(expand); 252 } else if(layoutsY[j].gridy > lastgrid) { 253 layoutsY[j].moveGridY(expand); 254 } 255 } 256 } 257 } 258 259 for (int i=0; i < components.length; i++) { 261 if (Math.max(layouts[i].gridx + layouts[i].gridwidth - 1, 262 layouts[i].gridy + layouts[i].gridheight - 1) >= 512) { 263 for (int j=0; j<i; j++) { 264 currentConstraints[j] = null; } 266 org.openide.DialogDisplayer.getDefault().notify( 267 new org.openide.NotifyDescriptor.Message( 268 NbBundle.getMessage(AbstractLayoutSupport.class, "MSG_ERR_MoreThan512"))); return; 270 } 271 GridBagConstraints gbc = new GridBagConstraints(); 272 gbc.gridx = layouts[i].gridx; 273 gbc.gridy = layouts[i].gridy; 274 gbc.gridwidth = layouts[i].gridwidth; 275 gbc.gridheight = layouts[i].gridheight; 276 gbc.anchor = GridBagConstraints.NORTHWEST; 277 278 gbc.insets = new java.awt.Insets (layouts[i].top , layouts[i].left, 279 layouts[i].bottom, layouts[i].right); 280 281 if (components[i].getClass().getName().equals("javax.swing.JScrollPane")) { gbc.weightx = 1.0; 283 gbc.weighty = 1.0; 284 gbc.fill = java.awt.GridBagConstraints.BOTH; 285 } 286 287 Rectangle bounds = components[i].getBounds(); 288 Dimension minsize = components[i].getMinimumSize(); 289 Dimension prefsize = components[i].getPreferredSize(); 290 291 if (bounds.width > minsize.width) 292 gbc.ipadx = bounds.width - minsize.width; 293 else if (bounds.width < prefsize.width) 294 gbc.ipadx = bounds.width - prefsize.width; 295 if (bounds.height > minsize.height) 296 gbc.ipady = bounds.height - minsize.height; 297 else if (bounds.height < prefsize.height) 298 gbc.ipady = bounds.height - prefsize.height; 299 300 currentConstraints[i] = new GridBagLayoutConstraints(gbc); 301 } 302 } 303 304 private static boolean isOverlapped(int border1, int border2, 305 int compPos1, int compPos2) 306 { 307 return compPos2 >= border1 && compPos1 < border2; 308 } 309 310 private static void insertLines(int line, java.util.List lines) { 311 if (line < 0) 312 line = 0; 313 for (int i=0; i < lines.size(); i++) { 314 int ival = ((Integer )lines.get(i)).intValue(); 315 if (line < ival) { 316 lines.add(i, new Integer (line)); 317 return; 318 } 319 else if (line == ival) 320 return; 321 } 322 lines.add(new Integer (line)); 323 } 324 325 328 private static class LayoutInfoComparator implements java.util.Comparator { 329 final static int XAXIS = 0; 330 final static int YAXIS = 1; 331 int cord; 332 333 public LayoutInfoComparator(int cord){ 334 this.cord = cord; 335 } 336 337 public int compare(Object left, Object right) { 338 LayoutInfo layoutleft = (LayoutInfo) left; 339 LayoutInfo layoutright = (LayoutInfo) right; 340 341 if ((left == null) || (right == null)) return 0; 342 if (cord == XAXIS) { 343 return layoutleft.getLastGridX() - layoutright.getLastGridX(); 344 } else { 345 return layoutleft.getLastGridY() - layoutright.getLastGridY(); 346 } 347 } 348 349 } 350 351 354 private static class LayoutInfo { 355 356 int gridx, gridy; 357 358 int gridwidth; 359 360 int gridheight; 361 362 int top = 0, left = 0, bottom = 0, right = 0; 363 364 void setLeft(int left){ 365 if(left < 0) left = 0; 366 this.left = left; 367 } 368 369 void setTop(int top){ 370 if(top < 0) top = 0; 371 this.top = top; 372 } 373 374 void setBottom(int bottom){ 375 if(bottom < 0) bottom = 0; 376 this.bottom = bottom; 377 } 378 379 void setRight(int right){ 380 if(right < 0) right = 0; 381 this.right = right; 382 } 383 384 void moveGridX(int diff) { 385 gridx += diff; 386 } 387 388 void moveGridY(int diff) { 389 gridy += diff; 390 } 391 392 void expandGridWidth(int diff) { 393 gridwidth += diff; 394 } 395 396 void expandGridHeight(int diff) { 397 gridheight += diff; 398 } 399 400 void incGridWidth(int gridx) { 401 if (gridwidth == 0) 402 this.gridx = gridx; 403 gridwidth++; 404 } 405 406 void incGridHeight(int gridy) { 407 if (gridheight == 0) 408 this.gridy = gridy; 409 gridheight++; 410 } 411 412 boolean containsGridX(int grid){ 413 return ((grid >= gridx) && (grid < gridx + gridwidth)); 414 } 415 416 boolean containsGridY(int grid){ 417 return ((grid >= gridy) && (grid < gridy + gridheight)); 418 } 419 420 int getLastGridX(){ 421 return gridx + gridwidth - 1; 422 } 423 424 int getLastGridY(){ 425 return gridy + gridheight - 1; 426 } 427 428 } 429 430 432 442 protected LayoutConstraints readConstraintsCode(CodeExpression constrExp, 443 CodeGroup constrCode, 444 CodeExpression compExp) 445 { 446 GridBagLayoutConstraints constr = new GridBagLayoutConstraints(); 447 constr.readCodeExpression(constrExp, constrCode); 449 return constr; 450 } 451 452 460 protected CodeExpression createConstraintsCode(CodeGroup constrCode, 461 LayoutConstraints constr, 462 CodeExpression compExp, 463 int index) 464 { 465 if (!(constr instanceof GridBagLayoutConstraints)) 466 return null; 467 468 return ((GridBagLayoutConstraints)constr).createCodeExpression( 470 getCodeStructure(), constrCode); 471 } 472 473 478 protected LayoutConstraints createDefaultConstraints() { 479 return new GridBagLayoutConstraints(); 480 } 481 482 484 503 public static class GridBagLayoutConstraints implements LayoutConstraints { 504 private GridBagConstraints constraints; 505 506 private GridBagConstraints defaultConstraints = new GridBagConstraints(); 507 508 private Property[] properties; 509 510 private CodeExpression constraintsExpression; 511 private CodeGroup constraintsCode; private CodeStatement[] propertyStatements; 514 private static Constructor constrConstructor; 515 516 private static final int variableType = CodeVariable.LOCAL 517 | CodeVariable.EXPLICIT_DECLARATION; 518 private static final int variableMask = CodeVariable.SCOPE_MASK 519 | CodeVariable.DECLARATION_MASK; 520 private static final String defaultVariableName = "gridBagConstraints"; 522 public GridBagLayoutConstraints() { 523 constraints = new GridBagConstraints(); 524 } 525 526 public GridBagLayoutConstraints(GridBagConstraints constraints) { 527 this.constraints = constraints; 528 } 529 530 public Node.Property[] getProperties() { 531 if (properties == null) { 532 createProperties(); 533 reinstateProperties(); 534 } 535 return properties; 536 } 537 538 public Object getConstraintsObject() { 539 return constraints; 540 } 541 542 public LayoutConstraints cloneConstraints() { 543 return new GridBagLayoutConstraints((GridBagConstraints) 544 constraints.clone()); 545 } 546 547 549 557 private CodeExpression createCodeExpression(CodeStructure codeStructure, 558 CodeGroup constrCode) 559 { 560 this.constraintsCode = constrCode; 561 propertyStatements = null; 562 563 constraintsExpression = codeStructure.createExpression( 565 getConstraintsConstructor(), 566 CodeStructure.EMPTY_PARAMS); 567 updateCodeExpression(); 570 571 return constraintsExpression; 572 } 573 574 582 private void readCodeExpression(CodeExpression constrExp, 583 CodeGroup constrCode) 584 { 585 constraintsExpression = constrExp; 586 constraintsCode = constrCode; 587 propertyStatements = null; 588 589 593 getProperties(); 595 boolean isAnyChanged = false; 596 597 Iterator it = CodeStructure.getDefinedStatementsIterator(constrExp); 598 while (it.hasNext()) { 599 CodeStatement statement = (CodeStatement) it.next(); 601 for (int j=0; j < properties.length; j++) { 602 Property prop = properties[j]; 603 if (prop.field.equals(statement.getMetaObject())) { 604 FormCodeSupport.readPropertyStatement( 607 statement, prop, false); 608 setPropertyStatement(j, statement); 609 if (prop.isChanged()) { constrCode.addStatement(statement); 611 isAnyChanged = true; 612 } 613 break; 614 } 615 } 616 } 617 618 setupVariable(isAnyChanged); 619 } 620 621 627 private void updateCodeExpression() { 628 if (constraintsCode == null || constraintsExpression == null) 629 return; 630 631 constraintsCode.removeAll(); 632 633 getProperties(); 635 boolean isAnyChanged = false; 636 for (int i=0; i < properties.length; i++) 637 if (properties[i].isChanged()) { 640 constraintsCode.addStatement(getPropertyStatement(i)); 641 isAnyChanged = true; 642 } 643 644 setupVariable(isAnyChanged); 645 } 646 647 651 private CodeStatement getPropertyStatement(int index) { 652 if (propertyStatements == null) 653 propertyStatements = new CodeStatement[properties.length]; 654 655 CodeStatement propStatement = propertyStatements[index]; 656 if (propStatement == null) { 657 CodeExpression propExp = 658 constraintsExpression.getCodeStructure().createExpression( 659 FormCodeSupport.createOrigin(properties[index])); 660 661 propStatement = CodeStructure.createStatement( 664 constraintsExpression, 665 properties[index].field, 666 propExp); 667 668 propertyStatements[index] = propStatement; 669 } 670 return propStatement; 671 } 672 673 677 private void setPropertyStatement(int index, 678 CodeStatement propStatement) 679 { 680 if (propertyStatements == null) 681 propertyStatements = new CodeStatement[properties.length]; 682 propertyStatements[index] = propStatement; 683 } 684 685 691 private void setupVariable(boolean anyChangedProperty) { 692 CodeStructure codeStructure = 693 constraintsExpression.getCodeStructure(); 694 CodeVariable var = constraintsExpression.getVariable(); 695 696 if (anyChangedProperty) { if (var == null) { var = findVariable(); if (var == null) { var = codeStructure.createVariableForExpression( 701 constraintsExpression, 702 variableType, 703 defaultVariableName); 704 } 705 else { codeStructure.attachExpressionToVariable( 707 constraintsExpression, var); 708 } 709 } 710 constraintsCode.addStatement( 712 0, var.getAssignment(constraintsExpression)); 713 } 714 else { codeStructure.removeExpressionFromVariable( 716 constraintsExpression); 717 } 718 } 719 720 private CodeVariable findVariable() { 721 CodeStructure codeStructure = 722 constraintsExpression.getCodeStructure(); 723 724 CodeVariable var = codeStructure.getVariable(defaultVariableName); 727 if (var != null 728 && (var.getType() & variableMask) == variableType 729 && GridBagConstraints.class.equals(var.getDeclaredType())) 730 return var; 731 732 Iterator it = codeStructure.getVariablesIterator( 734 variableType, 735 variableMask, 736 GridBagConstraints.class); 737 while (it.hasNext()) { 738 var = (CodeVariable) it.next(); 739 if (var.getName().startsWith(defaultVariableName)) 740 return var; 741 } 742 743 return null; 744 } 745 746 private void createProperties() { 747 properties = new Property[] { 748 new Property("gridx", Integer.TYPE, 750 getBundle().getString("PROP_gridx"), getBundle().getString("HINT_gridx"), GridPosEditor.class), 753 754 new Property("gridy", Integer.TYPE, 756 getBundle().getString("PROP_gridy"), getBundle().getString("HINT_gridy"), GridPosEditor.class), 759 760 new Property("gridwidth", Integer.TYPE, 762 getBundle().getString("PROP_gridwidth"), getBundle().getString("HINT_gridwidth"), GridSizeEditor.class), 765 766 new Property("gridheight", Integer.TYPE, 768 getBundle().getString("PROP_gridheight"), getBundle().getString("HINT_gridheight"), GridSizeEditor.class), 771 772 new Property("fill", Integer.TYPE, 774 getBundle().getString("PROP_fill"), getBundle().getString("HINT_fill"), FillEditor.class), 777 778 new Property("ipadx", Integer.TYPE, 780 getBundle().getString("PROP_ipadx"), getBundle().getString("HINT_ipadx"), null), 783 784 new Property("ipady", Integer.TYPE, 786 getBundle().getString("PROP_ipady"), getBundle().getString("HINT_ipady"), null), 789 790 new Property("anchor", Integer.TYPE, 792 getBundle().getString("PROP_anchor"), getBundle().getString("HINT_anchor"), AnchorEditor.class), 795 796 new Property("weightx", Double.TYPE, 798 getBundle().getString("PROP_weightx"), getBundle().getString("HINT_weightx"), null), 801 802 new Property("weighty", Double.TYPE, 804 getBundle().getString("PROP_weighty"), getBundle().getString("HINT_weighty"), null), 807 808 new Property("insets", Insets.class, 810 getBundle().getString("PROP_insets"), getBundle().getString("HINT_insets"), null) 813 }; 814 815 properties[0].setValue("canEditAsText", Boolean.TRUE); properties[1].setValue("canEditAsText", Boolean.TRUE); properties[2].setValue("canEditAsText", Boolean.TRUE); properties[3].setValue("canEditAsText", Boolean.TRUE); } 821 822 private void reinstateProperties() { 823 try { 824 for (int i=0; i < properties.length; i++) { 825 FormProperty prop = (FormProperty) properties[i]; 826 prop.reinstateProperty(); 827 } 828 } 829 catch(IllegalAccessException e1) {} catch(InvocationTargetException e2) {} } 832 833 private static Constructor getConstraintsConstructor() { 834 if (constrConstructor == null) { 835 try { 836 constrConstructor = 837 GridBagConstraints.class.getConstructor(new Class [0]); 838 } 839 catch (NoSuchMethodException ex) { ex.printStackTrace(); 841 } 842 } 843 return constrConstructor; 844 } 845 846 848 853 private final class Property extends FormProperty { 854 private Field field; 855 private Class propertyEditorClass; 856 857 Property(String name, Class type, 858 String displayName, String shortDescription, 859 Class propertyEditorClass) 860 { 861 super("GridBagLayoutConstraints "+name, type, displayName, shortDescription); 863 this.propertyEditorClass = propertyEditorClass; 864 try { 865 field = GridBagConstraints.class.getField(name); 866 } 867 catch (NoSuchFieldException ex) { ex.printStackTrace(); 869 } 870 } 871 872 public Object getTargetValue() { 873 try { 874 return field.get(constraints); 875 } 876 catch (Exception ex) { ex.printStackTrace(); 878 return null; 879 } 880 } 881 882 public void setTargetValue(Object value) { 883 try { 884 field.set(constraints, value); 885 } 886 catch (Exception ex) { ex.printStackTrace(); 888 } 889 } 890 891 public boolean supportsDefaultValue () { 892 return true; 893 } 894 895 public Object getDefaultValue() { 896 try { 897 return field.get(defaultConstraints); 898 } 899 catch (Exception ex) { ex.printStackTrace(); 901 return null; 902 } 903 } 904 905 public PropertyEditor getExpliciteEditor() { 906 if (propertyEditorClass == null) 907 return null; 908 try { 909 return (PropertyEditor) propertyEditorClass.newInstance(); 910 } 911 catch (Exception ex) { ex.printStackTrace(); 913 return null; 914 } 915 } 916 917 protected void propertyValueChanged(Object old, Object current) { 918 if (current instanceof Integer ) { 920 String name = getName(); 921 if (((name.endsWith("gridx") || name.endsWith("gridwidth")) && constraints.gridx + constraints.gridwidth > 512) 923 || ((name.endsWith("gridy") || name.endsWith("gridheight")) && constraints.gridy + constraints.gridheight > 512)) 925 { 926 boolean fire = isChangeFiring(); 927 setChangeFiring(false); 928 try { 929 setValue(old); 930 } 931 catch (Exception ex) {} setChangeFiring(fire); 933 return; 934 } 935 } 936 937 if (isChangeFiring()) 938 updateCodeExpression(); 939 super.propertyValueChanged(old, current); 940 } 941 942 public void setPropertyContext( 943 org.netbeans.modules.form.FormPropertyContext ctx) 944 { } } 947 } 948 949 952 private abstract static class GridBagConstrEditor extends PropertyEditorSupport { 953 String [] tags; 954 Integer [] values; 955 String [] javaInitStrings; 956 boolean otherValuesAllowed; 957 958 public String [] getTags() { 959 return tags; 960 } 961 962 public String getAsText() { 963 Object value = getValue(); 964 for (int i=0; i < values.length; i++) 965 if (values[i].equals(value)) 966 return tags[i]; 967 968 return otherValuesAllowed && value != null ? 969 value.toString() : null; 970 } 971 972 public void setAsText(String str) { 973 for (int i=0; i < tags.length; i++) 974 if (tags[i].equals(str)) { 975 setValue(values[i]); 976 return; 977 } 978 979 if (otherValuesAllowed) 980 try { 981 setValue(new Integer (Integer.parseInt(str))); 982 } 983 catch (NumberFormatException e) {} } 985 986 public String getJavaInitializationString() { 987 Object value = getValue(); 988 for (int i=0; i < values.length; i++) 989 if (values[i].equals(value)) 990 return javaInitStrings[i]; 991 992 if (!otherValuesAllowed) 993 return javaInitStrings[0]; 994 return value != null ? value.toString() : null; 995 } 996 } 997 998 public static final class GridPosEditor extends GridBagConstrEditor { 999 1000 public GridPosEditor() { 1001 tags = new String [] { 1002 getBundle().getString("VALUE_relative") }; 1004 values = new Integer [] { 1005 new Integer (GridBagConstraints.RELATIVE) 1006 }; 1007 javaInitStrings = new String [] { 1008 "java.awt.GridBagConstraints.RELATIVE" }; 1010 otherValuesAllowed = true; 1011 } 1012 } 1013 1014 public static final class GridSizeEditor extends GridBagConstrEditor { 1015 1016 public GridSizeEditor() { 1017 tags = new String [] { 1018 getBundle().getString("VALUE_relative"), getBundle().getString("VALUE_remainder") }; 1021 values = new Integer [] { 1022 new Integer (GridBagConstraints.RELATIVE), 1023 new Integer (GridBagConstraints.REMAINDER) 1024 }; 1025 javaInitStrings = new String [] { 1026 "java.awt.GridBagConstraints.RELATIVE", "java.awt.GridBagConstraints.REMAINDER" }; 1029 otherValuesAllowed = true; 1030 } 1031 } 1032 1033 public static final class FillEditor extends GridBagConstrEditor { 1034 public FillEditor() { 1035 tags = new String [] { 1036 getBundle().getString("VALUE_fill_none"), getBundle().getString("VALUE_fill_horizontal"), getBundle().getString("VALUE_fill_vertical"), getBundle().getString("VALUE_fill_both") }; 1041 values = new Integer [] { 1042 new Integer (GridBagConstraints.NONE), 1043 new Integer (GridBagConstraints.HORIZONTAL), 1044 new Integer (GridBagConstraints.VERTICAL), 1045 new Integer (GridBagConstraints.BOTH) 1046 }; 1047 javaInitStrings = new String [] { 1048 "java.awt.GridBagConstraints.NONE", "java.awt.GridBagConstraints.HORIZONTAL", "java.awt.GridBagConstraints.VERTICAL", "java.awt.GridBagConstraints.BOTH" }; 1053 otherValuesAllowed = false; 1054 } 1055 } 1056 1057 public static final class AnchorEditor extends GridBagConstrEditor { 1058 public AnchorEditor() { 1059 tags = new String [] { 1060 getBundle().getString("VALUE_anchor_center"), getBundle().getString("VALUE_anchor_north"), getBundle().getString("VALUE_anchor_northeast"), getBundle().getString("VALUE_anchor_east"), getBundle().getString("VALUE_anchor_southeast"), getBundle().getString("VALUE_anchor_south"), getBundle().getString("VALUE_anchor_southwest"), getBundle().getString("VALUE_anchor_west"), getBundle().getString("VALUE_anchor_northwest"), getBundle().getString("VALUE_anchor_pagestart"), getBundle().getString("VALUE_anchor_pageend"), getBundle().getString("VALUE_anchor_linestart"), getBundle().getString("VALUE_anchor_lineend"), getBundle().getString("VALUE_anchor_firstlinestart"), getBundle().getString("VALUE_anchor_firstlineend"), getBundle().getString("VALUE_anchor_lastlinestart"), getBundle().getString("VALUE_anchor_lastlineend") }; 1078 values = new Integer [] { 1079 new Integer (GridBagConstraints.CENTER), 1080 new Integer (GridBagConstraints.NORTH), 1081 new Integer (GridBagConstraints.NORTHEAST), 1082 new Integer (GridBagConstraints.EAST), 1083 new Integer (GridBagConstraints.SOUTHEAST), 1084 new Integer (GridBagConstraints.SOUTH), 1085 new Integer (GridBagConstraints.SOUTHWEST), 1086 new Integer (GridBagConstraints.WEST), 1087 new Integer (GridBagConstraints.NORTHWEST), 1088 new Integer (GridBagConstraints.PAGE_START), 1089 new Integer (GridBagConstraints.PAGE_END), 1090 new Integer (GridBagConstraints.LINE_START), 1091 new Integer (GridBagConstraints.LINE_END), 1092 new Integer (GridBagConstraints.FIRST_LINE_START), 1093 new Integer (GridBagConstraints.FIRST_LINE_END), 1094 new Integer (GridBagConstraints.LAST_LINE_START), 1095 new Integer (GridBagConstraints.LAST_LINE_END) 1096 }; 1097 javaInitStrings = new String [] { 1098 "java.awt.GridBagConstraints.CENTER", "java.awt.GridBagConstraints.NORTH", "java.awt.GridBagConstraints.NORTHEAST", "java.awt.GridBagConstraints.EAST", "java.awt.GridBagConstraints.SOUTHEAST", "java.awt.GridBagConstraints.SOUTH", "java.awt.GridBagConstraints.SOUTHWEST", "java.awt.GridBagConstraints.WEST", "java.awt.GridBagConstraints.NORTHWEST", "java.awt.GridBagConstraints.PAGE_START", "java.awt.GridBagConstraints.PAGE_END", "java.awt.GridBagConstraints.LINE_START", "java.awt.GridBagConstraints.LINE_END", "java.awt.GridBagConstraints.FIRST_LINE_START", "java.awt.GridBagConstraints.FIRST_LINE_END", "java.awt.GridBagConstraints.LAST_LINE_START", "java.awt.GridBagConstraints.LAST_LINE_END" }; 1116 otherValuesAllowed = false; 1117 } 1118 } 1119 1120 1123 static ResourceBundle getBundleHack() { 1124 return getBundle(); } 1126 1127 LayoutSupportContext getLayoutSupportHack() { 1128 return super.getLayoutContext(); 1129 } 1130} 1131 | Popular Tags |