Search in sources :

Example 1 with Paintable

use of ini.trakem2.display.Paintable in project TrakEM2 by trakem2.

the class TestGraphicsSource method asPaintable.

/**
 * Replaces all Patch instances by a smiley face.
 */
public List<? extends Paintable> asPaintable(final List<? extends Paintable> ds) {
    final ArrayList<Paintable> a = new ArrayList<Paintable>();
    for (final Paintable p : ds) {
        if (p instanceof Patch) {
            final Paintable pa = new Paintable() {

                public void paint(Graphics2D g, Rectangle srcRect, double magnification, boolean active, int channels, Layer active_layer, List<Layer> layers) {
                    Patch patch = (Patch) p;
                    Rectangle r = patch.getBoundingBox();
                    g.setColor(Color.magenta);
                    g.fillRect(r.x, r.y, r.width, r.height);
                    g.setColor(Color.green);
                    g.fillOval(r.x + r.width / 3, r.y + r.height / 3, r.width / 10, r.width / 10);
                    g.fillOval(r.x + 2 * (r.width / 3), r.y + r.height / 3, r.width / 10, r.width / 10);
                    g.fillOval(r.x + r.width / 3, r.y + 2 * (r.height / 3), r.width / 3, r.height / 6);
                }

                public void prePaint(Graphics2D g, Rectangle srcRect, double magnification, boolean active, int channels, Layer active_layer, List<Layer> layers) {
                    this.paint(g, srcRect, magnification, active, channels, active_layer, layers);
                }
            };
            a.add(pa);
        } else {
            a.add(p);
        }
    }
    return a;
}
Also used : Paintable(ini.trakem2.display.Paintable) ArrayList(java.util.ArrayList) Rectangle(java.awt.Rectangle) List(java.util.List) ArrayList(java.util.ArrayList) Patch(ini.trakem2.display.Patch) Layer(ini.trakem2.display.Layer) Graphics2D(java.awt.Graphics2D)

Aggregations

Layer (ini.trakem2.display.Layer)1 Paintable (ini.trakem2.display.Paintable)1 Patch (ini.trakem2.display.Patch)1 Graphics2D (java.awt.Graphics2D)1 Rectangle (java.awt.Rectangle)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1