|
@@ -1,7 +1,11 @@
|
|
|
package de.tu_darmstadt.tk.SmartHomeNetworkSim.view;
|
|
|
|
|
|
+import java.awt.BasicStroke;
|
|
|
import java.awt.Color;
|
|
|
import java.awt.Graphics;
|
|
|
+import java.awt.Graphics2D;
|
|
|
+import java.awt.RenderingHints;
|
|
|
+import java.awt.Stroke;
|
|
|
import java.awt.event.ComponentEvent;
|
|
|
import java.awt.event.ComponentListener;
|
|
|
|
|
@@ -116,6 +120,36 @@ public class VisualisationPanel extends JPanel implements Observer {
|
|
|
|
|
|
@Override
|
|
|
public void paint(Graphics g) {
|
|
|
+ // More beautiful Graphics
|
|
|
+ if(g instanceof Graphics2D){
|
|
|
+ /**
|
|
|
+ * Graphics2D options, if enabled on the machine
|
|
|
+ */
|
|
|
+ Graphics2D graphics = (Graphics2D) g;
|
|
|
+ RenderingHints renders = new RenderingHints(new HashMap<>());
|
|
|
+ /**
|
|
|
+ * Add AntiAliasing
|
|
|
+ */
|
|
|
+ renders.add(new RenderingHints(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON));
|
|
|
+ /**
|
|
|
+ * Add Text AntiAliasing
|
|
|
+ */
|
|
|
+ renders.add(new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON));
|
|
|
+ /**
|
|
|
+ * Add Improved Color Rendering
|
|
|
+ */
|
|
|
+ renders.add(new RenderingHints(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY));
|
|
|
+ /**
|
|
|
+ * Add general quality Rendering
|
|
|
+ */
|
|
|
+ renders.add(new RenderingHints(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_QUALITY));
|
|
|
+ /**
|
|
|
+ * Add improved interpolation for images
|
|
|
+ */
|
|
|
+ renders.add(new RenderingHints(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC));
|
|
|
+ graphics.setRenderingHints(renders);
|
|
|
+ }
|
|
|
+
|
|
|
// paint white background
|
|
|
g.setColor(Color.white);
|
|
|
g.fillRect(0, 0, this.getWidth(), this.getHeight());
|
|
@@ -166,6 +200,10 @@ public class VisualisationPanel extends JPanel implements Observer {
|
|
|
* the Graphics object to visualize on
|
|
|
*/
|
|
|
protected void paintDevices(Graphics g) {
|
|
|
+ /**
|
|
|
+ * Radius of devices
|
|
|
+ */
|
|
|
+ int deviceRadius = config.getDeviceVisualizationRadius();
|
|
|
/*
|
|
|
* Visualization calculations for all devices
|
|
|
*/
|
|
@@ -204,11 +242,22 @@ public class VisualisationPanel extends JPanel implements Observer {
|
|
|
i++;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ /**
|
|
|
+ * Original Stroke - if it was changed
|
|
|
+ */
|
|
|
+ Stroke f = null;
|
|
|
+ /**
|
|
|
+ * Set bigger brush size if possible
|
|
|
+ */
|
|
|
+ if(g instanceof Graphics2D){
|
|
|
+ Graphics2D g2 = (Graphics2D) g;
|
|
|
+ f = g2.getStroke();
|
|
|
+ g2.setStroke(new BasicStroke(Math.max(deviceRadius/20.0f,1f)));
|
|
|
+ }
|
|
|
/**
|
|
|
* Paint Devices
|
|
|
*/
|
|
|
-
|
|
|
+
|
|
|
//Values for dragging of multiple Devices
|
|
|
/**
|
|
|
* Pixel offset of dragged devices on the x axis
|
|
@@ -249,8 +298,8 @@ public class VisualisationPanel extends JPanel implements Observer {
|
|
|
Pair<Integer, Color> linkPos = linkColors.get(l);
|
|
|
if(linkPos==null)continue;//Skip Links, which are not in the model
|
|
|
g.setColor(linkPos.getRight());
|
|
|
- g.fillArc(x - config.getDeviceVisualizationRadius() - config.getLinkRadius(), y - config.getDeviceVisualizationRadius() - config.getLinkRadius(),
|
|
|
- 2 * config.getDeviceVisualizationRadius() - 1 + 2 * config.getLinkRadius(), 2 * config.getDeviceVisualizationRadius() - 1 + 2*config.getLinkRadius(),
|
|
|
+ g.fillArc(x - deviceRadius - config.getLinkRadius(), y - deviceRadius - config.getLinkRadius(),
|
|
|
+ 2 * deviceRadius - 1 + 2 * config.getLinkRadius(), 2 * deviceRadius - 1 + 2*config.getLinkRadius(),
|
|
|
(int)Math.round(linkPos.getLeft()*linkSlice), (int)Math.ceil(linkSlice));
|
|
|
}
|
|
|
|
|
@@ -262,21 +311,24 @@ public class VisualisationPanel extends JPanel implements Observer {
|
|
|
}else{
|
|
|
g.setColor(Color.WHITE);
|
|
|
}
|
|
|
- g.fillOval(x - config.getDeviceVisualizationRadius(), y - config.getDeviceVisualizationRadius(),
|
|
|
- 2 * config.getDeviceVisualizationRadius() - 1, 2 * config.getDeviceVisualizationRadius() - 1);
|
|
|
+ fillCircle(g, x, y, deviceRadius);
|
|
|
g.setColor(Color.BLACK);
|
|
|
- g.drawOval(x - config.getDeviceVisualizationRadius(), y - config.getDeviceVisualizationRadius(),
|
|
|
- 2 * config.getDeviceVisualizationRadius() - 1, 2 * config.getDeviceVisualizationRadius() - 1);
|
|
|
- g.setColor(Color.BLUE);
|
|
|
- g.drawOval(x - config.getDeviceVisualizationRadius() + 2,
|
|
|
- y - config.getDeviceVisualizationRadius() + 2, 2 * config.getDeviceVisualizationRadius() - 5,
|
|
|
- 2 * config.getDeviceVisualizationRadius() - 5);
|
|
|
+ drawCircle(g,x,y,deviceRadius);
|
|
|
+ g.setColor(new Color(91, 162, 229));
|
|
|
+ /**
|
|
|
+ * Distance in pixels between the two circles at the border
|
|
|
+ */
|
|
|
+ int innerDistance = Math.max(2, Math.round(deviceRadius/13f));
|
|
|
+ drawCircle(g, x, y, deviceRadius-innerDistance);
|
|
|
g.setColor(Color.BLACK);
|
|
|
if(config.isShowSmartDeviceNames())
|
|
|
g.drawString(s.getName(),
|
|
|
x - g.getFontMetrics().stringWidth(s.getName()) / 2, y
|
|
|
- + config.getDeviceVisualizationRadius() + 11 + (config.isShowLinks()?config.getLinkRadius():0));
|
|
|
+ + deviceRadius + 11 + (config.isShowLinks()?config.getLinkRadius():0));
|
|
|
}
|
|
|
+
|
|
|
+ if(f!=null)
|
|
|
+ ((Graphics2D) g).setStroke(f);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -466,5 +518,27 @@ public class VisualisationPanel extends JPanel implements Observer {
|
|
|
public void update(Observable o, Object arg) {
|
|
|
repaint();
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Fills a circle of radius radius around the given point (Radius includes middle), So width may be 2*radius-1
|
|
|
+ * @param g Graphics to be used
|
|
|
+ * @param x x Position of the middle
|
|
|
+ * @param y y Position of the middle
|
|
|
+ * @param radius radius of the circle
|
|
|
+ */
|
|
|
+ public void fillCircle(Graphics g, int x, int y, int radius){
|
|
|
+ g.fillOval(x-radius, y-radius, 2*radius+1, 2*radius+1);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Draws a circle of radius radius around the given point (Radius includes middle)
|
|
|
+ * @param g Graphics to be used
|
|
|
+ * @param x x Position of the middle
|
|
|
+ * @param y y Position of the middle
|
|
|
+ * @param radius radius of the circle
|
|
|
+ */
|
|
|
+ public void drawCircle(Graphics g, int x, int y, int radius){
|
|
|
+ g.drawOval(x-radius, y-radius, 2*radius-1, 2*radius-1);
|
|
|
+ }
|
|
|
|
|
|
}
|