Skip to content

migrating Preferences and Messages to stand-alone version #1130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ processing-examples
core/build/
build/publish/
app/build
app/utils/build
java/build/
/build/reports
/java/bin
Expand Down
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ compose.desktop {

dependencies {
implementation(project(":core"))
implementation(project(":app:utils"))
runtimeOnly(project(":java"))

implementation(libs.flatlaf)
Expand Down
7 changes: 3 additions & 4 deletions app/src/processing/app/Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import processing.app.ui.Toolkit;
import processing.core.*;
import processing.data.StringList;
import processing.utils.Util;

/**
* The base class for the main processing application.
Expand All @@ -67,8 +68,6 @@ public class Base {
*/
static public boolean DEBUG = System.getenv().containsKey("DEBUG");

/** True if running via Commander. */
static private boolean commandLine;

/**
* If settings.txt is present inside lib, it will be used to override
Expand Down Expand Up @@ -472,12 +471,12 @@ static public String getVersionName() {


public static void setCommandLine() {
commandLine = true;
System.setProperty("processing.cli", "true");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please explain why this needed to change?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main motivation behind this change was to be able to know if Processing is launched via CLI or not without the need to depend on app module via using Base.isCommandLine()

as for example im using it in the utils.Messages.kt

}


static public boolean isCommandLine() {
return commandLine;
return Boolean.getBoolean("processing.cli");
}


Expand Down
1 change: 1 addition & 0 deletions app/src/processing/app/Language.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import processing.core.PApplet;
import processing.data.StringList;
import processing.utils.Util;


/**
Expand Down
1 change: 1 addition & 0 deletions app/src/processing/app/Library.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import processing.core.*;
import processing.data.StringDict;
import processing.data.StringList;
import processing.utils.Util;


public class Library extends LocalContribution {
Expand Down
109 changes: 1 addition & 108 deletions app/src/processing/app/Messages.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,45 +26,8 @@ import java.io.StringWriter
import javax.swing.JFrame
import javax.swing.JOptionPane

class Messages {
class Messages : processing.utils.Messages() {
companion object {
/**
* "No cookie for you" type messages. Nothing fatal or all that
* much of a bummer, but something to notify the user about.
*/
@JvmStatic
fun showMessage(title: String = "Message", message: String) {
if (Base.isCommandLine()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say that the JOptionPane parts should stay and the println can be in the universal class

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If i understand you correctly, you wanna seperate the appearance of graphical messages via JOptionPane to be only used by app.Messages and a simple println only for the utils.Messages

but wouldn't that make an issue in utils module? as for example in processing.utils.settingslocation and processing.utils.Base
error messages via Messages.showError() wouldn't display a graphical message only just a console print. So is it accepctable? also bear in mind that i cannot use app.Messages for this purpose because i want the utils module along with the utils.preference class to be fully independent of app module

println("$title: $message")
} else {
JOptionPane.showMessageDialog(
Frame(), message, title,
JOptionPane.INFORMATION_MESSAGE
)
}
}


/**
* Non-fatal error message with optional stack trace side dish.
*/
/**
* Non-fatal error message.
*/
@JvmStatic
@JvmOverloads
fun showWarning(title: String = "Warning", message: String, e: Throwable? = null) {
if (Base.isCommandLine()) {
println("$title: $message")
} else {
JOptionPane.showMessageDialog(
Frame(), message, title,
JOptionPane.WARNING_MESSAGE
)
}
e?.printStackTrace()
}

/**
* Non-fatal error message with two levels of formatting.
* Unlike the others, this is non-blocking and will run later on the EDT.
Expand Down Expand Up @@ -92,26 +55,6 @@ class Messages {
}


/**
* Show an error message that's actually fatal to the program.
* This is an error that can't be recovered. Use showWarning()
* for errors that allow P5 to continue running.
*/
@JvmStatic
fun showError(title: String = "Error", message: String, e: Throwable?) {
if (Base.isCommandLine()) {
System.err.println("$title: $message")
} else {
JOptionPane.showMessageDialog(
Frame(), message, title,
JOptionPane.ERROR_MESSAGE
)
}
e?.printStackTrace()
System.exit(1)
}


/**
* Warning window that includes the stack trace.
*/
Expand Down Expand Up @@ -218,56 +161,6 @@ class Messages {
return -1
}


// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
@JvmStatic
@Deprecated("Use log() instead")
fun log(from: Any, message: String) {
if (Base.DEBUG) {
val callingClass = Throwable()
.stackTrace[2]
.className
.formatClassName()
println("$callingClass: $message")
}
}

@JvmStatic
fun log(message: String?) {
if (Base.DEBUG) {
val callingClass = Throwable()
.stackTrace[2]
.className
.formatClassName()
println("$callingClass$message")
}
}

@JvmStatic
fun logf(message: String?, vararg args: Any?) {
if (Base.DEBUG) {
val callingClass = Throwable()
.stackTrace[2]
.className
.formatClassName()
System.out.printf("$callingClass$message", *args)
}
}

@JvmStatic
@JvmOverloads
fun err(message: String?, e: Throwable? = null) {
if (Base.DEBUG) {
if (message != null) {
val callingClass = Throwable()
.stackTrace[4]
.className
.formatClassName()
System.err.println("$callingClass$message")
}
e?.printStackTrace()
}
}
}
}

Expand Down
1 change: 1 addition & 0 deletions app/src/processing/app/Mode.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import processing.app.ui.Recent;
import processing.app.ui.Toolkit;
import processing.core.PApplet;
import processing.utils.Util;


public abstract class Mode {
Expand Down
9 changes: 8 additions & 1 deletion app/src/processing/app/Platform.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import processing.core.PApplet;
import processing.core.PConstants;
import processing.data.StringDict;
import processing.utils.SettingsResolver;
import processing.utils.Util;


public class Platform {
Expand Down Expand Up @@ -129,7 +131,12 @@ static public float getSystemZoom() {


static public File getSettingsFolder() throws Exception {
return inst.getSettingsFolder();
File override = Base.getSettingsOverride();
if (override != null) {
return override;
}

return SettingsResolver.getSettingsFolder();
}


Expand Down
Loading