001: /*
002: * Copyright (c) 2000-2006 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.uif_lite.component;
032:
033: import java.awt.Component;
034: import java.awt.Insets;
035:
036: import javax.swing.AbstractButton;
037: import javax.swing.Action;
038: import javax.swing.BorderFactory;
039: import javax.swing.JButton;
040: import javax.swing.JScrollPane;
041: import javax.swing.JSplitPane;
042:
043: /**
044: * A very light version of the JGoodies <code>UIFactory</code> class.
045: * It consists only of static methods to create frequently used components.
046: *
047: * @author Karsten Lentzsch
048: * @version $Revision: 1.2 $
049: */
050:
051: public final class Factory {
052:
053: private Factory() {
054: // Overrides default constructor; prevents instantiation.
055: }
056:
057: /** Defines the margin used in toolbar buttons. */
058: private static final Insets TOOLBAR_BUTTON_MARGIN = new Insets(1,
059: 1, 1, 1);
060:
061: /**
062: * Creates and answers a <code>JScrollPane</code> that has an empty
063: * border.
064: */
065: public static JScrollPane createStrippedScrollPane(
066: Component component) {
067: JScrollPane scrollPane = new JScrollPane(component);
068: scrollPane.setBorder(BorderFactory.createEmptyBorder());
069: return scrollPane;
070: }
071:
072: /**
073: * Creates and returns a <code>JSplitPane</code> that has empty borders.
074: * Useful to avoid duplicate decorations, for example if the split pane
075: * is contained by other components that already provide a border.
076: *
077: * @param orientation the split pane's orientation: horizontal or vertical
078: * @param comp1 the top/left component
079: * @param comp2 the bottom/right component
080: * @param resizeWeight indicates how to distribute extra space
081: * @return a split panes that has an empty border
082: */
083: public static JSplitPane createStrippedSplitPane(int orientation,
084: Component comp1, Component comp2, double resizeWeight) {
085: JSplitPane split = UIFSplitPane.createStrippedSplitPane(
086: orientation, comp1, comp2);
087: split.setResizeWeight(resizeWeight);
088: return split;
089: }
090:
091: /**
092: * Creates and answers an <code>AbstractButton</code>
093: * configured for use in a JToolBar.<p>
094: *
095: * Superceded by ToolBarButton from the JGoodies UI framework.
096: */
097: public static AbstractButton createToolBarButton(Action action) {
098: JButton button = new JButton(action);
099: button.setFocusPainted(false);
100: button.setMargin(TOOLBAR_BUTTON_MARGIN);
101: //button.setHorizontalTextPosition(SwingConstants.CENTER);
102: //button.setVerticalTextPosition(SwingConstants.BOTTOM);
103: button.setText("");
104: return button;
105: }
106:
107: }
|