File: CompoundPainter.java

package info (click to toggle)
mac-widgets 0.10.0%2Bsvn416-dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,968 kB
  • ctags: 2,003
  • sloc: java: 9,909; makefile: 13; sh: 12
file content (29 lines) | stat: -rw-r--r-- 1,057 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package com.explodingpixels.painter;

import java.awt.Graphics2D;

/**
 * An implementation of {@link MacWidgetsPainter} that calls a series of {@code Painter}s in succession. {@code ComponentPainter}
 * does not do any painting itself.
 */
public class CompoundPainter<T> implements MacWidgetsPainter<T> {

    private MacWidgetsPainter<T>[] fPainters;

    /**
     * Creates a {@link MacWidgetsPainter} that calls the given {@code Painter}s in the order they are supplied when
     * {@link #paint(java.awt.Graphics2D, Object, int, int)} is called.
     * @param painters the {@code Painter}s to delegate to.
     */
    public CompoundPainter(MacWidgetsPainter<T>... painters) {
        fPainters = painters;
    }

    public void paint(Graphics2D graphics, T objectToPaint, int width, int height) {
        for (MacWidgetsPainter<T> painter : fPainters) {
            Graphics2D graphicsCopy = (Graphics2D) graphics.create();
            painter.paint(graphicsCopy, objectToPaint, width, height);
            graphicsCopy.dispose();
        }
    }
}