コード例 #1
0
ファイル: ImagePanel.java プロジェクト: nbbrooks/sami-crw
 private void rateSStateChanged(
     javax.swing.event.ChangeEvent evt) { // GEN-FIRST:event_rateSStateChanged
   if (Engine.getInstance().getProxyServer() instanceof CrwProxyServer) {
     CrwProxyServer server = (CrwProxyServer) Engine.getInstance().getProxyServer();
     if (!rateS.getModel().getValueIsAdjusting()) {
       server.setCameraRates((double) rateS.getValue());
     }
   }
 } // GEN-LAST:event_rateSStateChanged
コード例 #2
0
  @Override
  public void invoke(final OutputEvent oe, ArrayList<Token> tokens) {
    LOGGER.log(Level.FINE, "CoreEventHandler invoked with " + oe);
    if (oe instanceof AbortMission) {
      for (Token token : tokens) {
        if (token.getProxy() != null) {
          token.getProxy().abortMission(oe.getMissionId());
        }
      }
    } else if (oe instanceof CompleteMission) {
      for (Token token : tokens) {
        if (token.getProxy() != null) {
          token.getProxy().completeMission(oe.getMissionId());
        }
      }
    } else if (oe instanceof SendProxyAbortAllMissions) {
      for (Token token : tokens) {
        if (token.getProxy() != null) {
          // Add proxy that will be aborting the missions
          ArrayList<ProxyInt> relevantProxies = new ArrayList<ProxyInt>();
          relevantProxies.add(token.getProxy());
          // Get list of all mission ids proxy is involved in
          ArrayList<UUID> missionIds = new ArrayList<UUID>();
          ArrayList<OutputEvent> outputEvents = token.getProxy().getEvents();
          for (OutputEvent proxyOe : outputEvents) {
            if (!missionIds.contains(proxyOe.getMissionId())) {
              missionIds.add(proxyOe.getMissionId());
            }
          }
          // Send proxy abort mission for each mission
          for (UUID missionId : missionIds) {
            ProxyAbortMissionReceived pamr =
                new ProxyAbortMissionReceived(missionId, relevantProxies);
            ArrayList<GeneratedEventListenerInt> listenersCopy =
                (ArrayList<GeneratedEventListenerInt>) listeners.clone();
            for (GeneratedEventListenerInt listener : listenersCopy) {
              listener.eventGenerated(pamr);
            }
          }
        }
      }
    } else if (oe instanceof SendProxyAbortFutureMissions) {
      for (Token token : tokens) {
        if (token.getProxy() != null) {
          // Add proxy that will be aborting the missions
          ArrayList<ProxyInt> relevantProxies = new ArrayList<ProxyInt>();
          relevantProxies.add(token.getProxy());
          // Get list of all mission ids proxy is involved in
          ArrayList<UUID> missionIds = new ArrayList<UUID>();
          ArrayList<OutputEvent> outputEvents = token.getProxy().getEvents();
          for (OutputEvent proxyOe : outputEvents) {
            if (!missionIds.contains(proxyOe.getMissionId())) {
              missionIds.add(proxyOe.getMissionId());
            }
          }
          // Remove current mission from list of missions to be aborted by proxy
          OutputEvent curOe = token.getProxy().getCurrentEvent();
          if (curOe != null) {
            missionIds.remove(curOe);
          }
          // Send proxy abort mission for each mission
          for (UUID missionId : missionIds) {
            ProxyAbortMissionReceived pamr =
                new ProxyAbortMissionReceived(missionId, relevantProxies);
            ArrayList<GeneratedEventListenerInt> listenersCopy =
                (ArrayList<GeneratedEventListenerInt>) listeners.clone();
            for (GeneratedEventListenerInt listener : listenersCopy) {
              listener.eventGenerated(pamr);
            }
          }
        }
      }
    } else if (oe instanceof SendAbortMission) {
      // We will move all tokens out of all places in the plan and be in an end Recovery place
      //  Do nothing (abort mission is handled by PlanManager)
      AbortMissionReceived amr = new AbortMissionReceived(oe.getMissionId());
      ArrayList<GeneratedEventListenerInt> listenersCopy =
          (ArrayList<GeneratedEventListenerInt>) listeners.clone();
      for (GeneratedEventListenerInt listener : listenersCopy) {
        listener.eventGenerated(amr);
      }
    } else if (oe instanceof StartTimer) {
      Timer timer =
          new Timer(
              ((StartTimer) oe).timerDuration * 1000,
              new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent ae) {
                  TimerExpired te = new TimerExpired(oe.getId(), oe.getMissionId());
                  ArrayList<GeneratedEventListenerInt> listenersCopy =
                      (ArrayList<GeneratedEventListenerInt>) listeners.clone();
                  for (GeneratedEventListenerInt listener : listenersCopy) {
                    listener.eventGenerated(te);
                  }
                }
              });
      timer.setRepeats(false);
      timer.start();
    } else if (oe instanceof ReturnValue) {
      ReturnValue returnValue = (ReturnValue) oe;
      PlanManager pm = Engine.getInstance().getPlanManager(returnValue.getMissionId());
      String returnVariableName = pm.getPlanName() + MissionPlanSpecification.RETURN_SUFFIX;
      // Set local scope
      Engine.getInstance().setVariableValue(returnVariableName, returnValue.getReturnValue(), pm);
      // Set in parent's scope
      PlanManager parentPm = Engine.getInstance().getParentPm(pm);
      if (parentPm != null) {
        Engine.getInstance()
            .setVariableValue(returnVariableName, returnValue.getReturnValue(), parentPm);
      } else {
        LOGGER.warning("ReturnValue on event in mission with no parent mission.");
      }
    } else if (oe instanceof RefreshTasks) {
      for (Token token : tokens) {
        if (token.getType() == Token.TokenType.Task) {
          if (token.getTask() != null && token.getProxy() != null) {
            if (token.getProxy().getCurrentTask() == token.getTask()) {
              // Generate task started for every proxy
              ArrayList<ProxyInt> proxyList =
                  Engine.getInstance().getProxyServer().getProxyListClone();
              for (ProxyInt proxy : proxyList) {
                Task currentTask = proxy.getCurrentTask();
                if (currentTask != null) {
                  PlanManager pm = Engine.getInstance().getPlanManager(currentTask);
                  if (pm != null) {
                    pm.eventGenerated(new TaskStarted(pm.missionId, currentTask));
                  } else {
                    LOGGER.severe("No mapping from task to plan manager: " + currentTask);
                  }
                }
              }
            }
          } else if (token.getTask() == null) {
            LOGGER.warning("RefreshTasks activated with task token with a null task: " + token);
          } else {
            LOGGER.warning("RefreshTasks activated with task token with a null proxy: " + token);
          }
        }
      }
    } else if (oe instanceof TaskComplete) {
      for (Token token : tokens) {
        if (token.getType() == Token.TokenType.Task) {
          if (token.getTask() != null && token.getProxy() != null) {
            // Update proxy's task list
            token.getProxy().taskCompleted(token.getTask());
            token.setProxy(null);
            Engine.getInstance().unlinkTask(token.getTask());
          } else if (token.getTask() == null) {
            LOGGER.warning("TaskComplete activated with task token with a null task: " + token);
          } else {
            LOGGER.warning("TaskComplete activated with task token with a null proxy: " + token);
          }
        }
      }
    } else if (oe instanceof GetAllProxyTokens) {
      TokensReturned tr =
          new TokensReturned(oe.getId(), oe.getMissionId(), Engine.getInstance().getAllProxies());
      ArrayList<GeneratedEventListenerInt> listenersCopy =
          (ArrayList<GeneratedEventListenerInt>) listeners.clone();
      for (GeneratedEventListenerInt listener : listenersCopy) {
        listener.eventGenerated(tr);
      }
    }
  }