Esempio n. 1
1
  public void commandAction(Command command, Displayable displayable) {
    if ((displayable == D_MAIN) && D_MAIN.Responds()) {
      if (command == c_exit) {
        exitMIDlet();
      }
      if (command == c_history) {
        switchDisplayable(null, getL_history());
        Stack st = D_MAIN.getEqHS();
        Enumeration en = st.elements();
        l_history.deleteAll();
        while (en.hasMoreElements()) {
          l_history.append((String) en.nextElement(), null);
        }
      }
      if (command == c_tovars) {
        getL_vars().deleteAll();
        StringBuffer sb;
        Enumeration values = D_MAIN.getEqVars().elements();
        Enumeration names = D_MAIN.getEqVars().keys();
        String name;
        Real value;
        while ((values.hasMoreElements()) && (names.hasMoreElements())) {
          name = String.valueOf(names.nextElement());
          value = new Real(String.valueOf((values.nextElement())));
          Real.NumberFormat n = new Real.NumberFormat();
          n.maxwidth = 17;
          n.fse = Real.NumberFormat.FSE_NONE;
          sb = new StringBuffer(value.toString(n));
          if (chartools.contains(sb, 'e')) {
            StringBuffer ev = new StringBuffer();
            for (int i = sb.length() - 1; i > -1; --i) {
              if (sb.charAt(i) == 'e') {
                sb.deleteCharAt(i);
                break;
              }
              ev.append(sb.charAt(i));
              sb.deleteCharAt(i);
            }
            ev.reverse();
            sb.append(" * 10^(" + ev + ")");
            if ((!(sb.equals(new StringBuffer(""))))
                && (!(name.equals("")))
                && (!(sb.equals(new StringBuffer("null"))))
                && (!(name.equals("null")))) {
              l_vars.append(name + " = " + sb.toString(), null);
            }
          } else {
            if ((!(sb.equals(new StringBuffer(""))))
                && (!(name.equals("")))
                && (!(sb.equals(new StringBuffer("null"))))
                && (!(name.equals("null")))) {
              getL_vars().append(name + " = " + sb.toString(), null);
            }
          }
        }
        switchDisplayable(null, getL_vars());
      }
    }
    if (displayable == f_welcome) {
      if (command == c_canvas) {
        switchDisplayable(null, D_MAIN);
      }
    } else if (displayable == form) {
      if (command == c_history) {

      } else if (command == c_tovars) {

      }
    } else if (displayable == l_history) {
      if (command == List.SELECT_COMMAND) {

        l_historyAction();

      } else if (command == c_canvas) {
        switchDisplayable(null, D_MAIN);

      } else if (command == c_insert) {

        if (l_history.size() != 0) {
          StringBuffer sb = new StringBuffer();
          String his = l_history.getString(l_history.getSelectedIndex());
          boolean p_end = false;
          for (int i = 0; i < his.length(); i++) {
            if (his.charAt(i) == '=') {
              break;
            }
            if (p_end) {
              sb.append(his.charAt(i));
            }
            if (his.charAt(i) == ':') {
              p_end = true;
            }
          }
          sb.deleteCharAt(sb.length() - 1);
          D_MAIN.appendDispCont(" " + sb.toString());
        }
        switchDisplayable(null, D_MAIN);
        D_MAIN.repaint();
      }
    } else if (displayable == l_vars) {
      if (command == List.SELECT_COMMAND) {

        l_varsAction();

      } else if (command == c_canvas) {
        switchDisplayable(null, D_MAIN);

      } else if (command == c_delvar) {
        try {
          StringBuffer sb = new StringBuffer();
          String his = l_vars.getString(l_vars.getSelectedIndex());
          for (int i = 0; i < his.length(); i++) {
            if (his.charAt(i) == '=') {
              break;
            }
            sb.append(his.charAt(i));
          }
          D_MAIN.deletevar(sb.toString().trim());
          l_vars.delete(l_vars.getSelectedIndex());
        } catch (error er) {
          switchDisplayable(null, getA_error());
          a_error.setString(er.getMessage());
        }

      } else if (command == c_insert) {
        StringBuffer sb = new StringBuffer();
        String his = l_vars.getString(l_vars.getSelectedIndex());
        for (int i = 0; i < his.length(); i++) {
          if (his.charAt(i) == '=') {
            break;
          }
          sb.append(his.charAt(i));
        }
        D_MAIN.appendDispCont(sb.toString());
        switchDisplayable(null, D_MAIN);

        D_MAIN.repaint();
      }
    }
  }
Esempio n. 2
0
  public KeyBindingsScreen(final Display display) {

    super("Key Bindings", IMPLICIT);

    this.display = display;

    keyBindings = KeyBindings.getInstance();

    screenKeyBinder = new KeyBinderScreen(this);

    addCommand(CMD_RESET);
    setCommandListener(this);

    for (int i = 0; i < KeyBindings.actionNames.length; i++) append("", null);
    updateList();

    alertKeyConflict = new Alert("Key already in use!");
    alertKeyConflict.setType(AlertType.WARNING);
    alertKeyConflict.setTimeout(Alert.FOREVER);
    alertKeyConflict.addCommand(CMD.NO);
    alertKeyConflict.addCommand(CMD.YES);
    alertKeyConflict.setCommandListener(this);

    alertReset = new Alert("Please confirm:");
    alertReset.setString("Reset to default key bindings?");
    alertReset.setType(AlertType.WARNING);
    alertReset.addCommand(CMD.NO);
    alertReset.addCommand(CMD.YES);
    alertReset.setCommandListener(this);
  }
Esempio n. 3
0
  public void showException(Exception e) {
    Alert alert = new Alert("Error");
    alert.setString(e.getMessage());
    alert.setType(AlertType.ERROR);
    alert.setTimeout(Alert.FOREVER);

    display.setCurrent(alert);
  }
Esempio n. 4
0
 /**
  * Create a new Alert with the specified title, text, image, and alert type.
  *
  * @param title the title string
  * @param text the text string
  * @param image the image
  * @param type the alert type
  */
 public Alert(String title, String text, Image image, AlertType type) {
   super(title);
   construct();
   this.type = type;
   setImage(image);
   setString(text);
   setTimeout(getDefaultTimeout());
   super.addCommand(DISMISS_COMMAND);
   super.setCommandListener(implicitListener);
 }
Esempio n. 5
0
 /**
  * Sets the type of the Alert.
  *
  * @param type an AlertType or null if it doesn't have a specific type
  */
 public void setType(AlertType type) {
   this.type = type;
   if (text == null) {
     // show default text
     setString(text);
   }
   if (image == null) {
     // show default image
     setImage(image);
   }
 }
Esempio n. 6
0
 /** Notify a success event */
 public void notifySuccess(String message) {
   if (mActiveAlert != null) {
     if (mProgressActive) {
       System.out.println("Final progress message");
       mActiveAlert.setTitle("Info");
       mActiveAlert.setString(message);
       mActiveAlert.setIndicator(null);
       mProgressActive = false;
     } else {
       waitForNoAlert();
       mActiveAlert = null;
     }
   }
   if (mActiveAlert == null) {
     mActiveAlert = mController.showInfo(message);
     mActiveAlert.setCommandListener(this);
     mAlertDisplayed = true;
   }
 }
Esempio n. 7
0
 /** Notify an error event inluding a possible message and exception object */
 public void notifyError(String message, Throwable th) {
   String lErrorMsg = (th != null ? th.toString() : "");
   if (mActiveAlert != null) {
     if (mProgressActive) {
       mActiveAlert.setTitle("Error");
       mActiveAlert.setString(message + "\n" + lErrorMsg);
       mActiveAlert.setIndicator(null);
       mProgressActive = false;
     } else {
       waitForNoAlert();
       mActiveAlert = null;
     }
   }
   if (mActiveAlert == null) {
     mActiveAlert = mController.showError(message + "\n" + lErrorMsg);
     mActiveAlert.setCommandListener(this);
     mAlertDisplayed = true;
     if (mListener != null) {
       mListener.notifyError();
     }
   }
 }
Esempio n. 8
0
 public void commandAction(Command command, Displayable displayable) {
   if (command == cmdSave) {
     State.user = textUser.getString();
     State.password = textPass.getString();
     int period = Integer.parseInt(textPeriod.getString());
     if (period < 1) period = 1;
     State.connectionPeriod = period * 1000;
     try {
       Tools.updateRecord(RecordTypes.USER, State.user);
       Tools.updateRecord(RecordTypes.PASSWORD, State.password);
       Tools.updateRecord(RecordTypes.CONNECTIONPERIOD, Integer.toString(State.connectionPeriod));
     } catch (RecordStoreException rse) {
       Alert alertScreen = new Alert("Error");
       alertScreen.setString("There was an error storing the data");
       alertScreen.setTimeout(Alert.FOREVER);
     }
     State.display.setCurrent(mainForm);
   }
   if (command == cmdCancel) {
     State.display.setCurrent(mainForm);
   }
 }
Esempio n. 9
0
  public void keyPressed(int key) {

    int actionOld;
    String keyName;

    if (key == 0 || key == keyBindings.getKeyForAction(actionToBind)) {

      display.setCurrent(this);

    } else if (keyBindings.isBound(key)) {

      selectedKey = key;

      actionOld = keyBindings.getActionForKey(key);
      keyName = screenKeyBinder.getKeyName(key);

      msgKeyConflict.delete(0, msgKeyConflict.length());
      msgKeyConflict.append("Key ").append(keyName);
      msgKeyConflict.append(" is already in use for '");
      msgKeyConflict.append(KeyBindings.actionNames[actionOld]).append("'.");
      msgKeyConflict.append("\nDo you want to unset it from '");
      msgKeyConflict.append(KeyBindings.actionNames[actionOld]);
      msgKeyConflict.append("' and use it for '");
      msgKeyConflict.append(KeyBindings.actionNames[actionToBind]).append("' ?");
      alertKeyConflict.setString(msgKeyConflict.toString());

      display.setCurrent(alertKeyConflict);

    } else { // key is valid and free

      keyBindings.bindKeyToAction(actionToBind, key);

      updateList(actionToBind);

      display.setCurrent(this);
    }
  }
 public void showAlert(String title, String msg, Displayable next) {
   Alert alert = new Alert(title);
   alert.setString(msg);
   _manager.next(alert, next);
 }
Esempio n. 11
0
 public void displayAlert(String errorMessage, Form nextForm, MIDlet midlet) {
   image = null;
   alert.setString(errorMessage);
   alert.setTimeout(ConstantHelper.ALERT_TIMEOUT);
   Display.getDisplay(midlet).setCurrent(alert, nextForm);
 }
Esempio n. 12
0
  /** Respond to a commands issued on any Screen */
  public void commandAction(Command c, Displayable s) {
    if (c == undoCommand) {
      canvas.undoMove();
    } else if (c == restartCommand) {
      canvas.restartLevel();
    } else if (c == levelCommand) {
      levelScreen = canvas.getLevelScreen();
      levelScreen.addCommand(okCommand);
      levelScreen.setCommandListener(this);
      display.setCurrent(levelScreen);
    } else if ((c == okCommand) && (s == levelScreen)) {
      if (!canvas.gotoLevel()) {
        alert.setString("Could not load level");
        display.setCurrent(alert, canvas);
      } else {
        display.setCurrent(canvas);
      }
    } else if (c == scoresCommand) {
      scoreScreen = canvas.getScoreScreen();
      scoreScreen.addCommand(okCommand);
      scoreScreen.setCommandListener(this);
      display.setCurrent(scoreScreen);
    } else if ((c == okCommand) && (s == scoreScreen)) {
      display.setCurrent(canvas);
    } else if (c == exitCommand) {
      destroyApp(false);
      notifyDestroyed();
    } else if ((c == List.SELECT_COMMAND) && (s == canvas)) {
      // Solved the level
      scoreScreen = canvas.getScoreScreen();
      scoreScreen.addCommand(okCommand);
      scoreScreen.setCommandListener(this);
      display.setCurrent(scoreScreen);

      // Read the next screen.
      canvas.nextLevel(1);
    } else if (c == nextCommand) {
      if (!canvas.nextLevel(1)) {
        alert.setString("Could not load level " + (canvas.getLevel() + 1));
        display.setCurrent(alert, canvas);
      } else {
        display.setCurrent(canvas);
      }

      if (s == canvas) {
        canvas.repaint();
      }
    } else if (c == prevCommand) {
      if (!canvas.nextLevel(-1)) {
        alert.setString("Could not load level " + (canvas.getLevel() - 1));
        display.setCurrent(alert, canvas);
      } else {
        display.setCurrent(canvas);
      }

      if (s == canvas) {
        canvas.repaint();
      }
    } else if (c == themeCommand) {
      canvas.changeTheme();
    }
  }