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

Add Javadoc / Improvements

+ Add Javadoc to all DRAS related classes
+ Add close-icon to the close button at DRASLocalNodeViews
~ Fix issue, where nodes would still be displayed as clicked when they have been "unclicked" via closing the DRASLocalNodeView
~ Remove cloning of datasets before central uploading (now done in TimeoutPairedList::merge)
parent 7f1a395b
......@@ -61,16 +61,13 @@ import de.tud.kom.p2psim.api.linklayer.mac.MacLayer;
import de.tud.kom.p2psim.api.linklayer.mac.PhyType;
import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.api.topology.TopologyComponent;
import de.tud.kom.p2psim.api.topology.movement.MovementSupported;
import de.tud.kom.p2psim.api.topology.obstacles.ObstacleModel;
import de.tud.kom.p2psim.api.topology.views.TopologyView;
import de.tud.kom.p2psim.api.topology.waypoints.WaypointModel;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.mapvisualization.IMapVisualization;
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.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;
......@@ -224,7 +221,8 @@ public class VisualizationTopologyView extends JFrame implements TopologyView,
compVisPerHost.put(comp.getHost().getId(), tVis);
// this.visManager.addComponent("Topology", 0, new
// TopologyComponentVis(this, comp));
worldPanel.add(new TopologyComponentVis(this, comp));
//worldPanel.add(new TopologyComponentVis(this, comp));
worldPanel.add(tVis);
}
}
......@@ -426,11 +424,6 @@ public class VisualizationTopologyView extends JFrame implements TopologyView,
return plottingViews.get(name);
}
public static DisasterRegionCentralView createDisasterRegionView(IMapVisualization mapVisualization)
{
return new DisasterRegionCentralView(mapVisualization);
}
protected static void notifyInteractionListenersOnClick(long hostid,
boolean isActive) {
for (NodeVisInteractionListener listener : VisualizationInjector.interactionListeners) {
......@@ -695,4 +688,15 @@ public class VisualizationTopologyView extends JFrame implements TopologyView,
throw new NotSupportedException();
}
/**
* Retrieves the {@link TopologyComponentVis} of the specified host.
* @param id NodeID of the host of which you want to get the {@link TopologyComponentVis}
* @return {@link TopologyComponentVis} of the specified host.
*/
public TopologyComponentVis getCompVisOfHost(INodeID id)
{
return compVisPerHost.get(id);
}
}
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;
}
}
package de.tud.kom.p2psim.impl.topology.views.visualization.ui;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.mapvisualization.IMapVisualization;
import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView;
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.image.BufferedImage;
import java.util.List;
import java.util.Map;
/**
* Visualisation of the disaster region analysing.
*
* @author Clemens Krug
*/
public class DisasterRegionCentralView extends JFrame
{
private BufferedImage image;
/**
* Initialises the UI
* @param mapVisualization The {@link IMapVisualization} used to visualize the OSM-Maps. Can be null.
*/
public DisasterRegionCentralView(IMapVisualization mapVisualization)
{
image = new BufferedImage(VisualizationTopologyView.VisualizationInjector.getWorldX(),
VisualizationTopologyView.VisualizationInjector.getWorldY(), BufferedImage.TYPE_INT_ARGB);
JComponent comp = new JComponent()
{
@Override
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
g2.drawImage(image, 0, 0, null);
}
};
comp.setBounds(0, 0, VisualizationTopologyView.VisualizationInjector.getWorldX(),
VisualizationTopologyView.VisualizationInjector.getWorldY());
JLayeredPane layeredPane = new JLayeredPane();
layeredPane.setPreferredSize(new Dimension(VisualizationTopologyView.VisualizationInjector.getWorldX(),
VisualizationTopologyView.VisualizationInjector.getWorldY()));
layeredPane.add(comp);
if(mapVisualization != null)
{
((JComponent) mapVisualization).setBounds(0, 0, VisualizationTopologyView.VisualizationInjector.getWorldX(),
VisualizationTopologyView.VisualizationInjector.getWorldY());
layeredPane.add((JComponent) mapVisualization);
}
JScrollPane scrollPanel = new JScrollPane(layeredPane,
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollPanel.setPreferredSize(new Dimension(800, 600));
getContentPane().add(scrollPanel);
setTitle("Disaster Region Central Analyzer");
pack();
setVisible(true);
}
/**
* Called when the corresponding DisasterRegionAnalyzer has new data available.
* @param locations The updated locations with no connection.
*/
public void onDataUpdated(List locations)
{
Graphics2D g2 = (Graphics2D) image.getGraphics();
g2.setBackground(new Color(255, 255, 255, 0));
g2.clearRect(0, 0, VisualizationTopologyView.VisualizationInjector.getWorldX(), VisualizationTopologyView.VisualizationInjector.getWorldY());
g2.setColor(Color.BLACK);
locations.stream().forEach(l -> g2.fillOval(
(int) ((Pair<UniqueID, Location>) l).getValue().getLongitude(),
(int)((Pair<UniqueID, Location>) l).getValue().getLatitude(),
5, 5));
repaint();
}
}
......@@ -137,6 +137,7 @@ public class TopologyComponentVis extends JComponent {
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
if (clicked) {
g2.setColor(Color.MAGENTA);
} else {
......@@ -171,6 +172,11 @@ public class TopologyComponentVis extends JComponent {
// VisualizationInjector.getWorldPanel().invalidate();
}
public void toogleClicked()
{
clicked = !clicked;
}
protected PositionVector getPosition() {
return posVec;
}
......
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