Package ket.display.box

Source Code of ket.display.box.BorderedBox

/*
* Copyright (C) 2011  Alasdair C. Hamilton
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>
*/

package ket.display.box;

import java.awt.GradientPaint;
import java.awt.Color;
import java.awt.Graphics2D;

import geom.Offset;
import geom.Position;

import ket.display.ColourScheme;
import ket.display.BorderedColourSchemeDecorator;
import ket.math.Argument;

/**
* Display a box with a coloured background and border.
*/
public class BorderedBox extends Box {

  public static final int THICKNESS = 2;

  Box content;
  BorderedColourSchemeDecorator colourScheme;

  @Override
  public Box cloneBox() {
    return new BorderedBox(getArgument(), content, getSettings(), colourScheme.isHighlighted(), colourScheme.getDecoratedColourScheme());
  }

  public ColourScheme getColourScheme() {
    return colourScheme;
  }

  public BorderedBox(Argument argument, Box content, long settings, boolean highlight, ColourScheme colourScheme) {
    super(argument, settings);
    this.content = content;
    this.colourScheme = new BorderedColourSchemeDecorator(colourScheme, highlight);
  }

  @Override
  protected void calcMinimumSize() {
    content.setupInnerRectangle(Box.DEFAULT_BOX_FONT_SIZE); // TODO: Use the correct font size. given the recursive depth.
    Offset contentInner = content.getInnerRectangle();
    innerRectangle = new Offset(contentInner.width+5, contentInner.height+5);
  }

  @Override
  public void setupOuterRectangle(Offset actualSize) {
    content.setupOuterRectangle(content.getInnerRectangle());
    innerRectangle = new Offset(content.getInnerRectangle().width+5, content.getInnerRectangle().height+5);
    super.setupOuterRectangle(new Offset(actualSize.width, actualSize.height));
  }

  @Override
  public void draw(Graphics2D g2D, Position topLeft, ColourScheme colourScheme) {
    this.topLeft = topLeft; //?
    int x = (int) getXPosition(topLeft);
    int y = (int) getYPosition(topLeft);

    // Draw a bevelled border using a gradient of unselected argument colours.
    Color gradientFromColour = this.colourScheme.getGradientFrom();
    Color gradientToColor = this.colourScheme.getGradientTo();

    // Paint the background. 
    GradientPaint gp = new GradientPaint(
        (int) topLeft.x, (int) topLeft.y,
        gradientFromColour,
        (int) topLeft.x + (int) outerRectangle.width,
        (int) topLeft.y + 2 * (int) outerRectangle.height,
        gradientToColor, false);

    g2D.setPaint(gp);
    g2D.fillRoundRect(x, y, (int) innerRectangle.width, (int) innerRectangle.height, 10, 10);
    //- content.setColour(this.colourScheme.getBackgroundColour());

    // Paint the border.
    g2D.setColor(this.colourScheme.getBorderColour()); // edge
    g2D.drawRoundRect(x, y, (int) innerRectangle.width, (int) innerRectangle.height, 10, 10);

    Position contentTL = new Position(x+2, y+2);
    content.paint(g2D, contentTL, this.colourScheme);
  }

  @Override
  public String toString() {
    return "BorderedBox of:\n\t" + content.toString() + " ";
  }

}
TOP

Related Classes of ket.display.box.BorderedBox

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.