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 [6/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...
Propchange: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/SwingDeviceComponent.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/SwingDialogPanel.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/SwingDialogPanel.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/SwingDialogPanel.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/SwingDialogPanel.java Mon May 26 15:20:19 2008
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.microemu.app.ui.swing;
+
+import javax.swing.JButton;
+import javax.swing.JPanel;
+
+/**
+ * Bazowa klasa panelu wyswietlanego w oknie dialogowym
+ */
+
+public class SwingDialogPanel extends JPanel
+{
+
+ public JButton btOk = new JButton("OK");
+ public JButton btCancel = new JButton("Cancel");
+
+ boolean state;
+
+ boolean extra;
+
+ /**
+ * Walidacja panelu
+ *
+ * @param state czy wyswietlac komunikaty bledow
+ * @return true jesli wszysko jest ok
+ */
+ public boolean check(boolean state)
+ {
+ return true;
+ }
+
+
+ protected void hideNotify()
+ {
+ }
+
+
+ protected void showNotify()
+ {
+ }
+
+ protected JButton getExtraButton()
+ {
+ return null;
+ }
+
+ public boolean isExtraButtonPressed() {
+ return extra;
+ }
+
+}
\ No newline at end of file
Propchange: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/SwingDialogPanel.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/SwingDialogWindow.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/SwingDialogWindow.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/SwingDialogWindow.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/SwingDialogWindow.java Mon May 26 15:20:19 2008
@@ -0,0 +1,123 @@
+/*
+ * 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.Dimension;
+import java.awt.Frame;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import javax.swing.JButton;
+import javax.swing.JDialog;
+import javax.swing.JPanel;
+
+
+public class SwingDialogWindow
+{
+
+ /**
+ * Open modal dialog window
+ *
+ * @param title dialog title
+ * @param panel content
+ * @param hasCancel has Cancel button
+ * @return true if user pressed OK button
+ */
+ public static boolean show(Frame parent, String title, final SwingDialogPanel panel, boolean hasCancel)
+ {
+ final JDialog dialog = new JDialog(parent, title, true);
+ dialog.getContentPane().setLayout(new BorderLayout());
+ dialog.getContentPane().add(panel, BorderLayout.CENTER);
+
+ JPanel actionPanel = new JPanel();
+ actionPanel.add(panel.btOk);
+ if (hasCancel) {
+ actionPanel.add(panel.btCancel);
+ }
+ final JButton extraButton = panel.getExtraButton();
+ if (extraButton != null) {
+ actionPanel.add(extraButton);
+ }
+ dialog.getContentPane().add(actionPanel, BorderLayout.SOUTH);
+ dialog.pack();
+
+ Dimension frameSize = dialog.getSize();
+ int x = parent.getLocation().x + ((parent.getWidth() - frameSize.width) / 2);
+ if (x < 0) {
+ x = 0;
+ }
+ int y = parent.getLocation().y + ((parent.getHeight() - frameSize.height) / 2);
+ if (y < 0) {
+ y = 0;
+ }
+ dialog.setLocation(x, y);
+
+ ActionListener closeListener = new ActionListener() {
+ public void actionPerformed(ActionEvent event) {
+ Object source = event.getSource();
+ panel.extra = false;
+ if (source == panel.btOk || source == extraButton) {
+ if (panel.check(true)) {
+ if (source == extraButton) {
+ panel.extra = true;
+ }
+ panel.state = true;
+ dialog.setVisible(false);
+ panel.hideNotify();
+ }
+ } else {
+ panel.state = false;
+ dialog.setVisible(false);
+ panel.hideNotify();
+ }
+ }
+ };
+
+ WindowAdapter windowAdapter = new WindowAdapter()
+ {
+ public void windowClosing(WindowEvent e)
+ {
+ panel.state = false;
+ panel.hideNotify();
+ }
+ };
+
+ dialog.addWindowListener(windowAdapter);
+ panel.btOk.addActionListener(closeListener);
+ panel.btCancel.addActionListener(closeListener);
+ if (extraButton != null) {
+ extraButton.addActionListener(closeListener);
+ }
+ panel.showNotify();
+ dialog.setVisible(true);
+ panel.btOk.removeActionListener(closeListener);
+ panel.btCancel.removeActionListener(closeListener);
+ if (extraButton != null) {
+ extraButton.removeActionListener(closeListener);
+ }
+
+ return panel.state;
+ }
+
+}
+
Propchange: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/SwingDialogWindow.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/SwingDisplayComponent.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/SwingDisplayComponent.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/SwingDisplayComponent.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/SwingDisplayComponent.java Mon May 26 15:20:19 2008
@@ -0,0 +1,333 @@
+/*
+ * 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.Dimension;
+import java.awt.Graphics;
+import java.awt.Point;
+import java.awt.event.KeyEvent;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseMotionListener;
+import java.awt.event.MouseWheelEvent;
+import java.awt.event.MouseWheelListener;
+import java.util.Iterator;
+
+import javax.microedition.lcdui.Command;
+import javax.microedition.lcdui.Displayable;
+import javax.swing.JComponent;
+import javax.swing.SwingUtilities;
+
+import org.microemu.DisplayAccess;
+import org.microemu.DisplayComponent;
+import org.microemu.MIDletAccess;
+import org.microemu.MIDletBridge;
+import org.microemu.app.Common;
+import org.microemu.app.ui.DisplayRepaintListener;
+import org.microemu.device.Device;
+import org.microemu.device.DeviceDisplay;
+import org.microemu.device.DeviceFactory;
+import org.microemu.device.MutableImage;
+import org.microemu.device.impl.InputMethodImpl;
+import org.microemu.device.impl.SoftButton;
+import org.microemu.device.j2se.J2SEDeviceDisplay;
+import org.microemu.device.j2se.J2SEInputMethod;
+import org.microemu.device.j2se.J2SEMutableImage;
+
+public class SwingDisplayComponent extends JComponent implements DisplayComponent {
+ private static final long serialVersionUID = 1L;
+
+ private SwingDeviceComponent deviceComponent;
+
+ private J2SEMutableImage displayImage = null;
+
+ private SoftButton initialPressedSoftButton;
+
+ private DisplayRepaintListener displayRepaintListener;
+
+ private boolean showMouseCoordinates = false;
+
+ private Point pressedPoint = new Point();
+
+ private MouseAdapter mouseListener = new MouseAdapter() {
+
+ public void mousePressed(MouseEvent e) {
+ deviceComponent.requestFocus();
+ pressedPoint = e.getPoint();
+
+ if (MIDletBridge.getCurrentMIDlet() == null) {
+ return;
+ }
+
+ if (SwingUtilities.isMiddleMouseButton(e)) {
+ // fire
+ KeyEvent event = new KeyEvent(deviceComponent, 0, System.currentTimeMillis(), 0, KeyEvent.VK_ENTER,
+ KeyEvent.CHAR_UNDEFINED);
+ deviceComponent.keyPressed(event);
+ deviceComponent.keyReleased(event);
+ 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();
+
+ if (device.hasPointerEvents()) {
+ if (!fullScreenMode) {
+ Iterator it = device.getSoftButtons().iterator();
+ while (it.hasNext()) {
+ SoftButton button = (SoftButton) it.next();
+ if (button.isVisible()) {
+ org.microemu.device.impl.Rectangle pb = button.getPaintable();
+ if (pb != null && pb.contains(e.getX(), e.getY())) {
+ initialPressedSoftButton = button;
+ button.setPressed(true);
+ repaintRequest(pb.x, pb.y, pb.width, pb.height);
+ break;
+ }
+ }
+ }
+ }
+ Point p = deviceCoordinate(device.getDeviceDisplay(), e.getPoint());
+ inputMethod.pointerPressed(p.x, p.y);
+ }
+ }
+
+ public void mouseReleased(MouseEvent e) {
+ if (MIDletBridge.getCurrentMIDlet() == null) {
+ return;
+ }
+
+ Device device = DeviceFactory.getDevice();
+ J2SEInputMethod inputMethod = (J2SEInputMethod) device.getInputMethod();
+ boolean fullScreenMode = device.getDeviceDisplay().isFullScreenMode();
+ if (device.hasPointerEvents()) {
+ if (!fullScreenMode) {
+ if (initialPressedSoftButton != null && initialPressedSoftButton.isPressed()) {
+ initialPressedSoftButton.setPressed(false);
+ org.microemu.device.impl.Rectangle pb = initialPressedSoftButton.getPaintable();
+ if (pb != null) {
+ repaintRequest(pb.x, pb.y, pb.width, pb.height);
+ if (pb.contains(e.getX(), e.getY())) {
+ Command cmd = initialPressedSoftButton.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());
+ }
+ }
+ }
+ }
+ initialPressedSoftButton = null;
+ }
+ Point p = deviceCoordinate(device.getDeviceDisplay(), e.getPoint());
+ inputMethod.pointerReleased(p.x, p.y);
+ }
+ }
+
+ };
+
+ private MouseMotionListener mouseMotionListener = new MouseMotionListener() {
+
+ public void mouseDragged(MouseEvent e) {
+ if (showMouseCoordinates) {
+ StringBuffer buf = new StringBuffer();
+ int width = e.getX() - pressedPoint.x;
+ int height = e.getY() - pressedPoint.y;
+ Point p = deviceCoordinate(DeviceFactory.getDevice().getDeviceDisplay(), pressedPoint);
+ buf.append(p.x).append(",").append(p.y).append(" ").append(width).append("x").append(height);
+ Common.setStatusBar(buf.toString());
+ }
+
+ Device device = DeviceFactory.getDevice();
+ InputMethodImpl inputMethod = (InputMethodImpl) device.getInputMethod();
+ boolean fullScreenMode = device.getDeviceDisplay().isFullScreenMode();
+ if (device.hasPointerMotionEvents()) {
+ if (!fullScreenMode) {
+ if (initialPressedSoftButton != null) {
+ org.microemu.device.impl.Rectangle pb = initialPressedSoftButton.getPaintable();
+ if (pb != null) {
+ if (pb.contains(e.getX(), e.getY())) {
+ if (!initialPressedSoftButton.isPressed()) {
+ initialPressedSoftButton.setPressed(true);
+ repaintRequest(pb.x, pb.y, pb.width, pb.height);
+ }
+ } else {
+ if (initialPressedSoftButton.isPressed()) {
+ initialPressedSoftButton.setPressed(false);
+ repaintRequest(pb.x, pb.y, pb.width, pb.height);
+ }
+ }
+ }
+ }
+ }
+ Point p = deviceCoordinate(device.getDeviceDisplay(), e.getPoint());
+ inputMethod.pointerDragged(p.x, p.y);
+ }
+ }
+
+ public void mouseMoved(MouseEvent e) {
+ if (showMouseCoordinates) {
+ StringBuffer buf = new StringBuffer();
+ Point p = deviceCoordinate(DeviceFactory.getDevice().getDeviceDisplay(), e.getPoint());
+ buf.append(p.x).append(",").append(p.y);
+ Common.setStatusBar(buf.toString());
+ }
+ }
+
+ };
+
+ private MouseWheelListener mouseWheelListener = new MouseWheelListener() {
+
+ public void mouseWheelMoved(MouseWheelEvent ev) {
+ if (ev.getWheelRotation() > 0) {
+ // down
+ KeyEvent event = new KeyEvent(deviceComponent, 0, System.currentTimeMillis(), 0, KeyEvent.VK_DOWN,
+ KeyEvent.CHAR_UNDEFINED);
+ deviceComponent.keyPressed(event);
+ deviceComponent.keyReleased(event);
+ } else {
+ // up
+ KeyEvent event = new KeyEvent(deviceComponent, 0, System.currentTimeMillis(), 0, KeyEvent.VK_UP,
+ KeyEvent.CHAR_UNDEFINED);
+ deviceComponent.keyPressed(event);
+ deviceComponent.keyReleased(event);
+ }
+ }
+
+ };
+
+ SwingDisplayComponent(SwingDeviceComponent deviceComponent) {
+ this.deviceComponent = deviceComponent;
+
+ setFocusable(false);
+
+ addMouseListener(mouseListener);
+ addMouseMotionListener(mouseMotionListener);
+ addMouseWheelListener(mouseWheelListener);
+ }
+
+ public void init() {
+ synchronized (this) {
+ displayImage = null;
+ initialPressedSoftButton = null;
+ }
+ }
+
+ public void addDisplayRepaintListener(DisplayRepaintListener l) {
+ displayRepaintListener = l;
+ }
+
+ public void removeDisplayRepaintListener(DisplayRepaintListener l) {
+ if (displayRepaintListener == l) {
+ displayRepaintListener = null;
+ }
+ }
+
+ public MutableImage getDisplayImage() {
+ return displayImage;
+ }
+
+ public Dimension getPreferredSize() {
+ Device device = DeviceFactory.getDevice();
+ if (device == null) {
+ return new Dimension(0, 0);
+ }
+
+ return new Dimension(device.getDeviceDisplay().getFullWidth(), device.getDeviceDisplay().getFullHeight());
+ }
+
+ protected void paintComponent(Graphics g) {
+ if (displayImage != null) {
+ synchronized (displayImage) {
+ g.drawImage(displayImage.getImage(), 0, 0, null);
+ }
+ }
+ }
+
+ 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) {
+ synchronized (this) {
+ if (displayImage == null) {
+ displayImage = new J2SEMutableImage(device.getDeviceDisplay().getFullWidth(), device
+ .getDeviceDisplay().getFullHeight());
+ }
+
+ synchronized (displayImage) {
+ Graphics gc = displayImage.getImage().getGraphics();
+
+ J2SEDeviceDisplay deviceDisplay = (J2SEDeviceDisplay) device.getDeviceDisplay();
+ deviceDisplay.paintDisplayable(gc, x, y, width, height);
+ if (!deviceDisplay.isFullScreenMode()) {
+ deviceDisplay.paintControls(gc);
+ }
+ }
+
+ fireDisplayRepaint(displayImage);
+ }
+ }
+
+ repaint();
+ }
+
+ private void fireDisplayRepaint(MutableImage image) {
+ if (displayRepaintListener != null) {
+ displayRepaintListener.repaintInvoked(image);
+ }
+ }
+
+ Point deviceCoordinate(DeviceDisplay deviceDisplay, Point p) {
+ if (deviceDisplay.isFullScreenMode()) {
+ return p;
+ } else {
+ org.microemu.device.impl.Rectangle pb = ((J2SEDeviceDisplay) deviceDisplay).getDisplayPaintable();
+ return new Point(p.x - pb.x, p.y - pb.y);
+ }
+ }
+
+ void switchShowMouseCoordinates() {
+ showMouseCoordinates = !showMouseCoordinates;
+ }
+
+}
Propchange: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/SwingDisplayComponent.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/SwingErrorMessageDialogPanel.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/SwingErrorMessageDialogPanel.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/SwingErrorMessageDialogPanel.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/SwingErrorMessageDialogPanel.java Mon May 26 15:20:19 2008
@@ -0,0 +1,124 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.microemu.app.ui.swing;
+
+import java.awt.Dimension;
+import java.awt.Frame;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.Insets;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+import javax.swing.JLabel;
+import javax.swing.JScrollPane;
+import javax.swing.JTextArea;
+import javax.swing.UIManager;
+
+import org.microemu.app.ui.Message;
+import org.microemu.app.ui.MessageListener;
+
+/**
+ * @author vlads
+ *
+ */
+public class SwingErrorMessageDialogPanel extends SwingDialogPanel implements MessageListener {
+
+ private static final long serialVersionUID = 1L;
+
+ private Frame parent;
+
+ private JLabel iconLabel;
+
+ private JLabel textLabel;
+
+ private JTextArea stackTraceArea;
+
+ private JScrollPane stackTracePane;
+
+ /**
+ * @param parent
+ */
+ public SwingErrorMessageDialogPanel(Frame parent) {
+ this.parent = parent;
+
+ 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);
+
+ c.gridx = 1;
+ c.gridy = 0;
+ c.weightx = 1;
+ textLabel = new JLabel();
+ add(textLabel, c);
+
+ stackTraceArea = new JTextArea();
+ stackTraceArea.setEditable(false);
+ stackTracePane = new JScrollPane(stackTraceArea);
+ stackTracePane.setPreferredSize(new Dimension(250, 250));
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.microemu.app.ui.MessageListener#showMessage(int, java.lang.String, java.lang.String, java.lang.Throwable)
+ */
+ public void showMessage(int level, String title, String text, Throwable throwable) {
+ switch (level) {
+ case Message.ERROR:
+ iconLabel.setIcon(UIManager.getIcon("OptionPane.errorIcon"));
+ break;
+ case Message.WARN:
+ iconLabel.setIcon(UIManager.getIcon("OptionPane.warningIcon"));
+ break;
+ default:
+ iconLabel.setIcon(UIManager.getIcon("OptionPane.informationIcon"));
+ }
+
+ textLabel.setText(text);
+
+ if (throwable != null) {
+ StringWriter writer = new StringWriter();
+ throwable.printStackTrace(new PrintWriter(writer));
+ stackTraceArea.setText(writer.toString());
+ stackTraceArea.setCaretPosition(0);
+ GridBagConstraints c = new GridBagConstraints();
+ c.fill = GridBagConstraints.BOTH;
+ c.gridx = 0;
+ c.gridy = 1;
+ c.gridwidth = 2;
+ c.weightx = 1;
+ c.weighty = 1;
+ add(stackTracePane, c);
+ }
+
+ SwingDialogWindow.show(parent, title, this, false);
+
+ if (throwable != null) {
+ remove(stackTracePane);
+ }
+ }
+
+}
Propchange: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/SwingErrorMessageDialogPanel.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/SwingLogConsoleDialog.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/SwingLogConsoleDialog.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/SwingLogConsoleDialog.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/SwingLogConsoleDialog.java Mon May 26 15:20:19 2008
@@ -0,0 +1,203 @@
+/*
+ * 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.Frame;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Vector;
+
+import javax.swing.JCheckBoxMenuItem;
+import javax.swing.JFrame;
+import javax.swing.JMenu;
+import javax.swing.JMenuBar;
+import javax.swing.JMenuItem;
+import javax.swing.JScrollPane;
+import javax.swing.SwingUtilities;
+
+import org.microemu.app.Config;
+import org.microemu.app.ui.swing.logconsole.LogTextArea;
+import org.microemu.log.Logger;
+import org.microemu.log.LoggerAppender;
+import org.microemu.log.LoggingEvent;
+import org.microemu.log.QueueAppender;
+import org.microemu.log.StdOutAppender;
+
+public class SwingLogConsoleDialog extends JFrame implements LoggerAppender {
+
+ private static final long serialVersionUID = 1L;
+
+ private static final boolean tests = false;
+
+ private LogTextArea logArea;
+
+ private Vector logLinesQueue = new Vector();
+
+ private int testEventCounter = 0;
+
+ private class SwingLogUpdater implements Runnable {
+
+ private String getNextLine() {
+ synchronized (logLinesQueue) {
+ if (logLinesQueue.isEmpty()) {
+ return null;
+ }
+ String line = (String) logLinesQueue.firstElement();
+ logLinesQueue.removeElementAt(0);
+ return line;
+ }
+ }
+
+ public void run() {
+ String line;
+ while ((line = getNextLine()) != null) {
+ logArea.append(line);
+ }
+ }
+ }
+
+ public SwingLogConsoleDialog(Frame owner, QueueAppender logQueueAppender) {
+ super("Log console");
+
+ setIconImage(owner.getIconImage());
+
+ JMenuBar menuBar = new JMenuBar();
+ JMenu menu = new JMenu("Log");
+
+ JMenuItem menuClear = new JMenuItem("Clear");
+ menuClear.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ SwingLogConsoleDialog.this.logArea.setText("");
+ }
+ });
+ menu.add(menuClear);
+
+ menu.addSeparator();
+
+ final JCheckBoxMenuItem menuRecordLocation = new JCheckBoxMenuItem("Show record location");
+ menuRecordLocation.setState(Logger.isLocationEnabled());
+ menuRecordLocation.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ Logger.setLocationEnabled(menuRecordLocation.getState());
+ Config.setLogConsoleLocationEnabled(menuRecordLocation.getState());
+ }
+ });
+ menu.add(menuRecordLocation);
+
+ final JCheckBoxMenuItem menuStdOut = new JCheckBoxMenuItem("Write to standard output");
+ menuStdOut.setState(StdOutAppender.enabled);
+ menuStdOut.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ StdOutAppender.enabled = menuStdOut.getState();
+ }
+ });
+ menu.add(menuStdOut);
+
+ menuBar.add(menu);
+
+ if (tests) {
+ JMenu testMenu = new JMenu("Tests");
+ JMenuItem testLog = new JMenuItem("Log 10 events");
+ testLog.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ for (int i = 0; i < 10; i++) {
+ log(testEventCounter++ + " " + new Date() + "\n\t data tests.......\n");
+ }
+ }
+ });
+ testMenu.add(testLog);
+ menuBar.add(testMenu);
+ }
+
+ setJMenuBar(menuBar);
+
+ this.logArea = new LogTextArea(20, 40, 1000);
+ JScrollPane scrollPane = new JScrollPane(this.logArea);
+ scrollPane.setAutoscrolls(false);
+
+ getContentPane().add(scrollPane);
+
+ LoggingEvent event = null;
+ while ((event = logQueueAppender.poll()) != null) {
+ append(event);
+ }
+
+ Logger.removeAppender(logQueueAppender);
+ Logger.addAppender(this);
+ }
+
+ public void log(String message) {
+ boolean createUpdater = false;
+ synchronized (logLinesQueue) {
+ if (logLinesQueue.isEmpty()) {
+ createUpdater = true;
+ }
+ logLinesQueue.addElement(message);
+ }
+ if (createUpdater) {
+ SwingUtilities.invokeLater(new SwingLogUpdater());
+ }
+ }
+
+ private String formatLocation(StackTraceElement ste) {
+ if (ste == null) {
+ return "";
+ }
+ return ste.getClassName() + "." + ste.getMethodName() + "(" + ste.getFileName() + ":" + ste.getLineNumber()
+ + ")";
+ }
+
+ private String formatEventTime(long eventTime) {
+ DateFormat format = new SimpleDateFormat("HH:mm:ss.SSS ");
+ return format.format(new Date(eventTime));
+ }
+
+ public void append(LoggingEvent event) {
+ StringBuffer bug = new StringBuffer(formatEventTime(event.getEventTime()));
+ if (event.getLevel() == LoggingEvent.ERROR) {
+ bug.append("Error:");
+ }
+ bug.append(event.getMessage());
+ if (event.hasData()) {
+ bug.append(" [").append(event.getFormatedData()).append("]");
+ }
+ String location = formatLocation(event.getLocation());
+ if (location.length() > 0) {
+ bug.append("\n\t ");
+ }
+ bug.append(location);
+ if (event.getThrowable() != null) {
+ OutputStream out = new ByteArrayOutputStream();
+ PrintStream stream = new PrintStream(out);
+ event.getThrowable().printStackTrace(stream);
+ stream.flush();
+ bug.append(out.toString());
+ }
+ bug.append("\n");
+ log(bug.toString());
+ }
+
+}
Propchange: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/SwingLogConsoleDialog.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/SwingSelectDevicePanel.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/SwingSelectDevicePanel.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/SwingSelectDevicePanel.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/SwingSelectDevicePanel.java Mon May 26 15:20:19 2008
@@ -0,0 +1,294 @@
+/*
+ * 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.event.ActionEvent;
+import java.awt.event.ActionListener;
+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.jar.Attributes;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import java.util.jar.Manifest;
+
+import javax.swing.DefaultListModel;
+import javax.swing.JButton;
+import javax.swing.JFileChooser;
+import javax.swing.JList;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.ListSelectionModel;
+import javax.swing.border.EtchedBorder;
+import javax.swing.border.TitledBorder;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.event.ListSelectionListener;
+
+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.j2se.J2SEDevice;
+
+public class SwingSelectDevicePanel extends SwingDialogPanel {
+ private static final long serialVersionUID = 1L;
+
+ private EmulatorContext emulatorContext;
+
+ private JScrollPane spDevices;
+
+ private JButton btAdd;
+
+ private JButton btRemove;
+
+ private JButton btDefault;
+
+ private DefaultListModel lsDevicesModel;
+
+ private JList lsDevices;
+
+ private ActionListener btAddListener = new ActionListener() {
+ private JFileChooser fileChooser = null;
+
+ public void actionPerformed(ActionEvent ev) {
+ if (fileChooser == null) {
+ fileChooser = new JFileChooser();
+ ExtensionFileFilter fileFilter = new ExtensionFileFilter("Device profile (*.jar, *.zip)");
+ fileFilter.addExtension("jar");
+ fileFilter.addExtension("zip");
+ fileChooser.setFileFilter(fileFilter);
+ }
+
+ if (fileChooser.showOpenDialog(SwingSelectDevicePanel.this) == JFileChooser.APPROVE_OPTION) {
+ String manifestDeviceName = null;
+ URL[] urls = new URL[1];
+ ArrayList descriptorEntries = new ArrayList();
+ JarFile jar = null;
+ try {
+ jar = new JarFile(fileChooser.getSelectedFile());
+
+ 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);
+ }
+ }
+ urls[0] = fileChooser.getSelectedFile().toURL();
+ } catch (IOException e) {
+ Message.error("Error reading file: " + fileChooser.getSelectedFile().getName() + ", "
+ + Message.getCauseMessage(e), e);
+ return;
+ } finally {
+ if (jar != null) {
+ try {
+ jar.close();
+ } catch (IOException ignore) {
+ }
+ }
+ }
+
+ if (descriptorEntries.size() == 0) {
+ Message.error("Cannot find any device profile in file: " + fileChooser.getSelectedFile().getName());
+ return;
+ }
+
+ if (descriptorEntries.size() > 1) {
+ manifestDeviceName = null;
+ }
+
+ ClassLoader classLoader = Common.createExtensionsClassLoader(urls);
+ HashMap devices = new HashMap();
+ for (Iterator it = descriptorEntries.iterator(); it.hasNext();) {
+ String entryName = (String) it.next();
+ try {
+ devices.put(entryName, DeviceImpl.create(emulatorContext, classLoader, entryName,
+ J2SEDevice.class));
+ } catch (IOException e) {
+ Message.error("Error parsing device profile, " + Message.getCauseMessage(e), e);
+ return;
+ }
+ }
+
+ for (Enumeration en = lsDevicesModel.elements(); en.hasMoreElements();) {
+ DeviceEntry entry = (DeviceEntry) en.nextElement();
+ 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(), fileChooser.getSelectedFile().getName());
+ if (deviceFile.exists()) {
+ deviceFile = File.createTempFile("device", ".jar", Config.getConfigPath());
+ }
+ IOUtils.copyFile(fileChooser.getSelectedFile(), 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);
+ }
+ lsDevicesModel.addElement(entry);
+ Config.addDeviceEntry(entry);
+ }
+ lsDevices.setSelectedValue(entry, true);
+ } catch (IOException e) {
+ Message.error("Error adding device profile, " + Message.getCauseMessage(e), e);
+ return;
+ }
+ }
+ }
+ };
+
+ private ActionListener btRemoveListener = new ActionListener() {
+ public void actionPerformed(ActionEvent ev) {
+ DeviceEntry entry = (DeviceEntry) lsDevices.getSelectedValue();
+
+ boolean canDeleteFile = true;
+ for (Enumeration en = lsDevicesModel.elements(); en.hasMoreElements();) {
+ DeviceEntry test = (DeviceEntry) en.nextElement();
+ 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 (Enumeration en = lsDevicesModel.elements(); en.hasMoreElements();) {
+ DeviceEntry tmp = (DeviceEntry) en.nextElement();
+ if (!tmp.canRemove()) {
+ tmp.setDefaultDevice(true);
+ break;
+ }
+ }
+ }
+ lsDevicesModel.removeElement(entry);
+ Config.removeDeviceEntry(entry);
+ }
+ };
+
+ private ActionListener btDefaultListener = new ActionListener() {
+ public void actionPerformed(ActionEvent ev) {
+ DeviceEntry entry = (DeviceEntry) lsDevices.getSelectedValue();
+ for (Enumeration en = lsDevicesModel.elements(); en.hasMoreElements();) {
+ DeviceEntry tmp = (DeviceEntry) en.nextElement();
+ if (tmp == entry) {
+ tmp.setDefaultDevice(true);
+ } else {
+ tmp.setDefaultDevice(false);
+ }
+ Config.changeDeviceEntry(tmp);
+ }
+ lsDevices.repaint();
+ btDefault.setEnabled(false);
+ }
+ };
+
+ ListSelectionListener listSelectionListener = new ListSelectionListener() {
+ public void valueChanged(ListSelectionEvent ev) {
+ DeviceEntry entry = (DeviceEntry) lsDevices.getSelectedValue();
+ if (entry != null) {
+ if (entry.isDefaultDevice()) {
+ btDefault.setEnabled(false);
+ } else {
+ btDefault.setEnabled(true);
+ }
+ if (entry.canRemove()) {
+ btRemove.setEnabled(true);
+ } else {
+ btRemove.setEnabled(false);
+ }
+ btOk.setEnabled(true);
+ } else {
+ btDefault.setEnabled(false);
+ btRemove.setEnabled(false);
+ btOk.setEnabled(false);
+ }
+ }
+ };
+
+ public SwingSelectDevicePanel(EmulatorContext emulatorContext) {
+ this.emulatorContext = emulatorContext;
+
+ setLayout(new BorderLayout());
+ setBorder(new TitledBorder(new EtchedBorder(), "Installed devices"));
+
+ lsDevicesModel = new DefaultListModel();
+ lsDevices = new JList(lsDevicesModel);
+ lsDevices.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+ lsDevices.addListSelectionListener(listSelectionListener);
+ spDevices = new JScrollPane(lsDevices);
+ add(spDevices, BorderLayout.CENTER);
+
+ JPanel panel = new JPanel();
+ btAdd = new JButton("Add...");
+ btAdd.addActionListener(btAddListener);
+ btRemove = new JButton("Remove");
+ btRemove.addActionListener(btRemoveListener);
+ btDefault = new JButton("Set as default");
+ btDefault.addActionListener(btDefaultListener);
+ panel.add(btAdd);
+ panel.add(btRemove);
+ panel.add(btDefault);
+
+ add(panel, BorderLayout.SOUTH);
+
+ for (Enumeration e = Config.getDeviceEntries().elements(); e.hasMoreElements();) {
+ DeviceEntry entry = (DeviceEntry) e.nextElement();
+ lsDevicesModel.addElement(entry);
+ if (entry.isDefaultDevice()) {
+ lsDevices.setSelectedValue(entry, true);
+ }
+ }
+ }
+
+ public DeviceEntry getSelectedDeviceEntry() {
+ return (DeviceEntry) lsDevices.getSelectedValue();
+ }
+
+}
Propchange: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/SwingSelectDevicePanel.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/logconsole/LogTextArea.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/logconsole/LogTextArea.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/logconsole/LogTextArea.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/logconsole/LogTextArea.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.logconsole;
+
+/**
+ * @author Michael Lifshits
+ *
+ */
+import java.awt.Rectangle;
+
+import javax.swing.JTextArea;
+import javax.swing.JViewport;
+
+public class LogTextArea extends JTextArea {
+
+ private static final long serialVersionUID = 1L;
+
+ //private int maxLines = 20;
+
+ private LogTextCaret caret;
+
+ public LogTextArea(int rows, int columns, int maxLines) {
+ super(rows, columns);
+ caret = new LogTextCaret();
+ setCaret(caret);
+ //this.maxLines = maxLines;
+ setEditable(false);
+ }
+
+ public void setText(String t) {
+ super.setText(t);
+ caret.setVisibilityAdjustment(true);
+ }
+
+ public void append(String str) {
+
+ super.append(str);
+
+ JViewport viewport = (JViewport) getParent();
+ boolean scrollToBottom = Math.abs(viewport.getViewPosition().getY() - (getHeight() - viewport.getHeight())) < 100;
+
+ caret.setVisibilityAdjustment(scrollToBottom);
+
+ if (scrollToBottom) {
+ setCaretPosition(getText().length());
+ }
+
+ // if (getLineCount() > maxLines) {
+ // Document doc = getDocument();
+ // if (doc != null) {
+ // try {
+ // doc.remove(0, getLineStartOffset(getLineCount() - maxLines - 1));
+ // } catch (BadLocationException e) {
+ // }
+ // }
+ // if (!scrollToBottom) {
+ // Rectangle nloc = new Rectangle(0,30,10,10);
+ // if (SwingUtilities.isEventDispatchThread()) {
+ // scrollRectToVisible(nloc);
+ // } else {
+ // SwingUtilities.invokeLater(new SafeScroller(nloc));
+ // }
+ // }
+ // }
+ }
+
+ class SafeScroller implements Runnable {
+
+ Rectangle r;
+
+ SafeScroller(Rectangle r) {
+ this.r = r;
+ }
+
+ public void run() {
+ LogTextArea.this.scrollRectToVisible(r);
+ }
+ }
+
+}
\ No newline at end of file
Propchange: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/logconsole/LogTextArea.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/logconsole/LogTextCaret.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/logconsole/LogTextCaret.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/logconsole/LogTextCaret.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/logconsole/LogTextCaret.java Mon May 26 15:20:19 2008
@@ -0,0 +1,46 @@
+/*
+ * 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.logconsole;
+
+import java.awt.Rectangle;
+
+import javax.swing.text.DefaultCaret;
+
+/**
+ * @author Michael Lifshits
+ *
+ */
+public class LogTextCaret extends DefaultCaret{
+
+ private static final long serialVersionUID = 1L;
+
+ private boolean visibilityAdjustmentEnabled = true;
+
+ protected void adjustVisibility(Rectangle nloc) {
+ if (visibilityAdjustmentEnabled) {
+ super.adjustVisibility(nloc);
+ }
+ }
+
+ public void setVisibilityAdjustment(boolean flag) {
+ visibilityAdjustmentEnabled = flag;
+ }
+
+}
Propchange: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/app/ui/swing/logconsole/LogTextCaret.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/applet/CookieRecordStoreManager.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/applet/CookieRecordStoreManager.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/applet/CookieRecordStoreManager.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/applet/CookieRecordStoreManager.java Mon May 26 15:20:19 2008
@@ -0,0 +1,315 @@
+/*
+ * 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.applet;
+
+import java.applet.Applet;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.StringTokenizer;
+
+import javax.microedition.rms.RecordEnumeration;
+import javax.microedition.rms.RecordStore;
+import javax.microedition.rms.RecordStoreException;
+import javax.microedition.rms.RecordStoreNotFoundException;
+import javax.microedition.rms.RecordStoreNotOpenException;
+
+import netscape.javascript.JSObject;
+
+import org.microemu.MicroEmulator;
+import org.microemu.RecordStoreManager;
+import org.microemu.log.Logger;
+import org.microemu.util.Base64Coder;
+import org.microemu.util.ExtendedRecordListener;
+import org.microemu.util.RecordStoreImpl;
+
+public class CookieRecordStoreManager implements RecordStoreManager {
+
+ private static final int MAX_SPLIT_COOKIES = 5; // max 10
+
+ private static final int MAX_COOKIE_SIZE = 4096 * 3 / 4; // Base64
+
+ private ExtendedRecordListener recordListener = null;
+
+ private Applet applet;
+
+ private JSObject document;
+
+ private HashMap cookies;
+
+ private String expires;
+
+ public CookieRecordStoreManager(Applet applet) {
+ this.applet = applet;
+
+ Calendar c = Calendar.getInstance();
+ c.add(java.util.Calendar.YEAR, 1);
+ SimpleDateFormat format = new SimpleDateFormat("EEE, dd-MM-yyyy hh:mm:ss z");
+ this.expires = "; Max-Age=" + (60 * 60 * 24 * 365);
+ System.out.println("CookieRecordStoreManager: " + this.expires);
+ }
+
+ public void init(MicroEmulator emulator) {
+ }
+
+ public String getName() {
+ return this.getClass().toString();
+ }
+
+ public void deleteRecordStore(String recordStoreName) throws RecordStoreNotFoundException, RecordStoreException {
+ CookieContent cookieContent = (CookieContent) cookies.get(recordStoreName);
+ if (cookieContent == null) {
+ throw new RecordStoreNotFoundException(recordStoreName);
+ }
+
+ removeCookie(recordStoreName, cookieContent);
+ cookies.remove(recordStoreName);
+
+ fireRecordStoreListener(ExtendedRecordListener.RECORDSTORE_DELETE, recordStoreName);
+
+ System.out.println("deleteRecordStore: " + recordStoreName);
+ }
+
+ public void deleteStores() {
+ for (Iterator it = cookies.keySet().iterator(); it.hasNext();) {
+ try {
+ deleteRecordStore((String) it.next());
+ } catch (RecordStoreException ex) {
+ Logger.error(ex);
+ }
+ }
+ System.out.println("deleteStores:");
+ }
+
+ public void init() {
+ JSObject window = (JSObject) JSObject.getWindow(applet);
+ document = (JSObject) window.getMember("document");
+ cookies = new HashMap();
+
+ String load = (String) document.getMember("cookie");
+ if (load != null) {
+ StringTokenizer st = new StringTokenizer(load, ";");
+ while (st.hasMoreTokens()) {
+ String token = st.nextToken().trim();
+ int index = token.indexOf("=");
+ if (index != -1) {
+ if (token.charAt(index + 1) == 'a') {
+ String first = token.substring(0, 1);
+ String name = token.substring(1, index).trim();
+ CookieContent content = (CookieContent) cookies.get(name);
+ if (content == null) {
+ content = new CookieContent();
+ cookies.put(name, content);
+ }
+ if (first.equals("x")) {
+ content.setPart(0, token.substring(index + 2));
+ } else {
+ try {
+ content.setPart(Integer.parseInt(first), token.substring(index + 2));
+ } catch (NumberFormatException ex) {
+ }
+ }
+ System.out.println("init: " + token.substring(0, index) + "(" + token.substring(index + 2)
+ + ")");
+ }
+ }
+ }
+ }
+ System.out.println("init: " + cookies.size());
+ }
+
+ public String[] listRecordStores() {
+ System.out.println("listRecordStores:");
+ String[] result = (String[]) cookies.keySet().toArray();
+
+ if (result.length == 0) {
+ result = null;
+ }
+
+ return result;
+ }
+
+ public RecordStore openRecordStore(String recordStoreName, boolean createIfNecessary)
+ throws RecordStoreNotFoundException {
+ RecordStoreImpl result;
+
+ CookieContent load = (CookieContent) cookies.get(recordStoreName);
+ if (load != null) {
+ try {
+ byte[] data = Base64Coder.decode(load.toCharArray());
+ result = new RecordStoreImpl(this, new DataInputStream(new ByteArrayInputStream(data)));
+ } catch (IOException ex) {
+ Logger.error(ex);
+ throw new RecordStoreNotFoundException(ex.getMessage());
+ }
+ System.out.println("openRecordStore: " + recordStoreName + " (" + load.getParts().length + ")");
+ } else {
+ if (!createIfNecessary) {
+ throw new RecordStoreNotFoundException(recordStoreName);
+ }
+ result = new RecordStoreImpl(this, recordStoreName);
+ System.out.println("openRecordStore: " + recordStoreName + " (" + load + ")");
+ }
+ result.setOpen(true);
+ if (recordListener != null) {
+ result.addRecordListener(recordListener);
+ }
+
+ fireRecordStoreListener(ExtendedRecordListener.RECORDSTORE_OPEN, recordStoreName);
+
+ return result;
+ }
+
+ public void saveChanges(RecordStoreImpl recordStoreImpl) throws RecordStoreNotOpenException {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ DataOutputStream dos = new DataOutputStream(baos);
+ try {
+ recordStoreImpl.write(dos);
+ CookieContent cookieContent = new CookieContent(Base64Coder.encode(baos.toByteArray()));
+
+ CookieContent previousCookie = (CookieContent) cookies.get(recordStoreImpl.getName());
+ if (previousCookie != null) {
+ removeCookie(recordStoreImpl.getName(), previousCookie);
+ }
+
+ cookies.put(recordStoreImpl.getName(), cookieContent);
+
+ String[] parts = cookieContent.getParts();
+ if (parts.length == 1) {
+ document.setMember("cookie", "x" + recordStoreImpl.getName() + "=a" + parts[0] + expires);
+ } else {
+ for (int i = 0; i < parts.length; i++) {
+ document.setMember("cookie", i + recordStoreImpl.getName() + "=a" + parts[i] + expires);
+ }
+ }
+
+ System.out.println("saveChanges: " + recordStoreImpl.getName() + " (" + cookieContent.getParts().length
+ + ")");
+ } catch (IOException ex) {
+ Logger.error(ex);
+ }
+ }
+
+ public int getSizeAvailable(RecordStoreImpl recordStoreImpl) {
+ int size = MAX_COOKIE_SIZE * MAX_SPLIT_COOKIES;
+
+ size -= recordStoreImpl.getHeaderSize();
+ try {
+ RecordEnumeration en = recordStoreImpl.enumerateRecords(null, null, false);
+ while (en.hasNextElement()) {
+ size -= en.nextRecord().length + recordStoreImpl.getRecordHeaderSize();
+ }
+ } catch (RecordStoreException ex) {
+ Logger.error(ex);
+ }
+
+ // TODO Auto-generated method stub
+ System.out.println("getSizeAvailable: " + size);
+ return size;
+ }
+
+ private void removeCookie(String recordStoreName, CookieContent cookieContent) {
+ String[] parts = cookieContent.getParts();
+ if (parts.length == 1) {
+ document.setMember("cookie", "x" + recordStoreName + "=r");
+ } else {
+ for (int i = 0; i < parts.length; i++) {
+ document.setMember("cookie", i + recordStoreName + "=r");
+ }
+ }
+ System.out.println("removeCookie: " + recordStoreName);
+ }
+
+ private class CookieContent {
+ private String[] parts;
+
+ public CookieContent() {
+ }
+
+ public CookieContent(char[] buffer) {
+ parts = new String[buffer.length / MAX_COOKIE_SIZE + 1];
+ System.out.println("CookieContent(before): " + parts.length);
+ int index = 0;
+ for (int i = 0; i < parts.length; i++) {
+ int size = MAX_COOKIE_SIZE;
+ if (index + size > buffer.length) {
+ size = buffer.length - index;
+ }
+ System.out.println("CookieContent: " + i + "," + index + "," + size);
+ parts[i] = new String(buffer, index, size);
+ index += size;
+ }
+ }
+
+ public void setPart(int index, String content) {
+ if (parts == null) {
+ parts = new String[index + 1];
+ } else {
+ if (parts.length <= index) {
+ String[] newParts = new String[index + 1];
+ System.arraycopy(parts, 0, newParts, 0, parts.length);
+ parts = newParts;
+ }
+ }
+ System.out.println("setPart: " + index + "," + parts.length);
+
+ parts[index] = content;
+ }
+
+ public String[] getParts() {
+ System.out.println("getParts: " + parts);
+ return parts;
+ }
+
+ public char[] toCharArray() {
+ int size = 0;
+ for (int i = 0; i < parts.length; i++) {
+ size += parts[i].length();
+ }
+
+ char[] result = new char[size];
+
+ int index = 0;
+ for (int i = 0; i < parts.length; i++) {
+ System.out.println("toCharArray: " + i + "," + index + "," + size + "," + parts[i].length());
+ System.arraycopy(parts[i].toCharArray(), 0, result, index, parts[i].length());
+ index += parts[i].length();
+ }
+
+ return result;
+ }
+ }
+
+ public void setRecordListener(ExtendedRecordListener recordListener) {
+ this.recordListener = recordListener;
+ }
+
+ public void fireRecordStoreListener(int type, String recordStoreName) {
+ if (recordListener != null) {
+ recordListener.recordStoreEvent(type, System.currentTimeMillis(), recordStoreName);
+ }
+ }
+}
Propchange: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/applet/CookieRecordStoreManager.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/applet/Main.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/applet/Main.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/applet/Main.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/applet/Main.java Mon May 26 15:20:19 2008
@@ -0,0 +1,329 @@
+/*
+ * 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.applet;
+
+import java.applet.Applet;
+import java.awt.BorderLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Locale;
+import java.util.Vector;
+
+import javax.microedition.lcdui.Image;
+import javax.microedition.midlet.MIDlet;
+import javax.microedition.midlet.MIDletStateChangeException;
+import javax.swing.Timer;
+
+import org.microemu.DisplayComponent;
+import org.microemu.EmulatorContext;
+import org.microemu.MIDletBridge;
+import org.microemu.MIDletContext;
+import org.microemu.MicroEmulator;
+import org.microemu.RecordStoreManager;
+import org.microemu.app.launcher.Launcher;
+import org.microemu.app.ui.swing.SwingDeviceComponent;
+import org.microemu.app.util.MIDletResourceLoader;
+import org.microemu.app.util.MIDletSystemProperties;
+import org.microemu.device.DeviceDisplay;
+import org.microemu.device.DeviceFactory;
+import org.microemu.device.FontManager;
+import org.microemu.device.InputMethod;
+import org.microemu.device.impl.DeviceImpl;
+import org.microemu.device.j2se.J2SEDevice;
+import org.microemu.device.j2se.J2SEDeviceDisplay;
+import org.microemu.device.j2se.J2SEFontManager;
+import org.microemu.device.j2se.J2SEInputMethod;
+import org.microemu.log.Logger;
+import org.microemu.util.JadMidletEntry;
+import org.microemu.util.JadProperties;
+import org.microemu.util.MemoryRecordStoreManager;
+
+public class Main extends Applet implements MicroEmulator {
+
+ private static final long serialVersionUID = 1L;
+
+ private MIDlet midlet = null;
+
+ private RecordStoreManager recordStoreManager;
+
+ private JadProperties manifest = new JadProperties();
+
+ private SwingDeviceComponent devicePanel;
+
+ /**
+ * Host name accessible by MIDlet
+ */
+ private String accessibleHost;
+
+ private 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 getClass().getResourceAsStream(name);
+ }
+ };
+
+ public Main() {
+ devicePanel = new SwingDeviceComponent();
+ devicePanel.addKeyListener(devicePanel);
+ }
+
+ public void init() {
+ if (midlet != null) {
+ return;
+ }
+
+ MIDletSystemProperties.applyToJavaSystemProperties = false;
+ MIDletBridge.setMicroEmulator(this);
+
+ URL baseURL = getCodeBase();
+ if (baseURL != null) {
+ accessibleHost = baseURL.getHost();
+ }
+
+ recordStoreManager = new MemoryRecordStoreManager();
+
+ setLayout(new BorderLayout());
+ add(devicePanel, "Center");
+
+ DeviceImpl device;
+ String deviceParameter = getParameter("device");
+ if (deviceParameter == null) {
+ device = new J2SEDevice();
+ DeviceFactory.setDevice(device);
+ device.init(emulatorContext);
+ } else {
+ try {
+ Class cl = Class.forName(deviceParameter);
+ device = (DeviceImpl) cl.newInstance();
+ DeviceFactory.setDevice(device);
+ device.init(emulatorContext);
+ } catch (ClassNotFoundException ex) {
+ try {
+ device = DeviceImpl.create(emulatorContext, Main.class.getClassLoader(), deviceParameter,
+ J2SEDevice.class);
+ DeviceFactory.setDevice(device);
+ } catch (IOException ex1) {
+ Logger.error(ex);
+ return;
+ }
+ } catch (IllegalAccessException ex) {
+ Logger.error(ex);
+ return;
+ } catch (InstantiationException ex) {
+ Logger.error(ex);
+ return;
+ }
+ }
+
+ devicePanel.init();
+
+ manifest.clear();
+ try {
+ URL url = getClass().getClassLoader().getResource("META-INF/MANIFEST.MF");
+ manifest.load(url.openStream());
+ if (manifest.getProperty("MIDlet-Name") == null) {
+ manifest.clear();
+ }
+ } catch (IOException e) {
+ Logger.error(e);
+ }
+
+ // load jad
+ String midletClassName = null;
+ String jadFile = getParameter("jad");
+ if (jadFile != null) {
+ InputStream jadInputStream = null;
+ try {
+ URL jad = new URL(getCodeBase(), jadFile);
+ jadInputStream = jad.openStream();
+ manifest.load(jadInputStream);
+ Vector entries = manifest.getMidletEntries();
+ // only load the first (no midlet suite support anyway)
+ if (entries.size() > 0) {
+ JadMidletEntry entry = (JadMidletEntry) entries.elementAt(0);
+ midletClassName = entry.getClassName();
+ }
+ } catch (IOException e) {
+ } finally {
+ if (jadInputStream != null) {
+ try {
+ jadInputStream.close();
+ } catch (IOException e1) {
+ }
+ }
+ }
+ }
+
+ if (midletClassName == null) {
+ midletClassName = getParameter("midlet");
+ if (midletClassName == null) {
+ Logger.debug("There is no midlet parameter");
+ return;
+ }
+ }
+
+ // Applet is using only one classLoader
+ MIDletResourceLoader.classLoader = this.getClass().getClassLoader();
+ Class midletClass;
+ try {
+ midletClass = Class.forName(midletClassName);
+ } catch (ClassNotFoundException ex) {
+ Logger.error("Cannot find " + midletClassName + " MIDlet class");
+ return;
+ }
+
+ try {
+ midlet = (MIDlet) midletClass.newInstance();
+ } catch (Exception ex) {
+ Logger.error("Cannot initialize " + midletClass + " MIDlet class", ex);
+ return;
+ }
+
+ Image tmpImg = DeviceFactory.getDevice().getNormalImage();
+ resize(tmpImg.getWidth(), tmpImg.getHeight());
+
+ return;
+ }
+
+ public void start() {
+ devicePanel.requestFocus();
+
+ new Thread("midlet_starter") {
+ public void run() {
+ try {
+ MIDletBridge.getMIDletAccess(midlet).startApp();
+ } catch (MIDletStateChangeException ex) {
+ System.err.println(ex);
+ }
+ }
+ }.start();
+
+ Timer timer = new Timer(1000, new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ devicePanel.requestFocus();
+ }
+ });
+ timer.setRepeats(false);
+ timer.start();
+ }
+
+ public void stop() {
+ MIDletBridge.getMIDletAccess(midlet).pauseApp();
+ }
+
+ public void destroy() {
+ try {
+ MIDletBridge.getMIDletAccess(midlet).destroyApp(true);
+ } catch (MIDletStateChangeException ex) {
+ System.err.println(ex);
+ }
+ }
+
+ public RecordStoreManager getRecordStoreManager() {
+ return recordStoreManager;
+ }
+
+ public String getAppProperty(String key) {
+ if (key.equals("applet")) {
+ return "yes";
+ }
+
+ String value = null;
+ if (key.equals("microedition.platform")) {
+ value = "MicroEmulator";
+ } else if (key.equals("microedition.profiles")) {
+ value = "MIDP-2.0";
+ } else if (key.equals("microedition.configuration")) {
+ value = "CLDC-1.0";
+ } else if (key.equals("microedition.locale")) {
+ value = Locale.getDefault().getLanguage();
+ } else if (key.equals("microedition.encoding")) {
+ value = System.getProperty("file.encoding");
+ } else if (key.equals("microemu.applet")) {
+ value = "true";
+ } else if (key.equals("microemu.accessible.host")) {
+ value = accessibleHost;
+ } else if (getParameter(key) != null) {
+ value = getParameter(key);
+ } else {
+ value = manifest.getProperty(key);
+ }
+
+ return value;
+ }
+
+ public InputStream getResourceAsStream(String name) {
+ return emulatorContext.getResourceAsStream(name);
+ }
+
+ public boolean platformRequest(String url) {
+ try {
+ getAppletContext().showDocument(new URL(url), "mini");
+ } catch (Exception e) {
+ }
+ return false;
+ }
+
+ public void notifyDestroyed(MIDletContext midletContext) {
+ }
+
+ public void destroyMIDletContext(MIDletContext midletContext) {
+
+ }
+
+ public Launcher getLauncher() {
+ return null;
+ }
+
+ public String getAppletInfo() {
+ return "Title: MicroEmulator \nAuthor: Bartek Teodorczyk, 2001";
+ }
+
+ public String[][] getParameterInfo() {
+ String[][] info = { { "midlet", "MIDlet class name", "The MIDlet class name. This field is mandatory." }, };
+
+ return info;
+ }
+
+}
Propchange: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/applet/Main.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/BWImageFilter.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/BWImageFilter.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/BWImageFilter.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/BWImageFilter.java Mon May 26 15:20:19 2008
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.microemu.device.j2se;
+
+import java.awt.image.RGBImageFilter;
+
+import org.microemu.device.DeviceFactory;
+
+
+
+public class BWImageFilter extends RGBImageFilter
+{
+
+ private double Yr, Yg, Yb;
+
+
+ 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;
+ canFilterIndexColorModel = true;
+ }
+
+
+ public int filterRGB (int x, int y, int rgb)
+ {
+ int a = (rgb & 0xFF000000);
+ int r = (rgb & 0x00FF0000) >>> 16;
+ int g = (rgb & 0x0000FF00) >>> 8;
+ int b = (rgb & 0x000000FF);
+ int Y = (int)(Yr * r + Yg * g + Yb * b);
+ if (Y > 127) {
+ return a |
+ ((J2SEDeviceDisplay) DeviceFactory.getDevice().getDeviceDisplay()).getBackgroundColor().getRGB();
+ } else {
+ return a |
+ ((J2SEDeviceDisplay) DeviceFactory.getDevice().getDeviceDisplay()).getForegroundColor().getRGB();
+ }
+ }
+
+}
+
Propchange: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/BWImageFilter.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/GrayImageFilter.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/GrayImageFilter.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/GrayImageFilter.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/GrayImageFilter.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.j2se;
+
+import java.awt.image.RGBImageFilter;
+
+import org.microemu.device.DeviceFactory;
+import org.microemu.device.impl.Color;
+
+
+
+public class GrayImageFilter extends RGBImageFilter
+{
+
+ private double Yr, Yg, Yb;
+ private double Rr, Rg, Rb;
+
+
+ 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;
+ canFilterIndexColorModel = true;
+ Color backgroundColor =
+ ((J2SEDeviceDisplay) DeviceFactory.getDevice().getDeviceDisplay()).getBackgroundColor();
+ Color foregroundColor =
+ ((J2SEDeviceDisplay) DeviceFactory.getDevice().getDeviceDisplay()).getForegroundColor();
+ Rr = (backgroundColor.getRed() - foregroundColor.getRed()) / 256d;
+ Rg = (backgroundColor.getGreen() - foregroundColor.getGreen()) / 256d;
+ Rb = (backgroundColor.getBlue() - foregroundColor.getBlue()) / 256d;
+ }
+
+
+ public int filterRGB (int x, int y, int rgb)
+ {
+ int a = (rgb & 0xFF000000);
+ int r = (rgb & 0x00FF0000) >>> 16;
+ int g = (rgb & 0x0000FF00) >>> 8;
+ int b = (rgb & 0x000000FF);
+ int Y = (int)(Yr * r + Yg * g + Yb * b) % 256;
+ if (Y > 255) {
+ Y = 255;
+ }
+ Color foregroundColor =
+ ((J2SEDeviceDisplay) DeviceFactory.getDevice().getDeviceDisplay()).getForegroundColor();
+ r = (int) (Rr * Y) + foregroundColor.getRed();
+ g = (int) (Rg * Y) + foregroundColor.getGreen();
+ b = (int) (Rb * Y) + foregroundColor.getBlue();
+
+ return a | (r << 16) | (g << 8) | b;
+ }
+
+}
Propchange: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/GrayImageFilter.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEButton.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEButton.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEButton.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEButton.java Mon May 26 15:20:19 2008
@@ -0,0 +1,225 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.microemu.device.j2se;
+
+import java.awt.event.KeyEvent;
+import java.util.Hashtable;
+import java.util.StringTokenizer;
+
+import org.microemu.device.InputMethod;
+import org.microemu.device.impl.Button;
+import org.microemu.device.impl.ButtonDetaultDeviceKeyCodes;
+import org.microemu.device.impl.ButtonName;
+import org.microemu.device.impl.Shape;
+
+public class J2SEButton implements Button {
+
+ private String name;
+
+ private ButtonName functionalName;
+
+ private Shape shape;
+
+ private int[] keyboardKeys;
+
+ private String keyboardCharCodes;
+
+ private int keyCode;
+
+ private Hashtable inputToChars;
+
+ private boolean modeChange;
+
+ /**
+ * Create special functional buttons. e.g. ButtonName.DELETE and
+ * ButtonName.BACK_SPACE if not defined in 'device.xml'
+ *
+ * @param name
+ */
+ J2SEButton(ButtonName functionalName) {
+ this(20002, functionalName.getName(), null, Integer.MIN_VALUE, null, null, null, false);
+ }
+
+ /**
+ * @param name
+ * @param shape
+ * @param keyCode -
+ * Integer.MIN_VALUE when unspecified
+ * @param keyName
+ * @param chars
+ */
+ public J2SEButton(int skinVersion, String name, Shape shape, int keyCode, String keyboardKeys,
+ String keyboardChars, Hashtable inputToChars, boolean modeChange) {
+ this.name = name;
+ this.shape = shape;
+ if (skinVersion >= NAME_RIMARY_SINCE_SKIN_VERSION) {
+ this.functionalName = ButtonName.getButtonName(name);
+ } else {
+ this.functionalName = J2SEButtonDefaultKeyCodes.getBackwardCompatibleName(parseKeyboardKey(keyboardKeys));
+ if (this.functionalName == null) {
+ this.functionalName = ButtonName.getButtonName(name);
+ }
+ }
+
+ if (skinVersion >= NAME_RIMARY_SINCE_SKIN_VERSION) {
+ this.modeChange = modeChange;
+ } else {
+ this.modeChange = (functionalName == ButtonName.KEY_POUND);
+ }
+
+ if (keyCode == Integer.MIN_VALUE) {
+ this.keyCode = ButtonDetaultDeviceKeyCodes.getKeyCode(this.functionalName);
+ } else {
+ this.keyCode = keyCode;
+ }
+
+ if (keyboardKeys != null) {
+ StringTokenizer st = new StringTokenizer(keyboardKeys, " ");
+ while (st.hasMoreTokens()) {
+ int key = parseKeyboardKey(st.nextToken());
+ if (key == -1) {
+ continue;
+ }
+ if (this.keyboardKeys == null) {
+ this.keyboardKeys = new int[1];
+ } else {
+ int[] newKeyboardKeys = new int[this.keyboardKeys.length + 1];
+ System.arraycopy(keyboardKeys, 0, newKeyboardKeys, 0, this.keyboardKeys.length);
+ this.keyboardKeys = newKeyboardKeys;
+ }
+ this.keyboardKeys[this.keyboardKeys.length - 1] = key;
+ }
+ }
+ if ((this.keyboardKeys == null) || (this.keyboardKeys.length == 0)) {
+ this.keyboardKeys = J2SEButtonDefaultKeyCodes.getKeyCodes(this.functionalName);
+ }
+ if (keyboardChars != null) {
+ this.keyboardCharCodes = keyboardChars;
+ } else {
+ this.keyboardCharCodes = J2SEButtonDefaultKeyCodes.getCharCodes(this.functionalName);
+ }
+
+ this.inputToChars = inputToChars;
+ }
+
+ /**
+ * @deprecated
+ */
+ public int getKeyboardKey() {
+ if (keyboardKeys.length == 0) {
+ return 0;
+ }
+ return keyboardKeys[0];
+ }
+
+ public int getKeyCode() {
+ return keyCode;
+ }
+
+ public ButtonName getFunctionalName() {
+ return functionalName;
+ }
+
+ public int[] getKeyboardKeyCodes() {
+ return keyboardKeys;
+ }
+
+ /**
+ * CharCodes do not depends on InputMode. This is computer keyboard codes
+ * when it is impossible to map to VK keys.
+ */
+ public char[] getKeyboardCharCodes() {
+ if (keyboardCharCodes == null) {
+ return new char[0];
+ }
+ return keyboardCharCodes.toCharArray();
+ }
+
+ public boolean isModeChange() {
+ return modeChange;
+ }
+
+ void setModeChange() {
+ modeChange = true;
+ }
+
+ 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) {
+ if (inputToChars == null) {
+ return false;
+ }
+ 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 static int parseKeyboardKey(String keyName) {
+ int key;
+ try {
+ key = KeyEvent.class.getField(keyName).getInt(null);
+ } catch (Exception e) {
+ try {
+ key = Integer.parseInt(keyName);
+ } catch (NumberFormatException e1) {
+ key = -1;
+ }
+ }
+ return key;
+ }
+
+}
Propchange: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEButton.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEButtonDefaultKeyCodes.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEButtonDefaultKeyCodes.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEButtonDefaultKeyCodes.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEButtonDefaultKeyCodes.java Mon May 26 15:20:19 2008
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.microemu.device.j2se;
+
+import java.awt.event.KeyEvent;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.microemu.device.impl.ButtonName;
+
+/**
+ * This class defines default computer keyboard key and char codes for buttons.
+ *
+ * Use 'device.xml' to redefine codes for your device if required.
+ *
+ * CharCodes do not depends on InputMode. This is computer keyboard codes when
+ * it is impossible to map to VK keys.
+ *
+ * @author vlads
+ *
+ */
+public class J2SEButtonDefaultKeyCodes {
+
+ private static Map codes = new HashMap();
+
+ private static Map backwardCompatibleNames = new HashMap();
+
+ private static class KeyInformation {
+
+ int[] keyCodes;
+
+ String charCodes = "";
+
+ }
+
+ public static int[] getKeyCodes(ButtonName name) {
+ KeyInformation info = (KeyInformation) codes.get(name);
+ if (info == null) {
+ return new int[0];
+ }
+ return info.keyCodes;
+ }
+
+ public static String getCharCodes(ButtonName name) {
+ KeyInformation info = (KeyInformation) codes.get(name);
+ if (info == null) {
+ return "";
+ }
+ return info.charCodes;
+ }
+
+ static {
+ code(ButtonName.SOFT1, KeyEvent.VK_F1);
+ code(ButtonName.SOFT2, KeyEvent.VK_F2);
+ code(ButtonName.SELECT, KeyEvent.VK_ENTER);
+ code(ButtonName.UP, KeyEvent.VK_UP, KeyEvent.VK_KP_UP);
+ code(ButtonName.DOWN, KeyEvent.VK_DOWN, KeyEvent.VK_KP_DOWN);
+ code(ButtonName.LEFT, KeyEvent.VK_LEFT, KeyEvent.VK_KP_LEFT);
+ code(ButtonName.RIGHT, KeyEvent.VK_RIGHT, KeyEvent.VK_KP_RIGHT);
+
+ // code(ButtonName.BACK, KeyEvent.VK_HOME);
+ code(ButtonName.BACK_SPACE, KeyEvent.VK_BACK_SPACE);
+ code(ButtonName.DELETE, KeyEvent.VK_CLEAR, KeyEvent.VK_DELETE);
+
+ code(ButtonName.KEY_NUM0, KeyEvent.VK_0, KeyEvent.VK_NUMPAD0).charCodes = "0";
+ code(ButtonName.KEY_NUM1, KeyEvent.VK_1, KeyEvent.VK_NUMPAD1).charCodes = "1";
+ code(ButtonName.KEY_NUM2, KeyEvent.VK_2, KeyEvent.VK_NUMPAD2).charCodes = "2";
+ code(ButtonName.KEY_NUM3, KeyEvent.VK_3, KeyEvent.VK_NUMPAD3).charCodes = "3";
+ code(ButtonName.KEY_NUM4, KeyEvent.VK_4, KeyEvent.VK_NUMPAD4).charCodes = "4";
+ code(ButtonName.KEY_NUM5, KeyEvent.VK_5, KeyEvent.VK_NUMPAD5).charCodes = "5";
+ code(ButtonName.KEY_NUM6, KeyEvent.VK_6, KeyEvent.VK_NUMPAD6).charCodes = "6";
+ code(ButtonName.KEY_NUM7, KeyEvent.VK_7, KeyEvent.VK_NUMPAD7).charCodes = "7";
+ code(ButtonName.KEY_NUM8, KeyEvent.VK_8, KeyEvent.VK_NUMPAD8).charCodes = "8";
+ code(ButtonName.KEY_NUM9, KeyEvent.VK_9, KeyEvent.VK_NUMPAD9).charCodes = "9";
+ code(ButtonName.KEY_STAR, KeyEvent.VK_MULTIPLY, KeyEvent.VK_ASTERISK).charCodes = "*";
+ code(ButtonName.KEY_POUND, KeyEvent.VK_MODECHANGE, KeyEvent.VK_SUBTRACT).charCodes = "#";
+ }
+
+ private static KeyInformation code(ButtonName name, int code) {
+ KeyInformation info = new KeyInformation();
+ info.keyCodes = new int[] { code };
+ codes.put(name, info);
+ backwardCompatibleNames.put(new Integer(code), name);
+ return info;
+ }
+
+ private static KeyInformation code(ButtonName name, int code1, int code2) {
+ KeyInformation info = new KeyInformation();
+ info.keyCodes = new int[] { code1, code2 };
+ codes.put(name, info);
+ backwardCompatibleNames.put(new Integer(code1), name);
+ return info;
+ }
+
+ public static ButtonName getBackwardCompatibleName(int keyboardKey) {
+ return (ButtonName) backwardCompatibleNames.get(new Integer(keyboardKey));
+ }
+}
Propchange: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEButtonDefaultKeyCodes.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEDevice.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEDevice.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEDevice.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEDevice.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.j2se;
+
+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.j2se.ui.J2SECanvasUI;
+import org.microemu.device.j2se.ui.J2SEListUI;
+import org.microemu.device.j2se.ui.J2SETextBoxUI;
+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 J2SEDevice extends DeviceImpl {
+
+ private UIFactory ui = new UIFactory() {
+
+ public DisplayableUI createAlertUI(Alert alert) {
+ // TODO Not yet implemented
+ return new J2SECanvasUI(null);
+ }
+
+ public CanvasUI createCanvasUI(Canvas canvas) {
+ return new J2SECanvasUI(canvas);
+ }
+
+ public DisplayableUI createFormUI(Form form) {
+ // TODO Not yet implemented
+ return new J2SECanvasUI(null);
+ }
+
+ public ListUI createListUI(List list) {
+ return new J2SEListUI(list);
+ }
+
+ public TextBoxUI createTextBoxUI(TextBox textBox) {
+ return new J2SETextBoxUI(textBox);
+ }
+
+ };
+
+ public UIFactory getUIFactory() {
+ return ui;
+ }
+
+}
Propchange: harmony/enhanced/microemulator/microemu-javase-swing/src/main/java/org/microemu/device/j2se/J2SEDevice.java
------------------------------------------------------------------------------
svn:eol-style = native