-
Notifications
You must be signed in to change notification settings - Fork 339
Expand file tree
/
Copy pathElevationModelManagerPanel.java
More file actions
147 lines (122 loc) · 5.16 KB
/
ElevationModelManagerPanel.java
File metadata and controls
147 lines (122 loc) · 5.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*
* Copyright (C) 2013 United States Government as represented by the Administrator of the
* National Aeronautics and Space Administration.
* All Rights Reserved.
*/
package gov.nasa.worldwindx.examples.layermanager;
import gov.nasa.worldwind.WorldWindow;
import gov.nasa.worldwind.avlist.AVKey;
import gov.nasa.worldwind.globes.ElevationModel;
import gov.nasa.worldwind.terrain.CompoundElevationModel;
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.beans.*;
import java.util.*;
import java.util.List;
/**
* Manages visibility and Z order of elevation models, similar to the layer manager.
*
* @author tag
* @version $Id: ElevationModelManagerPanel.java 2071 2014-06-21 21:04:34Z tgaskins $
*/
public class ElevationModelManagerPanel extends JPanel
{
protected JPanel modelNamesPanel;
protected List<ElevationModelPanel> modelPanels = new ArrayList<ElevationModelPanel>();
public ElevationModelManagerPanel(final WorldWindow wwd)
{
super(new BorderLayout(10, 10));
this.modelNamesPanel = new JPanel(new GridLayout(0, 1, 0, 5));
this.modelNamesPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
// Add the panel to a titled panel.
JPanel titlePanel = new JPanel(new GridLayout(0, 1, 0, 10));
titlePanel.setBorder(
new CompoundBorder(BorderFactory.createEmptyBorder(9, 9, 9, 9), new TitledBorder("Elevations")));
titlePanel.setToolTipText("Elevation models to use");
titlePanel.add(this.modelNamesPanel);
this.add(titlePanel, BorderLayout.CENTER);
this.fill(wwd);
// Add a property change listener that causes this panel to be updated whenever the elevation model list
// changes.
wwd.addPropertyChangeListener(new PropertyChangeListener()
{
@Override
public void propertyChange(PropertyChangeEvent propertyChangeEvent)
{
if (propertyChangeEvent.getPropertyName().equals(AVKey.ELEVATION_MODEL))
if (!SwingUtilities.isEventDispatchThread())
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
update(wwd);
}
});
}
});
else
update(wwd);
}
});
}
public void update(WorldWindow wwd)
{
// Repopulate this elevation model manager.
this.fill(wwd);
this.revalidate();
this.repaint();
}
protected void fill(WorldWindow wwd)
{
// Populate this manager with an entry for each elevation model in the WorldWindow.
if (this.isUpToDate(wwd))
return;
// First remove all the existing entries.
this.modelPanels.clear();
this.modelNamesPanel.removeAll();
// Fill the panel with the titles of all elevation models in the WorldWindow.
if (!(wwd.getModel().getGlobe().getElevationModel() instanceof CompoundElevationModel))
{
ElevationModelPanel elevationModelPanel = new ElevationModelPanel(wwd, this,
wwd.getModel().getGlobe().getElevationModel());
this.modelPanels.add(elevationModelPanel);
this.modelNamesPanel.add(elevationModelPanel);
}
else
{
CompoundElevationModel cem = (CompoundElevationModel) wwd.getModel().getGlobe().getElevationModel();
for (ElevationModel elevationModel : cem.getElevationModels())
{
if (elevationModel.getValue(AVKey.IGNORE) != null)
continue;
ElevationModelPanel elevationModelPanel = new ElevationModelPanel(wwd, this, elevationModel);
this.modelPanels.add(elevationModelPanel);
this.modelNamesPanel.add(elevationModelPanel);
}
}
}
protected boolean isUpToDate(WorldWindow wwd)
{
// Determines whether this manager's elevation model list is consistent with the specified WorldWindow's.
// Knowing this prevents redundant updates.
if (!(wwd.getModel().getGlobe().getElevationModel() instanceof CompoundElevationModel))
{
if (this.modelPanels.size() == 0) return false;
return this.modelPanels.get(0).getElevationModel() == wwd.getModel().getGlobe().getElevationModel();
}
CompoundElevationModel cem = (CompoundElevationModel) wwd.getModel().getGlobe().getElevationModel();
if (this.modelPanels.size() != cem.getElevationModels().size())
return false;
for (int i = 0; i < cem.getElevationModels().size(); i++)
{
if (cem.getElevationModels().get(i) != this.modelPanels.get(i).getElevationModel())
return false;
}
return true;
}
}