当前位置: 首页>>代码示例>>Java>>正文


Java StyledDocument.getLength方法代码示例

本文整理汇总了Java中javax.swing.text.StyledDocument.getLength方法的典型用法代码示例。如果您正苦于以下问题:Java StyledDocument.getLength方法的具体用法?Java StyledDocument.getLength怎么用?Java StyledDocument.getLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.text.StyledDocument的用法示例。


在下文中一共展示了StyledDocument.getLength方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isEmpty

import javax.swing.text.StyledDocument; //导入方法依赖的package包/类
private static boolean isEmpty (
    int                     ln,
    StyledDocument          document,
    Set<Integer>            whitespaces
) throws BadLocationException {
    int start = NbDocument.findLineOffset (document, ln);
    int end = document.getLength ();
    try {
        end = NbDocument.findLineOffset (document, ln + 1) - 1;
    } catch (IndexOutOfBoundsException ex) {
    }
    TokenSequence ts = Utils.getTokenSequence (document, start);
    if (ts.token () == null) return true;
    while (whitespaces.contains (ts.token ().id ().ordinal ())) {
        if (!ts.moveNext ()) return true;
        if (ts.offset () > end) return true;
    }
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:IndentFactory.java

示例2: getPosition

import javax.swing.text.StyledDocument; //导入方法依赖的package包/类
private static Position getPosition(final StyledDocument doc, final int offset) {
    class Impl implements Runnable {
        private Position pos;
        public void run() {
            if (offset < 0 || offset >= doc.getLength())
                return ;

            try {
                pos = doc.createPosition(offset - NbDocument.findLineColumn(doc, offset));
            } catch (BadLocationException ex) {
                //should not happen?
                Logger.getLogger(ComputeAnnotations.class.getName()).log(Level.FINE, null, ex);
            }
        }
    }

    Impl i = new Impl();

    doc.render(i);

    return i.pos;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:ComputeAnnotations.java

示例3: markGuarded

import javax.swing.text.StyledDocument; //导入方法依赖的package包/类
/** Marks or unmarks the section as guarded.
 * @param doc The styled document where this section placed in.
 * @param bounds The rangeof text which should be marked or unmarked.
 * @param mark true means mark, false unmark.
 */
void markGuarded(StyledDocument doc, PositionBounds bounds, boolean mark) {
    int begin = bounds.getBegin().getOffset();
    int end = bounds.getEnd().getOffset();
    
    if (end == doc.getLength() + 1) {
        end--;
    }
    GuardedRegionMarker marker = LineDocumentUtils.as(doc, GuardedRegionMarker.class);
    if (marker != null) {
        if (mark) {
            marker.protectRegion(begin, end - begin + 1);
        } else {
            marker.unprotectRegion(begin, end - begin + 1);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:GuardedSectionImpl.java

示例4: reallyLog

import javax.swing.text.StyledDocument; //导入方法依赖的package包/类
private void reallyLog(String text, Style style) {
    if (log==null || text.length()==0) return;
    int i=text.lastIndexOf('\n'), j=text.lastIndexOf('\r');
    if (i>=0 && i<j) { i=j; }
    StyledDocument doc=log.getStyledDocument();
    try {
        if (i<0) {
            doc.insertString(doc.getLength(), text, style);
        } else {
            // Performs intelligent caret positioning
            doc.insertString(doc.getLength(), text.substring(0,i+1), style);
            log.setCaretPosition(doc.getLength());
            if (i<text.length()-1) {
                doc.insertString(doc.getLength(), text.substring(i+1), style);
            }
        }
    } catch (BadLocationException e) {
        // Harmless
    }
    if (style!=styleRed) { lastSize=doc.getLength(); }
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:22,代码来源:SwingLogPanel.java

示例5: reallyLog

import javax.swing.text.StyledDocument; //导入方法依赖的package包/类
private void reallyLog(String text, Style style) {
	if (log == null || text.length() == 0)
		return;
	int i = text.lastIndexOf('\n'), j = text.lastIndexOf('\r');
	if (i >= 0 && i < j) {
		i = j;
	}
	StyledDocument doc = log.getStyledDocument();
	try {
		if (i < 0) {
			doc.insertString(doc.getLength(), text, style);
		} else {
			// Performs intelligent caret positioning
			doc.insertString(doc.getLength(), text.substring(0, i + 1), style);
			log.setCaretPosition(doc.getLength());
			if (i < text.length() - 1) {
				doc.insertString(doc.getLength(), text.substring(i + 1), style);
			}
		}
	} catch (BadLocationException e) {
		// Harmless
	}
	if (style != styleRed) {
		lastSize = doc.getLength();
	}
}
 
开发者ID:AlloyTools,项目名称:org.alloytools.alloy,代码行数:27,代码来源:SwingLogPanel.java

示例6: setLength

import javax.swing.text.StyledDocument; //导入方法依赖的package包/类
/**
 * Truncate the log to the given length; if the log is shorter than the
 * number given, then nothing happens.
 */
void setLength(int newLength) {
	if (log == null)
		return;
	clearError();
	StyledDocument doc = log.getStyledDocument();
	int n = doc.getLength();
	if (n <= newLength)
		return;
	try {
		doc.remove(newLength, n - newLength);
	} catch (BadLocationException e) {
		// Harmless
	}
	if (lastSize > doc.getLength()) {
		lastSize = doc.getLength();
	}
}
 
开发者ID:AlloyTools,项目名称:org.alloytools.alloy,代码行数:22,代码来源:SwingLogPanel.java

示例7: clearError

import javax.swing.text.StyledDocument; //导入方法依赖的package包/类
/** Removes any messages writtin in "red" style. */
public void clearError() {
	if (log == null)
		return;
	// Since this class always removes "red" messages prior to writing
	// anything,
	// that means if there are any red messages, they will always be at the
	// end of the JTextPane.
	StyledDocument doc = log.getStyledDocument();
	int n = doc.getLength();
	if (n > lastSize) {
		try {
			doc.remove(lastSize, n - lastSize);
		} catch (BadLocationException e) {}
	}
	if (batch.size() > 0) {
		for (String msg : batch) {
			reallyLog(msg, styleRegular);
		}
		batch.clear();
	}
}
 
开发者ID:AlloyTools,项目名称:org.alloytools.alloy,代码行数:23,代码来源:SwingLogPanel.java

示例8: showDescription

import javax.swing.text.StyledDocument; //导入方法依赖的package包/类
private void showDescription() {
    StyledDocument doc = descValue.getStyledDocument();
    final Boolean matchCase = matchCaseValue.isSelected();
    try {
        doc.remove(0, doc.getLength());
        ModuleDependency[] deps = getSelectedDependencies();
        if (deps.length != 1) {
            return;
        }
        String longDesc = deps[0].getModuleEntry().getLongDescription();
        if (longDesc != null) {
            doc.insertString(0, longDesc, null);
        }
        String filterText = filterValue.getText().trim();
        if (filterText.length() != 0 && !FILTER_DESCRIPTION.equals(filterText)) {
            doc.insertString(doc.getLength(), "\n\n", null); // NOI18N
            Style bold = doc.addStyle(null, null);
            bold.addAttribute(StyleConstants.Bold, Boolean.TRUE);
            doc.insertString(doc.getLength(), getMessage("TEXT_matching_filter_contents"), bold);
            doc.insertString(doc.getLength(), "\n", null); // NOI18N
            if (filterText.length() > 0) {
                String filterTextLC = matchCase?filterText:filterText.toLowerCase(Locale.US);
                Style match = doc.addStyle(null, null);
                match.addAttribute(StyleConstants.Background, UIManager.get("selection.highlight")!=null?
                        UIManager.get("selection.highlight"):new Color(246, 248, 139));
                boolean isEven = false;
                Style even = doc.addStyle(null, null);
                even.addAttribute(StyleConstants.Background, UIManager.get("Panel.background"));
                if (filterer == null) {
                    return; // #101776
                }
                for (String hit : filterer.getMatchesFor(filterText, deps[0])) {
                    int loc = doc.getLength();
                    doc.insertString(loc, hit, (isEven ? even : null));
                    int start = (matchCase?hit:hit.toLowerCase(Locale.US)).indexOf(filterTextLC);
                    while (start != -1) {
                        doc.setCharacterAttributes(loc + start, filterTextLC.length(), match, true);
                        start = hit.toLowerCase(Locale.US).indexOf(filterTextLC, start + 1);
                    }
                    doc.insertString(doc.getLength(), "\n", (isEven ? even : null)); // NOI18N
                    isEven ^= true;
                }
            } else {
                Style italics = doc.addStyle(null, null);
                italics.addAttribute(StyleConstants.Italic, Boolean.TRUE);
                doc.insertString(doc.getLength(), getMessage("TEXT_no_filter_specified"), italics);
            }
        }
        descValue.setCaretPosition(0);
    } catch (BadLocationException e) {
        Util.err.notify(ErrorManager.INFORMATIONAL, e);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:54,代码来源:AddModulePanel.java

示例9: RevisionLinker

import javax.swing.text.StyledDocument; //导入方法依赖的package包/类
public RevisionLinker (String revision, StyledDocument sd, File repository, File root) {
    this.revision = revision;
    this.repository = repository;
    this.root = root;
    int doclen = sd.getLength();
    int textlen = revision.length();

    docstart = doclen;
    docend = doclen + textlen;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:TooltipWindow.java

示例10: do_command

import javax.swing.text.StyledDocument; //导入方法依赖的package包/类
/** This method processes a user command. */
private void do_command(Computer computer, String cmd) {
   cmd = cmd.trim();
   if (cmd.length()==0) return;
   StyledDocument doc = main.getStyledDocument();
   if (history.size()>=2 && cmd.equals(history.get(history.size()-2))) {
      // If the user merely repeated the most recent command, then don't grow the history
      history.set(history.size()-1, "");
   } else {
      // Otherwise, grow the history
      history.set(history.size()-1, cmd);
      history.add("");
   }
   browse = history.size()-1;
   // display the command
   int old = doc.getLength();   do_add(len, cmd+"\n\n", plain);   len += (doc.getLength() - old);
   // perform the computation
   boolean isBad = false;
   try { cmd = computer.compute(cmd); } catch(Throwable ex) { cmd = ex.toString(); isBad = true; }
   int savePosition = len;
   // display the outcome
   old = doc.getLength();   do_add(len, cmd.trim()+"\n\n", (isBad ? bad : good));    len += (doc.getLength() - old);
   // indent the outcome
   main.setSelectionStart(savePosition+1);   main.setSelectionEnd(len);   main.setParagraphAttributes(good, false);
   // redraw then scroll to the bottom
   invalidate();
   repaint();
   validate();
   sub.scrollRectToVisible(new Rectangle(0, sub.getY(), 1, sub.getHeight()));
   do_pagedown(); // need to do this after the validate() so that the scrollbar knows the new limit
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:32,代码来源:OurConsole.java

示例11: IssueLinker

import javax.swing.text.StyledDocument; //导入方法依赖的package包/类
private IssueLinker(VCSHyperlinkProvider hp, Style issueHyperlinkStyle, File root, StyledDocument sd, String text, int[] spans) {
    this.length = spans.length / 2;
    this.docstart = new int[length];
    this.docend = new int[length];
    this.start = new int[length];
    this.end = new int[length];
    this.hp = hp;
    this.root = root;
    this.text = text;
    this.issueHyperlinkStyle = issueHyperlinkStyle;

    for (int i = 0; i < spans.length;) {
        int linkeridx = i / 2;
        int spanstart = spans[i++];
        int spanend = spans[i++];
        if(spanend < spanstart) {
            LOG.warning("Hyperlink provider " + hp.getClass().getName() + " returns wrong spans [" + spanstart + "," + spanend + "]");
            continue;
        }

        int doclen = sd.getLength();
        this.start[linkeridx] = spanstart;
        this.end[linkeridx] = spanend;
        this.docstart[linkeridx] = doclen + spanstart;
        this.docend[linkeridx] = doclen + spanend;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:28,代码来源:VCSHyperlinkSupport.java

示例12: AuthorLinker

import javax.swing.text.StyledDocument; //导入方法依赖的package包/类
public AuthorLinker(KenaiUser kenaiUser, Style authorStyle, StyledDocument sd, String author, String insertToChat) throws BadLocationException {
    this.kenaiUser = kenaiUser;
    this.author = author;
    this.authorStyle = authorStyle;
    this.insertToChat = insertToChat;

    int doclen = sd.getLength();
    int textlen = author.length();

    docstart = doclen;
    docend = doclen + textlen;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:VCSHyperlinkSupport.java

示例13: add

import javax.swing.text.StyledDocument; //导入方法依赖的package包/类
/**
 * Add text to the transaction log.
 *
 * @param text The text to add.
 */
private void add(String text) {
    StyledDocument doc = getStyledDocument();
    try {
        if (doc.getLength() > 0) text = "\n\n" + text;
        doc.insertString(doc.getLength(), text, null);
    } catch (Exception e) {
        logger.log(Level.WARNING, "Transaction log update failure", e);
    }
}
 
开发者ID:wintertime,项目名称:FreeCol,代码行数:15,代码来源:EuropePanel.java

示例14: setLength

import javax.swing.text.StyledDocument; //导入方法依赖的package包/类
/** Truncate the log to the given length; if the log is shorter than the number given, then nothing happens. */
void setLength(int newLength) {
    if (log==null) return;
    clearError();
    StyledDocument doc=log.getStyledDocument();
    int n=doc.getLength();
    if (n<=newLength) return;
    try {
        doc.remove(newLength, n-newLength);
    } catch (BadLocationException e) {
        // Harmless
    }
    if (lastSize>doc.getLength()) { lastSize=doc.getLength(); }
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:15,代码来源:SwingLogPanel.java

示例15: clearError

import javax.swing.text.StyledDocument; //导入方法依赖的package包/类
/** Removes any messages writtin in "red" style. */
public void clearError() {
    if (log==null) return;
    // Since this class always removes "red" messages prior to writing anything,
    // that means if there are any red messages, they will always be at the end of the JTextPane.
    StyledDocument doc=log.getStyledDocument();
    int n=doc.getLength();
    if (n>lastSize) {
        try {doc.remove(lastSize, n-lastSize);} catch (BadLocationException e) {}
    }
    if (batch.size()>0) {
        for(String msg: batch) { reallyLog(msg, styleRegular); }
        batch.clear();
    }
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:16,代码来源:SwingLogPanel.java


注:本文中的javax.swing.text.StyledDocument.getLength方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。