int getLineLength(int y) {
   try {
     return ((StringBuffer) vectorLines.elementAt(y)).length();
   } catch (Exception ex) {
     System.out.println(ex.toString() + " in getLineLength()");
     return 0;
   }
 }
 StringBuffer getLine(int y) {
   try {
     return (StringBuffer) vectorLines.elementAt(y);
   } catch (Exception ex) {
     System.out.println(ex.toString() + " in getLine()");
     return new StringBuffer("");
   }
 }
 boolean addNewLine(int y) {
   try {
     vectorLines.insertElementAt(new StringBuffer(""), y);
     return true;
   } catch (Exception ex) {
     System.out.println(ex.toString());
     return false;
   }
 }
 boolean removeLine(int y) {
   try {
     vectorLines.removeElementAt(y);
     return true;
   } catch (Exception ex) {
     System.out.println(ex.toString() + " in removeLine()");
     return false;
   }
 }
 boolean setLine(int y, StringBuffer stringBuffer) {
   try {
     vectorLines.setElementAt(stringBuffer, y);
     return true;
   } catch (Exception ex) {
     System.out.println(ex.toString() + " in setLine()");
     return false;
   }
 }
  boolean copyLine(int sourceY, int destinationY) {
    try {
      // getLine
      StringBuffer currentLine = (StringBuffer) vectorLines.elementAt(sourceY);
      // setLine
      vectorLines.setElementAt(currentLine, destinationY);

      return true;
    } catch (Exception ex) {
      System.out.println(ex.toString() + " in copyLine()");
      return false;
    }
  }
  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;
    }
  }
  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;
    }
  }
示例#9
0
  /** Save the URL setting the user entered in to the urlTextBox. */
  private void saveURLSetting() {
    String temp;
    Exception ex;

    temp = urlTextBox.getString();

    ex = GraphicalInstaller.saveSettings(temp, MIDletSuite.INTERNAL_SUITE_ID);
    if (ex != null) {
      displayException(Resource.getString(ResourceConstants.EXCEPTION), ex.toString());
      return;
    }

    defaultInstallListUrl = temp;

    displaySuccessMessage(Resource.getString(ResourceConstants.AMS_MGR_SAVED));
  }
示例#10
0
  boolean shiftDown(int y) {
    try {
      addNewLine(getLinesCount() + 1 - 1);

      // tricky! -1 because of beginning from 0, -1 because next line, -1 because getLinesCount() is
      // already updated (+1)
      for (int sourceY = getLinesCount() - 2; sourceY >= y; sourceY--) // -1
      {
        copyLine(sourceY, sourceY + 1);
      }

      return true;
    } catch (Exception ex) {
      System.out.println(ex.toString() + " in shiftDown()");
      return false;
    }
  }
示例#11
0
  /** Ask the user for the URL. */
  private void getUrl() {
    try {
      if (urlTextBox == null) {
        urlTextBox =
            new TextBox(
                Resource.getString(ResourceConstants.AMS_DISC_APP_WEBSITE_INSTALL),
                defaultInstallListUrl,
                1024,
                TextField.ANY);
        urlTextBox.addCommand(endCmd);
        urlTextBox.addCommand(saveCmd);
        urlTextBox.addCommand(discoverCmd);
        urlTextBox.setCommandListener(this);
      }

      display.setCurrent(urlTextBox);
    } catch (Exception ex) {
      displayException(Resource.getString(ResourceConstants.EXCEPTION), ex.toString());
    }
  }
示例#12
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;
    }
  }
示例#13
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);
    }
  }
示例#14
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;
    }
  }
  public void run_1720() {
    FileConnection conn1 = null;
    int counter = 0;
    try {
      // 1 Opening a file.
      conn1 =
          (FileConnection)
              Connector.open(
                  "file:///" + iRoot + "mainTestDir/test170/readOnly.txt", Connector.READ_WRITE);
      counter = 1;
      InputStream stream = conn1.openInputStream();
      counter = 3;
      byte[] byteArray1 = new byte[500];
      int retValue = stream.read(byteArray1);
      counter = 4;
      if (retValue != 500) throw new TestFailedException("retValue: " + retValue);
      counter = 5;
      for (int i = 0; i < retValue; ++i) {
        if (byteArray1[i] != 56)
          throw new TestFailedException("byteArray1[i]: " + byteArray1[i] + "i: " + i);
      }
      conn1.setHidden(true);
      conn1.setHidden(true);
      counter = 6;
      boolean hiddenFlag = conn1.isHidden();
      if (hiddenFlag == false) throw new TestFailedException();
      counter = 7;
      try {
        stream.read(byteArray1);
        throw new TestFailedException();
      } catch (IOException ex) {
      }

      // Re-opening a InputStream.
      stream = conn1.openInputStream();
      counter = 71;
      byte[] byteArray12 = new byte[1601];
      retValue = stream.read(byteArray12);
      counter = 72;
      if (retValue != 1600) throw new TestFailedException("retValue: " + retValue);
      counter = 73;
      for (int i = 0; i < retValue; ++i) {
        if (byteArray12[i] != 56)
          throw new TestFailedException("byteArray12[i]: " + byteArray12[i] + "i: " + i);
      }
      stream.close();
      conn1.close();

      // 2 Re-open a file.
      conn1 =
          (FileConnection)
              Connector.open(
                  "file:///" + iRoot + "mainTestDir/test170/readOnly.txt", Connector.READ_WRITE);
      counter = 8;
      stream = conn1.openInputStream();
      counter = 9;
      byteArray1 = new byte[500];
      retValue = stream.read(byteArray1);
      counter = 10;
      if (retValue != 500) throw new TestFailedException("retValue: " + retValue);
      counter = 11;
      for (int i = 0; i < retValue; ++i) {
        if (byteArray1[i] != 56)
          throw new TestFailedException("byteArray1[i]: " + byteArray1[i] + "i: " + i);
      }
      counter = 12;
      conn1.setHidden(true);
      byte[] byteArray2 = new byte[1200];
      retValue = stream.read(byteArray2);
      counter = 13;
      if (retValue != 1100) throw new TestFailedException("retValue: " + retValue);
      counter = 14;
      for (int i = 0; i < retValue; ++i) {
        if (byteArray2[i] != 56)
          throw new TestFailedException("byteArray2[i]: " + byteArray2[i] + "i: " + i);
      }
      stream.close();
      conn1.close();

      // 3 Re-open a file.
      conn1 =
          (FileConnection)
              Connector.open(
                  "file:///" + iRoot + "mainTestDir/test170/readOnly.txt", Connector.READ_WRITE);
      stream = conn1.openInputStream();
      counter = 15;
      byteArray1 = new byte[500];
      retValue = stream.read(byteArray1);
      counter = 16;
      if (retValue != 500) throw new TestFailedException("retValue: " + retValue);
      counter = 17;
      for (int i = 0; i < retValue; ++i) {
        if (byteArray1[i] != 56)
          throw new TestFailedException("byteArray1[i]: " + byteArray1[i] + "i: " + i);
      }
      counter = 18;
      System.out.println(" Test 1720: COunter 8");
      conn1.setHidden(false);
      hiddenFlag = conn1.isHidden();
      if (hiddenFlag == true) throw new TestFailedException();
      counter = 19;
      try {
        stream.read(byteArray1);
        throw new TestFailedException();
      } catch (IOException ex) {
      }
      stream.close();
      conn1.close();

      assertTrue(" run_1720() ok ", true);
    } catch (Exception ex) {
      append(ex.toString());
      append("TEST FAILED!!! Case: run_1720() counter: " + counter + "\n");
      assertTrue(" run_1720() FAILED!!! Counter: " + counter, false);
    }
  }
  public void run_0420() {
    FileConnection conn1 = null;
    int counter = 0;
    try {
      // Make a connection to the new file.
      conn1 =
          (FileConnection)
              Connector.open(
                  "file:///" + iRoot + "mainTestDir/test040/new042File.txt", Connector.READ_WRITE);
      counter = 1;
      System.out.println(" run_0420: counter = 1 ");
      if (conn1.exists()) throw new TestFailedException();
      counter = 2;
      System.out.println(" run_0420: counter = 2 ");
      conn1.create();
      counter = 3;
      System.out.println(" run_0420: counter = 3 ");
      OutputStream stream = conn1.openOutputStream();
      counter = 4;
      System.out.println(" run_0420: counter = 4 ");
      byte[] byteArray1 = new byte[50];
      for (int i = 0; i < byteArray1.length; ++i) byteArray1[i] = 55;
      counter = 5;
      System.out.println(" run_0420: counter = 5 ");
      stream.write(byteArray1);
      stream.close();
      counter = 6;
      System.out.println(" run_0420: counter = 6 ");
      // Re-open an OutputStream.
      stream = conn1.openOutputStream(conn1.fileSize());
      counter = 7;
      System.out.println(" run_0420: counter = 7 ");
      for (int i = 0; i < byteArray1.length; ++i) byteArray1[i] = 56;
      conn1.close();
      counter = 8;
      stream.write(byteArray1);
      counter = 9;
      stream.close();

      System.out.println(" Going to second part of run_0420");

      // Re-open a connection.
      conn1 =
          (FileConnection)
              Connector.open(
                  "file:///" + iRoot + "mainTestDir/test040/new042File.txt", Connector.READ_WRITE);
      counter = 10;
      System.out.println(" run_0420: counter = 10 ");
      if (!conn1.exists()) throw new TestFailedException();
      counter = 11;
      System.out.println(" run_0420: counter = 11 ");
      InputStream inStream = conn1.openInputStream();
      counter = 12;
      System.out.println(" run_0420: counter = 12 ");
      byte[] byteArray2 = new byte[110];
      int retValue = inStream.read(byteArray2);
      if (retValue != 100) throw new TestFailedException("retValue: " + retValue);
      counter = 13;
      System.out.println(" run_0420: counter = 13 ");
      for (int i = 0; i < retValue; ++i) {
        if (i < 50) {
          if (byteArray2[i] != 55)
            throw new TestFailedException("i: " + i + " byteArray2[i]: " + byteArray2[i]);
        } else if (i > 49) {
          if (byteArray2[i] != 56)
            throw new TestFailedException("i: " + i + " byteArray2[i]: " + byteArray2[i]);
        }
      } // end for
      counter = 14;
      conn1.close();
      inStream.close();

      assertTrue(" run_0420() ok ", true);
    } catch (Exception ex) {
      append(ex.toString());
      append("TEST FAILED!!! Case: run_0420() counter: " + counter + "\n");
      assertTrue(" run_0420() FAILED!!! Counter: " + counter, false);
    }
  } // end run_0420()