Changeset 6220 in josm
- Timestamp:
- 2013-09-07T15:50:39+02:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/actions
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/ChangesetManagerToggleAction.java
r6084 r6220 10 10 import java.awt.event.WindowEvent; 11 11 import java.awt.event.WindowListener; 12 import java.util.ArrayList;13 import java.util.List;14 15 import javax.swing.ButtonModel;16 12 17 13 import org.openstreetmap.josm.gui.dialogs.changeset.ChangesetCacheManager; 18 14 import org.openstreetmap.josm.tools.Shortcut; 15 19 16 /** 20 17 * This action toggles the visibility of the {@link ChangesetCacheManager} dialog. 21 * 18 * @since 2685 22 19 */ 23 public class ChangesetManagerToggleAction extends JosmAction { 24 private final List<ButtonModel> buttonModels = new ArrayList<ButtonModel>(); 25 //FIXME: replace with property Action.SELECTED_KEY when migrating to 26 // Java 6 27 private boolean selected; 20 public class ChangesetManagerToggleAction extends ToggleAction { 28 21 private WindowListener changesetCacheManagerClosedHandler; 29 22 23 /** 24 * Constructs a new {@code ChangesetManagerToggleAction}. 25 */ 30 26 public ChangesetManagerToggleAction() { 31 super( 32 tr("Changeset Manager"), 33 "dialogs/changeset/changesetmanager", 34 tr("Toggle visibility of Changeset Manager window"), 35 Shortcut.registerShortcut("menu:windows:changesetdialog", 36 tr("Toggle visibility of Changeset Manager window"), 37 KeyEvent.VK_C, Shortcut.ALT_CTRL), 38 true /* register shortcut */ 27 super(tr("Changeset Manager"), 28 "dialogs/changeset/changesetmanager", 29 tr("Toggle visibility of Changeset Manager window"), 30 Shortcut.registerShortcut("menu:windows:changesetdialog", 31 tr("Toggle visibility of Changeset Manager window"), 32 KeyEvent.VK_C, Shortcut.ALT_CTRL), 33 true /* register shortcut */ 39 34 ); 40 35 notifySelectedState(); … … 43 38 } 44 39 45 public void addButtonModel(ButtonModel model) { 46 if (model != null && !buttonModels.contains(model)) { 47 buttonModels.add(model); 48 } 49 } 50 51 public void removeButtonModel(ButtonModel model) { 52 if (model != null && buttonModels.contains(model)) { 53 buttonModels.remove(model); 54 } 55 } 56 57 protected void notifySelectedState() { 58 for (ButtonModel model: buttonModels) { 59 if (model.isSelected() != selected) { 60 model.setSelected(selected); 61 } 62 } 63 } 64 65 protected void toggleSelectedState() { 66 selected = !selected; 40 @Override 41 public void actionPerformed(ActionEvent e) { 42 toggleSelectedState(); 67 43 notifySelectedState(); 68 if ( selected) {44 if (isSelected()) { 69 45 ChangesetCacheManager.getInstance().addWindowListener(changesetCacheManagerClosedHandler); 70 46 ChangesetCacheManager.getInstance().setVisible(true); … … 75 51 } 76 52 77 @Override78 public void actionPerformed(ActionEvent e) {79 toggleSelectedState();80 }81 82 53 private class ChangesetCacheManagerClosedHandler extends WindowAdapter { 83 54 @Override 84 55 public void windowClosed(WindowEvent e) { 85 se lected = false;56 setSelected(false); 86 57 notifySelectedState(); 87 58 ChangesetCacheManager.getInstance().removeWindowListener(changesetCacheManagerClosedHandler); -
trunk/src/org/openstreetmap/josm/actions/DialogsToggleAction.java
r6069 r6220 7 7 import java.awt.event.ActionEvent; 8 8 import java.awt.event.KeyEvent; 9 import java.util.ArrayList;10 import java.util.List;11 9 12 import javax.swing.ButtonModel;13 10 import javax.swing.Icon; 14 11 … … 16 13 import org.openstreetmap.josm.tools.Shortcut; 17 14 18 /* 19 * Action that hides or shows toggle dialogs panel and other panels 20 * to free more space for drawing (GIMP-like) 15 /** 16 * This action toggles visibility of dialogs panel and other panels to free more space for drawing (GIMP-like) 21 17 * @author cmuelle8 18 * @since 5965 22 19 */ 23 public class DialogsToggleAction extends JosmAction { 24 private final List<ButtonModel> buttonModels = new ArrayList<ButtonModel>(); 25 private boolean selected; 20 public class DialogsToggleAction extends ToggleAction { 26 21 22 /** 23 * Constructs a new {@code DialogsToggleAction}. 24 */ 27 25 public DialogsToggleAction() { 28 super( 29 tr("Toggle dialogs panel"), 30 (Icon) null, /* no icon */ 31 tr("Toggle dialogs panel, maximize mapview"), 32 Shortcut.registerShortcut("menu:view:dialogspanel", tr("Toggle dialogs panel"),KeyEvent.VK_TAB, Shortcut.DIRECT), 33 true, "dialogspanel", /* register in toolbar */ 34 false 26 super(tr("Toggle dialogs panel"), 27 (Icon) null, /* no icon */ 28 tr("Toggle dialogs panel, maximize mapview"), 29 Shortcut.registerShortcut("menu:view:dialogspanel", tr("Toggle dialogs panel"),KeyEvent.VK_TAB, Shortcut.DIRECT), 30 true, "dialogspanel", /* register in toolbar */ 31 false 35 32 ); 36 33 putValue("help", ht("/Action/ToggleDialogsPanel")); 37 se lected = Main.pref.getBoolean("draw.dialogspanel", true);34 setSelected(Main.pref.getBoolean("draw.dialogspanel", true)); 38 35 notifySelectedState(); 39 36 } 40 37 41 public void addButtonModel(ButtonModel model) { 42 if (model != null && !buttonModels.contains(model)) { 43 buttonModels.add(model); 44 } 45 } 46 47 public void removeButtonModel(ButtonModel model) { 48 if (model != null && buttonModels.contains(model)) { 49 buttonModels.remove(model); 50 } 51 } 52 53 protected void notifySelectedState() { 54 for (ButtonModel model: buttonModels) { 55 if (model.isSelected() != selected) { 56 model.setSelected(selected); 57 } 58 } 59 } 60 61 protected void toggleSelectedState() { 62 selected = !selected; 63 Main.pref.put("draw.dialogspanel", selected); 38 @Override 39 public void actionPerformed(ActionEvent e) { 40 toggleSelectedState(); 41 Main.pref.put("draw.dialogspanel", isSelected()); 64 42 notifySelectedState(); 65 43 setMode(); 66 44 } 67 45 46 /** 47 * To call if this action must be initially run at JOSM startup. 48 */ 68 49 public void initial() { 69 if (selected) {50 if (isSelected()) { 70 51 setMode(); 71 52 } … … 74 55 protected void setMode() { 75 56 if (Main.isDisplayingMapView()) { 57 boolean selected = isSelected(); 76 58 Main.map.setDialogsPanelVisible(selected); 77 59 Main.map.statusLine.setVisible(selected || Main.pref.getBoolean("statusbar.always-visible", true)); … … 85 67 } 86 68 } 87 88 @Override89 public void actionPerformed(ActionEvent e) {90 toggleSelectedState();91 }92 69 } -
trunk/src/org/openstreetmap/josm/actions/ExpertToggleAction.java
r6084 r6220 11 11 import java.util.List; 12 12 13 import javax.swing.ButtonModel;14 15 13 import org.openstreetmap.josm.Main; 16 14 17 public class ExpertToggleAction extends JosmAction { 18 19 private final List<ButtonModel> buttonModels = new ArrayList<ButtonModel>(); 20 private boolean selected; 15 /** 16 * This action toggles the Expert mode. 17 * @since 4840 18 */ 19 public class ExpertToggleAction extends ToggleAction { 21 20 22 21 public interface ExpertModeChangeListener { … … 118 117 } 119 118 119 /** 120 * Constructs a new {@code ExpertToggleAction}. 121 */ 120 122 public ExpertToggleAction() { 121 super( 122 tr("Expert Mode"), 123 "expert", 124 tr("Enable/disable expert mode"), 125 null, 126 false /* register toolbar */ 123 super(tr("Expert Mode"), 124 "expert", 125 tr("Enable/disable expert mode"), 126 null, 127 false /* register toolbar */ 127 128 ); 128 129 putValue("toolbar", "expertmode"); 129 130 Main.toolbar.register(this); 130 se lected = Main.pref.getBoolean("expert", false);131 setSelected(Main.pref.getBoolean("expert", false)); 131 132 notifySelectedState(); 132 133 } 133 134 134 public void addButtonModel(ButtonModel model) {135 if (model != null && !buttonModels.contains(model)) {136 buttonModels.add(model);137 model.setSelected(selected);138 }139 }140 141 public void removeButtonModel(ButtonModel model) {142 if (model != null && buttonModels.contains(model)) {143 buttonModels.remove(model);144 }145 }146 147 135 protected void notifySelectedState() { 148 for (ButtonModel model: buttonModels) { 149 if (model.isSelected() != selected) { 150 model.setSelected(selected); 151 } 152 } 153 fireExpertModeChanged(selected); 154 } 155 156 protected void toggleSelectedState() { 157 selected = !selected; 158 Main.pref.put("expert", selected); 159 notifySelectedState(); 136 super.notifySelectedState(); 137 fireExpertModeChanged(isSelected()); 160 138 } 161 139 … … 163 141 public void actionPerformed(ActionEvent e) { 164 142 toggleSelectedState(); 143 Main.pref.put("expert", isSelected()); 144 notifySelectedState(); 165 145 } 166 146 167 public boolean isSelected() {168 return selected;169 }170 147 /** 148 * Replies the unique instance of this action. 149 * @return The unique instance of this action 150 */ 171 151 public static ExpertToggleAction getInstance() { 172 152 return INSTANCE; 173 153 } 174 154 155 /** 156 * Determines if expert mode is enabled. 157 * @return {@code true} if expert mode is enabled, {@code false} otherwise. 158 */ 175 159 public static boolean isExpert() { 176 160 return INSTANCE.isSelected(); -
trunk/src/org/openstreetmap/josm/actions/FullscreenToggleAction.java
r6084 r6220 16 16 import java.util.List; 17 17 18 import javax.swing.ButtonModel;19 18 import javax.swing.JComponent; 20 19 import javax.swing.JFrame; … … 25 24 import org.openstreetmap.josm.tools.Shortcut; 26 25 27 public class FullscreenToggleAction extends JosmAction { 28 private final List<ButtonModel> buttonModels = new ArrayList<ButtonModel>(); 29 private boolean selected; 26 /** 27 * This class toggles the full-screen mode. 28 * @since 2533 29 */ 30 public class FullscreenToggleAction extends ToggleAction { 30 31 private GraphicsDevice gd; 31 32 private Rectangle prevBounds; 32 33 34 /** 35 * Constructs a new {@code FullscreenToggleAction}. 36 */ 33 37 public FullscreenToggleAction() { 34 super( 35 tr("Fullscreen view"), 36 null, /* no icon */ 37 tr("Toggle fullscreen view"), 38 Shortcut.registerShortcut("menu:view:fullscreen", tr("Toggle fullscreen view"),KeyEvent.VK_F11, Shortcut.DIRECT), 39 false /* register */ 38 super(tr("Fullscreen view"), 39 null, /* no icon */ 40 tr("Toggle fullscreen view"), 41 Shortcut.registerShortcut("menu:view:fullscreen", tr("Toggle fullscreen view"),KeyEvent.VK_F11, Shortcut.DIRECT), 42 false /* register */ 40 43 ); 41 44 putValue("help", ht("/Action/FullscreenView")); … … 43 46 Main.toolbar.register(this); 44 47 gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); 45 se lected = Main.pref.getBoolean("draw.fullscreen", false);48 setSelected(Main.pref.getBoolean("draw.fullscreen", false)); 46 49 notifySelectedState(); 47 50 } 48 51 49 public void addButtonModel(ButtonModel model) { 50 if (model != null && !buttonModels.contains(model)) { 51 buttonModels.add(model); 52 } 53 } 54 55 public void removeButtonModel(ButtonModel model) { 56 if (model != null && buttonModels.contains(model)) { 57 buttonModels.remove(model); 58 } 59 } 60 61 protected void notifySelectedState() { 62 for (ButtonModel model: buttonModels) { 63 if (model.isSelected() != selected) { 64 model.setSelected(selected); 65 } 66 } 67 } 68 69 protected void toggleSelectedState() { 70 selected = !selected; 71 Main.pref.put("draw.fullscreen", selected); 52 @Override 53 public void actionPerformed(ActionEvent e) { 54 toggleSelectedState(); 55 Main.pref.put("draw.fullscreen", isSelected()); 72 56 notifySelectedState(); 73 57 setMode(); 74 58 } 75 59 60 /** 61 * To call if this action must be initially run at JOSM startup. 62 */ 76 63 public void initial() { 77 if (selected)64 if (isSelected()) { 78 65 setMode(); 66 } 79 67 } 80 68 … … 89 77 } 90 78 } 79 80 boolean selected = isSelected(); 91 81 92 82 frame.dispose(); … … 120 110 frame.getJMenuBar().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_F10, 0), "none"); 121 111 } 122 123 @Override124 public void actionPerformed(ActionEvent e) {125 toggleSelectedState();126 }127 112 } -
trunk/src/org/openstreetmap/josm/actions/ViewportFollowToggleAction.java
r6084 r6220 7 7 import java.awt.event.ActionEvent; 8 8 import java.awt.event.KeyEvent; 9 import java.util.ArrayList;10 import java.util.List;11 12 import javax.swing.ButtonModel;13 9 14 10 import org.openstreetmap.josm.Main; 15 11 import org.openstreetmap.josm.tools.Shortcut; 16 12 17 public class ViewportFollowToggleAction extends JosmAction { 18 private final List<ButtonModel> buttonModels = new ArrayList<ButtonModel>(); 19 private boolean selected; 13 /** 14 * This action toggles automatic moving of the map view to last placed node 15 * @since 3837 16 */ 17 public class ViewportFollowToggleAction extends ToggleAction { 18 19 /** 20 * Constructs a new {@code ViewportFollowToggleAction}. 21 */ 20 22 public ViewportFollowToggleAction() { 21 super( 22 tr("Viewport Following"), 23 "viewport-follow", 24 tr("Enable/disable automatic moving of the map view to last placed node"), 25 Shortcut.registerShortcut("menu:view:viewportfollow", tr("Toggle Viewport Following"), 26 KeyEvent.VK_F, Shortcut.CTRL_SHIFT), 27 true /* register shortcut */ 23 super(tr("Viewport Following"), 24 "viewport-follow", 25 tr("Enable/disable automatic moving of the map view to last placed node"), 26 Shortcut.registerShortcut("menu:view:viewportfollow", tr("Toggle Viewport Following"), 27 KeyEvent.VK_F, Shortcut.CTRL_SHIFT), 28 true /* register shortcut */ 28 29 ); 29 30 putValue("help", ht("/Action/ViewportFollowing")); 30 se lected = false;31 setSelected(false); 31 32 notifySelectedState(); 32 33 } 33 34 34 public void addButtonModel(ButtonModel model) {35 if (model != null && !buttonModels.contains(model)) {36 buttonModels.add(model);37 model.setSelected(selected);38 }39 }40 41 public void removeButtonModel(ButtonModel model) {42 if (model != null && buttonModels.contains(model)) {43 buttonModels.remove(model);44 }45 }46 47 protected void notifySelectedState() {48 for (ButtonModel model: buttonModels) {49 if (model.isSelected() != selected) {50 model.setSelected(selected);51 }52 }53 }54 55 protected void toggleSelectedState() {56 selected = !selected;57 Main.map.mapView.viewportFollowing = selected;58 notifySelectedState();59 }60 35 @Override 61 36 public void actionPerformed(ActionEvent e) { 62 37 toggleSelectedState(); 38 Main.map.mapView.viewportFollowing = isSelected(); 39 notifySelectedState(); 63 40 } 64 41 -
trunk/src/org/openstreetmap/josm/actions/WireframeToggleAction.java
r6084 r6220 6 6 import java.awt.event.ActionEvent; 7 7 import java.awt.event.KeyEvent; 8 import java.util.ArrayList;9 import java.util.List;10 11 import javax.swing.ButtonModel;12 8 13 9 import org.openstreetmap.josm.Main; … … 17 13 import org.openstreetmap.josm.tools.Shortcut; 18 14 19 public class WireframeToggleAction extends JosmAction { 20 private final List<ButtonModel> buttonModels = new ArrayList<ButtonModel>(); 21 //FIXME: replace with property Action.SELECTED_KEY when migrating to 22 // Java 6 23 private boolean selected; 15 /** 16 * This class toggles the wireframe rendering mode. 17 * @since 2530 18 */ 19 public class WireframeToggleAction extends ToggleAction { 20 21 /** 22 * Constructs a new {@code WireframeToggleAction}. 23 */ 24 24 public WireframeToggleAction() { 25 super( 26 tr("Wireframe View"), 27 null, /* no icon */ 28 tr("Enable/disable rendering the map as wireframe only"), 29 Shortcut.registerShortcut("menu:view:wireframe", tr("Toggle Wireframe view"),KeyEvent.VK_W, Shortcut.CTRL), 30 false /* register toolbar */ 25 super(tr("Wireframe View"), 26 null, /* no icon */ 27 tr("Enable/disable rendering the map as wireframe only"), 28 Shortcut.registerShortcut("menu:view:wireframe", tr("Toggle Wireframe view"),KeyEvent.VK_W, Shortcut.CTRL), 29 false /* register toolbar */ 31 30 ); 32 31 putValue("toolbar", "wireframe"); 33 32 Main.toolbar.register(this); 34 se lected = MapRendererFactory.getInstance().isWireframeMapRendererActive();33 setSelected(MapRendererFactory.getInstance().isWireframeMapRendererActive()); 35 34 notifySelectedState(); 36 }37 38 public void addButtonModel(ButtonModel model) {39 if (model != null && !buttonModels.contains(model)) {40 buttonModels.add(model);41 model.setSelected(selected);42 }43 }44 45 public void removeButtonModel(ButtonModel model) {46 if (model != null && buttonModels.contains(model)) {47 buttonModels.remove(model);48 }49 }50 51 protected void notifySelectedState() {52 for (ButtonModel model: buttonModels) {53 if (model.isSelected() != selected) {54 model.setSelected(selected);55 }56 }57 }58 59 protected void toggleSelectedState() {60 selected = !selected;61 //Main.pref.put("draw.wireframe", selected);62 if (selected){63 MapRendererFactory.getInstance().activate(WireframeMapRenderer.class);64 } else {65 MapRendererFactory.getInstance().activate(StyledMapRenderer.class);66 }67 68 notifySelectedState();69 if (Main.isDisplayingMapView()) {70 Main.map.mapView.repaint();71 }72 }73 74 @Override75 public void actionPerformed(ActionEvent e) {76 toggleSelectedState();77 35 } 78 36 … … 82 40 } 83 41 84 public boolean isSelected() { 85 return selected; 42 @Override 43 public void actionPerformed(ActionEvent e) { 44 toggleSelectedState(); 45 if (isSelected()) { 46 MapRendererFactory.getInstance().activate(WireframeMapRenderer.class); 47 } else { 48 MapRendererFactory.getInstance().activate(StyledMapRenderer.class); 49 } 50 51 notifySelectedState(); 52 if (Main.isDisplayingMapView()) { 53 Main.map.mapView.repaint(); 54 } 86 55 } 87 56 }
Note:
See TracChangeset
for help on using the changeset viewer.