📄 maincommandmanager.java
字号:
/********************************************************************
* 项目名称 :<b>j2me学习 J2me Wap Explorer</b> <br/>
*
* Copyright 2005-2006 Wuhua. All rights reserved </br>
*
* 本程序只用于学习目的,不能用于商业目的。如有需要请联系作者
********************************************************************/
package org.wuhua.wap.main.service;
import org.wuhua.wap.WapExplorer;
import org.wuhua.wap.main.AboutDialog;
import org.wuhua.wap.main.CmdConst;
import org.wuhua.wap.main.MainForm;
import org.wuhua.wap.main.SendSmsForm;
import org.wuhua.wap.ui.Command;
import org.wuhua.wap.ui.event.CommandListener;
import org.wuhua.wap.ui.skin.Color;
import org.wuhua.wap.ui.skin.Skin;
import org.wuhua.wap.ui.skin.Style;
/**
* <b>类名:MainCommandManager.java</b> </br>
* 编写日期: 2006-12-25 <br/>
* 程序功能描述:主窗口执行命令的管理者,主要是为了M-V-C <br/>
* 实现的功能有,皮肤更换,语言选择,字体选择等
* Demo: <br/>
* Bug: <br/>
*
* 程序变更日期 :<br/>
* 变更作者 :<br/>
* 变更说明 :<br/>
*
* @author wuhua </br> <a href="mailto:rrq12345@163.com">rrq12345@163.com</a>
*/
public final class MainCommandManager implements CommandListener{
private Command exit = new Command(CmdConst.CN_EXIT, Command.RIGHT, Command.GENERAL_PRIORITY);
private Command open = new Command(CmdConst.CN_OPEN, Command.LEFT, Command.GENERAL_PRIORITY);
private Command homePage = new Command(CmdConst.CN_HOMEPAGE, Command.LEFT, Command.GENERAL_PRIORITY);
private Command url = new Command(CmdConst.CN_URL, Command.LEFT, Command.GENERAL_PRIORITY);
private Command save = new Command(CmdConst.CN_SAVE, Command.LEFT, Command.GENERAL_PRIORITY);
private Command bookMark = new Command(CmdConst.CN_BOOKMARK, Command.LEFT, Command.GENERAL_PRIORITY);
private Command reload = new Command(CmdConst.CN_RELOAD, Command.LEFT, Command.GENERAL_PRIORITY);
private Command about = new Command(CmdConst.CN_ABOUT, Command.LEFT, Command.GENERAL_PRIORITY);
private Command stop = new Command(CmdConst.CN_STOP, Command.LEFT, Command.GENERAL_PRIORITY);
private Command help = new Command(CmdConst.CN_HELP, Command.LEFT, Command.GENERAL_PRIORITY);
private Command phone = new Command(CmdConst.CN_PHONE, Command.LEFT, Command.GENERAL_PRIORITY);
private Command sendSMS = new Command(CmdConst.CN_SEND_SMS, Command.LEFT, Command.GENERAL_PRIORITY);
private Command sendMMS = new Command(CmdConst.CN_SEND_MMS, Command.LEFT, Command.GENERAL_PRIORITY);
private Command langue = new Command(CmdConst.CN_LANGUE, Command.LEFT, Command.GENERAL_PRIORITY);
private Command chinese = new Command(CmdConst.CN_LANGUE_CN, Command.LEFT, Command.GENERAL_PRIORITY);
private Command english = new Command(CmdConst.EN_LANGUE_EN, Command.LEFT, Command.GENERAL_PRIORITY);
private Command skin = new Command(CmdConst.CN_SKIN, Command.LEFT, Command.GENERAL_PRIORITY);
private Command blue = new Command(CmdConst.CN_BLUE, Command.LEFT, Command.GENERAL_PRIORITY);
private Command red = new Command(CmdConst.CN_RED, Command.LEFT, Command.GENERAL_PRIORITY);
private Command green = new Command(CmdConst.CN_GREEN, Command.LEFT, Command.GENERAL_PRIORITY);
private Command black = new Command(CmdConst.CN_BLACK, Command.LEFT, Command.GENERAL_PRIORITY);
private Command orange = new Command(CmdConst.CN_ORANGE, Command.LEFT, Command.GENERAL_PRIORITY);
private Command font = new Command(CmdConst.CN_FONT, Command.LEFT, Command.GENERAL_PRIORITY);
private Command fontLarge = new Command(CmdConst.CN_FONT_LARGE, Command.LEFT, Command.GENERAL_PRIORITY);
private Command fontMidden = new Command(CmdConst.CN_FONT_MIDDEN, Command.LEFT, Command.GENERAL_PRIORITY);
private Command fontSmall = new Command(CmdConst.CN_FONT_SMALL, Command.LEFT, Command.GENERAL_PRIORITY);
private MainForm form;
private AboutDialog aboutDialog;
private SendSmsForm ssf;
public MainCommandManager(MainForm form){
this.form = form;
setCmdsImpl();
form.setSoftButtonListener(this);
setBlueSkin();
form.setFont(Style.PLAIN_SMALL); //默认小字体
ssf = new SendSmsForm();
}
public void commandAction(Command cmd) {
setSkinImpl(cmd);
setFontImpl(cmd);
setLangueImpl(cmd);
openSmsForm(cmd);
openAboutDialogAndHelpDialog(cmd);
openCmdImpl(cmd);
exit(cmd);
}
private void openSmsForm(Command cmd) {
if(cmd == sendSMS){
WapExplorer.openForm(ssf);
}
}
private void openCmdImpl(Command cmd) {
if(this.homePage == cmd){
form.openMainPage();
}
}
private void exit(Command cmd) {
if(cmd == exit)
WapExplorer.openExitDialog();
}
private void openAboutDialogAndHelpDialog(Command cmd) {
if(cmd == about){
WapExplorer.openAboutDialog();
}else if(cmd == help){
WapExplorer.openHelpDialog();
}
}
private void setLangueImpl(Command cmd) {
if(cmd == chinese)
setChineseImpl();
else if(cmd == english){
setEnglishImpl();
}
}
private void setChineseImpl() {
exit.setName(CmdConst.CN_EXIT);
open.setName(CmdConst.CN_OPEN);
homePage.setName(CmdConst.CN_HOMEPAGE);
url.setName(CmdConst.CN_URL);
save.setName(CmdConst.CN_SAVE);
bookMark.setName(CmdConst.CN_BOOKMARK);
reload.setName(CmdConst.CN_RELOAD);
about.setName(CmdConst.CN_ABOUT);
stop.setName(CmdConst.CN_STOP);
help.setName(CmdConst.CN_HELP);
langue.setName(CmdConst.CN_LANGUE);
skin.setName(CmdConst.CN_SKIN);
blue.setName(CmdConst.CN_BLUE);
red.setName(CmdConst.CN_RED);
green.setName(CmdConst.CN_GREEN);
black.setName(CmdConst.CN_BLACK);
orange.setName(CmdConst.CN_ORANGE);
font.setName(CmdConst.CN_FONT);
fontLarge.setName(CmdConst.CN_FONT_LARGE);
fontMidden.setName(CmdConst.CN_FONT_MIDDEN);
fontSmall.setName(CmdConst.CN_FONT_SMALL);
form.getSoftButton().setMenu("菜单");
form.getSoftButton().setSelect("选择");
form.getSoftButton().setCancel("取消");
WapExplorer.ABOUT_DIALOG.setTitle(CmdConst.CN_ABOUT);
WapExplorer.HELP_DIALOG.setTitle(CmdConst.CN_HELP);
WapExplorer.ABOUT_DIALOG.setCommandName(CmdConst.CN_OK);
WapExplorer.HELP_DIALOG.setCommandName(CmdConst.CN_OK);
}
private void setEnglishImpl() {
exit.setName(CmdConst.EN_EXIT);
open.setName(CmdConst.EN_OPEN);
homePage.setName(CmdConst.EN_HOMEPAGE);
url.setName(CmdConst.EN_URL);
save.setName(CmdConst.EN_SAVE);
bookMark.setName(CmdConst.EN_BOOKMARK);
reload.setName(CmdConst.EN_RELOAD);
about.setName(CmdConst.EN_ABOUT);
stop.setName(CmdConst.EN_STOP);
help.setName(CmdConst.EN_HELP);
langue.setName(CmdConst.EN_LANGUE);
skin.setName(CmdConst.EN_SKIN);
blue.setName(CmdConst.EN_BLUE);
red.setName(CmdConst.EN_RED);
green.setName(CmdConst.EN_GREEN);
black.setName(CmdConst.EN_BLACK);
orange.setName(CmdConst.EN_ORANGE);
font.setName(CmdConst.EN_FONT);
fontLarge.setName(CmdConst.EN_FONT_LARGE);
fontMidden.setName(CmdConst.EN_FONT_MIDDEN);
fontSmall.setName(CmdConst.EN_FONT_SMALL);
form.getSoftButton().setMenu("Menu");
form.getSoftButton().setSelect("Select");
form.getSoftButton().setCancel("Cancel");
WapExplorer.ABOUT_DIALOG.setTitle(CmdConst.EN_ABOUT);
WapExplorer.HELP_DIALOG.setTitle(CmdConst.EN_HELP);
WapExplorer.ABOUT_DIALOG.setCommandName(CmdConst.EN_OK);
WapExplorer.HELP_DIALOG.setCommandName(CmdConst.EN_OK);
}
/*
* 设置字体
*/
private void setFontImpl(Command cmd) {
if(cmd == this.fontLarge){
form.setFont(Style.PLAIN_LARGE);
}if(cmd == this.fontMidden){
form.setFont(Style.PLAIN_MEDIUM);
}if(cmd == this.fontSmall){
form.setFont(Style.PLAIN_SMALL);
}
}
private void setCmdsImpl() {
form.addCommand(exit);
form.addCommand(open);
open.addCommandItem(homePage);
open.addCommandItem(url);
form.addCommand(save);
//手机支持
form.addCommand(phone);
phone.addCommandItem(sendSMS);
phone.addCommandItem(sendMMS);
form.addCommand(langue);
langue.addCommandItem(chinese);
langue.addCommandItem(english);
form.addCommand(skin);
skin.addCommandItem(blue);
skin.addCommandItem(red);
skin.addCommandItem(green);
skin.addCommandItem(black);
skin.addCommandItem(orange);
form.addCommand(font);
font.addCommandItem(fontLarge);
font.addCommandItem(fontMidden);
font.addCommandItem(fontSmall);
form.addCommand(bookMark);
form.addCommand(reload);
form.addCommand(about);
form.addCommand(stop);
form.addCommand(help);
}
/**
* 设置皮肤
* @param cmd
*/
private void setSkinImpl(Command cmd){
aboutDialog = WapExplorer.ABOUT_DIALOG;
Color c = null;
if(cmd == blue){
setBlueSkin();
c = Skin.getBlueColor();
}else if(cmd == red){
c = Skin.getRedColor();
}else if(cmd == green){
c = Skin.getGreenColor();
}else if(cmd == black){
c = Skin.getBlackColor();
}else if(cmd == orange){
c = Skin.getOrangeColor();
}
if(c != null){
form.setSoftButtonStyle(c.bgColor, c.fontColor);
form.getSoftButton().setSelectedStyle(c.selectColor);
form.setStyle(c.bgColor, c.fontColor);
aboutDialog.setStyle(c.bgColor, c.fontColor);
}
}
private void setBlueSkin() {
// 0xFFD84F
form.setSoftButtonStyle(Skin.getBlueColor().bgColor, Skin.getBlueColor().fontColor);
form.getSoftButton().setSelectedStyle(Skin.getBlueColor().selectColor);
form.setStyle(Skin.getBlueColor().bgColor, Skin.getBlueColor().fontColor);
//aboutDialog.setStyle(Skin.getBlueColor().bgColor, Skin.getBlueColor().fontColor);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -