Skip to content

Commit 004a138

Browse files
committed
moving extra configuration to app.preferences
1 parent 25b6a44 commit 004a138

File tree

2 files changed

+80
-73
lines changed

2 files changed

+80
-73
lines changed

app/src/processing/app/Preferences.java

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package processing.app;
22

33
import processing.app.ui.Toolkit;
4+
import processing.core.PApplet;
45

56
import java.awt.*;
67

@@ -13,6 +14,34 @@ static public void init() {
1314
if (Language.useInputMethod() && !getBoolean("editor.input_method_support")) {
1415
setBoolean("editor.input_method_support", true);
1516
}
17+
18+
if(get("run.window.bgcolor").isEmpty()){
19+
setColor("run.window.bgcolor", SystemColor.control);
20+
}
21+
22+
if(checkSketchbookPref()){
23+
save();
24+
}
25+
26+
PApplet.useNativeSelect =
27+
Preferences.getBoolean("chooser.files.native"); //$NON-NLS-1$
28+
29+
// Adding option to disable this in case it's getting in the way
30+
if (get("proxy.system").equals("true")) {
31+
// Use the system proxy settings by default
32+
// https://github.com/processing/processing/issues/2643
33+
System.setProperty("java.net.useSystemProxies", "true");
34+
}
35+
36+
// Set HTTP, HTTPS, and SOCKS proxies for individuals
37+
// who want/need to override the system setting
38+
// http://docs.oracle.com/javase/6/docs/technotes/guides/net/proxies.html
39+
// Less readable version with the Oracle style sheet:
40+
// http://docs.oracle.com/javase/8/docs/technotes/guides/net/proxies.html
41+
handleProxy("http", "http.proxyHost", "http.proxyPort");
42+
handleProxy("https", "https.proxyHost", "https.proxyPort");
43+
handleProxy("socks", "socksProxyHost", "socksProxyPort");
44+
1645
}
1746

1847

@@ -26,4 +55,54 @@ static public Font getFont(String familyAttr, String sizeAttr, int style) {
2655
}
2756
return new Font(fontFamily, style, fontSize);
2857
}
58+
59+
60+
static void handleProxy(String protocol, String hostProp, String portProp) {
61+
String proxyHost = get("proxy." + protocol + ".host");
62+
String proxyPort = get("proxy." + protocol + ".port");
63+
if (proxyHost != null && proxyHost.length() != 0 &&
64+
proxyPort != null && proxyPort.length() != 0) {
65+
System.setProperty(hostProp, proxyHost);
66+
System.setProperty(portProp, proxyPort);
67+
}
68+
69+
}
70+
71+
72+
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
73+
74+
75+
/**
76+
* Check for a 4.0 sketchbook location, and if none exists,
77+
* try to grab it from the 3.0 sketchbook location.
78+
* @return true if a location was found and the pref didn't exist
79+
*/
80+
static protected boolean checkSketchbookPref() {
81+
// If a 4.0 sketchbook location has never been inited
82+
if (getSketchbookPath() == null) {
83+
String threePath = get("sketchbook.path.three"); //$NON-NLS-1$
84+
// If they've run the 3.0 version, start with that location
85+
if (threePath != null) {
86+
setSketchbookPath(threePath);
87+
return true; // save the sketchbook right away
88+
}
89+
// Otherwise it'll be null, and reset properly by Base
90+
}
91+
return false;
92+
}
93+
94+
95+
static public String getOldSketchbookPath() {
96+
return get("sketchbook.path.three"); //$NON-NLS-1$
97+
}
98+
99+
100+
static public String getSketchbookPath() {
101+
return get("sketchbook.path.four"); //$NON-NLS-1$
102+
}
103+
104+
105+
public static void setSketchbookPath(String path) {
106+
set("sketchbook.path.four", path); //$NON-NLS-1$
107+
}
29108
}

app/utils/src/main/java/processing/utils/Preferences.java

Lines changed: 1 addition & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,6 @@ static public void init() {
7575
// This ensures that any new/added preference will be present.
7676
defaults = new HashMap<>(table);
7777

78-
// other things that have to be set explicitly for the defaults
79-
setColor("run.window.bgcolor", SystemColor.control); //$NON-NLS-1$
80-
8178
// next load user preferences file
8279
preferencesFile = Base.getSettingsFile(PREFS_FILE);
8380
boolean firstRun = !preferencesFile.exists();
@@ -94,31 +91,12 @@ static public void init() {
9491
}
9592
}
9693

97-
if (checkSketchbookPref() || firstRun) {
98-
// if (firstRun) {
94+
if (firstRun) {
9995
// create a new preferences file if none exists
10096
// saves the defaults out to the file
10197
save();
10298
}
10399

104-
PApplet.useNativeSelect =
105-
Preferences.getBoolean("chooser.files.native"); //$NON-NLS-1$
106-
107-
// Adding option to disable this in case it's getting in the way
108-
if (get("proxy.system").equals("true")) {
109-
// Use the system proxy settings by default
110-
// https://github.com/processing/processing/issues/2643
111-
System.setProperty("java.net.useSystemProxies", "true");
112-
}
113-
114-
// Set HTTP, HTTPS, and SOCKS proxies for individuals
115-
// who want/need to override the system setting
116-
// http://docs.oracle.com/javase/6/docs/technotes/guides/net/proxies.html
117-
// Less readable version with the Oracle style sheet:
118-
// http://docs.oracle.com/javase/8/docs/technotes/guides/net/proxies.html
119-
handleProxy("http", "http.proxyHost", "http.proxyPort");
120-
handleProxy("https", "https.proxyHost", "https.proxyPort");
121-
handleProxy("socks", "socksProxyHost", "socksProxyPort");
122100
}
123101

124102

@@ -130,18 +108,6 @@ static public void skipInit() {
130108
}
131109

132110

133-
static void handleProxy(String protocol, String hostProp, String portProp) {
134-
String proxyHost = get("proxy." + protocol + ".host");
135-
String proxyPort = get("proxy." + protocol + ".port");
136-
if (proxyHost != null && proxyHost.length() != 0 &&
137-
proxyPort != null && proxyPort.length() != 0) {
138-
System.setProperty(hostProp, proxyHost);
139-
System.setProperty(portProp, proxyPort);
140-
}
141-
142-
}
143-
144-
145111
static public String getPreferencesPath() {
146112
return preferencesFile.getAbsolutePath();
147113
}
@@ -339,42 +305,4 @@ static public void setColor(String attr, Color what) {
339305
set(attr, "#" + PApplet.hex(what.getRGB() & 0xffffff, 6)); //$NON-NLS-1$
340306
}
341307

342-
343-
344-
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
345-
346-
347-
/**
348-
* Check for a 4.0 sketchbook location, and if none exists,
349-
* try to grab it from the 3.0 sketchbook location.
350-
* @return true if a location was found and the pref didn't exist
351-
*/
352-
static protected boolean checkSketchbookPref() {
353-
// If a 4.0 sketchbook location has never been inited
354-
if (getSketchbookPath() == null) {
355-
String threePath = get("sketchbook.path.three"); //$NON-NLS-1$
356-
// If they've run the 3.0 version, start with that location
357-
if (threePath != null) {
358-
setSketchbookPath(threePath);
359-
return true; // save the sketchbook right away
360-
}
361-
// Otherwise it'll be null, and reset properly by Base
362-
}
363-
return false;
364-
}
365-
366-
367-
static public String getOldSketchbookPath() {
368-
return get("sketchbook.path.three"); //$NON-NLS-1$
369-
}
370-
371-
372-
static public String getSketchbookPath() {
373-
return get("sketchbook.path.four"); //$NON-NLS-1$
374-
}
375-
376-
377-
public static void setSketchbookPath(String path) {
378-
set("sketchbook.path.four", path); //$NON-NLS-1$
379-
}
380308
}

0 commit comments

Comments
 (0)