001: /*
002: * Lucane - a collaborative platform
003: * Copyright (C) 2004 Vincent Fiack <vfiack@mail15.com>
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: */
019: package org.lucane.applications.whiteboard.gui;
020:
021: import java.awt.event.ActionEvent;
022: import java.util.ArrayList;
023: import java.util.Iterator;
024:
025: import javax.swing.AbstractAction;
026: import javax.swing.Action;
027: import javax.swing.JToggleButton;
028: import javax.swing.JToolBar;
029:
030: import org.lucane.applications.whiteboard.WhiteBoard;
031: import org.lucane.applications.whiteboard.graph.shapes.ShapeManager;
032:
033: public class ShapeToolBar extends JToolBar {
034: private WhiteBoard plugin;
035: private ShapeManager shapes;
036:
037: private JToggleButton btnSelect;
038: private ArrayList buttons;
039:
040: public ShapeToolBar(WhiteBoard plugin, ShapeManager shapes) {
041: this .plugin = plugin;
042: this .shapes = shapes;
043: this .buttons = new ArrayList();
044: this .setFloatable(false);
045:
046: btnSelect = new JToggleButton(new ShapeAction(null,
047: "stock_draw-selection.png"));
048: btnSelect.setSelected(true);
049: addButton(btnSelect);
050:
051: addSeparator();
052:
053: JToggleButton btn;
054:
055: btn = new JToggleButton(new ShapeAction("rectangle",
056: "stock_draw-rectangle-unfilled.png"));
057: addButton(btn);
058:
059: btn = new JToggleButton(new ShapeAction("roundRectangle",
060: "stock_draw-rounded-rectangle-unfilled.png"));
061: addButton(btn);
062:
063: btn = new JToggleButton(new ShapeAction("diamond",
064: "stock_draw-diamond-unfilled.png"));
065: addButton(btn);
066:
067: btn = new JToggleButton(new ShapeAction("ellipse",
068: "stock_draw-ellipse-unfilled.png"));
069: addButton(btn);
070:
071: addSeparator();
072:
073: btn = new JToggleButton(new ShapeAction("line",
074: "stock_draw-line.png"));
075: addButton(btn);
076:
077: btn = new JToggleButton(new ShapeAction("simpleArrow",
078: "stock_draw-line-ends-with-arrow.png"));
079: addButton(btn);
080:
081: btn = new JToggleButton(new ShapeAction("doubleArrow",
082: "stock_draw-line-with-arrows.png"));
083: addButton(btn);
084:
085: addSeparator();
086:
087: btn = new JToggleButton(new ShapeAction("text",
088: "stock_draw-text.png"));
089: addButton(btn);
090:
091: btn = new JToggleButton(new ShapeAction("image",
092: "stock_insert_image.png"));
093: addButton(btn);
094: }
095:
096: private void addButton(JToggleButton button) {
097: this .buttons.add(button);
098: button.setFocusable(false);
099: add(button);
100: }
101:
102: public void setEnabled(boolean enabled) {
103: super .setEnabled(enabled);
104:
105: Iterator i = buttons.iterator();
106: while (i.hasNext())
107: ((JToggleButton) i.next()).setEnabled(enabled);
108:
109: if (enabled)
110: resetToSelection();
111: else
112: unToggle();
113:
114: }
115:
116: private void unToggle() {
117: Iterator i = buttons.iterator();
118: while (i.hasNext())
119: ((JToggleButton) i.next()).setSelected(false);
120: }
121:
122: public void resetToSelection() {
123: unToggle();
124: btnSelect.doClick();
125: }
126:
127: class ShapeAction extends AbstractAction {
128: private String shapeName;
129:
130: public ShapeAction(String shapeName, String icon) {
131: this .shapeName = shapeName;
132:
133: putValue(Action.SMALL_ICON, plugin.getImageIcon(icon));
134: if (shapeName != null)
135: putValue(Action.SHORT_DESCRIPTION, plugin.tr("tip."
136: + shapeName));
137: else
138: putValue(Action.SHORT_DESCRIPTION, plugin
139: .tr("tip.select"));
140: }
141:
142: public void actionPerformed(ActionEvent ae) {
143: JToggleButton btn = (JToggleButton) ae.getSource();
144: if (btn.isSelected()) {
145: unToggle();
146: btn.setSelected(true);
147: shapes.setSelectedShape(shapeName);
148: } else
149: btnSelect.doClick();
150: }
151: }
152: }
|