KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > core > gui > toolbar > ToolBarButtonFactory


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//limitations under the License.
10
//
11
//The Original Code is "The Columba Project"
12
//
13
//The Initial Developers of the Original Code are Frederik Dietz and Timo
14
// Stich.
15
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16
//
17
//All Rights Reserved.
18
package org.columba.core.gui.toolbar;
19
20 import javax.swing.Icon JavaDoc;
21 import javax.swing.ImageIcon JavaDoc;
22 import javax.swing.JButton JavaDoc;
23 import javax.swing.SwingConstants JavaDoc;
24
25 import org.columba.core.config.Config;
26 import org.columba.core.config.GuiItem;
27 import org.columba.core.gui.action.AbstractColumbaAction;
28 import org.columba.core.gui.base.ImageUtil;
29 import org.columba.core.help.HelpManager;
30 import org.columba.core.resourceloader.IconKeys;
31 import org.columba.core.resourceloader.ImageLoader;
32
33 /**
34  * Toolbar button factory.
35  *
36  * @author fdietz
37  *
38  */

39 public class ToolBarButtonFactory {
40
41     protected static boolean WITH_TEXT = false;
42
43     protected static boolean ALIGNMENT = true;
44
45 // public static JButton createAnimatedIconButton() {
46
// ImageSequenceTimer button = new ImageSequenceTimer();
47
//
48
// return button;
49
// }
50

51     public static JButton JavaDoc createButton(AbstractColumbaAction action) {
52         JButton JavaDoc button = new ToolBarButton(action);
53
54         // JavaHelp support
55
String JavaDoc topicID = (String JavaDoc) action
56                 .getValue(AbstractColumbaAction.TOPIC_ID);
57         if (topicID != null) {
58             HelpManager.getInstance().enableHelpOnButton(button, topicID);
59         }
60
61         GuiItem item = ((Config) Config.getInstance()).getOptionsConfig()
62                 .getGuiItem();
63
64         WITH_TEXT = item.getBoolean("toolbar", "enable_text");
65         ALIGNMENT = item.getBoolean("toolbar", "text_position");
66
67         ImageIcon JavaDoc icon = (ImageIcon JavaDoc) action
68                 .getValue(AbstractColumbaAction.LARGE_ICON);
69         if (icon == null) {
70             // toolbar buttons always need an icon
71
button.setIcon(ImageLoader.getIcon(IconKeys.IMAGE_MISSING));
72         }
73
74         if (icon != null) {
75             button.setIcon(icon);
76
77             // apply transparent icon
78
button.setDisabledIcon(ImageUtil.createTransparentIcon(icon));
79         }
80
81         if (WITH_TEXT) {
82             boolean showText = (action.isShowToolBarText() || ALIGNMENT);
83
84             if (!showText) {
85                 button.setText("");
86             } else {
87                 button.setText((String JavaDoc) action
88                         .getValue(AbstractColumbaAction.TOOLBAR_NAME));
89             }
90
91             if (ALIGNMENT) {
92                 button.setVerticalTextPosition(SwingConstants.BOTTOM);
93                 button.setHorizontalTextPosition(SwingConstants.CENTER);
94             } else {
95                 button.setVerticalTextPosition(SwingConstants.CENTER);
96                 button.setHorizontalTextPosition(SwingConstants.RIGHT);
97             }
98         } else {
99             button.setText(null);
100         }
101
102         return button;
103     }
104     
105     public static JButton JavaDoc createButton(String JavaDoc text, ImageIcon JavaDoc icon, boolean showToolBarText) {
106         
107         JButton JavaDoc button = new ToolBarButton();
108         
109         GuiItem item = ((Config) Config.getInstance()).getOptionsConfig()
110                 .getGuiItem();
111
112         WITH_TEXT = item.getBoolean("toolbar", "enable_text");
113         ALIGNMENT = item.getBoolean("toolbar", "text_position");
114
115
116         if (icon != null) {
117             button.setIcon(icon);
118
119             // apply transparent icon
120
//button.setDisabledIcon(ImageUtil.createTransparentIcon(icon));
121
}
122
123         if (WITH_TEXT) {
124             boolean showText = (showToolBarText || ALIGNMENT);
125
126             if (!showText) {
127                 button.setText("");
128             } else {
129                 button.setText(text);
130             }
131
132             if (ALIGNMENT) {
133                 button.setVerticalTextPosition(SwingConstants.BOTTOM);
134                 button.setHorizontalTextPosition(SwingConstants.CENTER);
135             } else {
136                 button.setVerticalTextPosition(SwingConstants.CENTER);
137                 button.setHorizontalTextPosition(SwingConstants.RIGHT);
138             }
139         } else {
140             button.setText(null);
141         }
142
143         return button;
144     }
145 }
146
Popular Tags