Skip to content

Commit b87cf16

Browse files
committed
major theme updates, moving theme out of Mode, pieces in place for dynamic updates
1 parent 83da053 commit b87cf16

31 files changed

Lines changed: 448 additions & 250 deletions

app/src/processing/app/Base.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ static private void createAndShowGUI(String[] args) {
185185
// run static initialization that grabs all the prefs
186186
Preferences.init();
187187

188+
// get colors for ui elements (after prefs, since depends on font choices)
189+
Theme.init();
190+
188191
if (!SingleInstance.alreadyRunning(args)) {
189192
// Set the look and feel before opening the window
190193
try {

app/src/processing/app/Mode.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,12 @@ public ClassLoader getClassLoader() {
190190
}
191191

192192

193-
/**
194-
* Setup additional elements that are only required when running with a GUI,
195-
* rather than from the command-line. Note that this will not be called when
196-
* the Mode is used from the command line (because Base will be null).
197-
*/
193+
// /**
194+
// * Setup additional elements that are only required when running with a GUI,
195+
// * rather than from the command-line. Note that this will not be called when
196+
// * the Mode is used from the command line (because Base will be null).
197+
// */
198+
/*
198199
public void setupGUI() {
199200
try {
200201
// First load the default theme data for the whole PDE.
@@ -226,6 +227,7 @@ public void setupGUI() {
226227
"Could not load theme.txt, please re-install Processing", e);
227228
}
228229
}
230+
*/
229231

230232

231233
public File getContentFile(String path) {
@@ -795,12 +797,14 @@ protected TokenMarker createTokenMarker() {
795797

796798
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
797799

800+
/*
798801
// Get attributes/values from the theme.txt file. To discourage burying this
799802
// kind of information in code where it doesn't belong (and is difficult to
800803
// track down), these don't have a "default" option as a second parameter.
801804
802805
803-
/** @since 3.0a6 */
806+
// removing, this doesn't seem to have been in use
807+
/// @since 3.0a6
804808
public String getString(String attribute) {
805809
return theme.get(attribute);
806810
}
@@ -878,6 +882,7 @@ public Image makeGradient(String attribute, int wide, int high) {
878882
// }
879883
return outgoing;
880884
}
885+
*/
881886

882887

883888
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

app/src/processing/app/Settings.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,12 @@ public void load(File additions) {
106106

107107

108108
public void save() {
109-
PrintWriter writer = PApplet.createWriter(file);
109+
save(file); // save back to the original file
110+
}
111+
112+
113+
public void save(File outputFile) {
114+
PrintWriter writer = PApplet.createWriter(outputFile);
110115

111116
for (String key : table.keySet()) {
112117
writer.println(key + "=" + table.get(key));

app/src/processing/app/contrib/ContributionManager.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,6 @@ static boolean download(URL source, byte[] post,
141141

142142
/**
143143
* Non-blocking call to download and install a contribution in a new thread.
144-
*
145-
* @param url
146-
* Direct link to the contribution.
147-
* @param toBeReplaced
148-
* The Contribution that will be replaced by this library being
149-
* installed (e.g. an advertised version of a contribution, or the
150-
* old version of a contribution that is being updated). Must not be
151-
* null.
152144
*/
153145
static void downloadAndInstall(final Base base,
154146
final URL url,

app/src/processing/app/contrib/ManagerFrame.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import processing.app.*;
3030
import processing.app.ui.Editor;
31+
import processing.app.ui.Theme;
3132
import processing.app.ui.Toolkit;
3233

3334

@@ -109,9 +110,11 @@ private void makeFrame() {
109110

110111
frame.setResizable(true);
111112

112-
Container c = frame.getContentPane();
113-
c.add(tabs);
114-
c.setBackground(base.getDefaultMode().getColor("manager.tab.background"));
113+
// Container c = frame.getContentPane();
114+
// c.add(tabs);
115+
// c.setBackground(Theme.getColor("manager.tab.background"));
116+
frame.getContentPane().add(tabs);
117+
updateTheme();
115118

116119
frame.validate();
117120
frame.repaint();
@@ -124,6 +127,11 @@ private void makeFrame() {
124127
}
125128

126129

130+
protected void updateTheme() {
131+
frame.getContentPane().setBackground(Theme.getColor("manager.tab.background"));
132+
}
133+
134+
127135
/**
128136
* Close the window after an OK or Cancel.
129137
*/
@@ -142,20 +150,16 @@ public void windowClosing(WindowEvent e) {
142150
}
143151
});
144152
// handle window closing commands for ctrl/cmd-W or hitting ESC.
145-
Toolkit.registerWindowCloseKeys(frame.getRootPane(), new ActionListener() {
146-
public void actionPerformed(ActionEvent actionEvent) {
147-
disposeFrame();
148-
}
149-
});
153+
Toolkit.registerWindowCloseKeys(frame.getRootPane(), actionEvent -> disposeFrame());
150154

151155
frame.getContentPane().addKeyListener(new KeyAdapter() {
152156
public void keyPressed(KeyEvent e) {
153-
//System.out.println(e);
154-
KeyStroke wc = Toolkit.WINDOW_CLOSE_KEYSTROKE;
155-
if ((e.getKeyCode() == KeyEvent.VK_ESCAPE)
156-
|| (KeyStroke.getKeyStrokeForEvent(e).equals(wc))) {
157-
disposeFrame();
158-
}
157+
//System.out.println(e);
158+
KeyStroke wc = Toolkit.WINDOW_CLOSE_KEYSTROKE;
159+
if ((e.getKeyCode() == KeyEvent.VK_ESCAPE)
160+
|| (KeyStroke.getKeyStrokeForEvent(e).equals(wc))) {
161+
disposeFrame();
162+
}
159163
}
160164
});
161165
}

app/src/processing/app/contrib/ManagerTabs.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040

4141
import processing.app.Base;
4242
import processing.app.Mode;
43+
import processing.app.ui.Theme;
4344
import processing.app.ui.Toolkit;
4445

4546

@@ -100,14 +101,14 @@ public ManagerTabs(Base base) {
100101
// But use the default (Java) mode settings just in case.
101102
mode = base.getDefaultMode();
102103

103-
textColor[SELECTED] = mode.getColor("manager.tab.text.selected.color");
104-
textColor[UNSELECTED] = mode.getColor("manager.tab.text.unselected.color");
105-
font = mode.getFont("manager.tab.text.font");
104+
textColor[SELECTED] = Theme.getColor("manager.tab.text.selected.color");
105+
textColor[UNSELECTED] = Theme.getColor("manager.tab.text.unselected.color");
106+
font = Theme.getFont("manager.tab.text.font");
106107

107-
tabColor[SELECTED] = mode.getColor("manager.tab.selected.color");
108-
tabColor[UNSELECTED] = mode.getColor("manager.tab.unselected.color");
108+
tabColor[SELECTED] = Theme.getColor("manager.tab.selected.color");
109+
tabColor[UNSELECTED] = Theme.getColor("manager.tab.unselected.color");
109110

110-
gradient = mode.makeGradient("manager.tab", Toolkit.zoom(400), HIGH);
111+
gradient = Theme.makeGradient("manager.tab", Toolkit.zoom(400), HIGH);
111112

112113
setBorder(new EmptyBorder(BORDER, BORDER, BORDER, BORDER));
113114

app/src/processing/app/contrib/ModeContribution.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ static public ModeContribution load(Base base, File folder,
8080
* @param className name of class and full package, or null to use default
8181
*/
8282
public ModeContribution(Base base, File folder,
83-
String className) throws Exception {
83+
String className) throws Exception {
8484
super(folder);
8585
className = initLoader(base, className);
8686
if (className != null) {
@@ -89,9 +89,9 @@ public ModeContribution(Base base, File folder,
8989
Constructor<?> con = modeClass.getConstructor(Base.class, File.class);
9090
mode = (Mode) con.newInstance(base, folder);
9191
mode.setClassLoader(loader);
92-
if (base != null) {
93-
mode.setupGUI();
94-
}
92+
// if (base != null) {
93+
// mode.setupGUI();
94+
// }
9595
}
9696
}
9797

app/src/processing/app/syntax/JEditTextArea.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,11 @@ public JEditTextArea(TextAreaDefaults defaults, InputHandler inputHandler) {
183183
}
184184

185185

186-
public void updateAppearance() {
186+
public void updateTheme() {
187187
// This default version will update the fonts and not much else.
188188
// It's expected to always be overridden by the PdeTextArea version,
189189
// but it's here if a Mode author *really* must avoid PdeTextArea.
190-
painter.updateAppearance();
190+
painter.updateTheme();
191191
repaint();
192192
}
193193

app/src/processing/app/syntax/PdeTextArea.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
import processing.app.Mode;
3131
import processing.app.ui.Editor;
32+
import processing.app.ui.Theme;
3233

3334

3435
/**
@@ -62,7 +63,7 @@ public PdeTextArea(TextAreaDefaults defaults, InputHandler inputHandler,
6263

6364
// load settings from theme.txt
6465
Mode mode = editor.getMode();
65-
gutterGradient = mode.makeGradient("editor", Editor.LEFT_GUTTER, 500);
66+
gutterGradient = Theme.makeGradient("editor", Editor.LEFT_GUTTER, 500);
6667
}
6768

6869

@@ -84,8 +85,8 @@ public void setMode(Mode mode) {
8485
*/
8586

8687
@Override
87-
public void updateAppearance() {
88-
((PdeTextAreaPainter) painter).updateAppearance(editor.getMode());
88+
public void updateTheme() {
89+
((PdeTextAreaPainter) painter).updateTheme();
8990
repaint();
9091
}
9192

app/src/processing/app/syntax/PdeTextAreaDefaults.java

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
package processing.app.syntax;
2727

2828
import processing.app.*;
29+
import processing.app.ui.Theme;
2930

3031

3132
/**
@@ -50,45 +51,45 @@ public PdeTextAreaDefaults(Mode mode) {
5051
rows = 5;
5152

5253
styles = new SyntaxStyle[Token.ID_COUNT];
53-
updateAppearance(mode);
54+
updateTheme();
5455
}
5556

5657

57-
protected void updateAppearance(Mode mode) {
58-
fgcolor = mode.getColor("editor.fgcolor");
59-
bgcolor = mode.getColor("editor.bgcolor");
58+
protected void updateTheme() {
59+
fgcolor = Theme.getColor("editor.fgcolor");
60+
bgcolor = Theme.getColor("editor.bgcolor");
6061

61-
styles[Token.COMMENT1] = mode.getStyle("comment1");
62-
styles[Token.COMMENT2] = mode.getStyle("comment2");
62+
styles[Token.COMMENT1] = Theme.getStyle("comment1");
63+
styles[Token.COMMENT2] = Theme.getStyle("comment2");
6364

64-
styles[Token.KEYWORD1] = mode.getStyle("keyword1");
65-
styles[Token.KEYWORD2] = mode.getStyle("keyword2");
66-
styles[Token.KEYWORD3] = mode.getStyle("keyword3");
67-
styles[Token.KEYWORD4] = mode.getStyle("keyword4");
68-
styles[Token.KEYWORD5] = mode.getStyle("keyword5");
69-
styles[Token.KEYWORD6] = mode.getStyle("keyword6");
65+
styles[Token.KEYWORD1] = Theme.getStyle("keyword1");
66+
styles[Token.KEYWORD2] = Theme.getStyle("keyword2");
67+
styles[Token.KEYWORD3] = Theme.getStyle("keyword3");
68+
styles[Token.KEYWORD4] = Theme.getStyle("keyword4");
69+
styles[Token.KEYWORD5] = Theme.getStyle("keyword5");
70+
styles[Token.KEYWORD6] = Theme.getStyle("keyword6");
7071

71-
styles[Token.FUNCTION1] = mode.getStyle("function1");
72-
styles[Token.FUNCTION2] = mode.getStyle("function2");
73-
styles[Token.FUNCTION3] = mode.getStyle("function3");
74-
styles[Token.FUNCTION4] = mode.getStyle("function4");
72+
styles[Token.FUNCTION1] = Theme.getStyle("function1");
73+
styles[Token.FUNCTION2] = Theme.getStyle("function2");
74+
styles[Token.FUNCTION3] = Theme.getStyle("function3");
75+
styles[Token.FUNCTION4] = Theme.getStyle("function4");
7576

76-
styles[Token.LITERAL1] = mode.getStyle("literal1");
77-
styles[Token.LITERAL2] = mode.getStyle("literal2");
77+
styles[Token.LITERAL1] = Theme.getStyle("literal1");
78+
styles[Token.LITERAL2] = Theme.getStyle("literal2");
7879

79-
styles[Token.LABEL] = mode.getStyle("label");
80-
styles[Token.OPERATOR] = mode.getStyle("operator");
80+
styles[Token.LABEL] = Theme.getStyle("label");
81+
styles[Token.OPERATOR] = Theme.getStyle("operator");
8182

8283
// area that's not in use by the text (replaced with tildes)
83-
styles[Token.INVALID] = mode.getStyle("invalid");
84-
85-
caretColor = mode.getColor("editor.caret.color");
86-
selectionColor = mode.getColor("editor.selection.color");
87-
lineHighlight = mode.getBoolean("editor.linehighlight");
88-
lineHighlightColor = mode.getColor("editor.linehighlight.color");
89-
bracketHighlight = mode.getBoolean("editor.brackethighlight");
90-
bracketHighlightColor = mode.getColor("editor.brackethighlight.color");
91-
eolMarkers = mode.getBoolean("editor.eolmarkers");
92-
eolMarkerColor = mode.getColor("editor.eolmarkers.color");
84+
styles[Token.INVALID] = Theme.getStyle("invalid");
85+
86+
caretColor = Theme.getColor("editor.caret.color");
87+
selectionColor = Theme.getColor("editor.selection.color");
88+
lineHighlight = Theme.getBoolean("editor.linehighlight");
89+
lineHighlightColor = Theme.getColor("editor.linehighlight.color");
90+
bracketHighlight = Theme.getBoolean("editor.brackethighlight");
91+
bracketHighlightColor = Theme.getColor("editor.brackethighlight.color");
92+
eolMarkers = Theme.getBoolean("editor.eolmarkers");
93+
eolMarkerColor = Theme.getColor("editor.eolmarkers.color");
9394
}
9495
}

0 commit comments

Comments
 (0)