001 /** 002 * planningtool - A Planning Tool with Critiquing Support. 003 * 004 * Copyright (C) 2006 olale 005 006 * This program is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU General Public License 008 * as published by the Free Software Foundation; either version 2 009 * of the License, or (at your option) any later version. 010 011 * This program is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 016 * You should have received a copy of the GNU General Public License 017 * along with this program; if not, write to the Free Software 018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 019 020 * Contact information: 021 * E-mail: olale@ida.liu.se 022 * olale@lysator.liu.se 023 */ 024 package se.liu.ida.critiquer.constraints; 025 026 import java.awt.Graphics2D; 027 import java.util.ArrayList; 028 import java.util.Calendar; 029 030 import se.liu.ida.critiquer.activities.Activity; 031 import se.liu.ida.critiquer.activities.parameters.Parameter; 032 import se.liu.ida.critiquer.gui.View; 033 import se.liu.ida.critiquer.simulation.AgentSimulationState; 034 import se.liu.ida.critiquer.simulation.DefaultAgentSimulationState; 035 import se.liu.ida.critiquer.simulation.SimulationEngine; 036 037 /** 038 * @author olale 039 * 040 */ 041 public class FuelLowCritic extends SimulationCritic implements TextCritic { 042 043 /** 044 * 045 */ 046 private static final long serialVersionUID = 1L; 047 private SimulationEngine engine; 048 private String information; 049 050 /** 051 * 052 */ 053 public FuelLowCritic() { 054 super(); 055 // TODO Auto-generated constructor stub 056 } 057 058 /* (non-Javadoc) 059 * @see se.liu.ida.critiquer.activities.AbstractParamChangedListener#paramChanged(se.liu.ida.critiquer.activities.Activity, se.liu.ida.critiquer.activities.parameters.Parameter) 060 */ 061 @Override 062 public <T> void paramChanged(Activity activity, Parameter<T> p) { 063 // TODO Auto-generated method stub 064 065 } 066 067 068 /* (non-Javadoc) 069 * @see se.liu.ida.critiquer.simulation.SimulationElement#stepForward(int) 070 */ 071 public void stepForward(int step) { 072 Calendar nextTime = (Calendar) engine.getCurrentTime().clone(); 073 nextTime.add(Calendar.MINUTE, step); 074 stepTo(nextTime); 075 076 } 077 078 /* (non-Javadoc) 079 * @see se.liu.ida.critiquer.simulation.SimulationElement#stepBackward(int) 080 */ 081 public void stepBackward(int step) { 082 Calendar previousTime = (Calendar) engine.getCurrentTime().clone(); 083 previousTime.add(Calendar.MINUTE, step); 084 stepTo(previousTime); 085 } 086 087 /* (non-Javadoc) 088 * @see se.liu.ida.critiquer.simulation.SimulationElement#stepTo(java.util.Calendar) 089 */ 090 public void stepTo(Calendar time) { 091 ArrayList<AgentSimulationState> simulationStates = engine.getAgentSimulationStates(); 092 for (AgentSimulationState state : simulationStates) { 093 Integer fuelLevel = state.getProperty(DefaultAgentSimulationState.FUEL_LEVEL, Integer.class); 094 if (fuelLevel<0) { 095 information="Agent "+state.getAgent()+" has not enough fuel"; 096 setConsistent(false); 097 return; 098 } 099 } 100 setConsistent(true); 101 } 102 103 /* (non-Javadoc) 104 * @see se.liu.ida.critiquer.constraints.SingletonConstraint#getDescription() 105 */ 106 public String getDescription() { 107 return "Displays the fuel status of\n"+ 108 "the various resources\n"+ 109 "during the mission and\n"+ 110 "reacts to low fuel levels"; 111 } 112 113 /* (non-Javadoc) 114 * @see se.liu.ida.critiquer.gui.ViewRenderingListener#viewUpdated(se.liu.ida.critiquer.gui.View, java.awt.Graphics2D) 115 */ 116 public void viewUpdated(View v, Graphics2D g2) { 117 // TODO Auto-generated method stub 118 119 } 120 121 /* (non-Javadoc) 122 * @see se.liu.ida.critiquer.simulation.SimulationElement#initSimulation(se.liu.ida.critiquer.simulation.SimulationEngine) 123 */ 124 public void initSimulation(SimulationEngine engine) { 125 this.engine=engine; 126 127 } 128 129 /* (non-Javadoc) 130 * @see se.liu.ida.critiquer.constraints.TextCritic#getText() 131 */ 132 public String getText() { 133 return information; 134 } 135 136 }