package CH.ifa.draw.util;

import java.awt.Color;
import java.awt.Composite;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
import java.awt.Image;
import java.awt.Paint;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.RenderingHints.Key;
import java.awt.Shape;
import java.awt.Stroke;
import java.awt.font.FontRenderContext;
import java.awt.font.GlyphVector;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.awt.image.BufferedImageOp;
import java.awt.image.ImageObserver;
import java.awt.image.RenderedImage;
import java.awt.image.renderable.RenderableImage;
import java.text.AttributedCharacterIterator;
import java.util.Map;


/**
 * A class that extends Graphics2D to add a background color to a Graphics2D object.
 * @deprecated This class is not to be used externally and will later be hidden.
 */
@Deprecated(since = "5.0", forRemoval = true)
public class ContextGraphics extends Graphics2D {
    private final Graphics2D _graphics;
    private final Color _background;

    /**
     * Constructs a new ContextGraphics with the background color
     * that will be used for the given Graphics2D object.
     *
     * @param g the graphic, to which a background will be added
     * @param back the color of the background
     */
    public ContextGraphics(Graphics2D g, Color back) {
        _graphics = g;
        _background = back;
    }

    @Override
    public void addRenderingHints(Map<?, ?> hints) {
        _graphics.addRenderingHints(hints);

    }

    @Override
    public void clip(Shape s) {
        _graphics.clip(s);

    }

    @Override
    public void draw(Shape s) {
        _graphics.draw(s);

    }

    @Override
    public void drawGlyphVector(GlyphVector g, float x, float y) {
        _graphics.drawGlyphVector(g, x, y);
    }

    @Override
    public boolean drawImage(Image img, AffineTransform xform, ImageObserver obs) {
        return _graphics.drawImage(img, xform, obs);
    }

    @Override
    public void drawImage(BufferedImage img, BufferedImageOp op, int x, int y) {
        _graphics.drawImage(img, op, x, y);

    }

    @Override
    public void drawRenderableImage(RenderableImage img, AffineTransform xform) {
        _graphics.drawRenderableImage(img, xform);

    }

    @Override
    public void drawRenderedImage(RenderedImage img, AffineTransform xform) {
        _graphics.drawRenderedImage(img, xform);

    }

    @Override
    public void drawString(String str, int x, int y) {
        _graphics.drawString(str, x, y);

    }

    @Override
    public void drawString(String str, float x, float y) {
        _graphics.drawString(str, x, y);

    }

    @Override
    public void drawString(AttributedCharacterIterator iterator, int x, int y) {
        _graphics.drawString(iterator, x, y);

    }

    @Override
    public void drawString(AttributedCharacterIterator iterator, float x, float y) {
        _graphics.drawString(iterator, x, y);

    }

    @Override
    public void fill(Shape s) {
        _graphics.fill(s);

    }

    @Override
    public Color getBackground() {
        return _graphics.getBackground();

    }

    @Override
    public Composite getComposite() {
        return _graphics.getComposite();

    }

    @Override
    public GraphicsConfiguration getDeviceConfiguration() {
        return _graphics.getDeviceConfiguration();

    }

    @Override
    public FontRenderContext getFontRenderContext() {
        return _graphics.getFontRenderContext();

    }

    @Override
    public Paint getPaint() {
        return _graphics.getPaint();

    }

    @Override
    public Object getRenderingHint(Key hintKey) {
        return _graphics.getRenderingHint(hintKey);

    }

    @Override
    public RenderingHints getRenderingHints() {
        return _graphics.getRenderingHints();

    }

    @Override
    public Stroke getStroke() {
        return _graphics.getStroke();

    }

    @Override
    public AffineTransform getTransform() {
        return _graphics.getTransform();

    }

    @Override
    public boolean hit(Rectangle rect, Shape s, boolean onStroke) {
        return _graphics.hit(rect, s, onStroke);

    }

    @Override
    public void rotate(double theta) {
        _graphics.rotate(theta);

    }

    @Override
    public void rotate(double theta, double x, double y) {
        _graphics.rotate(theta, x, y);

    }

    @Override
    public void scale(double sx, double sy) {
        _graphics.scale(sx, sy);

    }

    @Override
    public void setBackground(Color color) {
        _graphics.setBackground(color);

    }

    @Override
    public void setComposite(Composite comp) {
        _graphics.setComposite(comp);

    }

    @Override
    public void setPaint(Paint paint) {
        _graphics.setPaint(paint);

    }

    @Override
    public void setRenderingHint(Key hintKey, Object hintValue) {
        _graphics.setRenderingHint(hintKey, hintValue);

    }

    @Override
    public void setRenderingHints(Map<?, ?> hints) {
        _graphics.setRenderingHints(hints);

    }

    @Override
    public void setStroke(Stroke s) {
        _graphics.setStroke(s);

    }

    @Override
    public void setTransform(AffineTransform Tx) {
        _graphics.setTransform(Tx);

    }

    @Override
    public void shear(double shx, double shy) {
        _graphics.shear(shx, shy);

    }

    @Override
    public void transform(AffineTransform Tx) {
        _graphics.transform(Tx);

    }

    @Override
    public void translate(int x, int y) {
        _graphics.translate(x, y);

    }

    @Override
    public void translate(double tx, double ty) {
        _graphics.translate(tx, ty);

    }

    @Override
    public void clearRect(int x, int y, int width, int height) {
        _graphics.clearRect(x, y, width, height);

    }

    @Override
    public void clipRect(int x, int y, int width, int height) {
        _graphics.clipRect(x, y, width, height);

    }

    @Override
    public void copyArea(int x, int y, int width, int height, int dx, int dy) {
        _graphics.copyArea(x, y, width, height, dx, dy);

    }

    @Override
    public Graphics create() {
        return _graphics.create();

    }

    @Override
    public void dispose() {
        _graphics.dispose();

    }

    @Override
    public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
        _graphics.drawArc(x, y, width, height, startAngle, arcAngle);

    }

    @Override
    public boolean drawImage(Image img, int x, int y, ImageObserver observer) {
        return _graphics.drawImage(img, x, y, observer);

    }

    @Override
    public boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer) {
        return _graphics.drawImage(img, x, y, bgcolor, observer);

    }

    @Override
    public boolean drawImage(
        Image img, int x, int y, int width, int height, ImageObserver observer)
    {
        return _graphics.drawImage(img, x, y, width, height, observer);

    }

    @Override
    public boolean drawImage(
        Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer)
    {
        return _graphics.drawImage(img, x, y, bgcolor, observer);

    }

    @Override
    public boolean drawImage(
        Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2,
        ImageObserver observer)
    {
        return _graphics.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, observer);

    }

    @Override
    public boolean drawImage(
        Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2,
        Color bgcolor, ImageObserver observer)
    {
        return _graphics.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgcolor, observer);

    }

    @Override
    public void drawLine(int x1, int y1, int x2, int y2) {
        _graphics.drawLine(x1, y1, x2, y2);

    }

    @Override
    public void drawOval(int x, int y, int width, int height) {
        _graphics.drawOval(x, y, width, height);

    }

    @Override
    public void drawPolygon(int[] points, int[] points2, int points3) {
        _graphics.drawPolygon(points, points2, points3);

    }

    @Override
    public void drawPolyline(int[] points, int[] points2, int points3) {
        _graphics.drawPolyline(points, points2, points3);

    }

    @Override
    public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) {
        _graphics.drawRoundRect(x, y, width, height, arcWidth, arcHeight);

    }

    @Override
    public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
        _graphics.fillArc(x, y, width, height, startAngle, arcAngle);

    }

    @Override
    public void fillOval(int x, int y, int width, int height) {
        _graphics.fillOval(x, y, width, height);

    }

    @Override
    public void fillPolygon(int[] points, int[] points2, int points3) {
        _graphics.fillPolygon(points, points2, points3);

    }

    @Override
    public void fillRect(int x, int y, int width, int height) {
        _graphics.fillRect(x, y, width, height);

    }

    @Override
    public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) {
        _graphics.fillRoundRect(x, y, width, height, arcWidth, arcHeight);

    }

    @Override
    public Shape getClip() {
        return _graphics.getClip();

    }

    @Override
    public Rectangle getClipBounds() {
        return _graphics.getClipBounds();

    }

    @Override
    public Color getColor() {
        Color color = _graphics.getColor();
        if (color.equals(_background)) {
            return ColorMap.BACKGROUND;
        } else {
            return color;
        }
    }

    @Override
    public Font getFont() {
        return _graphics.getFont();
    }

    @Override
    public FontMetrics getFontMetrics(Font f) {
        return _graphics.getFontMetrics(f);

    }

    @Override
    public void setClip(Shape clip) {
        _graphics.setClip(clip);

    }

    @Override
    public void setClip(int x, int y, int width, int height) {
        _graphics.setClip(x, y, width, height);

    }

    @Override
    public void setColor(Color c) {
        if (ColorMap.isBackground(c)) {
            _graphics.setColor(_background);
        } else {
            _graphics.setColor(c);
        }
    }

    @Override
    public void setFont(Font font) {
        _graphics.setFont(font);

    }

    @Override
    public void setPaintMode() {
        _graphics.setPaintMode();

    }

    @Override
    public void setXORMode(Color c1) {
        _graphics.setXORMode(c1);

    }
}