Skip to content

Use a Event-Driven model to speed up IDE (FIX #10214 #10235) #10249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,6 @@
<classpathentry kind="lib" path="lib/jtouchbar-1.0.0.jar"/>
<classpathentry kind="lib" path="lib/commons-lang3-3.8.1.jar"/>
<classpathentry kind="lib" path="lib/jssc-2.8.0-arduino4.jar"/>
<classpathentry kind="lib" path="lib/eventbus4j-0.0.1.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Binary file added app/lib/eventbus4j-0.0.1.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ private void builtInPackageIsNewerCheck() throws InterruptedException {
return;
}

while (!base.hasActiveEditor()) {
Thread.sleep(100);
}
base.getWaitActiveEditor();

if (VersionComparator.greaterThan(installedBuiltIn.getParsedVersion(), installedNotBuiltIn.getParsedVersion())) {
SwingUtilities.invokeLater(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public void run() {
}

SwingUtilities.invokeLater(() -> {
Editor ed = base.getActiveEditor();
Editor ed = base.getWaitActiveEditor();
boolean accessibleIde = PreferencesData.getBoolean("ide.accessible");
if (accessibleIde) {
notificationPopup = new NotificationPopup(ed, hyperlinkListener, text, false, this, button1Name, button2Name);
Expand Down
105 changes: 105 additions & 0 deletions app/src/cc/arduino/view/JMenuLazy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package cc.arduino.view;

import java.awt.Component;
import java.util.LinkedList;

import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.JSeparator;
import javax.swing.event.MenuEvent;
import javax.swing.event.MenuListener;

/**
* Avoid slow rendering of menu while load full menu tree in background
*
* @author Ricardo JL Rufino - ([email protected])
* @date 13 de mai de 2020
*/
public class JMenuLazy extends JMenu {

private LinkedList<Component> components = new LinkedList<>();

private boolean loading = false;

public JMenuLazy(String s) {
super(s);
addMenuListener(menuListener);
}

public void setLoading(boolean loading) {
this.loading = loading;
this.setEnabled(!loading);
}

public boolean isLoading() {
return loading;
}

@Override
public Component add(Component c) {
if (isLoading()) {
components.add(c);
return c;
}
return super.add(c);
}

@Override
public JMenuItem add(JMenuItem c) {
if (isLoading()) {
components.add(c);
return c;
}
return super.add(c);
}

@Override
public void addSeparator() {
if (isLoading()) {
components.add(new JPopupMenu.Separator());
return;
}
super.addSeparator();
}

public void removeAll() {
super.removeAll();
synchronized (components) {
components.clear();
}
};

private MenuListener menuListener = new MenuListener() {

@Override
public void menuSelected(MenuEvent e) {
if (!isLoading()) {
if (loading == false) {
if (!components.isEmpty()) {
for (Component component : components) {
if (component instanceof JSeparator) {
JMenuLazy.super.addSeparator();
} else {
JMenuLazy.super.add(component);

}
}
components.clear();
}
}
}
}

@Override
public void menuDeselected(MenuEvent e) {

}

@Override
public void menuCanceled(MenuEvent e) {

}
};

}
24 changes: 24 additions & 0 deletions app/src/cc/arduino/view/SplashScreenHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public class SplashScreenHelper {
private final SplashScreen splash;
private Rectangle2D.Double splashTextArea;
private Graphics2D splashGraphics;
private int progress = 0;
private String text;

public SplashScreenHelper(SplashScreen splash) {
this.splash = splash;
Expand All @@ -58,8 +60,19 @@ public SplashScreenHelper(SplashScreen splash) {
desktopHints = null;
}
}

public void setProgress(int progress) {
this.progress = progress;
splashText(text);
}

public void splashText(String text, int progress) {
this.progress = progress;
splashText(text);
}

public void splashText(String text) {
this.text = text;
if (splash == null) {
printText(text);
return;
Expand All @@ -76,10 +89,13 @@ public void splashText(String text) {
eraseLastStatusText();

drawText(text);

if(progress > 0) drawProgress();

ensureTextIsDiplayed();
}


private void ensureTextIsDiplayed() {
synchronized (SplashScreen.class) {
if (splash.isVisible()) {
Expand All @@ -88,6 +104,14 @@ private void ensureTextIsDiplayed() {
}
}


private void drawProgress() {
splashGraphics.setPaint(new Color(0, 100, 104));
splashGraphics.setStroke(new BasicStroke(2));
int w = (int)(splashTextArea.getWidth()*(progress/100.0f));
splashGraphics.drawLine( (int) splashTextArea.getX(), (int) splashTextArea.getY(), (int) splashTextArea.getX() + w, (int) splashTextArea.getY());
}

private void drawText(String str) {
splashGraphics.setPaint(Color.BLACK);
FontMetrics metrics = splashGraphics.getFontMetrics();
Expand Down
11 changes: 11 additions & 0 deletions app/src/cc/arduino/view/preferences/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ private void initComponents() {
checkUpdatesBox = new javax.swing.JCheckBox();
saveVerifyUploadBox = new javax.swing.JCheckBox();
accessibleIDEBox = new javax.swing.JCheckBox();
checkRestoreSketch = new javax.swing.JCheckBox();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
scaleSpinner = new javax.swing.JSpinner();
Expand Down Expand Up @@ -284,6 +285,9 @@ public void mouseEntered(java.awt.event.MouseEvent evt) {

accessibleIDEBox.setText(tr("Use accessibility features"));
checkboxesContainer.add(accessibleIDEBox);

checkRestoreSketch.setText(tr("Ask to restore sketches"));
checkboxesContainer.add(checkRestoreSketch);

jLabel1.setText(tr("Interface scale:"));

Expand Down Expand Up @@ -718,6 +722,7 @@ private void autoScaleCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//
private javax.swing.JButton browseButton;
private javax.swing.JCheckBox checkUpdatesBox;
private javax.swing.JCheckBox accessibleIDEBox;
private javax.swing.JCheckBox checkRestoreSketch;
private javax.swing.JPanel checkboxesContainer;
private javax.swing.JComboBox comboLanguage;
private javax.swing.JLabel comboLanguageLabel;
Expand Down Expand Up @@ -832,6 +837,10 @@ private void savePreferencesData() {
PreferencesData.setBoolean("update.check", checkUpdatesBox.isSelected());

PreferencesData.setBoolean("ide.accessible", accessibleIDEBox.isSelected());

if(checkRestoreSketch.isSelected()) {
PreferencesData.set("last.sketch.restore", "ask");
}

PreferencesData.set("boardsmanager.additional.urls", additionalBoardsManagerField.getText().replace("\r\n", "\n").replace("\r", "\n").replace("\n", ","));

Expand Down Expand Up @@ -912,6 +921,8 @@ private void showPreferencesData() {
}

accessibleIDEBox.setSelected(PreferencesData.getBoolean("ide.accessible"));

checkRestoreSketch.setSelected(PreferencesData.get("last.sketch.restore", "ask").equals("ask"));

saveVerifyUploadBox.setSelected(PreferencesData.getBoolean("editor.save_on_verify"));

Expand Down
2 changes: 1 addition & 1 deletion app/src/log4j2.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn" name="Arduino" packages="cc.arduino">
<Configuration status="warn" name="Arduino" >
<Appenders>

<!-- Console Appender -->
Expand Down
Loading