示例#1
0
 /**
  * Save the text contained by the Document in the dataMap set as property.
  *
  * @param document
  */
 public void saveDocumentText(Document document) {
   try {
     String name = document.getText(0, document.getLength());
     Map<URI, Object> dataMap = (Map<URI, Object>) document.getProperty(DATA_MAP_PROPERTY);
     URI uri = (URI) document.getProperty(URI_PROPERTY);
     dataMap.put(uri, name);
   } catch (BadLocationException e) {
     LoggerFactory.getLogger(GeometryUI.class).error(e.getMessage());
   }
 }
  @Override
  public void actionPerformed(PhpModule phpModule) {
    // Check CakePHP project
    if (!CakePhpUtils.isCakePHP(phpModule)) {
      return;
    }

    // get EditorCookie
    Lookup lookup = Utilities.actionsGlobalContext();
    EditorCookie context = lookup.lookup(EditorCookie.class);
    if (context == null) {
      return;
    }

    Document doc = context.getDocument();
    if (doc == null) {
      return;
    }

    reformat(doc);

    // Change line feed
    if (!BaseDocument.LS_LF.equals(doc.getProperty(BaseDocument.READ_LINE_SEPARATOR_PROP))) {
      doc.putProperty(BaseDocument.READ_LINE_SEPARATOR_PROP, BaseDocument.LS_LF);
    }
  }
 private static OffsetsBag getBag(Document doc) {
   OffsetsBag bag = (OffsetsBag) doc.getProperty(RemoveSurroundingCodePanel.class);
   if (bag == null) {
     doc.putProperty(RemoveSurroundingCodePanel.class, bag = new OffsetsBag(doc));
   }
   return bag;
 }
示例#4
0
 private void updateBoard(DocumentEvent e) throws BadLocationException {
   Document doc = e.getDocument();
   int index = (int) doc.getProperty("index");
   String valueString = doc.getText(0, doc.getLength());
   if (doc.getLength() == 0) valueString = "0";
   int value = Integer.parseInt(valueString);
   gameBoard.changeCellAt(index, value);
   // gameBoard.out();
   if (gameBoard.checkGameOver()) {
     JOptionPane.showMessageDialog(frame, "NUMBRIX COMPLETED!!!");
   }
 }
示例#5
0
  public void setPage(final URL page) throws IOException {
    if (page == null) {
      throw new IOException(Messages.getString("swing.03", "Page")); // $NON-NLS-1$ //$NON-NLS-2$
    }

    String url = page.toString();
    String baseUrl = getBaseURL(url);
    Document oldDoc = getDocument();
    if (baseUrl != null
        && oldDoc != null
        && baseUrl.equals(oldDoc.getProperty(Document.StreamDescriptionProperty))) {

      scrollToReference(page.getRef());
      return;
    }
    InputStream stream = getStream(page);
    if (stream == null) {
      return;
    }
    Document newDoc = editorKit.createDefaultDocument();
    // Perhaps, it is reasonable only for HTMLDocument...
    if (newDoc instanceof HTMLDocument) {
      newDoc.putProperty(Document.StreamDescriptionProperty, baseUrl);
      newDoc.putProperty(StringConstants.IGNORE_CHARSET_DIRECTIVE, new Boolean(false));
      try {
        ((HTMLDocument) newDoc).setBase(new URL(baseUrl));
      } catch (IOException e) {
      }
    }
    // TODO Asynch loading doesn't work with completely.
    // Also page property change event is written incorrectly now
    // (at the asynchrounous loading), because loading may not be
    // completed.
    // int asynchronousLoadPriority = getAsynchronousLoadPriority(newDoc);
    int asynchronousLoadPriority = -1;
    if (asynchronousLoadPriority >= 0) {
      setDocument(newDoc);
      AsynchLoad newThread = new AsynchLoad(asynchronousLoadPriority, stream, page);
      newThread.start();
      if (newThread.successfulLoading) {
        changePage(page);
      }
    } else {
      try {
        documentLoading(stream, newDoc, page);
        stream.close();
        setDocument(newDoc);
        changePage(page);
      } catch (IOException e) {
      }
    }
  }
示例#6
0
  @Override
  public void read(Reader in, Document doc, int pos) throws IOException, BadLocationException {
    BufferedReader br = new BufferedReader(in);
    br.mark(1024);

    char[] buffer = new char[80];
    br.read(buffer);
    br.reset();

    Language language =
        languageManager.getLanguage(
            new String(buffer), (File) doc.getProperty(Document.StreamDescriptionProperty));

    SourceDocument document = (SourceDocument) doc;
    document.setLanguage(language);

    int offset = 0;
    String line;
    while ((line = br.readLine()) != null) {
      document.insertString(offset, line + "\n", null);
      offset += line.length() + 1;
    }
  }
  /**
   * 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();
        }
      }
    }
  }