001: /*
002: * Copyright (c) 2002-2007 JGoodies Karsten Lentzsch. All Rights Reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * o Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * o Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * o Neither the name of JGoodies Karsten Lentzsch nor the names of
015: * its contributors may be used to endorse or promote products derived
016: * from this software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
020: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
021: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
022: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
025: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
026: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
027: * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
028: * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029: */
030:
031: package com.jgoodies.forms.util;
032:
033: import java.util.logging.Logger;
034:
035: import com.jgoodies.forms.layout.ConstantSize;
036: import com.jgoodies.forms.layout.Size;
037:
038: /**
039: * An abstract class that describes a layout and design style guide.
040: * It provides constants used to lay out panels consistently.<p>
041: *
042: * This class is work in progress and the API may change without notice.
043: * Therefore it is recommended to not write custom subclasses
044: * for production code.
045: * A future version of this class will likely collaborate with a class
046: * <code>LogicalSize</code> or <code>StyledSize</code>.
047: *
048: * @author Karsten Lentzsch
049: * @version $Revision: 1.4 $
050: *
051: * @see com.jgoodies.forms.util.MacLayoutStyle
052: * @see com.jgoodies.forms.util.WindowsLayoutStyle
053: * @see com.jgoodies.forms.factories.FormFactory
054: * @see com.jgoodies.forms.factories.Borders
055: */
056:
057: public abstract class LayoutStyle {
058:
059: /**
060: * Holds the current layout style.
061: */
062: private static LayoutStyle current = initialLayoutStyle();
063:
064: // Computing the initial layout style *************************************
065:
066: /**
067: * Computes and returns the initial <code>LayoutStyle</code>.
068: * Checks the OS name and returns <code>MacLayoutStyle</code>
069: * on Mac OS X and <code>WindowLayoutStyle</code> on all other platforms.
070: *
071: * @return MacLayoutStyle on Mac, WindowsLayoutStyle on all other platforms
072: */
073: private static LayoutStyle initialLayoutStyle() {
074: if (isOSMac())
075: return MacLayoutStyle.INSTANCE;
076: return WindowsLayoutStyle.INSTANCE;
077: }
078:
079: /**
080: * Checks and answers whether Java runs on a Mac by requesting
081: * the system property <em>os.name</em>.
082: *
083: * @return true on Mac, false on all other Platforms
084: */
085: private static boolean isOSMac() {
086: return getSystemProperty("os.name").startsWith("Mac");
087: }
088:
089: /**
090: * Tries to look up the System property for the given key.
091: * In untrusted environments this may throw a SecurityException.
092: * In this case we catch the exception and answer <code>null</code>.
093: *
094: * @param key the name of the system property
095: * @return the system property's String value, or a blank string
096: * if there's no such value, or a SecurityException has been caught
097: */
098: private static String getSystemProperty(String key) {
099: try {
100: return System.getProperty(key);
101: } catch (SecurityException e) {
102: Logger.getLogger(LayoutStyle.class.getName()).warning(
103: "Can't read the System property " + key + ".");
104: return "";
105: }
106: }
107:
108: // Accessing the current style ******************************************
109:
110: /**
111: * Returns the current <code>LayoutStyle</code>.
112: *
113: * @return the current <code>LayoutStyle</code>
114: */
115: public static LayoutStyle getCurrent() {
116: return current;
117: }
118:
119: /**
120: * Set a new <code>LayoutStyle</code>.
121: *
122: * @param newLayoutStyle the style to be set
123: */
124: public static void setCurrent(LayoutStyle newLayoutStyle) {
125: current = newLayoutStyle;
126: }
127:
128: // Layout Sizes *********************************************************
129:
130: /**
131: * Returns this style's default button width.
132: *
133: * @return the default button width
134: *
135: * @see #getDefaultButtonHeight()
136: */
137: public abstract Size getDefaultButtonWidth();
138:
139: /**
140: * Returns this style's default button height.
141: *
142: * @return the default button height
143: *
144: * @see #getDefaultButtonWidth()
145: */
146: public abstract Size getDefaultButtonHeight();
147:
148: /**
149: * Returns this style's horizontal margin for general dialogs.
150: *
151: * @return the horizontal margin for general dialogs
152: *
153: * @see #getDialogMarginY()
154: * @see #getTabbedDialogMarginX()
155: */
156: public abstract ConstantSize getDialogMarginX();
157:
158: /**
159: * Returns this style's vertical margin for general dialogs.
160: *
161: * @return the vertical margin for general dialogs
162: *
163: * @see #getDialogMarginX()
164: * @see #getTabbedDialogMarginY()
165: */
166: public abstract ConstantSize getDialogMarginY();
167:
168: /**
169: * Returns this style's horizontal margin for dialogs that consist of
170: * a tabbed pane.
171: *
172: * @return the horizontal margin for dialogs that consist of a tabbed pane
173: * @since 1.0.3
174: *
175: * @see #getTabbedDialogMarginY()
176: * @see #getDialogMarginX()
177: */
178: public abstract ConstantSize getTabbedDialogMarginX();
179:
180: /**
181: * Returns this style's vertical margin for dialogs that consist of
182: * a tabbed pane.
183: *
184: * @return the vertical margin for dialogs that consist of a tabbed pane
185: * @since 1.0.3
186: *
187: * @see #getTabbedDialogMarginX()
188: * @see #getDialogMarginY()
189: */
190: public abstract ConstantSize getTabbedDialogMarginY();
191:
192: /**
193: * Returns a gap used to separate a label and associated control.
194: *
195: * @return a gap between label and associated control
196: *
197: * @see #getRelatedComponentsPadX()
198: * @see #getUnrelatedComponentsPadX()
199: */
200: public abstract ConstantSize getLabelComponentPadX();
201:
202: /**
203: * Returns a horizontal gap used to separate related controls.
204: *
205: * @return a horizontal gap between related controls
206: *
207: * @see #getLabelComponentPadX()
208: * @see #getRelatedComponentsPadY()
209: * @see #getUnrelatedComponentsPadX()
210: */
211: public abstract ConstantSize getRelatedComponentsPadX();
212:
213: /**
214: * Returns a vertical gap used to separate related controls.
215: *
216: * @return a vertical gap between related controls
217: *
218: * @see #getRelatedComponentsPadX()
219: * @see #getUnrelatedComponentsPadY()
220: */
221: public abstract ConstantSize getRelatedComponentsPadY();
222:
223: /**
224: * Returns a horizontal gap used to separate unrelated controls.
225: *
226: * @return a horizontal gap between unrelated controls
227: *
228: * @see #getLabelComponentPadX()
229: * @see #getUnrelatedComponentsPadY()
230: * @see #getRelatedComponentsPadX()
231: */
232: public abstract ConstantSize getUnrelatedComponentsPadX();
233:
234: /**
235: * Returns a vertical gap used to separate unrelated controls.
236: *
237: * @return a vertical gap between unrelated controls
238: *
239: * @see #getUnrelatedComponentsPadX()
240: * @see #getRelatedComponentsPadY()
241: */
242: public abstract ConstantSize getUnrelatedComponentsPadY();
243:
244: /**
245: * Returns a narrow vertical pad used to separate lines.
246: *
247: * @return a narrow vertical pad used to separate lines
248: *
249: * @see #getLinePad()
250: * @see #getParagraphPad()
251: */
252: public abstract ConstantSize getNarrowLinePad();
253:
254: /**
255: * Returns a narrow vertical pad used to separate lines.
256: *
257: * @return a vertical pad used to separate lines
258: *
259: * @see #getNarrowLinePad()
260: * @see #getParagraphPad()
261: */
262: public abstract ConstantSize getLinePad();
263:
264: /**
265: * Returns a pad used to separate paragraphs.
266: *
267: * @return a vertical pad used to separate paragraphs
268: *
269: * @see #getNarrowLinePad()
270: * @see #getLinePad()
271: */
272: public abstract ConstantSize getParagraphPad();
273:
274: /**
275: * Returns a pad used to separate a button bar from a component.
276: *
277: * @return a vertical pad used to separate paragraphs
278: * @since 1.0.3
279: *
280: * @see #getRelatedComponentsPadY()
281: * @see #getUnrelatedComponentsPadY()
282: */
283: public abstract ConstantSize getButtonBarPad();
284:
285: /**
286: * Checks and answers whether buttons are typically ordered from
287: * left to right or from right to left. Useful for building button bars
288: * that shall comply with the platform's layout style guide.<p>
289: *
290: * For example the Windows style guide recommends to layout out
291: * <em>OK, Cancel, Apply</em> from left to right, where the
292: * Mac Aqua style guide recommends to layout out these buttons
293: * from right to left.<p>
294: *
295: * Although most button sequences shall honor this order
296: * some buttons require a left to right order. For example
297: * <em>Back, Next</em> or <em>Move Left, Move Right</em>.<p>
298: *
299: * @return true if buttons are typically ordered from left to right
300: * @since 1.0.3
301: *
302: * @see com.jgoodies.forms.builder.ButtonBarBuilder
303: * @see com.jgoodies.forms.factories.ButtonBarFactory
304: */
305: public abstract boolean isLeftToRightButtonOrder();
306:
307: }
|