import javax.swing.SwingConstants;
import tim.prune.App;
-import tim.prune.Config;
import tim.prune.ExternalTools;
import tim.prune.GenericFunction;
import tim.prune.I18nManager;
+import tim.prune.config.Config;
import tim.prune.data.Altitude;
import tim.prune.data.DataPoint;
import tim.prune.data.Distance;
*/
public void begin()
{
+ // First check if gnuplot is available
+ if (!ExternalTools.isToolInstalled(ExternalTools.TOOL_GNUPLOT))
+ {
+ _app.showErrorMessage(getNameKey(), "dialog.charts.gnuplotnotfound");
+ return;
+ }
// Make dialog window
if (_dialog == null)
{
// button panel on bottom
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
- // Gnuplot button
- JButton gnuplotButton = new JButton(I18nManager.getText("button.gnuplotpath"));
- gnuplotButton.addActionListener(new ActionListener() {
+ // ok button
+ JButton okButton = new JButton(I18nManager.getText("button.ok"));
+ okButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
- setGnuplotPath();
+ showChart(_app.getTrackInfo().getTrack());
+ _dialog.setVisible(false);
}
});
- buttonPanel.add(gnuplotButton);
+ buttonPanel.add(okButton);
// Cancel button
JButton cancelButton = new JButton(I18nManager.getText("button.cancel"));
cancelButton.addActionListener(new ActionListener() {
}
});
buttonPanel.add(cancelButton);
- // ok button
- JButton okButton = new JButton(I18nManager.getText("button.ok"));
- okButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- showChart(_app.getTrackInfo().getTrack());
- _dialog.setVisible(false);
- }
- });
- buttonPanel.add(okButton);
dialogPanel.add(buttonPanel, BorderLayout.SOUTH);
return dialogPanel;
}
OutputStreamWriter writer = null;
try
{
- Process process = Runtime.getRuntime().exec(Config.getGnuplotPath() + " -persist");
+ final String gnuplotPath = Config.getConfigString(Config.KEY_GNUPLOT_PATH);
+ Process process = Runtime.getRuntime().exec(gnuplotPath + " -persist");
writer = new OutputStreamWriter(process.getOutputStream());
if (showSvg)
{
*/
private static String getUnitsLabel(String inMetric, String inImperial)
{
- String key = Config.getUseMetricUnits()?inMetric:inImperial;
+ String key = Config.getConfigBoolean(Config.KEY_METRIC_UNITS)?inMetric:inImperial;
return I18nManager.getText(key);
}
{
totalRads += DataPoint.calculateRadiansBetween(prevPoint, currPoint);
}
- if (Config.getUseMetricUnits()) {
+ if (Config.getConfigBoolean(Config.KEY_METRIC_UNITS)) {
values.setData(i, Distance.convertRadiansToDistance(totalRads, Units.KILOMETRES));
} else {
values.setData(i, Distance.convertRadiansToDistance(totalRads, Units.MILES));
private static ChartSeries getAltitudeValues(Track inTrack)
{
ChartSeries values = new ChartSeries(inTrack.getNumPoints());
- Altitude.Format altFormat = Config.getUseMetricUnits()?Altitude.Format.METRES:Altitude.Format.FEET;
+ Altitude.Format altFormat = Config.getConfigBoolean(Config.KEY_METRIC_UNITS)?Altitude.Format.METRES:Altitude.Format.FEET;
for (int i=0; i<inTrack.getNumPoints(); i++) {
if (inTrack.getPoint(i).hasAltitude()) {
values.setData(i, inTrack.getPoint(i).getAltitude().getValue(altFormat));
ChartSeries values = new ChartSeries(inTrack.getNumPoints());
DataPoint prevPoint = null, currPoint = null, nextPoint = null;
DataPoint[] points = getDataPoints(inTrack, false);
+ final boolean useMetric = Config.getConfigBoolean(Config.KEY_METRIC_UNITS);
// Loop over collected points
for (int i=1; i<(points.length-1); i++)
{
+ DataPoint.calculateRadiansBetween(currPoint, nextPoint);
double time = nextPoint.getTimestamp().getSecondsSince(prevPoint.getTimestamp()) / 60.0 / 60.0;
// Convert to distance and pass to chartseries
- if (Config.getUseMetricUnits()) {
+ if (useMetric) {
values.setData(i, Distance.convertRadiansToDistance(rads, Units.KILOMETRES) / time);
} else {
values.setData(i, Distance.convertRadiansToDistance(rads, Units.MILES) / time);
{
// Calculate speeds and fill in in values array
ChartSeries values = new ChartSeries(inTrack.getNumPoints());
- Altitude.Format altFormat = Config.getUseMetricUnits()?Altitude.Format.METRES:Altitude.Format.FEET;
+ Altitude.Format altFormat = Config.getConfigBoolean(Config.KEY_METRIC_UNITS)?Altitude.Format.METRES:Altitude.Format.FEET;
DataPoint prevPoint = null, currPoint = null, nextPoint = null;
DataPoint[] points = getDataPoints(inTrack, true); // require that points have altitudes too
// Loop over collected points
/**
* Select a file to write for the SVG output
- * @return
+ * @return selected File object or null if cancelled
*/
private File selectSvgFile()
{
_fileChooser.setFileFilter(new GenericFileFilter("filetype.svg", new String[] {"svg"}));
_fileChooser.setAcceptAllFileFilterUsed(false);
// start from directory in config which should be set
- File configDir = Config.getWorkingDirectory();
- if (configDir != null) {_fileChooser.setCurrentDirectory(configDir);}
+ String configDir = Config.getConfigString(Config.KEY_TRACK_DIR);
+ if (configDir != null) {_fileChooser.setCurrentDirectory(new File(configDir));}
}
boolean chooseAgain = true;
while (chooseAgain)
{
return file;
}
- else {
- chooseAgain = true;
- }
+ chooseAgain = true;
}
}
// Cancel pressed so no file selected
if (inNumCharts == 3) {return new int[] {40, 60, 20, 20, 0, 20};}
return new int[] {54, 46, 36, 18, 18, 18, 0, 18};
}
-
- /**
- * Prompt the user to set/edit the path to gnuplot
- */
- private void setGnuplotPath()
- {
- String currPath = Config.getGnuplotPath();
- Object path = JOptionPane.showInputDialog(_dialog,
- I18nManager.getText("dialog.charts.gnuplotpath"),
- I18nManager.getText(getNameKey()),
- JOptionPane.QUESTION_MESSAGE, null, null, "" + currPath);
- if (path != null)
- {
- String pathString = path.toString().trim();
- if (!pathString.equals("") && !pathString.equals(currPath)) {
- Config.setGnuplotPath(pathString);
- // warn if gnuplot still not found
- if (!ExternalTools.isGnuplotInstalled()) {
- _app.showErrorMessage(getNameKey(), "dialog.charts.gnuplotnotfound");
- }
- }
- }
- }
}