Commit 66a06e44 authored by Christopher Reis's avatar Christopher Reis

Added 3D window and buggy tracking

parent b91373b5
......@@ -13,6 +13,8 @@ import javax.swing.ImageIcon;
import javax.swing.JMenuItem;
import javax.swing.AbstractAction;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Action;
import javax.swing.JTree;
import javax.swing.tree.DefaultTreeModel;
......@@ -28,6 +30,11 @@ import java.awt.event.KeyEvent;
import java.awt.event.InputEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.swing.JDesktopPane;
import javax.swing.JToolBar;
import javax.swing.JProgressBar;
......@@ -37,19 +44,37 @@ import javax.swing.JTextField;
public class Application {
private JFrame frmSatelliteTracker;
private final Action action = new SwingAction();
TrackerList trackList = new TrackerList();
SatelliteDB satellites = new SatelliteDB("SatelliteDB");
static TrackerList trackList = new TrackerList();
static SatelliteDB satellites = new SatelliteDB("SatelliteDB");
static view3D threeDview = new view3D();
static ActionListener updateTracks = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
List<satPosition> pos = TrackerList.getTracks();
threeDview.updateTracks(pos);
System.out.println("update");
}
};
static ActionListener addtrack = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
threeDview.addSatellite(TrackerList.getTracks());
}
};
/**
* Launch the application.
* @throws InterruptedException
* @throws InvocationTargetException
*/
public static void main(String[] args) {
public static void main(String[] args) throws InvocationTargetException, InterruptedException {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Application window = new Application();
window.frmSatelliteTracker.setVisible(true);
new javax.swing.Timer(500, updateTracks).start();
new javax.swing.Timer(500, addtrack).start();
} catch (Exception e) {
e.printStackTrace();
}
......@@ -62,6 +87,18 @@ public class Application {
*/
public Application() {
initialize();
// EventQueue.invokeLater(new Runnable() {
// public void run() {
// try {
// while(true){
// System.out.println(new Date());
// Thread.sleep(500);
// }
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
// });
}
/**
......@@ -80,15 +117,26 @@ public class Application {
satTree.setClosable(true);
satTree.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
satTree.setResizable(true);
satTree.setBounds(10, 52, 867, 495);
satTree.setVisible(false);
satTree.setBounds(448, 177, 867, 495);
desktopPane.add(satTree);
satelliteStatus satStatus = new satelliteStatus();
satStatus.setLocation(32, 86);
satStatus.setClosable(true);
satStatus.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
satStatus.setResizable(true);
satStatus.setVisible(false);
desktopPane.add(satStatus);
threeDview = new view3D();
threeDview.setClosable(true);
threeDview.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
threeDview.setResizable(true);
threeDview.setVisible(true);
threeDview.setBounds(300, 20, 500, 500);
desktopPane.add(threeDview);
JMenuBar menuBar = new JMenuBar();
frmSatelliteTracker.setJMenuBar(menuBar);
......@@ -208,14 +256,5 @@ public class Application {
}
private class SwingAction extends AbstractAction {
public SwingAction() {
putValue(NAME, "SwingAction");
putValue(SHORT_DESCRIPTION, "Some short description");
}
public void actionPerformed(ActionEvent e) {
}
}
}
......@@ -25,6 +25,7 @@ import javax.swing.JPanel;
import javax.swing.JButton;
import java.awt.GridLayout;
@SuppressWarnings("serial")
public class satelliteStatus extends JInternalFrame {
SatelliteTrack curSat = null;
......@@ -56,7 +57,7 @@ public class satelliteStatus extends JInternalFrame {
TrackerList.startTrack(curSat.getTLE().getName(), "Albuquerque");
//thread.setSatellite(curSat);
//(new Thread(new thread())).start();
}
}
});
panel.setLayout(null);
panel.add(btnStartTracking);
......@@ -74,29 +75,21 @@ public class satelliteStatus extends JInternalFrame {
panel.add(btnStopTracking);
JLabel lblLatitude = new JLabel("Latitude");
lblLatitude.setBounds(35, 21, 165, 31);
lblLatitude.setBounds(35, 94, 92, 31);
panel.add(lblLatitude);
JLabel lblLongitude = new JLabel("Longitude");
lblLongitude.setBounds(35, 73, 92, 26);
lblLongitude.setBounds(35, 144, 92, 26);
panel.add(lblLongitude);
JLabel lblAltitude = new JLabel("Altitude");
lblAltitude.setBounds(35, 120, 92, 26);
lblAltitude.setBounds(35, 191, 92, 26);
panel.add(lblAltitude);
JLabel lblRange = new JLabel("Range");
lblRange.setBounds(35, 172, 92, 26);
lblRange.setBounds(35, 232, 92, 26);
panel.add(lblRange);
JLabel lblLat = new JLabel("Lat");
lblLat.setBounds(164, 23, 92, 26);
panel.add(lblLat);
JLabel lblLong = new JLabel("Long");
lblLong.setBounds(164, 73, 92, 26);
panel.add(lblLong);
//Where the tree is initialized:
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
......
package GUI;
import java.awt.Color;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JInternalFrame;
import gov.nasa.worldwind.BasicModel;
import gov.nasa.worldwind.WorldWind;
import gov.nasa.worldwind.avlist.AVKey;
import gov.nasa.worldwind.awt.WorldWindowGLCanvas;
import gov.nasa.worldwind.geom.Position;
import gov.nasa.worldwind.layers.Layer;
import gov.nasa.worldwind.layers.LayerList;
import gov.nasa.worldwind.layers.RenderableLayer;
import gov.nasa.worldwind.render.Offset;
import gov.nasa.worldwind.render.PointPlacemark;
import gov.nasa.worldwind.render.PointPlacemarkAttributes;
import gov.nasa.worldwind.render.Renderable;
import satellite.satPosition;
public class view3D extends JInternalFrame{
private List<satPosition> trackList = new ArrayList<satPosition>();
WorldWindowGLCanvas wwd;
public view3D()
{
wwd = new WorldWindowGLCanvas();
wwd.setPreferredSize(new java.awt.Dimension(500, 500));
this.getContentPane().add(wwd, java.awt.BorderLayout.CENTER);
wwd.setModel(new BasicModel());
//Add Layers
}
public void updateTracks(List<satPosition> positions){
LayerList layers = wwd.getModel().getLayers();
//wwd.getModel().getLayers().getLayerByName("Satellite");
for(int i = 0;i<layers.size();i++){
if(layers.get(i).getName().equals("Satellite")){
layers.get(i).dispose();
for(int j = 0;j<positions.size();j++){
PointPlacemark pp = new PointPlacemark(Position.fromDegrees(positions.get(j).getLat(),positions.get(j).getLon() , positions.get(j).getAlt()));
pp.setLabelText(positions.get(j).getName());
pp.setValue(AVKey.DISPLAY_NAME, "Clamp to ground, Label, Semi-transparent, Audio icon");
pp.setLineEnabled(false);
pp.setAltitudeMode(WorldWind.CLAMP_TO_GROUND);
PointPlacemarkAttributes attrs = new PointPlacemarkAttributes();
attrs.setImageAddress("gov/nasa/worldwindx/examples/images/audioicon-64.png");
attrs.setImageColor(new Color(1f, 1f, 1f, 0.6f));
attrs.setScale(0.6);
// attrs.setImageOffset(new Offset(19d, 8d, AVKey.PIXELS, AVKey.PIXELS));
attrs.setLabelOffset(new Offset(0.9d, 0.6d, AVKey.FRACTION, AVKey.FRACTION));
pp.setAttributes(attrs);
((RenderableLayer) layers.get(i)).addRenderable(pp);
}
wwd.getModel().setLayers(layers);
wwd.redraw();
return;
}
for(int j = 0;j<positions.size();j++){
PointPlacemark pp = new PointPlacemark(Position.fromDegrees(positions.get(j).getLat(),positions.get(j).getLon() , positions.get(j).getAlt()));
pp.setLabelText(positions.get(j).getName());
pp.setValue(AVKey.DISPLAY_NAME, "Clamp to ground, Label, Semi-transparent, Audio icon");
pp.setLineEnabled(false);
pp.setAltitudeMode(WorldWind.CLAMP_TO_GROUND);
PointPlacemarkAttributes attrs = new PointPlacemarkAttributes();
attrs.setImageAddress("gov/nasa/worldwindx/examples/images/audioicon-64.png");
attrs.setImageColor(new Color(1f, 1f, 1f, 0.6f));
attrs.setScale(0.6);
// attrs.setImageOffset(new Offset(19d, 8d, AVKey.PIXELS, AVKey.PIXELS));
attrs.setLabelOffset(new Offset(0.9d, 0.6d, AVKey.FRACTION, AVKey.FRACTION));
pp.setAttributes(attrs);
((RenderableLayer) layers.get(i)).addRenderable(pp);
}
wwd.getModel().setLayers(layers);
wwd.redraw();
return;
}
}
public void addTrack(String name, Double lat, Double lon){
RenderableLayer layer = new RenderableLayer();
Iterable<Renderable> iter = layer.getRenderables();
for(Renderable rend : iter){
if(rend instanceof PointPlacemark){
PointPlacemark delp = (PointPlacemark)rend;
if(delp.getLabelText().equals(name)){
delp.setPosition(Position.fromDegrees(lat, lon));
return;
}
}
}
PointPlacemark pp = new PointPlacemark(Position.fromDegrees(lat, lon, 1e4));
pp.setValue(AVKey.DISPLAY_NAME, "Clamp to ground, Audio icon, Heading -45, Globe relative");
pp.setLabelText(name);
pp.setLineEnabled(false);
pp.setAltitudeMode(WorldWind.CLAMP_TO_GROUND);
PointPlacemarkAttributes attrs = new PointPlacemarkAttributes();
attrs.setImageAddress("gov/nasa/worldwindx/examples/images/audioicon-64.png");
attrs.setHeading(-45d);
attrs.setHeadingReference(AVKey.RELATIVE_TO_GLOBE);
attrs.setScale(0.6);
// attrs.setImageOffset(new Offset(0.5, 0.5, AVKey.FRACTION, AVKey.FRACTION));
attrs.setImageOffset(new Offset(19d, 8d, AVKey.PIXELS, AVKey.PIXELS));
attrs.setLabelColor("ffffffff");
attrs.setLabelOffset(new Offset(0.9d, 0.6d, AVKey.FRACTION, AVKey.FRACTION));
pp.setAttributes(attrs);
layer.addRenderable(pp);
// Add the layer to the model.
wwd.getModel().getLayers().add(layer);
// Update layer panel
wwd.redraw();
}
public void addSatellite(List<satPosition> positions){
for(int i = 0; i<positions.size();i++){
addTrack(positions.get(i).getName(),positions.get(i).getLat(),positions.get(i).getLon());
}
}
}
......@@ -27,6 +27,14 @@ public class TrackerList {
return threadList.get(satNum).sat.getPosition();
}
public static List<satPosition> getTracks(){
List<satPosition> positions = new ArrayList<satPosition>();
for(int i =0;i<threadList.size();i++){
positions.add(threadList.get(i).getPos());
}
return positions;
}
private static int searchThread(String sat){
for(int i = 0;i<threadList.size();i++){
if(sat.trim().equals(threadList.get(i).name)){
......
......@@ -8,14 +8,29 @@ public class satPosition{
private final double lon;
private final double alt;
private final Date time;
private final String name;
public satPosition(double lat, double lon, double alt, Date time) {
super();
this.lat = lat;
this.lon = lon;
this.alt = alt;
this.name = "blank";
this.time = time;
}
public satPosition(double lat, double lon, double alt, String name) {
super();
this.lat = lat;
this.lon = lon;
this.alt = alt;
this.name = name;
this.time = new Date();
}
public String getName(){
return name;
}
public double getLat() {
return lat / (Math.PI * 2.0) * 360;
......
......@@ -3,16 +3,20 @@ package satellite;
public class tracker extends Thread{
public tracker(SatelliteTrack satellite){
sat = satellite;
name = satellite.getTLE().getName();
this.sat = satellite;
this.name = satellite.getTLE().getName();
this.image = satellite.getImage();
this.color = satellite.getTrackColor();
}
public String name;
public SatelliteTrack sat;
String image;
String color;
int seconds = 0;
public void run(){
while(true){
while(true){
System.out.println("Tracking " + sat.getTLE().getName() + " for: "+ seconds +" seconds");
System.out.println(sat.getPosition().getLat() + " " + sat.getPosition().getLon());
seconds++;
......@@ -24,4 +28,9 @@ public class tracker extends Thread{
}
}
}
public satPosition getPos(){
satPosition satPos = new satPosition(sat.getPosition().getLat(),sat.getPosition().getLon(),sat.getPosition().getAlt(),sat.getTLE().getName());
return satPos;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment