Dynamic logo layer
arcgissamples\display\MainApplication.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.awt.BorderLayout;
import java.io.File;
import java.io.IOException;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.SwingUtilities;

import com.esri.arcgis.beans.TOC.TOCBean;
import com.esri.arcgis.beans.map.MapBean;
import com.esri.arcgis.beans.toolbar.ToolbarBean;
import com.esri.arcgis.controls.ControlsMapNavigationToolbar;
import com.esri.arcgis.controls.ControlsMapRoamTool;
import com.esri.arcgis.system.AoInitialize;
import com.esri.arcgis.system.EngineInitializer;
import com.esri.arcgis.system.esriLicenseProductCode;
import com.esri.arcgis.system.esriLicenseStatus;
import com.esri.arcgis.systemUI.esriCommandStyles;

public class MainApplication extends JFrame {
  private static final long serialVersionUID = 1L;

  public static void main(String[] args) {
  //initialize the interop
  initializeInterop();
  //initialize to a license level
  initializeArcGISLicenses();
  //start the sample
  final MainApplication thisClass = new MainApplication();
  thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  SwingUtilities.invokeLater(new Runnable() {
      public void run() {
    thisClass.initializeUI();
    thisClass.setVisible(true);
      }
  });
    }


    private void initializeUI() {
  this.setSize(900, 800);
  this.setContentPane(getJContentPane());
  this.setTitle("Dynamic Display Application - Add Logo");
  this.addWindowListener(new java.awt.event.WindowAdapter() {
      public void windowClosing(java.awt.event.WindowEvent e) {
    try {
        new AoInitialize().shutdown();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
      }
  });
    }

    private JPanel jContentPane = null;

    private JPanel getJContentPane() {
  if (jContentPane == null) {
      jContentPane = new JPanel();
      jContentPane.setLayout(new BorderLayout());
      jContentPane.add(getToolbarBean(), java.awt.BorderLayout.NORTH);
      jContentPane.add(getJSplitPane(), java.awt.BorderLayout.CENTER);
  }
  return jContentPane;
    }

    private ToolbarBean toolbarBean = null;

    private ToolbarBean getToolbarBean() {
  if (toolbarBean == null) {
      toolbarBean = new ToolbarBean();

      try {
    //Add the AddLogoCommand to the toolbar
    toolbarBean.addItem(new AddLogoCommand(), 0, 0, false, 0,
        esriCommandStyles.esriCommandStyleIconAndText);
    toolbarBean.addItem(new ControlsMapNavigationToolbar(), 0,1,false,0,esriCommandStyles.esriCommandStyleIconOnly);
    toolbarBean.addItem(new ControlsMapRoamTool(), 0, -1, false, 0,
        esriCommandStyles.esriCommandStyleIconAndText);

    toolbarBean.setBuddyControl(getMapBean());
      } catch (IOException e) {
    e.printStackTrace();
      }
  }
  return toolbarBean;
    }

    private JSplitPane jSplitPane = null;

    private JSplitPane getJSplitPane() {
  if (jSplitPane == null) {
      jSplitPane = new JSplitPane();
      jSplitPane.setDividerLocation(150);
      jSplitPane.setDividerSize(2);
      jSplitPane.setRightComponent(getMapBean());
      jSplitPane.setLeftComponent(getTOCBean());
  }
  return jSplitPane;
    }

    private TOCBean TOCBean = null;

    private TOCBean getTOCBean() {
  if (TOCBean == null) {
      TOCBean = new TOCBean();
      try {
    TOCBean.setBuddyControl(getMapBean());
      } catch (IOException e) {
    e.printStackTrace();
      }
  }
  return TOCBean;
    }

    private MapBean mapBean = null;

    private MapBean getMapBean() {
  if (mapBean == null) {
      mapBean = new MapBean();
      //Get DEVKITHOME Home
    String devKitHome = System.getenv("AGSDEVKITJAVA");
      
      if (devKitHome != null && !"".equals(devKitHome)) {
    try {
        mapBean.loadMxFile(devKitHome + "java" + File.separator + 
                        "samples" + File.separator + 
                        "data" + File.separator + 
                        "mxds" + File.separator +
                        "gulf of st. lawrence.mxd", null, null);
    } catch (Exception e) {
        e.printStackTrace();
    }
      }
  }
  return mapBean;
    }

    static void initializeInterop() {
  //Visual beans mode required for multi-threaded applciations.
  EngineInitializer.initializeVisualBeans();
    }

    static void initializeArcGISLicenses() {
  try {
      AoInitialize ao = new AoInitialize();
      if (ao.isProductCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeEngine) == esriLicenseStatus.esriLicenseAvailable)
    ao.initialize(esriLicenseProductCode.esriLicenseProductCodeEngine);
      else if (ao.isProductCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeArcView) == esriLicenseStatus.esriLicenseAvailable)
    ao.initialize(esriLicenseProductCode.esriLicenseProductCodeArcView);
      else{
    System.err.println("Could not initialize an Engine or ArcView license. Exiting application.");
        System.exit(-1);
      }
  } catch (Exception e) {
      e.printStackTrace();
  }
    }
} // @jve:decl-index=0:visual-constraint="10,10"