Logo Search packages:      
Sourcecode: libjgoodies-forms-java version File versions  Download package

LayoutStyle.java

/*
 * Copyright (c) 2002-2004 JGoodies Karsten Lentzsch. All Rights Reserved.
 *
 * Redistribution and use in source and binary forms, with or without 
 * modification, are permitted provided that the following conditions are met:
 * 
 *  o Redistributions of source code must retain the above copyright notice, 
 *    this list of conditions and the following disclaimer. 
 *     
 *  o Redistributions in binary form must reproduce the above copyright notice, 
 *    this list of conditions and the following disclaimer in the documentation 
 *    and/or other materials provided with the distribution. 
 *     
 *  o Neither the name of JGoodies Karsten Lentzsch nor the names of 
 *    its contributors may be used to endorse or promote products derived 
 *    from this software without specific prior written permission. 
 *     
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
 */

package com.jgoodies.forms.util;

import java.util.logging.Logger;

import com.jgoodies.forms.layout.ConstantSize;
import com.jgoodies.forms.layout.Size;

/**
 * An abstract class that describes a layout and design style guide.
 * It provides constants used to lay out panels consistently.<p>
 * 
 * This class is work in progress and the API may change without notice.
 * Therefore it is recommended to not write custom subclasses 
 * for production code.
 * A future version of this class will likely collaborate with a class
 * <code>LogicalSize</code> or <code>StyledSize</code>.
 *
 * @author Karsten Lentzsch
 * @version $Revision: 1.7 $
 * 
 * @see com.jgoodies.forms.util.MacLayoutStyle
 * @see com.jgoodies.forms.util.WindowsLayoutStyle
 * @see com.jgoodies.forms.factories.FormFactory
 * @see com.jgoodies.forms.factories.Borders
 */

00057 public abstract class LayoutStyle {
    
    /**
     * Holds the current layout style.
     */
00062     private static LayoutStyle current = initialLayoutStyle();
    
    
    // Computing the initial layout style *************************************
    
    /**
     * Computes and returns the initial <code>LayoutStyle</code>.
     * Checks the OS name and returns <code>MacLayoutStyle</code> 
     * on Mac OS X and <code>WindowLayoutStyle</code> on all other platforms.
     * 
     * @return MacLayoutStyle on Mac, WindowsLayoutStyle on all other platforms
     */
00074     private static LayoutStyle initialLayoutStyle() {
        if (isOSMac())
            return MacLayoutStyle.INSTANCE;
        else
            return WindowsLayoutStyle.INSTANCE;
    }
    
    
    /**
     * Checks and answers whether Java runs on a Mac by requesting
     * the system property <em>os.name</em>.
     * 
     * @return true on Mac, false on all other Platforms
     */
00088     private static boolean isOSMac() {
        return getSystemProperty("os.name").startsWith("Mac");
    }
    
    
    /**
     * Tries to look up the System property for the given key.
     * In untrusted environments this may throw a SecurityException.
     * In this case we catch the exception and answer <code>null</code>. 
     * 
     * @param key   the name of the system property
     * @return the system property's String value, or a blank string 
     *     if there's no such value, or a SecurityException has been catched
     */
00102     private static String getSystemProperty(String key) {
        try {
            return System.getProperty(key);
        } catch (SecurityException e) {
            Logger.getLogger(LayoutStyle.class.getName()).warning(
                    "Can't read the System property " + key + ".");
            return "";
        }
    }

    
    // Accessing the current style ******************************************
    
    /**
     * Returns the current <code>LayoutStyle</code>.
     * 
     * @return the current <code>LayoutStyle</code>
     */
00120     public static LayoutStyle getCurrent() {
        return current;
    }
    
    
    /**
     * Set a new <code>LayoutStyle</code>
     * 
     * @param newLayoutStyle   the style to be set
     */
00130     public static void setCurrent(LayoutStyle newLayoutStyle) {
        current = newLayoutStyle;
    }
    
    
    // Layout Sizes *********************************************************

    /**
     * Returns this style's default button width.
     * 
     * @return the default button width
     * 
     * @see #getDefaultButtonHeight()
     */
    abstract public Size getDefaultButtonWidth();

    
    /**
     * Returns this style's default button height.
     * 
     * @return the default button height
     * 
     * @see #getDefaultButtonWidth()
     */
    abstract public Size getDefaultButtonHeight();

    
    /**
     * Returns this style's horizontal margin for general dialogs.
     * 
     * @return the horizontal margin for general dialogs
     * 
     * @see #getDialogMarginY()
     * @see #getTabbedDialogMarginX()
     */
    abstract public ConstantSize getDialogMarginX();

    
    /**
     * Returns this style's vertical margin for general dialogs.
     * 
     * @return the vertical margin for general dialogs
     * 
     * @see #getDialogMarginX()
     * @see #getTabbedDialogMarginY()
     */
    abstract public ConstantSize getDialogMarginY();

    
    /**
     * Returns this style's horizontal margin for dialogs that consist of 
     * a tabbed pane.
     * 
     * @return the horizontal margin for dialogs that consist of a tabbed pane
     * @since 1.0.3
     * 
     * @see #getTabbedDialogMarginY()
     * @see #getDialogMarginX()
     */
    abstract public ConstantSize getTabbedDialogMarginX();

    
    /**
     * Returns this style's vertical margin for dialogs that consist of
     * a tabbed pane.
     * 
     * @return the vertical margin for dialogs that consist of a tabbed pane
     * @since 1.0.3
     * 
     * @see #getTabbedDialogMarginX()
     * @see #getDialogMarginY()
     */
    abstract public ConstantSize getTabbedDialogMarginY();

    
    /**
     * Returns a gap used to separate a label and associated control.
     * 
     * @return a gap between label and associated control
     * 
     * @see #getRelatedComponentsPadX()
     * @see #getUnrelatedComponentsPadX()
     */
    abstract public ConstantSize getLabelComponentPadX();

    
    /**
     * Returns a horizontal gap used to separate related controls.
     * 
     * @return a horizontal gap between related controls
     * 
     * @see #getLabelComponentPadX()
     * @see #getRelatedComponentsPadY()
     * @see #getUnrelatedComponentsPadX()
     */
    abstract public ConstantSize getRelatedComponentsPadX();

    
    /**
     * Returns a vertical gap used to separate related controls.
     * 
     * @return a vertical gap between related controls
     * 
     * @see #getRelatedComponentsPadX()
     * @see #getUnrelatedComponentsPadY()
     */
    abstract public ConstantSize getRelatedComponentsPadY();

    
    /**
     * Returns a horizontal gap used to separate unrelated controls.
     * 
     * @return a horizontal gap between unrelated controls
     * 
     * @see #getLabelComponentPadX()
     * @see #getUnrelatedComponentsPadY()
     * @see #getRelatedComponentsPadX()
     */
    abstract public ConstantSize getUnrelatedComponentsPadX();

    
    /**
     * Returns a vertical gap used to separate unrelated controls.
     * 
     * @return a vertical gap between unrelated controls
     * 
     * @see #getUnrelatedComponentsPadX()
     * @see #getRelatedComponentsPadY()
     */
    abstract public ConstantSize getUnrelatedComponentsPadY();

    
    /**
     * Returns a narrow vertical pad used to separate lines.
     * 
     * @return a narrow vertical pad used to separate lines
     * 
     * @see #getLinePad()
     * @see #getParagraphPad()
     */
    abstract public ConstantSize getNarrowLinePad();

    
    /**
     * Returns a narrow vertical pad used to separate lines.
     * 
     * @return a vertical pad used to separate lines
     * 
     * @see #getNarrowLinePad()
     * @see #getParagraphPad()
     */
    abstract public ConstantSize getLinePad();

    
    /**
     * Returns a pad used to separate paragraphs.
     * 
     * @return a vertical pad used to separate paragraphs
     * 
     * @see #getNarrowLinePad()
     * @see #getLinePad()
     */
    abstract public ConstantSize getParagraphPad();


    /**
     * Returns a pad used to separate a button bar from a component.
     * 
     * @return a vertical pad used to separate paragraphs
     * @since 1.0.3
     * 
     * @see #getRelatedComponentsPadY()
     * @see #getUnrelatedComponentsPadY()
     */
    abstract public ConstantSize getButtonBarPad();

    
    /**
     * Checks and answers whether buttons are typically ordered from 
     * left to right or from right to left. Useful for building button bars 
     * that shall comply with the platform's layout style guide.<p>
     * 
     * For example the Windows style guide recommends to layout out
     * <em>OK, Cancel, Apply</em> from left to right, where the 
     * Mac Aqua style guide recommends to layout out these buttons
     * from right to left.<p>
     * 
     * Although most button sequences shall honor this order
     * some buttons require a left to right order. For example
     * <em>Back, Next</em> or <em>Move Left, Move Right</em>.<p>
     * 
     * @return true if buttons are typically ordered from left to right
     * @since 1.0.3
     * 
     * @see com.jgoodies.forms.builder.ButtonBarBuilder
     * @see com.jgoodies.forms.factories.ButtonBarFactory
     */
    abstract public boolean isLeftToRightButtonOrder();

    
}

Generated by  Doxygen 1.6.0   Back to index