Skip to content

Commit 83a1ec6

Browse files
committed
the new Export to Application debugged and working
1 parent 2607a72 commit 83a1ec6

3 files changed

Lines changed: 110 additions & 4 deletions

File tree

java/src/processing/mode/java/ExportPrompt.java

Lines changed: 104 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import processing.app.SketchException;
3030
import processing.app.ui.ColorChooser;
3131
import processing.core.PApplet;
32+
import processing.data.StringDict;
33+
import processing.data.StringList;
3234

3335
import javax.swing.*;
3436
import javax.swing.border.BevelBorder;
@@ -41,21 +43,29 @@
4143
import java.awt.event.MouseEvent;
4244
import java.io.File;
4345
import java.io.IOException;
46+
import java.util.ArrayList;
47+
import java.util.List;
4448

4549

4650
public class ExportPrompt {
4751
// Can't be .windows because that'll be stripped off as a per-platform pref
52+
static final String EXPORT_VARIANTS = "export.application.variants";
53+
/*
4854
static final String EXPORT_PREFIX = "export.application.platform_";
4955
static final String EXPORT_MACOSX = EXPORT_PREFIX + "macosx";
5056
static final String EXPORT_WINDOWS = EXPORT_PREFIX + "windows";
5157
static final String EXPORT_LINUX = EXPORT_PREFIX + "linux";
58+
*/
5259

5360
final JButton exportButton = new JButton(Language.text("prompt.export"));
5461
final JButton cancelButton = new JButton(Language.text("prompt.cancel"));
5562

63+
/*
5664
final JCheckBox windowsButton = new JCheckBox("Windows");
5765
final JCheckBox macosButton = new JCheckBox("Mac OS X");
5866
final JCheckBox linuxButton = new JCheckBox("Linux");
67+
*/
68+
List<JCheckBox> variantButtons;
5969

6070
final JavaEditor editor;
6171

@@ -64,13 +74,78 @@ public class ExportPrompt {
6474

6575
private ExportPrompt(JavaEditor editor) {
6676
this.editor = editor;
77+
78+
String pref = Preferences.get(EXPORT_VARIANTS);
79+
if (pref == null) {
80+
pref = Platform.getVariant(); // just add myself
81+
}
82+
StringList selectedVariants = new StringList(pref.split(","));
83+
84+
variantButtons = new ArrayList<>();
85+
for (StringDict.Entry entry : Platform.getSupportedVariants().entries()) {
86+
String variant = entry.key;
87+
JCheckBox button = new JCheckBox(entry.value); // variant name
88+
if (variant.startsWith("macos") && !Platform.isMacOS()) {
89+
button.setEnabled(false);
90+
} else {
91+
button.setSelected(selectedVariants.hasValue(variant));
92+
}
93+
button.setActionCommand(variant);
94+
button.addActionListener(e -> updateVariants());
95+
variantButtons.add(button);
96+
/*
97+
final String variant = entry.key;
98+
button.addActionListener(new ActionListener() {
99+
@Override
100+
public void actionPerformed(ActionEvent e) {
101+
e.getActionCommand();
102+
toggleVariant(variant);
103+
}
104+
});
105+
*/
106+
}
107+
}
108+
109+
110+
protected void updateVariants() {
111+
StringList list = new StringList();
112+
for (JCheckBox button : variantButtons) {
113+
if (button.isSelected()) {
114+
list.append(button.getActionCommand());
115+
}
116+
}
117+
Preferences.set(EXPORT_VARIANTS, list.join(","));
118+
exportButton.setEnabled(anyExportButton());
119+
}
120+
121+
122+
/*
123+
protected void toggleVariant(String variant) {
124+
String pref = Preferences.get(EXPORT_VARIANTS);
125+
StringList list = new StringList(pref.split(","));
126+
if (list.hasValue(variant)) {
127+
list.removeValue(variant);
128+
} else {
129+
list.append(variant);
130+
}
131+
pref = list.join(",");
132+
Preferences.set(EXPORT_VARIANTS, pref);
67133
}
68134
69135
70136
protected void updateExportButton() {
71-
exportButton.setEnabled(windowsButton.isSelected() ||
72-
macosButton.isSelected() ||
73-
linuxButton.isSelected());
137+
exportButton.setEnabled(anyExportButton());
138+
}
139+
*/
140+
141+
142+
protected boolean anyExportButton() {
143+
for (JCheckBox button : variantButtons) {
144+
if (button.isSelected()) {
145+
return true;
146+
}
147+
}
148+
return false;
74149
}
75150

76151

@@ -107,6 +182,7 @@ protected boolean trigger() throws IOException, SketchException {
107182
// label2.getPreferredSize().width);
108183
panel.add(Box.createVerticalStrut(12));
109184

185+
/*
110186
windowsButton.setSelected(Preferences.getBoolean(EXPORT_WINDOWS));
111187
windowsButton.addItemListener(e -> {
112188
Preferences.setBoolean(EXPORT_WINDOWS, windowsButton.isSelected());
@@ -143,6 +219,31 @@ protected boolean trigger() throws IOException, SketchException {
143219
platformPanel.add(macosButton);
144220
platformPanel.add(Box.createHorizontalStrut(6));
145221
platformPanel.add(linuxButton);
222+
*/
223+
224+
JPanel platformPanel = new JPanel();
225+
// platformPanel.setLayout(new BoxLayout(platformPanel, BoxLayout.X_AXIS));
226+
int half = (variantButtons.size() + 1) / 2;
227+
228+
Box leftPlatforms = Box.createVerticalBox();
229+
for (int i = 0; i < half; i++) {
230+
// if (i != 0) {
231+
// leftPlatforms.add(Box.createVerticalStrut(6));
232+
// }
233+
leftPlatforms.add(variantButtons.get(i));
234+
}
235+
236+
Box rightPlatforms = Box.createVerticalBox();
237+
for (int i = half; i < variantButtons.size(); i++) {
238+
// if (i != half) {
239+
// rightPlatforms.add(Box.createVerticalStrut(6));
240+
// }
241+
rightPlatforms.add(variantButtons.get(i));
242+
}
243+
244+
platformPanel.add(leftPlatforms);
245+
platformPanel.add(rightPlatforms);
246+
146247
platformPanel.setBorder(new TitledBorder(Language.text("export.platforms")));
147248
//Dimension goodIdea = new Dimension(wide, platformPanel.getPreferredSize().height);
148249
//platformPanel.setMaximumSize(goodIdea);

java/src/processing/mode/java/JavaBuild.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ protected boolean exportApplication() throws IOException, SketchException {
581581
*/
582582

583583
final String hostVariant = Platform.getVariant();
584-
for (String variant : Preferences.get("export.variants").split(",")) {
584+
for (String variant : Preferences.get(ExportPrompt.EXPORT_VARIANTS).split(",")) {
585585
// Can only embed Java on the native platform
586586
boolean embedJava = variant.equals(hostVariant) &&
587587
Preferences.getBoolean("export.application.embed_java");

todo.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ X did we lose settings.path because it was too buggy?
2525
_ https://github.com/processing/processing/issues/3948
2626
_ https://github.com/processing/processing4/pull/360
2727

28+
platforms/variants/export
29+
X replacing macosx with macos in prefs and languages
30+
X major rewrite of Export to Application for the six supported platforms
31+
_ now writes folders with different names instead of 'application.'
32+
2833
windows scaling
2934
X Fix "Could not delete disable_hidpi" message on macOS/Linux after closing prefs
3035
X remove old-school offscreen buffering from our custom components

0 commit comments

Comments
 (0)