You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by te...@apache.org on 2008/05/27 00:21:57 UTC
svn commit: r660326 [7/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/androi...
Added: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEDeviceButtonsHelper.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEDeviceButtonsHelper.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEDeviceButtonsHelper.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEDeviceButtonsHelper.java Mon May 26 15:20:19 2008
@@ -0,0 +1,144 @@
+/*
+ * 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.j2se;
+
+import java.awt.event.KeyEvent;
+import java.awt.event.MouseEvent;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.WeakHashMap;
+
+import org.microemu.device.Device;
+import org.microemu.device.DeviceFactory;
+import org.microemu.device.impl.ButtonName;
+import org.microemu.device.impl.SoftButton;
+import org.microemu.log.Logger;
+
+/**
+ * Maps keyboard and mouse events to Buttons
+ *
+ * @author vlads
+ *
+ */
+public class J2SEDeviceButtonsHelper {
+
+ private static Map devices = new WeakHashMap();
+
+ private static class DeviceInformation {
+
+ Map keyboardKeyCodes = new HashMap();
+
+ Map keyboardCharCodes = new HashMap();
+
+ Map functions = new HashMap();
+ }
+
+ public static SoftButton getSoftButton(MouseEvent ev) {
+ Iterator it = DeviceFactory.getDevice().getSoftButtons().iterator();
+ while (it.hasNext()) {
+ SoftButton button = (SoftButton) it.next();
+ if (button.isVisible()) {
+ org.microemu.device.impl.Rectangle pb = button.getPaintable();
+ if (pb != null && pb.contains(ev.getX(), ev.getY())) {
+ return button;
+ }
+ }
+ }
+ return null;
+ }
+
+ public static J2SEButton getSkinButton(MouseEvent ev) {
+ for (Enumeration en = DeviceFactory.getDevice().getButtons().elements(); en.hasMoreElements();) {
+ J2SEButton button = (J2SEButton) en.nextElement();
+ if (button.getShape() != null) {
+ if (button.getShape().contains(ev.getX(), ev.getY())) {
+ return button;
+ }
+ }
+ }
+ return null;
+ }
+
+ public static J2SEButton getButton(KeyEvent ev) {
+ DeviceInformation inf = getDeviceInformation();
+ J2SEButton button = (J2SEButton) inf.keyboardCharCodes.get(new Integer(ev.getKeyChar()));
+ if (button != null) {
+ return button;
+ }
+ return (J2SEButton) inf.keyboardKeyCodes.get(new Integer(ev.getKeyCode()));
+ }
+
+ public static J2SEButton getButton(ButtonName functionalName) {
+ DeviceInformation inf = getDeviceInformation();
+ return (J2SEButton) inf.functions.get(functionalName);
+ }
+
+ private static DeviceInformation getDeviceInformation() {
+ Device dev = DeviceFactory.getDevice();
+ DeviceInformation inf;
+ synchronized (J2SEDeviceButtonsHelper.class) {
+ inf = (DeviceInformation) devices.get(dev);
+ if (inf == null) {
+ inf = createDeviceInformation(dev);
+ }
+ }
+ return inf;
+ }
+
+ private static DeviceInformation createDeviceInformation(Device dev) {
+ DeviceInformation inf = new DeviceInformation();
+ boolean hasModeChange = false;
+ for (Enumeration en = dev.getButtons().elements(); en.hasMoreElements();) {
+ J2SEButton button = (J2SEButton) en.nextElement();
+ int keyCodes[] = button.getKeyboardKeyCodes();
+ for (int i = 0; i < keyCodes.length; i++) {
+ inf.keyboardKeyCodes.put(new Integer(keyCodes[i]), button);
+ }
+ char charCodes[] = button.getKeyboardCharCodes();
+ for (int i = 0; i < charCodes.length; i++) {
+ inf.keyboardCharCodes.put(new Integer(charCodes[i]), button);
+ }
+ inf.functions.put(button.getFunctionalName(), button);
+ if (button.isModeChange()) {
+ hasModeChange = true;
+ }
+ }
+
+ // Correction to missing code in xml
+ if (!hasModeChange) {
+ J2SEButton button = (J2SEButton) inf.functions.get(ButtonName.KEY_POUND);
+ if (button != null) {
+ button.setModeChange();
+ } else {
+ Logger.warn("Device has no ModeChange and POUND buttons");
+ }
+ }
+
+ if (inf.functions.get(ButtonName.DELETE) == null) {
+ dev.getButtons().add(new J2SEButton(ButtonName.DELETE));
+ }
+ if (inf.functions.get(ButtonName.BACK_SPACE) == null) {
+ dev.getButtons().add(new J2SEButton(ButtonName.BACK_SPACE));
+ }
+ return inf;
+ }
+}
Propchange: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEDeviceButtonsHelper.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEDeviceDisplay.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEDeviceDisplay.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEDeviceDisplay.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEDeviceDisplay.java Mon May 26 15:20:19 2008
@@ -0,0 +1,608 @@
+/*
+ * 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.j2se;
+
+import java.awt.Font;
+import java.awt.Graphics;
+import java.awt.MediaTracker;
+import java.awt.Toolkit;
+import java.awt.image.BufferedImage;
+import java.awt.image.FilteredImageSource;
+import java.awt.image.ImageFilter;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Vector;
+
+import javax.microedition.lcdui.Canvas;
+import javax.microedition.lcdui.Displayable;
+import javax.microedition.lcdui.Image;
+import javax.microedition.lcdui.game.Sprite;
+
+import org.microemu.DisplayAccess;
+import org.microemu.EmulatorContext;
+import org.microemu.MIDletAccess;
+import org.microemu.MIDletBridge;
+import org.microemu.app.util.IOUtils;
+import org.microemu.device.Device;
+import org.microemu.device.DeviceFactory;
+import org.microemu.device.InputMethod;
+import org.microemu.device.MutableImage;
+import org.microemu.device.impl.Button;
+import org.microemu.device.impl.Color;
+import org.microemu.device.impl.DeviceDisplayImpl;
+import org.microemu.device.impl.PositionedImage;
+import org.microemu.device.impl.Rectangle;
+import org.microemu.device.impl.Shape;
+import org.microemu.device.impl.SoftButton;
+
+public class J2SEDeviceDisplay implements DeviceDisplayImpl {
+ EmulatorContext context;
+
+ Rectangle displayRectangle;
+
+ Rectangle displayPaintable;
+
+ boolean isColor;
+
+ int numColors;
+
+ int numAlphaLevels;
+
+ java.awt.Color backgroundColor;
+
+ java.awt.Color foregroundColor;
+
+ PositionedImage mode123Image;
+
+ PositionedImage modeAbcUpperImage;
+
+ PositionedImage modeAbcLowerImage;
+
+ boolean resizable;
+
+ public J2SEDeviceDisplay(EmulatorContext context) {
+ this.context = context;
+ }
+
+ public MutableImage getDisplayImage() {
+ return context.getDisplayComponent().getDisplayImage();
+ }
+
+ public int getHeight() {
+ return displayPaintable.height;
+ }
+
+ public int getWidth() {
+ return displayPaintable.width;
+ }
+
+ public int getFullHeight() {
+ return displayRectangle.height;
+ }
+
+ public int getFullWidth() {
+ return displayRectangle.width;
+ }
+
+ public boolean isColor() {
+ return isColor;
+ }
+
+ public boolean isFullScreenMode() {
+ MIDletAccess ma = MIDletBridge.getMIDletAccess();
+ if (ma == null) {
+ return false;
+ } else {
+ DisplayAccess da = ma.getDisplayAccess();
+ if (da == null) {
+ return false;
+ } else {
+ return da.isFullScreenMode();
+ }
+ }
+ }
+
+ public int numAlphaLevels() {
+ return numAlphaLevels;
+ }
+
+ public int numColors() {
+ return numColors;
+ }
+
+ public void paintControls(Graphics g) {
+ Device device = DeviceFactory.getDevice();
+
+ g.setColor(backgroundColor);
+ g.fillRect(0, 0, displayRectangle.width, displayPaintable.y);
+ g.fillRect(0, displayPaintable.y, displayPaintable.x, displayPaintable.height);
+ g.fillRect(displayPaintable.x + displayPaintable.width, displayPaintable.y, displayRectangle.width
+ - displayPaintable.x - displayPaintable.width, displayPaintable.height);
+ g.fillRect(0, displayPaintable.y + displayPaintable.height, displayRectangle.width, displayRectangle.height
+ - displayPaintable.y - displayPaintable.height);
+
+ g.setColor(foregroundColor);
+ for (Enumeration s = device.getSoftButtons().elements(); s.hasMoreElements();) {
+ ((J2SESoftButton) s.nextElement()).paint(g);
+ }
+
+ int inputMode = device.getInputMethod().getInputMode();
+ if (inputMode == InputMethod.INPUT_123) {
+ g.drawImage(((J2SEImmutableImage) mode123Image.getImage()).getImage(), mode123Image.getRectangle().x,
+ mode123Image.getRectangle().y, null);
+ } else if (inputMode == InputMethod.INPUT_ABC_UPPER) {
+ g.drawImage(((J2SEImmutableImage) modeAbcUpperImage.getImage()).getImage(), modeAbcUpperImage
+ .getRectangle().x, modeAbcUpperImage.getRectangle().y, null);
+ } else if (inputMode == InputMethod.INPUT_ABC_LOWER) {
+ g.drawImage(((J2SEImmutableImage) modeAbcLowerImage.getImage()).getImage(), modeAbcLowerImage
+ .getRectangle().x, modeAbcLowerImage.getRectangle().y, null);
+ }
+ }
+
+ public void paintDisplayable(Graphics g, int x, int y, int width, int height) {
+ MIDletAccess ma = MIDletBridge.getMIDletAccess();
+ if (ma == null) {
+ return;
+ }
+ DisplayAccess da = ma.getDisplayAccess();
+ if (da == null) {
+ return;
+ }
+ Displayable current = da.getCurrent();
+ if (current == null) {
+ return;
+ }
+
+ g.setColor(foregroundColor);
+
+ java.awt.Shape oldclip = g.getClip();
+ if (!(current instanceof Canvas) || ((Canvas) current).getWidth() != displayRectangle.width
+ || ((Canvas) current).getHeight() != displayRectangle.height) {
+ g.translate(displayPaintable.x, displayPaintable.y);
+ }
+ g.setClip(x, y, width, height);
+ Font oldf = g.getFont();
+ ma.getDisplayAccess().paint(new J2SEDisplayGraphics((java.awt.Graphics2D) g, getDisplayImage()));
+ g.setFont(oldf);
+ if (!(current instanceof Canvas) || ((Canvas) current).getWidth() != displayRectangle.width
+ || ((Canvas) current).getHeight() != displayRectangle.height) {
+ g.translate(-displayPaintable.x, -displayPaintable.y);
+ }
+ g.setClip(oldclip);
+ }
+
+ public void repaint(int x, int y, int width, int height) {
+ context.getDisplayComponent().repaintRequest(x, y, width, height);
+ }
+
+ public void setScrollDown(boolean state) {
+ Enumeration en = DeviceFactory.getDevice().getSoftButtons().elements();
+ while (en.hasMoreElements()) {
+ SoftButton button = (SoftButton) en.nextElement();
+ if (button.getType() == SoftButton.TYPE_ICON && button.getName().equals("down")) {
+ button.setVisible(state);
+ }
+ }
+ }
+
+ public void setScrollUp(boolean state) {
+ Enumeration en = DeviceFactory.getDevice().getSoftButtons().elements();
+ while (en.hasMoreElements()) {
+ SoftButton button = (SoftButton) en.nextElement();
+ if (button.getType() == SoftButton.TYPE_ICON && button.getName().equals("up")) {
+ button.setVisible(state);
+ }
+ }
+ }
+
+ public boolean isResizable() {
+ return resizable;
+ }
+
+ public void setResizable(boolean state) {
+ resizable = state;
+ }
+
+ public Rectangle getDisplayRectangle() {
+ return displayRectangle;
+ }
+
+ public Rectangle getDisplayPaintable() {
+ return displayPaintable;
+ }
+
+ public Color getBackgroundColor() {
+ return new Color(backgroundColor.getRGB());
+ }
+
+ public Color getForegroundColor() {
+ return new Color(foregroundColor.getRGB());
+ }
+
+ public Image createImage(int width, int height) {
+ if (width <= 0 || height <= 0) {
+ throw new IllegalArgumentException();
+ }
+
+ return new J2SEMutableImage(width, height);
+ }
+
+ public Image createImage(String name) throws IOException {
+ return getImage(name);
+ }
+
+ public Image createImage(javax.microedition.lcdui.Image source) {
+ if (source.isMutable()) {
+ return new J2SEImmutableImage((J2SEMutableImage) source);
+ } else {
+ return source;
+ }
+ }
+
+ // Andres Navarro
+ public Image createImage(InputStream is) throws IOException {
+ if (is == null) {
+ throw new IOException();
+ }
+ return getImage(is);
+ }
+
+ public Image createRGBImage(int[] rgb, int width, int height, boolean processAlpha) {
+ if (rgb == null)
+ throw new NullPointerException();
+ if (width <= 0 || height <= 0)
+ throw new IllegalArgumentException();
+
+ BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
+
+ if (!processAlpha) {
+ // we should eliminate the transparency info
+ // but can't touch the original array
+ // so we just create another
+ int l = rgb.length;
+
+ int[] rgbAux = new int[l];
+ for (int i = 0; i < l; i++)
+ rgbAux[i] = rgb[i] | 0xff000000;
+ rgb = rgbAux;
+ }
+
+ img.setRGB(0, 0, width, height, rgb, 0, width);
+
+ // now apply the corresponding filter
+ ImageFilter filter = null;
+ if (isColor()) {
+ if (backgroundColor.getRed() != 255 || backgroundColor.getGreen() != 255
+ || backgroundColor.getBlue() != 255 || foregroundColor.getRed() != 0
+ || foregroundColor.getGreen() != 0 || foregroundColor.getBlue() != 0) {
+ filter = new RGBImageFilter();
+ }
+ } else {
+ if (numColors() == 2) {
+ filter = new BWImageFilter();
+ } else {
+ filter = new GrayImageFilter();
+ }
+ }
+ if (filter != null) {
+ FilteredImageSource imageSource = new FilteredImageSource(img.getSource(), filter);
+ return new J2SEImmutableImage(Toolkit.getDefaultToolkit().createImage(imageSource));
+ } else {
+ return new J2SEImmutableImage(img);
+ }
+ }
+
+ public Image createImage(Image image, int x, int y, int width, int height, int transform) {
+ if (image == null)
+ throw new NullPointerException();
+ if (x + width > image.getWidth() || y + height > image.getHeight() || width <= 0 || height <= 0 || x < 0
+ || y < 0)
+ throw new IllegalArgumentException("Area out of Image");
+
+ int[] rgbData = new int[height * width];
+ int[] rgbTransformedData = new int[height * width];
+ if (image instanceof J2SEImmutableImage) {
+ ((J2SEImmutableImage) image).getRGB(rgbData, 0, width, x, y, width, height);
+ } else {
+ ((J2SEMutableImage) image).getRGB(rgbData, 0, width, x, y, width, height);
+ }
+
+ int colIncr, rowIncr, offset;
+
+ switch (transform) {
+ case Sprite.TRANS_NONE: {
+ offset = 0;
+ colIncr = 1;
+ rowIncr = 0;
+ break;
+ }
+ case Sprite.TRANS_ROT90: {
+ offset = (height - 1) * width;
+ colIncr = -width;
+ rowIncr = (height * width) + 1;
+ int temp = width;
+ width = height;
+ height = temp;
+ break;
+ }
+ case Sprite.TRANS_ROT180: {
+ offset = (height * width) - 1;
+ colIncr = -1;
+ rowIncr = 0;
+ break;
+ }
+ case Sprite.TRANS_ROT270: {
+ offset = width - 1;
+ colIncr = width;
+ rowIncr = -(height * width) - 1;
+ int temp = width;
+ width = height;
+ height = temp;
+ break;
+ }
+ case Sprite.TRANS_MIRROR: {
+ offset = width - 1;
+ colIncr = -1;
+ rowIncr = width << 1;
+ break;
+ }
+ case Sprite.TRANS_MIRROR_ROT90: {
+ offset = (height * width) - 1;
+ colIncr = -width;
+ rowIncr = (height * width) - 1;
+ int temp = width;
+ width = height;
+ height = temp;
+ break;
+ }
+ case Sprite.TRANS_MIRROR_ROT180: {
+ offset = (height - 1) * width;
+ colIncr = 1;
+ rowIncr = -(width << 1);
+ break;
+ }
+ case Sprite.TRANS_MIRROR_ROT270: {
+ offset = 0;
+ colIncr = width;
+ rowIncr = -(height * width) + 1;
+ int temp = width;
+ width = height;
+ height = temp;
+ break;
+ }
+ default:
+ throw new IllegalArgumentException("Bad transform");
+ }
+
+ // now the loops!
+ for (int row = 0, i = 0; row < height; row++, offset += rowIncr) {
+ for (int col = 0; col < width; col++, offset += colIncr, i++) {
+ rgbTransformedData[i] = rgbData[offset];
+ }
+ }
+ // to aid gc
+ rgbData = null;
+ image = null;
+
+ return createRGBImage(rgbTransformedData, width, height, true);
+ }
+
+ // Andres Navarro
+
+ public Image createImage(byte[] imageData, int imageOffset, int imageLength) {
+ ByteArrayInputStream is = new ByteArrayInputStream(imageData, imageOffset, imageLength);
+ try {
+ return getImage(is);
+ } catch (IOException ex) {
+ throw new IllegalArgumentException(ex.toString());
+ }
+ }
+
+ public void setNumAlphaLevels(int i) {
+ numAlphaLevels = i;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.barteo.emulator.device.impl.DeviceDisplayImpl#setNumColors(int)
+ */
+ public void setNumColors(int i) {
+ numColors = i;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.barteo.emulator.device.impl.DeviceDisplayImpl#setIsColor(boolean)
+ */
+ public void setIsColor(boolean b) {
+ isColor = b;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.barteo.emulator.device.impl.DeviceDisplayImpl#setBackgroundColor(java.awt.Color)
+ */
+ public void setBackgroundColor(Color color) {
+ backgroundColor = new java.awt.Color(color.getRGB());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.barteo.emulator.device.impl.DeviceDisplayImpl#setForegroundColor(java.awt.Color)
+ */
+ public void setForegroundColor(Color color) {
+ foregroundColor = new java.awt.Color(color.getRGB());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.barteo.emulator.device.impl.DeviceDisplayImpl#setDisplayRectangle(java.awt.Rectangle)
+ */
+ public void setDisplayRectangle(Rectangle rectangle) {
+ displayRectangle = rectangle;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.barteo.emulator.device.impl.DeviceDisplayImpl#setDisplayPaintable(java.awt.Rectangle)
+ */
+ public void setDisplayPaintable(Rectangle rectangle) {
+ displayPaintable = rectangle;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.barteo.emulator.device.impl.DeviceDisplayImpl#setMode123Image(com.barteo.emulator.device.impl.PositionedImage)
+ */
+ public void setMode123Image(PositionedImage object) {
+ mode123Image = object;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.barteo.emulator.device.impl.DeviceDisplayImpl#setModeAbcLowerImage(com.barteo.emulator.device.impl.PositionedImage)
+ */
+ public void setModeAbcLowerImage(PositionedImage object) {
+ modeAbcLowerImage = object;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.barteo.emulator.device.impl.DeviceDisplayImpl#setModeAbcUpperImage(com.barteo.emulator.device.impl.PositionedImage)
+ */
+ public void setModeAbcUpperImage(PositionedImage object) {
+ modeAbcUpperImage = object;
+ }
+
+ public Image createSystemImage(URL url) throws IOException {
+ java.awt.Image resultImage = Toolkit.getDefaultToolkit().createImage(url);
+
+ // TODO not elegant solution, maybe use ImageObserver in
+ // image.getWitdth(..) instead
+ MediaTracker mediaTracker = new MediaTracker(new java.awt.Canvas());
+ mediaTracker.addImage(resultImage, 0);
+ try {
+ mediaTracker.waitForID(0);
+ } catch (InterruptedException ex) {
+ }
+ if (mediaTracker.isErrorID(0)) {
+ throw new IOException();
+ }
+
+ return new J2SEImmutableImage(resultImage);
+ }
+
+ private Image getImage(String str) throws IOException {
+ // TODO not always true, there could be some loading images before
+ // invoke startApp, right now getCurrentMIDlet returns prevoius MIDlet
+ Object midlet = MIDletBridge.getCurrentMIDlet();
+ if (midlet == null) {
+ midlet = getClass();
+ }
+ InputStream is = midlet.getClass().getResourceAsStream(str);
+
+ if (is == null) {
+ throw new IOException(str + " could not be found.");
+ }
+ try {
+ return getImage(is);
+ } finally {
+ IOUtils.closeQuietly(is);
+ }
+ }
+
+ private Image getImage(InputStream is) throws IOException {
+ byte[] imageBytes = new byte[1024];
+ int num;
+ ByteArrayOutputStream ba = new ByteArrayOutputStream();
+ while ((num = is.read(imageBytes)) != -1) {
+ ba.write(imageBytes, 0, num);
+ }
+
+ java.awt.Image image = Toolkit.getDefaultToolkit().createImage(ba.toByteArray());
+
+ ImageFilter filter = null;
+ if (isColor()) {
+ if (backgroundColor.getRed() != 255 || backgroundColor.getGreen() != 255
+ || backgroundColor.getBlue() != 255 || foregroundColor.getRed() != 0
+ || foregroundColor.getGreen() != 0 || foregroundColor.getBlue() != 0) {
+ filter = new RGBImageFilter();
+ }
+ } else {
+ if (numColors() == 2) {
+ filter = new BWImageFilter();
+ } else {
+ filter = new GrayImageFilter();
+ }
+ }
+ java.awt.Image resultImage;
+ if (filter != null) {
+ FilteredImageSource imageSource = new FilteredImageSource(image.getSource(), filter);
+ resultImage = Toolkit.getDefaultToolkit().createImage(imageSource);
+ } else {
+ resultImage = image;
+ }
+
+ // TODO not elegant solution, maybe use ImageObserver in
+ // image.getWitdth(..) instead
+ MediaTracker mediaTracker = new MediaTracker(new java.awt.Canvas());
+ mediaTracker.addImage(resultImage, 0);
+ try {
+ mediaTracker.waitForID(0);
+ } catch (InterruptedException ex) {
+ }
+ if (mediaTracker.isErrorID(0)) {
+ throw new IOException();
+ }
+
+ return new J2SEImmutableImage(resultImage);
+ }
+
+ public Button createButton(int skinVersion, String name, org.microemu.device.impl.Shape shape, int keyCode,
+ String keyboardKeys, String keyboardChars, Hashtable inputToChars, boolean modeChange) {
+ return new J2SEButton(skinVersion, name, shape, keyCode, keyboardKeys, keyboardChars, inputToChars, modeChange);
+ }
+
+ public SoftButton createSoftButton(int skinVersion, String name, Shape shape, int keyCode, String keyboardKeys,
+ Rectangle paintable, String alignmentName, Vector commands, javax.microedition.lcdui.Font font) {
+ return new J2SESoftButton(skinVersion, name, shape, keyCode, keyboardKeys, paintable, alignmentName, commands,
+ font);
+ }
+
+ public SoftButton createSoftButton(int skinVersion, String name, Rectangle paintable, Image normalImage,
+ Image pressedImage) {
+ return new J2SESoftButton(skinVersion, name, paintable, normalImage, pressedImage);
+ }
+
+}
\ No newline at end of file
Propchange: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEDeviceDisplay.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEDisplayGraphics.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEDisplayGraphics.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEDisplayGraphics.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEDisplayGraphics.java Mon May 26 15:20:19 2008
@@ -0,0 +1,484 @@
+/*
+ * 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.j2se;
+
+import java.awt.Color;
+import java.awt.Graphics2D;
+import java.awt.Rectangle;
+import java.awt.RenderingHints;
+import java.util.HashMap;
+
+import javax.microedition.lcdui.Image;
+import javax.microedition.lcdui.game.Sprite;
+
+import org.microemu.device.Device;
+import org.microemu.device.DeviceFactory;
+import org.microemu.device.DisplayGraphics;
+import org.microemu.device.MutableImage;
+
+public class J2SEDisplayGraphics extends javax.microedition.lcdui.Graphics implements DisplayGraphics {
+ // Andres Navarro
+ private java.awt.Graphics2D g;
+
+ // Andres Navarro
+
+ private MutableImage image;
+
+ private int color = 0;
+
+ // TODO use IntHashMap
+ private HashMap colorCache = new HashMap();
+
+ // Access to the AWT clip is expensive in memory allocation
+ private Rectangle clip;
+
+ private javax.microedition.lcdui.Font currentFont = javax.microedition.lcdui.Font.getDefaultFont();
+
+ private java.awt.image.RGBImageFilter filter = null;
+
+ // Andres Navarro
+ public J2SEDisplayGraphics(java.awt.Graphics2D a_g, MutableImage a_image)
+ // Andres Navarro
+ {
+ this.g = a_g;
+ this.image = a_image;
+
+ this.clip = a_g.getClipBounds();
+
+ Device device = DeviceFactory.getDevice();
+ J2SEFontManager fontManager = (J2SEFontManager) device.getFontManager();
+
+ J2SEFont tmpFont = (J2SEFont) fontManager.getFont(currentFont);
+ this.g.setFont(tmpFont.getFont());
+ if (fontManager.getAntialiasing()) {
+ this.g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
+ } else {
+ this.g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
+ }
+
+ J2SEDeviceDisplay display = (J2SEDeviceDisplay) device.getDeviceDisplay();
+ if (display.isColor()) {
+ if (display.backgroundColor.getRed() != 255 || display.backgroundColor.getGreen() != 255 || display.backgroundColor.getBlue() != 255 ||
+ display.foregroundColor.getRed() != 0 || display.foregroundColor.getGreen() != 0 || display.foregroundColor.getBlue() != 0) {
+ this.filter = new RGBImageFilter();
+ }
+ } else {
+ if (display.numColors() == 2) {
+ this.filter = new BWImageFilter();
+ } else {
+ this.filter = new GrayImageFilter();
+ }
+ }
+ }
+
+ public MutableImage getImage() {
+ return image;
+ }
+
+ public int getColor() {
+ return color;
+ }
+
+ public void setColor(int RGB) {
+ color = RGB;
+
+ Color awtColor = (Color) colorCache.get(new Integer(RGB));
+ if (awtColor == null) {
+ if (filter != null) {
+ awtColor = new Color(filter.filterRGB(0, 0, color));
+ } else {
+ awtColor = new Color(RGB);
+ }
+ colorCache.put(new Integer(RGB), awtColor);
+ }
+ g.setColor(awtColor);
+ }
+
+ public javax.microedition.lcdui.Font getFont() {
+ return currentFont;
+ }
+
+ public void setFont(javax.microedition.lcdui.Font font) {
+ currentFont = font;
+ J2SEFont tmpFont = (J2SEFont) ((J2SEFontManager) DeviceFactory.getDevice().getFontManager())
+ .getFont(currentFont);
+ g.setFont(tmpFont.getFont());
+ }
+
+ public void clipRect(int x, int y, int width, int height) {
+ g.clipRect(x, y, width, height);
+ clip = g.getClipBounds();
+ }
+
+ public void setClip(int x, int y, int width, int height) {
+ g.setClip(x, y, width, height);
+ clip.x = x;
+ clip.y = y;
+ clip.width = width;
+ clip.height = height;
+ }
+
+ public int getClipX() {
+ return clip.x;
+ }
+
+ public int getClipY() {
+ return clip.y;
+ }
+
+ public int getClipHeight() {
+ return clip.height;
+ }
+
+ public int getClipWidth() {
+ return clip.width;
+ }
+
+ public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
+ g.drawArc(x, y, width, height, startAngle, arcAngle);
+ }
+
+ public void drawImage(Image img, int x, int y, int anchor) {
+ int newx = x;
+ int newy = y;
+
+ if (anchor == 0) {
+ anchor = javax.microedition.lcdui.Graphics.TOP | javax.microedition.lcdui.Graphics.LEFT;
+ }
+
+ if ((anchor & javax.microedition.lcdui.Graphics.RIGHT) != 0) {
+ newx -= img.getWidth();
+ } else if ((anchor & javax.microedition.lcdui.Graphics.HCENTER) != 0) {
+ newx -= img.getWidth() / 2;
+ }
+ if ((anchor & javax.microedition.lcdui.Graphics.BOTTOM) != 0) {
+ newy -= img.getHeight();
+ } else if ((anchor & javax.microedition.lcdui.Graphics.VCENTER) != 0) {
+ newy -= img.getHeight() / 2;
+ }
+
+ if (img.isMutable()) {
+ g.drawImage(((J2SEMutableImage) img).getImage(), newx, newy, null);
+ } else {
+ g.drawImage(((J2SEImmutableImage) img).getImage(), newx, newy, null);
+ }
+ }
+
+ public void drawLine(int x1, int y1, int x2, int y2) {
+ g.drawLine(x1, y1, x2, y2);
+ }
+
+ public void drawRect(int x, int y, int width, int height) {
+ drawLine(x, y, x + width, y);
+ drawLine(x + width, y, x + width, y + height);
+ drawLine(x + width, y + height, x, y + height);
+ drawLine(x, y + height, x, y);
+ }
+
+ public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) {
+ g.drawRoundRect(x, y, width, height, arcWidth, arcHeight);
+ }
+
+ public void drawString(String str, int x, int y, int anchor) {
+ int newx = x;
+ int newy = y;
+
+ if (anchor == 0) {
+ anchor = javax.microedition.lcdui.Graphics.TOP | javax.microedition.lcdui.Graphics.LEFT;
+ }
+
+ if ((anchor & javax.microedition.lcdui.Graphics.TOP) != 0) {
+ newy += g.getFontMetrics().getAscent();
+ } else if ((anchor & javax.microedition.lcdui.Graphics.BOTTOM) != 0) {
+ newy -= g.getFontMetrics().getDescent();
+ }
+ if ((anchor & javax.microedition.lcdui.Graphics.HCENTER) != 0) {
+ newx -= g.getFontMetrics().stringWidth(str) / 2;
+ } else if ((anchor & javax.microedition.lcdui.Graphics.RIGHT) != 0) {
+ newx -= g.getFontMetrics().stringWidth(str);
+ }
+
+ g.drawString(str, newx, newy);
+
+ if ((currentFont.getStyle() & javax.microedition.lcdui.Font.STYLE_UNDERLINED) != 0) {
+ g.drawLine(newx, newy + 1, newx + g.getFontMetrics().stringWidth(str), newy + 1);
+ }
+ }
+
+ public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
+ g.fillArc(x, y, width, height, startAngle, arcAngle);
+ }
+
+ public void fillRect(int x, int y, int width, int height) {
+ g.fillRect(x, y, width, height);
+ }
+
+ public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) {
+ g.fillRoundRect(x, y, width, height, arcWidth, arcHeight);
+ }
+
+ public void translate(int x, int y) {
+ super.translate(x, y);
+ g.translate(x, y);
+ }
+
+ // Andres Navarro
+ public void drawRegion(Image src, int x_src, int y_src, int width, int height, int transform, int x_dst, int y_dst,
+ int anchor) {
+
+ // may throw NullPointerException, this is ok
+ if (x_src + width > src.getWidth() || y_src + height > src.getHeight() || width < 0 || height < 0 || x_src < 0
+ || y_src < 0)
+ throw new IllegalArgumentException("Area out of Image");
+
+ // this cannot be done on the same image we are drawing
+ // check this if the implementation of getGraphics change so
+ // as to return different Graphic Objects on each call to
+ // getGraphics
+ if (src.isMutable() && src.getGraphics() == this)
+ throw new IllegalArgumentException("Image is source and target");
+
+ java.awt.Image img;
+
+ if (src.isMutable()) {
+ img = ((J2SEMutableImage) src).getImage();
+ } else {
+ img = ((J2SEImmutableImage) src).getImage();
+ }
+
+ java.awt.geom.AffineTransform t = new java.awt.geom.AffineTransform();
+
+ int dW = width, dH = height;
+ switch (transform) {
+ case Sprite.TRANS_NONE: {
+ break;
+ }
+ case Sprite.TRANS_ROT90: {
+ t.translate((double) height, 0);
+ t.rotate(Math.PI / 2);
+ dW = height;
+ dH = width;
+ break;
+ }
+ case Sprite.TRANS_ROT180: {
+ t.translate(width, height);
+ t.rotate(Math.PI);
+ break;
+ }
+ case Sprite.TRANS_ROT270: {
+ t.translate(0, width);
+ t.rotate(Math.PI * 3 / 2);
+ dW = height;
+ dH = width;
+ break;
+ }
+ case Sprite.TRANS_MIRROR: {
+ t.translate(width, 0);
+ t.scale(-1, 1);
+ break;
+ }
+ case Sprite.TRANS_MIRROR_ROT90: {
+ t.translate((double) height, 0);
+ t.rotate(Math.PI / 2);
+ t.translate((double) width, 0);
+ t.scale(-1, 1);
+ dW = height;
+ dH = width;
+ break;
+ }
+ case Sprite.TRANS_MIRROR_ROT180: {
+ t.translate(width, 0);
+ t.scale(-1, 1);
+ t.translate(width, height);
+ t.rotate(Math.PI);
+ break;
+ }
+ case Sprite.TRANS_MIRROR_ROT270: {
+ t.rotate(Math.PI * 3 / 2);
+ t.scale(-1, 1);
+ dW = height;
+ dH = width;
+ break;
+ }
+ default:
+ throw new IllegalArgumentException("Bad transform");
+ }
+
+ // process anchor and correct x and y _dest
+ // vertical
+ boolean badAnchor = false;
+
+ if (anchor == 0) {
+ anchor = TOP | LEFT;
+ }
+
+ if ((anchor & 0x7f) != anchor || (anchor & BASELINE) != 0)
+ badAnchor = true;
+
+ if ((anchor & TOP) != 0) {
+ if ((anchor & (VCENTER | BOTTOM)) != 0)
+ badAnchor = true;
+ } else if ((anchor & BOTTOM) != 0) {
+ if ((anchor & VCENTER) != 0)
+ badAnchor = true;
+ else {
+ y_dst -= dH - 1;
+ }
+ } else if ((anchor & VCENTER) != 0) {
+ y_dst -= (dH - 1) >>> 1;
+ } else {
+ // no vertical anchor
+ badAnchor = true;
+ }
+
+ // horizontal
+ if ((anchor & LEFT) != 0) {
+ if ((anchor & (HCENTER | RIGHT)) != 0)
+ badAnchor = true;
+ } else if ((anchor & RIGHT) != 0) {
+ if ((anchor & HCENTER) != 0)
+ badAnchor = true;
+ else {
+ x_dst -= dW - 1;
+ }
+ } else if ((anchor & HCENTER) != 0) {
+ x_dst -= (dW - 1) >>> 1;
+ } else {
+ // no horizontal anchor
+ badAnchor = true;
+ }
+
+ if (badAnchor)
+ throw new IllegalArgumentException("Bad Anchor");
+
+ java.awt.geom.AffineTransform savedT = g.getTransform();
+
+ g.translate(x_dst, y_dst);
+ g.transform(t);
+
+ g.drawImage(img, 0, 0, width, height, x_src, y_src, x_src + width, y_src + height, null);
+
+ // return to saved
+ g.setTransform(savedT);
+ }
+
+ public void drawRGB(int[] rgbData, int offset, int scanlength, int x, int y, int width, int height,
+ boolean processAlpha) {
+ // this is less than ideal in terms of memory
+ // but it's the easiest way
+
+ if (rgbData == null)
+ throw new NullPointerException();
+
+ if (width == 0 || height == 0) {
+ return;
+ }
+
+ int l = rgbData.length;
+
+ if (width < 0 || height < 0 || offset < 0 || offset >= l || (scanlength < 0 && scanlength * (height - 1) < 0)
+ || (scanlength >= 0 && scanlength * (height - 1) + width - 1 >= l))
+ throw new ArrayIndexOutOfBoundsException();
+
+ int[] rgb = new int[width * height];
+ // this way we dont create yet another array in createImage
+ int transparencyMask = processAlpha ? 0 : 0xff000000;
+ for (int row = 0; row < height; row++) {
+ for (int px = 0; px < width; px++)
+ rgb[row * width + px] = rgbData[offset + px] | transparencyMask;
+ offset += scanlength;
+ }
+
+ // help gc
+ rgbData = null;
+ Image img = DeviceFactory.getDevice().getDeviceDisplay().createRGBImage(rgb, width, height, true);
+ drawImage(img, x, y, TOP | LEFT);
+ }
+
+ public void fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3) {
+ int[] xPoints = new int[3];
+ int[] yPoints = new int[3];
+ xPoints[0] = x1;
+ xPoints[1] = x2;
+ xPoints[2] = x3;
+ yPoints[0] = y1;
+ yPoints[1] = y2;
+ yPoints[2] = y3;
+
+ g.fillPolygon(xPoints, yPoints, 3);
+ }
+
+ public void copyArea(int x_src, int y_src, int width, int height, int x_dest, int y_dest, int anchor) {
+
+ // TODO check for Graphics Object size and
+ // that this is not the Graphics representing the Screen
+ if (width <= 0 || height <= 0)
+ return;//?? is this ok or should i throw IllegalArgument?
+
+ // process anchor and correct x and y _dest
+ // vertical
+ boolean badAnchor = false;
+ if ((anchor & 0x7f) != anchor || (anchor & BASELINE) != 0)
+ badAnchor = true;
+
+ if ((anchor & TOP) != 0) {
+ if ((anchor & (VCENTER | BOTTOM)) != 0)
+ badAnchor = true;
+ } else if ((anchor & BOTTOM) != 0) {
+ if ((anchor & VCENTER) != 0)
+ badAnchor = true;
+ else {
+ y_dest -= height - 1;
+ }
+ } else if ((anchor & VCENTER) != 0) {
+ y_dest -= (height - 1) >>> 1;
+ } else {
+ // no vertical anchor
+ badAnchor = true;
+ }
+
+ // horizontal
+ if ((anchor & LEFT) != 0) {
+ if ((anchor & (HCENTER | RIGHT)) != 0)
+ badAnchor = true;
+ } else if ((anchor & RIGHT) != 0) {
+ if ((anchor & HCENTER) != 0)
+ badAnchor = true;
+ else {
+ x_dest -= width;
+ }
+ } else if ((anchor & HCENTER) != 0) {
+ x_dest -= (width - 1) >>> 1;
+ } else {
+ // no horizontal anchor
+ badAnchor = true;
+ }
+
+ if (badAnchor)
+ throw new IllegalArgumentException("Bad Anchor");
+
+ g.copyArea(x_src, y_src, width, height, x_dest - x_src, y_dest - y_src);
+ }
+
+ public Graphics2D getGraphics() {
+ return g;
+ }
+
+}
Propchange: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEDisplayGraphics.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEFont.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEFont.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEFont.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEFont.java Mon May 26 15:20:19 2008
@@ -0,0 +1,30 @@
+/*
+ * 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.j2se;
+
+import java.awt.Font;
+
+public interface J2SEFont extends org.microemu.device.impl.Font {
+
+ Font getFont();
+
+ void setAntialiasing(boolean antialiasing);
+
+}
Propchange: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEFont.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEFontManager.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEFontManager.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEFontManager.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEFontManager.java Mon May 26 15:20:19 2008
@@ -0,0 +1,190 @@
+/*
+ * 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.j2se;
+
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.Hashtable;
+
+import javax.microedition.lcdui.Font;
+
+import org.microemu.device.impl.FontManagerImpl;
+
+public class J2SEFontManager implements FontManagerImpl
+{
+ private static String FACE_SYSTEM_NAME = "SansSerif";
+ private static String FACE_MONOSPACE_NAME = "Monospaced";
+ private static String FACE_PROPORTIONAL_NAME = "SansSerif";
+
+ private static int SIZE_SMALL = 9;
+ private static int SIZE_MEDIUM = 11;
+ private static int SIZE_LARGE = 13;
+
+ private Hashtable fonts = new Hashtable();
+
+ private boolean antialiasing;
+
+
+ org.microemu.device.impl.Font getFont(Font meFont)
+ {
+ int key = 0;
+ key |= meFont.getFace();
+ key |= meFont.getStyle();
+ key |= meFont.getSize();
+
+ org.microemu.device.impl.Font result = (org.microemu.device.impl.Font) fonts.get(new Integer(key));
+
+ if (result == null) {
+ String name = null;
+ if (meFont.getFace() == Font.FACE_SYSTEM) {
+ name = FACE_SYSTEM_NAME;
+ } else if (meFont.getFace() == Font.FACE_MONOSPACE) {
+ name = FACE_MONOSPACE_NAME;
+ } else if (meFont.getFace() == Font.FACE_PROPORTIONAL) {
+ name = FACE_PROPORTIONAL_NAME;
+ }
+ String style = ",";
+ if ((meFont.getStyle() & Font.STYLE_PLAIN) != 0) {
+ style += "plain,";
+ }
+ if ((meFont.getStyle() & Font.STYLE_BOLD) != 0) {
+ style += "bold,";
+ }
+ if ((meFont.getStyle() & Font.STYLE_ITALIC) != 0) {
+ style += "italic,";
+ }
+ if ((meFont.getStyle() & Font.STYLE_ITALIC) != 0) {
+ style += "underlined,";
+ }
+ style = style.substring(0, style.length() - 1);
+ int size = 0;
+ if (meFont.getSize() == Font.SIZE_SMALL) {
+ size = SIZE_SMALL;
+ } else if (meFont.getSize() == Font.SIZE_MEDIUM) {
+ size = SIZE_MEDIUM;
+ } else if (meFont.getSize() == Font.SIZE_LARGE) {
+ size = SIZE_LARGE;
+ }
+ result = new J2SESystemFont(name, style, size, antialiasing);
+ fonts.put(new Integer(key), result);
+ }
+
+ return result;
+ }
+
+
+ public void init()
+ {
+ fonts.clear();
+ }
+
+
+ public int charWidth(Font f, char ch)
+ {
+ return getFont(f).charWidth(ch);
+ }
+
+
+ public int charsWidth(Font f, char[] ch, int offset, int length)
+ {
+ return getFont(f).charsWidth(ch, offset, length);
+ }
+
+ public int getBaselinePosition(Font f)
+ {
+ return getFont(f).getBaselinePosition();
+ }
+
+
+ public int getHeight(Font f)
+ {
+ return getFont(f).getHeight();
+ }
+
+
+ public int stringWidth(Font f, String str)
+ {
+ return getFont(f).stringWidth(str);
+ }
+
+
+ public boolean getAntialiasing() {
+ return antialiasing;
+ }
+
+
+ public void setAntialiasing(boolean antialiasing)
+ {
+ this.antialiasing = antialiasing;
+
+ Enumeration en = fonts.elements();
+ while (en.hasMoreElements()) {
+ J2SEFont font = (J2SEFont) en.nextElement();
+ font.setAntialiasing(antialiasing);
+ }
+ }
+
+
+ public void setFont(String face, String style, String size, org.microemu.device.impl.Font font) {
+ int key = 0;
+
+ if (face.equalsIgnoreCase("system")) {
+ key |= Font.FACE_SYSTEM;
+ } else if (face.equalsIgnoreCase("monospace")) {
+ key |= Font.FACE_MONOSPACE;
+ } else if (face.equalsIgnoreCase("proportional")) {
+ key |= Font.FACE_PROPORTIONAL;
+ }
+
+ String testStyle = style.toLowerCase();
+ if (testStyle.indexOf("plain") != -1) {
+ key |= Font.STYLE_PLAIN;
+ }
+ if (testStyle.indexOf("bold") != -1) {
+ key |= Font.STYLE_BOLD;
+ }
+ if (testStyle.indexOf("italic") != -1) {
+ key |= Font.STYLE_ITALIC;
+ }
+ if (testStyle.indexOf("underlined") != -1) {
+ key |= Font.STYLE_UNDERLINED;
+ }
+
+ if (size.equalsIgnoreCase("small")) {
+ key |= Font.SIZE_SMALL;
+ } else if (size.equalsIgnoreCase("medium")) {
+ key |= Font.SIZE_MEDIUM;
+ } else if (size.equalsIgnoreCase("large")) {
+ key |= Font.SIZE_LARGE;
+ }
+
+ fonts.put(new Integer(key), font);
+ }
+
+
+ public org.microemu.device.impl.Font createSystemFont(String defName, String defStyle, int defSize, boolean antialiasing) {
+ return new J2SESystemFont(defName, defStyle, defSize, antialiasing);
+ }
+
+ public org.microemu.device.impl.Font createTrueTypeFont(URL defUrl, String defStyle, int defSize, boolean antialiasing) {
+ return new J2SETrueTypeFont(defUrl, defStyle, defSize, antialiasing);
+ }
+
+}
Propchange: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEFontManager.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEImmutableImage.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEImmutableImage.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEImmutableImage.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEImmutableImage.java Mon May 26 15:20:19 2008
@@ -0,0 +1,150 @@
+/*
+ * 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.j2se;
+
+import java.awt.Image;
+import java.awt.Toolkit;
+import java.awt.image.ImageObserver;
+
+import org.microemu.log.Logger;
+
+public class J2SEImmutableImage extends javax.microedition.lcdui.Image {
+ private Image img;
+
+ private int width;
+
+ private int height;
+
+ public J2SEImmutableImage(Image image) {
+ this.img = image;
+ this.width = -1;
+ this.height = -1;
+ }
+
+ public J2SEImmutableImage(J2SEMutableImage image) {
+ img = Toolkit.getDefaultToolkit().createImage(image.getImage().getSource());
+ this.width = -1;
+ this.height = -1;
+ }
+
+ public int getHeight() {
+ if (height == -1) {
+ ImageObserver observer = new ImageObserver() {
+ public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) {
+ if ((infoflags & ImageObserver.WIDTH) != 0) {
+ J2SEImmutableImage.this.width = width;
+ }
+ if ((infoflags & ImageObserver.HEIGHT) != 0) {
+ synchronized (this) {
+ J2SEImmutableImage.this.height = height;
+ this.notify();
+ }
+ return false;
+ }
+
+ return true;
+ }
+ };
+ synchronized (observer) {
+ // Fix for http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4905411 (Java < 1.5)
+ try {
+ height = img.getHeight(observer);
+ } catch (NullPointerException ex) {
+ }
+ if (height == -1) {
+ try {
+ observer.wait();
+ } catch (InterruptedException ex) {
+ }
+ }
+ }
+ }
+
+ return height;
+ }
+
+ public Image getImage() {
+ return img;
+ }
+
+ public int getWidth() {
+ if (width == -1) {
+ ImageObserver observer = new ImageObserver() {
+ public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) {
+ if ((infoflags & ImageObserver.HEIGHT) != 0) {
+ J2SEImmutableImage.this.height = height;
+ }
+ if ((infoflags & ImageObserver.WIDTH) != 0) {
+ synchronized (this) {
+ J2SEImmutableImage.this.width = width;
+ this.notify();
+ }
+ return false;
+ }
+
+ return true;
+ }
+ };
+ synchronized (observer) {
+ // Fix for http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4905411 (Java < 1.5)
+ try {
+ width = img.getWidth(observer);
+ } catch (NullPointerException ex) {
+ }
+ if (width == -1) {
+ try {
+ observer.wait();
+ } catch (InterruptedException ex) {
+ }
+ }
+ }
+ }
+
+ return width;
+ }
+
+ public void getRGB(int[] argb, int offset, int scanlength, int x, int y, int width, int height) {
+
+ if (width <= 0 || height <= 0)
+ return;
+ if (x < 0 || y < 0 || x + width > getWidth() || y + height > getHeight())
+ throw new IllegalArgumentException("Specified area exceeds bounds of image");
+ if ((scanlength < 0 ? -scanlength : scanlength) < width)
+ throw new IllegalArgumentException("abs value of scanlength is less than width");
+ if (argb == null)
+ throw new NullPointerException("null rgbData");
+ if (offset < 0 || offset + width > argb.length)
+ throw new ArrayIndexOutOfBoundsException();
+ if (scanlength < 0) {
+ if (offset + scanlength * (height - 1) < 0)
+ throw new ArrayIndexOutOfBoundsException();
+ } else {
+ if (offset + scanlength * (height - 1) + width > argb.length)
+ throw new ArrayIndexOutOfBoundsException();
+ }
+
+ try {
+ (new java.awt.image.PixelGrabber(img, x, y, width, height, argb, offset, scanlength)).grabPixels();
+ } catch (InterruptedException e) {
+ Logger.error(e);
+ }
+ }
+
+}
Propchange: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEImmutableImage.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEInputMethod.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEInputMethod.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEInputMethod.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEInputMethod.java Mon May 26 15:20:19 2008
@@ -0,0 +1,415 @@
+/*
+ * 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.j2se;
+
+import java.awt.event.KeyEvent;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Timer;
+import java.util.TimerTask;
+import java.util.Vector;
+
+import javax.microedition.lcdui.Command;
+import javax.microedition.lcdui.TextField;
+
+import org.microemu.DisplayAccess;
+import org.microemu.MIDletAccess;
+import org.microemu.MIDletBridge;
+import org.microemu.device.DeviceFactory;
+import org.microemu.device.InputMethod;
+import org.microemu.device.InputMethodEvent;
+import org.microemu.device.impl.ButtonDetaultDeviceKeyCodes;
+import org.microemu.device.impl.ButtonName;
+import org.microemu.device.impl.InputMethodImpl;
+import org.microemu.device.impl.SoftButton;
+import org.microemu.util.ThreadUtils;
+
+public class J2SEInputMethod extends InputMethodImpl {
+
+ private boolean eventAlreadyConsumed;
+
+ private Timer keyReleasedDelayTimer;
+
+ private List repeatModeKeyCodes = new Vector();
+
+ private class KeyReleasedDelayTask extends TimerTask {
+
+ private int repeatModeKeyCode;
+
+ KeyReleasedDelayTask(int repeatModeKeyCode) {
+ this.repeatModeKeyCode = repeatModeKeyCode;
+
+ }
+
+ public void run() {
+ if (repeatModeKeyCode != Integer.MIN_VALUE) {
+ MIDletAccess ma = MIDletBridge.getMIDletAccess();
+ if (ma == null) {
+ return;
+ }
+
+ DisplayAccess da = ma.getDisplayAccess();
+ if (da == null) {
+ return;
+ }
+
+ da.keyReleased(repeatModeKeyCode);
+ eventAlreadyConsumed = false;
+ repeatModeKeyCode = Integer.MIN_VALUE;
+ }
+ }
+ };
+
+ public J2SEInputMethod() {
+ super();
+
+ // TODO When InputMethod will be removed from EmulatorContext add:
+ // if (DeviceFactory.getDevice().hasRepeatEvents()) {
+ keyReleasedDelayTimer = ThreadUtils.createTimer("InputKeyReleasedDelayTimer");
+ }
+
+ /**
+ * Gets the game action associated with the given key code of the device.
+ *
+ * @return the game action corresponding to this key, or <code>0</code> if
+ * none
+ */
+ public int getGameAction(int keyCode) {
+ for (Iterator it = DeviceFactory.getDevice().getButtons().iterator(); it.hasNext();) {
+ J2SEButton button = (J2SEButton) it.next();
+ if (button.getKeyCode() == keyCode) {
+ return ButtonDetaultDeviceKeyCodes.getGameAction(button.getFunctionalName());
+ }
+ }
+ return 0;
+ }
+
+ /**
+ *
+ *
+ * @return a key code corresponding to this game action
+ * @throws IllegalArgumentException
+ * if <code>gameAction</code> is not a valid game action
+ */
+ public int getKeyCode(int gameAction) {
+ ButtonName name = ButtonDetaultDeviceKeyCodes.getButtonNameByGameAction(gameAction);
+ return J2SEDeviceButtonsHelper.getButton(name).getKeyCode();
+ }
+
+ /**
+ * @return a string name for the key
+ * @throws IllegalArgumentException
+ * if <code>keyCode</code> is not a valid key code
+ */
+ public String getKeyName(int keyCode) throws IllegalArgumentException {
+ for (Iterator it = DeviceFactory.getDevice().getButtons().iterator(); it.hasNext();) {
+ J2SEButton button = (J2SEButton) it.next();
+ if (button.getKeyCode() == keyCode) {
+ return button.getName();
+ }
+ }
+ return Character.toString((char) keyCode);
+ }
+
+ protected boolean fireInputMethodListener(J2SEButton button, char keyChar) {
+ MIDletAccess ma = MIDletBridge.getMIDletAccess();
+ if (ma == null) {
+ return false;
+ }
+ DisplayAccess da = ma.getDisplayAccess();
+ if (da == null) {
+ return false;
+ }
+
+ int keyCode = keyChar;
+ if (button != null && keyChar == '\0') {
+ keyCode = button.getKeyCode();
+ }
+
+ if (inputMethodListener == null) {
+ da.keyPressed(keyCode);
+ return true;
+ }
+
+ if (button == null) {
+ return true;
+ }
+
+ ButtonName functionalName = button.getFunctionalName();
+
+ if (functionalName == ButtonName.UP || functionalName == ButtonName.DOWN) {
+ da.keyPressed(button.getKeyCode());
+ return true;
+ }
+
+ int caret = inputMethodListener.getCaretPosition();
+
+ if (button.isModeChange()) {
+ switch (inputMethodListener.getConstraints() & TextField.CONSTRAINT_MASK) {
+ case TextField.ANY:
+ case TextField.EMAILADDR:
+ case TextField.URL:
+ if (getInputMode() == InputMethod.INPUT_123) {
+ setInputMode(InputMethod.INPUT_ABC_UPPER);
+ } else if (getInputMode() == InputMethod.INPUT_ABC_UPPER) {
+ setInputMode(InputMethod.INPUT_ABC_LOWER);
+ } else if (getInputMode() == InputMethod.INPUT_ABC_LOWER) {
+ setInputMode(InputMethod.INPUT_123);
+ }
+ synchronized (this) {
+ if (lastButton != null) {
+ caret++;
+ lastButton = null;
+ lastButtonCharIndex = -1;
+ }
+ }
+ InputMethodEvent event = new InputMethodEvent(InputMethodEvent.CARET_POSITION_CHANGED, caret,
+ inputMethodListener.getText());
+ inputMethodListener.caretPositionChanged(event);
+ break;
+ }
+ return true;
+ }
+
+ if (functionalName == ButtonName.LEFT || functionalName == ButtonName.RIGHT) {
+ synchronized (this) {
+ if ((functionalName == ButtonName.LEFT) && caret > 0) {
+ caret--;
+ } else if ((functionalName == ButtonName.RIGHT) && caret < inputMethodListener.getText().length()) {
+ caret++;
+ }
+ lastButton = null;
+ lastButtonCharIndex = -1;
+ }
+ InputMethodEvent event = new InputMethodEvent(InputMethodEvent.CARET_POSITION_CHANGED, caret,
+ inputMethodListener.getText());
+ inputMethodListener.caretPositionChanged(event);
+ return true;
+ }
+
+ if (functionalName == ButtonName.BACK_SPACE) {
+ String tmp = "";
+ synchronized (this) {
+ if (lastButton != null) {
+ caret++;
+ lastButton = null;
+ lastButtonCharIndex = -1;
+ }
+ if (caret > 0) {
+ caret--;
+ if (caret > 0) {
+ tmp += inputMethodListener.getText().substring(0, caret);
+ }
+ if (caret < inputMethodListener.getText().length() - 1) {
+ tmp += inputMethodListener.getText().substring(caret + 1);
+ }
+ }
+ }
+ if (!validate(tmp, inputMethodListener.getConstraints())) {
+ return true;
+ }
+ 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);
+ return true;
+ }
+
+ if (functionalName == ButtonName.DELETE) {
+ String tmp = inputMethodListener.getText();
+ synchronized (this) {
+ if (lastButton != null) {
+ lastButton = null;
+ lastButtonCharIndex = -1;
+ }
+ if (caret != inputMethodListener.getText().length()) {
+ tmp = inputMethodListener.getText().substring(0, caret)
+ + inputMethodListener.getText().substring(caret + 1);
+ }
+ }
+ if (!validate(tmp, inputMethodListener.getConstraints())) {
+ return true;
+ }
+ 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);
+ return true;
+ }
+
+ if (inputMethodListener.getText().length() < maxSize) {
+ StringBuffer editText = new StringBuffer(inputMethodListener.getText());
+ synchronized (this) {
+ lastButtonCharIndex++;
+ char[] buttonChars = filterConstraints(filterInputMode(button.getChars(getInputMode())));
+ if (keyChar != '\0') {
+ // Pass through letters and characters typed on keyboard but
+ // not numbers that are buttons keys (presumably).
+ editText.append(keyChar);
+ caret++;
+ lastButton = null;
+ lastButtonCharIndex = -1;
+ } else if (buttonChars.length > 0) {
+ if (lastButtonCharIndex == buttonChars.length) {
+ if (buttonChars.length == 1) {
+ if (lastButton != null) {
+ caret++;
+ }
+ lastButton = null;
+ } else {
+ lastButtonCharIndex = 0;
+ }
+ }
+ if (lastButton != button) {
+ if (lastButton != null) {
+ caret++;
+ }
+ if (editText.length() < caret) {
+ editText.append(buttonChars[0]);
+ } else {
+ editText.insert(caret, buttonChars[0]);
+ }
+ lastButton = button;
+ lastButtonCharIndex = 0;
+ } else {
+ editText.setCharAt(caret, buttonChars[lastButtonCharIndex]);
+ lastButton = button;
+ }
+ } else {
+ lastButton = null;
+ lastButtonCharIndex = -1;
+ }
+ resetKey = false;
+ notify();
+ }
+ if (!validate(editText.toString(), inputMethodListener.getConstraints())) {
+ return false;
+ }
+ InputMethodEvent event = new InputMethodEvent(InputMethodEvent.INPUT_METHOD_TEXT_CHANGED, caret, editText
+ .toString());
+ inputMethodListener.inputMethodTextChanged(event);
+ }
+ return false;
+ }
+
+ public void buttonTyped(J2SEButton button) {
+ if (eventAlreadyConsumed) {
+ return;
+ }
+ }
+
+ public void clipboardPaste(String str) {
+ if (inputMethodListener != null && inputMethodListener.getText() != null
+ && ((inputMethodListener.getText().length() + str.length()) <= maxSize)) {
+ insertText(str);
+ }
+ eventAlreadyConsumed = true;
+ }
+
+ public void buttonPressed(J2SEButton button, char keyChar) {
+ int keyCode = keyChar;
+ if (button != null && keyChar == '\0') {
+ keyCode = button.getKeyCode();
+ }
+ eventAlreadyConsumed = false;
+ if (DeviceFactory.getDevice().hasRepeatEvents()) {
+ if (repeatModeKeyCodes.contains(new Integer(keyCode))) {
+ MIDletAccess ma = MIDletBridge.getMIDletAccess();
+ if (ma == null) {
+ return;
+ }
+ DisplayAccess da = ma.getDisplayAccess();
+ if (da == null) {
+ return;
+ }
+ da.keyRepeated(keyCode);
+ eventAlreadyConsumed = true;
+ return;
+ } else {
+ repeatModeKeyCodes.add(new Integer(keyCode));
+ }
+ }
+
+ // invoke any associated commands, but send the raw key codes instead
+ boolean rawSoftKeys = DeviceFactory.getDevice().getDeviceDisplay().isFullScreenMode();
+ if (button instanceof SoftButton && !rawSoftKeys) {
+ Command cmd = ((SoftButton) button).getCommand();
+ if (cmd != null) {
+ MIDletAccess ma = MIDletBridge.getMIDletAccess();
+ if (ma == null) {
+ return;
+ }
+ DisplayAccess da = ma.getDisplayAccess();
+ if (da == null) {
+ return;
+ }
+ da.commandAction(cmd, da.getCurrent());
+ eventAlreadyConsumed = true;
+ return;
+ }
+ }
+
+ if (fireInputMethodListener(button, keyChar)) {
+ eventAlreadyConsumed = true;
+ return;
+ }
+ }
+
+ public void buttonReleased(J2SEButton button, char keyChar) {
+ int keyCode = keyChar;
+ if (button != null && keyChar == '\0') {
+ keyCode = button.getKeyCode();
+ }
+ if (DeviceFactory.getDevice().hasRepeatEvents()) {
+ repeatModeKeyCodes.remove(new Integer(keyCode));
+ keyReleasedDelayTimer.schedule(new KeyReleasedDelayTask(keyCode), 50);
+ } else {
+ MIDletAccess ma = MIDletBridge.getMIDletAccess();
+ if (ma == null) {
+ return;
+ }
+
+ DisplayAccess da = ma.getDisplayAccess();
+ if (da == null) {
+ return;
+ }
+
+ da.keyReleased(keyCode);
+ eventAlreadyConsumed = false;
+ }
+ }
+
+ public J2SEButton getButton(KeyEvent ev) {
+ J2SEButton button = J2SEDeviceButtonsHelper.getButton(ev);
+ if (button != null) {
+ return button;
+ }
+ if (getInputMode() != INPUT_123) {
+ for (Enumeration e = DeviceFactory.getDevice().getButtons().elements(); e.hasMoreElements();) {
+ button = (J2SEButton) e.nextElement();
+ if (button.isChar(ev.getKeyChar(), getInputMode())) {
+ return button;
+ }
+ }
+ }
+ return null;
+ }
+}
Propchange: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEInputMethod.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEMutableImage.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEMutableImage.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEMutableImage.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEMutableImage.java Mon May 26 15:20:19 2008
@@ -0,0 +1,127 @@
+/*
+ * 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.j2se;
+
+import java.awt.image.BufferedImage;
+import java.awt.image.PixelGrabber;
+
+import org.microemu.device.MutableImage;
+import org.microemu.log.Logger;
+
+
+public class J2SEMutableImage extends MutableImage
+{
+ private BufferedImage img;
+ private PixelGrabber grabber = null;
+ private int[] pixels;
+
+
+ public J2SEMutableImage(int width, int height)
+ {
+ img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
+ java.awt.Graphics g = img.getGraphics();
+ g.setColor(java.awt.Color.WHITE);
+ g.fillRect(0, 0, width, height);
+ }
+
+
+ public javax.microedition.lcdui.Graphics getGraphics()
+ {
+ java.awt.Graphics2D g = (java.awt.Graphics2D) img.getGraphics();
+ g.setClip(0, 0, getWidth(), getHeight());
+ J2SEDisplayGraphics displayGraphics = new J2SEDisplayGraphics(g, this);
+ displayGraphics.setColor(0x00000000);
+ displayGraphics.translate(-displayGraphics.getTranslateX(), -displayGraphics.getTranslateY());
+
+ return displayGraphics;
+ }
+
+
+ public boolean isMutable()
+ {
+ return true;
+ }
+
+
+ public int getHeight()
+ {
+ return img.getHeight();
+ }
+
+
+ public java.awt.Image getImage()
+ {
+ return img;
+ }
+
+
+ public int getWidth()
+ {
+ return img.getWidth();
+ }
+
+
+ public int[] getData()
+ {
+ if (grabber == null) {
+ pixels = new int[getWidth() * getHeight()];
+ grabber = new PixelGrabber(img, 0, 0, getWidth(), getHeight(), pixels, 0, getWidth());
+ }
+
+ try {
+ grabber.grabPixels();
+ } catch (InterruptedException e) {
+ Logger.error(e);
+ }
+
+ return pixels;
+ }
+
+ // Andres Navarro
+ public void getRGB(int []argb, int offset, int scanlength,
+ int x, int y, int width, int height) {
+
+ if (width <= 0 || height <= 0)
+ return;
+ if (x < 0 || y < 0 || x + width > getWidth() || y + height > getHeight())
+ throw new IllegalArgumentException("Specified area exceeds bounds of image");
+ if ((scanlength < 0? -scanlength:scanlength) < width)
+ throw new IllegalArgumentException("abs value of scanlength is less than width");
+ if (argb == null)
+ throw new NullPointerException("null rgbData");
+ if (offset < 0 || offset + width > argb.length)
+ throw new ArrayIndexOutOfBoundsException();
+ if (scanlength < 0) {
+ if (offset + scanlength*(height-1) < 0)
+ throw new ArrayIndexOutOfBoundsException();
+ } else {
+ if (offset + scanlength*(height-1) + width > argb.length)
+ throw new ArrayIndexOutOfBoundsException();
+ }
+
+ try {
+ (new PixelGrabber(img, x, y, width, height, argb, offset, scanlength)).grabPixels();
+ } catch (InterruptedException e) {
+ Logger.error(e);
+ }
+ }
+ // Andres Navarro
+
+}
Propchange: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEMutableImage.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SESoftButton.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SESoftButton.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SESoftButton.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SESoftButton.java Mon May 26 15:20:19 2008
@@ -0,0 +1,224 @@
+/*
+ * 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.j2se;
+
+import java.awt.FontMetrics;
+import java.awt.Graphics;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Vector;
+
+import javax.microedition.lcdui.Command;
+import javax.microedition.lcdui.Font;
+import javax.microedition.lcdui.Image;
+
+import org.microemu.device.Device;
+import org.microemu.device.DeviceFactory;
+import org.microemu.device.impl.Rectangle;
+import org.microemu.device.impl.Shape;
+import org.microemu.device.impl.SoftButton;
+
+public class J2SESoftButton extends J2SEButton implements SoftButton {
+
+ public static int LEFT = 1;
+
+ public static int RIGHT = 2;
+
+ private int type;
+
+ private Image normalImage;
+
+ private Image pressedImage;
+
+ private Vector commandTypes = new Vector();
+
+ private Command command = null;
+
+ private Rectangle paintable;
+
+ private int alignment;
+
+ private boolean visible;
+
+ private boolean pressed;
+
+ private Font font;
+
+ /**
+ * @param name
+ * @param rectangle
+ * @param keyCode -
+ * Integer.MIN_VALUE when unspecified
+ * @param keyName
+ * @param paintable
+ * @param alignmentName
+ * @param commands
+ * @param font
+ */
+ public J2SESoftButton(int skinVersion, String name, Shape shape, int keyCode, String keyboardKeys,
+ Rectangle paintable, String alignmentName, Vector commands, Font font) {
+ super(skinVersion, name, shape, keyCode, keyboardKeys, null, new Hashtable(), false);
+
+ this.type = TYPE_COMMAND;
+
+ this.paintable = paintable;
+ this.visible = true;
+ this.pressed = false;
+ this.font = font;
+
+ if (alignmentName != null) {
+ try {
+ alignment = J2SESoftButton.class.getField(alignmentName).getInt(null);
+ } catch (Exception ex) {
+ System.err.println(ex);
+ }
+ }
+
+ for (Enumeration e = commands.elements(); e.hasMoreElements();) {
+ String tmp = (String) e.nextElement();
+ try {
+ addCommandType(Command.class.getField(tmp).getInt(null));
+ } catch (Exception ex) {
+ System.err.println("a3" + ex);
+ }
+ }
+ }
+
+ public J2SESoftButton(int skinVersion, String name, Rectangle paintable, Image normalImage, Image pressedImage) {
+ super(skinVersion, name, null, Integer.MIN_VALUE, null, null, null, false);
+
+ this.type = TYPE_ICON;
+
+ this.paintable = paintable;
+ this.normalImage = normalImage;
+ this.pressedImage = pressedImage;
+
+ this.visible = true;
+ this.pressed = false;
+ }
+
+ public int getType() {
+ return type;
+ }
+
+ /**
+ * Sets the command attribute of the SoftButton object
+ *
+ * @param cmd
+ * The new command value
+ */
+ public void setCommand(Command cmd) {
+ synchronized (this) {
+ command = cmd;
+ }
+ }
+
+ /**
+ * Gets the command attribute of the SoftButton object
+ *
+ * @return The command value
+ */
+ public Command getCommand() {
+ return command;
+ }
+
+ public Rectangle getPaintable() {
+ return paintable;
+ }
+
+ public boolean isVisible() {
+ return visible;
+ }
+
+ public void setVisible(boolean state) {
+ visible = state;
+ }
+
+ public boolean isPressed() {
+ return pressed;
+ }
+
+ public void setPressed(boolean state) {
+ pressed = state;
+ }
+
+ public void paint(Graphics g) {
+ if (!visible || paintable == null) {
+ return;
+ }
+
+ java.awt.Shape clip = g.getClip();
+
+ g.setClip(paintable.x, paintable.y, paintable.width, paintable.height);
+ if (type == TYPE_COMMAND) {
+ int xoffset = 0;
+ Device device = DeviceFactory.getDevice();
+ J2SEDeviceDisplay deviceDisplay = (J2SEDeviceDisplay) device.getDeviceDisplay();
+ if (pressed) {
+ g.setColor(deviceDisplay.foregroundColor);
+ } else {
+ g.setColor(deviceDisplay.backgroundColor);
+ }
+ g.fillRect(paintable.x, paintable.y, paintable.width, paintable.height);
+ synchronized (this) {
+ if (command != null) {
+ if (font != null) {
+ J2SEFontManager fontManager = (J2SEFontManager) device.getFontManager();
+ J2SEFont buttonFont = (J2SEFont) fontManager.getFont(font);
+ g.setFont(buttonFont.getFont());
+ }
+ FontMetrics metrics = g.getFontMetrics();
+ if (alignment == RIGHT) {
+ xoffset = paintable.width - metrics.stringWidth(command.getLabel()) - 1;
+ }
+ if (pressed) {
+ g.setColor(deviceDisplay.backgroundColor);
+ } else {
+ g.setColor(deviceDisplay.foregroundColor);
+ }
+ g.drawString(command.getLabel(), paintable.x + xoffset, paintable.y + paintable.height
+ - metrics.getDescent());
+ }
+ }
+ } else if (type == TYPE_ICON) {
+ if (pressed) {
+ g.drawImage(((J2SEImmutableImage) pressedImage).getImage(), paintable.x, paintable.y, null);
+ } else {
+ g.drawImage(((J2SEImmutableImage) normalImage).getImage(), paintable.x, paintable.y, null);
+ }
+ }
+
+ g.setClip(clip);
+ }
+
+ public boolean preferredCommandType(Command cmd) {
+ for (Enumeration ct = commandTypes.elements(); ct.hasMoreElements();) {
+ if (cmd.getCommandType() == ((Integer) ct.nextElement()).intValue()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public void addCommandType(int commandType) {
+ commandTypes.addElement(new Integer(commandType));
+ }
+
+}
Propchange: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SESoftButton.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SESystemFont.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SESystemFont.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SESystemFont.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SESystemFont.java Mon May 26 15:20:19 2008
@@ -0,0 +1,122 @@
+/*
+ * 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.j2se;
+
+import java.awt.Font;
+import java.awt.FontMetrics;
+import java.awt.Graphics2D;
+import java.awt.RenderingHints;
+import java.awt.image.BufferedImage;
+
+public class J2SESystemFont implements J2SEFont {
+
+ private final static Graphics2D graphics = (Graphics2D) new BufferedImage(1, 1,
+ BufferedImage.TYPE_INT_ARGB).getGraphics();
+
+ private String name;
+
+ private String style;
+
+ private int size;
+
+ private boolean antialiasing;
+
+ private boolean initialized;
+
+ private FontMetrics fontMetrics;
+
+ public J2SESystemFont(String name, String style, int size, boolean antialiasing) {
+ this.name = name;
+ this.style = style.toLowerCase();
+ this.size = size;
+ this.antialiasing = antialiasing;
+
+ this.initialized = false;
+ }
+
+ public void setAntialiasing(boolean antialiasing) {
+ if (this.antialiasing != antialiasing) {
+ this.antialiasing = antialiasing;
+ initialized = false;
+ }
+ }
+
+ public int charWidth(char ch) {
+ checkInitialized();
+
+ return fontMetrics.charWidth(ch);
+ }
+
+ public int charsWidth(char[] ch, int offset, int length) {
+ checkInitialized();
+
+ return fontMetrics.charsWidth(ch, offset, length);
+ }
+
+ public int getBaselinePosition() {
+ checkInitialized();
+
+ return fontMetrics.getAscent();
+ }
+
+ public int getHeight() {
+ checkInitialized();
+
+ return fontMetrics.getHeight();
+ }
+
+ public int stringWidth(String str) {
+ checkInitialized();
+
+ return fontMetrics.stringWidth(str);
+ }
+
+ public Font getFont() {
+ checkInitialized();
+
+ return fontMetrics.getFont();
+ }
+
+ private synchronized void checkInitialized() {
+ if (!initialized) {
+ int awtStyle = 0;
+ if (style.indexOf("plain") != -1) {
+ awtStyle |= Font.PLAIN;
+ }
+ if (style.indexOf("bold") != -1) {
+ awtStyle |= Font.BOLD;
+ }
+ if (style.indexOf("italic") != -1) {
+ awtStyle |= Font.ITALIC;
+ }
+ if (style.indexOf("underlined") != -1) {
+ // TODO underlined style not implemented
+ }
+ if (antialiasing) {
+ graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
+ } else {
+ graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
+ }
+ fontMetrics = graphics.getFontMetrics(new Font(name, awtStyle, size));
+ initialized = true;
+ }
+ }
+
+}
Propchange: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SESystemFont.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SETrueTypeFont.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SETrueTypeFont.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SETrueTypeFont.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SETrueTypeFont.java Mon May 26 15:20:19 2008
@@ -0,0 +1,135 @@
+/*
+ * 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.j2se;
+
+import java.awt.Font;
+import java.awt.FontFormatException;
+import java.awt.FontMetrics;
+import java.awt.Graphics2D;
+import java.awt.RenderingHints;
+import java.awt.image.BufferedImage;
+import java.io.IOException;
+import java.net.URL;
+
+import org.microemu.log.Logger;
+
+public class J2SETrueTypeFont implements J2SEFont {
+
+ private final static Graphics2D graphics = (Graphics2D) new BufferedImage(1, 1,
+ BufferedImage.TYPE_INT_ARGB).getGraphics();
+
+ private URL url;
+
+ private String style;
+
+ private int size;
+
+ private boolean antialiasing;
+
+ private boolean initialized;
+
+ private FontMetrics fontMetrics;
+
+ public J2SETrueTypeFont(URL url, String style, int size, boolean antialiasing) {
+ this.url = url;
+ this.style = style.toLowerCase();
+ this.size = size;
+ this.antialiasing = antialiasing;
+
+ this.initialized = false;
+ }
+
+ public void setAntialiasing(boolean antialiasing) {
+ if (this.antialiasing != antialiasing) {
+ this.antialiasing = antialiasing;
+ initialized = false;
+ }
+ }
+
+ public int charWidth(char ch) {
+ checkInitialized();
+
+ return fontMetrics.charWidth(ch);
+ }
+
+ public int charsWidth(char[] ch, int offset, int length) {
+ checkInitialized();
+
+ return fontMetrics.charsWidth(ch, offset, length);
+ }
+
+ public int getBaselinePosition() {
+ checkInitialized();
+
+ return fontMetrics.getAscent();
+ }
+
+ public int getHeight() {
+ checkInitialized();
+
+ return fontMetrics.getHeight();
+ }
+
+ public int stringWidth(String str) {
+ checkInitialized();
+
+ return fontMetrics.stringWidth(str);
+ }
+
+ public Font getFont() {
+ checkInitialized();
+
+ return fontMetrics.getFont();
+ }
+
+ private synchronized void checkInitialized() {
+ if (!initialized) {
+ int awtStyle = 0;
+ if (style.indexOf("plain") != -1) {
+ awtStyle |= Font.PLAIN;
+ }
+ if (style.indexOf("bold") != -1) {
+ awtStyle |= Font.BOLD;
+ }
+ if (style.indexOf("italic") != -1) {
+ awtStyle |= Font.ITALIC;
+ }
+ if (style.indexOf("underlined") != -1) {
+ // TODO underlined style not implemented
+ }
+ if (antialiasing) {
+ graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
+ } else {
+ graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
+ }
+
+ try {
+ Font baseFont = Font.createFont(Font.TRUETYPE_FONT, url.openStream());
+ fontMetrics = graphics.getFontMetrics(baseFont.deriveFont(awtStyle, size));
+ initialized = true;
+ } catch (FontFormatException ex) {
+ Logger.error(ex);
+ } catch (IOException ex) {
+ Logger.error(ex);
+ }
+ }
+ }
+
+}
Propchange: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SETrueTypeFont.java
------------------------------------------------------------------------------
svn:eol-style = native