Worldwind public release 0.2
[worldwind-tracker.git] / worldwinddemo / StatusBar.java
blob1d90dc33a56a6c376c6f08f42e40c52db2c1ec01
1 /*
2 Copyright (C) 2001, 2006 United States Government
3 as represented by the Administrator of the
4 National Aeronautics and Space Administration.
5 All Rights Reserved.
6 */
7 package worldwinddemo;
9 import gov.nasa.worldwind.*;
10 import gov.nasa.worldwind.geom.*;
12 import javax.swing.*;
13 import java.awt.event.*;
15 /**
16 * @author tag
17 * @version $Id: StatusBar.java 1764 2007-05-07 20:01:57Z tgaskins $
19 public class StatusBar extends JPanel implements PositionListener
21 private WorldWindow eventSource;
22 private final JLabel latDisplay = new JLabel("");
23 private final JLabel lonDisplay = new JLabel("Off globe");
24 private final JLabel eleDisplay = new JLabel("");
26 public StatusBar()
28 super(new java.awt.GridLayout(1, 0));
30 final JLabel heartBeat = new JLabel("Downloading");
32 latDisplay.setHorizontalAlignment(SwingConstants.CENTER);
33 lonDisplay.setHorizontalAlignment(SwingConstants.CENTER);
34 eleDisplay.setHorizontalAlignment(SwingConstants.CENTER);
36 this.add(new JLabel("")); // dummy label to visually balance with heartbeat
37 this.add(latDisplay);
38 this.add(lonDisplay);
39 this.add(eleDisplay);
40 this.add(heartBeat);
42 heartBeat.setHorizontalAlignment(SwingConstants.CENTER);
43 heartBeat.setForeground(new java.awt.Color(255, 0, 0, 0));
45 Timer downloadTimer = new Timer(50, new ActionListener()
47 public void actionPerformed(java.awt.event.ActionEvent actionEvent)
50 java.awt.Color color = heartBeat.getForeground();
52 int alpha = color.getAlpha();
54 if (WorldWind.retrievalService().hasActiveTasks())
56 if (alpha == 255)
57 alpha = 255;
58 else
59 alpha = alpha < 16 ? 16 : Math.min(255, alpha + 20);
61 else
63 alpha = Math.max(0, alpha - 20);
65 heartBeat.setForeground(new java.awt.Color(255, 0, 0, alpha));
67 });
68 downloadTimer.start();
71 public void setEventSource(WorldWindow newEventSource)
73 if (this.eventSource != null)
74 this.eventSource.removePositionListener(this);
76 if (newEventSource != null)
77 newEventSource.addPositionListener(this);
79 this.eventSource = newEventSource;
82 public void moved(PositionEvent event)
84 this.handleCursorPositionChange(event);
87 public WorldWindow getEventSource()
89 return this.eventSource;
92 private void handleCursorPositionChange(PositionEvent event)
94 Position newPos = (Position) event.getPosition();
95 if (newPos != null)
97 String las = String.format("Latitude %7.3f\u00B0",
98 newPos.getLatitude().getDegrees());
99 String los = String.format("Longitude %7.3f\u00B0",
100 newPos.getLongitude().getDegrees());
101 String els = String.format("Elevation %7d meters", (int) newPos.getElevation());
102 latDisplay.setText(las);
103 lonDisplay.setText(los);
104 eleDisplay.setText(els);
106 else
108 latDisplay.setText("");
109 lonDisplay.setText("Off globe");
110 eleDisplay.setText("");