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

📄 magicplanetimagecomponent.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
		return mapBean;	}	/**	 * Set the MapBean, become a PropertyChangeListener object to it to know	 * when the background color on the MapBean changes. If there is already a	 * MapBean known to this component, this component will remove itself as a	 * listener to the previous MapBean.	 * 	 * @param mb MapBean.	 */	protected void setMapBean(MapBean mb) {		if (mapBean != null) {			mapBean.removePropertyChangeListener(this);		}		mapBean = mb;		if (mapBean != null) {			mapBean.addPropertyChangeListener(this);		}	}	public void setProperties(String prefix, Properties props) {		super.setProperties(prefix, props);		prefix = PropUtils.getScopedPropertyPrefix(prefix);		setOutputDirectoryString(props.getProperty(prefix				+ OutputDirectoryProperty));		setAutoUpdate(PropUtils.booleanFromProperties(props, prefix				+ AutoUpdateProperty, isAutoUpdate()));		setHeight(PropUtils.intFromProperties(props, prefix + HeightProperty,				getHeight()));		setWidth(PropUtils.intFromProperties(props, prefix + WidthProperty,				getWidth()));		setScale(PropUtils.floatFromProperties(props, prefix + ScaleProperty,				scale));		setUpdateInterval(PropUtils.intFromProperties(props, prefix				+ UpdateIntervalProperty, getUpdateInterval()));		setCleanup(PropUtils.booleanFromProperties(props, prefix				+ CleanupProperty, isCleanup()));		setCleanupInterval(PropUtils.intFromProperties(props, prefix				+ CleanupIntervalProperty, getCleanupInterval()));		setLastImageFile(props.getProperty(prefix + LastImageFileProperty,				getLastImageFile()));		setPostProcessingScript(props.getProperty(prefix				+ PostProcessingScriptProperty, getPostProcessingScript()));	}	public Properties getProperties(Properties props) {		props = super.getProperties(props);		String prefix = PropUtils.getScopedPropertyPrefix(this);		props.put(prefix + OutputDirectoryProperty, PropUtils				.unnull(getOutputDirectoryString()));		props				.put(prefix + AutoUpdateProperty, Boolean						.toString(isAutoUpdate()));		props.put(prefix + HeightProperty, Integer.toString(getHeight()));		props.put(prefix + WidthProperty, Integer.toString(getWidth()));		props.put(prefix + ScaleProperty, Float.toString(getScale()));		props.put(prefix + UpdateIntervalProperty, Integer				.toString(getUpdateInterval()));		props.put(prefix + CleanupProperty, Boolean.toString(isCleanup()));		props.put(prefix + CleanupIntervalProperty, Integer				.toString(getCleanupInterval()));		props.put(prefix + LastImageFileProperty, PropUtils				.unnull(getLastImageFile()));		props.put(prefix + PostProcessingScriptProperty, PropUtils				.unnull(getPostProcessingScript()));		return props;	}	public Properties getPropertyInfo(Properties props) {		props = super.getPropertyInfo(props);		String interString;		// -------		interString = i18n.get(MagicPlanetImageComponent.class,				OutputDirectoryProperty, I18n.TOOLTIP,				"Path to directory that holds created images.");		props.put(OutputDirectoryProperty, interString);		props.put(OutputDirectoryProperty + ScopedEditorProperty,				"com.bbn.openmap.util.propertyEditor.DirectoryPropertyEditor");		interString = i18n.get(MagicPlanetImageComponent.class,				OutputDirectoryProperty, "Directory Path");		props.put(OutputDirectoryProperty + LabelEditorProperty, interString);		// -------		interString = i18n				.get(MagicPlanetImageComponent.class, AutoUpdateProperty,						I18n.TOOLTIP,						"Immediately create new images when the layers/background color changes.");		props.put(AutoUpdateProperty, interString);		props.put(AutoUpdateProperty + ScopedEditorProperty,				"com.bbn.openmap.util.propertyEditor.YesNoPropertyEditor");		interString = i18n.get(MagicPlanetImageComponent.class,				AutoUpdateProperty, "Auto-Update");		props.put(AutoUpdateProperty + LabelEditorProperty, interString);		// -------		interString = i18n.get(MagicPlanetImageComponent.class, HeightProperty,				I18n.TOOLTIP,				"Image pixel height (-1 defers to scale setting).");		props.put(HeightProperty, interString);		interString = i18n.get(MagicPlanetImageComponent.class, HeightProperty,				"Image Height");		props.put(HeightProperty + LabelEditorProperty, interString);		// -------		interString = i18n				.get(MagicPlanetImageComponent.class, WidthProperty,						I18n.TOOLTIP,						"Image pixel width (-1 defers to scale setting).");		props.put(WidthProperty, interString);		interString = i18n.get(MagicPlanetImageComponent.class, WidthProperty,				"Image Width");		props.put(WidthProperty + LabelEditorProperty, interString);		// -------		interString = i18n				.get(MagicPlanetImageComponent.class, ScaleProperty,						I18n.TOOLTIP,						"Scale to use for image projection (larger numbers make smaller maps).");		props.put(ScaleProperty, interString);		interString = i18n.get(MagicPlanetImageComponent.class, ScaleProperty,				"Projection Scale");		props.put(ScaleProperty + LabelEditorProperty, interString);		// -------		interString = i18n.get(MagicPlanetImageComponent.class,				UpdateIntervalProperty, I18n.TOOLTIP,				"Number of milliseconds until next image.");		props.put(UpdateIntervalProperty, interString);		interString = i18n.get(MagicPlanetImageComponent.class,				UpdateIntervalProperty, "Update Interval");		props.put(UpdateIntervalProperty + LabelEditorProperty, interString);		// -------		interString = i18n.get(MagicPlanetImageComponent.class,				CleanupProperty, I18n.TOOLTIP,				"Delete old images automatically.");		props.put(CleanupProperty, interString);		props.put(CleanupProperty + ScopedEditorProperty,				"com.bbn.openmap.util.propertyEditor.YesNoPropertyEditor");		interString = i18n.get(MagicPlanetImageComponent.class,				CleanupProperty, "Delete Old Images");		props.put(CleanupProperty + LabelEditorProperty, interString);		// -------		interString = i18n				.get(MagicPlanetImageComponent.class, CleanupIntervalProperty,						I18n.TOOLTIP,						"Number of milliseconds to keep old images (86400000 is one day).");		props.put(CleanupIntervalProperty, interString);		interString = i18n.get(MagicPlanetImageComponent.class,				CleanupIntervalProperty, "Cleanup Interval");		props.put(CleanupIntervalProperty + LabelEditorProperty, interString);		// -------		interString = i18n.get(MagicPlanetImageComponent.class,				LastImageFileProperty, I18n.TOOLTIP,				"Path to file containing name of last image file created.");		props.put(LastImageFileProperty, interString);		interString = i18n.get(MagicPlanetImageComponent.class,				LastImageFileProperty, "Last Image Name");		props.put(LastImageFileProperty + LabelEditorProperty, interString);		// -------		interString = i18n.get(MagicPlanetImageComponent.class,				PostProcessingScriptProperty, I18n.TOOLTIP,				"Script to run on the image file after it's been created.");		props.put(LastImageFileProperty, interString);		interString = i18n.get(MagicPlanetImageComponent.class,				PostProcessingScriptProperty, "Post Processing Script");		props.put(PostProcessingScriptProperty + LabelEditorProperty,				interString);		props.put(initPropertiesProperty, OutputDirectoryProperty + " "				+ ScaleProperty + " " + UpdateIntervalProperty + " "				+ AutoUpdateProperty + " " + CleanupProperty + " "				+ CleanupIntervalProperty + " " + HeightProperty + " "				+ WidthProperty + LastImageFileProperty				+ PostProcessingScriptProperty);		return props;	}	/*	 * (non-Javadoc)	 * 	 * @see com.bbn.openmap.event.LayerListener#setLayers(com.bbn.openmap.event.LayerEvent)	 */	public void setLayers(LayerEvent evt) {		if (evt.getType() == LayerEvent.REPLACE) {			setLayers(evt.getLayers());		}	}	/**	 * Checks to see if there is a timer, and if the component wants to	 * automatically update the current image. If the timer isn't running, it's	 * started.	 */	public void handleUpdate() {		Timer timer = getTimer();		if (timer != null && (isAutoUpdate() || !timer.isRunning())) {			timer.restart();		}		// Else do nothing, the timer is running and will pick up the		// changes.	}	/**	 * Create a new image.	 */	public void createImage() {		if (isCleanup()) {			cleanup(false);		}		String fileName = getFileNameForTime(System.currentTimeMillis());		String filePath = getOutputDirectoryString() + "/" + fileName;		if (DEBUG) {			Debug.output("MagicPlanetImageComponent: creating image: "					+ filePath);		}		Layer[] layers = getLayers();		if (layers == null) {			return;		}		ImageServer is = new ImageServer(layers, new SunJPEGFormatter());		try {			is.setBackground(getBackground());		} catch (NoSuchMethodError nsme) {			// Older version of OpenMap, going to just use what the			// MapBean has		}		byte[] imageBytes = is.createImage(getProj(), getWidth(), getHeight());		FileOutputStream fos;		try {			fos = new FileOutputStream(filePath);			fos.write(imageBytes);			fos.flush();			fos.close();			if (DEBUG) {				Debug.output("  MP: done writing image");			}		} catch (FileNotFoundException e) {			e.printStackTrace();		} catch (IOException e) {			e.printStackTrace();		}		mapBean.setProjection(mapBean.getProjection());		String launchCmd = generatePostProcessingCmd(postProcessingScript,				filePath);		if (launchCmd != null) {			try {				if (DEBUG)					Debug.output("MP post processing: " + launchCmd);				Runtime.getRuntime().exec(launchCmd);			} catch (IOException e) {				System.err.println("MP post processing:  " + e);			}		}		if (lastImageFile != null) {			try {				File lastImageFileFile = new File(lastImageFile);				fos = new FileOutputStream(lastImageFileFile);				fos.write(new String(LAST_IMAGE_FILE_KEY + "=" + fileName)						.getBytes());				fos.flush();				fos.close();				if (DEBUG) {					Debug							.output("  MP: done writing file noting last image file name: "									+ lastImageFile);				}			} catch (IOException ioe) {				Debug						.error("MP: error writing file to note last image file name:\n"								+ ioe.getMessage());				ioe.printStackTrace();				lastImageFile = null;			}		}	}	protected String generatePostProcessingCmd(String script, String filePath) {		String ret = null;		if (script != null && filePath != null) {			// nvdxt.exe -file Image.jpg -all -swap -dxt1c -output			// Image.dds			// nvdxt.exe -file %FILENAME% -all -swap -dxt1c -output			// %FILENAME_WITHOUT_EXTENSION%.dds			if (DEBUG) {				Debug.output(" Replacing script: |" + script + "|" + filePath);			}			ret = script.replaceAll(REPLACE_FILEPATH_MARKER, filePath);			ret = ret.replaceAll(REPLACE_FILENAME_MARKER, filePath					.substring(filePath.lastIndexOf('/') + 1));			ret = ret.replaceAll(REPLACE_FILENAME_WOEXT_MARKER, filePath					.substring(filePath.lastIndexOf('/') + 1, filePath							.lastIndexOf('.')));			try {				if (Environment.get("os.name").startsWith("Windows")) {					ret = ret.replace('/', '\\');				}			} catch (NullPointerException npe) {				// Applet, or Environment not set up.			}			if (DEBUG) {				Debug.output(" returning script: " + ret);			}		}		return ret;	}	/**	 * @param l unix time in milliseconds	 * @return String representing file name for the given time.	 */	protected String getFileNameForTime(long l) {		Calendar cal = new GregorianCalendar();		cal.setTimeInMillis(l);		DecimalFormat twoDigits = new DecimalFormat("00");		String tMarker = Integer.toString(cal.get(Calendar.YEAR))				+ twoDigits.format(cal.get(Calendar.MONTH) + 1)				+ twoDigits.format(cal.get(Calendar.DAY_OF_MONTH))				+ twoDigits.format(cal.get(Calendar.HOUR_OF_DAY))				+ twoDigits.format(cal.get(Calendar.MINUTE))				+ twoDigits.format(cal.get(Calendar.SECOND));		return tMarker + "."

⌨️ 快捷键说明

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