org.microemu.app.Headless Maven / Gradle / Ivy
/**
* MicroEmulator
* Copyright (C) 2008 Bartek Teodorczyk
*
* It is licensed under the following two licenses as alternatives:
* 1. GNU Lesser General Public License (the "LGPL") version 2.1 or any newer version
* 2. Apache License (the "AL") Version 2.0
*
* You may not use this file except in compliance with at least one of
* the above two licenses.
*
* You may obtain a copy of the LGPL at
* http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
*
* You may obtain a copy of the AL at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the LGPL or the AL for the specific language governing permissions and
* limitations.
*/
package org.microemu.app;
import java.io.InputStream;
import java.util.ArrayList;
import org.microemu.DisplayComponent;
import org.microemu.EmulatorContext;
import org.microemu.MIDletBridge;
import org.microemu.app.ui.Message;
import org.microemu.app.ui.noui.NoUiDisplayComponent;
import org.microemu.app.util.DeviceEntry;
import org.microemu.device.DeviceDisplay;
import org.microemu.device.FontManager;
import org.microemu.device.InputMethod;
import org.microemu.device.impl.DeviceImpl;
import org.microemu.device.j2se.J2SEDevice;
import org.microemu.device.j2se.J2SEDeviceDisplay;
import org.microemu.device.j2se.J2SEFontManager;
import org.microemu.device.j2se.J2SEInputMethod;
import org.microemu.log.Logger;
public class Headless {
private Common emulator;
private EmulatorContext context = new EmulatorContext() {
private DisplayComponent displayComponent = new NoUiDisplayComponent();
private InputMethod inputMethod = new J2SEInputMethod();
private DeviceDisplay deviceDisplay = new J2SEDeviceDisplay(this);
private FontManager fontManager = new J2SEFontManager();
public DisplayComponent getDisplayComponent() {
return displayComponent;
}
public InputMethod getDeviceInputMethod() {
return inputMethod;
}
public DeviceDisplay getDeviceDisplay() {
return deviceDisplay;
}
public FontManager getDeviceFontManager() {
return fontManager;
}
public InputStream getResourceAsStream(String name) {
return MIDletBridge.getCurrentMIDlet().getClass().getResourceAsStream(name);
}
public boolean platformRequest(final String URL) {
new Thread(new Runnable() {
public void run() {
Message.info("MIDlet requests that the device handle the following URL: " + URL);
}
}).start();
return false;
}
};
public Headless() {
emulator = new Common(context);
}
public static void main(String[] args) {
StringBuffer debugArgs = new StringBuffer();
ArrayList params = new ArrayList();
// Allow to override in command line
// Non-persistent RMS
params.add("--rms");
params.add("memory");
for (int i = 0; i < args.length; i++) {
params.add(args[i]);
if (debugArgs.length() != 0) {
debugArgs.append(", ");
}
debugArgs.append("[").append(args[i]).append("]");
}
if (args.length > 0) {
Logger.debug("headless arguments", debugArgs.toString());
}
Headless app = new Headless();
DeviceEntry defaultDevice = new DeviceEntry("Default device", null, DeviceImpl.DEFAULT_LOCATION, true, false);
app.emulator.initParams(params, defaultDevice, J2SEDevice.class);
app.emulator.initMIDlet(true);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy