mirror of
https://github.com/arduino/Arduino.git
synced 2025-03-13 10:29:35 +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 timeoutUploadHandler;
|
||||
|
||||
private Map<String, Tool> internalToolCache = new HashMap<String, Tool>();
|
||||
|
||||
public Editor(Base ibase, File file, int[] storedLocation, int[] defaultLocation, Platform platform) throws Exception {
|
||||
super("Arduino");
|
||||
this.base = ibase;
|
||||
@ -963,8 +965,7 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
|
||||
JMenuItem createToolMenuItem(String className) {
|
||||
try {
|
||||
Class<?> toolClass = Class.forName(className);
|
||||
final Tool tool = (Tool) toolClass.newInstance();
|
||||
final Tool tool = getOrCreateToolInstance(className);
|
||||
|
||||
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) {
|
||||
JMenuItem item;
|
||||
|
Loading…
x
Reference in New Issue
Block a user