Skip to content

Commit 0303c0f

Browse files
committed
migrating Preferences and Messages to stand-alone version
1 parent eff28c9 commit 0303c0f

File tree

266 files changed

+23802
-2663
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

266 files changed

+23802
-2663
lines changed

app/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ compose.desktop {
9797

9898
dependencies {
9999
implementation(project(":core"))
100+
implementation(project(":app:utils"))
100101
runtimeOnly(project(":java"))
101102

102103
implementation(libs.flatlaf)
Lines changed: 3 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -19,52 +19,17 @@
1919
package processing.app
2020

2121
import processing.app.ui.Toolkit
22+
import processing.utils.Messages
23+
2224
import java.awt.EventQueue
2325
import java.awt.Frame
2426
import java.io.PrintWriter
2527
import java.io.StringWriter
2628
import javax.swing.JFrame
2729
import javax.swing.JOptionPane
2830

29-
class Messages {
31+
class AppMessages : Messages() {
3032
companion object {
31-
/**
32-
* "No cookie for you" type messages. Nothing fatal or all that
33-
* much of a bummer, but something to notify the user about.
34-
*/
35-
@JvmStatic
36-
fun showMessage(title: String = "Message", message: String) {
37-
if (Base.isCommandLine()) {
38-
println("$title: $message")
39-
} else {
40-
JOptionPane.showMessageDialog(
41-
Frame(), message, title,
42-
JOptionPane.INFORMATION_MESSAGE
43-
)
44-
}
45-
}
46-
47-
48-
/**
49-
* Non-fatal error message with optional stack trace side dish.
50-
*/
51-
/**
52-
* Non-fatal error message.
53-
*/
54-
@JvmStatic
55-
@JvmOverloads
56-
fun showWarning(title: String = "Warning", message: String, e: Throwable? = null) {
57-
if (Base.isCommandLine()) {
58-
println("$title: $message")
59-
} else {
60-
JOptionPane.showMessageDialog(
61-
Frame(), message, title,
62-
JOptionPane.WARNING_MESSAGE
63-
)
64-
}
65-
e?.printStackTrace()
66-
}
67-
6833
/**
6934
* Non-fatal error message with two levels of formatting.
7035
* Unlike the others, this is non-blocking and will run later on the EDT.
@@ -92,26 +57,6 @@ class Messages {
9257
}
9358

9459

95-
/**
96-
* Show an error message that's actually fatal to the program.
97-
* This is an error that can't be recovered. Use showWarning()
98-
* for errors that allow P5 to continue running.
99-
*/
100-
@JvmStatic
101-
fun showError(title: String = "Error", message: String, e: Throwable?) {
102-
if (Base.isCommandLine()) {
103-
System.err.println("$title: $message")
104-
} else {
105-
JOptionPane.showMessageDialog(
106-
Frame(), message, title,
107-
JOptionPane.ERROR_MESSAGE
108-
)
109-
}
110-
e?.printStackTrace()
111-
System.exit(1)
112-
}
113-
114-
11560
/**
11661
* Warning window that includes the stack trace.
11762
*/
@@ -218,56 +163,6 @@ class Messages {
218163
return -1
219164
}
220165

221-
222-
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
223-
@JvmStatic
224-
@Deprecated("Use log() instead")
225-
fun log(from: Any, message: String) {
226-
if (Base.DEBUG) {
227-
val callingClass = Throwable()
228-
.stackTrace[2]
229-
.className
230-
.formatClassName()
231-
println("$callingClass: $message")
232-
}
233-
}
234-
235-
@JvmStatic
236-
fun log(message: String?) {
237-
if (Base.DEBUG) {
238-
val callingClass = Throwable()
239-
.stackTrace[2]
240-
.className
241-
.formatClassName()
242-
println("$callingClass$message")
243-
}
244-
}
245-
246-
@JvmStatic
247-
fun logf(message: String?, vararg args: Any?) {
248-
if (Base.DEBUG) {
249-
val callingClass = Throwable()
250-
.stackTrace[2]
251-
.className
252-
.formatClassName()
253-
System.out.printf("$callingClass$message", *args)
254-
}
255-
}
256-
257-
@JvmStatic
258-
@JvmOverloads
259-
fun err(message: String?, e: Throwable? = null) {
260-
if (Base.DEBUG) {
261-
if (message != null) {
262-
val callingClass = Throwable()
263-
.stackTrace[4]
264-
.className
265-
.formatClassName()
266-
System.err.println("$callingClass$message")
267-
}
268-
e?.printStackTrace()
269-
}
270-
}
271166
}
272167
}
273168

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package processing.app;
2+
3+
import processing.utils.Preferences;
4+
import processing.app.ui.Toolkit;
5+
6+
import java.awt.*;
7+
8+
public class AppPreferences extends Preferences {
9+
10+
static public void init() {
11+
Preferences.init();
12+
13+
// For CJK users, enable IM support by default
14+
if (Language.useInputMethod() && !getBoolean("editor.input_method_support")) {
15+
setBoolean("editor.input_method_support", true);
16+
}
17+
}
18+
19+
20+
static public Font getFont(String familyAttr, String sizeAttr, int style) {
21+
int fontSize = getInteger(sizeAttr);
22+
23+
String fontFamily = get(familyAttr);
24+
if ("processing.mono".equals(fontFamily) ||
25+
Toolkit.getMonoFontName().equals(fontFamily)) {
26+
return Toolkit.getMonoFont(fontSize, style);
27+
}
28+
return new Font(fontFamily, style, fontSize);
29+
}
30+
}

0 commit comments

Comments
 (0)