public GElement generateGraph(String dotFile) throws IOException {

    BufferedReader br = new BufferedReader(new FileReader(dotFile));
    graph = null;

    /**
     * The problem here is that DOT sometime inserts a '\' at the end of a long line so we have to
     * skip it and continue to parse until a "real" EOL is reached. Example: statement ->
     * compoundStatement [pos="e,3264,507 3271,2417 3293,2392 ... 3237,565 3234,560 32\ 39,545
     * 3243,534 3249,523 3257,514"];
     */
    StringBuffer line = new StringBuffer();
    int c; // current character
    int pc = -1; // previous character
    while ((c = br.read()) != -1) {
      if (c == '\n') {
        if (pc == '\\') {
          // Remove the last \ if it was part of the DOT wrapping character
          line.deleteCharAt(line.length() - 1);
        } else {
          GElement element = parseLine(line.toString());
          if (element != null) {
            if (graph == null) graph = element;
            else graph.addElement(element);
          }
          line.delete(0, line.length());
        }
      } else if (c != '\r') {
        line.append((char) c);
      }
      pc = c;
    }
    return graph;
  }
Esempio n. 2
0
    /**
     * Create a Transferable to use as the source for a data transfer.
     *
     * @param c The component holding the data to be transfered. This argument is provided to enable
     *     sharing of TransferHandlers by multiple components.
     * @return The representation of the data to be transfered.
     */
    protected Transferable createTransferable(JComponent c) {
      Object[] values = null;
      if (c instanceof JList) {
        values = ((JList) c).getSelectedValues();
      } else if (c instanceof JTable) {
        JTable table = (JTable) c;
        int[] rows = table.getSelectedRows();
        if (rows != null) {
          values = new Object[rows.length];
          for (int i = 0; i < rows.length; i++) {
            values[i] = table.getValueAt(rows[i], 0);
          }
        }
      }
      if (values == null || values.length == 0) {
        return null;
      }

      StringBuffer plainBuf = new StringBuffer();
      StringBuffer htmlBuf = new StringBuffer();

      htmlBuf.append("<html>\n<body>\n<ul>\n");

      for (Object obj : values) {
        String val = ((obj == null) ? "" : obj.toString());
        plainBuf.append(val + "\n");
        htmlBuf.append("  <li>" + val + "\n");
      }

      // remove the last newline
      plainBuf.deleteCharAt(plainBuf.length() - 1);
      htmlBuf.append("</ul>\n</body>\n</html>");

      return new FileTransferable(plainBuf.toString(), htmlBuf.toString(), values);
    }
  public String toString() {
    StringBuffer b = new StringBuffer();
    b.append("ID:" + id);
    b.append("\tName:" + name);
    b.append("\tSex:" + sex + "\n");
    b.append("\tAffected:" + affection + "\n");

    if (mother == null) {
      b.append("\tMother: null");
    } else {
      b.append("\tMother:" + mother.id);
    }

    if (father == null) {
      b.append("\tFather: null");
    } else {
      b.append("\tFather:" + father.id);
    }

    b.append("\tChildren:");
    Vector<PelicanPerson> children = getChildren();
    if (children.size() > 0) {
      Iterator<PelicanPerson> it = children.iterator();
      while (it.hasNext()) {
        PelicanPerson p = it.next();
        b.append(p.id + ",");
      }
      b.deleteCharAt(b.length() - 1);
    } else {
      b.append("none");
    }
    b.append("\n");
    return b.toString();
  }
Esempio n. 4
0
 /**
  * Reads a line of text edited by the user, terminated by <code>ENTER</code>. Editing is performed
  * at the current cursor position.
  *
  * @param field Maximum length of the text
  * @return The text read. <code>null</code> if it was pressed the <code>Esc</code> key.
  */
 public static String nextLine(int field) {
   boolean oldCursorOn = frame.isCursorOn();
   boolean oldEcho = frame.isEcho();
   cursor(false);
   int lin = frame.getLin(), col = frame.getCol();
   for (int i = 0; i < field; ++i) print(' ');
   cursor(lin, col);
   cursor(true);
   echo(false);
   StringBuffer res = new StringBuffer(field);
   char c;
   while ((c = waitChar(0)) != '\n') {
     if (c == KeyEvent.VK_ESCAPE) {
       res = null;
       break;
     } // Esc (27)
     else if (c == KeyEvent.VK_BACK_SPACE) { // Backspace (8)
       if (res.length() == 0) continue;
       res.deleteCharAt(res.length() - 1);
       cursor(false);
       cursor(frame.getLin(), frame.getCol() - 1);
       print(' ');
       cursor(frame.getLin(), frame.getCol() - 1);
       cursor(true);
     } else if (res.length() < field) {
       print(c);
       res.append(c);
     }
   }
   cursor(oldCursorOn);
   echo(oldEcho);
   return res == null ? null : res.toString();
 }
  /** Handle string insertion. */
  public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
    // Store source data

    int sourceLength = getLength();
    String sourceText = getText(0, sourceLength);
    StringBuffer strBuffer = new StringBuffer(sourceText);

    // Check if old value is zero

    if (offs == 0 && sourceLength > 0 && str.length() > 0) {
      long oldValue;

      try {
        oldValue = myFormat.parse(strBuffer.toString()).longValue();

        if (oldValue == 0) {
          strBuffer.deleteCharAt(0);
        }
      } catch (Exception e) {
      }
    }

    // Now add new string

    strBuffer.insert(offs, str);

    BigDecimal value;

    try {
      value = new BigDecimal(myFormat.parse(strBuffer.toString()).doubleValue());
    } catch (Exception e) {
      if (sourceLength > 0) {
        if (sourceText.startsWith(",")) {
          sourceText = "0" + sourceText;
        }

        value = new BigDecimal(getRealString(sourceText));
      } else {
        value = new BigDecimal(0.0);
      }
    }

    // Set the new value

    if (textField == null) {
      return;
    }

    textField.setValue(new Money(value, textField.getValue().getCurrency()), false);

    super.remove(0, sourceLength);
    super.insertString(0, myFormat.format(value.doubleValue()), a);

    // Set caret to correct caret position

    if (!"".equals(sourceText)) // <=> initilized
    {
      int lengthDiff = getLength() - sourceLength;
      int caretPos = lengthDiff + offs;
      int caretDiff = sourceLength - offs;

      // Adjust for columns after centSperator (currently Diff < 3)

      if ((caretDiff > 0 && caretDiff < 3) || (value.abs().longValue() < 10 && caretPos == 0)) {
        caretPos += 1;
      }

      if (caretPos < 0) {
        caretPos = 0;
      }

      textField.setCaretPosition(caretPos);
    } else {
      textField.setCaretPosition(1);
    }
  }
Esempio n. 6
0
File: Chat.java Progetto: brgj/Tales
 /** Backspace a character from the message buffer */
 public void removeChar() {
   if (messageToSend.length() > 0) messageToSend.deleteCharAt(messageToSend.length() - 1);
 }
  public static boolean parse(StringBuffer pattern, GElementTMOperation gop) {
    TMOperation op = gop.getOperation();
    String s = pattern.toString();

    if (s.startsWith(TMOperation.OPS_LEFT_UNTIL)) {
      pattern.delete(0, 2);
      gop.setLabel(TMOperation.OPS_LEFT_UNTIL + pattern.charAt(0));
      op.setOperation(TMOperation.OP_LEFT_UNTIL);
      op.setParameter(pattern.substring(0, 1));
      pattern.deleteCharAt(0);
    } else if (s.startsWith(TMOperation.OPS_LEFT_UNTIL_NOT)) {
      pattern.delete(0, 2);
      gop.setLabel(TMOperation.OPS_LEFT_UNTIL_NOT + pattern.charAt(0));
      op.setOperation(TMOperation.OP_LEFT_UNTIL_NOT);
      op.setParameter(pattern.substring(0, 1));
      pattern.deleteCharAt(0);
    } else if (s.startsWith(TMOperation.OPS_LEFT)) {
      pattern.deleteCharAt(0);
      gop.setLabel(TMOperation.OPS_LEFT);
      op.setOperation(TMOperation.OP_LEFT);
    } else if (s.startsWith(TMOperation.OPS_RIGHT_UNTIL)) {
      pattern.delete(0, 2);
      gop.setLabel(TMOperation.OPS_RIGHT_UNTIL + pattern.charAt(0));
      op.setOperation(TMOperation.OP_RIGHT_UNTIL);
      op.setParameter(pattern.substring(0, 1));
      pattern.deleteCharAt(0);
    } else if (s.startsWith(TMOperation.OPS_RIGHT_UNTIL_NOT)) {
      pattern.delete(0, 2);
      gop.setLabel(TMOperation.OPS_RIGHT_UNTIL_NOT + pattern.charAt(0));
      op.setOperation(TMOperation.OP_RIGHT_UNTIL_NOT);
      op.setParameter(pattern.substring(0, 1));
      pattern.deleteCharAt(0);
    } else if (s.startsWith(TMOperation.OPS_RIGHT)) {
      pattern.deleteCharAt(0);
      gop.setLabel(TMOperation.OPS_RIGHT);
      op.setOperation(TMOperation.OP_RIGHT);
    } else if (s.startsWith(TMOperation.OPS_OUTPUT)) {
      gop.setLabel(TMOperation.OPS_OUTPUT);
      op.setOperation(TMOperation.OP_OUTPUT);
      pattern.deleteCharAt(0);
    } else if (s.startsWith(TMOperation.OPS_YES)) {
      gop.setLabel(TMOperation.OPS_YES);
      op.setOperation(TMOperation.OP_YES);
      pattern.deleteCharAt(0);
    } else if (s.startsWith(TMOperation.OPS_NO)) {
      gop.setLabel(TMOperation.OPS_NO);
      op.setOperation(TMOperation.OP_NO);
      pattern.deleteCharAt(0);
    } else if (s.startsWith(TMOperation.OPS_CALL)) {
      pattern.deleteCharAt(0); // consume M
      pattern.deleteCharAt(0); // consume [
      String machineName = pattern.substring(0, pattern.indexOf("]"));
      pattern.delete(0, pattern.indexOf("]") + 1);

      op.setOperation(TMOperation.OP_CALL);
      op.setParameter(machineName);
      gop.setLabel(TMOperation.OP_CALL + "[" + op.getParameter() + "]");
    } else {
      op.setOperation(TMOperation.OP_WRITE);
      if (s.startsWith(TMMachine.SYMBOL_VAR)) {
        op.setParameter(pattern.substring(0, 2));
        pattern.delete(0, 2);
      } else {
        op.setParameter(pattern.substring(0, 1));
        pattern.deleteCharAt(0);
      }
      gop.setLabel(op.getParameter());
    }

    return true;
  }