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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,52 +19,17 @@
package processing.app

import processing.app.ui.Toolkit
import processing.utils.Messages

import java.awt.EventQueue
import java.awt.Frame
import java.io.PrintWriter
import java.io.StringWriter
import javax.swing.JFrame
import javax.swing.JOptionPane

class Messages {
class AppMessages : 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()) {
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 +57,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 +163,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
30 changes: 30 additions & 0 deletions app/src/processing/app/AppPreferences.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package processing.app;

import processing.utils.Preferences;
import processing.app.ui.Toolkit;

import java.awt.*;

public class AppPreferences extends Preferences {

static public void init() {
Preferences.init();

// For CJK users, enable IM support by default
if (Language.useInputMethod() && !getBoolean("editor.input_method_support")) {
setBoolean("editor.input_method_support", true);
}
}


static public Font getFont(String familyAttr, String sizeAttr, int style) {
int fontSize = getInteger(sizeAttr);

String fontFamily = get(familyAttr);
if ("processing.mono".equals(fontFamily) ||
Toolkit.getMonoFontName().equals(fontFamily)) {
return Toolkit.getMonoFont(fontSize, style);
}
return new Font(fontFamily, style, fontSize);
}
}
Loading