harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r660326 [13/17] - in /harmony/enhanced/microemulator: ./ microemu-android/ microemu-android/src/ microemu-android/src/org/ microemu-android/src/org/microemu/ microemu-android/src/org/microemu/android/ microemu-android/src/org/microemu/andro...
Date Mon, 26 May 2008 22:21:57 GMT
Added: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/DeviceImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/DeviceImpl.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/DeviceImpl.java (added)
+++ harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/DeviceImpl.java Mon May 26 15:20:19 2008
@@ -0,0 +1,826 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License 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 License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.microemu.device.impl;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Vector;
+
+import javax.microedition.lcdui.Font;
+import javax.microedition.lcdui.Image;
+
+import nanoxml.XMLElement;
+import nanoxml.XMLParseException;
+
+import org.microemu.DisplayAccess;
+import org.microemu.EmulatorContext;
+import org.microemu.app.util.IOUtils;
+import org.microemu.device.Device;
+import org.microemu.device.DeviceDisplay;
+import org.microemu.device.FontManager;
+import org.microemu.device.InputMethod;
+
+public abstract class DeviceImpl implements Device {
+
+	private String name;
+
+	private EmulatorContext context;
+
+	private Image normalImage;
+
+	private Image overImage;
+
+	private Image pressedImage;
+
+	private Vector buttons;
+
+	private Vector softButtons;
+
+	private boolean hasPointerEvents;
+
+	private boolean hasPointerMotionEvents;
+
+	// TODO not implemented yet
+	private boolean hasRepeatEvents;
+
+	private Map systemProperties;
+
+	private int skinVersion;
+
+	public static final String DEFAULT_LOCATION = "org/microemu/device/default/device.xml";
+
+	/**
+	 * @deprecated
+	 */
+	private String descriptorLocation;
+
+	private static Map specialInheritanceAttributeSet;
+
+	public DeviceImpl() {
+		// Permits null values.
+		systemProperties = new HashMap();
+		buttons = new Vector();
+		softButtons = new Vector();
+	}
+
+	public static DeviceImpl create(EmulatorContext context, ClassLoader classLoader, String descriptorLocation,
+			Class defaultDeviceClass) throws IOException {
+		XMLElement doc = loadDeviceDescriptor(classLoader, descriptorLocation);
+		// saveDevice(doc);
+		DeviceImpl device = null;
+		for (Enumeration e = doc.enumerateChildren(); e.hasMoreElements();) {
+			XMLElement tmp = (XMLElement) e.nextElement();
+			if (tmp.getName().equals("class-name")) {
+				try {
+					Class deviceClass = Class.forName(tmp.getContent(), true, classLoader);
+					device = (DeviceImpl) deviceClass.newInstance();
+				} catch (ClassNotFoundException ex) {
+					throw new IOException(ex.getMessage());
+				} catch (InstantiationException ex) {
+					throw new IOException(ex.getMessage());
+				} catch (IllegalAccessException ex) {
+					throw new IOException(ex.getMessage());
+				}
+				break;
+			}
+		}
+
+		if (device == null) {
+			try {
+				device = (DeviceImpl) defaultDeviceClass.newInstance();
+			} catch (InstantiationException ex) {
+				throw new IOException(ex.getMessage());
+			} catch (IllegalAccessException ex) {
+				throw new IOException(ex.getMessage());
+			}
+		}
+		device.context = context;
+		device.loadConfig(classLoader, besourceBase(descriptorLocation), doc);
+
+		return device;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.microemu.device.DeviceA#init()
+	 */
+	public void init() {
+
+	}
+
+	/**
+	 * @deprecated use Device.create(EmulatorContext context, ClassLoader
+	 *             classLoader, String descriptorLocation);
+	 */
+	public void init(EmulatorContext context) {
+		init(context, DEFAULT_LOCATION);
+	}
+
+	/**
+	 * @deprecated use Device.create(EmulatorContext context, ClassLoader
+	 *             classLoader, String descriptorLocation);
+	 */
+	public void init(EmulatorContext context, String descriptorLocation) {
+		this.context = context;
+		if (descriptorLocation.startsWith("/")) {
+			this.descriptorLocation = descriptorLocation.substring(1);
+		} else {
+			this.descriptorLocation = descriptorLocation;
+		}
+
+		try {
+			String base = descriptorLocation.substring(0, descriptorLocation.lastIndexOf("/"));
+			XMLElement doc = loadDeviceDescriptor(getClass().getClassLoader(), descriptorLocation);
+			loadConfig(getClass().getClassLoader(), base, doc);
+		} catch (IOException ex) {
+			System.out.println("Cannot load config: " + ex);
+		}
+	}
+
+	/**
+	 * @deprecated
+	 */
+	public String getDescriptorLocation() {
+		return descriptorLocation;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.microemu.device.DeviceA#destroy()
+	 */
+	public void destroy() {
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.microemu.device.DeviceA#getName()
+	 */
+	public String getName() {
+		return name;
+	}
+
+	public EmulatorContext getEmulatorContext() {
+		return context;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.microemu.device.DeviceA#getInputMethod()
+	 */
+	public InputMethod getInputMethod() {
+		return context.getDeviceInputMethod();
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.microemu.device.DeviceA#getFontManager()
+	 */
+	public FontManager getFontManager() {
+		return context.getDeviceFontManager();
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.microemu.device.DeviceA#getDeviceDisplay()
+	 */
+	public DeviceDisplay getDeviceDisplay() {
+		return context.getDeviceDisplay();
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.microemu.device.DeviceA#getNormalImage()
+	 */
+	public Image getNormalImage() {
+		return normalImage;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.microemu.device.DeviceA#getOverImage()
+	 */
+	public Image getOverImage() {
+		return overImage;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.microemu.device.DeviceA#getPressedImage()
+	 */
+	public Image getPressedImage() {
+		return pressedImage;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.microemu.device.DeviceA#getSoftButtons()
+	 */
+	public Vector getSoftButtons() {
+		return softButtons;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.microemu.device.DeviceA#getButtons()
+	 */
+	public Vector getButtons() {
+		return buttons;
+	}
+
+	protected void loadConfig(ClassLoader classLoader, String base, XMLElement doc) throws IOException {
+		String deviceName = doc.getStringAttribute("name");
+		if (deviceName != null) {
+			name = deviceName;
+		} else {
+			name = base;
+		}
+
+		loadSkinVersion(doc);
+
+		hasPointerEvents = false;
+		hasPointerMotionEvents = false;
+		hasRepeatEvents = false;
+
+		((FontManagerImpl) getFontManager()).setAntialiasing(false);
+
+		/*
+		 * parseDisplay have to be performed first to check if device display
+		 * has resizable flag set, parseInput skips rectangle or polygon element
+		 * then, also normalImage, overImage and pressedImage aren't needed
+		 */
+		parseDisplay(classLoader, base, doc.getChild("display"));
+
+		for (Enumeration e = doc.enumerateChildren(); e.hasMoreElements();) {
+			XMLElement tmp = (XMLElement) e.nextElement();
+			if (tmp.getName().equals("system-properties")) {
+				parseSystemProperties(tmp);
+			} else if (tmp.getName().equals("img") && !((DeviceDisplayImpl) getDeviceDisplay()).isResizable()) {
+				try {
+					if (tmp.getStringAttribute("name").equals("normal")) {
+						normalImage = loadImage(classLoader, base, tmp.getStringAttribute("src"));
+					} else if (tmp.getStringAttribute("name").equals("over")) {
+						overImage = loadImage(classLoader, base, tmp.getStringAttribute("src"));
+					} else if (tmp.getStringAttribute("name").equals("pressed")) {
+						pressedImage = loadImage(classLoader, base, tmp.getStringAttribute("src"));
+					}
+				} catch (IOException ex) {
+					System.out.println("Cannot load " + tmp.getStringAttribute("src"));
+					return;
+				}
+			} else if (tmp.getName().equals("fonts")) {
+				parseFonts(classLoader, base, tmp);
+			} else if (tmp.getName().equals("input") || tmp.getName().equals("keyboard")) {
+				// "keyboard" is for backward compatibility
+				parseInput(tmp);
+			}
+		}
+	}
+
+	private void loadSkinVersion(XMLElement doc) {
+		String xmlns = doc.getStringAttribute("xmlns");
+		if (xmlns == null) {
+			skinVersion = 20000;
+		} else {
+			if (xmlns.endsWith("/2.0.2/")) {
+				skinVersion = 20002;
+			} else {
+				skinVersion = 20000;
+			}
+		}
+	}
+
+	private void parseDisplay(ClassLoader classLoader, String base, XMLElement tmp) throws IOException {
+		DeviceDisplayImpl deviceDisplay = (DeviceDisplayImpl) getDeviceDisplay();
+
+		String resizable = tmp.getStringAttribute("resizable", "false");
+		if (resizable.equalsIgnoreCase("true")) {
+			deviceDisplay.setResizable(true);
+		} else {
+			deviceDisplay.setResizable(false);
+		}
+
+		for (Enumeration e_display = tmp.enumerateChildren(); e_display.hasMoreElements();) {
+			XMLElement tmp_display = (XMLElement) e_display.nextElement();
+			if (tmp_display.getName().equals("numcolors")) {
+				deviceDisplay.setNumColors(Integer.parseInt(tmp_display.getContent()));
+			} else if (tmp_display.getName().equals("iscolor")) {
+				deviceDisplay.setIsColor(parseBoolean(tmp_display.getContent()));
+			} else if (tmp_display.getName().equals("numalphalevels")) {
+				deviceDisplay.setNumAlphaLevels(Integer.parseInt(tmp_display.getContent()));
+			} else if (tmp_display.getName().equals("background")) {
+				deviceDisplay.setBackgroundColor(new Color(Integer.parseInt(tmp_display.getContent(), 16)));
+			} else if (tmp_display.getName().equals("foreground")) {
+				deviceDisplay.setForegroundColor(new Color(Integer.parseInt(tmp_display.getContent(), 16)));
+			} else if (tmp_display.getName().equals("rectangle")) {
+				Rectangle rect = getRectangle(tmp_display);
+				if (deviceDisplay.isResizable()) {
+					rect.x = 0;
+					rect.y = 0;
+				}
+				deviceDisplay.setDisplayRectangle(rect);
+			} else if (tmp_display.getName().equals("paintable")) {
+				deviceDisplay.setDisplayPaintable(getRectangle(tmp_display));
+			}
+		}
+		for (Enumeration e_display = tmp.enumerateChildren(); e_display.hasMoreElements();) {
+			XMLElement tmp_display = (XMLElement) e_display.nextElement();
+			if (tmp_display.getName().equals("img")) {
+				if (tmp_display.getStringAttribute("name").equals("up")
+						|| tmp_display.getStringAttribute("name").equals("down")) {
+					// deprecated, moved to icon
+					SoftButton icon = deviceDisplay.createSoftButton(skinVersion, tmp_display
+							.getStringAttribute("name"), getRectangle(tmp_display.getChild("paintable")), loadImage(
+							classLoader, base, tmp_display.getStringAttribute("src")), loadImage(classLoader, base,
+							tmp_display.getStringAttribute("src")));
+					getSoftButtons().addElement(icon);
+				} else if (tmp_display.getStringAttribute("name").equals("mode")) {
+					// deprecated, moved to status
+					if (tmp_display.getStringAttribute("type").equals("123")) {
+						deviceDisplay.setMode123Image(new PositionedImage(loadImage(classLoader, base, tmp_display
+								.getStringAttribute("src")), getRectangle(tmp_display.getChild("paintable"))));
+					} else if (tmp_display.getStringAttribute("type").equals("abc")) {
+						deviceDisplay.setModeAbcLowerImage(new PositionedImage(loadImage(classLoader, base, tmp_display
+								.getStringAttribute("src")), getRectangle(tmp_display.getChild("paintable"))));
+					} else if (tmp_display.getStringAttribute("type").equals("ABC")) {
+						deviceDisplay.setModeAbcUpperImage(new PositionedImage(loadImage(classLoader, base, tmp_display
+								.getStringAttribute("src")), getRectangle(tmp_display.getChild("paintable"))));
+					}
+				}
+			} else if (tmp_display.getName().equals("icon")) {
+				Image iconNormalImage = null;
+				Image iconPressedImage = null;
+				for (Enumeration e_icon = tmp_display.enumerateChildren(); e_icon.hasMoreElements();) {
+					XMLElement tmp_icon = (XMLElement) e_icon.nextElement();
+					if (tmp_icon.getName().equals("img")) {
+						if (tmp_icon.getStringAttribute("name").equals("normal")) {
+							iconNormalImage = loadImage(classLoader, base, tmp_icon.getStringAttribute("src"));
+						} else if (tmp_icon.getStringAttribute("name").equals("pressed")) {
+							iconPressedImage = loadImage(classLoader, base, tmp_icon.getStringAttribute("src"));
+						}
+					}
+				}
+				SoftButton icon = deviceDisplay.createSoftButton(skinVersion, tmp_display.getStringAttribute("name"),
+						getRectangle(tmp_display.getChild("paintable")), iconNormalImage, iconPressedImage);
+				if (icon.getName().equals("up")) {
+					icon.setCommand(DisplayAccess.CMD_SCREEN_UP);
+				} else if (icon.getName().equals("down")) {
+					icon.setCommand(DisplayAccess.CMD_SCREEN_DOWN);
+				}
+				getSoftButtons().addElement(icon);
+			} else if (tmp_display.getName().equals("status")) {
+				if (tmp_display.getStringAttribute("name").equals("input")) {
+					Rectangle paintable = getRectangle(tmp_display.getChild("paintable"));
+					for (Enumeration e_status = tmp_display.enumerateChildren(); e_status.hasMoreElements();) {
+						XMLElement tmp_status = (XMLElement) e_status.nextElement();
+						if (tmp_status.getName().equals("img")) {
+							if (tmp_status.getStringAttribute("name").equals("123")) {
+								deviceDisplay.setMode123Image(new PositionedImage(loadImage(classLoader, base,
+										tmp_status.getStringAttribute("src")), paintable));
+							} else if (tmp_status.getStringAttribute("name").equals("abc")) {
+								deviceDisplay.setModeAbcLowerImage(new PositionedImage(loadImage(classLoader, base,
+										tmp_status.getStringAttribute("src")), paintable));
+							} else if (tmp_status.getStringAttribute("name").equals("ABC")) {
+								deviceDisplay.setModeAbcUpperImage(new PositionedImage(loadImage(classLoader, base,
+										tmp_status.getStringAttribute("src")), paintable));
+							}
+						}
+					}
+				}
+			}
+		}
+	}
+
+	private void parseFonts(ClassLoader classLoader, String base, XMLElement tmp) throws IOException {
+		FontManagerImpl fontManager = (FontManagerImpl) getFontManager();
+
+		String hint = tmp.getStringAttribute("hint");
+		boolean antialiasing = false;
+		if (hint != null && hint.equals("antialiasing")) {
+			antialiasing = true;
+		}
+		fontManager.setAntialiasing(antialiasing);
+
+		for (Enumeration e_fonts = tmp.enumerateChildren(); e_fonts.hasMoreElements();) {
+			XMLElement tmp_font = (XMLElement) e_fonts.nextElement();
+			if (tmp_font.getName().equals("font")) {
+				String face = tmp_font.getStringAttribute("face").toLowerCase();
+				String style = tmp_font.getStringAttribute("style").toLowerCase();
+				String size = tmp_font.getStringAttribute("size").toLowerCase();
+
+				if (face.startsWith("face_")) {
+					face = face.substring("face_".length());
+				}
+				if (style.startsWith("style_")) {
+					style = style.substring("style_".length());
+				}
+				if (size.startsWith("size_")) {
+					size = size.substring("size_".length());
+				}
+
+				for (Enumeration e_defs = tmp_font.enumerateChildren(); e_defs.hasMoreElements();) {
+					XMLElement tmp_def = (XMLElement) e_defs.nextElement();
+					if (tmp_def.getName().equals("system")) {
+						String defName = tmp_def.getStringAttribute("name");
+						String defStyle = tmp_def.getStringAttribute("style");
+						int defSize = Integer.parseInt(tmp_def.getStringAttribute("size"));
+
+						fontManager.setFont(face, style, size, fontManager.createSystemFont(defName, defStyle, defSize,
+								antialiasing));
+					} else if (tmp_def.getName().equals("ttf")) {
+						String defSrc = tmp_def.getStringAttribute("src");
+						String defStyle = tmp_def.getStringAttribute("style");
+						int defSize = Integer.parseInt(tmp_def.getStringAttribute("size"));
+
+						fontManager.setFont(face, style, size, fontManager.createTrueTypeFont(getResourceUrl(
+								classLoader, base, defSrc), defStyle, defSize, antialiasing));
+					}
+				}
+			}
+		}
+	}
+
+	private void parseInput(XMLElement tmp) {
+		DeviceDisplayImpl deviceDisplay = (DeviceDisplayImpl) getDeviceDisplay();
+		boolean resizable = deviceDisplay.isResizable();
+
+		for (Enumeration e_keyboard = tmp.enumerateChildren(); e_keyboard.hasMoreElements();) {
+			XMLElement tmp_keyboard = (XMLElement) e_keyboard.nextElement();
+			if (tmp_keyboard.getName().equals("haspointerevents")) {
+				hasPointerEvents = parseBoolean(tmp_keyboard.getContent());
+			} else if (tmp_keyboard.getName().equals("haspointermotionevents")) {
+				hasPointerMotionEvents = parseBoolean(tmp_keyboard.getContent());
+			} else if (tmp_keyboard.getName().equals("hasrepeatevents")) {
+				hasRepeatEvents = parseBoolean(tmp_keyboard.getContent());
+			} else if (tmp_keyboard.getName().equals("button")) {
+				Shape shape = null;
+				Hashtable inputToChars = new Hashtable();
+				for (Enumeration e_button = tmp_keyboard.enumerateChildren(); e_button.hasMoreElements();) {
+					XMLElement tmp_button = (XMLElement) e_button.nextElement();
+					if (tmp_button.getName().equals("chars")) {
+						String input = tmp_button.getStringAttribute("input", "common");
+						Vector stringArray = new Vector();
+						for (Enumeration e_chars = tmp_button.enumerateChildren(); e_chars.hasMoreElements();) {
+							XMLElement tmp_chars = (XMLElement) e_chars.nextElement();
+							if (tmp_chars.getName().equals("char")) {
+								stringArray.addElement(tmp_chars.getContent());
+							}
+						}
+						char[] charArray = new char[stringArray.size()];
+						for (int i = 0; i < stringArray.size(); i++) {
+							String str = (String) stringArray.elementAt(i);
+							if (str.length() > 0) {
+								charArray[i] = str.charAt(0);
+							} else {
+								charArray[i] = ' ';
+							}
+						}
+						inputToChars.put(input, charArray);
+					} else if (tmp_button.getName().equals("rectangle") && !resizable) {
+						shape = getRectangle(tmp_button);
+					} else if (tmp_button.getName().equals("polygon") && !resizable) {
+						shape = getPolygon(tmp_button);
+					}
+				}
+				int keyCode = tmp_keyboard.getIntAttribute("keyCode", Integer.MIN_VALUE);
+				getButtons().addElement(
+						deviceDisplay.createButton(skinVersion, tmp_keyboard.getStringAttribute("name"), shape,
+								keyCode, tmp_keyboard.getStringAttribute("key"), tmp_keyboard
+										.getStringAttribute("keyboardChars"), inputToChars, tmp_keyboard
+										.getBooleanAttribute("modeChange", false)));
+			} else if (tmp_keyboard.getName().equals("softbutton")) {
+				Vector commands = new Vector();
+				Shape shape = null;
+				Rectangle paintable = null;
+				Font font = null;
+				for (Enumeration e_button = tmp_keyboard.enumerateChildren(); e_button.hasMoreElements();) {
+					XMLElement tmp_button = (XMLElement) e_button.nextElement();
+					if (tmp_button.getName().equals("rectangle") && !resizable) {
+						shape = getRectangle(tmp_button);
+					} else if (tmp_button.getName().equals("polygon") && !resizable) {
+						shape = getPolygon(tmp_button);
+					} else if (tmp_button.getName().equals("paintable")) {
+						paintable = getRectangle(tmp_button);
+					} else if (tmp_button.getName().equals("command")) {
+						commands.addElement(tmp_button.getContent());
+					} else if (tmp_button.getName().equals("font")) {
+						font = getFont(tmp_button.getStringAttribute("face"), tmp_button.getStringAttribute("style"),
+								tmp_button.getStringAttribute("size"));
+					}
+				}
+				int keyCode = tmp_keyboard.getIntAttribute("keyCode", Integer.MIN_VALUE);
+				SoftButton button = deviceDisplay.createSoftButton(skinVersion,
+						tmp_keyboard.getStringAttribute("name"), shape, keyCode,
+						tmp_keyboard.getStringAttribute("key"), paintable,
+						tmp_keyboard.getStringAttribute("alignment"), commands, font);
+				getButtons().addElement(button);
+				getSoftButtons().addElement(button);
+			}
+		}
+	}
+
+	private void parseSystemProperties(XMLElement tmp) {
+		for (Enumeration e_prop = tmp.enumerateChildren(); e_prop.hasMoreElements();) {
+			XMLElement tmp_prop = (XMLElement) e_prop.nextElement();
+			if (tmp_prop.getName().equals("system-property")) {
+				systemProperties.put(tmp_prop.getStringAttribute("name"), tmp_prop.getStringAttribute("value"));
+			}
+		}
+	}
+
+	private static Font getFont(String face, String style, String size) {
+		int meFace = 0;
+		if (face.equalsIgnoreCase("system")) {
+			meFace |= Font.FACE_SYSTEM;
+		} else if (face.equalsIgnoreCase("monospace")) {
+			meFace |= Font.FACE_MONOSPACE;
+		} else if (face.equalsIgnoreCase("proportional")) {
+			meFace |= Font.FACE_PROPORTIONAL;
+		}
+
+		int meStyle = 0;
+		String testStyle = style.toLowerCase();
+		if (testStyle.indexOf("plain") != -1) {
+			meStyle |= Font.STYLE_PLAIN;
+		}
+		if (testStyle.indexOf("bold") != -1) {
+			meStyle |= Font.STYLE_BOLD;
+		}
+		if (testStyle.indexOf("italic") != -1) {
+			meStyle |= Font.STYLE_ITALIC;
+		}
+		if (testStyle.indexOf("underlined") != -1) {
+			meStyle |= Font.STYLE_UNDERLINED;
+		}
+
+		int meSize = 0;
+		if (size.equalsIgnoreCase("small")) {
+			meSize |= Font.SIZE_SMALL;
+		} else if (size.equalsIgnoreCase("medium")) {
+			meSize |= Font.SIZE_MEDIUM;
+		} else if (size.equalsIgnoreCase("large")) {
+			meSize |= Font.SIZE_LARGE;
+		}
+
+		return Font.getFont(meFace, meStyle, meSize);
+	}
+
+	private Rectangle getRectangle(XMLElement source) {
+		Rectangle rect = new Rectangle();
+
+		for (Enumeration e_rectangle = source.enumerateChildren(); e_rectangle.hasMoreElements();) {
+			XMLElement tmp_rectangle = (XMLElement) e_rectangle.nextElement();
+			if (tmp_rectangle.getName().equals("x")) {
+				rect.x = Integer.parseInt(tmp_rectangle.getContent());
+			} else if (tmp_rectangle.getName().equals("y")) {
+				rect.y = Integer.parseInt(tmp_rectangle.getContent());
+			} else if (tmp_rectangle.getName().equals("width")) {
+				rect.width = Integer.parseInt(tmp_rectangle.getContent());
+			} else if (tmp_rectangle.getName().equals("height")) {
+				rect.height = Integer.parseInt(tmp_rectangle.getContent());
+			}
+		}
+
+		return rect;
+	}
+
+	private Polygon getPolygon(XMLElement source) {
+		Polygon poly = new Polygon();
+
+		for (Enumeration e_poly = source.enumerateChildren(); e_poly.hasMoreElements();) {
+			XMLElement tmp_point = (XMLElement) e_poly.nextElement();
+			if (tmp_point.getName().equals("point")) {
+				poly.addPoint(Integer.parseInt(tmp_point.getStringAttribute("x")), Integer.parseInt(tmp_point
+						.getStringAttribute("y")));
+			}
+		}
+
+		return poly;
+	}
+
+	private boolean parseBoolean(String value) {
+		if (value.toLowerCase().equals(new String("true").toLowerCase())) {
+			return true;
+		} else {
+			return false;
+		}
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.microemu.device.DeviceA#hasPointerEvents()
+	 */
+	public boolean hasPointerEvents() {
+		return hasPointerEvents;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.microemu.device.DeviceA#hasPointerMotionEvents()
+	 */
+	public boolean hasPointerMotionEvents() {
+		return hasPointerMotionEvents;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.microemu.device.DeviceA#hasRepeatEvents()
+	 */
+	public boolean hasRepeatEvents() {
+		return hasRepeatEvents;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.microemu.device.DeviceA#hasRepeatEvents()
+	 */
+	public boolean vibrate(int duration) {
+		return false;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.microemu.device.DeviceA#getSystemProperties()
+	 */
+	public Map getSystemProperties() {
+		return this.systemProperties;
+	}
+
+	private static void saveDevice(XMLElement doc) {
+		File configFile = new File(".", "device-tmp.xml");
+		FileWriter fw = null;
+		try {
+			fw = new FileWriter(configFile);
+			doc.write(fw);
+			fw.close();
+		} catch (IOException ex) {
+			System.out.println(ex);
+		} finally {
+			IOUtils.closeQuietly(fw);
+		}
+	}
+
+	private static XMLElement loadDeviceDescriptor(ClassLoader classLoader, String descriptorLocation)
+			throws IOException {
+		InputStream descriptor = classLoader.getResourceAsStream(descriptorLocation);
+		if (descriptor == null) {
+			throw new IOException("Cannot find descriptor at: " + descriptorLocation);
+		}
+		XMLElement doc;
+		try {
+			doc = loadXmlDocument(descriptor);
+		} finally {
+			IOUtils.closeQuietly(descriptor);
+		}
+
+		String parent = doc.getStringAttribute("extends");
+		if (parent != null) {
+			return inheritXML(loadDeviceDescriptor(classLoader, expandResourcePath(besourceBase(descriptorLocation),
+					parent)), doc, "/");
+		}
+		return doc;
+	}
+
+	private static void inheritanceConstInit() {
+		if (specialInheritanceAttributeSet == null) {
+			specialInheritanceAttributeSet = new Hashtable();
+			specialInheritanceAttributeSet.put("//FONTS/FONT", new String[] { "face", "style", "size" });
+		}
+	}
+
+	/**
+	 * Very simple xml inheritance for devices.
+	 */
+	static XMLElement inheritXML(XMLElement parent, XMLElement child, String parentName) {
+		inheritanceConstInit();
+		if (parent == null) {
+			return child;
+		}
+		parent.setContent(child.getContent());
+		for (Enumeration ena = child.enumerateAttributeNames(); ena.hasMoreElements();) {
+			String key = (String) ena.nextElement();
+			parent.setAttribute(key, child.getAttribute(key));
+		}
+		for (Enumeration enc = child.enumerateChildren(); enc.hasMoreElements();) {
+			XMLElement c = (XMLElement) enc.nextElement();
+			String fullName = (parentName + "/" + c.getName()).toUpperCase(Locale.ENGLISH);
+			// System.out.println("processing [" + fullName + "]");
+			boolean inheritWithName = false;
+			if (c.getStringAttribute("name") != null) {
+				inheritWithName = true;
+			} else {
+				// Find if element has siblings
+				inheritWithName = ((child.getChildCount(c.getName()) > 1) || (parent.getChildCount(c.getName()) > 1));
+			}
+			XMLElement p;
+			if (inheritWithName) {
+				String[] equalAttributes = (String[]) specialInheritanceAttributeSet.get(fullName);
+				if (equalAttributes != null) {
+					p = parent.getChild(c.getName(), c.getStringAttributes(equalAttributes));
+				} else {
+					p = parent.getChild(c.getName(), c.getStringAttribute("name"));
+				}
+			} else {
+				p = parent.getChild(c.getName());
+			}
+			// System.out.println("inheritXML " + c.getName());
+			if (p == null) {
+				parent.addChild(c);
+			} else {
+				inheritXML(p, c, fullName);
+			}
+		}
+		return parent;
+	}
+
+	private static XMLElement loadXmlDocument(InputStream descriptor) throws IOException {
+		BufferedReader dis = new BufferedReader(new InputStreamReader(descriptor));
+		XMLElement doc = new XMLElement();
+		try {
+			doc.parseFromReader(dis, 1);
+		} catch (XMLParseException ex) {
+			throw new IOException(ex.toString());
+		} finally {
+			dis.close();
+		}
+		return doc;
+	}
+
+	private static String besourceBase(String descriptorLocation) {
+		return descriptorLocation.substring(0, descriptorLocation.lastIndexOf("/"));
+	}
+
+	private static String expandResourcePath(String base, String src) throws IOException {
+		String expandedSource;
+		if (src.startsWith("/")) {
+			expandedSource = src;
+		} else {
+			expandedSource = base + "/" + src;
+		}
+		if (expandedSource.startsWith("/")) {
+			expandedSource = expandedSource.substring(1);
+		}
+		return expandedSource;
+	}
+
+	private URL getResourceUrl(ClassLoader classLoader, String base, String src) throws IOException {
+		String expandedSource = expandResourcePath(base, src);
+
+		URL result = classLoader.getResource(expandedSource);
+
+		if (result == null) {
+			throw new IOException("Cannot find resource: " + expandedSource);
+		}
+
+		return result;
+	}
+
+	private Image loadImage(ClassLoader classLoader, String base, String src) throws IOException {
+		URL url = getResourceUrl(classLoader, base, src);
+
+		return ((DeviceDisplayImpl) getDeviceDisplay()).createSystemImage(url);
+	}
+
+}

Propchange: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/DeviceImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/Font.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/Font.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/Font.java (added)
+++ harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/Font.java Mon May 26 15:20:19 2008
@@ -0,0 +1,34 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License 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 License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.microemu.device.impl;
+
+public interface Font {
+
+	int charWidth(char ch);
+	
+	int charsWidth(char[] ch, int offset, int length);
+	
+	int getBaselinePosition();
+	
+	int getHeight();
+	
+	int stringWidth(String str);
+	
+}

Propchange: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/Font.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/FontManagerImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/FontManagerImpl.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/FontManagerImpl.java (added)
+++ harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/FontManagerImpl.java Mon May 26 15:20:19 2008
@@ -0,0 +1,36 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License 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 License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.microemu.device.impl;
+
+import java.net.URL;
+
+import org.microemu.device.FontManager;
+
+public interface FontManagerImpl extends FontManager {
+
+	void setAntialiasing(boolean antialiasing);
+
+	void setFont(String face, String style, String size, Font font);
+
+	Font createSystemFont(String defName, String defStyle, int defSize, boolean antialiasing);
+	
+	Font createTrueTypeFont(URL defUrl, String defStyle, int defSize, boolean antialiasing);
+	
+}

Propchange: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/FontManagerImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/InputMethodImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/InputMethodImpl.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/InputMethodImpl.java (added)
+++ harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/InputMethodImpl.java Mon May 26 15:20:19 2008
@@ -0,0 +1,216 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License 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 License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.microemu.device.impl;
+
+import javax.microedition.lcdui.TextField;
+
+import org.microemu.MIDletBridge;
+import org.microemu.device.DeviceFactory;
+import org.microemu.device.InputMethod;
+import org.microemu.device.InputMethodEvent;
+import org.microemu.device.InputMethodListener;
+
+public abstract class InputMethodImpl extends InputMethod implements Runnable {
+
+	protected boolean resetKey;
+	
+	protected Button lastButton;
+	
+	protected int lastButtonCharIndex;
+
+	private boolean cancel;
+	
+	private Thread t;
+
+	public InputMethodImpl() {
+		this.lastButton = null;
+		this.lastButtonCharIndex = -1;
+		
+		this.cancel = false;
+		this.t = new Thread(this, "InputMethodThread");
+		this.t.setDaemon(true);
+		this.t.start();
+	}
+
+	// TODO to be removed when event dispatcher will run input method task
+	public void dispose() {
+		cancel = true;
+		synchronized (this) {
+			notify();
+		}
+	}
+
+	// Runnable
+	public void run() 
+	{
+		while (!cancel) {
+			try {
+				resetKey = true;
+				synchronized (this) {
+					wait(1500);
+				}
+			} catch (InterruptedException ex) {
+			}
+			synchronized (this) {
+				if (resetKey && lastButton != null && inputMethodListener != null) {
+					int caret = inputMethodListener.getCaretPosition() + 1;
+                    if (caret <= inputMethodListener.getText().length()) {
+    					lastButton = null;
+    					lastButtonCharIndex = -1;
+						InputMethodEvent event = new InputMethodEvent(InputMethodEvent.CARET_POSITION_CHANGED, caret, inputMethodListener.getText());
+						inputMethodListener.caretPositionChanged(event);
+                    }
+				}
+			}
+		}
+	}
+	
+    public void setInputMethodListener(InputMethodListener l) {
+        super.setInputMethodListener(l);
+
+        lastButton = null;
+        lastButtonCharIndex = -1;
+    }
+	
+	public void pointerPressed(int x, int y) {		
+		if (DeviceFactory.getDevice().hasPointerEvents()) {
+			MIDletBridge.getMIDletAccess().getDisplayAccess().pointerPressed(x, y);
+		}
+	}
+
+	public void pointerReleased(int x, int y) {
+		if (DeviceFactory.getDevice().hasPointerEvents()) {
+			MIDletBridge.getMIDletAccess().getDisplayAccess().pointerReleased(x, y);
+		}
+	}
+
+	public void pointerDragged(int x, int y) {
+		if (DeviceFactory.getDevice().hasPointerMotionEvents()) {
+			MIDletBridge.getMIDletAccess().getDisplayAccess().pointerDragged(x, y);
+		}
+	}
+	
+	protected void insertText(String str) {
+		if (str.length() > 0) {
+			int caret = inputMethodListener.getCaretPosition();
+			String tmp = "";
+			synchronized (this) {
+				if (lastButton != null) {
+					caret++;
+					lastButton = null;
+					lastButtonCharIndex = -1;
+				}
+				if (caret > 0) {
+					tmp += inputMethodListener.getText().substring(0, caret);
+				}
+				tmp += str;
+				if (caret < inputMethodListener.getText().length()) {
+					tmp += inputMethodListener.getText().substring(caret);
+				}
+				caret += str.length();
+			}
+            if (!validate(tmp, inputMethodListener.getConstraints())) {
+                return;
+            }
+			InputMethodEvent event = new InputMethodEvent(InputMethodEvent.INPUT_METHOD_TEXT_CHANGED, caret, tmp);
+			inputMethodListener.inputMethodTextChanged(event);
+			event = new InputMethodEvent(InputMethodEvent.CARET_POSITION_CHANGED, caret, tmp);
+			inputMethodListener.caretPositionChanged(event);
+		}
+	}
+
+	protected char[] filterConstraints(char[] chars) {
+		char[] result = new char[chars.length];
+		int i, j;
+
+		for (i = 0, j = 0; i < chars.length; i++) {
+            switch (inputMethodListener.getConstraints() & TextField.CONSTRAINT_MASK) {
+                case TextField.ANY :
+                    result[j] = chars[i];
+                    j++;
+                    break;
+                case TextField.EMAILADDR :
+                    // TODO
+                    break;
+                case TextField.NUMERIC :
+                    if (Character.isDigit(chars[i]) || chars[i] == '-') {
+                        result[j] = chars[i];
+                        j++;
+                    }
+                    break;
+                case TextField.PHONENUMBER :
+                    // TODO
+                    break;
+                case TextField.URL :
+                    if (chars[i] != '\n') {
+                        result[j] = chars[i];
+                        j++;
+                    }
+                    break;
+                case TextField.DECIMAL :
+                    if (Character.isDigit(chars[i]) || chars[i] == '-' || chars[i] == '.') {
+                        result[j] = chars[i];
+                        j++;
+                    }
+                    break;
+            }
+		}
+		if (i != j) {
+			char[] newresult = new char[j];
+			System.arraycopy(result, 0, newresult, 0, j);
+			result = newresult;
+		}
+
+		return result;
+	}
+
+	protected char[] filterInputMode(char[] chars) {
+	    if (chars == null) {
+	        return new char[0];
+	    }
+	    
+		int inputMode = getInputMode();
+		char[] result = new char[chars.length];
+		int i, j;
+
+		for (i = 0, j = 0; i < chars.length; i++) {
+			if (inputMode == InputMethod.INPUT_ABC_UPPER) {
+				result[j] = Character.toUpperCase(chars[i]);
+				j++;
+			} else if (inputMode == InputMethod.INPUT_ABC_LOWER) {
+				result[j] = Character.toLowerCase(chars[i]);
+				j++;
+			} else if (inputMode == InputMethod.INPUT_123) {
+				if (Character.isDigit(chars[i]) || chars[i] == '-' || chars[i] == '.') {
+					result[j] = chars[i];
+					j++;
+				}
+			}
+		}
+		if (i != j) {
+			char[] newresult = new char[j];
+			System.arraycopy(result, 0, newresult, 0, j);
+			result = newresult;
+		}
+
+		return result;
+	}
+	
+}

Propchange: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/InputMethodImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/PositionedImage.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/PositionedImage.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/PositionedImage.java (added)
+++ harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/PositionedImage.java Mon May 26 15:20:19 2008
@@ -0,0 +1,47 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License 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 License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.microemu.device.impl;
+
+import javax.microedition.lcdui.Image;
+
+
+public class PositionedImage
+{
+    private Image image;
+
+    private Rectangle rectangle;
+
+    public PositionedImage(Image img, Rectangle arectangle)
+    {
+        image = img;
+        rectangle = arectangle;
+    }
+
+    public Image getImage()
+    {
+        return image;
+    }
+
+    public Rectangle getRectangle()
+    {
+        return rectangle;
+    }
+
+}

Propchange: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/PositionedImage.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/ui/DisplayableImplUI.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/ui/DisplayableImplUI.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/ui/DisplayableImplUI.java (added)
+++ harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/ui/DisplayableImplUI.java Mon May 26 15:20:19 2008
@@ -0,0 +1,58 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License 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 License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.microemu.device.impl.ui;
+
+import javax.microedition.lcdui.Command;
+import javax.microedition.lcdui.CommandListener;
+
+import org.microemu.device.ui.DisplayableUI;
+
+public class DisplayableImplUI implements DisplayableUI {
+
+	public void addCommand(Command cmd) {
+		// TODO Auto-generated method stub
+
+	}
+
+	public void removeCommand(Command cmd) {
+		// TODO Auto-generated method stub
+
+	}
+
+	public void setCommandListener(CommandListener l) {
+		// TODO Auto-generated method stub
+
+	}
+
+	public void hideNotify() {
+		// TODO Auto-generated method stub
+
+	}
+
+	public void showNotify() {
+		// TODO Auto-generated method stub
+
+	}
+
+	public void invalidate() {
+		// TODO implement invalidate
+	}
+
+}

Propchange: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/ui/DisplayableImplUI.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/log/Logger.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/log/Logger.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/log/Logger.java (added)
+++ harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/log/Logger.java Mon May 26 15:20:19 2008
@@ -0,0 +1,302 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License 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 License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.microemu.log;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.Vector;
+
+/**
+ * 
+ * This class is used as abstraction layer for log messages Minimum Log4j
+ * implemenation with multiple overloaded functions
+ * 
+ * @author vlads
+ * 
+ */
+public class Logger {
+
+	private static final String FQCN = Logger.class.getName();
+
+	private static final Set fqcnSet = new HashSet();
+
+	private static final Set logFunctionsSet = new HashSet();
+
+	private static boolean java13 = false;
+	
+	private static boolean locationEnabled = true;
+
+	private static List loggerAppenders = new Vector();
+
+	static {
+		fqcnSet.add(FQCN);
+		// Message class can be moved to different sub project, See call to
+		// addLogOrigin
+		// Also Message calss can be refactored by ProGuard
+		// fqcnSet.add("org.microemu.app.ui.Message");
+
+		addAppender(new StdOutAppender());
+
+		// This is done for MIDletInternlaLogger a wrapper for
+		// System.out.println functions.
+		logFunctionsSet.add("debug");
+		logFunctionsSet.add("log");
+		logFunctionsSet.add("error");
+		logFunctionsSet.add("fatal");
+		logFunctionsSet.add("info");
+		logFunctionsSet.add("warn");
+	}
+
+	public static boolean isDebugEnabled() {
+		return true;
+	}
+
+	public static boolean isErrorEnabled() {
+		return true;
+	}
+	
+	public static boolean isLocationEnabled() {
+		return locationEnabled;
+	}
+	
+	public static void setLocationEnabled(boolean state) {
+		locationEnabled = state;
+	}
+
+	private static StackTraceElement getLocation() {
+		if (java13 || !locationEnabled) {
+			return null;
+		}
+		try {
+			StackTraceElement[] ste = new Throwable().getStackTrace();
+			boolean wrapperFound = false;
+			for (int i = 0; i < ste.length - 1; i++) {
+				if (fqcnSet.contains(ste[i].getClassName())) {
+					wrapperFound = false;
+					String nextClassName = ste[i + 1].getClassName();
+					if (nextClassName.startsWith("java.") || nextClassName.startsWith("sun.")) {
+						continue;
+					}
+					if (!fqcnSet.contains(nextClassName)) {
+						if (logFunctionsSet.contains(ste[i + 1].getMethodName())) {
+							wrapperFound = true;
+						} else {
+							// if dynamic proxy classes
+							if (nextClassName.startsWith("$Proxy")) {
+								return ste[i + 2];
+							} else {
+								return ste[i + 1];
+							}
+						}
+					}
+				} else if (wrapperFound) {
+					if (!logFunctionsSet.contains(ste[i].getMethodName())) {
+						return ste[i];
+					}
+				}
+			}
+			return ste[ste.length - 1];
+		} catch (Throwable e) {
+			java13 = true;
+		}
+		return null;
+	}
+
+	private static void write(int level, String message, Throwable throwable) {
+		callAppenders(new LoggingEvent(level, message, getLocation(), throwable));
+	}
+
+	private static void write(int level, String message, Throwable throwable, Object data) {
+		callAppenders(new LoggingEvent(level, message, getLocation(), throwable, data));
+	}
+
+	public static void debug(String message) {
+		if (isDebugEnabled()) {
+			write(LoggingEvent.DEBUG, message, null);
+		}
+	}
+
+	public static void debug(String message, Throwable t) {
+		if (isDebugEnabled()) {
+			write(LoggingEvent.DEBUG, message, t);
+		}
+	}
+
+	public static void debug(Throwable t) {
+		if (isDebugEnabled()) {
+			write(LoggingEvent.DEBUG, "error", t);
+		}
+	}
+
+	public static void debug(String message, String v) {
+		if (isDebugEnabled()) {
+			write(LoggingEvent.DEBUG, message, null, v);
+		}
+	}
+
+	public static void debug(String message, Object o) {
+		if (isDebugEnabled()) {
+			write(LoggingEvent.DEBUG, message, null, new LoggerDataWrapper(o));
+		}
+	}
+
+	public static void debug(String message, String v1, String v2) {
+		if (isDebugEnabled()) {
+			write(LoggingEvent.DEBUG, message, null, new LoggerDataWrapper(v1, v2));
+		}
+	}
+
+	public static void debug(String message, long v) {
+		if (isDebugEnabled()) {
+			write(LoggingEvent.DEBUG, message, null, new LoggerDataWrapper(v));
+		}
+	}
+
+	public static void debug0x(String message, long v) {
+		if (isDebugEnabled()) {
+			write(LoggingEvent.DEBUG, message, null, new LoggerDataWrapper("0x" + Long.toHexString(v)));
+		}
+	}
+
+	public static void debug(String message, long v1, long v2) {
+		if (isDebugEnabled()) {
+			write(LoggingEvent.DEBUG, message, null, new LoggerDataWrapper(v1, v2));
+		}
+	}
+
+	public static void debug(String message, boolean v) {
+		if (isDebugEnabled()) {
+			write(LoggingEvent.DEBUG, message, null, new LoggerDataWrapper(v));
+		}
+	}
+
+	public static void debugClassLoader(String message, Object obj) {
+		if (obj == null) {
+			write(LoggingEvent.DEBUG, message + " no class, no object", null, null);
+			return;
+		}
+		Class klass;
+		StringBuffer buf = new StringBuffer();
+		buf.append(message).append(" ");
+		if (obj instanceof Class) {
+			klass = (Class) obj;
+			buf.append("class ");
+		} else {
+			klass = obj.getClass();
+			buf.append("instance ");
+		}
+		buf.append(klass.getName() + " loaded by ");
+		if (klass.getClassLoader() != null) {
+			buf.append(klass.getClassLoader().hashCode());
+			buf.append(" ");
+			buf.append(klass.getClassLoader().getClass().getName());
+		} else {
+			buf.append("system");
+		}
+		write(LoggingEvent.DEBUG, buf.toString(), null, null);
+	}
+
+	public static void info(String message) {
+		if (isErrorEnabled()) {
+			write(LoggingEvent.INFO, message, null);
+		}
+	}
+
+	public static void info(String message, String data) {
+		if (isErrorEnabled()) {
+			write(LoggingEvent.INFO, message, null, data);
+		}
+	}
+
+	public static void warn(String message) {
+		if (isErrorEnabled()) {
+			write(LoggingEvent.WARN, message, null);
+		}
+	}
+
+	public static void error(String message) {
+		if (isErrorEnabled()) {
+			write(LoggingEvent.ERROR, "error " + message, null);
+		}
+	}
+
+	public static void error(String message, long v) {
+		if (isErrorEnabled()) {
+			write(LoggingEvent.ERROR, "error " + message, null, new LoggerDataWrapper(v));
+		}
+	}
+
+	public static void error(String message, String v) {
+		if (isErrorEnabled()) {
+			write(LoggingEvent.ERROR, "error " + message, null, v);
+		}
+	}
+
+	public static void error(String message, String v, Throwable t) {
+		if (isErrorEnabled()) {
+			write(LoggingEvent.ERROR, "error " + message, t, v);
+		}
+	}
+
+	public static void error(Throwable t) {
+		if (isErrorEnabled()) {
+			write(LoggingEvent.ERROR, "error " + t.toString(), t);
+		}
+	}
+
+	public static void error(String message, Throwable t) {
+		if (isErrorEnabled()) {
+			write(LoggingEvent.ERROR, "error " + message + " " + t.toString(), t);
+		}
+	}
+
+	private static void callAppenders(LoggingEvent event) {
+		for (Iterator iter = loggerAppenders.iterator(); iter.hasNext();) {
+			LoggerAppender a = (LoggerAppender) iter.next();
+			a.append(event);
+		}
+		;
+	}
+
+	/**
+	 * Add the Class which serves as entry point for log message location.
+	 * 
+	 * @param origin
+	 *            Class
+	 */
+	public static void addLogOrigin(Class origin) {
+		fqcnSet.add(origin.getName());
+	}
+
+	public static void addAppender(LoggerAppender newAppender) {
+		loggerAppenders.add(newAppender);
+	}
+
+	public static void removeAppender(LoggerAppender appender) {
+		loggerAppenders.remove(appender);
+	}
+
+	public static void removeAllAppenders() {
+		loggerAppenders.clear();
+	}
+
+}

Propchange: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/log/Logger.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/log/LoggerAppender.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/log/LoggerAppender.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/log/LoggerAppender.java (added)
+++ harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/log/LoggerAppender.java Mon May 26 15:20:19 2008
@@ -0,0 +1,25 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License 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 License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.microemu.log;
+
+public interface LoggerAppender {
+
+	public void append(LoggingEvent event);
+}

Propchange: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/log/LoggerAppender.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/log/LoggerDataWrapper.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/log/LoggerDataWrapper.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/log/LoggerDataWrapper.java (added)
+++ harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/log/LoggerDataWrapper.java Mon May 26 15:20:19 2008
@@ -0,0 +1,55 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License 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 License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.microemu.log;
+
+/**
+ * @author vlads
+ *
+ * Convinient method to format debug data
+ *
+ */
+public class LoggerDataWrapper {
+	
+	private String text; 
+
+	public LoggerDataWrapper(boolean v1) {
+		this.text = String.valueOf(v1);	
+	}
+	
+	public LoggerDataWrapper(long v1) {
+		this.text = String.valueOf(v1);	
+	}
+
+	public LoggerDataWrapper(Object v1) {
+		this.text = String.valueOf(v1);
+	}
+
+	public LoggerDataWrapper(long v1, long v2) {
+		this.text = String.valueOf(v1) + " " + String.valueOf(v2);	
+	}
+	
+	public LoggerDataWrapper(String v1, String v2) {
+		this.text = v1 + " " + v2;	
+	}
+	
+	public String toString() {
+		return this.text;
+	}
+}

Propchange: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/log/LoggerDataWrapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/log/LoggingEvent.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/log/LoggingEvent.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/log/LoggingEvent.java (added)
+++ harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/log/LoggingEvent.java Mon May 26 15:20:19 2008
@@ -0,0 +1,113 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License 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 License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.microemu.log;
+
+/**
+ * @author vlads
+ *
+ */
+public class LoggingEvent {
+
+	public final static int DEBUG = 1;
+
+	public final static int INFO = 2;
+
+	public final static int WARN = 3;
+
+	public final static int ERROR = 4;
+	
+	protected int level;
+
+	protected String message;
+    
+	protected StackTraceElement location; 
+
+	protected boolean hasData = false;
+
+	protected Object data;
+
+	protected Throwable throwable;
+
+	protected long eventTime;
+
+
+    public LoggingEvent() {
+    	this.eventTime = System.currentTimeMillis();
+    }
+    
+	public LoggingEvent(int level, String message, StackTraceElement location, Throwable throwable) {
+		this();
+		this.level = level;
+		this.message = message;
+		this.location = location;
+		this.throwable = throwable;
+	}
+	
+	public LoggingEvent(int level, String message, StackTraceElement location, Throwable throwable, Object data) {
+		this(level, message, location, throwable);
+		setData(data);
+	}
+
+	public Object getData() {
+		return this.data;
+	}
+
+	public void setData(Object data) {
+		this.data = data;
+		this.hasData = true;
+	}
+
+	public boolean hasData() {
+		return this.hasData;
+	}
+
+	public String getFormatedData() {
+		if (hasData()) {
+			if (getData() == null) {
+				return "{null}";
+			} else {
+				return getData().toString();
+			}
+		} else {
+			return "";
+		}
+	}
+	
+	public long getEventTime() {
+		return this.eventTime;
+	}
+
+	public int getLevel() {
+		return this.level;
+	}
+
+	public StackTraceElement getLocation() {
+		return this.location;
+	}
+
+	public String getMessage() {
+		return this.message;
+	}
+
+	public Throwable getThrowable() {
+		return this.throwable;
+	}
+
+}

Propchange: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/log/LoggingEvent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/log/QueueAppender.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/log/QueueAppender.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/log/QueueAppender.java (added)
+++ harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/log/QueueAppender.java Mon May 26 15:20:19 2008
@@ -0,0 +1,49 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License 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 License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.microemu.log;
+
+import java.util.LinkedList;
+import java.util.List;
+
+public class QueueAppender implements LoggerAppender {
+
+	private int buferSize;
+
+	private List queue = new LinkedList();
+
+	public QueueAppender(int buferSize) {
+		this.buferSize = buferSize;
+	}
+
+	public void append(LoggingEvent event) {
+		queue.add(event);
+		if (queue.size() > buferSize) {
+			queue.remove(0);
+		}
+	}
+
+	public LoggingEvent poll() {
+		if (queue.size() == 0) {
+			return null;
+		}
+		return (LoggingEvent) queue.remove(0);
+	}
+
+}

Propchange: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/log/QueueAppender.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/log/StdOutAppender.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/log/StdOutAppender.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/log/StdOutAppender.java (added)
+++ harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/log/StdOutAppender.java Mon May 26 15:20:19 2008
@@ -0,0 +1,69 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License 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 License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.microemu.log;
+
+import java.io.PrintStream;
+
+/**
+ * @author vlads
+ * 
+ */
+public class StdOutAppender implements LoggerAppender {
+
+	public static boolean enabled = true;
+	
+	public static String formatLocation(StackTraceElement ste) {
+		if (ste == null) {
+			return "";
+		}
+		// Make Line# clickable in eclipse
+		return ste.getClassName() + "." + ste.getMethodName() + "(" + ste.getFileName() + ":" + ste.getLineNumber()
+				+ ")";
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.microemu.log.LoggerAppender#append(org.microemu.log.LoggingEvent)
+	 */
+	public void append(LoggingEvent event) {
+		if (!enabled) {
+			return;
+		}
+		PrintStream out = System.out; 
+    	if (event.getLevel() == LoggingEvent.ERROR) {
+    		out = System.err;
+    	}
+    	String data = "";
+    	if (event.hasData()) {
+    		data = " [" + event.getFormatedData() + "]";
+    	}
+    	String location = formatLocation(event.getLocation());
+    	if (location.length() > 0) {
+    		location = "\n\t  " + location;
+    	}
+    	out.println(event.getMessage() + data + location);
+    	if (event.getThrowable() != null) {
+    		event.getThrowable().printStackTrace(out);
+    	}
+
+	}
+
+}

Propchange: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/log/StdOutAppender.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/util/JadMidletEntry.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/util/JadMidletEntry.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/util/JadMidletEntry.java (added)
+++ harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/util/JadMidletEntry.java Mon May 26 15:20:19 2008
@@ -0,0 +1,57 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License 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 License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+ 
+package org.microemu.util;
+
+
+public class JadMidletEntry
+{
+  
+  String name;
+  String icon;
+  String className;
+  
+  
+  JadMidletEntry(String name, String icon, String className)
+  {
+    this.name = name;
+    this.icon = icon;
+    this.className = className;
+  }
+  
+  
+  public String getClassName()
+  {
+    return className;
+  }
+  
+  
+  public String getName()
+  {
+    return name;
+  }
+  
+  
+  // remove it later
+  public String toString()
+  {
+    return name +"+"+ icon +"+"+ className;
+  }
+  
+}

Propchange: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/util/JadMidletEntry.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/util/JadProperties.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/util/JadProperties.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/util/JadProperties.java (added)
+++ harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/util/JadProperties.java Mon May 26 15:20:19 2008
@@ -0,0 +1,124 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License 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 License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.microemu.util;
+
+import java.util.Enumeration;
+import java.util.Properties;
+import java.util.Vector;
+
+public class JadProperties extends Properties {
+
+	private static final long serialVersionUID = 1L;
+
+	static String MIDLET_PREFIX = "MIDlet-";
+
+	Vector midletEntries = null;
+
+	String correctedJarURL = null;
+
+	public void clear() {
+		super.clear();
+
+		midletEntries = null;
+		correctedJarURL = null;
+	}
+
+	public String getSuiteName() {
+		return getProperty("MIDlet-Name");
+	}
+
+	public String getVersion() {
+		return getProperty("MIDlet-Version");
+	}
+
+	public String getVendor() {
+		return getProperty("MIDlet-Vendor");
+	}
+
+	public String getProfile() {
+		return getProperty("MicroEdition-Profile");
+	}
+
+	public String getConfiguration() {
+		return getProperty("MicroEdition-Configuration");
+	}
+
+	public String getJarURL() {
+		if (correctedJarURL != null) {
+			return correctedJarURL;
+		} else {
+			return getProperty("MIDlet-Jar-URL");
+		}
+	}
+
+	public void setCorrectedJarURL(String correctedJarURL) {
+		this.correctedJarURL = correctedJarURL;
+	}
+
+	public int getJarSize() {
+		return Integer.parseInt(getProperty("MIDlet-Jar-Size"));
+	}
+
+	public Vector getMidletEntries() {
+		String name, icon, className, test;
+		int pos;
+
+		if (midletEntries == null) {
+			midletEntries = new Vector();
+
+			for (Enumeration e = propertyNames(); e.hasMoreElements();) {
+				test = (String) e.nextElement();
+				if (test.startsWith(MIDLET_PREFIX)) {
+					try {
+						Integer.parseInt(test.substring(MIDLET_PREFIX.length()));
+						test = getProperty(test);
+						pos = test.indexOf(',');
+						name = test.substring(0, pos).trim();
+						icon = test.substring(pos + 1, test.indexOf(',', pos + 1)).trim();
+						className = test.substring(test.indexOf(',', pos + 1) + 1).trim();
+						midletEntries.addElement(new JadMidletEntry(name, icon, className));
+					} catch (NumberFormatException ex) {
+					}
+				}
+			}
+		}
+
+		return midletEntries;
+	}
+
+	public String getProperty(String key, String defaultValue) {
+		String result = super.getProperty(key, defaultValue);
+		if (result != null) {
+			return result.trim();
+		} else {
+			return null;
+		}
+	}
+
+	public String getProperty(String key) {
+		String result = super.getProperty(key);
+		if (result != null) {
+			return result.trim();
+		} else {
+			return null;
+		}
+	}
+
+}

Propchange: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/util/JadProperties.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/util/MemoryRecordStoreManager.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/util/MemoryRecordStoreManager.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/util/MemoryRecordStoreManager.java (added)
+++ harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/util/MemoryRecordStoreManager.java Mon May 26 15:20:19 2008
@@ -0,0 +1,118 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License 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 License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.microemu.util;
+
+import java.util.Enumeration;
+import java.util.Hashtable;
+
+import javax.microedition.rms.RecordStore;
+import javax.microedition.rms.RecordStoreException;
+import javax.microedition.rms.RecordStoreNotFoundException;
+
+import org.microemu.MicroEmulator;
+import org.microemu.RecordStoreManager;
+
+public class MemoryRecordStoreManager implements RecordStoreManager {
+	private Hashtable recordStores = new Hashtable();
+
+	private ExtendedRecordListener recordListener = null;
+
+	public void init(MicroEmulator emulator) {
+	}
+
+	public String getName() {
+		return "Memory record store";
+	}
+
+	public void deleteRecordStore(String recordStoreName) throws RecordStoreNotFoundException, RecordStoreException {
+		RecordStoreImpl recordStoreImpl = (RecordStoreImpl) recordStores.get(recordStoreName);
+		if (recordStoreImpl == null) {
+			throw new RecordStoreNotFoundException(recordStoreName);
+		}
+		if (recordStoreImpl.isOpen()) {
+			throw new RecordStoreException();
+		}
+		recordStores.remove(recordStoreName);
+
+		fireRecordStoreListener(ExtendedRecordListener.RECORDSTORE_DELETE, recordStoreName);
+	}
+
+	public RecordStore openRecordStore(String recordStoreName, boolean createIfNecessary)
+			throws RecordStoreNotFoundException {
+		RecordStoreImpl recordStoreImpl = (RecordStoreImpl) recordStores.get(recordStoreName);
+		if (recordStoreImpl == null) {
+			if (!createIfNecessary) {
+				throw new RecordStoreNotFoundException(recordStoreName);
+			}
+			recordStoreImpl = new RecordStoreImpl(this, recordStoreName);
+			recordStores.put(recordStoreName, recordStoreImpl);
+		}
+		recordStoreImpl.setOpen(true);
+		if (recordListener != null) {
+			recordStoreImpl.addRecordListener(recordListener);
+		}
+
+		fireRecordStoreListener(ExtendedRecordListener.RECORDSTORE_OPEN, recordStoreName);
+
+		return recordStoreImpl;
+	}
+
+	public String[] listRecordStores() {
+		String[] result = null;
+
+		int i = 0;
+		for (Enumeration e = recordStores.keys(); e.hasMoreElements();) {
+			if (result == null) {
+				result = new String[recordStores.size()];
+			}
+			result[i] = (String) e.nextElement();
+			i++;
+		}
+
+		return result;
+	}
+
+	public void saveChanges(RecordStoreImpl recordStoreImpl) {
+	}
+
+	public void init() {
+		deleteStores();
+	}
+
+	public void deleteStores() {
+		if (recordStores != null)
+			recordStores.clear();
+	}
+
+	public int getSizeAvailable(RecordStoreImpl recordStoreImpl) {
+		// FIXME returns too much
+		return (int) Runtime.getRuntime().freeMemory();
+	}
+
+	public void setRecordListener(ExtendedRecordListener recordListener) {
+		this.recordListener = recordListener;
+	}
+
+	public void fireRecordStoreListener(int type, String recordStoreName) {
+		if (recordListener != null) {
+			recordListener.recordStoreEvent(type, System.currentTimeMillis(), recordStoreName);
+		}
+	}
+}

Propchange: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/util/MemoryRecordStoreManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/util/ThreadUtils.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/util/ThreadUtils.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/util/ThreadUtils.java (added)
+++ harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/util/ThreadUtils.java Mon May 26 15:20:19 2008
@@ -0,0 +1,88 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License 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 License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.microemu.util;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.util.Timer;
+
+public class ThreadUtils {
+
+	private static boolean java13 = false;
+	
+	private static boolean java14 = false;
+	
+	/**
+     * Creates a new timer whose associated thread has the specified name in Java 1.5.
+	 * 
+	 * @param name the name of the associated thread
+     *
+	 */
+	public static Timer createTimer(String name) {
+		try {
+			Constructor c = Timer.class.getConstructor(new Class[] { String.class });
+			return (Timer)c.newInstance(new Object[]{name});
+		} catch (Throwable e) {
+			// In cany case create new Timer
+			return new Timer();
+		}
+	}
+
+	public static String getCallLocation(String fqn) {
+		if (!java13) {
+			try {
+				StackTraceElement[] ste = new Throwable().getStackTrace();
+				for (int i = 0; i < ste.length - 1; i++) {
+					if (fqn.equals(ste[i].getClassName())) {
+						StackTraceElement callLocation = ste[i + 1];
+						String nextClassName = callLocation.getClassName();
+						if (nextClassName.equals(fqn)) {
+							continue;
+						}
+						return callLocation.toString();
+					}
+				}
+			} catch (Throwable e) {
+				java13 = true;
+			}
+		}
+		return null;
+	}
+	
+	public static String getTreadStackTrace(Thread t) {
+		if (java14) {
+			return "";
+		}
+		try {
+			// Java 1.5 thread.getStackTrace();
+			Method m = t.getClass().getMethod("getStackTrace", null);
+			
+			StackTraceElement[] trace = (StackTraceElement[])m.invoke(t, null);
+			StringBuffer b = new StringBuffer();  
+			for (int i=0; i < trace.length; i++) {
+			    b.append("\n\tat ").append(trace[i]);
+			}
+			return b.toString();
+		} catch (Throwable e) {
+			java14 = true;
+			return "";
+		}
+	}
+}

Propchange: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/util/ThreadUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/microemulator/microemu-javase/src/main/resources/org/microemu/device/default/123.png
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase/src/main/resources/org/microemu/device/default/123.png?rev=660326&view=auto
==============================================================================
Binary file - no diff available.

Propchange: harmony/enhanced/microemulator/microemu-javase/src/main/resources/org/microemu/device/default/123.png
------------------------------------------------------------------------------
    svn:mime-type = image/png

Added: harmony/enhanced/microemulator/microemu-javase/src/main/resources/org/microemu/device/default/abc_lower.png
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase/src/main/resources/org/microemu/device/default/abc_lower.png?rev=660326&view=auto
==============================================================================
Binary file - no diff available.

Propchange: harmony/enhanced/microemulator/microemu-javase/src/main/resources/org/microemu/device/default/abc_lower.png
------------------------------------------------------------------------------
    svn:mime-type = image/png

Added: harmony/enhanced/microemulator/microemu-javase/src/main/resources/org/microemu/device/default/abc_upper.png
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase/src/main/resources/org/microemu/device/default/abc_upper.png?rev=660326&view=auto
==============================================================================
Binary file - no diff available.

Propchange: harmony/enhanced/microemulator/microemu-javase/src/main/resources/org/microemu/device/default/abc_upper.png
------------------------------------------------------------------------------
    svn:mime-type = image/png



Mime
View raw message