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

Last change on this file since 8 was 8, checked in by imi, 19 years ago
  • added Selection Dialog
  • added support for graphic engines with a better default engine
  • reorganized data classes with back references
File size: 1.3 KB
Line 
1package org.openstreetmap.josm.gui;
2
3import java.beans.PropertyChangeEvent;
4import java.beans.PropertyChangeListener;
5
6import javax.swing.Action;
7import javax.swing.JComponent;
8import javax.swing.JToggleButton;
9
10/**
11 * Just a toggle button, with smaller border and icon only to display in
12 * MapFrame toolbars.
13 *
14 * @author imi
15 */
16public class IconToggleButton extends JToggleButton implements PropertyChangeListener {
17
18 /**
19 * Construct the toggle button with the given action.
20 */
21 public IconToggleButton(JComponent acceleratorReceiver, Action action) {
22 super(action);
23 setText(null);
24
25 // Tooltip
26 String toolTipText = "";
27 Object o = action.getValue(Action.LONG_DESCRIPTION);
28 if (o != null)
29 toolTipText += o.toString();
30 o = action.getValue(Action.ACCELERATOR_KEY);
31 if (o != null) {
32 String ksName = o.toString();
33 if (ksName.startsWith("pressed "))
34 ksName = ksName.substring("pressed ".length());
35 else if (ksName.startsWith("released "))
36 ksName = ksName.substring("released ".length());
37 toolTipText += " Shortcut: "+ksName;
38 }
39 setToolTipText(toolTipText);
40
41 action.addPropertyChangeListener(this);
42 }
43
44 public void propertyChange(PropertyChangeEvent evt) {
45 if (evt.getPropertyName().equals("active"))
46 setSelected((Boolean)evt.getNewValue());
47 }
48}
Note: See TracBrowser for help on using the repository browser.