KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jgoodies > uif_lite > component > Factory


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

30
31 package com.jgoodies.uif_lite.component;
32
33 import java.awt.Component JavaDoc;
34 import java.awt.Insets JavaDoc;
35
36 import javax.swing.AbstractButton JavaDoc;
37 import javax.swing.Action JavaDoc;
38 import javax.swing.BorderFactory JavaDoc;
39 import javax.swing.JButton JavaDoc;
40 import javax.swing.JScrollPane JavaDoc;
41 import javax.swing.JSplitPane JavaDoc;
42
43
44 /**
45  * A very light version of the JGoodies <code>UIFactory</code> class.
46  * It consists only of static methods to create frequently used components.
47  *
48  * @author Karsten Lentzsch
49  * @version $Revision: 1.4 $
50  */

51
52 public final class Factory {
53
54     /** Defines the margin used in toolbar buttons. */
55     private static final Insets JavaDoc TOOLBAR_BUTTON_MARGIN = new Insets JavaDoc(1, 1, 1, 1);
56
57     /**
58      * Creates and answers a <code>JScrollPane</code> that has an empty
59      * border.
60      */

61     public static JScrollPane JavaDoc createStrippedScrollPane(Component JavaDoc component) {
62         JScrollPane JavaDoc scrollPane = new JScrollPane JavaDoc(component);
63         scrollPane.setBorder(BorderFactory.createEmptyBorder());
64         return scrollPane;
65     }
66
67     /**
68      * Creates and returns a <code>JSplitPane</code> that has empty borders.
69      * Useful to avoid duplicate decorations, for example if the split pane
70      * is contained by other components that already provide a border.
71      *
72      * @param orientation the split pane's orientation: horizontal or vertical
73      * @param comp1 the top/left component
74      * @param comp2 the bottom/right component
75      * @param resizeWeight indicates how to distribute extra space
76      * @return a split panes that has an empty border
77      */

78     public static JSplitPane JavaDoc createStrippedSplitPane(int orientation,
79             Component JavaDoc comp1, Component JavaDoc comp2, double resizeWeight) {
80         JSplitPane JavaDoc split = UIFSplitPane.createStrippedSplitPane(orientation, comp1, comp2);
81         split.setResizeWeight(resizeWeight);
82         return split;
83     }
84     
85     /**
86      * Creates and answers an <code>AbstractButton</code>
87      * configured for use in a JToolBar.<p>
88      *
89      * Superceded by ToolBarButton from the JGoodies UI framework.
90      */

91     public static AbstractButton JavaDoc createToolBarButton(Action JavaDoc action) {
92         JButton JavaDoc button = new JButton JavaDoc(action);
93         button.setFocusPainted(false);
94         button.setMargin(TOOLBAR_BUTTON_MARGIN);
95         //button.setHorizontalTextPosition(SwingConstants.CENTER);
96
//button.setVerticalTextPosition(SwingConstants.BOTTOM);
97
button.setText("");
98         return button;
99     }
100
101 }
Popular Tags