📄 optionstrack.java
字号:
// J2ME GPS Track
// Copyright (C) 2006 Dana Peters
// http://www.qcontinuum.org/gpstrack
package org.qcontinuum.gpstrack;
import javax.microedition.lcdui.*;
public class OptionsTrack extends Form implements CommandListener {
private Displayable mParent;
private Command mCancelCommand, mOkCommand;
private ChoiceGroup mDistanceChoiceGroup, mTimeChoiceGroup;
private static final String mDistanceMetricStrings[] = {
"No Minimum",
"10 m",
"20 m",
"50 m",
"100 m",
"200 m",
"500 m",
"1 km"
};
private static final int mDistanceMetricValues[] = { 0, 10, 20, 50, 100, 200, 500, 1000 };
private static final String mDistanceUSStrings[] = {
"No Minimum",
"30 feet",
"100 feet",
"200 feet",
"500 feet",
"1000 feet",
"0.25 mile",
"0.5 mile"
};
private static final int mDistanceUSValues[] = { 0, 9, 30, 61, 152, 305, 402, 805 };
private static final String mTimeStrings[] = {
"2 sec",
"10 sec",
"20 sec",
"30 sec",
"1 min",
"2 min"
};
private static final int mTimeValues[] = { 2, 10, 20, 30, 60, 120 };
public OptionsTrack(Displayable parent) {
super("Track Options");
mParent = parent;
Preferences preferences = GpsTrack.getPreferences();
int minDistance = preferences.getMinDistance();
switch (preferences.getUnitType()) {
case Preferences.UNITTYPE_METRIC:
mDistanceChoiceGroup = new ChoiceGroup("Minimum Distance", List.EXCLUSIVE, mDistanceMetricStrings, null);
mDistanceChoiceGroup.setSelectedIndex(findClosestValue(mDistanceMetricValues, minDistance), true);
break;
case Preferences.UNITTYPE_US:
mDistanceChoiceGroup = new ChoiceGroup("Minimum Distance", List.EXCLUSIVE, mDistanceUSStrings, null);
mDistanceChoiceGroup.setSelectedIndex(findClosestValue(mDistanceUSValues, minDistance), true);
break;
}
int minTime = preferences.getMinTime();
mTimeChoiceGroup = new ChoiceGroup("Minimum Time", List.EXCLUSIVE, mTimeStrings, null);
mTimeChoiceGroup.setSelectedIndex(findClosestValue(mTimeValues, minTime), true);
mCancelCommand = new Command("Cancel", Command.EXIT, 1);
mOkCommand = new Command("OK", Command.OK, 1);
append(mDistanceChoiceGroup);
append(mTimeChoiceGroup);
addCommand(mCancelCommand);
addCommand(mOkCommand);
setCommandListener(this);
}
public void commandAction(Command c, Displayable d) {
if (c == mOkCommand) {
Preferences preferences = GpsTrack.getPreferences();
switch (preferences.getUnitType()) {
case Preferences.UNITTYPE_METRIC:
preferences.setMinDistance(mDistanceMetricValues[mDistanceChoiceGroup.getSelectedIndex()]);
break;
case Preferences.UNITTYPE_US:
preferences.setMinDistance(mDistanceUSValues[mDistanceChoiceGroup.getSelectedIndex()]);
break;
}
preferences.setMinTime(mTimeValues[mTimeChoiceGroup.getSelectedIndex()]);
preferences.save();
GpsTrack.display(mParent);
} else if (c == mCancelCommand) {
GpsTrack.display(mParent);
}
}
private int findClosestValue(int [] values, int value) {
int index, minIndex = -1, minDelta = -1;
for (index = 0; index < values.length; index++) {
int delta = Math.abs(values[index] - value);
if (minDelta > delta || minDelta < 0) {
minIndex = index;
minDelta = delta;
}
}
return minIndex;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -