Ejemplo n.º 1
0
  /** @see CommandListener#commandAction(Command, Displayable) */
  public void commandAction(Command cmd, Displayable disp) {
    if (cmd.getCommandType() == Command.EXIT) {
      sim.destroyApp(false);
      sim.notifyDestroyed();
    } else {
      Display d = Sim.getDisplay();

      switch (getSelectedIndex()) {
        case 0: // Neues Spiel
          gamemode = new GameModeForm();
          d.setCurrent(gamemode);
          break;

        case 1: // Einstellungen
          d.setCurrent(new PrefForm());
          break;

        case 2: // Info
          Info.showInfo(d);
          break;

        case 3: // About
          Alert alert2 =
              new Alert(
                  "About",
                  "SimME\n by SPIESSEIN\n based on HEXI\n by Prof. Slany\n",
                  null,
                  AlertType.INFO);
          alert2.setTimeout(Alert.FOREVER);
          d.setCurrent(alert2, this);
          break;
      }
    }
  }
Ejemplo n.º 2
0
 public void commandAction(Command c, Displayable s) {
   if (c.getCommandType() == Command.EXIT) {
     destroyApp(true);
     notifyDestroyed();
   } else if (c == mCameraCommand) showCamera();
   else if (c == mBackCommand) mDisplay.setCurrent(mMainForm);
   else if (c == mCaptureCommand) {
     capture();
   }
 }
Ejemplo n.º 3
0
  public void commandAction(Command cmd, de.enough.polish.ui.Item item) {
    item = this.mShortcutList.getFocusedItem();

    // #debug
    System.out.println(
        "cmd: " + cmd.getLabel() + ", type: " + cmd.getCommandType() + ", item: " + item);
    if (item instanceof ShortcutItem) {
      ShortcutItem shortcut = (ShortcutItem) item;
      createShortcutEditTab(shortcut);
    }
  }
Ejemplo n.º 4
0
  public void commandAction(Command command, Displayable display) {
    if (command == javax.microedition.lcdui.List.SELECT_COMMAND) {
      // View this verse

      // Grab the reference
      int selectedIndex = getSelectedIndex();

      if (selectedIndex != -1) {
        // Convert to cyclic history list
        selectedIndex += goBible.historyStartIndex;

        if (selectedIndex >= GoBible.HISTORY_SIZE) {
          selectedIndex -= GoBible.HISTORY_SIZE;
        }

        goBible.currentBookIndex = goBible.historyVerseIndices[selectedIndex * 3] & 0xff;
        goBible.currentChapterIndex = goBible.historyVerseIndices[selectedIndex * 3 + 1] & 0xff;
        goBible.currentVerseIndex = goBible.historyVerseIndices[selectedIndex * 3 + 2] & 0xff;

        goBible.bibleCanvas.enterLoadingMode();
        goBible.display.setCurrent(goBible.bibleCanvas);
        goBible.loadCurrentChapter();
        goBible.bibleCanvas.update();
      }
    } else {
      switch (command.getCommandType()) {
        case Command.OK:
        case Command.CANCEL:
          {
            // Revert to the previously displayed verse
            goBible.bibleCanvas.enterLoadingMode();
            goBible.display.setCurrent(goBible.bibleCanvas);
            goBible.bibleCanvas.repaint();
            goBible.loadCurrentChapter();
            goBible.showMainScreen();
            break;
          }
      }
    }
  }
 public void commandAction(Command command, Displayable display) {
   getController().control(command.getCommandType());
 }
Ejemplo n.º 6
0
 /**
  * WARNING: Can only be used in JavaSE environments! Serializes the specified object.
  *
  * @param object the object
  * @param out the stream into which the object should be serialized
  * @param useObfuscation true when classnames are obfuscated
  * @throws IOException when serialization data could not be written or when encountering an object
  *     that cannot be serialized
  */
 public static void serialize(Object object, DataOutputStream out, boolean useObfuscation)
     throws IOException {
   // #endif
   out.writeByte(VERSION);
   boolean isNull = (object == null);
   out.writeBoolean(isNull);
   if (!isNull) {
     if (object instanceof Externalizable) {
       out.writeByte(TYPE_EXTERNALIZABLE);
       String className = object.getClass().getName();
       // #if polish.JavaSE
       if (useObfuscation && obfuscationSerializeMap != null) {
         String obfuscatedClassName = (String) obfuscationSerializeMap.get(className);
         if (obfuscatedClassName != null) {
           // System.out.println("Serializer.serialize: translating classname from " + className +
           // " to " +  obfuscatedClassName +  " useObfuscationIndicator=" +
           // useObfuscationIndicator.get() );
           className = obfuscatedClassName;
         }
       }
       // #endif
       // #debug debug
       // #= System.out.println("serializing " + className + "=" + object);
       out.writeUTF(className);
       ((Externalizable) object).write(out);
     } else if (object instanceof Externalizable[]) {
       out.writeByte(TYPE_EXTERNALIZABLE_ARRAY);
       String cn = object.getClass().getName();
       cn = cn.substring(cn.lastIndexOf('[') + 2, cn.length() - 1);
       // #if polish.JavaSE
       if (useObfuscation && obfuscationSerializeMap != null) {
         String obfuscatedClassName = (String) obfuscationSerializeMap.get(cn);
         if (obfuscatedClassName != null) {
           // System.out.println("Serializer.serialize: translating classname from " + className +
           // " to " +  obfuscatedClassName );
           cn = obfuscatedClassName;
         }
       }
       // #endif
       out.writeUTF(cn);
       Externalizable[] externalizables = (Externalizable[]) object;
       out.writeInt(externalizables.length);
       Hashtable classNames = new Hashtable();
       Class lastClass = null;
       byte lastId = 0;
       byte idCounter = 0;
       for (int i = 0; i < externalizables.length; i++) {
         Externalizable externalizable = externalizables[i];
         Class currentClass = externalizable.getClass();
         if (currentClass == lastClass) {
           out.writeByte(lastId);
         } else {
           Byte knownId = (Byte) classNames.get(currentClass);
           if (knownId != null) {
             out.writeByte(knownId.byteValue());
           } else {
             // this is a class that has not yet been encountered:
             out.writeByte(0);
             idCounter++;
             String className = currentClass.getName();
             // #if polish.JavaSE
             if (useObfuscation && obfuscationSerializeMap != null) {
               String obfuscatedClassName = (String) obfuscationSerializeMap.get(className);
               if (obfuscatedClassName != null) {
                 // System.out.println("Serializer.serialize: translating classname from " +
                 // className + " to " +  obfuscatedClassName );
                 className = obfuscatedClassName;
               }
             }
             // #endif
             // #debug debug
             // #= System.out.println("serializing " + className + "=" + object);
             out.writeUTF(className);
             lastClass = currentClass;
             lastId = idCounter;
             classNames.put(currentClass, new Byte(lastId));
           }
         }
         externalizable.write(out);
       }
     } else if (object instanceof Object[]) {
       out.writeByte(TYPE_OBJECT_ARRAY);
       Object[] objects = (Object[]) object;
       out.writeInt(objects.length);
       for (int i = 0; i < objects.length; i++) {
         Object obj = objects[i];
         serialize(obj, out);
       }
     } else if (object instanceof Byte) {
       out.writeByte(TYPE_BYTE);
       out.writeByte(((Byte) object).byteValue());
     } else if (object instanceof Short) {
       out.writeByte(TYPE_SHORT);
       out.writeShort(((Short) object).shortValue());
     } else if (object instanceof Integer) {
       out.writeByte(TYPE_INTEGER);
       out.writeInt(((Integer) object).intValue());
     } else if (object instanceof Long) {
       out.writeByte(TYPE_LONG);
       out.writeLong(((Long) object).longValue());
       // #if polish.hasFloatingPoint
     } else if (object instanceof Float) {
       out.writeByte(TYPE_FLOAT);
       out.writeFloat(((Float) object).floatValue());
     } else if (object instanceof Double) {
       out.writeByte(TYPE_DOUBLE);
       out.writeDouble(((Double) object).doubleValue());
       // #endif
     } else if (object instanceof String) {
       out.writeByte(TYPE_STRING);
       out.writeUTF((String) object);
     } else if (object instanceof StringBuffer) {
       out.writeByte(TYPE_STRING_BUFFER);
       out.writeUTF(((StringBuffer) object).toString());
     } else if (object instanceof Character) {
       out.writeByte(TYPE_CHARACTER);
       out.writeChar(((Character) object).charValue());
     } else if (object instanceof Boolean) {
       out.writeByte(TYPE_BOOLEAN);
       out.writeBoolean(((Boolean) object).booleanValue());
     } else if (object instanceof Date) {
       out.writeByte(TYPE_DATE);
       out.writeLong(((Date) object).getTime());
     } else if (object instanceof Calendar) {
       out.writeByte(TYPE_CALENDAR);
       out.writeLong(((Calendar) object).getTime().getTime());
     } else if (object instanceof Random) {
       out.writeByte(TYPE_RANDOM);
     } else if (object instanceof Hashtable) {
       out.writeByte(TYPE_HASHTABLE);
       Hashtable table = (Hashtable) object;
       out.writeInt(table.size());
       Enumeration enumeration = table.keys();
       while (enumeration.hasMoreElements()) {
         Object key = enumeration.nextElement();
         serialize(key, out);
         Object value = table.get(key);
         serialize(value, out);
       }
     } else if (object instanceof Vector) { // also serializes stacks
       if (object instanceof Stack) {
         out.writeByte(TYPE_STACK);
       } else {
         out.writeByte(TYPE_VECTOR);
       }
       Vector vector = (Vector) object;
       int size = vector.size();
       out.writeInt(size);
       for (int i = 0; i < size; i++) {
         serialize(vector.elementAt(i), out);
       }
       // #if polish.midp2
     } else if (object instanceof Image) {
       out.writeByte(TYPE_IMAGE);
       // #if polish.JavaSE
       boolean handled = false;
       // we are within a Java SE environment. When the J2ME Polish runtime librarby is used, we
       // can
       // store the image in PNG format instead of in the much more verbose RGB format:
       try {
         // #if false
         Field bufferedImageField = null;
         // #else
         // # Field bufferedImageField = object.getClass().getDeclaredField("bufferedImage");
         // #endif
         bufferedImageField.setAccessible(true);
         BufferedImage bufferedImage = (BufferedImage) bufferedImageField.get(object);
         ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
         ImageIO.write(bufferedImage, "png", byteOut);
         out.writeByte(TYPE_IMAGE_BYTES);
         byte[] data = byteOut.toByteArray();
         out.writeInt(data.length);
         for (int i = 0; i < data.length; i++) {
           out.writeByte(data[i]);
         }
         handled = true;
       } catch (Exception e) {
         e.printStackTrace();
         // #debug warn
         System.out.println(
             "Warning: Unable to retrieve bufferedImage field of javax.microedition.lcdui.Image - probably the enough-polish-runtime library is not used.");
       }
       if (!handled) {
         // #endif
         Image image = (Image) object;
         out.writeByte(TYPE_IMAGE_RGB);
         int width = image.getWidth();
         int height = image.getHeight();
         out.writeInt(width);
         out.writeInt(height);
         int[] rgb = new int[width * height];
         image.getRGB(rgb, 0, width, 0, 0, width, height);
         for (int i = 0; i < rgb.length; i++) {
           out.writeInt(rgb[i]);
         }
         // #if polish.JavaSE
       }
       // #endif
       // #endif
       // #if polish.midp
     } else if (object instanceof Font) {
       out.writeByte(TYPE_FONT);
       Font font = (Font) object;
       out.writeInt(font.getFace());
       out.writeInt(font.getStyle());
       out.writeInt(font.getSize());
     } else if (object instanceof Command) {
       out.writeByte(TYPE_COMMAND);
       Command command = (Command) object;
       out.writeInt(command.getCommandType());
       out.writeInt(command.getPriority());
       out.writeUTF(command.getLabel());
       // #endif
     } else if (object instanceof byte[]) {
       out.writeByte(TYPE_BYTE_ARRAY);
       byte[] numbers = (byte[]) object;
       out.writeInt(numbers.length);
       out.write(numbers, 0, numbers.length);
     } else if (object instanceof short[]) {
       out.writeByte(TYPE_SHORT_ARRAY);
       short[] numbers = (short[]) object;
       out.writeInt(numbers.length);
       for (int i = 0; i < numbers.length; i++) {
         short number = numbers[i];
         out.writeShort(number);
       }
     } else if (object instanceof int[]) {
       out.writeByte(TYPE_INT_ARRAY);
       int[] numbers = (int[]) object;
       out.writeInt(numbers.length);
       for (int i = 0; i < numbers.length; i++) {
         int number = numbers[i];
         out.writeInt(number);
       }
     } else if (object instanceof long[]) {
       out.writeByte(TYPE_LONG_ARRAY);
       long[] numbers = (long[]) object;
       out.writeInt(numbers.length);
       for (int i = 0; i < numbers.length; i++) {
         long number = numbers[i];
         out.writeLong(number);
       }
       // #if polish.hasFloatingPoint
     } else if (object instanceof float[]) {
       out.writeByte(TYPE_FLOAT_ARRAY);
       float[] numbers = (float[]) object;
       out.writeInt(numbers.length);
       for (int i = 0; i < numbers.length; i++) {
         float number = numbers[i];
         out.writeFloat(number);
       }
     } else if (object instanceof double[]) {
       out.writeByte(TYPE_DOUBLE_ARRAY);
       double[] numbers = (double[]) object;
       out.writeInt(numbers.length);
       for (int i = 0; i < numbers.length; i++) {
         double number = numbers[i];
         out.writeDouble(number);
       }
       // #endif
     } else if (object instanceof char[]) {
       out.writeByte(TYPE_CHAR_ARRAY);
       char[] characters = (char[]) object;
       out.writeInt(characters.length);
       for (int i = 0; i < characters.length; i++) {
         char c = characters[i];
         out.writeChar(c);
       }
     } else if (object instanceof boolean[]) {
       out.writeByte(TYPE_BOOLEAN_ARRAY);
       boolean[] bools = (boolean[]) object;
       out.writeInt(bools.length);
       for (int i = 0; i < bools.length; i++) {
         boolean b = bools[i];
         out.writeBoolean(b);
       }
     } else if (object instanceof String[]) {
       out.writeByte(TYPE_STRING_ARRAY);
       String[] strings = (String[]) object;
       out.writeInt(strings.length);
       for (int i = 0; i < strings.length; i++) {
         String s = strings[i];
         out.writeUTF(s);
       }
     } else {
       throw new IOException("Cannot serialize " + object.getClass().getName());
     }
   }
 }