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


Java StyledDocument类代码示例

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


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

示例1: insideAttribute

import javax.swing.text.StyledDocument; //导入依赖的package包/类
/**
 * Checks if caret position is inside attributes quotes
 *
 * @param doc edited document
 * @param caretOffset current caret location offset
 * @return true if caret inside attribute
 */
static boolean insideAttribute(StyledDocument doc, int caretOffset) {
    boolean insideQuotes = false;
    while (caretOffset > 0) {
        try {
            String chars = doc.getText(caretOffset - 1, 1);
            if (chars.equals("<") || chars.equals("\"") && insideQuotes) {
                return false;
            } else if (chars.equals("\"") && (doc.getText(caretOffset - 2, 1).equals("="))) {
                return true;
            } else if (chars.equals("\"")) {
                insideQuotes = true;
            }
            caretOffset--;
        } catch (BadLocationException ex) {
            Exceptions.printStackTrace(ex);
        }
    }
    return false;
}
 
开发者ID:ArturWisniewski,项目名称:NB-Thymeleaf-Code-Completion,代码行数:27,代码来源:CompletionUtils.java

示例2: attachDetach

import javax.swing.text.StyledDocument; //导入依赖的package包/类
private void attachDetach(ToDo t) {
    if (t.lineStart != null) {
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("addAnnotation: pos=" + t.lineStart.getOffset() + ", a="+ t.a + ", doc=" +
                    System.identityHashCode(doc) + "\n");
        }
        t.a.attachAnnotation((StyledDocument) doc, t.lineStart);
    } else {
        if (doc != null) {
            if (LOG.isLoggable(Level.FINE)) {
                LOG.fine("removeAnnotation: a=" + t.a + ", doc=" + System.identityHashCode(doc) + "\n");
            }
            t.a.detachAnnotation((StyledDocument) doc);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:AnnotationHolder.java

示例3: computeLineSpan

import javax.swing.text.StyledDocument; //导入依赖的package包/类
static int[] computeLineSpan(Document doc, int lineNumber) throws BadLocationException {
    lineNumber = Math.min(lineNumber, NbDocument.findLineRootElement((StyledDocument) doc).getElementCount());
    
    int lineStartOffset = NbDocument.findLineOffset((StyledDocument) doc, Math.max(0, lineNumber - 1));
    int lineEndOffset;
    
    if (doc instanceof BaseDocument) {
        lineEndOffset = Utilities.getRowEnd((BaseDocument) doc, lineStartOffset);
    } else {
        //XXX: performance:
        String lineText = doc.getText(lineStartOffset, doc.getLength() - lineStartOffset);
        
        lineText = lineText.indexOf('\n') != (-1) ? lineText.substring(0, lineText.indexOf('\n')) : lineText;
        lineEndOffset = lineStartOffset + lineText.length();
    }
    
    int[] span = new int[] {lineStartOffset, lineEndOffset};
    
    computeLineSpan(doc, span);
    
    return span;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:HintsControllerImpl.java

示例4: generate

import javax.swing.text.StyledDocument; //导入依赖的package包/类
private void generate(final Document doc, final Descriptor desc, final JTextComponent jtc) throws BadLocationException {
    final Indent ie = Indent.get(doc);
    try {
        ie.lock();
        NbDocument.runAtomicAsUser((StyledDocument) doc, new Runnable() {

            public void run() {
                try {
                    int caretPos = jtc.getCaretPosition();
                    generateJavadoc(doc, desc, ie);
                    // move caret
                    jtc.setCaretPosition(caretPos);
                } catch (BadLocationException ex) {
                    Exceptions.printStackTrace(ex);
                }
            }

        });
    } finally {
        ie.unlock();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:GenerateJavadocAction.java

示例5: defaultAction

import javax.swing.text.StyledDocument; //导入依赖的package包/类
@Override
public void defaultAction(final JTextComponent component) {
    Completion.get().hideCompletion();
    Completion.get().hideDocumentation();
    NbDocument.runAtomic((StyledDocument) component.getDocument(), new Runnable() {
        @Override
        public void run() {
            Document doc = component.getDocument();
            
            try {
                doc.remove(substituteOffset, component.getCaretPosition() - substituteOffset);
                doc.insertString(substituteOffset, getText(), null);
            } catch (BadLocationException e) {
                Logger.getLogger(FXMLCompletionItem.class.getName()).log(Level.FINE, null, e);
            }
        }
    });
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:FXMLCompletionItem.java

示例6: testCallingFromAWTIsOk

import javax.swing.text.StyledDocument; //导入依赖的package包/类
public void testCallingFromAWTIsOk() throws Exception {
    StyledDocument doc = support.openDocument();
    doc.insertString(0, "Ble", null);
    
    assertTrue("Modified", support.isModified());
    
    class AWT implements Runnable {
        boolean success;
        
        public synchronized void run() {
            success = support.canClose();
        }
    }
    
    AWT b = new AWT();
    javax.swing.SwingUtilities.invokeAndWait(b);
    
    assertTrue("Ok, we managed to ask the question", b.success);
    
    if (ErrManager.messages.length() > 0) {
        fail("No messages should be reported: " + ErrManager.messages);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:DocumentCannotBeClosedWhenAWTBlockedTest.java

示例7: 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

示例8: refreshDocument

import javax.swing.text.StyledDocument; //导入依赖的package包/类
private static void refreshDocument(final FileObject fo) throws IOException {
    RP.post(new Runnable() {
        @Override
        public void run() {
            try {
                DataObject dobj = DataObject.find(fo);
                EditorCookie editorCookie = dobj.getLookup().lookup(EditorCookie.class);
                StyledDocument document = editorCookie.openDocument();
                forceReparse(document);
            } catch (IOException  ex) {
                Exceptions.printStackTrace(ex);
            }
        }
    });

}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:HtmlHintsProvider.java

示例9: 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

示例10: defaultAction

import javax.swing.text.StyledDocument; //导入依赖的package包/类
@Override
public void defaultAction(final JTextComponent component) {
    Completion.get().hideCompletion();
    Completion.get().hideDocumentation();
    NbDocument.runAtomic((StyledDocument) component.getDocument(), new Runnable() {
        @Override
        public void run() {
            Document doc = component.getDocument();

            try {
                doc.remove(0, doc.getLength());
                doc.insertString(0, getText(), null);
            } catch (BadLocationException e) {
                Logger.getLogger(SearchCompletionItem.class.getName()).log(Level.FINE, null, e);
            }
        }
    });
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:SearchCompletionItem.java

示例11: loadFromStreamToKit

import javax.swing.text.StyledDocument; //导入依赖的package包/类
@Override
protected void loadFromStreamToKit(StyledDocument doc, InputStream stream, EditorKit kit) throws IOException, BadLocationException {
    if (guardedEditor == null) {
        guardedEditor = new FormGEditor();
        GuardedSectionsFactory gFactory = GuardedSectionsFactory.find("text/x-java");
        if (gFactory != null) {
            guardedProvider = gFactory.create(guardedEditor);
        }
    }

    if (guardedProvider != null) {
        guardedEditor.doc = doc;
        Charset c = FileEncodingQuery.getEncoding(this.getDataObject().getPrimaryFile());
        Reader reader = guardedProvider.createGuardedReader(stream, c);
        try {
            kit.read(reader, doc, 0);
        } finally {
            reader.close();
        }
    } else {
        super.loadFromStreamToKit(doc, stream, kit);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:GuardedBlockTest.java

示例12: logDivider

import javax.swing.text.StyledDocument; //导入依赖的package包/类
/** Write a horizontal separator into the log window. */
public void logDivider() {
	if (log == null)
		return;
	clearError();
	StyledDocument doc = log.getStyledDocument();
	Style dividerStyle = doc.addStyle("bar", styleRegular);
	JPanel jpanel = new JPanel();
	jpanel.setBackground(Color.LIGHT_GRAY);
	jpanel.setPreferredSize(new Dimension(300, 1)); // 300 is arbitrary,
													// since it will
													// auto-stretch
	StyleConstants.setComponent(dividerStyle, jpanel);
	reallyLog(".", dividerStyle); // Any character would do; "." will be
									// replaced by the JPanel
	reallyLog("\n\n", styleRegular);
	log.setCaretPosition(doc.getLength());
	lastSize = doc.getLength();
}
 
开发者ID:AlloyTools,项目名称:org.alloytools.alloy,代码行数:20,代码来源:SwingLogPanel.java

示例13: insertString

import javax.swing.text.StyledDocument; //导入依赖的package包/类
@Override
public void insertString(StyledDocument sd, Style style) throws BadLocationException {
    if(style == null) {
        style = authorStyle;
    }
    sd.insertString(sd.getLength(), author, style);

    String iconStyleName = AUTHOR_ICON_STYLE + author;
    Style iconStyle = sd.getStyle(iconStyleName);
    if(iconStyle == null) {
        iconStyle = sd.addStyle(iconStyleName, null);
        StyleConstants.setIcon(iconStyle, kenaiUser.getIcon());
    }
    sd.insertString(sd.getLength(), " ", style);
    sd.insertString(sd.getLength(), " ", iconStyle);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:VCSHyperlinkSupport.java

示例14: getCurrentTagName

import javax.swing.text.StyledDocument; //导入依赖的package包/类
/**
 * Checks if caret is inside tag and returns tags name
 *
 * @param doc edited document
 * @param caretOffset current caret location offset
 * @return String tag name or empty if not inside tag
 * @throws BadLocationException
 */
static String getCurrentTagName(StyledDocument doc, int caretOffset) throws BadLocationException {
    int lastWhiteSpace = caretOffset;
    while (caretOffset > 0) {
        String chars = doc.getText(caretOffset - 1, 1);
        if (chars.equals(">")) {
            break;
        } else if (chars.equals(" ")) {
            lastWhiteSpace = caretOffset;
        } else if (chars.equals("<")) {
            return doc.getText(caretOffset, lastWhiteSpace - caretOffset);
        }
        caretOffset--;
    }
    return "";
}
 
开发者ID:ArturWisniewski,项目名称:NB-Thymeleaf-Code-Completion,代码行数:24,代码来源:CompletionUtils.java

示例15: testNationalCharactersSaved

import javax.swing.text.StyledDocument; //导入依赖的package包/类
public void testNationalCharactersSaved() throws Exception {
    DataObject d = DataObject.find(testFileObject);
    
    encodingName = "ISO-8859-2"; // NOI18N
    
    EditorCookie o = d.getLookup().lookup(EditorCookie.class);
    StyledDocument doc = o.openDocument();
    doc.insertString(0, CZECH_STRING_UTF, null);
    
    o.saveDocument();

    // try to open the file
    InputStream istm = testFileObject.getInputStream();
    try {
        BufferedReader r = new BufferedReader(new InputStreamReader(istm, "ISO-8859-2")); // NOI18N
        String line = r.readLine();

        assertEquals("Text differs", CZECH_STRING_UTF, line); // NOI18N
    } finally {
        istm.close();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:DataEditorSupportEncodingTest.java


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