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 [9/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-swt/src/main/java/org/microemu/app/ui/swt/SwtSelectDeviceDialog.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/app/ui/swt/SwtSelectDeviceDialog.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/app/ui/swt/SwtSelectDeviceDialog.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/app/ui/swt/SwtSelectDeviceDialog.java Mon May 26 15:20:19 2008
@@ -0,0 +1,358 @@
+/*
+ * 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.app.ui.swt;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Vector;
+import java.util.jar.Attributes;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import java.util.jar.Manifest;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.List;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Shell;
+import org.microemu.EmulatorContext;
+import org.microemu.app.Common;
+import org.microemu.app.Config;
+import org.microemu.app.ui.Message;
+import org.microemu.app.util.DeviceEntry;
+import org.microemu.app.util.IOUtils;
+import org.microemu.device.Device;
+import org.microemu.device.impl.DeviceImpl;
+import org.microemu.device.swt.SwtDevice;
+
+public class SwtSelectDeviceDialog extends SwtDialog {
+ private EmulatorContext emulatorContext;
+
+ private Button btAdd;
+
+ private Button btRemove;
+
+ private Button btDefault;
+
+ private List lsDevices;
+
+ private Vector deviceModel;
+
+ private DeviceEntry selectedEntry;
+
+ private Listener btAddListener = new Listener() {
+ private FileDialog fileDialog = null;
+
+ public void handleEvent(Event event) {
+ if (fileDialog == null) {
+ fileDialog = new FileDialog(getShell(), SWT.OPEN);
+ fileDialog.setText("Open device profile file...");
+ fileDialog.setFilterNames(new String[] { "Device profile (*.jar)" });
+ fileDialog.setFilterExtensions(new String[] { "*.jar" });
+ }
+
+ fileDialog.open();
+
+ if (fileDialog.getFileName() != null) {
+ File file;
+ String manifestDeviceName = null;
+ URL[] urls = new URL[1];
+ ArrayList descriptorEntries = new ArrayList();
+ try {
+ file = new File(fileDialog.getFilterPath(), fileDialog.getFileName());
+ JarFile jar = new JarFile(file);
+
+ Manifest manifest = jar.getManifest();
+ if (manifest != null) {
+ Attributes attrs = manifest.getMainAttributes();
+ manifestDeviceName = attrs.getValue("Device-Name");
+ }
+
+ for (Enumeration en = jar.entries(); en.hasMoreElements();) {
+ String entry = ((JarEntry) en.nextElement()).getName();
+ if ((entry.toLowerCase().endsWith(".xml") || entry.toLowerCase().endsWith("device.txt"))
+ && !entry.toLowerCase().startsWith("meta-inf")) {
+ descriptorEntries.add(entry);
+ }
+ }
+ jar.close();
+ urls[0] = file.toURL();
+ } catch (IOException ex) {
+ Message.error("Error reading file: " + fileDialog.getFileName() + ", "
+ + Message.getCauseMessage(ex), ex);
+ return;
+ }
+
+ if (descriptorEntries.size() == 0) {
+ Message.error("Cannot find any device profile in file: " + fileDialog.getFileName());
+ return;
+ }
+
+ if (descriptorEntries.size() > 1) {
+ manifestDeviceName = null;
+ }
+
+ ClassLoader classLoader = Common.createExtensionsClassLoader(urls);
+ HashMap devices = new HashMap();
+ for (Iterator it = descriptorEntries.iterator(); it.hasNext();) {
+ JarEntry entry = (JarEntry) it.next();
+ try {
+ devices.put(entry.getName(), DeviceImpl.create(emulatorContext, classLoader, entry.getName(),
+ SwtDevice.class));
+ } catch (IOException ex) {
+ Message.error("Error parsing device profile, " + Message.getCauseMessage(ex), ex);
+ return;
+ }
+ }
+
+ for (int i = 0; i < deviceModel.size(); i++) {
+ DeviceEntry entry = (DeviceEntry) deviceModel.elementAt(i);
+ if (devices.containsKey(entry.getDescriptorLocation())) {
+ devices.remove(entry.getDescriptorLocation());
+ }
+ }
+ if (devices.size() == 0) {
+ Message.info("Device profile already added");
+ return;
+ }
+
+ try {
+ File deviceFile = new File(Config.getConfigPath(), file.getName());
+ if (deviceFile.exists()) {
+ deviceFile = File.createTempFile("device", ".jar", Config.getConfigPath());
+ }
+ IOUtils.copyFile(file, deviceFile);
+
+ DeviceEntry entry = null;
+ for (Iterator it = devices.keySet().iterator(); it.hasNext();) {
+ String descriptorLocation = (String) it.next();
+ Device device = (Device) devices.get(descriptorLocation);
+ if (manifestDeviceName != null) {
+ entry = new DeviceEntry(manifestDeviceName, deviceFile.getName(), descriptorLocation, false);
+ } else {
+ entry = new DeviceEntry(device.getName(), deviceFile.getName(), descriptorLocation, false);
+ }
+ deviceModel.addElement(entry);
+ for (int i = 0; i < deviceModel.size(); i++) {
+ if (deviceModel.elementAt(i) == entry) {
+ lsDevices.add(entry.getName());
+ lsDevices.select(i);
+ }
+ }
+ Config.addDeviceEntry(entry);
+ }
+ lsDevicesListener.widgetSelected(null);
+ } catch (IOException ex) {
+ Message.error("Error adding device profile, " + Message.getCauseMessage(ex), ex);
+ return;
+ }
+
+ }
+ }
+ };
+
+ private Listener btRemoveListener = new Listener() {
+ public void handleEvent(Event event) {
+ DeviceEntry entry = (DeviceEntry) deviceModel.elementAt(lsDevices.getSelectionIndex());
+
+ boolean canDeleteFile = true;
+ for (int i = 0; i < deviceModel.size(); i++) {
+ DeviceEntry test = (DeviceEntry) deviceModel.elementAt(i);
+ if (test != entry && test.getFileName() != null && test.getFileName().equals(entry.getFileName())) {
+ canDeleteFile = false;
+ break;
+ }
+ }
+ if (canDeleteFile) {
+ File deviceFile = new File(Config.getConfigPath(), entry.getFileName());
+ deviceFile.delete();
+ }
+
+ if (entry.isDefaultDevice()) {
+ for (int i = 0; i < deviceModel.size(); i++) {
+ DeviceEntry tmp = (DeviceEntry) deviceModel.elementAt(i);
+ if (!tmp.canRemove()) {
+ tmp.setDefaultDevice(true);
+ lsDevices.setItem(i, tmp.getName() + " (default)");
+ break;
+ }
+ }
+ }
+ for (int i = 0; i < deviceModel.size(); i++) {
+ if (deviceModel.elementAt(i) == entry) {
+ deviceModel.removeElementAt(i);
+ lsDevices.remove(i);
+ break;
+ }
+ }
+ lsDevicesListener.widgetSelected(null);
+ Config.removeDeviceEntry(entry);
+ }
+ };
+
+ private Listener btDefaultListener = new Listener() {
+ public void handleEvent(Event event) {
+ DeviceEntry entry = (DeviceEntry) deviceModel.elementAt(lsDevices.getSelectionIndex());
+ for (int i = 0; i < deviceModel.size(); i++) {
+ DeviceEntry tmp = (DeviceEntry) deviceModel.elementAt(i);
+ if (tmp == entry) {
+ tmp.setDefaultDevice(true);
+ lsDevices.setItem(i, tmp.getName() + " (default)");
+ } else {
+ tmp.setDefaultDevice(false);
+ lsDevices.setItem(i, tmp.getName());
+ }
+ Config.changeDeviceEntry(tmp);
+ }
+ btDefault.setEnabled(false);
+ }
+ };
+
+ SelectionAdapter lsDevicesListener = new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ int index = lsDevices.getSelectionIndex();
+ if (index != -1) {
+ selectedEntry = (DeviceEntry) deviceModel.elementAt(index);
+ if (selectedEntry.isDefaultDevice()) {
+ btDefault.setEnabled(false);
+ } else {
+ btDefault.setEnabled(true);
+ }
+ if (selectedEntry.canRemove()) {
+ btRemove.setEnabled(true);
+ } else {
+ btRemove.setEnabled(false);
+ }
+ btOk.setEnabled(true);
+ } else {
+ selectedEntry = null;
+ btDefault.setEnabled(false);
+ btRemove.setEnabled(false);
+ btOk.setEnabled(false);
+ }
+ }
+ };
+
+ public SwtSelectDeviceDialog(Shell parent, EmulatorContext emulatorContext) {
+ super(parent);
+
+ this.emulatorContext = emulatorContext;
+
+ Vector devs = Config.getDeviceEntries();
+ for (int i = 0; i < devs.size(); i++) {
+ DeviceEntry entry = (DeviceEntry) devs.elementAt(i);
+ if (entry.isDefaultDevice()) {
+ selectedEntry = entry;
+ }
+ }
+ }
+
+ protected void configureShell(Shell shell) {
+ super.configureShell(shell);
+
+ shell.setText("Select device...");
+ }
+
+ protected Control createDialogArea(Composite composite) {
+ GridLayout gridLayout = new GridLayout();
+ gridLayout.numColumns = 1;
+ composite.setLayout(gridLayout);
+
+ Group gpDevices = new Group(composite, SWT.NONE);
+ gpDevices.setText("Installed devices");
+ gridLayout = new GridLayout();
+ gridLayout.numColumns = 1;
+ gpDevices.setLayout(gridLayout);
+ gpDevices.setLayoutData(new GridData(GridData.FILL_BOTH));
+
+ lsDevices = new List(gpDevices, SWT.SINGLE | SWT.V_SCROLL);
+ GridData gridData = new GridData(GridData.FILL_BOTH);
+ gridData.horizontalSpan = 3;
+ gridData.grabExcessVerticalSpace = true;
+ Rectangle trim = lsDevices.computeTrim(0, 0, 0, lsDevices.getItemHeight() * 5);
+ gridData.heightHint = trim.height;
+ lsDevices.setLayoutData(gridData);
+ lsDevices.addSelectionListener(lsDevicesListener);
+
+ Composite btDevices = new Composite(gpDevices, SWT.NONE);
+ gridLayout = new GridLayout();
+ gridLayout.numColumns = 3;
+ btDevices.setLayout(gridLayout);
+ btDevices.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
+
+ btAdd = new Button(btDevices, SWT.PUSH);
+ btAdd.setText("Add...");
+ btAdd.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
+ btAdd.addListener(SWT.Selection, btAddListener);
+
+ btRemove = new Button(btDevices, SWT.PUSH);
+ btRemove.setText("Remove");
+ btRemove.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
+ btRemove.addListener(SWT.Selection, btRemoveListener);
+
+ btDefault = new Button(btDevices, SWT.PUSH);
+ btDefault.setText("Set as default");
+ btDefault.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
+ btDefault.addListener(SWT.Selection, btDefaultListener);
+
+ Vector devs = Config.getDeviceEntries();
+ deviceModel = new Vector();
+ for (int i = 0; i < devs.size(); i++) {
+ DeviceEntry entry = (DeviceEntry) devs.elementAt(i);
+ deviceModel.addElement(entry);
+ if (entry.isDefaultDevice()) {
+ lsDevices.add(entry.getName() + " (default)");
+ lsDevices.select(i);
+ } else {
+ lsDevices.add(entry.getName());
+ }
+ }
+
+ return composite;
+ }
+
+ protected Control createButtonBar(Composite parent) {
+ Control control = super.createButtonBar(parent);
+
+ lsDevicesListener.widgetSelected(null);
+
+ return control;
+ }
+
+ public DeviceEntry getSelectedDeviceEntry() {
+ return selectedEntry;
+ }
+
+}
Propchange: harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/app/ui/swt/SwtSelectDeviceDialog.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/BWImageFilter.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/BWImageFilter.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/BWImageFilter.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/BWImageFilter.java Mon May 26 15:20:19 2008
@@ -0,0 +1,71 @@
+/*
+ * 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.swt;
+
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGB;
+import org.microemu.app.ui.swt.ImageFilter;
+import org.microemu.app.ui.swt.SwtDeviceComponent;
+import org.microemu.device.DeviceFactory;
+
+
+
+public final class BWImageFilter implements ImageFilter
+{
+
+ private double Yr, Yg, Yb;
+ private Color backgroundColor;
+ private Color foregroundColor;
+
+
+ public BWImageFilter ()
+ {
+ this(0.2126d, 0.7152d, 0.0722d);
+ }
+
+
+ public BWImageFilter (double Yr, double Yg, double Yb)
+ {
+ this.Yr = Yr;
+ this.Yg = Yg;
+ this.Yb = Yb;
+ backgroundColor = SwtDeviceComponent.getColor(new RGB(
+ ((SwtDeviceDisplay) DeviceFactory.getDevice().getDeviceDisplay()).getBackgroundColor().getRed(),
+ ((SwtDeviceDisplay) DeviceFactory.getDevice().getDeviceDisplay()).getBackgroundColor().getGreen(),
+ ((SwtDeviceDisplay) DeviceFactory.getDevice().getDeviceDisplay()).getBackgroundColor().getBlue()));
+ foregroundColor = SwtDeviceComponent.getColor(new RGB(
+ ((SwtDeviceDisplay) DeviceFactory.getDevice().getDeviceDisplay()).getForegroundColor().getRed(),
+ ((SwtDeviceDisplay) DeviceFactory.getDevice().getDeviceDisplay()).getForegroundColor().getGreen(),
+ ((SwtDeviceDisplay) DeviceFactory.getDevice().getDeviceDisplay()).getForegroundColor().getBlue()));
+ }
+
+
+ public RGB filterRGB (int x, int y, RGB rgb)
+ {
+ int Y = (int)(Yr * rgb.red + Yg * rgb.green + Yb * rgb.blue);
+ if (Y > 127) {
+ return backgroundColor.getRGB();
+ } else {
+ return foregroundColor.getRGB();
+ }
+ }
+
+}
+
Propchange: harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/BWImageFilter.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/GrayImageFilter.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/GrayImageFilter.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/GrayImageFilter.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/GrayImageFilter.java Mon May 26 15:20:19 2008
@@ -0,0 +1,75 @@
+/*
+ * 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.swt;
+
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGB;
+import org.microemu.app.ui.swt.ImageFilter;
+import org.microemu.app.ui.swt.SwtDeviceComponent;
+import org.microemu.device.DeviceFactory;
+
+
+
+public final class GrayImageFilter implements ImageFilter
+{
+
+ private double Yr, Yg, Yb;
+ private double Rr, Rg, Rb;
+ private Color foregroundColor;
+
+ public GrayImageFilter ()
+ {
+ this(0.2126d, 0.7152d, 0.0722d);
+ }
+
+
+ public GrayImageFilter (double Yr, double Yg, double Yb)
+ {
+ this.Yr = Yr;
+ this.Yg = Yg;
+ this.Yb = Yb;
+ Color backgroundColor = SwtDeviceComponent.getColor(new RGB(
+ ((SwtDeviceDisplay) DeviceFactory.getDevice().getDeviceDisplay()).getBackgroundColor().getRed(),
+ ((SwtDeviceDisplay) DeviceFactory.getDevice().getDeviceDisplay()).getBackgroundColor().getGreen(),
+ ((SwtDeviceDisplay) DeviceFactory.getDevice().getDeviceDisplay()).getBackgroundColor().getBlue()));
+ foregroundColor = SwtDeviceComponent.getColor(new RGB(
+ ((SwtDeviceDisplay) DeviceFactory.getDevice().getDeviceDisplay()).getForegroundColor().getRed(),
+ ((SwtDeviceDisplay) DeviceFactory.getDevice().getDeviceDisplay()).getForegroundColor().getGreen(),
+ ((SwtDeviceDisplay) DeviceFactory.getDevice().getDeviceDisplay()).getForegroundColor().getBlue()));
+ Rr = (backgroundColor.getRed() - foregroundColor.getRed()) / 256d;
+ Rg = (backgroundColor.getGreen() - foregroundColor.getGreen()) / 256d;
+ Rb = (backgroundColor.getBlue() - foregroundColor.getBlue()) / 256d;
+ }
+
+
+ public RGB filterRGB (int x, int y, RGB rgb)
+ {
+ int Y = (int)(Yr * rgb.red + Yg * rgb.green + Yb * rgb.blue) % 256;
+ if (Y > 255) {
+ Y = 255;
+ }
+
+ return new RGB(
+ (int) (Rr * Y) + foregroundColor.getRed(),
+ (int) (Rg * Y) + foregroundColor.getGreen(),
+ (int) (Rb * Y) + foregroundColor.getBlue());
+ }
+
+}
Propchange: harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/GrayImageFilter.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/RGBImageFilter.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/RGBImageFilter.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/RGBImageFilter.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/RGBImageFilter.java Mon May 26 15:20:19 2008
@@ -0,0 +1,77 @@
+/*
+ * 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.swt;
+
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGB;
+import org.microemu.app.ui.swt.ImageFilter;
+import org.microemu.app.ui.swt.SwtDeviceComponent;
+import org.microemu.device.DeviceFactory;
+
+
+
+public final class RGBImageFilter implements ImageFilter
+{
+
+ private double Rr, Rg, Rb;
+ private Color backgroundColor;
+ private Color foregroundColor;
+
+
+ public RGBImageFilter()
+ {
+ backgroundColor = SwtDeviceComponent.getColor(new RGB(
+ ((SwtDeviceDisplay) DeviceFactory.getDevice().getDeviceDisplay()).getBackgroundColor().getRed(),
+ ((SwtDeviceDisplay) DeviceFactory.getDevice().getDeviceDisplay()).getBackgroundColor().getGreen(),
+ ((SwtDeviceDisplay) DeviceFactory.getDevice().getDeviceDisplay()).getBackgroundColor().getBlue()));
+ foregroundColor = SwtDeviceComponent.getColor(new RGB(
+ ((SwtDeviceDisplay) DeviceFactory.getDevice().getDeviceDisplay()).getForegroundColor().getRed(),
+ ((SwtDeviceDisplay) DeviceFactory.getDevice().getDeviceDisplay()).getForegroundColor().getGreen(),
+ ((SwtDeviceDisplay) DeviceFactory.getDevice().getDeviceDisplay()).getForegroundColor().getBlue()));
+ Rr = foregroundColor.getRed() - backgroundColor.getRed();
+ Rg = foregroundColor.getGreen() - backgroundColor.getGreen();
+ Rb = foregroundColor.getBlue() - backgroundColor.getBlue();
+ }
+
+
+ public RGB filterRGB (int x, int y, RGB rgb)
+ {
+ int r, g, b;
+
+ if (Rr > 0) {
+ r = (int) (rgb.red * Rr) / 255 + backgroundColor.getRed();
+ } else {
+ r = (int) (rgb.red * -Rr) / 255 + foregroundColor.getRed();
+ }
+ if (Rr > 0) {
+ g = (int) (rgb.green * Rg) / 255 + backgroundColor.getGreen();
+ } else {
+ g = (int) (rgb.green * -Rg) / 255 + foregroundColor.getGreen();
+ }
+ if (Rr > 0) {
+ b = (int) (rgb.blue * Rb) / 255 + backgroundColor.getBlue();
+ } else {
+ b = (int) (rgb.blue * -Rb) / 255 + foregroundColor.getBlue();
+ }
+
+ return new RGB(r, g, b);
+ }
+
+}
Propchange: harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/RGBImageFilter.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtButton.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtButton.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtButton.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtButton.java Mon May 26 15:20:19 2008
@@ -0,0 +1,187 @@
+/*
+ * 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.swt;
+
+import java.util.Hashtable;
+
+import javax.microedition.lcdui.Canvas;
+
+import org.eclipse.swt.SWT;
+import org.microemu.device.InputMethod;
+import org.microemu.device.impl.Button;
+import org.microemu.device.impl.Shape;
+
+
+
+public class SwtButton implements Button
+{
+
+ String name;
+ Shape shape;
+ private int keyboardKey;
+ private int keyCode;
+ private Hashtable inputToChars;
+
+
+ /**
+ * @param name
+ * @param shape
+ * @param keyCode - Integer.MIN_VALUE when unspecified
+ * @param keyName
+ * @param chars
+ */
+ public SwtButton(String name, Shape shape, int keyCode, String keyName, Hashtable inputToChars)
+ {
+ this.name = name;
+ this.shape = shape;
+ this.keyboardKey = parseKeyboardKey(keyName);
+
+ if (keyCode == Integer.MIN_VALUE) {
+ if (keyName != null) {
+ this.keyCode = this.keyboardKey;
+ } else {
+ this.keyCode = -1;
+ }
+ } else {
+ this.keyCode = keyCode;
+ }
+ this.inputToChars = inputToChars;
+ }
+
+
+ public int getKeyboardKey()
+ {
+ return keyboardKey;
+ }
+
+
+ public int getKeyCode()
+ {
+ return keyCode;
+ }
+
+
+ public char[] getChars(int inputMode)
+ {
+ char[] result = null;
+ switch (inputMode) {
+ case InputMethod.INPUT_123 :
+ result = (char[]) inputToChars.get("123");
+ break;
+ case InputMethod.INPUT_ABC_LOWER :
+ result = (char[]) inputToChars.get("abc");
+ break;
+ case InputMethod.INPUT_ABC_UPPER :
+ result = (char[]) inputToChars.get("ABC");
+ break;
+ }
+ if (result == null) {
+ result = (char[]) inputToChars.get("common");
+ }
+ if (result == null) {
+ result = new char[0];
+ }
+
+ return result;
+ }
+
+
+ public boolean isChar(char c, int inputMode)
+ {
+ c = Character.toLowerCase(c);
+ char[] chars = getChars(inputMode);
+ if (chars != null) {
+ for (int i = 0; i < chars.length; i++) {
+ if (c == Character.toLowerCase(chars[i])) {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+
+ public String getName()
+ {
+ return name;
+ }
+
+
+ public Shape getShape()
+ {
+ return shape;
+ }
+
+
+ private int parseKeyboardKey(String keyName)
+ {
+ if (keyName == null) {
+ return -1;
+ }
+ // TODO poprawic KeyEvent
+ if (keyName.equals("VK_LEFT")) {
+ return SWT.ARROW_LEFT;
+ } else if (keyName.equals("VK_RIGHT")) {
+ return SWT.ARROW_RIGHT;
+ } else if (keyName.equals("VK_UP")) {
+ return SWT.ARROW_UP;
+ } else if (keyName.equals("VK_DOWN")) {
+ return SWT.ARROW_DOWN;
+ } else if (keyName.equals("VK_ENTER")) {
+ return SWT.CR;
+ } else if (keyName.equals("VK_F1")) {
+ return SWT.F1;
+ } else if (keyName.equals("VK_F2")) {
+ return SWT.F2;
+ } else if (keyName.equals("VK_0")) {
+ return Canvas.KEY_NUM0;
+ } else if (keyName.equals("VK_1")) {
+ return Canvas.KEY_NUM1;
+ } else if (keyName.equals("VK_2")) {
+ return Canvas.KEY_NUM2;
+ } else if (keyName.equals("VK_3")) {
+ return Canvas.KEY_NUM3;
+ } else if (keyName.equals("VK_4")) {
+ return Canvas.KEY_NUM4;
+ } else if (keyName.equals("VK_5")) {
+ return Canvas.KEY_NUM5;
+ } else if (keyName.equals("VK_6")) {
+ return Canvas.KEY_NUM6;
+ } else if (keyName.equals("VK_7")) {
+ return Canvas.KEY_NUM7;
+ } else if (keyName.equals("VK_8")) {
+ return Canvas.KEY_NUM8;
+ } else if (keyName.equals("VK_9")) {
+ return Canvas.KEY_NUM9;
+ } else if (keyName.equals("VK_MULTIPLY")) {
+ return Canvas.KEY_STAR;
+ } else if (keyName.equals("VK_MODECHANGE")) {
+ return Canvas.KEY_POUND;
+ } else {
+ try {
+ return Integer.parseInt(keyName);
+ } catch (NumberFormatException ex) {
+ return -1;
+ }
+ }
+ }
+
+}
Propchange: harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtButton.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtDevice.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtDevice.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtDevice.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtDevice.java Mon May 26 15:20:19 2008
@@ -0,0 +1,70 @@
+/*
+ * 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.swt;
+
+import javax.microedition.lcdui.Alert;
+import javax.microedition.lcdui.Canvas;
+import javax.microedition.lcdui.Form;
+import javax.microedition.lcdui.List;
+import javax.microedition.lcdui.TextBox;
+
+import org.microemu.device.impl.DeviceImpl;
+import org.microemu.device.swt.ui.SwtCanvasUI;
+import org.microemu.device.swt.ui.SwtListUI;
+import org.microemu.device.swt.ui.SwtTextBoxUI;
+import org.microemu.device.ui.CanvasUI;
+import org.microemu.device.ui.DisplayableUI;
+import org.microemu.device.ui.ListUI;
+import org.microemu.device.ui.TextBoxUI;
+import org.microemu.device.ui.UIFactory;
+
+public class SwtDevice extends DeviceImpl {
+
+ private UIFactory ui = new UIFactory() {
+
+ public DisplayableUI createAlertUI(Alert alert) {
+ // TODO Not yet implemented
+ return new SwtCanvasUI(null);
+ }
+
+ public CanvasUI createCanvasUI(Canvas canvas) {
+ return new SwtCanvasUI(canvas);
+ }
+
+ public DisplayableUI createFormUI(Form form) {
+ // TODO Not yet implemented
+ return new SwtCanvasUI(null);
+ }
+
+ public ListUI createListUI(List list) {
+ return new SwtListUI(list);
+ }
+
+ public TextBoxUI createTextBoxUI(TextBox textBox) {
+ return new SwtTextBoxUI(textBox);
+ }
+
+ };
+
+ public UIFactory getUIFactory() {
+ return ui;
+ }
+
+}
Propchange: harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtDevice.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtDeviceDisplay.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtDeviceDisplay.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtDeviceDisplay.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtDeviceDisplay.java Mon May 26 15:20:19 2008
@@ -0,0 +1,557 @@
+/*
+ * 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.swt;
+
+import java.io.ByteArrayInputStream;
+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.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.ImageData;
+import org.eclipse.swt.graphics.RGB;
+import org.microemu.DisplayAccess;
+import org.microemu.EmulatorContext;
+import org.microemu.MIDletAccess;
+import org.microemu.MIDletBridge;
+import org.microemu.app.ui.swt.ImageFilter;
+import org.microemu.app.ui.swt.SwtDeviceComponent;
+import org.microemu.app.ui.swt.SwtGraphics;
+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 SwtDeviceDisplay implements DeviceDisplayImpl {
+ EmulatorContext context;
+
+ Rectangle displayRectangle;
+
+ Rectangle displayPaintable;
+
+ boolean isColor;
+
+ int numColors;
+
+ int numAlphaLevels;
+
+ Color backgroundColor;
+
+ Color foregroundColor;
+
+ PositionedImage mode123Image;
+
+ PositionedImage modeAbcUpperImage;
+
+ PositionedImage modeAbcLowerImage;
+
+ public SwtDeviceDisplay(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(SwtGraphics g) {
+ Device device = DeviceFactory.getDevice();
+
+ g.setBackground(g.getColor(new RGB(backgroundColor.getRed(), backgroundColor.getGreen(), backgroundColor
+ .getBlue())));
+ g.fillRectangle(0, 0, displayRectangle.width, displayPaintable.y);
+ g.fillRectangle(0, displayPaintable.y, displayPaintable.x, displayPaintable.height);
+ g.fillRectangle(displayPaintable.x + displayPaintable.width, displayPaintable.y, displayRectangle.width
+ - displayPaintable.x - displayPaintable.width, displayPaintable.height);
+ g.fillRectangle(0, displayPaintable.y + displayPaintable.height, displayRectangle.width,
+ displayRectangle.height - displayPaintable.y - displayPaintable.height);
+
+ g.setForeground(g.getColor(new RGB(foregroundColor.getRed(), foregroundColor.getGreen(), foregroundColor
+ .getBlue())));
+ for (Enumeration s = device.getSoftButtons().elements(); s.hasMoreElements();) {
+ ((SwtSoftButton) s.nextElement()).paint(g);
+ }
+
+ int inputMode = device.getInputMethod().getInputMode();
+ if (inputMode == InputMethod.INPUT_123) {
+ g.drawImage(((SwtImmutableImage) mode123Image.getImage()).getImage(), mode123Image.getRectangle().x,
+ mode123Image.getRectangle().y);
+ } else if (inputMode == InputMethod.INPUT_ABC_UPPER) {
+ g.drawImage(((SwtImmutableImage) modeAbcUpperImage.getImage()).getImage(),
+ modeAbcUpperImage.getRectangle().x, modeAbcUpperImage.getRectangle().y);
+ } else if (inputMode == InputMethod.INPUT_ABC_LOWER) {
+ g.drawImage(((SwtImmutableImage) modeAbcLowerImage.getImage()).getImage(),
+ modeAbcLowerImage.getRectangle().x, modeAbcLowerImage.getRectangle().y);
+ }
+ }
+
+ public void paintDisplayable(SwtGraphics 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.setForeground(g.getColor(new RGB(foregroundColor.getRed(), foregroundColor.getGreen(), foregroundColor
+ .getBlue())));
+
+ org.eclipse.swt.graphics.Rectangle oldclip = g.getClipping();
+ if (!(current instanceof Canvas) || ((Canvas) current).getWidth() != displayRectangle.width
+ || ((Canvas) current).getHeight() != displayRectangle.height) {
+ g.translate(displayPaintable.x, displayPaintable.y);
+ }
+ g.setClipping(new org.eclipse.swt.graphics.Rectangle(x, y, width, height));
+ Font oldf = g.getFont();
+ ma.getDisplayAccess().paint(new SwtDisplayGraphics(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.setClipping(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 Rectangle getDisplayRectangle() {
+ return displayRectangle;
+ }
+
+ public Rectangle getDisplayPaintable() {
+ return displayPaintable;
+ }
+
+ public Color getBackgroundColor() {
+ return backgroundColor;
+ }
+
+ public Color getForegroundColor() {
+ return foregroundColor;
+ }
+
+ public Image createImage(int width, int height) {
+ if (width <= 0 || height <= 0) {
+ throw new IllegalArgumentException();
+ }
+
+ return new SwtMutableImage(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 SwtImmutableImage((SwtMutableImage) source);
+ } else {
+ return source;
+ }
+ }
+
+ 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 Image createImage(InputStream is) throws IOException {
+ if (is == null) {
+ throw new IOException();
+ }
+
+ return getImage(is);
+ }
+
+ 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 = color;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.barteo.emulator.device.impl.DeviceDisplayImpl#setForegroundColor(java.awt.Color)
+ */
+ public void setForegroundColor(Color color) {
+ foregroundColor = color;
+ }
+
+ /*
+ * (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 {
+ return new SwtImmutableImage(SwtDeviceComponent.createImage(url.openStream()));
+ }
+
+ 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 {
+ ImageFilter filter = null;
+ if (isColor()) {
+ filter = new RGBImageFilter();
+ } else {
+ if (numColors() == 2) {
+ filter = new BWImageFilter();
+ } else {
+ filter = new GrayImageFilter();
+ }
+ }
+
+ return new SwtImmutableImage(SwtDeviceComponent.createImage(is, filter));
+ }
+
+ public Button createButton(int skinVersion, String name, Shape shape, int keyCode, String keyboardKeys,
+ String keyboardChars, Hashtable inputToChars, boolean modeChange) {
+ return new SwtButton(name, shape, keyCode, keyboardKeys, inputToChars);
+ }
+
+ public SoftButton createSoftButton(int skinVersion, String name, Shape shape, int keyCode, String keyName,
+ Rectangle paintable, String alignmentName, Vector commands, javax.microedition.lcdui.Font font) {
+ return new SwtSoftButton(name, shape, keyCode, keyName, paintable, alignmentName, commands, font);
+ }
+
+ public SoftButton createSoftButton(int skinVersion, String name, Rectangle paintable, Image normalImage,
+ Image pressedImage) {
+ return new SwtSoftButton(name, paintable, normalImage, pressedImage);
+ }
+
+ 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();
+
+ org.eclipse.swt.graphics.Image img = SwtDeviceComponent.createImage(width, height);
+ ImageData imageData = img.getImageData();
+
+ 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;
+ }
+
+ for (int y = 0; y < height; y++) {
+ imageData.setPixels(0, y, width, rgb, y * width);
+ }
+
+ // TODO now apply the corresponding filter
+ ImageFilter filter = null;
+ if (isColor()) {
+ filter = new RGBImageFilter();
+ } else {
+ if (numColors() == 2) {
+ filter = new BWImageFilter();
+ } else {
+ filter = new GrayImageFilter();
+ }
+ }
+
+ return new SwtImmutableImage(SwtDeviceComponent.createImage(imageData));
+ }
+
+ 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 SwtImmutableImage) {
+ ((SwtImmutableImage) image).getRGB(rgbData, 0, width, x, y, width, height);
+ } else {
+ ((SwtMutableImage) 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);
+ }
+
+ public boolean isResizable() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public void setResizable(boolean state) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
\ No newline at end of file
Propchange: harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtDeviceDisplay.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtDisplayGraphics.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtDisplayGraphics.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtDisplayGraphics.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtDisplayGraphics.java Mon May 26 15:20:19 2008
@@ -0,0 +1,336 @@
+/*
+ * 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.swt;
+
+import javax.microedition.lcdui.Image;
+
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.graphics.Rectangle;
+import org.microemu.DisplayAccess;
+import org.microemu.MIDletBridge;
+import org.microemu.app.ui.swt.ImageFilter;
+import org.microemu.app.ui.swt.SwtGraphics;
+import org.microemu.device.Device;
+import org.microemu.device.DeviceFactory;
+import org.microemu.device.DisplayGraphics;
+import org.microemu.device.MutableImage;
+
+
+public class SwtDisplayGraphics extends javax.microedition.lcdui.Graphics implements DisplayGraphics
+{
+ public SwtGraphics g;
+
+ private MutableImage image;
+ private int color = 0;
+ private javax.microedition.lcdui.Font currentFont = javax.microedition.lcdui.Font.getDefaultFont();
+ private ImageFilter filter;
+
+
+ public SwtDisplayGraphics(SwtGraphics a_g, MutableImage a_image)
+ {
+ this.g = a_g;
+ this.image = a_image;
+
+ Device device = DeviceFactory.getDevice();
+
+ this.g.setBackground(g.getColor(new RGB(
+ ((SwtDeviceDisplay) device.getDeviceDisplay()).getBackgroundColor().getRed(),
+ ((SwtDeviceDisplay) device.getDeviceDisplay()).getBackgroundColor().getGreen(),
+ ((SwtDeviceDisplay) device.getDeviceDisplay()).getBackgroundColor().getBlue())));
+ SwtFont tmpFont = (SwtFont) ((SwtFontManager) device.getFontManager()).getFont(currentFont);
+ this.g.setFont(tmpFont.getFont());
+
+ if (device.getDeviceDisplay().isColor()) {
+ this.filter = new RGBImageFilter();
+ } else {
+ if (device.getDeviceDisplay().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;
+
+ g.setForeground(g.getColor(filter.filterRGB(0, 0, new RGB((color >> 16) & 0xff, (color >> 8) & 0xff, color & 0xff))));
+ }
+
+
+ public javax.microedition.lcdui.Font getFont()
+ {
+ return currentFont;
+ }
+
+
+ public void setFont(javax.microedition.lcdui.Font font)
+ {
+ currentFont = font;
+ SwtFont tmpFont = (SwtFont)((SwtFontManager) DeviceFactory.getDevice().getFontManager()).getFont(currentFont);
+ g.setFont(tmpFont.getFont());
+ }
+
+
+ public void clipRect(int x, int y, int width, int height)
+ {
+ Rectangle rect = new Rectangle(x, y, width, height);
+
+ if (rect.x < getClipX()) {
+ rect.x = getClipX();
+ }
+
+ if (rect.y < getClipY()) {
+ rect.y = getClipY();
+ }
+
+ if (x + width > getClipX() + getClipWidth()) {
+ rect.width = getClipX() + getClipWidth() - rect.x;
+ } else {
+ rect.width = x + width - rect.x;
+ }
+
+ if (y + height > getClipY() + getClipHeight()) {
+ rect.height = getClipY() + getClipHeight() - rect.y;
+ } else {
+ rect.height = y + height - rect.y;
+ }
+
+ setClip(rect.x, rect.y, rect.width, rect.height);
+ }
+
+
+ public void setClip(int x, int y, int width, int height)
+ {
+ g.setClipping(x, y, width, height);
+ }
+
+
+ public int getClipX()
+ {
+ Rectangle rect = g.getClipping();
+ if (rect == null) {
+ return 0;
+ } else {
+ return rect.x;
+ }
+ }
+
+
+ public int getClipY()
+ {
+ Rectangle rect = g.getClipping();
+ if (rect == null) {
+ return 0;
+ } else {
+ return rect.y;
+ }
+ }
+
+
+ public int getClipHeight()
+ {
+ Rectangle rect = g.getClipping();
+ if (rect == null) {
+ DisplayAccess da = MIDletBridge.getMIDletAccess().getDisplayAccess();
+ return da.getCurrent().getHeight();
+ } else {
+ return rect.height;
+ }
+ }
+
+
+ public int getClipWidth()
+ {
+ Rectangle rect = g.getClipping();
+ if (rect == null) {
+ DisplayAccess da = MIDletBridge.getMIDletAccess().getDisplayAccess();
+ return da.getCurrent().getWidth();
+ } else {
+ return rect.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(((SwtMutableImage) img).getImage(), newx, newy);
+ } else {
+ g.drawImage(((SwtImmutableImage) img).getImage(), newx, newy);
+ }
+ }
+
+
+ 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 drawRegion(Image src, int x_src, int y_src, int width, int height, int transform, int x_dst, int y_dst, int anchor) {
+ // TODO implement drawRegion
+ super.drawRegion(src, x_src, y_src, width, height, transform, x_dst, y_dst,
+ anchor);
+ }
+
+
+ public void drawRGB(int[] rgbData, int offset, int scanlength, int x, int y, int width, int height, boolean processAlpha) {
+ // TODO implement drawRGB
+ super.drawRGB(rgbData, offset, scanlength, x, y, width, height, processAlpha);
+ }
+
+
+ public void fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3) {
+ int[] points = new int[6];
+ points[0] = x1;
+ points[1] = y1;
+ points[2] = x2;
+ points[3] = y2;
+ points[4] = x3;
+ points[5] = y3;
+
+ g.fillPolygon(points);
+ }
+
+
+ public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
+ {
+ g.drawRoundRectangle(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.VCENTER) != 0) {
+ newy -= g.getFontMetrics().getAscent();
+ } else if ((anchor & javax.microedition.lcdui.Graphics.BOTTOM) != 0) {
+ newy -= g.getFontMetrics().getHeight();
+ }
+ if ((anchor & javax.microedition.lcdui.Graphics.HCENTER) != 0) {
+ newx -= g.stringWidth(str) / 2;
+ } else if ((anchor & javax.microedition.lcdui.Graphics.RIGHT) != 0) {
+ newx -= g.stringWidth(str);
+ }
+
+ boolean textAntialiasing = ((SwtFontManager) DeviceFactory.getDevice().getFontManager()).getAntialiasing();
+ boolean graphicsAntialiasing = g.getAntialias();
+ if (textAntialiasing != graphicsAntialiasing) {
+ g.setAntialias(textAntialiasing);
+ }
+
+ g.drawString(str, newx, newy, true);
+
+ if (textAntialiasing != graphicsAntialiasing) {
+ g.setAntialias(graphicsAntialiasing);
+ }
+
+ if ((currentFont.getStyle() & javax.microedition.lcdui.Font.STYLE_UNDERLINED) != 0) {
+ g.drawLine(newx, newy + 1, newx + g.stringWidth(str), newy + 1);
+ }
+ }
+
+
+ public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle)
+ {
+ Color tmp = g.getBackground();
+ g.setBackground(g.getForeground());
+ g.fillArc(x, y, width, height, startAngle, arcAngle);
+ g.setBackground(tmp);
+ }
+
+
+ public void fillRect(int x, int y, int width, int height)
+ {
+ Color tmp = g.getBackground();
+ g.setBackground(g.getForeground());
+ g.fillRectangle(x, y, width, height);
+ g.setBackground(tmp);
+ }
+
+
+ public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
+ {
+ g.fillRoundRectangle(x, y, width, height, arcWidth, arcHeight);
+ }
+
+
+ public void translate(int x, int y)
+ {
+ super.translate(x, y);
+ g.translate(x, y);
+ }
+
+}
Propchange: harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtDisplayGraphics.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtFont.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtFont.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtFont.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtFont.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.swt;
+
+import org.eclipse.swt.graphics.Font;
+
+public interface SwtFont extends org.microemu.device.impl.Font {
+
+ Font getFont();
+
+ void setAntialiasing(boolean antialiasing);
+
+}
Propchange: harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtFont.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtFontManager.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtFontManager.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtFontManager.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtFontManager.java Mon May 26 15:20:19 2008
@@ -0,0 +1,179 @@
+/*
+ * 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.swt;
+
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.Hashtable;
+
+import javax.microedition.lcdui.Font;
+
+import org.eclipse.swt.graphics.FontMetrics;
+import org.microemu.app.ui.swt.SwtDeviceComponent;
+import org.microemu.device.impl.FontManagerImpl;
+
+public class SwtFontManager implements FontManagerImpl {
+
+ static String FACE_SYSTEM_NAME = "SansSerif";
+
+ static String FACE_MONOSPACE_NAME = "Monospaced";
+
+ static String FACE_PROPORTIONAL_NAME = "SansSerif";
+
+ static int SIZE_SMALL = 6;
+
+ static int SIZE_MEDIUM = 8;
+
+ static int SIZE_LARGE = 10;
+
+ 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 SwtSystemFont(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()) {
+ SwtFont font = (SwtFont) 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 SwtSystemFont(defName, defStyle, defSize, antialiasing);
+ }
+
+ public org.microemu.device.impl.Font createTrueTypeFont(URL defUrl, String defStyle, int defSize, boolean antialiasing) {
+ return new SwtTrueTypeFont(defUrl, defStyle, defSize, antialiasing);
+ }
+
+}
Propchange: harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtFontManager.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtImmutableImage.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtImmutableImage.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtImmutableImage.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtImmutableImage.java Mon May 26 15:20:19 2008
@@ -0,0 +1,94 @@
+/*
+ * 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.swt;
+
+import org.eclipse.swt.graphics.ImageData;
+import org.microemu.app.ui.swt.SwtDeviceComponent;
+
+
+public class SwtImmutableImage extends javax.microedition.lcdui.Image
+{
+ org.eclipse.swt.graphics.Image img;
+
+
+ public SwtImmutableImage(org.eclipse.swt.graphics.Image image)
+ {
+ img = image;
+ }
+
+
+ public SwtImmutableImage(SwtMutableImage image)
+ {
+ img = SwtDeviceComponent.createImage(image.getImage());
+ }
+
+
+ public int getHeight()
+ {
+ return img.getBounds().height;
+ }
+
+
+ public org.eclipse.swt.graphics.Image getImage()
+ {
+ return img;
+ }
+
+
+ public int getWidth()
+ {
+ return img.getBounds().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();
+ }
+ }
+
+ ImageData imageData = img.getImageData();
+ for (int i = 0; i < height; i++) {
+ imageData.getPixels(x, y + i, width, argb, offset + i * scanlength);
+ }
+ }
+
+}
Propchange: harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtImmutableImage.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtInputMethod.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtInputMethod.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtInputMethod.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtInputMethod.java Mon May 26 15:20:19 2008
@@ -0,0 +1,450 @@
+/*
+ * 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.swt;
+
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.Timer;
+import java.util.TimerTask;
+
+import javax.microedition.lcdui.Canvas;
+import javax.microedition.lcdui.Command;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.KeyEvent;
+import org.microemu.DisplayAccess;
+import org.microemu.MIDletAccess;
+import org.microemu.MIDletBridge;
+import org.microemu.device.DeviceFactory;
+import org.microemu.device.InputMethodEvent;
+import org.microemu.device.impl.InputMethodImpl;
+import org.microemu.device.impl.SoftButton;
+
+public class SwtInputMethod extends InputMethodImpl {
+
+ private Timer keyRepeatTimer;
+
+ private int repeatModeKeyCode;
+
+ private boolean clearRepeatFlag;
+
+ private class KeyRepeatTask extends TimerTask {
+ public void run() {
+ if (repeatModeKeyCode != Integer.MIN_VALUE) {
+ MIDletAccess ma = MIDletBridge.getMIDletAccess();
+ if (ma == null) {
+ return;
+ }
+
+ DisplayAccess da = ma.getDisplayAccess();
+ if (da == null) {
+ return;
+ }
+
+ if (clearRepeatFlag) {
+ da.keyReleased(repeatModeKeyCode);
+ repeatModeKeyCode = Integer.MIN_VALUE;
+ }
+ }
+ }
+ };
+
+ public SwtInputMethod() {
+ super();
+
+ // TODO When InputMethod will be removed from EmulatorContext add:
+ // if (DeviceFactory.getDevice().hasRepeatEvents()) {
+ keyRepeatTimer = new Timer();
+ repeatModeKeyCode = Integer.MIN_VALUE;
+ clearRepeatFlag = false;
+ }
+
+ public int getGameAction(int keyCode) {
+ // TODO fix KeyEvent
+ switch (keyCode) {
+ case SWT.ARROW_UP:
+ return Canvas.UP;
+
+ case SWT.ARROW_DOWN:
+ return Canvas.DOWN;
+
+ case SWT.ARROW_LEFT:
+ return Canvas.LEFT;
+
+ case SWT.ARROW_RIGHT:
+ return Canvas.RIGHT;
+
+ case SWT.CR:
+ return Canvas.FIRE;
+
+ /*
+ * case KeyEvent.VK_1: case KeyEvent.VK_A: return Canvas.GAME_A;
+ *
+ * case KeyEvent.VK_3: case KeyEvent.VK_B: return Canvas.GAME_B;
+ *
+ * case KeyEvent.VK_7: case KeyEvent.VK_C: return Canvas.GAME_C;
+ *
+ * case KeyEvent.VK_9: case KeyEvent.VK_D: return Canvas.GAME_D;
+ */
+
+ default:
+ return 0;
+ }
+ }
+
+ public int getKeyCode(int gameAction) {
+ // TODO fix KeyEvent
+ switch (gameAction) {
+ case Canvas.UP:
+ return SWT.ARROW_UP;
+
+ case Canvas.DOWN:
+ return SWT.ARROW_DOWN;
+
+ case Canvas.LEFT:
+ return SWT.ARROW_LEFT;
+
+ case Canvas.RIGHT:
+ return SWT.ARROW_RIGHT;
+
+ case Canvas.FIRE:
+ return SWT.CR;
+
+ /*
+ * case Canvas.GAME_A: return KeyEvent.VK_1;
+ *
+ * case Canvas.GAME_B: return KeyEvent.VK_3;
+ *
+ * case Canvas.GAME_C: return KeyEvent.VK_7;
+ *
+ * case Canvas.GAME_D: return KeyEvent.VK_9;
+ */
+
+ default:
+ throw new IllegalArgumentException();
+ }
+ }
+
+ public String getKeyName(int keyCode) throws IllegalArgumentException {
+ for (Iterator it = DeviceFactory.getDevice().getButtons().iterator(); it.hasNext();) {
+ SwtButton button = (SwtButton) it.next();
+ if (button.getKeyCode() == keyCode) {
+ return button.getName();
+ }
+ }
+
+ for (Iterator it = DeviceFactory.getDevice().getButtons().iterator(); it.hasNext();) {
+ SwtButton button = (SwtButton) it.next();
+ if (button.getKeyboardKey() == keyCode) {
+ return button.getName();
+ }
+ }
+
+ throw new IllegalArgumentException();
+ }
+
+ private boolean commonKeyPressed(KeyEvent ev) {
+ int keyCode = ev.keyCode;
+ if (inputMethodListener == null) {
+ int midpKeyCode;
+ switch (ev.keyCode) {
+ case SWT.BS:
+ return true;
+ default:
+ midpKeyCode = keyCode;
+ }
+ switch (ev.character) {
+ case '*':
+ midpKeyCode = Canvas.KEY_STAR;
+ break;
+ case '#':
+ midpKeyCode = Canvas.KEY_POUND;
+ break;
+ default:
+ midpKeyCode = keyCode;
+ }
+ MIDletBridge.getMIDletAccess().getDisplayAccess().keyPressed(midpKeyCode);
+ return true;
+ }
+
+ if (getGameAction(keyCode) == Canvas.UP || getGameAction(keyCode) == Canvas.DOWN) {
+ MIDletBridge.getMIDletAccess().getDisplayAccess().keyPressed(keyCode);
+ return true;
+ }
+
+ // TODO fix KeyEvent
+ /*
+ * if (keyCode == KeyEvent.VK_MODECHANGE) { 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,
+ * text); inputMethodListener.caretPositionChanged(event); return true;
+ */
+
+ int caret = inputMethodListener.getCaretPosition();
+
+ if (getGameAction(keyCode) == Canvas.LEFT || getGameAction(keyCode) == Canvas.RIGHT) {
+ synchronized (this) {
+ if (getGameAction(keyCode) == Canvas.LEFT && caret > 0) {
+ caret--;
+ }
+ if (getGameAction(keyCode) == Canvas.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 (keyCode == SWT.BS) {
+ String tmp = inputMethodListener.getText();
+ synchronized (this) {
+ if (lastButton != null) {
+ caret++;
+ lastButton = null;
+ lastButtonCharIndex = -1;
+ }
+ if (caret > 0) {
+ caret--;
+ tmp = "";
+ 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 (keyCode == SWT.DEL) {
+ 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 (keyCode == SWT.SHIFT || keyCode == SWT.CTRL || keyCode == SWT.ALT) {
+ return true;
+ }
+
+ return false;
+ }
+
+ public void keyPressed(KeyEvent ev) {
+ if (DeviceFactory.getDevice().hasRepeatEvents() && inputMethodListener == null) {
+ clearRepeatFlag = false;
+ if (repeatModeKeyCode == ev.keyCode) {
+ MIDletAccess ma = MIDletBridge.getMIDletAccess();
+ if (ma == null) {
+ return;
+ }
+
+ DisplayAccess da = ma.getDisplayAccess();
+ if (da == null) {
+ return;
+ }
+
+ da.keyRepeated(ev.keyCode);
+
+ return;
+ }
+
+ repeatModeKeyCode = ev.keyCode;
+ }
+
+ // invoke any associated commands, but send the raw key codes instead
+ boolean rawSoftKeys = DeviceFactory.getDevice().getDeviceDisplay().isFullScreenMode();
+ SwtButton pressedButton = getButton(ev);
+ if (pressedButton != null) {
+ if (pressedButton instanceof SoftButton && !rawSoftKeys) {
+ Command cmd = ((SoftButton) pressedButton).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());
+ return;
+ }
+ }
+ }
+
+ if (commonKeyPressed(ev)) {
+ return;
+ }
+
+ if (inputMethodListener.getText().length() < maxSize && (ev.keyCode & SWT.EMBEDDED) == 0) {
+ insertText(new Character(ev.character).toString());
+ }
+ }
+
+ public void keyReleased(KeyEvent ev) {
+ if (DeviceFactory.getDevice().hasRepeatEvents() && inputMethodListener == null) {
+ clearRepeatFlag = true;
+ keyRepeatTimer.schedule(new KeyRepeatTask(), 50);
+ } else {
+ MIDletAccess ma = MIDletBridge.getMIDletAccess();
+ if (ma == null) {
+ return;
+ }
+
+ DisplayAccess da = ma.getDisplayAccess();
+ if (da == null) {
+ return;
+ }
+
+ da.keyReleased(ev.keyCode);
+ }
+ }
+
+ public void mousePressed(KeyEvent ev) {
+ if (commonKeyPressed(ev)) {
+ return;
+ }
+
+ if (inputMethodListener.getText().length() < maxSize) {
+ for (Enumeration e = DeviceFactory.getDevice().getButtons().elements(); e.hasMoreElements();) {
+ SwtButton button = (SwtButton) e.nextElement();
+ if (ev.keyCode == button.getKeyCode()) {
+ int caret = inputMethodListener.getCaretPosition();
+ String tmp = inputMethodListener.getText();
+ synchronized (this) {
+ lastButtonCharIndex++;
+ char[] buttonChars = filterConstraints(filterInputMode(button.getChars(getInputMode())));
+ 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++;
+ }
+ tmp = "";
+ if (caret > 0) {
+ tmp += inputMethodListener.getText().substring(0, caret);
+ }
+ tmp += buttonChars[0];
+ if (caret < inputMethodListener.getText().length()) {
+ tmp += inputMethodListener.getText().substring(caret);
+ }
+ lastButton = button;
+ lastButtonCharIndex = 0;
+ } else {
+ tmp = "";
+ if (caret > 0) {
+ tmp += inputMethodListener.getText().substring(0, caret);
+ }
+ tmp += buttonChars[lastButtonCharIndex];
+ if (caret < inputMethodListener.getText().length() - 1) {
+ tmp += inputMethodListener.getText().substring(caret + 1);
+ }
+ lastButton = button;
+ }
+ } else {
+ lastButton = null;
+ lastButtonCharIndex = -1;
+ }
+ resetKey = false;
+ notify();
+ }
+ if (!validate(tmp, inputMethodListener.getConstraints())) {
+ return;
+ }
+ InputMethodEvent event = new InputMethodEvent(InputMethodEvent.INPUT_METHOD_TEXT_CHANGED, caret,
+ tmp);
+ inputMethodListener.inputMethodTextChanged(event);
+ break;
+ }
+ }
+ }
+ }
+
+ public void mouseReleased(int keyCode) {
+ MIDletAccess ma = MIDletBridge.getMIDletAccess();
+ if (ma == null) {
+ return;
+ }
+
+ DisplayAccess da = ma.getDisplayAccess();
+ if (da == null) {
+ return;
+ }
+
+ da.keyReleased(keyCode);
+ }
+
+ public SwtButton getButton(KeyEvent ev) {
+ for (Enumeration e = DeviceFactory.getDevice().getButtons().elements(); e.hasMoreElements();) {
+ SwtButton button = (SwtButton) e.nextElement();
+ if (ev.keyCode == button.getKeyCode()) {
+ return button;
+ }
+ if (button.isChar(ev.character, getInputMode())) {
+ return button;
+ }
+ }
+
+ return null;
+ }
+
+}
Propchange: harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtInputMethod.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtMutableImage.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtMutableImage.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtMutableImage.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtMutableImage.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.swt;
+
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.ImageData;
+import org.microemu.app.ui.swt.SwtDeviceComponent;
+import org.microemu.app.ui.swt.SwtGraphics;
+import org.microemu.device.MutableImage;
+
+
+public class SwtMutableImage extends MutableImage
+{
+ public org.eclipse.swt.graphics.Image img;
+
+ private org.eclipse.swt.graphics.GC gc;
+
+
+ public SwtMutableImage(int width, int height)
+ {
+ this.img = SwtDeviceComponent.createImage(width, height);
+ this.gc = new GC(this.img);
+ SwtDisplayGraphics displayGraphics = new SwtDisplayGraphics(new SwtGraphics(gc), this);
+ displayGraphics.setColor(0x00ffffff);
+ displayGraphics.fillRect(0, 0, width, height);
+ }
+
+
+ public javax.microedition.lcdui.Graphics getGraphics()
+ {
+ SwtDisplayGraphics displayGraphics = new SwtDisplayGraphics(new SwtGraphics(gc), this);
+ displayGraphics.setColor(0x00000000);
+ displayGraphics.setClip(0, 0, getWidth(), getHeight());
+ displayGraphics.translate(-displayGraphics.getTranslateX(), -displayGraphics.getTranslateY());
+
+ return displayGraphics;
+ }
+
+
+ public boolean isMutable()
+ {
+ return true;
+ }
+
+
+ public int getHeight()
+ {
+ return img.getBounds().height;
+ }
+
+
+ public org.eclipse.swt.graphics.Image getImage()
+ {
+ return img;
+ }
+
+
+ public int getWidth()
+ {
+ return img.getBounds().width;
+ }
+
+
+ public int[] getData()
+ {
+ byte[] tmp = img.getImageData().data;
+ int[] result = new int[tmp.length];
+
+ for (int i = 0; i < tmp.length; i++) {
+ result[i] = tmp[i];
+ }
+
+ return result;
+ }
+
+
+ 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();
+ }
+ }
+
+ ImageData imageData = img.getImageData();
+ for (int i = 0; i < height; i++) {
+ imageData.getPixels(x, y + i, width, argb, offset + i * scanlength);
+ }
+ }
+
+}
Propchange: harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtMutableImage.java
------------------------------------------------------------------------------
svn:eol-style = native