001: /*--
002:
003: Copyright (C) 2002 Anthony Eden.
004: All rights reserved.
005:
006: Redistribution and use in source and binary forms, with or without
007: modification, are permitted provided that the following conditions
008: are met:
009:
010: 1. Redistributions of source code must retain the above copyright
011: notice, this list of conditions, and the following disclaimer.
012:
013: 2. Redistributions in binary form must reproduce the above copyright
014: notice, this list of conditions, and the disclaimer that follows
015: these conditions in the documentation and/or other materials
016: provided with the distribution.
017:
018: 3. The names "OBE" and "Open Business Engine" must not be used to
019: endorse or promote products derived from this software without prior
020: written permission. For written permission, please contact
021: me@anthonyeden.com.
022:
023: 4. Products derived from this software may not be called "OBE" or
024: "Open Business Engine", nor may "OBE" or "Open Business Engine"
025: appear in their name, without prior written permission from
026: Anthony Eden (me@anthonyeden.com).
027:
028: In addition, I request (but do not require) that you include in the
029: end-user documentation provided with the redistribution and/or in the
030: software itself an acknowledgement equivalent to the following:
031: "This product includes software developed by
032: Anthony Eden (http://www.anthonyeden.com/)."
033:
034: THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
035: WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
036: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
037: DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT,
038: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
039: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
040: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
041: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
042: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
043: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
044: POSSIBILITY OF SUCH DAMAGE.
045:
046: For more information on OBE, please see <http://obe.sourceforge.net/>.
047:
048: */
049:
050: package org.obe.designer;
051:
052: import java.awt.Insets;
053: import java.awt.Dimension;
054: import java.awt.event.ActionEvent;
055: import java.awt.event.ActionListener;
056: import java.util.Map;
057:
058: import javax.swing.Box;
059: import javax.swing.Action;
060: import javax.swing.JPanel;
061: import javax.swing.JButton;
062: import javax.swing.JToolBar;
063: import javax.swing.JComboBox;
064:
065: import com.anthonyeden.lib.util.IconManager;
066:
067: import org.obe.designer.util.Scale;
068:
069: public class OBEDesignerToolBar extends JToolBar {
070:
071: private static Insets NO_MARGIN = new Insets(0, 0, 0, 0);
072:
073: private OBEDesigner parent;
074:
075: private JButton newButton;
076: private JButton openButton;
077: private JButton closeButton;
078: private JButton saveButton;
079: private JButton saveAsButton;
080: private JButton cutButton;
081: private JButton copyButton;
082: private JButton pasteButton;
083:
084: private JComboBox scaleComboBox;
085:
086: public OBEDesignerToolBar(OBEDesigner parent) {
087: this .parent = parent;
088: init();
089: }
090:
091: public void loadResources() {
092: IconManager iconManager = new IconManager(
093: "toolbarButtonGraphics/");
094:
095: newButton.setIcon(iconManager.getIcon("general/New24.gif"));
096: newButton.setToolTipText("New");
097: newButton.setFocusPainted(false);
098: newButton.setMargin(NO_MARGIN);
099:
100: openButton.setIcon(iconManager.getIcon("general/Open24.gif"));
101: openButton.setToolTipText("Open");
102: openButton.setFocusPainted(false);
103: openButton.setMargin(NO_MARGIN);
104:
105: saveButton.setIcon(iconManager.getIcon("general/Save24.gif"));
106: saveButton.setToolTipText("Save");
107: saveButton.setFocusPainted(false);
108: saveButton.setMargin(NO_MARGIN);
109:
110: saveAsButton.setIcon(iconManager
111: .getIcon("general/SaveAs24.gif"));
112: saveAsButton.setToolTipText("Save As");
113: saveAsButton.setFocusPainted(false);
114: saveAsButton.setMargin(NO_MARGIN);
115:
116: cutButton.setIcon(iconManager.getIcon("general/Cut24.gif"));
117: cutButton.setToolTipText("Cut");
118: cutButton.setFocusPainted(false);
119: cutButton.setMargin(NO_MARGIN);
120:
121: copyButton.setIcon(iconManager.getIcon("general/Copy24.gif"));
122: copyButton.setToolTipText("Copy");
123: copyButton.setFocusPainted(false);
124: copyButton.setMargin(NO_MARGIN);
125:
126: pasteButton.setIcon(iconManager.getIcon("general/Paste24.gif"));
127: pasteButton.setToolTipText("Paste");
128: pasteButton.setFocusPainted(false);
129: pasteButton.setMargin(NO_MARGIN);
130: }
131:
132: public void setScale(Scale scale) {
133: scaleComboBox.setSelectedItem(scale);
134: }
135:
136: private void init() {
137: //setBorderPainted(false);
138: //setRollover(true);
139: //setMargin(new Insets(0, 0, 0, 0));
140:
141: Map actions = parent.getActions();
142:
143: newButton = add((Action) actions.get("file.new"));
144: openButton = add((Action) actions.get("file.open"));
145: saveButton = add((Action) actions.get("file.save"));
146: saveAsButton = add((Action) actions.get("file.saveAs"));
147:
148: cutButton = add((Action) actions.get("edit.cut"));
149: copyButton = add((Action) actions.get("edit.copy"));
150: pasteButton = add((Action) actions.get("edit.paste"));
151:
152: scaleComboBox = new JComboBox(Scale.DEFAULT_SET);
153: scaleComboBox.setSelectedItem(parent.getScale());
154: scaleComboBox.setEditable(true);
155: scaleComboBox.setMaximumSize(new Dimension(30, 20));
156: scaleComboBox.addActionListener(new ActionListener() {
157: public void actionPerformed(ActionEvent evt) {
158: Object scale = scaleComboBox.getSelectedItem();
159: if (scale instanceof Scale) {
160: parent.setScale((Scale) scale);
161: } else {
162: try {
163: parent.setScale(Scale.parseScale(scale
164: .toString()));
165: } catch (NumberFormatException e) {
166: OBEDesigner.error(e);
167: }
168: }
169: }
170: });
171: add(scaleComboBox);
172:
173: add(Box.createHorizontalGlue());
174:
175: loadResources();
176: }
177:
178: }
|