📄 options.java
字号:
// J2ME Compass
// Copyright (C) 2007 Dana Peters
// http://www.qcontinuum.org/compass
package org.qcontinuum.compass;
import javax.microedition.lcdui.*;
public class Options extends Form implements CommandListener {
private Displayable mParent;
private Preferences mPreferences;
private Command mOkCommand, mCancelCommand;
private ChoiceGroup mFacesChoiceGroup, mTopChoiceGroup, mTimeChoiceGroup;
private ChoiceGroup mDayColourChoiceGroup, mNightColourChoiceGroup;
private final int colors[] = { 0x00ffff, 0x0080ff, 0x00ff00, 0x808080, 0xffffff };
private final String names[] = { "Teal", "Blue", "Green", "Gray", "White" };
public Options(Displayable parent) {
super("Orientation Options");
mParent = parent;
mPreferences = Compass.getPreferences();
append(mFacesChoiceGroup = new ChoiceGroup("Screen Faces", List.EXCLUSIVE));
mFacesChoiceGroup.append("Sky", null);
mFacesChoiceGroup.append("Ground", null);
mFacesChoiceGroup.setSelectedIndex(mPreferences.ScreenDown ? 1 : 0, true);
append(mTopChoiceGroup = new ChoiceGroup("Screen Top Points", List.EXCLUSIVE));
mTopChoiceGroup.append("North", null);
mTopChoiceGroup.append("Sun or Moon", null);
mTopChoiceGroup.append("Destination", null);
mTopChoiceGroup.setSelectedIndex(mPreferences.ScreenTop, true);
append(mTimeChoiceGroup = new ChoiceGroup("Time Format", List.EXCLUSIVE));
mTimeChoiceGroup.append("12 Hour", null);
mTimeChoiceGroup.append("24 Hour", null);
mTimeChoiceGroup.setSelectedIndex(mPreferences.Hour24 ? 1 : 0, true);
append(mDayColourChoiceGroup = new ChoiceGroup("Day Color", List.EXCLUSIVE));
initColourChoices(mDayColourChoiceGroup, mPreferences.DayColour);
append(mNightColourChoiceGroup = new ChoiceGroup("Night Color", List.EXCLUSIVE));
initColourChoices(mNightColourChoiceGroup, mPreferences.NightColour);
addCommand(mCancelCommand = new Command("Cancel", Command.CANCEL, 1));
addCommand(mOkCommand = new Command("OK", Command.OK, 1));
setCommandListener(this) ;
}
private void initColourChoices(ChoiceGroup colourChoiceGroup, int selectedColour) {
int selectedIndex = -1;
for (int i = 0; i < colors.length; i++) {
Image mutableImage = Image.createImage(11,11);
Graphics myGraphics = mutableImage.getGraphics();
myGraphics.fillRect(0, 0, 10, 10);
myGraphics.setColor(colors[i]);
myGraphics.fillRect(1, 1, 8, 8);
Image immutableImage = Image.createImage(mutableImage);
colourChoiceGroup.append(names[i], immutableImage);
if (colors[i] == selectedColour)
selectedIndex = i;
}
if (selectedIndex >= 0)
colourChoiceGroup.setSelectedIndex(selectedIndex, true);
}
public void commandAction(Command c, Displayable d) {
if (c == mOkCommand) {
mPreferences.ScreenDown = mFacesChoiceGroup.getSelectedIndex() == 1;
mPreferences.ScreenTop = (short)mTopChoiceGroup.getSelectedIndex();
mPreferences.Hour24 = mTimeChoiceGroup.getSelectedIndex() == 1;
mPreferences.DayColour = colors[mDayColourChoiceGroup.getSelectedIndex()];
mPreferences.NightColour = colors[mNightColourChoiceGroup.getSelectedIndex()];
mPreferences.save();
Compass.display(mParent);
} else if (c == mCancelCommand) {
Compass.display(mParent);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -