Commit a9baf33b authored by Björn Richerzhagen's avatar Björn Richerzhagen
Browse files

Merge remote-tracking branch 'simonstrator/tm/vehicular-services'

parents 705984e5 f476dae3
......@@ -26,14 +26,15 @@ import java.util.List;
import java.util.Map;
import javax.swing.JComponent;
import javax.swing.JMenu;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
import de.tud.kom.p2psim.impl.topology.views.visualization.ui.SimControlPanel;
import de.tud.kom.p2psim.impl.topology.views.visualization.ui.VisualizationComponent;
import de.tud.kom.p2psim.impl.util.guirunner.Config;
/**
* This manager keeps track of all components that are added to the UI. It can
......@@ -148,8 +149,14 @@ public class ComponentVisManager {
* @param component
*/
public void toggleComponent(String name) {
boolean first = true;
for (JComponent component : nameToComponentMap.get(name)) {
toggleComponent(component);
if (first) {
Config.setValue(SimControlPanel.getConfMainPath(name), component.isVisible());
first = false;
}
}
}
......
......@@ -20,6 +20,7 @@
package de.tud.kom.p2psim.impl.topology.views.visualization.ui;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
......@@ -28,12 +29,16 @@ import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.JSpinner;
import javax.swing.JToggleButton;
import javax.swing.SpinnerNumberModel;
import javax.swing.SwingConstants;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
......@@ -43,6 +48,10 @@ import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.Visualiza
import de.tud.kom.p2psim.impl.topology.views.visualization.ComponentVisManager;
import de.tud.kom.p2psim.impl.topology.views.visualization.ComponentVisManager.VisInfo;
import de.tud.kom.p2psim.impl.topology.views.visualization.ComponentVisManager.VisualizationListener;
import de.tud.kom.p2psim.impl.util.guirunner.Config;
import de.tudarmstadt.maki.simonstrator.api.Event;
import de.tudarmstadt.maki.simonstrator.api.EventHandler;
import de.tudarmstadt.maki.simonstrator.api.Time;
/**
* Menu-Bar containing means to alter the simulation speed, pause and un-pause
......@@ -51,8 +60,9 @@ import de.tud.kom.p2psim.impl.topology.views.visualization.ComponentVisManager.V
* @author Bjoern Richerzhagen
* @version 1.0, 27.08.2012
*/
public class SimControlPanel extends JMenuBar
implements ActionListener, ChangeListener, VisualizationListener {
public class SimControlPanel extends JMenuBar implements ActionListener, ChangeListener, VisualizationListener {
private static final String CONF_PATH = "GUIRunner/Menu/Layels/";
private static final long serialVersionUID = -914578954798611308L;
......@@ -68,6 +78,8 @@ public class SimControlPanel extends JMenuBar
private ComponentVisManager visManager;
private JPanel runUntil;
public SimControlPanel(ComponentVisManager visManager) {
// super("Control");
this.visManager = visManager;
......@@ -84,6 +96,8 @@ public class SimControlPanel extends JMenuBar
this.add(getSpeedLabel());
this.add(Box.createHorizontalStrut(10));
this.add(getPlayPauseButton());
this.add(Box.createHorizontalStrut(10));
this.add(getRunUntil());
this.add(Box.createHorizontalGlue());
}
......@@ -119,7 +133,14 @@ public class SimControlPanel extends JMenuBar
@Override
public void visualizationAdded(VisInfo visInfo) {
JCheckBoxMenuItem checkBox = new JCheckBoxMenuItem(visInfo.getName());
checkBox.setSelected(visInfo.isActiveByDefault());
boolean isActive = visInfo.isActiveByDefault();
isActive = Config.getValue(getConfMainPath(visInfo.getName()), isActive);
checkBox.setSelected(isActive);
if (!isActive) {
getVisManager().deactivateComponent(visInfo.getName());
}
checkBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
......@@ -153,6 +174,53 @@ public class SimControlPanel extends JMenuBar
return speedslider;
}
protected JPanel getRunUntil() {
if (runUntil == null) {
runUntil = new JPanel();
runUntil.setBackground(new Color(0, 0, 0, 0));
JButton button = new JButton("Run until");
runUntil.add(button);
JSpinner spinner = new JSpinner(new SpinnerNumberModel(0, 0, Simulator.getEndTime() / Time.MINUTE, 1));
runUntil.add(spinner);
runUntil.add(new JLabel("min"));
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent pE) {
int value = (int)((double) spinner.getValue());
boolean wasPaused = isSimulatorPaused;
if (Time.getCurrentTime() < value * Time.MINUTE) {
if (wasPaused) {
unpauseSimulation();
}
double timeSkew = Simulator.getScheduler().getTimeSkew();
Simulator.getScheduler().setTimeSkew(0);
Event.scheduleWithDelay(value * Time.MINUTE - Time.getCurrentTime(), new EventHandler() {
@Override
public void eventOccurred(Object pContent, int pType) {
if (Simulator.getScheduler().getTimeSkew() == 0) {
Simulator.getScheduler().setTimeSkew(timeSkew);
}
if (wasPaused) {
pauseSimulation();
}
}
}, null, 0);
}
}
});
}
return runUntil;
}
protected JLabel getSpeedLabel() {
if (speedlabel == null) {
speedlabel = new JLabel("max");
......@@ -221,4 +289,22 @@ public class SimControlPanel extends JMenuBar
}
}
/**
* @return the confPath
*/
public static String getConfPath(String pName) {
String newName = "Layer_" + pName.replace(":", "").replaceAll(" ", "").replace("/", "_");
if (newName.length() > 1) {
return CONF_PATH + newName + "/Main";
}
return CONF_PATH + newName;
}
/**
* @return the confPath
*/
public static String getConfMainPath(String pName) {
return getConfPath(pName) + "/Main";
}
}
......@@ -27,6 +27,7 @@ import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.RenderingHints;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
......@@ -58,22 +59,26 @@ import de.tudarmstadt.maki.simonstrator.api.component.overlay.NodeInformation;
* @version 1.0, Jul 9, 2015
*/
public class NodeInfoComponentVis extends JComponent
implements VisualizationComponent {
implements VisualizationComponent {
protected Collection<NodeVis> nodes = new LinkedList<>();
private JMenu menu = new JMenu("Node Information");
private JMenu menu = new JMenu("Node Info");
protected boolean[] activeLayers = null;
protected boolean[] activeLayers = new boolean[0];
boolean hideInactiveNodes = false;
private final String name;
public <T extends HostComponent> NodeInfoComponentVis(
final Class<T> componentClass) {
setBounds(0, 0, VisualizationInjector.getWorldX(),
VisualizationInjector.getWorldY());
setOpaque(true);
setVisible(true);
this.name = componentClass.getSimpleName();
menu.setText("Info: "+name);
Event.scheduleWithDelay(1 * Time.MICROSECOND, new EventHandler() {
@Override
......@@ -108,7 +113,7 @@ public class NodeInfoComponentVis extends JComponent
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
boolean first = true;
for (NodeVis vis : nodes) {
for (NodeVis vis : new ArrayList<>(nodes)) {
vis.draw(g2);
if (first) {
first = false;
......@@ -174,13 +179,13 @@ public class NodeInfoComponentVis extends JComponent
private final Color[] tuColors = {
new Color(93, 133, 195), // 1a
new Color(80, 182, 149), // 3a
// new Color(221,223,72), // 5a
// new Color(221,223,72), // 5a
new Color(248,186,60), // 7a
new Color(233,80,62), // 9a
new Color(128, 69, 151), // 11a
new Color(0, 78, 138), // 1c
new Color(0, 136, 119), // 3c
// new Color(177, 189, 0), // 5c
// new Color(177, 189, 0), // 5c
new Color(210, 135, 0), // 7c
new Color(185, 15, 34), // 9c
new Color(97, 28, 115), // 11c
......@@ -207,12 +212,12 @@ public class NodeInfoComponentVis extends JComponent
* http://stackoverflow.com/questions/2355157/dynamically-
* creating-colors-with-different-brightness
*/
// float hsbVals[] = Color.RGBtoHSB(baseColor.getRed(),
// baseColor.getGreen(), baseColor.getBlue(), null);
// float hsbVals[] = Color.RGBtoHSB(baseColor.getRed(),
// baseColor.getGreen(), baseColor.getBlue(), null);
for (int i = 0; i < dimensionSize; i++) {
float hue = i / (float) dimensionSize;
// colors[dim][i] = Color.getHSBColor(hue, hsbVals[1],
// hsbVals[2]);
// colors[dim][i] = Color.getHSBColor(hue, hsbVals[1],
// hsbVals[2]);
colors[dim][i] = tuColors[i];
}
}
......@@ -234,7 +239,7 @@ public class NodeInfoComponentVis extends JComponent
g2.setStroke(new BasicStroke(3));
for (int color = 0; color < segments; color++) {
if (!activeLayers[color]) {
if (activeLayers.length <= color || !activeLayers[color]) {
continue;
}
g2.setColor(Color.DARK_GRAY);
......@@ -312,7 +317,7 @@ public class NodeInfoComponentVis extends JComponent
@Override
public String getDisplayName() {
return "Node Information";
return "Info: "+name;
}
}
......@@ -48,6 +48,7 @@ import de.tud.kom.p2psim.impl.util.db.metric.Measurement;
import de.tud.kom.p2psim.impl.util.db.metric.MeasurementPair;
import de.tud.kom.p2psim.impl.util.db.metric.MeasurementPairList;
import de.tud.kom.p2psim.impl.util.db.metric.MeasurementSingle;
import de.tud.kom.p2psim.impl.util.db.metric.MeasurementSpatial;
import de.tud.kom.p2psim.impl.util.db.metric.MeasurementStatistic;
import de.tud.kom.p2psim.impl.util.db.metric.Metric;
import de.tud.kom.p2psim.impl.util.db.metric.MetricDescription;
......@@ -155,6 +156,7 @@ public class DAO {
cfg.addAnnotatedClass(MeasurementPair.class);
cfg.addAnnotatedClass(MeasurementPairList.class);
cfg.addAnnotatedClass(MeasurementSingle.class);
cfg.addAnnotatedClass(MeasurementSpatial.class);
cfg.addAnnotatedClass(MeasurementStatistic.class);
cfg.addAnnotatedClass(Metric.class);
cfg.addAnnotatedClass(MetricDescription.class);
......
......@@ -32,6 +32,7 @@ import de.tud.kom.p2psim.impl.util.db.metric.Measurement;
import de.tud.kom.p2psim.impl.util.db.metric.MeasurementPair;
import de.tud.kom.p2psim.impl.util.db.metric.MeasurementPairList;
import de.tud.kom.p2psim.impl.util.db.metric.MeasurementSingle;
import de.tud.kom.p2psim.impl.util.db.metric.MeasurementSpatial;
import de.tud.kom.p2psim.impl.util.db.metric.MeasurementStatistic;
import de.tud.kom.p2psim.impl.util.db.metric.Metric;
import de.tud.kom.p2psim.impl.util.db.metric.MetricDescription;
......@@ -102,6 +103,31 @@ public class MeasurementDAO extends DAO {
addToPersistQueue(measurement);
}
/**
* Store a single measurement for a host, tied to a specific location.
*
* @param metricDesc
* @param hostId
* @param time
* @param value
* @param locationX
* @param locationY
*/
public static void storeSpatialMeasurement(MetricDescription metricDesc,
long hostId, long time, double value, int locationX,
int locationY) {
if (inactive) {
return;
}
Metric metric = MetricDAO.lookupSpatialMetric(metricDesc);
HostMetric hostMetric = HostMetricDAO.lookupHostMetric(metric, hostId);
MeasurementSpatial measurement = new MeasurementSpatial(time, value,
hostMetric, locationX, locationY);
addToPersistQueue(measurement);
}
/**
* Stores for a series of measurements the given values for a host. The
* given values are a statistical representation of the series of
......
......@@ -27,7 +27,7 @@ public class MetricDAO extends DAO {
/**
* Identifier for a single metric
*/
SINGLE,
SINGLE, SPATIAL,
/**
* Identifier for an aggregate metric
*/
......@@ -63,6 +63,16 @@ public class MetricDAO extends DAO {
return lookupMetric(metricDesc, MetricType.SINGLE);
}
/** Retrieve a {@link Metric} object for the given MetricDescription
* for spatial value metrics.
*
* If there is no matching Metric object, it is created, persisted, and cached
* automatically.
*/
public static Metric lookupSpatialMetric(MetricDescription metricDesc) {
return lookupMetric(metricDesc, MetricType.SPATIAL);
}
/** Retrieve a {@link Metric} object for the given MetricDescription
* for pair value metrics.
*
......
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package de.tud.kom.p2psim.impl.util.db.metric;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
/**
* A single measurement, but with an assigned location.
*
* @author Bjoern Richerzhagen
*/
@Entity
@Table(name = "measurements_spatial", indexes = {
@Index(columnList = "time", name = "time"),
@Index(columnList = "hostMetricId", name = "hostMetricId") })
public class MeasurementSpatial {
/**
* A unique Id, will be set by the database
*/
@SuppressWarnings("unused")
@Id
@GeneratedValue()
private int id;
/**
* The simulation time of this measurement
*/
@SuppressWarnings("unused")
private long time;
/**
* The value for this measurement
*/
@SuppressWarnings("unused")
@Column(nullable = true)
private Double value;
@Column(nullable = true, name = "[locationX]")
private Integer locationX;
@Column(nullable = true, name = "[locationY]")
private Integer locationY;
/**
* The mapping Object of this measurement to the {@link Metric}-Object,
* which describes this metric.
*/
@SuppressWarnings("unused")
@ManyToOne
@JoinColumn(name = "hostMetricId")
private HostMetric hostMetric;
/**
* Creates a {@link MeasurementSingle}-Object with the given parameters. If
* value has the value infinity or NaN, then will be set this value to null.
*
* @param time
* The simulation time as date to this measurement
* @param value
* The value for this measurement
* @param statistic
* The reference to the {@link Metric}-Object, which describes
* this metric. Is used for the mapping.
*/
public MeasurementSpatial(long time, Double value, HostMetric hostMetric, Integer locationX, Integer locationY) {
super();
this.time = time;
this.hostMetric = hostMetric;
// check for infinity or NaN
this.value = checkForSpecialNumbers(value);
this.locationX = locationX;
this.locationY = locationY;
}
/**
* Check for special numbers, like infinity or NaN. If the given value is
* equals this numbers then will be return null, otherwise will be returned
* the given value.
*
* @param value
* The value, which should be checked.
* @return The value or null, if it is a special number.
*/
private Double checkForSpecialNumbers(Double value) {
if (value == null)
return value;
if (value.equals(Double.NEGATIVE_INFINITY)
|| value.equals(Double.POSITIVE_INFINITY)
|| value.equals(Double.NaN)) {
return null;
} else {
return value;
}
}
}
......@@ -27,6 +27,7 @@ import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
......@@ -113,8 +114,15 @@ public class GUIRunner extends JFrame implements WindowListener, KeyListener {
int winWidth = Config.getValue(CONF_PATH_WIDTH, 600);
int winHeight = Config.getValue(CONF_PATH_HEIGHT, 600);
this.setSize(winWidth, winHeight);
this.setLocation(new Point(Config.getValue(CONF_PATH_POSX, 0), Config
.getValue(CONF_PATH_POSY, 0)));
Point point = new Point(Config.getValue(CONF_PATH_POSX, 0), Config
.getValue(CONF_PATH_POSY, 0));
if (point.getX() >= 0 && point.getY() >= 0
&& Toolkit.getDefaultToolkit().getScreenSize().getWidth()
< point.getX() - winWidth
&& Toolkit.getDefaultToolkit().getScreenSize().getHeight()
< point.getY() - winHeight) {
this.setLocation(point);
}
this.setLayout(new BorderLayout());
......
......@@ -55,7 +55,28 @@ public class RunnerController implements ActionListener {
* @param configFile
*/
private void runSimulator() {
new SimulationThread(selectedFile, det.getChosenSeed()).start();
SimulationThread simulationThread = new SimulationThread(selectedFile, det.getChosenSeed());
simulationThread.start();
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
while (true) {
StackTraceElement[] stackTrace = simulationThread.getStackTrace();
System.out.println();
System.out.println();
for (int i = 0; i < stackTrace.length; i++) {
System.out.println(stackTrace[i]);
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
}
}
});
// thread.start();
}
public void setLastOpened(LastOpened lastOpened) {
......
Markdown is supported
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