⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 magicplanetimagecomponent.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
// **********************************************************************////<copyright>////BBN Technologies, a Verizon Company//10 Moulton Street//Cambridge, MA 02138//(617) 873-8000////Copyright (C) BBNT Solutions LLC. All rights reserved.////</copyright>//**********************************************************************////$Source:///cvs/darwars/ambush/aar/src/com/bbn/ambush/mission/MissionHandler.java,v//$//$RCSfile: MagicPlanetImageComponent.java,v $//$Revision: 1.1.2.3 $//$Date: 2005/08/11 21:03:12 $//$Author: dietrick $////**********************************************************************package com.bbn.openmap.image;import java.awt.Paint;import java.awt.Point;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.beans.PropertyChangeEvent;import java.beans.PropertyChangeListener;import java.io.File;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.text.DecimalFormat;import java.util.Calendar;import java.util.GregorianCalendar;import java.util.Properties;import javax.swing.JOptionPane;import javax.swing.Timer;import com.bbn.openmap.Environment;import com.bbn.openmap.I18n;import com.bbn.openmap.LatLonPoint;import com.bbn.openmap.Layer;import com.bbn.openmap.LayerHandler;import com.bbn.openmap.MapBean;import com.bbn.openmap.OMComponent;import com.bbn.openmap.event.LayerEvent;import com.bbn.openmap.event.LayerListener;import com.bbn.openmap.proj.LLXY;import com.bbn.openmap.proj.Projection;import com.bbn.openmap.util.Debug;import com.bbn.openmap.util.PropUtils;/** * The MagicPlanetImageComponent is an OpenMap Component designed to create * images for Global Imagination's MagicPlanet Globe. This component, when added * to an OpenMap MapHandler, will find the LayerHandler so it can find out when * the Layer given to the MapBean change, so it knows which ones to use when * creating an image file. This component also connects to the MapBean as a * PropertyChangeListener to find out when the ocean color has changed. The * MagicPlanet software (Storyteller) has the option of displaying images stored * in a particular directory, either displaying the latest (lexically) image or * cycling through a set of images in the directory to create a movie on the * globe. * <p> *  * The class has options that change the format of the images created, where the * images are stored, how often they are created, and the scale of the images. * The scale of the image dictates its pixel size, since the proportion of the * projection has to be constant for it to work on the globe. The projection * used for the images is always the OpenMap LLXY projection, that's what the * MagicPlanet expects. * <p> *  * The properties for this component are: *  * <pre> *            outputDirectory=path_to_directory_for_writing_images *             *            # Milliseconds between image creation, 60000 is the default, representing 1 minute *            updateInterval=60000 *             *            # The scale of the image, it determines the size of the image.  This  *            # may be important for certain layers to show particular details.   *            # The default is 60000000F, which represents an image approximately 2kx1k *            scale=60000000F *             *            # Property to tell the component to create a new image and reset the timer if the  *            # layers on the MapBean change.  True by default. *            autoUpdate=true *             *            # Property to tell the component to remove old images, default is true *            cleanup=true *             *            # Property to set the wait time before deleting old images, represented  *            # in milliseconds. The default is 86400000, representing one day.  *            cleanupInterval=86400000 *             *            # Properties for setting the pixel width and height of the images. These properties  *            # provide a more precise way to control the image size, and tell the component to  *            # scale the image created with the scale setting set above.  The closer you get  *            # the scale to provide you the image size you want, the higher quality image  *            # you will have.  The default values for these properties are -1, which tells *            # the component to not change the size of the image resulting from the scale setting. *            width=-1  *            height=-1 *             *            # Property to set the name of the last image written in a file, so other programs  *            # can more easily figure out what it was.  The property should reflect the path  *            # to the file to be written, which will contain 'MagicPlanet.lastFile=YYYYMMDDhhmmss.ext', *            # where YYYYMMDDhhmmss are year, month, day, hour, minute and second the file was created,  *            # and ext is the extension for the image type.  This information, combined with the directory  *            # information stored above, will let you know where the file is.  If this property is not set,  *            # no text file will be written. *            lastImageFile=path_to_text_file  *             *            # Property that describes a system command that should be run each time an image is created. *            # The property should contain exactly what would be typed into a command line for a script  *            # to be run, in the same environment this component is being run in.  There are special arguments *            # that can be inserted into this property string that the component will use to replace the current *            # image file name: *            # *            # %FILEPATH% gets replaced with the complete path of the new image file. *            # %FILENAME% gets replaced with the file name if the image file. *            # %FILENAME_WITHOUT_EXTENSION% gets replaced with the file name without a '.' or anything after that. *            # *            # The default is no value being set for the script, which means nothing will happen.  Here is an example for *            # creating a .dds file from the current image, using nvidiea's nvdxt script. *            postProcessingScript=&quot;c:/Program Files/NVIDIA Corporation/NVIDIA DDS Utilities/nvdxt.exe&quot; -swap -dxt1c -file %FILEPATH% -output c:/%FILENAME_WITHOUT_EXTENSION%.dds * </pre> *  * @author dietrick */public class MagicPlanetImageComponent extends OMComponent implements		LayerListener, PropertyChangeListener, ActionListener {	public final static String OutputDirectoryProperty = "outputDirectory";	public final static String UpdateIntervalProperty = "updateInterval";	public final static String ScaleProperty = "scale";	public final static String AutoUpdateProperty = "autoUpdate";	public final static String CleanupProperty = "cleanup";	public final static String CleanupIntervalProperty = "cleanupInterval";	public final static String HeightProperty = "height";	public final static String WidthProperty = "width";	public final static String LastImageFileProperty = "lastImageFile";	public final static String PostProcessingScriptProperty = "postProcessingScript";	public final static String LAST_IMAGE_FILE_KEY = "MagicPlanet.lastFile";	public final static String REPLACE_FILEPATH_MARKER = "%FILEPATH%";	public final static String REPLACE_FILENAME_MARKER = "%FILENAME%";	public final static String REPLACE_FILENAME_WOEXT_MARKER = "%FILENAME_WITHOUT_EXTENSION%";	protected boolean DEBUG = false;	// Kept in case replacements are added to the application, so we	// remember who to disconnect from.	protected LayerHandler layerHandler;	protected MapBean mapBean;	/**	 * Parent directory for images.	 */	protected String outputDirectoryString;	protected int updateInterval = 60000;	protected float scale = 60000000F; // Produces 2k x 1k image	protected Projection proj;	protected Paint background;	protected Layer[] layers;	protected boolean autoUpdate = true;	protected ImageFormatter imageFormatter = new SunJPEGFormatter();	protected boolean cleanup = true;	protected int cleanupInterval = 86400000; // one day	protected int height = -1;// unscaled, go with scale	protected int width = -1; // unscaled, go with scale	protected String lastImageFile = null;	protected String postProcessingScript = null;	protected Timer timer;	public MagicPlanetImageComponent() {		DEBUG = Debug.debugging("magicplanet");	}	/**	 * MapHandlerChild method extended through the OMComponent hierarchy. This	 * is the method called by the MapHandler with objects added to the	 * MapHandler.	 */	public void findAndInit(Object someObj) {		if (someObj instanceof LayerHandler) {			setLayerHandler((LayerHandler) someObj);		}		if (someObj instanceof MapBean) {			setMapBean((MapBean) someObj);		}	}	/**	 * MapHandlerChild method extended through the OMComponent hierarchy. This	 * is the method called by the MapHandler with objects removed from the	 * MapHandler.	 */	public void findAndUndo(Object someObj) {		if (someObj instanceof LayerHandler && someObj == getLayerHandler()) {			setLayerHandler(null);		}		if (someObj instanceof MapBean && someObj == getMapBean()) {			setMapBean(null);		}	}	/**	 * Get the timer being used for automatic updates. May be null if a timer is	 * not set.	 */	public Timer getTimer() {		return timer;	}	/**	 * If you want the layer to update itself at certain intervals, you can set	 * the timer to do that. Set it to null to disable it. If the current timer	 * is not null, the graphic loader is removed as an ActionListener. If the	 * new one is not null, the graphic loader is added as an ActionListener.	 */	public void setTimer(Timer t) {		if (timer != null) {			timer.removeActionListener(this);			timer.stop();		}		timer = t;		if (timer != null) {			timer.addActionListener(this);		}	}	/**	 * Creates a timer with the current updateInterval and calls setTimer().	 */	public void createTimer() {		Timer t = new Timer(updateInterval, null);		t.setInitialDelay(0);		setTimer(t);	}	/**	 * The delay between timer pulses, in milliseconds.	 */	public void setUpdateInterval(int delay) {		updateInterval = delay;		if (timer != null) {			timer.setDelay(updateInterval);			if (timer.isRunning()) {				timer.restart();			}		}	}	public int getUpdateInterval() {		return updateInterval;	}	/*	 * Called when the timer kicks off.	 * 	 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)	 */	public void actionPerformed(ActionEvent e) {		if (false && DEBUG) {			Debug.output("MPIC.actionPerformed("					+ e.getSource().getClass().getName() + ")");		}		createImage();	}	/**	 * @return the object currently known as the LayerHandler by this object.	 */	protected LayerHandler getLayerHandler() {		return layerHandler;	}	/**	 * Set the LayerHandler, become a LayerListener object to it to know when	 * the layers on the MapBean change. If there is already a LayerHandler	 * known to this component, this component will remove itself as a listener	 * to the previous LayerHandler.	 * 	 * @param lh LayerHandler.	 */	protected void setLayerHandler(LayerHandler lh) {		if (layerHandler != null) {			layerHandler.removeLayerListener(this);		}		layerHandler = lh;		if (layerHandler != null) {			layerHandler.addLayerListener(this);			// calling setLayers() will kick off an image creation.			// Don't want that right now, just setting the layers for			// initialization purposes, we'll let events or timer			// create the image.			layers = layerHandler.getMapLayers();			Timer timer = getTimer();			if (timer == null) {				createTimer();			}		}	}	/**	 * @return the object currently known as the MapBean by this object.	 */	protected MapBean getMapBean() {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -