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:
042: package org.netbeans.modules.uml.ui.products.ad.application;
043:
044: import java.awt.BorderLayout;
045: import java.awt.event.MouseAdapter;
046: import java.awt.event.MouseEvent;
047: import java.awt.event.MouseListener;
048: import java.awt.Component;
049: import javax.swing.BoxLayout;
050:
051: import javax.swing.JToolBar;
052: import javax.swing.Icon;
053: import javax.swing.JMenu;
054: import javax.swing.JPanel;
055: import javax.swing.JPopupMenu;
056:
057: import org.netbeans.modules.uml.ui.swing.plaf.basic.BasicPullDownButtonBorder;
058: import org.netbeans.modules.uml.ui.swing.pulldownbutton.JPullDownButton;
059: import org.netbeans.modules.uml.ui.swing.pulldownbutton.PopupMenuInvoker;
060: import org.netbeans.modules.uml.ui.swing.testbed.addin.menu.TestBedMenuManager;
061:
062: /**
063: *
064: * @author Trey Spiva
065: */
066: public abstract class ApplicationView extends JPanel {
067: private String m_Title = "";
068: private Icon m_Icon = null;
069: private String m_ToolTip = null;
070: private String m_Id = "";
071: private JToolBar m_ToolBarManager = null;
072:
073: // IZ# 78924 - conover: needed to be a panel to left align the toolbar
074: // wasn't working as a Box for some reason
075: // private Box m_ToolComponent = Box.createHorizontalBox();
076: private JPanel m_ToolComponent;
077:
078: public ApplicationView(String id) {
079: setId(id);
080: }
081:
082: public JPanel getView() {
083: setLayout(new BorderLayout());
084:
085: JPanel viewSite = new JPanel();
086: createViewControl(viewSite);
087: add(viewSite, BorderLayout.CENTER);
088: setPopupMenuListener(new PopupMenuManager(viewSite));
089: initializeUIBars(this );
090:
091: return this ;
092: }
093:
094: public PopupMenuManager getPopupMenuManager(JPanel panel) {
095: return new PopupMenuManager(panel);
096: }
097:
098: protected void initializeUIBars(JPanel view) {
099: // IZ# 78924 - conover: layout the toolbar panel to left align the icons
100:
101: m_ToolComponent = new JPanel();
102: BoxLayout boxlayout = new BoxLayout(m_ToolComponent,
103: BoxLayout.X_AXIS);
104: m_ToolComponent.setLayout(boxlayout);
105:
106: JToolBar bar = new JToolBar();
107: bar.setFloatable(false);
108: m_ToolBarManager = bar;
109:
110: TestBedMenuManager menuManager = new TestBedMenuManager();
111: JMenu menu = new JMenu();
112: menuManager.setMenuItem(menu);
113:
114: contributeActionBars(m_ToolBarManager);
115:
116: m_ToolComponent.add(m_ToolBarManager);
117: menuManager.createMenuBar();
118:
119: if (menu.getItemCount() > 0) {
120: JPullDownButton btn = new JPullDownButton();
121: btn.setBorder(new BasicPullDownButtonBorder(false));
122: btn.setPulldownInvoker(new PopupMenuInvoker(menu
123: .getPopupMenu()));
124: m_ToolComponent.add(btn);
125: }
126:
127: view.add(m_ToolComponent, BorderLayout.NORTH);
128: }
129:
130: public abstract void createViewControl(JPanel parent);
131:
132: protected void contributeActionBars(JToolBar bars) {
133: }
134:
135: public void setPopupMenuListener(MouseListener listener) {
136: }
137:
138: //**************************************************
139: // Context Menu Methods
140: //**************************************************
141: // private PopupMenuExtender m_ContextMenu = null;
142: private TestBedMenuManager m_ContextMenuManager = null;
143: private JMenu m_ContextPopup = new JMenu();
144:
145: public void registerContextMenu(boolean clearBeforeShow) {
146: // registerContextMenu(getId(), clearBeforeShow, prov);
147: registerContextMenu(getId(), clearBeforeShow);
148: }
149:
150: public void registerContextMenu(String id, boolean clearBeforeShow) {
151: m_ContextMenuManager = new TestBedMenuManager();
152: m_ContextMenuManager.setRemoveAllWhenShown(clearBeforeShow);
153:
154: m_ContextMenuManager.setMenuItem(m_ContextPopup);
155: // m_ContextMenu = new PopupMenuExtender(id, m_ContextMenuManager, prov, this);
156: }
157:
158: /**
159: * This method should be over ridden by any subclass which wants to contribute items to the menu
160: *
161: */
162: public void menuAboutToShow(IMenuManager manager) {
163: }
164:
165: /**
166: * This method should be overridden by any subclass that wants to remove any items from the context menu.
167: * @param manager
168: */
169: public void processRemovesIfAny(IMenuManager manager) {
170: }
171:
172: //**************************************************
173: // Data Access Methods
174: //**************************************************
175:
176: /**
177: * @return
178: */
179: public String getTitle() {
180: return m_Title;
181: }
182:
183: /**
184: * @param string
185: */
186: public void setTitle(String string) {
187: m_Title = string;
188: }
189:
190: /**
191: * @return
192: */
193: public Icon getIcon() {
194: return m_Icon;
195: }
196:
197: /**
198: * @param icon
199: */
200: public void setIcon(Icon icon) {
201: m_Icon = icon;
202: }
203:
204: /**
205: * @return
206: */
207: public String getToolTip() {
208: return m_ToolTip;
209: }
210:
211: /**
212: * @param string
213: */
214: public void setToolTip(String string) {
215: m_ToolTip = string;
216: }
217:
218: /**
219: * @return
220: */
221: public String getId() {
222: return m_Id;
223: }
224:
225: /**
226: * @param string
227: */
228: public void setId(String string) {
229: m_Id = string;
230: }
231:
232: public class PopupMenuManager extends MouseAdapter {
233: JPanel m_View = null;
234:
235: public PopupMenuManager(JPanel view) {
236: m_View = view;
237: }
238:
239: /* (non-Javadoc)
240: * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
241: */
242: public void mouseReleased(MouseEvent e) {
243: // Some Operating Systems will show the popupmenu on the mouse
244: // down and some will show it on the mouse up.
245: showPopupMenu(e);
246: }
247:
248: public void showPopupMenu(Component c) {
249:
250: if (m_ContextMenuManager.getRemoveAllWhenShown() == true) {
251: m_ContextMenuManager.removeAll();
252: m_ContextPopup.removeAll();
253: }
254:
255: menuAboutToShow(m_ContextMenuManager);
256: processRemovesIfAny(m_ContextMenuManager);
257:
258: // m_ContextMenu.menuAboutToShow(m_ContextMenuManager);
259: m_ContextMenuManager.createMenuBar();
260: JPopupMenu menu = m_ContextPopup.getPopupMenu();
261: menu.show(c, c.getLocation().x, c.getLocation().y);
262: }
263:
264: private boolean showPopupMenu(MouseEvent e) {
265: boolean retVal = e.isPopupTrigger();
266:
267: if (retVal == true) {
268: if (m_ContextMenuManager.getRemoveAllWhenShown() == true) {
269: m_ContextMenuManager.removeAll();
270: m_ContextPopup.removeAll();
271: }
272:
273: menuAboutToShow(m_ContextMenuManager);
274: processRemovesIfAny(m_ContextMenuManager);
275:
276: // m_ContextMenu.menuAboutToShow(m_ContextMenuManager);
277: m_ContextMenuManager.createMenuBar();
278: JPopupMenu menu = m_ContextPopup.getPopupMenu();
279: Component source = e.getComponent();
280: menu.show(source, e.getX(), e.getY());
281: } else {
282: super .mousePressed(e);
283: }
284:
285: return retVal;
286: }
287:
288: /* (non-Javadoc)
289: * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
290: */
291: public void mousePressed(MouseEvent e) {
292: // Some Operating Systems will show the popupmenu on the mouse
293: // down and some will show it on the mouse up.
294: showPopupMenu(e);
295: }
296:
297: }
298:
299: }
|