Exemplo n.º 1
0
  @Override
  public Status getStatus() {
    Status status = new Status();

    status.put("id", this.getUUID());
    if (variable != null) {
      status.put("variable", variable.getStatus());
    }

    if (leftVariable != null) {
      status.put("left", leftVariable.getStatus());
    } else if (arg1 != null) {
      status.put("left", arg1.getStatus());
    } else {
      status.put("left", tf1.getText());
    }

    status.put("op", cb.getValue());

    if (arg2 != null) {
      status.put("right", arg2.getStatus());
    } else {
      status.put("right", tf2.getText());
    }

    return status;
  }
Exemplo n.º 2
0
 @Override
 public void toFront() {
   super.toFront();
   if (variable != null) {
     variable.toFront();
   }
   if (leftVariable != null) {
     leftVariable.toFront();
   }
 }
Exemplo n.º 3
0
 @Override
 public void move(double dx, double dy) {
   if (variable != null) {
     variable.toFront();
     variable.move(dx + 10, dy + 10);
   }
   if (leftVariable != null) {
     leftVariable.toFront();
     leftVariable.move(dx + 80, dy + 10);
   }
   super.move(dx, dy);
 }
Exemplo n.º 4
0
  @Override
  public void show() {
    super.show();

    if (variable != null) {
      variable.show();
    }

    if (leftVariable != null) {
      leftVariable.show();
    }
  }
Exemplo n.º 5
0
  @Override
  public String intern() {
    StringBuilder sb = new StringBuilder();
    sb.append(variable.intern());
    sb.append(" = (");

    StringBuilder v = new StringBuilder();
    if (leftVariable != null) {
      v.append(leftVariable.intern());
    } else {
      if (arg1 != null) {
        v.append(arg1);
      } else {
        try {
          // As number
          v.append(Integer.parseInt(tf1.getText()));
        } catch (NumberFormatException nfe) {
          // As String
          v.append("\"");
          v.append(tf1.getText());
          v.append("\"");
        }
      }
    }

    v.append(" ");
    v.append(cb.getValue());
    v.append(" ");

    if (arg2 != null) {
      v.append(arg2);
    } else {
      try {
        // As number
        v.append(Integer.parseInt(tf2.getText()));
      } catch (NumberFormatException nfe) {
        // As String
        v.append("\"");
        v.append(tf2.getText());
        v.append("\"");
      }
    }

    sb.append(v.toString());
    sb.append(")\n");

    if (nextBlock != null) {
      sb.append(nextBlock.intern());
    }

    return sb.toString();
  }
Exemplo n.º 6
0
  @Override
  public void setStatus(Status status) {
    changeable = false; // 一時的にリスナーを無効化

    this.setUUID((String) status.get("id"));

    for (Object key : status.keySet()) {
      if (key.equals("variable")) {
        // 変数ブロック
        Variable val = (Variable) BlockUtil.create("Variable");
        val.setSprite(getSprite());
        val.setStatus(BlockUtil.convertMapToStatus(status.get(key)));

        setVariable(val);
      } else if (key.equals("left")) {
        Object value = status.get(key);

        if (value instanceof String) {
          tf1.setText((String) value); // テキスト
        } else {
          // 変数ブロック
          Variable val = (Variable) BlockUtil.create("Variable");
          val.setSprite(getSprite());
          val.setStatus(BlockUtil.convertMapToStatus(status.get(key)));

          setLeftVariable(val);
        }
      } else if (key.equals("op")) {
        cb.setValue(status.get(key));
      } else if (key.equals("right")) {
        Object value = status.get(key);

        if (value instanceof String) {
          tf2.setText((String) status.get(key)); // テキスト
        } else {
          // 変数ブロック
          arg2 = (Variable) BlockUtil.create("Variable");
          arg2.setSprite(getSprite());
          arg2.setStatus(BlockUtil.convertMapToStatus(status.get(key)));
        }
      }
    }

    changeable = true;
  }
Exemplo n.º 7
0
 public void setLeftVariable(Variable v) {
   this.leftVariable = v;
   if (v != null) {
     v.mother = this;
   }
 }