1 package net.miginfocom.layout;
3 import java.util.HashMap;
9 * Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com)
10 * All rights reserved.
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.
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
35 * @author Mikael Grev, MiG InfoCom AB
37 * @author Xxxx Xxxx, Xxxx - Gnome support
41 /** Currently handles Windows, Mac OS X, and GNOME spacing.
43 public final class PlatformDefaults
45 /** Property to use in LAF settings and as JComponent client property
46 * to specify the visual padding.
49 public static String VISUAL_PADDING_PROPERTY = "visualPadding";
51 private static int DEF_H_UNIT = UnitValue.LPX;
52 private static int DEF_V_UNIT = UnitValue.LPY;
54 private static InCellGapProvider GAP_PROVIDER = null;
56 private static volatile int MOD_COUNT = 0;
58 // private static final UnitValue LPX1 = new UnitValue(1, UnitValue.LPX, null);
59 // private static final UnitValue LPX4 = new UnitValue(4, UnitValue.LPX, null);
60 private static final UnitValue LPX6 = new UnitValue(6, UnitValue.LPX, null);
61 private static final UnitValue LPX7 = new UnitValue(7, UnitValue.LPX, null);
62 // private static final UnitValue LPX8 = new UnitValue(8, UnitValue.LPX, null);
63 // private static final UnitValue LPX9 = new UnitValue(9, UnitValue.LPX, null);
64 // private static final UnitValue LPX10 = new UnitValue(10, UnitValue.LPX, null);
65 private static final UnitValue LPX11 = new UnitValue(11, UnitValue.LPX, null);
66 private static final UnitValue LPX12 = new UnitValue(12, UnitValue.LPX, null);
67 // private static final UnitValue LPX14 = new UnitValue(14, UnitValue.LPX, null);
68 private static final UnitValue LPX16 = new UnitValue(16, UnitValue.LPX, null);
69 private static final UnitValue LPX18 = new UnitValue(18, UnitValue.LPX, null);
70 private static final UnitValue LPX20 = new UnitValue(20, UnitValue.LPX, null);
72 // private static final UnitValue LPY1 = new UnitValue(1, UnitValue.LPY, null);
73 // private static final UnitValue LPY4 = new UnitValue(4, UnitValue.LPY, null);
74 private static final UnitValue LPY6 = new UnitValue(6, UnitValue.LPY, null);
75 private static final UnitValue LPY7 = new UnitValue(7, UnitValue.LPY, null);
76 // private static final UnitValue LPY8 = new UnitValue(8, UnitValue.LPY, null);
77 // private static final UnitValue LPY9 = new UnitValue(9, UnitValue.LPY, null);
78 // private static final UnitValue LPY10 = new UnitValue(10, UnitValue.LPY, null);
79 private static final UnitValue LPY11 = new UnitValue(11, UnitValue.LPY, null);
80 private static final UnitValue LPY12 = new UnitValue(12, UnitValue.LPY, null);
81 // private static final UnitValue LPY14 = new UnitValue(14, UnitValue.LPY, null);
82 private static final UnitValue LPY16 = new UnitValue(16, UnitValue.LPY, null);
83 private static final UnitValue LPY18 = new UnitValue(18, UnitValue.LPY, null);
84 private static final UnitValue LPY20 = new UnitValue(20, UnitValue.LPY, null);
86 public static final int WINDOWS_XP = 0;
87 public static final int MAC_OSX = 1;
88 public static final int GNOME = 2;
89 // private static final int KDE = 3;
91 private static int CUR_PLAF = WINDOWS_XP;
93 // Used for holding values.
94 private final static UnitValue[] PANEL_INS = new UnitValue[4];
95 private final static UnitValue[] DIALOG_INS = new UnitValue[4];
97 private static String BUTTON_FORMAT = null;
99 private static final HashMap<String, UnitValue> HOR_DEFS = new HashMap<String, UnitValue>(32);
100 private static final HashMap<String, UnitValue> VER_DEFS = new HashMap<String, UnitValue>(32);
101 private static BoundSize DEF_VGAP = null, DEF_HGAP = null;
102 static BoundSize RELATED_X = null, RELATED_Y = null, UNRELATED_X = null, UNRELATED_Y = null;
103 private static UnitValue BUTT_WIDTH = null;
104 private static UnitValue BUTT_PADDING = null;
106 private static Float horScale = null, verScale = null;
108 /** I value indicating that the size of the font for the container of the component
109 * will be used as a base for calculating the logical pixel size. This is much as how
110 * Windows calculated DLU (dialog units).
111 * @see net.miginfocom.layout.UnitValue#LPX
112 * @see net.miginfocom.layout.UnitValue#LPY
113 * @see #setLogicalPixelBase(int)
115 public static final int BASE_FONT_SIZE = 100;
117 /** I value indicating that the screen DPI will be used as a base for calculating the
118 * logical pixel size.
120 * This is the default value.
121 * @see net.miginfocom.layout.UnitValue#LPX
122 * @see net.miginfocom.layout.UnitValue#LPY
123 * @see #setLogicalPixelBase(int)
124 * @see #setVerticalScaleFactor(Float)
125 * @see #setHorizontalScaleFactor(Float)
127 public static final int BASE_SCALE_FACTOR = 101;
129 /** I value indicating that the size of a logical pixel should always be a real pixel
130 * and thus no compensation will be made.
131 * @see net.miginfocom.layout.UnitValue#LPX
132 * @see net.miginfocom.layout.UnitValue#LPY
133 * @see #setLogicalPixelBase(int)
135 public static final int BASE_REAL_PIXEL = 102;
137 private static int LP_BASE = BASE_SCALE_FACTOR;
139 private static Integer BASE_DPI_FORCED = null;
140 private static int BASE_DPI = 96;
142 private static boolean dra = true;
144 private static final HashMap<String, int[]> VISUAL_BOUNDS = new HashMap<String, int[]>(64);
147 setPlatform(getCurrentPlatform());
151 /** Returns the platform that the JRE is running on currently.
152 * @return The platform that the JRE is running on currently. E.g. {@link #MAC_OSX}, {@link #WINDOWS_XP}, or {@link #GNOME}.
154 public static int getCurrentPlatform()
156 if (/** @j2sNative true ||*/false)
158 final String os = System.getProperty("os.name");
159 if (os.startsWith("Mac OS")) {
161 } else if (os.startsWith("Linux")) {
168 private PlatformDefaults()
172 /** Set the defaults to the default for the platform
173 * @param plaf The platform. <code>PlatformDefaults.WINDOWS_XP</code>,
174 * <code>PlatformDefaults.MAC_OSX</code>, or
175 * <code>PlatformDefaults.GNOME</code>.
177 public static void setPlatform(int plaf)
181 setDefaultVisualPadding("TabbedPane." + VISUAL_PADDING_PROPERTY, new int[]{1, 0, 1, 2});
182 setRelatedGap(LPX7, LPY7);
183 setUnrelatedGap(LPX11, LPY11);
184 setParagraphGap(LPX20, LPY20);
185 setIndentGap(LPX11, LPY11);
186 setGridCellGap(LPX7, LPY7);
188 setMinimumButtonWidth(new UnitValue(75, UnitValue.LPX, null));
189 setButtonOrder("L_E+U+YNBXOCAH_I_R");
190 setDialogInsets(LPY11, LPX11, LPY11, LPX11);
191 setPanelInsets(LPY7, LPX7, LPY7, LPX7);
196 setDefaultVisualPadding("Button." + VISUAL_PADDING_PROPERTY, new int[]{3, 6, 5, 6});
197 setDefaultVisualPadding("Button.icon." + VISUAL_PADDING_PROPERTY, new int[]{3, 2, 3, 2});
198 setDefaultVisualPadding("Button.square." + VISUAL_PADDING_PROPERTY, new int[]{4, 4, 4, 4});
199 setDefaultVisualPadding("Button.square.icon." + VISUAL_PADDING_PROPERTY, new int[]{4, 4, 4, 4});
200 setDefaultVisualPadding("Button.gradient." + VISUAL_PADDING_PROPERTY, new int[]{5, 4, 5, 4});
201 setDefaultVisualPadding("Button.gradient.icon." + VISUAL_PADDING_PROPERTY, new int[]{5, 4, 5, 4});
202 setDefaultVisualPadding("Button.bevel." + VISUAL_PADDING_PROPERTY, new int[]{2, 2, 3, 2});
203 setDefaultVisualPadding("Button.bevel.icon." + VISUAL_PADDING_PROPERTY, new int[]{2, 2, 3, 2});
204 setDefaultVisualPadding("Button.textured." + VISUAL_PADDING_PROPERTY, new int[]{3, 2, 3, 2});
205 setDefaultVisualPadding("Button.textured.icon." + VISUAL_PADDING_PROPERTY, new int[]{3, 2, 3, 2});
206 setDefaultVisualPadding("Button.roundRect." + VISUAL_PADDING_PROPERTY, new int[]{5, 4, 5, 4});
207 setDefaultVisualPadding("Button.roundRect.icon." + VISUAL_PADDING_PROPERTY, new int[]{5, 4, 5, 4});
208 setDefaultVisualPadding("Button.recessed." + VISUAL_PADDING_PROPERTY, new int[]{5, 4, 5, 4});
209 setDefaultVisualPadding("Button.recessed.icon." + VISUAL_PADDING_PROPERTY, new int[]{5, 4, 5, 4});
210 setDefaultVisualPadding("Button.help." + VISUAL_PADDING_PROPERTY, new int[]{4, 3, 3, 4});
211 setDefaultVisualPadding("Button.help.icon." + VISUAL_PADDING_PROPERTY, new int[]{4, 3, 3, 4});
213 setDefaultVisualPadding("ComboBox." + VISUAL_PADDING_PROPERTY, new int[]{2, 4, 4, 5});
214 setDefaultVisualPadding("ComboBox.isPopDown." + VISUAL_PADDING_PROPERTY, new int[]{2, 5, 4, 5});
215 setDefaultVisualPadding("ComboBox.isSquare." + VISUAL_PADDING_PROPERTY, new int[]{1, 6, 5, 7});
217 setDefaultVisualPadding("ComboBox.editable." + VISUAL_PADDING_PROPERTY, new int[]{3, 3, 3, 2});
218 setDefaultVisualPadding("ComboBox.editable.isSquare." + VISUAL_PADDING_PROPERTY, new int[]{3, 3, 3, 1});
220 setDefaultVisualPadding("TextField." + VISUAL_PADDING_PROPERTY, new int[]{3, 3, 3, 3});
221 setDefaultVisualPadding("TabbedPane." + VISUAL_PADDING_PROPERTY, new int[]{4, 8, 11, 8});
223 setDefaultVisualPadding("Spinner." + VISUAL_PADDING_PROPERTY, new int[]{3, 3, 3, 1});
225 setDefaultVisualPadding("RadioButton." + VISUAL_PADDING_PROPERTY, new int[]{4, 6, 3, 5});
226 setDefaultVisualPadding("RadioButton.small." + VISUAL_PADDING_PROPERTY, new int[]{4, 6, 3, 5});
227 setDefaultVisualPadding("RadioButton.mini." + VISUAL_PADDING_PROPERTY, new int[]{5, 7, 4, 5});
228 setDefaultVisualPadding("CheckBox." + VISUAL_PADDING_PROPERTY, new int[]{5, 7, 4, 5});
229 setDefaultVisualPadding("CheckBox.small." + VISUAL_PADDING_PROPERTY, new int[]{5, 7, 4, 5});
230 setDefaultVisualPadding("CheckBox.mini." + VISUAL_PADDING_PROPERTY, new int[]{6, 7, 3, 5});
232 setRelatedGap(LPX7, LPY7);
233 setUnrelatedGap(LPX11, LPY11);
234 setParagraphGap(LPX20, LPY20);
235 setIndentGap(LPX11, LPY11);
236 setGridCellGap(LPX7, LPY7);
238 setMinimumButtonWidth(new UnitValue(70, UnitValue.LPX, null));
239 setMinimumButtonPadding(new UnitValue(8, UnitValue.LPX, null));
240 setButtonOrder("L_HE+U+NYBXCOA_I_R");
241 setDialogInsets(LPY20, LPX20, LPY20, LPX20);
242 setPanelInsets(LPY16, LPX16, LPY16, LPX16);
246 setRelatedGap(LPX6, LPY6); // GNOME HIG 8.2.3
247 setUnrelatedGap(LPX12, LPY12); // GNOME HIG 8.2.3
248 setParagraphGap(LPX18, LPY18); // GNOME HIG 8.2.3
249 setIndentGap(LPX12, LPY12); // GNOME HIG 8.2.3
250 setGridCellGap(LPX6, LPY6); // GNOME HIG 8.2.3
252 // GtkButtonBox, child-min-width property default value
253 setMinimumButtonWidth(new UnitValue(85, UnitValue.LPX, null));
254 setButtonOrder("L_HE+UNYACBXO_I_R"); // GNOME HIG 3.4.2, 3.7.1
255 setDialogInsets(LPY12, LPX12, LPY12, LPX12); // GNOME HIG 3.4.3
256 setPanelInsets(LPY6, LPX6, LPY6, LPX6); // ???
259 throw new IllegalArgumentException("Unknown platform: " + plaf);
262 BASE_DPI = BASE_DPI_FORCED != null ? BASE_DPI_FORCED : getPlatformDPI(plaf);
265 /** Sets the visual bounds for a component type.
266 * @param key The component type. E.g. "TabbedPane.visualPadding" or "ComboBox.editable.isSquare.visualPadding". See source code for list.
267 * @param insets Top, left, bottom, right. Always length 4 or null.
268 * @see net.miginfocom.layout.ComponentWrapper#getVisualPadding()
270 public static void setDefaultVisualPadding(String key, int[] insets)
272 VISUAL_BOUNDS.put(key, insets);
275 /** Returns the visual bounds for a component type.
276 * @param key The component type. E.g. "TabbedPane.visualPadding" or "ComboBox.editable.isSquare.visualPadding". See source code for list.
277 * @return insets Top, left, bottom, right. Always length 4 or null. Live object, MUST NOT BE CHANGED!.
278 * @see net.miginfocom.layout.ComponentWrapper#getVisualPadding()
280 public static int[] getDefaultVisualPadding(String key)
282 return VISUAL_BOUNDS.get(key);
285 public static int getPlatformDPI(int plaf)
293 return java.awt.Toolkit.getDefaultToolkit().getScreenResolution();
294 } catch (Throwable t) {
298 throw new IllegalArgumentException("Unknown platform: " + plaf);
302 /** Returns the current platform
303 * @return <code>PlatformDefaults.WINDOWS</code> or <code>PlatformDefaults.MAC_OSX</code>
305 public static int getPlatform()
310 public static int getDefaultDPI()
315 /** Sets the default platform DPI. Normally this is set in the {@link #setPlatform(int)} for the different platforms
316 * but it can be tweaked here. For instance SWT on Mac does this.
318 * Note that this is not the actual current DPI, but the base DPI for the toolkit.
319 * @param dpi The base DPI. If null the default DPI is reset to the platform base DPI.
321 public static void setDefaultDPI(Integer dpi)
323 BASE_DPI = dpi != null ? dpi : getPlatformDPI(CUR_PLAF);
324 BASE_DPI_FORCED = dpi;
327 /** The forced scale factor that all screen relative units (e.g. millimeters, inches and logical pixels) will be multiplied
328 * with. If <code>null</code> this will default to a scale that will scale the current screen to the default screen resolution
329 * (72 DPI for Mac and 92 DPI for Windows).
330 * @return The forced scale or <code>null</code> for default scaling.
331 * @see #getHorizontalScaleFactor()
332 * @see ComponentWrapper#getHorizontalScreenDPI()
334 public static Float getHorizontalScaleFactor()
339 /** The forced scale factor that all screen relative units (e.g. millimeters, inches and logical pixels) will be multiplied
340 * with. If <code>null</code> this will default to a scale that will scale the current screen to the default screen resolution
341 * (72 DPI for Mac and 92 DPI for Windows).
342 * @param f The forced scale or <code>null</code> for default scaling.
343 * @see #getHorizontalScaleFactor()
344 * @see ComponentWrapper#getHorizontalScreenDPI()
346 public static void setHorizontalScaleFactor(Float f)
348 if (!LayoutUtil.equals(horScale, f)) {
354 /** The forced scale factor that all screen relative units (e.g. millimeters, inches and logical pixels) will be multiplied
355 * with. If <code>null</code> this will default to a scale that will scale the current screen to the default screen resolution
356 * (72 DPI for Mac and 92 DPI for Windows).
357 * @return The forced scale or <code>null</code> for default scaling.
358 * @see #getHorizontalScaleFactor()
359 * @see ComponentWrapper#getVerticalScreenDPI()
361 public static Float getVerticalScaleFactor()
366 /** The forced scale factor that all screen relative units (e.g. millimeters, inches and logical pixels) will be multiplied
367 * with. If <code>null</code> this will default to a scale that will scale the current screen to the default screen resolution
368 * (72 DPI for Mac and 92 DPI for Windows).
369 * @param f The forced scale or <code>null</code> for default scaling.
370 * @see #getHorizontalScaleFactor()
371 * @see ComponentWrapper#getVerticalScreenDPI()
373 public static void setVerticalScaleFactor(Float f)
375 if (!LayoutUtil.equals(verScale, f)) {
381 /** What base value should be used to calculate logical pixel sizes.
382 * @return The current base. Default is {@link #BASE_SCALE_FACTOR}
383 * @see #BASE_FONT_SIZE
384 * @see #BASE_SCALE_FACTOR
385 * @see #BASE_REAL_PIXEL
387 public static int getLogicalPixelBase()
392 /** What base value should be used to calculate logical pixel sizes.
393 * @param base The new base. Default is {@link #BASE_SCALE_FACTOR}
394 * @see #BASE_FONT_SIZE
395 * @see #BASE_SCALE_FACTOR
396 * @see #BASE_REAL_PIXEL
398 public static void setLogicalPixelBase(int base)
400 if (LP_BASE != base) {
401 if (base < BASE_FONT_SIZE || base > BASE_REAL_PIXEL)
402 throw new IllegalArgumentException("Unrecognized base: " + base);
409 /** Sets gap value for components that are "related".
410 * @param x The value that will be transformed to pixels. If <code>null</code> the current value will not change.
411 * @param y The value that will be transformed to pixels. If <code>null</code> the current value will not change.
413 public static void setRelatedGap(UnitValue x, UnitValue y)
415 setUnitValue(new String[] {"r", "rel", "related"}, x, y);
417 RELATED_X = new BoundSize(x, x, null, "rel:rel");
418 RELATED_Y = new BoundSize(y, y, null, "rel:rel");
421 /** Sets gap value for components that are "unrelated".
422 * @param x The value that will be transformed to pixels. If <code>null</code> the current value will not change.
423 * @param y The value that will be transformed to pixels. If <code>null</code> the current value will not change.
425 public static void setUnrelatedGap(UnitValue x, UnitValue y)
427 setUnitValue(new String[] {"u", "unrel", "unrelated"}, x, y);
429 UNRELATED_X = new BoundSize(x, x, null, "unrel:unrel");
430 UNRELATED_Y = new BoundSize(y, y, null, "unrel:unrel");
433 /** Sets paragraph gap value for components.
434 * @param x The value that will be transformed to pixels. If <code>null</code> the current value will not change.
435 * @param y The value that will be transformed to pixels. If <code>null</code> the current value will not change.
437 public static void setParagraphGap(UnitValue x, UnitValue y)
439 setUnitValue(new String[] {"p", "para", "paragraph"}, x, y);
442 /** Sets gap value for components that are "intended".
443 * @param x The value that will be transformed to pixels. If <code>null</code> the current value will not change.
444 * @param y The value that will be transformed to pixels. If <code>null</code> the current value will not change.
446 public static void setIndentGap(UnitValue x, UnitValue y)
448 setUnitValue(new String[] {"i", "ind", "indent"}, x, y);
451 /** 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
452 * on the component constraints. The value will be the min and preferred size of the gap.
453 * @param x The value that will be transformed to pixels. If <code>null</code> the current value will not change.
454 * @param y The value that will be transformed to pixels. If <code>null</code> the current value will not change.
456 public static void setGridCellGap(UnitValue x, UnitValue y)
459 DEF_HGAP = new BoundSize(x, x, null, null);
462 DEF_VGAP = new BoundSize(y, y, null, null);
467 /** Sets the recommended minimum button width.
468 * @param width The recommended minimum button width.
470 public static void setMinimumButtonWidth(UnitValue width)
476 /** Returns the recommended minimum button width depending on the current set platform.
477 * @return The recommended minimum button width depending on the current set platform.
479 public static UnitValue getMinimumButtonWidth()
484 public static void setMinimumButtonPadding(UnitValue padding)
486 BUTT_PADDING = padding;
490 public static UnitValue getMinimumButtonPadding()
495 public static float getMinimumButtonWidthIncludingPadding(float refValue, ContainerWrapper parent, ComponentWrapper comp)
497 final int buttonMinWidth = getMinimumButtonWidth().getPixels(refValue, parent, comp);
498 if (comp != null && getMinimumButtonPadding() != null) {
499 return Math.max(comp.getMinimumWidth(comp.getWidth()) + getMinimumButtonPadding().getPixels(refValue, parent, comp) * 2, buttonMinWidth);
501 return buttonMinWidth;
505 /** Returns the unit value associated with the unit. (E.i. "related" or "indent"). Must be lower case.
506 * @param unit The unit string.
507 * @return The unit value associated with the unit. <code>null</code> for unrecognized units.
509 public static UnitValue getUnitValueX(String unit)
511 return HOR_DEFS.get(unit);
514 /** Returns the unit value associated with the unit. (E.i. "related" or "indent"). Must be lower case.
515 * @param unit The unit string.
516 * @return The unit value associated with the unit. <code>null</code> for unrecognized units.
518 public static UnitValue getUnitValueY(String unit)
520 return VER_DEFS.get(unit);
523 /** Sets the unit value associated with a unit string. This may be used to store values for new unit strings
524 * or modify old. Note that if a built in unit (such as "related") is modified all versions of it must be
525 * set (I.e. "r", "rel" and "related"). The build in values will be reset to the default ones if the platform
527 * @param unitStrings The unit strings. E.g. "mu", "myunit". Will be converted to lower case and trimmed. Not <code>null</code>.
528 * @param x The value for the horizontal dimension. If <code>null</code> the value is not changed.
529 * @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.
531 public static void setUnitValue(String[] unitStrings, UnitValue x, UnitValue y)
533 for (String unitString : unitStrings) {
534 String s = unitString.toLowerCase().trim();
543 /** Understands ("r", "rel", "related") OR ("u", "unrel", "unrelated") OR ("i", "ind", "indent") OR ("p", "para", "paragraph").
545 static int convertToPixels(float value, String unit, boolean isHor, float ref, ContainerWrapper parent, ComponentWrapper comp)
547 UnitValue uv = (isHor ? HOR_DEFS : VER_DEFS).get(unit);
548 return uv != null ? Math.round(value * uv.getPixels(ref, parent, comp)) : UnitConverter.UNABLE;
551 /** Returns the order for the typical buttons in a standard button bar. It is one letter per button type.
552 * @return The button order.
553 * @see #setButtonOrder(String)
555 public static String getButtonOrder()
557 return BUTTON_FORMAT;
560 /** Sets the order for the typical buttons in a standard button bar. It is one letter per button type.
562 * Letter in upper case will get the minimum button width that the {@link #getMinimumButtonWidth()} specifies
563 * and letters in lower case will get the width the current look&feel specifies.
565 * Gaps will never be added to before the first component or after the last component. However, '+' (push) will be
566 * applied before and after as well, but with a minimum size of 0 if first/last so there will not be a gap
569 * If gaps are explicitly set on buttons they will never be reduced, but they may be increased.
571 * These are the characters that can be used:
573 * <li><code>'L'</code> - Buttons with this style tag will statically end up on the left end of the bar.
574 * <li><code>'R'</code> - Buttons with this style tag will statically end up on the right end of the bar.
575 * <li><code>'H'</code> - A tag for the "help" button that normally is supposed to be on the right.
576 * <li><code>'E'</code> - A tag for the "help2" button that normally is supposed to be on the left.
577 * <li><code>'Y'</code> - A tag for the "yes" button.
578 * <li><code>'N'</code> - A tag for the "no" button.
579 * <li><code>'X'</code> - A tag for the "next >" or "forward >" button.
580 * <li><code>'B'</code> - A tag for the "< back" or "< previous" button.
581 * <li><code>'I'</code> - A tag for the "finish" button.
582 * <li><code>'A'</code> - A tag for the "apply" button.
583 * <li><code>'C'</code> - A tag for the "cancel" or "close" button.
584 * <li><code>'O'</code> - A tag for the "ok" or "done" button.
585 * <li><code>'U'</code> - All Uncategorized, Other, or "Unknown" buttons. Tag will be "other".
586 * <li><code>'+'</code> - A glue push gap that will take as much space as it can and at least an "unrelated" gap. (Platform dependent)
587 * <li><code>'_'</code> - (underscore) An "unrelated" gap. (Platform dependent)
590 * Even though the style tags are normally applied to buttons this works with all components.
592 * The normal style for MAC OS X is <code>"L_HE+U+NYBXCOA_I_R"</code>,
593 * for Windows is <code>"L_E+U+YNBXOCAH_I_R"</code>, and for GNOME is
594 * <code>"L_HE+UNYACBXO_I_R"</code>.
596 * @param order The new button order for the current platform.
598 public static void setButtonOrder(String order)
600 BUTTON_FORMAT = order;
604 /** Returns the tag (used in the {@link CC}) for a char. The char is same as used in {@link #getButtonOrder()}.
605 * @param c The char. Must be lower case!
606 * @return The tag that corresponds to the char or <code>null</code> if the char is unrecognized.
608 static String getTagForChar(char c)
626 return "next"; // a.k.a forward
628 return "back"; // a.k.a. previous
642 /** Returns the platform recommended inter-cell gap in the horizontal (x) dimension..
643 * @return The platform recommended inter-cell gap in the horizontal (x) dimension..
645 public static BoundSize getGridGapX()
650 /** Returns the platform recommended inter-cell gap in the vertical (x) dimension..
651 * @return The platform recommended inter-cell gap in the vertical (x) dimension..
653 public static BoundSize getGridGapY()
658 /** Returns the default dialog insets depending of the current platform.
659 * @param side top == 0, left == 1, bottom = 2, right = 3.
660 * @return The insets. Never <code>null</code>.
662 public static UnitValue getDialogInsets(int side)
664 return DIALOG_INS[side];
667 /** Sets the default insets for a dialog. Values that are null will not be changed.
668 * @param top The top inset. May be <code>null</code>.
669 * @param left The left inset. May be <code>null</code>.
670 * @param bottom The bottom inset. May be <code>null</code>.
671 * @param right The right inset. May be <code>null</code>.
673 public static void setDialogInsets(UnitValue top, UnitValue left, UnitValue bottom, UnitValue right)
679 DIALOG_INS[1] = left;
682 DIALOG_INS[2] = bottom;
685 DIALOG_INS[3] = right;
690 /** Returns the default panel insets depending of the current platform.
691 * @param side top == 0, left == 1, bottom = 2, right = 3.
692 * @return The insets. Never <code>null</code>.
694 public static UnitValue getPanelInsets(int side)
696 return PANEL_INS[side];
699 /** Sets the default insets for a dialog. Values that are null will not be changed.
700 * @param top The top inset. May be <code>null</code>.
701 * @param left The left inset. May be <code>null</code>.
702 * @param bottom The bottom inset. May be <code>null</code>.
703 * @param right The right inset. May be <code>null</code>.
705 public static void setPanelInsets(UnitValue top, UnitValue left, UnitValue bottom, UnitValue right)
714 PANEL_INS[2] = bottom;
717 PANEL_INS[3] = right;
722 /** Returns the percentage used for alignment for labels (0 is left, 50 is center and 100 is right).
723 * @return The percentage used for alignment for labels
725 public static float getLabelAlignPercentage()
727 return CUR_PLAF == MAC_OSX ? 1f : 0f;
730 /** Returns the default gap between two components that <b>are in the same cell</b>.
731 * @param comp The component that the gap is for. Never <code>null</code>.
732 * @param adjacentComp The adjacent component if any. May be <code>null</code>.
733 * @param adjacentSide What side the <code>adjacentComp</code> is on. {@link javax.swing.SwingUtilities#TOP} (1) or
734 * {@link javax.swing.SwingUtilities#LEFT} (2) or {@link javax.swing.SwingUtilities#BOTTOM} (3) or {@link javax.swing.SwingUtilities#RIGHT} (4).
735 * @param tag The tag string that the component might be tagged with in the component constraints. May be <code>null</code>.
736 * @param isLTR If it is left-to-right.
737 * @return The default gap between two components or <code>null</code> if there should be no gap.
739 static BoundSize getDefaultComponentGap(ComponentWrapper comp, ComponentWrapper adjacentComp, int adjacentSide, String tag, boolean isLTR)
741 if (GAP_PROVIDER != null)
742 return GAP_PROVIDER.getDefaultGap(comp, adjacentComp, adjacentSide, tag, isLTR);
744 if (adjacentComp == null)
747 // if (adjacentComp == null || adjacentSide == SwingConstants.LEFT || adjacentSide == SwingConstants.TOP)
750 // SwingConstants.RIGHT == 4, SwingConstants.LEFT == 2
751 return (adjacentSide == 2 || adjacentSide == 4) ? RELATED_X : RELATED_Y;
754 /** Returns the current gap provider or <code>null</code> if none is set and "related" should always be used.
755 * @return The current gap provider or <code>null</code> if none is set and "related" should always be used.
757 public static InCellGapProvider getGapProvider()
762 /** Sets the current gap provider or <code>null</code> if none is set and "related" should always be used.
763 * @param provider The current gap provider or <code>null</code> if none is set and "related" should always be used.
765 public static void setGapProvider(InCellGapProvider provider)
767 GAP_PROVIDER = provider;
770 /** Returns how many times the defaults has been changed. This can be used as a light weight check to
771 * see if layout caches needs to be refreshed.
772 * @return How many times the defaults has been changed.
774 public static int getModCount()
779 /** Tells all layout manager instances to revalidate and recalculated everything.
781 public void invalidate()
786 /** Returns the current default unit. The default unit is the unit used if no unit is set. E.g. "width 10".
787 * @return The current default unit.
788 * @see UnitValue#PIXEL
791 public static int getDefaultHorizontalUnit()
796 /** Sets the default unit. The default unit is the unit used if no unit is set. E.g. "width 10".
797 * @param unit The new default unit.
798 * @see UnitValue#PIXEL
801 public static void setDefaultHorizontalUnit(int unit)
803 if (unit < UnitValue.PIXEL || unit > UnitValue.LABEL_ALIGN)
804 throw new IllegalArgumentException("Illegal Unit: " + unit);
806 if (DEF_H_UNIT != unit) {
812 /** Returns the current default unit. The default unit is the unit used if no unit is set. E.g. "width 10".
813 * @return The current default unit.
814 * @see UnitValue#PIXEL
817 public static int getDefaultVerticalUnit()
822 /** Sets the default unit. The default unit is the unit used if no unit is set. E.g. "width 10".
823 * @param unit The new default unit.
824 * @see UnitValue#PIXEL
827 public static void setDefaultVerticalUnit(int unit)
829 if (unit < UnitValue.PIXEL || unit > UnitValue.LABEL_ALIGN)
830 throw new IllegalArgumentException("Illegal Unit: " + unit);
832 if (DEF_V_UNIT != unit) {
838 /** The default alignment for rows. Pre v3.5 this was <code>false</code> but now it is
840 * @return The current value. Default is <code>true</code>.
843 public static boolean getDefaultRowAlignmentBaseline()
848 /** The default alignment for rows. Pre v3.5 this was <code>false</code> but now it is
850 * @param b The new value. Default is <code>true</code> from v3.5.
853 public static void setDefaultRowAlignmentBaseline(boolean b)