| | 1 | package org.openstreetmap.josm.gui.mappaint; |
| | 2 | |
| | 3 | import static org.openstreetmap.josm.tools.I18n.tr; |
| | 4 | |
| | 5 | import java.awt.event.ActionEvent; |
| | 6 | import javax.swing.JCheckBoxMenuItem; |
| | 7 | import javax.swing.JMenu; |
| | 8 | import org.openstreetmap.josm.Main; |
| | 9 | import org.openstreetmap.josm.actions.JosmAction; |
| | 10 | import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.MapPaintSylesUpdateListener; |
| | 11 | import org.openstreetmap.josm.tools.ImageProvider; |
| | 12 | |
| | 13 | public class MapPaintMenu extends JMenu implements MapPaintSylesUpdateListener { |
| | 14 | |
| | 15 | private static class MapPaintAction extends JosmAction { |
| | 16 | |
| | 17 | private StyleSource style; |
| | 18 | private JCheckBoxMenuItem button; |
| | 19 | |
| | 20 | public MapPaintAction(StyleSource style) { |
| | 21 | super(style.getDisplayString(), style.icon, |
| | 22 | tr("Select the map painting styles"), null, style.icon != null); |
| | 23 | if (style.icon == null) { |
| | 24 | putValue("toolbar", "mappaint/" + style.getDisplayString()); |
| | 25 | Main.toolbar.register(this); |
| | 26 | } |
| | 27 | this.button = new JCheckBoxMenuItem(this); |
| | 28 | this.style = style; |
| | 29 | updateButton(); |
| | 30 | } |
| | 31 | |
| | 32 | private void updateButton() { |
| | 33 | button.getModel().setSelected(style.active); |
| | 34 | } |
| | 35 | |
| | 36 | private void toggleStyle() { |
| | 37 | MapPaintStyles.toggleStyleActive(MapPaintStyles.getStyles().getStyleSources().indexOf(style)); |
| | 38 | updateButton(); |
| | 39 | } |
| | 40 | |
| | 41 | @Override |
| | 42 | public void actionPerformed(ActionEvent ae) { |
| | 43 | toggleStyle(); |
| | 44 | } |
| | 45 | |
| | 46 | public JCheckBoxMenuItem getButton() { |
| | 47 | return button; |
| | 48 | } |
| | 49 | |
| | 50 | @Override |
| | 51 | public void updateEnabledState() { |
| | 52 | setEnabled(Main.map != null && Main.main.getEditLayer() != null); |
| | 53 | } |
| | 54 | } |
| | 55 | |
| | 56 | public MapPaintMenu() { |
| | 57 | super(tr("Map Paint Styles")); |
| | 58 | setIcon(ImageProvider.get("dialogs", "mapstyle")); |
| | 59 | MapPaintStyles.addMapPaintSylesUpdateListener(this); |
| | 60 | } |
| | 61 | |
| | 62 | @Override |
| | 63 | public void mapPaintStylesUpdated() { |
| | 64 | removeAll(); |
| | 65 | for (StyleSource style : MapPaintStyles.getStyles().getStyleSources()) { |
| | 66 | add(new MapPaintAction(style).getButton()); |
| | 67 | } |
| | 68 | } |
| | 69 | |
| | 70 | @Override |
| | 71 | public void mapPaintStyleEntryUpdated(int idx) { |
| | 72 | mapPaintStylesUpdated(); |
| | 73 | } |
| | 74 | } |