Ignore:
Timestamp:
2013-03-24T20:08:00+01:00 (13 years ago)
Author:
zverik
Message:

iodb: small refactoring, also offset watcher

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/imagery_offset_db/src/iodb/GetImageryOffsetAction.java

    r29384 r29394  
    77import java.net.*;
    88import java.util.*;
     9import javax.swing.Action;
     10import javax.swing.Icon;
    911import javax.swing.JOptionPane;
    1012import org.openstreetmap.josm.Main;
     
    1517import org.openstreetmap.josm.gui.layer.ImageryLayer;
    1618import static org.openstreetmap.josm.tools.I18n.tr;
     19import org.openstreetmap.josm.tools.ImageProvider;
    1720import org.openstreetmap.josm.tools.Shortcut;
    1821
     
    2427 */
    2528public class GetImageryOffsetAction extends JosmAction {
     29    private Icon iconOffsetOk;
     30    private Icon iconOffsetBad;
    2631   
    2732    /**
    2833     * Initialize the action. Sets "Ctrl+Alt+I" shortcut: the only shortcut in this plugin.
     34     * Also registers itself with {@link ImageryOffsetWatcher}.
    2935     */
    3036    public GetImageryOffsetAction() {
     
    3238                Shortcut.registerShortcut("imageryoffset:get", tr("Imagery: {0}", tr("Get Imagery Offset...")),
    3339                KeyEvent.VK_I, Shortcut.ALT_CTRL), true);
     40        iconOffsetOk = ImageProvider.get("getoffset");
     41        iconOffsetBad = ImageProvider.get("getoffsetnow"); // todo: create icon
     42        ImageryOffsetWatcher.getInstance().register(this);
    3443    }
    3544
     
    8493
    8594    /**
     95     * Update action icon based on an offset state.
     96     */
     97    public void offsetStateChanged( boolean isOffsetGood ) {
     98        putValue(Action.SMALL_ICON, isOffsetGood ? iconOffsetOk : iconOffsetBad);
     99    }
     100
     101    /**
     102     * Remove offset listener.
     103     */
     104    @Override
     105    public void destroy() {
     106        ImageryOffsetWatcher.getInstance().unregister(this);
     107        super.destroy();
     108    }
     109
     110    /**
    86111     * A task that downloads offsets for a given position and imagery layer,
    87112     * then parses resulting XML and calls
    88113     * {@link #showOffsetDialog(java.util.List)} on success.
    89114     */
    90     class DownloadOffsetsTask extends SimpleOffsetQueryTask {
     115    private class DownloadOffsetsTask extends SimpleOffsetQueryTask {
    91116        private ImageryLayer layer;
    92117        private List<ImageryOffsetBase> offsets;
Note: See TracChangeset for help on using the changeset viewer.