Ignore:
Timestamp:
2006-04-23T00:41:38+02:00 (18 years ago)
Author:
imi
Message:
  • added "insert node into line segment" mapmode
  • added direction hint to line segments
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/org/openstreetmap/josm/actions/GroupAction.java

    r91 r93  
    33import java.awt.event.ActionEvent;
    44import java.awt.event.ActionListener;
     5import java.awt.event.KeyEvent;
     6import java.beans.PropertyChangeEvent;
     7import java.beans.PropertyChangeListener;
    58import java.util.ArrayList;
    69import java.util.List;
    710
    8 import javax.swing.AbstractAction;
    911import javax.swing.Action;
    1012import javax.swing.Icon;
    1113import javax.swing.JMenuItem;
    1214import javax.swing.JPopupMenu;
     15import javax.swing.KeyStroke;
    1316
    1417import org.openstreetmap.josm.gui.IconToggleButton;
     
    1720
    1821
    19 public class GroupAction extends AbstractAction {
     22public class GroupAction extends JosmAction {
    2023
    2124        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;
    2338
    2439        protected void setCurrent(int current) {
     40                if (this.current != -1)
     41                        actions.get(this.current).removePropertyChangeListener(forwardActiveListener);
     42                actions.get(current).addPropertyChangeListener(forwardActiveListener);
     43
    2544                this.current = current;
    2645                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>&nbsp;</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        }
    2968
    3069        public void actionPerformed(ActionEvent e) {
     
    3372                        b.setSelected(!b.isSelected());
    3473                        openPopup(b);
    35                 } else
     74                } else {
     75                        if (cycle)
     76                                setCurrent((current+1)%actions.size());
     77                        else
     78                                cycle = true;
    3679                        actions.get(current).actionPerformed(e);
    37     }
     80                }
     81        }
    3882
    3983        private void openPopup(IconToggleButton b) {
     
    4589                                public void actionPerformed(ActionEvent e) {
    4690                                        setCurrent(j);
    47                 }
     91                                }
    4892                        });
    4993                        popup.add(item);
    5094                }
    5195                popup.show(b, b.getWidth(), 0);
    52     }
     96        }
    5397}
Note: See TracChangeset for help on using the changeset viewer.