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
.WWObjectImpl
;
10 import gov
.nasa
.worldwind
.avlist
.AVKey
;
11 import gov
.nasa
.worldwind
.geom
.Position
;
12 import gov
.nasa
.worldwind
.render
.DrawContext
;
13 import gov
.nasa
.worldwind
.util
.Logging
;
17 * @version $Id: AbstractLayer.java 2471 2007-07-31 21:50:57Z tgaskins $
19 public abstract class AbstractLayer
extends WWObjectImpl
implements Layer
21 private boolean enabled
= true;
22 private boolean pickable
= true;
23 private double opacity
= 1d
;
24 private double minActiveAltitude
= -Double
.MAX_VALUE
;
25 private double maxActiveAltitude
= Double
.MAX_VALUE
;
27 public boolean isEnabled()
32 public boolean isPickEnabled()
37 public void setPickEnabled(boolean pickable
)
39 this.pickable
= pickable
;
42 public void setEnabled(boolean enabled
)
44 this.enabled
= enabled
;
47 public String
getName()
49 Object n
= this.getValue(AVKey
.DISPLAY_NAME
);
51 return n
!= null ? n
.toString() : this.toString();
54 public void setName(String name
)
56 this.setValue(AVKey
.DISPLAY_NAME
, name
);
59 public String
toString()
61 Object n
= this.getValue(AVKey
.DISPLAY_NAME
);
63 return n
!= null ? n
.toString() : super.toString();
66 public double getOpacity()
71 public void setOpacity(double opacity
)
73 this.opacity
= opacity
;
76 public double getMinActiveAltitude()
78 return minActiveAltitude
;
81 public void setMinActiveAltitude(double minActiveAltitude
)
83 this.minActiveAltitude
= minActiveAltitude
;
86 public double getMaxActiveAltitude()
88 return maxActiveAltitude
;
91 public void setMaxActiveAltitude(double maxActiveAltitude
)
93 this.maxActiveAltitude
= maxActiveAltitude
;
97 * Indicates whether the layer is in the view. The method implemented here is a default indicating the layer is in
98 * view. Subclasses able to determine their presence in the view should override this implementation.
100 * @param dc the current draw context
101 * @return <code>true</code> if the layer is in the view, <code>false</code> otherwise.
103 public boolean isLayerInView(DrawContext dc
)
107 String message
= Logging
.getMessage("nullValue.DrawContextIsNull");
108 Logging
.logger().severe(message
);
109 throw new IllegalStateException(message
);
116 * Indicates whether the layer is active based on arbitrary criteria. The method implemented here is a default
117 * indicating the layer is active if the current altitude is within the layer's min and max active altitudes.
118 * Subclasses able to consider more criteria should override this implementation.
120 * @param dc the current draw context
121 * @return <code>true</code> if the layer is active, <code>false</code> otherwise.
123 public boolean isLayerActive(DrawContext dc
)
127 String message
= Logging
.getMessage("nullValue.DrawContextIsNull");
128 Logging
.logger().severe(message
);
129 throw new IllegalStateException(message
);
132 if (null == dc
.getView())
134 String message
= Logging
.getMessage("layers.AbstractLayer.NoViewSpecifiedInDrawingContext");
135 Logging
.logger().severe(message
);
136 throw new IllegalStateException(message
);
139 Position eyePos
= dc
.getView().getEyePosition();
143 double altitude
= eyePos
.getElevation();
144 return altitude
>= this.minActiveAltitude
&& altitude
<= this.maxActiveAltitude
;
148 * @param dc the current draw context
149 * @throws IllegalArgumentException if <code>dc</code> is null, or <code>dc</code>'s <code>Globe</code> or
150 * <code>View</code> is null
152 public void render(DrawContext dc
)
155 return; // Don't check for arg errors if we're disabled
159 String message
= Logging
.getMessage("nullValue.DrawContextIsNull");
160 Logging
.logger().severe(message
);
161 throw new IllegalStateException(message
);
164 if (null == dc
.getGlobe())
166 String message
= Logging
.getMessage("layers.AbstractLayer.NoGlobeSpecifiedInDrawingContext");
167 Logging
.logger().severe(message
);
168 throw new IllegalStateException(message
);
171 if (null == dc
.getView())
173 String message
= Logging
.getMessage("layers.AbstractLayer.NoViewSpecifiedInDrawingContext");
174 Logging
.logger().severe(message
);
175 throw new IllegalStateException(message
);
178 if (!this.isLayerActive(dc
))
181 if (!this.isLayerInView(dc
))
187 public void pick(DrawContext dc
, java
.awt
.Point point
)
190 return; // Don't check for arg errors if we're disabled
194 String message
= Logging
.getMessage("nullValue.DrawContextIsNull");
195 Logging
.logger().severe(message
);
196 throw new IllegalStateException(message
);
199 if (null == dc
.getGlobe())
201 String message
= Logging
.getMessage("layers.AbstractLayer.NoGlobeSpecifiedInDrawingContext");
202 Logging
.logger().severe(message
);
203 throw new IllegalStateException(message
);
206 if (null == dc
.getView())
208 String message
= Logging
.getMessage("layers.AbstractLayer.NoViewSpecifiedInDrawingContext");
209 Logging
.logger().severe(message
);
210 throw new IllegalStateException(message
);
213 if (!this.isLayerActive(dc
))
216 if (!this.isLayerInView(dc
))
219 this.doPick(dc
, point
);
222 protected void doPick(DrawContext dc
, java
.awt
.Point point
)
224 // any state that could change the color needs to be disabled, such as GL_TEXTURE, GL_LIGHTING or GL_FOG.
225 // re-draw with unique colors
226 // store the object info in the selectable objects table
227 // read the color under the coursor
228 // use the color code as a key to retrieve a selected object from the selectable objects table
229 // create an instance of the PickedObject and add to the dc via the dc.addPickedObject() method
232 public void dispose() // override if disposal is a supported operation
236 protected abstract void doRender(DrawContext dc
);