Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Scratch for Java Studio is a desktop IDE for students moving from Scratch to
Java. It builds projects with [Scratch for Java](https://github.com/openpatch/scratch-for-java)
and keeps them as ordinary Java source files that also work in BlueJ and VS Code.

**Status: 0.1.0-alpha.10.** The IDE and its
**Status: 0.1.0-alpha.11.** The IDE and its
project format may change while we test it with students and teachers.

![Scratch for Java Studio with the code editor and the visual stage designer side by side](docs/screenshot.png)
Expand Down
2 changes: 1 addition & 1 deletion app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.openpatch.scratch4j</groupId>
<artifactId>scratch4j-ide</artifactId>
<version>0.1.0-alpha.10</version>
<version>0.1.0-alpha.11</version>
</parent>

<artifactId>app</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.openpatch.scratch4j</groupId>
<artifactId>scratch4j-ide</artifactId>
<version>0.1.0-alpha.10</version>
<version>0.1.0-alpha.11</version>
</parent>

<artifactId>core</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion export/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.openpatch.scratch4j</groupId>
<artifactId>scratch4j-ide</artifactId>
<version>0.1.0-alpha.10</version>
<version>0.1.0-alpha.11</version>
</parent>

<artifactId>export</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>org.openpatch.scratch4j</groupId>
<artifactId>scratch4j-ide</artifactId>
<version>0.1.0-alpha.10</version>
<version>0.1.0-alpha.11</version>
<packaging>pom</packaging>

<name>Scratch for Java Studio</name>
Expand Down
2 changes: 1 addition & 1 deletion runner/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.openpatch.scratch4j</groupId>
<artifactId>scratch4j-ide</artifactId>
<version>0.1.0-alpha.10</version>
<version>0.1.0-alpha.11</version>
</parent>

<artifactId>runner</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ static void start() {
new Hook();
hooked = true;
}
System.err.println(MARK + "frames " + frames);
// "loading" while the library's loading screen shows (slow PCs stop
// drawing for a while when the stage takes over)
System.err.println(MARK + "frames " + frames + (loading() ? " loading" : ""));
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
Expand Down Expand Up @@ -358,6 +360,24 @@ static Object call(Object target, String name, Class<?>[] types, Object... args)
}

/** The library's Processing sketch (reflective: no Processing types needed to compile). */
private static java.lang.reflect.Field state;

/** The library still shows its loading screen (before the stage runs). */
static boolean loading() {
Object applet = applet();
if (applet == null) return false;
try {
if (state == null) {
java.lang.reflect.Field field = applet.getClass().getDeclaredField("state");
field.setAccessible(true);
state = field;
}
return String.valueOf(state.get(applet)).equals("LOADING");
} catch (ReflectiveOperationException | RuntimeException e) {
return false; // an older library: no loading screen to wait for
}
}

static Object applet() {
try {
return Class.forName("org.openpatch.scratch.internal.Applet")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ public void stop() {
private static void control(String message, RunListener listener) {
if (message.startsWith("frames ")) {
try {
listener.onFrames(Long.parseLong(message.substring("frames ".length()).trim()));
String[] beat = message.substring("frames ".length()).trim().split(" ");
listener.onFrames(Long.parseLong(beat[0]),
beat.length > 1 && beat[1].equals("loading"));
} catch (NumberFormatException ignored) {
// a garbled heartbeat is skipped
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ default void onCompileFailed(org.openpatch.scratch4j.core.compile.CompileResult
*/
default void onFrames(long frames) {}

/**
* The heartbeat with whether the library still shows its loading screen
* (where a slow PC may draw nothing for a while). Defaults to {@link #onFrames(long)}.
*/
default void onFrames(long frames, boolean loading) {
onFrames(frames);
}

/** The game loop stopped ({@code pause}, or after a {@code step}) at this frame. */
default void onPaused(long frame) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,14 @@ void aForeverLoopInRunStopsTheFrameCount() throws Exception {
+ " while (true) { }\n }\n }"));
ScratchProject project = ScratchProject.open(tmp.resolve("frozen"));
List<Long> beats = new CopyOnWriteArrayList<>();
List<Boolean> loading = new CopyOnWriteArrayList<>();
RunHandle handle = new ProjectRunner().run(project,
RunConfig.of(project.startStage()).withControl(),
new RunListener() {
@Override public void onFrames(long f) { beats.add(f); }
@Override public void onFrames(long f, boolean l) {
beats.add(f);
loading.add(l);
}
});
try {
waitFor(() -> beats.size() >= 8 && beats.get(beats.size() - 1) > 0, 20000);
Expand All @@ -243,6 +247,8 @@ void aForeverLoopInRunStopsTheFrameCount() throws Exception {
assertThat(beats.get(beats.size() - 1)).as("frozen: no new frames").isEqualTo(last);
// run() starts a few frames after the first drawn frame
assertThat(last).isBetween(55L, 200L);
// past the loading screen: the IDE's short freeze limit applies
assertThat(loading.get(loading.size() - 1)).as("loading flags %s", loading).isFalse();
} finally {
handle.stop();
}
Expand Down
2 changes: 1 addition & 1 deletion sound/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.openpatch.scratch4j</groupId>
<artifactId>scratch4j-ide</artifactId>
<version>0.1.0-alpha.10</version>
<version>0.1.0-alpha.11</version>
</parent>

<artifactId>sound</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion ui/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.openpatch.scratch4j</groupId>
<artifactId>scratch4j-ide</artifactId>
<version>0.1.0-alpha.10</version>
<version>0.1.0-alpha.11</version>
</parent>

<artifactId>ui</artifactId>
Expand Down
7 changes: 7 additions & 0 deletions ui/src/main/java/org/openpatch/scratch4j/ui/EditorTabs.java
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,13 @@ boolean close(Tab tab) {
return true;
}

/** Drops every tab without asking (the project closes or another one opens). */
void clear() {
getTabs().clear();
openTabs.clear();
toolTabs.clear();
}

/** Right-click on a tab: close it, the others, or all. */
private javafx.scene.control.ContextMenu tabMenu(Tab tab) {
javafx.scene.control.MenuItem close = new javafx.scene.control.MenuItem(
Expand Down
14 changes: 8 additions & 6 deletions ui/src/main/java/org/openpatch/scratch4j/ui/StudioApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ private void closeProject() {
checkDelay.stop();
hotSwapDelay.stop();
stuckDelay.stop();
editor.getTabs().clear();
editor.clear();
project.set(null);
hasProject.set(false);
stage.setTitle("Scratch for Java Studio");
Expand Down Expand Up @@ -1031,7 +1031,7 @@ private void open(ScratchProject p) {
projectTitle.setText(p.name());
hasProject.set(true);
fileTree.setRoot(p.root());
editor.getTabs().clear();
editor.clear();
selector = new StageSelectorView(p, this::openDesigner,
cls -> editor.open(p.root().resolve(cls + ".java")),
() -> {
Expand Down Expand Up @@ -1531,8 +1531,10 @@ private Path mediaFile(String extension) {
* A program whose frame count stops for 3 seconds (or that never shows a
* window) is frozen - almost always a loop that never ends. The console
* explains it once; the Problems tab shows where the transition lint found it.
* On the loading screen it gets 20 seconds: a slow PC draws nothing for a
* while when the stage takes over.
*/
void watchdog(long frames) {
void watchdog(long frames, boolean loading) {
long now = System.currentTimeMillis();
if (frames != watchFrames) {
if (watchWarned && frames > watchFrames && watchFrames >= 0) {
Expand All @@ -1558,7 +1560,7 @@ void watchdog(long frames) {
watchChanged = now;
return;
}
boolean stalled = frames >= 0 && now - watchChanged >= 3000;
boolean stalled = frames >= 0 && now - watchChanged >= (loading ? 20000 : 3000);
boolean noWindow = frames < 0 && now - watchStarted >= 10000;
if ((stalled || noWindow) && !watchWarned && running.get()) {
watchWarned = true;
Expand Down Expand Up @@ -3092,8 +3094,8 @@ private void runStage(String startStage, boolean debug) {
liveSwap = new org.openpatch.scratch4j.runner.HotSwap(p, session);
RunHandle handle = runner.run(p, config,
new RunListener() {
@Override public void onFrames(long frames) {
Platform.runLater(() -> watchdog(frames));
@Override public void onFrames(long frames, boolean loading) {
Platform.runLater(() -> watchdog(frames, loading));
}

@Override public void onPaused(long frame) {
Expand Down
Loading