31
31
import javax .swing .*;
32
32
33
33
import processing .app .debug .Compiler ;
34
- import processing .app .debug .Target ;
34
+ import processing .app .debug .TargetPackage ;
35
+ import processing .app .debug .TargetPlatform ;
36
+ import processing .app .helpers .PreferencesMap ;
37
+ import processing .app .helpers .filefilters .OnlyDirs ;
35
38
import processing .core .*;
36
39
import static processing .app .I18n ._ ;
37
40
@@ -90,7 +93,7 @@ public class Base {
90
93
// found in the sketchbook)
91
94
static public String librariesClassPath ;
92
95
93
- static public Map <String , Target > targetsTable ;
96
+ static public Map <String , TargetPackage > targetsTable ;
94
97
95
98
// Location for untitled items
96
99
static File untitledFolder ;
@@ -267,7 +270,7 @@ public Base(String[] args) {
267
270
}
268
271
}
269
272
270
- targetsTable = new HashMap <String , Target >();
273
+ targetsTable = new HashMap <String , TargetPackage >();
271
274
loadHardware (getHardwareFolder ());
272
275
loadHardware (getSketchbookHardwareFolder ());
273
276
@@ -939,52 +942,51 @@ protected void rebuildSketchbookMenu(JMenu menu) {
939
942
}
940
943
941
944
942
- public void rebuildImportMenu (JMenu importMenu ) {
943
- //System.out.println("rebuilding import menu");
944
- importMenu .removeAll ();
945
-
946
- // reset the set of libraries
947
- libraries = new HashSet <File >();
948
-
949
- // reset the table mapping imports to libraries
950
- importToLibraryTable = new HashMap <String , File >();
951
-
952
- // Add from the "libraries" subfolder in the Processing directory
953
- //Choose which library to add by chip platform
954
-
955
- try {
956
- // Find the current target. Get the platform, and then select the
957
- // correct name and core path.
958
- String platformname = getBoardPreferences ().get ("platform" );
959
- String targetname = getPlatformPreferences (platformname )
960
- .get ("name" );
961
- String libraryPath = getPlatformPreferences (platformname ).get (
962
- "library.core.path" );
963
-
964
- JMenuItem platformItem = new JMenuItem (targetname );
965
- platformItem .setEnabled (false );
966
- importMenu .add (platformItem );
967
- importMenu .addSeparator ();
968
- addLibraries (importMenu , getCoreLibraries (libraryPath ));
969
- } catch (IOException e ) {
970
- e .printStackTrace ();
971
- }
972
- // Add libraries found in the sketchbook folder
973
- int separatorIndex = importMenu .getItemCount ();
974
- try {
975
- File sketchbookLibraries = getSketchbookLibrariesFolder ();
976
- boolean found = addLibraries (importMenu , sketchbookLibraries );
977
- if (found ) {
978
- JMenuItem contrib = new JMenuItem (_ ("Contributed" ));
979
- contrib .setEnabled (false );
980
- importMenu .insert (contrib , separatorIndex );
981
- importMenu .insertSeparator (separatorIndex );
982
- }
983
- } catch (IOException e ) {
984
- e .printStackTrace ();
985
- }
986
- }
987
-
945
+ public void rebuildImportMenu (JMenu importMenu ) {
946
+ // System.out.println("rebuilding import menu");
947
+ importMenu .removeAll ();
948
+
949
+ // reset the set of libraries
950
+ libraries = new HashSet <File >();
951
+
952
+ // reset the table mapping imports to libraries
953
+ importToLibraryTable = new HashMap <String , File >();
954
+
955
+ // Add from the "libraries" subfolder in the Processing directory
956
+ // Choose which library to add by chip platform
957
+
958
+ try {
959
+ // Find the current target. Get the platform, and then select the
960
+ // correct name and core path.
961
+ String platformname = getBoardPreferences ().get ("platform" );
962
+ String targetname = getPlatformPreferences (platformname ).get ("name" );
963
+ String libraryPath = getPlatformPreferences (platformname ).get (
964
+ "library.core.path" );
965
+
966
+ JMenuItem platformItem = new JMenuItem (targetname );
967
+ platformItem .setEnabled (false );
968
+ importMenu .add (platformItem );
969
+ importMenu .addSeparator ();
970
+ addLibraries (importMenu , getCoreLibraries (libraryPath ));
971
+ } catch (IOException e ) {
972
+ e .printStackTrace ();
973
+ }
974
+
975
+ // Add libraries found in the sketchbook folder
976
+ int separatorIndex = importMenu .getItemCount ();
977
+ try {
978
+ File sketchbookLibraries = getSketchbookLibrariesFolder ();
979
+ boolean found = addLibraries (importMenu , sketchbookLibraries );
980
+ if (found ) {
981
+ JMenuItem contrib = new JMenuItem (_ ("Contributed" ));
982
+ contrib .setEnabled (false );
983
+ importMenu .insert (contrib , separatorIndex );
984
+ importMenu .insertSeparator (separatorIndex );
985
+ }
986
+ } catch (IOException e ) {
987
+ e .printStackTrace ();
988
+ }
989
+ }
988
990
989
991
public void rebuildExamplesMenu (JMenu menu ) {
990
992
//System.out.println("rebuilding examples menu");
@@ -1008,64 +1010,73 @@ public void onBoardOrPortChange() {
1008
1010
}
1009
1011
1010
1012
1011
- public void rebuildBoardsMenu (JMenu menu ) {
1013
+ @ SuppressWarnings ("serial" )
1014
+ public void rebuildBoardsMenu (JMenu menu ) {
1012
1015
//System.out.println("rebuilding boards menu");
1013
1016
menu .removeAll ();
1014
1017
ButtonGroup group = new ButtonGroup ();
1015
- for (Target target : targetsTable .values ()) {
1016
- for (String board : target .getBoards ().keySet ()) {
1017
- AbstractAction action =
1018
- new AbstractAction (target .getBoards ().get (board ).get ("name" )) {
1019
- public void actionPerformed (ActionEvent actionevent ) {
1020
- //System.out.println("Switching to " + target + ":" + board);
1021
- Preferences .set ("target" , (String ) getValue ("target" ));
1022
- Preferences .set ("board" , (String ) getValue ("board" ));
1023
- onBoardOrPortChange ();
1024
- Sketch .buildSettingChanged ();
1025
- //Debug: created new imports menu based on board
1026
- rebuildImportMenu (activeEditor .importMenu );
1027
- }
1028
- };
1029
- action .putValue ("target" , target .getName ());
1030
- action .putValue ("board" , board );
1031
- JMenuItem item = new JRadioButtonMenuItem (action );
1032
- if (target .getName ().equals (Preferences .get ("target" )) &&
1033
- board .equals (Preferences .get ("board" ))) {
1034
- item .setSelected (true );
1035
- }
1036
- group .add (item );
1037
- menu .add (item );
1038
- }
1039
- }
1018
+ for (TargetPackage targetPackage : targetsTable .values ()) {
1019
+ for (TargetPlatform targetPlatform : targetPackage .platforms ()) {
1020
+ for (String board : targetPlatform .getBoards ().keySet ()) {
1021
+ AbstractAction action = new AbstractAction (targetPlatform .getBoards ().get (
1022
+ board ).get ("name" )) {
1023
+ public void actionPerformed (ActionEvent actionevent ) {
1024
+ // System.out.println("Switching to " + target + ":" + board);
1025
+ Preferences .set ("package" , (String ) getValue ("package" ));
1026
+ Preferences .set ("platform" , (String ) getValue ("platform" ));
1027
+ Preferences .set ("board" , (String ) getValue ("board" ));
1028
+ onBoardOrPortChange ();
1029
+ Sketch .buildSettingChanged ();
1030
+ // Debug: created new imports menu based on board
1031
+ rebuildImportMenu (activeEditor .importMenu );
1032
+ }
1033
+ };
1034
+ action .putValue ("package" , targetPackage .getName ());
1035
+ action .putValue ("platform" , targetPlatform .getName ());
1036
+ action .putValue ("board" , board );
1037
+ JMenuItem item = new JRadioButtonMenuItem (action );
1038
+ if (targetPackage .getName ().equals (Preferences .get ("package" ))
1039
+ && targetPlatform .getName ().equals (Preferences .get ("platform" ))
1040
+ && board .equals (Preferences .get ("board" ))) {
1041
+ item .setSelected (true );
1042
+ }
1043
+ group .add (item );
1044
+ menu .add (item );
1045
+ }
1046
+ }
1047
+ }
1040
1048
}
1041
1049
1042
1050
1043
- public void rebuildProgrammerMenu (JMenu menu ) {
1051
+ @ SuppressWarnings ("serial" )
1052
+ public void rebuildProgrammerMenu (JMenu menu ) {
1044
1053
//System.out.println("rebuilding programmer menu");
1045
1054
menu .removeAll ();
1046
1055
ButtonGroup group = new ButtonGroup ();
1047
- for (Target target : targetsTable .values ()) {
1048
- for (String programmer : target .getProgrammers ().keySet ()) {
1049
- AbstractAction action =
1050
- new AbstractAction (
1051
- target .getProgrammers ().get (programmer ).get ("name" )) {
1052
- public void actionPerformed (ActionEvent actionevent ) {
1053
- Preferences .set ("programmer" , getValue ("target" ) + ":" +
1054
- getValue ("programmer" ));
1055
- }
1056
- };
1057
- action .putValue ("target" , target .getName ());
1058
- action .putValue ("programmer" , programmer );
1059
- JMenuItem item = new JRadioButtonMenuItem (action );
1060
- if (Preferences .get ("programmer" ).equals (target .getName () + ":" +
1061
- programmer )) {
1062
- item .setSelected (true );
1063
- }
1064
- group .add (item );
1065
- menu .add (item );
1066
- }
1067
- }
1068
- }
1056
+ for (TargetPackage targetPackage : targetsTable .values ()) {
1057
+ for (TargetPlatform targetPlatform : targetPackage .platforms ()) {
1058
+ for (String programmer : targetPlatform .getProgrammers ().keySet ()) {
1059
+ String id = targetPackage .getName () + ":" + targetPlatform .getName () + ":"
1060
+ + programmer ;
1061
+ AbstractAction action = new AbstractAction (targetPlatform .getProgrammers ()
1062
+ .get (programmer ).get ("name" )) {
1063
+ public void actionPerformed (ActionEvent actionevent ) {
1064
+ Preferences .set ("programmer" , "" + getValue ("id" ));
1065
+ }
1066
+ };
1067
+ // action.putValue("package", targetPackage.getName());
1068
+ // action.putValue("platform", targetPlatform.getName());
1069
+ // action.putValue("programmer", programmer);
1070
+ action .putValue ("id" , id );
1071
+ JMenuItem item = new JRadioButtonMenuItem (action );
1072
+ if (Preferences .get ("programmer" ).equals (id ))
1073
+ item .setSelected (true );
1074
+ group .add (item );
1075
+ menu .add (item );
1076
+ }
1077
+ }
1078
+ }
1079
+ }
1069
1080
1070
1081
1071
1082
/**
@@ -1260,14 +1271,8 @@ public void actionPerformed(ActionEvent e) {
1260
1271
protected void loadHardware (File folder ) {
1261
1272
if (!folder .isDirectory ()) return ;
1262
1273
1263
- String list [] = folder .list (new FilenameFilter () {
1264
- public boolean accept (File dir , String name ) {
1265
- // skip .DS_Store files, .svn folders, etc
1266
- if (name .charAt (0 ) == '.' ) return false ;
1267
- if (name .equals ("CVS" )) return false ;
1268
- return (new File (dir , name ).isDirectory ());
1269
- }
1270
- });
1274
+ String list [] = folder .list (new OnlyDirs ());
1275
+
1271
1276
// if a bad folder or something like that, this might come back null
1272
1277
if (list == null ) return ;
1273
1278
@@ -1277,7 +1282,7 @@ public boolean accept(File dir, String name) {
1277
1282
1278
1283
for (String target : list ) {
1279
1284
File subfolder = new File (folder , target );
1280
- targetsTable .put (target , new Target (target , subfolder ));
1285
+ targetsTable .put (target , new TargetPackage (target , subfolder ));
1281
1286
}
1282
1287
}
1283
1288
@@ -1560,36 +1565,38 @@ static public String getAvrBasePath() {
1560
1565
}
1561
1566
1562
1567
1563
- static public Target getTarget () {
1564
- System .out .println ("Base.targetsTable.get(Preferences.get(\" target\" ))" + Base .targetsTable .get (Preferences .get ("target" )));
1565
- System .out .println ("Preferences.get(\" target\" )" + Preferences .get ("target" ));
1566
- Target target = Base .targetsTable .get (Preferences .get ("target" ));
1567
- if (target == null ) {
1568
- System .out .println ("default target is not in list. Replace with default." );
1569
- Preferences .set ("target" , "arduino" );
1570
- target = Base .targetsTable .get (Preferences .get ("target" ));
1568
+ static public TargetPlatform getTarget () {
1569
+ TargetPackage pack = targetsTable .get (Preferences .get ("target_package" ));
1570
+ TargetPlatform platform = pack .get (Preferences .get ("target_platform" ));
1571
+ if (platform == null ) {
1572
+ System .out .println ("Selected platform is not in list. Replace with default." );
1573
+ Preferences .set ("target_platform" , "arduino" );
1574
+ platform = pack .get (Preferences .get ("target_platform" ));
1571
1575
}
1572
- return target ;
1576
+ return platform ;
1573
1577
}
1574
1578
1575
1579
1576
1580
static public PreferencesMap getPlatformPreferences () {
1577
- Target target = getTarget ();
1578
- Map <String , PreferencesMap > platforms = target .getPlatforms ();
1579
- return platforms .get (Preferences .get ("platform" ));
1581
+ return getTarget ().getPlatform ();
1580
1582
}
1581
1583
1582
- //Get a specific platform
1583
- static public PreferencesMap getPlatformPreferences (String platformName ) {
1584
- if (platformName == null )
1585
- platformName = Preferences .get ("platform" );
1586
- Target target = getTarget ();
1587
- Map <String , PreferencesMap > platforms = target .getPlatforms ();
1588
- return platforms .get (platformName );
1584
+ // Search for a specific platform
1585
+ static public TargetPlatform getTargetPlatform (String pack , String platform ) {
1586
+ return targetsTable .get (pack ).get (platform );
1589
1587
}
1588
+
1589
+ // Get a specific platform preferences inside actual package
1590
+ static public PreferencesMap getPlatformPreferences (String platformName ) {
1591
+ if (platformName == null )
1592
+ platformName = Preferences .get ("platform" );
1593
+ TargetPackage pack = targetsTable .get (Preferences .get ("target_package" ));
1594
+ TargetPlatform target = pack .get (platformName );
1595
+ return target .getPlatform ();
1596
+ }
1590
1597
1591
1598
static public PreferencesMap getBoardPreferences () {
1592
- Target target = getTarget ();
1599
+ TargetPlatform target = getTarget ();
1593
1600
if (target != null ) {
1594
1601
String board = Preferences .get ("board" );
1595
1602
return target .getBoards ().get (board );
0 commit comments