|
@@ -4,10 +4,12 @@ import java.awt.Color;
|
|
import java.awt.Graphics;
|
|
import java.awt.Graphics;
|
|
import java.awt.event.ComponentEvent;
|
|
import java.awt.event.ComponentEvent;
|
|
import java.awt.event.ComponentListener;
|
|
import java.awt.event.ComponentListener;
|
|
|
|
+import java.util.Collection;
|
|
|
|
|
|
import javax.swing.JPanel;
|
|
import javax.swing.JPanel;
|
|
|
|
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller;
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller;
|
|
|
|
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Connection;
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Model;
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Model;
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.SmartDevice;
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.SmartDevice;
|
|
|
|
|
|
@@ -85,7 +87,9 @@ public class VisualisationPanel extends JPanel {
|
|
// paint white background
|
|
// paint white background
|
|
g.setColor(Color.white);
|
|
g.setColor(Color.white);
|
|
g.fillRect(0, 0, this.getWidth(), this.getHeight());
|
|
g.fillRect(0, 0, this.getWidth(), this.getHeight());
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ paintConnections(g);
|
|
|
|
+
|
|
paintDevices(g);
|
|
paintDevices(g);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -104,6 +108,8 @@ public class VisualisationPanel extends JPanel {
|
|
x = interactor.dragged_x;
|
|
x = interactor.dragged_x;
|
|
y = interactor.dragged_y;
|
|
y = interactor.dragged_y;
|
|
}
|
|
}
|
|
|
|
+ g.setColor(Color.WHITE);
|
|
|
|
+ g.fillOval(x - visualisationRadius, y - visualisationRadius, 2*visualisationRadius-1, 2*visualisationRadius-1);
|
|
g.setColor(Color.BLACK);
|
|
g.setColor(Color.BLACK);
|
|
g.drawOval(x - visualisationRadius, y - visualisationRadius, 2*visualisationRadius-1, 2*visualisationRadius-1);
|
|
g.drawOval(x - visualisationRadius, y - visualisationRadius, 2*visualisationRadius-1, 2*visualisationRadius-1);
|
|
g.setColor(Color.BLUE);
|
|
g.setColor(Color.BLUE);
|
|
@@ -112,6 +118,54 @@ public class VisualisationPanel extends JPanel {
|
|
g.drawString(s.getName(), x - g.getFontMetrics().stringWidth(s.getName()) / 2, y + visualisationRadius+11);
|
|
g.drawString(s.getName(), x - g.getFontMetrics().stringWidth(s.getName()) / 2, y + visualisationRadius+11);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Paints the Connections
|
|
|
|
+ * @param g
|
|
|
|
+ */
|
|
|
|
+ private void paintConnections(Graphics g){
|
|
|
|
+ g.setColor(Color.RED);
|
|
|
|
+ //For all Connections
|
|
|
|
+ for (SmartDevice s : model.getDevices())
|
|
|
|
+ for(Connection c: s.getConnections()){
|
|
|
|
+ //Draw just once, if the device is the source
|
|
|
|
+ if(c.getSource() == s){
|
|
|
|
+ /**
|
|
|
|
+ * All Devices that are part of the connection
|
|
|
|
+ */
|
|
|
|
+ Collection<SmartDevice> d = c.getParticipants();
|
|
|
|
+ if(d.size() == 2){
|
|
|
|
+
|
|
|
|
+ for(SmartDevice sd: d)
|
|
|
|
+ if(s!=sd){
|
|
|
|
+ //Check if dragged object
|
|
|
|
+ int s_x,s_y,sd_x,sd_y;
|
|
|
|
+ if(s == interactor.dragged){
|
|
|
|
+ s_x = interactor.dragged_x;
|
|
|
|
+ s_y = interactor.dragged_y;
|
|
|
|
+ }else{
|
|
|
|
+ s_x = s.getX();
|
|
|
|
+ s_y = s.getY();
|
|
|
|
+ }
|
|
|
|
+ if(sd == interactor.dragged){
|
|
|
|
+ sd_x = interactor.dragged_x;
|
|
|
|
+ sd_y = interactor.dragged_y;
|
|
|
|
+ }else{
|
|
|
|
+ sd_x = sd.getX();
|
|
|
|
+ sd_y = sd.getY();
|
|
|
|
+ }
|
|
|
|
+ g.drawLine(s_x, s_y, sd_x, sd_y);
|
|
|
|
+ }
|
|
|
|
+ }else if(d.size() == 1){
|
|
|
|
+
|
|
|
|
+ } else if(d.size() <= 0){
|
|
|
|
+ //Invalid Connection
|
|
|
|
+ }else{
|
|
|
|
+ //Draw MultiConnection
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
/**
|
|
* @return the visualisationRadius
|
|
* @return the visualisationRadius
|