📄 mainscreen.java
字号:
/* * JRemCntl - Copyright (C) 2007 Filippo Di Vattimo <fildiv@gmail.com> * See COPYING */package fildiv.jremcntl.client.ui;import javax.microedition.lcdui.AlertType;import javax.microedition.lcdui.Command;import javax.microedition.lcdui.CommandListener;import javax.microedition.lcdui.Display;import javax.microedition.lcdui.Displayable;import fildiv.jremcntl.client.Main;import fildiv.jremcntl.client.core.AppContext;import fildiv.jremcntl.client.core.JRemForm;import fildiv.jremcntl.client.util.UIUtils;import fildiv.jremcntl.common.core.Logger;public class MainScreen extends AbstractScreen implements CommandListener { private static String INITIAL_MESSAGE = "JRemote control"; private final static Command CMD_EXIT = new Command("Exit", Command.EXIT, 1); private final static Command CMD_SCAN = new Command("Scan", Command.SCREEN, 2); private final static Command CMD_RECONNECT = new Command("Reconnect", Command.SCREEN, 2); private final static Command CMD_SAVE_PREFS = new Command("Save prefs", Command.SCREEN, 2); private static final Command CMD_SHOW_LOG = new Command("Logs", Command.SCREEN, 10); private static final Command CMD_HELP = new Command("Help", Command.SCREEN, 11); private static final Command CMD_ABOUT = new Command("About", Command.SCREEN, 11); private ConnectionScreen connScreen; private ControlPanelScreen cpScreen; private JRemForm mainForm; private HelpScreen helpScreen; private AboutScreen aboutScreen; private Main midlet; public MainScreen(AppContext appCtx, Main midlet) { super(appCtx, null); this.midlet = midlet; connScreen = new ConnectionScreen(appCtx, this); cpScreen = new ControlPanelScreen(appCtx, this); aboutScreen = new AboutScreen(appCtx, this); helpScreen = new HelpScreen(appCtx, this); mainForm = new JRemForm("JRem Control"); resetMainForm(); } protected void resetMainForm() { clean(); mainForm.addCommand(CMD_EXIT); mainForm.addCommand(CMD_ABOUT); mainForm.addCommand(CMD_HELP); if (!getAppCtx().getConnector().isBluetoothUp()) { logln("Bluetooth is not active."); UIUtils.appendText(mainForm, "\nBluetooth is not active, " + "please enable it and try again."); } else { String lastDeviceAddr = getAppCtx().getLastURL(); if (lastDeviceAddr != null) mainForm.addCommand(CMD_RECONNECT); mainForm.addCommand(CMD_SAVE_PREFS); mainForm.addCommand(CMD_SCAN); mainForm.addCommand(CMD_SHOW_LOG); } } private void clean() { String vers = getAppCtx().getVersion(); mainForm.deleteAll(); mainForm.setCommandListener(this); UIUtils.appendText(mainForm, "\n"); UIUtils.appendText(mainForm, INITIAL_MESSAGE); UIUtils.appendText(mainForm, "\nVers. " + vers); } public void setLogger(Logger logger) { super.setLogger(logger); connScreen.setLogger(logger); cpScreen.setLogger(logger); } public void commandAction(Command c, Displayable d) { if (c == CMD_EXIT) notifyExit(); else if (c == CMD_SCAN) scan(); else if (c == CMD_SHOW_LOG) showLogs(); else if (c == CMD_RECONNECT) reconnect(); else if (c == CMD_SAVE_PREFS) savePrefs(); else if (c == CMD_ABOUT) showAbout(); else if (c == CMD_HELP) showHelp(); } private void showHelp() { helpScreen.show(); } private void showAbout() { aboutScreen.show(); } private void savePrefs() { getAppCtx().savePrefs(); UIUtils.showAlert(getDisplay(), mainForm, "Prefs saved.", AlertType.INFO); } private void reconnect() { String url = getAppCtx().getLastURL(); if (url == null) scan(); else connScreen.showAndConnect(url); } private void scan() { connScreen.show(); } private void notifyExit() { hide(); midlet.destroyApp(); } protected void onActivate() { resetMainForm(); boolean isConnected = getAppCtx().isConnected(); if (isConnected) { cpScreen.setConnector(getAppCtx().getConnector()); cpScreen.show(); } else getDisplay().setCurrent(mainForm); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -