📄 dtedframecachehandler.java
字号:
* returns the one passed in. */ protected OMGraphicList loadListFromHandler(OMGraphicList graphics) { if (graphics == null) { graphics = new OMGraphicList(); } OMGraphic image = getNextImage(); while (image != null) { graphics.add(image); image = getNextImage(); } return graphics; } /** * The method to call to let the cache handler know what the * projection looks like so it can figure out which frames (and * subframes) will be needed. * * @param proj the EqualArc projection of the screen. */ public void setProjection(EqualArc proj) { setProjection(proj, proj.getUpperLeft().getLatitude(), proj.getUpperLeft().getLongitude(), proj.getLowerRight().getLatitude(), proj.getLowerRight().getLongitude()); } /** * The method to call to let the cache handler know what the * projection looks like so it can figure out which frames (and * subframes) will be needed. Should be called when the * CacheHandler is dealing with just a part of the map, such as * when the map covers the dateline or equator. * * @param proj the EqualArc projection of the screen. * @param lat1 latitude of the upper left corner of the window, in * decimal degrees. * @param lon1 longitude of the upper left corner of the window, * in decimal degrees. * @param lat2 latitude of the lower right corner of the window, * in decimal degrees. * @param lon2 longitude of the lower right corner of the window, * in decimal degrees. */ public void setProjection(EqualArc proj, float lat1, float lon1, float lat2, float lon2) { firstImageReturned = true; // upper lat of top frame of the screen // lower lat of bottom frame of the screen // left lon of left frame of the screen // upper lon of right frame of the screen frameUp = Math.floor((double) lat1); frameDown = Math.floor((double) lat2); frameLeft = Math.floor((double) lon1); frameRight = Math.ceil((double) lon2); if (Debug.debugging("dted")) Debug.output("frameUp = " + frameUp + ", frameDown = " + frameDown + ", frameLeft = " + frameLeft + ", frameRight = " + frameRight); } /** * Returns the next OMRaster image. When setProjection() is * called, the cache sets the projection parameters it needs, and * also resets this popping mechanism. When this mechanism is * reset, you can keep calling this method to get another subframe * image. When it returns a null value, it is done. It will * automatically skip over window frames it doesn't have, and * return the next one it does have. It traverses from the top * left to right frames, and top to bottom for each column of * frames. It handles all the subframes for a frame at one time. * * @return OMRaster image. */ public OMGraphic getNextImage() { if (Debug.debugging("dted")) Debug.output("--- DTEDFrameCacheHandler: getNextImage:"); while (true) { if (firstImageReturned == true) { frameLon = frameLeft; frameLat = frameDown; newframe = true; firstImageReturned = false; } else if (frameLon < frameRight) { // update statics to look for next frame if (frameLat < frameUp) { frameLat++; } else { frameLat = frameDown; frameLon++; } newframe = true; } else { // bounds exceeded, all done return (OMGraphic) null; } if (newframe && frameLon < frameRight) { if (Debug.debugging("dted")) { Debug.output(" gni: Getting new frame Lat = " + frameLat + " Lon = " + frameLon); } OMGraphic omg = get(frameLat, frameLon, dtedLevel); if (omg != null) { return omg; } } } } /** * Return an OMGraphic for the Dted Frame, given A lat, lon and * dted level. * * @param lat latitude of point * @param lon longitude of point * @param level the dted level wanted (0, 1, 2) * @return OMGraphic, most likely an OMGrid. */ public OMGraphic get(double lat, double lon, int level) { // First, put together a key from the above info, and then // look for it in the local cache. If it's not there, then go // to the DTEDFrameCache. String key = new String(lat + ":" + lon + ":" + level); CacheObject ret = searchCache(key); if (ret != null) { if (Debug.debugging("dted")) { Debug.output("DTEDFrameCacheHandler.get(): retrieving frame from cache (" + lat + ":" + lon + ":" + level + ")"); } return (OMGraphic) ret.obj; } ret = load(key, lat, lon, level); if (ret == null) { return null; } replaceLeastUsed(ret); if (Debug.debugging("dted")) { Debug.output("DTEDFrameCacheHandler.get(): loading new frame into cache (" + lat + ":" + lon + ":" + level + ")"); } return (OMGraphic) ret.obj; } /** * Load a dted frame into the cache, based on the path of the * frame as a key. Implements abstract CacheHandler method. * * @param key key to remember raster created for DTED frame. * @return DTED frame, hidden as a CacheObject. */ public CacheObject load(String key, double lat, double lon, int level) { if (frameCache != null) { DTEDFrame frame = frameCache.get(lat, lon, level); if (frame != null) { OMGrid omgrid = frame.getOMGrid(); // Need to create a unique generator for each OMGrid. omgrid.setGenerator(getGenerator()); return new DTEDCacheObject(key, omgrid); } } return null; } public CacheObject load(String key) { // Do nothing, because this implementation doesn't use it. // The get() method has been overridden to c all the other // load method with addition needed information to better call // the DTEDFrameCache. return null; } /** * A private class that makes sure that cached frames get disposed * properly. */ private static class DTEDCacheObject extends CacheObject { /** * Construct a DTEDCacheObject, just calls superclass * constructor * * @param id passed to superclass * @param obj passed to superclass */ public DTEDCacheObject(String id, OMGraphic omg) { super(id, omg); } } // //// PropertyConsumer Interface Methods /** * Token uniquely identifying this component in the application * properties. */ protected String propertyPrefix = null; /** * Sets the properties for the OMComponent. * * @param props the <code>Properties</code> object. */ public void setProperties(java.util.Properties props) { setProperties(getPropertyPrefix(), props); } /** * Sets the properties for the OMComponent. * * @param prefix the token to prefix the property names * @param props the <code>Properties</code> object */ public void setProperties(String prefix, java.util.Properties props) { setPropertyPrefix(prefix); String realPrefix = PropUtils.getScopedPropertyPrefix(prefix); String generatorList = props.getProperty(realPrefix + GeneratorLoadersProperty); if (generatorList != null) { Vector generatorMarkers = PropUtils.parseSpacedMarkers(generatorList); for (Iterator it = generatorMarkers.iterator(); it.hasNext();) { String loaderPrefix = realPrefix + (String) it.next(); String loaderClassnameProperty = loaderPrefix + ".class"; String classname = props.getProperty(loaderClassnameProperty); try { GeneratorLoader loader = (GeneratorLoader) ComponentFactory.create(classname); loader.setProperties(loaderPrefix, props); generatorLoaders.add(loader); loader.addPropertyChangeListener(this); // Initialize if (activeGeneratorLoader == null) { activeGeneratorLoader = loader; } } catch (ClassCastException cce) { Debug.output("DTEDFrameCacheHandler created " + classname + ", but it's not a GeneratorLoader"); } catch (NullPointerException npe) { Debug.error("DTEDFrameCacheHandler: problem creating generator loader: " + classname + " from " + loaderClassnameProperty); } } } } /** * PropertyConsumer method, to fill in a Properties object, * reflecting the current values of the OMComponent. If the * component has a propertyPrefix set, the property keys should * have that prefix plus a separating '.' prepended to each * propery key it uses for configuration. * * @param props a Properties object to load the PropertyConsumer * properties into. If props equals null, then a new * Properties object should be created. * @return Properties object containing PropertyConsumer property * values. If getList was not null, this should equal * getList. Otherwise, it should be the Properties object * created by the PropertyConsumer. */ public Properties getProperties(Properties props) { if (props == null) { props = new Properties(); } String prefix = PropUtils.getScopedPropertyPrefix(this); StringBuffer sb = new StringBuffer(); for (Iterator it = generatorLoaders.iterator(); it.hasNext();) { GeneratorLoader gl = (GeneratorLoader) it.next(); String pref = gl.getPropertyPrefix(); props.put(pref + ".class", gl.getClass().getName()); gl.getProperties(props); int index = pref.indexOf(prefix); if (index != -1) { pref = pref.substring(index + prefix.length()); } sb.append(pref + " "); } props.put(prefix + GeneratorLoadersProperty, sb.toString()); return props; } /** * Method to fill in a Properties object with values reflecting * the properties able to be set on this PropertyConsumer. The key * for each property should be the raw property name (without a * prefix) with a value that is a String that describes what the * property key represents, along with any other information about * the property that would be helpful (range, default value, * etc.). For Layer, this method should at least return the * 'prettyName' property. * * @param list a Properties object to load the PropertyConsumer * properties into. If getList equals null, then a new * Properties object should be created. * @return Properties object containing PropertyConsumer property * values. If getList was not null, this should equal * getList. Otherwise, it should be the Properties object * created by the PropertyConsumer. */ public Properties getPropertyInfo(Properties list) { if (list == null) { list = new Properties(); } // Not sure how to set up an inspector to create child classes // yet. return list; } /** * Set the property key prefix that should be used by the * PropertyConsumer. The prefix, along with a '.', should be * prepended to the property keys known by the PropertyConsumer. * * @param prefix the prefix String. */ public void setPropertyPrefix(String prefix) { propertyPrefix = prefix; } /** * Get the property key prefix that is being used to prepend to * the property keys for Properties lookups. * * @return the property prefix string */ public String getPropertyPrefix() { return propertyPrefix; } /** * The DTEDFrameCacheHandler needs to sign up as a * PropertyChangeListener so if anything on the GeneratorLoader * GUI changes, it knows to dump the current representations so * they can be rebuild with the current GUI settings. */ public void propertyChange(PropertyChangeEvent pce) { clear(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -