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

View File

@ -53,15 +53,52 @@ public class TargetBoard {
return prefs;
}
public void setMenuOptions(String menuId, PreferencesMap _menuOptions) {
menuOptions.put(menuId, _menuOptions);
}
public PreferencesMap getMenuOptions(String menuId) {
return menuOptions.get(menuId);
}
public boolean hasMenuOptions(String menuId) {
/**
* Check if the board has a sub menu.
*
* @param menuId
* The menu ID to check
* @return
*/
public boolean hasMenu(String 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.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import processing.app.helpers.PreferencesMap;
@ -131,6 +132,10 @@ public class TargetPlatform {
return customMenus;
}
public Set<String> getCustomMenusKeys() {
return customMenus.keySet();
}
public Map<String, PreferencesMap> getProgrammers() {
return programmers;
}

View File

@ -28,7 +28,6 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
@ -155,64 +154,6 @@ public class PreferencesMap extends LinkedHashMap<String, String> {
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
* the current mapping. Top level pairs are discarded. E.g. the folowing