⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 blueconfig.java

📁 欢迎使用蓝牙联网坦克大战
💻 JAVA
字号:
/*
 * Bluetooth Multiplayer Games Framework
 * Author: Francesco Panciroli (email fif0302@iperbole.bologna.it)
 * Copyright (C) 2006  Francesco Panciroli
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

package newpackage;

import javax.microedition.lcdui.Choice;
import javax.microedition.lcdui.ChoiceGroup;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.TextField;

import org.apache.log4j.Category;
import org.apache.log4j.Priority;

public class BlueConfig extends Form implements CommandListener {
	
	public static final int PROTOCOL_L2CAP = 0;
	public static final int PROTOCOL_SPP = 1;
	
	private final BlueMIDlet midlet;
    private Command backCommand;
	private ChoiceGroup logLevelChoiceGroup;
	private ChoiceGroup connectionProtocolChoiceGroup;
	private TextField waitBeforeReceiveData;

	static Category log = Category.getInstance("panci");

	public BlueConfig(String formName, BlueMIDlet midlet) {
		super(formName);
		this.midlet = midlet;
		
		logLevelChoiceGroup = new ChoiceGroup("log level:", Choice.EXCLUSIVE);
        logLevelChoiceGroup.append("OFF", null);
        logLevelChoiceGroup.append("DEBUG", null);
        logLevelChoiceGroup.append("INFO", null);
        logLevelChoiceGroup.append("WARN", null);
        logLevelChoiceGroup.append("ERROR", null);
        logLevelChoiceGroup.append("FATAL", null);
        setCurrentPriority();
        append(logLevelChoiceGroup);

		connectionProtocolChoiceGroup = new ChoiceGroup("Connection Protocol:", Choice.EXCLUSIVE);
		connectionProtocolChoiceGroup.append("L2CAP", null);
		connectionProtocolChoiceGroup.append("SPP", null);
		setCurrentProtocol();
        append(connectionProtocolChoiceGroup);

		waitBeforeReceiveData = new TextField("Extra Latency (ms)", "0", 5, TextField.NUMERIC);
		append(waitBeforeReceiveData);

        backCommand = new Command("Back", Command.BACK, 2);
        addCommand(backCommand);
        
        setCommandListener(this);
	}

    private void setCurrentPriority() {
    	if (log.getPriority() != null) {
    		int priority = log.getPriority().toInt();
    		switch (priority) {
    		case Priority.OFF_INT: logLevelChoiceGroup.setSelectedIndex(0, true); break;
    		case Priority.DEBUG_INT: logLevelChoiceGroup.setSelectedIndex(1, true); break;
    		case Priority.INFO_INT: logLevelChoiceGroup.setSelectedIndex(2, true); break;
    		case Priority.WARN_INT: logLevelChoiceGroup.setSelectedIndex(3, true); break;
    		case Priority.ERROR_INT: logLevelChoiceGroup.setSelectedIndex(4, true); break;
    		case Priority.FATAL_INT: logLevelChoiceGroup.setSelectedIndex(5, true); break;
    		}
    	}
    }
	
    private void setCurrentProtocol() {
    	connectionProtocolChoiceGroup.setSelectedIndex(0, true);
    }
	
	public void commandAction(Command c, Displayable d)
    {
        if (c == backCommand) {
        	int selectedIndex = logLevelChoiceGroup.getSelectedIndex();
        	switch (selectedIndex) {
			case 0: log.setPriority(Priority.OFF); break;
			case 1: log.setPriority(Priority.DEBUG); break;
			case 2: log.setPriority(Priority.INFO); break;
			case 3: log.setPriority(Priority.WARN); break;
			case 4: log.setPriority(Priority.ERROR); break;
			case 5: log.setPriority(Priority.FATAL); break;
			}
        	log.warn("BlueConfig: Log Priority index: " + selectedIndex);
        	midlet.backToMenu();
        }
    }
	
    public int getWaitBeforeReceiveData()
    {
    	try {
        	return Integer.valueOf(waitBeforeReceiveData.getString()).intValue();
    	} catch(NumberFormatException e) {
    		log.error("getWaitBeforeReceiveData: NumberFormatException: " + e.getMessage());
    	}
    	return 0;
    }

    public int getConnectionProtocol()
    {
    	return connectionProtocolChoiceGroup.getSelectedIndex();
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -