source: josm/trunk/src/org/openstreetmap/josm/gui/IconToggleButton.java@ 4079

Last change on this file since 4079 was 3451, checked in by jttt, 14 years ago

Memory leaks, minor changes needed by wmsplugin

  • Property svn:eol-style set to native
File size: 1.7 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.gui;
3
4import java.awt.event.MouseAdapter;
5import java.awt.event.MouseEvent;
6import java.beans.PropertyChangeEvent;
7import java.beans.PropertyChangeListener;
8
9import javax.swing.Action;
10import javax.swing.JToggleButton;
11
12import org.openstreetmap.josm.tools.Destroyable;
13
14/**
15 * Just a toggle button, with smaller border and icon only to display in
16 * MapFrame toolbars.
17 *
18 * @author imi
19 */
20public class IconToggleButton extends JToggleButton implements PropertyChangeListener, Destroyable {
21
22 public boolean groupbutton;
23
24 /**
25 * Construct the toggle button with the given action.
26 */
27 public IconToggleButton(Action action) {
28 super(action);
29 setText(null);
30
31 Object o = action.getValue(Action.SHORT_DESCRIPTION);
32 if (o != null) {
33 setToolTipText(o.toString());
34 }
35
36 action.addPropertyChangeListener(this);
37
38 addMouseListener(new MouseAdapter(){
39 @Override public void mousePressed(MouseEvent e) {
40 groupbutton = e.getX() > getWidth()/2 && e.getY() > getHeight()/2;
41 }
42 });
43 }
44
45 public void propertyChange(PropertyChangeEvent evt) {
46 if (evt.getPropertyName().equals("active")) {
47 setSelected((Boolean)evt.getNewValue());
48 requestFocusInWindow();
49 } else if (evt.getPropertyName().equals("selected")) {
50 setSelected((Boolean)evt.getNewValue());
51 }
52 }
53
54 public void destroy() {
55 Action action = getAction();
56 if (action instanceof Destroyable) {
57 ((Destroyable) action).destroy();
58 }
59 action.removePropertyChangeListener(this);
60 }
61}
Note: See TracBrowser for help on using the repository browser.