001: //** Copyright Statement ***************************************************
002: //The Salmon Open Framework for Internet Applications (SOFIA)
003: // Copyright (C) 1999 - 2002, Salmon LLC
004: //
005: // This program is free software; you can redistribute it and/or
006: // modify it under the terms of the GNU General Public License version 2
007: // as published by the Free Software Foundation;
008: //
009: // This program is distributed in the hope that it will be useful,
010: // but WITHOUT ANY WARRANTY; without even the implied warranty of
011: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: // GNU General Public License for more details.
013: //
014: // You should have received a copy of the GNU General Public License
015: // along with this program; if not, write to the Free Software
016: // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: //
018: // For more information please visit http://www.salmonllc.com
019: //** End Copyright Statement ***************************************************
020: package com.salmonllc.ideTools;
021:
022: /////////////////////////
023: //$Archive: /SOFIA/SourceCode/com/salmonllc/ideTools/DialogComponentFactory.java $
024: //$Author: Dan $
025: //$Revision: 9 $
026: //$Modtime: 3/25/04 5:44p $
027: /////////////////////////
028: import javax.swing.*;
029: import javax.swing.plaf.ColorUIResource;
030:
031: import com.salmonllc.swing.SComboBox;
032:
033: import java.awt.*;
034:
035: public class DialogComponentFactory {
036: private static int PREFERREDHEIGHT = 25;
037:
038: /**
039: * Makes a button of the specified width and height
040: */
041: public static JButton makeButton(String text, int width, int height) {
042: JButton b = new JButton(text);
043: if (height == -1 || width == -1) {
044: Dimension d = b.getPreferredSize();
045: if (height == -1)
046: height = (int) d.getHeight();
047: if (width == -1)
048: width = (int) d.getWidth();
049: }
050: b.setMaximumSize(new Dimension(width, height));
051: b.setPreferredSize(new Dimension(width, height));
052: b.setMinimumSize(new Dimension(width, height));
053:
054: b.setVerticalAlignment(JButton.TOP);
055: b.setVerticalTextPosition(JButton.TOP);
056: b.setHorizontalAlignment(JButton.LEFT);
057: b.setHorizontalTextPosition(JButton.LEFT);
058: return b;
059: }
060:
061: /**
062: * Returns a Combo Box Pane with the correct settings
063: */
064: public static JComboBox makeComboBox() {
065: UIDefaults def = UIManager.getDefaults();
066: if (IDETool.getDefaultScrollBarColor() != null)
067: def.put("ScrollBar.thumb", IDETool
068: .getDefaultScrollBarColor());
069: JComboBox b = new JComboBox();
070:
071: return b;
072: }
073:
074: /**
075: * Makes a text field of the specified width
076: */
077: public static JComboBox makeComboBox(int width) {
078: JComboBox f = makeComboBox();
079: f.setMaximumSize(new Dimension(width, PREFERREDHEIGHT));
080: f.setPreferredSize(new Dimension(width, PREFERREDHEIGHT));
081: f.setMinimumSize(new Dimension(width, PREFERREDHEIGHT));
082: return f;
083: }
084:
085: /**
086: * Makes a text field of the specified width
087: */
088: public static SComboBox makeSComboBox(int width) {
089: SComboBox f = new SComboBox();
090: f.setMaximumSize(new Dimension(width, PREFERREDHEIGHT));
091: f.setPreferredSize(new Dimension(width, PREFERREDHEIGHT));
092: f.setMinimumSize(new Dimension(width, PREFERREDHEIGHT));
093: return f;
094: }
095:
096: /**
097: * Returns a JLabel with the correct text and color
098: */
099: public static JLabel makeLabel(String text) {
100: JLabel lab = new JLabel(text);
101: lab.setForeground(IDETool.DEFAULT_FONT_COLOR);
102: lab.setFont(IDETool.getDefaultFont());
103: return lab;
104: }
105:
106: /**
107: * Makes a label of the specified the specified width
108: */
109: public static JLabel makeLabel(String text, int width) {
110: JLabel l = makeLabel(text);
111: l.setMaximumSize(new Dimension(width, PREFERREDHEIGHT));
112: l.setPreferredSize(new Dimension(width, PREFERREDHEIGHT));
113: l.setMinimumSize(new Dimension(width, PREFERREDHEIGHT));
114: return l;
115: }
116:
117: /**
118: * Make list with the correct correct settings
119: */
120: public static JList makeList(ListModel m) {
121: UIDefaults def = UIManager.getDefaults();
122: if (IDETool.getDefaultScrollBarColor() != null)
123: def.put("ScrollBar.thumb", IDETool
124: .getDefaultScrollBarColor());
125: def.put("List.background", ColorUIResource.white);
126: JList l = new JList(m);
127:
128: return l;
129: }
130:
131: /**
132: * Makes a scroll pane of the specified width and height with the passed component
133: */
134: public static JScrollPane makeScrollPane(int width, int height,
135: Component list) {
136: JScrollPane p = new JScrollPane(list);
137: p.setMaximumSize(new Dimension(width, height));
138: p.setPreferredSize(new Dimension(width, height));
139: p.setMinimumSize(new Dimension(width, height));
140: return p;
141: }
142:
143: /**
144: * Returns a Scroll Pane with the correct settings
145: */
146: public static JScrollPane makeScrollPane(JComponent comp) {
147: UIDefaults def = UIManager.getDefaults();
148: if (IDETool.getDefaultScrollBarColor() != null)
149: def.put("ScrollBar.thumb", IDETool
150: .getDefaultScrollBarColor());
151: JScrollPane p = new JScrollPane(comp);
152:
153: return p;
154: }
155:
156: /**
157: * Makes a text field of the specified width
158: */
159: public static JTextField makeTextField(int width) {
160: JTextField f = new JTextField(255);
161: f.setMaximumSize(new Dimension(width, PREFERREDHEIGHT));
162: f.setPreferredSize(new Dimension(width, PREFERREDHEIGHT));
163: f.setMinimumSize(new Dimension(width, PREFERREDHEIGHT));
164: return f;
165: }
166: }
|