/*
 * Licensed Materials - Property of Rogue Wave Software, Inc. 
 * © Copyright Rogue Wave Software, Inc. 2014, 2016 
 * © 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.
 */

import ilog.views.IlvPoint;
import ilog.views.IlvRect;
import ilog.views.graphic.IlvLabel;
import ilog.views.graphic.IlvRectangle;
import ilog.views.io.IlvOutputStream;
import ilog.views.tiling.IlvTile;
import ilog.views.tiling.IlvTileLoader;

/**
 * This tile loader generates graphics for a given tile. These graphics are
 * composed of: - The boundary of the tile - The name of the tile - The
 * coordinates of the tile
 */
public class ScaleLodLoader implements IlvTileLoader {
  /**
   * This variable stores the layer name
   */
  private String layerName;
  private int ratioFactor;

  /**
   * Constructs a new loader with specified name
   */
  public ScaleLodLoader(String name, int ratio) {
    layerName = name;
    ratioFactor = ratio;
  }

  /**
   * Loads the graphic objects for specified tile. For this example, this
   * simulate loading of data by generating graphic objects
   */
  public void load(IlvTile tile) throws Exception {
    IlvRect bbox = new IlvRect();
    tile.boundingBox(bbox);

    // Add this tile representation
    tile.addObject(new IlvRectangle(bbox), null);
    // Add a little text
    String text = this.layerName + " (" + (tile.getColumn() * ratioFactor) + "," + (tile.getRow() * ratioFactor) + ")";
    IlvPoint textCenter = new IlvPoint(bbox.x + bbox.width / 2, bbox.y + bbox.height / 2);
    tile.addObject(new IlvLabel(textCenter, text), null);

    tile.loadComplete();
  }

  /**
   * Release the objects on this tile
   */
  public void release(IlvTile tile) {
    tile.deleteAll();
  }

  // This loader is not persistent, so these methodes need not to
  // be active
  public boolean isPersistent() {
    return false;
  }

  public void write(IlvOutputStream stream) {
  }
}