Changeset 3737 in josm


Ignore:
Timestamp:
2010-12-21T18:37:05+01:00 (11 years ago)
Author:
Upliner
Message:

make possible to place imagery offset action to the top toolbar and place it there by default; completely fixes #5726

Location:
trunk/src/org/openstreetmap/josm
Files:
1 added
6 edited

Legend:

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

    r3734 r3737  
    223223                OffsetBookmark.bookmarkOffset(tBookmarkName.getText(), layer);
    224224            }
    225             Main.main.menu.imageryMenuUpdater.refreshOffsetMenu();
     225            Main.main.menu.imageryMenu.refreshOffsetMenu();
    226226            if (Main.map == null) return;
    227227            if (oldMapMode != null) {
  • trunk/src/org/openstreetmap/josm/data/imagery/ImageryLayerInfo.java

    r3720 r3737  
    121121        instance.add(info);
    122122        instance.save();
    123         Main.main.menu.imageryMenuUpdater.refreshImageryMenu();
     123        Main.main.menu.imageryMenu.refreshImageryMenu();
    124124    }
    125125}
  • trunk/src/org/openstreetmap/josm/gui/MainMenu.java

    r3733 r3737  
    55import static org.openstreetmap.josm.tools.I18n.marktr;
    66import static org.openstreetmap.josm.tools.I18n.tr;
    7 import static org.openstreetmap.josm.tools.I18n.trc;
    8 
    9 import java.awt.event.ActionEvent;
     7
    108import java.awt.event.KeyEvent;
    11 import java.util.List;
    129
    1310import javax.swing.JCheckBoxMenuItem;
     
    1916import org.openstreetmap.josm.Main;
    2017import org.openstreetmap.josm.actions.AboutAction;
    21 import org.openstreetmap.josm.actions.AddImageryLayerAction;
    2218import org.openstreetmap.josm.actions.AddNodeAction;
    2319import org.openstreetmap.josm.actions.AlignInCircleAction;
     
    4642import org.openstreetmap.josm.actions.JosmAction;
    4743import org.openstreetmap.josm.actions.JumpToAction;
    48 import org.openstreetmap.josm.actions.Map_Rectifier_WMSmenuAction;
    4944import org.openstreetmap.josm.actions.MergeLayerAction;
    5045import org.openstreetmap.josm.actions.MergeNodesAction;
     
    9085import org.openstreetmap.josm.actions.audio.AudioSlowerAction;
    9186import org.openstreetmap.josm.actions.search.SearchAction;
    92 import org.openstreetmap.josm.data.imagery.ImageryInfo;
    93 import org.openstreetmap.josm.data.imagery.ImageryLayerInfo;
    9487import org.openstreetmap.josm.gui.io.RecentlyOpenedFilesMenu;
    95 import org.openstreetmap.josm.gui.layer.ImageryLayer;
    9688import org.openstreetmap.josm.gui.layer.Layer;
    97 import org.openstreetmap.josm.gui.layer.WMSLayer;
    9889import org.openstreetmap.josm.gui.tagging.TaggingPresetSearchAction;
    99 import org.openstreetmap.josm.tools.ImageProvider;
    10090import org.openstreetmap.josm.tools.Shortcut;
    10191
     
    190180    public final JMenu toolsMenu = addMenu(marktr("Tools"), KeyEvent.VK_T, 3, ht("/Menu/Tools"));
    191181    public final JMenu presetsMenu = addMenu(marktr("Presets"), KeyEvent.VK_P, 4, ht("/Menu/Presets"));
    192     public final JMenu imageryMenu = addMenu(marktr("Imagery"), KeyEvent.VK_I, 5, ht("/Menu/Imagery"));
     182    public final ImageryMenu imageryMenu =
     183        (ImageryMenu)addMenu(new ImageryMenu(), marktr("Imagery"), KeyEvent.VK_I, 5, ht("/Menu/Imagery"));
    193184    public JMenu audioMenu = null;
    194185    public final JMenu helpMenu = addMenu(marktr("Help"), KeyEvent.VK_H, 6, ht("/Menu/Help"));
     
    202193
    203194    public final TaggingPresetSearchAction presetSearchAction = new TaggingPresetSearchAction();
    204     public final ImageryMenuUpdater imageryMenuUpdater;
    205195
    206196    /**
     
    223213
    224214    public JMenu addMenu(String name, int mnemonicKey, int position, String relativeHelpTopic) {
    225         JMenu menu = new JMenu(tr(name));
     215        return addMenu(new JMenu(tr(name)), name, mnemonicKey, position, relativeHelpTopic);
     216    }
     217
     218    public JMenu addMenu(JMenu menu, String name, int mnemonicKey, int position, String relativeHelpTopic) {
    226219        Shortcut.registerShortcut("menu:" + name, tr("Menu: {0}", tr(name)), mnemonicKey,
    227220                Shortcut.GROUP_MNEMONIC).setMnemonic(menu);
     
    358351
    359352        new PresetsMenuEnabler(presetsMenu).refreshEnabled();
    360         imageryMenuUpdater = new ImageryMenuUpdater();
    361353    }
    362354
     
    390382        }
    391383    }
    392 
    393     public class ImageryMenuUpdater implements MapView.LayerChangeListener {
    394         JMenuItem disabledOffset = new JMenuItem(trc("layer","Offset"));
    395         JMenuItem offsetSubMenu = disabledOffset;
    396         int offsPos;
    397 
    398         public ImageryMenuUpdater() {
    399             MapView.addLayerChangeListener(this);
    400             disabledOffset.setEnabled(false);
    401         }
    402 
    403         public void refreshImageryMenu() {
    404             imageryMenu.removeAll();
    405 
    406             // for each configured WMSInfo, add a menu entry.
    407             for (final ImageryInfo u : ImageryLayerInfo.instance.getLayers()) {
    408                 imageryMenu.add(new AddImageryLayerAction(u));
    409             }
    410             imageryMenu.addSeparator();
    411             imageryMenu.add(new JMenuItem(new Map_Rectifier_WMSmenuAction()));
    412 
    413             imageryMenu.addSeparator();
    414             offsPos = imageryMenu.getMenuComponentCount();
    415             imageryMenu.add(offsetSubMenu);
    416             imageryMenu.addSeparator();
    417             imageryMenu.add(new JMenuItem(new JosmAction(
    418                     tr("Blank Layer"), "blankmenu", tr("Open a blank WMS layer to load data from a file"), null, false) {
    419                 @Override
    420                 public void actionPerformed(ActionEvent ev) {
    421                     if (!isEnabled()) return;
    422                     Main.main.addLayer(new WMSLayer());
    423                 }
    424 
    425                 @Override
    426                 protected void updateEnabledState() {
    427                     setEnabled(Main.map != null && Main.map.mapView != null && !Main.map.mapView.getAllLayers().isEmpty());
    428                 }
    429             }));
    430         }
    431 
    432         private JMenuItem getNewOffsetMenu(){
    433             if (Main.map == null || Main.map.mapView == null)
    434                 return disabledOffset;
    435             List<ImageryLayer> layers = Main.map.mapView.getLayersOfType(ImageryLayer.class);
    436             if (layers.isEmpty())
    437                 return disabledOffset;
    438             if (layers.size() == 1)
    439                 return layers.get(0).getOffsetMenuItem();
    440             JMenu newMenu = new JMenu(trc("layer","Offset"));
    441             newMenu.setIcon(ImageProvider.get("mapmode", "adjustimg"));
    442             for (ImageryLayer layer : layers) {
    443                 JMenuItem layerMenu = layer.getOffsetMenuItem();
    444                 layerMenu.setText(layer.getName());
    445                 layerMenu.setIcon(layer.getIcon());
    446                 newMenu.add(layerMenu);
    447             }
    448             return newMenu;
    449         }
    450 
    451         public void refreshOffsetMenu() {
    452             JMenuItem newItem = getNewOffsetMenu();
    453             imageryMenu.remove(offsetSubMenu);
    454             imageryMenu.add(newItem, offsPos);
    455             offsetSubMenu = newItem;
    456         }
    457 
    458         @Override
    459         public void activeLayerChange(Layer oldLayer, Layer newLayer) {
    460         }
    461 
    462         @Override
    463         public void layerAdded(Layer newLayer) {
    464             if (newLayer instanceof ImageryLayer) {
    465                 refreshOffsetMenu();
    466             }
    467         }
    468 
    469         @Override
    470         public void layerRemoved(Layer oldLayer) {
    471             if (oldLayer instanceof ImageryLayer) {
    472                 refreshOffsetMenu();
    473             }
    474         }
    475     }
    476384}
  • trunk/src/org/openstreetmap/josm/gui/layer/ImageryLayer.java

    r3733 r3737  
    1919import javax.swing.Icon;
    2020import javax.swing.JCheckBoxMenuItem;
     21import javax.swing.JComponent;
    2122import javax.swing.JMenu;
    2223import javax.swing.JMenuItem;
     
    128129        public void actionPerformed(ActionEvent ev) {
    129130            setOffset(b.dx, b.dy);
    130             Main.main.menu.imageryMenuUpdater.refreshOffsetMenu();
     131            Main.main.menu.imageryMenu.refreshOffsetMenu();
    131132            Main.map.repaint();
    132133        }
     
    152153
    153154    public JMenuItem getOffsetMenuItem() {
     155        JMenu subMenu = new JMenu(trc("layer", "Offset"));
     156        subMenu.setIcon(ImageProvider.get("mapmode", "adjustimg"));
     157        return (JMenuItem)getOffsetMenuItem(subMenu);
     158    }
     159
     160    public JComponent getOffsetMenuItem(JComponent subMenu) {
    154161        JMenuItem adjustMenuItem = new JMenuItem(adjustAction);
    155162        if (OffsetBookmark.allBookmarks.isEmpty()) return adjustMenuItem;
    156163
    157         JMenu subMenu = new JMenu(trc("layer", "Offset"));
    158         subMenu.setIcon(ImageProvider.get("mapmode", "adjustimg"));
    159164        subMenu.add(adjustMenuItem);
    160165        subMenu.add(new JSeparator());
  • trunk/src/org/openstreetmap/josm/gui/preferences/ImageryPreference.java

    r3729 r3737  
    274274        boolean restartRequired = false;
    275275        ImageryLayerInfo.instance.save();
    276         Main.main.menu.imageryMenuUpdater.refreshImageryMenu();
    277         Main.main.menu.imageryMenuUpdater.refreshOffsetMenu();
     276        Main.main.menu.imageryMenu.refreshImageryMenu();
     277        Main.main.menu.imageryMenu.refreshOffsetMenu();
    278278        OffsetBookmark.saveBookmarks();
    279279
     
    746746        ImageryLayerInfo.instance.load();
    747747        OffsetBookmark.loadBookmarks();
    748         Main.main.menu.imageryMenuUpdater.refreshImageryMenu();
    749         Main.main.menu.imageryMenuUpdater.refreshOffsetMenu();
     748        Main.main.menu.imageryMenu.refreshImageryMenu();
     749        Main.main.menu.imageryMenu.refreshOffsetMenu();
    750750    }
    751751}
  • trunk/src/org/openstreetmap/josm/gui/preferences/ToolbarPreferences.java

    r3583 r3737  
    712712    }
    713713
    714     private static final String[] deftoolbar = {"open", "save", "download", "upload", "|", "undo", "redo", "|", "dialogs/search", "preference", "|", "splitway", "combineway", "wayflip", "|", "tagginggroup_Highways/Streets", "tagginggroup_Highways/Ways", "tagginggroup_Highways/Waypoints", "tagginggroup_Highways/Barriers", "|", "tagginggroup_Transport/Car", "tagginggroup_Transport/Public Transport", "|", "tagginggroup_Travel/Tourism", "tagginggroup_Travel/Food+Drinks", "|", "tagginggroup_Travel/Historic Places", "|", "tagginggroup_Man-Made/Man Made"};
     714    private static final String[] deftoolbar = {"open", "save", "download", "upload", "|", "undo", "redo", "|", "dialogs/search", "preference", "|", "splitway", "combineway", "wayflip", "|", "imagery-offset", "|", "tagginggroup_Highways/Streets", "tagginggroup_Highways/Ways", "tagginggroup_Highways/Waypoints", "tagginggroup_Highways/Barriers", "|", "tagginggroup_Transport/Car", "tagginggroup_Transport/Public Transport", "|", "tagginggroup_Travel/Tourism", "tagginggroup_Travel/Food+Drinks", "|", "tagginggroup_Travel/Historic Places", "|", "tagginggroup_Man-Made/Man Made"};
    715715
    716716    private static Collection<String> getToolString() {
Note: See TracChangeset for help on using the changeset viewer.