@Override public void run() { textArea.setText(content); restoreScrollPosition(scrollPercent); } });
public void setContent(String content) { textArea.setText(content); }
@Override public void setViewText(String text) { textArea.setText(text); }
private void setContentPreserveLastScrollPosition(final String content) { final Double scrollPercent = lastScrollPercent; if (scrollPercent != null && initialNavigationLink == null) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { textArea.setText(content); restoreScrollPosition(scrollPercent); } }); } else { textArea.setText(content); } }
@Override public void clear() { jp_contentType.clear(); jtf_name.setText(""); jta_part.setText(""); }
private void registerLogListener() { LogCollector logCollector = LogCollector.getInstance(); logCollector.resetListener(); textPane.setText(""); logCollector.registerListener(new ILogListener() { @Override public Level getFilterLevel() { return level; } @Override public void onAppend(final String logStr) { SwingUtilities.invokeLater(() -> textPane.append(logStr)); } }); }
private Component makeCell(JNode node, int column) { if (column == 0) { JLabel label = new JLabel(node.makeLongString() + " ", node.getIcon(), SwingConstants.LEFT); label.setFont(font); label.setOpaque(true); label.setToolTipText(label.getText()); return label; } if (!node.hasDescString()) { return emptyLabel; } RSyntaxTextArea textArea = CodeArea.getDefaultArea(mainWindow); textArea.setLayout(new GridLayout(1, 1)); textArea.setEditable(false); textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA); textArea.setText(" " + node.makeDescString()); textArea.setRows(1); textArea.setColumns(textArea.getText().length() + 1); if (highlightText != null) { SearchContext searchContext = new SearchContext(highlightText); searchContext.setMatchCase(!highlightTextCaseInsensitive); searchContext.setMarkAll(true); SearchEngine.markAll(textArea, searchContext); } return textArea; }
ImagePanel(TabbedPane panel, JResource res) { super(panel, res); setLayout(new BorderLayout()); try { BufferedImage img = loadImage(res); ImageViewer imageViewer = new ImageViewer(img); add(imageViewer.getComponent()); } catch (Exception e) { RSyntaxTextArea textArea = CodeArea.getDefaultArea(panel.getMainWindow()); textArea.setText("Image load error: \n" + Utils.getStackTrace(e)); add(textArea); } }
textArea.setText("");
/** * Sets the content in the text area to that in the specified resource. * * @param resource The resource to load. */ private void setText(String resource) { BufferedReader r; try { r = new BufferedReader(new InputStreamReader( getClass().getResourceAsStream(resource), StandardCharsets.UTF_8)); textArea.read(r, null); r.close(); textArea.setCaretPosition(0); textArea.discardAllEdits(); } catch (RuntimeException re) { throw re; // FindBugs } catch (Exception e) { // Never happens textArea.setText("Type here to see syntax highlighting"); } }
public void showCell(Script script, int row, int col, String[] text) { this.script = script; this.row = row; this.col = col; this.cell = script.data.get(row).get(col); String editText = text[0]; resetText = text[1]; if (SX.isNotSet(text)) { editText = cell.get(); } cellTextArea.setText(editText); setLocationRelativeTo(script.getWindow()); setVisible(true); }
@Test public void testGetPreviousWord_manyLinesInBetween() throws Exception { DumbCompleteWordAction action = new DumbCompleteWordAction(); RSyntaxDocument doc = new RSyntaxDocument( SyntaxConstants.SYNTAX_STYLE_JAVA); RSyntaxTextArea textArea = new RSyntaxTextArea(doc); textArea.setText("aaron arthur aardvark\nfoo bar\n// bad code\namazing\n a"); Assert.assertEquals(textArea.getDocument().getLength()-1, action.getPreviousWord(textArea, textArea.getDocument().getLength())); Assert.assertEquals("aaron arthur aardvark\nfoo bar\n// bad code\n".length(), action.getPreviousWord(textArea, textArea.getDocument().getLength()-2)); Assert.assertEquals("aaron arthur ".length(), action.getPreviousWord(textArea, 22)); Assert.assertEquals("aaron ".length(), action.getPreviousWord(textArea, 8)); }
@Test public void testSearchEngineReplaceAll_zeroLengthMatches() { textArea.setText("one two three"); SearchContext context = new SearchContext(); context.setSearchFor(".*"); context.setReplaceWith(""); context.setRegularExpression(true); int count = replaceAllImpl(context); // The goal here is simply to not go into an infinite loop assertEquals(1, count); }
@Test public void testSearchEngineReplaceAll_zeroLengthMatches_emptyText() { textArea.setText(""); SearchContext context = new SearchContext(); context.setSearchFor(".*"); context.setReplaceWith(""); context.setRegularExpression(true); int count = replaceAllImpl(context); // The goal here is simply to not go into an infinite loop assertEquals(1, count); }
@Test public void testGetWordEnd_noSelection_happyPath() { EndWordAction action = new EndWordAction("endWordAction", false); RSyntaxDocument doc = new RSyntaxDocument( SyntaxConstants.SYNTAX_STYLE_JAVA); RSyntaxTextArea textArea = new RSyntaxTextArea(doc); final String TEXT = "This is the best"; textArea.setText(TEXT); for (int i = 0; i < "This".length(); i++) { textArea.setCaretPosition(i); action.actionPerformed(createActionEvent(textArea)); Assert.assertEquals("This".length(), textArea.getCaretPosition()); } textArea.setCaretPosition("This".length()); action.actionPerformed(createActionEvent(textArea)); Assert.assertEquals("This ".length(), textArea.getCaretPosition()); textArea.setCaretPosition("This ".length()); action.actionPerformed(createActionEvent(textArea)); Assert.assertEquals("This is".length(), textArea.getCaretPosition()); textArea.setCaretPosition(TEXT.length()); action.actionPerformed(createActionEvent(textArea)); Assert.assertEquals(TEXT.length(), textArea.getCaretPosition()); }
@Test public void testActionPerformed_dollarSignImportant() throws Exception { RSyntaxDocument doc = new RSyntaxDocument( SyntaxConstants.SYNTAX_STYLE_JAVASCRIPT); RSyntaxTextArea textArea = new RSyntaxTextArea(doc); DumbCompleteWordAction action = getDumbCompleteWordAction(textArea); textArea.setText("$routeProvider routeSkip $ro"); action.actionPerformed(createActionEvent(textArea)); String actual = textArea.getText(); Assert.assertEquals("$routeProvider routeSkip $routeProvider", actual); }
@Test public void testSearchEngineReplaceAll_zeroLengthMatches_multiMatch() { textArea.setText("a\nba\n\na"); SearchContext context = new SearchContext(); context.setSearchFor("(?=a)"); context.setReplaceWith("CCC"); context.setRegularExpression(true); int count = replaceAllImpl(context); assertEquals(3, count); assertEquals("CCCa\nbCCCa\n\nCCCa", textArea.getText()); }
@Test public void testActionPerformed_underscoresImportant() throws Exception { RSyntaxDocument doc = new RSyntaxDocument( SyntaxConstants.SYNTAX_STYLE_JAVASCRIPT); RSyntaxTextArea textArea = new RSyntaxTextArea(doc); DumbCompleteWordAction action = getDumbCompleteWordAction(textArea); textArea.setText("__foo\n__bar __bas\n_"); action.actionPerformed(createActionEvent(textArea)); String actual = textArea.getText(); Assert.assertEquals("__foo\n__bar __bas\n__bas", actual); action.actionPerformed(createActionEvent(textArea)); actual = textArea.getText(); Assert.assertEquals("__foo\n__bar __bas\n__bar", actual); action.actionPerformed(createActionEvent(textArea)); actual = textArea.getText(); Assert.assertEquals("__foo\n__bar __bas\n__foo", actual); // No change when run again action.actionPerformed(createActionEvent(textArea)); actual = textArea.getText(); Assert.assertEquals("__foo\n__bar __bas\n__foo", actual); }
@Test public void testActionPerformed_manyLinesInBetween() throws Exception { DumbCompleteWordAction action = new DumbCompleteWordAction(); RSyntaxDocument doc = new RSyntaxDocument( SyntaxConstants.SYNTAX_STYLE_JAVA); RSyntaxTextArea textArea = new RSyntaxTextArea(doc); textArea.setText("aaron arthur aardvark\nfoo bar\n// bad code\namazing\n a"); action.actionPerformed(createActionEvent(textArea)); Assert.assertEquals("aaron arthur aardvark\nfoo bar\n// bad code\namazing\n amazing", textArea.getText()); action.actionPerformed(createActionEvent(textArea)); Assert.assertEquals("aaron arthur aardvark\nfoo bar\n// bad code\namazing\n aardvark", textArea.getText()); action.actionPerformed(createActionEvent(textArea)); Assert.assertEquals("aaron arthur aardvark\nfoo bar\n// bad code\namazing\n arthur", textArea.getText()); action.actionPerformed(createActionEvent(textArea)); Assert.assertEquals("aaron arthur aardvark\nfoo bar\n// bad code\namazing\n aaron", textArea.getText()); action.actionPerformed(createActionEvent(textArea)); Assert.assertEquals("aaron arthur aardvark\nfoo bar\n// bad code\namazing\n aaron", textArea.getText()); }
/** * https://github.com/bobbylight/RSyntaxTextArea/issues/38 */ @Test public void testSearchEngineRegexFindEmptyString() throws Exception { textArea.setText("how the who for what is it howhow"); String searchFor = "[how]{3}|"; SearchContext context = new SearchContext(searchFor); context.setRegularExpression(true); assertTrue(findImpl(context)); assertResult(new SearchResult(new DocumentRange(0, 3), 1, 4)); assertTrue(findImpl(context)); assertResult(new SearchResult(new DocumentRange(8, 11), 1, 4)); assertTrue(findImpl(context)); assertResult(new SearchResult(new DocumentRange(27, 30), 1, 4)); assertTrue(findImpl(context)); assertResult(new SearchResult(new DocumentRange(30, 33), 1, 4)); assertFalse(findImpl(context)); }