Worldwind public release 0.2
[worldwind-tracker.git] / gov / nasa / worldwind / layers / AbstractLayer.java
blob233509627d261d01cdda3564714bc3427b793b76
1 /*
2 Copyright (C) 2001, 2006 United States Government
3 as represented by the Administrator of the
4 National Aeronautics and Space Administration.
5 All Rights Reserved.
6 */
7 package gov.nasa.worldwind.layers;
9 import gov.nasa.worldwind.*;
11 /**
12 * @author tag
13 * @version $Id: AbstractLayer.java 1735 2007-05-05 09:50:26Z tgaskins $
15 public abstract class AbstractLayer extends WWObjectImpl implements Layer
17 private boolean enabled = true;
18 private boolean pickable = true;
19 private double opacity = 1d;
20 private double minActiveAltitude = Double.MIN_VALUE;
21 private double maxActiveAltitude = Double.MAX_VALUE;
23 public boolean isEnabled()
25 return this.enabled;
28 public boolean isPickEnabled()
30 return pickable;
33 public void setPickEnabled(boolean pickable)
35 this.pickable = pickable;
38 public void setEnabled(boolean enabled)
40 this.enabled = enabled;
43 public String getName()
45 return this.myName();
48 public void setName(String name)
50 this.setValue(AVKey.DISPLAY_NAME, name);
53 public String toString()
55 return this.myName();
58 private String myName()
60 String myName = null;
61 Object name = this.getValue(AVKey.DISPLAY_NAME);
62 if (null != name)
63 myName = name.toString();
64 if (null == myName)
65 myName = this.toString();
66 return myName;
69 public double getOpacity()
71 return opacity;
74 public void setOpacity(double opacity)
76 this.opacity = opacity;
79 public double getMinActiveAltitude()
81 return minActiveAltitude;
84 public void setMinActiveAltitude(double minActiveAltitude)
86 this.minActiveAltitude = minActiveAltitude;
89 public double getMaxActiveAltitude()
91 return maxActiveAltitude;
94 public void setMaxActiveAltitude(double maxActiveAltitude)
96 this.maxActiveAltitude = maxActiveAltitude;
99 /**
100 * Indicates whether the layer is in the view. The method implemented here is a default indicating the layer is in
101 * view. Subclasses able to determine their presence in the view should override this implementation.
103 * @param dc the current draw context
104 * @return <code>true</code> if the layer is in the view, <code>false</code> otherwise.
106 public boolean isLayerInView(DrawContext dc)
108 if (dc == null)
110 String message = WorldWind.retrieveErrMsg("nullValue.DrawContextIsNull");
111 WorldWind.logger().log(java.util.logging.Level.FINE, message);
112 throw new IllegalStateException(message);
115 return true;
119 * Indicates whether the layer is active based on arbitrary criteria. The method implemented here is a default
120 * indicating the layer is active if the current altitude is within the layer's min and max active altitudes.
121 * Subclasses able to consider more criteria should override this implementation.
122 * @param dc the current draw context
123 * @return <code>true</code> if the layer is active, <code>false</code> otherwise.
125 public boolean isLayerActive(DrawContext dc)
127 if (dc == null)
129 String message = WorldWind.retrieveErrMsg("nullValue.DrawContextIsNull");
130 WorldWind.logger().log(java.util.logging.Level.FINE, message);
131 throw new IllegalStateException(message);
134 if (null == dc.getView())
136 String message = WorldWind.retrieveErrMsg("layers.AbstractLayer.NoViewSpecifiedInDrawingContext");
137 WorldWind.logger().log(java.util.logging.Level.FINE, message);
138 throw new IllegalStateException(message);
141 double altitude = dc.getView().getAltitude();
143 return altitude >= this.minActiveAltitude && altitude <= this.maxActiveAltitude;
147 * @param dc the current draw context
148 * @throws IllegalArgumentException if <code>dc</code> is null, or <code>dc</code>'s <code>Globe</code> or
149 * <code>View</code> is null
151 public void render(DrawContext dc)
153 if (!this.enabled)
154 return; // Don't check for arg errors if we're disabled
156 if (null == dc)
158 String message = WorldWind.retrieveErrMsg("nullValue.DrawContextIsNull");
159 WorldWind.logger().log(java.util.logging.Level.FINE, message);
160 throw new IllegalStateException(message);
163 if (null == dc.getGlobe())
165 String message = WorldWind.retrieveErrMsg("layers.AbstractLayer.NoGlobeSpecifiedInDrawingContext");
166 WorldWind.logger().log(java.util.logging.Level.FINE, message);
167 throw new IllegalStateException(message);
170 if (null == dc.getView())
172 String message = WorldWind.retrieveErrMsg("layers.AbstractLayer.NoViewSpecifiedInDrawingContext");
173 WorldWind.logger().log(java.util.logging.Level.FINE, message);
174 throw new IllegalStateException(message);
177 if (!this.isLayerActive(dc))
178 return;
180 if (!this.isLayerInView(dc))
181 return;
183 this.doRender(dc);
186 public void pick(DrawContext dc, java.awt.Point point)
188 if (!this.enabled)
189 return; // Don't check for arg errors if we're disabled
191 if (null == dc)
193 String message = WorldWind.retrieveErrMsg("nullValue.DrawContextIsNull");
194 WorldWind.logger().log(java.util.logging.Level.FINE, message);
195 throw new IllegalStateException(message);
198 if (null == dc.getGlobe())
200 String message = WorldWind.retrieveErrMsg("layers.AbstractLayer.NoGlobeSpecifiedInDrawingContext");
201 WorldWind.logger().log(java.util.logging.Level.FINE, message);
202 throw new IllegalStateException(message);
205 if (null == dc.getView())
207 String message = WorldWind.retrieveErrMsg("layers.AbstractLayer.NoViewSpecifiedInDrawingContext");
208 WorldWind.logger().log(java.util.logging.Level.FINE, message);
209 throw new IllegalStateException(message);
212 if (!this.isLayerActive(dc))
213 return;
215 if (!this.isLayerInView(dc))
216 return;
218 this.doPick(dc, point);
221 protected void doPick(DrawContext dc, java.awt.Point point)
223 // any state that could change the color needs to be disabled, such as GL_TEXTURE, GL_LIGHTING or GL_FOG.
224 // re-draw with unique colors
225 // store the object info in the selectable objects table
226 // read the color under the coursor
227 // use the color code as a key to retrieve a selected object from the selectable objects table
228 // create an instance of the PickedObject and add to the dc via the dc.addPickedObject() method
231 public void dispose() // override if disposal is a supported operation
235 protected abstract void doRender(DrawContext dc);