Dynamic logo layer
arcgissamples\display\LogoLayer.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 arcgissamples.display;

import java.io.IOException;
import java.util.HashMap;

import com.esri.arcgis.carto.IDynamicLayer;
import com.esri.arcgis.carto.ILayer;
import com.esri.arcgis.display.IDisplay;
import com.esri.arcgis.display.IDynamicDisplay;
import com.esri.arcgis.display.IDynamicDrawScreen;
import com.esri.arcgis.display.IDynamicGlyph;
import com.esri.arcgis.display.IDynamicGlyphFactory;
import com.esri.arcgis.display.IDynamicSymbolProperties;
import com.esri.arcgis.display.RgbColor;
import com.esri.arcgis.display.esriDynamicDrawPhase;
import com.esri.arcgis.display.esriDynamicGlyphType;
import com.esri.arcgis.display.esriDynamicSymbolType;
import com.esri.arcgis.geometry.Envelope;
import com.esri.arcgis.geometry.ISpatialReference;
import com.esri.arcgis.geometry.Point;
import com.esri.arcgis.interop.AutomationException;
import com.esri.arcgis.system.ITrackCancel;
import com.esri.arcgis.system.esriDrawPhase;

public class LogoLayer implements ILayer, IDynamicLayer {
  private static final long serialVersionUID = 1L;

  // holds the state of the layer for different phases. true=dirty,
    // false=!dirty
    private HashMap<Integer, Boolean> layerState = new HashMap<Integer, Boolean>();

    public LogoLayer() {
  // Set the layer as dirty (for compiled phase) at the begining of time.
  // This will force it to get drawn when it's added to the map
  layerState.put(esriDynamicDrawPhase.esriDDPCompiled, true);
  layerState.put(esriDynamicDrawPhase.esriDDPImmediate, false);
    }

    public boolean isDynamicLayerDirty(int dynamicDrawPhase)
      throws IOException, AutomationException {
  return this.layerState.get(dynamicDrawPhase);
    }

    public void setDynamicLayerDirty(int dynamicDrawPhase, boolean dirty)
      throws IOException, AutomationException {
  this.layerState.put(dynamicDrawPhase, dirty);

    }

    public int getDynamicRecompileRate() throws IOException,
      AutomationException {
  // set the recomile rate to a large value (in msec)
  // because the drawing commands for the logo don't change
  // set this value to be low if you're periodically changing what
  // you draw in drawDynamicLayer() of compiled phase
  return 10000;
    }

    private IDynamicGlyphFactory glyphFactory;

    private IDynamicSymbolProperties symbolProperties;

    private IDynamicDrawScreen dynamicDrawScreen;

    private IDynamicGlyph logoGlyph;

    private Point anchor;

    // this method gets called to draw in dynamic mode
    public void drawDynamicLayer(int dynamicDrawPhase, IDisplay display,
      IDynamicDisplay dynamicDisplay) throws IOException,
      AutomationException {
  try {
      // draw in the Compiled phase of dynamic display when the
      // layer is visible.
      // Compile phase is used in order to draw semi-static items
                // (items
      // which have update rate lower than the display update rate).
      if (!this.isValid() || !this.isVisible()
        || dynamicDrawPhase != esriDynamicDrawPhase.esriDDPCompiled)
    return;
      // create the logoGlyph only once using the Dynamic Display API
      if (glyphFactory == null) {
    glyphFactory = dynamicDisplay.getDynamicGlyphFactory();
    symbolProperties = (IDynamicSymbolProperties) dynamicDisplay;

    dynamicDrawScreen = (IDynamicDrawScreen) dynamicDisplay;

    // create the dynamic glyph for the logo
    RgbColor white = new RgbColor();
    white.setRed(255);
    white.setBlue(255);
    white.setGreen(255);
    String logoPath = this.getClass().getClassLoader().getResource(
        "esri_logo.png").getPath();
      if(System.getProperty("os.name").toLowerCase().indexOf("win")>-1){
      logoPath =logoPath.substring(1).replaceAll("%20"," ");
      }

    logoGlyph = glyphFactory.createDynamicGlyphFromFile(
        esriDynamicGlyphType.esriDGlyphMarker, logoPath, white);
    anchor = new Point();
    anchor.putCoords(120, 160);
    symbolProperties.setDynamicGlyphByRef(
        esriDynamicSymbolType.esriDSymbolMarker, logoGlyph);
    symbolProperties.setScale(
        esriDynamicSymbolType.esriDSymbolMarker, 0.5f, 0.5f);
    // Set the dirty flag to false to prevent the layer from being
                // drawn repetitively.
    // The logo is static and so we can afford to do this.
    this.setDynamicLayerDirty(esriDynamicDrawPhase.esriDDPCompiled,
        false);
      }
      // draw the logo
      dynamicDrawScreen.drawScreenMarker(anchor);

  } catch (Exception e) {
      e.printStackTrace();
  }
    }

    public Envelope getAreaOfInterest() throws IOException,
      AutomationException {
  return null;
    }

    public String getName() throws IOException, AutomationException {
  return this.name;
    }

    public int getSupportedDrawPhases() throws IOException, AutomationException {
  return esriDrawPhase.esriDPAnnotation;
    }

    public String getTipText(double x, double y, double tolerance)
      throws IOException, AutomationException {
  return null;
    }

    public boolean isShowTips() throws IOException, AutomationException {
  return showTips;
    }

    public boolean isValid() throws IOException, AutomationException {
  return true;
    }

    private boolean cached = false;

    public void setCached(boolean cached) throws IOException,
      AutomationException {
  this.cached = cached;
    }

    public boolean isCached() throws IOException, AutomationException {
  return this.cached;
    }

    private double maxScale;

    public void setMaximumScale(double maxScale) throws IOException,
      AutomationException {
  this.maxScale = maxScale;

    }

    public double getMaximumScale() throws IOException, AutomationException {
  return this.maxScale;
    }

    private double minScale;

    public void setMinimumScale(double minScale) throws IOException,
      AutomationException {
  this.minScale = minScale;

    }

    public double getMinimumScale() throws IOException, AutomationException {
  return this.minScale;
    }

    private String name = "ESRI Logo";

    public void setName(String name) throws IOException, AutomationException {
  this.name = name;
    }

    private boolean showTips;

    public void setShowTips(boolean show) throws IOException,
      AutomationException {
  this.showTips = show;

    }

    @SuppressWarnings("unused")
  private ISpatialReference spatialRef;

    public void setSpatialReferenceByRef(ISpatialReference rhs1)
      throws IOException, AutomationException {
  this.spatialRef = rhs1;
    }

    private boolean visible = true;

    public void setVisible(boolean visible) throws IOException,
      AutomationException {
  this.visible = visible;

    }

    public boolean isVisible() throws IOException, AutomationException {
  return visible;
    }

    public void draw(int drawPhase, IDisplay display, ITrackCancel trackCancel)
      throws IOException, AutomationException {
  // empty implemenation
  // this layer will only be drawn in dynamic mode
    }

}