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