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 [5/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/app/Main.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/Main.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/Main.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/Main.java Mon May 26 15:20:19 2008
@@ -0,0 +1,925 @@
+/*
+ *  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;
+
+import java.awt.BorderLayout;
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.FontMetrics;
+import java.awt.Toolkit;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.ComponentAdapter;
+import java.awt.event.ComponentEvent;
+import java.awt.event.ComponentListener;
+import java.awt.event.KeyEvent;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.Timer;
+import java.util.TimerTask;
+
+import javax.microedition.midlet.MIDletStateChangeException;
+import javax.swing.JButton;
+import javax.swing.JCheckBoxMenuItem;
+import javax.swing.JFileChooser;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JMenu;
+import javax.swing.JMenuBar;
+import javax.swing.JMenuItem;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.KeyStroke;
+import javax.swing.UIManager;
+
+import org.microemu.DisplayAccess;
+import org.microemu.DisplayComponent;
+import org.microemu.EmulatorContext;
+import org.microemu.MIDletAccess;
+import org.microemu.MIDletBridge;
+import org.microemu.app.capture.AnimatedGifEncoder;
+import org.microemu.app.classloader.MIDletClassLoader;
+import org.microemu.app.ui.DisplayRepaintListener;
+import org.microemu.app.ui.Message;
+import org.microemu.app.ui.ResponseInterfaceListener;
+import org.microemu.app.ui.StatusBarListener;
+import org.microemu.app.ui.swing.DropTransferHandler;
+import org.microemu.app.ui.swing.ExtensionFileFilter;
+import org.microemu.app.ui.swing.JMRUMenu;
+import org.microemu.app.ui.swing.JadUrlPanel;
+import org.microemu.app.ui.swing.RecordStoreManagerDialog;
+import org.microemu.app.ui.swing.ResizeDeviceDisplayDialog;
+import org.microemu.app.ui.swing.SwingAboutDialog;
+import org.microemu.app.ui.swing.SwingDeviceComponent;
+import org.microemu.app.ui.swing.SwingDialogWindow;
+import org.microemu.app.ui.swing.SwingDisplayComponent;
+import org.microemu.app.ui.swing.SwingErrorMessageDialogPanel;
+import org.microemu.app.ui.swing.SwingLogConsoleDialog;
+import org.microemu.app.ui.swing.SwingSelectDevicePanel;
+import org.microemu.app.util.AppletProducer;
+import org.microemu.app.util.DeviceEntry;
+import org.microemu.app.util.IOUtils;
+import org.microemu.app.util.MidletURLReference;
+import org.microemu.device.Device;
+import org.microemu.device.DeviceDisplay;
+import org.microemu.device.DeviceFactory;
+import org.microemu.device.FontManager;
+import org.microemu.device.InputMethod;
+import org.microemu.device.MutableImage;
+import org.microemu.device.impl.DeviceDisplayImpl;
+import org.microemu.device.impl.DeviceImpl;
+import org.microemu.device.impl.Rectangle;
+import org.microemu.device.j2se.J2SEDevice;
+import org.microemu.device.j2se.J2SEDeviceDisplay;
+import org.microemu.device.j2se.J2SEFontManager;
+import org.microemu.device.j2se.J2SEInputMethod;
+import org.microemu.device.j2se.J2SEMutableImage;
+import org.microemu.log.Logger;
+import org.microemu.log.QueueAppender;
+import org.microemu.util.JadMidletEntry;
+
+public class Main extends JFrame {
+
+	private static final long serialVersionUID = 1L;
+
+	protected Common common;
+
+	protected SwingSelectDevicePanel selectDevicePanel = null;
+
+	private JadUrlPanel jadUrlPanel = null;
+
+	private JFileChooser saveForWebChooser;
+
+	private JFileChooser fileChooser = null;
+
+	private JFileChooser captureFileChooser = null;
+
+	private JMenuItem menuOpenJADFile;
+
+	private JMenuItem menuOpenJADURL;
+
+	private JMenuItem menuSelectDevice;
+
+	private JMenuItem menuSaveForWeb;
+
+	private JMenuItem menuStartCapture;
+
+	private JMenuItem menuStopCapture;
+
+	private JCheckBoxMenuItem menuMIDletNetworkConnection;
+
+	private JCheckBoxMenuItem menuLogConsole;
+
+	private JCheckBoxMenuItem menuRecordStoreManager;
+
+	private SwingDeviceComponent devicePanel;
+
+	private SwingLogConsoleDialog logConsoleDialog;
+
+	private RecordStoreManagerDialog recordStoreManagerDialog;
+
+	private QueueAppender logQueueAppender;
+
+	private DeviceEntry deviceEntry;
+
+	private AnimatedGifEncoder encoder;
+
+	private JLabel statusBar = new JLabel("Status");
+
+	private JButton resizeButton = new JButton("Resize");
+
+	private ResizeDeviceDisplayDialog resizeDeviceDisplayDialog = null;
+
+	protected EmulatorContext emulatorContext = new EmulatorContext() {
+
+		private InputMethod inputMethod = new J2SEInputMethod();
+
+		private DeviceDisplay deviceDisplay = new J2SEDeviceDisplay(this);
+
+		private FontManager fontManager = new J2SEFontManager();
+
+		public DisplayComponent getDisplayComponent() {
+			return devicePanel.getDisplayComponent();
+		}
+
+		public InputMethod getDeviceInputMethod() {
+			return inputMethod;
+		}
+
+		public DeviceDisplay getDeviceDisplay() {
+			return deviceDisplay;
+		}
+
+		public FontManager getDeviceFontManager() {
+			return fontManager;
+		}
+
+		public InputStream getResourceAsStream(String name) {
+			return MIDletBridge.getCurrentMIDlet().getClass().getResourceAsStream(name);
+		}
+	};
+
+	private ActionListener menuOpenJADFileListener = new ActionListener() {
+		public void actionPerformed(ActionEvent ev) {
+			if (fileChooser == null) {
+				ExtensionFileFilter fileFilter = new ExtensionFileFilter("JAD files");
+				fileFilter.addExtension("jad");
+				// TODO- Read manifest in jar
+				// fileFilter.addExtension("jar");
+				fileChooser = new JFileChooser();
+				fileChooser.setFileFilter(fileFilter);
+				fileChooser.setDialogTitle("Open JAD File...");
+				fileChooser.setCurrentDirectory(new File(Config.getRecentDirectory("recentJadDirectory")));
+			}
+
+			int returnVal = fileChooser.showOpenDialog(Main.this);
+			if (returnVal == JFileChooser.APPROVE_OPTION) {
+				Config.setRecentDirectory("recentJadDirectory", fileChooser.getCurrentDirectory().getAbsolutePath());
+				String url = IOUtils.getCanonicalFileURL(fileChooser.getSelectedFile());
+				Common.openJadUrlSafe(url);
+				if (recordStoreManagerDialog != null) {
+					recordStoreManagerDialog.refresh();
+				}
+			}
+		}
+	};
+
+	private ActionListener menuOpenJADURLListener = new ActionListener() {
+		public void actionPerformed(ActionEvent ev) {
+			if (jadUrlPanel == null) {
+				jadUrlPanel = new JadUrlPanel();
+			}
+			if (SwingDialogWindow.show(Main.this, "Enter JAD URL:", jadUrlPanel, true)) {
+				Common.openJadUrlSafe(jadUrlPanel.getText());
+				if (recordStoreManagerDialog != null) {
+					recordStoreManagerDialog.refresh();
+				}
+			}
+		}
+	};
+
+	private ActionListener menuCloseMidletListener = new ActionListener() {
+		public void actionPerformed(ActionEvent e) {
+			common.startLauncher(MIDletBridge.getMIDletContext());
+		}
+	};
+
+	private ActionListener menuSaveForWebListener = new ActionListener() {
+		public void actionPerformed(ActionEvent e) {
+			if (saveForWebChooser == null) {
+				ExtensionFileFilter fileFilter = new ExtensionFileFilter("HTML files");
+				fileFilter.addExtension("html");
+				saveForWebChooser = new JFileChooser();
+				saveForWebChooser.setFileFilter(fileFilter);
+				saveForWebChooser.setDialogTitle("Save for Web...");
+				saveForWebChooser.setCurrentDirectory(new File(Config.getRecentDirectory("recentSaveForWebDirectory")));
+			}
+			if (saveForWebChooser.showSaveDialog(Main.this) == JFileChooser.APPROVE_OPTION) {
+				Config.setRecentDirectory("recentSaveForWebDirectory", saveForWebChooser.getCurrentDirectory()
+						.getAbsolutePath());
+				File pathFile = saveForWebChooser.getSelectedFile().getParentFile();
+
+				String name = saveForWebChooser.getSelectedFile().getName();
+				if (!name.toLowerCase().endsWith(".html") && name.indexOf('.') == -1) {
+					name = name + ".html";
+				}
+
+				// try to get from distribution home location
+				String resource = MIDletClassLoader.getClassResourceName(this.getClass().getName());
+				URL url = this.getClass().getClassLoader().getResource(resource);
+				String path = url.getPath();
+				int prefix = path.indexOf(':');
+				String mainJarFileName = path.substring(prefix + 1, path.length() - resource.length());
+				File appletJarDir = new File(new File(mainJarFileName).getParent(), "lib");
+				File appletJarFile = new File(appletJarDir, "microemu-javase-applet.jar");
+				if (!appletJarFile.exists()) {
+					appletJarFile = null;
+				}
+
+				if (appletJarFile == null) {
+					// try to get from maven2 repository
+					/*
+					 * loc/org/microemu/microemulator/2.0.1-SNAPSHOT/microemulator-2.0.1-20070227.080140-1.jar
+					 * String version = doRegExpr(mainJarFileName, ); String
+					 * basePath = "loc/org/microemu/" appletJarFile = new
+					 * File(basePath + "microemu-javase-applet/" + version +
+					 * "/microemu-javase-applet" + version + ".jar"); if
+					 * (!appletJarFile.exists()) { appletJarFile = null; }
+					 */
+				}
+
+				if (appletJarFile == null) {
+					ExtensionFileFilter fileFilter = new ExtensionFileFilter("JAR packages");
+					fileFilter.addExtension("jar");
+					JFileChooser appletChooser = new JFileChooser();
+					appletChooser.setFileFilter(fileFilter);
+					appletChooser.setDialogTitle("Select MicroEmulator applet jar package...");
+					appletChooser.setCurrentDirectory(new File(Config.getRecentDirectory("recentAppletJarDirectory")));
+					if (appletChooser.showOpenDialog(Main.this) == JFileChooser.APPROVE_OPTION) {
+						Config.setRecentDirectory("recentAppletJarDirectory", appletChooser.getCurrentDirectory()
+								.getAbsolutePath());
+						appletJarFile = appletChooser.getSelectedFile();
+					} else {
+						return;
+					}
+				}
+
+				JadMidletEntry jadMidletEntry;
+				Iterator it = common.jad.getMidletEntries().iterator();
+				if (it.hasNext()) {
+					jadMidletEntry = (JadMidletEntry) it.next();
+				} else {
+					Message.error("MIDlet Suite has no entries");
+					return;
+				}
+
+				String midletInput = common.jad.getJarURL();
+				DeviceEntry deviceInput = selectDevicePanel.getSelectedDeviceEntry();
+				if (deviceInput != null && deviceInput.getDescriptorLocation().equals(DeviceImpl.DEFAULT_LOCATION)) {
+					deviceInput = null;
+				}
+
+				File htmlOutputFile = new File(pathFile, name);
+				if (!allowOverride(htmlOutputFile)) {
+					return;
+				}
+				File appletPackageOutputFile = new File(pathFile, "microemu-javase-applet.jar");
+				if (!allowOverride(appletPackageOutputFile)) {
+					return;
+				}
+				File midletOutputFile = new File(pathFile, midletInput.substring(midletInput.lastIndexOf("/") + 1));
+				if (!allowOverride(midletOutputFile)) {
+					return;
+				}
+				File deviceOutputFile = null;
+				String deviceDescriptorLocation = null;
+				if (deviceInput != null) {
+					deviceOutputFile = new File(pathFile, deviceInput.getFileName());
+					if (!allowOverride(deviceOutputFile)) {
+						return;
+					}
+					deviceDescriptorLocation = deviceInput.getDescriptorLocation();
+				}
+
+				try {
+					AppletProducer.createHtml(htmlOutputFile, DeviceFactory.getDevice(), jadMidletEntry.getClassName(),
+							midletOutputFile, appletPackageOutputFile, deviceOutputFile, deviceDescriptorLocation);
+					AppletProducer.createMidlet(midletInput, midletOutputFile);
+					IOUtils.copyFile(appletJarFile, appletPackageOutputFile);
+					if (deviceInput != null) {
+						IOUtils.copyFile(new File(Config.getConfigPath(), deviceInput.getFileName()), deviceOutputFile);
+					}
+				} catch (IOException ex) {
+					Logger.error(ex);
+				}
+			}
+		}
+
+		private boolean allowOverride(File file) {
+			if (file.exists()) {
+				int answer = JOptionPane.showConfirmDialog(Main.this, "Override the file:" + file + "?", "Question?",
+						JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
+				if (answer == 1 /* no */) {
+					return false;
+				}
+			}
+
+			return true;
+		}
+	};
+
+	private ActionListener menuStartCaptureListener = new ActionListener() {
+		public void actionPerformed(ActionEvent e) {
+			if (captureFileChooser == null) {
+				ExtensionFileFilter fileFilter = new ExtensionFileFilter("GIF files");
+				fileFilter.addExtension("gif");
+				captureFileChooser = new JFileChooser();
+				captureFileChooser.setFileFilter(fileFilter);
+				captureFileChooser.setDialogTitle("Capture to GIF File...");
+				captureFileChooser.setCurrentDirectory(new File(Config.getRecentDirectory("recentCaptureDirectory")));
+			}
+
+			if (captureFileChooser.showSaveDialog(Main.this) == JFileChooser.APPROVE_OPTION) {
+				Config.setRecentDirectory("recentCaptureDirectory", captureFileChooser.getCurrentDirectory()
+						.getAbsolutePath());
+				String name = captureFileChooser.getSelectedFile().getName();
+				if (!name.toLowerCase().endsWith(".gif") && name.indexOf('.') == -1) {
+					name = name + ".gif";
+				}
+				File captureFile = new File(captureFileChooser.getSelectedFile().getParentFile(), name);
+				if (!allowOverride(captureFile)) {
+					return;
+				}
+
+				encoder = new AnimatedGifEncoder();
+				encoder.start(captureFile.getAbsolutePath());
+
+				menuStartCapture.setEnabled(false);
+				menuStopCapture.setEnabled(true);
+
+				emulatorContext.getDisplayComponent().addDisplayRepaintListener(new DisplayRepaintListener() {
+					long start = 0;
+
+					public void repaintInvoked(MutableImage image) {
+						synchronized (Main.this) {
+							if (encoder != null) {
+								if (start == 0) {
+									start = System.currentTimeMillis();
+								} else {
+									long current = System.currentTimeMillis();
+									encoder.setDelay((int) (current - start));
+									start = current;
+								}
+
+								encoder.addFrame((BufferedImage) ((J2SEMutableImage) image).getImage());
+							}
+						}
+					}
+				});
+			}
+		}
+
+		private boolean allowOverride(File file) {
+			if (file.exists()) {
+				int answer = JOptionPane.showConfirmDialog(Main.this, "Override the file:" + file + "?", "Question?",
+						JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
+				if (answer == 1 /* no */) {
+					return false;
+				}
+			}
+
+			return true;
+		}
+	};
+
+	private ActionListener menuStopCaptureListener = new ActionListener() {
+		public void actionPerformed(ActionEvent e) {
+			menuStopCapture.setEnabled(false);
+
+			synchronized (Main.this) {
+				encoder.finish();
+				encoder = null;
+			}
+
+			menuStartCapture.setEnabled(true);
+		}
+	};
+
+	private ActionListener menuMIDletNetworkConnectionListener = new ActionListener() {
+		public void actionPerformed(ActionEvent e) {
+			org.microemu.cldc.http.Connection.setAllowNetworkConnection(menuMIDletNetworkConnection.getState());
+		}
+
+	};
+
+	private ActionListener menuRecordStoreManagerListener = new ActionListener() {
+		public void actionPerformed(ActionEvent e) {
+			if (recordStoreManagerDialog == null) {
+				recordStoreManagerDialog = new RecordStoreManagerDialog(Main.this, common);
+				recordStoreManagerDialog.addWindowListener(new WindowAdapter() {
+					public void windowClosing(WindowEvent e) {
+						menuRecordStoreManager.setState(false);
+					}
+				});
+				recordStoreManagerDialog.pack();
+				Rectangle window = Config.getWindow("recordStoreManager", new Rectangle(0, 0, 640, 320));
+				recordStoreManagerDialog.setBounds(window.x, window.y, window.width, window.height);
+			}
+			recordStoreManagerDialog.setVisible(!recordStoreManagerDialog.isVisible());
+		}
+	};
+
+	private ActionListener menuLogConsoleListener = new ActionListener() {
+		public void actionPerformed(ActionEvent e) {
+			if (logConsoleDialog == null) {
+				logConsoleDialog = new SwingLogConsoleDialog(Main.this, Main.this.logQueueAppender);
+				logConsoleDialog.addWindowListener(new WindowAdapter() {
+					public void windowClosing(WindowEvent e) {
+						menuLogConsole.setState(false);
+					}
+				});
+				logConsoleDialog.pack();
+				// To avoid NPE on MacOS setFocusableWindowState(false) have to be called after pack()
+				logConsoleDialog.setFocusableWindowState(false);
+				Rectangle window = Config.getWindow("logConsole", new Rectangle(0, 0, 640, 320));
+				logConsoleDialog.setBounds(window.x, window.y, window.width, window.height);
+			}
+			logConsoleDialog.setVisible(!logConsoleDialog.isVisible());
+		}
+	};
+
+	private ActionListener menuAboutListener = new ActionListener() {
+		public void actionPerformed(ActionEvent e) {
+			SwingDialogWindow.show(Main.this, "About", new SwingAboutDialog(), false);
+		}
+	};
+
+	private ActionListener menuExitListener = new ActionListener() {
+		public void actionPerformed(ActionEvent e) {
+			synchronized (Main.this) {
+				if (encoder != null) {
+					encoder.finish();
+					encoder = null;
+				}
+			}
+
+			if (logConsoleDialog != null) {
+				Config.setWindow("logConsole", new Rectangle(logConsoleDialog.getX(), logConsoleDialog.getY(),
+						logConsoleDialog.getWidth(), logConsoleDialog.getHeight()), logConsoleDialog.isVisible());
+			}
+			if (recordStoreManagerDialog != null) {
+				Config.setWindow("recordStoreManager", new Rectangle(recordStoreManagerDialog.getX(),
+						recordStoreManagerDialog.getY(), recordStoreManagerDialog.getWidth(), recordStoreManagerDialog
+								.getHeight()), recordStoreManagerDialog.isVisible());
+			}
+			Config.setWindow("main", new Rectangle(Main.this.getX(), Main.this.getY(), Main.this.getWidth(), Main.this
+					.getHeight()), true);
+
+			System.exit(0);
+		}
+	};
+
+	private ActionListener menuSelectDeviceListener = new ActionListener() {
+		public void actionPerformed(ActionEvent e) {
+			if (SwingDialogWindow.show(Main.this, "Select device...", selectDevicePanel, true)) {
+				if (selectDevicePanel.getSelectedDeviceEntry().equals(deviceEntry)) {
+					return;
+				}
+				int restartMidlet = 1;
+				if (MIDletBridge.getCurrentMIDlet() != common.getLauncher()) {
+					restartMidlet = JOptionPane.showConfirmDialog(Main.this,
+							"Changing device may trigger MIDlet to the unpredictable state and restart of MIDlet is recommended. \n"
+									+ "Do you want to restart the MIDlet? All MIDlet data will be lost.", "Question?",
+							JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
+				}
+				if (!setDevice(selectDevicePanel.getSelectedDeviceEntry())) {
+					return;
+				}
+				if (restartMidlet == 0) {
+					try {
+						common.initMIDlet(true);
+					} catch (Exception ex) {
+						System.err.println(ex);
+					}
+				} else {
+					DeviceDisplay deviceDisplay = DeviceFactory.getDevice().getDeviceDisplay();
+					DisplayAccess da = MIDletBridge.getMIDletAccess().getDisplayAccess();
+					if (da != null) {
+						da.sizeChanged(da.getCurrent().getWidth(), da.getCurrent().getHeight());
+						deviceDisplay.repaint(0, 0, deviceDisplay.getFullWidth(), deviceDisplay.getFullHeight());
+					}
+				}
+			}
+		}
+	};
+
+	private StatusBarListener statusBarListener = new StatusBarListener() {
+		public void statusBarChanged(String text) {
+			FontMetrics metrics = statusBar.getFontMetrics(statusBar.getFont());
+			statusBar.setPreferredSize(new Dimension(metrics.stringWidth(text), metrics.getHeight()));
+			statusBar.setText(text);
+		}
+	};
+
+	private ResponseInterfaceListener responseInterfaceListener = new ResponseInterfaceListener() {
+		public void stateChanged(boolean state) {
+			menuOpenJADFile.setEnabled(state);
+			menuOpenJADURL.setEnabled(state);
+			menuSelectDevice.setEnabled(state);
+
+			if (common.jad.getJarURL() != null) {
+				menuSaveForWeb.setEnabled(state);
+			} else {
+				menuSaveForWeb.setEnabled(false);
+			}
+		}
+	};
+
+	private ComponentListener componentListener = new ComponentAdapter() {
+		Timer timer;
+
+		int count = 0;
+
+		public void componentResized(ComponentEvent e) {
+			count++;
+			DeviceDisplayImpl deviceDisplay = (DeviceDisplayImpl) DeviceFactory.getDevice().getDeviceDisplay();
+			if (deviceDisplay.isResizable()) {
+				deviceDisplay.setDisplayRectangle(new Rectangle(0, 0, devicePanel.getWidth(), devicePanel.getHeight()));
+				((SwingDisplayComponent) devicePanel.getDisplayComponent()).init();
+				MIDletAccess ma = MIDletBridge.getMIDletAccess();
+				if (ma == null) {
+					return;
+				}
+				DisplayAccess da = ma.getDisplayAccess();
+				if (da != null) {
+					da.sizeChanged(da.getCurrent().getWidth(), da.getCurrent().getHeight());
+					deviceDisplay.repaint(0, 0, deviceDisplay.getFullWidth(), deviceDisplay.getFullHeight());
+				}
+				devicePanel.revalidate();
+				statusBarListener.statusBarChanged("New size: " + deviceDisplay.getFullWidth() + "x"
+						+ deviceDisplay.getFullHeight());
+				synchronized (statusBarListener) {
+					if (timer == null) {
+						timer = new Timer();
+					}
+					timer.schedule(new CountTimerTask(count) {
+						public void run() {
+							if (counter == count) {
+								Config.setDeviceEntryDisplaySize(deviceEntry, new Rectangle(0, 0, devicePanel
+										.getWidth(), devicePanel.getHeight()));
+								statusBarListener.statusBarChanged("");
+								timer.cancel();
+								timer = null;
+							}
+						}
+					}, 2000);
+				}
+			}
+		}
+	};
+
+	private WindowAdapter windowListener = new WindowAdapter() {
+		public void windowClosing(WindowEvent ev) {
+			menuExitListener.actionPerformed(null);
+		}
+
+		public void windowIconified(WindowEvent ev) {
+			MIDletBridge.getMIDletAccess(MIDletBridge.getCurrentMIDlet()).pauseApp();
+		}
+
+		public void windowDeiconified(WindowEvent ev) {
+			try {
+				MIDletBridge.getMIDletAccess(MIDletBridge.getCurrentMIDlet()).startApp();
+			} catch (MIDletStateChangeException ex) {
+				System.err.println(ex);
+			}
+		}
+	};
+
+	public Main() {
+		this(null);
+	}
+
+	public Main(DeviceEntry defaultDevice) {
+
+		this.logQueueAppender = new QueueAppender(1024);
+		Logger.addAppender(logQueueAppender);
+
+		JMenuBar menuBar = new JMenuBar();
+
+		JMenu menuFile = new JMenu("File");
+
+		menuOpenJADFile = new JMenuItem("Open JAD File...");
+		menuOpenJADFile.addActionListener(menuOpenJADFileListener);
+		menuFile.add(menuOpenJADFile);
+
+		menuOpenJADURL = new JMenuItem("Open JAD URL...");
+		menuOpenJADURL.addActionListener(menuOpenJADURLListener);
+		menuFile.add(menuOpenJADURL);
+
+		JMenuItem menuItemTmp = new JMenuItem("Close MIDlet");
+		menuItemTmp.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, ActionEvent.CTRL_MASK));
+		menuItemTmp.addActionListener(menuCloseMidletListener);
+		menuFile.add(menuItemTmp);
+
+		menuFile.addSeparator();
+
+		JMRUMenu urlsMRU = new JMRUMenu("Recent MIDlets...");
+		urlsMRU.addActionListener(new ActionListener() {
+			public void actionPerformed(ActionEvent event) {
+				if (event instanceof JMRUMenu.MRUActionEvent) {
+					Common.openJadUrlSafe(((MidletURLReference) ((JMRUMenu.MRUActionEvent) event).getSourceMRU())
+							.getUrl());
+					if (recordStoreManagerDialog != null) {
+						recordStoreManagerDialog.refresh();
+					}
+				}
+			}
+		});
+
+		Config.getUrlsMRU().setListener(urlsMRU);
+		menuFile.add(urlsMRU);
+
+		menuFile.addSeparator();
+
+		menuSaveForWeb = new JMenuItem("Save for Web...");
+		menuSaveForWeb.addActionListener(menuSaveForWebListener);
+		menuFile.add(menuSaveForWeb);
+
+		menuFile.addSeparator();
+
+		JMenuItem menuItem = new JMenuItem("Exit");
+		menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK));
+		menuItem.addActionListener(menuExitListener);
+		menuFile.add(menuItem);
+
+		JMenu menuOptions = new JMenu("Options");
+
+		menuSelectDevice = new JMenuItem("Select device...");
+		menuSelectDevice.addActionListener(menuSelectDeviceListener);
+		menuOptions.add(menuSelectDevice);
+
+		menuStartCapture = new JMenuItem("Start capture to GIF...");
+		menuStartCapture.addActionListener(menuStartCaptureListener);
+		menuOptions.add(menuStartCapture);
+
+		menuStopCapture = new JMenuItem("Stop capture");
+		menuStopCapture.setEnabled(false);
+		menuStopCapture.addActionListener(menuStopCaptureListener);
+		menuOptions.add(menuStopCapture);
+
+		menuMIDletNetworkConnection = new JCheckBoxMenuItem("MIDlet Network access");
+		menuMIDletNetworkConnection.setState(true);
+		menuMIDletNetworkConnection.addActionListener(menuMIDletNetworkConnectionListener);
+		menuOptions.add(menuMIDletNetworkConnection);
+
+		menuRecordStoreManager = new JCheckBoxMenuItem("Record Store Manager");
+		menuRecordStoreManager.setState(false);
+		menuRecordStoreManager.addActionListener(menuRecordStoreManagerListener);
+		menuOptions.add(menuRecordStoreManager);
+
+		menuLogConsole = new JCheckBoxMenuItem("Log console");
+		menuLogConsole.setState(false);
+		menuLogConsole.addActionListener(menuLogConsoleListener);
+		menuOptions.add(menuLogConsole);
+
+		menuOptions.addSeparator();
+		JCheckBoxMenuItem menuShowMouseCoordinates = new JCheckBoxMenuItem("Mouse coordinates");
+		menuShowMouseCoordinates.setState(false);
+		menuShowMouseCoordinates.addActionListener(new ActionListener() {
+			public void actionPerformed(ActionEvent event) {
+				devicePanel.switchShowMouseCoordinates();
+			}
+		});
+		menuOptions.add(menuShowMouseCoordinates);
+
+		JMenu menuHelp = new JMenu("Help");
+		JMenuItem menuAbout = new JMenuItem("About");
+		menuAbout.addActionListener(menuAboutListener);
+		menuHelp.add(menuAbout);
+
+		menuBar.add(menuFile);
+		menuBar.add(menuOptions);
+		menuBar.add(menuHelp);
+		setJMenuBar(menuBar);
+
+		setTitle("MicroEmulator");
+
+		this.setIconImage(Toolkit.getDefaultToolkit().getImage(Main.class.getResource("/org/microemu/icon.png")));
+
+		addWindowListener(windowListener);
+
+		Config.loadConfig(defaultDevice, emulatorContext);
+		Logger.setLocationEnabled(Config.isLogConsoleLocationEnabled());
+
+		Rectangle window = Config.getWindow("main", new Rectangle(0, 0, 160, 120));
+		this.setLocation(window.x, window.y);
+
+		getContentPane().add(createContents(getContentPane()), "Center");
+
+		selectDevicePanel = new SwingSelectDevicePanel(emulatorContext);
+
+		this.common = new Common(emulatorContext);
+		this.common.setStatusBarListener(statusBarListener);
+		this.common.setResponseInterfaceListener(responseInterfaceListener);
+		this.common.loadImplementationsFromConfig();
+
+		this.resizeButton.addActionListener(new ActionListener() {
+			public void actionPerformed(ActionEvent ev) {
+				if (resizeDeviceDisplayDialog == null) {
+					resizeDeviceDisplayDialog = new ResizeDeviceDisplayDialog();
+				}
+				DeviceDisplayImpl deviceDisplay = (DeviceDisplayImpl) DeviceFactory.getDevice().getDeviceDisplay();
+				resizeDeviceDisplayDialog.setDeviceDisplaySize(deviceDisplay.getFullWidth(), deviceDisplay
+						.getFullHeight());
+				if (SwingDialogWindow.show(Main.this, "Enter new size...", resizeDeviceDisplayDialog, true)) {
+					deviceDisplay.setDisplayRectangle(new Rectangle(0, 0, resizeDeviceDisplayDialog
+							.getDeviceDisplayWidth(), resizeDeviceDisplayDialog.getDeviceDisplayHeight()));
+					((SwingDisplayComponent) devicePanel.getDisplayComponent()).init();
+					MIDletAccess ma = MIDletBridge.getMIDletAccess();
+					if (ma == null) {
+						return;
+					}
+					DisplayAccess da = ma.getDisplayAccess();
+					if (da != null) {
+						da.sizeChanged(da.getCurrent().getWidth(), da.getCurrent().getHeight());
+						deviceDisplay.repaint(0, 0, deviceDisplay.getFullWidth(), deviceDisplay.getFullHeight());
+					}
+					pack();
+				}
+			}
+		});
+
+		JPanel statusPanel = new JPanel();
+		statusPanel.setLayout(new BorderLayout());
+		statusPanel.add(statusBar, "West");
+		statusPanel.add(this.resizeButton, "East");
+
+		getContentPane().add(statusPanel, "South");
+
+		Message.addListener(new SwingErrorMessageDialogPanel(this));
+
+		devicePanel.setTransferHandler(new DropTransferHandler());
+	}
+
+	protected Component createContents(Container parent) {
+		devicePanel = new SwingDeviceComponent();
+		devicePanel.addKeyListener(devicePanel);
+		addKeyListener(devicePanel);
+
+		return devicePanel;
+	}
+
+	public boolean setDevice(DeviceEntry entry) {
+		if (DeviceFactory.getDevice() != null) {
+			// ((J2SEDevice) DeviceFactory.getDevice()).dispose();
+		}
+		final String errorTitle = "Error creating device";
+		try {
+			ClassLoader classLoader = getClass().getClassLoader();
+			if (entry.getFileName() != null) {
+				URL[] urls = new URL[1];
+				urls[0] = new File(Config.getConfigPath(), entry.getFileName()).toURI().toURL();
+				classLoader = Common.createExtensionsClassLoader(urls);
+			}
+
+			// TODO font manager have to be moved from emulatorContext into
+			// device
+			emulatorContext.getDeviceFontManager().init();
+
+			Device device = DeviceImpl.create(emulatorContext, classLoader, entry.getDescriptorLocation(),
+					J2SEDevice.class);
+			this.deviceEntry = entry;
+
+			DeviceDisplayImpl deviceDisplay = (DeviceDisplayImpl) device.getDeviceDisplay();
+			if (deviceDisplay.isResizable()) {
+				Rectangle size = Config.getDeviceEntryDisplaySize(entry);
+				if (size != null) {
+					deviceDisplay.setDisplayRectangle(size);
+				}
+			}
+			common.setDevice(device);
+			updateDevice();
+			return true;
+		} catch (MalformedURLException e) {
+			Message.error(errorTitle, errorTitle + ", " + Message.getCauseMessage(e), e);
+		} catch (IOException e) {
+			Message.error(errorTitle, errorTitle + ", " + Message.getCauseMessage(e), e);
+		} catch (Throwable e) {
+			Message.error(errorTitle, errorTitle + ", " + Message.getCauseMessage(e), e);
+		}
+		return false;
+	}
+
+	protected void updateDevice() {
+		devicePanel.init();
+		if (((DeviceDisplayImpl) DeviceFactory.getDevice().getDeviceDisplay()).isResizable()) {
+			setResizable(true);
+			resizeButton.setVisible(true);
+		} else {
+			setResizable(false);
+			resizeButton.setVisible(false);
+		}
+
+		pack();
+
+		devicePanel.requestFocus();
+	}
+
+	public static void main(String args[]) {
+		try {
+			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
+		} catch (Exception ex) {
+			Logger.error(ex);
+		}
+
+		List params = new ArrayList();
+		StringBuffer debugArgs = new StringBuffer();
+		for (int i = 0; i < args.length; i++) {
+			params.add(args[i]);
+			if (debugArgs.length() != 0) {
+				debugArgs.append(", ");
+			}
+			debugArgs.append("[").append(args[i]).append("]");
+		}
+
+		final Main app = new Main();
+		if (args.length > 0) {
+			Logger.debug("arguments", debugArgs.toString());
+		}
+		
+		app.common.initParams(params, app.selectDevicePanel.getSelectedDeviceEntry(), J2SEDevice.class);
+		app.deviceEntry = app.selectDevicePanel.getSelectedDeviceEntry();
+		DeviceDisplayImpl deviceDisplay = (DeviceDisplayImpl) DeviceFactory.getDevice().getDeviceDisplay();
+		if (deviceDisplay.isResizable()) {
+			Rectangle size = Config.getDeviceEntryDisplaySize(app.deviceEntry);
+			if (size != null) {
+				deviceDisplay.setDisplayRectangle(size);
+			}
+		}
+		app.updateDevice();
+
+		app.validate();
+		app.setVisible(true);
+
+		if (Config.isWindowOnStart("logConsole")) {
+			app.menuLogConsoleListener.actionPerformed(null);
+			app.menuLogConsole.setSelected(true);
+		}
+		if (Config.isWindowOnStart("recordStoreManager")) {
+			app.menuRecordStoreManagerListener.actionPerformed(null);
+			app.menuRecordStoreManager.setSelected(true);
+		}
+
+		String midletString;
+		try {
+			midletString = (String) params.iterator().next();
+		} catch (NoSuchElementException ex) {
+			midletString = null;
+		}
+		app.common.initMIDlet(false);
+
+		app.addComponentListener(app.componentListener);
+
+		app.responseInterfaceListener.stateChanged(true);
+	}
+
+	private abstract class CountTimerTask extends TimerTask {
+
+		protected int counter;
+
+		public CountTimerTask(int counter) {
+			this.counter = counter;
+		}
+
+	}
+
+}

Propchange: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/Main.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/noui/NoUiDisplayComponent.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/noui/NoUiDisplayComponent.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/noui/NoUiDisplayComponent.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/noui/NoUiDisplayComponent.java Mon May 26 15:20:19 2008
@@ -0,0 +1,99 @@
+/*
+ *  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.noui;
+
+import java.awt.Graphics;
+
+import javax.microedition.lcdui.Displayable;
+
+import org.microemu.DisplayAccess;
+import org.microemu.DisplayComponent;
+import org.microemu.MIDletAccess;
+import org.microemu.MIDletBridge;
+import org.microemu.app.ui.DisplayRepaintListener;
+import org.microemu.device.Device;
+import org.microemu.device.DeviceFactory;
+import org.microemu.device.MutableImage;
+import org.microemu.device.j2se.J2SEDeviceDisplay;
+import org.microemu.device.j2se.J2SEMutableImage;
+
+public class NoUiDisplayComponent implements DisplayComponent {
+
+	private J2SEMutableImage displayImage = null;
+	private DisplayRepaintListener displayRepaintListener;
+	
+	public void addDisplayRepaintListener(DisplayRepaintListener l) {
+		displayRepaintListener = l;
+	}
+
+	public void removeDisplayRepaintListener(DisplayRepaintListener l) {
+		if (displayRepaintListener == l) {
+			displayRepaintListener = null;
+		}
+	}
+
+	public MutableImage getDisplayImage() {
+		return displayImage;
+	}
+
+	public void repaintRequest(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;
+		}
+
+		Device device = DeviceFactory.getDevice();
+
+		if (device != null) {
+			if (displayImage == null) {
+				displayImage = new J2SEMutableImage(
+						device.getDeviceDisplay().getFullWidth(), device.getDeviceDisplay().getFullHeight());
+			}
+					
+			Graphics gc = displayImage.getImage().getGraphics();
+
+			J2SEDeviceDisplay deviceDisplay = (J2SEDeviceDisplay) device.getDeviceDisplay();				
+			if (!deviceDisplay.isFullScreenMode()) {
+				deviceDisplay.paintControls(gc);
+			}
+			deviceDisplay.paintDisplayable(gc, x, y, width, height);
+
+			fireDisplayRepaint(displayImage);
+		}	
+	}
+
+
+	private void fireDisplayRepaint(MutableImage image)
+	{
+		if (displayRepaintListener != null) {
+			displayRepaintListener.repaintInvoked(image);
+		}
+	}
+
+}

Propchange: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/noui/NoUiDisplayComponent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/DropTransferHandler.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/DropTransferHandler.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/DropTransferHandler.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/DropTransferHandler.java Mon May 26 15:20:19 2008
@@ -0,0 +1,210 @@
+/*
+ *  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.swing;
+
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.Transferable;
+import java.awt.datatransfer.UnsupportedFlavorException;
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import javax.swing.JComponent;
+import javax.swing.TransferHandler;
+
+import org.microemu.app.Common;
+import org.microemu.app.ui.Message;
+import org.microemu.app.util.IOUtils;
+import org.microemu.log.Logger;
+
+/**
+ * @author vlads
+ *
+ */
+public class DropTransferHandler extends TransferHandler {
+
+	private static final long serialVersionUID = 1L;
+
+	private static DataFlavor uriListFlavor = new DataFlavor("text/uri-list;class=java.lang.String", null);
+	
+	private static boolean debugImport = false;
+	
+	public int getSourceActions(JComponent c) {
+        return TransferHandler.COPY;
+    }
+
+	public boolean canImport(JComponent comp, DataFlavor transferFlavors[]) {
+		for (int i = 0; i < transferFlavors.length; i++) {
+			Class representationclass = transferFlavors[i].getRepresentationClass();
+			// URL from Explorer or Firefox, KDE
+        	if ((representationclass != null) && URL.class.isAssignableFrom(representationclass)) {
+        		if (debugImport) {
+        			Logger.debug("acepted ", transferFlavors[i]);
+        		}
+        		return true;
+        	}
+        	// Drop from Windows Explorer
+        	if (DataFlavor.javaFileListFlavor.equals(transferFlavors[i])) {
+        		if (debugImport) {
+        			Logger.debug("acepted ", transferFlavors[i]);
+        		}
+        		return true;
+            }
+        	// Drop from GNOME
+            if (DataFlavor.stringFlavor.equals(transferFlavors[i])) {
+            	if (debugImport) {
+        			Logger.debug("acepted ", transferFlavors[i]);
+        		}
+                return true;
+            }
+			if (uriListFlavor.equals(transferFlavors[i])) {
+				if (debugImport) {
+        			Logger.debug("acepted ", transferFlavors[i]);
+        		}
+				return true;
+        	}
+//          String mimePrimaryType = transferFlavors[i].getPrimaryType();
+//			String mimeSubType = transferFlavors[i].getSubType();
+//			if ((mimePrimaryType != null) && (mimeSubType != null)) {
+//				if (mimePrimaryType.equals("text") && mimeSubType.equals("uri-list")) {
+//					Logger.debug("acepted ", transferFlavors[i]);
+//					return true;
+//				}
+//			}
+			if (debugImport) {
+				Logger.debug(i + " unknown import ", transferFlavors[i]);
+			}
+		}
+		if (debugImport) {
+			Logger.debug("import rejected");
+		}
+        return false;
+	}
+	
+	public boolean importData(JComponent comp, Transferable t) {
+		DataFlavor[] transferFlavors = t.getTransferDataFlavors();
+        for (int i = 0; i < transferFlavors.length; i++) {
+        	// Drop from Windows Explorer
+        	if (DataFlavor.javaFileListFlavor.equals(transferFlavors[i])) {
+        		Logger.debug("importing", transferFlavors[i]);
+        		try {
+					List fileList = (List) t.getTransferData(DataFlavor.javaFileListFlavor);
+					if (fileList.get(0) instanceof File) {
+						File f = (File) fileList.get(0);
+						if (Common.isJadExtension(f.getName())) {
+							Common.openJadUrlSafe(IOUtils.getCanonicalFileURL(f));
+						} else {
+							Message.warn("Unable to open " + f.getAbsolutePath() + ", Only JAD files are acepted");	
+						}
+					} else {
+						Logger.debug("Unknown object in list ", fileList.get(0));	
+					}
+				} catch (UnsupportedFlavorException e) {
+					Logger.debug(e);
+				} catch (IOException e) {
+					Logger.debug(e);
+				}
+        		return true;
+            }
+        	
+        	// Drop from GNOME Firefox
+            if (DataFlavor.stringFlavor.equals(transferFlavors[i])) {
+            	Object data;
+				try {
+					data = t.getTransferData(DataFlavor.stringFlavor);
+				} catch (UnsupportedFlavorException e) {
+					continue;
+				} catch (IOException e) {
+					continue;
+				}
+            	if (data instanceof String) {
+                	Logger.debug("importing", transferFlavors[i]);
+                	String path = getPathString((String) data);
+          			if (Common.isJadExtension(path)) {
+						Common.openJadUrlSafe(path);
+					} else {
+						Message.warn("Unable to open " + path + ", Only JAD files are acepted");	
+					}
+          			return true;
+              	}
+            }
+            // Drop from GNOME Nautilus
+            if (uriListFlavor.equals(transferFlavors[i])) {
+				Object data;
+				try {
+					data = t.getTransferData(uriListFlavor);
+				} catch (UnsupportedFlavorException e) {
+					continue;
+				} catch (IOException e) {
+					continue;
+				}
+				if (data instanceof String) {
+					Logger.debug("importing", transferFlavors[i]);
+					String path = getPathString((String) data);
+					if (Common.isJadExtension(path)) {
+						Common.openJadUrlSafe(path);
+					} else {
+						Message.warn("Unable to open " + path + ", Only JAD files are acepted");
+					}
+					return true;
+				}
+			}
+            if (debugImport) {
+            	Logger.debug(i + " unknown importData ", transferFlavors[i]);
+            }
+        }
+        // This is the second best option since it works incorrectly  on Max OS X making url like this [file://localhost/users/work/app.jad]
+        for (int i = 0; i < transferFlavors.length; i++) {
+        	Class representationclass = transferFlavors[i].getRepresentationClass();
+        	// URL from Explorer or Firefox, KDE
+        	if ((representationclass != null) && URL.class.isAssignableFrom(representationclass)) {
+        		Logger.debug("importing", transferFlavors[i]);
+        		try {
+					URL jadUrl = (URL)t.getTransferData(transferFlavors[i]);
+					String urlString = jadUrl.toExternalForm();
+					if (Common.isJadExtension(urlString)) {
+						Common.openJadUrlSafe(urlString);
+					} else {
+						Message.warn("Unable to open " + urlString + ", Only JAD url are acepted");	
+					}
+				} catch (UnsupportedFlavorException e) {
+					Logger.debug(e);
+				} catch (IOException e) {
+					Logger.debug(e);
+				}
+				return true;
+        	}
+        }
+		return false;
+	}
+	
+	private String getPathString(String path) {
+		if (path == null) {
+			return null;
+		}
+		StringTokenizer st = new StringTokenizer(path.trim(), "\n\r");
+		if (st.hasMoreTokens()) {
+			return st.nextToken();
+		}
+		return path;
+	}
+}

Propchange: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/DropTransferHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/ExtensionFileFilter.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/ExtensionFileFilter.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/ExtensionFileFilter.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/ExtensionFileFilter.java Mon May 26 15:20:19 2008
@@ -0,0 +1,83 @@
+/*
+ *  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.swing;
+
+import java.io.File;
+import java.util.Hashtable;
+
+import javax.swing.filechooser.FileFilter;
+
+
+public class ExtensionFileFilter extends FileFilter 
+{
+  
+  String description;
+  
+  Hashtable extensions = new Hashtable(); 
+  
+
+  public ExtensionFileFilter(String description)
+  {
+    this.description = description;
+  }
+  
+  
+  public boolean accept(File file) 
+  {
+    if(file != null) {
+	    if(file.isDirectory()) {
+        return true;
+	    }
+      String ext = getExtension(file);
+      if(ext != null && extensions.get(ext) != null) {
+        return true;
+      }
+    }
+    
+  	return false;
+  }
+  
+  
+  public void addExtension(String extension)
+  {
+    extensions.put(extension.toLowerCase(), this);
+  }
+
+  
+  public String getDescription() 
+  {
+    return description;
+  }
+
+  
+  String getExtension(File file) 
+  {
+    if (file != null) {
+	    String filename = file.getName();
+	    int i = filename.lastIndexOf('.');
+	    if (i > 0 && i < filename.length() - 1) {
+        return filename.substring(i + 1).toLowerCase();
+	    }
+    }
+  
+    return null;
+  }
+  
+}

Propchange: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/ExtensionFileFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/JMRUMenu.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/JMRUMenu.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/JMRUMenu.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/JMRUMenu.java Mon May 26 15:20:19 2008
@@ -0,0 +1,97 @@
+/*
+ *  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.swing;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.AbstractAction;
+import javax.swing.JMenu;
+import javax.swing.JMenuItem;
+
+import org.microemu.app.util.MRUListListener;
+
+/**
+ * @author vlads
+ * 
+ */
+public class JMRUMenu extends JMenu implements MRUListListener {
+
+	private static final long serialVersionUID = 1L;
+
+	public static class MRUActionEvent extends ActionEvent {
+
+		private static final long serialVersionUID = 1L;
+
+		Object sourceMRU;
+
+		public MRUActionEvent(Object sourceMRU, ActionEvent orig) {
+			super(orig.getSource(), orig.getID(), orig.getActionCommand(), orig.getWhen(), orig.getModifiers());
+			this.sourceMRU = sourceMRU;
+		}
+
+		public Object getSourceMRU() {
+			return sourceMRU;
+		}
+
+	}
+
+	public JMRUMenu(String s) {
+		super(s);
+	}
+
+	public void listItemChanged(final Object item) {
+		String label = item.toString();
+		for (int i = 0; i < getItemCount(); i++) {
+			if (getItem(i).getText().equals(label)) {
+				remove(i);
+				break;
+			}
+		}
+		AbstractAction a = new AbstractAction(label) {
+
+			private static final long serialVersionUID = 1L;
+
+			Object sourceMRU = item;
+
+			public void actionPerformed(ActionEvent e) {
+				JMRUMenu.this.fireActionPerformed(new MRUActionEvent(sourceMRU, e));
+			}
+		};
+
+		JMenuItem menu = new JMenuItem(a);
+		this.insert(menu, 0);
+	}
+
+	/**
+	 * Do not create new Event
+	 */
+	protected void fireActionPerformed(ActionEvent event) {
+		Object[] listeners = listenerList.getListenerList();
+		// Process the listeners last to first, notifying
+		// those that are interested in this event
+		for (int i = listeners.length - 2; i >= 0; i -= 2) {
+			if (listeners[i] == ActionListener.class) {
+				((ActionListener) listeners[i + 1]).actionPerformed(event);
+			}
+		}
+	}
+
+}

Propchange: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/JMRUMenu.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/JadUrlPanel.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/JadUrlPanel.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/JadUrlPanel.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/JadUrlPanel.java Mon May 26 15:20:19 2008
@@ -0,0 +1,44 @@
+/*
+ *  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.swing;
+
+import javax.swing.JTextField;
+
+import org.microemu.app.ui.swing.SwingDialogPanel;
+
+public class JadUrlPanel extends SwingDialogPanel {
+	
+    private static final long serialVersionUID = 1L;
+    
+    private JTextField jadUrlField = new JTextField(50);
+
+	public JadUrlPanel() {		
+		add(jadUrlField);
+	}
+	
+	public String getText() {
+		return jadUrlField.getText();
+	}
+
+	protected void showNotify() {
+		jadUrlField.setText("");
+	}
+	
+}

Propchange: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/JadUrlPanel.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/RecordStoreChangePanel.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/RecordStoreChangePanel.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/RecordStoreChangePanel.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/RecordStoreChangePanel.java Mon May 26 15:20:19 2008
@@ -0,0 +1,55 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.microemu.app.ui.swing;
+
+import javax.swing.JComboBox;
+import javax.swing.JLabel;
+
+import org.microemu.app.Common;
+import org.microemu.app.util.FileRecordStoreManager;
+
+public class RecordStoreChangePanel extends SwingDialogPanel {
+
+	private static final long serialVersionUID = 1L;
+
+	private Common common;
+
+	private JComboBox selectStoreCombo = new JComboBox(new String[] { "File record store", "Memory record store" });
+
+	public RecordStoreChangePanel(Common common) {
+		this.common = common;
+
+		add(new JLabel("Record store type:"));
+		add(selectStoreCombo);
+	}
+
+	protected void showNotify() {
+		if (common.getRecordStoreManager() instanceof FileRecordStoreManager) {
+			selectStoreCombo.setSelectedIndex(0);
+		} else {
+			selectStoreCombo.setSelectedIndex(1);
+		}
+	}
+
+	public String getSelectedRecordStoreName() {
+		return (String) selectStoreCombo.getSelectedItem();
+	}
+
+}

Propchange: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/RecordStoreChangePanel.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/RecordStoreManagerDialog.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/RecordStoreManagerDialog.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/RecordStoreManagerDialog.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/RecordStoreManagerDialog.java Mon May 26 15:20:19 2008
@@ -0,0 +1,280 @@
+/*
+ *  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.swing;
+
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Frame;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.Insets;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import javax.microedition.rms.RecordStore;
+import javax.microedition.rms.RecordStoreNotOpenException;
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTabbedPane;
+import javax.swing.JTable;
+import javax.swing.table.DefaultTableCellRenderer;
+import javax.swing.table.DefaultTableModel;
+
+import org.microemu.RecordStoreManager;
+import org.microemu.app.Common;
+import org.microemu.app.Config;
+import org.microemu.app.util.FileRecordStoreManager;
+import org.microemu.log.Logger;
+import org.microemu.util.ExtendedRecordListener;
+import org.microemu.util.MemoryRecordStoreManager;
+
+public class RecordStoreManagerDialog extends JFrame {
+
+	private static final long serialVersionUID = 1L;
+
+	private Common common;
+
+	private SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss.S");
+
+	private JLabel recordStoreTypeLabel = new JLabel();
+
+	private JLabel suiteNameLabel = new JLabel();
+
+	private RecordStoreChangePanel recordStoreChangePanel = null;
+
+	private DefaultTableModel modelTable = new DefaultTableModel();
+
+	private JTable logTable = new JTable(modelTable);
+
+	private JScrollPane logScrollPane = new JScrollPane(logTable);
+
+	private ActionListener recordStoreTypeChangeListener = new ActionListener() {
+
+		public void actionPerformed(ActionEvent e) {
+			if (recordStoreChangePanel == null) {
+				recordStoreChangePanel = new RecordStoreChangePanel(common);
+			}
+			if (SwingDialogWindow.show(RecordStoreManagerDialog.this, "Change Record Store...", recordStoreChangePanel,
+					true)) {
+				String recordStoreName = recordStoreChangePanel.getSelectedRecordStoreName();
+				if (!recordStoreName.equals(common.getRecordStoreManager().getName())) {
+					if (JOptionPane.showConfirmDialog(RecordStoreManagerDialog.this,
+							"Changing record store type requires MIDlet restart. \n"
+									+ "Do you want to proceed? All MIDlet data will be lost.", "Question?",
+							JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == 0) {
+						for (int i = modelTable.getRowCount() - 1; i >= 0; i--) {
+							modelTable.removeRow(i);
+						}
+						RecordStoreManager manager;
+						if (recordStoreName.equals("File record store")) {
+							manager = new FileRecordStoreManager();
+						} else {
+							manager = new MemoryRecordStoreManager();
+						}
+						common.setRecordStoreManager(manager);
+						Config.setRecordStoreManagerClassName(manager.getClass().getName());
+						refresh();
+						try {
+							common.initMIDlet(true);
+						} catch (Exception ex) {
+							Logger.error(ex);
+						}
+					}
+				}
+			}
+		}
+
+	};
+
+	public RecordStoreManagerDialog(Frame owner, Common common) {
+		super("Record Store Manager");
+
+		this.common = common;
+
+		setIconImage(owner.getIconImage());
+		setFocusableWindowState(false);
+
+		setLayout(new BorderLayout());
+
+		refresh();
+
+		JButton recordStoreTypeChangeButton = new JButton("Change...");
+		recordStoreTypeChangeButton.addActionListener(recordStoreTypeChangeListener);
+
+		JPanel headerPanel = new JPanel();
+		headerPanel.setLayout(new GridBagLayout());
+		GridBagConstraints c = new GridBagConstraints();
+		c.insets = new Insets(3, 3, 3, 3);
+
+		c.gridx = 0;
+		c.gridy = 0;
+		c.gridwidth = 1;
+		c.gridheight = 1;
+		c.fill = GridBagConstraints.NONE;
+		c.weightx = 0.0;
+		c.weighty = 0.0;
+		headerPanel.add(new JLabel("Record store type:"), c);
+
+		c.gridx = 1;
+		c.gridy = 0;
+		c.gridwidth = 1;
+		c.gridheight = 1;
+		c.fill = GridBagConstraints.HORIZONTAL;
+		c.weightx = 1.0;
+		c.weighty = 0.0;
+		headerPanel.add(recordStoreTypeLabel, c);
+
+		c.gridx = 2;
+		c.gridy = 0;
+		c.gridwidth = 1;
+		c.gridheight = 1;
+		c.fill = GridBagConstraints.NONE;
+		c.weightx = 0.0;
+		c.weighty = 0.0;
+		headerPanel.add(recordStoreTypeChangeButton, c);
+
+		c.gridx = 0;
+		c.gridy = 1;
+		c.gridwidth = 1;
+		c.gridheight = 1;
+		c.fill = GridBagConstraints.NONE;
+		c.weightx = 0.0;
+		c.weighty = 0.0;
+		headerPanel.add(new JLabel("Suite name:"), c);
+
+		c.gridx = 1;
+		c.gridy = 1;
+		c.gridwidth = 1;
+		c.gridheight = 1;
+		c.fill = GridBagConstraints.HORIZONTAL;
+		c.weightx = 1.0;
+		c.weighty = 0.0;
+		headerPanel.add(suiteNameLabel, c);
+
+		modelTable.addColumn("Timestamp");
+		modelTable.addColumn("Action type");
+		modelTable.addColumn("Record store name");
+		modelTable.addColumn("Details");
+		logTable.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() {
+
+			private Color SUPER_LIGHT_GRAY = new Color(240, 240, 240);
+
+			public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
+					boolean hasFocus, int row, int column) {
+				if ((row % 2) == 0) {
+					setBackground(Color.WHITE);
+				} else {
+					setBackground(SUPER_LIGHT_GRAY);
+				}
+
+				return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
+			}
+
+			private static final long serialVersionUID = 1L;
+
+		});
+		logTable.setShowGrid(false);
+		logScrollPane.setAutoscrolls(true);
+
+		JTabbedPane viewPanel = new JTabbedPane();
+		// viewPanel.addTab("Records view", new JLabel("Records view"));
+		viewPanel.addTab("Log view", logScrollPane);
+
+		getContentPane().add(headerPanel, BorderLayout.NORTH);
+		getContentPane().add(viewPanel, BorderLayout.CENTER);
+	}
+
+	public void refresh() {
+		recordStoreTypeLabel.setText(common.getRecordStoreManager().getName());
+
+		suiteNameLabel.setText(common.getLauncher().getSuiteName());
+
+		common.getRecordStoreManager().setRecordListener(new ExtendedRecordListener() {
+
+			public void recordEvent(int type, long timestamp, RecordStore recordStore, int recordId) {
+				String eventMessageType = null;
+
+				switch (type) {
+				case ExtendedRecordListener.RECORD_ADD:
+					eventMessageType = "added";
+					break;
+				case ExtendedRecordListener.RECORD_READ:
+					eventMessageType = "read";
+					break;
+				case ExtendedRecordListener.RECORD_CHANGE:
+					eventMessageType = "changed";
+					break;
+				case ExtendedRecordListener.RECORD_DELETE:
+					eventMessageType = "deleted";
+					break;
+				}
+
+				try {
+					modelTable.addRow(new Object[] { dateFormat.format(new Date(timestamp)),
+							"record " + eventMessageType, recordStore.getName(), "recordId = " + recordId });
+				} catch (RecordStoreNotOpenException e) {
+					// TODO Auto-generated catch block
+					e.printStackTrace();
+				}
+				logTable.scrollRectToVisible(logTable.getCellRect(modelTable.getRowCount() - 1, 0, true));
+			}
+
+			public void recordStoreEvent(int type, long timestamp, String recordStoreName) {
+				String eventMessageType = null;
+
+				switch (type) {
+				case ExtendedRecordListener.RECORDSTORE_OPEN:
+					eventMessageType = "opened";
+					break;
+				case ExtendedRecordListener.RECORDSTORE_CLOSE:
+					eventMessageType = "closed";
+					break;
+				case ExtendedRecordListener.RECORDSTORE_DELETE:
+					eventMessageType = "deleted";
+					break;
+				}
+
+				modelTable.addRow(new Object[] { dateFormat.format(new Date(timestamp)), "store " + eventMessageType,
+						recordStoreName, null });
+				logTable.scrollRectToVisible(logTable.getCellRect(modelTable.getRowCount() - 1, 0, true));
+			}
+
+			public void recordAdded(RecordStore recordStore, int recordId) {
+				// already handled by recordEvent
+			}
+
+			public void recordChanged(RecordStore recordStore, int recordId) {
+				// already handled by recordEvent
+			}
+
+			public void recordDeleted(RecordStore recordStore, int recordId) {
+				// already handled by recordEvent
+			}
+
+		});
+	}
+}

Propchange: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/RecordStoreManagerDialog.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/ResizeDeviceDisplayDialog.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/ResizeDeviceDisplayDialog.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/ResizeDeviceDisplayDialog.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/ResizeDeviceDisplayDialog.java Mon May 26 15:20:19 2008
@@ -0,0 +1,113 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.microemu.app.ui.swing;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.JButton;
+import javax.swing.JLabel;
+import javax.swing.JTextField;
+import javax.swing.text.AttributeSet;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.Document;
+import javax.swing.text.PlainDocument;
+
+public class ResizeDeviceDisplayDialog extends SwingDialogPanel {
+
+    private static final long serialVersionUID = 1L;
+    
+    private class IntegerField extends JTextField {
+
+        private static final long serialVersionUID = 1L;
+        
+        private int minValue;
+        
+        private int maxValue;
+
+        public IntegerField(int cols, int minValue, int maxValue) {
+            super(cols);
+            
+            this.minValue = minValue;
+            this.maxValue = maxValue;
+        }
+
+        protected Document createDefaultModel() {
+            return new IntegerDocument();
+        }
+
+        class IntegerDocument extends PlainDocument {
+
+            private static final long serialVersionUID = 1L;
+
+            public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
+                if (str == null) {
+                    return;
+                }
+                char[] test = str.toCharArray();
+                for (int i = 0; i < test.length; i++) {
+                    if (!Character.isDigit(test[i])) {
+                        return;
+                    }
+                }
+                String prevText = getText(0, getLength());
+                super.insertString(offs, str, a);
+                int testValue = Integer.parseInt(getText(0, getLength()));
+                if (testValue < minValue | testValue > maxValue) {
+                    replace(0, getLength(), prevText, a);
+                }                
+            }
+        }
+    };    
+    
+    private IntegerField widthField = new IntegerField(5, 1, 9999);
+    
+    private IntegerField heightField = new IntegerField(5, 1, 9999);
+
+    public ResizeDeviceDisplayDialog() {
+        add(new JLabel("Width:"));
+        add(this.widthField);
+        add(new JLabel("Height:"));
+        add(this.heightField);
+        JButton swapButton = new JButton("Swap");
+        swapButton.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+                String tmp = widthField.getText();
+                widthField.setText(heightField.getText());
+                heightField.setText(tmp);
+            }
+        });
+        add(swapButton);
+    }
+
+    public void setDeviceDisplaySize(int width, int height) {
+        widthField.setText("" + width);
+        heightField.setText("" + height);
+    }
+    
+    public int getDeviceDisplayWidth() {
+        return Integer.parseInt(widthField.getText());
+    }
+    
+    public int getDeviceDisplayHeight() {
+        return Integer.parseInt(heightField.getText());
+    }
+
+}

Propchange: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/ResizeDeviceDisplayDialog.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/SwingAboutDialog.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/SwingAboutDialog.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/SwingAboutDialog.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/SwingAboutDialog.java Mon May 26 15:20:19 2008
@@ -0,0 +1,80 @@
+/*
+ *  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.swing;
+
+import java.awt.Font;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.Toolkit;
+
+import javax.swing.ImageIcon;
+import javax.swing.JLabel;
+
+import org.microemu.app.Main;
+import org.microemu.app.util.BuildVersion;
+
+/**
+ * @author vlads
+ *
+ */
+public class SwingAboutDialog extends SwingDialogPanel {
+
+	private static final long serialVersionUID = 1L;
+
+	private JLabel iconLabel;
+	
+	private JLabel textLabel;
+	
+	public SwingAboutDialog() {
+		
+		setLayout(new GridBagLayout());
+		
+		GridBagConstraints c = new GridBagConstraints();
+		
+		c.ipadx = 10;
+		c.ipady = 10;
+		c.gridx = 0;
+		c.gridy = 0;
+		iconLabel = new JLabel();
+		add(iconLabel, c);
+		
+		iconLabel.setIcon(new ImageIcon(Toolkit.getDefaultToolkit().getImage(Main.class.getResource("/org/microemu/icon.png"))));
+		
+		c.gridx = 1;
+		c.gridy = 0;
+		c.weightx = 1;
+		c.gridwidth = GridBagConstraints.REMAINDER;
+		textLabel = new JLabel("MicroEmulator");
+		textLabel.setFont(new Font("Default", Font.BOLD, 18));
+		add(textLabel, c);
+		
+		c.gridy = 1;
+		c.weightx = 0.0;
+		c.gridwidth = GridBagConstraints.REMAINDER;
+		c.anchor = GridBagConstraints.WEST;
+		add(new JLabel("version: " + BuildVersion.getVersion()), c);
+		
+		c.gridy = 2;
+		c.weightx = 0.0;
+		c.gridwidth = GridBagConstraints.REMAINDER;
+		add(new JLabel("Copyright (C) 2001-2007 Bartek Teodorczyk & co"), c);
+
+	}
+}

Propchange: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/SwingAboutDialog.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/SwingDeviceComponent.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/SwingDeviceComponent.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/SwingDeviceComponent.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/SwingDeviceComponent.java Mon May 26 15:20:19 2008
@@ -0,0 +1,485 @@
+/*
+ *  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.swing;
+
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.Image;
+import java.awt.Polygon;
+import java.awt.Shape;
+import java.awt.Toolkit;
+import java.awt.datatransfer.Clipboard;
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.Transferable;
+import java.awt.datatransfer.UnsupportedFlavorException;
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.awt.event.MouseMotionListener;
+import java.io.IOException;
+import java.util.Timer;
+import java.util.TimerTask;
+
+import javax.microedition.lcdui.Command;
+import javax.swing.JPanel;
+import javax.swing.UIManager;
+
+import org.microemu.DisplayAccess;
+import org.microemu.DisplayComponent;
+import org.microemu.MIDletAccess;
+import org.microemu.MIDletBridge;
+import org.microemu.app.Common;
+import org.microemu.device.Device;
+import org.microemu.device.DeviceFactory;
+import org.microemu.device.impl.DeviceDisplayImpl;
+import org.microemu.device.impl.Rectangle;
+import org.microemu.device.impl.SoftButton;
+import org.microemu.device.j2se.J2SEButton;
+import org.microemu.device.j2se.J2SEDeviceButtonsHelper;
+import org.microemu.device.j2se.J2SEDeviceDisplay;
+import org.microemu.device.j2se.J2SEImmutableImage;
+import org.microemu.device.j2se.J2SEInputMethod;
+import org.microemu.device.j2se.J2SEMutableImage;
+import org.microemu.log.Logger;
+
+public class SwingDeviceComponent extends JPanel implements KeyListener {
+
+	private static final long serialVersionUID = 1L;
+
+	SwingDisplayComponent dc;
+
+	J2SEButton prevOverButton;
+
+	J2SEButton overButton;
+
+	J2SEButton pressedButton;
+
+	private boolean mouseButtonDown = false;
+
+	Image offi;
+
+	Graphics offg;
+
+	private boolean showMouseCoordinates = false;
+
+	private int pressedX;
+
+	private int pressedY;
+
+	private static class MouseRepeatedTimerTask extends TimerTask {
+
+		private static final int DELAY = 100;
+
+		Timer timer;
+
+		Component source;
+
+		J2SEButton button;
+
+		J2SEInputMethod inputMethod;
+
+		static MouseRepeatedTimerTask task;
+
+		static void schedule(Component source, J2SEButton button, J2SEInputMethod inputMethod) {
+			if (task != null) {
+				task.cancel();
+			}
+			task = new MouseRepeatedTimerTask();
+			task.source = source;
+			task.button = button;
+			task.inputMethod = inputMethod;
+			task.timer = new Timer();
+			task.timer.scheduleAtFixedRate(task, 5 * DELAY, DELAY);
+		}
+
+		static void stop() {
+			if (task != null) {
+				task.inputMethod = null;
+				if (task.timer != null) {
+					task.timer.cancel();
+				}
+				task.cancel();
+				task = null;
+			}
+		}
+
+		public static void mouseReleased() {
+			if ((task != null) && (task.inputMethod != null)) {
+				task.inputMethod.buttonReleased(task.button, '\0');
+				stop();
+			}
+
+		}
+
+		public void run() {
+			if (inputMethod != null) {
+				inputMethod.buttonPressed(button, '\0');
+			}
+		}
+
+	}
+
+	private MouseAdapter mouseListener = new MouseAdapter() {
+
+		public void mousePressed(MouseEvent e) {
+			requestFocus();
+			mouseButtonDown = true;
+			pressedX = e.getX();
+			pressedY = e.getY();
+
+			MouseRepeatedTimerTask.stop();
+			if (MIDletBridge.getCurrentMIDlet() == null) {
+				return;
+			}
+
+			Device device = DeviceFactory.getDevice();
+			J2SEInputMethod inputMethod = (J2SEInputMethod) device.getInputMethod();
+			// if the displayable is in full screen mode, we should not
+			// invoke any associated commands, but send the raw key codes
+			// instead
+			boolean fullScreenMode = device.getDeviceDisplay().isFullScreenMode();
+
+			pressedButton = J2SEDeviceButtonsHelper.getSkinButton(e);
+			if (pressedButton != null) {
+				if (pressedButton instanceof SoftButton && !fullScreenMode) {
+					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());
+					}
+				} else {
+					inputMethod.buttonPressed(pressedButton, '\0');
+					MouseRepeatedTimerTask.schedule(SwingDeviceComponent.this, pressedButton, inputMethod);
+				}
+				// optimize for some video cards.
+				repaint(pressedButton.getShape().getBounds());
+			}
+		}
+
+		public void mouseReleased(MouseEvent e) {
+			mouseButtonDown = false;
+			MouseRepeatedTimerTask.stop();
+
+			if (pressedButton == null) {
+				return;
+			}
+
+			if (MIDletBridge.getCurrentMIDlet() == null) {
+				return;
+			}
+
+			Device device = DeviceFactory.getDevice();
+			J2SEInputMethod inputMethod = (J2SEInputMethod) device.getInputMethod();
+			J2SEButton prevOverButton = J2SEDeviceButtonsHelper.getSkinButton(e);
+			if (prevOverButton != null) {
+				inputMethod.buttonReleased(prevOverButton, '\0');
+			}
+			pressedButton = null;
+			// optimize for some video cards.
+			if (prevOverButton != null) {
+				repaint(prevOverButton.getShape().getBounds());
+			} else {
+				repaint();
+			}
+		}
+
+	};
+
+	private MouseMotionListener mouseMotionListener = new MouseMotionListener() {
+
+		public void mouseDragged(MouseEvent e) {
+			mouseMoved(e);
+		}
+
+		public void mouseMoved(MouseEvent e) {
+			if (showMouseCoordinates) {
+				StringBuffer buf = new StringBuffer();
+				if (mouseButtonDown) {
+					int width = e.getX() - pressedX;
+					int height = e.getY() - pressedY;
+					buf.append(pressedX).append(",").append(pressedY).append(" ").append(width).append("x").append(
+							height);
+				} else {
+					buf.append(e.getX()).append(",").append(e.getY());
+				}
+				Common.setStatusBar(buf.toString());
+			}
+
+			if (mouseButtonDown && pressedButton == null) {
+				return;
+			}
+
+			prevOverButton = overButton;
+			overButton = J2SEDeviceButtonsHelper.getSkinButton(e);
+			if (overButton != prevOverButton) {
+				// optimize for some video cards.
+				if (prevOverButton != null) {
+					MouseRepeatedTimerTask.mouseReleased();
+					pressedButton = null;
+					repaint(prevOverButton.getShape().getBounds());
+				}
+				if (overButton != null) {
+					repaint(overButton.getShape().getBounds());
+				}
+			} else if (overButton == null) {
+				MouseRepeatedTimerTask.mouseReleased();
+				pressedButton = null;
+				if (prevOverButton != null) {
+					repaint(prevOverButton.getShape().getBounds());
+				}
+			}
+		}
+
+	};
+
+	public SwingDeviceComponent() {
+		dc = new SwingDisplayComponent(this);
+		setLayout(new XYLayout());
+
+		addMouseListener(mouseListener);
+		addMouseMotionListener(mouseMotionListener);
+	}
+
+	public DisplayComponent getDisplayComponent() {
+		return dc;
+	}
+
+	public void init() {
+		dc.init();
+
+		remove(dc);
+
+		Rectangle r = ((J2SEDeviceDisplay) DeviceFactory.getDevice().getDeviceDisplay()).getDisplayRectangle();
+		add(dc, new XYConstraints(r.x, r.y, -1, -1));
+
+		revalidate();
+	}
+
+	private void repaint(Rectangle r) {
+		repaint(r.x, r.y, r.width, r.height);
+	}
+
+	public void switchShowMouseCoordinates() {
+		// TODO skin editing mode.
+		// showMouseCoordinates = !showMouseCoordinates;
+		dc.switchShowMouseCoordinates();
+	}
+
+	public void keyTyped(KeyEvent ev) {
+		if (MIDletBridge.getCurrentMIDlet() == null) {
+			return;
+		}
+
+		J2SEInputMethod inputMethod = ((J2SEInputMethod) DeviceFactory.getDevice().getInputMethod());
+		J2SEButton button = inputMethod.getButton(ev);
+		if (button != null) {
+			inputMethod.buttonTyped(button);
+		}
+	}
+
+	public void keyPressed(KeyEvent ev) {
+		if (MIDletBridge.getCurrentMIDlet() == null) {
+			return;
+		}
+
+		Device device = DeviceFactory.getDevice();
+		J2SEInputMethod inputMethod = (J2SEInputMethod) device.getInputMethod();
+
+		if (ev.getKeyCode() == KeyEvent.VK_V && (ev.getModifiers() & KeyEvent.CTRL_MASK) != 0) {
+			Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
+			Transferable transferable = clipboard.getContents(null);
+			if (transferable != null) {
+				try {
+					Object data = transferable.getTransferData(DataFlavor.stringFlavor);
+					if (data instanceof String) {
+						inputMethod.clipboardPaste((String) data);
+					}
+				} catch (UnsupportedFlavorException ex) {
+					Logger.error(ex);
+				} catch (IOException ex) {
+					Logger.error(ex);
+				}
+			}
+			return;
+		}
+
+		switch (ev.getKeyCode()) {
+		case 0:
+		case KeyEvent.VK_ALT:
+		case KeyEvent.VK_CONTROL:
+		case KeyEvent.VK_SHIFT:
+			return;
+		}
+
+		char keyChar = '\0';
+		if (ev.getKeyChar() >= 32 && ev.getKeyChar() != 65535) {
+			keyChar = ev.getKeyChar();
+		}
+		J2SEButton button = inputMethod.getButton(ev);
+		if (button != null) {
+			pressedButton = button;
+			// numeric keypad functions as hot keys for buttons only
+			if ((ev.getKeyCode() >= KeyEvent.VK_NUMPAD0) && (ev.getKeyCode() <= KeyEvent.VK_NUMPAD9)) {
+				keyChar = '\0';
+			}
+			// soft buttons
+			if ((ev.getKeyCode() >= KeyEvent.VK_F1) && (ev.getKeyCode() <= KeyEvent.VK_F12)) {
+				keyChar = '\0';
+			}
+			org.microemu.device.impl.Shape shape = button.getShape();
+			if (shape != null) {
+				repaint(shape.getBounds());
+			}
+		} else {
+			// Logger.debug0x("no button for KeyCode", ev.getKeyCode());
+		}
+		inputMethod.buttonPressed(button, keyChar);
+	}
+
+	public void keyReleased(KeyEvent ev) {
+		if (MIDletBridge.getCurrentMIDlet() == null) {
+			return;
+		}
+
+		switch (ev.getKeyCode()) {
+		case 0:
+		case KeyEvent.VK_ALT:
+		case KeyEvent.VK_CONTROL:
+		case KeyEvent.VK_SHIFT:
+			return;
+		}
+
+		Device device = DeviceFactory.getDevice();
+		J2SEInputMethod inputMethod = (J2SEInputMethod) device.getInputMethod();
+
+		char keyChar = '\0';
+		if (ev.getKeyChar() >= 32 && ev.getKeyChar() != 65535) {
+			keyChar = ev.getKeyChar();
+		}
+		// numeric keypad functions as hot keys for buttons only
+		if ((ev.getKeyCode() >= KeyEvent.VK_NUMPAD0) && (ev.getKeyCode() <= KeyEvent.VK_NUMPAD9)) {
+			keyChar = '\0';
+		}
+		// soft buttons
+		if ((ev.getKeyCode() >= KeyEvent.VK_F1) && (ev.getKeyCode() <= KeyEvent.VK_F12)) {
+			keyChar = '\0';
+		}
+		inputMethod.buttonReleased(inputMethod.getButton(ev), keyChar);
+
+		prevOverButton = pressedButton;
+		pressedButton = null;
+		if (prevOverButton != null) {
+			org.microemu.device.impl.Shape shape = prevOverButton.getShape();
+			if (shape != null) {
+				repaint(shape.getBounds());
+			}
+		}
+	}
+
+	public MouseListener getDefaultMouseListener() {
+		return mouseListener;
+	}
+
+	public MouseMotionListener getDefaultMouseMotionListener() {
+		return mouseMotionListener;
+	}
+
+	protected void paintComponent(Graphics g) {
+		if (offg == null || offi.getWidth(null) != getSize().width || offi.getHeight(null) != getSize().height) {
+			offi = new J2SEMutableImage(getSize().width, getSize().height).getImage();
+			offg = offi.getGraphics();
+		}
+
+		Dimension size = getSize();
+		offg.setColor(UIManager.getColor("text"));
+		offg.fillRect(0, 0, size.width, size.height);
+		Device device = DeviceFactory.getDevice();
+		if (device == null) {
+			g.drawRect(0, 0, getWidth() - 1, getHeight() - 1);
+			return;
+		}
+		if (((DeviceDisplayImpl) device.getDeviceDisplay()).isResizable()) {
+			return;
+		}
+
+		offg.drawImage(((J2SEImmutableImage) device.getNormalImage()).getImage(), 0, 0, this);
+
+		if (prevOverButton != null) {
+			org.microemu.device.impl.Shape shape = prevOverButton.getShape();
+			if (shape != null) {
+				drawImageInShape(offg, ((J2SEImmutableImage) device.getNormalImage()).getImage(), shape);
+			}
+			prevOverButton = null;
+		}
+		if (overButton != null) {
+			org.microemu.device.impl.Shape shape = overButton.getShape();
+			if (shape != null) {
+				drawImageInShape(offg, ((J2SEImmutableImage) device.getOverImage()).getImage(), shape);
+			}
+		}
+		if (pressedButton != null) {
+			org.microemu.device.impl.Shape shape = pressedButton.getShape();
+			if (shape != null) {
+				drawImageInShape(offg, ((J2SEImmutableImage) device.getPressedImage()).getImage(), shape);
+			}
+		}
+
+		g.drawImage(offi, 0, 0, null);
+	}
+
+	private void drawImageInShape(Graphics g, Image image, org.microemu.device.impl.Shape shape) {
+		Shape clipSave = g.getClip();
+		if (shape instanceof org.microemu.device.impl.Polygon) {
+			Polygon poly = new Polygon(((org.microemu.device.impl.Polygon) shape).xpoints,
+					((org.microemu.device.impl.Polygon) shape).ypoints,
+					((org.microemu.device.impl.Polygon) shape).npoints);
+			g.setClip(poly);
+		}
+		org.microemu.device.impl.Rectangle r = shape.getBounds();
+		g.drawImage(image, r.x, r.y, r.x + r.width, r.y + r.height, r.x, r.y, r.x + r.width, r.y + r.height, null);
+		g.setClip(clipSave);
+	}
+
+	public Dimension getPreferredSize() {
+		Device device = DeviceFactory.getDevice();
+		if (device == null) {
+			return new Dimension(0, 0);
+		}
+
+		DeviceDisplayImpl deviceDisplay = (DeviceDisplayImpl) DeviceFactory.getDevice().getDeviceDisplay();
+		if (deviceDisplay.isResizable()) {
+			return new Dimension(deviceDisplay.getFullWidth(), deviceDisplay.getFullHeight());
+		} else {
+			javax.microedition.lcdui.Image img = device.getNormalImage();
+			return new Dimension(img.getWidth(), img.getHeight());
+		}
+	}
+
+}