FurniturePlanner/src/Recliner.java

62 lines
2.2 KiB
Java

import java.awt.Color;
import java.awt.Shape;
import java.awt.geom.GeneralPath;
import java.awt.geom.Rectangle2D;
/**
* Ein Sessel, der manipuliert werden kann und sich selbst auf einer Leinwand
* zeichnet.
*
* @author Claus Albowski
* @version 2.2 (aug 07)
*/
public class Recliner extends Furniture {
private static final long serialVersionUID = 1L;
/**
* Erzeuge einen neuen Sessel mit einer Standardfarbe und Standardgroesse an
* einer Standardposition. (Standardkonstruktor)
*/
public Recliner() {
xPosition = 250;
yPosition = 70;
color = Color.green;
orientation = 90;
isVisible = false;
width = 60;
depth = 60;
}
public Recliner(int xPosition, int yPosition, Color color, int orientation) {
this.xPosition = xPosition;
this.yPosition = yPosition;
this.color = color;
this.currentColor = color; // the default color is set to the initial color
this.defaultColor = color; // the default color is set to the initial color
this.orientation = orientation;
isVisible = false;
width = 60;
depth = 60;
this.defaultWidth = width; // the default width is set to the initial width
this.defaultDepth = depth; // the default width is set to the initial depth
}
/**
* Berechnet das zu zeichnende Shape anhand der gegebenen Daten
*/
protected Shape getCurrentFigure() {
// einen GeneralPath definieren
GeneralPath recliner = new GeneralPath();
Rectangle2D leftArmRest = new Rectangle2D.Double(0, 0, width / 6, depth);
Rectangle2D rightArmRest = new Rectangle2D.Double(5 * width / 6, 0, width / 6, depth);
Rectangle2D sittingArea = new Rectangle2D.Double(width / 6, depth / 6, 2 * width / 3, depth - depth / 6);
Rectangle2D back = new Rectangle2D.Double(width / 6, 0, 2 * width / 3, depth / 6);
recliner.append(leftArmRest, false);
recliner.append(rightArmRest, false);
recliner.append(sittingArea, false);
recliner.append(back, false);
return transform(recliner);
}
}