29
29
import java .util .List ;
30
30
31
31
import javax .swing .*;
32
- import javax .swing .filechooser .FileNameExtensionFilter ;
33
32
34
33
import processing .app .debug .TargetPackage ;
35
34
import processing .app .debug .TargetPlatform ;
38
37
import processing .app .helpers .PreferencesMap ;
39
38
import processing .app .helpers .filefilters .OnlyDirs ;
40
39
import processing .app .helpers .filefilters .OnlyFilesWithExtension ;
41
- import processing .app .tools .MapWithSubkeys ;
40
+ import processing .app .javax . swing . filechooser . FileNameExtensionFilter ; import processing . app . tools .MapWithSubkeys ;
42
41
import processing .app .tools .ZipDeflater ;
43
42
import processing .core .*;
44
43
import static processing .app .I18n ._ ;
@@ -88,18 +87,18 @@ public class Base {
88
87
static private File toolsFolder ;
89
88
90
89
static private List <File > librariesFolders ;
91
-
90
+
92
91
// maps library name to their library folder
93
92
static private Map <String , File > libraries ;
94
-
93
+
95
94
// maps #included files to their library folder
96
95
static Map <String , File > importToLibraryTable ;
97
96
98
97
// classpath for all known libraries for p5
99
98
// (both those in the p5/libs folder and those with lib subfolders
100
99
// found in the sketchbook)
101
100
static public String librariesClassPath ;
102
-
101
+
103
102
static public Map <String , TargetPackage > packages ;
104
103
105
104
// Location for untitled items
@@ -273,7 +272,7 @@ public Base(String[] args) throws Exception {
273
272
defaultFolder .mkdirs ();
274
273
}
275
274
}
276
-
275
+
277
276
packages = new HashMap <String , TargetPackage >();
278
277
loadHardware (getHardwareFolder ());
279
278
loadHardware (getSketchbookHardwareFolder ());
@@ -993,7 +992,7 @@ public Map<String, File> getUserLibs() {
993
992
994
993
public void rebuildImportMenu (JMenu importMenu , final Editor editor ) {
995
994
importMenu .removeAll ();
996
-
995
+
997
996
JMenuItem addLibraryMenuItem = new JMenuItem (_ ("Add Library..." ));
998
997
addLibraryMenuItem .addActionListener (new ActionListener () {
999
998
public void actionPerformed (ActionEvent e ) {
@@ -1040,7 +1039,7 @@ public void actionPerformed(ActionEvent e) {
1040
1039
public void rebuildExamplesMenu (JMenu menu ) {
1041
1040
try {
1042
1041
menu .removeAll ();
1043
-
1042
+
1044
1043
// Add examples from distribution "example" folder
1045
1044
boolean found = addSketches (menu , examplesFolder , false );
1046
1045
if (found ) menu .addSeparator ();
@@ -1074,14 +1073,14 @@ public void rebuildExamplesMenu(JMenu menu) {
1074
1073
e .printStackTrace ();
1075
1074
}
1076
1075
}
1077
-
1076
+
1078
1077
public Map <String , File > scanLibraries (List <File > folders ) {
1079
- Map <String , File > res = new HashMap <String , File >();
1078
+ Map <String , File > res = new HashMap <String , File >();
1080
1079
for (File folder : folders )
1081
1080
res .putAll (scanLibraries (folder ));
1082
1081
return res ;
1083
1082
}
1084
-
1083
+
1085
1084
public Map <String , File > scanLibraries (File folder ) {
1086
1085
Map <String , File > res = new HashMap <String , File >();
1087
1086
String list [] = folder .list (new OnlyDirs ());
@@ -1101,7 +1100,7 @@ public Map<String, File> scanLibraries(File folder) {
1101
1100
}
1102
1101
1103
1102
subfolder = scanFatLibrary (subfolder );
1104
-
1103
+
1105
1104
// (also replace previously found libs with the same name)
1106
1105
if (subfolder != null )
1107
1106
res .put (libName , subfolder );
@@ -1117,7 +1116,7 @@ public Map<String, File> scanLibraries(File folder) {
1117
1116
* <br />
1118
1117
* If a non-"FAT" library is detected, we assume that the library is suitable
1119
1118
* for the current architecture and the libFolder parameter is returned.<br />
1120
- *
1119
+ *
1121
1120
* @param libFolder
1122
1121
* @return
1123
1122
*/
@@ -1134,18 +1133,18 @@ public File scanFatLibrary(File libFolder) {
1134
1133
return null ;
1135
1134
return archSubfolder ;
1136
1135
}
1137
-
1136
+
1138
1137
public void onBoardOrPortChange () {
1139
1138
// Calculate paths for libraries and examples
1140
1139
examplesFolder = getContentFile ("examples" );
1141
1140
toolsFolder = getContentFile ("tools" );
1142
-
1141
+
1143
1142
File platformFolder = getTargetPlatform ().getFolder ();
1144
1143
librariesFolders = new ArrayList <File >();
1145
1144
librariesFolders .add (getContentFile ("libraries" ));
1146
1145
librariesFolders .add (new File (platformFolder , "libraries" ));
1147
1146
librariesFolders .add (getSketchbookLibrariesFolder ());
1148
-
1147
+
1149
1148
// Scan for libraries in each library folder.
1150
1149
// Libraries located in the latest folders on the list can override
1151
1150
// other libraries with the same name.
@@ -1158,7 +1157,7 @@ public void onBoardOrPortChange() {
1158
1157
for (String pkg : packages )
1159
1158
importToLibraryTable .put (pkg , subfolder );
1160
1159
}
1161
-
1160
+
1162
1161
// Update editors status bar
1163
1162
for (Editor editor : editors )
1164
1163
editor .onBoardOrPortChange ();
@@ -1170,14 +1169,14 @@ public void rebuildBoardsMenu(JMenu toolsMenu, final Editor editor) {
1170
1169
String selPackage = Preferences .get ("target_package" );
1171
1170
String selPlatform = Preferences .get ("target_platform" );
1172
1171
String selBoard = Preferences .get ("board" );
1173
-
1172
+
1174
1173
boolean first = true ;
1175
-
1174
+
1176
1175
List <JMenuItem > menuItemsToClickAfterStartup = new LinkedList <JMenuItem >();
1177
1176
1178
1177
ButtonGroup boardsButtonGroup = new ButtonGroup ();
1179
1178
Map <String , ButtonGroup > buttonGroupsMap = new HashMap <String , ButtonGroup >();
1180
-
1179
+
1181
1180
// Cycle through all packages
1182
1181
for (TargetPackage targetPackage : packages .values ()) {
1183
1182
String packageName = targetPackage .getName ();
@@ -1189,17 +1188,17 @@ public void rebuildBoardsMenu(JMenu toolsMenu, final Editor editor) {
1189
1188
if (targetPlatform .getPreferences ().get ("name" ) == null || targetPlatform .getBoards ().isEmpty ()) {
1190
1189
continue ;
1191
1190
}
1192
-
1191
+
1193
1192
// Add a title for each group of boards
1194
1193
if (!first ) {
1195
1194
boardsMenu .add (new JSeparator ());
1196
1195
}
1197
1196
first = false ;
1198
-
1197
+
1199
1198
JMenuItem separator = new JMenuItem (_ (targetPlatform .getPreferences ().get ("name" )));
1200
1199
separator .setEnabled (false );
1201
1200
boardsMenu .add (separator );
1202
-
1201
+
1203
1202
// For every platform cycle through all boards
1204
1203
for (final String boardID : targetPlatform .getBoards ().keySet ()) {
1205
1204
// Setup a menu item for the current board
@@ -1211,7 +1210,7 @@ public void actionPerformed(ActionEvent actionevent) {
1211
1210
}
1212
1211
};
1213
1212
action .putValue ("b" , packageName + ":" + platformName + ":" + boardID );
1214
-
1213
+
1215
1214
JRadioButtonMenuItem item = new JRadioButtonMenuItem (action );
1216
1215
boardsMenu .add (item );
1217
1216
boardsButtonGroup .add (item );
@@ -1256,7 +1255,7 @@ public void actionPerformed(ActionEvent e) {
1256
1255
if (!buttonGroupsMap .containsKey (customMenuID )) {
1257
1256
buttonGroupsMap .put (customMenuID , new ButtonGroup ());
1258
1257
}
1259
-
1258
+
1260
1259
item = new JRadioButtonMenuItem (subAction );
1261
1260
menu .add (item );
1262
1261
buttonGroupsMap .get (customMenuID ).add (item );
@@ -1322,7 +1321,7 @@ private JMenu makeOrGetBoardMenu(JMenu toolsMenu, String label) {
1322
1321
toolsMenu .add (menu );
1323
1322
return menu ;
1324
1323
}
1325
-
1324
+
1326
1325
private static JMenuItem selectVisibleSelectedOrFirstMenuItem (JMenu menu ) {
1327
1326
JMenuItem firstVisible = null ;
1328
1327
for (int i = 0 ; i < menu .getItemCount (); i ++) {
@@ -1336,14 +1335,14 @@ private static JMenuItem selectVisibleSelectedOrFirstMenuItem(JMenu menu) {
1336
1335
}
1337
1336
}
1338
1337
}
1339
-
1338
+
1340
1339
if (firstVisible != null ) {
1341
1340
return firstVisible ;
1342
1341
}
1343
-
1342
+
1344
1343
throw new IllegalStateException ("Menu has no enabled items" );
1345
1344
}
1346
-
1345
+
1347
1346
private static JMenuItem selectFirstEnabledMenuItem (JMenu menu ) {
1348
1347
for (int i = 0 ; i < menu .getItemCount (); i ++) {
1349
1348
JMenuItem item = menu .getItem (i );
@@ -1360,7 +1359,7 @@ private void selectBoard(String selectBoard, Editor editor) {
1360
1359
Preferences .set ("target_package" , split [0 ]);
1361
1360
Preferences .set ("target_platform" , split [1 ]);
1362
1361
Preferences .set ("board" , split [2 ]);
1363
-
1362
+
1364
1363
filterVisibilityOfSubsequentBoardMenus (split [2 ], 1 );
1365
1364
1366
1365
onBoardOrPortChange ();
@@ -1426,7 +1425,7 @@ protected boolean addSketches(JMenu menu, File folder,
1426
1425
if (addSketchesSubmenu (menu , name , subfolder , replaceExisting ))
1427
1426
ifound = true ;
1428
1427
}
1429
-
1428
+
1430
1429
return ifound ; // actually ignored, but..
1431
1430
}
1432
1431
@@ -1482,7 +1481,7 @@ public void actionPerformed(ActionEvent e) {
1482
1481
item .setActionCommand (entry .getAbsolutePath ());
1483
1482
menu .add (item );
1484
1483
return true ;
1485
- }
1484
+ }
1486
1485
1487
1486
// don't create an extra menu level for a folder named "examples"
1488
1487
if (folder .getName ().equals ("examples" ))
@@ -1500,7 +1499,7 @@ protected void addLibraries(JMenu menu, Map<String, File> libs) throws IOExcepti
1500
1499
1501
1500
List <String > list = new ArrayList <String >(libs .keySet ());
1502
1501
Collections .sort (list , String .CASE_INSENSITIVE_ORDER );
1503
-
1502
+
1504
1503
ActionListener listener = new ActionListener () {
1505
1504
public void actionPerformed (ActionEvent e ) {
1506
1505
activeEditor .getSketch ().importLibrary (e .getActionCommand ());
@@ -1519,7 +1518,7 @@ public void actionPerformed(ActionEvent e) {
1519
1518
// XXX: DAM: should recurse here so that library folders can be nested
1520
1519
}
1521
1520
}
1522
-
1521
+
1523
1522
/**
1524
1523
* Given a folder, return a list of the header files in that folder (but not
1525
1524
* the header files in its sub-folders, as those should be included from
@@ -1528,19 +1527,19 @@ public void actionPerformed(ActionEvent e) {
1528
1527
static public String [] headerListFromIncludePath (File path ) {
1529
1528
return path .list (new OnlyFilesWithExtension (".h" ));
1530
1529
}
1531
-
1530
+
1532
1531
protected void loadHardware (File folder ) {
1533
1532
if (!folder .isDirectory ()) return ;
1534
-
1533
+
1535
1534
String list [] = folder .list (new OnlyDirs ());
1536
-
1535
+
1537
1536
// if a bad folder or something like that, this might come back null
1538
1537
if (list == null ) return ;
1539
1538
1540
1539
// alphabetize list, since it's not always alpha order
1541
1540
// replaced hella slow bubble sort with this feller for 0093
1542
1541
Arrays .sort (list , String .CASE_INSENSITIVE_ORDER );
1543
-
1542
+
1544
1543
for (String target : list ) {
1545
1544
// Skip reserved 'tools' folder.
1546
1545
if (target .equals ("tools" ))
@@ -1809,17 +1808,17 @@ static public File getHardwareFolder() {
1809
1808
// before the other folders / paths get cached).
1810
1809
return getContentFile ("hardware" );
1811
1810
}
1812
-
1811
+
1813
1812
//Get the core libraries
1814
1813
static public File getCoreLibraries (String path ) {
1815
- return getContentFile (path );
1814
+ return getContentFile (path );
1816
1815
}
1817
-
1816
+
1818
1817
static public String getHardwarePath () {
1819
1818
return getHardwareFolder ().getAbsolutePath ();
1820
1819
}
1821
-
1822
-
1820
+
1821
+
1823
1822
static public String getAvrBasePath () {
1824
1823
String path = getHardwarePath () + File .separator + "tools" +
1825
1824
File .separator + "avr" + File .separator + "bin" + File .separator ;
@@ -1828,22 +1827,22 @@ static public String getAvrBasePath() {
1828
1827
}
1829
1828
return path ;
1830
1829
}
1831
-
1832
-
1830
+
1831
+
1833
1832
/**
1834
1833
* Returns the currently selected TargetPlatform.
1835
- *
1834
+ *
1836
1835
* @return
1837
1836
*/
1838
1837
static public TargetPlatform getTargetPlatform () {
1839
1838
String packageName = Preferences .get ("target_package" );
1840
1839
String platformName = Preferences .get ("target_platform" );
1841
1840
return getTargetPlatform (packageName , platformName );
1842
1841
}
1843
-
1842
+
1844
1843
/**
1845
1844
* Returns a specific TargetPlatform searching Package/Platform
1846
- *
1845
+ *
1847
1846
* @param packageName
1848
1847
* @param platformName
1849
1848
* @return
@@ -1900,8 +1899,8 @@ static public File getSketchbookLibrariesFolder() {
1900
1899
static public String getSketchbookLibrariesPath () {
1901
1900
return getSketchbookLibrariesFolder ().getAbsolutePath ();
1902
1901
}
1903
-
1904
-
1902
+
1903
+
1905
1904
static public File getSketchbookHardwareFolder () {
1906
1905
return new File (getSketchbookFolder (), "hardware" );
1907
1906
}
@@ -2054,7 +2053,7 @@ static public void setIcon(Frame frame) {
2054
2053
// don't use the low-res icon on Mac OS X; the window should
2055
2054
// already have the right icon from the .app file.
2056
2055
if (Base .isMacOS ()) return ;
2057
-
2056
+
2058
2057
Image image = Toolkit .getDefaultToolkit ().createImage (PApplet .ICON_IMAGE );
2059
2058
frame .setIconImage (image );
2060
2059
}
@@ -2138,7 +2137,7 @@ static public void showTroubleshooting() {
2138
2137
static public void showFAQ () {
2139
2138
showReference (_ ("FAQ.html" ));
2140
2139
}
2141
-
2140
+
2142
2141
2143
2142
// .................................................................
2144
2143
0 commit comments