mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-17 11:54:33 +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:
parent
ec67b0d4be
commit
56b9f1cd6f
@ -1077,6 +1077,10 @@ public class Base {
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
boolean first = true;
|
||||
@ -1698,11 +1702,6 @@ public class Base {
|
||||
return BaseNoGui.getBoardPreferences();
|
||||
}
|
||||
|
||||
public static TargetBoard getTargetBoard() {
|
||||
String boardId = Preferences.get("board");
|
||||
return getTargetPlatform().getBoard(boardId);
|
||||
}
|
||||
|
||||
static public File getPortableFolder() {
|
||||
return BaseNoGui.getPortableFolder();
|
||||
}
|
||||
|
@ -1,5 +1,3 @@
|
||||
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
|
||||
/*
|
||||
Part of the Processing project - http://processing.org
|
||||
|
||||
@ -23,18 +21,23 @@
|
||||
package processing.app;
|
||||
|
||||
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.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.
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class EditorLineStatus extends JComponent {
|
||||
JEditTextArea textarea;
|
||||
int start = -1, stop;
|
||||
@ -52,7 +55,6 @@ public class EditorLineStatus extends JComponent {
|
||||
String name = "";
|
||||
String serialport = "";
|
||||
|
||||
|
||||
public EditorLineStatus(JEditTextArea textarea) {
|
||||
this.textarea = textarea;
|
||||
textarea.editorLineStatus = this;
|
||||
@ -70,7 +72,6 @@ public class EditorLineStatus extends JComponent {
|
||||
//linestatus.color = #FFFFFF
|
||||
}
|
||||
|
||||
|
||||
public void set(int newStart, int newStop) {
|
||||
if ((newStart == start) && (newStop == stop)) return;
|
||||
|
||||
@ -93,11 +94,10 @@ public class EditorLineStatus extends JComponent {
|
||||
repaint();
|
||||
}
|
||||
|
||||
|
||||
public void paintComponent(Graphics g) {
|
||||
if (name=="" && serialport=="") {
|
||||
Map<String, String> boardPreferences = Base.getBoardPreferences();
|
||||
if (boardPreferences!=null)
|
||||
if (name == "" && serialport == "") {
|
||||
PreferencesMap boardPreferences = Base.getBoardPreferences();
|
||||
if (boardPreferences != null)
|
||||
setBoardName(boardPreferences.get("name"));
|
||||
else
|
||||
setBoardName("-");
|
||||
@ -124,8 +124,13 @@ public class EditorLineStatus extends JComponent {
|
||||
}
|
||||
}
|
||||
|
||||
public void setBoardName(String name) { this.name = name; }
|
||||
public void setSerialPort(String serialport) { this.serialport = serialport; }
|
||||
public void setBoardName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setSerialPort(String serialport) {
|
||||
this.serialport = serialport;
|
||||
}
|
||||
|
||||
public Dimension getPreferredSize() {
|
||||
return new Dimension(300, high);
|
||||
|
@ -152,6 +152,8 @@ public class BaseNoGui {
|
||||
|
||||
static public PreferencesMap getBoardPreferences() {
|
||||
TargetBoard board = getTargetBoard();
|
||||
if (board == null)
|
||||
return null;
|
||||
|
||||
PreferencesMap prefs = new PreferencesMap(board.getPreferences());
|
||||
for (String menuId : board.getMenuIds()) {
|
||||
@ -343,8 +345,11 @@ public class BaseNoGui {
|
||||
}
|
||||
|
||||
public static TargetBoard getTargetBoard() {
|
||||
TargetPlatform targetPlatform = getTargetPlatform();
|
||||
if (targetPlatform == null)
|
||||
return null;
|
||||
String boardId = PreferencesData.get("board");
|
||||
return getTargetPlatform().getBoard(boardId);
|
||||
return targetPlatform.getBoard(boardId);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -669,28 +674,27 @@ public class BaseNoGui {
|
||||
}
|
||||
|
||||
static public void onBoardOrPortChange() {
|
||||
TargetPlatform targetPlatform = getTargetPlatform();
|
||||
if (targetPlatform == null)
|
||||
return;
|
||||
|
||||
// Calculate paths for libraries and examples
|
||||
examplesFolder = getContentFile("examples");
|
||||
toolsFolder = getContentFile("tools");
|
||||
|
||||
File platformFolder = targetPlatform.getFolder();
|
||||
librariesFolders = new ArrayList<File>();
|
||||
librariesFolders.add(getContentFile("libraries"));
|
||||
String core = getBoardPreferences().get("build.core");
|
||||
if (core.contains(":")) {
|
||||
String referencedCore = core.split(":")[0];
|
||||
TargetPlatform referencedPlatform = getTargetPlatform(referencedCore, targetPlatform.getId());
|
||||
if (referencedPlatform != null) {
|
||||
File referencedPlatformFolder = referencedPlatform.getFolder();
|
||||
librariesFolders.add(new File(referencedPlatformFolder, "libraries"));
|
||||
|
||||
// Add library folder for the current selected platform
|
||||
TargetPlatform targetPlatform = getTargetPlatform();
|
||||
if (targetPlatform != null) {
|
||||
String core = getBoardPreferences().get("build.core");
|
||||
if (core.contains(":")) {
|
||||
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.
|
||||
// Libraries located in the latest folders on the list can override
|
||||
|
Loading…
x
Reference in New Issue
Block a user