1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-17 22:23:10 +03:00

Other refinement in TargetBoard

This commit is contained in:
Cristian Maglie
2013-03-03 12:08:16 +01:00
parent 51c36c7325
commit acc477af05
4 changed files with 64 additions and 88 deletions

View File

@ -1270,14 +1270,11 @@ public class Base {
String title = customMenus.get(menuId); String title = customMenus.get(menuId);
JMenu menu = makeOrGetBoardMenu(toolsMenu, _(title)); JMenu menu = makeOrGetBoardMenu(toolsMenu, _(title));
//Map<String, PreferencesMap> customMenu = customMenus.subTree(menuId).firstLevelMap(); if (board.hasMenu(menuId)) {
if (board.hasMenuOptions(menuId)) { PreferencesMap boardCustomMenu = board.getMenuLabels(menuId);
//if (customMenu.containsKey(boardId)) {
//PreferencesMap boardCustomMenu = customMenu.get(boardId);
PreferencesMap boardCustomMenu = board.getMenuOptions(menuId);
final int currentIndex = i + 1 + 1; //plus 1 to skip the first board menu, plus 1 to keep the custom menu next to this one final int currentIndex = i + 1 + 1; //plus 1 to skip the first board menu, plus 1 to keep the custom menu next to this one
i++; i++;
for (String customMenuOption : boardCustomMenu.topLevelKeySet()) { for (String customMenuOption : boardCustomMenu.keySet()) {
@SuppressWarnings("serial") @SuppressWarnings("serial")
Action subAction = new AbstractAction(_(boardCustomMenu.get(customMenuOption))) { Action subAction = new AbstractAction(_(boardCustomMenu.get(customMenuOption))) {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
@ -1936,22 +1933,18 @@ public class Base {
TargetPlatform target = getTargetPlatform(); TargetPlatform target = getTargetPlatform();
String boardId = Preferences.get("board"); String boardId = Preferences.get("board");
TargetBoard board = target.getBoard(boardId); TargetBoard board = target.getBoard(boardId);
PreferencesMap boardPreferences = new PreferencesMap(board.getPreferences()); PreferencesMap prefs = new PreferencesMap(board.getPreferences());
PreferencesMap customMenus = target.getCustomMenus(); for (String menuId : target.getCustomMenusKeys()) {
for (String menuId : customMenus.keySet()) { String entry = Preferences.get("custom_" + menuId);
PreferencesMap boardCustomMenu = board.getMenuOptions(menuId); if (board.hasMenu(menuId) && entry != null &&
String selectedCustomMenuEntry = Preferences.get("custom_" + menuId); entry.startsWith(boardId)) {
if (boardCustomMenu != null && boardCustomMenu.size() > 0 && String selectionId = entry.substring(entry.indexOf("_") + 1);
selectedCustomMenuEntry != null && prefs.putAll(board.getMenuConfiguration(menuId, selectionId));
selectedCustomMenuEntry.startsWith(boardId)) { prefs.put("name", prefs.get("name") + ", " +
String menuEntryId = selectedCustomMenuEntry board.getMenuLabel(menuId, selectionId));
.substring(selectedCustomMenuEntry.indexOf("_") + 1);
boardPreferences.putAll(boardCustomMenu.subTree(menuEntryId));
boardPreferences.put("name", boardPreferences.get("name") + ", " +
boardCustomMenu.get(menuEntryId));
} }
} }
return boardPreferences; return prefs;
} }
static public File getPortableFolder() { static public File getPortableFolder() {

View File

@ -53,15 +53,52 @@ public class TargetBoard {
return prefs; return prefs;
} }
public void setMenuOptions(String menuId, PreferencesMap _menuOptions) { /**
menuOptions.put(menuId, _menuOptions); * Check if the board has a sub menu.
} *
* @param menuId
public PreferencesMap getMenuOptions(String menuId) { * The menu ID to check
return menuOptions.get(menuId); * @return
} */
public boolean hasMenu(String menuId) {
public boolean hasMenuOptions(String menuId) {
return menuOptions.containsKey(menuId); return menuOptions.containsKey(menuId);
} }
/**
* Returns the options available on a specific menu
*
* @param menuId
* The menu ID
* @return
*/
public PreferencesMap getMenuLabels(String menuId) {
return menuOptions.get(menuId).topLevelMap();
}
/**
* Returns the label of the specified option in the specified menu
*
* @param menuId
* The menu ID
* @param selectionId
* The option ID
* @return
*/
public String getMenuLabel(String menuId, String selectionId) {
return getMenuLabels(menuId).get(selectionId);
}
/**
* Returns the configuration parameters to override (as a PreferenceMap) when
* the specified option in the specified menu is selected
*
* @param menuId
* The menu ID
* @param selectionId
* The option ID
* @return
*/
public PreferencesMap getMenuConfiguration(String menuId, String selectionId) {
return menuOptions.get(menuId).subTree(selectionId);
}
} }

View File

@ -30,6 +30,7 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import java.util.Set;
import processing.app.helpers.PreferencesMap; import processing.app.helpers.PreferencesMap;
@ -131,6 +132,10 @@ public class TargetPlatform {
return customMenus; return customMenus;
} }
public Set<String> getCustomMenusKeys() {
return customMenus.keySet();
}
public Map<String, PreferencesMap> getProgrammers() { public Map<String, PreferencesMap> getProgrammers() {
return programmers; return programmers;
} }

View File

@ -28,7 +28,6 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.Collection;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.Map; import java.util.Map;
@ -155,64 +154,6 @@ public class PreferencesMap extends LinkedHashMap<String, String> {
return res; return res;
} }
/**
* Returns the values of all the top level pairs of the current mapping. E.g.
* the folowing mapping:<br />
*
* <pre>
* Map (
* alpha = Alpha
* alpha.some.keys = v1
* alpha.other.keys = v2
* beta = Beta
* beta.some.keys = v3
* )
* </pre>
*
* will generate the following result:
*
* <pre>
* Collection (
* Alpha
* Beta
* )
* </pre>
*
* @return
*/
public Collection<String> topLevelValues() {
return topLevelMap().values();
}
/**
* Returns a key set of all the top level pairs of the current mapping. E.g.
* the folowing mapping:<br />
*
* <pre>
* Map (
* alpha = Alpha
* alpha.some.keys = v1
* alpha.other.keys = v2
* beta = Beta
* beta.some.keys = v3
* )
* </pre>
*
* will generate the following result:
*
* <pre>
* Set (
* alpha
* beta
* )
* </pre>
*
* @return
*/
public Set<String> topLevelKeySet() {
return topLevelMap().keySet();
}
/** /**
* Create a new Map<String, PreferenceMap> where keys are the first level of * Create a new Map<String, PreferenceMap> where keys are the first level of
* the current mapping. Top level pairs are discarded. E.g. the folowing * the current mapping. Top level pairs are discarded. E.g. the folowing