001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.actions; 003 004import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 005import static org.openstreetmap.josm.tools.I18n.tr; 006 007import java.awt.event.ActionEvent; 008import java.awt.event.KeyEvent; 009 010import org.openstreetmap.josm.Main; 011import org.openstreetmap.josm.tools.Shortcut; 012 013/** 014 * Zoom in map. 015 * @since 770 016 */ 017public final class ZoomInAction extends JosmAction { 018 019 /** 020 * Constructs a new {@code ZoomInAction}. 021 */ 022 public ZoomInAction() { 023 super( 024 tr("Zoom In"), 025 "dialogs/zoomin", 026 tr("Zoom In"), 027 // Although it might be possible on few custom keyboards, the vast majority of layouts do not have a direct '+' key, see below 028 Shortcut.registerShortcut("view:zoomin", tr("View: {0}", tr("Zoom In")),KeyEvent.VK_PLUS, Shortcut.DIRECT), 029 true 030 ); 031 putValue("help", ht("/Action/ZoomIn")); 032 // On standard QWERTY, AZERTY and other common layouts the '+' key is obtained with Shift+EQUALS 033 Main.registerActionShortcut(this, 034 Shortcut.registerShortcut("view:zoominbis", tr("View: {0}", tr("Zoom In")), 035 KeyEvent.VK_EQUALS, Shortcut.SHIFT)); 036 // make numpad + behave like + 037 Main.registerActionShortcut(this, 038 Shortcut.registerShortcut("view:zoominkeypad", tr("View: {0}", tr("Zoom In (Keypad)")), 039 KeyEvent.VK_ADD, Shortcut.DIRECT)); 040 } 041 042 @Override 043 public void actionPerformed(ActionEvent e) { 044 if (!Main.isDisplayingMapView()) return; 045 Main.map.mapView.zoomToFactor(1/Math.sqrt(2)); 046 } 047 048 @Override 049 protected void updateEnabledState() { 050 setEnabled( 051 Main.isDisplayingMapView() 052 && Main.map.mapView.hasLayers() 053 ); 054 } 055 056}