2 Copyright (C) 2001, 2006 United States Government
3 as represented by the Administrator of the
4 National Aeronautics and Space Administration.
9 import gov
.nasa
.worldwind
.*;
10 import gov
.nasa
.worldwind
.geom
.*;
13 import java
.awt
.event
.*;
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("");
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
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())
59 alpha
= alpha
< 16 ?
16 : Math
.min(255, alpha
+ 20);
63 alpha
= Math
.max(0, alpha
- 20);
65 heartBeat
.setForeground(new java
.awt
.Color(255, 0, 0, alpha
));
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();
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
);
108 latDisplay
.setText("");
109 lonDisplay
.setText("Off globe");
110 eleDisplay
.setText("");