Пример #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);
  }
Пример #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) {
        }
      }
    }
  }
Пример #3
0
  public static int readLine(
      InputStream in, OutputStream out, Display display, boolean echo, byte[] buf, int maxLen) {
    // get a line from the input stream into the buffer buf, of max length maxLen
    // line is terminated with a return character;
    // echo back to output stream
    // also write to line 0 of the display, up to 16 characters
    try {
      int data;
      int len = 0;
      maxLen--; // make room for a null byte
      while ((data = in.read()) != -1) {
        if (data == 0) continue;
        if (data == '\n') continue;
        if (echo) out.write(data); // echo it back
        byte ch = (byte) data;

        if (ch == '\r') {
          if (echo) out.write('\n');
          int dlen = len; // LCD panel display length
          if (dlen > 16) dlen = 16;
          byte[] screenBuf = new byte[dlen];
          for (int i = 0; i < dlen; i++) screenBuf[i] = buf[i];
          display.print(0, screenBuf); // echo it to the display
          buf[len] = 0;
          return len;
        } else if (len < maxLen) {
          buf[len++] = ch;
        }
      }
    } catch (Exception e) {
      display.print(0, "oops!");
    }
    return -1;
  }
Пример #4
0
 public static void main(String[] args) {
   Display display = new Display();
   AddressBook application = new AddressBook();
   Shell shell = application.open(display);
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) display.sleep();
   }
   display.dispose();
 }
Пример #5
0
  public static void main(String args[]) {
    Display display = IntelliBrain.getLcdDisplay();
    IBB ibb = new IBB();

    try {
      SerialPort comPort = IntelliBrain.getCom1();

      // Serial Parameters
      comPort.setSerialPortParams(
          38400, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);

      InputStream inputStream = comPort.getInputStream();
      OutputStream outputStream = comPort.getOutputStream();

      // clear screen
      display.print(0, "");
      display.print(1, "");

      // test the readLine routine
      byte[] buf = new byte[128];

      while (true) {
        int len = readLine(inputStream, outputStream, display, true, buf, 128);

        if (len == 0) continue;

        switch (buf[0]) {
          case 'B':
            ibb.getVersion(outputStream, buf, len);
            break;
          case 'D':
            ibb.setSpeed(outputStream, buf, len);
            break;
          case 'H':
            ibb.sysBeep(outputStream, buf, len);
            break;
          case 'L':
            ibb.setLedState(outputStream, buf, len);
            break;
          case 'N':
            ibb.readProximitySensors(outputStream, buf, len);
            break;
          case 'O':
            ibb.readLightSensors(outputStream, buf, len);
            break;
          case 'Z':
            ibb.motorsOff(outputStream, buf, len);
            break;
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
 public static void main(String[] args) {
   Display display = new Display();
   MessageWindow application = new MessageWindow();
   Shell shell = application.open(display);
   if (args.length != 0) {
     application.openAddressBook(args[0]);
   }
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) display.sleep();
   }
   display.dispose();
 }
 /** Invokes as a standalone program. */
 public static void main(String[] args) {
   Display display = new Display();
   Shell shell = new Shell(display, SWT.SHELL_TRIM);
   shell.setLayout(new FillLayout());
   ControlExample instance = new ControlExample(shell);
   shell.setText(getResourceString("window.title"));
   setShellSize(instance, shell);
   shell.open();
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) display.sleep();
   }
   instance.dispose();
   display.dispose();
 }
Пример #8
0
  @Override
  protected void doLayout() {
    beginDoLayout(sourceTemplate);
    // ------
    ; // line 1
    p("\n"); // line 3
    p("\n" + "\n"); // line 5
    if (allPost.size() > 0) { // line 8
      p("	<p></p>\n" + "	"); // line 8
      for (Post p : allPost) { // line 10
        p("	    "); // line 10
        final Display _Display1 = new Display(getOut());
        _Display1.setActionRunners(getActionRunners()).setOut(getOut());
        _Display1.render( // line 11
            new Display.DoBody<String>() { // line 11
              public void render(final String title) { // line 11
                // line 11
                p("			<p>The real title is: "); // line 11
                p(title); // line 12
                p(";</p>\n" + "	    "); // line 12
              }

              StringBuilder oriBuffer;

              @Override
              public void setBuffer(StringBuilder sb) {
                oriBuffer = getOut();
                setOut(sb);
              }

              @Override
              public void resetBuffer() {
                setOut(oriBuffer);
              }
            },
            named("post", p),
            named("as", "home")); // line 11
        p("	"); // line 13
      } // line 14
    } else { // line 15
      p("	<p>There is no post at this moment</p>\n"); // line 15
    } // line 17
    p("\n"); // line 17
    final Tag2 _Tag22 = new Tag2(getOut());
    _Tag22.setActionRunners(getActionRunners()).setOut(getOut());
    _Tag22.render(named("msg", blogTitle), named("age", 1000)); // line 19// line 19
    p("\n" + "<p>end of it</p>"); // line 19

    endDoLayout(sourceTemplate);
  }
Пример #9
0
 public static void main(String[] args) {
   Display display = Display.getDefault();
   Shell shell = new Shell(display);
   @SuppressWarnings("unused")
   MainWindow inst = new MainWindow(shell, SWT.NULL);
   shell.setLayout(new FillLayout());
   shell.setImage(SWTResourceManager.getImage("images/16x16.png"));
   shell.setText("Change This Title");
   shell.setBackgroundImage(SWTResourceManager.getImage("images/ToolbarBackground.gif"));
   shell.layout();
   shell.open();
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) display.sleep();
   }
 }
Пример #10
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);
  }
Пример #11
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;
  }
Пример #12
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);
  }
Пример #13
0
 public void startApp() {
   textBox = new TextBox("Ophone", "\n", 512, TextField.UNEDITABLE);
   OxportMIDlet.addtext("Listo para exportar servicios...");
   textBox.addCommand(exitCom);
   textBox.addCommand(playCom);
   textBox.addCommand(initCom);
   textBox.setCommandListener(this);
   display.setCurrent(textBox);
 }
  /** Invoked when an action occurs. */
  public static BoxItem createNewElement(String className, int posX, int posY) {
    BoxItem ret = null;
    Element elem = null;
    try {
      if (debug) System.out.println("Creating new element '" + className + "'");
      elem = Element.newInstance(className);

      if (elem == null) {
        if (debug) System.out.println("Element '" + className + "' not found");
        return null;
      }

      ret = elem.getDesignerBox();
      ret.setBounds(
          (posX / DesignEventHandler.ELEM_STEP) * DesignEventHandler.ELEM_STEP,
          (posY / DesignEventHandler.ELEM_STEP) * DesignEventHandler.ELEM_STEP,
          ConfigurableSystemSettings.getDesignerElementWidth(),
          ConfigurableSystemSettings.getDesignerElementHeight());
      Main.app.designFrame.addElement(ret);
      Item.highlighted.clear();
      Item.highlighted.add(ret);
      Main.app.processor.add(elem);
      // elem.setActive(false);
      Main.app.designFrame.panel.repaint();

      if (elem instanceof Display) {
        Chart chart = ((Display) elem).newChart();
        ((Display) elem).setChart(chart);
        chart.setAtTopLayer();
        // System.out.println("c1 " + chart.getBounds());
        Main.app.runtimeFrame.addChart(chart);
        // Main.app.runtimeFrame.show();
        Main.app.runtimeFrame.setVisible();
        // Main.app.runtimeFrame.repaint();

        // Change runtime to edit mode if not now
        if (!Main.app.runtimeFrame.framedCharts) {
          Main.app.runtimeFrame.framedCharts = true;
          try {
            Main.app.runtimeFrame.reload();
          } catch (Exception ex) {
            ex.printStackTrace();
          }
        }
      }
      elem.reinit();
    } catch (Exception e) {
      if (elem != null) elem.disactivate(e);
      System.out.println("New element error: " + e);
      // e.printStackTrace();
    } catch (Throwable e) {
      System.out.println("Critical error occurred while creating new element: " + e);
      e.printStackTrace();
    }

    return ret;
  }
Пример #15
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);
 }
Пример #16
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();
  }
Пример #17
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);
 }
Пример #18
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();
   }
 }
Пример #19
0
 void createStyledText() {
   text =
       new org.eclipse.swt.custom.StyledText(
           shell, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
   org.eclipse.swt.layout.GridData spec = new org.eclipse.swt.layout.GridData();
   spec.horizontalAlignment = GridData.FILL;
   spec.grabExcessHorizontalSpace = true;
   spec.verticalAlignment = GridData.FILL;
   spec.grabExcessVerticalSpace = true;
   text.setLayoutData(spec);
   text.addLineStyleListener(lineStyler);
   text.setEditable(false);
   org.eclipse.swt.graphics.Color bg = Display.getDefault().getSystemColor(SWT.COLOR_GRAY);
   text.setBackground(bg);
 }
Пример #20
0
 public OriginatingINVITE() {
   // <i><b>Initialize MIDlet display</b></i>
   display = Display.getDisplay(this);
   // <i><b>create a Form for progess info printings</b></i>
   form = new Form("Session example");
   address = new TextField("INVITE:", "sip:[email protected]:5070", 40, TextField.LAYOUT_LEFT);
   form.append(address);
   byeCmd = new Command("Bye", Command.ITEM, 1);
   restartCmd = new Command("Restart", Command.ITEM, 1);
   startCmd = new Command("Start", Command.ITEM, 1);
   form.addCommand(startCmd);
   exitCmd = new Command("Exit", Command.EXIT, 1);
   form.addCommand(exitCmd);
   form.setCommandListener(this);
 }
Пример #21
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);
  }
Пример #22
0
 void initializeColors() {
   Display display = Display.getDefault();
   colors =
       new Color[] {
         new Color(display, new RGB(0, 0, 0)), // black
         new Color(display, new RGB(255, 0, 0)), // red
         new Color(display, new RGB(0, 255, 0)), // green
         new Color(display, new RGB(0, 0, 255)) // blue
       };
   tokenColors = new int[MAXIMUM_TOKEN];
   tokenColors[WORD] = 0;
   tokenColors[WHITE] = 0;
   tokenColors[KEY] = 3;
   tokenColors[COMMENT] = 1;
   tokenColors[STRING] = 2;
   tokenColors[OTHER] = 0;
   tokenColors[NUMBER] = 0;
 }
Пример #23
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);
  }
Пример #24
0
  public void commandAction(Command c, Displayable s) {
    if (c == exitCom) {
      destroyApp(true);
      notifyDestroyed();

    } else if (c == initCom) {
      if (ox == null) {
        textBox.insert("Exportando...\n", textBox.size());
        ox = new Oxport();
        ox.start();
      }
    } else if (c == playCom) {
      if ((ox == null) || (ox.getOServer() == null)) addtext("Playground need a OServer running");
      else {
        if (playground == null) playground = new PlayGround(this);
        display.setCurrent(playground);
      }
    } else {
    }
  }
Пример #25
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());
    }
  }
Пример #26
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);
    }
  }
Пример #27
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);
 }
 static Browser findBrowser(long /*int*/ handle) {
   Display display = Display.getCurrent();
   return (Browser) display.findWidget(handle);
 }
Пример #29
0
 public OxportMIDlet() {
   display = Display.getDisplay(this);
   exitCom = new Command("Exit", Command.EXIT, 2);
   initCom = new Command("Export", Command.SCREEN, 1);
   playCom = new Command("PlayGround", Command.SCREEN, 1);
 }
Пример #30
0
 public void exitPlay() {
   display.setCurrent(textBox);
 }