imagetilelayer.java
来自「OpenMap是一个基于JavaBeansTM的开发工具包。利用OpenMap你」· Java 代码 · 共 1,440 行 · 第 1/4 页
JAVA
1,440 行
//**********************************************************************////<copyright>////BBN Technologies//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: ImageTileLayer.java,v $//$Revision: 1.1.4.4 $//$Date: 2007/01/22 16:34:07 $//$Author: dietrick $////**********************************************************************package com.bbn.openmap.layer.imageTile;import java.awt.Color;import java.awt.Component;import java.awt.Dimension;import java.awt.Font;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.Insets;import java.awt.Polygon;import java.awt.Rectangle;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.MouseEvent;import java.awt.event.MouseListener;import java.awt.event.MouseMotionListener;import java.awt.geom.Line2D;import java.awt.geom.Rectangle2D;import java.io.File;import java.io.IOException;import java.net.MalformedURLException;import java.net.URL;import java.util.Iterator;import java.util.Properties;import java.util.Vector;import java.util.logging.Level;import java.util.logging.Logger;import javax.swing.DefaultListModel;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JFileChooser;import javax.swing.JLabel;import javax.swing.JList;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JToggleButton;import javax.swing.ListCellRenderer;import javax.swing.ListModel;import javax.swing.ListSelectionModel;import javax.swing.event.ListSelectionEvent;import javax.swing.event.ListSelectionListener;import javax.swing.filechooser.FileFilter;import com.bbn.openmap.Environment;import com.bbn.openmap.I18n;import com.bbn.openmap.LatLonPoint;import com.bbn.openmap.MapBean;import com.bbn.openmap.MapHandler;import com.bbn.openmap.dataAccess.image.ErrImageTile;import com.bbn.openmap.dataAccess.image.ImageReader;import com.bbn.openmap.dataAccess.image.ImageReaderLoader;import com.bbn.openmap.dataAccess.image.ImageTile;import com.bbn.openmap.event.LayerStatusEvent;import com.bbn.openmap.gui.LayerControlButtonPanel;import com.bbn.openmap.gui.LayersPanel;import com.bbn.openmap.layer.OMGraphicHandlerLayer;import com.bbn.openmap.omGraphics.DrawingAttributes;import com.bbn.openmap.omGraphics.OMColor;import com.bbn.openmap.omGraphics.OMGraphic;import com.bbn.openmap.omGraphics.OMGraphicList;import com.bbn.openmap.proj.Proj;import com.bbn.openmap.tools.icon.BasicIconPart;import com.bbn.openmap.tools.icon.IconPart;import com.bbn.openmap.tools.icon.IconPartList;import com.bbn.openmap.tools.icon.OMIconFactory;import com.bbn.openmap.util.ComponentFactory;import com.bbn.openmap.util.PropUtils;/** * The ImageTileLayer is a layer that manages georeferenced images over a map. * The layer uses ImageReaders to figure out how to load images from a file, * create an ImageTile object from the image data, and deduce where the * ImageTile should be located from the information provided with/in the image * data. * <P> * * ImageReaderLoader objects are held by the layer to assist in finding the * appropriate ImageReader for an image file. * <P> * * The properties for this layer are: * * <pre> * # semi-colon separated paths to image files or directories containing images * imageTileLayer.imageFilePath=path/to/file1;path/to/directory;path/to/file2 * * # optional - image cache size specifies how many images will be held in memory for fast retrieval. * imageTileLayer.imageCacheSize=20 * * # optional - image cutoff scale specifies the scale that images will not load when the projection is zoomed out from it. * imageTileLayer.imageCutoffScale=1000000 * * # optional - image Reader loaders specify which image files are handled * imageTileLayer.iamgeReaderLoaders=geotiff * imageTileLayer.geotiff=com.bbn.openmap.dataAccess.image.geotiff.GeoTIFFImageReader.Loader * * # optional - Drawing attributes properties for image highlighting * imageTileLayer.lineWidth=2 * imageTileLayer.selectColor=FFFFFF00 * </pre> * * @author dietrick * */public class ImageTileLayer extends OMGraphicHandlerLayer { public static Logger logger = Logger.getLogger("com.bbn.openmap.layer.imageTile.ImageTileLayer"); public final static String ImageFilePathProperty = "imageFilePath"; public final static String ImageReaderLoadersProperty = "imageReaderLoaders"; public final static String ImageCacheSizeProperty = "imageCacheSize"; public final static String ImageCutoffRatioProperty = "imageCutoffRatio"; protected String SHOW_TILES_TITLE; protected String HIDE_TILES_TITLE; protected Vector filePaths; protected Vector imageReaderLoaders; protected ImageTile.Cache imageCache; protected DrawingAttributes selectedDrawingAttributes = DrawingAttributes.getDefaultClone(); /** * Default constructor for layer, initializes tile cache. * */ public ImageTileLayer() { configureImageReaderLoaders(); imageCache = new ImageTile.Cache(); SHOW_TILES_TITLE = i18n.get(ImageTileLayer.class, "showTilesButton", "Show"); HIDE_TILES_TITLE = i18n.get(ImageTileLayer.class, "hideTilesButton", "Hide"); } /** * PropertyConsumer interface method. */ public void setProperties(String prefix, Properties props) { super.setProperties(prefix, props); selectedDrawingAttributes.setProperties(prefix, props); prefix = PropUtils.getScopedPropertyPrefix(prefix); filePaths = PropUtils.parseMarkers(props.getProperty(prefix + ImageFilePathProperty), ";"); imageCache.resetCache(PropUtils.intFromProperties(props, prefix + ImageCacheSizeProperty, imageCache.getCacheSize())); imageCache.setCutoffScaleRatio(PropUtils.floatFromProperties(props, prefix + ImageCutoffRatioProperty, imageCache.getCutoffScaleRatio())); String imageReaderLoaderString = props.getProperty(prefix + ImageReaderLoadersProperty); if (imageReaderLoaders == null) { imageReaderLoaders = new Vector(); } if (imageReaderLoaderString != null) { imageReaderLoaders.clear(); Vector idls = PropUtils.parseSpacedMarkers(imageReaderLoaderString); for (Iterator it = idls.iterator(); it.hasNext();) { String idlMarkerName = (String) it.next(); String idlClassName = props.getProperty(prefix + idlMarkerName); Object obj = ComponentFactory.create(idlClassName); if (obj != null && obj instanceof ImageReaderLoader) { imageReaderLoaders.add((ImageReaderLoader) obj); } } } } /** * Internal callback method for subclasses to use to be able to configure * imageReaderLoader Vector with specific ImageReaderLoaders. By default, * loads GeoTIFFImageReader.Loader. */ protected void configureImageReaderLoaders() { imageReaderLoaders = new Vector(); ImageReaderLoader idl = (ImageReaderLoader) ComponentFactory.create("com.bbn.openmap.dataAccess.image.geotiff.GeoTIFFImageReaderLoader"); if (idl != null) { imageReaderLoaders.add(idl); } else { logger.warning("ImageTileLayer needs JAI installed in order to use GeoTIFF Image Reader."); } idl = (ImageReaderLoader) ComponentFactory.create("com.bbn.openmap.dataAccess.image.WorldFileImageReaderLoader"); if (idl != null) { imageReaderLoaders.add(idl); } else { logger.warning("ImageTileLayer needs JAI installed in order to use World File Image Reader."); } } /** * PropertyConsumer interface method. */ public Properties getProperties(Properties props) { props = super.getProperties(props); selectedDrawingAttributes.getProperties(props); String prefix = PropUtils.getScopedPropertyPrefix(this); OMGraphicList list = getList(); if (list != null) { StringBuffer buf = null; for (Iterator it = list.iterator(); it.hasNext();) { if (buf == null) { buf = new StringBuffer(); } else { buf.append(";"); } ImageTile imageTile = (ImageTile) it.next(); String filePath = (String) imageTile.getAttribute(FILE_PATH_ATTRIBUTE); if (filePath != null) { buf.append(filePath); } } props.put(prefix + ImageFilePathProperty, buf.toString()); } if (imageReaderLoaders != null) { int count = 0; StringBuffer sbuf = null; for (Iterator it = imageReaderLoaders.iterator(); it.hasNext(); count++) { ImageReaderLoader idl = (ImageReaderLoader) it.next(); props.put(prefix + "idl" + count, idl.getClass().getName()); if (sbuf == null) { sbuf = new StringBuffer("idl" + count); } else { // Space separated for parsing on input sbuf.append(" idl" + count); } } if (sbuf != null) { props.put(prefix + ImageReaderLoadersProperty, sbuf.toString()); } } props.put(prefix + ImageCacheSizeProperty, Integer.toString(imageCache.getCacheSize())); props.put(prefix + ImageCutoffRatioProperty, Float.toString(imageCache.getCutoffScaleRatio())); return props; } /** * PropertyConsumer interface method. */ public Properties getPropertyInfo(Properties props) { props = super.getPropertyInfo(props); selectedDrawingAttributes.getPropertyInfo(props); PropUtils.setI18NPropertyInfo(i18n, props, ImageTileLayer.class, ImageFilePathProperty, "Images", "A list of images or directories to display (separated by ;).", "com.bbn.openmap.util.propertyEditor.MultiDirFilePropertyEditor"); PropUtils.setI18NPropertyInfo(i18n, props, ImageTileLayer.class, ImageCacheSizeProperty, "Cache Size", "Number of images to keep in cache.", null); PropUtils.setI18NPropertyInfo(i18n, props, ImageTileLayer.class, ImageCutoffRatioProperty, "Cutoff Scale", "Projection scale where larger values won't cause images to be loaded and displayed.", null); String dummyMarker = PropUtils.getDummyMarkerForPropertyInfo(getPropertyPrefix(), null); PropUtils.setI18NPropertyInfo(i18n, props, ImageTileLayer.class, dummyMarker, "Highlight Settings", "Settings for annototations on highlighted images.", "com.bbn.openmap.omGraphics.DrawingAttributesPropertyEditor"); props.put(initPropertiesProperty, ImageFilePathProperty + " " + ImageCacheSizeProperty + " " + ImageCutoffRatioProperty + " " + dummyMarker); return props; } /** * OMGraphicHandlerLayer method called when projection changes or when * doPrepare() is called. If the interal OMGraphicList is null the image * file paths will be used to read image files. */ public synchronized OMGraphicList prepare() { OMGraphicList list = getList(); if (list == null) { list = new OMGraphicList(); setList(list); Thread loadThread = new Thread() { public void run() { loadImages(); fireStatusUpdate(LayerStatusEvent.FINISH_WORKING); } }; loadThread.start(); } else { list.generate(getProjection()); } return list; } /** * Gets the filePaths and loads the images found in those places. Should be
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?