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 2080 2007-06-18 16:41:30Z 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
.MAX_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()
45 Object n
= this.getValue(AVKey
.DISPLAY_NAME
);
47 return n
!= null ? n
.toString() : this.toString();
50 public void setName(String name
)
52 this.setValue(AVKey
.DISPLAY_NAME
, name
);
55 public String
toString()
57 Object n
= this.getValue(AVKey
.DISPLAY_NAME
);
59 return n
!= null ? n
.toString() : super.toString();
62 public double getOpacity()
67 public void setOpacity(double opacity
)
69 this.opacity
= opacity
;
72 public double getMinActiveAltitude()
74 return minActiveAltitude
;
77 public void setMinActiveAltitude(double minActiveAltitude
)
79 this.minActiveAltitude
= minActiveAltitude
;
82 public double getMaxActiveAltitude()
84 return maxActiveAltitude
;
87 public void setMaxActiveAltitude(double maxActiveAltitude
)
89 this.maxActiveAltitude
= maxActiveAltitude
;
93 * Indicates whether the layer is in the view. The method implemented here is a default indicating the layer is in
94 * view. Subclasses able to determine their presence in the view should override this implementation.
96 * @param dc the current draw context
97 * @return <code>true</code> if the layer is in the view, <code>false</code> otherwise.
99 public boolean isLayerInView(DrawContext dc
)
103 String message
= WorldWind
.retrieveErrMsg("nullValue.DrawContextIsNull");
104 WorldWind
.logger().log(java
.util
.logging
.Level
.FINE
, message
);
105 throw new IllegalStateException(message
);
112 * Indicates whether the layer is active based on arbitrary criteria. The method implemented here is a default
113 * indicating the layer is active if the current altitude is within the layer's min and max active altitudes.
114 * Subclasses able to consider more criteria should override this implementation.
116 * @param dc the current draw context
117 * @return <code>true</code> if the layer is active, <code>false</code> otherwise.
119 public boolean isLayerActive(DrawContext dc
)
123 String message
= WorldWind
.retrieveErrMsg("nullValue.DrawContextIsNull");
124 WorldWind
.logger().log(java
.util
.logging
.Level
.FINE
, message
);
125 throw new IllegalStateException(message
);
128 if (null == dc
.getView())
130 String message
= WorldWind
.retrieveErrMsg("layers.AbstractLayer.NoViewSpecifiedInDrawingContext");
131 WorldWind
.logger().log(java
.util
.logging
.Level
.FINE
, message
);
132 throw new IllegalStateException(message
);
135 double altitude
= dc
.getView().getAltitude();
137 return altitude
>= this.minActiveAltitude
&& altitude
<= this.maxActiveAltitude
;
141 * @param dc the current draw context
142 * @throws IllegalArgumentException if <code>dc</code> is null, or <code>dc</code>'s <code>Globe</code> or
143 * <code>View</code> is null
145 public void render(DrawContext dc
)
148 return; // Don't check for arg errors if we're disabled
152 String message
= WorldWind
.retrieveErrMsg("nullValue.DrawContextIsNull");
153 WorldWind
.logger().log(java
.util
.logging
.Level
.FINE
, message
);
154 throw new IllegalStateException(message
);
157 if (null == dc
.getGlobe())
159 String message
= WorldWind
.retrieveErrMsg("layers.AbstractLayer.NoGlobeSpecifiedInDrawingContext");
160 WorldWind
.logger().log(java
.util
.logging
.Level
.FINE
, message
);
161 throw new IllegalStateException(message
);
164 if (null == dc
.getView())
166 String message
= WorldWind
.retrieveErrMsg("layers.AbstractLayer.NoViewSpecifiedInDrawingContext");
167 WorldWind
.logger().log(java
.util
.logging
.Level
.FINE
, message
);
168 throw new IllegalStateException(message
);
171 if (!this.isLayerActive(dc
))
174 if (!this.isLayerInView(dc
))
180 public void pick(DrawContext dc
, java
.awt
.Point point
)
183 return; // Don't check for arg errors if we're disabled
187 String message
= WorldWind
.retrieveErrMsg("nullValue.DrawContextIsNull");
188 WorldWind
.logger().log(java
.util
.logging
.Level
.FINE
, message
);
189 throw new IllegalStateException(message
);
192 if (null == dc
.getGlobe())
194 String message
= WorldWind
.retrieveErrMsg("layers.AbstractLayer.NoGlobeSpecifiedInDrawingContext");
195 WorldWind
.logger().log(java
.util
.logging
.Level
.FINE
, message
);
196 throw new IllegalStateException(message
);
199 if (null == dc
.getView())
201 String message
= WorldWind
.retrieveErrMsg("layers.AbstractLayer.NoViewSpecifiedInDrawingContext");
202 WorldWind
.logger().log(java
.util
.logging
.Level
.FINE
, message
);
203 throw new IllegalStateException(message
);
206 if (!this.isLayerActive(dc
))
209 if (!this.isLayerInView(dc
))
212 this.doPick(dc
, point
);
215 protected void doPick(DrawContext dc
, java
.awt
.Point point
)
217 // any state that could change the color needs to be disabled, such as GL_TEXTURE, GL_LIGHTING or GL_FOG.
218 // re-draw with unique colors
219 // store the object info in the selectable objects table
220 // read the color under the coursor
221 // use the color code as a key to retrieve a selected object from the selectable objects table
222 // create an instance of the PickedObject and add to the dc via the dc.addPickedObject() method
225 public void dispose() // override if disposal is a supported operation
229 protected abstract void doRender(DrawContext dc
);