/** * @(#)ZRect.java 12/12/99 * @author Peter Au * All rights reserved. */ package vishnu.testvis.treemap.rectangle; import java.awt.*; public class ZRect extends Rect{ //-- no of doc that the rectangle represented private int _capacity=0; //-- the new points that the rectangle will be translated (java coordination) protected float _t_left_x=0f, _t_left_y=0f, _t_right_x=0f, _t_right_y=0f; //-- if the rectangle has been choosen, set it to true private boolean _chosen=false; public ZRect(float x1, float y1, float x2, float y2, Color c){ super(x1, y1, x2, y2, c); } public ZRect(float x1, float y1, float x2, float y2, Color c, int s){ super(x1, y1, x2, y2, c); _capacity = s; } public int getCapacity(){return _capacity;} public void setCapacity(int i){_capacity=i;} public boolean isChosen(){return _chosen;} public void setChosen(){_chosen=true;} public void resetChosen(){_chosen=false;} /** * set the new coordinate, that the rectangle will move to * pre: the coordinate is based on Java graphic coordination * x1,y1 is the left upper corner and * x2,y2 is the right lower corner */ public void translateTo(float x1, float y1, float x2, float y2){ _t_left_x=x1; _t_left_y=y1; _t_right_x=x2; _t_right_y=y2; } private static boolean almostEqual(float a, float b){ float tolerant = 0.00001F; return (Math.abs(a-b) <= tolerant); } /** * @param x is the input value * @param x1 is the orginal x-coordinate of the rectangle * @param y1 is the orginal y-coordinate of the rectangle * @param x2 is the translated x-coordinate * @param y2 is the translated y-coordinate * @return y, based on x */ private static float newY( float x, float x1, float y1, float x2, float y2, int totalFrame, int currentFrame){ // return (x1==x2)? y2: ((x*(y1-y2) + x1*y2 - x2*y1) / (x1-x2)); if (almostEqual(x1,x2)) return ((y2-y1)/(float) totalFrame) * (float) (currentFrame+1) + y1; else return ((x*(y1-y2) + x1*y2 - x2*y1) / (x1-x2)); } /** * @param y is the input value * @param x1 is the orginal x-coordinate of the rectangle * @param y1 is the orginal y-coordinate of the rectangle * @param x2 is the translated x-coordinate * @param y2 is the translated y-coordinate * @return x, based on y */ private static float newX( float y, float x1, float y1, float x2, float y2, int totalFrame, int currentFrame){ // return (y1==y2)? x2: ((y*(x1-x2) - x1*y2 + x2*y1)/(y1-y2)); if (almostEqual(y1,y2)) return ((x2-x1)/(float) totalFrame) * (float) (currentFrame+1) + x1; else return ((y*(x1-x2) - x1*y2 + x2*y1)/(y1-y2)); } /** * pre: translateTo is called * @param how many animated pictures u want to create * @retrun a list of animation picture (rectangles with diff positions) */ public ZRect[] zooming(int noOfFrame){ ZRect[] vec = new ZRect[noOfFrame]; float dist1, dist2, t1, t2; switch (getDirection()){ case __NORTH: case __SOUTH: dist1 = (_t_left_y - getUpperLeftY())/(float)noOfFrame; dist2 = (_t_right_y - getLowerRightY())/(float)noOfFrame; t1 = getUpperLeftY(); t2 = getLowerRightY(); //-- create the animated pictures, except the last image for(int i=0;i