    001// License: GPL. For details, see LICENSE file.
    002package org.openstreetmap.josm.plugins.streetside;
    003
    004import org.openstreetmap.josm.Main;
    005import org.openstreetmap.josm.gui.MainApplication;
    006import org.openstreetmap.josm.gui.MainMenu;
    007import org.openstreetmap.josm.gui.MapFrame;
    008import org.openstreetmap.josm.gui.MapView;
    009import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
    010import org.openstreetmap.josm.plugins.Plugin;
    011import org.openstreetmap.josm.plugins.PluginInformation;
    012import org.openstreetmap.josm.plugins.streetside.actions.StreetsideDownloadAction;
    013import org.openstreetmap.josm.plugins.streetside.actions.StreetsideDownloadViewAction;
    014import org.openstreetmap.josm.plugins.streetside.actions.StreetsideExportAction;
    015import org.openstreetmap.josm.plugins.streetside.actions.StreetsideJoinAction;
    016import org.openstreetmap.josm.plugins.streetside.actions.StreetsideWalkAction;
    017import org.openstreetmap.josm.plugins.streetside.actions.StreetsideZoomAction;
    018import org.openstreetmap.josm.plugins.streetside.cubemap.CubemapBuilder;
    019import org.openstreetmap.josm.plugins.streetside.gui.StreetsideMainDialog;
    020import org.openstreetmap.josm.plugins.streetside.gui.StreetsidePreferenceSetting;
    021import org.openstreetmap.josm.plugins.streetside.gui.StreetsideViewerDialog;
    022import org.openstreetmap.josm.plugins.streetside.gui.imageinfo.ImageInfoHelpPopup;
    023import org.openstreetmap.josm.plugins.streetside.gui.imageinfo.ImageInfoPanel;
    024import org.openstreetmap.josm.plugins.streetside.oauth.StreetsideUser;
    025import org.openstreetmap.josm.plugins.streetside.utils.StreetsideProperties;
    026import org.openstreetmap.josm.tools.ImageProvider;
    027
    028/**
    029 * This is the main class of the Streetside plugin.
    030 */
    031public class StreetsidePlugin extends Plugin {
    032
    033  public static final ImageProvider LOGO = new ImageProvider("streetside-logo");
    034
    035  /** Zoom action */
    036  private static final StreetsideZoomAction ZOOM_ACTION = new StreetsideZoomAction();
    037  /** Walk action */
    038  private static final StreetsideWalkAction WALK_ACTION = new StreetsideWalkAction();
    039  /** Upload action */
    040  //private static final StreetsideUploadAction UPLOAD_ACTION = new StreetsideUploadAction();
    041
    042  static {
    043    if (Main.main != null) {
    044      MainMenu.add(MainApplication.getMenu().fileMenu, new StreetsideExportAction(), false, 14);
    045      MainMenu.add(MainApplication.getMenu().imagerySubMenu, new StreetsideDownloadAction(), false);
    046      MainMenu.add(MainApplication.getMenu().viewMenu, ZOOM_ACTION, false, 15);
    047      MainMenu.add(MainApplication.getMenu().fileMenu, new StreetsideDownloadViewAction(), false, 14);
    048      MainMenu.add(MainApplication.getMenu().dataMenu, new StreetsideJoinAction(), false);
    049      MainMenu.add(MainApplication.getMenu().moreToolsMenu, WALK_ACTION, false);
    050      //MainMenu.add(MainApplication.getMenu().imagerySubMenu, new MapObjectLayerAction(), false);
    051      //MainMenu.add(MainApplication.getMenu().imagerySubMenu, new MapObjectLayerAction(), false);
    052    }
    053  }
    054
    055  /**
    056   * Main constructor.
    057   *
    058   * @param info
    059   *          Required information of the plugin. Obtained from the jar file.
    060   */
    061  public StreetsidePlugin(PluginInformation info) {
    062    super(info);
    063
    064    if (StreetsideProperties.ACCESS_TOKEN.get() == null) {
    065      StreetsideUser.setTokenValid(false);
    066    }
    067  }
    068
    069  static StreetsideDataListener[] getStreetsideDataListeners() {
    070        return new StreetsideDataListener[]{WALK_ACTION, ZOOM_ACTION, CubemapBuilder.getInstance()};
    071  }
    072
    073
    074  /**
    075   * @return the {@link StreetsideWalkAction} for the plugin
    076   */
    077  public static StreetsideWalkAction getStreetsideWalkAction() {
    078    return WALK_ACTION;
    079  }
    080
    081  /**
    082   * Called when the JOSM map frame is created or destroyed.
    083   */
    084  @Override
    085  public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {
    086    if (oldFrame == null && newFrame != null) { // map frame added
    087      MainApplication.getMap().addToggleDialog(StreetsideMainDialog.getInstance(), false);
    088      StreetsideMainDialog.getInstance().setImageInfoHelp(new ImageInfoHelpPopup(
    089          MainApplication.getMap().addToggleDialog(ImageInfoPanel.getInstance(), false)
    090      ));
    091      MainApplication.getMap().addToggleDialog(StreetsideViewerDialog.getInstance(), false);
    092      //MainApplication.getMap().addToggleDialog(StreetsideHistoryDialog.getInstance(), false);
    093      //MainApplication.getMap().addToggleDialog(StreetsideChangesetDialog.getInstance(), false);
    094      //MainApplication.getMap().addToggleDialog(StreetsideFilterDialog.getInstance(), false);
    095    }
    096    if (oldFrame != null && newFrame == null) { // map frame destroyed
    097      StreetsideMainDialog.destroyInstance();
    098      //StreetsideHistoryDialog.destroyInstance();
    099      //StreetsideChangesetDialog.destroyInstance();
    100      //StreetsideFilterDialog.destroyInstance();
    101      ImageInfoPanel.destroyInstance();
    102      CubemapBuilder.destroyInstance();
    103
    104    }
    105  }
    106
    107  @Override
    108  public PreferenceSetting getPreferenceSetting() {
    109    return new StreetsidePreferenceSetting();
    110  }
    111
    112  /**
    113   * @return the current {@link MapView} without throwing a {@link NullPointerException}
    114   */
    115  public static MapView getMapView() {
    116    final MapFrame mf = MainApplication.getMap();
    117    if (mf != null) {
    118      return mf.mapView;
    119    }
    120    return null;
    121  }
    122
    123  /**
    124   * @return the {@link StreetsideUploadAction} for the plugin
    125   */
    126  /*public static StreetsideUploadAction getUploadAction() {
    127    return UPLOAD_ACTION;
    128  }*/
    129
    130  /**
    131   * @return the {@link StreetsideZoomAction} for the plugin
    132   */
    133  /*public static StreetsideZoomAction getZoomAction() {
    134    return ZOOM_ACTION;
    135  }*/
    136  }