Пример #1
0
  @Test
  public void testFormAdd() throws Exception {
    Form form = new Form(request);
    assertEquals(0, form.size());

    Button button = Button.button("OK");
    form.add(button);
    assertEquals(1, form.size());

    TextField field = new TextField("name");
    form.add(field, "Name");
    form.add(null); // ignored
    form.add(null, "Name"); // ignored
    assertEquals(2, form.size());
    assertSame(field, form.get(1));
    assertSame(field, form.get("name"));
    assertNull(form.get("x"));
    assertNull(form.get(null));
    try {
      // cannot add twice
      form.add(field);
      fail();
    } catch (IllegalStateException e) {
    }

    form.setRequired(true);
    assertTrue(field.isRequired());
    form.setReadOnly(true);
    assertTrue(field.isReadOnly());

    assertTrue(form.validate(true));

    form.remove(field);
    assertEquals(1, form.size());
  }
Пример #2
0
  /**
   * Update URL and gauge of the progress form.
   *
   * @param url new URL, null to remove, "" to not change
   * @param size 0 if unknown, else size of object to download in K bytes
   * @param gaugeLabel label for progress gauge
   */
  private void updateProgressForm(String url, int size, String gaugeLabel) {
    Gauge oldProgressGauge;
    Gauge progressGauge;
    StringItem urlItem;

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

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

    oldProgressGauge = (Gauge) progressForm.get(progressGaugeIndex);
    progressForm.set(progressGaugeIndex, progressGauge);

    // this ends the background thread of gauge.
    oldProgressGauge.setValue(Gauge.CONTINUOUS_IDLE);

    if (url == null) {
      urlItem = new StringItem("", "");
      progressForm.set(progressUrlIndex, urlItem);
    } else if (url.length() != 0) {
      urlItem = new StringItem(Resource.getString(ResourceConstants.AMS_WEBSITE) + ": ", url);
      progressForm.set(progressUrlIndex, urlItem);
    }

    lastDisplayChange = System.currentTimeMillis();
  }
Пример #3
0
  public void capture() {
    try {
      // Get the image.
      byte[] raw = mVideoControl.getSnapshot(null);
      Image image = Image.createImage(raw, 0, raw.length);

      Image thumb = ImageUtility.createThumbnail(image);

      // Place it in the main form.
      if (mMainForm.size() > 0 && mMainForm.get(0) instanceof StringItem) mMainForm.delete(0);
      mMainForm.append(thumb);

      // Flip back to the main form.
      mDisplay.setCurrent(mMainForm);

      // Shut down the player.
      mPlayer.close();
      mPlayer = null;
      mVideoControl = null;
    } catch (MediaException me) {
      handleException(me);
    }
  }