FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
processing/app/src/processing/app/Settings.java at master · processing/processing · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
processing
/
processing
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
1.5k
Star
6.5k
Code
Issues
0
Pull requests
0
Actions
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
processing
/
app
/
src
/
processing
/
app
/
Settings.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
233 lines (180 loc) · 6.25 KB
Breadcrumbs
processing
/
app
/
src
/
processing
/
app
/
Settings.java
Copy path
File metadata and controls
233 lines (180 loc) · 6.25 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
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
Part of the Processing project - http://processing.org
Copyright (c) 2004-11 Ben Fry and Casey Reas
Copyright (c) 2001-04 Massachusetts Institute of Technology
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
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
.*;
import
java
.
io
.*;
import
java
.
util
.*;
import
processing
.
app
.
ui
.
Toolkit
;
import
processing
.
core
.*;
/**
* Storage class for theme settings. This was separated from the Preferences
* class for 1.0 so that the coloring wouldn't conflict with previous releases
* and to make way for future ability to customize.
*/
public
class
Settings
{
/**
* Copy of the defaults in case the user mangles a preference.
* It's necessary to keep a copy of the defaults around, because the user may
* have replaced a setting on their own. In the past, we used to load the
* defaults, then replace those with what was in the user's preferences file.
* Problem is, if something like a font entry in the user's file no longer
* parses properly, we need to be able to get back to a clean version of that
* setting so we can recover.
*/
HashMap
<
String
,
String
>
defaults
;
/** Table of attributes/values. */
HashMap
<
String
,
String
>
table
=
new
HashMap
<
String
,
String
>();;
/** Associated file for this settings data. */
File
file
;
public
Settings
(
File
file
)
throws
IOException
{
this
.
file
=
file
;
if
(
file
.
exists
()) {
load
();
}
// clone the hash table
defaults
= (
HashMap
<
String
,
String
>)
table
.
clone
();
}
public
void
load
() {
load
(
file
);
}
public
void
load
(
File
additions
) {
String
[]
lines
=
PApplet
.
loadStrings
(
additions
);
for
(
String
line
:
lines
) {
if
((
line
.
length
() ==
0
) ||
(
line
.
charAt
(
0
) ==
'#'
))
continue
;
// this won't properly handle = signs being in the text
int
equals
=
line
.
indexOf
(
'='
);
if
(
equals
!= -
1
) {
String
key
=
line
.
substring
(
0
,
equals
).
trim
();
String
value
=
line
.
substring
(
equals
+
1
).
trim
();
table
.
put
(
key
,
value
);
}
}
// check for platform-specific properties in the defaults
String
platformExt
=
"."
+
Platform
.
getName
();
int
platformExtLength
=
platformExt
.
length
();
for
(
String
key
:
table
.
keySet
()) {
if
(
key
.
endsWith
(
platformExt
)) {
// this is a key specific to a particular platform
String
actualKey
=
key
.
substring
(
0
,
key
.
length
() -
platformExtLength
);
String
value
=
get
(
key
);
table
.
put
(
actualKey
,
value
);
}
}
}
public
void
save
() {
PrintWriter
writer
=
PApplet
.
createWriter
(
file
);
for
(
String
key
:
table
.
keySet
()) {
writer
.
println
(
key
+
"="
+
table
.
get
(
key
));
}
writer
.
flush
();
writer
.
close
();
}
public
String
get
(
String
attribute
) {
return
table
.
get
(
attribute
);
}
public
String
getDefault
(
String
attribute
) {
return
defaults
.
get
(
attribute
);
}
public
void
set
(
String
attribute
,
String
value
) {
table
.
put
(
attribute
,
value
);
}
public
boolean
getBoolean
(
String
attribute
) {
String
value
=
get
(
attribute
);
if
(
value
==
null
) {
System
.
err
.
println
(
"Boolean not found: "
+
attribute
);
return
false
;
}
return
Boolean
.
parseBoolean
(
value
);
}
public
void
setBoolean
(
String
attribute
,
boolean
value
) {
set
(
attribute
,
value
?
"true"
:
"false"
);
}
public
int
getInteger
(
String
attribute
) {
String
value
=
get
(
attribute
);
if
(
value
==
null
) {
System
.
err
.
println
(
"Integer not found: "
+
attribute
);
return
0
;
}
return
Integer
.
parseInt
(
value
);
}
public
void
setInteger
(
String
key
,
int
value
) {
set
(
key
,
String
.
valueOf
(
value
));
}
public
Color
getColor
(
String
attribute
) {
Color
parsed
=
null
;
String
s
=
get
(
attribute
);
if
((
s
!=
null
) && (
s
.
indexOf
(
"#"
) ==
0
)) {
try
{
int
v
=
Integer
.
parseInt
(
s
.
substring
(
1
),
16
);
parsed
=
new
Color
(
v
);
}
catch
(
Exception
e
) {
}
}
return
parsed
;
}
public
void
setColor
(
String
attr
,
Color
what
) {
set
(
attr
,
"#"
+
PApplet
.
hex
(
what
.
getRGB
() &
0xffffff
,
6
));
}
// identical version found in Preferences.java
public
Font
getFont
(
String
attr
) {
try
{
boolean
replace
=
false
;
String
value
=
get
(
attr
);
if
(
value
==
null
) {
// use the default font instead
value
=
getDefault
(
attr
);
replace
=
true
;
}
String
[]
pieces
=
PApplet
.
split
(
value
,
','
);
if
(
pieces
.
length
!=
3
) {
value
=
getDefault
(
attr
);
pieces
=
PApplet
.
split
(
value
,
','
);
replace
=
true
;
}
String
name
=
pieces
[
0
];
int
style
=
Font
.
PLAIN
;
// equals zero
if
(
pieces
[
1
].
indexOf
(
"bold"
) != -
1
) {
//$NON-NLS-1$
style
|=
Font
.
BOLD
;
}
if
(
pieces
[
1
].
indexOf
(
"italic"
) != -
1
) {
//$NON-NLS-1$
style
|=
Font
.
ITALIC
;
}
int
size
=
PApplet
.
parseInt
(
pieces
[
2
],
12
);
size
=
Toolkit
.
zoom
(
size
);
// replace bad font with the default from lib/preferences.txt
if
(
replace
) {
set
(
attr
,
value
);
}
if
(!
name
.
startsWith
(
"processing."
)) {
return
new
Font
(
name
,
style
,
size
);
}
else
{
if
(
pieces
[
0
].
equals
(
"processing.sans"
)) {
return
Toolkit
.
getSansFont
(
size
,
style
);
}
else
if
(
pieces
[
0
].
equals
(
"processing.mono"
)) {
return
Toolkit
.
getMonoFont
(
size
,
style
);
}
}
}
catch
(
Exception
e
) {
// Adding try/catch block because this may be where
// a lot of startup crashes are happening.
Messages
.
log
(
"Error with font "
+
get
(
attr
) +
" for attribute "
+
attr
);
}
return
new
Font
(
"Dialog"
,
Font
.
PLAIN
,
12
);
}
}
Back
|
FazBrowse Home
|
New Git URL