📄 airspaces.java
字号:
this.airspaceLayer.setDrawExtents(cb.isSelected());
this.wwd.redraw();
}
}
public void setAirspaces(Collection<Airspace> airspaces)
{
this.airspaceLayer.removeAllAirspaces();
if (airspaces != null)
{
for (Airspace a : airspaces)
{
if (a != null)
{
this.airspaceLayer.addAirspace(a);
}
}
}
}
public void initializeSelectionMonitoring()
{
this.dragger = new BasicDragger(this.wwd);
this.wwd.addSelectListener(new SelectListener()
{
public void selected(SelectEvent event)
{
if (lastHighlit != null
&& (event.getTopObject() == null || !event.getTopObject().equals(lastHighlit)))
{
lastHighlit.setAttributes(lastAttrs);
lastHighlit = null;
}
if (lastToolTip != null
&& (event.getTopObject() == null || !event.getTopObject().equals(lastHighlit)))
{
annotationLayer.removeAnnotation(lastAnnotation);
lastToolTip = null;
}
// Have rollover events highlight the rolled-over object.
if (event.getEventAction().equals(SelectEvent.ROLLOVER) && !dragger.isDragging())
{
if (event.getTopObject() != null && event.getTopPickedObject().getParentLayer() != null)
{
if (event.getTopPickedObject().getParentLayer() == airspaceLayer)
{
AirspacesController.this.highlight(event.getTopObject());
AirspacesController.this.wwd.redraw();
}
}
}
// Have hover events popup an annotation about the hovered-over object.
else if (event.getEventAction().equals(SelectEvent.HOVER) && !dragger.isDragging())
{
if (event.getTopObject() != null && event.getTopPickedObject().getParentLayer() != null)
{
if (event.getTopPickedObject().getParentLayer() == airspaceLayer)
{
AirspacesController.this.popupToolTip(event.getTopObject(), event);
AirspacesController.this.wwd.redraw();
}
}
}
// Have drag events drag the selected object.
else if (event.getEventAction().equals(SelectEvent.DRAG_END)
|| event.getEventAction().equals(SelectEvent.DRAG))
{
// Delegate dragging computations to a dragger.
dragger.selected(event);
// We missed any roll-over events while dragging, so highlight any under the cursor now,
// or de-highlight the dragged shape if it's no longer under the cursor.
if (event.getEventAction().equals(SelectEvent.DRAG_END))
{
PickedObjectList pol = AirspacesController.this.wwd.getObjectsAtCurrentPosition();
if (pol != null)
{
AirspacesController.this.highlight(pol.getTopObject());
AirspacesController.this.wwd.repaint();
}
}
}
}
});
}
private void highlight(Object o)
{
if (lastHighlit == o)
return; // same thing selected
if (lastHighlit == null && o instanceof Airspace)
{
lastHighlit = (Airspace) o;
lastAttrs = lastHighlit.getAttributes();
BasicAirspaceAttributes highliteAttrs = new BasicAirspaceAttributes(lastAttrs);
highliteAttrs.setMaterial(Material.WHITE);
lastHighlit.setAttributes(highliteAttrs);
}
}
private void popupToolTip(Object o, SelectEvent e)
{
if (lastToolTip == o)
return;
if (lastToolTip == null && o instanceof Airspace)
{
lastToolTip = (Airspace) o;
lastAnnotation = this.createToolTip((Airspace) o, e);
annotationLayer.addAnnotation(lastAnnotation);
}
}
private Annotation createToolTip(Airspace a, SelectEvent e)
{
Object o = a.getValue(DESCRIPTION);
if (o == null)
o = a.getClass().getName();
java.awt.Point point = e.getPickPoint();
Position pos = wwd.getView().computePositionFromScreenPoint(point.x, point.y);
if (pos != null)
{
double[] altitudes = a.getAltitudes();
pos = new Position(pos.getLatitude(), pos.getLongitude(), altitudes[1]);
return new GlobeAnnotation(o.toString(), pos);
}
else
{
return new ScreenAnnotation(o.toString(), point);
}
}
private void setupDefaultMaterial(Airspace a, Color color)
{
Color outlineColor = makeBrighter(color);
a.getAttributes().setDrawOutline(true);
a.getAttributes().setMaterial(new Material(color));
a.getAttributes().setOutlineMaterial(new Material(outlineColor));
a.getAttributes().setOpacity(0.8);
a.getAttributes().setOutlineOpacity(0.9);
a.getAttributes().setOutlineWidth(3.0);
}
private static Color makeBrighter(Color color)
{
float[] hsbComponents = new float[3];
Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), hsbComponents);
float hue = hsbComponents[0];
float saturation = hsbComponents[1];
float brightness = hsbComponents[2];
saturation /= 3f;
brightness *= 3f;
if (saturation < 0f)
saturation = 0f;
if (brightness > 1f)
brightness = 1f;
int rgbInt = Color.HSBtoRGB(hue, saturation, brightness);
return new Color(rgbInt);
}
public void doLoadDemoAirspaces()
{
ArrayList<Airspace> airspaces = new ArrayList<Airspace>();
// Cylinder.
CappedCylinder cyl = new CappedCylinder();
cyl.setCenter(LatLon.fromDegrees(47.7477, -123.6372));
cyl.setRadius(30000.0);
cyl.setAltitudes(5000.0, 10000.0);
cyl.setTerrainConforming(true, true);
cyl.setValue(DESCRIPTION, "30,000m Radius Cylinder. Top & bottom terrain conformance.");
this.setupDefaultMaterial(cyl, Color.BLUE);
airspaces.add(cyl);
// Continent-sized cylinder.
cyl = new CappedCylinder();
cyl.setCenter(LatLon.fromDegrees(0.0, 0.0));
cyl.setRadius(3000000.0);
cyl.setAltitudes(100000.0, 500000.0);
cyl.setTerrainConforming(true, false);
cyl.setValue(DESCRIPTION, "3,000,000m Cylinder.");
this.setupDefaultMaterial(cyl, Color.RED);
airspaces.add(cyl);
// Radarc
PartialCappedCylinder partCyl = new PartialCappedCylinder();
partCyl.setCenter(LatLon.fromDegrees(46.7477, -123.6372));
partCyl.setAltitudes(5000.0, 10000.0);
partCyl.setTerrainConforming(false, true);
// To render a Radarc,
// (1) Specify inner radius and outer radius.
// (2) Specify start and stop azimuth.
partCyl.setRadii(15000.0, 30000.0);
partCyl.setAzimuths(Angle.fromDegrees(0.0), Angle.fromDegrees(90.0));
partCyl.setValue(DESCRIPTION, "Partial Cylinder from 0 to 90 degrees.");
this.setupDefaultMaterial(partCyl, Color.DARK_GRAY);
airspaces.add(partCyl);
// Radarc
partCyl = new PartialCappedCylinder();
partCyl.setCenter(LatLon.fromDegrees(46.7477, -122.6372));
partCyl.setAltitudes(5000.0, 10000.0);
partCyl.setTerrainConforming(true, true);
// To render a Radarc,
// (1) Specify inner radius and outer radius.
// (2) Specify start and stop azimuth.
partCyl.setRadii(15000.0, 30000.0);
partCyl.setAzimuths(Angle.fromDegrees(90.0), Angle.fromDegrees(0.0));
partCyl.setValue(DESCRIPTION, "Partial Cylinder from 90 to 0 degrees.");
this.setupDefaultMaterial(partCyl, Color.GRAY);
airspaces.add(partCyl);
// Cake
Cake cake = new Cake();
cake.setLayers(Arrays.asList(
new Cake.Layer(LatLon.fromDegrees(46.7477, -121.6372), 10000.0, Angle.fromDegrees(190.0),
Angle.fromDegrees(170.0), 10000.0, 15000.0),
new Cake.Layer(LatLon.fromDegrees(46.7477, -121.6372), 15000.0, Angle.fromDegrees(190.0),
Angle.fromDegrees(90.0), 16000.0, 21000.0),
new Cake.Layer(LatLon.fromDegrees(46.7477, -121.6372), 12500.0, Angle.fromDegrees(270.0),
Angle.fromDegrees(60.0), 22000.0, 27000.0)));
cake.getLayers().get(0).setTerrainConforming(false, false);
cake.getLayers().get(1).setTerrainConforming(false, false);
cake.getLayers().get(2).setTerrainConforming(false, true);
cake.setValue(DESCRIPTION, "3 layer Cake.");
this.setupDefaultMaterial(cake, Color.YELLOW);
airspaces.add(cake);
cake = new Cake();
cake.setLayers(Arrays.asList(
new Cake.Layer(LatLon.fromDegrees(36, -121), 10000.0, Angle.fromDegrees(0.0),
Angle.fromDegrees(360.0), 10000.0, 15000.0),
new Cake.Layer(LatLon.fromDegrees(36.1, -121.1), 15000.0, Angle.fromDegrees(0.0),
Angle.fromDegrees(360.0), 16000.0, 21000.0),
new Cake.Layer(LatLon.fromDegrees(35.9, -120.9), 12500.0, Angle.fromDegrees(0.0),
Angle.fromDegrees(360.0), 22000.0, 27000.0)));
cake.getLayers().get(0).setTerrainConforming(true, true);
cake.getLayers().get(1).setTerrainConforming(true, true);
cake.getLayers().get(2).setTerrainConforming(true, true);
cake.setValue(DESCRIPTION, "3 layer Cake. With disjoint layers.");
this.setupDefaultMaterial(cake, Color.MAGENTA);
airspaces.add(cake);
// Left Orbit
Orbit orbit = new Orbit();
orbit.setLocations(LatLon.fromDegrees(45.7477, -123.6372), LatLon.fromDegrees(45.7477, -122.6372));
orbit.setAltitudes(10000.0, 20000.0);
orbit.setWidth(30000.0);
orbit.setOrbitType(Orbit.OrbitType.LEFT);
orbit.setTerrainConforming(false, true);
orbit.setValue(DESCRIPTION, "LEFT Orbit.");
this.setupDefaultMaterial(orbit, Color.LIGHT_GRAY);
airspaces.add(orbit);
// Center Orbit
orbit = new Orbit();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -