Skip to content

Commit 1b3ae5f

Browse files
committed
Created second level in hardware folder: hardware/PACKAGE/PLATFORM/...
Made some helper class for files filtering. platforms.txt now contains only one platform at a time. Some cleanup in Compiler and AvrDudeUploader classes.
1 parent dc61660 commit 1b3ae5f

File tree

131 files changed

+483
-391
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

131 files changed

+483
-391
lines changed

app/src/processing/app/Base.java

Lines changed: 134 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@
3131
import javax.swing.*;
3232

3333
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;
3538
import processing.core.*;
3639
import static processing.app.I18n._;
3740

@@ -90,7 +93,7 @@ public class Base {
9093
// found in the sketchbook)
9194
static public String librariesClassPath;
9295

93-
static public Map<String, Target> targetsTable;
96+
static public Map<String, TargetPackage> targetsTable;
9497

9598
// Location for untitled items
9699
static File untitledFolder;
@@ -267,7 +270,7 @@ public Base(String[] args) {
267270
}
268271
}
269272

270-
targetsTable = new HashMap<String, Target>();
273+
targetsTable = new HashMap<String, TargetPackage>();
271274
loadHardware(getHardwareFolder());
272275
loadHardware(getSketchbookHardwareFolder());
273276

@@ -939,52 +942,51 @@ protected void rebuildSketchbookMenu(JMenu menu) {
939942
}
940943

941944

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+
}
988990

989991
public void rebuildExamplesMenu(JMenu menu) {
990992
//System.out.println("rebuilding examples menu");
@@ -1008,64 +1010,73 @@ public void onBoardOrPortChange() {
10081010
}
10091011

10101012

1011-
public void rebuildBoardsMenu(JMenu menu) {
1013+
@SuppressWarnings("serial")
1014+
public void rebuildBoardsMenu(JMenu menu) {
10121015
//System.out.println("rebuilding boards menu");
10131016
menu.removeAll();
10141017
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+
}
10401048
}
10411049

10421050

1043-
public void rebuildProgrammerMenu(JMenu menu) {
1051+
@SuppressWarnings("serial")
1052+
public void rebuildProgrammerMenu(JMenu menu) {
10441053
//System.out.println("rebuilding programmer menu");
10451054
menu.removeAll();
10461055
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+
}
10691080

10701081

10711082
/**
@@ -1260,14 +1271,8 @@ public void actionPerformed(ActionEvent e) {
12601271
protected void loadHardware(File folder) {
12611272
if (!folder.isDirectory()) return;
12621273

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+
12711276
// if a bad folder or something like that, this might come back null
12721277
if (list == null) return;
12731278

@@ -1277,7 +1282,7 @@ public boolean accept(File dir, String name) {
12771282

12781283
for (String target : list) {
12791284
File subfolder = new File(folder, target);
1280-
targetsTable.put(target, new Target(target, subfolder));
1285+
targetsTable.put(target, new TargetPackage(target, subfolder));
12811286
}
12821287
}
12831288

@@ -1560,36 +1565,38 @@ static public String getAvrBasePath() {
15601565
}
15611566

15621567

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"));
15711575
}
1572-
return target;
1576+
return platform;
15731577
}
15741578

15751579

15761580
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();
15801582
}
15811583

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);
15891587
}
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+
}
15901597

15911598
static public PreferencesMap getBoardPreferences() {
1592-
Target target = getTarget();
1599+
TargetPlatform target = getTarget();
15931600
if (target != null) {
15941601
String board = Preferences.get("board");
15951602
return target.getBoards().get(board);

app/src/processing/app/Preferences.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
import javax.swing.*;
3232

33+
import processing.app.helpers.PreferencesMap;
3334
import processing.app.syntax.*;
3435
import processing.core.*;
3536
import static processing.app.I18n._;

0 commit comments

Comments
 (0)