1
1
package processing .mode .android ;
2
2
3
- import java .awt .FileDialog ;
4
- import java .awt .Frame ;
5
- import java .io .File ;
6
- import java .io .IOException ;
7
- import java .text .DateFormat ;
8
- import java .text .ParseException ;
9
- import java .text .SimpleDateFormat ;
10
- import java .util .Date ;
11
-
12
- import javax .swing .JFileChooser ;
13
- import javax .swing .JOptionPane ;
14
-
15
3
import processing .app .Base ;
16
4
import processing .app .Platform ;
17
5
import processing .app .Preferences ;
18
6
import processing .app .exec .ProcessHelper ;
19
7
import processing .app .exec .ProcessResult ;
20
8
import processing .core .PApplet ;
21
9
10
+ import javax .swing .*;
11
+ import java .awt .*;
12
+ import java .io .File ;
13
+ import java .io .IOException ;
14
+ import java .text .DateFormat ;
15
+ import java .text .ParseException ;
16
+ import java .text .SimpleDateFormat ;
17
+ import java .util .Date ;
18
+
22
19
class AndroidSDK {
23
20
private final File folder ;
24
21
private final File tools ;
@@ -31,8 +28,10 @@ class AndroidSDK {
31
28
private static final String ANDROID_SDK_SECONDARY =
32
29
"The Android SDK does not appear to be installed, <br>" +
33
30
"because the ANDROID_SDK variable is not set. <br>" +
34
- "If it is installed, click “Yes” to select the <br>" +
35
- "location of the SDK, or “No” to visit the SDK<br>" +
31
+ "If it is installed, click “Locate SDK path” to select the <br>" +
32
+ "location of the SDK, or “Download SDK” to let <br>" +
33
+ "Processing download SDK automatically.<br><br>" +
34
+ "If you want to download SDK manually, you can visit <br>" +
36
35
"download site at http://developer.android.com/sdk." ;
37
36
38
37
private static final String SELECT_ANDROID_SDK_FOLDER =
@@ -236,13 +235,12 @@ public static AndroidSDK load() throws BadSDKException, IOException {
236
235
237
236
static public AndroidSDK locate (final Frame window )
238
237
throws BadSDKException , IOException {
239
- final int result = Base .showYesNoQuestion (window , "Android SDK" ,
240
- ANDROID_SDK_PRIMARY , ANDROID_SDK_SECONDARY );
238
+ final int result = showLocateDialog (window );
241
239
if (result == JOptionPane .CANCEL_OPTION ) {
242
240
throw new BadSDKException ("User canceled attempt to find SDK." );
243
241
}
244
- if (result == JOptionPane .NO_OPTION ) {
245
- // user admitted they don't have the SDK installed, and need help.
242
+ if (result == JOptionPane .YES_OPTION ) {
243
+ // here we are going to download sdk automatically
246
244
Base .openURL (ANDROID_SDK_URL );
247
245
throw new BadSDKException ("No SDK installed." );
248
246
}
@@ -263,6 +261,48 @@ static public AndroidSDK locate(final Frame window)
263
261
}
264
262
}
265
263
264
+ static public int showLocateDialog (Frame editor ) {
265
+ if (!Base .isMacOS ()) {
266
+ return JOptionPane .showConfirmDialog (editor ,
267
+ "<html><body>" +
268
+ "<b>" + ANDROID_SDK_PRIMARY + "</b>" +
269
+ "<br>" + ANDROID_SDK_SECONDARY , "Android SDK" ,
270
+ JOptionPane .YES_NO_OPTION ,
271
+ JOptionPane .QUESTION_MESSAGE );
272
+ } else {
273
+ // Pane formatting adapted from the Quaqua guide
274
+ // http://www.randelshofer.ch/quaqua/guide/joptionpane.html
275
+ JOptionPane pane =
276
+ new JOptionPane ("<html> " +
277
+ "<head> <style type=\" text/css\" >" +
278
+ "b { font: 13pt \" Lucida Grande\" }" +
279
+ "p { font: 11pt \" Lucida Grande\" ; margin-top: 8px; width: 300px }" +
280
+ "</style> </head>" +
281
+ "<b>" + ANDROID_SDK_PRIMARY + "</b>" +
282
+ "<p>" + ANDROID_SDK_SECONDARY + "</p>" ,
283
+ JOptionPane .QUESTION_MESSAGE );
284
+
285
+ String [] options = new String [] {
286
+ "Download SDK automatically" , "Locate SDK path manually"
287
+ };
288
+ pane .setOptions (options );
289
+
290
+ // highlight the safest option ala apple hig
291
+ pane .setInitialValue (options [0 ]);
292
+
293
+ JDialog dialog = pane .createDialog (editor , null );
294
+ dialog .setVisible (true );
295
+
296
+ Object result = pane .getValue ();
297
+ if (result == options [0 ]) {
298
+ return JOptionPane .YES_OPTION ;
299
+ } else if (result == options [1 ]) {
300
+ return JOptionPane .NO_OPTION ;
301
+ } else {
302
+ return JOptionPane .CLOSED_OPTION ;
303
+ }
304
+ }
305
+ }
266
306
267
307
// this was banished from Base because it encourages bad practice.
268
308
// TODO figure out a better way to handle the above.
0 commit comments