Пример #1
0
  // get the caption for the loop's visual representation
  // the caption is an abbreviated form of the code
  // the caption appears in the upper-left corner of the loop
  public String getCaption() {
    String caption = "";
    switch (type) {
      case LOOP_TYPE_REPETITIONS:
        if (!numWarmups.equals("0")) {
          caption += numWarmups + " " + Utility.wordForm(numWarmups, "warmups") + " + ";
          if (sync) caption += "sync + ";
        }
        caption += numReps + " " + Utility.wordForm(numReps, "reps");
        return caption;
      case LOOP_TYPE_FOR_EACH:
        caption = sequenceName + " in ";
        for (int i = 0; i < sequences.size(); i++) {
          String sequence = (String) sequences.elementAt(i);
          if (i > 0) caption += ", ";
          caption += "{" + sequence + "}";
        }

        return caption;
      case LOOP_TYPE_TIMED:
        return toCode();
      default:
        assert false;
        return "";
    }
  }
Пример #2
0
  // returns the code for the header of the loop, not code for
  // the entire loop that it contains
  public String toCode() {
    String code;
    switch (type) {
      case LOOP_TYPE_REPETITIONS:
        code = "for " + numReps + " " + Utility.wordForm(numReps, "repetitions");

        if (!numWarmups.equals("0")) {
          code += " plus " + numWarmups + " warmup " + Utility.wordForm(numWarmups, "repetitions");
          if (sync) code += " and a synchronization";
        }
        return code;
      case LOOP_TYPE_FOR_EACH:
        code = "for each " + sequenceName + " in ";
        for (int i = 0; i < sequences.size(); i++) {
          String sequence = (String) sequences.elementAt(i);
          if (i > 0) code += ", ";
          code += "{" + sequence + "}";
        }
        return code;
      case LOOP_TYPE_TIMED:
        code = "for " + time + " " + Utility.wordForm(time, timeUnits);
        return code;
      default:
        assert false;
        return "";
    }
  }
Пример #3
0
 @Override
 public void mouseClicked(MouseEvent me) {
   Element el = doc.getCharacterElement(viewToModel(me.getPoint()));
   if (el == null) return;
   AttributeSet as = el.getAttributes();
   if (as.isDefined("ip")) {
     String ip = (String) as.getAttribute("ip");
     ScriptException se = (ScriptException) as.getAttribute("exception");
     Node node = net.getAtIP(ip);
     if (node == null) {
       Utility.displayError("Error", "Computer does not exist");
       return;
     }
     String errorString =
         "--ERROR--\n"
             + "Error at line number "
             + se.getLineNumber()
             + " and column number "
             + se.getColumnNumber()
             + "\n"
             + se.getMessage();
     new ScriptDialog(
             parentFrame,
             str -> {
               if (str != null) {
                 node.setScript(str);
               }
             },
             node.getScript(),
             errorString)
         .setVisible(true);
   }
 }
Пример #4
0
 // generate the code corresponding to the compute aggregates
 public String toCodeComputeAggregates() {
   if (computeAggregatesGroup == null) return null;
   else
     return computeAggregatesGroup.toCodeSource()
         + " "
         + Utility.wordForm(computeAggregatesGroup.toCodeSource(), "computes")
         + " aggregates";
 }
Пример #5
0
  public ReverseFlashCard() {
    // basic init
    setTitle("WayMemo -Reverse Flash Card Mode");
    this.setSize(800, 600);
    paneCenter = new JPanel(new GridLayout(7, 1));

    add(ln, "North");
    add(paneCenter, "Center");
    add(b2, "West");
    add(bReset, "South");
    add(b1, "East");
    paneCenter.add(l1);
    paneCenter.add(l2);
    paneCenter.add(l3);
    paneCenter.add(l4);
    paneCenter.add(l5);
    paneCenter.add(b3);
    paneCenter.add(pMark);
    pMark.add(bMark);
    pMark.add(bUnMark);
    pMark.add(lt);

    // text area init

    Utility.initTextAreaView(l1);
    Utility.initTextAreaView(l2);
    Utility.initTextAreaView(l3);
    Utility.initTextAreaView(l4);
    Utility.initTextAreaView(l5);

    // action

    //
    Action actionNext =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            num++;
            wordDisplay();
          }
        };
    b1.getInputMap().put(KeyStroke.getKeyStroke("C"), "pressed");
    b1.getActionMap().put("released", actionNext);
    //
    Action actionBack =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            num--;
            wordDisplay();
          }
        };
    b2.getInputMap().put(KeyStroke.getKeyStroke("Z"), "pressed");
    b2.getActionMap().put("released", actionBack);
    //
    Action actionShow =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            l1.setText(dtr[num]);
            l3.setText(d2[num]);
            l4.setText(d3[num]);
            l5.setText(d4[num]);
          }
        };
    b3.getInputMap().put(KeyStroke.getKeyStroke("X"), "pressed");
    b3.getActionMap().put("released", actionShow);
    //
    //
    Action actionMark =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            d1[num] = "[MARKED*]" + d1[num];
            l2.setText(d1[num]);
          }
        };
    bMark.getInputMap().put(KeyStroke.getKeyStroke("S"), "pressed");
    bMark.getActionMap().put("released", actionMark);
    //
    //
    //
    Action actionUnmark =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            d1[num] = od1[num];
            l2.setText(d1[num]);
          }
        };
    bUnMark.getInputMap().put(KeyStroke.getKeyStroke("F2"), "pressed");
    bUnMark.getActionMap().put("released", actionUnmark);
    //
    //
    Action actionReset =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            num = 0;
            wordDisplay();
          }
        };
    bReset.getInputMap().put(KeyStroke.getKeyStroke("r"), "pressed");
    bReset.getActionMap().put("released", actionReset);
    //
    //
    b1.setMnemonic(KeyEvent.VK_C);
    b2.setMnemonic(KeyEvent.VK_Z);
    b3.setMnemonic(KeyEvent.VK_X);
    bMark.setMnemonic(KeyEvent.VK_S);
    bUnMark.setMnemonic(KeyEvent.VK_D);
    bReset.setMnemonic(KeyEvent.VK_R);

    b1.addActionListener(actionNext);
    b2.addActionListener(actionBack);
    b3.addActionListener(actionShow);
    bReset.addActionListener(actionReset);
    bMark.addActionListener(actionMark);
    bUnMark.addActionListener(actionUnmark);
    //
    //
    try {
      this.fileScan(new OpenFileDTR().getPathDTR());
    } catch (IOException e) {
    } catch (ClassNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (InstantiationException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IllegalAccessException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (UnsupportedLookAndFeelException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Пример #6
0
 /**
  * Print a debug message and byte array as a pretty printed hex dump to the console.
  *
  * @param sMsg a debug message.
  * @param data a <code>byte</code> array.
  * @param offset an index of <code>data</code> from which hex dump starts.
  * @param len the length of hex dump.
  */
 public static void reportStatus(String sMsg, byte[] data, int offset, int len) {
   if ((debugLevel & DEBUG_MSG) != 0) reportStatus(Utility.hexDump(data, offset, len, 20));
 }
Пример #7
0
  /**
   * Print a debug message and byte array as a pretty printed hex dump to the console.
   *
   * @param sMsg a debug message.
   * @param data a <code>byte</code> array.
   */
  public static void reportStatus(String sMsg, byte[] data) {
    if (sMsg != null) reportStatus(sMsg);

    if ((debugLevel & DEBUG_MSG) != 0) reportStatus(Utility.hexDump(data, 0, data.length, 20));
  }