Select Git revision
-
Radu-Andrei Coanda authoredRadu-Andrei Coanda authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
Canvas.java 23.23 KiB
/*
* HINWEIS:
*
* Sie brauchen den Java-Code, der in dieser Datei steht, nicht zu lesen oder zu
* verstehen. Alle Hinweise, die zur Verwendung der Datei noetig sind, koennen Sie
* aus den jeweiligen Aufgabentexten entnehmen.
*/
import java.awt.*;
import java.awt.event.*;
import java.awt.font.*;
import java.awt.geom.*;
import java.util.*;
import javax.swing.*;
/**
* User interface for a Logo-like language. Allows to see the painting process step-by-step.
*/
public class Canvas {
/**
* The color brown.
*/
public static final Color BROWN = new Color(160, 82, 45);
/**
* The color green.
*/
public static final Color GREEN = Color.GREEN;
/**
* Adds the current position to the specified bounds.
* @param g The graphics object to draw on.
* @param boundsParam The bounds of the canvas.
*/
private static void addCurrentPos(Graphics2D g, Rectangle boundsParam) {
if (boundsParam != null) {
Canvas.addToBounds(new Point2D.Float(0f, 0f), boundsParam, g);
}
}
/**
* Adds a point to the bounds, transformed as in the current graphics object.
* @param point The point to add to the bounds.
* @param boundsParam The bounds.
* @param g The graphics object storing affine transformations.
*/
private static void addToBounds(Point2D point, Rectangle boundsParam, Graphics2D g) {
boundsParam.add(g.getTransform().transform(point, null));
}
/**
* Adds a rectangle to the bounds, transformed as in the current graphics object.
* @param r The rectangle to add to the bounds.
* @param boundsParam The bounds.
* @param g The graphics object storing affine transformations.
*/
private static void addToBounds(Rectangle2D r, Rectangle boundsParam, Graphics2D g) {
double maxX = r.getMaxX();
double maxY = r.getMaxY();
double minX = r.getMinX();
double minY = r.getMinY();
Canvas.addToBounds(new Point2D.Double(maxX, maxY), boundsParam, g);
Canvas.addToBounds(new Point2D.Double(maxX, minY), boundsParam, g);
Canvas.addToBounds(new Point2D.Double(minX, maxY), boundsParam, g);
Canvas.addToBounds(new Point2D.Double(minX, minY), boundsParam, g);
}
/**