bobbylight / rsyntaxtextarea Goto Github PK
View Code? Open in Web Editor NEWA syntax highlighting, code folding text editor for Java Swing applications.
License: BSD 3-Clause "New" or "Revised" License
A syntax highlighting, code folding text editor for Java Swing applications.
License: BSD 3-Clause "New" or "Revised" License
Here is an SSCA for the case:
public class CodeHighlightTest
{
public static void main ( String[] args )
{
final RSyntaxTextArea area = new RSyntaxTextArea ();
area.setMargin ( new Insets ( 10, 10, 10, 10 ) );
area.setSyntaxEditingStyle ( SyntaxConstants.SYNTAX_STYLE_JAVA );
area.setText ( "boolean v = getTitle().equals(\"test\");" );
final RTextScrollPane scrollPane = new RTextScrollPane ( area );
final JFrame frame = new JFrame ( "Test" );
frame.add ( scrollPane );
frame.setSize ( 400, 100 );
frame.setLocationRelativeTo ( null );
frame.setDefaultCloseOperation ( WindowConstants.EXIT_ON_CLOSE );
frame.setVisible ( true );
}
}
It doesn't seem to be painting bug because it will not be gone even if i resize the window to cause area repainting:
It is gone only when i move caret atleast once in the area:
I guess its just initial line highlight position value bug.
If i try to set the margin line color for a TextEditorPane like this
setMarginLineColor(new Color(248,248,248));
The color doesn't change.
I even changed the value in eclipse.xml theme file but that also doesn't work.
As demonstrated below, if you search for an empty string and you have a previous search that returned some hits, these preexisting hits are not cleared (observe error strip).
I believe that any previous mark all highlights should be cleared on any new search.
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import org.fife.ui.rsyntaxtextarea.ErrorStrip;
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
import org.fife.ui.rtextarea.RTextScrollPane;
import org.fife.ui.rtextarea.SearchContext;
import org.fife.ui.rtextarea.SearchEngine;
import org.fife.ui.rtextarea.SearchResult;
public class RSTAEmptySearchTerm extends JFrame {
private RTextScrollPane rtscpMain;
private RSyntaxTextArea rstaMain;
private JButton button;
private ErrorStrip strip;
public RSTAEmptySearchTerm() {
setLayout(new BorderLayout());
rstaMain = new RSyntaxTextArea();
rstaMain.setTabSize(2);
rstaMain.setTabsEmulated(true);
rstaMain.setAntiAliasingEnabled(true);
rtscpMain = new RTextScrollPane(rstaMain);
add(rtscpMain);
strip = new ErrorStrip(rstaMain);
add(strip, BorderLayout.EAST);
String content =
"RSyntaxTextArea is a customizable, syntax highlighting text component for\n"
+ "Java Swing applications. Out of the box, it supports syntax highlighting\n"
+ "for over 30 programming languages, code folding, search and replace, and\n"
+ "has add-on libraries for code completion and spell checking. Syntax\n"
+ "highlighting for additional languages can be added via tools such as JFlex."
+ "\n\n"
+ "RSyntaxTextArea is available under a modified BSD license. For more\n"
+ "information, visit http://fifesoft.com/rsyntaxtextarea.";
rstaMain.setText(content);
{
// a pre-existing search
SearchContext context = new SearchContext();
context.setMatchCase(false);
context.setMarkAll(true);
context.setSearchFor("box");
context.setWholeWord(false);
SearchResult result = SearchEngine.find(rstaMain, context);
if (!result.wasFound()) {
rstaMain.setCaretPosition(0);
SearchEngine.find(rstaMain, context);
}
}
final String what = ""; // empty
button = new JButton(
"Find \"" + what + "\".");
add(button, BorderLayout.PAGE_END);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// new search
SearchContext context = new SearchContext();
context.setMatchCase(false);
context.setMarkAll(true);
context.setSearchFor(what);
context.setWholeWord(false);
SearchResult result = SearchEngine.find(rstaMain, context);
if (!result.wasFound()) {
rstaMain.setCaretPosition(0);
SearchEngine.find(rstaMain, context);
}
}
});
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(600, 410);
setLocationRelativeTo(null);
rstaMain.setCaretPosition(0);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new RSTAEmptySearchTerm().setVisible(true);
}
});
}
}
I found some really strange rendering issue that happens on JDK6 while running RyntaxTextArea with Java code on Ubuntu (10.04):
It seems that this happens due to tag <p/>
because w/o it everything is fine and if it disappears from the visible area - everything starts rendering normally.
Also i were not able to reproduce this bug on Windows systems:
Here is the RSyntaxTextArea code:
final RSyntaxTextArea source = new RSyntaxTextArea ();
source.setSyntaxEditingStyle ( SyntaxConstants.SYNTAX_STYLE_JAVA );
source.setEditable ( false );
source.setMargin ( new Insets ( 0, 5, 0, 0 ) );
source.setAntiAliasingEnabled ( true );
source.setUseFocusableTips ( true );
source.setTabSize ( 4 );
source.setCodeFoldingEnabled ( true );
source.setPaintTabLines ( false );
source.setWhitespaceVisible ( false );
source.setEOLMarkersVisible ( false );
( ( RSyntaxTextAreaHighlighter ) source.getHighlighter () ).setDrawsLayeredHighlights ( false );
final RTextScrollPane sourceScroll = new RTextScrollPane ( source );
sourceScroll.setVerticalScrollBarPolicy ( WebScrollPane.VERTICAL_SCROLLBAR_ALWAYS );
I also use a custom CodeLinkGenerator - i can provide it if it may cause the issue, but I doubt that because i didn't press the link-key - this bug appears right at the textarea display without any additional actions.
Here is the code displayed in the demo app inside the RSyntaxTextArea:
package com.alee.extended.window;
import com.alee.laf.label.WebLabel;
import com.alee.laf.panel.WebPanel;
import com.alee.laf.progressbar.WebProgressBar;
import com.alee.laf.rootpane.WebDialog;
import com.alee.utils.SwingUtils;
import javax.swing.*;
import java.awt.*;
/**
* User: mgarin Date: 14.02.12 Time: 12:08
* <p>
* This class provides a quick way to display a progress dialog anywhere you need it and change the progress values without any additional
* efforts like working with Swing thread to update progress
*/
public class WebProgressDialog extends WebDialog
{
private int preferredProgressWidth = 0;
private boolean shownOnce = false;
private WebPanel container;
private WebLabel titleText;
private Component middleComponent = null;
private WebProgressBar progressBar;
public WebProgressDialog ( String title )
{
this ( null, title );
}
public WebProgressDialog ( Window owner, String title )
{
super ( owner, title );
setLayout ( new BorderLayout () );
container = new WebPanel ( new BorderLayout ( 5, 5 ) );
container.setMargin ( 10, 10, 10, 10 );
container.setOpaque ( false );
add ( container, BorderLayout.CENTER );
// Creating label with single space to hold label height on pack
titleText = new WebLabel ( " ", WebLabel.CENTER )
{
@Override
public Dimension getPreferredSize ()
{
Dimension ps = super.getPreferredSize ();
ps.width = 0;
return ps;
}
};
titleText.setDrawShade ( true );
container.add ( titleText, BorderLayout.NORTH );
// Default progress bar
progressBar = new WebProgressBar ( WebProgressBar.HORIZONTAL, 0, 100 )
{
@Override
public Dimension getPreferredSize ()
{
Dimension ps = super.getPreferredSize ();
if ( preferredProgressWidth > 0 )
{
ps.width = preferredProgressWidth;
}
return ps;
}
};
progressBar.setStringPainted ( true );
container.add ( progressBar, BorderLayout.SOUTH );
setDefaultCloseOperation ( JDialog.DISPOSE_ON_CLOSE );
setResizable ( false );
setModal ( false );
updateBounds ();
setLocationRelativeTo ( owner );
}
public void setText ( final String text )
{
SwingUtils.invokeLater ( new Runnable ()
{
@Override
public void run ()
{
titleText.setText ( text );
}
} );
}
public String getText ()
{
return titleText.getText ();
}
public void setProgressText ( final String progressText )
{
SwingUtils.invokeLater ( new Runnable ()
{
@Override
public void run ()
{
progressBar.setString ( progressText );
}
} );
}
public String getProgressText ()
{
return progressBar.getString ();
}
public void setShowProgressText ( final boolean showProgressText )
{
SwingUtils.invokeLater ( new Runnable ()
{
@Override
public void run ()
{
progressBar.setStringPainted ( showProgressText );
updateBounds ();
}
} );
}
public boolean isShowProgressText ()
{
return progressBar.isStringPainted ();
}
public void setIndeterminate ( final boolean indeterminate )
{
SwingUtils.invokeLater ( new Runnable ()
{
@Override
public void run ()
{
progressBar.setIndeterminate ( indeterminate );
}
} );
}
public boolean isIndeterminate ()
{
return progressBar.isIndeterminate ();
}
public void setMinimum ( final int minimum )
{
SwingUtils.invokeLater ( new Runnable ()
{
@Override
public void run ()
{
progressBar.setMinimum ( minimum );
}
} );
}
public int getMinimum ()
{
return progressBar.getMinimum ();
}
public void setMaximum ( final int maximum )
{
SwingUtils.invokeLater ( new Runnable ()
{
@Override
public void run ()
{
progressBar.setMaximum ( maximum );
}
} );
}
public int getMaximum ()
{
return progressBar.getMaximum ();
}
public void setProgress ( final int progress )
{
SwingUtils.invokeLater ( new Runnable ()
{
@Override
public void run ()
{
progressBar.setValue ( progress );
}
} );
}
public int getPreferredProgressWidth ()
{
return preferredProgressWidth;
}
public void setPreferredProgressWidth ( int preferredProgressWidth )
{
this.preferredProgressWidth = preferredProgressWidth;
updateBounds ();
}
public int getProgress ()
{
return progressBar.getValue ();
}
public WebLabel getTitleLabel ()
{
return titleText;
}
public Component getMiddleComponent ()
{
return middleComponent;
}
public void setMiddleComponent ( Component middleComponent )
{
if ( this.middleComponent != null )
{
container.remove ( middleComponent );
}
this.middleComponent = middleComponent;
container.add ( middleComponent, BorderLayout.CENTER );
container.revalidate ();
updateBounds ();
}
public WebProgressBar getProgressBar ()
{
return progressBar;
}
public void setShowProgressBar ( boolean showProgressBar )
{
if ( showProgressBar )
{
if ( progressBar.getParent () != container )
{
container.add ( progressBar, BorderLayout.SOUTH );
container.revalidate ();
updateBounds ();
}
}
else
{
if ( progressBar.getParent () == container )
{
container.remove ( progressBar );
container.revalidate ();
updateBounds ();
}
}
}
private void updateBounds ()
{
pack ();
if ( !shownOnce )
{
setLocationRelativeTo ( getOwner () );
}
}
@Override
public void setVisible ( boolean b )
{
if ( b )
{
shownOnce = true;
}
super.setVisible ( b );
}
}
Hello,
I face an issue with RSyntaxTextArea put inside a RTextScrollPane.
Note I have used setFoldIndicatorEnabled(true) and set syntax to XML.
If text makes a scrollbar appear and you can only scroll once, then when I scroll down text gets mixed up in terms of display. If I lose and get focus back then display is fine.
Hello,
We use your nice project in jmeter.
We had a bug reported which leads to OutOfMemoryError, see this for more details:
PHP syntax highlighting should be enhanced in the following ways:
textArea.getHighlightSecondaryLanguages()==true)
, PHP code should use the background color dictated by language index 3 (since index 1 is CSS and index 2 is JavaScript). This makes PHP code easier to distinguish from markup.In my favorite code editors, the search and search&replace dialogs are not normally popup dialogs, but instead are mini panels that appear in the southern region of the editor as needed, and disappear when dismissed. It would be great if RSyntaxTextArea supplied this out of the box, or if it was available as part of RSTAUI. I believe that all of the APIs for hooking up this UI already exist (if feature request #13 is added), so this request is just for the UI.
Sublime Text's search panels are a great example, so I've included screenshots of that application below.
Copied from SourceForge:
As reported here:
http://fifesoft.com/forum/viewtopic.php?f=10&t=597
"If a keyword is the last word of a line followed by a line break, then the tool tip window will even pop up if your mouse is a lot more right of this word but on the same line."
This occurs because we're using View#viewToModel(Point) to determine a document offset at the mouse position. viewToModel() returns the closest offset. We need to change our technique to return null if the mouse isn't actually over a word."
Copied over from SourceForge:
Add the ability with TMM to specified a regex like "\d{1,2}/\d{1,2}/\d+" for example, to describe a token.
RSyntaxTextArea.markAll() is much slower than marking stuff via MarkOccurrencesSupport, and there's no real reason for this. Note it's typically only a problem in the pedantic worst-case (many thousands of instances of the token to "mark"), but it is still something that should be rectified.
Links are compared (RSyntaxTextArea at line 3088) by offsets only (RSyntaxTextArea at line 3026). So component is not being repainted if you have two (or more) lines with same urls (or just same offsets) and you are moving between them.
Code Folding does not work when SYNTAX_STYLE_SQL is used. For XML its works well.
Experienced some strangeness in AbstractJFlexCTokenMaker based token makers. When inside a multi-line comment, an asterisk gets appended for every newline. If the point of insertion is followed by whitespace, the caret will "slide" for each new newline.
Run the following program and start hitting Enter. It's fun. Not sure if intentional though.
import java.awt.BorderLayout;
import java.io.IOException;
import java.io.StringReader;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import org.fife.ui.rsyntaxtextarea.RSyntaxDocument;
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
import org.fife.ui.rsyntaxtextarea.modes.JavaTokenMaker;
import org.fife.ui.rtextarea.RTextScrollPane;
public class RSTASlidingMLCCaret extends JFrame {
private RTextScrollPane rtscpMain;
private RSyntaxTextArea rstaMain;
public RSTASlidingMLCCaret() throws IOException {
setLayout(new BorderLayout());
rstaMain = new RSyntaxTextArea();
// set an AbstractJFlexCTokenMaker instance
RSyntaxDocument document = (RSyntaxDocument) rstaMain.getDocument();
document.setSyntaxStyle(new JavaTokenMaker());
String content;
content = "/*\n * \n */";
// ^ note whitespace here
StringReader reader = new StringReader(content);
rstaMain.read(reader, reader);
rstaMain.discardAllEdits();
rstaMain.setCaretPosition(5); // just before that space
rtscpMain = new RTextScrollPane(rstaMain);
add(rtscpMain);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(300, 400);
setTitle("Hit Enter Repeatedly");
setLocationRelativeTo(null);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
try {
new RSTASlidingMLCCaret().setVisible(true);
} catch (IOException ex) {
ex.printStackTrace();
}
}
});
}
}
The bug reproducable, exists even in the demo app on the project page.
Steps to reproduce the bug:
What happens:
The bookmark follows the caret to the new line, and every other new line created afterwards.
What is the expected behavior:
The bookmark should remain its position
Version: latest stable
System:
java version "1.7.0_25"
OpenJDK Runtime Environment (IcedTea 2.3.10) (7u25-2.3.10-1ubuntu0.12.04.2)
OpenJDK Server VM (build 23.7-b01, mixed mode)
Ubuntu 12.04 and Mint 15
The "new RSyntaxTextArea(String)" constructor throws an NPE. A simple workaround is:
RSyntaxTextArea textArea = new RSyntaxTextArea(); // Any other constructor
textArea.setText(text);
The reason this occurs is the funky way RSTA installs its own TextAreaUI. The JTextArea constructor taking a String parameter takes a code path that breaks because of the way the proper TextAreaUI isn't yet installed.
A fix for this may be tricky to come up with. There's probably a better way to handle installing the UI, but right now things are delicately done (i.e. hacked together) to keep things working and avoid other issues. In the meantime, the next release might see this constructor go away, or maybe throw an "UnsupportedOperationException" until I have more time to come up with a real fix. It's not such a big deal since the workaround is so simple.
The following program freezes when I click the only button and eventually dies with java.lang.OutOfMemoryError. This is with 2.5.1 built from git repo on 03/04/14. Note that it happens with regex search.
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import org.fife.ui.rsyntaxtextarea.ErrorStrip;
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
import org.fife.ui.rtextarea.RTextScrollPane;
import org.fife.ui.rtextarea.SearchContext;
import org.fife.ui.rtextarea.SearchEngine;
import org.fife.ui.rtextarea.SearchResult;
public class RSTARegexMarkAll extends JFrame {
private RTextScrollPane rtscpMain;
private RSyntaxTextArea rstaMain;
private JButton replace;
private ErrorStrip strip;
public RSTARegexMarkAll() {
setLayout(new BorderLayout());
rstaMain = new RSyntaxTextArea();
rstaMain.setTabSize(2);
rstaMain.setTabsEmulated(true);
rstaMain.setAntiAliasingEnabled(true);
rtscpMain = new RTextScrollPane(rstaMain);
add(rtscpMain);
strip = new ErrorStrip(rstaMain);
add(strip, BorderLayout.EAST);
String content =
"RSyntaxTextArea is a customizable, syntax highlighting text component for\n"
+ "Java Swing applications. Out of the box, it supports syntax highlighting\n"
+ "for over 30 programming languages, code folding, search and replace, and\n"
+ "has add-on libraries for code completion and spell checking. Syntax\n"
+ "highlighting for additional languages can be added via tools such as JFlex."
+ "\n\n"
+ "RSyntaxTextArea is available under a modified BSD license. For more\n"
+ "information, visit http://fifesoft.com/rsyntaxtextarea.";
rstaMain.setText(content);
final String what = "[box]{3}|";
replace = new JButton(
"Find \"" + what + "\" (regex).");
add(replace, BorderLayout.PAGE_END);
replace.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
SearchContext context = new SearchContext();
context.setMatchCase(false);
context.setMarkAll(true);
context.setRegularExpression(true);
context.setSearchFor(what);
context.setWholeWord(false);
SearchResult result = SearchEngine.find(rstaMain, context);
if (!result.wasFound()) {
rstaMain.setCaretPosition(0);
SearchEngine.find(rstaMain, context);
}
}
});
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(600, 410);
setLocationRelativeTo(null);
rstaMain.setCaretPosition(0);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new RSTARegexMarkAll().setVisible(true);
}
});
}
}
Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:2245)
at java.util.Arrays.copyOf(Arrays.java:2219)
at java.util.ArrayList.grow(ArrayList.java:213)
at java.util.ArrayList.ensureCapacityInternal(ArrayList.java:187)
at java.util.ArrayList.add(ArrayList.java:411)
at org.fife.ui.rtextarea.SearchEngine.markAllImpl(SearchEngine.java:706)
at org.fife.ui.rtextarea.SearchEngine.find(SearchEngine.java:99)
at com.mgsoft.testing.rsta.RSTARegexMarkAll$1.actionPerformed(RSTARegexMarkAll.java:65)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:729)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:688)
at java.awt.EventQueue$3.run(EventQueue.java:686)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
To provide LinkGenerator you should code something like this:
editor.setLinkGenerator ( new LinkGenerator ()
{
@Override
public LinkGeneratorResult isLinkAtOffset ( final RSyntaxTextArea rSyntaxTextArea, final int i )
{
return new LinkGeneratorResult ()
{
@Override
public HyperlinkEvent execute ()
{
// Some execution here
return new HyperlinkEvent ( this, HyperlinkEvent.EventType.EXITED, null );
}
@Override
public int getSourceOffset ()
{
// Link beginning offset
return 0;
}
};
}
} );
This is pretty smooth and convenient way.
But there are cases when i want to specify hyperlink exact length. This cannot be done at the moment because editor decides where the link ends (using the provided source offset i guess).
Could you provide an additional method in LinkGeneratorResult that would return hyperlink length? Basically, something like this:
editor.setLinkGenerator ( new LinkGenerator ()
{
@Override
public LinkGeneratorResult isLinkAtOffset ( final RSyntaxTextArea rSyntaxTextArea, final int i )
{
return new LinkGeneratorResult ()
{
...
@Override
public int getSourceLength ()
{
// Link length
return 0;
}
};
}
} );
Or does that interfere with your vision of this feature somehow?
RSyntaxDocument implements Iterable, but is broken and doesn't return all paintable Tokens in all circumstances.
BadLocationException occurs in the following scenario. Caret at offset 0:
one
one
replace first instance of regex "\s+o". BLE occurs marking next occurrence in the document. We are miscalculating the offset based on the new caret position.
.org.fife.ui.rtextarea.SearchContext.PROPERTY_SELECTION_ONLY
It's not evident for end user that this flag is currently not supported.
I use compiled jar without javadoc and it took me about half an hour to find why this functionality doesn't work. Arghh...
How about throwing any exception in getter and setter? To prevent user from using this flag
I don't see a way to search inside selection from SearchEngine code. The implementation uses caret position and forward/backward property to determine where to search, but ignores selection entirely.
Currently client code would have to roll on their own to implement this feature (and would also need a way to programmatically handle mark all for highlights - relies on package private methods).
It would be great if there was a way to automatically have search wrap at the end of the document. I didn't see any options to do this within FindDialog or directly in the SearchEngine.
Hi,
For RSyntaxArea 2.0.7
There is a NullPointerException when we swap the LookAndFeel.
Maybe check for null value in org.fife.ui.rsyntaxtextarea.WrappedSyntaxView.java
host or host.getMargin() is null
alloc.y -= host.getMargin().top;
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at org.fife.ui.rsyntaxtextarea.WrappedSyntaxView.childAllocation2(WrappedSyntaxView.java:173)
at org.fife.ui.rsyntaxtextarea.WrappedSyntaxView.getViewAtPoint(WrappedSyntaxView.java:612)
at org.fife.ui.rsyntaxtextarea.WrappedSyntaxView.viewToModel(WrappedSyntaxView.java:1005)
at javax.swing.plaf.basic.BasicTextUI$RootView.viewToModel(BasicTextUI.java:1552)
at javax.swing.plaf.basic.BasicTextUI.viewToModel(BasicTextUI.java:1101)
at javax.swing.plaf.basic.BasicTextUI.viewToModel(BasicTextUI.java:1074)
at javax.swing.text.JTextComponent.viewToModel(JTextComponent.java:1446)
at org.fife.ui.rtextarea.LineNumberList.paintWrappedLineNumbers(LineNumberList.java:429)
at org.fife.ui.rtextarea.LineNumberList.paintComponent(LineNumberList.java:303)
at javax.swing.JComponent.paint(JComponent.java:1045)
at javax.swing.JComponent.paintChildren(JComponent.java:878)
at javax.swing.JComponent.paint(JComponent.java:1054)
at javax.swing.JComponent.paintChildren(JComponent.java:878)
at javax.swing.JComponent.paint(JComponent.java:1054)
at javax.swing.JViewport.paint(JViewport.java:731)
at javax.swing.JComponent.paintChildren(JComponent.java:878)
at javax.swing.JComponent.paint(JComponent.java:1054)
at javax.swing.JComponent.paintChildren(JComponent.java:878)
at javax.swing.JComponent.paint(JComponent.java:1054)
at javax.swing.JComponent.paintChildren(JComponent.java:878)
at javax.swing.JComponent.paint(JComponent.java:1054)
at javax.swing.JComponent.paintChildren(JComponent.java:878)
at bibliothek.gui.dock.util.BackgroundPanel.paintChildren(BackgroundPanel.java:147)
at javax.swing.JComponent.paint(JComponent.java:1054)
at bibliothek.gui.dock.util.BackgroundPanel.paint(BackgroundPanel.java:104)
at javax.swing.JComponent.paintChildren(JComponent.java:878)
at bibliothek.gui.dock.util.BackgroundPanel.paintChildren(BackgroundPanel.java:147)
at javax.swing.JComponent.paint(JComponent.java:1054)
at bibliothek.gui.dock.util.BackgroundPanel.paint(BackgroundPanel.java:104)
at javax.swing.JComponent.paintChildren(JComponent.java:878)
at bibliothek.gui.dock.util.BackgroundPanel.paintChildren(BackgroundPanel.java:147)
at javax.swing.JComponent.paint(JComponent.java:1054)
at bibliothek.gui.dock.util.BackgroundPanel.paint(BackgroundPanel.java:104)
at javax.swing.JComponent.paintChildren(JComponent.java:878)
at bibliothek.gui.dock.util.BackgroundPanel.paintChildren(BackgroundPanel.java:147)
at javax.swing.JComponent.paint(JComponent.java:1054)
at bibliothek.gui.dock.util.BackgroundPanel.paint(BackgroundPanel.java:104)
at javax.swing.JComponent.paintChildren(JComponent.java:878)
at javax.swing.JComponent.paint(JComponent.java:1054)
at javax.swing.JLayeredPane.paint(JLayeredPane.java:585)
at javax.swing.JComponent.paintChildren(JComponent.java:878)
at javax.swing.JComponent.paint(JComponent.java:1054)
at javax.swing.JComponent.paintChildren(JComponent.java:878)
at javax.swing.JComponent.paint(JComponent.java:1054)
at javax.swing.JComponent.paintChildren(JComponent.java:878)
at javax.swing.JComponent.paint(JComponent.java:1054)
at javax.swing.JComponent.paintChildren(JComponent.java:878)
at javax.swing.JComponent.paint(JComponent.java:1054)
at javax.swing.JLayer.paint(JLayer.java:433)
at javax.swing.plaf.LayerUI.paint(LayerUI.java:79)
at org.orbisgis.view.main.frames.MessageOverlay.paint(MessageOverlay.java:75)
at javax.swing.plaf.ComponentUI.update(ComponentUI.java:161)
at javax.swing.JComponent.paintComponent(JComponent.java:769)
at javax.swing.JLayer.paint(JLayer.java:428)
at javax.swing.JComponent.paintChildren(JComponent.java:878)
at javax.swing.JComponent.paint(JComponent.java:1054)
at javax.swing.JComponent.paintChildren(JComponent.java:878)
at javax.swing.JComponent.paint(JComponent.java:1054)
at javax.swing.JLayeredPane.paint(JLayeredPane.java:585)
at javax.swing.JComponent.paintChildren(JComponent.java:878)
at javax.swing.JComponent.paint(JComponent.java:1054)
at javax.swing.JComponent.paintToOffscreen(JComponent.java:5210)
at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1529)
at javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1452)
at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java:311)
at javax.swing.RepaintManager.paint(RepaintManager.java:1249)
at javax.swing.JComponent._paintImmediately(JComponent.java:5158)
at javax.swing.JComponent.paintImmediately(JComponent.java:4969)
at javax.swing.RepaintManager$3.run(RepaintManager.java:808)
at javax.swing.RepaintManager$3.run(RepaintManager.java:796)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:796)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:769)
at javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:718)
at javax.swing.RepaintManager.access$1100(RepaintManager.java:62)
at javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1677)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:733)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:694)
at java.awt.EventQueue$3.run(EventQueue.java:692)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:703)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
I will create a test case next week. Thanks for support
Copied over from SourceForge:
Original ticket:
Pretty print features for XML: auto-indent/tokenize
<x><y>test</y></x>
becomes
<x>
<y>test</y>
</x>
Response:
"This may happen at some point, being added to the RSTALanguageSupport library for XML, but probably not any time soon. If you are interested in such a feature, I recommend you check out JTidy, a Java port of HTML Tidy. RText (which uses RSyntaxTextArea) uses this library for its XML formatting:
https://sourceforge.net/projects/jtidy/
"
Word wrapping is done at word boundaries most of the time, but for "long" tokens (tokens that can have embedded whitespace, such as comments), wrapping is done at char boundaries.. The fix fort his will be in WrappedSyntaxView.java, starting at line 99.
Hello,
I noticed another behaviour which seems strange:
Now when you use it, if you open a GUI which has for example 100 lines, if you hit CTRL +Z then everything is cleaned up. This seems very strange to me.
Is there some method to call to reset UndoManager edits ?
Is it discardAllEdits() or is there a better way ?
Thanks
Copied over from SourceForge:
Like it says on the tin. As a workaround, folks could try transporting just the RGapContent of an RSyntaxDocument.
Copied over from SourceForge:
I modify the example "Code Templates Example"(http://fifesoft.com/rsyntaxtextarea/examples/example2.php) to support the customized insert code template keystroke. I did this like the following code, but it didn't take any effect, "CTRL+SHIFT+SPACE" keystroke is still available.
CodeTemplateManager ctm = RSyntaxTextArea.getCodeTemplateManager();
//Replace the default keystroke "CTRL+SHIFIT_SPACE" with "ALT + SLASH"
ctm.setInsertTrigger(KeyStroke.getKeyStroke(KeyEvent.VK_SLASH,
InputEvent.ALT_DOWN_MASK));
When highlighting languages such as PHP and HTML, there are "sub-languages" that also get highlighted (e.g. PHP, JavaScript, CSS). These "sub-languages" usually have different syntaxes for line comments from one another, and from the "main" language. When toggling line comments (via Ctrl/Cmd+/), RSTA should be smart enough to use the line comment syntax appropriate for the selected sub-language.
For example, toggle comments around markup tags in HTML with "" (since there isn't a concept of a line comment in HTML). However, if the selected lines are all JavaScript, toggle the comments by prepending "//".
In eclipse you can see that all static members and enum members are in italic and blue color font.. It would me good to read if the same can be done here...
In eclipse if there is TODO and FIXME in comments then it shows a tracking icon on the left margin which also looks good..
And i don't know if this is the right place to tell you this but i am using your great project in one of my projects you can find it here and here..
http://www.badlogicgames.com/forum/viewtopic.php?f=17&t=13355
https://github.com/pyros2097/GdxStudio
Adding an escaped double-quote appears to break syntax highlighting in Clojure files. It does not appear to break highlighting in Java files, so it may be specific to the Clojure syntax style. You can see screenshots of this problem here:
Like it says on the tin. TMM should provide a checkbox that makes multi-line comments nestable, as some languages need this future.
I manage to crash the following program by doing random text insertions. Happens most of the time when I enter a newline somewhere among those spaces and then try to enter a random character. Text also disappears sometimes. Applies to 2.5.0.
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
import org.fife.ui.rtextarea.RTextScrollPane;
public class RSTAWhitespace extends JFrame {
private RTextScrollPane rtscpMain;
private RSyntaxTextArea rstaMain;
public RSTAWhitespace() {
setLayout(new BorderLayout());
rstaMain = new RSyntaxTextArea(
"Some sample text\nwith newline and\t\t spaces");
rstaMain.setWhitespaceVisible(true);
rtscpMain = new RTextScrollPane(rstaMain);
add(rtscpMain);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(300, 400);
setLocationRelativeTo(null);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new RSTAWhitespace().setVisible(true);
}
});
}
}
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 5
at org.fife.ui.rsyntaxtextarea.VisibleWhitespaceTokenPainter.paintImpl(VisibleWhitespaceTokenPainter.java:83)
at org.fife.ui.rsyntaxtextarea.DefaultTokenPainter.paint(DefaultTokenPainter.java:58)
at org.fife.ui.rsyntaxtextarea.SyntaxView.drawLine(SyntaxView.java:178)
at org.fife.ui.rsyntaxtextarea.SyntaxView.paint(SyntaxView.java:722)
at javax.swing.plaf.basic.BasicTextUI$RootView.paint(BasicTextUI.java:1434)
at javax.swing.plaf.basic.BasicTextUI.paintSafely(BasicTextUI.java:737)
at javax.swing.plaf.basic.BasicTextUI.paint(BasicTextUI.java:881)
at javax.swing.plaf.basic.BasicTextUI.update(BasicTextUI.java:860)
at org.fife.ui.rtextarea.RTextAreaBase.paintComponent(RTextAreaBase.java:702)
at org.fife.ui.rsyntaxtextarea.RSyntaxTextArea.paintComponent(RSyntaxTextArea.java:1926)
at javax.swing.JComponent.paint(JComponent.java:1054)
at javax.swing.JComponent.paintToOffscreen(JComponent.java:5221)
at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1512)
at javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1443)
at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java:311)
at javax.swing.RepaintManager.paint(RepaintManager.java:1236)
at javax.swing.JComponent._paintImmediately(JComponent.java:5169)
at javax.swing.JComponent.paintImmediately(JComponent.java:4980)
at javax.swing.RepaintManager$3.run(RepaintManager.java:796)
at javax.swing.RepaintManager$3.run(RepaintManager.java:784)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:784)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:757)
at javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:706)
at javax.swing.RepaintManager.access$1000(RepaintManager.java:62)
at javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1651)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:727)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:688)
at java.awt.EventQueue$3.run(EventQueue.java:686)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:697)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
preditcon
I would like to propose to add following code to SyntaxScheme.java:
416. public void restoreDefaults(Font baseFont, boolean fontStyles) {
417.
418. // Colors used by tokens.
419. Color comment = new Color(0,128,0);
:
438. Font keywordFont = baseFont;
439. if (fontStyles) {
440. // WORKAROUND for Sun JRE bug 6282887 (Asian font bug in 1.4/1.5)
441. // That bug seems to be hidden now, see 6289072 instead.
442. StyleContext sc = StyleContext.getDefaultStyleContext();
443. Font boldFont = sc.getFont(baseFont.getFamily(), Font.BOLD,
444. baseFont.getSize());
445. Font italicFont = sc.getFont(baseFont.getFamily(), Font.ITALIC,
446. baseFont.getSize());
447. commentFont = italicFont;//baseFont.deriveFont(Font.ITALIC);
448. keywordFont = boldFont;//baseFont.deriveFont(Font.BOLD);
449. }
449.1 for (int i = 0; i < styles.length; i++)
449.2 {
449.3 styles[i] = new Style(null);
449.4 }
Reason is following:
If we change TokenTypes.java then additional types are not initialized in SyntaxSceme class and it causes runtime exception.
I changed TokenTypes because standard types are not enough for my languages.
As originally requested in the forums here:
http://fifesoft.com/forum/viewtopic.php?f=10&t=827
If RTextScrollPane allowed for JLayer/JXLayer as its view, users could decorate RSTA with (quite possibly) the last cool new feature that will ever be added to Swing. :(
I tried to create my own LinkGenerator and use it in RSyntaxTextArea:
public class CodeHighlightTest
{
public static void main ( String[] args )
{
final RSyntaxTextArea area = new RSyntaxTextArea ();
area.setEditable ( false );
area.setMargin ( new Insets ( 5, 5, 5, 5 ) );
area.setSyntaxEditingStyle ( SyntaxConstants.SYNTAX_STYLE_JAVA );
area.setText ( "boolean v = getTitle().equals(\"test\");" );
area.setLinkScanningMask ( KeyEvent.SHIFT_MASK );
area.setHyperlinksEnabled ( true );
area.setLinkGenerator ( new CodeLinkGenerator () );
final RTextScrollPane scrollPane = new RTextScrollPane ( area );
final JFrame frame = new JFrame ( "Test" );
frame.add ( scrollPane );
frame.setSize ( 400, 100 );
frame.setLocationRelativeTo ( null );
frame.setDefaultCloseOperation ( WindowConstants.EXIT_ON_CLOSE );
frame.setVisible ( true );
}
public static class CodeLinkGenerator implements LinkGenerator
{
/**
* Separators used to determine words in text.
*/
private static final java.util.List<String> textSeparators =
Arrays.asList ( " ", ".", ",", ":", ";", "/", "\\", "\n", "\t", "|", "{", "}", "[", "]", "(", ")", "<", ">", "-", "+", "\"",
"'", "*", "%", "$", "#", "@", "!", "~", "^", "&", "?" );
/**
* Cached link generation results.
*/
private Map<Dimension, LinkGeneratorResult> results = new HashMap<Dimension, LinkGeneratorResult> ();
@Override
public LinkGeneratorResult isLinkAtOffset ( RSyntaxTextArea source, final int pos )
{
final String code = source.getText ();
final int wordStart = getWordStart ( code, pos );
final int wordEnd = getWordEnd ( code, pos );
final String word = code.substring ( wordStart, wordEnd );
final Dimension key = new Dimension ( wordStart, wordEnd );
final LinkGeneratorResult value;
if ( results.containsKey ( key ) )
{
value = results.get ( key );
}
else
{
if ( word != null )
{
System.out.println ( "Generated" );
value = new LinkGeneratorResult ()
{
@Override
public HyperlinkEvent execute ()
{
System.out.println ( "Executed" );
return new HyperlinkEvent ( this, HyperlinkEvent.EventType.EXITED, null );
}
@Override
public int getSourceOffset ()
{
return pos;
}
};
}
else
{
value = null;
}
results.put ( key, value );
}
return value;
}
/**
* Returns a word start index at the specified location.
*
* @param text text to retrieve the word start index from
* @param location word location
* @return word start index
*/
public static int getWordStart ( final String text, final int location )
{
int wordStart = location;
while ( wordStart > 0 && !textSeparators.contains ( text.substring ( wordStart - 1, wordStart ) ) )
{
wordStart--;
}
return wordStart;
}
/**
* Returns a word end index at the specified location.
*
* @param text text to retrieve the word end index from
* @param location word location
* @return word end index
*/
public static int getWordEnd ( final String text, final int location )
{
int wordEnd = location;
while ( wordEnd < text.length () - 1 && !textSeparators.contains ( text.substring ( wordEnd, wordEnd + 1 ) ) )
{
wordEnd++;
}
return wordEnd;
}
}
}
All links are properly generated and cached - that part seems to be fine.
There are a few bugs though:
0
index into isLinkAtOffset
method when trying to retrieve link for the empty place above the code made by margin - that causes it to display first word in the code highlighted. I guess it might be better to return -1
in that case.By the way, here are the visual rendering bug example screenshots:
In particular finding the matching opening tag for a selected closing tag, when the document has several nested tags of that type.
TODOs highlighting might be a good addition.
Here is an example of TODOs in Java code (in RSyntaxTextArea):
And here is how IntelliJ IDEA highlights it:
Basically - it highlights anything that goes after "todo" (ignoring case) mark on its line inside any comment with blue color.
Color can be moved to RSyntaxTextArea style settings i guess.
RSTA isn't the fastest when faced with very long lines. For example, as originally reported on SourceForge here:
https://sourceforge.net/p/rsyntaxtextarea/feature-requests/21/
"When the RSyntaxTextArea has one line with many characters (more than 15 000) and has the "Line Wrap" option enabled, using the option "Select All" takes too much time to select all the text. Trying to use the scroll bar with all the text selected also takes too much time. Navigating the text with the arrow keys up and down takes more time than normally would. Editing the text or navigating with the arrow keys left and right takes the normal time."
This ticket is to track performance improvements with WrappedSyntaxView. There is no specific end-goal for this ticket other than "noticeably faster in some instances." No hard metrics.
As the title suggests, when I add RSyntaxTextArea to the RTextScrollPane via getViewPort().add(), retrieving the gutter using RSyntaxUtilities.getGutter() and using it (e.g. gutter.setBookMarkIcon()), throws an NPE. Debugging the code, I see getGutter retrieving a valid Gutter, but, somehow, it gets "lost" along the way.
The reason I place the text area on the view port, instead of adding it directly to the scroll pane, is because the scroll pane only scrolls according to the initial content of the text area. If I add to the content beyond the initial row size, it doesn't "grow" and scroll to display the added content. As you can tell, the text area I implemented accepts dynamic content.
So I'm caught between 2 undesirable outcomes, I either have working scroll behavior, but I lose the gutter, or I have the gutter, but cannot go beyond the initial rows set when I instantiated the text area with certain content.
RSyntaxTextArea gives exception during initialization if SeaGlassLookAndFeel LAF is used.
Caused by: java.lang.NullPointerException
at sun.font.FontDesignMetrics$MetricsKey.init(Unknown Source)
at sun.font.FontDesignMetrics.getMetrics(Unknown Source)
at sun.swing.SwingUtilities2.getFontMetrics(Unknown Source)
at javax.swing.JComponent.getFontMetrics(Unknown Source)
at org.fife.ui.rtextarea.RTextAreaBase.updateMarginLineX(RTextAreaBase.java:1146)
at org.fife.ui.rtextarea.RTextAreaBase.setFont(RTextAreaBase.java:951)
at org.fife.ui.rtextarea.RTextArea.setFont(RTextArea.java:1)
at org.fife.ui.rsyntaxtextarea.RSyntaxTextArea.setFont(RSyntaxTextArea.java:2391)
at javax.swing.plaf.basic.BasicTextUI.installDefaults(Unknown Source)
at javax.swing.plaf.basic.BasicTextAreaUI.installDefaults(Unknown Source)
at org.fife.ui.rtextarea.RTextAreaUI.installDefaults(RTextAreaUI.java:356)
at javax.swing.plaf.basic.BasicTextUI.installUI(Unknown Source)
at org.fife.ui.rtextarea.RTextAreaUI.installUI(RTextAreaUI.java:415)
at javax.swing.JComponent.setUI(Unknown Source)
at javax.swing.text.JTextComponent.setUI(Unknown Source)
at org.fife.ui.rtextarea.RTextAreaBase.setRTextAreaUI(RTextAreaBase.java:1096)
at org.fife.ui.rtextarea.RTextAreaBase.init(RTextAreaBase.java:630)
at org.fife.ui.rtextarea.RTextArea.init(RTextArea.java:861)
at org.fife.ui.rsyntaxtextarea.RSyntaxTextArea.init(RSyntaxTextArea.java:1825)
at org.fife.ui.rtextarea.RTextAreaBase.(RTextAreaBase.java:80)
at org.fife.ui.rtextarea.RTextArea.(RTextArea.java:184)
at org.fife.ui.rsyntaxtextarea.RSyntaxTextArea.(RSyntaxTextArea.java:339)
at com.db.EasySQL.getJTextSQLArea(EasySQL.java:465)
at com.db.util.Constants.(Constants.java:102)
Hi, with some nice fixes done, could you release a new Maven version ?
That would be great!
Best,
Joerg
This example freezes when I click the only button. No exceptions generated. I've only experienced this with XML syntax scheme.
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
import org.fife.ui.rtextarea.RTextScrollPane;
import org.fife.ui.rtextarea.SearchContext;
import org.fife.ui.rtextarea.SearchEngine;
public class RSTAReplaceAllXML extends JFrame {
private RTextScrollPane rtscpMain;
private RSyntaxTextArea rstaMain;
private JButton replace;
public RSTAReplaceAllXML() {
setLayout(new BorderLayout());
rstaMain = new RSyntaxTextArea();
rstaMain.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_XML);
rstaMain.setTabSize(2);
rstaMain.setTabsEmulated(true);
rstaMain.setAntiAliasingEnabled(true);
rtscpMain = new RTextScrollPane(rstaMain);
add(rtscpMain);
String content =
"<?xml version=\"1.0\"?>\n" +
"<catalog>\n" +
" <book id=\"bk101\">\n" +
" <author>Gambardella, Matthew</author>\n" +
" <title>XML Developer's Guide</title>\n" +
" <genre>Computer</genre>\n" +
" <price>44.95</price>\n" +
" <publish_date>2000-10-01</publish_date>\n" +
" <description>An in-depth look at creating applications \n" +
" with XML.</description>\n" +
" </book>\n" +
" <book id=\"bk102\">\n" +
" <author>Ralls, Kim</author>\n" +
" <title>Midnight Rain</title>\n" +
" <genre>Fantasy</genre>\n" +
" <price>5.95</price>\n" +
" <publish_date>2000-12-16</publish_date>\n" +
" <description>A former architect battles corporate zombies, \n" +
" an evil sorceress, and her own childhood to become queen \n" +
" of the world.</description>\n" +
" </book>\n" +
"</catalog>";
rstaMain.setText(content);
final String what = "author";
final String with = "author1";
replace = new JButton("Replace all \"" + what + "\" with \"" + with + "\".");
add(replace, BorderLayout.PAGE_END);
replace.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
SearchContext context = new SearchContext();
context.setSearchFor(what);
context.setReplaceWith(with);
SearchEngine.replaceAll(rstaMain, context);
}
});
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(600, 410);
setLocationRelativeTo(null);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new RSTAReplaceAllXML().setVisible(true);
}
});
}
}
Copied over from SourceForge:
It would be handy to be able to add new keywords to existing language scanners, such as Java. This would allow users to leverage existing TokenMaker implementations with minimal fuss, assuming all they want is new keywords.
This would be accomplished by checking each normal identifier parsed against the "new keyword" list. If found, it's highlighted as a keyword.
One possible issue is performance, although there are TokenMakers in RSTA (WindowsBatchTokenMaker, UnixShellTokenMaker) that already work in the manner suggested above and don't seem to have performance issues.
Another thing to consider is making ALL keywords done in this manner (e.g. none hard-coded). This would allow users to replace a language scanner's keywords, not just append to it.
This same technique could also be applied to the "Function" token type as well as Keywords.
Copied over from SourceForge:
There is no easy way to add a popup menu to the Gutter component. Perhaps allow adding a MouseListener to the (package private) IconRowHeader. This would provide maximum flexibility, but it might be just as useful to provide a custom event/listener API (something like "LineHeaderMouseListener/LineHeaderMouseEvent", but better named) that add easy methods to return line number clicked and other useful info.
Comment: "I needed the same functionality and used a workaround by installing listener on all components returned by gutter.getComponents(). It will be nice if gutter exposes listener interfaces and installs them on all visible components."
Hello,
Intermitently I get this exception using RSyntaxTextArea on JMeter.
I think it happens when:
But not sure yet.
Full stacktrace:
BadLocationException: Position not represented by view
javax.swing.text.BadLocationException: Position not represented by view
at org.fife.ui.rsyntaxtextarea.WrappedSyntaxView.modelToView(WrappedSyntaxView.java:726)
at javax.swing.plaf.basic.BasicTextUI$RootView.modelToView(BasicTextUI.java:1498)
at javax.swing.plaf.basic.BasicTextUI.modelToView(BasicTextUI.java:1036)
at javax.swing.plaf.basic.BasicTextUI.modelToView(BasicTextUI.java:1011)
at javax.swing.text.JTextComponent.modelToView(JTextComponent.java:1400)
at org.fife.ui.rtextarea.RTextAreaBase.possiblyUpdateCurrentLineHighlightLocation(RTextAreaBase.java:721)
at org.fife.ui.rsyntaxtextarea.RSyntaxTextArea.foldToggled(RSyntaxTextArea.java:870)
at org.fife.ui.rsyntaxtextarea.folding.Fold.setCollapsed(Fold.java:508)
at org.fife.ui.rsyntaxtextarea.folding.Fold.toggleCollapsedState(Fold.java:537)
at org.fife.ui.rsyntaxtextarea.folding.FoldManager$Listener.removeUpdate(FoldManager.java:697)
at javax.swing.text.AbstractDocument.fireRemoveUpdate(AbstractDocument.java:243)
at org.fife.ui.rsyntaxtextarea.RSyntaxDocument.fireRemoveUpdate(RSyntaxDocument.java:252)
at javax.swing.text.AbstractDocument.handleRemove(AbstractDocument.java:608)
at javax.swing.text.AbstractDocument.remove(AbstractDocument.java:576)
at javax.swing.text.AbstractDocument.replace(AbstractDocument.java:652)
at javax.swing.text.JTextComponent.replaceSelection(JTextComponent.java:1351)
at org.fife.ui.rtextarea.RTextArea.handleReplaceSelection(RTextArea.java:853)
at org.fife.ui.rtextarea.RTextArea.replaceSelection(RTextArea.java:1226)
at org.fife.ui.rtextarea.RTATextTransferHandler.handleReaderImport(RTATextTransferHandler.java:172)
at org.fife.ui.rtextarea.RTATextTransferHandler.importData(RTATextTransferHandler.java:275)
at javax.swing.TransferHandler.importData(TransferHandler.java:755)
at javax.swing.TransferHandler$TransferAction.actionPerformedImpl(TransferHandler.java:1696)
at javax.swing.TransferHandler$TransferAction.access$700(TransferHandler.java:1621)
at javax.swing.TransferHandler$TransferAction$1.run(TransferHandler.java:1645)
at javax.swing.TransferHandler$TransferAction$1.run(TransferHandler.java:1643)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:86)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:97)
at javax.swing.TransferHandler$TransferAction$2.run(TransferHandler.java:1660)
at javax.swing.TransferHandler$TransferAction$2.run(TransferHandler.java:1658)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:86)
at javax.swing.TransferHandler$TransferAction.actionPerformed(TransferHandler.java:1657)
at javax.swing.text.JTextComponent.invokeAction(JTextComponent.java:1485)
at javax.swing.text.JTextComponent.paste(JTextComponent.java:1463)
at org.fife.ui.rtextarea.RTextArea.paste(RTextArea.java:981)
at org.fife.ui.rtextarea.RTextAreaEditorKit$PasteAction.actionPerformedImpl(RTextAreaEditorKit.java:2020)
at org.fife.ui.rtextarea.RecordableTextAction.actionPerformed(RecordableTextAction.java:105)
at javax.swing.SwingUtilities.notifyAction(SwingUtilities.java:1645)
at javax.swing.JComponent.processKeyBinding(JComponent.java:2859)
at javax.swing.JComponent.processKeyBindings(JComponent.java:2894)
at javax.swing.JComponent.processKeyEvent(JComponent.java:2822)
at java.awt.Component.processEvent(Component.java:6191)
at java.awt.Container.processEvent(Container.java:2083)
at java.awt.Component.dispatchEventImpl(Component.java:4776)
at java.awt.Container.dispatchEventImpl(Container.java:2141)
at java.awt.Component.dispatchEvent(Component.java:4604)
at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1856)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:722)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:1000)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:865)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:686)
at java.awt.Component.dispatchEventImpl(Component.java:4648)
at java.awt.Container.dispatchEventImpl(Container.java:2141)
at java.awt.Window.dispatchEventImpl(Window.java:2489)
at java.awt.Component.dispatchEvent(Component.java:4604)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:717)
at java.awt.EventQueue.access$400(EventQueue.java:82)
at java.awt.EventQueue$2.run(EventQueue.java:676)
at java.awt.EventQueue$2.run(EventQueue.java:674)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:86)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:690)
at java.awt.EventQueue$3.run(EventQueue.java:688)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:86)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:687)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
UNDO of DecreaseIndentAction in the case of performing in forward selection of CSS files is not is not atomically.
This problem does not occur in the editing of Java files.
Steps to reproduce the bug:
Theme t1 = Theme.load(new FileInputStream("C:\\default.xml"));
t1.save(new FileOutputStream("C:\\theme.xml"));
Theme t2 = Theme.load(new FileInputStream("C:\\theme.xml"));
Result:
java.io.IOException: org.xml.sax.SAXParseException: The content of element type "RSyntaxTheme" must
match "(baseFont?,background,caret,selection,currentLineHighlight,marginLine,markAllHighlight,markOc
currencesHighlight,matchedBracket,hyperlinks,secondaryLanguages,gutterBorder,lineNumbers,foldIndicat
or,iconRowHeader,tokenStyles)".
at org.fife.ui.rsyntaxtextarea.Theme$XmlHandler.load(Theme.java:600)
at org.fife.ui.rsyntaxtextarea.Theme.load(Theme.java:337)
at org.fife.ui.rsyntaxtextarea.Theme.load(Theme.java:315)
If we check theme.xml file we can see that following attributes have not been saved:
Problem with save of secondaryLanguage can be solved very easy:
org.fife.ui.rsyntaxtextarea.Theme.java:
354. public void save(OutputStream out) throws IOException {
:
419. elem = doc.createElement("secondaryLanguages");
420. for (int i=0; i<secondaryLanguages.length; i++) {
421. Color color = secondaryLanguages[i];
422. Element elem2 = doc.createElement("language");
423. elem2.setAttribute("index", Integer.toString(i+1));
424. elem2.setAttribute("bg", color==null ? "":colorToString(color));
424.new elem.appendChild(elem2);
425. }
426.new root.appendChild(elem);
:
As far as I can see "iconRowHeader" is not loaded from xml, so maybe it should be marked as not mandatory element in theme.dtd? Or removed.
<!ELEMENT RSyntaxTheme (baseFont?, background, caret, selection,
currentLineHighlight, marginLine, markAllHighlight, markOccurrencesHighlight,
matchedBracket, hyperlinks, secondaryLanguages, gutterBorder, lineNumbers,
foldIndicator, iconRowHeader?, tokenStyles)>
It would be good to see the latest version up in maven central.
Version 2.11 of JMeter is using version 2.5.1 of RSyntaxArea and the dependency tree of the maven release is currently broken which is currently a blocker for version 1.10.0 of the JMeter Maven Plugin.
Any ETA for an upload?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.