mirror of
https://github.com/arduino/Arduino.git
synced 2025-03-14 11:29:26 +01:00
Cache editor tools (don't create new instance for each menu item)
This commit is contained in:
parent
a15abacc7f
commit
1fd794dfdb
@ -198,6 +198,8 @@ public class Editor extends JFrame implements RunnerListener {
|
|||||||
private Runnable exportAppHandler;
|
private Runnable exportAppHandler;
|
||||||
private Runnable timeoutUploadHandler;
|
private Runnable timeoutUploadHandler;
|
||||||
|
|
||||||
|
private Map<String, Tool> internalToolCache = new HashMap<String, Tool>();
|
||||||
|
|
||||||
public Editor(Base ibase, File file, int[] storedLocation, int[] defaultLocation, Platform platform) throws Exception {
|
public Editor(Base ibase, File file, int[] storedLocation, int[] defaultLocation, Platform platform) throws Exception {
|
||||||
super("Arduino");
|
super("Arduino");
|
||||||
this.base = ibase;
|
this.base = ibase;
|
||||||
@ -963,8 +965,7 @@ public class Editor extends JFrame implements RunnerListener {
|
|||||||
|
|
||||||
JMenuItem createToolMenuItem(String className) {
|
JMenuItem createToolMenuItem(String className) {
|
||||||
try {
|
try {
|
||||||
Class<?> toolClass = Class.forName(className);
|
final Tool tool = getOrCreateToolInstance(className);
|
||||||
final Tool tool = (Tool) toolClass.newInstance();
|
|
||||||
|
|
||||||
JMenuItem item = new JMenuItem(tool.getMenuTitle());
|
JMenuItem item = new JMenuItem(tool.getMenuTitle());
|
||||||
|
|
||||||
@ -983,6 +984,20 @@ public class Editor extends JFrame implements RunnerListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Tool getOrCreateToolInstance(String className) {
|
||||||
|
Tool internalTool = internalToolCache.get(className);
|
||||||
|
if (internalTool == null) {
|
||||||
|
try {
|
||||||
|
Class<?> toolClass = Class.forName(className);
|
||||||
|
internalTool = (Tool) toolClass.newInstance();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
internalToolCache.put(className, internalTool);
|
||||||
|
}
|
||||||
|
return internalTool;
|
||||||
|
}
|
||||||
|
|
||||||
private void addInternalTools(JMenu menu) {
|
private void addInternalTools(JMenu menu) {
|
||||||
JMenuItem item;
|
JMenuItem item;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user