1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-02-20 14:54:31 +01:00

Fixed NPE when currently selected platform is no more installed.

BaseNoGui.getTargetBoard() now handles null TargetBoard.
Removed unused method Base.getTargetBoard()
This commit is contained in:
Cristian Maglie 2014-05-01 16:17:43 +02:00
parent ec67b0d4be
commit 56b9f1cd6f
3 changed files with 44 additions and 36 deletions

View File

@ -1077,6 +1077,10 @@ public class Base {
} }
public void rebuildBoardsMenu(JMenu toolsMenu, Editor editor) throws Exception { public void rebuildBoardsMenu(JMenu toolsMenu, Editor editor) throws Exception {
// If there are no platforms installed skip menu creation
if (BaseNoGui.packages.size() == 0)
return;
JMenu boardsMenu = getBoardCustomMenu(); JMenu boardsMenu = getBoardCustomMenu();
boolean first = true; boolean first = true;
@ -1698,11 +1702,6 @@ public class Base {
return BaseNoGui.getBoardPreferences(); return BaseNoGui.getBoardPreferences();
} }
public static TargetBoard getTargetBoard() {
String boardId = Preferences.get("board");
return getTargetPlatform().getBoard(boardId);
}
static public File getPortableFolder() { static public File getPortableFolder() {
return BaseNoGui.getPortableFolder(); return BaseNoGui.getPortableFolder();
} }

View File

@ -1,5 +1,3 @@
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/* /*
Part of the Processing project - http://processing.org Part of the Processing project - http://processing.org
@ -23,18 +21,23 @@
package processing.app; package processing.app;
import processing.app.helpers.OSUtils; import processing.app.helpers.OSUtils;
import processing.app.syntax.*;
import java.awt.*; import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D;
import java.util.Map;
import javax.swing.*; import javax.swing.JComponent;
import processing.app.helpers.PreferencesMap;
import processing.app.syntax.JEditTextArea;
/** /**
* Li'l status bar fella that shows the line number. * Li'l status bar fella that shows the line number.
*/ */
@SuppressWarnings("serial")
public class EditorLineStatus extends JComponent { public class EditorLineStatus extends JComponent {
JEditTextArea textarea; JEditTextArea textarea;
int start = -1, stop; int start = -1, stop;
@ -52,7 +55,6 @@ public class EditorLineStatus extends JComponent {
String name = ""; String name = "";
String serialport = ""; String serialport = "";
public EditorLineStatus(JEditTextArea textarea) { public EditorLineStatus(JEditTextArea textarea) {
this.textarea = textarea; this.textarea = textarea;
textarea.editorLineStatus = this; textarea.editorLineStatus = this;
@ -70,7 +72,6 @@ public class EditorLineStatus extends JComponent {
//linestatus.color = #FFFFFF //linestatus.color = #FFFFFF
} }
public void set(int newStart, int newStop) { public void set(int newStart, int newStop) {
if ((newStart == start) && (newStop == stop)) return; if ((newStart == start) && (newStop == stop)) return;
@ -93,11 +94,10 @@ public class EditorLineStatus extends JComponent {
repaint(); repaint();
} }
public void paintComponent(Graphics g) { public void paintComponent(Graphics g) {
if (name=="" && serialport=="") { if (name == "" && serialport == "") {
Map<String, String> boardPreferences = Base.getBoardPreferences(); PreferencesMap boardPreferences = Base.getBoardPreferences();
if (boardPreferences!=null) if (boardPreferences != null)
setBoardName(boardPreferences.get("name")); setBoardName(boardPreferences.get("name"));
else else
setBoardName("-"); setBoardName("-");
@ -124,8 +124,13 @@ public class EditorLineStatus extends JComponent {
} }
} }
public void setBoardName(String name) { this.name = name; } public void setBoardName(String name) {
public void setSerialPort(String serialport) { this.serialport = serialport; } this.name = name;
}
public void setSerialPort(String serialport) {
this.serialport = serialport;
}
public Dimension getPreferredSize() { public Dimension getPreferredSize() {
return new Dimension(300, high); return new Dimension(300, high);

View File

@ -152,6 +152,8 @@ public class BaseNoGui {
static public PreferencesMap getBoardPreferences() { static public PreferencesMap getBoardPreferences() {
TargetBoard board = getTargetBoard(); TargetBoard board = getTargetBoard();
if (board == null)
return null;
PreferencesMap prefs = new PreferencesMap(board.getPreferences()); PreferencesMap prefs = new PreferencesMap(board.getPreferences());
for (String menuId : board.getMenuIds()) { for (String menuId : board.getMenuIds()) {
@ -343,8 +345,11 @@ public class BaseNoGui {
} }
public static TargetBoard getTargetBoard() { public static TargetBoard getTargetBoard() {
TargetPlatform targetPlatform = getTargetPlatform();
if (targetPlatform == null)
return null;
String boardId = PreferencesData.get("board"); String boardId = PreferencesData.get("board");
return getTargetPlatform().getBoard(boardId); return targetPlatform.getBoard(boardId);
} }
/** /**
@ -669,28 +674,27 @@ public class BaseNoGui {
} }
static public void onBoardOrPortChange() { static public void onBoardOrPortChange() {
TargetPlatform targetPlatform = getTargetPlatform();
if (targetPlatform == null)
return;
// Calculate paths for libraries and examples
examplesFolder = getContentFile("examples"); examplesFolder = getContentFile("examples");
toolsFolder = getContentFile("tools"); toolsFolder = getContentFile("tools");
File platformFolder = targetPlatform.getFolder();
librariesFolders = new ArrayList<File>(); librariesFolders = new ArrayList<File>();
librariesFolders.add(getContentFile("libraries")); librariesFolders.add(getContentFile("libraries"));
String core = getBoardPreferences().get("build.core");
if (core.contains(":")) { // Add library folder for the current selected platform
String referencedCore = core.split(":")[0]; TargetPlatform targetPlatform = getTargetPlatform();
TargetPlatform referencedPlatform = getTargetPlatform(referencedCore, targetPlatform.getId()); if (targetPlatform != null) {
if (referencedPlatform != null) { String core = getBoardPreferences().get("build.core");
File referencedPlatformFolder = referencedPlatform.getFolder(); if (core.contains(":")) {
librariesFolders.add(new File(referencedPlatformFolder, "libraries")); String referencedCore = core.split(":")[0];
TargetPlatform referencedPlatform = getTargetPlatform(referencedCore, targetPlatform.getId());
if (referencedPlatform != null) {
File referencedPlatformFolder = referencedPlatform.getFolder();
librariesFolders.add(new File(referencedPlatformFolder, "libraries"));
}
} }
File platformFolder = targetPlatform.getFolder();
librariesFolders.add(new File(platformFolder, "libraries"));
librariesFolders.add(getSketchbookLibrariesFolder());
} }
librariesFolders.add(new File(platformFolder, "libraries"));
librariesFolders.add(getSketchbookLibrariesFolder());
// Scan for libraries in each library folder. // Scan for libraries in each library folder.
// Libraries located in the latest folders on the list can override // Libraries located in the latest folders on the list can override