Custom Resource
com\esri\adf\sample\resource\util\MyCustomUtil.java
/* Copyright 2010 ESRI
* 
* All rights reserved under the copyright laws of the United States
* and applicable international laws, treaties, and conventions.
* 
* You may freely redistribute and use this sample code, with or
* without modification, provided you include the original copyright
* notice and use restrictions.
* 
* See the use restrictions.
* 
*/
package com.esri.adf.sample.resource.util;

import java.text.DecimalFormat;
import java.util.ArrayList;

import com.esri.adf.sample.resource.ADFMyCustomException;
import com.esri.adf.web.data.GraphicElement;
import com.esri.adf.web.data.WebElementConverter;
import com.esri.adf.web.data.geometry.WebExtent;
import com.esri.adf.web.data.geometry.WebPath;
import com.esri.adf.web.data.geometry.WebPoint;
import com.esri.adf.web.data.geometry.WebPolyline;
import com.esri.adf.web.data.symbol.WebSimpleLineSymbol;
import com.esri.adf.web.data.symbol.WebTrueTypeMarkerSymbol;

public class MyCustomUtil {
  private MyCustomUtil() {
  }

  public static GraphicElement drawGrid(int width, int height, int divider) {
    GraphicElement element = new GraphicElement();
    WebPolyline geometry = new WebPolyline();
    int value = 0;
    WebPath path = null;
    while (value < height - divider) {
      path = new WebPath();
      path.addPoint(new WebPoint(0, value += divider));
      path.addPoint(new WebPoint(width, value));
      geometry.addPath(path);
    }
    value = 0;
    while (value < width - divider) {
      path = new WebPath();
      path.addPoint(new WebPoint(value += divider, 0));
      path.addPoint(new WebPoint(value, height));
      geometry.addPath(path);
    }
    element.setGeometry(geometry);
    WebSimpleLineSymbol symbol = new WebSimpleLineSymbol();
    symbol.setWidth(2);
    symbol.setColor("0,0,0");
    element.setSymbol(symbol);
    return element;
  }

  public static void drawExtent(WebElementConverter converter, int width, int height, WebExtent currentExtent) {
    try {
      DecimalFormat format = new DecimalFormat("###.00");
      GraphicElement element = new GraphicElement();
      WebTrueTypeMarkerSymbol font = new WebTrueTypeMarkerSymbol();
      font.setFontName("Arial");
      font.setFontColor("0,0,255");
      font.setFontStyle(WebTrueTypeMarkerSymbol.BOLD);
      font.setFontSize(15);
      ArrayList<String> text = new ArrayList<String>(1);
      text.add(format.format(currentExtent.getMinX()));
      font.setTextValues(text);
      element.setGeometry(new WebPoint(30, 15));
      element.setSymbol(font);
      converter.draw(element);
      text.clear();
      text.add(format.format(currentExtent.getMinX()));
      font.setAngle(0);
      element.setGeometry(new WebPoint(30, height - 15));
      converter.draw(element);
      text.clear();
      text.add(format.format(currentExtent.getMaxX()));
      font.setAngle(0);
      element.setGeometry(new WebPoint(width - 50, 15));
      converter.draw(element);
      text.clear();
      text.add(format.format(currentExtent.getMaxX()));
      font.setAngle(0);
      element.setGeometry(new WebPoint(width - 50, height - 15));
      converter.draw(element);

      text.clear();
      text.add(format.format(currentExtent.getMaxY()));
      font.setAngle(90.0);
      element.setGeometry(new WebPoint(15, 50));
      converter.draw(element);
      text.clear();
      text.add(format.format(currentExtent.getMinY()));
      font.setAngle(90.0);
      element.setGeometry(new WebPoint(15, height - 50));
      converter.draw(element);
      text.clear();
      text.add(format.format(currentExtent.getMaxY()));
      font.setAngle(270.0);
      element.setGeometry(new WebPoint(width - 15, 50));
      converter.draw(element);
      text.clear();
      text.add(format.format(currentExtent.getMinY()));
      font.setAngle(270.0);
      element.setGeometry(new WebPoint(width - 15, height - 50));
      converter.draw(element);
    } catch (Exception e) {
      throw new ADFMyCustomException("Unable to draw Current Extent");
    }
  }
}