001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.sql.framework.ui.graph.view.impl;
042:
043: import java.awt.Component;
044: import java.awt.Dimension;
045: import java.util.ArrayList;
046: import java.util.Iterator;
047: import java.util.List;
048:
049: import javax.swing.Action;
050: import javax.swing.JToolBar;
051:
052: import org.netbeans.modules.sql.framework.ui.graph.IGraphView;
053: import org.netbeans.modules.sql.framework.ui.graph.IToolBar;
054: import org.netbeans.modules.sql.framework.ui.graph.actions.GraphActionDelegator;
055: import org.netbeans.modules.sql.framework.ui.graph.actions.ZoomAction;
056:
057: /**
058: * @author Ritesh Adval
059: * @version $Revision$
060: */
061: public class BasicToolBar extends JToolBar implements IToolBar {
062: private Object tController;
063: private IGraphView graphView;
064: private List customActions;
065: private List graphActionDelegators = new ArrayList();
066:
067: /**
068: * get the toolbar actions that need to be shown
069: *
070: * @return a list of GraphAction, null in list represents a seperator
071: */
072: public List getActions() {
073: return customActions;
074: }
075:
076: /**
077: * set toolbar actions on this view
078: *
079: * @param actions list of GraphAction
080: */
081: public void setActions(List actions) {
082: this .customActions = actions;
083: }
084:
085: /**
086: * get a action given its class
087: *
088: * @param actionClass
089: * @return action
090: */
091: public Action getAction(Class actionClass) {
092: List actions = this .getActions();
093: if (actions == null) {
094: return null;
095: }
096:
097: Iterator it = actions.iterator();
098:
099: while (it.hasNext()) {
100: Action act = (Action) it.next();
101: if (act != null
102: && act.getClass().getName().equals(
103: actionClass.getName())) {
104: return act;
105: }
106: }
107:
108: return null;
109: }
110:
111: /**
112: * set the graph view for this tool bar
113: *
114: * @param gView graph view
115: */
116: public void setGraphView(IGraphView gView) {
117: this .graphView = gView;
118: }
119:
120: /**
121: * get the graph view for this tool bar
122: *
123: * @return graph view
124: */
125: public IGraphView getGraphView() {
126: return this .graphView;
127: }
128:
129: /**
130: * Sets tool bar controller
131: *
132: * @param controller tool bar controller
133: */
134: public void setToolBarController(Object controller) {
135: tController = controller;
136: }
137:
138: /**
139: * Gets tool bar controller
140: *
141: * @return tool bar controller
142: */
143: public Object getToolBarController() {
144: return tController;
145: }
146:
147: /**
148: * call this to add items in tool bar based on actions set in this toolbar
149: */
150: public void initializeToolBar() {
151: List actions = this .getActions();
152: if (actions == null) {
153: return;
154: }
155:
156: Iterator it = actions.iterator();
157:
158: while (it.hasNext()) {
159: Action action = (Action) it.next();
160: GraphActionDelegator gaDelegator = new GraphActionDelegator(
161: this .getGraphView(), action);
162: if (action != null) {
163: if (action instanceof ZoomAction) {
164: Component comp = ((ZoomAction) action)
165: .getComponent();
166: if (comp != null) {
167: this .add(comp);
168: }
169: } else {
170: this .add(gaDelegator);
171: graphActionDelegators.add(gaDelegator);
172: }
173: } else {
174: this .addSeparator(new Dimension(1, 0));
175: this .addSeparator(new Dimension(2, 30));
176: this .addSeparator(new Dimension(1, 0));
177: }
178: }
179: this .setRollover(true);
180: }
181:
182: public void enableToolBar(boolean enable) {
183: this .setEnabled(enable);
184:
185: Iterator it = this .graphActionDelegators.iterator();
186:
187: while (it.hasNext()) {
188: Action action = (Action) it.next();
189: if (action != null) {
190: action.setEnabled(enable);
191: }
192: }
193: }
194: }
|