Unverified Commit 342fea6f authored by Juon Kawakami's avatar Juon Kawakami 🥗
Browse files

init

parent 54f6cedf
/*
* Last change: $Date: 2004/05/04 03:09:38 $
* $Revision: 1.3 $
*
* Copyright (c) 2004, The Black Sheep, Department of Computer Science, The University of Auckland
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of The Black Sheep, The Department of Computer Science or The University of Auckland nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package rescuecore.debug;
import rescuecore.*;
import rescuecore.event.*;
public class DebugMemoryListener implements MemoryListener {
private RescueComponent component;
public DebugMemoryListener(RescueComponent component){
this.component = component;
}
public void objectAdded(ObjectAddedEvent event){
RescueObject object = event.getObject();
int time = event.getTimestamp();
DebugWriter.logObjectAdded(component,object,time);
}
public void objectChanged(ObjectChangedEvent event){
RescueObject object = event.getObject();
int timeStamp = event.getTimestamp();
int property = event.getProperty();
Property p = object.getProperty(property);
DebugWriter.logObjectChanged(component,object,p,timeStamp);
/*
if (p instanceof IntProperty) {
int value = ((IntProperty)p).getValue();
}
if (p instanceof ArrayProperty) {
int[] values = ((ArrayProperty)p).getValues();
DebugWriter.log(component,new DebugEntry.ArrayPropertyUpdateEntry(object.getID(),property,values,timeStamp));
}
*/
}
}
/*
* Last change: $Date: 2005/03/17 06:07:12 $
* $Revision: 1.10 $
*
* Copyright (c) 2004, The Black Sheep, Department of Computer Science, The University of Auckland
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of The Black Sheep, The Department of Computer Science or The University of Auckland nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package rescuecore.debug;
import rescuecore.*;
import rescuecore.view.*;
import rescuecore.objects.*;
import javax.swing.*;
import java.awt.*;
import java.util.*;
public class DebugPane extends JPanel{
private DebugLog log;
private String name;
private Memory memory;
protected JTabbedPane tabs;
private int timeStep;
private rescuecore.view.Map map;
private Layer moveHistory;
private ArrayList<Handler> handlers;
private JPanel handlerPanel;
public static final int HANDLER_WIDTH = 200;
int height = 0;
public DebugPane(DebugLog log, String name){
super(new BorderLayout());
this.log = log;
this.name = name;
ObjectInspector inspector = new ObjectInspector();
memory = new HashMemory();
setName(name);
map = new rescuecore.view.Map(memory);
ObjectSelector selector = new ObjectSelector(map);
map.addMouseListener(selector);
selector.addObjectSelectionListener(inspector);
add(map,BorderLayout.CENTER);
map.addLayer(Layer.createBuildingLayer(memory));
map.addLayer(Layer.createRoadLayer(memory));
map.addLayer(Layer.createNodeLayer(memory));
map.addLayer(Layer.createHumanoidLayer(memory));
moveHistory = new Layer("Movement History");
moveHistory.addRenderer(RescueObject[].class,OutlineRenderer.YELLOW);
map.addLayer(moveHistory);
handlerPanel = new JPanel();
handlerPanel.setLayout(new BoxLayout(handlerPanel,BoxLayout.Y_AXIS));
JScrollPane sp = new JScrollPane(inspector,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
sp.setPreferredSize(new Dimension(HANDLER_WIDTH,200));
handlerPanel.add(sp);
add(new JScrollPane(handlerPanel,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS),BorderLayout.EAST);
handlers = new ArrayList<Handler>(10);
}
public void registerHandler(Handler h){
h.setMemory(memory);
handlers.add(h);
JComponent comp = h.getComponent();
if(comp != null){
handlerPanel.add(comp);
height += (int)comp.getPreferredSize().getHeight();
handlerPanel.setPreferredSize(new Dimension(HANDLER_WIDTH+10,height));
}
Layer lay = h.getLayer();
if(lay != null)
map.addLayer(lay);
}
protected void moveToTimeStep(int timeStep){
memory = new HashMemory();
for (int i=0;i<=timeStep;++i) {
Collection<DebugEntry> entries = log.getEntriesForTime(name,i);
for (DebugEntry next : entries) {
processEntry(next);
}
}
map.setMemory(memory);
for (Handler next : handlers) next.setMemory(memory);
repaint();
/*
if(timeStep < this.timeStep)
for(int i = this.timeStep; i > timeStep; i--)
log.invertAll(i,memory);
else if(timeStep > this.timeStep)
for(int i = this.timeStep+1; i <= timeStep; i++)
log.applyAll(i,memory);
else{
repaint();
return;
}
this.timeStep = timeStep;
setHistory();
repaint();
*/
}
private void processEntry(DebugEntry entry) {
// FIXME: Nasty nasty nasty! This sort of thing should really be in class DebugEntry.
if (entry instanceof DebugEntry.RescueObjectEntry) {
RescueObject object = ((DebugEntry.RescueObjectEntry)entry).getObject();
memory.add(object.copy(),entry.getTimestep());
}
else if (entry instanceof DebugEntry.RescueObjectCollectionEntry) {
Collection<RescueObject> objects = ((DebugEntry.RescueObjectCollectionEntry)entry).getObjects();
for (RescueObject next : objects) {
memory.add(next.copy(),entry.getTimestep());
}
}
else if (entry instanceof DebugEntry.IntPropertyUpdateEntry) {
int property = ((DebugEntry.IntPropertyUpdateEntry)entry).getProperty();
int value = ((DebugEntry.IntPropertyUpdateEntry)entry).getNewValue();
int id = ((DebugEntry.IntPropertyUpdateEntry)entry).getObjectID();
RescueObject o = memory.lookup(id);
if (o!=null) {
Property p = o.getProperty(property);
if (p instanceof IntProperty) {
((IntProperty)p).setValue(value,entry.getTimestep(),null);
}
}
}
else if (entry instanceof DebugEntry.ArrayPropertyUpdateEntry) {
int property = ((DebugEntry.ArrayPropertyUpdateEntry)entry).getProperty();
int[] value = ((DebugEntry.ArrayPropertyUpdateEntry)entry).getNewValue();
int id = ((DebugEntry.ArrayPropertyUpdateEntry)entry).getObjectID();
RescueObject o = memory.lookup(id);
if (o!=null) {
Property p = o.getProperty(property);
if (p instanceof ArrayProperty) {
((ArrayProperty)p).setValues(value,entry.getTimestep(),null);
}
}
}
else if (entry instanceof DebugEntry.ObjectDebugEntry) {
Object obj = ((DebugEntry.ObjectDebugEntry)entry).getObject();
for(int j = handlers.size()-1; j >= 0; j--){
Handler h = (Handler)handlers.get(j);
if(h.handle(obj,entry.getTimestep()))
break;
}
}
}
/*
protected RescueObject getAgent(){
return memory.lookup(log.getID());
}
*/
/*
protected void processObjects(){
ArrayList objects = log.getObjects(timeStep);
for(int i = 0; i < objects.size(); i++){
Object obj = objects.get(i);
for(int j = handlers.size()-1; j >= 0; j--){
Handler h = (Handler)handlers.get(j);
if(h.handle(obj,timeStep))
break;
}
}
doLayout();
}
protected void setHistory(){
if(!getAgent().isHumanoid())
return;
int[] hist = ((Humanoid)getAgent()).getPositionHistory();
moveHistory.removeAllObjects();
if(hist.length > 0){
RescueObject[] rs = new RescueObject[hist.length];
rs[0] = memory.lookup(hist[0]);
for (int i=1;i<rs.length;++i){
rs[i] = memory.lookup(hist[i]);
//if(rs[i-1].isNode() || i==1)
moveHistory.addObject(new RescueObject[]{rs[i-1],rs[i]});
}
}
}
*/
}
package rescuecore.debug;
import java.util.*;
import java.io.*;
import rescuecore.*;
public class DebugWriter {
// private static Map<RescueComponent,List<DebugEntry>> componentToEntries = new HashMap<RescueComponent,List<DebugEntry>>();
private static Map<RescueComponent,DebugTarget> componentTargets = new HashMap<RescueComponent,DebugTarget>();
private static Map<RescueComponent,String> componentNames = new HashMap<RescueComponent,String>();
private static Map<String,DebugTarget> targets = new HashMap<String,DebugTarget>();
public static void register(RescueComponent component,String name, String targetName) {
DebugTarget target = createTarget(targetName);
if (target!=null) {
componentTargets.put(component,target);
// componentToEntries.put(component,new ArrayList<DebugEntry>());
componentNames.put(component,name);
}
}
public static void logInitialObjects(RescueComponent component, Collection<RescueObject> objects) {
log(component,new DebugEntry.RescueObjectCollectionEntry(objects,0));
}
public static void logObjectAdded(RescueComponent component, RescueObject o, int time) {
log(component,new DebugEntry.RescueObjectEntry(o,time));
}
public static void logObjectChanged(RescueComponent component, RescueObject o, Property p, int time) {
if (p instanceof IntProperty) {
log(component,new DebugEntry.IntPropertyUpdateEntry(o.getID(),p.getType(),((IntProperty)p).getValue(),time));
}
if (p instanceof ArrayProperty) {
log(component,new DebugEntry.ArrayPropertyUpdateEntry(o.getID(),p.getType(),((ArrayProperty)p).getValues(),time));
}
}
public static void logUserObject(RescueComponent component, Object o, int time) {
log(component,new DebugEntry.ObjectDebugEntry(o,time));
}
private static void log(RescueComponent component, DebugEntry entry) {
DebugTarget target = componentTargets.get(component);
String name = componentNames.get(component);
if (target==null) System.err.println("WARNING: Unregistered component tried to log something: "+component);
else {
synchronized(target) {
try {
target.write(name,entry);
}
catch (IOException e) {
e.printStackTrace();
}
}
}
}
public static void flush(RescueComponent component) {
DebugTarget target = componentTargets.get(component);
if (target!=null) {
synchronized(target) {
try {
target.flush();
}
catch (IOException e) {
e.printStackTrace();
}
}
}
}
public static void flushAll() {
for (RescueComponent next : componentTargets.keySet()) {
flush(next);
}
}
private static DebugTarget createTarget(String target) {
DebugTarget result = targets.get(target);
if (result==null) {
try {
result = new FileDebugTarget(target);
targets.put(target,result);
}
catch (IOException e) {
System.err.println("ERROR: Could not create debug target: "+e);
return null;
}
}
return result;
}
private abstract static class DebugTarget {
public abstract void write(String owner, DebugEntry entry) throws IOException;
public abstract void flush() throws IOException;
public abstract void close() throws IOException;
}
private static class FileDebugTarget extends DebugTarget {
private ObjectOutputStream out;
public FileDebugTarget(String fileName) throws IOException {
out = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(fileName)));
}
public void write(String owner, DebugEntry entry) throws IOException {
out.writeUTF(owner);
out.writeObject(entry);
}
public void flush() throws IOException {
out.flush();
}
public void close() throws IOException {
out.close();
out = null;
}
}
}
/*
* Last change: $Date: 2004/05/31 01:56:13 $ $Revision: 1.6 $ Copyright (c)
* 2004, The Black Sheep, Department of Computer Science, The University of
* Auckland All rights reserved. Redistribution and use in source and binary
* forms, with or without modification, are permitted provided that the
* following conditions are met: Redistributions of source code must retain the
* above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. Neither the name of
* The Black Sheep, The Department of Computer Science or The University of
* Auckland nor the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package rescuecore.debug;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.JTabbedPane;
import javax.swing.border.Border;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
public class Debugger extends JPanel {
private Collection<DebugPane> panes;
// private WorldLog log;
private DebugLog log;
private JTabbedPane tabs;
private JSlider time;
public Debugger() {
super(new BorderLayout());
tabs = new JTabbedPane(JTabbedPane.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);
// lower panel
JPanel bottom = new JPanel();
JPanel timePanel = new JPanel(new BorderLayout());
Border b = BorderFactory.createLineBorder(Color.BLACK);
b = BorderFactory.createTitledBorder(b, "Time Step");
timePanel.setBorder(b);
time = new JSlider(0, 300, 0);
time.setPaintLabels(true);
time.setPaintTicks(true);
time.setSnapToTicks(true);
time.setMinorTickSpacing(1);
time.setMajorTickSpacing(50);
JButton left = new JButton(" < ");
JButton right = new JButton(" > ");
left.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
moveTime(-1);
}
});
right.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
moveTime(1);
}
});
time.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
setTimeStep(time.getValue());
}
});
timePanel.add(time, BorderLayout.CENTER);
timePanel.add(left, BorderLayout.WEST);
timePanel.add(right, BorderLayout.EAST);
add(tabs, BorderLayout.CENTER);
add(timePanel, BorderLayout.SOUTH);
}
public void init(File file) throws IOException, ClassNotFoundException {
// log = new WorldLog(file);
log = new DebugLog(file);
// Create one tab per rescue component
tabs.removeAll();
// AgentLog[] aLogs = log.getAgentLogs();
Collection<String> names = log.getAllNames();
panes = new ArrayList<DebugPane>(names.size());
for (String next : names) {
DebugPane pane = makeDebugPane(next, log);
panes.add(pane);
tabs.add(pane);
}
try {
registerHandler(CommandHandler.class);
registerHandler(StringHandler.class);
registerHandler(UpdateHandler.class);
} catch (Exception e) {
// Should never happen
e.printStackTrace();
}
time.setMaximum(log.getMaxTimestep());
setTimeStep(0);
}
public int getTimeStep() {
return time.getValue();
}
public void registerHandler(String className) throws ClassNotFoundException, InstantiationException,
IllegalAccessException, InvocationTargetException, NoSuchMethodException {
registerHandler(Class.forName(className));
}
public void registerHandler(Class clazz)
throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
for (DebugPane next : panes) {
Handler hand = (Handler) clazz.getDeclaredConstructor().newInstance();
next.registerHandler(hand);
}
}
@Deprecated
public void registerHandler(Handler h) {
try {
registerHandler(h.getClass());
} catch (Exception e) {
e.printStackTrace();
}
}
private void moveTime(int change) {
time.setValue(time.getValue() + change);
}
public DebugPane makeDebugPane(String name, DebugLog log) {
return new DebugPane(log, name);
}
private void setTimeStep(int time) {
for (DebugPane next : panes) {
next.moveToTimeStep(time);
}
}
public static void main(String[] args) {
Debugger d = null;
String fileName = null;
Collection handlers = new ArrayList();
for (int i = 0; i < args.length; ++i) {
if (args[i].equalsIgnoreCase("-h") || args[i].equalsIgnoreCase("--help")) {
printUsage();
return;
} else if (fileName == null)
fileName = args[i];
else {
// Is this a file?
File f = new File(args[i]);
if (f.exists()) {
String nextClass = null;
try {
BufferedReader in = new BufferedReader(new FileReader(f));
nextClass = in.readLine();
while (nextClass != null) {
if (!nextClass.equals("") && !nextClass.startsWith("#")) {
handlers.add(nextClass);
}
nextClass = in.readLine();
}
} catch (IOException e) {
System.err.println("Error reading file " + args[i] + ": " + e);
}
} else {
handlers.add(args[i]);
}
}
}
d = new Debugger();
File file = null;
try {
if (fileName == null) {
JFileChooser chooser = new JFileChooser();
int returnVal = chooser.showOpenDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
file = chooser.getSelectedFile();
} else
System.exit(0);
} else {
file = new File(fileName);
}
d.init(file);
} catch (Exception e) {
e.printStackTrace();
System.exit(-1);
}
for (Iterator it = handlers.iterator(); it.hasNext();) {
String next = (String) it.next();
try {
d.registerHandler(next);
} catch (Exception e) {
System.err.println("Couldn't register handler " + next + ": " + e);
}
}
JFrame frame = new JFrame("Debugger");
frame.setContentPane(d);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
Toolkit t = Toolkit.getDefaultToolkit();
Dimension size = t.getScreenSize();
frame.setSize((int) size.getWidth(), (int) size.getHeight());
frame.setVisible(true);
}
private static void printUsage() {
System.out.println("Usage: Debugger [options] [filename [handlers]]");
System.out.println(
"Any handlers will be loaded and registered automatically. You can specify handlers as either fully-qualified class names or file names. Each line in each file name should contain the fully-qualified class name of a handler, lines beginning with a # will be ignored");
System.out.println("Options");
System.out.println("-h\t--help\tPrint this message");
}
}
\ No newline at end of file
/*
* Last change: $Date: 2004/05/04 03:09:38 $
* $Revision: 1.2 $
*
* Copyright (c) 2004, The Black Sheep, Department of Computer Science, The University of Auckland
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of The Black Sheep, The Department of Computer Science or The University of Auckland nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package rescuecore.debug;
import java.awt.Color;
import rescuecore.*;
import rescuecore.objects.*;
public class ExtinguishCommand{
private int[] coords;
private Color colour = new Color(0,64,255,160);
public ExtinguishCommand(Building b, Humanoid h, Memory memory) throws CannotFindLocationException {
coords = new int[4];
int[] xy = memory.getXY(memory.lookup(h.getPosition()));
coords[0] = xy[0];
coords[1] = xy[1];
coords[2] = b.getX();
coords[3] = b.getY();
}
public Color getColour(){
return colour;
}
public int[] getCoords(){
return coords;
}
}
/*
* Last change: $Date: 2004/05/04 03:09:38 $
* $Revision: 1.3 $
*
* Copyright (c) 2004, The Black Sheep, Department of Computer Science, The University of Auckland
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of The Black Sheep, The Department of Computer Science or The University of Auckland nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package rescuecore.debug;
import java.awt.*;
import java.awt.geom.*;
import rescuecore.view.*;
import rescuecore.*;
public class ExtinguishCommandRenderer implements MapRenderer {
public boolean canRender(Object o) {
return o instanceof ExtinguishCommand;
}
public Shape render(Object o, Memory memory, Graphics g, ScreenTransform transform) {
ExtinguishCommand ec = (ExtinguishCommand)o;
int[] coords = ec.getCoords();
Shape shape = new Line2D.Double(transform.toScreenX(coords[0]),transform.toScreenY(coords[1]),transform.toScreenX(coords[2]),transform.toScreenY(coords[3]));
shape = new BasicStroke(3).createStrokedShape(shape);
RenderTools.setFillMode(g,ViewConstants.FILL_MODE_SOLID,ec.getColour());
((Graphics2D)g).fill(shape);
return shape;
}
}
/*
* Last change: $Date: 2004/05/04 03:09:38 $
* $Revision: 1.3 $
*
* Copyright (c) 2004, The Black Sheep, Department of Computer Science, The University of Auckland
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of The Black Sheep, The Department of Computer Science or The University of Auckland nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package rescuecore.debug;
import rescuecore.*;
import rescuecore.view.*;
import javax.swing.*;
public interface Handler{
/**
* Called once by the DebugPane when the Handler is registered. This gets
* a JComponent to add to the Debugger that this Handler may write to.
* @return A JComponent to add, or null if no JComponent is used by this Handler.
**/
public JComponent getComponent();
/**
* Gets a Layer for this Handler to draw to.
* @return A Layer to draw on, or null if no Layer is needed by this Handler.
**/
public Layer getLayer();
/**
* Handles the debugging of a transient object.
* @return Whether or not this Handler has dealt with the Object.
**/
public boolean handle(Object o, int timeStep);
/**
* Sets up the Handler on a given memory.
**/
public void setMemory(Memory m);
}
/*
* Last change: $Date: 2004/05/04 03:09:38 $
* $Revision: 1.3 $
*
* Copyright (c) 2004, The Black Sheep, Department of Computer Science, The University of Auckland
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of The Black Sheep, The Department of Computer Science or The University of Auckland nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package rescuecore.debug;
import java.awt.*;
import rescuecore.view.*;
import rescuecore.objects.*;
import rescuecore.*;
public class OutlineRenderer implements MapRenderer {
public static final OutlineRenderer RED = new OutlineRenderer(Color.RED);
public static final OutlineRenderer GREEN = new OutlineRenderer(Color.GREEN);
public static final OutlineRenderer BLUE = new OutlineRenderer(Color.BLUE);
public static final OutlineRenderer ORANGE = new OutlineRenderer(Color.ORANGE);
public static final OutlineRenderer YELLOW = new OutlineRenderer(Color.YELLOW);
public static final OutlineRenderer WHITE = new OutlineRenderer(Color.WHITE);
private Color outline;
private Color fill;
private OutlineRenderer(Color outline){
this.outline = outline;
this.fill = new Color(outline.getRed(),outline.getGreen(),outline.getBlue(),96);
}
public boolean canRender(Object o) {
if (o instanceof RescueObject[] && ((RescueObject[])o).length == 2){
return true;
}
return false;
}
public Shape render(Object o, Memory memory, Graphics g, ScreenTransform transform) {
RescueObject[] rs = (RescueObject[])o;
int x1 = 0;
int y1 = 0;
int x2 = 0;
int y2 = 0;
if(rs[1].isBuilding()){
Building b = (Building)rs[1];
Node n = (Node)rs[0];
x2 = transform.toScreenX(b.getX());
y2 = transform.toScreenY(b.getY());
x1 = transform.toScreenX(n.getX());
y1 = transform.toScreenY(n.getY());
}
else if(rs[0].isBuilding()){
Building b = (Building)rs[0];
Node n = (Node)rs[1];
x2 = transform.toScreenX(b.getX());
y2 = transform.toScreenY(b.getY());
x1 = transform.toScreenX(n.getX());
y1 = transform.toScreenY(n.getY());
}
else if(rs[1].isRoad() || rs[0].isRoad()){
Road r;
if(rs[0].isRoad())
r = (Road)rs[0];
else
r = (Road)rs[1];
Node head = (Node)(memory.lookup(r.getHead()));
Node tail = (Node)(memory.lookup(r.getTail()));
x2 = transform.toScreenX(head.getX());
y2 = transform.toScreenY(head.getY());
x1 = transform.toScreenX(tail.getX());
y1 = transform.toScreenY(tail.getY());
}
else if(rs[0].isNode() && rs[1].isNode()){
Node n1 = (Node)rs[0];
Node n2 = (Node)rs[1];
x2 = transform.toScreenX(n1.getX());
y2 = transform.toScreenY(n1.getY());
x1 = transform.toScreenX(n2.getX());
y1 = transform.toScreenY(n2.getY());
}
else
return new Polygon(new int[0],new int[0],0);
Shape shape = new java.awt.geom.Line2D.Double(x1,y1,x2,y2);
shape = new BasicStroke(6).createStrokedShape(shape);
//RenderTools.setLineMode(g,ViewConstants.LINE_MODE_SOLID,outline);
RenderTools.setFillMode(g,ViewConstants.FILL_MODE_SOLID,fill);
((Graphics2D)g).fill(shape);
return shape;
}
}
/*
* Created on 21/05/2004
*
* To change the template for this generated file go to
* Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
*/
package rescuecore.debug;
import javax.swing.JComponent;
import rescuecore.Memory;
import rescuecore.view.Layer;
import javax.swing.*;
import javax.swing.border.Border;
import java.awt.*;
/**
* @author Jono
*
*/
public class StringHandler implements Handler {
private int timeStep = -1;
private JScrollPane pane;
private JTextArea notes;
/* (non-Javadoc)
* @see rescuecore.debug.Handler#getComponent()
*/
public JComponent getComponent() {
if(pane == null){
JPanel p = new JPanel(new BorderLayout());
Border bord = BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.BLACK),"Notes");
p.setBorder(bord);
notes = new JTextArea(50,10);
p.add(notes,BorderLayout.CENTER);
pane = new JScrollPane(p);
pane.setPreferredSize(new Dimension(DebugPane.HANDLER_WIDTH,200));
}
return pane;
}
/* (non-Javadoc)
* @see rescuecore.debug.Handler#getLayer()
*/
public Layer getLayer() {
return null;
}
/* (non-Javadoc)
* @see rescuecore.debug.Handler#handle(java.lang.Object, int)
*/
public boolean handle(Object o, int timeStep) {
if(this.timeStep != timeStep){
notes.setText("");
this.timeStep = timeStep;
}
if(!(o instanceof String))
return false;
notes.append(o.toString());
notes.append("\n");
return true;
}
/* (non-Javadoc)
* @see rescuecore.debug.Handler#setMemory(rescuecore.Memory)
*/
public void setMemory(Memory m) {}
}
/*
* Last change: $Date: 2004/06/10 01:17:51 $
* $Revision: 1.11 $
*
* Copyright (c) 2004, The Black Sheep, Department of Computer Science, The University of Auckland
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of The Black Sheep, The Department of Computer Science or The University of Auckland nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package rescuecore.debug;
import rescuecore.*;
import rescuecore.objects.*;
import rescuecore.view.*;
import rescuecore.commands.*;
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
public class UpdateHandler implements Handler {
private DefaultListModel messages;
private JScrollPane messagePane;
public UpdateHandler(){
JPanel messagePanel = new JPanel(new BorderLayout());
messagePanel.setBorder(BorderFactory.createTitledBorder("Updates"));
messages = new DefaultListModel();
JList messageList = new JList(messages);
messagePanel.add(messageList,BorderLayout.CENTER);
messagePane = new JScrollPane(messagePanel);
messagePane.setPreferredSize(new Dimension(DebugPane.HANDLER_WIDTH,80));
}
public void setMemory(Memory m){
}
public JComponent getComponent(){
return messagePane;
}
public Layer getLayer(){
return null;
}
public boolean handle(Object o, int timeStep){
int time;
RescueObject[] objects;
if (o instanceof KASense) {
time = ((KASense)o).getTime();
objects = ((KASense)o).getUpdatedObjects();
}
else if (o instanceof Update) {
time = ((Update)o).getTime();
objects = ((Update)o).getUpdatedObjects();
}
else return false;
messages.clear();
for (RescueObject next : objects) {
messages.addElement(next.toString());
int[] known = next.getKnownPropertyTypes();
for (int prop : known) {
if (next.getLastPropertyUpdate(prop)==time) {
messages.addElement(" "+next.getProperty(prop));
}
}
}
return true;
}
}
/*
* Last change: $Date: 2004/05/04 03:09:38 $
* $Revision: 1.2 $
*
* Copyright (c) 2004, The Black Sheep, Department of Computer Science, The University of Auckland
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of The Black Sheep, The Department of Computer Science or The University of Auckland nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package rescuecore.event;
import rescuecore.*;
/**
This class will filter which events get passed to a MemoryListener
*/
public class FilterMemoryListener implements MemoryListener {
private int mode;
private Class clazz;
private int type;
private MemoryListener listener;
public final static int MODE_CLASS = 0;
public final static int MODE_TYPE = 1;
private FilterMemoryListener(int mode, Class clazz, int type, MemoryListener l) {
this.mode = mode;
this.clazz = clazz;
this.type = type;
this.listener = l;
}
/**
Create a new FilterMemoryListener that will only pass on notifications that concern RescueObjects of a particular class
@param clazz The Class we are interested in
@param l The MemoryListener to pass qualifying updates down to
@return A MemoryListener that will filter out all notifications that do not concern RescueObjects of the given class
*/
public static MemoryListener createClassFilter(Class clazz, MemoryListener l) {
return new FilterMemoryListener(MODE_CLASS,clazz,0,l);
}
/**
Create a new FilterMemoryListener that will only pass on notifications that concern RescueObjects of a particular type
@param type The type we are interested in
@param l The MemoryListener to pass qualifying updates down to
@return A MemoryListener that will filter out all notifications that do not concern RescueObjects of the given type
@see RescueConstants#TYPE_CIVILIAN
@see RescueConstants#TYPE_FIRE_BRIGADE
@see RescueConstants#TYPE_AMBULANCE_TEAM
@see RescueConstants#TYPE_POLICE_FORCE
@see RescueConstants#TYPE_ROAD
@see RescueConstants#TYPE_NODE
@see RescueConstants#TYPE_RIVER
@see RescueConstants#TYPE_RIVER_NODE
@see RescueConstants#TYPE_BUILDING
@see RescueConstants#TYPE_REFUGE
@see RescueConstants#TYPE_FIRE_STATION
@see RescueConstants#TYPE_AMBULANCE_CENTER
@see RescueConstants#TYPE_POLICE_OFFICE
@see RescueConstants#TYPE_WORLD
@see RescueConstants#TYPE_CAR
*/
public static MemoryListener createTypeFilter(int type, MemoryListener l) {
return new FilterMemoryListener(MODE_TYPE,null,type,l);
}
public void objectAdded(ObjectAddedEvent event) {
if (filter(event.getObject())) listener.objectAdded(event);
}
public void objectChanged(ObjectChangedEvent event) {
if (filter(event.getObject())) listener.objectChanged(event);
}
private boolean filter(RescueObject o) {
switch(mode) {
case MODE_CLASS:
return (clazz.isInstance(o));
case MODE_TYPE:
return (o.getType()==type);
}
return false;
}
}
/*
* Last change: $Date: 2004/05/04 03:09:38 $
* $Revision: 1.2 $
*
* Copyright (c) 2004, The Black Sheep, Department of Computer Science, The University of Auckland
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of The Black Sheep, The Department of Computer Science or The University of Auckland nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package rescuecore.event;
import rescuecore.*;
public abstract class MemoryEvent extends java.util.EventObject {
private RescueObject object;
private int timestamp;
public final static Object DEFAULT_SOURCE = "No source";
protected MemoryEvent(RescueObject object, int timestamp, Object source) {
super(source==null?DEFAULT_SOURCE:source);
this.object = object;
this.timestamp = timestamp;
}
public RescueObject getObject() {
return object;
}
public int getTimestamp() {
return timestamp;
}
}
/*
* Last change: $Date: 2004/05/04 03:09:38 $
* $Revision: 1.2 $
*
* Copyright (c) 2004, The Black Sheep, Department of Computer Science, The University of Auckland
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of The Black Sheep, The Department of Computer Science or The University of Auckland nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package rescuecore.event;
/**
This interface allows notification of adds/changes to the Memory
@see rescuecore.Memory
*/
public interface MemoryListener {
/**
Notification that an object has been added to the memory
@param event An ObjectAddedEvent describing the change
*/
public void objectAdded(ObjectAddedEvent event);
/**
Notification that an object in the memory has been changed
@param event An ObjectChangedEvent describing the change
*/
public void objectChanged(ObjectChangedEvent event);
}
/*
* Last change: $Date: 2004/05/04 03:09:38 $
* $Revision: 1.2 $
*
* Copyright (c) 2004, The Black Sheep, Department of Computer Science, The University of Auckland
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of The Black Sheep, The Department of Computer Science or The University of Auckland nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package rescuecore.event;
import rescuecore.*;
public class ObjectAddedEvent extends MemoryEvent {
public ObjectAddedEvent(RescueObject object, int timestamp, Object source) {
super(object,timestamp,source);
}
}
/*
* Last change: $Date: 2004/05/04 03:09:38 $
* $Revision: 1.2 $
*
* Copyright (c) 2004, The Black Sheep, Department of Computer Science, The University of Auckland
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of The Black Sheep, The Department of Computer Science or The University of Auckland nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package rescuecore.event;
import rescuecore.*;
public class ObjectChangedEvent extends MemoryEvent {
private int property;
public ObjectChangedEvent(RescueObject object, int property, int timestamp, Object source) {
super(object,timestamp,source);
this.property = property;
}
public ObjectChangedEvent(PropertyChangedEvent event) {
super(event.getObject(),event.getTimestamp(),event.getSource());
this.property = event.getProperty();
}
public int getProperty() {
return property;
}
}
/*
* Last change: $Date: 2004/05/04 03:09:38 $
* $Revision: 1.2 $
*
* Copyright (c) 2004, The Black Sheep, Department of Computer Science, The University of Auckland
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of The Black Sheep, The Department of Computer Science or The University of Auckland nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package rescuecore.event;
import rescuecore.*;
public class PropertyChangedEvent extends MemoryEvent {
private int property;
public PropertyChangedEvent(RescueObject object, int property, int timestamp, Object source) {
super(object,timestamp,source);
this.property = property;
}
public int getProperty() {
return property;
}
}
/*
* Last change: $Date: 2004/05/04 03:09:38 $
* $Revision: 1.2 $
*
* Copyright (c) 2004, The Black Sheep, Department of Computer Science, The University of Auckland
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of The Black Sheep, The Department of Computer Science or The University of Auckland nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package rescuecore.event;
/**
This interface allows notification of changes to the properties of an object
@see rescuecore.RescueObject
@see rescuecore.Property
*/
public interface PropertyListener {
/**
Notification that a property has been changed
@param event A PropertyChangedEvent describing the change
*/
public void propertyChanged(PropertyChangedEvent event);
}
package rescuecore.log;
import java.io.*;
public class ConvertLog {
public static void main(String[] args) {
String inFile = args[0];
String outFile = args[1];
try {
DataInputStream input = new DataInputStream(new BufferedInputStream(new FileInputStream(new File(inFile))));
// Check the header
byte[] preamble = new byte[Log.HEADER_LENGTH];
input.read(preamble,0,preamble.length);
String preambleString = new String(preamble);
if (Log.HEADER_VERSION_0.equals(preambleString)) {
// OK
System.out.println("Original log version 0");
}
else if (Log.HEADER_VERSION_1.equals(preambleString)) {
System.out.println("Original log version 1");
// Read and discard parameters
int length = input.readInt();
input.skip(length);
}
else {
throw new InvalidLogException("Unknown log version: "+preambleString);
}
// Write the header
DataOutputStream out = new DataOutputStream(new FileOutputStream(new File(outFile)));
preamble = Log.HEADER_VERSION_0.getBytes();
out.write(preamble);
byte[] buffer = new byte[1024];
int received = 0;
do {
received = input.read(buffer);
if (received>0) {
out.write(buffer,0,received);
}
} while (received>0);
out.flush();
out.close();
input.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
/*
* Last change: $Date: 2004/05/04 03:09:38 $
* $Revision: 1.2 $
*
* Copyright (c) 2004, The Black Sheep, Department of Computer Science, The University of Auckland
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of The Black Sheep, The Department of Computer Science or The University of Auckland nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package rescuecore.log;
public class InvalidLogException extends Exception {
public InvalidLogException() {super();}
public InvalidLogException(String s) {super(s);}
}
/*
* Last change: $Date: 2005/06/14 21:55:52 $
* $Revision: 1.9 $
*
* Copyright (c) 2004, The Black Sheep, Department of Computer Science, The University of Auckland
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of The Black Sheep, The Department of Computer Science or The University of Auckland nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package rescuecore.log;
import java.io.*;
import java.util.*;
import rescuecore.*;
import rescuecore.commands.*;
public abstract class Log {
public final static String HEADER_VERSION_0 = "RoboCup-Rescue Prototype Log 00\0";
public final static String HEADER_VERSION_1 = "RoboCup-Rescue Prototype Log 01\0";
public final static String HEADER_VERSION_2 = "RoboCup-Rescue Prototype Log 02\0";
public final static int HEADER_LENGTH = HEADER_VERSION_0.length();
public abstract int getMaxTimestep();
public abstract Memory getMemory(int timestep);
public abstract Update getUpdate(int timestep);
public abstract Commands getCommands(int timestep);
public abstract Map<String,String> getConfigValues();
public static Log generateLog(String filename) throws IOException, InvalidLogException {
File file = new File(filename);
DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(file)));
byte[] data = new byte[(int)file.length()];
in.readFully(data);
InputBuffer input = new InputBuffer(data);
// Check the header
byte[] preamble = new byte[HEADER_LENGTH];
input.readBytes(preamble);
String preambleString = new String(preamble);
if (HEADER_VERSION_0.equals(preambleString)) {
throw new InvalidLogException("Log version 0 is no longer supported");
}
else if (HEADER_VERSION_1.equals(preambleString)) {
throw new InvalidLogException("Log version 1 is no longer supported");
}
else if (HEADER_VERSION_2.equals(preambleString)) {
return new LogVersion2(input);
}
else {
throw new InvalidLogException("Unknown log version: "+preambleString);
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment