[2711] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
| 2 | package org.openstreetmap.josm.actions;
|
---|
| 3 |
|
---|
| 4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
| 5 |
|
---|
| 6 | import java.awt.event.ActionEvent;
|
---|
| 7 | import java.awt.event.KeyEvent;
|
---|
| 8 |
|
---|
[4087] | 9 | import org.openstreetmap.josm.data.osm.visitor.paint.MapRendererFactory;
|
---|
| 10 | import org.openstreetmap.josm.data.osm.visitor.paint.StyledMapRenderer;
|
---|
| 11 | import org.openstreetmap.josm.data.osm.visitor.paint.WireframeMapRenderer;
|
---|
[12637] | 12 | import org.openstreetmap.josm.gui.MainApplication;
|
---|
[12354] | 13 | import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
---|
[2711] | 14 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
| 15 |
|
---|
[6220] | 16 | /**
|
---|
| 17 | * This class toggles the wireframe rendering mode.
|
---|
| 18 | * @since 2530
|
---|
| 19 | */
|
---|
| 20 | public class WireframeToggleAction extends ToggleAction {
|
---|
| 21 |
|
---|
| 22 | /**
|
---|
| 23 | * Constructs a new {@code WireframeToggleAction}.
|
---|
| 24 | */
|
---|
[2711] | 25 | public WireframeToggleAction() {
|
---|
[6220] | 26 | super(tr("Wireframe View"),
|
---|
| 27 | null, /* no icon */
|
---|
| 28 | tr("Enable/disable rendering the map as wireframe only"),
|
---|
[8510] | 29 | Shortcut.registerShortcut("menu:view:wireframe", tr("Toggle Wireframe view"), KeyEvent.VK_W, Shortcut.CTRL),
|
---|
[6220] | 30 | false /* register toolbar */
|
---|
[2711] | 31 | );
|
---|
[6069] | 32 | putValue("toolbar", "wireframe");
|
---|
[12637] | 33 | MainApplication.getToolbar().register(this);
|
---|
[6220] | 34 | setSelected(MapRendererFactory.getInstance().isWireframeMapRendererActive());
|
---|
[4175] | 35 | notifySelectedState();
|
---|
[2711] | 36 | }
|
---|
| 37 |
|
---|
[6220] | 38 | @Override
|
---|
| 39 | protected void updateEnabledState() {
|
---|
[12636] | 40 | setEnabled(getLayerManager().getEditLayer() != null);
|
---|
[4175] | 41 | }
|
---|
[2711] | 42 |
|
---|
[6220] | 43 | @Override
|
---|
| 44 | public void actionPerformed(ActionEvent e) {
|
---|
[6327] | 45 | toggleSelectedState(e);
|
---|
[6220] | 46 | if (isSelected()) {
|
---|
| 47 | MapRendererFactory.getInstance().activate(WireframeMapRenderer.class);
|
---|
| 48 | } else {
|
---|
| 49 | MapRendererFactory.getInstance().activate(StyledMapRenderer.class);
|
---|
[2711] | 50 | }
|
---|
[4175] | 51 |
|
---|
| 52 | notifySelectedState();
|
---|
[12636] | 53 | getLayerManager().getLayersOfType(OsmDataLayer.class).forEach(OsmDataLayer::invalidate);
|
---|
[2711] | 54 | }
|
---|
| 55 | }
|
---|