import java.io.IOException; import java.util.Timer; import java.util.TimerTask; import com.esri.arcgis.addins.desktop.ComboBox; import com.esri.arcgis.controls.HookHelper; import com.esri.arcgis.controls.IHookHelper; import com.esri.arcgis.interop.AutomationException; /** * ArcMap Add-in that lets the user specify intervals for the map to refresh. * * @author donahuel * */ public class MapRefreshCBX extends ComboBox{ /** * Called when the combo box is initialized. Subclasses must implement this method * to add entries to the combo box using the add() method. * * @exception java.io.IOException if there are interop problems. * @exception com.esri.arcgis.interop.AutomationException if the component throws an ArcObjects exception. */ @Override public void initialize() { try { manual = add("Manual Map Refresh"); thirty = add("30 seconds"); sixty = add("60 seconds"); ninety = add("90 seconds"); onetwenty = add("120 seconds"); onefifty = add("150 seconds"); oneeighty = add("180 seconds"); twoten = add("210 seconds"); twoforty = add("240 seconds"); twoseventy = add("270 seconds"); threehundred = add("300 seconds"); hookHelper = new HookHelper(); hookHelper.setHookByRef(this.hook.getHook()); timer = new Timer(); select(manual); } catch (AutomationException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } /** * Called by system when the edit box is typed into (if editable) * * @param editString the String typed into the edit box * @exception java.io.IOException if there are interop problems. * @exception com.esri.arcgis.interop.AutomationException if the component throws an ArcObjects exception. */ @Override public void onEditChange(String arg0) throws IOException, AutomationException { } @Override public void onEnter() throws IOException, AutomationException { } /** * Called by system when the combo box gets or loses focus * * @param setFocus - true when combo box gets focus, false when it loses focus * @exception java.io.IOException if there are interop problems. * @exception com.esri.arcgis.interop.AutomationException if the component throws an ArcObjects exception. */ @Override public void onFocus(boolean arg0) throws IOException, AutomationException { } /** * Called by system when a selection changes * * @param cookie the item selected * @exception java.io.IOException if there are interop problems. * @exception com.esri.arcgis.interop.AutomationException if the component throws an ArcObjects exception. */ @Override public void onSelChange(int arg0) throws IOException, AutomationException { isTimerStopped = false; if(arg0 == manual){ timer.cancel(); isTimerStopped = true; } if(arg0 == thirty){ period = 30000; if(isTimerStopped){ } else { timer.cancel(); timer = new Timer(); } } if(arg0 == sixty){ period = 60000; if(isTimerStopped){ } else { timer.cancel(); timer = new Timer(); } } if(arg0 == ninety){ period = 90000; if(isTimerStopped){ } else { timer.cancel(); timer = new Timer(); } } if(arg0 == onetwenty){ period = 120000; if(isTimerStopped){ } else { timer.cancel(); timer = new Timer(); } } if(arg0 == onefifty){ period = 150000; if(isTimerStopped){ } else { timer.cancel(); timer = new Timer(); } } if(arg0 == oneeighty){ period = 180000; if(isTimerStopped){ } else { timer.cancel(); timer = new Timer(); } } if(arg0 == twoten){ period = 210000; if(isTimerStopped){ } else { timer.cancel(); timer = new Timer(); } } if(arg0 == twoforty){ period = 240000; if(isTimerStopped){ } else { timer.cancel(); timer = new Timer(); } } if(arg0 == twoseventy){ period = 270000; if(isTimerStopped){ } else { timer.cancel(); timer = new Timer(); } } if(arg0 == threehundred){ period = 300000; if(isTimerStopped){ } else { timer.cancel(); timer = new Timer(); } } if(isTimerStopped){ // don't schedule anything because it will log an error saying the timer is already stopped } else { timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { try { hookHelper.getActiveView().refresh(); } catch (AutomationException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }, delay, period); } } private int manual; private int thirty; private int sixty; private int ninety; private int onetwenty; private int onefifty; private int oneeighty; private int twoten; private int twoforty; private int twoseventy; private int threehundred; private Timer timer; private int delay = 0; private int period; private boolean isTimerStopped; private IHookHelper hookHelper; }
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.