📄 daynightlayer.java
字号:
// **********************************************************************// // <copyright>// // BBN Technologies// 10 Moulton Street// Cambridge, MA 02138// (617) 873-8000// // Copyright (C) BBNT Solutions LLC. All rights reserved.// // </copyright>// **********************************************************************// // $Source: /cvs/distapps/openmap/src/openmap/com/bbn/openmap/layer/daynight/DayNightLayer.java,v $// $RCSfile: DayNightLayer.java,v $// $Revision: 1.6.2.4 $// $Date: 2005/08/09 18:10:45 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.layer.daynight;/* Java Core */import java.awt.Color;import java.awt.event.ActionListener;import java.util.Properties;import javax.swing.Timer;/* OpenMap */import com.bbn.openmap.I18n;import com.bbn.openmap.LatLonPoint;import com.bbn.openmap.MoreMath;import com.bbn.openmap.util.Debug;import com.bbn.openmap.util.PropUtils;import com.bbn.openmap.event.ProjectionListener;import com.bbn.openmap.layer.OMGraphicHandlerLayer;import com.bbn.openmap.omGraphics.OMCircle;import com.bbn.openmap.omGraphics.OMGraphic;import com.bbn.openmap.omGraphics.OMGraphicList;import com.bbn.openmap.omGraphics.OMRaster;import com.bbn.openmap.proj.Cylindrical;import com.bbn.openmap.proj.GreatCircle;import com.bbn.openmap.proj.Length;import com.bbn.openmap.proj.Projection;/** * The DayNightLayer is a layer that draws the day/Night terminator on * the map. When the layer is re-projected, it figures out the * brightest point on the earth (closest to the sun), and creates an * image that has daytime pixels clear and the nighttime pixels * shaded. There are a couple of options available for the layer. The * terminator can be faded from light to dark, and the width of the * fading can be adjusted. The color of the shading can be changed. * The shading can reflect the current time, or be set to display the * shading of a specified time. A time interval can be set to have the * layer automatically update at regular intervals. * * <P> * The openmap.properties file can control the layer with the * following settings: <code><pre> * * # These are all optional, and can be omitted if you want to use the defaults. * # draw terminator as poly (faster calculation than image, * # defaults to true). * daynight.doPolyTerminator=true * # number of vertices for polygon terminator line. this is only valid * # if doPolyTerminator is true... * daynight.terminatorVerts=360 * # termFade - the distance of the transition of fade, as a percentage of PI. * daynight.termFade=.1 * # currentTime - true to display the shading at the computer's current time. * daynight.currentTime=true * # overlayTime - time, in milliseconds from java/unix epoch, to set the layer * # time being displayed. currentTime has to be false for this to be used. * daynight.overlayTime=919453689000 * # updateInterval - time in milliseconds between updates. currentTime has to be * # true for this to be used. * daynight.updateInterval=300000 * # Color of the shading (32bit Hex ARGB) * daynight.nighttimeColor=64000000 * * </pre></code> In addition, you can get this layer to work with the * OpenMap viewer by editing your openmap.properties file: <code><pre> * * # layers * openmap.layers=daynight ... * # class * daynight.class=com.bbn.openmap.layer.daynight.DayNightLayer * # name * daynight.prettyName=Day/Night Shading * * </pre></code> * */public class DayNightLayer extends OMGraphicHandlerLayer implements ProjectionListener, ActionListener { /** * Default value of fade to the terminator line, set to .10f. This * means that the last 10% of the horizon will be faded out. */ public static final float DEFAULT_TERM_FADE = .10f; /** * Default update interval, which is never - updates occur on * re-projections. */ public static final int DO_NOT_UPDATE = -1; /** The color of daytime - default is white and clear. */ protected Color daytimeColor = new Color(0x00FFFFFF); /** the color of darkness - default is black. */ protected Color nighttimeColor = new Color(0x7F000000); /** * Percentage of the distance from the horizon to the brightest * point to start fading to darkness. Expected to be between 0.0 * and 0.5. */ protected float termFade = DEFAULT_TERM_FADE; /** * If true, the layer will set the darkness according to the * current time. */ protected boolean currentTime = true; /** * The time used to create the layer, in milliseconds from * java/unix epoch. */ protected long overlayTime = 0; /** * Update interval to automatically update the layer, in * milli-seconds */ protected int updateInterval = 300000; /** Update timer. */ protected Timer timer; /** * Create the terminator line as a polygon. */ protected boolean doPolyTerminator = true; /** * The number of vertices of the polygon terminator line. */ protected int terminatorVerts = 360; /////// Properties public static final String DaytimeColorProperty = "daytimeColor"; public static final String NighttimeColorProperty = "nighttimeColor"; public static final String TermFadeProperty = "termFade"; public static final String CurrentTimeProperty = "useCurrentTime"; public static final String OverlayTimeProperty = "overlayTime"; public static final String UpdateIntervalProperty = "updateInterval"; public static final String DoPolyTerminatorProperty = "doPolyTerminator"; public static final String TerminatorVertsProperty = "terminatorVerts"; /** * The default constructor for the Layer. All of the attributes * are set to their default values. */ public DayNightLayer() { setName("Day-Night"); } /** * The properties and prefix are managed and decoded here, for the * standard uses of the DayNightLayer. * * @param prefix string prefix used in the properties file for * this layer. * @param properties the properties set in the properties file. */ public void setProperties(String prefix, java.util.Properties properties) { super.setProperties(prefix, properties); prefix = PropUtils.getScopedPropertyPrefix(prefix); overlayTime = PropUtils.longFromProperties(properties, prefix + OverlayTimeProperty, overlayTime); if (overlayTime <= 0) { currentTime = true; } currentTime = PropUtils.booleanFromProperties(properties, prefix + CurrentTimeProperty, currentTime); updateInterval = PropUtils.intFromProperties(properties, prefix + UpdateIntervalProperty, updateInterval); if (updateInterval > 0) { timer = new Timer(updateInterval, this); } termFade = PropUtils.floatFromProperties(properties, prefix + TermFadeProperty, termFade); if (termFade < 0 || termFade >= .5) { Debug.output("DayNightLayer: termFade funky value ignored."); termFade = DEFAULT_TERM_FADE; } daytimeColor = (Color) PropUtils.parseColorFromProperties(properties, prefix + DaytimeColorProperty, daytimeColor); nighttimeColor = (Color) PropUtils.parseColorFromProperties(properties, prefix + NighttimeColorProperty, nighttimeColor); doPolyTerminator = PropUtils.booleanFromProperties(properties, prefix + DoPolyTerminatorProperty, doPolyTerminator); terminatorVerts = PropUtils.intFromProperties(properties, prefix + TerminatorVertsProperty, terminatorVerts); } public Properties getProperties(Properties props) { props = super.getProperties(props); String prefix = PropUtils.getScopedPropertyPrefix(this); props.put(prefix + OverlayTimeProperty, Long.toString(overlayTime)); props.put(prefix + CurrentTimeProperty, new Boolean(currentTime).toString()); props.put(prefix + UpdateIntervalProperty, Integer.toString(updateInterval)); props.put(prefix + TermFadeProperty, Float.toString(termFade)); props.put(prefix + DaytimeColorProperty, Integer.toHexString(daytimeColor.getRGB())); props.put(prefix + NighttimeColorProperty, Integer.toHexString(nighttimeColor.getRGB())); props.put(prefix + DoPolyTerminatorProperty, new Boolean(doPolyTerminator).toString()); props.put(prefix + TerminatorVertsProperty, Integer.toString(terminatorVerts)); return props; } public Properties getPropertyInfo(Properties props) { props = super.getPropertyInfo(props); String interString; interString = i18n.get(DayNightLayer.class, OverlayTimeProperty, I18n.TOOLTIP, "The time used to create the layer, in milliseconds from java/unix epoch (leave empty for current time)."); props.put(OverlayTimeProperty, interString); interString = i18n.get(DayNightLayer.class, OverlayTimeProperty, OverlayTimeProperty); props.put(OverlayTimeProperty + LabelEditorProperty, interString); interString = i18n.get(DayNightLayer.class, CurrentTimeProperty, I18n.TOOLTIP, "If true, the layer will set the darkness according to the current time."); props.put(CurrentTimeProperty, interString); interString = i18n.get(DayNightLayer.class, CurrentTimeProperty, CurrentTimeProperty); props.put(CurrentTimeProperty + LabelEditorProperty, interString); props.put(CurrentTimeProperty + ScopedEditorProperty, "com.bbn.openmap.util.propertyEditor.YesNoPropertyEditor"); interString = i18n.get(DayNightLayer.class, UpdateIntervalProperty, I18n.TOOLTIP, "Update interval to automatically update the layer, in milli-seconds."); props.put(UpdateIntervalProperty, interString); interString = i18n.get(DayNightLayer.class, UpdateIntervalProperty, UpdateIntervalProperty); props.put(UpdateIntervalProperty + LabelEditorProperty, interString);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -