Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added protocol that enables detection of whether a TiledImageLayer re…

…ndered anything in a particular frame. Added an example showing usage. This feature can be used to indicate whether a specific TiledImageLayer is in view.
commit 7c9886ab67ac03d53bdb04f161b9605d3f3dd810 1 parent 022ea4f
tgaskins authored
View
6 WorldWind/src/gov/nasa/worldwind/AbstractSceneController.java
@@ -362,7 +362,11 @@ protected void initializeDrawContext(DrawContext dc)
dc.setPickPoint(this.pickPoint);
dc.setPickRectangle(this.pickRect);
dc.setViewportCenterScreenPoint(this.getViewportCenter(dc));
- dc.setFrameTimeStamp(System.currentTimeMillis());
+
+ long frameTimeStamp = System.currentTimeMillis();
+ dc.setFrameTimeStamp(frameTimeStamp);
+ // Indicate the frame time stamp to apps.
+ this.setValue(AVKey.FRAME_TIMESTAMP, frameTimeStamp);
}
protected Point getViewportCenter(DrawContext dc)
View
3  WorldWind/src/gov/nasa/worldwind/avlist/AVKey.java
@@ -135,8 +135,8 @@
final String FORWARD = "gov.nasa.worldwind.avkey.Forward";
final String FOV = "gov.nasa.worldwind.avkey.FieldOfView";
final String FORCE_LEVEL_ZERO_LOADS = "gov.nasa.worldwind.avkey.ForceLevelZeroLoads";
- final String RETAIN_LEVEL_ZERO_TILES = "gov.nasa.worldwind.avkey.RetainLevelZeroTiles";
final String FRACTION = "gov.nasa.worldwind.avkey.Fraction";
+ final String FRAME_TIMESTAMP = "gov.nasa.worldwind.avkey.FrameTimestamp";
final String GDAL_AREA = "gov.nasa.worldwind.avkey.GDAL.Area";
final String GDAL_CACHEMAX = "gov.nasa.worldwind.avkey.GDAL.CacheMax";
@@ -352,6 +352,7 @@
final String RESIZE_SHRINK_ONLY = "gov.nasa.worldwind.CompassLayer.ResizeShrinkOnly";
/** Does not modify the item size when the window changes size. */
final String RESIZE_KEEP_FIXED_SIZE = "gov.nasa.worldwind.CompassLayer.ResizeKeepFixedSize";
+ final String RETAIN_LEVEL_ZERO_TILES = "gov.nasa.worldwind.avkey.RetainLevelZeroTiles";
final String RETRIEVAL_POOL_SIZE = "gov.nasa.worldwind.avkey.RetrievalPoolSize";
final String RETRIEVE_PROPERTIES_FROM_SERVICE = "gov.nasa.worldwind.avkey.RetrievePropertiesFromService";
final String RETRIEVAL_QUEUE_SIZE = "gov.nasa.worldwind.avkey.RetrievalQueueSize";
View
3  WorldWind/src/gov/nasa/worldwind/layers/TiledImageLayer.java
@@ -617,6 +617,9 @@ protected void draw(DrawContext dc)
if (this.currentTiles.size() >= 1)
{
+ // Indicate that this layer rendered something this frame.
+ this.setValue(AVKey.FRAME_TIMESTAMP, dc.getFrameTimeStamp());
+
if (this.getScreenCredit() != null)
{
dc.addScreenCredit(this.getScreenCredit());
View
216 WorldWind/src/gov/nasa/worldwindx/examples/DynamicLayerPanelDisplay.java
@@ -0,0 +1,216 @@
+/*
+ * Copyright (c) 2011. Goodrich Corporation. All rights reserved.
+ */
+
+package gov.nasa.worldwindx.examples;
+
+import gov.nasa.worldwind.*;
+import gov.nasa.worldwind.avlist.AVKey;
+import gov.nasa.worldwind.awt.WorldWindowGLCanvas;
+import gov.nasa.worldwind.event.*;
+import gov.nasa.worldwind.layers.*;
+import gov.nasa.worldwind.util.*;
+
+import javax.swing.*;
+import java.awt.*;
+import java.util.*;
+
+/**
+ * Shows how to use the scene controller's frame time stamp to identify whether tiled image layers have rendered during
+ * the most recent frame, and convey this information to the user.
+ *
+ * @author tag
+ * @version $Id$
+ */
+public class DynamicLayerPanelDisplay
+{
+ // Derive a layer panel from the default one. This derived version keeps an association between a layer and the
+ // layer's check box in the layer panel. It uses this info to update the check boxes label font to indicate
+ // whether the corresponding layer has been rendered.
+
+ protected static class DynamicLayerPanel extends LayerPanel
+ {
+ protected java.util.Map<Layer, JCheckBox> checkBoxes;
+
+ public DynamicLayerPanel(WorldWindow wwd)
+ {
+ super(wwd);
+ }
+
+ @Override
+ protected void fill(WorldWindow wwd)
+ {
+ if (this.checkBoxes == null)
+ this.checkBoxes = new HashMap<Layer, JCheckBox>();
+
+ this.checkBoxes.clear();
+
+ for (Layer layer : wwd.getModel().getLayers())
+ {
+ if (!(layer instanceof TiledImageLayer))
+ continue;
+
+ LayerAction action = new LayerAction(layer, wwd, layer.isEnabled());
+ JCheckBox jcb = new JCheckBox(action);
+ jcb.setSelected(action.selected);
+ this.layersPanel.add(jcb);
+ this.checkBoxes.put(layer, jcb);
+ }
+
+ this.updateLayerActivity(wwd);
+ }
+
+ /**
+ * Loops through this layer panel's layer/checkbox map and updates the checkbox font to indicate whether the
+ * corresponding layer was just rendered. This method is called by a rendering listener -- see below.
+ *
+ * @param wwd the world window.
+ */
+ protected void updateLayerActivity(WorldWindow wwd)
+ {
+ for (Map.Entry<Layer, JCheckBox> entry : this.checkBoxes.entrySet())
+ {
+ // The frame timestamp from the layer indicates the last frame in which it rendered something. If that
+ // timestamp matches the current timestamp of the scene controller, then the layer rendered something
+ // during the most recent frame. Note that this frame timestamp protocol is only in place by default
+ // for TiledImageLayer and its subclasses. Applications could, however, implement it for the layers
+ // they design.
+
+ Long layerTimeStamp = (Long) entry.getKey().getValue(AVKey.FRAME_TIMESTAMP);
+ Long frameTimeStamp = (Long) wwd.getSceneController().getValue(AVKey.FRAME_TIMESTAMP);
+
+ if (layerTimeStamp != null && frameTimeStamp != null
+ && layerTimeStamp.longValue() == frameTimeStamp.longValue())
+ {
+ // Set the font to bold if the layer was just rendered.
+ entry.getValue().setFont(entry.getValue().getFont().deriveFont(Font.BOLD));
+ }
+ else
+ {
+ // Set the font to plain if the layer was not just rendered.
+ entry.getValue().setFont(entry.getValue().getFont().deriveFont(Font.PLAIN));
+ }
+ }
+ }
+ }
+
+ // The rest of this class just instantiates the World Window and installs the layer panel. It's a stripped down
+ // version of the code in ApplicationTemplate. The only part that is special to this example is the instantiation
+ // of the DynamicLayerPanel.
+
+ public static class AppPanel extends JPanel
+ {
+ protected WorldWindow wwd;
+ protected StatusBar statusBar;
+
+ public AppPanel(Dimension canvasSize)
+ {
+ super(new BorderLayout());
+
+ this.wwd = new WorldWindowGLCanvas();
+ ((Component) this.wwd).setPreferredSize(canvasSize);
+
+ // Create the default model as described in the current worldwind properties.
+ Model m = (Model) WorldWind.createConfigurationComponent(AVKey.MODEL_CLASS_NAME);
+ this.wwd.setModel(m);
+
+ this.add((Component) this.wwd, BorderLayout.CENTER);
+
+ this.statusBar = new StatusBar();
+ this.add(statusBar, BorderLayout.PAGE_END);
+ this.statusBar.setEventSource(wwd);
+ }
+ }
+
+ protected static class AppFrame extends JFrame
+ {
+ protected Dimension canvasSize = new Dimension(800, 600);
+
+ protected AppPanel wwjPanel;
+ protected DynamicLayerPanel layerPanel;
+
+ public AppFrame()
+ {
+ this.initialize();
+ }
+
+ protected void initialize()
+ {
+ // Create the WorldWindow.
+ this.wwjPanel = new AppPanel(this.canvasSize);
+ this.wwjPanel.setPreferredSize(canvasSize);
+
+ // Put the pieces together.
+ this.getContentPane().add(wwjPanel, BorderLayout.CENTER);
+ this.layerPanel = new DynamicLayerPanel(this.wwjPanel.wwd);
+
+ this.getContentPane().add(this.layerPanel, BorderLayout.WEST);
+
+ // Register a rendering exception listener that's notified when exceptions occur during rendering.
+ this.wwjPanel.wwd.addRenderingListener(new RenderingListener()
+ {
+ @Override
+ public void stageChanged(RenderingEvent event)
+ {
+ layerPanel.updateLayerActivity(wwjPanel.wwd);
+ }
+ });
+
+ this.pack();
+
+ // Center the application on the screen.
+ WWUtil.alignComponent(null, this, AVKey.CENTER);
+ this.setResizable(true);
+ }
+ }
+
+ static
+ {
+ System.setProperty("java.net.useSystemProxies", "true");
+ if (Configuration.isMacOS())
+ {
+ System.setProperty("apple.laf.useScreenMenuBar", "true");
+ System.setProperty("com.apple.mrj.application.apple.menu.about.name", "World Wind Application");
+ System.setProperty("com.apple.mrj.application.growbox.intrudes", "false");
+ System.setProperty("apple.awt.brushMetalLook", "true");
+ }
+ else if (Configuration.isWindowsOS())
+ {
+ System.setProperty("sun.awt.noerasebackground", "true"); // prevents flashing during window resizing
+ }
+ }
+
+ public static AppFrame start(String appName, Class appFrameClass)
+ {
+ if (Configuration.isMacOS() && appName != null)
+ {
+ System.setProperty("com.apple.mrj.application.apple.menu.about.name", appName);
+ }
+
+ try
+ {
+ final AppFrame frame = (AppFrame) appFrameClass.newInstance();
+ frame.setTitle(appName);
+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ java.awt.EventQueue.invokeLater(new Runnable()
+ {
+ public void run()
+ {
+ frame.setVisible(true);
+ }
+ });
+
+ return frame;
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ public static void main(String[] args)
+ {
+ start("World Wind Application", AppFrame.class);
+ }
+}
View
4 WorldWind/src/gov/nasa/worldwindx/examples/LayerPanel.java
@@ -119,8 +119,8 @@ public void setToolTipText(String string)
protected static class LayerAction extends AbstractAction
{
WorldWindow wwd;
- private Layer layer;
- private boolean selected;
+ protected Layer layer;
+ protected boolean selected;
public LayerAction(Layer layer, WorldWindow wwd, boolean selected)
{
Please sign in to comment.
Something went wrong with that request. Please try again.