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
/*
* 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.topology.views.fiveg.models;
/**
* An exponential model
* exp(u) = a * e^(c * (u - d)) + b
* @author Marc Schiller
* @version 1.0, 15 Dec 2016
*/
public class ExponentialModel extends AbstractModel {
// exp(u) = a * e ^(c * u + d) + b
private double a = 1;
private double b = 0;
private double c = 1;
private double d = 0;
public void setA(double a) {
this.a = a;
}
public void setB(double b) {
this.b = b;
}
public void setC(double c) {
this.c = c;
}
public void setD(double d) {
this.d = d;
}
@Override
public long getLong(int users) {
return (long) getDouble(users);
}
@Override
public double getDouble(int users) {
return this.a * Math.exp(this.c * (users - this.d)) + this.b;
}
@Override
public String toString() {
return "Exponential Model: exp(u) = " + this.a + " * e^(" + this.c + " * (u - " + this.d + ")) + " + this.b;
}
}
/*
* 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.topology.views.fiveg.models;
/**
* An exponential model
* exp(u) = a * e^(c * (u - d)) + b
* @author Marc Schiller
* @version 1.0, 15 Dec 2016
*/
public class ExponentialModel extends AbstractModel {
// exp(u) = a * e ^(c * u + d) + b
private double a = 1;
private double b = 0;
private double c = 1;
private double d = 0;
public void setA(double a) {
this.a = a;
}
public void setB(double b) {
this.b = b;
}
public void setC(double c) {
this.c = c;
}
public void setD(double d) {
this.d = d;
}
@Override
public long getLong(int users) {
return (long) getDouble(users);
}
@Override
public double getDouble(int users) {
return this.a * Math.exp(this.c * (users - this.d)) + this.b;
}
@Override
public String toString() {
return "Exponential Model: exp(u) = " + this.a + " * e^(" + this.c + " * (u - " + this.d + ")) + " + this.b;
}
}
/*
* 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.topology.views.fiveg.models;
/**
* Linear Model
* lin(u) = a * u + b
* @author Marc Schiller
* @version 1.0, 15 Dec 2016
*/
public class LinearModel extends AbstractModel {
private double a = 1;
private double b = 0;
public void setA(double a) {
this.a = a;
}
public void setB(double b) {
this.b = b;
}
@Override
public long getLong(int users) {
return (long) (this.a * users + this.b);
}
@Override
public double getDouble(int users) {
return this.a * users + this.b;
}
public String toString() {
return "Linear Model: lin(u) = " + a + " * u + " + b;
}
}
/*
* 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.topology.views.fiveg.models;
/**
* Linear Model
* lin(u) = a * u + b
* @author Marc Schiller
* @version 1.0, 15 Dec 2016
*/
public class LinearModel extends AbstractModel {
private double a = 1;
private double b = 0;
public void setA(double a) {
this.a = a;
}
public void setB(double b) {
this.b = b;
}
@Override
public long getLong(int users) {
return (long) (this.a * users + this.b);
}
@Override
public double getDouble(int users) {
return this.a * users + this.b;
}
public String toString() {
return "Linear Model: lin(u) = " + a + " * u + " + b;
}
}
/*
* 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.topology.views.fiveg.models;
/**
* Logarithmic model
* log(u) = a * ln(c * (u - d)) + b
* @author Marc Schiller
* @version 1.0, 15 Dec 2016
*/
public class LogarithmicModel extends AbstractModel {
private double a = 1;
private double b = 0;
private double c = 1;
private double d = 0;
public void setA(double a) {
this.a = a;
}
public void setB(double b) {
this.b = b;
}
public void setC(double c) {
this.c = c;
}
public void setD(double d) {
this.d = d;
}
@Override
public long getLong(int users) {
return (long) getDouble(users);
}
@Override
public double getDouble(int users) {
double tmp = this.a * Math.log(this.c * (users - this.d)) + this.b;
if(tmp < 0) {
return 0;
} else {
return tmp;
}
}
@Override
public String toString() {
return "Logarithmic Model: log(u) = " + this.a + " * ln(" + this.c + " * (u - " + this.d + ")) + " + this.b;
}
}
/*
* 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.topology.views.fiveg.models;
/**
* Logarithmic model
* log(u) = a * ln(c * (u - d)) + b
* @author Marc Schiller
* @version 1.0, 15 Dec 2016
*/
public class LogarithmicModel extends AbstractModel {
private double a = 1;
private double b = 0;
private double c = 1;
private double d = 0;
public void setA(double a) {
this.a = a;
}
public void setB(double b) {
this.b = b;
}
public void setC(double c) {
this.c = c;
}
public void setD(double d) {
this.d = d;
}
@Override
public long getLong(int users) {
return (long) getDouble(users);
}
@Override
public double getDouble(int users) {
double tmp = this.a * Math.log(this.c * (users - this.d)) + this.b;
if(tmp < 0) {
return 0;
} else {
return tmp;
}
}
@Override
public String toString() {
return "Logarithmic Model: log(u) = " + this.a + " * ln(" + this.c + " * (u - " + this.d + ")) + " + this.b;
}
}
# 5G Models
> **IMPORTANT!** The colors of each segment reflect the status *per* characteristic not the global status of this segment. If a segment is overloaded the text "overload" is shown.
This module allows to add transmission models to each segment of the map to accommodate different behaviors of wireless network transmission technologies. It enables the developer to define different models for **Latency**, **Bandwidth** and **Drop Rate** (called *characteristics*), for **Upload** and **Download** and for every **Segment**.
Whenever one of the characteristic for a client is requested every other characteristic is evaluated to check if one of them is overloaded such that no connection is possible. The thresholds for the overload are defined in [`FiveGTopologyDatabase.Entry`](https://dev.kom.e-technik.tu-darmstadt.de/gitlab/simonstrator/simonstrator-peerfactsim/blob/nr/monitoring-model/src/de/tud/kom/p2psim/impl/topology/views/fiveg/ModelBasedSegmentDatabase.java#L182)
## Configuration / Setup
The models are enabled by changing the `Database` of the `FiveGTopologyView` to `ModelBasedSegmentDatabase`. For a minimal config the `ModelBasedSegmentDatabase` needs at least a model for each characteristic. Therefore, the models are passed to the database. Each model has its specific defaults described [here](#models). In addition to that every model has parameters for `direction` (*UPLOAD*, *DOWNLOAD* or **BOTH**), `parameterType` (*BANDWIDTH*, *LATENCY* and *DROPRATE*), `segmentID` (to which segmentID this model is applied - **-1** means that it is applied to every segment) and debug (TRUE or **FALSE**). **Bold** values mark the defaults.
## Examples
> **IMPORTANT!** For every characteristic there needs to be one and *only one* default model.
### General Setup
Here the general setup for the model based segments is shown. The models are placed inside the database element.
```xml
<View class="de.tud.kom.p2psim.impl.topology.views.FiveGTopologyView" phy="UMTS" cloudGroups="Cloud">
<Database class="de.tud.kom.p2psim.impl.topology.views.fiveg.ModelBasedSegmentDatabase" enableVis="$ENABLE_VIS" gridSize="$CELL_GRID_SIZE">
<!-- Place model definitions here -->
</Database>
</View>
```
### A default constant model for every characteristic
```xml
<Model class="de.tud.kom.p2psim.impl.topology.views.fiveg.models.ConstantModel" c="300" parameterType="BANDWIDTH" />
<Model class="de.tud.kom.p2psim.impl.topology.views.fiveg.models.ConstantModel" c="5" parameterType="LATENCY" />
<Model class="de.tud.kom.p2psim.impl.topology.views.fiveg.models.ConstantModel" c="0.1" parameterType="DROPRATE" />
```
For every segment the bandwidth is 300 kBit/s, the latency 5 ms and drop rate is 1% (0.1) in both directions.
### Advanced setup
```xml
<Model class="de.tud.kom.p2psim.impl.topology.views.fiveg.models.ConstantModel" c="300" parameterType="BANDWIDTH" direction="UPLOAD" />
<Model class="de.tud.kom.p2psim.impl.topology.views.fiveg.models.ConstantModel" c="10" parameterType="BANDWIDTH" direction="DOWNLOAD" />
<Model class="de.tud.kom.p2psim.impl.topology.views.fiveg.models.LogarithmicModel" a="3" b="10" c="-5" d="-10" parameterType="LATENCY" />
<Model class="de.tud.kom.p2psim.impl.topology.views.fiveg.models.ExponentialModel" parameterType="DROPRATE" />
<Model class="de.tud.kom.p2psim.impl.topology.views.fiveg.models.CutoffModel" parameterType="BANDWIDTH" segmentID="123" debug="TRUE" />
```
Every segment has 300 kBit/s upload bandwidth and 10 kBit/s download bandwidth with a constant model. The latency of every segment is equal for up- and download and is based on a logarithmic model with $`a=3`$, $`b=10`$, $`c=-5`$ and $`d=-10`$. A default exponential model is applied on the latency. At last there is a cut-off model for the bandwidth for the segment with the ID `123`. It also shows the debug graph.
## Models
* [Constant](#constant)
* [Linear](#linear)
* [Exponential](#exponential)
* [Logarithmic](#logarithmic)
* [Cut-Off](#cut-off)
### Constant
![](https://dev.kom.e-technik.tu-darmstadt.de/gitlab/simonstrator/simonstrator-peerfactsim/raw/nr/monitoring-model/src/de/tud/kom/p2psim/impl/topology/views/fiveg/models/img/constant.png)
$`c(u)=C`$
> The constant model applies the the same constant value `c` to the selected characteristic regardless of the number of hosts in the segment.
*Model-specific Parameters*:
`c` the constant value (*default* `0`)
### Linear
![](https://dev.kom.e-technik.tu-darmstadt.de/gitlab/simonstrator/simonstrator-peerfactsim/raw/nr/monitoring-model/src/de/tud/kom/p2psim/impl/topology/views/fiveg/models/img/linear.png)
$`lin(u)=a*u+b`$
*Model-specific Parameters*:
`a` the slope (*default* `1`)
`b` y-axis intersection (*default* `0`)
### Exponential
![](https://dev.kom.e-technik.tu-darmstadt.de/gitlab/simonstrator/simonstrator-peerfactsim/raw/nr/monitoring-model/src/de/tud/kom/p2psim/impl/topology/views/fiveg/models/img/exponential.png)
$`exp(u)=a*e^{c(u-d)}+b`$
*Model-specific Parameters*:
`a` scaling factor (*default* `1`)
`b` y-axis offset (*default* `0`)
`c` exponent scaling (*default* `1`)
`d` x-axis offset (*default* `0`)
### Logarithmic
![](https://dev.kom.e-technik.tu-darmstadt.de/gitlab/simonstrator/simonstrator-peerfactsim/raw/nr/monitoring-model/src/de/tud/kom/p2psim/impl/topology/views/fiveg/models/img/logarithmic.png)
$`log(u)=a*ln(c(u-d))+b`$
*Model-specific Parameters*:
`a` scaling factor (*default* `1`)
`b` y-axis offset (*default* `0`)
`c` logarithm scaling (*default* `1`)
`d` x-axis offset (*default* `0`)
### Cut-Off
![](https://dev.kom.e-technik.tu-darmstadt.de/gitlab/simonstrator/simonstrator-peerfactsim/raw/nr/monitoring-model/src/de/tud/kom/p2psim/impl/topology/views/fiveg/models/img/cutoff.png)
$`cut(u)=a*\theta(c(u-d))+b`$
> The cut-off model is based on the [Heaviside step function](https://en.wikipedia.org/wiki/Heaviside_step_function).
*Model-specific Parameters*:
`a` scaling factor (*default* `1`)
`b` y-axis offset (*default* `0`)
`c` scaling (*default* `1`)
# 5G Models
> **IMPORTANT!** The colors of each segment reflect the status *per* characteristic not the global status of this segment. If a segment is overloaded the text "overload" is shown.
This module allows to add transmission models to each segment of the map to accommodate different behaviors of wireless network transmission technologies. It enables the developer to define different models for **Latency**, **Bandwidth** and **Drop Rate** (called *characteristics*), for **Upload** and **Download** and for every **Segment**.
Whenever one of the characteristic for a client is requested every other characteristic is evaluated to check if one of them is overloaded such that no connection is possible. The thresholds for the overload are defined in [`FiveGTopologyDatabase.Entry`](https://dev.kom.e-technik.tu-darmstadt.de/gitlab/simonstrator/simonstrator-peerfactsim/blob/nr/monitoring-model/src/de/tud/kom/p2psim/impl/topology/views/fiveg/ModelBasedSegmentDatabase.java#L182)
## Configuration / Setup
The models are enabled by changing the `Database` of the `FiveGTopologyView` to `ModelBasedSegmentDatabase`. For a minimal config the `ModelBasedSegmentDatabase` needs at least a model for each characteristic. Therefore, the models are passed to the database. Each model has its specific defaults described [here](#models). In addition to that every model has parameters for `direction` (*UPLOAD*, *DOWNLOAD* or **BOTH**), `parameterType` (*BANDWIDTH*, *LATENCY* and *DROPRATE*), `segmentID` (to which segmentID this model is applied - **-1** means that it is applied to every segment) and debug (TRUE or **FALSE**). **Bold** values mark the defaults.
## Examples
> **IMPORTANT!** For every characteristic there needs to be one and *only one* default model.
### General Setup
Here the general setup for the model based segments is shown. The models are placed inside the database element.
```xml
<View class="de.tud.kom.p2psim.impl.topology.views.FiveGTopologyView" phy="UMTS" cloudGroups="Cloud">
<Database class="de.tud.kom.p2psim.impl.topology.views.fiveg.ModelBasedSegmentDatabase" enableVis="$ENABLE_VIS" gridSize="$CELL_GRID_SIZE">
<!-- Place model definitions here -->
</Database>
</View>
```
### A default constant model for every characteristic
```xml
<Model class="de.tud.kom.p2psim.impl.topology.views.fiveg.models.ConstantModel" c="300" parameterType="BANDWIDTH" />
<Model class="de.tud.kom.p2psim.impl.topology.views.fiveg.models.ConstantModel" c="5" parameterType="LATENCY" />
<Model class="de.tud.kom.p2psim.impl.topology.views.fiveg.models.ConstantModel" c="0.1" parameterType="DROPRATE" />
```
For every segment the bandwidth is 300 kBit/s, the latency 5 ms and drop rate is 1% (0.1) in both directions.
### Advanced setup
```xml
<Model class="de.tud.kom.p2psim.impl.topology.views.fiveg.models.ConstantModel" c="300" parameterType="BANDWIDTH" direction="UPLOAD" />
<Model class="de.tud.kom.p2psim.impl.topology.views.fiveg.models.ConstantModel" c="10" parameterType="BANDWIDTH" direction="DOWNLOAD" />
<Model class="de.tud.kom.p2psim.impl.topology.views.fiveg.models.LogarithmicModel" a="3" b="10" c="-5" d="-10" parameterType="LATENCY" />
<Model class="de.tud.kom.p2psim.impl.topology.views.fiveg.models.ExponentialModel" parameterType="DROPRATE" />
<Model class="de.tud.kom.p2psim.impl.topology.views.fiveg.models.CutoffModel" parameterType="BANDWIDTH" segmentID="123" debug="TRUE" />
```
Every segment has 300 kBit/s upload bandwidth and 10 kBit/s download bandwidth with a constant model. The latency of every segment is equal for up- and download and is based on a logarithmic model with $`a=3`$, $`b=10`$, $`c=-5`$ and $`d=-10`$. A default exponential model is applied on the latency. At last there is a cut-off model for the bandwidth for the segment with the ID `123`. It also shows the debug graph.
## Models
* [Constant](#constant)
* [Linear](#linear)
* [Exponential](#exponential)
* [Logarithmic](#logarithmic)
* [Cut-Off](#cut-off)
### Constant
![](https://dev.kom.e-technik.tu-darmstadt.de/gitlab/simonstrator/simonstrator-peerfactsim/raw/nr/monitoring-model/src/de/tud/kom/p2psim/impl/topology/views/fiveg/models/img/constant.png)
$`c(u)=C`$
> The constant model applies the the same constant value `c` to the selected characteristic regardless of the number of hosts in the segment.
*Model-specific Parameters*:
`c` the constant value (*default* `0`)
### Linear
![](https://dev.kom.e-technik.tu-darmstadt.de/gitlab/simonstrator/simonstrator-peerfactsim/raw/nr/monitoring-model/src/de/tud/kom/p2psim/impl/topology/views/fiveg/models/img/linear.png)
$`lin(u)=a*u+b`$
*Model-specific Parameters*:
`a` the slope (*default* `1`)
`b` y-axis intersection (*default* `0`)
### Exponential
![](https://dev.kom.e-technik.tu-darmstadt.de/gitlab/simonstrator/simonstrator-peerfactsim/raw/nr/monitoring-model/src/de/tud/kom/p2psim/impl/topology/views/fiveg/models/img/exponential.png)
$`exp(u)=a*e^{c(u-d)}+b`$
*Model-specific Parameters*:
`a` scaling factor (*default* `1`)
`b` y-axis offset (*default* `0`)
`c` exponent scaling (*default* `1`)
`d` x-axis offset (*default* `0`)
### Logarithmic
![](https://dev.kom.e-technik.tu-darmstadt.de/gitlab/simonstrator/simonstrator-peerfactsim/raw/nr/monitoring-model/src/de/tud/kom/p2psim/impl/topology/views/fiveg/models/img/logarithmic.png)
$`log(u)=a*ln(c(u-d))+b`$
*Model-specific Parameters*:
`a` scaling factor (*default* `1`)
`b` y-axis offset (*default* `0`)
`c` logarithm scaling (*default* `1`)
`d` x-axis offset (*default* `0`)
### Cut-Off
![](https://dev.kom.e-technik.tu-darmstadt.de/gitlab/simonstrator/simonstrator-peerfactsim/raw/nr/monitoring-model/src/de/tud/kom/p2psim/impl/topology/views/fiveg/models/img/cutoff.png)
$`cut(u)=a*\theta(c(u-d))+b`$
> The cut-off model is based on the [Heaviside step function](https://en.wikipedia.org/wiki/Heaviside_step_function).
*Model-specific Parameters*:
`a` scaling factor (*default* `1`)
`b` y-axis offset (*default* `0`)
`c` scaling (*default* `1`)
`d` x-axis offset (*default* `0`)
\ No newline at end of file
/*
* 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.topology.views.fiveg.utils;
/**
* Enumeration for defining the direction (Up,Down or Both) for a model.
* @author Marc Schiller
* @version 1.0, 15 Dec 2016
*/
public enum Direction {
BOTH(),
UPLOAD(),
DOWNLOAD();
public static String printTypes() {
Direction[] types = values();
String out = "";
for (int i = 0; i < types.length; i++) {
if (i > 0) {
out += ", ";
}
out += types[i].name();
}
return out;
}
}
/*
* 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.topology.views.fiveg.utils;
/**
* Enumeration for defining the direction (Up,Down or Both) for a model.
* @author Marc Schiller
* @version 1.0, 15 Dec 2016
*/
public enum Direction {
BOTH(),
UPLOAD(),
DOWNLOAD();
public static String printTypes() {
Direction[] types = values();
String out = "";
for (int i = 0; i < types.length; i++) {
if (i > 0) {
out += ", ";
}
out += types[i].name();
}
return out;
}
}
/*
* 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.topology.views.fiveg.utils;
/**
* Enumeration for defining the type (Bandwidth, Drop Rate, Latency) for a model.
* @author Marc Schiller
* @version 1.0, 15 Dec 2016
*/
public enum ParameterType {
BANDWIDTH(),
DROPRATE(),
LATENCY();
public static String printTypes() {
ParameterType[] types = values();
String out = "";
for (int i = 0; i < types.length; i++) {
if (i > 0) {
out += ", ";
}
out += types[i].name();
}
return out;
}
}
/*
* 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.topology.views.fiveg.utils;
/**
* Enumeration for defining the type (Bandwidth, Drop Rate, Latency) for a model.
* @author Marc Schiller
* @version 1.0, 15 Dec 2016
*/
public enum ParameterType {
BANDWIDTH(),
DROPRATE(),
LATENCY();
public static String printTypes() {
ParameterType[] types = values();
String out = "";
for (int i = 0; i < types.length; i++) {
if (i > 0) {
out += ", ";
}
out += types[i].name();
}
return out;
}
}
......@@ -2,17 +2,17 @@
* 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/>.
*
......@@ -26,20 +26,21 @@ 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
* be used to add/remove named component to/from the UI and allows to change the
* components visibility based on their name or component reference.
*
*
* @author Fabio Zöllner
* @version 1.0, 12.07.2012
*/
......@@ -63,7 +64,7 @@ public class ComponentVisManager {
/**
* Adds the given component to the visualization
*
*
* @param name
* @param priority
* @param component
......@@ -74,7 +75,7 @@ public class ComponentVisManager {
/**
* Adds the given component to the visualization
*
*
* @param name
* @param priority
* @param component
......@@ -85,7 +86,7 @@ public class ComponentVisManager {
/**
* Adds the component of the given VisInfo to the visualization
*
*
* @param visInfo
*/
public void addComponent(VisInfo visInfo) {
......@@ -108,7 +109,7 @@ public class ComponentVisManager {
/**
* Removes the given component from the visualization
*
*
* @param name
*/
public void removeComponent(String name) {
......@@ -124,7 +125,7 @@ public class ComponentVisManager {
/**
* Removes the given component from the visualization
*
*
* @param component
*/
public void removeComponent(JComponent component) {
......@@ -144,20 +145,26 @@ public class ComponentVisManager {
/**
* Toggles the visibility of a component.
*
*
* @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;
}
}
}
/**
* Toggles the visibility of a component.
*
*
* It's the same as component.setVisible(!component.isVisible());
*
*
* @param component
*/
public void toggleComponent(JComponent component) {
......@@ -178,7 +185,7 @@ public class ComponentVisManager {
/**
* Sets the given component invisible.
*
*
* @param component
*/
public void deactivateComponent(String name) {
......@@ -189,9 +196,9 @@ public class ComponentVisManager {
/**
* Sets the given component invisible.
*
*
* It's the same as component.setVisible(false);
*
*
* @param component
*/
public void deactivateComponent(JComponent component) {
......@@ -204,7 +211,7 @@ public class ComponentVisManager {
/**
* Sets the given component visible.
*
*
* @param component
*/
public void activateComponent(String name) {
......@@ -215,9 +222,9 @@ public class ComponentVisManager {
/**
* Sets the given component visible.
*
*
* It's the same as component.setVisible(true);
*
*
* @param component
*/
public void activateComponent(JComponent component) {
......@@ -229,7 +236,7 @@ public class ComponentVisManager {
/**
* Adds a visualization listener to the manager
*
*
* @param listener
*/
public void addVisualizationListener(VisualizationListener listener) {
......@@ -238,7 +245,7 @@ public class ComponentVisManager {
/**
* Removes a visualization listener from the manager
*
*
* @param listener
*/
public void removeVisualizationListener(VisualizationListener listener) {
......@@ -259,9 +266,9 @@ public class ComponentVisManager {
/**
* Bean that holds the name, priority and reference to the component.
*
*
* Note: The equals and hashCode methods omit the priority.
*
*
* @author Fabio Zöllner
* @version 1.0, 12.07.2012
*/
......@@ -290,7 +297,7 @@ public class ComponentVisManager {
/**
* Recommended way: use the {@link VisualizationComponent}
*
*
* @param comp
*/
public VisInfo(VisualizationComponent comp) {
......@@ -308,7 +315,7 @@ public class ComponentVisManager {
/**
* Recommended container for custom visualizations.
*
*
* @return may be null (legacy visualizations)
*/
public VisualizationComponent getVisualizationComponent() {
......@@ -363,7 +370,7 @@ public class ComponentVisManager {
/**
* A listener interface that is used by the ComponentVisManager to notify
* interested parties about added or removed visualization components.
*
*
* @author Fabio Zöllner
* @version 1.0, 12.07.2012
*/
......@@ -375,7 +382,7 @@ public class ComponentVisManager {
/**
* Returns a list of currently visible and invisible components.
*
*
* @return
*/
public Collection<VisInfo> getVisualizations() {
......
/*
* 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.topology.views.visualization.ui;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Map;
import javax.swing.*;
import javax.swing.border.BevelBorder;
import com.google.common.collect.Maps;
/**
* JFrame which holds all the live plots.
*
* @author Unknown
*
* 21.03.2017 Clemens Krug:
* Changed this class up quite a bit because when one would
* add more and more metrics to the visualisation, they would get unreadable small. Reworked this
* class so the charts will allways fill the view if theres is space, but if you add do many plots
* they will stay add a minimum height of 250 px and a scrollbar will be added instead.
*/
public class PlottingView extends JFrame {
private static final int VIEW_WIDTH = 900;
private static final int VIEW_HEIGHT = 800;
private static final int PLOT_HEIGHT_MIN = 250;
private static final Color PLOT_BACKGROUND_COLOR = Color.WHITE;
private Map<String, XYChart> nameToPlotMap = Maps.newLinkedHashMap();
private JPanel plotBox;
private JScrollPane spane;
public PlottingView(String name) {
setTitle(name);
setVisible(true);
buildUI();
}
private void buildUI() {
plotBox = new PlotBox();
plotBox.setLayout(new BoxLayout(plotBox, BoxLayout.Y_AXIS));
plotBox.setBackground(PLOT_BACKGROUND_COLOR);
plotBox.setBorder(BorderFactory.createEtchedBorder());
spane = new JScrollPane(plotBox);
add(spane);
setSize(VIEW_WIDTH, VIEW_HEIGHT);
setPreferredSize(new Dimension(VIEW_WIDTH, VIEW_HEIGHT));
}
public XYChart createPlot(String name, String seriesName) {
XYChart plot = new XYChart(PLOT_BACKGROUND_COLOR, name, seriesName);
JPanel chartPanel = plot.getChartPanel();
chartPanel = wrapInCollabsable(chartPanel, name);
plotBox.add(chartPanel);
plotBox.repaint();
spane.validate();
nameToPlotMap.put(name, plot);
return plot;
}
public XYChart createPlot(String name) {
return createPlot(name, name);
}
private JPanel wrapInCollabsable(JPanel chartPanel, String title) {
final JPanel innerPanel = new JPanel();
innerPanel.setLayout(new BorderLayout());
innerPanel.add(new JLabel(" "), BorderLayout.WEST);
innerPanel.add(chartPanel, BorderLayout.CENTER);
innerPanel.setBackground(PLOT_BACKGROUND_COLOR);
final JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.setBackground(PLOT_BACKGROUND_COLOR);
Box header = Box.createHorizontalBox();
header.setBackground(PLOT_BACKGROUND_COLOR);
final JLabel collapseButton = new JLabel("-");
Dimension buttonSize = new Dimension(11, 11);
collapseButton.setBackground(PLOT_BACKGROUND_COLOR);
collapseButton.setPreferredSize(buttonSize);
collapseButton.setMaximumSize(buttonSize);
collapseButton.setMinimumSize(buttonSize);
collapseButton.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
collapseButton.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent arg0) {
collapseButton.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
}
@Override
public void mouseReleased(MouseEvent arg0) {
collapseButton.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
if (collapseButton.getText().equals("-")) {
collapseButton.setText("+");
panel.remove(innerPanel);
panel.setMinimumSize(header.getPreferredSize());
panel.repaint();
} else {
collapseButton.setText("-");
panel.add(innerPanel, BorderLayout.CENTER);
panel.setMinimumSize(new Dimension(850,PLOT_HEIGHT_MIN));
}
}
});
JLabel titleLabel = new JLabel(" " + title);
Font font = titleLabel.getFont();
titleLabel.setFont(font.deriveFont(5));
titleLabel.setBackground(PLOT_BACKGROUND_COLOR);
header.add(new JLabel(" "));
header.add(collapseButton);
header.add(titleLabel);
panel.add(header, BorderLayout.NORTH);
panel.add(innerPanel, BorderLayout.CENTER);
panel.setMinimumSize(new Dimension(850,PLOT_HEIGHT_MIN));
return panel;
}
public void removeAllPlots() {
nameToPlotMap.clear();
plotBox.removeAll();
plotBox.validate();
}
/**
* Custom JPanel to implement the desired scrolling policy. Basically
* there won't be a scrollbar if all of the components have a greater height than
* {@link #PLOT_HEIGHT_MIN}. However, if you add so many components that they can't
* fit in while maintaining that minimum height, a scrollbar will be added.
*
* @author Clemens Krug
*/
private class PlotBox extends JPanel implements Scrollable
{
private boolean enableScroll = false;
private Dimension preferredSize = new Dimension(VIEW_WIDTH, 800);
@Override
public Component add(Component comp)
{
Component retComp = super.add(comp);
preferredSize.height = getComponentCount() * PLOT_HEIGHT_MIN;
checkScrollNeeded();
return retComp;
}
/**
* Check if scrolling should be enabled and to so if it should.
*/
private void checkScrollNeeded()
{
enableScroll = getComponentCount() * PLOT_HEIGHT_MIN > getParent().getHeight();
}
@Override
public Dimension getPreferredSize() {
return preferredSize;
}
@Override
public Dimension getPreferredScrollableViewportSize() {
return getPreferredSize();
}
@Override
public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) {
return 50;
}
@Override
public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) {
return PLOT_HEIGHT_MIN;
}
@Override
public boolean getScrollableTracksViewportWidth() {
return true;
}
@Override
public boolean getScrollableTracksViewportHeight() {
return !enableScroll;
}
}
/*
* 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.topology.views.visualization.ui;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Map;
import javax.swing.*;
import javax.swing.border.BevelBorder;
import com.google.common.collect.Maps;
/**
* JFrame which holds all the live plots.
*
* @author Unknown
*
* 21.03.2017 Clemens Krug:
* Changed this class up quite a bit because when one would
* add more and more metrics to the visualisation, they would get unreadable small. Reworked this
* class so the charts will allways fill the view if theres is space, but if you add do many plots
* they will stay add a minimum height of 250 px and a scrollbar will be added instead.
*/
public class PlottingView extends JFrame {
private static final int VIEW_WIDTH = 900;
private static final int VIEW_HEIGHT = 800;
private static final int PLOT_HEIGHT_MIN = 250;
private static final Color PLOT_BACKGROUND_COLOR = Color.WHITE;
private Map<String, XYChart> nameToPlotMap = Maps.newLinkedHashMap();
private JPanel plotBox;
private JScrollPane spane;
public PlottingView(String name) {
setTitle(name);
setVisible(true);
buildUI();
}
private void buildUI() {
plotBox = new PlotBox();
plotBox.setLayout(new BoxLayout(plotBox, BoxLayout.Y_AXIS));
plotBox.setBackground(PLOT_BACKGROUND_COLOR);
plotBox.setBorder(BorderFactory.createEtchedBorder());
spane = new JScrollPane(plotBox);
add(spane);
setSize(VIEW_WIDTH, VIEW_HEIGHT);
setPreferredSize(new Dimension(VIEW_WIDTH, VIEW_HEIGHT));
}
public XYChart createPlot(String name, String seriesName) {
XYChart plot = new XYChart(PLOT_BACKGROUND_COLOR, name, seriesName);
JPanel chartPanel = plot.getChartPanel();
chartPanel = wrapInCollabsable(chartPanel, name);
plotBox.add(chartPanel);
plotBox.repaint();
spane.validate();
nameToPlotMap.put(name, plot);
return plot;
}
public XYChart createPlot(String name) {
return createPlot(name, name);
}
private JPanel wrapInCollabsable(JPanel chartPanel, String title) {
final JPanel innerPanel = new JPanel();
innerPanel.setLayout(new BorderLayout());
innerPanel.add(new JLabel(" "), BorderLayout.WEST);
innerPanel.add(chartPanel, BorderLayout.CENTER);
innerPanel.setBackground(PLOT_BACKGROUND_COLOR);
final JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.setBackground(PLOT_BACKGROUND_COLOR);
Box header = Box.createHorizontalBox();
header.setBackground(PLOT_BACKGROUND_COLOR);
final JLabel collapseButton = new JLabel("-");
Dimension buttonSize = new Dimension(11, 11);
collapseButton.setBackground(PLOT_BACKGROUND_COLOR);
collapseButton.setPreferredSize(buttonSize);
collapseButton.setMaximumSize(buttonSize);
collapseButton.setMinimumSize(buttonSize);
collapseButton.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
collapseButton.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent arg0) {
collapseButton.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
}
@Override
public void mouseReleased(MouseEvent arg0) {
collapseButton.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
if (collapseButton.getText().equals("-")) {
collapseButton.setText("+");
panel.remove(innerPanel);
panel.setMinimumSize(header.getPreferredSize());
panel.repaint();
} else {
collapseButton.setText("-");
panel.add(innerPanel, BorderLayout.CENTER);
panel.setMinimumSize(new Dimension(850,PLOT_HEIGHT_MIN));
}
}
});
JLabel titleLabel = new JLabel(" " + title);
Font font = titleLabel.getFont();
titleLabel.setFont(font.deriveFont(5));
titleLabel.setBackground(PLOT_BACKGROUND_COLOR);
header.add(new JLabel(" "));
header.add(collapseButton);
header.add(titleLabel);
panel.add(header, BorderLayout.NORTH);
panel.add(innerPanel, BorderLayout.CENTER);
panel.setMinimumSize(new Dimension(850,PLOT_HEIGHT_MIN));
return panel;
}
public void removeAllPlots() {
nameToPlotMap.clear();
plotBox.removeAll();
plotBox.validate();
}
/**
* Custom JPanel to implement the desired scrolling policy. Basically
* there won't be a scrollbar if all of the components have a greater height than
* {@link #PLOT_HEIGHT_MIN}. However, if you add so many components that they can't
* fit in while maintaining that minimum height, a scrollbar will be added.
*
* @author Clemens Krug
*/
private class PlotBox extends JPanel implements Scrollable
{
private boolean enableScroll = false;
private Dimension preferredSize = new Dimension(VIEW_WIDTH, 800);
@Override
public Component add(Component comp)
{
Component retComp = super.add(comp);
preferredSize.height = getComponentCount() * PLOT_HEIGHT_MIN;
checkScrollNeeded();
return retComp;
}
/**
* Check if scrolling should be enabled and to so if it should.
*/
private void checkScrollNeeded()
{
enableScroll = getComponentCount() * PLOT_HEIGHT_MIN > getParent().getHeight();
}
@Override
public Dimension getPreferredSize() {
return preferredSize;
}
@Override
public Dimension getPreferredScrollableViewportSize() {
return getPreferredSize();
}
@Override
public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) {
return 50;
}
@Override
public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) {
return PLOT_HEIGHT_MIN;
}
@Override
public boolean getScrollableTracksViewportWidth() {
return true;
}
@Override
public boolean getScrollableTracksViewportHeight() {
return !enableScroll;
}
}
}
\ No newline at end of file
......@@ -2,17 +2,17 @@
* 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/>.
*
......@@ -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,16 +48,21 @@ 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
* simulations and (new) configuration of plots and visualization layers.
*
*
* @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());
}
......@@ -111,7 +125,7 @@ public class SimControlPanel extends JMenuBar
}
return layerMenu;
}
public ComponentVisManager getVisManager() {
return visManager;
}
......@@ -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";
}
}
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