01: /*
02: * uDig - User Friendly Desktop Internet GIS client
03: * http://udig.refractions.net
04: * (C) 2004, Refractions Research Inc.
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation;
09: * version 2.1 of the License.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: */
17: package net.refractions.udig.project.ui.internal.tool.display;
18:
19: import net.refractions.udig.project.ui.internal.ImageConstants;
20: import net.refractions.udig.project.ui.internal.Images;
21: import net.refractions.udig.project.ui.internal.Messages;
22:
23: import org.eclipse.jface.action.ContributionItem;
24: import org.eclipse.swt.SWT;
25: import org.eclipse.swt.events.SelectionEvent;
26: import org.eclipse.swt.events.SelectionListener;
27: import org.eclipse.swt.widgets.Menu;
28: import org.eclipse.swt.widgets.MenuItem;
29: import org.eclipse.swt.widgets.ToolBar;
30: import org.eclipse.swt.widgets.ToolItem;
31:
32: /**
33: * A Toolbar item that creates a drop down menu of all the objects in the category.
34: *
35: * @author jeichar
36: * @since 0.9.0
37: *
38: * @deprecated
39: */
40: public class ToolbarDropDownItem extends ContributionItem {
41:
42: ToolCategory category;
43: AbstractToolbarContributionItem currentItem;
44:
45: /**
46: * Construct <code>ToolbarDropDownItem</code>.
47: */
48: public ToolbarDropDownItem(ToolCategory category,
49: AbstractToolbarContributionItem currentItem) {
50: this .category = category;
51: this .currentItem = currentItem;
52: }
53:
54: /**
55: * @see org.eclipse.jface.action.ContributionItem#fill(org.eclipse.swt.widgets.ToolBar, int)
56: */
57: public void fill(final ToolBar parent, int index) {
58: super .fill(parent, index);
59: ToolItem arrow = new ToolItem(parent, SWT.PUSH, index);
60: arrow.setImage(Images.get(ImageConstants.DROP_DOWN_BUTTON));
61: arrow.setWidth(16);
62: arrow.setToolTipText(Messages.ToolbarDropDownItem_chooseTool);
63: arrow.addSelectionListener(new SelectionListener() {
64:
65: public void widgetSelected(SelectionEvent e) {
66: widgetDefaultSelected(e);
67: }
68:
69: public void widgetDefaultSelected(SelectionEvent e) {
70: final Menu menu = new Menu(parent.getParent());
71: for (final ModalItem tool : category) {
72: MenuItem menuItem = new MenuItem(menu, SWT.PUSH);
73: menuItem.setImage(tool.getImage());
74: menuItem.setText(tool.getName());
75: menuItem
76: .addSelectionListener(new SelectionListener() {
77:
78: public void widgetSelected(
79: SelectionEvent e) {
80: widgetDefaultSelected(e);
81: }
82:
83: public void widgetDefaultSelected(
84: SelectionEvent e) {
85: currentItem.setCurrentTool(tool);
86: currentItem.runCurrentTool();
87: menu.dispose();
88: }
89: });
90: }
91: menu.setVisible(true);
92: }
93:
94: });
95: }
96: }
|