📄 settingsscreen.java
字号:
// Copyright 2003 Nokia Corporation.
//
// THIS SOURCE CODE IS PROVIDED 'AS IS', WITH NO WARRANTIES WHATSOEVER,
// EXPRESS OR IMPLIED, INCLUDING ANY WARRANTY OF MERCHANTABILITY, FITNESS
// FOR ANY PARTICULAR PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE
// OR TRADE PRACTICE, RELATING TO THE SOURCE CODE OR ANY WARRANTY OTHERWISE
// ARISING OUT OF ANY PROPOSAL, SPECIFICATION, OR SAMPLE AND WITH NO
// OBLIGATION OF NOKIA TO PROVIDE THE LICENSEE WITH ANY MAINTENANCE OR
// SUPPORT. FURTHERMORE, NOKIA MAKES NO WARRANTY THAT EXERCISE OF THE
// RIGHTS GRANTED HEREUNDER DOES NOT INFRINGE OR MAY NOT CAUSE INFRINGEMENT
// OF ANY PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OWNED OR CONTROLLED
// BY THIRD PARTIES
//
// Furthermore, information provided in this source code is preliminary,
// and may be changed substantially prior to final release. Nokia Corporation
// retains the right to make changes to this source code at
// any time, without notice. This source code is provided for informational
// purposes only.
//
// Nokia and Nokia Connecting People are registered trademarks of Nokia
// Corporation.
// Java and all Java-based marks are trademarks or registered trademarks of
// Sun Microsystems, Inc.
// Other product and company names mentioned herein may be trademarks or
// trade names of their respective owners.
//
// A non-exclusive, non-transferable, worldwide, limited license is hereby
// granted to the Licensee to download, print, reproduce and modify the
// source code. The licensee has the right to market, sell, distribute and
// make available the source code in original or modified form only when
// incorporated into the programs developed by the Licensee. No other
// license, express or implied, by estoppel or otherwise, to any other
// intellectual property rights is granted herein.
import javax.microedition.lcdui.*;
class SettingsScreen
extends Form
implements CommandListener, ItemStateListener
{
private static final int DE = 0;
private static final int EN = 1;
private static final int ES = 2;
private static final int FR = 3;
private static final int IT = 4;
private static final int PT = 5;
private static final String[] inputLocaleStrings = { "de",
"en",
"es",
"fr",
"it",
"pt" };
private static final String[][] outputLocaleArray =
{
{"en", "fr"} , // row DE: "de" to ...
{"de", "es", "fr", "it", "pt" } , // row EN: "en" to ...
{"en"} , // row ES: "es" to ...
{"de", "en"}, // row FR: "fr" to ...
{"en"} , // row IT: "it" to ...
{"en"} // row PT: "pt" to ...
};
// The default translation setting is from "en" to "fr"
static final String DEFAULT_INPUT_LOCALE = "en";
static final String DEFAULT_OUTPUT_LOCALE =
outputLocaleArray[EN][2]; // "fr"
private final Command cancelCommand;
private final Command applyCommand;
private final TranslatorMIDlet midlet;
private ChoiceGroup inputLocaleChoiceGroup;
private ChoiceGroup outputLocaleChoiceGroup;
private int row = EN;
private int column = 2; // "fr" (see DEFAULT_OUTPUT_LOCALE above)
SettingsScreen(TranslatorMIDlet midlet)
{
// (this.titleString() can't be referenced
// until after super() is called)
super(null);
setTitle(titleString());
this.midlet = midlet;
// Add the input locale setting choices
inputLocaleChoiceGroup = new ChoiceGroup("Input locale",
ChoiceGroup.EXCLUSIVE,
inputLocaleStrings,
null);
inputLocaleChoiceGroup.setSelectedIndex(row, true);
append(inputLocaleChoiceGroup);
// Add the output locale setting choices
// (based on input locale selected)
outputLocaleChoiceGroup = makeOutputLocaleChoiceGroup(
outputLocaleArray[row],
0);
outputLocaleChoiceGroup.setSelectedIndex(column, true);
append(outputLocaleChoiceGroup);
setItemStateListener(this);
// Add the screen commands
cancelCommand = new Command("Cancel", Command.BACK, 1);
addCommand(cancelCommand);
applyCommand = new Command("Use settings", Command.SCREEN, 1);
addCommand(applyCommand);
setCommandListener(this);
}
private String titleString()
{
return ("Settings: " + inputLocaleStrings[row] +
" to " +
outputLocaleArray[row][column]);
}
private ChoiceGroup makeOutputLocaleChoiceGroup(String[] strings,
int selectedIndex)
{
ChoiceGroup cg = new ChoiceGroup("Output locale",
ChoiceGroup.EXCLUSIVE,
strings,
null);
cg.setSelectedIndex(selectedIndex, true);
return cg;
}
public void itemStateChanged(Item item)
{
row = inputLocaleChoiceGroup.getSelectedIndex();
if (item == inputLocaleChoiceGroup)
{
// replace old output locale choices
delete(1);
outputLocaleChoiceGroup = makeOutputLocaleChoiceGroup(
outputLocaleArray[row],
0);
append(outputLocaleChoiceGroup);
column = 0;
}
else
{
column = outputLocaleChoiceGroup.getSelectedIndex();
}
setTitle(titleString());
}
public void commandAction(Command command, Displayable d)
{
if (command == cancelCommand)
{
midlet.settingsScreenBack();
}
else
{
// applyCommand: 'Use settings'
String inputLocale = inputLocaleStrings[row];
String outputLocale =
outputLocaleArray[row][column];
midlet.settingsScreenSave(inputLocale, outputLocale);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -