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 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367
|
package tim.prune.function;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import tim.prune.App;
import tim.prune.GenericFunction;
import tim.prune.I18nManager;
import tim.prune.config.Config;
import tim.prune.data.RangeStats;
import tim.prune.data.Selection;
import tim.prune.data.Unit;
import tim.prune.gui.DisplayUtils;
import tim.prune.gui.profile.SpeedData;
/**
* Class to show the full range details in a separate popup
*/
public class FullRangeDetails extends GenericFunction
{
/** Dialog */
private JDialog _dialog = null;
/** Label for number of points */
private JLabel _numPointsLabel = null;
/** Label for number of segments */
private JLabel _numSegsLabel = null;
/** Label for the maximum speed */
private JLabel _maxSpeedLabel = null;
/** Label for heading of "total" column */
private JLabel _colTotalLabel = null;
/** Label for heading of "segments" column */
private JLabel _colSegmentsLabel = null;
/** Labels for distances */
private JLabel _totalDistanceLabel = null, _movingDistanceLabel = null;
/** Labels for durations */
private JLabel _totalDurationLabel = null, _movingDurationLabel = null;
/** Labels for climbs */
private JLabel _totalClimbLabel = null, _movingClimbLabel = null;
/** Labels for descents */
private JLabel _totalDescentLabel = null, _movingDescentLabel = null;
/** Labels for pace */
private JLabel _totalPaceLabel = null, _movingPaceLabel = null;
/** Labels for gradient */
private JLabel _totalGradientLabel = null, _movingGradientLabel = null;
/** Labels for speed */
private JLabel _totalSpeedLabel, _movingSpeedLabel = null;
/** Labels for vertical speed */
private JLabel _totalVertSpeedLabel, _movingVertSpeedLabel = null;
/**
* Constructor
* @param inApp App object
*/
public FullRangeDetails(App inApp)
{
super(inApp);
}
/** Get the name key */
public String getNameKey() {
return "function.fullrangedetails";
}
/**
* Begin the function
*/
public void begin()
{
if (_dialog == null)
{
_dialog = new JDialog(_parentFrame, I18nManager.getText(getNameKey()), true);
_dialog.setLocationRelativeTo(_parentFrame);
_dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
_dialog.getContentPane().add(makeDialogComponents());
_dialog.pack();
}
updateDetails();
_dialog.setVisible(true);
}
/**
* Create dialog components
* @return Panel containing all gui elements in dialog
*/
private Component makeDialogComponents()
{
JPanel dialogPanel = new JPanel();
dialogPanel.setLayout(new BorderLayout(5, 5));
// Label at top
JLabel topLabel = new JLabel(I18nManager.getText("dialog.fullrangedetails.intro") + ":");
topLabel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
dialogPanel.add(topLabel, BorderLayout.NORTH);
// Details panel in middle
JPanel midPanel = new JPanel();
midPanel.setLayout(new GridLayout(0, 3, 6, 2));
midPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 15));
// Number of points
JLabel pointsLabel = new JLabel(I18nManager.getText("details.track.points") + ": ");
pointsLabel.setHorizontalAlignment(JLabel.RIGHT);
midPanel.add(pointsLabel);
_numPointsLabel = new JLabel("100");
midPanel.add(_numPointsLabel);
midPanel.add(new JLabel(" "));
// Number of segments
JLabel segLabel = new JLabel(I18nManager.getText("details.range.numsegments") + ": ");
segLabel.setHorizontalAlignment(JLabel.RIGHT);
midPanel.add(segLabel);
_numSegsLabel = new JLabel("100");
midPanel.add(_numSegsLabel);
midPanel.add(new JLabel(" "));
// Maximum speed
JLabel maxSpeedLabel = new JLabel(I18nManager.getText("details.range.maxspeed") + ": ");
maxSpeedLabel.setHorizontalAlignment(JLabel.RIGHT);
midPanel.add(maxSpeedLabel);
_maxSpeedLabel = new JLabel("10 km/h");
midPanel.add(_maxSpeedLabel);
midPanel.add(new JLabel(" "));
// blank row
for (int i=0; i<3; i++) midPanel.add(new JLabel(" "));
// Row for column headings
midPanel.add(new JLabel(" "));
_colTotalLabel = new JLabel(I18nManager.getText("dialog.fullrangedetails.coltotal"));
midPanel.add(_colTotalLabel);
_colSegmentsLabel = new JLabel(I18nManager.getText("dialog.fullrangedetails.colsegments"));
midPanel.add(_colSegmentsLabel);
// Distance
JLabel distLabel = new JLabel(I18nManager.getText("fieldname.distance") + ": ");
distLabel.setHorizontalAlignment(JLabel.RIGHT);
midPanel.add(distLabel);
_totalDistanceLabel = new JLabel("5 km");
midPanel.add(_totalDistanceLabel);
_movingDistanceLabel = new JLabel("5 km");
midPanel.add(_movingDistanceLabel);
// Duration
JLabel durationLabel = new JLabel(I18nManager.getText("fieldname.duration") + ": ");
durationLabel.setHorizontalAlignment(JLabel.RIGHT);
midPanel.add(durationLabel);
_totalDurationLabel = new JLabel("15 min");
midPanel.add(_totalDurationLabel);
_movingDurationLabel = new JLabel("15 min");
midPanel.add(_movingDurationLabel);
// Speed
JLabel speedLabel = new JLabel(I18nManager.getText("details.range.avespeed") + ": ");
speedLabel.setHorizontalAlignment(JLabel.RIGHT);
midPanel.add(speedLabel);
_totalSpeedLabel = new JLabel("5.5 km/h");
midPanel.add(_totalSpeedLabel);
_movingSpeedLabel = new JLabel("5.5 km/h");
midPanel.add(_movingSpeedLabel);
// Pace
JLabel paceLabel = new JLabel(I18nManager.getText("details.range.pace") + ": ");
paceLabel.setHorizontalAlignment(JLabel.RIGHT);
midPanel.add(paceLabel);
_totalPaceLabel = new JLabel("8 min/km");
midPanel.add(_totalPaceLabel);
_movingPaceLabel = new JLabel("8 min/km");
midPanel.add(_movingPaceLabel);
// Climb
JLabel climbLabel = new JLabel(I18nManager.getText("details.range.climb") + ": ");
climbLabel.setHorizontalAlignment(JLabel.RIGHT);
midPanel.add(climbLabel);
_totalClimbLabel = new JLabel("1000 m");
midPanel.add(_totalClimbLabel);
_movingClimbLabel = new JLabel("1000 m");
midPanel.add(_movingClimbLabel);
// Descent
JLabel descentLabel = new JLabel(I18nManager.getText("details.range.descent") + ": ");
descentLabel.setHorizontalAlignment(JLabel.RIGHT);
midPanel.add(descentLabel);
_totalDescentLabel = new JLabel("1000 m");
midPanel.add(_totalDescentLabel);
_movingDescentLabel = new JLabel("1000 m");
midPanel.add(_movingDescentLabel);
// Gradient
JLabel gradientLabel = new JLabel(I18nManager.getText("details.range.gradient") + ": ");
gradientLabel.setHorizontalAlignment(JLabel.RIGHT);
midPanel.add(gradientLabel);
_totalGradientLabel = new JLabel("10 %");
midPanel.add(_totalGradientLabel);
_movingGradientLabel = new JLabel("10 %");
midPanel.add(_movingGradientLabel);
// Vertical speed
JLabel vSpeedLabel = new JLabel(I18nManager.getText("fieldname.verticalspeed") + ": ");
vSpeedLabel.setHorizontalAlignment(JLabel.RIGHT);
midPanel.add(vSpeedLabel);
_totalVertSpeedLabel = new JLabel("1 m/s");
midPanel.add(_totalVertSpeedLabel);
_movingVertSpeedLabel = new JLabel("1 m/s");
midPanel.add(_movingVertSpeedLabel);
dialogPanel.add(midPanel, BorderLayout.CENTER);
// button panel at bottom
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
JButton closeButton = new JButton(I18nManager.getText("button.close"));
closeButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
_dialog.dispose();
}
});
closeButton.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent inE) {
if (inE.getKeyCode() == KeyEvent.VK_ESCAPE) {_dialog.dispose();}
super.keyPressed(inE);
}
});
buttonPanel.add(closeButton);
dialogPanel.add(buttonPanel, BorderLayout.SOUTH);
return dialogPanel;
}
/**
* Update the labels with the current details
*/
private void updateDetails()
{
Selection selection = _app.getTrackInfo().getSelection();
// Do the calculations with a separate class
RangeStats stats = new RangeStats(_app.getTrackInfo().getTrack(), selection.getStart(), selection.getEnd());
// Number of points
_numPointsLabel.setText("" + stats.getNumPoints());
// Number of segments
_numSegsLabel.setText("" + stats.getNumSegments());
final boolean isMultiSegments = (stats.getNumSegments() > 1);
// Set visibility of third column accordingly
_movingDistanceLabel.setVisible(isMultiSegments);
_movingDurationLabel.setVisible(isMultiSegments || stats.getTimestampsOutOfSequence());
// FIXME: What to show if timestamps are out of sequence? Warning message?
_movingClimbLabel.setVisible(isMultiSegments);
_movingDescentLabel.setVisible(isMultiSegments);
_movingSpeedLabel.setVisible(isMultiSegments);
_movingPaceLabel.setVisible(isMultiSegments);
_movingGradientLabel.setVisible(isMultiSegments);
_movingVertSpeedLabel.setVisible(isMultiSegments);
// Total and moving distance in current units
final Unit distUnit = Config.getUnitSet().getDistanceUnit();
final String distUnitsStr = I18nManager.getText(distUnit.getShortnameKey());
_totalDistanceLabel.setText(DisplayUtils.roundedNumber(stats.getTotalDistance()) + " " + distUnitsStr);
_movingDistanceLabel.setText(DisplayUtils.roundedNumber(stats.getMovingDistance()) + " " + distUnitsStr);
// Duration
_totalDurationLabel.setText(DisplayUtils.buildDurationString(stats.getTotalDurationInSeconds()));
_movingDurationLabel.setText(DisplayUtils.buildDurationString(stats.getMovingDurationInSeconds()));
// Climb and descent
final Unit altUnit = Config.getUnitSet().getAltitudeUnit();
final String altUnitsStr = " " + I18nManager.getText(altUnit.getShortnameKey());
if (stats.getTotalAltitudeRange().hasRange()) {
_totalClimbLabel.setText(stats.getTotalAltitudeRange().getClimb(altUnit) + altUnitsStr);
_totalDescentLabel.setText(stats.getTotalAltitudeRange().getDescent(altUnit) + altUnitsStr);
}
else {
_totalClimbLabel.setText("");
_totalDescentLabel.setText("");
}
if (stats.getMovingAltitudeRange().hasRange()) {
_movingClimbLabel.setText(stats.getMovingAltitudeRange().getClimb(altUnit) + altUnitsStr);
_movingDescentLabel.setText(stats.getMovingAltitudeRange().getDescent(altUnit) + altUnitsStr);
}
else {
_movingClimbLabel.setText("");
_movingDescentLabel.setText("");
}
// Overall pace and speed
final String speedUnitsStr = I18nManager.getText(Config.getUnitSet().getSpeedUnit().getShortnameKey());
long numSecs = stats.getTotalDurationInSeconds();
double dist = stats.getTotalDistance();
if (numSecs > 0 && dist > 0)
{
_totalSpeedLabel.setText(DisplayUtils.roundedNumber(dist/numSecs*3600.0) + " " + speedUnitsStr);
_totalPaceLabel.setText(DisplayUtils.buildDurationString((long) (numSecs/dist))
+ " / " + distUnitsStr);
}
else {
_totalSpeedLabel.setText("");
_totalPaceLabel.setText("");
}
// and same for within the segments
numSecs = stats.getMovingDurationInSeconds();
dist = stats.getMovingDistance();
if (numSecs > 0 && dist > 0)
{
_movingSpeedLabel.setText(DisplayUtils.roundedNumber(dist/numSecs*3600.0) + " " + speedUnitsStr);
_movingPaceLabel.setText(DisplayUtils.buildDurationString((long) (numSecs/dist))
+ " / " + distUnitsStr);
}
else {
_movingSpeedLabel.setText("");
_movingPaceLabel.setText("");
}
// Gradient
if (stats.getTotalAltitudeRange().hasRange()) {
_totalGradientLabel.setText(DisplayUtils.formatOneDp(stats.getTotalGradient()) + " %");
}
else {
_totalGradientLabel.setText("");
}
if (stats.getMovingAltitudeRange().hasRange()) {
_movingGradientLabel.setText(DisplayUtils.formatOneDp(stats.getMovingGradient()) + " %");
}
else {
_movingGradientLabel.setText("");
}
// Maximum speed
SpeedData speeds = new SpeedData(_app.getTrackInfo().getTrack());
speeds.init(Config.getUnitSet());
double maxSpeed = 0.0;
for (int i=selection.getStart(); i<=selection.getEnd(); i++)
{
if (speeds.hasData(i) && (speeds.getData(i) > maxSpeed)) {
maxSpeed = speeds.getData(i);
}
}
if (maxSpeed > 0.0) {
_maxSpeedLabel.setText(DisplayUtils.roundedNumber(maxSpeed) + " " + speedUnitsStr);
}
else {
_maxSpeedLabel.setText("");
}
// vertical speed
final String vertSpeedUnitsStr = I18nManager.getText(Config.getUnitSet().getVerticalSpeedUnit().getShortnameKey());
if (stats.getMovingAltitudeRange().hasRange() && stats.getTotalDurationInSeconds() > 0)
{
// got an altitude and time - do totals
_totalVertSpeedLabel.setText(DisplayUtils.roundedNumber(stats.getTotalVerticalSpeed()) + " " + vertSpeedUnitsStr);
_movingVertSpeedLabel.setText(DisplayUtils.roundedNumber(stats.getMovingVerticalSpeed()) + " " + vertSpeedUnitsStr);
}
else
{
// no vertical speed available
_totalVertSpeedLabel.setText("");
_movingVertSpeedLabel.setText("");
}
}
}
|