Exemplo 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();
      }
    }
  }
Exemplo n.º 2
0
  private void getTrafficSpots() {
    controller.showProgressBar();
    String uploadWebsite =
        "http://" + controller.selectedCity.URL + "/php/trafficstatus.cache?dummy=ert43";
    String[] ArrayOfData = null;
    StreamConnection c = null;
    InputStream s = null;
    StringBuffer b = new StringBuffer();

    String url = uploadWebsite;
    System.out.print(url);
    try {
      c = (StreamConnection) Connector.open(url);
      s = c.openDataInputStream();
      int ch;
      int k = 0;
      while ((ch = s.read()) != -1) {
        System.out.print((char) ch);
        b.append((char) ch);
      }
      // System.out.println("b"+b);
      try {
        JSONObject ff1 = new JSONObject(b.toString());
        String data1 = ff1.getString("locations");
        JSONArray jsonArray1 = new JSONArray(data1);
        Vector TrafficStatus = new Vector();
        for (int i = 0; i < jsonArray1.length(); i++) {

          System.out.println(jsonArray1.getJSONArray(i).getString(3));
          double aDoubleLat = Double.parseDouble(jsonArray1.getJSONArray(i).getString(1));
          double aDoubleLon = Double.parseDouble(jsonArray1.getJSONArray(i).getString(2));
          System.out.println(aDoubleLat + " " + aDoubleLon);
          TrafficStatus.addElement(
              new LocationPointer(
                  jsonArray1.getJSONArray(i).getString(3),
                  (float) aDoubleLon,
                  (float) aDoubleLat,
                  1,
                  true));
        }
        controller.setCurrentScreen(controller.TrafficSpots(TrafficStatus));
      } catch (Exception E) {
        controller.setCurrentScreen(traf);
        new Thread() {
          public void run() {
            controller.showAlert("Error in network connection.", Alert.FOREVER, AlertType.INFO);
          }
        }.start();
      }

    } catch (Exception e) {

      controller.setCurrentScreen(traf);
      new Thread() {
        public void run() {
          controller.showAlert("Error in network connection.", Alert.FOREVER, AlertType.INFO);
        }
      }.start();
    }
  }
Exemplo n.º 3
0
  public void setText(String text) {
    vectorLines.removeAllElements();

    char[] chars = text.toCharArray();

    StringBuffer stringBuffer = new StringBuffer("");

    for (int i = 0; i < chars.length; i++) {
      if (chars[i] == '\n' || chars[i] == '\r') {
        if (chars[i] == '\n') {
          vectorLines.addElement(stringBuffer);

          stringBuffer = new StringBuffer();
        }
        continue;
      }

      stringBuffer.append(chars[i]); // probably bug fixed?

      if (i == chars.length - 1) {
        vectorLines.addElement(stringBuffer);
      }
    }

    if (chars.length == 0) {
      vectorLines.addElement(stringBuffer);
    }

    setCursorPosition(0, 0);
    updateCaretPosition();
  }
Exemplo n.º 4
0
  public void setText(String text, int x, int y) {
    if (text.indexOf('\n') == -1) {
      if (!addToLine(x, y, new StringBuffer(text))) {
        return;
      }

      setCursorPosition(x + text.length(), y);
      updateCaretPosition();
    } else {
      if (!divideLine(x, y)) {
        return;
      }

      String firstLine = text.substring(0, text.indexOf('\n'));

      if (!addToLine(x, y, new StringBuffer(firstLine))) {
        return;
      }

      text = text.substring(text.indexOf('\n') + 1);

      char[] chars = text.toCharArray();

      StringBuffer stringBuffer = new StringBuffer("");

      for (int i = 0; i < chars.length; i++) {
        if (chars[i] == '\n' || chars[i] == '\r') {
          if (chars[i] == '\n') {
            y++;

            if (!divideLine(0, y)) {
              return;
            }

            setLine(y, stringBuffer);

            stringBuffer = new StringBuffer();
          }
          continue;
        }

        stringBuffer.append(chars[i]);

        if (i == chars.length - 1) {
          y++;
          addToLine(0, y, stringBuffer);
          setCursorPosition(stringBuffer.toString().length(), y);
        }
      }

      updateCaretPosition();
    }
  }
Exemplo n.º 5
0
  boolean removeFromLine(int xFrom, int xTo, int y) {
    try {
      // getLine
      StringBuffer currentLine = (StringBuffer) vectorLines.elementAt(y);

      currentLine.delete(xFrom, xTo);
      // setLine
      vectorLines.setElementAt(currentLine, y);
      return true;
    } catch (Exception ex) {
      System.out.println(ex.toString() + " in removeFromLine()");
      return false;
    }
  }
Exemplo n.º 6
0
  boolean updateToLine(int x, int y, char ch) {
    try {
      // getLine
      StringBuffer currentLine = (StringBuffer) vectorLines.elementAt(y);

      currentLine.setCharAt(x - 1, ch);
      // setLine
      vectorLines.setElementAt(currentLine, y);

      return true;
    } catch (Exception ex) {
      System.out.println(ex.toString() + " in updateToLine()");
      return false;
    }
  }
Exemplo n.º 7
0
 public static String URLdecode(String str) {
   StringBuffer result = new StringBuffer();
   int l = str.length();
   for (int i = 0; i < l; ++i) {
     char c = str.charAt(i);
     if (c == '%' && i + 2 < l) {
       char c1 = str.charAt(i + 1);
       char c2 = str.charAt(i + 2);
       if (isHexit(c1) && isHexit(c2)) {
         result.append((char) (hexit(c1) * 16 + hexit(c2)));
         i += 2;
       } else result.append(c);
     } else result.append(c);
   }
   return result.toString();
 }
Exemplo n.º 8
0
  public void removeCharacter() {
    int x = getCursorX();
    int y = getCursorY();

    if (x != 0) // not first cursor position
    {
      if (removeFromLine(x, y)) {
        if (y != 0) // not first line
        {
          /*
          if(isEmptyLine(y))
          {
          	if(removeLine(y))
          	{
          		int maxX = getLineLength(y-1);
          		setCursorPosition(maxX, y-1);
          	}
          }
          else
          {
          */
          setCursorPosition(x - 1, y);
          /* } */
        } else {
          setCursorPosition(x - 1, y);
        }
      }
    } else {
      if (y != 0) // not beginning of the document
      {
        if (isEmptyLine(y)) {
          if (removeLine(y)) {
            int maxX = getLineLength(y - 1);
            setCursorPosition(maxX, y - 1);
          }
        } else {
          StringBuffer currentLine = getLine(y); // (StringBuffer)vectorLines.elementAt(y);

          if (removeLine(y)) {
            int maxX = getLineLength(y - 1);
            addToLine(maxX, y - 1, currentLine.toString());
            setCursorPosition(maxX, y - 1);
          }
        }
      }
    }
  }
Exemplo n.º 9
0
  private String[] GetDataFromSite() {

    String uploadWebsite = "http://" + controller.selectedCity.URL + "/cameras/mobile_cam_list.php";
    String[] ArrayOfData = null;
    StreamConnection c = null;
    InputStream s = null;
    StringBuffer b = new StringBuffer();

    String url = uploadWebsite;
    System.out.print(url);
    try {
      c = (StreamConnection) Connector.open(url);
      s = c.openDataInputStream();
      int ch;
      int k = 0;
      while ((ch = s.read()) != -1) {
        System.out.print((char) ch);
        b.append((char) ch);
      }

      String result = b.toString();
      if (!result.equals("")) {

        ArrayOfData = StringUtil.split(result.toString().trim(), "~~");
        if (ArrayOfData.length == 0) {
          controller.MainMenu();
          new Thread() {
            public void run() {
              controller.showAlert("Network Error", 0, AlertType.ERROR);
            }
          }.start();
        }
      }
    } catch (Exception e) {
      System.out.print(e);
      new Thread() {
        public void run() {
          controller.showProgressBar();
        }
      }.start();
      // controller.getDisp().setCurrent(this);

    }

    return ArrayOfData;
  }
  public void commandAction(Command c, Displayable d) {
    if (c == cmdCancel) {
      destroyView();
    }
    // if (c==cmdBookmarks) { new Bookmarks(display, null); }
    if (c == cmdJoin || c == cmdAdd) {
      String nick = nickField.getString().trim();
      String host = hostField.getString().trim();
      String room = roomField.getString().trim();
      String pass = passField.getString();
      int msgLimit = msgLimitField.getValue();

      if (nick.length() == 0) return;
      if (room.length() == 0) return;
      if (host.length() == 0) return;
      StringBuffer gchat = new StringBuffer(room.trim());
      gchat.append('@');
      gchat.append(host.trim());
      // sd.roster.mucContact(gchat.toString(), Contact.ORIGIN_GROUPCHAT);
      if (c == cmdAdd) new Bookmarks(display, new BookmarkItem(gchat.toString(), nick, pass));
      else {
        try {
          gchat.append('/');
          gchat.append(nick);
          join(gchat.toString(), pass, msgLimit);

          display.setCurrent(sd.roster);
        } catch (Exception e) {
          e.printStackTrace();
          // display.setCurrent(new Alert("Exception", e.toString(), null, AlertType.ERROR),
          // sd.roster);
        }
      }
    }
  }
Exemplo n.º 11
0
  boolean addToLine(int x, int y, char ch) {
    try {
      // getLine
      StringBuffer currentLine = (StringBuffer) vectorLines.elementAt(y);

      currentLine.insert(x, ch);

      if (vectorLines.size() < y) {
        vectorLines.addElement(currentLine);
      } else {
        // setLine
        vectorLines.setElementAt(currentLine, y);
      }

      return true;
    } catch (Exception ex) {
      System.out.println(ex.toString() + " in addToLine()");
      return false;
    }
  }
Exemplo n.º 12
0
  public void itemStateChanged(Item item) {
    if (item == tGrpList) {
      int index = tGrpList.getSelectedIndex();
      if (index == tGrpList.size() - 1) {
        f.set(grpFIndex, tGroup);
      }
      // tGroup.setString(group(index));
    }

    // if (item==tGroup) {
    //    updateChoise(tGroup.getString(), tGrpList);
    // }

    if (item == tTranspList) {
      int index = tTranspList.getSelectedIndex();
      if (index == tTranspList.size() - 1) return;

      String transport = tTranspList.getString(index);

      String jid = tJid.getString();
      StringBuffer jidBuf = new StringBuffer(jid);

      int at = jid.indexOf('@');
      if (at < 0) at = tJid.size();

      jidBuf.setLength(at);
      jidBuf.append('@');
      jidBuf.append(transport);
      tJid.setString(jidBuf.toString());
    }
    if (item == tJid) {
      String s1 = tJid.getString();
      int at = tJid.getString().indexOf('@');
      try {
        updateChoise(s1.substring(at + 1), tTranspList);
      } catch (Exception e) {
      }
    }
  }
Exemplo n.º 13
0
  boolean divideLine(int x, int y) // fire <=> enter + insert when # pressed
      {
    try {
      // getLine
      StringBuffer currentLine = (StringBuffer) vectorLines.elementAt(y);

      String newLine = currentLine.toString().substring(x, currentLine.toString().length());

      currentLine.delete(x, currentLine.length());
      // setLine
      vectorLines.setElementAt(currentLine, y);

      if (shiftDown(y)) {
        vectorLines.setElementAt(new StringBuffer(newLine), y + 1);
      }

      return true;
    } catch (Exception ex) {
      System.out.println(ex.toString() + " in divideLine()");
      return false;
    }
  }
Exemplo n.º 14
0
  /**
   * Install a suite.
   *
   * @param selectedSuite index into the installList
   */
  private void installSuite(int selectedSuite) {
    MIDletStateHandler midletStateHandler = MIDletStateHandler.getMidletStateHandler();
    MIDletSuite midletSuite = midletStateHandler.getMIDletSuite();
    SuiteDownloadInfo suite;
    String displayName;

    suite = (SuiteDownloadInfo) installList.elementAt(selectedSuite);

    midletSuite.setTempProperty(null, "arg-0", "I");
    midletSuite.setTempProperty(null, "arg-1", suite.url);
    midletSuite.setTempProperty(null, "arg-2", suite.label);

    displayName = Resource.getString(ResourceConstants.INSTALL_APPLICATION);
    try {
      midletStateHandler.startMIDlet("com.sun.midp.installer.GraphicalInstaller", displayName);
      /*
       * Give the create MIDlet notification 1 second to get to
       * AMS.
       */
      Thread.sleep(1000);
      notifyDestroyed();
    } catch (Exception ex) {
      StringBuffer sb = new StringBuffer();

      sb.append(displayName);
      sb.append("\n");
      sb.append(Resource.getString(ResourceConstants.ERROR));
      sb.append(": ");
      sb.append(ex.toString());

      Alert a =
          new Alert(
              Resource.getString(ResourceConstants.AMS_CANNOT_START),
              sb.toString(),
              null,
              AlertType.ERROR);
      a.setTimeout(Alert.FOREVER);
      display.setCurrent(a, urlTextBox);
    }
  }
Exemplo n.º 15
0
 /**
  * Encode a string to the "x-www-form-urlencoded" form, enhanced with the UTF-8-in-URL proposal.
  * This is what happens:
  *
  * <ul>
  *   <li>
  *       <p>The ASCII characters 'a' through 'z', 'A' through 'Z', and '0' through '9' remain the
  *       same.
  *   <li>
  *       <p>The space character ' ' is converted into a plus sign '+'.
  *   <li>
  *       <p>All other ASCII characters are converted into the 3-character string "%xy", where xy
  *       is the two-digit hexadecimal representation of the character code
  *   <li>
  *       <p>All non-ASCII characters are encoded in two steps: first to a sequence of 2 or 3
  *       bytes, using the UTF-8 algorithm; secondly each of these bytes is encoded as "%xx".
  * </ul>
  *
  * @param s The string to be encoded
  * @return The encoded string
  */
 public static String URLencode(String s) {
   StringBuffer sbuf = new StringBuffer();
   int len = s.length();
   for (int i = 0; i < len; i++) {
     int ch = s.charAt(i);
     if ('A' <= ch && ch <= 'Z') { // 'A'..'Z'
       sbuf.append((char) ch);
     } else if ('a' <= ch && ch <= 'z') { // 'a'..'z'
       sbuf.append((char) ch);
     } else if ('0' <= ch && ch <= '9') { // '0'..'9'
       sbuf.append((char) ch);
     } else if (ch == ' ') { // space
       sbuf.append('+');
     } else if (ch <= 0x007f) { // other ASCII
       sbuf.append(hex[ch]);
     } else if (ch <= 0x07FF) { // non-ASCII <= 0x7FF
       sbuf.append(hex[0xc0 | (ch >> 6)]);
       sbuf.append(hex[0x80 | (ch & 0x3F)]);
     } else { // 0x7FF < ch <= 0xFFFF
       sbuf.append(hex[0xe0 | (ch >> 12)]);
       sbuf.append(hex[0x80 | ((ch >> 6) & 0x3F)]);
       sbuf.append(hex[0x80 | (ch & 0x3F)]);
     }
   }
   return sbuf.toString();
 }