Changeset 93 in josm for src/org/openstreetmap/josm/actions/GroupAction.java
- Timestamp:
- 2006-04-23T00:41:38+02:00 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/actions/GroupAction.java
r91 r93 3 3 import java.awt.event.ActionEvent; 4 4 import java.awt.event.ActionListener; 5 import java.awt.event.KeyEvent; 6 import java.beans.PropertyChangeEvent; 7 import java.beans.PropertyChangeListener; 5 8 import java.util.ArrayList; 6 9 import java.util.List; 7 10 8 import javax.swing.AbstractAction;9 11 import javax.swing.Action; 10 12 import javax.swing.Icon; 11 13 import javax.swing.JMenuItem; 12 14 import javax.swing.JPopupMenu; 15 import javax.swing.KeyStroke; 13 16 14 17 import org.openstreetmap.josm.gui.IconToggleButton; … … 17 20 18 21 19 public class GroupAction extends AbstractAction {22 public class GroupAction extends JosmAction { 20 23 21 24 protected final List<Action> actions = new ArrayList<Action>(); 22 private int current; 25 private int current = -1; 26 private String shortCutName = ""; 27 28 private PropertyChangeListener forwardActiveListener = new PropertyChangeListener(){ 29 public void propertyChange(PropertyChangeEvent evt) { 30 if (evt.getPropertyName().equals("active")) { 31 putValue("active", evt.getNewValue()); 32 if (evt.getNewValue() == Boolean.FALSE) 33 cycle = false; 34 } 35 } 36 }; 37 public boolean cycle; 23 38 24 39 protected void setCurrent(int current) { 40 if (this.current != -1) 41 actions.get(this.current).removePropertyChangeListener(forwardActiveListener); 42 actions.get(current).addPropertyChangeListener(forwardActiveListener); 43 25 44 this.current = current; 26 45 putValue(SMALL_ICON, ImageProvider.overlay((Icon)actions.get(current).getValue(SMALL_ICON), "right", OverlayPosition.SOUTHEAST)); 27 putValue(SHORT_DESCRIPTION, actions.get(current).getValue(SHORT_DESCRIPTION)); 28 } 46 Object tooltip = actions.get(current).getValue(SHORT_DESCRIPTION); 47 putValue(SHORT_DESCRIPTION, "<html>"+tooltip+" <font size='-2'>"+shortCutName+"</font> </html>"); 48 } 49 50 public GroupAction(int shortCut, int modifiers) { 51 registerShortCut(getClass().getName(), KeyStroke.getKeyStroke(shortCut, modifiers)); 52 if ((modifiers & KeyEvent.CTRL_DOWN_MASK) != 0) 53 shortCutName += "Ctrl-"; 54 if ((modifiers & KeyEvent.ALT_DOWN_MASK) != 0) 55 shortCutName += "Alt-"; 56 if ((modifiers & KeyEvent.ALT_GRAPH_DOWN_MASK) != 0) 57 shortCutName += "AltGr-"; 58 if ((modifiers & KeyEvent.SHIFT_DOWN_MASK) != 0) 59 shortCutName += "Shift-"; 60 shortCutName += Character.toUpperCase((char)shortCut); 61 addPropertyChangeListener(new PropertyChangeListener(){ 62 public void propertyChange(PropertyChangeEvent evt) { 63 if (evt.getPropertyName().equals("active") && evt.getNewValue() == Boolean.FALSE) 64 cycle = false; 65 } 66 }); 67 } 29 68 30 69 public void actionPerformed(ActionEvent e) { … … 33 72 b.setSelected(!b.isSelected()); 34 73 openPopup(b); 35 } else 74 } else { 75 if (cycle) 76 setCurrent((current+1)%actions.size()); 77 else 78 cycle = true; 36 79 actions.get(current).actionPerformed(e); 37 } 80 } 81 } 38 82 39 83 private void openPopup(IconToggleButton b) { … … 45 89 public void actionPerformed(ActionEvent e) { 46 90 setCurrent(j); 47 91 } 48 92 }); 49 93 popup.add(item); 50 94 } 51 95 popup.show(b, b.getWidth(), 0); 52 96 } 53 97 }
Note:
See TracChangeset
for help on using the changeset viewer.