001: /*
002: The contents of this file are subject to the Common Public Attribution License
003: Version 1.0 (the "License"); you may not use this file except in compliance with
004: the License. You may obtain a copy of the License at
005: http://www.projity.com/license . The License is based on the Mozilla Public
006: License Version 1.1 but Sections 14 and 15 have been added to cover use of
007: software over a computer network and provide for limited attribution for the
008: Original Developer. In addition, Exhibit A has been modified to be consistent
009: with Exhibit B.
010:
011: Software distributed under the License is distributed on an "AS IS" basis,
012: WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the
013: specific language governing rights and limitations under the License. The
014: Original Code is OpenProj. The Original Developer is the Initial Developer and
015: is Projity, Inc. All portions of the code written by Projity are Copyright (c)
016: 2006, 2007. All Rights Reserved. Contributors Projity, Inc.
017:
018: Alternatively, the contents of this file may be used under the terms of the
019: Projity End-User License Agreeement (the Projity License), in which case the
020: provisions of the Projity License are applicable instead of those above. If you
021: wish to allow use of your version of this file only under the terms of the
022: Projity License and not to allow others to use your version of this file under
023: the CPAL, indicate your decision by deleting the provisions above and replace
024: them with the notice and other provisions required by the Projity License. If
025: you do not delete the provisions above, a recipient may use your version of this
026: file under either the CPAL or the Projity License.
027:
028: [NOTE: The text of this license may differ slightly from the text of the notices
029: in Exhibits A and B of the license at http://www.projity.com/license. You should
030: use the latest text at http://www.projity.com/license for your modifications.
031: You may not remove this license text from the source files.]
032:
033: Attribution Information: Attribution Copyright Notice: Copyright � 2006, 2007
034: Projity, Inc. Attribution Phrase (not exceeding 10 words): Powered by OpenProj,
035: an open source solution from Projity. Attribution URL: http://www.projity.com
036: Graphic Image as provided in the Covered Code as file: openproj_logo.png with
037: alternatives listed on http://www.projity.com/logo
038:
039: Display of Attribution Information is required in Larger Works which are defined
040: in the CPAL as a work which combines Covered Code or portions thereof with code
041: not governed by the terms of the CPAL. However, in addition to the other notice
042: obligations, all copies of the Covered Code in Executable and Source Code form
043: distributed must, as a form of attribution of the original author, include on
044: each user interface screen the "OpenProj" logo visible to all users. The
045: OpenProj logo should be located horizontally aligned with the menu bar and left
046: justified on the top left of the screen adjacent to the File menu. The logo
047: must be at least 100 x 25 pixels. When users click on the "OpenProj" logo it
048: must direct them back to http://www.projity.com.
049: */
050: package com.projity.menu;
051:
052: import java.util.ArrayList;
053: import java.util.Collection;
054: import java.util.Iterator;
055: import java.util.LinkedList;
056: import java.util.Locale;
057: import java.util.MissingResourceException;
058: import java.util.ResourceBundle;
059:
060: import javax.swing.AbstractButton;
061: import javax.swing.Action;
062: import javax.swing.JMenuBar;
063: import javax.swing.JMenuItem;
064: import javax.swing.JPopupMenu;
065: import javax.swing.JToggleButton;
066: import javax.swing.JToolBar;
067:
068: import org.apache.batik.util.gui.resource.ActionMap;
069: import org.apache.batik.util.gui.resource.ButtonFactory;
070:
071: import com.projity.pm.graphic.TabbedNavigation;
072: import com.projity.strings.DirectoryClassLoader;
073: import com.projity.util.ClassLoaderUtils;
074:
075: /**
076: *
077: */
078: public class MenuManager {
079: private static final String MENU_BUNDLE = "com.projity.menu.menu";
080: private static final String MENU_BUNDLE_CONF_DIR = "menu";
081: public static final String STANDARD_MENU = "StandardMenuBar";
082: public static final String SERVER_STANDARD_MENU = "ServerStandardMenuBar";
083: public static final String SF_MENU = "SFMenuBar";
084: public static final String STANDARD_TOOL_BAR = "StandardToolBar";
085: public static final String FILE_TOOL_BAR = "FileToolBar";
086: public static final String BIG_TOOL_BAR = "BigToolBar";
087: public static final String VIEW_TOOL_BAR = "ViewToolBar";
088: public static final String VIEW_TOOL_BAR_WITH_NO_SUB_VIEW_OPTION = "ViewToolBarNoSubView";
089: public static final String PRINT_PREVIEW_TOOL_BAR = "PrintPreviewToolBar";
090:
091: //private static MenuManager instance = null;
092: ResourceBundle bundle;
093: ExtMenuFactory menuFactory;
094: ExtToolBarFactory toolBarFactory;
095: ActionMap rootActionMap;
096:
097: LinkedList tabbedNavigations = new LinkedList();
098:
099: public void add(TabbedNavigation t) {
100: tabbedNavigations.add(t);
101: }
102:
103: private MenuManager(ActionMap rootActionMap) {
104: this .rootActionMap = rootActionMap;
105: try {
106: DirectoryClassLoader dir = new DirectoryClassLoader();
107: if (dir.isValid()) {
108: bundle = ResourceBundle.getBundle(MENU_BUNDLE_CONF_DIR,
109: Locale.getDefault(), dir);
110: }
111: } catch (Exception e) {
112: }
113: if (bundle == null)
114: bundle = ResourceBundle.getBundle(MENU_BUNDLE, Locale
115: .getDefault(), ClassLoaderUtils
116: .getLocalClassLoader());
117: menuFactory = new ExtMenuFactory(bundle, rootActionMap);
118: toolBarFactory = new ExtToolBarFactory(bundle, rootActionMap);
119: }
120:
121: public static MenuManager getInstance(ActionMap rootActionMap) {
122: // if (instance == null)
123: // instance = new MenuManager(rootActionMap);
124: // return instance;
125: return new MenuManager(rootActionMap);
126: }
127:
128: public JMenuBar getMenu(String name) {
129: return menuFactory.createJMenuBar(name);
130: }
131:
132: public JPopupMenu getPopupMenu(String name) {
133: return menuFactory.createJPopupMenuBar(name);
134: }
135:
136: public String getString(String key) {
137: return menuFactory.getString(key);
138: }
139:
140: public String getStringOrNull(String key) {
141: try {
142: return getString(key);
143: } catch (MissingResourceException e) {
144: return null;
145: }
146: }
147:
148: public String getActionStringFromId(String id) {
149: String result = menuFactory.getActionStringFromId(id);
150: if (result == null)
151: System.out
152: .println("Invalid item: "
153: + id
154: + " it must be a menu item in the menu properties, even if it's only shown in a toolbar");
155: return result;
156: }
157:
158: public Action getActionFromId(String id) {
159: return menuFactory.getActionFromId(id);
160: }
161:
162: public String getStringFromAction(Action action) {
163: return menuFactory.getStringFromAction(action);
164: }
165:
166: public JMenuItem getMenuItemFromId(String id) {
167: return menuFactory.getMenuItemFromId(id);
168: }
169:
170: public ArrayList getToolButtonsFromId(String id) {
171: return toolBarFactory.getButtonsFromId(id);
172: }
173:
174: public final ExtToolBarFactory getToolBarFactory() {
175: return toolBarFactory;
176: }
177:
178: public JToolBar getToolBar(String name) {
179: return toolBarFactory.createJToolBar(name);
180: }
181:
182: public void setActionEnabled(String id, boolean enable) {
183: Collection buttons = toolBarFactory.getButtonsFromId(id);
184: if (buttons != null) {
185: Iterator i = buttons.iterator();
186: while (i.hasNext()) {
187: AbstractButton button = (AbstractButton) i.next();
188: if (button != null)
189: button.setEnabled(enable);
190: }
191: }
192: JMenuItem menuItem = menuFactory.getMenuItemFromId(id);
193: if (menuItem != null)
194: menuItem.setEnabled(enable);
195: }
196:
197: public void setActionVisible(String id, boolean enable) {
198: Collection buttons = toolBarFactory.getButtonsFromId(id);
199: if (buttons != null) {
200: Iterator i = buttons.iterator();
201: while (i.hasNext()) {
202: AbstractButton button = (AbstractButton) i.next();
203: if (button != null)
204: button.setVisible(enable);
205: }
206: }
207: JMenuItem menuItem = menuFactory.getMenuItemFromId(id);
208: if (menuItem != null)
209: menuItem.setVisible(enable);
210: }
211:
212: public void setActionSelected(String id, boolean enable) {
213: Collection buttons = toolBarFactory.getButtonsFromId(id);
214: if (buttons != null) {
215: Iterator i = buttons.iterator();
216: while (i.hasNext()) {
217: AbstractButton button = (AbstractButton) i.next();
218: if (button != null) {
219: button.setSelected(enable);
220: if (button instanceof JToggleButton) {
221: // button.setBackground(enable ? Color.GRAY : ExtButtonFactory.BACKGROUND_COLOR);
222: }
223: }
224: }
225: }
226: JMenuItem menuItem = menuFactory.getMenuItemFromId(id);
227: if (menuItem != null)
228: menuItem.setSelected(enable);
229: Iterator i = tabbedNavigations.iterator();
230: while (i.hasNext())
231: ((TabbedNavigation) i.next()).setActivatedView(id, enable);
232:
233: }
234:
235: public void setText(String id, String text) {
236: Collection buttons = toolBarFactory.getButtonsFromId(id);
237: if (buttons != null) {
238: Iterator i = buttons.iterator();
239: while (i.hasNext()) {
240: AbstractButton button = (AbstractButton) i.next();
241: if (button != null)
242: button.setToolTipText(text);
243: }
244: }
245: JMenuItem menuItem = menuFactory.getMenuItemFromId(id);
246: if (menuItem != null)
247: menuItem.setText(text);
248: }
249:
250: public String getTextForId(String id) {
251: return menuFactory.getTextForId(id);
252: }
253:
254: public String getFullTipText(String name) {
255: String s = getStringOrNull(name + ButtonFactory.TOOLTIP_SUFFIX);
256: if (s != null) {
257: String help = getStringOrNull(name
258: + ButtonFactory.HELP_SUFFIX);
259: String demo = getStringOrNull(name
260: + ButtonFactory.DEMO_SUFFIX);
261: String doc = getStringOrNull(name
262: + ButtonFactory.DOC_SUFFIX);
263:
264: if (doc != null)
265: s = HyperLinkToolTip.helpTipText(s, help, demo, doc);
266: }
267: return s;
268: }
269:
270: }
|