2929import processing .app .SketchException ;
3030import processing .app .ui .ColorChooser ;
3131import processing .core .PApplet ;
32+ import processing .data .StringDict ;
33+ import processing .data .StringList ;
3234
3335import javax .swing .*;
3436import javax .swing .border .BevelBorder ;
4143import java .awt .event .MouseEvent ;
4244import java .io .File ;
4345import java .io .IOException ;
46+ import java .util .ArrayList ;
47+ import java .util .List ;
4448
4549
4650public 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);
0 commit comments