File |
Project |
Line |
nl/tudelft/simulation/dsol/swing/animation/d2/VisualizationPanel.java |
DSOL swing project |
558 |
nl/tudelft/simulation/dsol/web/animation/d2/HtmlGridPanel.java |
DSOL gui project for Web interfaces |
337 |
setExtent(new Bounds2d(minX, minX + w, minY, minY + h));
}
/**
* Added to make sure the recursive render-call calls THIS render method instead of a potential super-class defined
* 'paintComponent' render method.
* @param g Graphics; the graphics object
*/
protected synchronized void drawGrid(final Graphics g)
{
// we prepare the graphics object for the grid
g.setFont(g.getFont().deriveFont(11.0f));
g.setColor(GRIDCOLOR);
double scaleX = this.renderableScale.getXScale(this.extent, this.getSize());
double scaleY = this.renderableScale.getYScale(this.extent, this.getSize());
int count = 0;
int gridSizePixelsX = (int) Math.round(this.gridSizeX / scaleX);
while (gridSizePixelsX < 40)
{
this.gridSizeX = 10 * this.gridSizeX;
int maximumNumberOfDigits = (int) Math.max(0, 1 + Math.ceil(Math.log(1 / this.gridSizeX) / Math.log(10)));
this.formatter.setMaximumFractionDigits(maximumNumberOfDigits);
gridSizePixelsX = (int) Math.round(this.gridSizeX / scaleX);
if (count++ > 10)
{
break;
}
}
count = 0;
while (gridSizePixelsX > 10 * 40)
{
int maximumNumberOfDigits = (int) Math.max(0, 2 + Math.ceil(Math.log(1 / this.gridSizeX) / Math.log(10)));
this.formatter.setMaximumFractionDigits(maximumNumberOfDigits);
this.gridSizeX = this.gridSizeX / 10;
gridSizePixelsX = (int) Math.round(this.gridSizeX / scaleX);
if (count++ > 10)
{
break;
}
}
int gridSizePixelsY = (int) Math.round(this.gridSizeY / scaleY);
while (gridSizePixelsY < 40)
{
this.gridSizeY = 10 * this.gridSizeY;
int maximumNumberOfDigits = (int) Math.max(0, 1 + Math.ceil(Math.log(1 / this.gridSizeY) / Math.log(10)));
this.formatter.setMaximumFractionDigits(maximumNumberOfDigits);
gridSizePixelsY = (int) Math.round(this.gridSizeY / scaleY);
if (count++ > 10)
{
break;
}
}
count = 0;
while (gridSizePixelsY > 10 * 40)
{
int maximumNumberOfDigits = (int) Math.max(0, 2 + Math.ceil(Math.log(1 / this.gridSizeY) / Math.log(10)));
this.formatter.setMaximumFractionDigits(maximumNumberOfDigits);
this.gridSizeY = this.gridSizeY / 10;
gridSizePixelsY = (int) Math.round(this.gridSizeY / scaleY);
if (count++ > 10)
{
break;
}
}
// Let's draw the vertical lines
double mod = this.extent.getMinX() % this.gridSizeX;
int x = (int) -Math.round(mod / scaleX);
while (x < this.getWidth())
{
Point2d point = this.renderableScale.getWorldCoordinates(new Point2D.Double(x, 0), this.extent, this.getSize());
if (point != null)
{
String label = this.formatter.format(Math.round(point.getX() / this.gridSizeX) * this.gridSizeX);
double labelWidth = this.getFontMetrics(this.getFont()).getStringBounds(label, g).getWidth();
if (x > labelWidth + 4)
{
g.drawLine(x, 15, x, this.getHeight());
g.drawString(label, (int) Math.round(x - 0.5 * labelWidth), 11);
}
}
x = x + gridSizePixelsX;
}
// Let's draw the horizontal lines
mod = Math.abs(this.extent.getMinY()) % this.gridSizeY;
int y = (int) Math.round(this.getSize().getHeight() - (mod / scaleY));
while (y > 15)
{
Point2d point = this.renderableScale.getWorldCoordinates(new Point2D.Double(0, y), this.extent, this.getSize());
if (point != null)
{
String label = this.formatter.format(Math.round(point.getY() / this.gridSizeY) * this.gridSizeY);
RectangularShape labelBounds = this.getFontMetrics(this.getFont()).getStringBounds(label, g);
g.drawLine((int) Math.round(labelBounds.getWidth() + 4), y, this.getWidth(), y);
g.drawString(label, 2, (int) Math.round(y + labelBounds.getHeight() * 0.3));
}
y = y - gridSizePixelsY;
}
}
/**
* @return renderableScale
*/
public RenderableScale getRenderableScale() |
File |
Project |
Line |
nl/tudelft/simulation/dsol/web/DsolWebModel.java |
DSOL gui project for Web interfaces |
283 |
nl/tudelft/simulation/dsol/web/DsolWebServer.java |
DSOL gui project for Web interfaces |
342 |
answer = controlButtonResponse(getSimulator() != null, started);
break;
}
case "animate":
{
answer = animationPanel.getDrawingCommands();
break;
}
case "arrowDown":
{
animationPanel.pan(HtmlGridPanel.DOWN, 0.1);
break;
}
case "arrowUp":
{
animationPanel.pan(HtmlGridPanel.UP, 0.1);
break;
}
case "arrowLeft":
{
animationPanel.pan(HtmlGridPanel.LEFT, 0.1);
break;
}
case "arrowRight":
{
animationPanel.pan(HtmlGridPanel.RIGHT, 0.1);
break;
}
case "pan":
{
if (parts.length == 3)
{
// TODO: probably use the animatinPanel.pan()
int dx = Integer.parseInt(parts[1]);
int dy = Integer.parseInt(parts[2]);
double scaleX = animationPanel.getRenderableScale().getXScale(animationPanel.getExtent(),
animationPanel.getSize());
double scaleY = animationPanel.getRenderableScale().getYScale(animationPanel.getExtent(),
animationPanel.getSize());
Bounds2d extent = animationPanel.getExtent();
animationPanel.setExtent(new Bounds2d(extent.getMinX() - dx * scaleX,
extent.getMinX() - dx * scaleX + extent.getDeltaX(), extent.getMinY() + dy * scaleY,
extent.getMinY() + dy * scaleY + extent.getDeltaY()));
}
break;
}
case "introspect":
{
if (parts.length == 3)
{
int x = Integer.parseInt(parts[1]);
int y = Integer.parseInt(parts[2]);
List<Locatable> targets = new ArrayList<Locatable>();
try
{
Point2d point = animationPanel.getRenderableScale().getWorldCoordinates(new Point2D.Double(x, y),
animationPanel.getExtent(), animationPanel.getSize());
for (Renderable2dInterface<?> renderable : animationPanel.getElements())
{
if (animationPanel.isShowElement(renderable)
&& renderable.contains(point, animationPanel.getExtent()))
{
targets.add(renderable.getSource());
}
}
}
catch (Exception exception)
{
this.simulator.getLogger().always().warn(exception, "getSelectedObjects"); |
File |
Project |
Line |
nl/tudelft/simulation/dsol/web/DsolWebModel.java |
DSOL gui project for Web interfaces |
543 |
nl/tudelft/simulation/dsol/web/DsolWebServer.java |
DSOL gui project for Web interfaces |
602 |
setSpeedFactor(speedFactor);
// System.out.println("speed factor changed to " + speedFactor);
}
catch (NumberFormatException exception)
{
answer = "<message>Error: " + exception.getMessage() + "</message>";
}
}
// System.out.println(answer);
response.setContentType("text/xml");
response.setHeader("Cache-Control", "no-cache");
response.setContentLength(answer.length());
response.setStatus(HttpServletResponse.SC_OK);
response.getWriter().write(answer);
response.flushBuffer();
baseRequest.setHandled(true);
}
/**
* @param active boolean; is the simulation active?
* @param started boolean; has the simulation been started?
* @return XML message to send to the server
*/
private String controlButtonResponse(final boolean active, final boolean started)
{
if (!active)
{
return "<controls>\n" + "<oneEventActive>false</oneEventActive>\n" + "<allEventsActive>false</allEventsActive>\n"
+ "<startStop>start</startStop>\n" + "<startStopActive>false</startStopActive>\n"
+ "<resetActive>false</resetActive>\n" + "</controls>\n";
}
if (started)
{
return "<controls>\n" + "<oneEventActive>false</oneEventActive>\n" + "<allEventsActive>false</allEventsActive>\n"
+ "<startStop>stop</startStop>\n" + "<startStopActive>true</startStopActive>\n"
+ "<resetActive>false</resetActive>\n" + "</controls>\n";
}
else
{
return "<controls>\n" + "<oneEventActive>true</oneEventActive>\n" + "<allEventsActive>true</allEventsActive>\n"
+ "<startStop>start</startStop>\n" + "<startStopActive>true</startStopActive>\n"
+ "<resetActive>false</resetActive>\n" + "</controls>\n";
}
}
/**
* Return the toggle button info for the toggle panel.
* @param panel the HtmlAnimationPanel
* @return the String that can be parsed by the select.html iframe
*/
private String getToggles(final HtmlAnimationPanel panel)
{
String ret = "<toggles>\n";
for (ToggleButtonInfo toggle : panel.getToggleButtons())
{
if (toggle instanceof ToggleButtonInfo.Text)
{
ret += "<text>" + toggle.getName() + "</text>\n";
}
else if (toggle instanceof ToggleButtonInfo.LocatableClass)
{
ret += "<class>" + toggle.getName() + "," + toggle.isVisible() + "</class>\n";
}
else if (toggle instanceof ToggleButtonInfo.Gis)
{
ret += "<gis>" + toggle.getName() + "," + ((ToggleButtonInfo.Gis) toggle).getLayerName() + ","
+ toggle.isVisible() + "</gis>\n";
}
}
ret += "</toggles>\n";
return ret;
}
/**
* Returns the simulation speed.
* @param simTime double; simulation time
* @return simulation speed
*/
private double getSimulationSpeed(final double simTime)
{
long now = System.currentTimeMillis();
if (this.lastWallTIme < 0 || this.lastWallTIme == now)
{
this.lastWallTIme = now;
this.prevSimTime = simTime;
return Double.NaN;
}
double speed = (simTime - this.prevSimTime) / (0.001 * (now - this.lastWallTIme));
this.prevSimTime = simTime;
this.lastWallTIme = now;
return speed;
}
} |
File |
Project |
Line |
nl/tudelft/simulation/dsol/web/DsolWebModel.java |
DSOL gui project for Web interfaces |
466 |
nl/tudelft/simulation/dsol/web/DsolWebServer.java |
DSOL gui project for Web interfaces |
525 |
Object simTimeObject = getSimulator().getSimulatorTime();
double simTime = 0.0;
if (simTimeObject instanceof Double)
simTime = (double) simTimeObject;
else if (simTimeObject instanceof Float)
simTime = (float) simTimeObject;
else if (simTimeObject instanceof DoubleScalar)
simTime = ((DoubleScalar<?, ?>) simTimeObject).si;
else if (simTimeObject instanceof FloatScalar)
simTime = ((FloatScalar<?, ?>) simTimeObject).si;
else if (simTimeObject instanceof Calendar)
simTime = ((Calendar) simTimeObject).getTimeInMillis();
double speed = getSimulationSpeed(simTime);
String speedText = "";
if (!Double.isNaN(speed))
{
speedText = String.format("% 5.2fx ", speed);
}
answer = speedText;
break;
}
case "getToggles":
{
answer = getToggles(animationPanel);
break;
}
// we expect something of the form toggle|class|Node|true or toggle|gis|streets|false
case "toggle":
{
if (parts.length != 4)
System.err.println("wrong toggle commmand: " + message);
else
{
String toggleName = parts[1];
boolean gis = parts[2].equals("gis");
boolean show = parts[3].equals("true");
if (gis)
{
if (show)
animationPanel.showGISLayer(toggleName);
else
animationPanel.hideGISLayer(toggleName);
}
else
{
if (show)
animationPanel.showClass(toggleName);
else
animationPanel.hideClass(toggleName);
}
}
break;
}
default:
{
System.err.println("Got unknown message from client: " + command);
answer = "<message>" + request.getParameter("message") + "</message>";
break;
}
}
}
if (request.getParameter("slider") != null)
{
// System.out.println(request.getParameter("slider") + "\n");
try
{
int value = Integer.parseInt(request.getParameter("slider"));
// values range from 100 to 1400. 100 = 0.1, 400 = 1, 1399 = infinite
double speedFactor = 1.0;
if (value > 1398)
speedFactor = Double.MAX_VALUE;
else
speedFactor = Math.pow(2.15444, value / 100.0) / 21.5444; |
File |
Project |
Line |
nl/tudelft/simulation/dsol/animation/gis/esri/EsriRenderable2d.java |
DSOL ESRI Shape File Map Animation |
153 |
nl/tudelft/simulation/dsol/animation/gis/osm/OsmRenderable2d.java |
DSOL OpenStreetMap Animation |
155 |
public EsriRenderable2d getSource()
{
return this;
}
/** {@inheritDoc} */
@Override
public Bounds3d getBounds()
{
return this.bounds;
}
/** {@inheritDoc} */
@Override
public OrientedPoint3d getLocation()
{
return this.location;
}
/**
* @return map the Shapefile map
*/
@Override
public GisMapInterface getMap()
{
return this.map;
}
/**
* caches the GIS map by creating an image. This prevents continuous rendering.
* @throws Exception on graphicsProblems and network connection failures.
*/
private void cacheImage() throws Exception
{
this.cachedImage = new BufferedImage((int) this.map.getImage().getSize().getWidth(),
(int) this.map.getImage().getSize().getHeight(), BufferedImage.TYPE_4BYTE_ABGR);
Graphics2D bg = this.cachedImage.createGraphics();
this.map.drawMap(bg);
bg.dispose();
this.cachedScreenSize = (Dimension) this.map.getImage().getSize().clone();
this.cachedExtent = this.map.getExtent();
this.location = new OrientedPoint3d(this.cachedExtent.midPoint().getX(), this.cachedExtent.midPoint().getY(),
-Double.MIN_VALUE);
this.bounds = new Bounds3d(this.cachedExtent.getDeltaX(), this.cachedExtent.getDeltaY(), 0.0);
}
/**
* destroys an RenderableObject by unsubscribing it from the context.
*/
@Override
public void destroy(final Contextualized contextProvider)
{
try
{
ContextUtil.lookupOrCreateSubContext(contextProvider.getContext(), "animation/2D")
.unbindObject(Integer.toString(System.identityHashCode(this)));
}
catch (Throwable throwable)
{
CategoryLogger.always().warn(throwable, "finalize");
}
}
/** {@inheritDoc} */
@Override
public boolean contains(final Point2d pointWorldCoordinates, final Bounds2d extent)
{
return false;
}
/** {@inheritDoc} */
@Override
public long getId()
{
return -1; // drawn before the rest in case all z-values are the same
}
} |
File |
Project |
Line |
nl/tudelft/simulation/dsol/web/DsolWebModel.java |
DSOL gui project for Web interfaces |
87 |
nl/tudelft/simulation/dsol/web/DsolWebServer.java |
DSOL gui project for Web interfaces |
126 |
}
}
/**
* @return title
*/
public String getTitle()
{
return this.title;
}
/**
* @return simulator
*/
public SimulatorInterface<?> getSimulator()
{
return this.simulator;
}
/**
* @return animationPanel
*/
public HtmlAnimationPanel getAnimationPanel()
{
return this.animationPanel;
}
/**
* Try to start the simulator, and return whether the simulator has been started.
* @return whether the simulator has been started or not
*/
protected boolean startSimulator()
{
if (getSimulator() == null)
{
System.out.println("SIMULATOR == NULL");
return false;
}
try
{
System.out.println("START THE SIMULATOR");
getSimulator().start();
}
catch (SimRuntimeException exception)
{
this.simulator.getLogger().always().warn(exception, "Problem starting Simulator");
}
if (getSimulator().isStartingOrRunning())
{
return true;
}
this.dirtyControls = false; // undo the notification
return false;
}
/**
* Try to stop the simulator, and return whether the simulator has been stopped.
* @return whether the simulator has been stopped or not
*/
protected boolean stopSimulator()
{
if (getSimulator() == null)
{
return true;
}
try
{
System.out.println("STOP THE SIMULATOR");
getSimulator().stop();
}
catch (SimRuntimeException exception)
{
this.simulator.getLogger().always().warn(exception, "Problem stopping Simulator");
}
if (!getSimulator().isStartingOrRunning())
{
return true;
}
this.dirtyControls = false; // undo the notification
return false;
}
/**
* @param speedFactor double; the new speed factor
*/
protected void setSpeedFactor(final double speedFactor)
{
if (this.simulator instanceof DevsRealTimeAnimator)
{
((DevsRealTimeAnimator<?>) this.simulator).setSpeedFactor(speedFactor);
}
}
/** {@inheritDoc} */
@Override
public void notify(final Event event) throws RemoteException
{
if (event.getType().equals(SimulatorInterface.START_EVENT))
{
this.dirtyControls = true;
}
else if (event.getType().equals(SimulatorInterface.STOP_EVENT))
{
this.dirtyControls = true;
}
}
/**
* Delegate handle method from the main web server for this particular model.
* @param target t
* @param baseRequest br
* @param request r
* @param response re
* @throws IOException on error
* @throws ServletException on error
*/
public void handle(final String target, final Request baseRequest, final HttpServletRequest request, |
File |
Project |
Line |
nl/tudelft/simulation/dsol/web/DsolWebModel.java |
DSOL gui project for Web interfaces |
429 |
nl/tudelft/simulation/dsol/web/DsolWebServer.java |
DSOL gui project for Web interfaces |
488 |
Object simTime = getSimulator().getSimulatorTime();
if (simTime instanceof Double || simTime instanceof Float)
{
double now = Math.round(((double) simTime) * 1000) / 1000d;
int seconds = (int) Math.floor(now);
int fractionalSeconds = (int) Math.floor(1000 * (now - seconds));
String timeText = String.format(" %02d:%02d:%02d.%03d ", seconds / 3600, seconds / 60 % 60,
seconds % 60, fractionalSeconds);
answer = timeText;
}
else if (simTime instanceof DoubleScalar)
{
double now = Math.round(((DoubleScalar<?, ?>) simTime).si * 1000) / 1000d;
int seconds = (int) Math.floor(now);
int fractionalSeconds = (int) Math.floor(1000 * (now - seconds));
String timeText = String.format(" %02d:%02d:%02d.%03d ", seconds / 3600, seconds / 60 % 60,
seconds % 60, fractionalSeconds);
answer = timeText;
}
else if (simTime instanceof FloatScalar)
{
double now = Math.round(((FloatScalar<?, ?>) simTime).si * 1000) / 1000d;
int seconds = (int) Math.floor(now);
int fractionalSeconds = (int) Math.floor(1000 * (now - seconds));
String timeText = String.format(" %02d:%02d:%02d.%03d ", seconds / 3600, seconds / 60 % 60,
seconds % 60, fractionalSeconds);
answer = timeText;
}
else
{
answer = simTime.toString();
}
break;
}
case "getSpeed":
{
Object simTimeObject = getSimulator().getSimulatorTime(); |
File |
Project |
Line |
nl/tudelft/simulation/dsol/web/DsolWebModel.java |
DSOL gui project for Web interfaces |
358 |
nl/tudelft/simulation/dsol/web/DsolWebServer.java |
DSOL gui project for Web interfaces |
417 |
this.simulator.getLogger().always().warn(exception, "getSelectedObjects");
}
if (targets.size() > 0)
{
Object introspectedObject = targets.get(0);
Property[] properties = new BeanIntrospector().getProperties(introspectedObject);
SortedMap<String, Property> propertyMap = new TreeMap<>();
for (Property property : properties)
propertyMap.put(property.getName(), property);
answer = "<introspection>\n";
for (Property property : propertyMap.values())
{
answer += "<property><field>" + property.getName() + "</field><value>" + property.getValue()
+ "</value></property>\n";
}
answer += "<introspection>\n";
}
else
{
answer = "<none />";
}
}
break;
}
case "zoomIn":
{
if (parts.length == 1)
animationPanel.zoom(0.9);
else
{
int x = Integer.parseInt(parts[1]);
int y = Integer.parseInt(parts[2]);
animationPanel.zoom(0.9, x, y);
}
break;
}
case "zoomOut":
{
if (parts.length == 1)
animationPanel.zoom(1.1);
else
{
int x = Integer.parseInt(parts[1]);
int y = Integer.parseInt(parts[2]);
animationPanel.zoom(1.1, x, y);
}
break;
}
case "zoomAll":
{
animationPanel.zoomAll();
break;
}
case "home":
{
animationPanel.home();
break;
}
case "toggleGrid":
{
animationPanel.setShowGrid(!animationPanel.isShowGrid());
break;
}
case "getTime":
{
Object simTime = getSimulator().getSimulatorTime(); |
File |
Project |
Line |
nl/tudelft/simulation/dsol/swing/introspection/gui/CollectionTableModel.java |
DSOL swing project |
85 |
nl/tudelft/simulation/dsol/swing/introspection/gui/ImmutableCollectionTableModel.java |
DSOL swing project |
78 |
public CollectionTableModel(final Property parentProperty, final Introspector introspector)
{
Object values;
try
{
values = parentProperty.getValue();
}
catch (Exception e)
{
values = new String("-");
}
if (values.getClass().isArray())
{
for (int i = 0; i < Array.getLength(values); i++)
{
addValue(Array.get(values, i));
}
}
if (values instanceof Collection)
{
for (Iterator<?> i = ((Collection<?>) values).iterator(); i.hasNext();)
{
addValue(i.next());
}
}
if (values instanceof ImmutableCollection)
{
for (Iterator<?> i = ((ImmutableCollection<?>) values).iterator(); i.hasNext();)
{
addValue(i.next());
}
}
this.parentProperty = parentProperty;
this.introspector = introspector;
// Initialize buttons
for (int i = 0; i < this.instances.size(); i++)
{
this.buttons.add(new ExpandButton(getProperty(i), this));
}
}
/**
* Adds a new value to the managed composite property.
* @param value Object; the value to add
*/
private void addValue(final Object value)
{
Integer nextKey = Integer.valueOf(this.maxKey++);
this.keys.add(nextKey);
this.instances.put(nextKey, value);
}
/** {@inheritDoc} */
@Override
public int getRowCount()
{
return this.instances.size();
}
/** {@inheritDoc} */
@Override
public int getColumnCount()
{
return CollectionTableModel.COLUMNS.length; |
File |
Project |
Line |
nl/tudelft/simulation/dsol/animation/gis/esri/ShapeFileReader.java |
DSOL ESRI Shape File Map Animation |
550 |
nl/tudelft/simulation/dsol/animation/gis/esri/ShapeFileReader.java |
DSOL ESRI Shape File Map Animation |
687 |
private synchronized Object readPolyLineZ(final ObjectEndianInputStream input, final int contentLength,
final boolean skipBoundingBox) throws IOException
{
this.currentType = GisMapInterface.LINE;
if (skipBoundingBox)
{
input.skipBytes(32);
}
input.setEndianness(Endianness.LITTLE_ENDIAN);
int numParts = input.readInt();
int numPoints = input.readInt();
int byteCounter = 44;
int[] partBegin = new int[numParts + 1];
for (int i = 0; i < partBegin.length - 1; i++)
{
partBegin[i] = input.readInt();
byteCounter += 4;
}
partBegin[partBegin.length - 1] = numPoints;
SerializablePath result = new SerializablePath(Path2D.WIND_NON_ZERO, numPoints);
for (int i = 0; i < numParts; i++)
{
float[] mf = this.coordinateTransform.floatTransform(input.readDouble(), input.readDouble());
result.moveTo(mf[0], mf[1]);
byteCounter += 16;
for (int ii = (partBegin[i] + 1); ii < partBegin[i + 1]; ii++)
{
float[] lf = this.coordinateTransform.floatTransform(input.readDouble(), input.readDouble());
result.lineTo(lf[0], lf[1]);
byteCounter += 16;
}
}
input.skipBytes((contentLength * 2) - byteCounter);
return result;
}
/**
* reads a readPolygonZ.
* @param input ObjectEndianInputStream; the inputStream
* @param contentLength int; the contentLength
* @param skipBoundingBox boolean; whether to skip the bytes of the bounding box because they have not yet been read
* @return the java2D PointShape
* @throws IOException on file IO or database connection failure
*/
private synchronized Object readPolygonZ(final ObjectEndianInputStream input, final int contentLength, |
File |
Project |
Line |
nl/tudelft/simulation/dsol/animation/gis/esri/ShapeFileReader.java |
DSOL ESRI Shape File Map Animation |
597 |
nl/tudelft/simulation/dsol/animation/gis/esri/ShapeFileReader.java |
DSOL ESRI Shape File Map Animation |
732 |
private synchronized Object readPolygonZ(final ObjectEndianInputStream input, final int contentLength,
final boolean skipBoundingBox) throws IOException
{
this.currentType = GisMapInterface.POLYGON;
if (skipBoundingBox)
{
input.skipBytes(32);
}
input.setEndianness(Endianness.LITTLE_ENDIAN);
int numParts = input.readInt();
int numPoints = input.readInt();
int byteCounter = 44;
int[] partBegin = new int[numParts + 1];
for (int i = 0; i < partBegin.length - 1; i++)
{
partBegin[i] = input.readInt();
byteCounter += 4;
}
partBegin[partBegin.length - 1] = numPoints;
SerializablePath result = new SerializablePath(Path2D.WIND_NON_ZERO, numPoints);
for (int i = 0; i < numParts; i++)
{
float[] mf = this.coordinateTransform.floatTransform(input.readDouble(), input.readDouble());
result.moveTo(mf[0], mf[1]);
byteCounter += 16;
for (int ii = (partBegin[i] + 1); ii < partBegin[i + 1]; ii++)
{
float[] lf = this.coordinateTransform.floatTransform(input.readDouble(), input.readDouble());
result.lineTo(lf[0], lf[1]);
byteCounter += 16;
}
}
input.skipBytes((contentLength * 2) - byteCounter);
return result;
}
/**
* reads a readMultiPointZ.
* @param input ObjectEndianInputStream; the inputStream
* @param contentLength int; the contentLength
* @param skipBoundingBox boolean; whether to skip the bytes of the bounding box because they have not yet been read
* @return the java2D PointShape
* @throws IOException on file IO or database connection failure
*/
private synchronized Object readMultiPointZ(final ObjectEndianInputStream input, final int contentLength, |
File |
Project |
Line |
nl/tudelft/simulation/dsol/swing/gui/inputparameters/InputFieldDistContinuous.java |
DSOL swing project |
93 |
nl/tudelft/simulation/dsol/swing/gui/inputparameters/InputFieldDistDiscrete.java |
DSOL swing project |
93 |
InputParameterMapDistContinuous value = parameter.getOptions().get(option);
JTextField[] paramFields = new JTextField[value.getSortedSet().size()];
int index = 0;
for (InputParameter<?, ?> param : value.getSortedSet())
{
JPanel itemPanel = new JPanel();
itemPanel.setLayout(new GridLayout(1, 2, 5, 0));
itemPanel.add(new JLabel(param.getShortName()));
paramFields[index] = new JTextField(param.getDefaultValue().toString(), 20);
itemPanel.add(paramFields[index]);
distParamPanel.add(itemPanel);
index++;
}
this.textFields.put(option.toString(), paramFields);
distParamPanel.add(Box.createVerticalGlue());
this.distPanel.add(distParamPanel, option.toString());
}
container.add(this.distComboBox);
container.add(this.distPanel);
panel.add(container);
cardLayout.show(this.distPanel, selections[defaultIndex]);
JLabel explanation = new JLabel(parameter.getDescription());
panel.add(explanation);
}
/** {@inheritDoc} */
@Override
public void itemStateChanged(final ItemEvent event)
{
CardLayout cardLayout = (CardLayout) (this.distPanel.getLayout());
cardLayout.show(this.distPanel, (String) event.getItem());
}
/** {@inheritDoc} */
@Override
public InputParameterDistContinuousSelection getParameter() |
File |
Project |
Line |
nl/tudelft/simulation/dsol/animation/gis/esri/ShapeFileReader.java |
DSOL ESRI Shape File Map Animation |
554 |
nl/tudelft/simulation/dsol/animation/gis/esri/ShapeFileReader.java |
DSOL ESRI Shape File Map Animation |
601 |
nl/tudelft/simulation/dsol/animation/gis/esri/ShapeFileReader.java |
DSOL ESRI Shape File Map Animation |
691 |
nl/tudelft/simulation/dsol/animation/gis/esri/ShapeFileReader.java |
DSOL ESRI Shape File Map Animation |
736 |
if (skipBoundingBox)
{
input.skipBytes(32);
}
input.setEndianness(Endianness.LITTLE_ENDIAN);
int numParts = input.readInt();
int numPoints = input.readInt();
int byteCounter = 44;
int[] partBegin = new int[numParts + 1];
for (int i = 0; i < partBegin.length - 1; i++)
{
partBegin[i] = input.readInt();
byteCounter += 4;
}
partBegin[partBegin.length - 1] = numPoints;
SerializablePath result = new SerializablePath(Path2D.WIND_NON_ZERO, numPoints);
for (int i = 0; i < numParts; i++)
{
float[] mf = this.coordinateTransform.floatTransform(input.readDouble(), input.readDouble());
result.moveTo(mf[0], mf[1]);
byteCounter += 16;
for (int ii = (partBegin[i] + 1); ii < partBegin[i + 1]; ii++)
{
float[] lf = this.coordinateTransform.floatTransform(input.readDouble(), input.readDouble());
result.lineTo(lf[0], lf[1]);
byteCounter += 16;
}
}
input.skipBytes((contentLength * 2) - byteCounter);
return result;
}
/**
* reads a readPolygonZ.
* @param input ObjectEndianInputStream; the inputStream
* @param contentLength int; the contentLength
* @param skipBoundingBox boolean; whether to skip the bytes of the bounding box because they have not yet been read
* @return the java2D PointShape
* @throws IOException on file IO or database connection failure
*/
private synchronized Object readPolygonZ(final ObjectEndianInputStream input, final int contentLength, |
File |
Project |
Line |
nl/tudelft/simulation/dsol/animation/gis/esri/ShapeFileReader.java |
DSOL ESRI Shape File Map Animation |
430 |
nl/tudelft/simulation/dsol/animation/gis/esri/ShapeFileReader.java |
DSOL ESRI Shape File Map Animation |
471 |
if (skipBoundingBox)
{
input.skipBytes(32);
}
input.setEndianness(Endianness.LITTLE_ENDIAN);
int numParts = input.readInt();
int numPoints = input.readInt();
int[] partBegin = new int[numParts + 1];
for (int i = 0; i < partBegin.length - 1; i++)
{
partBegin[i] = input.readInt();
}
partBegin[partBegin.length - 1] = numPoints;
SerializablePath result = new SerializablePath(Path2D.WIND_NON_ZERO, numPoints);
for (int i = 0; i < numParts; i++)
{
float[] mf = this.coordinateTransform.floatTransform(input.readDouble(), input.readDouble());
result.moveTo(mf[0], mf[1]);
for (int ii = (partBegin[i] + 1); ii < partBegin[i + 1]; ii++)
{
float[] lf = this.coordinateTransform.floatTransform(input.readDouble(), input.readDouble());
result.lineTo(lf[0], lf[1]);
}
}
return result;
}
/**
* reads a Polygon.
* @param input ObjectEndianInputStream; the inputStream
* @param skipBoundingBox boolean; whether to skip the bytes of the bounding box because they have not yet been read
* @return the java2D PointShape
* @throws IOException on file IO or database connection failure
*/
private synchronized Object readPolygon(final ObjectEndianInputStream input, final boolean skipBoundingBox) |
File |
Project |
Line |
nl/tudelft/simulation/dsol/animation/gis/esri/EsriRenderable2d.java |
DSOL ESRI Shape File Map Animation |
92 |
nl/tudelft/simulation/dsol/animation/gis/osm/OsmRenderable2d.java |
DSOL OpenStreetMap Animation |
92 |
public EsriRenderable2d(final Contextualized contextProvider, final GisMapInterface map,
final CoordinateTransform coordinateTransform, final double z)
{
try
{
this.map = map;
this.location = new OrientedPoint3d(this.cachedExtent.midPoint().getX(), this.cachedExtent.midPoint().getY(), z);
this.bounds = new Bounds3d(this.cachedExtent.getDeltaX(), this.cachedExtent.getDeltaY(), 0.0);
this.bind2Context(contextProvider);
}
catch (Exception exception)
{
CategoryLogger.always().warn(exception, "<init>");
}
}
/**
* binds a renderable2D to the context. The reason for specifying this in an independent method instead of adding the code
* in the constructor is related to the RFE submitted by van Houten that in specific distributed context, such binding must
* be overwritten.
* @param contextProvider Contextualized; the object that can provide the context to store the animation objects
*/
protected void bind2Context(final Contextualized contextProvider)
{
try
{
ContextUtil.lookupOrCreateSubContext(contextProvider.getContext(), "animation/2D")
.bindObject(Integer.toString(System.identityHashCode(this)), this);
}
catch (NamingException | RemoteException exception)
{
CategoryLogger.always().warn(exception, "<init>");
}
}
/** {@inheritDoc} */
@Override
public void paintComponent(final Graphics2D graphics, final Bounds2d extent, final Dimension screen,
final RenderableScale renderableScale, final ImageObserver observer)
{
try
{ |
File |
Project |
Line |
nl/tudelft/simulation/examples/dsol/animation/gis/EsriCsvSwingApplication.java |
DSOL demo project |
49 |
nl/tudelft/simulation/examples/dsol/animation/gis/EsriXmlSwingApplication.java |
DSOL demo project |
49 |
public EsriCsvSwingApplication(final String title, final DsolPanel panel, final DsolAnimationGisTab animationTab)
throws RemoteException, IllegalArgumentException, DsolException
{
super(panel, title, animationTab);
panel.enableSimulationControlButtons();
}
/** */
private static final long serialVersionUID = 1L;
/**
* @param args String[]; arguments, expected to be empty
* @throws SimRuntimeException on error
* @throws RemoteException on error
* @throws NamingException on error
* @throws DsolException when simulator is not an animator
*/
public static void main(final String[] args) throws SimRuntimeException, RemoteException, NamingException, DsolException
{
DevsRealTimeAnimator.TimeDouble simulator = new DevsRealTimeAnimator.TimeDouble("EsriSwingApplication", 0.001);
EmptyModel model = new EmptyModel(simulator);
Replication<Double> replication = new SingleReplication<Double>("rep1", 0.0, 0.0, 1000000.0);
simulator.initialize(model, replication);
DsolPanel panel = new DsolPanel(new RealTimeControlPanel.TimeDouble(model, simulator));
Bounds2d mapBounds = new Bounds2d(4.355, 4.386, 51.995, 52.005);
DsolAnimationGisTab animationTab = new DsolAnimationGisTab(mapBounds, simulator);
animationTab.getAnimationPanel().setRenderableScale(
new RenderableScale(Math.cos(Math.toRadians(mapBounds.midPoint().getY())), 1.0 / 111319.24));
animationTab.addAllToggleGISButtonText("MAP LAYERS", model.getGisMap(), "hide or show this GIS layer");
new EsriCsvSwingApplication("EsriSwingApplication", panel, animationTab); |
File |
Project |
Line |
nl/tudelft/simulation/jstats/distributions/empirical/DistributionFrequencies.java |
DSOL core project |
37 |
nl/tudelft/simulation/jstats/distributions/empirical/DistributionFrequencies.java |
DSOL core project |
117 |
public static DiscreteEmpiricalDistribution createDiscreteDistribution(final Number[] values, final long[] frequencies)
{
Throw.whenNull(values, "values array cannot be null");
Throw.whenNull(frequencies, "frequencies array cannot be null");
Throw.when(values.length == 0, IllegalArgumentException.class, "values array cannot be empty");
Throw.when(frequencies.length == 0, IllegalArgumentException.class, "frequencies array cannot be empty");
Throw.when(frequencies.length != values.length, IllegalArgumentException.class,
"values array and frequencies array should have the same length");
double sum = 0.0;
for (int i = 0; i < frequencies.length; i++)
{
Throw.when(frequencies[i] <= 0, IllegalArgumentException.class, "frequency cannot be zero or negative");
sum += 1.0 * frequencies[i];
}
double[] cumulativeProbabilities;
double partialSum = 0;
cumulativeProbabilities = new double[frequencies.length];
for (int i = 0; i < frequencies.length; i++)
{
partialSum += 1.0 * frequencies[i];
cumulativeProbabilities[i] = partialSum / sum;
}
cumulativeProbabilities[cumulativeProbabilities.length - 1] = 1.0;
return new DiscreteEmpiricalDistribution(values.clone(), cumulativeProbabilities);
}
/**
* Create a discrete empirical distribution from two arrays, one with frequencies or weights, and one with corresponding
* values.
* @param values double[] the values
* @param frequencies long[]; the frequencies for the corresponding values
* @return the cumulative distribution object belonging to the given arrays
* @throws NullPointerException when values array is null or frequencies array is null, or when one of the values is null
* @throws IllegalArgumentException when frequencies array or values array are empty, or have unequal length, or when
* frequencies are zero or negative, or when values are not in ascending order
*/
public static DiscreteEmpiricalDistribution createDiscreteDistribution(final double[] values, final long[] frequencies) |
File |
Project |
Line |
nl/tudelft/simulation/jstats/ode/integrators/RungeKuttaCashCarp.java |
DSOL core project |
49 |
nl/tudelft/simulation/jstats/ode/integrators/RungeKuttaFehlberg.java |
DSOL core project |
49 |
public RungeKuttaCashCarp(final double stepSize, final DifferentialEquationInterface equation)
{
super(stepSize, equation);
}
/** {@inheritDoc} */
@Override
public double[] next(final double x, final double[] y)
{
double[][] k = new double[nk][];
for (int i = 0; i < nk; i++)
{
double[] ysum = y.clone();
for (int j = 0; j < i; j++)
{
if (b[i][j] != 0.0)
{
ysum = add(ysum, multiply(b[i][j], k[j]));
}
}
k[i] = multiply(this.stepSize, this.equation.dy(x + a[i] * this.stepSize, ysum));
}
double[] sum = y.clone();
super.error = new double[y.length];
for (int i = 0; i < nk; i++)
{
sum = add(sum, this.multiply(c[i], k[i])); |
File |
Project |
Line |
nl/tudelft/simulation/dsol/swing/animation/d2/VisualizationPanel.java |
DSOL swing project |
516 |
nl/tudelft/simulation/dsol/web/animation/d2/HtmlGridPanel.java |
DSOL gui project for Web interfaces |
294 |
setExtent(this.renderableScale.computeVisibleExtent(this.homeExtent, this.getSize()));
}
/**
* @return Returns the showGrid.
*/
public boolean isShowGrid()
{
return this.showGrid;
}
/**
* @param showGrid boolean; The showGrid to set.
*/
public void setShowGrid(final boolean showGrid)
{
this.showGrid = showGrid;
}
/**
* zooms in/out.
* @param factor double; The zoom factor
*/
public synchronized void zoom(final double factor)
{
zoom(factor, (int) (this.getWidth() / 2.0), (int) (this.getHeight() / 2.0));
}
/**
* zooms in/out.
* @param factor double; The zoom factor
* @param mouseX int; x-position of the mouse around which we zoom
* @param mouseY int; y-position of the mouse around which we zoom
*/
public synchronized void zoom(final double factor, final int mouseX, final int mouseY)
{
Point2d mwc = this.renderableScale.getWorldCoordinates(new Point2D.Double(mouseX, mouseY), this.extent, this.getSize());
double minX = mwc.getX() - (mwc.getX() - this.extent.getMinX()) * factor;
double minY = mwc.getY() - (mwc.getY() - this.extent.getMinY()) * factor;
double w = this.extent.getDeltaX() * factor;
double h = this.extent.getDeltaY() * factor; |
File |
Project |
Line |
nl/tudelft/simulation/dsol/swing/gui/inputparameters/InputFieldDoubleScalar.java |
DSOL swing project |
47 |
nl/tudelft/simulation/dsol/swing/gui/inputparameters/InputFieldFloatScalar.java |
DSOL swing project |
47 |
.setText("" + parameter.getDefaultTypedValue().getInUnit(parameter.getDefaultTypedValue().getDisplayUnit()));
JLabel explanation = new JLabel(parameter.getDescription());
String[] selections = new String[parameter.getUnitParameter().getOptions().size()];
int defaultIndex = 0;
int i = 0;
for (String option : parameter.getUnitParameter().getOptions().keySet())
{
selections[i] = option.toString();
U value = parameter.getUnitParameter().getOptions().get(option);
if (value.equals(parameter.getUnitParameter().getDefaultValue()))
{
defaultIndex = i;
}
i++;
}
this.unitField = new JComboBox<>(selections);
this.unitField.setSelectedIndex(defaultIndex);
panel.add(label);
JPanel scalarPanel = new JPanel();
scalarPanel.setLayout(new GridLayout(1, 2, 5, 0));
scalarPanel.add(this.doubleField); |
File |
Project |
Line |
nl/tudelft/simulation/dsol/swing/gui/inputparameters/InputFieldDistContinuous.java |
DSOL swing project |
143 |
nl/tudelft/simulation/dsol/swing/gui/inputparameters/InputFieldDistDiscrete.java |
DSOL swing project |
143 |
InputParameterMapDistContinuous ipMap = this.selectionMap.get(selectedOption);
JTextField[] paramFields = this.textFields.get(selectedOption);
int index = 0;
for (InputParameter<?, ?> param : ipMap.getSortedSet())
{
String sValue = paramFields[index].getText();
if (param instanceof InputParameterDouble)
{
InputParameterDouble dParam = (InputParameterDouble) param;
dParam.setDoubleValue(InputFieldDouble.getDoubleValue(sValue, param.getShortName()));
}
else if (param instanceof InputParameterFloat)
{
InputParameterFloat fParam = (InputParameterFloat) param;
fParam.setFloatValue(InputFieldFloat.getFloatValue(sValue, param.getShortName()));
}
else if (param instanceof InputParameterInteger)
{
InputParameterInteger iParam = (InputParameterInteger) param;
iParam.setIntValue(InputFieldInteger.getIntValue(sValue, param.getShortName()));
}
else if (param instanceof InputParameterLong)
{
InputParameterLong lParam = (InputParameterLong) param;
lParam.setLongValue(InputFieldLong.getLongValue(sValue, param.getShortName()));
}
index++;
}
}
} |
File |
Project |
Line |
nl/tudelft/simulation/dsol/animation/gis/SerializableRectangle2d.java |
DSOL Animation classes |
62 |
nl/tudelft/simulation/dsol/animation/gis/SerializableRectangle2d.java |
DSOL Animation classes |
200 |
this.rectangle = new Rectangle2D.Double(x, y, w, h);
}
/** {@inheritDoc} */
@Override
public Rectangle2D createIntersection(final Rectangle2D r)
{
return this.rectangle.createIntersection(r);
}
/** {@inheritDoc} */
@Override
public Rectangle2D createUnion(final Rectangle2D r)
{
return this.rectangle.createUnion(r);
}
/** {@inheritDoc} */
@Override
public Rectangle2D getBounds2D()
{
return this.rectangle.getBounds2D();
}
/** {@inheritDoc} */
@Override
public double getHeight()
{
return this.rectangle.getHeight();
}
/** {@inheritDoc} */
@Override
public double getWidth()
{
return this.rectangle.getWidth();
}
/** {@inheritDoc} */
@Override
public double getX()
{
return this.rectangle.getX();
}
/** {@inheritDoc} */
@Override
public double getY()
{
return this.rectangle.getY();
}
/** {@inheritDoc} */
@Override
public boolean isEmpty()
{
return this.rectangle.isEmpty();
}
/** {@inheritDoc} */
@Override
public int outcode(final double x, final double y)
{
return this.rectangle.outcode(x, y);
} |
File |
Project |
Line |
nl/tudelft/simulation/dsol/simulators/DevDessAnimator.java |
DSOL core project |
89 |
nl/tudelft/simulation/dsol/simulators/DevsAnimator.java |
DSOL core project |
72 |
&& runUntil.compareTo(this.eventList.first().getAbsoluteExecutionTime()) >= 0)
{
synchronized (super.semaphore)
{
int cmp = this.eventList.first().getAbsoluteExecutionTime().compareTo(this.runUntilTime);
if ((cmp == 0 && !this.runUntilIncluding) || cmp > 0)
{
this.simulatorTime = SimTime.copy(this.runUntilTime);
this.runState = RunState.STOPPING;
break;
}
SimEventInterface<T> event = this.eventList.removeFirst();
if (event.getAbsoluteExecutionTime().compareTo(super.simulatorTime) != 0)
{
super.fireUnverifiedTimedEvent(SimulatorInterface.TIME_CHANGED_EVENT, null,
event.getAbsoluteExecutionTime());
}
this.simulatorTime = event.getAbsoluteExecutionTime();
try
{
event.execute();
if (this.eventList.isEmpty())
{
this.simulatorTime = SimTime.copy(this.runUntilTime);
this.runState = RunState.STOPPING;
break;
}
}
catch (Exception exception)
{
handleSimulationException(exception);
}
}
} |
File |
Project |
Line |
nl/tudelft/simulation/dsol/simulators/DevDessAnimator.java |
DSOL core project |
91 |
nl/tudelft/simulation/dsol/simulators/DevDessSimulator.java |
DSOL core project |
80 |
nl/tudelft/simulation/dsol/simulators/DevsAnimator.java |
DSOL core project |
74 |
synchronized (super.semaphore)
{
int cmp = this.eventList.first().getAbsoluteExecutionTime().compareTo(this.runUntilTime);
if ((cmp == 0 && !this.runUntilIncluding) || cmp > 0)
{
this.simulatorTime = SimTime.copy(this.runUntilTime);
this.runState = RunState.STOPPING;
break;
}
SimEventInterface<T> event = this.eventList.removeFirst();
if (event.getAbsoluteExecutionTime().compareTo(super.simulatorTime) != 0)
{
super.fireUnverifiedTimedEvent(SimulatorInterface.TIME_CHANGED_EVENT, null,
event.getAbsoluteExecutionTime());
}
this.simulatorTime = event.getAbsoluteExecutionTime();
try
{
event.execute();
if (this.eventList.isEmpty())
{
this.simulatorTime = SimTime.copy(this.runUntilTime);
this.runState = RunState.STOPPING;
break;
}
}
catch (Exception exception)
{
handleSimulationException(exception);
}
} |
File |
Project |
Line |
nl/tudelft/simulation/dsol/statistics/SimCounter.java |
DSOL core project |
59 |
nl/tudelft/simulation/dsol/statistics/SimTally.java |
DSOL core project |
57 |
public SimCounter(final String description, final DsolModel<T, ? extends SimulatorInterface<T>> model)
{
super(description);
Throw.whenNull(model, "model cannot be null");
model.getOutputStatistics().add(this);
this.simulator = model.getSimulator();
try
{
// only if we are before the warmup time, subscribe to the warmul event
if (this.simulator.getSimulatorTime().compareTo(this.simulator.getReplication().getWarmupTime()) < 0)
{
this.simulator.addListener(this, Replication.WARMUP_EVENT, ReferenceType.STRONG);
}
ContextInterface context =
ContextUtil.lookupOrCreateSubContext(this.simulator.getReplication().getContext(), "statistics");
context.bindObject(this);
}
catch (NamingException | RemoteException exception)
{
this.simulator.getLogger().always().warn(exception, "<init>");
}
}
/**
* constructs a new SimCounter.
* @param description String; the description
* @param model DsolModel<T, SimulatorInterface<T>>; the model
* @param target EventProducer; the target on which to count
* @param eventType EventType; the EventType for which counting takes place
*/
public SimCounter(final String description, final DsolModel<T, ? extends SimulatorInterface<T>> model, |
File |
Project |
Line |
nl/tudelft/simulation/dsol/swing/animation/d2/VisualizationPanel.java |
DSOL swing project |
425 |
nl/tudelft/simulation/dsol/web/animation/d2/HtmlGridPanel.java |
DSOL gui project for Web interfaces |
201 |
}
/**
* Set the world coordinates based on a mouse move.
* @param point Point2D; the x,y world coordinates
*/
public synchronized void setWorldCoordinate(final Point2d point)
{
this.worldCoordinate = point;
}
/**
* @return worldCoordinate
*/
public synchronized Point2d getWorldCoordinate()
{
return this.worldCoordinate;
}
/**
* Display a tooltip with the last known world coordinates of the mouse, in case the tooltip should be displayed.
*/
public synchronized void displayWorldCoordinateToolTip()
{
if (this.showToolTip)
{
String worldPoint = "(x=" + this.formatter.format(this.worldCoordinate.getX()) + " ; y="
+ this.formatter.format(this.worldCoordinate.getY()) + ")";
setToolTipText(worldPoint);
}
}
/**
* @return showToolTip
*/
public synchronized boolean isShowToolTip()
{
return this.showToolTip;
}
/**
* @param showToolTip boolean; set showToolTip
*/
public synchronized void setShowToolTip(final boolean showToolTip)
{
this.showToolTip = showToolTip;
}
/**
* pans the panel in a specified direction.
* @param direction int; the direction
* @param percentage double; the percentage
*/
public synchronized void pan(final int direction, final double percentage)
{
if (percentage <= 0 || percentage > 1.0)
{
throw new IllegalArgumentException("percentage<=0 || >1.0");
}
switch (direction)
{
case LEFT: |
File |
Project |
Line |
nl/tudelft/simulation/dsol/eventlists/EventListPriorityQueue.java |
DSOL core project |
49 |
nl/tudelft/simulation/dsol/eventlists/RedBlackTree.java |
DSOL core project |
64 |
}
/** {@inheritDoc} */
@Override
public void add(final SimEventInterface<T> event)
{
this.eventList.add(event);
}
/** {@inheritDoc} */
@Override
public boolean contains(final SimEventInterface<T> event)
{
return this.eventList.contains(event);
}
/** {@inheritDoc} */
@Override
public void clear()
{
this.eventList.clear();
}
/** {@inheritDoc} */
@Override
public boolean isEmpty()
{
return this.eventList.isEmpty();
}
/** {@inheritDoc} */
@Override
public Iterator<SimEventInterface<T>> iterator()
{
return this.eventList.iterator();
}
/** {@inheritDoc} */
@Override
public boolean remove(final SimEventInterface<T> event)
{
return this.eventList.remove(event);
}
/** {@inheritDoc} */
@Override
public int size()
{
return this.eventList.size();
}
} |
File |
Project |
Line |
nl/tudelft/simulation/dsol/statistics/SimCounter.java |
DSOL core project |
89 |
nl/tudelft/simulation/dsol/statistics/SimTally.java |
DSOL core project |
87 |
public SimCounter(final String description, final DsolModel<T, ? extends SimulatorInterface<T>> model,
final EventProducer target, final EventType eventType)
{
this(description, model);
try
{
target.addListener(this, eventType, ReferenceType.STRONG);
}
catch (RemoteException exception)
{
this.simulator.getLogger().always().warn(exception, "<init>");
}
}
/** {@inheritDoc} */
@Override
public void initialize()
{
super.initialize();
// note that when initialize() is called from the (super) constructor, there cannot be listeners yet
if (this.simulator != null)
{
try
{
fireTimedEvent(TIMED_INITIALIZED_EVENT, this, this.simulator.getSimulatorTime());
}
catch (RemoteException exception)
{
this.simulator.getLogger().always().warn(exception, "initialize()");
}
}
}
/** {@inheritDoc} */
@Override |
File |
Project |
Line |
nl/tudelft/simulation/dsol/statistics/SimCounter.java |
DSOL core project |
89 |
nl/tudelft/simulation/dsol/statistics/SimPersistent.java |
DSOL core project |
90 |
nl/tudelft/simulation/dsol/statistics/SimTally.java |
DSOL core project |
87 |
public SimCounter(final String description, final DsolModel<T, ? extends SimulatorInterface<T>> model,
final EventProducer target, final EventType eventType)
{
this(description, model);
try
{
target.addListener(this, eventType, ReferenceType.STRONG);
}
catch (RemoteException exception)
{
this.simulator.getLogger().always().warn(exception, "<init>");
}
}
/** {@inheritDoc} */
@Override
public void initialize()
{
super.initialize();
// note that when initialize() is called from the (super) constructor, there cannot be listeners yet
if (this.simulator != null)
{
try
{
fireTimedEvent(TIMED_INITIALIZED_EVENT, this, this.simulator.getSimulatorTime());
}
catch (RemoteException exception)
{
this.simulator.getLogger().always().warn(exception, "initialize()");
}
}
}
/** {@inheritDoc} */
@Override |
File |
Project |
Line |
nl/tudelft/simulation/dsol/swing/gui/inputparameters/InputFieldDistContinuous.java |
DSOL swing project |
73 |
nl/tudelft/simulation/dsol/swing/gui/inputparameters/InputFieldDistDiscrete.java |
DSOL swing project |
73 |
InputParameterMapDistContinuous value = parameter.getOptions().get(option);
this.selectionMap.put(selections[i], value);
if (value.equals(parameter.getDefaultValue()))
{
defaultIndex = i;
}
i++;
}
this.distComboBox = new JComboBox<>(selections);
this.distComboBox.setSelectedIndex(defaultIndex);
this.distComboBox.addItemListener(this);
comboBoxPane.add(this.distComboBox);
CardLayout cardLayout = new CardLayout();
this.distPanel = new JPanel(cardLayout);
for (String option : parameter.getOptions().keySet())
{
JPanel distParamPanel = new JPanel();
BoxLayout boxLayout = new BoxLayout(distParamPanel, BoxLayout.Y_AXIS);
distParamPanel.setLayout(boxLayout); |
File |
Project |
Line |
nl/tudelft/simulation/dsol/formalisms/Resource.java |
DSOL core project |
278 |
nl/tudelft/simulation/examples/dsol/terminal/IntResource.java |
DSOL demo project |
258 |
public static class RequestComparator<T extends Number & Comparable<T>> implements Comparator<Request<T>>
{
/** {@inheritDoc} */
@Override
public int compare(final Request<T> arg0, final Request<T> arg1)
{
if (arg0.getPriority() > arg1.getPriority())
{
return -1;
}
if (arg0.getPriority() < arg1.getPriority())
{
return 1;
}
if (arg0.getId() < arg1.getId())
{
return -1;
}
if (arg0.getId() > arg1.getId())
{
return 1;
}
return 0;
}
}
/**
* A Request.
* @param <T> the simulation time type to use.
*/
public static class Request<T extends Number & Comparable<T>>
{
/** the priority of the request. */
private int priority = 5;
/** the number of this request. */
private long id = -1;
/** requestor the resourceRequestor. */
private ResourceRequestorInterface<T> requestor; |
File |
Project |
Line |
nl/tudelft/simulation/dsol/demo/event/mm1/MM1Model.java |
DSOL demo project |
75 |
nl/tudelft/simulation/dsol/demo/flow/mm1/MM1Model.java |
DSOL demo project |
62 |
InputParameterMap generatorMap = new InputParameterMap("generator", "Generator", "Generator", 1.0);
generatorMap.add(new InputParameterDouble("intervalTime", "Average interval time", "Average interval time", 1.0, 1.0));
generatorMap.add(new InputParameterDouble("startTime", "Generator start time", "Generator start time", 0.0, 2.0));
generatorMap.add(new InputParameterInteger("batchSize", "Batch size", "batch size", 1, 3.0));
this.inputParameterMap.add(generatorMap);
InputParameterMap resourceMap = new InputParameterMap("resource", "Resource", "Resource", 2.0);
resourceMap.add(new InputParameterInteger("capacity", "Resource capacity", "Resource capacity", 1, 1.0));
resourceMap.add(new InputParameterDouble("serviceTime", "Average service time", "Average service time", 0.9, 2.0));
this.inputParameterMap.add(resourceMap);
} |
File |
Project |
Line |
nl/tudelft/simulation/dsol/swing/animation/d2/VisualizationPanel.java |
DSOL swing project |
723 |
nl/tudelft/simulation/dsol/web/animation/d2/HtmlAnimationPanel.java |
DSOL gui project for Web interfaces |
294 |
Point<?> l = renderable.getSource().getLocation();
if (l != null)
{
Bounds<?, ?, ?> b = renderable.getSource().getBounds();
minX = Math.min(minX, l.getX() + b.getMinX());
minY = Math.min(minY, l.getY() + b.getMinY());
maxX = Math.max(maxX, l.getX() + b.getMaxX());
maxY = Math.max(maxY, l.getY() + b.getMaxY());
}
}
}
catch (Exception e)
{
// ignore
}
minX -= EXTENT_MARGIN_FACTOR * Math.abs(maxX - minX); |
File |
Project |
Line |
nl/tudelft/simulation/dsol/formalisms/Resource.java |
DSOL core project |
239 |
nl/tudelft/simulation/examples/dsol/terminal/IntResource.java |
DSOL demo project |
220 |
if (amount > 0.0)
{
this.alterClaimedCapacity(-Math.min(this.capacity, amount));
}
synchronized (this.requests)
{
for (Iterator<Request<T>> i = this.requests.iterator(); i.hasNext();)
{
Request<T> request = i.next();
if ((this.capacity - this.claimedCapacity) >= request.getAmount())
{
this.alterClaimedCapacity(request.getAmount());
request.getRequestor().receiveRequestedResource(request.getAmount(), this);
synchronized (this.requests)
{
i.remove();
}
this.fireTimedEvent(Resource.QUEUE_LENGTH_EVENT, this.requests.size(), |
File |
Project |
Line |
nl/tudelft/simulation/jstats/ode/integrators/RungeKutta3.java |
DSOL core project |
27 |
nl/tudelft/simulation/jstats/ode/integrators/RungeKutta4.java |
DSOL core project |
27 |
public RungeKutta3(final double stepSize, final DifferentialEquationInterface equation)
{
super(stepSize, equation);
}
/** {@inheritDoc} */
@Override
public double[] next(final double x, final double[] y)
{
double[] k1 = this.equation.dy(x, y);
double[] k2 = this.equation.dy(x + 0.5 * this.stepSize, add(y, multiply(0.5 * this.stepSize, k1)));
double[] k3 = this.equation.dy(x + 0.5 * this.stepSize, add(y, multiply(0.5 * this.stepSize, k2)));
double[] sum = add(k1, multiply(4.0, k2), k3); |
File |
Project |
Line |
nl/tudelft/simulation/examples/dsol/animation/gis/EsriCsvSwingApplication.java |
DSOL demo project |
68 |
nl/tudelft/simulation/examples/dsol/animation/gis/EsriXmlSwingApplication.java |
DSOL demo project |
68 |
nl/tudelft/simulation/examples/dsol/animation/gis/OsmSwingApplication.java |
DSOL demo project |
68 |
DevsRealTimeAnimator.TimeDouble simulator = new DevsRealTimeAnimator.TimeDouble("EsriSwingApplication", 0.001);
EmptyModel model = new EmptyModel(simulator);
Replication<Double> replication = new SingleReplication<Double>("rep1", 0.0, 0.0, 1000000.0);
simulator.initialize(model, replication);
DsolPanel panel = new DsolPanel(new RealTimeControlPanel.TimeDouble(model, simulator));
Bounds2d mapBounds = new Bounds2d(4.355, 4.386, 51.995, 52.005);
DsolAnimationGisTab animationTab = new DsolAnimationGisTab(mapBounds, simulator);
animationTab.getAnimationPanel().setRenderableScale(
new RenderableScale(Math.cos(Math.toRadians(mapBounds.midPoint().getY())), 1.0 / 111319.24));
animationTab.addAllToggleGISButtonText("MAP LAYERS", model.getGisMap(), "hide or show this GIS layer"); |
File |
Project |
Line |
nl/tudelft/simulation/dsol/simulators/DevDessAnimator.java |
DSOL core project |
43 |
nl/tudelft/simulation/dsol/simulators/DevsAnimator.java |
DSOL core project |
40 |
@Override
public long getAnimationDelay()
{
return this.animationDelay;
}
/** {@inheritDoc} */
@Override
public void setAnimationDelay(final long animationDelay)
{
this.animationDelay = animationDelay;
this.fireEvent(ANIMATION_DELAY_CHANGED_EVENT, animationDelay);
}
/** {@inheritDoc} */
@Override
public void updateAnimation()
{
this.fireTimedEvent(AnimatorInterface.UPDATE_ANIMATION_EVENT, null, this.simulatorTime);
}
/** {@inheritDoc} */
@Override
public void run()
{
AnimationThread animationThread = new AnimationThread(this);
animationThread.start();
// set the run flag semaphore to signal to startImpl() that the run method has started
this.runflag = true;
while (!isStoppingOrStopped() && !this.eventList.isEmpty()
&& this.simulatorTime.compareTo(this.replication.getEndTime()) <= 0)
{ |
File |
Project |
Line |
nl/tudelft/simulation/dsol/swing/introspection/gui/CollectionTableModel.java |
DSOL swing project |
303 |
nl/tudelft/simulation/dsol/swing/introspection/gui/ImmutableCollectionTableModel.java |
DSOL swing project |
221 |
}
/** {@inheritDoc} */
@Override
public Introspector getIntrospector()
{
return this.introspector;
}
/** {@inheritDoc} */
@Override
public Class<?> getTypeAt(final int rowIndex, final int columnIndex)
{
if (columnIndex == 0)
{
return String.class;
}
if (columnIndex == 1)
{
return ExpandButton.class;
}
if (columnIndex == 2)
{
return this.instances.get(this.keys.get(rowIndex)).getClass();
}
return null;
}
/**
* Sets the modelmanager. By default, a {see DefaultModelManager}is used.
* @param manager ModelManager; the manager
*/
public void setModelManager(final ModelManager manager)
{
this.manager = manager;
}
/**
* By default, a {see DefaultModelManager}returned.
* @see nl.tudelft.simulation.dsol.swing.introspection.gui.IntrospectingTableModelInterface #getModelManager()
* @return the Manager
*/
@Override
public ModelManager getModelManager()
{
return this.manager;
} |
File |
Project |
Line |
nl/tudelft/simulation/naming/context/JvmContext.java |
Naming project for DSOL |
418 |
nl/tudelft/simulation/naming/context/RemoteContext.java |
Naming project for DSOL |
274 |
}
/** {@inheritDoc} */
@Override
public void fireObjectChangedEventValue(final Object object)
throws NameNotFoundException, NullPointerException, NamingException, RemoteException
{
Throw.whenNull(object, "object cannot be null");
fireObjectChangedEventKey(makeObjectKey(object));
}
/** {@inheritDoc} */
@Override
public void fireObjectChangedEventKey(final String key)
throws NameNotFoundException, NullPointerException, NamingException, RemoteException
{
Throw.whenNull(key, "key cannot be null");
Throw.when(key.length() == 0 || key.contains(ContextInterface.SEPARATOR), NamingException.class,
"key [%s] is the empty string or key contains '/'", key);
if (!hasKey(key))
{
throw new NameNotFoundException("Could not find object with key " + key + " for fireObjectChangedEvent");
}
try
{ |
File |
Project |
Line |
nl/tudelft/simulation/dsol/animation/gis/esri/ShapeFileReader.java |
DSOL ESRI Shape File Map Animation |
643 |
nl/tudelft/simulation/dsol/animation/gis/esri/ShapeFileReader.java |
DSOL ESRI Shape File Map Animation |
778 |
private synchronized Object readMultiPointZ(final ObjectEndianInputStream input, final int contentLength,
final boolean skipBoundingBox) throws IOException
{
this.currentType = GisMapInterface.POINT;
if (skipBoundingBox)
{
input.skipBytes(32);
}
input.setEndianness(Endianness.LITTLE_ENDIAN);
Point2D[] result = new Point2D.Double[input.readInt()];
int byteCounter = 40;
for (int i = 0; i < result.length; i++)
{
result[i] = (Point2D) readPoint(input);
byteCounter += 16;
}
input.skipBytes((contentLength * 2) - byteCounter);
return result;
}
/**
* reads a readPointM.
* @param input ObjectEndianInputStream; the inputStream
* @param contentLength int; the contentLength
* @return the java2D PointShape
* @throws IOException on file IO or database connection failure
*/
private synchronized Object readPointM(final ObjectEndianInputStream input, final int contentLength) throws IOException |
File |
Project |
Line |
nl/tudelft/simulation/dsol/web/animation/HtmlGraphics2D.java |
DSOL gui project for Web interfaces |
277 |
nl/tudelft/simulation/dsol/web/animation/HtmlGraphics2D.java |
DSOL gui project for Web interfaces |
351 |
protected void addTransformPathFloat(Path2D.Float path, boolean fill)
{
if (fill)
this.commands.append("<transformPath>FILL");
else
this.commands.append("<transformPath>DRAW");
addAffineTransform();
addColor(this.color);
if (fill)
{
if (path.getWindingRule() == Path2D.WIND_EVEN_ODD)
this.commands.append(",WIND_EVEN_ODD");
else
this.commands.append(",WIND_NON_ZERO");
}
else
{
if (this.stroke instanceof BasicStroke)
this.commands.append("," + ((BasicStroke) this.stroke).getLineWidth());
else
this.commands.append(", 0.1");
} |
File |
Project |
Line |
nl/tudelft/simulation/dsol/model/inputparameters/InputParameterDoubleScalar.java |
DSOL core project |
76 |
nl/tudelft/simulation/dsol/model/inputparameters/InputParameterFloatScalar.java |
DSOL core project |
75 |
public InputParameterDoubleScalar(final String key, final String shortName, final String description, final T defaultValue,
final T minimumValue, final T maximumValue, final boolean minIncluded, final boolean maxIncluded,
final String format, final double displayPriority) throws InputParameterException
{
this(key, shortName, description, defaultValue, minimumValue.si, maximumValue.si, minIncluded, maxIncluded, format,
displayPriority);
Throw.whenNull(format, "format cannot be null");
Throw.whenNull(defaultValue, "defaultValue cannot be null");
Throw.whenNull(minimumValue, "minimumValue cannot be null");
Throw.whenNull(maximumValue, "maximumValue cannot be null");
}
/**
* Construct a new InputParameterDoubleScalar.
* @param key String; unique (within the parent's input parameter map) name of the new InputParameterDoubleUnit
* @param shortName String; concise description of the input parameter
* @param description String; double description of the input parameter (may use HTML markup)
* @param defaultValue T; the default value of this input parameter
* @param minimumValueSI double; the lowest value allowed as input (in SI units)
* @param maximumValueSI double; the highest value allowed as input (in SI units)
* @param minIncluded boolean; is the minimum value included or excluded in the allowed interval?
* @param maxIncluded boolean; is the maximum value included or excluded in the allowed interval?
* @param format String; the format to use in displaying the double
* @param displayPriority double; sorting order when properties are displayed to the user
* @throws NullPointerException when key, shortName, defaultValue, description, format, or defaultValue is null
* @throws IllegalArgumentException when displayPriority is NaN
* @throws InputParameterException when unit for the default value cannot be found in the unit definition
*/
@SuppressWarnings("checkstyle:parameternumber")
public InputParameterDoubleScalar(final String key, final String shortName, final String description, final T defaultValue, |
File |
Project |
Line |
nl/tudelft/simulation/dsol/animation/gis/esri/EsriRenderable2d.java |
DSOL ESRI Shape File Map Animation |
135 |
nl/tudelft/simulation/dsol/animation/gis/osm/OsmRenderable2d.java |
DSOL OpenStreetMap Animation |
137 |
if (extent.equals(this.cachedExtent) && screen.equals(this.cachedScreenSize) && this.map.isSame())
{
graphics.drawImage(this.cachedImage, 0, 0, null);
return;
}
this.map.setExtent(extent);
this.map.getImage().setSize(screen);
this.cacheImage();
this.paintComponent(graphics, extent, screen, renderableScale, observer);
}
catch (Exception exception)
{
CategoryLogger.always().warn(exception, "paint");
}
}
/** {@inheritDoc} */
@Override
public EsriRenderable2d getSource() |
File |
Project |
Line |
nl/tudelft/simulation/dsol/model/inputparameters/InputParameterDoubleScalar.java |
DSOL core project |
113 |
nl/tudelft/simulation/dsol/model/inputparameters/InputParameterFloatScalar.java |
DSOL core project |
112 |
-Double.MAX_VALUE, Double.MAX_VALUE, false, false, format, 1.0));
add(new InputParameterUnit<U>("unit", "unit", "unit for the value", defaultValue.getDisplayUnit(), 2.0));
this.minimumValueSI = minimumValueSI;
this.maximumValueSI = maximumValueSI;
this.minIncluded = minIncluded;
this.maxIncluded = maxIncluded;
}
/**
* @return the unit sub-parameter
* @throws RuntimeException when parameter map has been corrupted and no unit parameter can be found
*/
@SuppressWarnings("unchecked")
public InputParameterUnit<U> getUnitParameter()
{
try
{
return (InputParameterUnit<U>) get("unit");
}
catch (InputParameterException exception)
{
throw new RuntimeException(
"Parameter map has been corrupted and no unit parameter can be found for field " + getShortName(),
exception);
}
}
/**
* @return the double sub-parameter
* @throws RuntimeException when parameter map has been corrupted and no value parameter can be found
*/
public InputParameterDouble getDoubleParameter() |
File |
Project |
Line |
nl/tudelft/simulation/dsol/swing/gui/inputparameters/InputFieldDistContinuous.java |
DSOL swing project |
57 |
nl/tudelft/simulation/dsol/swing/gui/inputparameters/InputFieldDistDiscrete.java |
DSOL swing project |
57 |
public InputFieldDistContinuous(final JPanel panel, final InputParameterDistContinuousSelection parameter)
{
super(parameter);
JLabel label = new JLabel(parameter.getShortName());
panel.add(label);
JPanel container = new JPanel();
container.setLayout(new BoxLayout(container, BoxLayout.Y_AXIS));
JPanel comboBoxPane = new JPanel(); // use FlowLayout
String[] selections = new String[parameter.getOptions().size()];
int defaultIndex = 0;
int i = 0;
for (String option : parameter.getOptions().keySet())
{
selections[i] = option.toString(); |
File |
Project |
Line |
nl/tudelft/simulation/naming/context/event/ContextEventProducerImpl.java |
Naming project for DSOL |
127 |
nl/tudelft/simulation/naming/context/event/ContextEventProducerImpl.java |
Naming project for DSOL |
145 |
context.addListener(this, ContextInterface.OBJECT_CHANGED_EVENT);
}
for (Entry<String, PatternListener> entry : this.regExpListenerMap.entrySet())
{
String path = (String) content[0] + ContextInterface.SEPARATOR + (String) content[1];
if (entry.getValue().getPattern().matcher(path).matches())
{
entry.getValue().getListener().notify(event);
}
}
}
else if (event.getType().equals(ContextInterface.OBJECT_REMOVED_EVENT)) |
File |
Project |
Line |
nl/tudelft/simulation/dsol/web/AbstractTestDemoServer.java |
DSOL gui project for Web interfaces |
372 |
nl/tudelft/simulation/dsol/web/AbstractTestDemoServer.java |
DSOL gui project for Web interfaces |
389 |
answer.append("<doubleScalar key='" + pds.getExtendedKey() + "' name='" + pds.getShortName() + "' description='"
+ pds.getDescription() + "'><value>" + val + "</value>\n");
for (String unit : units)
{
Unit<?> unitValue = pds.getUnitParameter().getOptions().get(unit);
if (unitValue.equals(pds.getUnitParameter().getValue()))
answer.append("<unit chosen='true'>" + unit + "</unit>\n");
else
answer.append("<unit chosen='false'>" + unit + "</unit>\n");
}
answer.append("</doubleScalar>\n"); |