Skip to content

Commit ba82cfd

Browse files
committed
Merge branch 'main' into preferences-impl
2 parents 91cf11b + 1237c55 commit ba82cfd

File tree

5 files changed

+343
-404
lines changed

5 files changed

+343
-404
lines changed

app/src/processing/app/Messages.kt

Lines changed: 26 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,28 @@ package processing.app
2020

2121
import androidx.compose.foundation.layout.Column
2222
import androidx.compose.foundation.layout.padding
23-
import androidx.compose.material.icons.Icons
24-
import androidx.compose.material.icons.filled.Error
25-
import androidx.compose.material.icons.filled.Info
26-
import androidx.compose.material.icons.filled.Warning
27-
import androidx.compose.material3.*
28-
import androidx.compose.runtime.Composable
29-
import androidx.compose.ui.ExperimentalComposeUiApi
23+
import androidx.compose.material3.Button
24+
import androidx.compose.material3.Text
3025
import androidx.compose.ui.Modifier
31-
import androidx.compose.ui.awt.ComposeDialog
32-
import androidx.compose.ui.graphics.RectangleShape
33-
import androidx.compose.ui.layout.onSizeChanged
34-
import androidx.compose.ui.platform.LocalDensity
35-
import androidx.compose.ui.text.font.FontWeight
3626
import androidx.compose.ui.unit.DpSize
3727
import androidx.compose.ui.unit.dp
3828
import androidx.compose.ui.window.Window
3929
import androidx.compose.ui.window.application
4030
import androidx.compose.ui.window.rememberWindowState
4131
import com.formdev.flatlaf.FlatLightLaf
32+
import androidx.compose.runtime.Composable
33+
import androidx.compose.ui.ExperimentalComposeUiApi
34+
import androidx.compose.ui.awt.ComposeDialog
35+
import androidx.compose.ui.layout.onSizeChanged
36+
import androidx.compose.ui.platform.LocalDensity
4237
import processing.app.ui.Toolkit
4338
import processing.app.ui.theme.PDETheme
39+
import java.awt.EventQueue
4440
import java.awt.Dimension
4541
import java.awt.Frame
4642
import java.io.PrintWriter
4743
import java.io.StringWriter
44+
import javax.swing.JFrame
4845
import javax.swing.JOptionPane
4946
import javax.swing.UIManager
5047

@@ -60,23 +57,10 @@ class Messages {
6057
if (Base.isCommandLine()) {
6158
println("$title: $message")
6259
} else {
63-
showDialog(title) { modifier, dismiss ->
64-
AlertDialog(
65-
modifier = modifier,
66-
onDismissRequest = { },
67-
shape = RectangleShape,
68-
icon = { Icon(Icons.Default.Info, contentDescription = "Info!") },
69-
title = { Text(title) },
70-
text = { Text(message) },
71-
confirmButton = {
72-
Button(
73-
onClick = { dismiss() }
74-
) {
75-
Text("OK")
76-
}
77-
}
78-
)
79-
}
60+
JOptionPane.showMessageDialog(
61+
Frame(), message, title,
62+
JOptionPane.INFORMATION_MESSAGE
63+
)
8064
}
8165
}
8266

@@ -93,27 +77,10 @@ class Messages {
9377
if (Base.isCommandLine()) {
9478
println("$title: $message")
9579
} else {
96-
showDialog(title) { modifier, dismiss ->
97-
AlertDialog(
98-
modifier = modifier,
99-
onDismissRequest = { },
100-
shape = RectangleShape,
101-
icon = { Icon(Icons.Default.Warning, contentDescription = "Alert!") },
102-
iconContentColor = MaterialTheme.colorScheme.tertiary,
103-
title = { Text(title) },
104-
text = { Text(message) },
105-
confirmButton = {
106-
Button(
107-
onClick = { dismiss() },
108-
colors = ButtonDefaults.outlinedButtonColors(
109-
contentColor = MaterialTheme.colorScheme.tertiary
110-
)
111-
) {
112-
Text("OK")
113-
}
114-
}
115-
)
116-
}
80+
JOptionPane.showMessageDialog(
81+
Frame(), message, title,
82+
JOptionPane.WARNING_MESSAGE
83+
)
11784
}
11885
e?.printStackTrace()
11986
}
@@ -133,30 +100,11 @@ class Messages {
133100
// proper parsing on the command line. Many have \n in them.
134101
println("$title: $primary\n$secondary")
135102
} else {
136-
showDialog(title) { modifier, dismiss ->
137-
AlertDialog(
138-
modifier = modifier,
139-
onDismissRequest = { },
140-
shape = RectangleShape,
141-
icon = { Icon(Icons.Default.Warning, contentDescription = "Alert!") },
142-
iconContentColor = MaterialTheme.colorScheme.tertiary,
143-
title = { Text(title) },
144-
text = {
145-
Column {
146-
Text(primary, fontWeight = FontWeight.Bold)
147-
Text(secondary)
148-
}
149-
},
150-
confirmButton = {
151-
Button(
152-
onClick = { dismiss() },
153-
colors = ButtonDefaults.outlinedButtonColors(
154-
contentColor = MaterialTheme.colorScheme.tertiary
155-
)
156-
) {
157-
Text("OK")
158-
}
159-
}
103+
EventQueue.invokeLater {
104+
JOptionPane.showMessageDialog(
105+
JFrame(),
106+
Toolkit.formatMessage(primary, secondary),
107+
title, JOptionPane.WARNING_MESSAGE
160108
)
161109
}
162110
}
@@ -174,28 +122,10 @@ class Messages {
174122
if (Base.isCommandLine()) {
175123
System.err.println("$title: $message")
176124
} else {
177-
showDialog(title) { modifier, dismiss ->
178-
AlertDialog(
179-
modifier = modifier,
180-
onDismissRequest = { },
181-
shape = RectangleShape,
182-
icon = { Icon(Icons.Default.Error, contentDescription = "Alert!") },
183-
iconContentColor = MaterialTheme.colorScheme.error,
184-
title = { Text(title) },
185-
text = { Text(message) },
186-
confirmButton = {
187-
Button(
188-
onClick = { dismiss() },
189-
colors = ButtonDefaults.buttonColors(
190-
containerColor = MaterialTheme.colorScheme.error,
191-
contentColor = MaterialTheme.colorScheme.onError
192-
)
193-
) {
194-
Text("OK")
195-
}
196-
}
197-
)
198-
}
125+
JOptionPane.showMessageDialog(
126+
Frame(), message, title,
127+
JOptionPane.ERROR_MESSAGE
128+
)
199129
}
200130
e?.printStackTrace()
201131
System.exit(1)
@@ -229,8 +159,6 @@ class Messages {
229159
if (fatal) JOptionPane.ERROR_MESSAGE else JOptionPane.WARNING_MESSAGE
230160
)
231161

232-
233-
234162
if (fatal) {
235163
System.exit(1)
236164
}

app/src/processing/app/Preferences.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ class ReactiveProperties : Properties() {
3232
return snapshotStateMap[key] ?: super.getProperty(key)
3333
}
3434

35-
override fun remove(key: Any?): Any? {
36-
snapshotStateMap.remove(key as String)
37-
return super.remove(key)
38-
}
39-
4035
operator fun get(key: String): String? = getProperty(key)
4136

4237
operator fun set(key: String, value: String) {

app/src/processing/app/ui/PDEWelcome.kt

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import androidx.compose.ui.Alignment
2323
import androidx.compose.ui.ExperimentalComposeUiApi
2424
import androidx.compose.ui.Modifier
2525
import androidx.compose.ui.draw.clip
26+
import androidx.compose.ui.draw.shadow
2627
import androidx.compose.ui.graphics.ImageBitmap
2728
import androidx.compose.ui.graphics.decodeToImageBitmap
2829
import androidx.compose.ui.graphics.painter.BitmapPainter
@@ -49,14 +50,13 @@ fun PDEWelcome(base: Base? = null) {
4950
modifier = Modifier
5051
.fillMaxSize()
5152
.background(MaterialTheme.colorScheme.surfaceContainerLowest),
52-
) {
53+
){
5354
val shape = RoundedCornerShape(12.dp)
5455
val xsPadding = PaddingValues(horizontal = 8.dp, vertical = 4.dp)
5556
val xsModifier = Modifier
5657
.defaultMinSize(minHeight = 1.dp)
5758
.height(32.dp)
58-
val textColor =
59-
if (isSystemInDarkTheme()) MaterialTheme.colorScheme.onSurface else MaterialTheme.colorScheme.onSecondaryContainer
59+
val textColor = if(isSystemInDarkTheme()) MaterialTheme.colorScheme.onSurface else MaterialTheme.colorScheme.onSecondaryContainer
6060
val locale = LocalLocale.current
6161

6262
/**
@@ -77,10 +77,10 @@ fun PDEWelcome(base: Base? = null) {
7777
/**
7878
* Title row
7979
*/
80-
Row(
80+
Row (
8181
horizontalArrangement = Arrangement.spacedBy(8.dp),
8282
modifier = Modifier.fillMaxWidth()
83-
) {
83+
){
8484
Image(
8585
painter = painterResource("logo.svg"),
8686
modifier = Modifier
@@ -99,7 +99,7 @@ fun PDEWelcome(base: Base? = null) {
9999
.fillMaxWidth()
100100
.align(Alignment.CenterVertically),
101101
horizontalArrangement = Arrangement.End,
102-
) {
102+
){
103103
val showLanguageMenu = remember { mutableStateOf(false) }
104104
OutlinedButton(
105105
onClick = {
@@ -108,7 +108,7 @@ fun PDEWelcome(base: Base? = null) {
108108
contentPadding = xsPadding,
109109
modifier = xsModifier,
110110
shape = shape
111-
) {
111+
){
112112
Icon(Icons.Default.Language, contentDescription = "", modifier = Modifier.size(20.dp))
113113
Spacer(Modifier.width(4.dp))
114114
Text(text = locale.locale.displayName)
@@ -123,7 +123,7 @@ fun PDEWelcome(base: Base? = null) {
123123
val colors = ButtonDefaults.textButtonColors(
124124
contentColor = textColor
125125
)
126-
Column {
126+
Column{
127127
ProvideTextStyle(MaterialTheme.typography.titleMedium) {
128128
val medModifier = Modifier
129129
.sizeIn(minHeight = 56.dp)
@@ -141,7 +141,7 @@ fun PDEWelcome(base: Base? = null) {
141141
}
142142
TextButton(
143143
onClick = {
144-
base?.let {
144+
base?.let{
145145
base.showSketchbookFrame()
146146
} ?: noBaseWarning()
147147
},
@@ -151,14 +151,11 @@ fun PDEWelcome(base: Base? = null) {
151151
) {
152152
Icon(Icons.Outlined.FolderOpen, contentDescription = "")
153153
Spacer(Modifier.width(12.dp))
154-
Text(
155-
locale["welcome.actions.sketchbook"],
156-
modifier = Modifier.align(Alignment.CenterVertically)
157-
)
154+
Text(locale["welcome.actions.sketchbook"], modifier = Modifier.align(Alignment.CenterVertically))
158155
}
159156
TextButton(
160157
onClick = {
161-
base?.let {
158+
base?.let{
162159
base.showExamplesFrame()
163160
} ?: noBaseWarning()
164161
},
@@ -183,7 +180,7 @@ fun PDEWelcome(base: Base? = null) {
183180
containerColor = MaterialTheme.colorScheme.surfaceVariant,
184181
contentColor = MaterialTheme.colorScheme.onSurfaceVariant
185182
)
186-
) {
183+
){
187184
Row(
188185
horizontalArrangement = Arrangement.spacedBy(48.dp),
189186
modifier = Modifier
@@ -344,7 +341,7 @@ fun PDEWelcome(base: Base? = null) {
344341
/**
345342
* Show on startup checkbox
346343
*/
347-
Row {
344+
Row{
348345
val preferences = LocalPreferences.current
349346
val showOnStartup = preferences["welcome.four.show"].toBoolean()
350347
fun toggle(next: Boolean? = null) {
@@ -425,7 +422,7 @@ fun PDEWelcome(base: Base? = null) {
425422
verticalArrangement = Arrangement.spacedBy(12.dp)
426423
) {
427424
items(examples) { example ->
428-
example.card {
425+
example.card{
429426
base?.let {
430427
base.handleOpen("${example.path}/${example.name}.pde")
431428
} ?: noBaseWarning()
@@ -565,7 +562,6 @@ fun noBaseWarning() {
565562

566563
val size = DpSize(970.dp, 600.dp)
567564
const val titleKey = "menu.help.welcome"
568-
569565
class WelcomeScreen
570566

571567
fun showWelcomeScreen(base: Base? = null) {
@@ -575,7 +571,7 @@ fun showWelcomeScreen(base: Base? = null) {
575571
unique = WelcomeScreen::class,
576572
fullWindowContent = true
577573
) {
578-
PDEWelcome(base)
574+
PDEWelcomeWithSurvey(base)
579575
}
580576
}
581577

@@ -601,16 +597,35 @@ fun languagesDropdown(showOptions: MutableState<Boolean>) {
601597
}
602598
}
603599

604-
fun main() {
600+
@Composable
601+
fun PDEWelcomeWithSurvey(base: Base? = null) {
602+
Box {
603+
PDEWelcome(base)
604+
Column(
605+
modifier = Modifier
606+
.align(Alignment.BottomEnd)
607+
.padding(16.dp)
608+
.padding(bottom = 12.dp)
609+
.shadow(
610+
elevation = 5.dp,
611+
shape = RoundedCornerShape(12.dp)
612+
)
613+
) {
614+
SurveyInvitation()
615+
}
616+
}
617+
}
618+
619+
fun main(){
605620
application {
606621
PDEComposeWindow(titleKey = titleKey, size = size, fullWindowContent = true) {
607622
PDETheme(darkTheme = true) {
608-
PDEWelcome()
623+
PDEWelcomeWithSurvey()
609624
}
610625
}
611626
PDEComposeWindow(titleKey = titleKey, size = size, fullWindowContent = true) {
612627
PDETheme(darkTheme = false) {
613-
PDEWelcome()
628+
PDEWelcomeWithSurvey()
614629
}
615630
}
616631
}

0 commit comments

Comments
 (0)