本文整理汇总了Java中org.fife.ui.rsyntaxtextarea.RSyntaxDocument类的典型用法代码示例。如果您正苦于以下问题:Java RSyntaxDocument类的具体用法?Java RSyntaxDocument怎么用?Java RSyntaxDocument使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RSyntaxDocument类属于org.fife.ui.rsyntaxtextarea包,在下文中一共展示了RSyntaxDocument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: SQLEditor
import org.fife.ui.rsyntaxtextarea.RSyntaxDocument; //导入依赖的package包/类
public SQLEditor() {
super(new RSyntaxDocument(TextType.SQL.getSyntaxIdentifier()));
setAnimateBracketMatching(true);
setAutoIndentEnabled(true);
setAutoscrolls(true);
// A CompletionProvider is what knows of all possible completions, and
// analyzes the contents of the text area at the caret position to
// determine what completion choices should be presented. Most instances
// of CompletionProvider (such as DefaultCompletionProvider) are designed
// so that they can be shared among multiple text components.
CompletionProvider provider = new LanguageAwareCompletionProvider(new DefaultCompletionProvider(BASIC_SQL_DIALECT));
// An AutoCompletion acts as a "middle-man" between a text component
// and a CompletionProvider. It manages any options associated with
// the auto-completion (the popup trigger key, whether to display a
// documentation window along with completion choices, etc.). Unlike
// CompletionProviders, instances of AutoCompletion cannot be shared
// among multiple text components.
AutoCompletion ac = new AutoCompletion(provider);
ac.install(this);
requestFocusInWindow();
}
示例2: testParse_error_unclosedTag_nodtd
import org.fife.ui.rsyntaxtextarea.RSyntaxDocument; //导入依赖的package包/类
@Test
public void testParse_error_unclosedTag_nodtd() throws Exception {
XmlParser parser = new XmlParser();
// Include a DTD just for more code coverage
RSyntaxDocument doc = new RSyntaxDocument(
SyntaxConstants.SYNTAX_STYLE_XML);
doc.insertString(0, "<?xml version='1.0'?>\n" +
"<books>", null);
ParseResult res = parser.parse(doc, doc.getSyntaxStyle());
Assert.assertEquals(parser, res.getParser());
Assert.assertEquals(0, res.getFirstLineParsed());
Assert.assertEquals(1, res.getLastLineParsed());
List<ParserNotice> notices = res.getNotices();
Assert.assertEquals(1, notices.size());
ParserNotice notice = notices.get(0);
Assert.assertEquals(ParserNotice.Level.ERROR, notice.getLevel());
}
示例3: testParse_error_unclosedTag_withDtd
import org.fife.ui.rsyntaxtextarea.RSyntaxDocument; //导入依赖的package包/类
@Test
public void testParse_error_unclosedTag_withDtd() throws Exception {
XmlParser parser = new XmlParser();
// Include a DTD just for more code coverage
RSyntaxDocument doc = new RSyntaxDocument(
SyntaxConstants.SYNTAX_STYLE_XML);
doc.insertString(0, "<?xml version='1.0'?>\n" +
"<!DOCTYPE RSyntaxTheme SYSTEM \"theme.dtd\">\n" +
"<books>", null);
ParseResult res = parser.parse(doc, doc.getSyntaxStyle());
Assert.assertEquals(parser, res.getParser());
Assert.assertEquals(0, res.getFirstLineParsed());
Assert.assertEquals(2, res.getLastLineParsed());
List<ParserNotice> notices = res.getNotices();
Assert.assertEquals(1, notices.size());
ParserNotice notice = notices.get(0);
Assert.assertEquals(ParserNotice.Level.ERROR, notice.getLevel());
}
示例4: testParse_happyPath
import org.fife.ui.rsyntaxtextarea.RSyntaxDocument; //导入依赖的package包/类
@Test
public void testParse_happyPath() throws Exception {
TaskTagParser parser = new TaskTagParser();
RSyntaxDocument doc = new RSyntaxDocument(
SyntaxConstants.SYNTAX_STYLE_C);
doc.insertString(0, "/* TODO: Fix this */", null);
ParseResult res = parser.parse(doc, doc.getSyntaxStyle());
Assert.assertEquals(parser, res.getParser());
Assert.assertEquals(0, res.getFirstLineParsed());
Assert.assertEquals(0, res.getLastLineParsed());
List<ParserNotice> notices = res.getNotices();
Assert.assertEquals(1, notices.size());
// Note that the parser does not understand EOL vs. MLC comments, so
// it just returns everything from the start of the task to the end of
// the line.
Assert.assertEquals("TODO: Fix this */", notices.get(0).getToolTipText());
}
示例5: testParse_nullTaskPattern
import org.fife.ui.rsyntaxtextarea.RSyntaxDocument; //导入依赖的package包/类
@Test
public void testParse_nullTaskPattern() throws Exception {
TaskTagParser parser = new TaskTagParser();
parser.setTaskPattern(null);
RSyntaxDocument doc = new RSyntaxDocument(
SyntaxConstants.SYNTAX_STYLE_C);
doc.insertString(0, "/* TODO: Fix this */ for", null);
ParseResult res = parser.parse(doc, doc.getSyntaxStyle());
Assert.assertEquals(parser, res.getParser());
Assert.assertEquals(0, res.getFirstLineParsed());
Assert.assertEquals(0, res.getLastLineParsed());
List<ParserNotice> notices = res.getNotices();
Assert.assertEquals(0, notices.size());
}
示例6: testParse_noLanguage
import org.fife.ui.rsyntaxtextarea.RSyntaxDocument; //导入依赖的package包/类
@Test
public void testParse_noLanguage() throws Exception {
TaskTagParser parser = new TaskTagParser();
parser.setTaskPattern(null);
RSyntaxDocument doc = new RSyntaxDocument(
SyntaxConstants.SYNTAX_STYLE_NONE);
doc.insertString(0, "/* TODO: Fix this */ for", null);
ParseResult res = parser.parse(doc, doc.getSyntaxStyle());
Assert.assertEquals(parser, res.getParser());
Assert.assertEquals(0, res.getFirstLineParsed());
Assert.assertEquals(0, res.getLastLineParsed());
List<ParserNotice> notices = res.getNotices();
Assert.assertEquals(0, notices.size());
doc.setSyntaxStyle((String)null); // Not really valid, but whatever
res = parser.parse(doc, doc.getSyntaxStyle());
Assert.assertEquals(parser, res.getParser());
Assert.assertEquals(0, res.getFirstLineParsed());
Assert.assertEquals(0, res.getLastLineParsed());
notices = res.getNotices();
Assert.assertEquals(0, notices.size());
}
示例7: parse
import org.fife.ui.rsyntaxtextarea.RSyntaxDocument; //导入依赖的package包/类
@Override
public ParseResult parse(RSyntaxDocument doc, String style) {
DefaultParseResult result = new DefaultParseResult(this);
CodeModel.ErrorMessage errorMessage = codeModel.compileScript(sourceFile);
if (errorMessage != null) {
int line = errorMessage.line - 1;
try {
DefaultParserNotice notice = new DefaultParserNotice(this,
errorMessage.message,
line,
textArea.getLineStartOffset(line),
textArea.getLineEndOffset(line));
result.addNotice(notice);
} catch (BadLocationException e) {
// Do nothing
}
}
return result;
}
示例8: parse
import org.fife.ui.rsyntaxtextarea.RSyntaxDocument; //导入依赖的package包/类
@Override // lang can be set using editor.setSyntaxEditingStyle
public ParseResult parse(RSyntaxDocument code, String lang) {
DefaultParseResult result = new DefaultParseResult(this);
if((lang != "sat" && lang != "smt" && lang != "qbf") || code.getLength()==0)
return result;
if(bufferErrors == null) {
try {
TranslationLatex tr = new TranslationLatex(code.getText(0, code.getLength()), lang, true);
bufferErrors = tr.getErrors();
if (tr.getFormula().length() != 0 && edition != null) {
edition.setLatex(tr.getFormula());
}
} catch (Exception e) {
e.printStackTrace();
}
}
for (TranslationError error : bufferErrors) {
result.addNotice(new ErrorParserNotice(this, error));
}
bufferErrors = null;
return result;
}
示例9: getCurrentLine
import org.fife.ui.rsyntaxtextarea.RSyntaxDocument; //导入依赖的package包/类
public String getCurrentLine() {
if (syntaxDocument == null)
updateDocument();
RSyntaxDocument myDoc = syntaxDocument; // the RSyntaxDocument being edited
int caretpos = editorPane.getCaretPosition(); // the caret's current position
int startpos = editorPane.getCaretOffsetFromLineStart(); // offset of caret from the start of line
// subtract the offset from the start of line, in order scanpos to be the position of the start of the line
int scanpos = caretpos - startpos;
// scan until a newline accumulating the line
String s = "";
try {
char ch = myDoc.charAt(scanpos);
while (ch != '\n') {
s += myDoc.charAt(scanpos);
scanpos += 1;
ch = myDoc.charAt(scanpos);
}
} catch (BadLocationException ex) {
ex.printStackTrace();
}
return s; // return the string of the current line
}
示例10: addNotices
import org.fife.ui.rsyntaxtextarea.RSyntaxDocument; //导入依赖的package包/类
/**
* Adds all notices from the Java parser to the results object.
*/
private void addNotices(RSyntaxDocument doc) {
result.clearNotices();
int count = cu==null ? 0 : cu.getParserNoticeCount();
if (count==0) {
return;
}
for (int i=0; i<count; i++) {
ParserNotice notice = cu.getParserNotice(i);
int offs = getOffset(doc, notice);
if (offs>-1) {
int len = notice.getLength();
result.addNotice(new DefaultParserNotice(this,
notice.getMessage(), notice.getLine(), offs, len));
}
}
}
示例11: actionPerformed
import org.fife.ui.rsyntaxtextarea.RSyntaxDocument; //导入依赖的package包/类
public void actionPerformed(ActionEvent e) {
RSyntaxTextArea textArea = (RSyntaxTextArea)getTextComponent(e);
RSyntaxDocument doc = (RSyntaxDocument)textArea.getDocument();
Caret c = textArea.getCaret();
int dot = c.getDot(); // Get before "<" insertion
boolean selection = dot!=c.getMark(); // Me too
textArea.replaceSelection(">");
// Don't automatically complete a tag if there was a selection
if (!selection && getAutoAddClosingTags()) {
Token t = doc.getTokenListForLine(textArea.getCaretLineNumber());
t = RSyntaxUtilities.getTokenAtOffset(t, dot);
if (t!=null && t.isSingleChar(Token.MARKUP_TAG_DELIMITER, '>')) {
String tagName = discoverTagName(doc, dot);
if (tagName!=null) {
textArea.replaceSelection("</" + tagName + ">");
textArea.setCaretPosition(dot+1);
}
}
}
}
示例12: parse
import org.fife.ui.rsyntaxtextarea.RSyntaxDocument; //导入依赖的package包/类
@Override
public ParseResult parse(RSyntaxDocument doc, String style) {
ZScriptAst old = ast;
AstFactory parser2 = new AstFactory(doc, this, null);
ZScriptParseResult zspr = parser2.parse();
DefaultParseResult result = new DefaultParseResult(this);
ast = zspr.getAst();
List<ParserNotice> notices = zspr.getNotices();
for (ParserNotice notice : notices) {
//System.out.println(">>> " + notice);
result.addNotice(notice);
}
support.firePropertyChange(PROPERTY_AST, old, ast);
//System.out.println("----------");
//ast.getRootNode().accept(new org.fife.rsta.zscript.ast.AstPrinter());
//System.out.println("----------");
return result;
}
示例13: isAutoActivateOkay
import org.fife.ui.rsyntaxtextarea.RSyntaxDocument; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public boolean isAutoActivateOkay(JTextComponent tc) {
boolean ok = super.isAutoActivateOkay(tc);
// In our constructor, we set up auto-activation of the completion
// popup to occur on space chars. This extra check makes it a little
// more sane, by only letting space auto-activate completion choices
// for property values.
if (ok) {
RSyntaxDocument doc = (RSyntaxDocument)tc.getDocument();
int dot = tc.getCaretPosition();
try {
if (dot>1 && doc.charAt(dot)==' ') { // Caret hasn't advanced (?)
ok = doc.charAt(dot-1)==':';
}
} catch (BadLocationException ble) {
ble.printStackTrace(); // Never happens
}
}
return ok;
}
示例14: sniff
import org.fife.ui.rsyntaxtextarea.RSyntaxDocument; //导入依赖的package包/类
public ValidationConfig sniff(RSyntaxDocument doc) {
ValidationConfig config = null;
OUTER:
for (Token token : doc) {
switch (token.getType()) {
case TokenTypes.MARKUP_DTD:
//System.out.println("DTD: " + token.getLexeme());
break OUTER;
case TokenTypes.MARKUP_TAG_NAME:
// We only care about the first element
//System.out.println("First element: " + token.getLexeme());
break OUTER;
}
}
return config;
}
示例15: XMLEditor
import org.fife.ui.rsyntaxtextarea.RSyntaxDocument; //导入依赖的package包/类
public XMLEditor(MainFrame mainFrame) {
super(new BorderLayout());
this.mainFrame = mainFrame;
// create text area
this.editor = new RSyntaxTextArea(new RSyntaxDocument(SyntaxConstants.SYNTAX_STYLE_XML));
this.editor.setAnimateBracketMatching(true);
this.editor.setAutoIndentEnabled(true);
this.editor.setSelectionColor(Colors.TEXT_HIGHLIGHT_BACKGROUND);
this.editor.setBorder(null);
JToolBar toolBar = new ExtendedJToolBar();
toolBar.setBorder(null);
toolBar.add(new ResourceAction(true, "xml_editor.apply_changes") {
private static final long serialVersionUID = 1L;
@Override
public void actionPerformed(ActionEvent e) {
try {
validateProcess();
} catch (IOException | XMLException e1) {
LogService.getRoot().log(Level.WARNING,
"com.rapidminer.gui.processeditor.XMLEditor.failed_to_parse_process");
}
}
});
toolBar.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Colors.TEXTFIELD_BORDER));
add(toolBar, BorderLayout.NORTH);
RTextScrollPane rTextScrollPane = new RTextScrollPane(editor);
rTextScrollPane.setBorder(null);
add(rTextScrollPane, BorderLayout.CENTER);
}