/*      */ 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.Point;
/*      */ 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.KeyListener;
/*      */ import java.awt.event.MouseEvent;
/*      */ import java.awt.event.MouseListener;
/*      */ import java.awt.event.MouseMotionListener;
/*      */ import java.awt.event.MouseWheelEvent;
/*      */ import java.awt.event.MouseWheelListener;
/*      */ 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.ImageIcon;
/*      */ 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.TransferHandler;
/*      */ import javax.swing.UIManager;
/*      */ import javax.swing.filechooser.FileFilter;
/*      */ 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.MessageListener;
/*      */ 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.MIDletUrlPanel;
/*      */ 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.SwingDialogPanel;
/*      */ 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.MRUListListener;
/*      */ import org.microemu.app.util.MidletURLReference;
/*      */ import org.microemu.cldc.http.Connection;
/*      */ 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.LoggerAppender;
/*      */ import org.microemu.log.QueueAppender;
/*      */ import org.microemu.util.JadMidletEntry;
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ public class Main
/*      */   extends JFrame
/*      */ {
/*      */   private static final long serialVersionUID = 1L;
/*      */   protected Common common;
/*  127 */   protected SwingSelectDevicePanel selectDevicePanel = null;
/*      */   
/*  129 */   private MIDletUrlPanel midletUrlPanel = null;
/*      */   
/*      */   private JFileChooser saveForWebChooser;
/*      */   
/*  133 */   private JFileChooser fileChooser = null;
/*      */   
/*  135 */   private JFileChooser captureFileChooser = null;
/*      */   
/*      */   private JMenuItem menuOpenMIDletFile;
/*      */   
/*      */   private JMenuItem menuOpenMIDletURL;
/*      */   
/*      */   private JMenuItem menuSelectDevice;
/*      */   
/*      */   private JMenuItem menuSaveForWeb;
/*      */   
/*      */   private JMenuItem menuStartCapture;
/*      */   
/*      */   private JMenuItem menuStopCapture;
/*      */   
/*      */   private JCheckBoxMenuItem menuMIDletNetworkConnection;
/*      */   
/*      */   private JCheckBoxMenuItem menuLogConsole;
/*      */   
/*      */   private JCheckBoxMenuItem menuRecordStoreManager;
/*      */   
/*      */   private JFrame scaledDisplayFrame;
/*      */   
/*      */   private JCheckBoxMenuItem[] zoomLevels;
/*      */   
/*      */   private SwingDeviceComponent devicePanel;
/*      */   
/*      */   private SwingLogConsoleDialog logConsoleDialog;
/*      */   
/*      */   private RecordStoreManagerDialog recordStoreManagerDialog;
/*      */   
/*      */   private QueueAppender logQueueAppender;
/*      */   
/*      */   private DeviceEntry deviceEntry;
/*      */   
/*      */   private AnimatedGifEncoder encoder;
/*      */   
/*  171 */   private JLabel statusBar = new JLabel("Status");
/*      */   
/*  173 */   private JButton resizeButton = new JButton("Resize");
/*      */   
/*  175 */   private ResizeDeviceDisplayDialog resizeDeviceDisplayDialog = null;
/*      */   
/*  177 */   protected EmulatorContext emulatorContext = new EmulatorContext()
/*      */     {
/*  179 */       private InputMethod inputMethod = (InputMethod)new J2SEInputMethod();
/*      */       
/*  181 */       private DeviceDisplay deviceDisplay = (DeviceDisplay)new J2SEDeviceDisplay(this);
/*      */       
/*  183 */       private FontManager fontManager = (FontManager)new J2SEFontManager(); private final Main this$0;
/*      */       
/*      */       public DisplayComponent getDisplayComponent() {
/*  186 */         return Main.this.devicePanel.getDisplayComponent();
/*      */       }
/*      */       
/*      */       public InputMethod getDeviceInputMethod() {
/*  190 */         return this.inputMethod;
/*      */       }
/*      */       
/*      */       public DeviceDisplay getDeviceDisplay() {
/*  194 */         return this.deviceDisplay;
/*      */       }
/*      */       
/*      */       public FontManager getDeviceFontManager() {
/*  198 */         return this.fontManager;
/*      */       }
/*      */       
/*      */       public InputStream getResourceAsStream(String name) {
/*  202 */         return MIDletBridge.getCurrentMIDlet().getClass().getResourceAsStream(name);
/*      */       }
/*      */       
/*      */       public boolean platformRequest(final String URL) {
/*  206 */         (new Thread(new Runnable() { private final String val$URL;
/*      */               public void run() {
/*  208 */                 Message.info("MIDlet requests that the device handle the following URL: " + URL);
/*      */               }
/*      */               private final Main.null this$1; }
/*      */           )).start();
/*  212 */         return false;
/*      */       }
/*      */     };
/*      */   
/*  216 */   private ActionListener menuOpenMIDletFileListener = new ActionListener() { private final Main this$0;
/*      */       public void actionPerformed(ActionEvent ev) {
/*  218 */         if (Main.this.fileChooser == null) {
/*  219 */           ExtensionFileFilter fileFilter = new ExtensionFileFilter("MIDlet files");
/*  220 */           fileFilter.addExtension("jad");
/*  221 */           fileFilter.addExtension("jar");
/*  222 */           Main.this.fileChooser = new JFileChooser();
/*  223 */           Main.this.fileChooser.setFileFilter((FileFilter)fileFilter);
/*  224 */           Main.this.fileChooser.setDialogTitle("Open MIDlet File...");
/*  225 */           Main.this.fileChooser.setCurrentDirectory(new File(Config.getRecentDirectory("recentJadDirectory")));
/*      */         } 
/*      */         
/*  228 */         int returnVal = Main.this.fileChooser.showOpenDialog(Main.this);
/*  229 */         if (returnVal == 0) {
/*  230 */           Config.setRecentDirectory("recentJadDirectory", Main.this.fileChooser.getCurrentDirectory().getAbsolutePath());
/*  231 */           String url = IOUtils.getCanonicalFileURL(Main.this.fileChooser.getSelectedFile());
/*  232 */           Common.openMIDletUrlSafe(url);
/*  233 */           if (Main.this.recordStoreManagerDialog != null) {
/*  234 */             Main.this.recordStoreManagerDialog.refresh();
/*      */           }
/*      */         } 
/*      */       } }
/*      */   ;
/*      */   
/*  240 */   private ActionListener menuOpenMIDletURLListener = new ActionListener() { private final Main this$0;
/*      */       public void actionPerformed(ActionEvent ev) {
/*  242 */         if (Main.this.midletUrlPanel == null) {
/*  243 */           Main.this.midletUrlPanel = new MIDletUrlPanel();
/*      */         }
/*  245 */         if (SwingDialogWindow.show(Main.this, "Enter MIDlet URL:", (SwingDialogPanel)Main.this.midletUrlPanel, true)) {
/*  246 */           Common.openMIDletUrlSafe(Main.this.midletUrlPanel.getText());
/*  247 */           if (Main.this.recordStoreManagerDialog != null) {
/*  248 */             Main.this.recordStoreManagerDialog.refresh();
/*      */           }
/*      */         } 
/*      */       } }
/*      */   ;
/*      */   
/*  254 */   private ActionListener menuCloseMidletListener = new ActionListener() { private final Main this$0;
/*      */       public void actionPerformed(ActionEvent e) {
/*  256 */         Main.this.common.startLauncher(MIDletBridge.getMIDletContext());
/*      */       } }
/*      */   ;
/*      */   
/*  260 */   private ActionListener menuSaveForWebListener = new ActionListener() { private final Main this$0;
/*      */       public void actionPerformed(ActionEvent e) {
/*  262 */         if (Main.this.saveForWebChooser == null) {
/*  263 */           ExtensionFileFilter fileFilter = new ExtensionFileFilter("HTML files");
/*  264 */           fileFilter.addExtension("html");
/*  265 */           Main.this.saveForWebChooser = new JFileChooser();
/*  266 */           Main.this.saveForWebChooser.setFileFilter((FileFilter)fileFilter);
/*  267 */           Main.this.saveForWebChooser.setDialogTitle("Save for Web...");
/*  268 */           Main.this.saveForWebChooser.setCurrentDirectory(new File(Config.getRecentDirectory("recentSaveForWebDirectory")));
/*      */         } 
/*  270 */         if (Main.this.saveForWebChooser.showSaveDialog(Main.this) == 0) {
/*  271 */           JadMidletEntry jadMidletEntry; Config.setRecentDirectory("recentSaveForWebDirectory", Main.this.saveForWebChooser.getCurrentDirectory().getAbsolutePath());
/*      */           
/*  273 */           File pathFile = Main.this.saveForWebChooser.getSelectedFile().getParentFile();
/*      */           
/*  275 */           String name = Main.this.saveForWebChooser.getSelectedFile().getName();
/*  276 */           if (!name.toLowerCase().endsWith(".html") && name.indexOf('.') == -1) {
/*  277 */             name = name + ".html";
/*      */           }
/*      */ 
/*      */           
/*  281 */           String resource = MIDletClassLoader.getClassResourceName(getClass().getName());
/*  282 */           URL url = getClass().getClassLoader().getResource(resource);
/*  283 */           String path = url.getPath();
/*  284 */           int prefix = path.indexOf(':');
/*  285 */           String mainJarFileName = path.substring(prefix + 1, path.length() - resource.length());
/*  286 */           File appletJarDir = new File((new File(mainJarFileName)).getParent(), "lib");
/*  287 */           File appletJarFile = new File(appletJarDir, "microemu-javase-applet.jar");
/*  288 */           if (!appletJarFile.exists()) {
/*  289 */             appletJarFile = null;
/*      */           }
/*      */           
/*  292 */           if (appletJarFile == null);
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */           
/*  302 */           if (appletJarFile == null) {
/*  303 */             ExtensionFileFilter fileFilter = new ExtensionFileFilter("JAR packages");
/*  304 */             fileFilter.addExtension("jar");
/*  305 */             JFileChooser appletChooser = new JFileChooser();
/*  306 */             appletChooser.setFileFilter((FileFilter)fileFilter);
/*  307 */             appletChooser.setDialogTitle("Select MicroEmulator applet jar package...");
/*  308 */             appletChooser.setCurrentDirectory(new File(Config.getRecentDirectory("recentAppletJarDirectory")));
/*  309 */             if (appletChooser.showOpenDialog(Main.this) == 0) {
/*  310 */               Config.setRecentDirectory("recentAppletJarDirectory", appletChooser.getCurrentDirectory().getAbsolutePath());
/*      */               
/*  312 */               appletJarFile = appletChooser.getSelectedFile();
/*      */             } else {
/*      */               return;
/*      */             } 
/*      */           } 
/*      */ 
/*      */           
/*  319 */           Iterator it = Main.this.common.jad.getMidletEntries().iterator();
/*  320 */           if (it.hasNext()) {
/*  321 */             jadMidletEntry = it.next();
/*      */           } else {
/*  323 */             Message.error("MIDlet Suite has no entries");
/*      */             
/*      */             return;
/*      */           } 
/*  327 */           String midletInput = Main.this.common.jad.getJarURL();
/*  328 */           DeviceEntry deviceInput = Main.this.selectDevicePanel.getSelectedDeviceEntry();
/*  329 */           if (deviceInput != null && deviceInput.getDescriptorLocation().equals("org/microemu/device/default/device.xml")) {
/*  330 */             deviceInput = null;
/*      */           }
/*      */           
/*  333 */           File htmlOutputFile = new File(pathFile, name);
/*  334 */           if (!allowOverride(htmlOutputFile)) {
/*      */             return;
/*      */           }
/*  337 */           File appletPackageOutputFile = new File(pathFile, "microemu-javase-applet.jar");
/*  338 */           if (!allowOverride(appletPackageOutputFile)) {
/*      */             return;
/*      */           }
/*  341 */           File midletOutputFile = new File(pathFile, midletInput.substring(midletInput.lastIndexOf("/") + 1));
/*  342 */           if (!allowOverride(midletOutputFile)) {
/*      */             return;
/*      */           }
/*  345 */           File deviceOutputFile = null;
/*  346 */           if (deviceInput != null && deviceInput.getFileName() != null) {
/*  347 */             deviceOutputFile = new File(pathFile, deviceInput.getFileName());
/*  348 */             if (!allowOverride(deviceOutputFile)) {
/*      */               return;
/*      */             }
/*      */           } 
/*      */           
/*      */           try {
/*  354 */             AppletProducer.createHtml(htmlOutputFile, (DeviceImpl)DeviceFactory.getDevice(), jadMidletEntry.getClassName(), midletOutputFile, appletPackageOutputFile, deviceOutputFile);
/*      */             
/*  356 */             AppletProducer.createMidlet(new URL(midletInput), midletOutputFile);
/*  357 */             IOUtils.copyFile(appletJarFile, appletPackageOutputFile);
/*  358 */             if (deviceInput != null && deviceInput.getFileName() != null) {
/*  359 */               IOUtils.copyFile(new File(Config.getConfigPath(), deviceInput.getFileName()), deviceOutputFile);
/*      */             }
/*  361 */           } catch (IOException ex) {
/*  362 */             Logger.error(ex);
/*      */           } 
/*      */         } 
/*      */       }
/*      */       
/*      */       private boolean allowOverride(File file) {
/*  368 */         if (file.exists()) {
/*  369 */           int answer = JOptionPane.showConfirmDialog(Main.this, "Override the file:" + file + "?", "Question?", 0, 3);
/*      */           
/*  371 */           if (answer == 1) {
/*  372 */             return false;
/*      */           }
/*      */         } 
/*      */         
/*  376 */         return true;
/*      */       } }
/*      */   ;
/*      */   
/*  380 */   private ActionListener menuStartCaptureListener = new ActionListener() { private final Main this$0;
/*      */       public void actionPerformed(ActionEvent e) {
/*  382 */         if (Main.this.captureFileChooser == null) {
/*  383 */           ExtensionFileFilter fileFilter = new ExtensionFileFilter("GIF files");
/*  384 */           fileFilter.addExtension("gif");
/*  385 */           Main.this.captureFileChooser = new JFileChooser();
/*  386 */           Main.this.captureFileChooser.setFileFilter((FileFilter)fileFilter);
/*  387 */           Main.this.captureFileChooser.setDialogTitle("Capture to GIF File...");
/*  388 */           Main.this.captureFileChooser.setCurrentDirectory(new File(Config.getRecentDirectory("recentCaptureDirectory")));
/*      */         } 
/*      */         
/*  391 */         if (Main.this.captureFileChooser.showSaveDialog(Main.this) == 0) {
/*  392 */           Config.setRecentDirectory("recentCaptureDirectory", Main.this.captureFileChooser.getCurrentDirectory().getAbsolutePath());
/*      */           
/*  394 */           String name = Main.this.captureFileChooser.getSelectedFile().getName();
/*  395 */           if (!name.toLowerCase().endsWith(".gif") && name.indexOf('.') == -1) {
/*  396 */             name = name + ".gif";
/*      */           }
/*  398 */           File captureFile = new File(Main.this.captureFileChooser.getSelectedFile().getParentFile(), name);
/*  399 */           if (!allowOverride(captureFile)) {
/*      */             return;
/*      */           }
/*      */           
/*  403 */           Main.this.encoder = new AnimatedGifEncoder();
/*  404 */           Main.this.encoder.start(captureFile.getAbsolutePath());
/*      */           
/*  406 */           Main.this.menuStartCapture.setEnabled(false);
/*  407 */           Main.this.menuStopCapture.setEnabled(true);
/*      */           
/*  409 */           Main.this.emulatorContext.getDisplayComponent().addDisplayRepaintListener(new DisplayRepaintListener() {
/*  410 */                 long start = 0L; private final Main.null this$1;
/*      */                 
/*      */                 public void repaintInvoked(MutableImage image) {
/*  413 */                   synchronized (Main.null.access$900(Main.null.this)) {
/*  414 */                     if ((Main.null.access$900(Main.null.this)).encoder != null) {
/*  415 */                       if (this.start == 0L) {
/*  416 */                         this.start = System.currentTimeMillis();
/*      */                       } else {
/*  418 */                         long current = System.currentTimeMillis();
/*  419 */                         (Main.null.access$900(Main.null.this)).encoder.setDelay((int)(current - this.start));
/*  420 */                         this.start = current;
/*      */                       } 
/*      */                       
/*  423 */                       (Main.null.access$900(Main.null.this)).encoder.addFrame((BufferedImage)((J2SEMutableImage)image).getImage());
/*      */                     } 
/*      */                   } 
/*      */                 }
/*      */               });
/*      */         } 
/*      */       }
/*      */       
/*      */       private boolean allowOverride(File file) {
/*  432 */         if (file.exists()) {
/*  433 */           int answer = JOptionPane.showConfirmDialog(Main.this, "Override the file:" + file + "?", "Question?", 0, 3);
/*      */           
/*  435 */           if (answer == 1) {
/*  436 */             return false;
/*      */           }
/*      */         } 
/*      */         
/*  440 */         return true;
/*      */       } }
/*      */   ;
/*      */   
/*  444 */   private ActionListener menuStopCaptureListener = new ActionListener() { private final Main this$0;
/*      */       public void actionPerformed(ActionEvent e) {
/*  446 */         Main.this.menuStopCapture.setEnabled(false);
/*      */         
/*  448 */         synchronized (Main.this) {
/*  449 */           Main.this.encoder.finish();
/*  450 */           Main.this.encoder = null;
/*      */         } 
/*      */         
/*  453 */         Main.this.menuStartCapture.setEnabled(true);
/*      */       } }
/*      */   ;
/*      */   
/*  457 */   private ActionListener menuMIDletNetworkConnectionListener = new ActionListener() { private final Main this$0;
/*      */       public void actionPerformed(ActionEvent e) {
/*  459 */         Connection.setAllowNetworkConnection(Main.this.menuMIDletNetworkConnection.getState());
/*      */       } }
/*      */   ;
/*      */ 
/*      */   
/*  464 */   private ActionListener menuRecordStoreManagerListener = new ActionListener() { private final Main this$0;
/*      */       public void actionPerformed(ActionEvent e) {
/*  466 */         if (Main.this.recordStoreManagerDialog == null) {
/*  467 */           Main.this.recordStoreManagerDialog = new RecordStoreManagerDialog(Main.this, Main.this.common);
/*  468 */           Main.this.recordStoreManagerDialog.addWindowListener(new WindowAdapter() { private final Main.null this$1;
/*      */                 public void windowClosing(WindowEvent e) {
/*  470 */                   (Main.null.access$1100(Main.null.this)).menuRecordStoreManager.setState(false);
/*      */                 } }
/*      */             );
/*  473 */           Main.this.recordStoreManagerDialog.pack();
/*  474 */           Rectangle window = Config.getWindow("recordStoreManager", new Rectangle(0, 0, 640, 320));
/*  475 */           Main.this.recordStoreManagerDialog.setBounds(window.x, window.y, window.width, window.height);
/*      */         } 
/*  477 */         Main.this.recordStoreManagerDialog.setVisible(!Main.this.recordStoreManagerDialog.isVisible());
/*      */       } }
/*      */   ;
/*      */   
/*  481 */   private ActionListener menuLogConsoleListener = new ActionListener() { private final Main this$0;
/*      */       public void actionPerformed(ActionEvent e) {
/*  483 */         if (Main.this.logConsoleDialog == null) {
/*  484 */           Main.this.logConsoleDialog = new SwingLogConsoleDialog(Main.this, Main.this.logQueueAppender);
/*  485 */           Main.this.logConsoleDialog.addWindowListener(new WindowAdapter() { private final Main.null this$1;
/*      */                 public void windowClosing(WindowEvent e) {
/*  487 */                   (Main.null.access$1500(Main.null.this)).menuLogConsole.setState(false);
/*      */                 } }
/*      */             );
/*  490 */           Main.this.logConsoleDialog.pack();
/*      */           
/*  492 */           Main.this.logConsoleDialog.setFocusableWindowState(false);
/*  493 */           Rectangle window = Config.getWindow("logConsole", new Rectangle(0, 0, 640, 320));
/*  494 */           Main.this.logConsoleDialog.setBounds(window.x, window.y, window.width, window.height);
/*      */         } 
/*  496 */         Main.this.logConsoleDialog.setVisible(!Main.this.logConsoleDialog.isVisible());
/*      */       } }
/*      */   ;
/*      */   
/*  500 */   private ActionListener menuAboutListener = new ActionListener() { private final Main this$0;
/*      */       public void actionPerformed(ActionEvent e) {
/*  502 */         SwingDialogWindow.show(Main.this, "About", (SwingDialogPanel)new SwingAboutDialog(), false);
/*      */       } }
/*      */   ;
/*      */   
/*  506 */   private ActionListener menuExitListener = new ActionListener() { private final Main this$0;
/*      */       public void actionPerformed(ActionEvent e) {
/*  508 */         synchronized (Main.this) {
/*  509 */           if (Main.this.encoder != null) {
/*  510 */             Main.this.encoder.finish();
/*  511 */             Main.this.encoder = null;
/*      */           } 
/*      */         } 
/*      */         
/*  515 */         if (Main.this.logConsoleDialog != null) {
/*  516 */           Config.setWindow("logConsole", new Rectangle(Main.this.logConsoleDialog.getX(), Main.this.logConsoleDialog.getY(), Main.this.logConsoleDialog.getWidth(), Main.this.logConsoleDialog.getHeight()), Main.this.logConsoleDialog.isVisible());
/*      */         }
/*      */         
/*  519 */         if (Main.this.recordStoreManagerDialog != null) {
/*  520 */           Config.setWindow("recordStoreManager", new Rectangle(Main.this.recordStoreManagerDialog.getX(), Main.this.recordStoreManagerDialog.getY(), Main.this.recordStoreManagerDialog.getWidth(), Main.this.recordStoreManagerDialog.getHeight()), Main.this.recordStoreManagerDialog.isVisible());
/*      */         }
/*      */ 
/*      */         
/*  524 */         if (Main.this.scaledDisplayFrame != null) {
/*  525 */           Config.setWindow("scaledDisplay", new Rectangle(Main.this.scaledDisplayFrame.getX(), Main.this.scaledDisplayFrame.getY(), 0, 0), false);
/*      */         }
/*      */         
/*  528 */         Config.setWindow("main", new Rectangle(Main.this.getX(), Main.this.getY(), Main.this.getWidth(), Main.this.getHeight()), true);
/*      */ 
/*      */         
/*  531 */         System.exit(0);
/*      */       } }
/*      */   ;
/*      */   
/*  535 */   private ActionListener menuSelectDeviceListener = new ActionListener() { private final Main this$0;
/*      */       public void actionPerformed(ActionEvent e) {
/*  537 */         if (SwingDialogWindow.show(Main.this, "Select device...", (SwingDialogPanel)Main.this.selectDevicePanel, true)) {
/*  538 */           if (Main.this.selectDevicePanel.getSelectedDeviceEntry().equals(Main.this.deviceEntry)) {
/*      */             return;
/*      */           }
/*  541 */           int restartMidlet = 1;
/*  542 */           if (MIDletBridge.getCurrentMIDlet() != Main.this.common.getLauncher()) {
/*  543 */             restartMidlet = JOptionPane.showConfirmDialog(Main.this, "Changing device may trigger MIDlet to the unpredictable state and restart of MIDlet is recommended. \nDo you want to restart the MIDlet? All MIDlet data will be lost.", "Question?", 0, 3);
/*      */           }
/*      */ 
/*      */ 
/*      */           
/*  548 */           if (!Main.this.setDevice(Main.this.selectDevicePanel.getSelectedDeviceEntry())) {
/*      */             return;
/*      */           }
/*  551 */           if (restartMidlet == 0) {
/*      */             try {
/*  553 */               Main.this.common.initMIDlet(true);
/*  554 */             } catch (Exception ex) {
/*  555 */               System.err.println(ex);
/*      */             } 
/*      */           } else {
/*  558 */             DeviceDisplay deviceDisplay = DeviceFactory.getDevice().getDeviceDisplay();
/*  559 */             DisplayAccess da = MIDletBridge.getMIDletAccess().getDisplayAccess();
/*  560 */             if (da != null) {
/*  561 */               da.sizeChanged();
/*  562 */               deviceDisplay.repaint(0, 0, deviceDisplay.getFullWidth(), deviceDisplay.getFullHeight());
/*      */             } 
/*      */           } 
/*      */         } 
/*      */       } }
/*      */   ;
/*      */   
/*  569 */   private ActionListener menuScaledDisplayListener = new ActionListener() { private DisplayRepaintListener updateScaledImageListener;
/*      */       private final Main this$0;
/*      */       
/*      */       public void actionPerformed(ActionEvent e) {
/*  573 */         final JCheckBoxMenuItem selectedZoomLevelMenuItem = (JCheckBoxMenuItem)e.getSource();
/*  574 */         if (selectedZoomLevelMenuItem.isSelected()) {
/*  575 */           for (int i = 0; i < Main.this.zoomLevels.length; i++) {
/*  576 */             if (Main.this.zoomLevels[i] != e.getSource()) {
/*  577 */               Main.this.zoomLevels[i].setSelected(false);
/*      */             }
/*      */           } 
/*  580 */           final int scale = Integer.parseInt(e.getActionCommand());
/*  581 */           if (Main.this.scaledDisplayFrame != null) {
/*  582 */             Main.this.emulatorContext.getDisplayComponent().removeDisplayRepaintListener(this.updateScaledImageListener);
/*  583 */             Main.this.scaledDisplayFrame.dispose();
/*      */           } 
/*  585 */           Main.this.scaledDisplayFrame = new JFrame(Main.this.getTitle());
/*  586 */           Main.this.scaledDisplayFrame.setContentPane(new JLabel(new ImageIcon()));
/*  587 */           this.updateScaledImageListener = new DisplayRepaintListener() { private final int val$scale; private final Main.null this$1;
/*      */               public void repaintInvoked(MutableImage image) {
/*  589 */                 Main.null.this.updateScaledImage(scale, (Main.null.access$2000(Main.null.this)).scaledDisplayFrame);
/*  590 */                 (Main.null.access$2000(Main.null.this)).scaledDisplayFrame.validate();
/*      */               } }
/*      */             ;
/*  593 */           Main.this.scaledDisplayFrame.addWindowListener(new WindowAdapter() { private final JCheckBoxMenuItem val$selectedZoomLevelMenuItem; private final Main.null this$1;
/*      */                 public void windowClosing(WindowEvent event) {
/*  595 */                   selectedZoomLevelMenuItem.setSelected(false);
/*      */                 } }
/*      */             );
/*  598 */           Main.this.scaledDisplayFrame.getContentPane().addMouseListener(new MouseListener() {
/*  599 */                 private MouseListener receiver = ((SwingDisplayComponent)(Main.null.access$2000(Main.null.this)).emulatorContext.getDisplayComponent()).getMouseListener(); private final int val$scale;
/*      */                 private final Main.null this$1;
/*      */                 
/*      */                 public void mouseClicked(MouseEvent e) {
/*  603 */                   this.receiver.mouseClicked(Main.null.this.createAdaptedMouseEvent(e, scale));
/*      */                 }
/*      */                 
/*      */                 public void mousePressed(MouseEvent e) {
/*  607 */                   this.receiver.mousePressed(Main.null.this.createAdaptedMouseEvent(e, scale));
/*      */                 }
/*      */                 
/*      */                 public void mouseReleased(MouseEvent e) {
/*  611 */                   this.receiver.mouseReleased(Main.null.this.createAdaptedMouseEvent(e, scale));
/*      */                 }
/*      */                 
/*      */                 public void mouseEntered(MouseEvent e) {
/*  615 */                   this.receiver.mouseEntered(Main.null.this.createAdaptedMouseEvent(e, scale));
/*      */                 }
/*      */                 
/*      */                 public void mouseExited(MouseEvent e) {
/*  619 */                   this.receiver.mouseExited(Main.null.this.createAdaptedMouseEvent(e, scale));
/*      */                 }
/*      */               });
/*  622 */           Main.this.scaledDisplayFrame.getContentPane().addMouseMotionListener(new MouseMotionListener() {
/*  623 */                 private MouseMotionListener receiver = ((SwingDisplayComponent)(Main.null.access$2000(Main.null.this)).emulatorContext.getDisplayComponent()).getMouseMotionListener(); private final int val$scale;
/*      */                 private final Main.null this$1;
/*      */                 
/*      */                 public void mouseDragged(MouseEvent e) {
/*  627 */                   this.receiver.mouseDragged(Main.null.this.createAdaptedMouseEvent(e, scale));
/*      */                 }
/*      */                 
/*      */                 public void mouseMoved(MouseEvent e) {
/*  631 */                   this.receiver.mouseMoved(Main.null.this.createAdaptedMouseEvent(e, scale));
/*      */                 }
/*      */               });
/*  634 */           Main.this.scaledDisplayFrame.getContentPane().addMouseWheelListener(new MouseWheelListener() {
/*  635 */                 private MouseWheelListener receiver = ((SwingDisplayComponent)(Main.null.access$2000(Main.null.this)).emulatorContext.getDisplayComponent()).getMouseWheelListener(); private final int val$scale;
/*      */                 private final Main.null this$1;
/*      */                 
/*      */                 public void mouseWheelMoved(MouseWheelEvent e) {
/*  639 */                   MouseWheelEvent adaptedEvent = Main.null.this.createAdaptedMouseWheelEvent(e, scale);
/*  640 */                   this.receiver.mouseWheelMoved(adaptedEvent);
/*      */                 }
/*      */               });
/*  643 */           Main.this.scaledDisplayFrame.addKeyListener((KeyListener)Main.this.devicePanel);
/*      */           
/*  645 */           updateScaledImage(scale, Main.this.scaledDisplayFrame);
/*  646 */           Main.this.emulatorContext.getDisplayComponent().addDisplayRepaintListener(this.updateScaledImageListener);
/*  647 */           Main.this.scaledDisplayFrame.setIconImage(Main.this.getIconImage());
/*  648 */           Main.this.scaledDisplayFrame.setResizable(false);
/*  649 */           Point location = Main.this.getLocation();
/*  650 */           Dimension size = Main.this.getSize();
/*  651 */           Rectangle window = Config.getWindow("scaledDisplay", new Rectangle(location.x + size.width, location.y, 0, 0));
/*      */           
/*  653 */           Main.this.scaledDisplayFrame.setLocation(window.x, window.y);
/*  654 */           Config.setWindow("scaledDisplay", new Rectangle(Main.this.scaledDisplayFrame.getX(), Main.this.scaledDisplayFrame.getY(), 0, 0), false);
/*      */           
/*  656 */           Main.this.scaledDisplayFrame.pack();
/*  657 */           Main.this.scaledDisplayFrame.setVisible(true);
/*      */         } else {
/*  659 */           Main.this.emulatorContext.getDisplayComponent().removeDisplayRepaintListener(this.updateScaledImageListener);
/*  660 */           Main.this.scaledDisplayFrame.dispose();
/*      */         } 
/*      */       }
/*      */       
/*      */       private MouseEvent createAdaptedMouseEvent(MouseEvent e, int scale) {
/*  665 */         return new MouseEvent(e.getComponent(), e.getID(), e.getWhen(), e.getModifiers(), e.getX() / scale, e.getY() / scale, e.getClickCount(), e.isPopupTrigger(), e.getButton());
/*      */       }
/*      */ 
/*      */ 
/*      */       
/*      */       private MouseWheelEvent createAdaptedMouseWheelEvent(MouseWheelEvent e, int scale) {
/*  671 */         return new MouseWheelEvent(e.getComponent(), e.getID(), e.getWhen(), e.getModifiers(), e.getX() / scale, e.getY() / scale, e.getClickCount(), e.isPopupTrigger(), e.getScrollType(), e.getScrollAmount(), e.getWheelRotation());
/*      */       }
/*      */ 
/*      */ 
/*      */ 
/*      */       
/*      */       private void updateScaledImage(int scale, JFrame scaledLCDFrame) {
/*  678 */         J2SEMutableImage scaledImage = (J2SEMutableImage)((SwingDisplayComponent)Main.this.emulatorContext.getDisplayComponent()).getScaledDisplayImage(scale);
/*      */         
/*  680 */         ((ImageIcon)((JLabel)scaledLCDFrame.getContentPane()).getIcon()).setImage(scaledImage.getImage());
/*  681 */         ((JLabel)scaledLCDFrame.getContentPane()).repaint();
/*      */       } }
/*      */   ;
/*      */   
/*  685 */   private StatusBarListener statusBarListener = new StatusBarListener() { private final Main this$0;
/*      */       public void statusBarChanged(String text) {
/*  687 */         FontMetrics metrics = Main.this.statusBar.getFontMetrics(Main.this.statusBar.getFont());
/*  688 */         Main.this.statusBar.setPreferredSize(new Dimension(metrics.stringWidth(text), metrics.getHeight()));
/*  689 */         Main.this.statusBar.setText(text);
/*      */       } }
/*      */   ;
/*      */   
/*  693 */   private ResponseInterfaceListener responseInterfaceListener = new ResponseInterfaceListener() { private final Main this$0;
/*      */       public void stateChanged(boolean state) {
/*  695 */         Main.this.menuOpenMIDletFile.setEnabled(state);
/*  696 */         Main.this.menuOpenMIDletURL.setEnabled(state);
/*  697 */         Main.this.menuSelectDevice.setEnabled(state);
/*      */         
/*  699 */         if (Main.this.common.jad.getJarURL() != null) {
/*  700 */           Main.this.menuSaveForWeb.setEnabled(state);
/*      */         } else {
/*  702 */           Main.this.menuSaveForWeb.setEnabled(false);
/*      */         } 
/*      */       } }
/*      */   ;
/*      */   
/*  707 */   private ComponentListener componentListener = new ComponentAdapter()
/*      */     {
/*      */       Timer timer;
/*  710 */       int count = 0; private final Main this$0;
/*      */       
/*      */       public void componentResized(ComponentEvent e) {
/*  713 */         this.count++;
/*  714 */         DeviceDisplayImpl deviceDisplay = (DeviceDisplayImpl)DeviceFactory.getDevice().getDeviceDisplay();
/*  715 */         if (deviceDisplay.isResizable()) {
/*  716 */           deviceDisplay.setDisplayRectangle(new Rectangle(0, 0, Main.this.devicePanel.getWidth(), Main.this.devicePanel.getHeight()));
/*  717 */           ((SwingDisplayComponent)Main.this.devicePanel.getDisplayComponent()).init();
/*  718 */           MIDletAccess ma = MIDletBridge.getMIDletAccess();
/*  719 */           if (ma == null) {
/*      */             return;
/*      */           }
/*  722 */           DisplayAccess da = ma.getDisplayAccess();
/*  723 */           if (da != null) {
/*  724 */             da.sizeChanged();
/*  725 */             deviceDisplay.repaint(0, 0, deviceDisplay.getFullWidth(), deviceDisplay.getFullHeight());
/*      */           } 
/*  727 */           Main.this.devicePanel.revalidate();
/*  728 */           Main.this.statusBarListener.statusBarChanged("New size: " + deviceDisplay.getFullWidth() + "x" + deviceDisplay.getFullHeight());
/*      */           
/*  730 */           synchronized (Main.this.statusBarListener) {
/*  731 */             if (this.timer == null) {
/*  732 */               this.timer = new Timer();
/*      */             }
/*  734 */             this.timer.schedule(new Main.CountTimerTask(this.count) { private final Main.null this$1;
/*      */                   public void run() {
/*  736 */                     if (this.counter == Main.null.this.count) {
/*  737 */                       Config.setDeviceEntryDisplaySize((Main.null.access$3000(Main.null.this)).deviceEntry, new Rectangle(0, 0, (Main.null.access$3000(Main.null.this)).devicePanel.getWidth(), (Main.null.access$3000(Main.null.this)).devicePanel.getHeight()));
/*      */                       
/*  739 */                       (Main.null.access$3000(Main.null.this)).statusBarListener.statusBarChanged("");
/*  740 */                       Main.null.this.timer.cancel();
/*  741 */                       Main.null.this.timer = null;
/*      */                     } 
/*      */                   } }
/*      */                 2000L);
/*      */           } 
/*      */         } 
/*      */       }
/*      */     };
/*      */   
/*  750 */   private WindowAdapter windowListener = new WindowAdapter() { private final Main this$0;
/*      */       public void windowClosing(WindowEvent ev) {
/*  752 */         Main.this.menuExitListener.actionPerformed(null);
/*      */       }
/*      */       
/*      */       public void windowIconified(WindowEvent ev) {
/*  756 */         MIDletBridge.getMIDletAccess(MIDletBridge.getCurrentMIDlet()).pauseApp();
/*      */       }
/*      */       
/*      */       public void windowDeiconified(WindowEvent ev) {
/*      */         try {
/*  761 */           MIDletBridge.getMIDletAccess(MIDletBridge.getCurrentMIDlet()).startApp();
/*  762 */         } catch (MIDletStateChangeException ex) {
/*  763 */           System.err.println(ex);
/*      */         } 
/*      */       } }
/*      */   ;
/*      */   
/*      */   public Main() {
/*  769 */     this((DeviceEntry)null);
/*      */   }
/*      */ 
/*      */   
/*      */   public Main(DeviceEntry defaultDevice) {
/*  774 */     this.logQueueAppender = new QueueAppender(1024);
/*  775 */     Logger.addAppender((LoggerAppender)this.logQueueAppender);
/*      */     
/*  777 */     JMenuBar menuBar = new JMenuBar();
/*      */     
/*  779 */     JMenu menuFile = new JMenu("File");
/*      */     
/*  781 */     this.menuOpenMIDletFile = new JMenuItem("Open MIDlet File...");
/*  782 */     this.menuOpenMIDletFile.addActionListener(this.menuOpenMIDletFileListener);
/*  783 */     menuFile.add(this.menuOpenMIDletFile);
/*      */     
/*  785 */     this.menuOpenMIDletURL = new JMenuItem("Open MIDlet URL...");
/*  786 */     this.menuOpenMIDletURL.addActionListener(this.menuOpenMIDletURLListener);
/*  787 */     menuFile.add(this.menuOpenMIDletURL);
/*      */     
/*  789 */     JMenuItem menuItemTmp = new JMenuItem("Close MIDlet");
/*  790 */     menuItemTmp.setAccelerator(KeyStroke.getKeyStroke(87, 2));
/*  791 */     menuItemTmp.addActionListener(this.menuCloseMidletListener);
/*  792 */     menuFile.add(menuItemTmp);
/*      */     
/*  794 */     menuFile.addSeparator();
/*      */     
/*  796 */     JMRUMenu urlsMRU = new JMRUMenu("Recent MIDlets...");
/*  797 */     urlsMRU.addActionListener(new ActionListener() { private final Main this$0;
/*      */           public void actionPerformed(ActionEvent event) {
/*  799 */             if (event instanceof JMRUMenu.MRUActionEvent) {
/*  800 */               Common.openMIDletUrlSafe(((MidletURLReference)((JMRUMenu.MRUActionEvent)event).getSourceMRU()).getUrl());
/*      */               
/*  802 */               if (Main.this.recordStoreManagerDialog != null) {
/*  803 */                 Main.this.recordStoreManagerDialog.refresh();
/*      */               }
/*      */             } 
/*      */           } }
/*      */       );
/*      */     
/*  809 */     Config.getUrlsMRU().setListener((MRUListListener)urlsMRU);
/*  810 */     menuFile.add((JMenuItem)urlsMRU);
/*      */     
/*  812 */     menuFile.addSeparator();
/*      */     
/*  814 */     this.menuSaveForWeb = new JMenuItem("Save for Web...");
/*  815 */     this.menuSaveForWeb.addActionListener(this.menuSaveForWebListener);
/*  816 */     menuFile.add(this.menuSaveForWeb);
/*      */     
/*  818 */     menuFile.addSeparator();
/*      */     
/*  820 */     JMenuItem menuItem = new JMenuItem("Exit");
/*  821 */     menuItem.setAccelerator(KeyStroke.getKeyStroke(81, 2));
/*  822 */     menuItem.addActionListener(this.menuExitListener);
/*  823 */     menuFile.add(menuItem);
/*      */     
/*  825 */     JMenu menuOptions = new JMenu("Options");
/*      */     
/*  827 */     this.menuSelectDevice = new JMenuItem("Select device...");
/*  828 */     this.menuSelectDevice.addActionListener(this.menuSelectDeviceListener);
/*  829 */     menuOptions.add(this.menuSelectDevice);
/*      */     
/*  831 */     JMenu menuScaleLCD = new JMenu("Scaled display");
/*  832 */     menuOptions.add(menuScaleLCD);
/*  833 */     this.zoomLevels = new JCheckBoxMenuItem[3];
/*  834 */     for (int i = 0; i < this.zoomLevels.length; i++) {
/*  835 */       this.zoomLevels[i] = new JCheckBoxMenuItem("x " + (i + 2));
/*  836 */       this.zoomLevels[i].setActionCommand("" + (i + 2));
/*  837 */       this.zoomLevels[i].addActionListener(this.menuScaledDisplayListener);
/*  838 */       menuScaleLCD.add(this.zoomLevels[i]);
/*      */     } 
/*      */     
/*  841 */     this.menuStartCapture = new JMenuItem("Start capture to GIF...");
/*  842 */     this.menuStartCapture.addActionListener(this.menuStartCaptureListener);
/*  843 */     menuOptions.add(this.menuStartCapture);
/*      */     
/*  845 */     this.menuStopCapture = new JMenuItem("Stop capture");
/*  846 */     this.menuStopCapture.setEnabled(false);
/*  847 */     this.menuStopCapture.addActionListener(this.menuStopCaptureListener);
/*  848 */     menuOptions.add(this.menuStopCapture);
/*      */     
/*  850 */     this.menuMIDletNetworkConnection = new JCheckBoxMenuItem("MIDlet Network access");
/*  851 */     this.menuMIDletNetworkConnection.setState(true);
/*  852 */     this.menuMIDletNetworkConnection.addActionListener(this.menuMIDletNetworkConnectionListener);
/*  853 */     menuOptions.add(this.menuMIDletNetworkConnection);
/*      */     
/*  855 */     this.menuRecordStoreManager = new JCheckBoxMenuItem("Record Store Manager");
/*  856 */     this.menuRecordStoreManager.setState(false);
/*  857 */     this.menuRecordStoreManager.addActionListener(this.menuRecordStoreManagerListener);
/*  858 */     menuOptions.add(this.menuRecordStoreManager);
/*      */     
/*  860 */     this.menuLogConsole = new JCheckBoxMenuItem("Log console");
/*  861 */     this.menuLogConsole.setState(false);
/*  862 */     this.menuLogConsole.addActionListener(this.menuLogConsoleListener);
/*  863 */     menuOptions.add(this.menuLogConsole);
/*      */     
/*  865 */     menuOptions.addSeparator();
/*  866 */     JCheckBoxMenuItem menuShowMouseCoordinates = new JCheckBoxMenuItem("Mouse coordinates");
/*  867 */     menuShowMouseCoordinates.setState(false);
/*  868 */     menuShowMouseCoordinates.addActionListener(new ActionListener() { private final Main this$0;
/*      */           public void actionPerformed(ActionEvent event) {
/*  870 */             Main.this.devicePanel.switchShowMouseCoordinates();
/*      */           } }
/*      */       );
/*  873 */     menuOptions.add(menuShowMouseCoordinates);
/*      */     
/*  875 */     JMenu menuHelp = new JMenu("Help");
/*  876 */     JMenuItem menuAbout = new JMenuItem("About");
/*  877 */     menuAbout.addActionListener(this.menuAboutListener);
/*  878 */     menuHelp.add(menuAbout);
/*      */     
/*  880 */     menuBar.add(menuFile);
/*  881 */     menuBar.add(menuOptions);
/*  882 */     menuBar.add(menuHelp);
/*  883 */     setJMenuBar(menuBar);
/*      */     
/*  885 */     setTitle("MicroEmulator");
/*      */     
/*  887 */     setIconImage(Toolkit.getDefaultToolkit().getImage(Main.class.getResource("/org/microemu/icon.png")));
/*      */     
/*  889 */     addWindowListener(this.windowListener);
/*      */     
/*  891 */     Config.loadConfig(defaultDevice, this.emulatorContext);
/*  892 */     Logger.setLocationEnabled(Config.isLogConsoleLocationEnabled());
/*      */     
/*  894 */     Rectangle window = Config.getWindow("main", new Rectangle(0, 0, 160, 120));
/*  895 */     setLocation(window.x, window.y);
/*      */     
/*  897 */     getContentPane().add(createContents(getContentPane()), "Center");
/*      */     
/*  899 */     this.selectDevicePanel = new SwingSelectDevicePanel(this.emulatorContext);
/*      */     
/*  901 */     this.common = new Common(this.emulatorContext);
/*  902 */     this.common.setStatusBarListener(this.statusBarListener);
/*  903 */     this.common.setResponseInterfaceListener(this.responseInterfaceListener);
/*  904 */     this.common.loadImplementationsFromConfig();
/*      */     
/*  906 */     this.resizeButton.addActionListener(new ActionListener() { private final Main this$0;
/*      */           public void actionPerformed(ActionEvent ev) {
/*  908 */             if (Main.this.resizeDeviceDisplayDialog == null) {
/*  909 */               Main.this.resizeDeviceDisplayDialog = new ResizeDeviceDisplayDialog();
/*      */             }
/*  911 */             DeviceDisplayImpl deviceDisplay = (DeviceDisplayImpl)DeviceFactory.getDevice().getDeviceDisplay();
/*  912 */             Main.this.resizeDeviceDisplayDialog.setDeviceDisplaySize(deviceDisplay.getFullWidth(), deviceDisplay.getFullHeight());
/*      */             
/*  914 */             if (SwingDialogWindow.show(Main.this, "Enter new size...", (SwingDialogPanel)Main.this.resizeDeviceDisplayDialog, true)) {
/*  915 */               deviceDisplay.setDisplayRectangle(new Rectangle(0, 0, Main.this.resizeDeviceDisplayDialog.getDeviceDisplayWidth(), Main.this.resizeDeviceDisplayDialog.getDeviceDisplayHeight()));
/*      */               
/*  917 */               ((SwingDisplayComponent)Main.this.devicePanel.getDisplayComponent()).init();
/*  918 */               MIDletAccess ma = MIDletBridge.getMIDletAccess();
/*  919 */               if (ma == null) {
/*      */                 return;
/*      */               }
/*  922 */               DisplayAccess da = ma.getDisplayAccess();
/*  923 */               if (da != null) {
/*  924 */                 da.sizeChanged();
/*  925 */                 deviceDisplay.repaint(0, 0, deviceDisplay.getFullWidth(), deviceDisplay.getFullHeight());
/*      */               } 
/*  927 */               Main.this.pack();
/*      */             } 
/*      */           } }
/*      */       );
/*      */     
/*  932 */     JPanel statusPanel = new JPanel();
/*  933 */     statusPanel.setLayout(new BorderLayout());
/*  934 */     statusPanel.add(this.statusBar, "West");
/*  935 */     statusPanel.add(this.resizeButton, "East");
/*      */     
/*  937 */     getContentPane().add(statusPanel, "South");
/*      */     
/*  939 */     Message.addListener((MessageListener)new SwingErrorMessageDialogPanel(this));
/*      */     
/*  941 */     this.devicePanel.setTransferHandler((TransferHandler)new DropTransferHandler());
/*      */   }
/*      */   
/*      */   protected Component createContents(Container parent) {
/*  945 */     this.devicePanel = new SwingDeviceComponent();
/*  946 */     this.devicePanel.addKeyListener((KeyListener)this.devicePanel);
/*  947 */     addKeyListener((KeyListener)this.devicePanel);
/*      */     
/*  949 */     return (Component)this.devicePanel;
/*      */   }
/*      */   
/*      */   public boolean setDevice(DeviceEntry entry) {
/*  953 */     if (DeviceFactory.getDevice() != null);
/*      */ 
/*      */     
/*  956 */     String errorTitle = "Error creating device";
/*      */     try {
/*  958 */       ClassLoader classLoader = getClass().getClassLoader();
/*  959 */       if (entry.getFileName() != null) {
/*  960 */         URL[] urls = new URL[1];
/*  961 */         urls[0] = (new File(Config.getConfigPath(), entry.getFileName())).toURI().toURL();
/*  962 */         classLoader = Common.createExtensionsClassLoader(urls);
/*      */       } 
/*      */ 
/*      */ 
/*      */       
/*  967 */       this.emulatorContext.getDeviceFontManager().init();
/*      */       
/*  969 */       DeviceImpl deviceImpl = DeviceImpl.create(this.emulatorContext, classLoader, entry.getDescriptorLocation(), J2SEDevice.class);
/*      */       
/*  971 */       this.deviceEntry = entry;
/*      */       
/*  973 */       DeviceDisplayImpl deviceDisplay = (DeviceDisplayImpl)deviceImpl.getDeviceDisplay();
/*  974 */       if (deviceDisplay.isResizable()) {
/*  975 */         Rectangle size = Config.getDeviceEntryDisplaySize(entry);
/*  976 */         if (size != null) {
/*  977 */           deviceDisplay.setDisplayRectangle(size);
/*      */         }
/*      */       } 
/*  980 */       this.common.setDevice((Device)deviceImpl);
/*  981 */       updateDevice();
/*  982 */       return true;
/*  983 */     } catch (MalformedURLException e) {
/*  984 */       Message.error("Error creating device", "Error creating device, " + Message.getCauseMessage(e), e);
/*  985 */     } catch (IOException e) {
/*  986 */       Message.error("Error creating device", "Error creating device, " + Message.getCauseMessage(e), e);
/*  987 */     } catch (Throwable e) {
/*  988 */       Message.error("Error creating device", "Error creating device, " + Message.getCauseMessage(e), e);
/*      */     } 
/*  990 */     return false;
/*      */   }
/*      */   
/*      */   protected void updateDevice() {
/*  994 */     this.devicePanel.init();
/*  995 */     if (((DeviceDisplayImpl)DeviceFactory.getDevice().getDeviceDisplay()).isResizable()) {
/*  996 */       setResizable(true);
/*  997 */       this.resizeButton.setVisible(true);
/*      */     } else {
/*  999 */       setResizable(false);
/* 1000 */       this.resizeButton.setVisible(false);
/*      */     } 
/*      */     
/* 1003 */     pack();
/*      */     
/* 1005 */     this.devicePanel.requestFocus();
/*      */   }
/*      */   
/*      */   public static void main(String[] args) {
/* 1009 */     List params = new ArrayList();
/* 1010 */     StringBuffer debugArgs = new StringBuffer();
/* 1011 */     for (int i = 0; i < args.length; i++) {
/* 1012 */       params.add(args[i]);
/* 1013 */       if (debugArgs.length() != 0) {
/* 1014 */         debugArgs.append(", ");
/*      */       }
/* 1016 */       debugArgs.append("[").append(args[i]).append("]");
/*      */     } 
/* 1018 */     if (params.contains("--headless")) {
/* 1019 */       Headless.main(args);
/*      */       
/*      */       return;
/*      */     } 
/*      */     try {
/* 1024 */       UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
/* 1025 */     } catch (Exception ex) {
/* 1026 */       Logger.error(ex);
/*      */     } 
/*      */     
/* 1029 */     Main app = new Main();
/* 1030 */     if (args.length > 0) {
/* 1031 */       Logger.debug("arguments", debugArgs.toString());
/*      */     }
/*      */     
/* 1034 */     if (app.common.initParams(params, app.selectDevicePanel.getSelectedDeviceEntry(), J2SEDevice.class)) {
/* 1035 */       app.deviceEntry = app.selectDevicePanel.getSelectedDeviceEntry();
/* 1036 */       DeviceDisplayImpl deviceDisplay = (DeviceDisplayImpl)DeviceFactory.getDevice().getDeviceDisplay();
/* 1037 */       if (deviceDisplay.isResizable()) {
/* 1038 */         Rectangle size = Config.getDeviceEntryDisplaySize(app.deviceEntry);
/* 1039 */         if (size != null) {
/* 1040 */           deviceDisplay.setDisplayRectangle(size);
/*      */         }
/*      */       } 
/*      */     } 
/* 1044 */     app.updateDevice();
/*      */     
/* 1046 */     app.validate();
/* 1047 */     app.setVisible(true);
/*      */     
/* 1049 */     if (Config.isWindowOnStart("logConsole")) {
/* 1050 */       app.menuLogConsoleListener.actionPerformed(null);
/* 1051 */       app.menuLogConsole.setSelected(true);
/*      */     } 
/* 1053 */     if (Config.isWindowOnStart("recordStoreManager")) {
/* 1054 */       app.menuRecordStoreManagerListener.actionPerformed(null);
/* 1055 */       app.menuRecordStoreManager.setSelected(true);
/*      */     } 
/*      */ 
/*      */     
/*      */     try {
/* 1060 */       String midletString = params.iterator().next();
/* 1061 */     } catch (NoSuchElementException ex) {
/* 1062 */       Object object = null;
/*      */     } 
/* 1064 */     app.common.initMIDlet(false);
/*      */     
/* 1066 */     app.addComponentListener(app.componentListener);
/*      */     
/* 1068 */     app.responseInterfaceListener.stateChanged(true);
/*      */   }
/*      */   
/*      */   private abstract class CountTimerTask extends TimerTask {
/*      */     protected int counter;
/*      */     private final Main this$0;
/*      */     
/*      */     public CountTimerTask(int counter) {
/* 1076 */       this.counter = counter;
/*      */     }
/*      */   }
/*      */ }


/* Location:              /home/manish/mcmod/microemulator.jar!/org/microemu/app/Main.class
 * Java compiler version: 4 (48.0)
 * JD-Core Version:       1.1.3
 */