Esempio n. 1
0
    public void execute() {
      if (!isEditable() || !isEnabled()) {
        return;
      }
      int position = lastClickPoint != null ? viewToModel(lastClickPoint) : getCaretPosition();
      lastClickPoint = null;
      Document document = getDocument();
      String selectedText = getSelectedText();

      try {
        if (selectedText != null && !CommonUtil.isEmpty(selectedText)) {
          String trimmed = selectedText.trim();
          if (trimmed.startsWith("<!--") && trimmed.endsWith("-->")) {
            StringBuffer buffer = new StringBuffer(selectedText);
            int pos = buffer.indexOf("<!--");
            buffer.delete(pos, pos + 4);
            pos = buffer.lastIndexOf("-->");
            buffer.delete(pos, pos + 3);
            replaceSelection(buffer.toString());
          } else {
            String newSelection = "<!--" + selectedText + "-->";
            replaceSelection(newSelection);
          }
        } else {
          final int docLen = document.getLength();
          int fromIndex = Math.max(0, getText(0, position).lastIndexOf('\n'));
          int toIndex = getText(fromIndex + 1, docLen - position).indexOf('\n');
          toIndex = toIndex < 0 ? docLen : fromIndex + toIndex;
          String textToComment = getText(fromIndex, toIndex - fromIndex + 1);

          if (textToComment.startsWith("\n")) {
            textToComment = textToComment.substring(1);
            fromIndex++;
          }
          if (textToComment.endsWith("\n")) {
            textToComment = textToComment.substring(0, textToComment.length() - 1);
            toIndex--;
          }
          String trimmed = textToComment.trim();
          if (trimmed.startsWith("<!--") && trimmed.endsWith("-->")) {
            int pos = textToComment.lastIndexOf("-->");
            document.remove(fromIndex + pos, 3);
            pos = textToComment.indexOf("<!--");
            document.remove(fromIndex + pos, 4);
          } else {
            document.insertString(Math.min(toIndex + 1, docLen), "-->", null);
            document.insertString(fromIndex, "<!--", null);
          }
        }
      } catch (BadLocationException e1) {
        e1.printStackTrace();
      }
    }
Esempio n. 2
0
  public Font toFont() {
    StringBuffer stringBuffer = new StringBuffer(getFont());
    String fontName = stringBuffer.substring(0, stringBuffer.indexOf("-"));
    stringBuffer = stringBuffer.delete(0, stringBuffer.indexOf("-") + 1);
    String dataStyle = stringBuffer.substring(0, stringBuffer.indexOf("-"));
    if (dataStyle.equalsIgnoreCase("PLAIN")) fontStyle = Font.PLAIN;
    else if (dataStyle.equalsIgnoreCase("BOLD")) fontStyle = Font.BOLD;
    else if (dataStyle.equalsIgnoreCase("")) fontStyle = Font.ITALIC;

    stringBuffer = stringBuffer.delete(0, stringBuffer.indexOf("-") + 1);
    int fontSize = Integer.parseInt(stringBuffer.toString());

    Font font = new Font(fontName, fontStyle, fontSize);
    return font;
  }
  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. 4
0
File: Chat.java Progetto: brgj/Tales
 /**
  * Send a message to the client
  *
  * @return true if message is not empty
  */
 public boolean sendMessage() {
   if (messageToSend.length() == 0) return false;
   client.sendMessage(messageToSend.toString());
   addMessageToLog("You: " + messageToSend.toString());
   messageToSend.delete(0, messageToSend.length());
   return true;
 }
Esempio n. 5
0
  private void onReceiveChar(char character) {

    buffer.append(character);

    if (buffer.charAt(buffer.length() - 1) == '\n') {
      onReceiveLine(buffer.toString());
      buffer.delete(0, buffer.length());
    }
  }
Esempio n. 6
0
 public void deleteEnclosedText(TextLocation start, TextLocation end) {
   ArrayList<TypedLayout> lines = getLines();
   int startIndex = start.toIndex(lines);
   int endIndex = end.toIndex(lines);
   synchronized (this) {
     text.delete(startIndex, endIndex);
     clearCache();
   }
   setCaretLocation(start);
   setSelectionLocation(start);
 }
Esempio n. 7
0
  /**
   * Method description
   *
   * @param color
   * @return
   */
  public static String getcommaSeparatedRGBString(Color color) {

    if (color != null) {

      scratchBuffer.delete(0, scratchBuffer.length()); // Clear
      int red = color.getRed();
      int green = color.getGreen();
      int blue = color.getBlue();
      scratchBuffer.append(red);
      scratchBuffer.append(",");
      scratchBuffer.append(green);
      scratchBuffer.append(",");
      scratchBuffer.append(blue);
    }
    return scratchBuffer.toString();
  }
  // Generate css-file
  private String generateCssStyles(String param) {
    String sessionId;
    if (!param.contains("sessionid")) {
      return "";
    }
    sessionId = param.substring(param.indexOf("sessionid=") + 10);

    Map<MyTextAttributes, Integer> mapAttributes = mapCss.get(Integer.parseInt(sessionId));
    StringBuffer buffer = new StringBuffer();
    buffer.append(
        "body { font-family: monospace; font-size: 12px; color: #000000; background-color: #FFFFFF;} ");
    buffer.append(
        " a {text-decoration: none; color: #000000;} span.highlighting { background-color: yellow !important;}");
    buffer.append(
        " a span {text-decoration: none; color: #000000;} a:hover span {color: blue; text-decoration: underline;}");
    if (mapAttributes != null) {
      for (MyTextAttributes attr : mapAttributes.keySet()) {
        buffer.append("\nspan.class");
        buffer.append(mapAttributes.get(attr)).append("{");
        String tmp = MyBaseHandler.getColor(attr.getForegroundColor());
        if (!tmp.equals("#000000")) {
          buffer.append("color: ").append(tmp).append("; ");
        }
        tmp = MyBaseHandler.getColor(attr.getBackgroundColor());
        if (!tmp.equals("#ffffff")) {
          buffer.append("background-color: ").append(tmp).append("; ");
        }
        buffer.append(MyBaseHandler.getFontType(attr.getFontType())).append(" ");
        if (attr.getEffectType().equals(EffectType.LINE_UNDERSCORE)) {
          buffer.append("text-decoration: underline; ").append("; ");
        }
        buffer.append("}");

        // Cut empty styles
        tmp = "\nspan.class" + mapAttributes.get(attr) + "{ }";
        int position = buffer.toString().indexOf(tmp);
        if (position != -1) {
          buffer = buffer.delete(position, buffer.length());
        }
      }
    }
    return buffer.toString();
  }
  void setupPanel(JabRefFrame frame, BasePanel bPanel, boolean addKeyField, String title) {

    InputMap im = panel.getInputMap(JComponent.WHEN_FOCUSED);
    ActionMap am = panel.getActionMap();

    im.put(Globals.prefs.getKey("Entry editor, previous entry"), "prev");
    am.put("prev", parent.prevEntryAction);
    im.put(Globals.prefs.getKey("Entry editor, next entry"), "next");
    am.put("next", parent.nextEntryAction);

    im.put(Globals.prefs.getKey("Entry editor, store field"), "store");
    am.put("store", parent.storeFieldAction);
    im.put(Globals.prefs.getKey("Entry editor, next panel"), "right");
    im.put(Globals.prefs.getKey("Entry editor, next panel 2"), "right");
    am.put("left", parent.switchLeftAction);
    im.put(Globals.prefs.getKey("Entry editor, previous panel"), "left");
    im.put(Globals.prefs.getKey("Entry editor, previous panel 2"), "left");
    am.put("right", parent.switchRightAction);
    im.put(Globals.prefs.getKey("Help"), "help");
    am.put("help", parent.helpAction);
    im.put(Globals.prefs.getKey("Save database"), "save");
    am.put("save", parent.saveDatabaseAction);
    im.put(Globals.prefs.getKey("Next tab"), "nexttab");
    am.put("nexttab", parent.frame.nextTab);
    im.put(Globals.prefs.getKey("Previous tab"), "prevtab");
    am.put("prevtab", parent.frame.prevTab);

    panel.setName(title);
    // String rowSpec = "left:pref, 4dlu, fill:pref:grow, 4dlu, fill:pref";
    String colSpec =
        "fill:pref, 1dlu, fill:10dlu:grow, 1dlu, fill:pref, "
            + "8dlu, fill:pref, 1dlu, fill:10dlu:grow, 1dlu, fill:pref";
    StringBuffer sb = new StringBuffer();
    int rows = (int) Math.ceil((double) fields.length / 2.0);
    for (int i = 0; i < rows; i++) {
      sb.append("fill:pref:grow, ");
    }
    if (addKeyField) sb.append("4dlu, fill:pref");
    else if (sb.length() >= 2) sb.delete(sb.length() - 2, sb.length());
    String rowSpec = sb.toString();

    DefaultFormBuilder builder = new DefaultFormBuilder(new FormLayout(colSpec, rowSpec), panel);

    for (int i = 0; i < fields.length; i++) {
      // Create the text area:
      int editorType = BibtexFields.getEditorType(fields[i]);

      final FieldEditor ta;
      if (editorType == GUIGlobals.FILE_LIST_EDITOR)
        ta = new FileListEditor(frame, bPanel.metaData(), fields[i], null, parent);
      else ta = new FieldTextArea(fields[i], null);
      // ta.addUndoableEditListener(bPanel.undoListener);

      JComponent ex = parent.getExtra(fields[i], ta);

      // Add autocompleter listener, if required for this field:
      AbstractAutoCompleter autoComp = bPanel.getAutoCompleter(fields[i]);
      AutoCompleteListener acl = null;
      if (autoComp != null) {
        acl = new AutoCompleteListener(autoComp);
      }
      setupJTextComponent(ta.getTextComponent(), acl);
      ta.setAutoCompleteListener(acl);

      // Store the editor for later reference:
      editors.put(fields[i], ta);
      if (i == 0) activeField = ta;
      // System.out.println(fields[i]+": "+BibtexFields.getFieldWeight(fields[i]));
      // ta.getPane().setPreferredSize(new Dimension(100,
      //        (int)(50.0*BibtexFields.getFieldWeight(fields[i]))));
      builder.append(ta.getLabel());
      if (ex == null) builder.append(ta.getPane(), 3);
      else {
        builder.append(ta.getPane());
        JPanel pan = new JPanel();
        pan.setLayout(new BorderLayout());
        pan.add(ex, BorderLayout.NORTH);
        builder.append(pan);
      }
      if (i % 2 == 1) builder.nextLine();
    }

    // Add the edit field for Bibtex-key.
    if (addKeyField) {
      final FieldTextField tf =
          new FieldTextField(
              BibtexFields.KEY_FIELD, parent.getEntry().getField(BibtexFields.KEY_FIELD), true);
      // tf.addUndoableEditListener(bPanel.undoListener);
      setupJTextComponent(tf, null);

      editors.put("bibtexkey", tf);
      /*
       * If the key field is the only field, we should have only one
       * editor, and this one should be set as active initially:
       */
      if (editors.size() == 1) activeField = tf;
      builder.nextLine();
      builder.append(tf.getLabel());
      builder.append(tf, 3);
    }
  }
  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;
  }