Revision 404:2c5b61a2f653

View differences:

src/main/java/cz/agents/alite/vis/visualizable/Point2dAdapter.java
1
package cz.agents.alite.vis.visualizable;
2

  
3
import javax.vecmath.Point2d;
4

  
5
/**
6
 * @author Ondrej Hrstka (ondrej.hrstka at agents.fel.cvut.cz)
7
 */
8
public interface Point2dAdapter<T> {
9

  
10
    public Point2d convert(T t);
11

  
12
}
src/main/java/cz/agents/alite/vis/visualizable/Visualizable.java
1
package cz.agents.alite.vis.visualizable;
2

  
3
import java.awt.*;
4
import java.awt.geom.Rectangle2D;
5

  
6
/**
7
 * @author Ondrej Hrstka (ondrej.hrstka at agents.fel.cvut.cz)
8
 */
9
public interface Visualizable {
10

  
11
    public void paint(Graphics2D canvas, Rectangle2D drawingRectangle);
12

  
13
}
src/main/java/cz/agents/alite/vis/visualizable/VisualizableLayer.java
1
package cz.agents.alite.vis.visualizable;
2

  
3
import cz.agents.alite.vis.Vis;
4
import cz.agents.alite.vis.layer.AbstractLayer;
5

  
6
import java.awt.*;
7
import java.awt.geom.Rectangle2D;
8

  
9
/**
10
 * @author Ondrej Hrstka (ondrej.hrstka at agents.fel.cvut.cz)
11
 */
12
public class VisualizableLayer extends AbstractLayer {
13

  
14
    private final VisualizableProvider provider;
15

  
16
    public VisualizableLayer(VisualizableProvider provider) {
17
        this.provider = provider;
18
    }
19

  
20
    @Override
21
    public void paint(Graphics2D canvas) {
22
        Dimension dim = Vis.getDrawingDimension();
23
        Rectangle2D drawingRectangle = new Rectangle(dim);
24
        for (Visualizable visualizable : provider.getData()) {
25
            visualizable.paint(canvas, drawingRectangle);
26
        }
27
    }
28
}
src/main/java/cz/agents/alite/vis/visualizable/VisualizableProvider.java
1
package cz.agents.alite.vis.visualizable;
2

  
3
/**
4
 * @author Ondrej Hrstka (ondrej.hrstka at agents.fel.cvut.cz)
5
 */
6
public interface VisualizableProvider {
7

  
8
    public Iterable<? extends Visualizable> getData();
9

  
10
}
src/main/java/cz/agents/alite/vis/visualizable/implementation/PointVis.java
1
package cz.agents.alite.vis.visualizable.implementation;
2

  
3
import cz.agents.alite.vis.Vis;
4
import cz.agents.alite.vis.visualizable.Point2dAdapter;
5
import cz.agents.alite.vis.visualizable.Visualizable;
6

  
7
import javax.vecmath.Point2d;
8
import java.awt.*;
9
import java.awt.geom.Ellipse2D;
10
import java.awt.geom.Rectangle2D;
11

  
12
/**
13
 * @author Ondrej Hrstka (ondrej.hrstka at agents.fel.cvut.cz)
14
 */
15
public class PointVis<T> implements Visualizable {
16

  
17
    private final T centerPosition;
18
    private final int radiusInPx;
19
    private final Point2dAdapter<T> adapter;
20
    private final Color color;
21

  
22
    public PointVis(T centerPosition, int radiusInPx, Color color, Point2dAdapter<T> adapter) {
23
        this.centerPosition = centerPosition;
24
        this.radiusInPx = radiusInPx;
25
        this.adapter = adapter;
26
        this.color = color;
27
    }
28

  
29
    @Override
30
    public void paint(Graphics2D canvas, Rectangle2D drawingRectangle) {
31
        Point2d center = adapter.convert(centerPosition);
32
        int x = Vis.transX(center.x);
33
        int y = Vis.transY(center.y);
34
        canvas.setColor(color);
35

  
36
        Ellipse2D point = new Ellipse2D.Double(x - radiusInPx, y - radiusInPx,
37
                2 * radiusInPx + 1, 2 * radiusInPx + 1);
38

  
39
        if (drawingRectangle.intersects(point.getBounds2D())) {
40
            canvas.fill(point);
41
        }
42
    }
43
}

Also available in: Unified diff