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