Java 8 AbstractDocument - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 AbstractDocument class.

This code example shows how to use the following methods:getLength, getText, remove
    public Document getDocument() {
        return _doc;
    } 
     
    private void makeSpace(int count) {
        int length = _doc.getLength();
        if (length + count < _max) return;
        try { 
            if (count > _max) {
                _doc.remove(0, length);
            } else { 
                int min = length + count - _max;
                String remove = _doc.getText(min, Math.min(500, length - min));
                int cr = remove.indexOf("\n");
                if (cr<0) {
                    min = min + remove.length();
                } else { 
                    min = Math.min(min + cr + 1, length);
                } 
                _doc.remove(0, min);

6
CodeRank
This code example shows how to use the following methods:getLength, getText, remove
        	SwingUtilities.invokeLater(r);
        } 
    } 
     
    private void makeSpace(int count) {
        int length = _doc.getLength();
        if (length + count < _max) return;
        try { 
            if (count > _max) {
                _doc.remove(0, length);
            } else { 
                int min = length + count - _max;
                String remove = _doc.getText(min, Math.min(500, length - min));
                int cr = remove.indexOf("\n");
                if (cr<0) {
                    min = min + remove.length();
                } else { 
                    min = Math.min(min + cr + 1, length);
                } 
                _doc.remove(0, min);

6
CodeRank
This code example shows how to use the following methods:setAsynchronousLoadPriority, setParser, setTokenThreshold
	@Override 
	public Document createDefaultDocument() {
		StyleSheet styles = getStyleSheet();
		StyleSheet ss = new ScaledStyleSheet();
		ss.addStyleSheet(styles);
		HTMLDocument doc = new HTMLDocument(ss);
		doc.setParser(getParser());
		doc.setAsynchronousLoadPriority(4);
		doc.setTokenThreshold(100);
		return doc;
	} 
 
	/** 
	 * Sets the async policy to flush everything in one chunk, and 
	 * to not display unknown tags. 
	 */ 
	Document createDefaultDocument(Font defaultFont, Color foreground) {
		StyleSheet styles = getStyleSheet();
		StyleSheet ss = new ScaledStyleSheet();
		ss.addStyleSheet(styles);
6
CodeRank
This code example shows how to use the following methods:getDocumentProperties, setBase
		} 
	} 
 
	public void initImageLoader(HTMLDocument document) {
		try { 
			document.setBase(new URL(ImageLoaderCache.IMAGE_URL_PREFIX));
		} catch (MalformedURLException e) {
			log.error(e.getMessage());
		} 
		setContextResource(navigator.getCurrentResource());
		document.getDocumentProperties().put("imageCache", this);
	} 
 
 
	private String getResourceHref(String requestUrl) {
		String resourceHref = requestUrl.toString().substring(IMAGE_URL_PREFIX.length());
		resourceHref = currentFolder + resourceHref;
		resourceHref = FilenameUtils.normalize(resourceHref);
		// normalize uses the SYSTEM_SEPARATOR, which on windows is a '\' 
		// replace with '/' to make it href '/' 
6
CodeRank
This code example shows how to use the following methods:setAsynchronousLoadPriority, setParser, setTokenThreshold
        StyleSheet ss = new StyleSheet();
 
        ss.addStyleSheet(styles);
 
        HTMLDocument doc = new CustomHTMLDocument(ss);
        doc.setParser(getParser());
        doc.setAsynchronousLoadPriority(4);
        doc.setTokenThreshold(100);
        return doc;
    } 
 
    /** 
     * Gets the set of styles to be used to render HTML elements. 
     * 
     * @return A <code>StyleSheet</code> containing the default HTML element styles. 
     */ 
    public StyleSheet getStyleSheet()
    { 
        StyleSheet style;
 
5
CodeRank
This code example shows how to use the following methods:addDocumentListener, removeDocumentListener, setBase
		final SHTMLPanel noteViewerComponent = noteController.getNoteViewerComponent();
		if (noteViewerComponent == null) {
			return; 
		} 
		final HTMLDocument document = noteViewerComponent.getDocument();
		document.removeDocumentListener(mNoteDocumentListener);
		try { 
			final URL url = node.getMap().getURL();
			if (url != null) {
				document.setBase(url);
			} 
			else { 
				document.setBase(new URL("file: "));
			} 
		} 
		catch (final Exception e) {
		} 
		noteController.setDefaultFont();
		final String note = node != null ? NoteModel.getNoteText(node) : null;
		if (note != null) {

5
CodeRank
This code example shows how to use the following methods:removeDocumentListener, addDocumentListener, setBase
		final SHTMLPanel noteViewerComponent = noteController.getNoteViewerComponent();
		if (noteViewerComponent == null) {
			return; 
		} 
		final HTMLDocument document = noteViewerComponent.getDocument();
		document.removeDocumentListener(mNoteDocumentListener);
		try { 
			final URL url = node.getMap().getURL();
			if (url != null) {
				document.setBase(url);
			} 
			else { 
				document.setBase(new URL("file: "));
			} 
		} 
		catch (final Exception e) {
		} 
		noteController.setDefaultFont();
		final String note = node != null ? NoteModel.getNoteText(node) : null;
		if (note != null) {

5
CodeRank
This code example shows how to use the following methods:remove
    backend.putProperty(key, value);
  } 
 
  public void remove(final int offs, final int len) throws BadLocationExceptionbackend.remove(offs, len);
  } 
 
  public void insertString(final int offset, final String str, final AttributeSet a) throws BadLocationExceptionbackend.insertString(offset, str, a);
  } 
 
  public String getText(final int offset, final int length) throws BadLocationException
  { 
    return backend.getText(offset, length);
  } 
 
  public void getText(final int offset, final int length, final Segment txt) throws BadLocationException
4
CodeRank
This code example shows how to use the following methods:setDocumentFilter, addDocumentListener
  public static JTextArea newReadOnlyLengthLimitedTextArea(DocumentListener listener, int rows, int columns) {
 
    JTextArea textArea = newReadOnlyTextArea(rows, columns);
 
    // Limit the length of the underlying document 
    DefaultStyledDocument doc = new DefaultStyledDocument();
    doc.setDocumentFilter(new DocumentMaxLengthFilter(rows * columns));
    textArea.setDocument(doc);
 
    // Ensure we monitor changes 
    doc.addDocumentListener(listener);
 
    return textArea;
 
  } 
 
  /** 
   * @return A new "enter transaction label" text field 
   */ 
  public static JTextField newEnterTransactionLabel() {
4
CodeRank
This code example shows how to use the following methods:remove
            int offset = editor.getSelectionStart();
 
            HTMLEditorKit kit = (HTMLEditorKit)editor.getEditorKit();
            try 
            { 
                htmlDocument.remove(offset, editor.getSelectionEnd() - offset);
                kit.insertHTML(htmlDocument, offset, txt, 0, 0, HTML.Tag.A);
            } catch (Throwable e)
            { 
                LOG.log(Level.WARNING, "Failed to insert link", e);
            } 
        } else 
        { 
            editor.replaceSelection(txt);
        } 
    } 
 
    /** 
     * Returns the text which is currently selected. 
     * 
4
CodeRank
See Code Examples for Java 8 AbstractDocument Methods: