Debian Codegraph @

arduino-core/src/processing/app/debug/LegacyTargetBoard.java

raw symbols SCIP
1 /*
2 TargetPackage - Represents a hardware package
3 Part of the Arduino project - http://www.arduino.cc/
4
5 Copyright (c) 2014 Cristian Maglie
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software Foundation,
19 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21 package processing.app.debug;
22
23 import processing.app.helpers.PreferencesMap;
24
25 import java.util.LinkedHashMap;
26 import java.util.Map;
27 import java.util.Set;
28
29 public class LegacyTargetBoard implements TargetBoard {
30
31 private final String id;
32 private final PreferencesMap prefs;
33 private Map<String, PreferencesMap> menuOptions = new LinkedHashMap<>();
34 private final TargetPlatform containerPlatform;
35
36 /**
37 * Create a TargetBoard based on preferences passed as argument.
38 */
39 public LegacyTargetBoard(String _id, PreferencesMap _prefs,
40 TargetPlatform parent) {
41 containerPlatform = parent;
42 id = _id;
43 prefs = new PreferencesMap(_prefs);
44
45 // Setup sub-menus
46 PreferencesMap menus = prefs.firstLevelMap().get("menu");
47 if (menus != null)
48 menuOptions = menus.firstLevelMap();
49
50 // Auto generate build.board if not set
51 if (!prefs.containsKey("build.board")) {
52 String board = containerPlatform.getId() + "_" + id;
53 board = board.toUpperCase();
54 prefs.put("build.board", board);
55 }
56 }
57
58 @Override
59 public String getName() {
60 return prefs.get("name");
61 }
62
63 @Override
64 public String getId() {
65 return id;
66 }
67
68 @Override
69 public PreferencesMap getPreferences() {
70 return prefs;
71 }
72
73 @Override
74 public boolean hasMenu(String menuId) {
75 return menuOptions.containsKey(menuId);
76 }
77
78 @Override
79 public PreferencesMap getMenuLabels(String menuId) {
80 return menuOptions.get(menuId).topLevelMap();
81 }
82
83 @Override
84 public String getMenuLabel(String menuId, String selectionId) {
85 return getMenuLabels(menuId).get(selectionId);
86 }
87
88 @Override
89 public Set<String> getMenuIds() {
90 return menuOptions.keySet();
91 }
92
93 @Override
94 public PreferencesMap getMenuPreferences(String menuId, String selectionId) {
95 return menuOptions.get(menuId).subTree(selectionId);
96 }
97
98 @Override
99 public TargetPlatform getContainerPlatform() {
100 return containerPlatform;
101 }
102
103 @Override
104 public String getFQBN() {
105 return getContainerPlatform().getContainerPackage().getId() + ":" + getContainerPlatform().getId() + ":" + getId();
106 }
107 }