Revision 402:f750db761a27

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.Rectangle2D;
10

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

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

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

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

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

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

Also available in: Unified diff