SysPropForm.java
package com.nokia.example.systemproperties;
/*
* Copyright © 2011 Nokia Corporation. All rights reserved.
* Nokia and Nokia Connecting People are registered trademarks of Nokia Corporation.
* Oracle and Java are trademarks or registered trademarks of Oracle and/or its
* affiliates. Other product and company names mentioned herein may be trademarks
* or trade names of their respective owners.
* See LICENSE.TXT for license information.
*/
import javax.bluetooth.BluetoothStateException;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.bluetooth.LocalDevice;
import javax.microedition.m3g.Graphics3D;
import java.util.Hashtable;
public class SysPropForm extends Form implements CommandListener {
private Command backCommand;
private Command exitCommand;
private SystemProperties midlet;
private String[] items;
//Constructor
public SysPropForm(String title, SystemProperties midlet, String[] list) {
super(title);
items = list;
this.midlet = midlet;
backCommand = new Command("Back", Command.BACK, 1);
exitCommand = new Command("Exit", Command.EXIT, 1);
addCommand(backCommand);
addCommand(exitCommand);
setCommandListener(this);
}
//Draw the details of the property
protected void update(String title, String[] list) {
this.setTitle(title);
items = list;
this.deleteAll(); //Clear the screen
//Special case for Bluetooth details
if (midlet.bt) {
try {
append("BT address: " + LocalDevice.getLocalDevice().getBluetoothAddress() + "\n");
append("Friendly name: " + LocalDevice.getLocalDevice().getFriendlyName() + "\n");
} catch (BluetoothStateException ex) {
append("BluetoothStateException: " + ex.getMessage());
}
}
//Default way of displaying details
for (int i = 0; i < items.length; i++) {
append(items[i] + ":\n");
if (midlet.bt) {
append(LocalDevice.getProperty(items[i]) + "\n");
} else if (midlet.m3g) {
// Properties "maxViewportWidth" and "maxViewportHeight" were
// added in M3G 1.1, in case of M3G 1.0 this MIDlet returns
// "null" for these properties.
// Property "m3gRelease" is not mandated by the specification, but
// it is a implementation specific property.
Hashtable g3dtable = new Hashtable();
g3dtable = Graphics3D.getProperties();
Object property = g3dtable.get(list[i]);
if (property != null) {
append(property.toString() + "\n");
} else {
append("null\n");
}
} else if (midlet.index == 14) {
try {
append(System.getProperty(items[i]) + "\n");
} catch (SecurityException se) {
// In case of untrusted or trusted 3rd party MIDlet
// SecurityException should be thrown for all the
// PROTECTED_SYSPROPS properties.
append("SecurityException: " + se.getMessage());
}
} else {
append(System.getProperty(items[i]) + "\n");
}
}
}
//This is called when a command is issued
public void commandAction(Command c, Displayable d) {
if (c == backCommand) {
midlet.showList();
midlet.bt = false;
midlet.m3g = false;
}
if (c == exitCommand) {
midlet.quitApp();
}
}
}