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

Last change on this file since 2946 was 2871, checked in by jttt, 14 years ago

Partially fix situation after last layer removal - most objects still stay in memory but at least there are less references and forgotten listeners

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