2 Copyright (C) 2001, 2006 United States Government
3 as represented by the Administrator of the
4 National Aeronautics and Space Administration.
7 package gov
.nasa
.worldwind
.layers
;
9 import gov
.nasa
.worldwind
.*;
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()
28 public boolean isPickEnabled()
33 public void setPickEnabled(boolean pickable
)
35 this.pickable
= pickable
;
38 public void setEnabled(boolean enabled
)
40 this.enabled
= enabled
;
43 public String
getName()
48 public void setName(String name
)
50 this.setValue(AVKey
.DISPLAY_NAME
, name
);
53 public String
toString()
58 private String
myName()
61 Object name
= this.getValue(AVKey
.DISPLAY_NAME
);
63 myName
= name
.toString();
65 myName
= this.toString();
69 public double getOpacity()
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
;
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
)
110 String message
= WorldWind
.retrieveErrMsg("nullValue.DrawContextIsNull");
111 WorldWind
.logger().log(java
.util
.logging
.Level
.FINE
, message
);
112 throw new IllegalStateException(message
);
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
)
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
)
154 return; // Don't check for arg errors if we're disabled
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
))
180 if (!this.isLayerInView(dc
))
186 public void pick(DrawContext dc
, java
.awt
.Point point
)
189 return; // Don't check for arg errors if we're disabled
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
))
215 if (!this.isLayerInView(dc
))
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
);