Skip to content

Commit ea599ab

Browse files
committed
- Bugfix: EditorPane#loadPreferences() called twice - Bugfix: Setting Editor's title fails when active document is a class-less Java file - Workaround: Avoid calling addNotify() until GUI is fully initialized - Workaround: Catch more exceptions before giving up when loading new documents - Workaround: Add DocumentNotifiers as late as possible to avoid spurious refreshes
1 parent d67805f commit ea599ab

File tree

3 files changed

+294
-40
lines changed

3 files changed

+294
-40
lines changed

pom.xml.releaseBackup

Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<groupId>org.scijava</groupId>
7+
<artifactId>pom-scijava</artifactId>
8+
<version>31.1.0</version>
9+
<relativePath />
10+
</parent>
11+
12+
<artifactId>script-editor</artifactId>
13+
<version>0.7.3-SNAPSHOT</version>
14+
15+
<name>SciJava Script Editor</name>
16+
<description>Script Editor and Interpreter for SciJava script languages.</description>
17+
<url>https://github.com/scijava/script-editor</url>
18+
<inceptionYear>2009</inceptionYear>
19+
<organization>
20+
<name>SciJava</name>
21+
<url>https://scijava.org/</url>
22+
</organization>
23+
<licenses>
24+
<license>
25+
<name>Simplified BSD License</name>
26+
<distribution>repo</distribution>
27+
</license>
28+
</licenses>
29+
30+
<developers>
31+
<developer>
32+
<id>ctrueden</id>
33+
<name>Curtis Rueden</name>
34+
<url>https://imagej.net/User:Rueden</url>
35+
<roles>
36+
<role>lead</role>
37+
<role>developer</role>
38+
<role>debugger</role>
39+
<role>reviewer</role>
40+
<role>support</role>
41+
<role>maintainer</role>
42+
</roles>
43+
</developer>
44+
<developer>
45+
<id>acardona</id>
46+
<name>Albert Cardona</name>
47+
<url>https://imagej.net/User:Albertcardona</url>
48+
<roles>
49+
<role>developer</role>
50+
</roles>
51+
</developer>
52+
</developers>
53+
<contributors>
54+
<contributor>
55+
<name>Johannes Schindelin</name>
56+
<url>https://imagej.net/User:Schindelin</url>
57+
<roles><role>founder</role></roles>
58+
<properties><id>dscho</id></properties>
59+
</contributor>
60+
<contributor>
61+
<name>Sumit Dubey</name>
62+
<roles><role>founder</role></roles>
63+
</contributor>
64+
<contributor>
65+
<name>Jan Eglinger</name>
66+
<url>https://imagej.net/User:Eglinger</url>
67+
<properties><id>imagejan</id></properties>
68+
</contributor>
69+
<contributor>
70+
<name>Ulrik Günther</name>
71+
<properties><id>skalarproduktraum</id></properties>
72+
</contributor>
73+
<contributor>
74+
<name>Jonathan Hale</name>
75+
<properties><id>Squareys</id></properties>
76+
</contributor>
77+
<contributor>
78+
<name>Stefan Helfrich</name>
79+
<url>https://imagej.net/User:Stelfrich</url>
80+
<properties><id>stelfrich</id></properties>
81+
</contributor>
82+
<contributor>
83+
<name>Mark Hiner</name>
84+
<url>https://imagej.net/User:Hinerm</url>
85+
<properties><id>hinerm</id></properties>
86+
</contributor>
87+
<contributor>
88+
<name>Samuel Inverso</name>
89+
<url>https://imagej.net/User:Sinverso</url>
90+
<properties><id>sinverso</id></properties>
91+
</contributor>
92+
<contributor>
93+
<name>Tom Kazimiers</name>
94+
<url>https://imagej.net/User:Kazimiers</url>
95+
<properties><id>tomka</id></properties>
96+
</contributor>
97+
<contributor>
98+
<name>Jacques Pecreaux</name>
99+
</contributor>
100+
<contributor>
101+
<name>Luke Stuyvenberg</name>
102+
<url>https://imagej.net/User:Stuyvenberg</url>
103+
<properties><id>stuyvenberg</id></properties>
104+
</contributor>
105+
<contributor>
106+
<name>Jean-Yves Tinevez</name>
107+
<url>https://imagej.net/User:JeanYvesTinevez</url>
108+
<properties><id>tinevez</id></properties>
109+
</contributor>
110+
<contributor>
111+
<name>Yili Zhao</name>
112+
<url>https://imagej.net/User:Panovr</url>
113+
<properties><id>panovr</id></properties>
114+
</contributor>
115+
</contributors>
116+
117+
<mailingLists>
118+
<mailingList>
119+
<name>SciJava</name>
120+
<subscribe>https://groups.google.com/group/scijava</subscribe>
121+
<unsubscribe>https://groups.google.com/group/scijava</unsubscribe>
122+
<post>scijava.com</post>
123+
<archive>https://groups.google.com/group/scijava</archive>
124+
</mailingList>
125+
</mailingLists>
126+
127+
<scm>
128+
<connection>scm:git:https://github.com/scijava/script-editor</connection>
129+
<developerConnection>scm:git:git@github.com:scijava/script-editor</developerConnection>
130+
<tag>HEAD</tag>
131+
<url>https://github.com/scijava/script-editor</url>
132+
</scm>
133+
<issueManagement>
134+
<system>GitHub Issues</system>
135+
<url>https://github.com/scijava/script-editor/issues</url>
136+
</issueManagement>
137+
<ciManagement>
138+
<system>GitHub Actions</system>
139+
<url>https://github.com/scijava/script-editor/actions</url>
140+
</ciManagement>
141+
142+
<properties>
143+
<main-class>org.scijava.ui.swing.script.Main</main-class>
144+
<package-name>org.scijava.ui.swing.script</package-name>
145+
<license.licenseName>bsd_2</license.licenseName>
146+
<license.copyrightOwners>SciJava developers.</license.copyrightOwners>
147+
148+
<!-- NB: Deploy releases to the SciJava Maven repository. -->
149+
<releaseProfiles>sign,deploy-to-scijava</releaseProfiles>
150+
</properties>
151+
152+
<dependencies>
153+
<!-- SciJava dependencies -->
154+
<dependency>
155+
<groupId>org.scijava</groupId>
156+
<artifactId>scijava-common</artifactId>
157+
</dependency>
158+
<dependency>
159+
<groupId>org.scijava</groupId>
160+
<artifactId>scripting-java</artifactId>
161+
</dependency>
162+
163+
<!-- Third-party dependencies -->
164+
<dependency>
165+
<groupId>com.fifesoft</groupId>
166+
<artifactId>rsyntaxtextarea</artifactId>
167+
</dependency>
168+
<dependency>
169+
<groupId>com.fifesoft</groupId>
170+
<artifactId>languagesupport</artifactId>
171+
</dependency>
172+
<dependency>
173+
<groupId>com.miglayout</groupId>
174+
<artifactId>miglayout-swing</artifactId>
175+
</dependency>
176+
<dependency>
177+
<groupId>org.scijava</groupId>
178+
<artifactId>batch-processor</artifactId>
179+
</dependency>
180+
181+
<!-- Test scope dependencies -->
182+
<dependency>
183+
<groupId>junit</groupId>
184+
<artifactId>junit</artifactId>
185+
<scope>test</scope>
186+
</dependency>
187+
<dependency>
188+
<groupId>org.scijava</groupId>
189+
<artifactId>parsington</artifactId>
190+
<scope>test</scope>
191+
</dependency>
192+
<dependency>
193+
<groupId>org.scijava</groupId>
194+
<artifactId>scijava-ui-swing</artifactId>
195+
<scope>test</scope>
196+
</dependency>
197+
<dependency>
198+
<groupId>org.scijava</groupId>
199+
<artifactId>scripting-groovy</artifactId>
200+
<scope>test</scope>
201+
</dependency>
202+
</dependencies>
203+
204+
<repositories>
205+
<repository>
206+
<id>scijava.public</id>
207+
<url>https://maven.scijava.org/content/groups/public</url>
208+
</repository>
209+
</repositories>
210+
211+
<profiles>
212+
<!-- Launch the Script Editor via Maven using: mvn -Pexec,editor -->
213+
<profile>
214+
<id>editor</id>
215+
<properties>
216+
<main-class>org.scijava.ui.swing.script.ScriptEditorTestDrive</main-class>
217+
<exec.classpathScope>test</exec.classpathScope>
218+
</properties>
219+
</profile>
220+
<!-- Launch the Script Interpreter via Maven using: mvn -Pexec,interp -->
221+
<profile>
222+
<id>interp</id>
223+
<properties>
224+
<main-class>org.scijava.ui.swing.script.ScriptInterpreterTestDrive</main-class>
225+
<exec.classpathScope>test</exec.classpathScope>
226+
</properties>
227+
</profile>
228+
</profiles>
229+
</project>

src/main/java/org/scijava/ui/swing/script/EditorPane.java

Lines changed: 56 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,10 @@ public void hyperlinkUpdate(final HyperlinkEvent hle) {
178178
});
179179
// Add support for TODO, FIXME, HACK
180180
addParser(new TaskTagParser());
181-
// load preferences
182-
loadPreferences();
183181

184-
// Register recordable actions
182+
//NB: Loading of preferences will happen by calling #loadPreferences();
183+
184+
// Register recordable actions: TODO this should go to EditorPaneActions
185185
getActionMap().put(EditorPaneActions.nextWordAction, wordMovement("Next-Word-Action", +1, false));
186186
getActionMap().put(EditorPaneActions.selectionNextWordAction, wordMovement("Next-Word-Select-Action", +1, true));
187187
getActionMap().put(EditorPaneActions.previousWordAction, wordMovement("Prev-Word-Action", -1, false));
@@ -192,7 +192,6 @@ public void hyperlinkUpdate(final HyperlinkEvent hle) {
192192
adjustPopupMenu();
193193

194194
ToolTipManager.sharedInstance().registerComponent(this);
195-
getDocument().addDocumentListener(this);
196195
addMouseListener(new MouseAdapter() {
197196

198197
SearchContext context;
@@ -235,6 +234,13 @@ protected boolean isLocked() {
235234
return !(isEditable() && isEnabled());
236235
}
237236

237+
@Override
238+
public void addNotify() {
239+
// this seems to solve these issues reported here:
240+
// https://forum.image.sc/t/shiny-new-script-editor/64160/19
241+
if (isVisible()) super.addNotify();
242+
}
243+
238244
@Override
239245
protected JPopupMenu createPopupMenu() {
240246
super.createPopupMenu();
@@ -533,43 +539,54 @@ public void write(final File file) throws IOException {
533539
public void open(final File file) throws IOException {
534540
final File oldFile = curFile;
535541
curFile = null;
536-
if (file == null) setText("");
542+
if (file == null)
543+
setText("");
537544
else {
538545
int line = 0;
539546
try {
540-
if (file.getCanonicalPath().equals(oldFile.getCanonicalPath())) line =
541-
getCaretLineNumber();
542-
}
543-
catch (final Exception e) { /* ignore */}
547+
if (file.getCanonicalPath().equals(oldFile.getCanonicalPath()))
548+
line = getCaretLineNumber();
549+
} catch (final Exception e) {
550+
/* ignore */}
544551
if (!file.exists()) {
545552
modifyCount = Integer.MIN_VALUE;
546553
setFileName(file);
547-
return;
554+
return;
555+
}
556+
final StringBuffer string = new StringBuffer();
557+
try (BufferedReader reader = new BufferedReader(
558+
new InputStreamReader(new FileInputStream(file), "UTF-8"))) {
559+
final char[] buffer = new char[16384];
560+
for (;;) {
561+
final int count = reader.read(buffer);
562+
if (count < 0)
563+
break;
564+
string.append(buffer, 0, count);
565+
}
566+
reader.close();
548567
}
549-
final StringBuffer string = new StringBuffer();
550-
final BufferedReader reader =
551-
new BufferedReader(new InputStreamReader(new FileInputStream(file),
552-
"UTF-8"));
553-
final char[] buffer = new char[16384];
554-
for (;;) {
555-
final int count = reader.read(buffer);
556-
if (count < 0) break;
557-
string.append(buffer, 0, count);
568+
try {
569+
setText(string.toString());
570+
} catch (final Error | IndexOutOfBoundsException e2) {
571+
// Mysterious parsing errors w/ IJM!? Syntax highlighting will
572+
// fail but things should be back to normal on next repaint. See
573+
// https://github.com/scijava/script-editor/issues/14
574+
// https://forum.image.sc/t/shiny-new-script-editor/64160/19
575+
log.debug(e2);
558576
}
559-
reader.close();
560-
SwingUtilities.invokeLater(() -> {
561-
setText(string.toString()); // otherwise GUI freezes!??
562-
});
563577
curFile = file;
564-
if (line > getLineCount()) line = getLineCount() - 1;
578+
if (line > getLineCount())
579+
line = getLineCount() - 1;
565580
try {
566581
setCaretPosition(getLineStartOffset(line));
582+
} catch (final BadLocationException e) {
583+
/* ignore */
584+
}
567585
}
568-
catch (final BadLocationException e) { /* ignore */}
569-
}
570-
discardAllEdits();
571-
modifyCount = 0;
572-
fileLastModified = file == null || !file.exists() ? 0 : file.lastModified();
586+
discardAllEdits();
587+
fileLastModified = file == null || !file.exists() ? 0 : file.lastModified();
588+
modifyCount = 0;
589+
getDocument().addDocumentListener(this); // Add as late as possible to avoid spurious updates
573590
}
574591

575592
/**
@@ -644,9 +661,13 @@ protected String getFileName() {
644661
extension = "." + extensions.get(0);
645662
}
646663
if (currentLanguage.getLanguageName().equals("Java")) {
647-
final String name = new TokenFunctions(this).getClassName();
648-
if (name != null) {
649-
return name + extension;
664+
try {
665+
final String name = new TokenFunctions(this).getClassName();
666+
if (name != null) {
667+
return name + extension;
668+
}
669+
} catch (final Exception ignored) {
670+
// Do nothing
650671
}
651672
}
652673
}
@@ -731,9 +752,10 @@ protected void setLanguage(final ScriptLanguage language,
731752
try {
732753
setSyntaxEditingStyle(styleName);
733754
}
734-
catch (final NullPointerException exc) {
735-
// NB: Avoid possible NPEs in RSyntaxTextArea code.
755+
catch (final NullPointerException | IndexOutOfBoundsException exc) {
756+
// NB Avoid possible NPEs and other exceptions in RSyntaxTextArea code.
736757
// See: https://fiji.sc/bug/1181.html
758+
// See: https://forum.image.sc/t/shiny-new-script-editor/64160/19
737759
log.debug(exc);
738760
}
739761

0 commit comments

Comments
 (0)