Commit d2ac4a44 authored by Clemens Krug's avatar Clemens Krug
Browse files

Add visualisation for local analysing

+ Add visualisation structure for local analysing
+ Add README explaining how DRAS works
parent 579e065e
......@@ -70,7 +70,7 @@ import de.tud.kom.p2psim.impl.topology.movement.modularosm.mapvisualization.IMap
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.ui.ComponentToggler;
import de.tud.kom.p2psim.impl.topology.views.visualization.ui.DisasterRegionView;
import de.tud.kom.p2psim.impl.topology.views.visualization.ui.DisasterRegionCentralView;
import de.tud.kom.p2psim.impl.topology.views.visualization.ui.PlottingView;
import de.tud.kom.p2psim.impl.topology.views.visualization.ui.SimControlPanel;
import de.tud.kom.p2psim.impl.topology.views.visualization.world.NodeVisInteractionListener;
......@@ -423,9 +423,9 @@ public class VisualizationTopologyView extends JFrame implements TopologyView,
return plottingViews.get(name);
}
public static DisasterRegionView createDisasterRegionView(IMapVisualization mapVisualization)
public static DisasterRegionCentralView createDisasterRegionView(IMapVisualization mapVisualization)
{
return new DisasterRegionView(mapVisualization);
return new DisasterRegionCentralView(mapVisualization);
}
protected static void notifyInteractionListenersOnClick(long hostid,
......
package de.tud.kom.p2psim.impl.topology.views.visualization.ui;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.mapvisualization.IMapVisualization;
import de.tudarmstadt.maki.simonstrator.api.common.UniqueID;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
import javafx.util.Pair;
import javax.swing.*;
import java.awt.*;
import java.util.List;
import java.util.ArrayList;
import java.util.HashMap;
/**
* Created by Clemens on 26.06.2016.
*/
public class DRASLocalMonitor extends JFrame
{
JPanel panel;
JScrollPane scrollPanel;
private int panelSize = 400;
HashMap<Long, DRASLocalNodeView> nodeViews = new HashMap<>();
ArrayList<DRASLocalNodeView> nodeOrder = new ArrayList<>();
public DRASLocalMonitor()
{
SwingUtilities.invokeLater(() -> createGUI());
}
public void createGUI()
{
panel = new JPanel();
panel.setLayout(null);
scrollPanel = new JScrollPane(panel,
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollPanel.setPreferredSize(new Dimension(panelSize, panelSize));
getContentPane().add(scrollPanel);
pack();
}
public void updateView(Long nodeID, List<Pair<UniqueID, Location>> noUMTSLocations, List<Pair<UniqueID, Location>> netAvailableLocations)
{
DRASLocalNodeView view = nodeViews.get(nodeID);
if(view != null) view.update(noUMTSLocations, netAvailableLocations);
}
public void addNodeView(long id)
{
SwingUtilities.invokeLater(() -> {
int viewCount = nodeViews.size();
DRASLocalNodeView nodeView = new DRASLocalNodeView(id, this);
nodeViews.put(id, nodeView);
nodeOrder.add(nodeView);
nodeView.setBounds(viewCount % 3 * panelSize, viewCount / 3 * panelSize, panelSize, panelSize);
scrollPanel.setPreferredSize(new Dimension(viewCount < 3 ? (viewCount+1)*panelSize : panelSize*3,
viewCount / 3 * panelSize + panelSize));
panel.add(nodeView);
pack();
panel.repaint();
if(viewCount == 0) setVisible(true);
});
}
public void removeNodeView(long id)
{
SwingUtilities.invokeLater(() -> {
DRASLocalNodeView nodeView = nodeViews.get(id);
nodeViews.remove(id);
panel.remove(nodeView);
for(int i = nodeOrder.indexOf(nodeView)+1 ; i < nodeOrder.size(); i++)
{
DRASLocalNodeView cur = nodeOrder.get(i);
int newX, newY;
if(cur.getX() == 0)
{
newX = 2*panelSize;
newY = cur.getY()-panelSize;
}
else
{
newX = cur.getX()-panelSize;
newY = cur.getY();
}
cur.setLocation(newX, newY);
}
int viewCount = nodeViews.size();
scrollPanel.setPreferredSize(new Dimension(viewCount < 3 ? (viewCount)*panelSize : 3*panelSize,
(viewCount-1) / 3 * panelSize + panelSize));
panel.repaint();
pack();
if(nodeViews.size() < 1) setVisible(false);
});
}
public void setIMapVisualization(IMapVisualization mapVisualization)
{
}
public void setPanelSize(int size)
{
panelSize = size;
panel.setPreferredSize(new Dimension(panelSize*3, panelSize*4));
DRASLocalNodeView.setPanelSize(panelSize);
}
}
package de.tud.kom.p2psim.impl.topology.views.visualization.ui;
import de.tudarmstadt.maki.simonstrator.api.common.UniqueID;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
import javafx.util.Pair;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.stream.Collectors;
/**
* Created by Clemens on 26.06.2016.
*/
public class DRASLocalNodeView extends JComponent
{
private long id;
private BufferedImage image;
private static int panelSize = 400;
private DRASLocalMonitor parent;
public DRASLocalNodeView(long id, DRASLocalMonitor parent)
{
this.id = id;
setOpaque(true);
setSize(panelSize, panelSize);
JButton close = new JButton();
close.setBounds(panelSize-30, 10, 20, 20);
close.addActionListener(e -> parent.removeNodeView(id));
add(close);
image = new BufferedImage(panelSize, panelSize, BufferedImage.TYPE_INT_ARGB);
}
@Override
protected void paintComponent(Graphics g)
{
Graphics2D g2 = (Graphics2D) image.getGraphics();
g.setColor(Color.GRAY);
g.fillRect(0,0,panelSize,panelSize);
g2.setColor(Color.BLACK);
g2.drawString("Node " + id, 15 , 15);
g2.drawRect(0,0,panelSize-1,panelSize-1);
g.drawImage(image, 0, 0, null);
}
public void update(List<Pair<UniqueID, Location>> noUMTSLocations, List<Pair<UniqueID, Location>> netAvailableLocations)
{
Graphics2D g2 = image.createGraphics();
g2.setBackground(new Color(255, 255, 255, 0));
g2.clearRect(0, 0, panelSize, panelSize);
g2.setColor(Color.BLACK);
Point center = noUMTSLocations != null && noUMTSLocations.size() > 0 ? calculateCenter(noUMTSLocations) : calculateCenter(netAvailableLocations);
int xDif = center.x - panelSize/2;
int yDif = center.y - panelSize/2;
if (noUMTSLocations != null)
{
noUMTSLocations.stream().forEach(l -> g2.fillOval(
(int) l.getValue().getLongitude() - xDif,
(int) l.getValue().getLatitude() - yDif,
5, 5));
}
g2.setColor(Color.RED);
if(netAvailableLocations != null)
{
netAvailableLocations.stream().forEach(l -> g2.fillOval(
(int) l.getValue().getLongitude() - xDif,
(int) l.getValue().getLatitude() - yDif,
5, 5));
}
repaint();
}
private Point calculateCenter(List<Pair<UniqueID, Location>> locations)
{
try
{
List<Location> loc = locations.stream().map(p -> p.getValue()).collect(Collectors.toList());
double xMin = loc.stream().mapToDouble(l -> l.getLongitude()).min().getAsDouble();
double xMax = loc.stream().mapToDouble(l -> l.getLongitude()).max().getAsDouble();
double yMin = loc.stream().mapToDouble(l -> l.getLatitude()).min().getAsDouble();
double yMax = loc.stream().mapToDouble(l -> l.getLatitude()).max().getAsDouble();
return new Point((int) (xMax+xMin)/2, (int) (yMax+yMin)/2);
}
catch (NoSuchElementException nse)
{
return new Point(0,0);
}
}
@Override
public Dimension getPreferredSize()
{
return new Dimension(panelSize, panelSize);
}
public static void setPanelSize(int size)
{
panelSize = size;
}
}
......@@ -18,7 +18,7 @@ import java.util.Map;
*
* @author Clemens Krug
*/
public class DisasterRegionView extends JFrame
public class DisasterRegionCentralView extends JFrame
{
private BufferedImage image;
......@@ -27,7 +27,7 @@ public class DisasterRegionView extends JFrame
* Initialises the UI
* @param mapVisualization The {@link IMapVisualization} used to visualize the OSM-Maps. Can be null.
*/
public DisasterRegionView(IMapVisualization mapVisualization)
public DisasterRegionCentralView(IMapVisualization mapVisualization)
{
image = new BufferedImage(VisualizationTopologyView.VisualizationInjector.getWorldX(),
VisualizationTopologyView.VisualizationInjector.getWorldY(), BufferedImage.TYPE_INT_ARGB);
......@@ -63,7 +63,7 @@ public class DisasterRegionView extends JFrame
getContentPane().add(scrollPanel);
setTitle("Disaster Region Analyzer");
setTitle("Disaster Region Central Analyzer");
pack();
setVisible(true);
}
......
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