0N/A/*
2362N/A * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/Apackage javax.swing;
0N/A
0N/Aimport java.awt.Container;
0N/Aimport javax.swing.plaf.ComponentUI;
0N/Aimport sun.awt.AppContext;
0N/A
0N/A/**
0N/A * <code>LayoutStyle</code> provides information about how to position
0N/A * components. This class is primarily useful for visual tools and
0N/A * layout managers. Most developers will not need to use this class.
0N/A * <p>
0N/A * You typically don't set or create a
0N/A * <code>LayoutStyle</code>. Instead use the static method
0N/A * <code>getInstance</code> to obtain the current instance.
0N/A *
0N/A * @since 1.6
0N/A */
0N/Apublic abstract class LayoutStyle {
0N/A /**
0N/A * Sets the shared instance of <code>LayoutStyle</code>. Specifying
0N/A * <code>null</code> results in using the <code>LayoutStyle</code> from
0N/A * the current <code>LookAndFeel</code>.
0N/A *
0N/A * @param style the <code>LayoutStyle</code>, or <code>null</code>
0N/A * @see #getInstance
0N/A */
0N/A public static void setInstance(LayoutStyle style) {
0N/A synchronized(LayoutStyle.class) {
0N/A if (style == null) {
0N/A AppContext.getAppContext().remove(LayoutStyle.class);
0N/A }
0N/A else {
0N/A AppContext.getAppContext().put(LayoutStyle.class, style);
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the shared instance of <code>LayoutStyle</code>. If an instance
0N/A * has not been specified in <code>setInstance</code>, this will return
0N/A * the <code>LayoutStyle</code> from the current <code>LookAndFeel</code>.
0N/A *
0N/A * @see LookAndFeel#getLayoutStyle
0N/A * @return the shared instance of <code>LayoutStyle</code>
0N/A */
0N/A public static LayoutStyle getInstance() {
0N/A LayoutStyle style;
0N/A synchronized(LayoutStyle.class) {
0N/A style = (LayoutStyle)AppContext.getAppContext().
0N/A get(LayoutStyle.class);
0N/A }
0N/A if (style == null) {
0N/A return UIManager.getLookAndFeel().getLayoutStyle();
0N/A }
0N/A return style;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * <code>ComponentPlacement</code> is an enumeration of the
0N/A * possible ways two components can be placed relative to each
0N/A * other. <code>ComponentPlacement</code> is used by the
0N/A * <code>LayoutStyle</code> method <code>getPreferredGap</code>. Refer to
0N/A * <code>LayoutStyle</code> for more information.
0N/A *
0N/A * @see LayoutStyle#getPreferredGap(JComponent,JComponent,
0N/A * ComponentPlacement,int,Container)
0N/A * @since 1.6
0N/A */
0N/A public enum ComponentPlacement {
0N/A /**
0N/A * Enumeration value indicating the two components are
0N/A * visually related and will be placed in the same parent.
0N/A * For example, a <code>JLabel</code> providing a label for a
0N/A * <code>JTextField</code> is typically visually associated
0N/A * with the <code>JTextField</code>; the constant <code>RELATED</code>
0N/A * is used for this.
0N/A */
0N/A RELATED,
0N/A
0N/A /**
0N/A * Enumeration value indicating the two components are
0N/A * visually unrelated and will be placed in the same parent.
0N/A * For example, groupings of components are usually visually
0N/A * separated; the constant <code>UNRELATED</code> is used for this.
0N/A */
0N/A UNRELATED,
0N/A
0N/A /**
0N/A * Enumeration value indicating the distance to indent a component
0N/A * is being requested. For example, often times the children of
0N/A * a label will be horizontally indented from the label. To determine
0N/A * the preferred distance for such a gap use the
0N/A * <code>INDENT</code> type.
0N/A * <p>
0N/A * This value is typically only useful with a direction of
0N/A * <code>EAST</code> or <code>WEST</code>.
0N/A */
0N/A INDENT;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Creates a new <code>LayoutStyle</code>. You generally don't
0N/A * create a <code>LayoutStyle</code>. Instead use the method
0N/A * <code>getInstance</code> to obtain the current
0N/A * <code>LayoutStyle</code>.
0N/A */
0N/A public LayoutStyle() {
0N/A }
0N/A
0N/A /**
0N/A * Returns the amount of space to use between two components.
0N/A * The return value indicates the distance to place
0N/A * <code>component2</code> relative to <code>component1</code>.
0N/A * For example, the following returns the amount of space to place
0N/A * between <code>component2</code> and <code>component1</code>
0N/A * when <code>component2</code> is placed vertically above
0N/A * <code>component1</code>:
0N/A * <pre>
0N/A * int gap = getPreferredGap(component1, component2,
0N/A * ComponentPlacement.RELATED,
0N/A * SwingConstants.NORTH, parent);
0N/A * </pre>
0N/A * The <code>type</code> parameter indicates the relation between
0N/A * the two components. If the two components will be contained in
0N/A * the same parent and are showing similar logically related
0N/A * items, use <code>RELATED</code>. If the two components will be
0N/A * contained in the same parent but show logically unrelated items
0N/A * use <code>UNRELATED</code>. Some look and feels may not
0N/A * distinguish between the <code>RELATED</code> and
0N/A * <code>UNRELATED</code> types.
0N/A * <p>
0N/A * The return value is not intended to take into account the
0N/A * current size and position of <code>component2</code> or
0N/A * <code>component1</code>. The return value may take into
0N/A * consideration various properties of the components. For
0N/A * example, the space may vary based on font size, or the preferred
0N/A * size of the component.
0N/A *
0N/A * @param component1 the <code>JComponent</code>
0N/A * <code>component2</code> is being placed relative to
0N/A * @param component2 the <code>JComponent</code> being placed
0N/A * @param position the position <code>component2</code> is being placed
0N/A * relative to <code>component1</code>; one of
0N/A * <code>SwingConstants.NORTH</code>,
0N/A * <code>SwingConstants.SOUTH</code>,
0N/A * <code>SwingConstants.EAST</code> or
0N/A * <code>SwingConstants.WEST</code>
0N/A * @param type how the two components are being placed
0N/A * @param parent the parent of <code>component2</code>; this may differ
0N/A * from the actual parent and it may be <code>null</code>
0N/A * @return the amount of space to place between the two components
0N/A * @throws NullPointerException if <code>component1</code>,
0N/A * <code>component2</code> or <code>type</code> is
0N/A * <code>null</code>
0N/A * @throws IllegalArgumentException if <code>position</code> is not
0N/A * one of <code>SwingConstants.NORTH</code>,
0N/A * <code>SwingConstants.SOUTH</code>,
0N/A * <code>SwingConstants.EAST</code> or
0N/A * <code>SwingConstants.WEST</code>
0N/A * @see LookAndFeel#getLayoutStyle
0N/A * @since 1.6
0N/A */
0N/A public abstract int getPreferredGap(JComponent component1,
0N/A JComponent component2,
0N/A ComponentPlacement type, int position,
0N/A Container parent);
0N/A
0N/A /**
0N/A * Returns the amount of space to place between the component and specified
0N/A * edge of its parent.
0N/A *
0N/A * @param component the <code>JComponent</code> being positioned
0N/A * @param position the position <code>component</code> is being placed
0N/A * relative to its parent; one of
0N/A * <code>SwingConstants.NORTH</code>,
0N/A * <code>SwingConstants.SOUTH</code>,
0N/A * <code>SwingConstants.EAST</code> or
0N/A * <code>SwingConstants.WEST</code>
0N/A * @param parent the parent of <code>component</code>; this may differ
0N/A * from the actual parent and may be <code>null</code>
0N/A * @return the amount of space to place between the component and specified
0N/A * edge
0N/A * @throws IllegalArgumentException if <code>position</code> is not
0N/A * one of <code>SwingConstants.NORTH</code>,
0N/A * <code>SwingConstants.SOUTH</code>,
0N/A * <code>SwingConstants.EAST</code> or
0N/A * <code>SwingConstants.WEST</code>
0N/A */
0N/A public abstract int getContainerGap(JComponent component, int position,
0N/A Container parent);
0N/A}