コード例 #1
0
 private String getElementText(Element element) {
   String text = "";
   try {
     int startOffset = element.getStartOffset();
     int endOffset = element.getEndOffset();
     int length = endOffset - startOffset;
     text = element.getDocument().getText(startOffset, length);
   } catch (Exception e) {
     logger.error("", e);
   }
   return text.trim();
 }
コード例 #2
0
  /**
   * @param pre the preformatted Element containing Scilab's code
   * @return the code
   */
  private static String getCode(Element pre) {
    int size = pre.getElementCount();
    Document doc = pre.getDocument();
    StringBuilder buffer = new StringBuilder();
    for (int i = 0; i < size; i++) {
      Element line = pre.getElement(i);
      int ssize = line.getElementCount();
      for (int j = 0; j < ssize; j++) {
        Element content = line.getElement(j);
        if (content.isLeaf()) {
          try {
            buffer.append(
                doc.getText(
                    content.getStartOffset(), content.getEndOffset() - content.getStartOffset()));
          } catch (BadLocationException e) {
          }
        }
      }
    }

    return buffer.toString().trim();
  }
コード例 #3
0
  private Element process(final javax.swing.text.Element textElement) throws BadLocationException {
    if (textElement.isLeaf()) {
      final int endOffset = textElement.getEndOffset();
      final int startOffset = textElement.getStartOffset();
      final String text = textElement.getDocument().getText(startOffset, endOffset - startOffset);
      final Element result = new Element();
      result.setElementType(LabelType.INSTANCE);
      result.setAttribute(AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, text);
      configureStyle(textElement.getAttributes(), result);
      return result;
    }

    final Band band = new Band();
    configureStyle(textElement.getAttributes(), band);
    configureBand(textElement, band);
    final int size = textElement.getElementCount();
    for (int i = 0; i < size; i++) {
      final Element element = process(textElement.getElement(i));
      band.addElement(element);
    }
    return band;
  }
コード例 #4
0
  public void setEnabled(boolean enabled) {
    if (!enabled && this.enabled && lastElement != null) {
      // Insert a timeout to the last generated command
      Editor ed = editorPnl.getEditor();
      if (lastElement.getDocument().equals(ed.getDocument())) {
        Element e = ed.getCurrentElement();
        int offset = ed.getCaretPosition() - e.getStartOffset();
        ed.setCaretPosition(lastElement.getStartOffset());
        String text = DocumentUtils.getElementText(lastElement);
        int pos = text.indexOf(" ");
        String cmd = pos >= 0 ? text.substring(0, pos) : text;
        String time = convertTime(System.currentTimeMillis() - lastInsertTime);
        CommandHandler h =
            (CommandHandler) scriptManager.getCommandHandlers().get(cmd.toUpperCase());

        if (h != null
            && h.getContextAttributes() != null
            && h.getContextAttributes().containsKey("wait")) {
          text += " wait=" + time;
        } else {
          text += "\nWait " + time;
        }
        insertLine(text, true, false, false);
      }
    }
    this.enabled = enabled;
    fb.setRecordingMode(enabled);
    if (enabled) {
      firstRecord = true;
      lastElement = null;
      lastInsertTime = -1;
      lastMouseMoveEvent = null;
      events.clear();
      synchronized (rfbEvents) {
        rfbEvents.clear();
      }
    }
  }
コード例 #5
0
  /**
   * Writes out all empty elements (all tags that have no corresponding end tag).
   *
   * @param elem an Element
   * @exception IOException on any I/O error
   * @exception BadLocationException if pos represents an invalid location within the document.
   */
  protected void emptyTag(Element elem) throws BadLocationException, IOException {

    if (!inContent && !inPre) {
      indent();
    }

    AttributeSet attr = elem.getAttributes();
    closeOutUnwantedEmbeddedTags(attr);
    writeEmbeddedTags(attr);

    if (matchNameAttribute(attr, HTML.Tag.CONTENT)) {
      inContent = true;
      text(elem);
    } else if (matchNameAttribute(attr, HTML.Tag.COMMENT)) {
      comment(elem);
    } else {
      boolean isBlock = isBlockTag(elem.getAttributes());
      if (inContent && isBlock) {
        writeLineSeparator();
        indent();
      }

      Object nameTag = (attr != null) ? attr.getAttribute(StyleConstants.NameAttribute) : null;
      Object endTag = (attr != null) ? attr.getAttribute(HTML.Attribute.ENDTAG) : null;

      boolean outputEndTag = false;
      // If an instance of an UNKNOWN Tag, or an instance of a
      // tag that is only visible during editing
      //
      if (nameTag != null
          && endTag != null
          && (endTag instanceof String)
          && ((String) endTag).equals("true")) {
        outputEndTag = true;
      }

      if (completeDoc && matchNameAttribute(attr, HTML.Tag.HEAD)) {
        if (outputEndTag) {
          // Write out any styles.
          writeStyles(((HTMLDocument) getDocument()).getStyleSheet());
        }
        wroteHead = true;
      }

      write('<');
      if (outputEndTag) {
        write('/');
      }
      write(elem.getName());
      writeAttributes(attr);
      write('>');
      if (matchNameAttribute(attr, HTML.Tag.TITLE) && !outputEndTag) {
        Document doc = elem.getDocument();
        String title = (String) doc.getProperty(Document.TitleProperty);
        write(title);
      } else if (!inContent || isBlock) {
        writeLineSeparator();
        if (isBlock && inContent) {
          indent();
        }
      }
    }
  }