Ejemplo n.º 1
1
  public void startApp() {
    // Create Record Store
    try {
      rs = RecordStore.openRecordStore("myrs", true);
    } catch (RecordStoreException e) {
    }

    dsp = Display.getDisplay(this);
    listMenu.setCommandListener(this);
    listMenu.addCommand(cmdExit);
    dsp.setCurrent(listMenu);
  }
Ejemplo n.º 2
1
  public void commandAction(Command c, Displayable d) {

    if (c == List.SELECT_COMMAND) {
      List down = (List) dsp.getCurrent();
      String title = down.getTitle();

      if (title.equals("Menu:")) {
        switch (down.getSelectedIndex()) {
          case 0:
            {
              System.out.println("Stisknul jsi " + down.getString(down.getSelectedIndex()));
              addRecordForm();
              break;
            }
          case 1:
            {
              System.out.println("Stisknul jsi " + down.getString(down.getSelectedIndex()));
              showAllRecordForm();
              break;
            }
          case 2:
            {
              System.out.println("Stisknul jsi " + down.getString(down.getSelectedIndex()));
              showFirstRecord();
              break;
            }
          case 3:
            {
              System.out.println("Stisknul jsi " + down.getString(down.getSelectedIndex()));
              getNumberRecord();
              break;
            }
          case 4:
            {
              System.out.println("Stisknul jsi " + down.getString(down.getSelectedIndex()));
              editRecord(1);
              break;
            }
        }
      }
    }

    if (c == cmdExit) {
      // rs.closeRecordStore();
      notifyDestroyed();
    }
    if (c == cmdMenu) {
      dsp.setCurrent(listMenu);
    }
    if (c == cmdEdit) {
      ByteArrayOutputStream buffer = new ByteArrayOutputStream();
      // filtr; filtr dostane pri vytvoreni stream jako parametr;
      // format dat nezavisly na platforme
      // definuje metodu write() pro vsechny primitivni typy
      DataOutputStream dout = new DataOutputStream(buffer);
      // byte [] data = txf.getString().getBytes();
      try {
        dout.writeUTF(txfName.getString());
        dout.writeInt(Integer.valueOf(txfNumber.getString()).intValue());
        txfName.delete(0, txfName.size());
        txfNumber.delete(0, txfNumber.size());
        // zapise buffer do streamu
        dout.flush();
        // prevod ByteArrayOutputStream na pole bytu;
        byte[] b = buffer.toByteArray();
        rs.setRecord(1, b, 0, b.length);
      } catch (Exception e) {
      } finally {
        try {
          dout.close();
        } catch (Exception e2) {
        }
      }
    }
    if (c == cmdAdd) {
      // vystupni stream; zapisuje do buferu v pamžti
      ByteArrayOutputStream buffer = new ByteArrayOutputStream();
      // filtr; filtr dostane pri vytvoreni stream jako parametr;
      // format dat nezavisly na platforme
      // definuje metodu write() pro vsechny primitivni typy
      DataOutputStream dout = new DataOutputStream(buffer);
      // byte [] data = txf.getString().getBytes();
      try {
        dout.writeUTF(txfName.getString());
        dout.writeInt(Integer.valueOf(txfNumber.getString()).intValue());
        txfName.delete(0, txfName.size());
        txfNumber.delete(0, txfNumber.size());
        // zapise buffer do streamu
        dout.flush();
        // prevod ByteArrayOutputStream na pole bytu;
        byte[] b = buffer.toByteArray();
        rs.addRecord(b, 0, b.length);
      } catch (Exception e) {
      } finally {
        try {
          dout.close();
        } catch (Exception e2) {
        }
      }
    }
  }
Ejemplo n.º 3
0
  /**
   * Display the connecting form to the user, let call set actions.
   *
   * @param action action to put in the form's title
   * @param name name to in the form's title
   * @param url URL of a JAD
   * @param size 0 if unknown, else size of object to download in K bytes
   * @param gaugeLabel label for progress gauge
   * @return displayed form
   */
  private Form displayProgressForm(
      String action, String name, String url, int size, String gaugeLabel) {
    Gauge progressGauge;
    StringItem urlItem;

    progressForm = new Form(null);

    progressForm.setTitle(action + " " + name);

    if (size <= 0) {
      progressGauge = new Gauge(gaugeLabel, false, Gauge.INDEFINITE, Gauge.CONTINUOUS_RUNNING);
    } else {
      progressGauge = new Gauge(gaugeLabel, false, size, 0);
    }

    progressGaugeIndex = progressForm.append(progressGauge);

    if (url == null) {
      urlItem = new StringItem("", "");
    } else {
      urlItem = new StringItem(Resource.getString(ResourceConstants.AMS_WEBSITE) + ": ", url);
    }

    progressUrlIndex = progressForm.append(urlItem);

    display.setCurrent(progressForm);
    lastDisplayChange = System.currentTimeMillis();

    return progressForm;
  }
Ejemplo n.º 4
0
  public void showAllRecordForm() {
    fmAllRecords = new Form("All records");
    try {
      RecordEnumeration recEnum = rs.enumerateRecords(null, null, false);
      while (recEnum.hasNextElement()) {
        try {
          // System.out.println(new String(recEnum.nextRecord()));
          String name = "Nenacetl jsem";
          int number = 0;
          try {
            byte[] record = recEnum.nextRecord();
            ByteArrayInputStream buffer = new ByteArrayInputStream(record);
            DataInputStream dis = new DataInputStream(buffer);
            name = dis.readUTF();
            number = dis.readInt();
            dis.close();
          } catch (Exception e) {
          }

          fmAllRecords.append(name + " " + String.valueOf(number) + "\n");
        } catch (Exception e) {
          System.out.println(e.getMessage());
        }

        //
      }
    } catch (Exception ex) {
      System.out.println(ex.getMessage());
    }
    fmAllRecords.addCommand(cmdMenu);
    fmAllRecords.setCommandListener(this);
    dsp.setCurrent(fmAllRecords);
  }
Ejemplo n.º 5
0
  /**
   * Display an exception to the user, with a done command.
   *
   * @param title exception form's title
   * @param message exception message
   */
  private void displayException(String title, String message) {
    Alert a = new Alert(title, message, null, AlertType.ERROR);

    a.setTimeout(Alert.FOREVER);
    a.setCommandListener(this);

    display.setCurrent(a);
  }
Ejemplo n.º 6
0
  /**
   * Create and initialize a new discovery application MIDlet. The saved URL is retrieved and the
   * list of MIDlets are retrieved.
   */
  public DiscoveryApp() {
    String storageName;

    display = Display.getDisplay(this);

    GraphicalInstaller.initSettings();
    restoreSettings();

    // get the URL of a list of suites to install
    getUrl();
  }
Ejemplo n.º 7
0
 public void addRecordForm() {
   fmAddRecord = new Form("Add Record");
   txfName = new TextField("Name", "", 10, TextField.ANY);
   txfNumber = new TextField("Number", "", 10, TextField.NUMERIC);
   fmAddRecord.append(txfName);
   fmAddRecord.append(txfNumber);
   fmAddRecord.addCommand(cmdAdd);
   fmAddRecord.addCommand(cmdMenu);
   fmAddRecord.setCommandListener(this);
   dsp.setCurrent(fmAddRecord);
 }
Ejemplo n.º 8
0
 public void getNumberRecord() {
   fmNumbers = new Form("Number of Records");
   int number = 0;
   try {
     number = rs.getNumRecords();
   } catch (Exception e) {
   }
   fmNumbers.append("Numbers of Records: " + number);
   dsp.setCurrent(fmNumbers);
   fmNumbers.setCommandListener(this);
   fmNumbers.addCommand(cmdMenu);
 }
Ejemplo n.º 9
0
 /**
  * Respond to a command issued on any Screen.
  *
  * @param c command activated by the user
  * @param s the Displayable the command was on.
  */
 public void commandAction(Command c, Displayable s) {
   if (c == discoverCmd) {
     // user wants to discover the suites that can be installed
     discoverSuitesToInstall(urlTextBox.getString());
   } else if (s == installListBox && (c == List.SELECT_COMMAND || c == installCmd)) {
     installSuite(installListBox.getSelectedIndex());
   } else if (c == backCmd) {
     display.setCurrent(urlTextBox);
   } else if (c == saveCmd) {
     saveURLSetting();
   } else if (c == endCmd || c == Alert.DISMISS_COMMAND) {
     // goto back to the manager midlet
     notifyDestroyed();
   }
 }
Ejemplo n.º 10
0
  /**
   * Alert the user that an action was successful.
   *
   * @param successMessage message to display to user
   */
  private void displaySuccessMessage(String successMessage) {
    Image icon;
    Alert successAlert;

    icon = GraphicalInstaller.getImageFromInternalStorage("_dukeok8");

    successAlert = new Alert(null, successMessage, icon, null);

    successAlert.setTimeout(GraphicalInstaller.ALERT_TIMEOUT);

    // We need to prevent "flashing" on fast development platforms.
    while (System.currentTimeMillis() - lastDisplayChange < GraphicalInstaller.ALERT_TIMEOUT) ;

    lastDisplayChange = System.currentTimeMillis();
    display.setCurrent(successAlert);
  }
Ejemplo n.º 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());
    }
  }
Ejemplo n.º 12
0
  public void showFirstRecord() {
    fmFirstRecord = new Form("First Record");
    String name = "Nenacetl jsem";
    int number = 0;
    try {
      byte[] record = rs.getRecord(1);
      ByteArrayInputStream buffer = new ByteArrayInputStream(record);
      DataInputStream dis = new DataInputStream(buffer);
      name = dis.readUTF();
      number = dis.readInt();
      dis.close();
    } catch (Exception e) {
    }

    fmFirstRecord.append(name + " " + String.valueOf(number));
    // fmFirstRecord.append(String.valueOf(number));
    fmFirstRecord.setCommandListener(this);
    fmFirstRecord.addCommand(cmdMenu);
    dsp.setCurrent(fmFirstRecord);
  }
Ejemplo n.º 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);
    }
  }
Ejemplo n.º 14
0
 public void editRecord(int record_num) {
   fmEditRecord = new Form("Edit Record");
   String name = "Nenacetl jsem";
   int number = 0;
   try {
     byte[] record = rs.getRecord(record_num);
     ByteArrayInputStream buffer = new ByteArrayInputStream(record);
     DataInputStream dis = new DataInputStream(buffer);
     name = dis.readUTF();
     number = dis.readInt();
     dis.close();
   } catch (Exception e) {
   }
   txfName = new TextField("Name", name, 10, TextField.ANY);
   txfNumber = new TextField("Number", String.valueOf(number), 10, TextField.NUMERIC);
   fmEditRecord.append(txfName);
   fmEditRecord.append(txfNumber);
   fmEditRecord.addCommand(cmdEdit);
   fmEditRecord.addCommand(cmdMenu);
   fmEditRecord.setCommandListener(this);
   dsp.setCurrent(fmEditRecord);
 }