/* * Copyright © 2013 Nokia Corporation. All rights reserved. Nokia and Nokia * Connecting People are registered trademarks of Nokia Corporation. Oracle and * Java are trademarks or registered trademarks of Oracle and/or its affiliates. * Other product and company names mentioned herein may be trademarks or trade * names of their respective owners. See LICENSE.TXT for license information. */ package com.nokia.example; import com.nokia.mid.ui.IconCommand; import com.nokia.mid.ui.VirtualKeyboard; import java.io.IOException; import javax.microedition.lcdui.*; import javax.microedition.midlet.MIDlet; /** * Simple midlet that displays a static SVG file. */ public class LoadStaticMidlet extends MIDlet implements CommandListener { public static Image zoomIcon = null; public static Image moveIcon = null; /** * Constructor. */ public LoadStaticMidlet() { /** * VirtualKeyboard is supported from Java Runtime 2.0.0 for Series 40 * onwards. To determine whether a Series 40 device is a Full Touch * device and hide the open keypad command from the Options menu. */ if (System.getProperty("com.nokia.keyboard.type").equals("None")) { VirtualKeyboard.hideOpenKeypadCommand(true); } try { /** * Create images for action button 1 */ zoomIcon = Image.createImage("/zoomIcon.png"); moveIcon = Image.createImage("/moveIcon.png"); } catch (Exception e) { e.printStackTrace(); } // *** create the SVG canvas svgCanvas = new SvgCanvas2(false); svgCanvas.setCommandListener(this); // *** grab a reference to the display display = Display.getDisplay(this); display.setCurrent(svgCanvas); // *** set up the midlet menu int hotKey = 1; /** * IconCommand is supported from Java Runtime 2.0.0 for Series 40 * onwards. Creates a new IconCommand Zoom with the given label, * unselected icon, selected icon, type and priority. */ cmZoom = new IconCommand("Zoom", zoomIcon, zoomIcon, IconCommand.ICON_OK, hotKey++); svgCanvas.addCommand(cmZoom); /** * IconCommand is supported from Java Runtime 2.0.0 for Series 40 * onwards. Creates a new IconCommand Move with the given label, * unselected icon, selected icon, type and priority. */ cmMove = new IconCommand("Move", moveIcon, moveIcon, IconCommand.ICON_OK, hotKey++); cmZoomIn = new Command("Zoom In", Command.SCREEN, hotKey++); svgCanvas.addCommand(cmZoomIn); cmZoomOut = new Command("Zoom Out", Command.SCREEN, hotKey++); svgCanvas.addCommand(cmZoomOut); cmRotateIn = new Command("Rotate Counter", Command.SCREEN, hotKey++); svgCanvas.addCommand(cmRotateIn); cmRotateOut = new Command("Rotate Clockwise", Command.SCREEN, hotKey++); svgCanvas.addCommand(cmRotateOut); cmRestoreView = new Command("Restore View", Command.SCREEN, hotKey++); svgCanvas.addCommand(cmRestoreView); cmExit = new Command("Exit", Command.BACK, hotKey++); svgCanvas.addCommand(cmExit); SvgCanvas2.iconCommandState = SvgCanvas2.IMAGE_MOVE; } /** * Required midlet method. */ public void startApp() { } /** * Required midlet method. */ public void pauseApp() { } /** * Required midlet method. */ public void destroyApp(boolean unconditional) { } /** * Handle the various menu actions. */ public void commandAction(Command c, Displayable s) { if (c == cmExit) { try { if (SvgCanvas2.iConnection != null) { SvgCanvas2.iConnection.removeDataListener(); SvgCanvas2.iConnection.close(); SvgCanvas2.iConnection = null; } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } destroyApp(false); notifyDestroyed(); } else if (c == cmZoomIn) { svgCanvas.zoomIn(); } else if (c == cmZoomOut) { svgCanvas.zoomOut(); } else if (c == cmRotateIn) { svgCanvas.rotateIn(); } else if (c == cmRotateOut) { svgCanvas.rotateOut(); } else if (c == cmRestoreView) { svgCanvas.restoreView(); } else if (c == cmMove) { SvgCanvas2.iconCommandState = SvgCanvas2.IMAGE_MOVE; svgCanvas.addCommand(cmZoom); svgCanvas.removeCommand(cmMove); } else if (c == cmZoom) { SvgCanvas2.iconCommandState = SvgCanvas2.IMAGE_ZOOM; svgCanvas.addCommand(cmMove); svgCanvas.removeCommand(cmZoom); } } /* * Private members */ private Display display; private SvgCanvas2 svgCanvas; private Command cmZoomIn; private Command cmZoomOut; private Command cmRotateIn; private Command cmRotateOut; private Command cmRestoreView; private Command cmExit; private IconCommand cmMove; private IconCommand cmZoom; }