Skip to content

Commit

Permalink
Merge branch 'master' of ssh://etatara@repast.git.sourceforge.net/git…
Browse files Browse the repository at this point in the history
…root/repast/repast.simphony
  • Loading branch information
etatara committed Feb 27, 2012
2 parents 43e846c + fe32694 commit 4d1b8d8
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
@SuppressWarnings("serial")
public class BatchUpdateXYSeries extends XYSeriesCollection {

private static long UPDATE_INTERVAL = 17;

private boolean update = true;
private long lastUpdate = 0;

private volatile boolean running = false;;

public void setUpdate(boolean update) {
this.update = update;
Expand All @@ -34,6 +39,26 @@ protected void notifyListeners(DatasetChangeEvent evt) {
* Notifies listeners that
*/
public void update() {
super.notifyListeners(new DatasetChangeEvent(this, this));
long ts = System.currentTimeMillis();
if (!running || ts - lastUpdate > UPDATE_INTERVAL) {
super.notifyListeners(new DatasetChangeEvent(this, this));
lastUpdate = ts;
}
}

/**
* @return the running
*/
public boolean isRunning() {
return running;
}

/**
* Tells this BatchUpdateXYSeries whether the sim is running or not.
*
* @param running
*/
public void setRunning(boolean running) {
this.running = running;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
package repast.simphony.chart2;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -55,32 +56,30 @@ protected static class SeriesData {

private class Updater implements Runnable {

private SeriesData data = new SeriesData();
private List<SeriesData> data = new ArrayList<SeriesData>();

public Updater(SeriesData other) {
data.key = other.key;
data.val = other.val;
data.tick = other.tick;
data.addSeries = other.addSeries;
public Updater(List<SeriesData> data) {
this.data.addAll(data);
}

public void run() {
xydata.setUpdate(false);
if (data.addSeries) {
xydata.addSeries(new XYSeries(data.key));
for (SeriesData datum : data) {
if (datum.addSeries) {
xydata.addSeries(new XYSeries(datum.key));
}
xydata.getSeries(datum.key).add(datum.tick, datum.val);
}
xydata.getSeries(data.key).add(data.tick, data.val);


xydata.setUpdate(true);
xydata.update();

// System.out.printf("key: %s, val: %f, tick: %f%n", data.key, data.val,
// data.tick);
}

}

private String dsSeriesKey, dataValueSourceId;
private SeriesData data = new SeriesData();
private List<SeriesData> allData = new ArrayList<SeriesData>();
private SeriesData data;
private Set<String> addedSeries = new HashSet<String>();
private DataConverter converter = new InitDataConverter();

Expand Down Expand Up @@ -119,6 +118,8 @@ public void open(List<String> sourceIds) {
*/
@Override
public void rowStarted() {
data = new SeriesData();
allData.add(data);
}

/*
Expand All @@ -145,18 +146,27 @@ else if (key.equals(dsSeriesKey)) {
/*
* (non-Javadoc)
*
* @see projz.data.DataSink#rowEnded()
* @see projz.data.DataSink#recordEnded()
*/
@Override
public void rowEnded() {
public void recordEnded() {
// we need to update on the AWT thread.
if (SwingUtilities.isEventDispatchThread())
new Updater(data).run();
new Updater(allData).run();
else
// this makes a copy of the row, so
// it is OK to clear it
SwingUtilities.invokeLater(new Updater(data));
data.addSeries = false;
SwingUtilities.invokeLater(new Updater(allData));
allData.clear();
}

/*
* (non-Javadoc)
*
* @see projz.data.DataSink#rowEnded()
*/
@Override
public void rowEnded() {
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,11 @@ public String getSeriesLabel(String seriesId) {
*
* @param seriesId
*
* @return the color of the specified series.
* @return the color of the specified series, or null if there
* is no color.
*/
public Color getSeriesColor(String seriesId) {
return seriesIds.get(seriesId).color;
SeriesData data = seriesIds.get(seriesId);
return data == null ? null : data.color;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import repast.simphony.engine.controller.DescriptorControllerAction;
import repast.simphony.engine.environment.DefaultControllerAction;
import repast.simphony.engine.environment.GUIRegistryType;
import repast.simphony.engine.environment.RunListener;
import repast.simphony.engine.environment.RunState;
import simphony.util.messages.MessageCenter;

Expand All @@ -25,13 +26,15 @@
* @author Nick Collier
*/
public class TimeSeriesComponentControllerAction extends DefaultControllerAction implements
DescriptorControllerAction<TimeSeriesChartDescriptor> {
DescriptorControllerAction<TimeSeriesChartDescriptor>, RunListener {

private static MessageCenter msgCenter = MessageCenter
.getMessageCenter(TimeSeriesComponentControllerAction.class);

private TimeSeriesChartDescriptor descriptor;
private LineChartCreator chartCreator;
private BatchUpdateXYSeries chartData;
private boolean added = false;

public TimeSeriesComponentControllerAction(TimeSeriesChartDescriptor descriptor) {
this.descriptor = descriptor;
Expand Down Expand Up @@ -69,7 +72,7 @@ public void batchInitialize(RunState runState, Object contextId) {
}

// create a chart data sink to feed data from the dataset to the chart.
BatchUpdateXYSeries chartData = new BatchUpdateXYSeries();
chartData = new BatchUpdateXYSeries();
List<String> sourceIds = descriptor.getSeriesIds();
if (builder.isAggregate()) {
XYDataSinkSourceSeries sink = new XYDataSinkSourceSeries(chartData, sourceIds);
Expand All @@ -86,6 +89,10 @@ public void batchInitialize(RunState runState, Object contextId) {
builder.addDataSink(sink);
}

if (!added) {
runState.getScheduleRegistry().getScheduleRunner().addRunListener(this);
added = true;
}
chartCreator = new LineChartCreator(chartData);
runState.getGUIRegistry().addComponent(chartCreator.createChartComponent(descriptor),
GUIRegistryType.CHART, descriptor.getChartTitle());
Expand All @@ -101,5 +108,38 @@ public void batchInitialize(RunState runState, Object contextId) {
@Override
public void runCleanup(RunState runState, Object contextId) {
chartCreator.reset();
chartData = null;
}

/* (non-Javadoc)
* @see repast.simphony.engine.environment.RunListener#stopped()
*/
@Override
public void stopped() {
if (chartData != null) chartData.setRunning(false);
}

/* (non-Javadoc)
* @see repast.simphony.engine.environment.RunListener#paused()
*/
@Override
public void paused() {
if (chartData != null) chartData.setRunning(false);
}

/* (non-Javadoc)
* @see repast.simphony.engine.environment.RunListener#started()
*/
@Override
public void started() {
if (chartData != null) chartData.setRunning(true);
}

/* (non-Javadoc)
* @see repast.simphony.engine.environment.RunListener#restarted()
*/
@Override
public void restarted() {
if (chartData != null) chartData.setRunning(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class ButtonCoordinator {

private long lastTLUpdate = 0;
private JLabel tickCountLabel;
private String lastTick = "";

private class TLUpdater implements Runnable {
private String text;
Expand Down Expand Up @@ -197,10 +198,15 @@ public void init(GUIBarManager config) {
ActionFactory.getInstance().getAction(RSGUIConstants.SAVE_DEFAULT_LAYOUT_ACTION)
.setEnabled(false);
}

public void updateTickCountLabel() {
if (lastTick.length() > 0) ThreadUtilities.runInEventThread(new TLUpdater(lastTick));
}

public void updateTickCountLabel(String val) {
// only update every Xth of a second so we don't flood
// the event queue
lastTick = val;
long ts = System.currentTimeMillis();
if (ts - lastTLUpdate > TICK_LABEL_UPDATE_INTERVAL) {
ThreadUtilities.runInEventThread(new TLUpdater(val));
Expand Down
2 changes: 2 additions & 0 deletions repast.simphony.gui/src/repast/simphony/ui/RSGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,7 @@ public void setGUIForStepped() {

public void setGUIForPaused() {
running = false;
buttonCoordinator.updateTickCountLabel();
buttonCoordinator.setGUIForPaused(dockingManager.getBarManager());
for (JComponent comp : compsToDisable) {
comp.setEnabled(true);
Expand All @@ -670,6 +671,7 @@ public void setGUIForPaused() {

public void setGUIForStopped() {
running = false;
buttonCoordinator.updateTickCountLabel();
buttonCoordinator.setGUIForStopped(dockingManager.getBarManager());
tree.setEnabled(true);
for (JComponent comp : compsToDisable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import repast.simphony.context.Context;
import repast.simphony.relogo.factories.LinkFactory;
import repast.simphony.space.continuous.NdPoint;
import repast.simphony.space.graph.Network;
import repast.simphony.space.grid.GridPoint;
import repast.simphony.ui.probe.ProbeID;

Expand Down Expand Up @@ -498,9 +499,23 @@ public AgentSet bothEnds() {
* Removes the link.
*/
public void die() {
myObserver.getContext().remove(this);
myObserver.getNetwork(getLinkType()).removeEdge(this);
}
myObserver.getContext().remove(this);
Network n1 = myObserver.getNetwork(getLinkType());
if (n1.containsEdge(this)){
n1.removeEdge(this);
}
else {
List<Network> networks = new ArrayList<Network>();
networks.add(myObserver.getNetwork("DirectedLinks"));
networks.add(myObserver.getNetwork("UndirectedLinks"));
for (Network n : networks){
if (n.containsEdge(this)){
n.removeEdge(this);
break;
}
}
}
}

/**
* Returns the heading of a link.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ public void prepare() {
unorderedTarget.add(new AgentData(className));
}
}

Collections.sort(orders);
for (int i : orders)
target.add(i, orderedMap.get(i));
Expand All @@ -166,7 +167,7 @@ public void prepare() {
Collections.reverse(target);

// append the unordered layers to the end of the ordered list.
// target.addAll(unorderedTarget);
target.addAll(unorderedTarget);

// the list of all agents available to the runtime.
List<AgentData> source = model.getContext().getAgentData(true);
Expand Down

0 comments on commit 4d1b8d8

Please sign in to comment.