KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > util > gui > resource > ToolBarFactory


1 /*
2
3    Copyright 1999-2003 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17 */

18
19 package org.apache.batik.util.gui.resource;
20
21 import java.util.Iterator JavaDoc;
22 import java.util.List JavaDoc;
23 import java.util.MissingResourceException JavaDoc;
24 import java.util.ResourceBundle JavaDoc;
25
26 import javax.swing.JButton JavaDoc;
27 import javax.swing.JToolBar JavaDoc;
28
29 /**
30  * This class represents a tool bar factory which builds
31  * tool bars from the content of a resource file. <br>
32  *
33  * The resource entries format is (for a tool bar named 'ToolBar'):<br>
34  * <pre>
35  * ToolBar = Item1 Item2 - Item3 ...
36  * See ButtonFactory.java for details about the items
37  * ...
38  * '-' represents a separator
39  * </pre>
40  * All entries are optional.
41  *
42  * @author <a HREF="mailto:stephane@hillion.org">Stephane Hillion</a>
43  * @version $Id: ToolBarFactory.java,v 1.6 2005/03/27 08:58:37 cam Exp $
44  */

45 public class ToolBarFactory extends ResourceManager {
46     // Constants
47
//
48
private final static String JavaDoc SEPARATOR = "-";
49
50     /**
51      * The table which contains the actions
52      */

53     private ActionMap actions;
54
55     /**
56      * The button factory
57      */

58     private ButtonFactory buttonFactory;
59
60     /**
61      * Creates a new tool bar factory
62      * @param rb the resource bundle that contains the menu bar
63      * description.
64      * @param am the actions to add to menu items
65      */

66     public ToolBarFactory(ResourceBundle JavaDoc rb, ActionMap am) {
67     super(rb);
68     actions = am;
69     buttonFactory = new ButtonFactory(rb, am);
70     }
71
72     /**
73      * Creates a tool bar
74      * @param name the name of the menu bar in the resource bundle
75      * @throws MissingResourceException if one of the keys that compose the
76      * tool bar is missing.
77      * It is not thrown if the action key is missing.
78      * @throws ResourceFormatException if a boolean is malformed
79      * @throws MissingListenerException if an item action is not found in the
80      * action map.
81      */

82     public JToolBar JavaDoc createJToolBar(String JavaDoc name)
83     throws MissingResourceException JavaDoc,
84                ResourceFormatException,
85            MissingListenerException {
86     JToolBar JavaDoc result = new JToolBar JavaDoc();
87         List JavaDoc buttons = getStringList(name);
88         Iterator JavaDoc it = buttons.iterator();
89
90         while (it.hasNext()) {
91         String JavaDoc s = (String JavaDoc)it.next();
92         if (s.equals(SEPARATOR)) {
93         result.add(new JToolbarSeparator());
94         } else {
95         result.add(createJButton(s));
96         }
97         }
98     return result;
99     }
100
101     /**
102      * Creates and returns a new swing button
103      * @param name the name of the button in the resource bundle
104      * @throws MissingResourceException if key is not the name of a button.
105      * It is not thrown if the mnemonic and the action keys are missing
106      * @throws ResourceFormatException if the mnemonic is not a single
107      * character
108      * @throws MissingListenerException if the button action is not found in
109      * the action map.
110      */

111     public JButton JavaDoc createJButton(String JavaDoc name)
112     throws MissingResourceException JavaDoc,
113            ResourceFormatException,
114            MissingListenerException {
115     return buttonFactory.createJToolbarButton(name);
116     }
117 }
118
Popular Tags