FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
processing/app/src/processing/app/Messages.java at master · dimr/processing · GitHub
dimr
processing
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
processing
/
app
/
src
/
processing
/
app
/
Messages.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
343 lines (279 loc) · 10.9 KB
Breadcrumbs
processing
/
app
/
src
/
processing
/
app
/
Messages.java
Copy path
File metadata and controls
343 lines (279 loc) · 10.9 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
Part of the Processing project - http://processing.org
Copyright (c) 2015 The Processing Foundation
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2, as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package
processing
.
app
;
import
java
.
awt
.
Frame
;
import
java
.
io
.
PrintWriter
;
import
java
.
io
.
StringWriter
;
import
javax
.
swing
.
JDialog
;
import
javax
.
swing
.
JFrame
;
import
javax
.
swing
.
JOptionPane
;
import
processing
.
app
.
ui
.
Editor
;
public
class
Messages
{
/**
* "No cookie for you" type messages. Nothing fatal or all that
* much of a bummer, but something to notify the user about.
*/
static
public
void
showMessage
(
String
title
,
String
message
) {
if
(
title
==
null
)
title
=
"Message"
;
if
(
Base
.
isCommandLine
()) {
System
.
out
.
println
(
title
+
": "
+
message
);
}
else
{
JOptionPane
.
showMessageDialog
(
new
Frame
(),
message
,
title
,
JOptionPane
.
INFORMATION_MESSAGE
);
}
}
/**
* Non-fatal error message.
*/
static
public
void
showWarning
(
String
title
,
String
message
) {
showWarning
(
title
,
message
,
null
);
}
/**
* Non-fatal error message with optional stack trace side dish.
*/
static
public
void
showWarning
(
String
title
,
String
message
,
Throwable
e
) {
if
(
title
==
null
)
title
=
"Warning"
;
if
(
Base
.
isCommandLine
()) {
System
.
out
.
println
(
title
+
": "
+
message
);
}
else
{
JOptionPane
.
showMessageDialog
(
new
Frame
(),
message
,
title
,
JOptionPane
.
WARNING_MESSAGE
);
}
if
(
e
!=
null
)
e
.
printStackTrace
();
}
/**
* Non-fatal error message with optional stack trace side dish.
*/
static
public
void
showWarningTiered
(
String
title
,
String
primary
,
String
secondary
,
Throwable
e
) {
if
(
title
==
null
)
title
=
"Warning"
;
final
String
message
=
primary
+
"
\n
"
+
secondary
;
if
(
Base
.
isCommandLine
()) {
System
.
out
.
println
(
title
+
": "
+
message
);
}
else
{
// JOptionPane.showMessageDialog(new Frame(), message,
// title, JOptionPane.WARNING_MESSAGE);
if
(!
Platform
.
isMacOS
()) {
JOptionPane
.
showMessageDialog
(
new
JFrame
(),
"<html><body>"
+
"<b>"
+
primary
+
"</b>"
+
"<br>"
+
secondary
,
title
,
JOptionPane
.
WARNING_MESSAGE
);
}
else
{
// Pane formatting adapted from the Quaqua guide
// http://www.randelshofer.ch/quaqua/guide/joptionpane.html
JOptionPane
pane
=
new
JOptionPane
(
"<html> "
+
"<head> <style type=
\"
text/css
\"
>"
+
"b { font: 13pt
\"
Lucida Grande
\"
}"
+
"p { font: 11pt
\"
Lucida Grande
\"
; margin-top: 8px; width: 300px }"
+
"</style> </head>"
+
"<b>"
+
primary
+
"</b>"
+
"<p>"
+
secondary
+
"</p>"
,
JOptionPane
.
WARNING_MESSAGE
);
// String[] options = new String[] {
// "Yes", "No"
// };
// pane.setOptions(options);
// highlight the safest option ala apple hig
// pane.setInitialValue(options[0]);
JDialog
dialog
=
pane
.
createDialog
(
new
JFrame
(),
null
);
dialog
.
setVisible
(
true
);
// Object result = pane.getValue();
// if (result == options[0]) {
// return JOptionPane.YES_OPTION;
// } else if (result == options[1]) {
// return JOptionPane.NO_OPTION;
// } else {
// return JOptionPane.CLOSED_OPTION;
// }
}
}
if
(
e
!=
null
)
e
.
printStackTrace
();
}
/**
* 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.
*/
static
public
void
showError
(
String
title
,
String
message
,
Throwable
e
) {
if
(
title
==
null
)
title
=
"Error"
;
if
(
Base
.
isCommandLine
()) {
System
.
err
.
println
(
title
+
": "
+
message
);
}
else
{
JOptionPane
.
showMessageDialog
(
new
Frame
(),
message
,
title
,
JOptionPane
.
ERROR_MESSAGE
);
}
if
(
e
!=
null
)
e
.
printStackTrace
();
System
.
exit
(
1
);
}
/**
* Testing a new warning window that includes the stack trace.
*/
static
public
void
showTrace
(
String
title
,
String
message
,
Throwable
t
,
boolean
fatal
) {
if
(
title
==
null
)
title
=
fatal
?
"Error"
:
"Warning"
;
if
(
Base
.
isCommandLine
()) {
System
.
err
.
println
(
title
+
": "
+
message
);
if
(
t
!=
null
) {
t
.
printStackTrace
();
}
}
else
{
StringWriter
sw
=
new
StringWriter
();
t
.
printStackTrace
(
new
PrintWriter
(
sw
));
// Necessary to replace \n with <br/> (even if pre) otherwise Java
// treats it as a closed tag and reverts to plain formatting.
message
= (
"<html>"
+
message
+
"<br/><font size=2><br/>"
+
sw
+
"</html>"
).
replaceAll
(
"
\n
"
,
"<br/>"
);
JOptionPane
.
showMessageDialog
(
new
Frame
(),
message
,
title
,
fatal
?
JOptionPane
.
ERROR_MESSAGE
:
JOptionPane
.
WARNING_MESSAGE
);
if
(
fatal
) {
System
.
exit
(
1
);
}
}
}
// ...................................................................
// incomplete
static
public
int
showYesNoCancelQuestion
(
Editor
editor
,
String
title
,
String
primary
,
String
secondary
) {
if
(!
Platform
.
isMacOS
()) {
int
result
=
JOptionPane
.
showConfirmDialog
(
null
,
primary
+
"
\n
"
+
secondary
,
title
,
JOptionPane
.
YES_NO_CANCEL_OPTION
,
JOptionPane
.
QUESTION_MESSAGE
);
return
result
;
// if (result == JOptionPane.YES_OPTION) {
//
// } else if (result == JOptionPane.NO_OPTION) {
// return true; // ok to continue
//
// } else if (result == JOptionPane.CANCEL_OPTION) {
// return false;
//
// } else {
// throw new IllegalStateException();
// }
}
else
{
// Pane formatting adapted from the Quaqua guide
// http://www.randelshofer.ch/quaqua/guide/joptionpane.html
JOptionPane
pane
=
new
JOptionPane
(
"<html> "
+
"<head> <style type=
\"
text/css
\"
>"
+
"b { font: 13pt
\"
Lucida Grande
\"
}"
+
"p { font: 11pt
\"
Lucida Grande
\"
; margin-top: 8px; width: 300px }"
+
"</style> </head>"
+
"<b>"
+
Language
.
text
(
"save.title"
) +
"</b>"
+
"<p>"
+
Language
.
text
(
"save.hint"
) +
"</p>"
,
JOptionPane
.
QUESTION_MESSAGE
);
String
[]
options
=
new
String
[] {
Language
.
text
(
"save.btn.save"
),
Language
.
text
(
"prompt.cancel"
),
Language
.
text
(
"save.btn.dont_save"
)
};
pane
.
setOptions
(
options
);
// highlight the safest option ala apple hig
pane
.
setInitialValue
(
options
[
0
]);
// on macosx, setting the destructive property places this option
// away from the others at the lefthand side
pane
.
putClientProperty
(
"Quaqua.OptionPane.destructiveOption"
,
Integer
.
valueOf
(
2
));
JDialog
dialog
=
pane
.
createDialog
(
editor
,
null
);
dialog
.
setVisible
(
true
);
Object
result
=
pane
.
getValue
();
if
(
result
==
options
[
0
]) {
return
JOptionPane
.
YES_OPTION
;
}
else
if
(
result
==
options
[
1
]) {
return
JOptionPane
.
CANCEL_OPTION
;
}
else
if
(
result
==
options
[
2
]) {
return
JOptionPane
.
NO_OPTION
;
}
else
{
return
JOptionPane
.
CLOSED_OPTION
;
}
}
}
static
public
int
showYesNoQuestion
(
Frame
editor
,
String
title
,
String
primary
,
String
secondary
) {
if
(!
Platform
.
isMacOS
()) {
return
JOptionPane
.
showConfirmDialog
(
editor
,
"<html><body>"
+
"<b>"
+
primary
+
"</b>"
+
"<br>"
+
secondary
,
title
,
JOptionPane
.
YES_NO_OPTION
,
JOptionPane
.
QUESTION_MESSAGE
);
}
else
{
// Pane formatting adapted from the Quaqua guide
// http://www.randelshofer.ch/quaqua/guide/joptionpane.html
JOptionPane
pane
=
new
JOptionPane
(
"<html> "
+
"<head> <style type=
\"
text/css
\"
>"
+
"b { font: 13pt
\"
Lucida Grande
\"
}"
+
"p { font: 11pt
\"
Lucida Grande
\"
; margin-top: 8px; width: 300px }"
+
"</style> </head>"
+
"<b>"
+
primary
+
"</b>"
+
"<p>"
+
secondary
+
"</p>"
,
JOptionPane
.
QUESTION_MESSAGE
);
String
[]
options
=
new
String
[] {
"Yes"
,
"No"
};
pane
.
setOptions
(
options
);
// highlight the safest option ala apple hig
pane
.
setInitialValue
(
options
[
0
]);
JDialog
dialog
=
pane
.
createDialog
(
editor
,
null
);
dialog
.
setVisible
(
true
);
Object
result
=
pane
.
getValue
();
if
(
result
==
options
[
0
]) {
return
JOptionPane
.
YES_OPTION
;
}
else
if
(
result
==
options
[
1
]) {
return
JOptionPane
.
NO_OPTION
;
}
else
{
return
JOptionPane
.
CLOSED_OPTION
;
}
}
}
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
static
public
void
log
(
Object
from
,
String
message
) {
if
(
Base
.
DEBUG
) {
System
.
out
.
println
(
from
.
getClass
().
getName
() +
": "
+
message
);
}
}
static
public
void
log
(
String
message
) {
if
(
Base
.
DEBUG
) {
System
.
out
.
println
(
message
);
}
}
static
public
void
logf
(
String
message
,
Object
...
args
) {
if
(
Base
.
DEBUG
) {
System
.
out
.
println
(
String
.
format
(
message
,
args
));
}
}
static
public
void
loge
(
String
message
,
Throwable
e
) {
if
(
Base
.
DEBUG
) {
if
(
message
!=
null
) {
System
.
err
.
println
(
message
);
}
e
.
printStackTrace
();
}
}
static
public
void
loge
(
String
message
) {
if
(
Base
.
DEBUG
) {
System
.
err
.
println
(
message
);
}
}
}
Back
|
FazBrowse Home
|
New Git URL