KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > ide > diagrams > ToolButton


1 /*
2  * @(#)ToolButton.java
3  *
4  * Project: JHotdraw - a GUI framework for technical drawings
5  * http://www.jhotdraw.org
6  * http://jhotdraw.sourceforge.net
7  * Copyright: © by the original author(s) and all contributors
8  * License: Lesser GNU Public License (LGPL)
9  * http://www.opensource.org/licenses/lgpl-license.html
10  */

11
12 package org.objectweb.jac.ide.diagrams;
13
14 import CH.ifa.draw.framework.Tool;
15 import CH.ifa.draw.framework.ToolListener;
16 import CH.ifa.draw.util.PaletteButton;
17 import CH.ifa.draw.util.PaletteListener;
18 import java.util.EventObject JavaDoc;
19 import javax.swing.BorderFactory JavaDoc;
20 import javax.swing.ImageIcon JavaDoc;
21 import javax.swing.border.BevelBorder JavaDoc;
22 import javax.swing.border.Border JavaDoc;
23
24 /**
25  * A PaletteButton that is associated with a tool.
26  *
27  * @see Tool
28  *
29  * @version <$CURRENT_VERSION$>
30  */

31 public class ToolButton extends PaletteButton implements ToolListener {
32
33    private String JavaDoc name;
34    private Tool tool;
35
36    public ToolButton(PaletteListener listener, ImageIcon JavaDoc icon, String JavaDoc name, Tool tool) {
37       super(listener);
38       tool.addToolListener(this);
39       setEnabled(tool.isUsable());
40
41       this.tool = tool;
42       this.name = name;
43                 
44       setIcon(icon);
45       setToolTipText(name);
46       setEnabled(true);
47       setBorder(normalBorder);
48    }
49
50    Border JavaDoc normalBorder =
51       BorderFactory.createCompoundBorder(
52          BorderFactory.createBevelBorder(BevelBorder.RAISED),
53          BorderFactory.createEmptyBorder(2,2,2,2));
54    Border JavaDoc pressedBorder =
55       BorderFactory.createCompoundBorder(
56          BorderFactory.createBevelBorder(BevelBorder.LOWERED),
57          BorderFactory.createEmptyBorder(2,2,2,2));
58
59    public Tool getTool() {
60       return tool;
61    }
62
63    public String JavaDoc getName() {
64       return name;
65    }
66
67    public Object JavaDoc attributeValue() {
68       return getTool();
69    }
70
71    public void toolUsable(EventObject JavaDoc toolEvent) {
72       setEnabled(true);
73    }
74
75    public void toolUnusable(EventObject JavaDoc toolEvent) {
76       setEnabled(false);
77       setSelected(false);
78    }
79
80    public void toolActivated(EventObject JavaDoc toolEvent) {
81       setBorder(pressedBorder);
82    }
83
84    public void toolDeactivated(EventObject JavaDoc toolEvent) {
85       setBorder(normalBorder);
86    }
87
88    public void toolEnabled(EventObject JavaDoc toolEvent) {
89       setEnabled(true);
90    }
91
92    public void toolDisabled(EventObject JavaDoc toolEvent) {
93       setEnabled(false);
94    }
95 }
96
Popular Tags