Coverage Report - net.miginfocom.layout.PlatformDefaults
 
Classes in this File Line Coverage Branch Coverage Complexity
PlatformDefaults
N/A
N/A
2.8
 
 1  
 package net.miginfocom.layout;
 2  
 
 3  
 import javax.swing.*;
 4  
 import java.util.HashMap;
 5  
 /*
 6  
  * License (BSD):
 7  
  * ==============
 8  
  *
 9  
  * Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com)
 10  
  * All rights reserved.
 11  
  *
 12  
  * Redistribution and use in source and binary forms, with or without modification,
 13  
  * are permitted provided that the following conditions are met:
 14  
  * Redistributions of source code must retain the above copyright notice, this list
 15  
  * of conditions and the following disclaimer.
 16  
  * Redistributions in binary form must reproduce the above copyright notice, this
 17  
  * list of conditions and the following disclaimer in the documentation and/or other
 18  
  * materials provided with the distribution.
 19  
  * Neither the name of the MiG InfoCom AB nor the names of its contributors may be
 20  
  * used to endorse or promote products derived from this software without specific
 21  
  * prior written permission.
 22  
  *
 23  
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 24  
  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 25  
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 26  
  * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 27  
  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 28  
  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
 29  
  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 30  
  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 31  
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
 32  
  * OF SUCH DAMAGE.
 33  
  *
 34  
  * @version 1.0
 35  
  * @author Mikael Grev, MiG InfoCom AB
 36  
  *         Date: 2006-sep-08
 37  
  * @author Xxxx Xxxx, Xxxx  - Gnome support
 38  
  *         Date: 2008-jan-16
 39  
  */
 40  
 
 41  
 /** Currently handles Windows, Mac OS X, and GNOME spacing.
 42  
  */
 43  
 public final class PlatformDefaults
 44  
 {
 45  
         private static int DEF_H_UNIT = UnitValue.LPX;
 46  
         private static int DEF_V_UNIT = UnitValue.LPY;
 47  
 
 48  
         private static InCellGapProvider GAP_PROVIDER = null;
 49  
 
 50  
         private static volatile int MOD_COUNT = 0;
 51  
 
 52  
         private static final UnitValue LPX4 = new UnitValue(4, UnitValue.LPX, null);
 53  
         private static final UnitValue LPX6 = new UnitValue(6, UnitValue.LPX, null);
 54  
         private static final UnitValue LPX7 = new UnitValue(7, UnitValue.LPX, null);
 55  
 //        private static final UnitValue LPX8 = new UnitValue(8, UnitValue.LPX, null);
 56  
         private static final UnitValue LPX9 = new UnitValue(9, UnitValue.LPX, null);
 57  
         private static final UnitValue LPX10 = new UnitValue(10, UnitValue.LPX, null);
 58  
         private static final UnitValue LPX11 = new UnitValue(11, UnitValue.LPX, null);
 59  
         private static final UnitValue LPX12 = new UnitValue(12, UnitValue.LPX, null);
 60  
         private static final UnitValue LPX14 = new UnitValue(14, UnitValue.LPX, null);
 61  
         private static final UnitValue LPX16 = new UnitValue(16, UnitValue.LPX, null);
 62  
         private static final UnitValue LPX18 = new UnitValue(18, UnitValue.LPX, null);
 63  
         private static final UnitValue LPX20 = new UnitValue(20, UnitValue.LPX, null);
 64  
 
 65  
         private static final UnitValue LPY4 = new UnitValue(4, UnitValue.LPY, null);
 66  
         private static final UnitValue LPY6 = new UnitValue(6, UnitValue.LPY, null);
 67  
         private static final UnitValue LPY7 = new UnitValue(7, UnitValue.LPY, null);
 68  
 //        private static final UnitValue LPY8 = new UnitValue(8, UnitValue.LPY, null);
 69  
         private static final UnitValue LPY9 = new UnitValue(9, UnitValue.LPY, null);
 70  
         private static final UnitValue LPY10 = new UnitValue(10, UnitValue.LPY, null);
 71  
         private static final UnitValue LPY11 = new UnitValue(11, UnitValue.LPY, null);
 72  
         private static final UnitValue LPY12 = new UnitValue(12, UnitValue.LPY, null);
 73  
         private static final UnitValue LPY14 = new UnitValue(14, UnitValue.LPY, null);
 74  
         private static final UnitValue LPY16 = new UnitValue(16, UnitValue.LPY, null);
 75  
         private static final UnitValue LPY18 = new UnitValue(18, UnitValue.LPY, null);
 76  
         private static final UnitValue LPY20 = new UnitValue(20, UnitValue.LPY, null);
 77  
 
 78  
         public static final int WINDOWS_XP = 0;
 79  
         public static final int MAC_OSX = 1;
 80  
         public static final int GNOME = 2;
 81  
 //        private static final int KDE = 3;
 82  
 
 83  
         private static int CUR_PLAF = WINDOWS_XP;
 84  
 
 85  
         // Used for holding values.
 86  
         private final static UnitValue[] PANEL_INS = new UnitValue[4];
 87  
         private final static UnitValue[] DIALOG_INS = new UnitValue[4];
 88  
 
 89  
         private static String BUTTON_FORMAT = null;
 90  
 
 91  
         private static final HashMap<String, UnitValue> HOR_DEFS = new HashMap<String, UnitValue>(32);
 92  
         private static final HashMap<String, UnitValue> VER_DEFS = new HashMap<String, UnitValue>(32);
 93  
         private static BoundSize DEF_VGAP = null, DEF_HGAP = null;
 94  
         static BoundSize RELATED_X = null, RELATED_Y = null, UNRELATED_X = null, UNRELATED_Y = null;
 95  
         private static UnitValue BUTT_WIDTH = null;
 96  
 
 97  
         private static Float horScale = null, verScale = null;
 98  
 
 99  
         /** I value indicating that the size of the font for the container of the component
 100  
          * will be used as a base for calculating the logical pixel size. This is much as how
 101  
          * Windows calculated DLU (dialog units).
 102  
          * @see net.miginfocom.layout.UnitValue#LPX
 103  
          * @see net.miginfocom.layout.UnitValue#LPY
 104  
          * @see #setLogicalPixelBase(int)
 105  
          */
 106  
         public static final int BASE_FONT_SIZE = 100;
 107  
 
 108  
         /** I value indicating that the screen DPI will be used as a base for calculating the
 109  
          * logical pixel size.
 110  
          * <p>
 111  
          * This is the default value.
 112  
          * @see net.miginfocom.layout.UnitValue#LPX
 113  
          * @see net.miginfocom.layout.UnitValue#LPY
 114  
          * @see #setLogicalPixelBase(int)
 115  
          * @see #setVerticalScaleFactor(Float)
 116  
          * @see #setHorizontalScaleFactor(Float)
 117  
          */
 118  
         public static final int BASE_SCALE_FACTOR = 101;
 119  
 
 120  
         /** I value indicating that the size of a logical pixel should always be a real pixel
 121  
          * and thus no compensation will be made.
 122  
          * @see net.miginfocom.layout.UnitValue#LPX
 123  
          * @see net.miginfocom.layout.UnitValue#LPY
 124  
          * @see #setLogicalPixelBase(int)
 125  
          */
 126  
         public static final int BASE_REAL_PIXEL = 102;
 127  
 
 128  
         private static int LP_BASE = BASE_SCALE_FACTOR;
 129  
 
 130  
         private static Integer BASE_DPI_FORCED = null;
 131  
         private static int BASE_DPI = 96;
 132  
 
 133  
         private static boolean dra = true;
 134  
 
 135  
         static {
 136  
                 setPlatform(getCurrentPlatform());
 137  
                 MOD_COUNT = 0;
 138  
         }
 139  
 
 140  
         /** Returns the platform that the JRE is running on currently.
 141  
          * @return The platform that the JRE is running on currently. E.g. {@link #MAC_OSX}, {@link #WINDOWS_XP}, or {@link #GNOME}.
 142  
          */
 143  
         public static int getCurrentPlatform()
 144  
         {
 145  
                 final String os = System.getProperty("os.name");
 146  
                 if (os.startsWith("Mac OS")) {
 147  
                         return MAC_OSX;
 148  
                 } else if (os.startsWith("Linux")) {
 149  
                         return GNOME;
 150  
                 } else {
 151  
                         return WINDOWS_XP;
 152  
                 }
 153  
         }
 154  
 
 155  
         private PlatformDefaults()
 156  
         {
 157  
         }
 158  
 
 159  
         /** Set the defaults to the default for the platform
 160  
          * @param plaf The platform. <code>PlatformDefaults.WINDOWS_XP</code>,
 161  
          * <code>PlatformDefaults.MAC_OSX</code>, or
 162  
          * <code>PlatformDefaults.GNOME</code>.
 163  
          */
 164  
         public static void setPlatform(int plaf)
 165  
         {
 166  
                 switch (plaf) {
 167  
                         case WINDOWS_XP:
 168  
                                 setRelatedGap(LPX4, LPY4);
 169  
                                 setUnrelatedGap(LPX7, LPY9);
 170  
                                 setParagraphGap(LPX14, LPY14);
 171  
                                 setIndentGap(LPX9, LPY9);
 172  
                                 setGridCellGap(LPX4, LPY4);
 173  
 
 174  
                                 setMinimumButtonWidth(new UnitValue(75, UnitValue.LPX, null));
 175  
                                 setButtonOrder("L_E+U+YNBXOCAH_R");
 176  
                                 setDialogInsets(LPY11, LPX11, LPY11, LPX11);
 177  
                                 setPanelInsets(LPY7, LPX7, LPY7, LPX7);
 178  
                                 break;
 179  
                         case MAC_OSX:
 180  
                                 setRelatedGap(LPX4, LPY4);
 181  
                                 setUnrelatedGap(LPX7, LPY9);
 182  
                                 setParagraphGap(LPX14, LPY14);
 183  
                                 setIndentGap(LPX10, LPY10);
 184  
                                 setGridCellGap(LPX4, LPY4);
 185  
 
 186  
                                 setMinimumButtonWidth(new UnitValue(68, UnitValue.LPX, null));
 187  
                                 setButtonOrder("L_HE+U+NYBXCOA_R");
 188  
                                 setDialogInsets(LPY14, LPX20, LPY20, LPX20);
 189  
                                 setPanelInsets(LPY16, LPX16, LPY16, LPX16);
 190  
 
 191  
 //                                setRelatedGap(LPX8, LPY8);
 192  
 //                                setUnrelatedGap(LPX12, LPY12);
 193  
 //                                setParagraphGap(LPX16, LPY16);
 194  
 //                                setIndentGap(LPX10, LPY10);
 195  
 //                                setGridCellGap(LPX8, LPY8);
 196  
 //
 197  
 //                                setMinimumButtonWidth(new UnitValue(68, UnitValue.LPX, null));
 198  
 //                                setButtonOrder("L_HE+U+NYBXCOA_R");
 199  
 //                                setDialogInsets(LPY14, LPX20, LPY20, LPX20);
 200  
 //                                setPanelInsets(LPY16, LPX16, LPY16, LPX16);
 201  
                                 break;
 202  
                         case GNOME:
 203  
                                 setRelatedGap(LPX6, LPY6);                    // GNOME HIG 8.2.3
 204  
                                 setUnrelatedGap(LPX12, LPY12);                // GNOME HIG 8.2.3
 205  
                                 setParagraphGap(LPX18, LPY18);                // GNOME HIG 8.2.3
 206  
                                 setIndentGap(LPX12, LPY12);                   // GNOME HIG 8.2.3
 207  
                                 setGridCellGap(LPX6, LPY6);                   // GNOME HIG 8.2.3
 208  
 
 209  
                                 // GtkButtonBox, child-min-width property default value
 210  
                                 setMinimumButtonWidth(new UnitValue(85, UnitValue.LPX, null));
 211  
                                 setButtonOrder("L_HE+UNYACBXIO_R");           // GNOME HIG 3.4.2, 3.7.1
 212  
                                 setDialogInsets(LPY12, LPX12, LPY12, LPX12);  // GNOME HIG 3.4.3
 213  
                                 setPanelInsets(LPY6, LPX6, LPY6, LPX6);       // ???
 214  
                                 break;
 215  
                         default:
 216  
                                 throw new IllegalArgumentException("Unknown platform: " + plaf);
 217  
                 }
 218  
                 CUR_PLAF = plaf;
 219  
                 BASE_DPI = BASE_DPI_FORCED != null ? BASE_DPI_FORCED : getPlatformDPI(plaf);
 220  
         }
 221  
 
 222  
         private static int getPlatformDPI(int plaf)
 223  
         {
 224  
                 switch (plaf) {
 225  
                         case WINDOWS_XP:
 226  
                         case GNOME:
 227  
                                 return 96;
 228  
                         case MAC_OSX:
 229  
                                 try {
 230  
                                         return System.getProperty("java.version").compareTo("1.6") < 0 ? 72 : 96; // Default DPI was 72 prior to JSE 1.6
 231  
                                 } catch (Throwable t) {
 232  
                                         return 72;
 233  
                                 }
 234  
                         default:
 235  
                                 throw new IllegalArgumentException("Unknown platform: " + plaf);
 236  
                 }
 237  
         }
 238  
 
 239  
         /** Returns the current platform
 240  
          * @return <code>PlatformDefaults.WINDOWS</code> or <code>PlatformDefaults.MAC_OSX</code>
 241  
          */
 242  
         public static int getPlatform()
 243  
         {
 244  
                 return CUR_PLAF;
 245  
         }
 246  
 
 247  
         public static int getDefaultDPI()
 248  
         {
 249  
                 return BASE_DPI;
 250  
         }
 251  
 
 252  
         /** Sets the default platform DPI. Normally this is set in the {@link #setPlatform(int)} for the different platforms
 253  
          * but it can be tweaked here. For instance SWT on Mac does this.
 254  
          * <p>
 255  
          * Note that this is not the actual current DPI, but the base DPI for the toolkit.
 256  
          * @param dpi The base DPI. If null the default DPI is reset to the platform base DPI.
 257  
          */
 258  
         public static void setDefaultDPI(Integer dpi)
 259  
         {
 260  
                 BASE_DPI = dpi != null ? dpi : getPlatformDPI(CUR_PLAF);
 261  
                 BASE_DPI_FORCED = dpi;
 262  
         }
 263  
 
 264  
         /** The forced scale factor that all screen relative units (e.g. millimeters, inches and logical pixels) will be multiplied
 265  
          * with. If <code>null</code> this will default to a scale that will scale the current screen to the default screen resolution
 266  
          * (72 DPI for Mac and 92 DPI for Windows).
 267  
          * @return The forced scale or <code>null</code> for default scaling.
 268  
          * @see #getHorizontalScaleFactor()
 269  
          * @see ComponentWrapper#getHorizontalScreenDPI()
 270  
          */
 271  
         public static Float getHorizontalScaleFactor()
 272  
         {
 273  
                 return horScale;
 274  
         }
 275  
 
 276  
         /** The forced scale factor that all screen relative units (e.g. millimeters, inches and logical pixels) will be multiplied
 277  
          * with. If <code>null</code> this will default to a scale that will scale the current screen to the default screen resolution
 278  
          * (72 DPI for Mac and 92 DPI for Windows).
 279  
          * @param f The forced scale or <code>null</code> for default scaling.
 280  
          * @see #getHorizontalScaleFactor()
 281  
          * @see ComponentWrapper#getHorizontalScreenDPI()
 282  
          */
 283  
         public static void setHorizontalScaleFactor(Float f)
 284  
         {
 285  
                 if (LayoutUtil.equals(horScale, f) == false) {
 286  
                         horScale = f;
 287  
                         MOD_COUNT++;
 288  
                 }
 289  
         }
 290  
 
 291  
         /** The forced scale factor that all screen relative units (e.g. millimeters, inches and logical pixels) will be multiplied
 292  
          * with. If <code>null</code> this will default to a scale that will scale the current screen to the default screen resolution
 293  
          * (72 DPI for Mac and 92 DPI for Windows).
 294  
          * @return The forced scale or <code>null</code> for default scaling.
 295  
          * @see #getHorizontalScaleFactor()
 296  
          * @see ComponentWrapper#getVerticalScreenDPI()
 297  
          */
 298  
         public static Float getVerticalScaleFactor()
 299  
         {
 300  
                 return verScale;
 301  
         }
 302  
 
 303  
         /** The forced scale factor that all screen relative units (e.g. millimeters, inches and logical pixels) will be multiplied
 304  
          * with. If <code>null</code> this will default to a scale that will scale the current screen to the default screen resolution
 305  
          * (72 DPI for Mac and 92 DPI for Windows).
 306  
          * @param f The forced scale or <code>null</code> for default scaling.
 307  
          * @see #getHorizontalScaleFactor()
 308  
          * @see ComponentWrapper#getVerticalScreenDPI()
 309  
          */
 310  
         public static void setVerticalScaleFactor(Float f)
 311  
         {
 312  
                 if (LayoutUtil.equals(verScale, f) == false) {
 313  
                         verScale = f;
 314  
                         MOD_COUNT++;
 315  
                 }
 316  
         }
 317  
 
 318  
         /** What base value should be used to calculate logical pixel sizes.
 319  
          * @return The current base. Default is {@link #BASE_SCALE_FACTOR}
 320  
          * @see #BASE_FONT_SIZE
 321  
          * @see #BASE_SCALE_FACTOR
 322  
          * @see #BASE_REAL_PIXEL
 323  
 */
 324  
         public static int getLogicalPixelBase()
 325  
         {
 326  
                 return LP_BASE;
 327  
         }
 328  
 
 329  
         /** What base value should be used to calculate logical pixel sizes.
 330  
          * @param base The new base. Default is {@link #BASE_SCALE_FACTOR}
 331  
          * @see #BASE_FONT_SIZE
 332  
          * @see #BASE_SCALE_FACTOR
 333  
          * @see #BASE_REAL_PIXEL
 334  
          */
 335  
         public static void setLogicalPixelBase(int base)
 336  
         {
 337  
                 if (LP_BASE != base) {
 338  
                         if (base < BASE_FONT_SIZE || base > BASE_SCALE_FACTOR)
 339  
                                 throw new IllegalArgumentException("Unrecognized base: " + base);
 340  
 
 341  
                         LP_BASE = base;
 342  
                         MOD_COUNT++;
 343  
                 }
 344  
         }
 345  
 
 346  
         /** Sets gap value for components that are "related".
 347  
          * @param x The value that will be transformed to pixels. If <code>null</code> the current value will not change.
 348  
          * @param y The value that will be transformed to pixels. If <code>null</code> the current value will not change.
 349  
          */
 350  
         public static void setRelatedGap(UnitValue x, UnitValue y)
 351  
         {
 352  
                 setUnitValue(new String[] {"r", "rel", "related"}, x, y);
 353  
 
 354  
                 RELATED_X = new BoundSize(x, x, null, "rel:rel");
 355  
                 RELATED_Y = new BoundSize(y, y, null, "rel:rel");
 356  
         }
 357  
 
 358  
         /** Sets gap value for components that are "unrelated".
 359  
          * @param x The value that will be transformed to pixels. If <code>null</code> the current value will not change.
 360  
          * @param y The value that will be transformed to pixels. If <code>null</code> the current value will not change.
 361  
          */
 362  
         public static void setUnrelatedGap(UnitValue x, UnitValue y)
 363  
         {
 364  
                 setUnitValue(new String[] {"u", "unrel", "unrelated"}, x, y);
 365  
 
 366  
                 UNRELATED_X = new BoundSize(x, x, null, "unrel:unrel");
 367  
                 UNRELATED_Y = new BoundSize(y, y, null, "unrel:unrel");
 368  
         }
 369  
 
 370  
         /** Sets paragraph gap value for components.
 371  
          * @param x The value that will be transformed to pixels. If <code>null</code> the current value will not change.
 372  
          * @param y The value that will be transformed to pixels. If <code>null</code> the current value will not change.
 373  
          */
 374  
         public static void setParagraphGap(UnitValue x, UnitValue y)
 375  
         {
 376  
                 setUnitValue(new String[] {"p", "para", "paragraph"}, x, y);
 377  
         }
 378  
 
 379  
         /** Sets gap value for components that are "intended".
 380  
          * @param x The value that will be transformed to pixels. If <code>null</code> the current value will not change.
 381  
          * @param y The value that will be transformed to pixels. If <code>null</code> the current value will not change.
 382  
          */
 383  
         public static void setIndentGap(UnitValue x, UnitValue y)
 384  
         {
 385  
                 setUnitValue(new String[] {"i", "ind", "indent"}, x, y);
 386  
         }
 387  
 
 388  
         /** Sets gap between two cells in the grid. Note that this is not a gap between component IN a cell, that has to be set
 389  
          * on the component constraints. The value will be the min and preferred size of the gap.
 390  
          * @param x The value that will be transformed to pixels. If <code>null</code> the current value will not change.
 391  
          * @param y The value that will be transformed to pixels. If <code>null</code> the current value will not change.
 392  
          */
 393  
         public static void setGridCellGap(UnitValue x, UnitValue y)
 394  
         {
 395  
                 if (x != null)
 396  
                         DEF_HGAP = new BoundSize(x, x, null, null);
 397  
 
 398  
                 if (y != null)
 399  
                         DEF_VGAP = new BoundSize(y, y, null, null);
 400  
 
 401  
                 MOD_COUNT++;
 402  
         }
 403  
 
 404  
         /** Sets the recommended minimum button width.
 405  
          * @param width The recommended minimum button width.
 406  
          */
 407  
         public static void setMinimumButtonWidth(UnitValue width)
 408  
         {
 409  
                 BUTT_WIDTH = width;
 410  
                 MOD_COUNT++;
 411  
         }
 412  
 
 413  
         /** Returns the recommended minimum button width depending on the current set platform.
 414  
          * @return The recommended minimum button width depending on the current set platform.
 415  
          */
 416  
         public static UnitValue getMinimumButtonWidth()
 417  
         {
 418  
                 return BUTT_WIDTH;
 419  
         }
 420  
 
 421  
         /** Returns the unit value associated with the unit. (E.i. "related" or "indent"). Must be lower case.
 422  
          * @param unit The unit string.
 423  
          * @return The unit value associated with the unit. <code>null</code> for unrecognized units.
 424  
          */
 425  
         public static UnitValue getUnitValueX(String unit)
 426  
         {
 427  
                 return HOR_DEFS.get(unit);
 428  
         }
 429  
 
 430  
         /** Returns the unit value associated with the unit. (E.i. "related" or "indent"). Must be lower case.
 431  
          * @param unit The unit string.
 432  
          * @return The unit value associated with the unit. <code>null</code> for unrecognized units.
 433  
          */
 434  
         public static UnitValue getUnitValueY(String unit)
 435  
         {
 436  
                 return VER_DEFS.get(unit);
 437  
         }
 438  
 
 439  
         /** Sets the unit value associated with a unit string. This may be used to store values for new unit strings
 440  
          * or modify old. Note that if a built in unit (such as "related") is modified all versions of it must be
 441  
          * set (I.e. "r", "rel" and "related"). The build in values will be reset to the default ones if the platform
 442  
          * is re-set.
 443  
          * @param unitStrings The unit strings. E.g. "mu", "myunit". Will be converted to lower case and trimmed. Not <code>null</code>.
 444  
          * @param x The value for the horizontal dimension. If <code>null</code> the value is not changed.
 445  
          * @param y The value for the vertical dimension. Might be same object as for <code>x</code>. If <code>null</code> the value is not changed.
 446  
          */
 447  
         public static final void setUnitValue(String[] unitStrings, UnitValue x, UnitValue y)
 448  
         {
 449  
                 for (String unitString : unitStrings) {
 450  
                         String s = unitString.toLowerCase().trim();
 451  
                         if (x != null)
 452  
                                 HOR_DEFS.put(s, x);
 453  
                         if (y != null)
 454  
                                 VER_DEFS.put(s, y);
 455  
                 }
 456  
                 MOD_COUNT++;
 457  
         }
 458  
 
 459  
         /** Understands ("r", "rel", "related") OR ("u", "unrel", "unrelated") OR ("i", "ind", "indent") OR ("p", "para", "paragraph").
 460  
          */
 461  
         static int convertToPixels(float value, String unit, boolean isHor, float ref, ContainerWrapper parent, ComponentWrapper comp)
 462  
         {
 463  
                 UnitValue uv = (isHor ? HOR_DEFS : VER_DEFS).get(unit);
 464  
                 return uv != null ? Math.round(value * uv.getPixels(ref, parent, comp)) : UnitConverter.UNABLE;
 465  
         }
 466  
 
 467  
         /** Returns the order for the typical buttons in a standard button bar. It is one letter per button type.
 468  
          * @return The button order.
 469  
          * @see #setButtonOrder(String)
 470  
          */
 471  
         public static String getButtonOrder()
 472  
         {
 473  
                 return BUTTON_FORMAT;
 474  
         }
 475  
 
 476  
         /** Sets the order for the typical buttons in a standard button bar. It is one letter per button type.
 477  
          * <p>
 478  
          * Letter in upper case will get the minimum button width that the {@link #getMinimumButtonWidth()} specifies
 479  
          * and letters in lower case will get the width the current look&feel specifies.
 480  
          * <p>
 481  
          * Gaps will never be added to before the first component or after the last component. However, '+' (push) will be
 482  
          * applied before and after as well, but with a minimum size of 0 if first/last so there will not be a gap
 483  
          * before or after.
 484  
          * <p>
 485  
          * If gaps are explicitly set on buttons they will never be reduced, but they may be increased.
 486  
          * <p>
 487  
          * These are the characters that can be used:
 488  
          * <ul>
 489  
          * <li><code>'L'</code> - Buttons with this style tag will staticall end up on the left end of the bar.
 490  
          * <li><code>'R'</code> - Buttons with this style tag will staticall end up on the right end of the bar.
 491  
          * <li><code>'H'</code> - A tag for the "help" button that normally is supposed to be on the right.
 492  
          * <li><code>'E'</code> - A tag for the "help2" button that normally is supposed to be on the left.
 493  
          * <li><code>'Y'</code> - A tag for the "yes" button.
 494  
          * <li><code>'N'</code> - A tag for the "no" button.
 495  
          * <li><code>'X'</code> - A tag for the "next >" or "forward >" button.
 496  
          * <li><code>'B'</code> - A tag for the "< back>" or "< previous" button.
 497  
          * <li><code>'I'</code> - A tag for the "finish".
 498  
          * <li><code>'A'</code> - A tag for the "apply" button.
 499  
          * <li><code>'C'</code> - A tag for the "cancel" or "close" button.
 500  
          * <li><code>'O'</code> - A tag for the "ok" or "done" button.
 501  
          * <li><code>'U'</code> - All Uncategorized, Other, or "Unknown" buttons. Tag will be "other".
 502  
          * <li><code>'+'</code> - A glue push gap that will take as much space as it can and at least an "unrelated" gap. (Platform dependant)
 503  
          * <li><code>'_'</code> - (underscore) An "unrelated" gap. (Platform dependant)
 504  
          * </ul>
 505  
          * <p>
 506  
          * Even though the style tags are normally applied to buttons this works with all components.
 507  
          * <p>
 508  
          * The normal style for MAC OS X is <code>"L_HE+U+FBI_NYCOA_R"</code>,
 509  
          * for Windows is <code>"L_E+U+FBI_YNOCAH_R"</code>, and for GNOME is
 510  
          * <code>"L_HE+UNYACBXIO_R"</code>.
 511  
          *
 512  
          * @param order The new button order for the current platform.
 513  
          */
 514  
         public static void setButtonOrder(String order)
 515  
         {
 516  
                 BUTTON_FORMAT = order;
 517  
                 MOD_COUNT++;
 518  
         }
 519  
 
 520  
         /** Returns the tag (used in the {@link CC}) for a char. The char is same as used in {@link #getButtonOrder()}.
 521  
          * @param c The char. Must be lower case!
 522  
          * @return The tag that corresponds to the char or <code>null</code> if the char is unrecognized.
 523  
          */
 524  
         static String getTagForChar(char c)
 525  
         {
 526  
                 switch (c) {
 527  
                         case 'o':
 528  
                                 return "ok";
 529  
                         case 'c':
 530  
                                 return "cancel";
 531  
                         case 'h':
 532  
                                 return "help";
 533  
                         case 'e':
 534  
                                 return "help2";
 535  
                         case 'y':
 536  
                                 return "yes";
 537  
                         case 'n':
 538  
                                 return "no";
 539  
                         case 'a':
 540  
                                 return "apply";
 541  
                         case 'x':
 542  
                                 return "next";  // a.k.a forward
 543  
                         case 'b':
 544  
                                 return "back";  // a.k.a. previous
 545  
                         case 'i':
 546  
                                 return "finish";
 547  
                         case 'l':
 548  
                                 return "left";
 549  
                         case 'r':
 550  
                                 return "right";
 551  
                         case 'u':
 552  
                                 return "other";
 553  
                         default:
 554  
                                 return null;
 555  
                 }
 556  
         }
 557  
 
 558  
         /** Returns the platform recommended inter-cell gap in the horizontal (x) dimension..
 559  
          * @return The platform recommended inter-cell gap in the horizontal (x) dimension..
 560  
          */
 561  
         public static BoundSize getGridGapX()
 562  
         {
 563  
                 return DEF_HGAP;
 564  
         }
 565  
 
 566  
         /** Returns the platform recommended inter-cell gap in the vertical (x) dimension..
 567  
          * @return The platform recommended inter-cell gap in the vertical (x) dimension..
 568  
          */
 569  
         public static BoundSize getGridGapY()
 570  
         {
 571  
                 return DEF_VGAP;
 572  
         }
 573  
 
 574  
         /** Returns the default dialog inset depending of the current platform.
 575  
          * @param side top == 0, left == 1, bottom = 2, right = 3.
 576  
          * @return The inset. Never <code>null</code>.
 577  
          */
 578  
         public static UnitValue getDialogInsets(int side)
 579  
         {
 580  
                 return DIALOG_INS[side];
 581  
         }
 582  
 
 583  
         /** Sets the default insets for a dialog. Values that are null will not be changed.
 584  
          * @param top The top inset. May be <code>null</code>.
 585  
          * @param left The left inset. May be <code>null</code>.
 586  
          * @param bottom The bottom inset. May be <code>null</code>.
 587  
          * @param right The right inset. May be <code>null</code>.
 588  
          */
 589  
         public static void setDialogInsets(UnitValue top, UnitValue left, UnitValue bottom, UnitValue right)
 590  
         {
 591  
                 if (top != null)
 592  
                         DIALOG_INS[0] = top;
 593  
 
 594  
                 if (left != null)
 595  
                         DIALOG_INS[1] = left;
 596  
 
 597  
                 if (bottom != null)
 598  
                         DIALOG_INS[2] = bottom;
 599  
 
 600  
                 if (right != null)
 601  
                         DIALOG_INS[3] = right;
 602  
 
 603  
                 MOD_COUNT++;
 604  
         }
 605  
 
 606  
         /** Returns the default panel inset depending of the current platform.
 607  
          * @param side top == 0, left == 1, bottom = 2, right = 3.
 608  
          * @return The inset. Never <code>null</code>.
 609  
          */
 610  
         public static UnitValue getPanelInsets(int side)
 611  
         {
 612  
                 return PANEL_INS[side];
 613  
         }
 614  
 
 615  
         /** Sets the default insets for a dialog. Values that are null will not be changed.
 616  
          * @param top The top inset. May be <code>null</code>.
 617  
          * @param left The left inset. May be <code>null</code>.
 618  
          * @param bottom The bottom inset. May be <code>null</code>.
 619  
          * @param right The right inset. May be <code>null</code>.
 620  
          */
 621  
         public static void setPanelInsets(UnitValue top, UnitValue left, UnitValue bottom, UnitValue right)
 622  
         {
 623  
                 if (top != null)
 624  
                         PANEL_INS[0] = top;
 625  
 
 626  
                 if (left != null)
 627  
                         PANEL_INS[1] = left;
 628  
 
 629  
                 if (bottom != null)
 630  
                         PANEL_INS[2] = bottom;
 631  
 
 632  
                 if (right != null)
 633  
                         PANEL_INS[3] = right;
 634  
 
 635  
                 MOD_COUNT++;
 636  
         }
 637  
 
 638  
         /** Returns the percentage used for alignment for labels (0 is left, 50 is center and 100 is right).
 639  
          * @return The percentage used for alignment for labels
 640  
          */
 641  
         public static float getLabelAlignPercentage()
 642  
         {
 643  
                 return CUR_PLAF == MAC_OSX ? 1f : 0f;
 644  
         }
 645  
 
 646  
         /** Returns the default gap between two components that <b>are in the same cell</b>.
 647  
          * @param comp The component that the gap is for. Never <code>null</code>.
 648  
          * @param adjacentComp The adjacent component if any. May be <code>null</code>.
 649  
          * @param adjacentSide What side the <code>adjacentComp</code> is on. {@link javax.swing.SwingUtilities#TOP} or
 650  
          * {@link javax.swing.SwingUtilities#LEFT} or {@link javax.swing.SwingUtilities#BOTTOM} or {@link javax.swing.SwingUtilities#RIGHT}.
 651  
          * @param tag The tag string that the component might be tagged with in the component constraints. May be <code>null</code>.
 652  
          * @param isLTR If it is left-to-right.
 653  
          * @return The default gap between two components or <code>null</code> if there should be no gap.
 654  
          */
 655  
         static BoundSize getDefaultComponentGap(ComponentWrapper comp, ComponentWrapper adjacentComp, int adjacentSide, String tag, boolean isLTR)
 656  
         {
 657  
                 if (GAP_PROVIDER != null)
 658  
                         return GAP_PROVIDER.getDefaultGap(comp, adjacentComp, adjacentSide, tag, isLTR);
 659  
 
 660  
                 if (adjacentComp == null)
 661  
                         return null;
 662  
 
 663  
 //                if (adjacentComp == null || adjacentSide == SwingConstants.LEFT || adjacentSide == SwingConstants.TOP)
 664  
 //                        return null;
 665  
 
 666  
                 return (adjacentSide == SwingConstants.LEFT || adjacentSide == SwingConstants.RIGHT) ? RELATED_X : RELATED_Y;
 667  
         }
 668  
 
 669  
         /** Returns the current gap provider or <code>null</code> if none is set and "related" should always be used.
 670  
          * @return The current gap provider or <code>null</code> if none is set and "related" should always be used.
 671  
          */
 672  
         public static InCellGapProvider getGapProvider()
 673  
         {
 674  
                 return GAP_PROVIDER;
 675  
         }
 676  
 
 677  
         /** Sets the current gap provider or <code>null</code> if none is set and "related" should always be used.
 678  
          * @param provider The current gap provider or <code>null</code> if none is set and "related" should always be used.
 679  
          */
 680  
         public static void setGapProvider(InCellGapProvider provider)
 681  
         {
 682  
                 GAP_PROVIDER = provider;
 683  
         }
 684  
 
 685  
         /** Returns how many times the defaults has been changed. This can be used as a light weight check to
 686  
          * see if layout caches needs to be refreshed.
 687  
          * @return How many times the defaults has been changed.
 688  
          */
 689  
         public static int getModCount()
 690  
         {
 691  
                 return MOD_COUNT;
 692  
         }
 693  
 
 694  
         /** Tells all layout manager instances to revalidate and recalculated everything.
 695  
          */
 696  
         public void invalidate()
 697  
         {
 698  
                 MOD_COUNT++;
 699  
         }
 700  
 
 701  
         /** Returns the current default unit. The default unit is the unit used if no unit is set. E.g. "width 10".
 702  
          * @return The current default unit.
 703  
          * @see UnitValue#PIXEL
 704  
          * @see UnitValue#LPX
 705  
          */
 706  
         public static int getDefaultHorizontalUnit()
 707  
         {
 708  
                 return DEF_H_UNIT;
 709  
         }
 710  
 
 711  
         /** Sets the default unit. The default unit is the unit used if no unit is set. E.g. "width 10".
 712  
          * @param unit The new default unit.
 713  
          * @see UnitValue#PIXEL
 714  
          * @see UnitValue#LPX
 715  
          */
 716  
         public static void setDefaultHorizontalUnit(int unit)
 717  
         {
 718  
                 if (unit < UnitValue.PIXEL || unit > UnitValue.LABEL_ALIGN)
 719  
                         throw new IllegalArgumentException("Illegal Unit: " + unit);
 720  
 
 721  
                 if (DEF_H_UNIT != unit) {
 722  
                         DEF_H_UNIT = unit;
 723  
                         MOD_COUNT++;
 724  
                 }
 725  
         }
 726  
 
 727  
         /** Returns the current default unit. The default unit is the unit used if no unit is set. E.g. "width 10".
 728  
          * @return The current default unit.
 729  
          * @see UnitValue#PIXEL
 730  
          * @see UnitValue#LPY
 731  
          */
 732  
         public static int getDefaultVerticalUnit()
 733  
         {
 734  
                 return DEF_V_UNIT;
 735  
         }
 736  
 
 737  
         /** Sets the default unit. The default unit is the unit used if no unit is set. E.g. "width 10".
 738  
          * @param unit The new default unit.
 739  
          * @see UnitValue#PIXEL
 740  
          * @see UnitValue#LPY
 741  
          */
 742  
         public static void setDefaultVerticalUnit(int unit)
 743  
         {
 744  
                 if (unit < UnitValue.PIXEL || unit > UnitValue.LABEL_ALIGN)
 745  
                         throw new IllegalArgumentException("Illegal Unit: " + unit);
 746  
 
 747  
                 if (DEF_V_UNIT != unit) {
 748  
                         DEF_V_UNIT = unit;
 749  
                         MOD_COUNT++;
 750  
                 }
 751  
         }
 752  
 
 753  
         /** The default alignment for rows. Pre v3.5 this was <code>false</code> but now it is
 754  
          * <code>true</code>.
 755  
          * @return The current value. Default is <code>true</code>.
 756  
          * @since 3.5
 757  
          */
 758  
         public static boolean getDefaultRowAlignmentBaseline()
 759  
         {
 760  
                 return dra;
 761  
         }
 762  
 
 763  
         /** The default alignment for rows. Pre v3.5 this was <code>false</code> but now it is
 764  
          * <code>true</code>.
 765  
          * @param b The new value. Default is <code>true</code> from v3.5.
 766  
          * @since 3.5
 767  
          */
 768  
         public static void setDefaultRowAlignmentBaseline(boolean b)
 769  
         {
 770  
                 dra = b;
 771  
         }
 772  
 }