/*
 * Licensed Materials - Property of Rogue Wave Software, Inc. 
 * © Copyright Rogue Wave Software, Inc. 2014, 2015 
 * © Copyright IBM Corp. 2009, 2014
 * © Copyright ILOG 1996, 2009
 * All Rights Reserved.
 *
 * Note to U.S. Government Users Restricted Rights:
 * The Software and Documentation were developed at private expense and
 * are "Commercial Items" as that term is defined at 48 CFR 2.101,
 * consisting of "Commercial Computer Software" and
 * "Commercial Computer Software Documentation", as such terms are
 * used in 48 CFR 12.212 or 48 CFR 227.7202-1 through 227.7202-4,
 * as applicable.
 */
package demo;

import java.util.StringTokenizer;

/**
 * Server side bean to store the view configuration: height, width and tiling parameters.
 */
public class ViewConfigurationBean {
  int width;
  int height;
  int tileSize;
  Boolean tiling;
  /**
   * @return the view height in pixels.
   */
  public int getHeight() {
    return height;
  }
  /**
   * @param height the view height to set.
   */
  public void setHeight(int height) {
    this.height = height;
  }
  /**
   * @return the tile size.
   */
  public int getTileSize() {
    return tileSize;
  }
  /**
   * @param tileSize the number of pixels each tile should have, or 0 to prevent tiling.
   */
  public void setTileSize(int tileSize) {
    this.tileSize = tileSize;
  }
  /**
   * @return the view width in pixels.
   */
  public int getWidth() {
    return width;
  }
  /**
   * @param width the view width to set.
   */
  public void setWidth(int width) {
    this.width = width;
  }
  /**
   * @return Indicates whether or not tiling is enabled.
   */
  public Boolean getTiling() {
    return Boolean.valueOf(getTileSize()!=0);
  }
  /** Sets the tiling on (tile size of 256) or off (0).
   * @param tiling should the view be tiled.
   */
  public void setTiling(Boolean tiling) {
    setTileSize(tiling.booleanValue()?256:0);
  }
  /**
   * @return the size in the format WxH for setting size in a single call.
   */
  public String getSize() {
    return getWidth()+"x"+getHeight(); //$NON-NLS-1$
  }
  /**
   * @param size the size in the format WxH.
   */
  public void setSize(String size) {
    StringTokenizer st=new StringTokenizer(size,"x"); //$NON-NLS-1$
    String w=st.nextToken();
    String h=st.nextToken();
    setWidth(Integer.parseInt(w));
    setHeight(Integer.parseInt(h));
  }
  
  /**
   * Returns the CSS style of the panel containing the views components.
   * @return The CSS style of the panel.
   */
  public String getPanelStyle() {
    return "position:relative;width:"+getWidth()+"px;height:"+getHeight()+"px;";//$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
  }

  /**
   * Returns the CSS style of the overview.
   * @return The CSS style of the overview.
   */
  public String getOverviewStyle() {
    int w = 180;
    int h = 90;
    int x =  getWidth() - w;
    int y = 0;    
    return "position:absolute;left:"+x+"px;top:"+y+"px;width:"+w+"px;height:"+h+"px;";//$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$//$NON-NLS-5$
  }

  /**
   * Returns the CSS style of the pan tool.
   * @return The CSS style of the pan tool.
   */
  public String getPanToolStyle() {
    int w = 50;
    int h = 50;
    int x =  0;
    int y = getHeight()-h-4;    
    return "position:absolute;left:"+x+"px;top:"+y+"px;width:"+w+"px;height:"+h+"px;";//$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$//$NON-NLS-5$
  }
       
}