import java.awt.Color;
import java.awt.Graphics;

public class Window {
    /** The length of the resizing triangle's non-hypotenuse edges. */
    private static final int RESIZE_TRIANGLE_SIZE = 10;

    /** The name of this window. */
    private String name;

    /** The color of this window. */
    private Color color;

    /** The x-coordinate of this window's left edge. */
    private int x;

    /** The y-coordinate of this window's top edge. */
    private int y;

    /** The width of this window, in pixels. */
    private int width;

    /** The height of this window, in pixels. */
    private int height;

    /** Constructs a window with the given name, color,
     * position, and size. */
    public Window(String inName, Color inColor, int inX, int inY,
            int inWidth, int inHeight) {
        name = inName;
        color = inColor;
        x = inX;
        y = inY;
        width = inWidth;
        height = inHeight;
    }

    /** Returns the x-coordinate of this window's left edge. */
    public int getX() {
        return x;
    }

    /** Returns the y-coordinate of this window's top edge. */
    public int getY() {
        return y;
    }

    /** Returns the width of this window, in pixels. */
    public int getWidth() {
        return width;
    }

    /** Returns the height of this window, in pixels. */
    public int getHeight() {
        return height;
    }

    /** Paints this window using g. */
    public void paint(Graphics g) {
        g.setColor(color);
        g.fillRect(x, y, width, height);
        g.setColor(Color.BLACK);
        g.drawRect(x, y, width, height);

        int resizeSize = Math.min(RESIZE_TRIANGLE_SIZE,
                Math.min(width, height));
        g.drawLine(x + width, y + height - resizeSize,
                x + width - resizeSize, y + height);
    }

    /** Returns a string representation of this window. */
    public String toString() {
        return name + "[" + x + "," + y + "/"
            + width + "x" + height + "]";
    }

    /** Changes the location of this window as specified. */
    public void setLocation(int inX, int inY) {
        x = inX;
        y = inY;
    }

    /** Changes the size of this window as specified. */
    public void setSize(int inWidth, int inHeight) {
        width = inWidth;
        height = inHeight;
    }

    /** Returns true if the query point lies within this
     * window's resize region. The method assumes that the query
     * point lies within the overall window. */
    public boolean isInResizeRegion(int queryX, int queryY) {
        int resizeSize = Math.min(RESIZE_TRIANGLE_SIZE,
                Math.min(width, height));
        return queryX + queryY >= x + width + y + height - resizeSize;
    }
}
