Skip to content

Commit 9ce5101

Browse files
authored
Merge branch 'master' into add-file-cache
2 parents 3c5dbe6 + ba34eb6 commit 9ce5101

File tree

65 files changed

+1006
-227
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1006
-227
lines changed

Diff for: app/lib/jssc-2.8.0-arduino3.jar

-160 KB
Binary file not shown.

Diff for: app/lib/jssc-2.8.0-arduino4.jar

159 KB
Binary file not shown.

Diff for: app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellJPanel.java

+1
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ public ContributedLibraryTableCellJPanel(JTable parentTable, Object value,
213213
}
214214
}
215215

216+
// TODO Make this a method of Theme
216217
private JTextPane makeNewDescription() {
217218
if (getComponentCount() > 0) {
218219
remove(0);

Diff for: app/src/cc/arduino/contributions/libraries/ui/LibraryManagerUI.java

+22-3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import cc.arduino.contributions.libraries.ContributedLibraryReleases;
5353
import cc.arduino.contributions.libraries.LibraryInstaller;
5454
import cc.arduino.contributions.libraries.LibraryTypeComparator;
55+
import cc.arduino.contributions.libraries.ui.MultiLibraryInstallDialog.Result;
5556
import cc.arduino.contributions.ui.DropdownItem;
5657
import cc.arduino.contributions.ui.FilteredAbstractTableModel;
5758
import cc.arduino.contributions.ui.InstallerJDialog;
@@ -85,7 +86,7 @@ protected void onInstall(ContributedLibrary selectedLibrary, Optional<Contribute
8586
if (mayInstalledLibrary.isPresent() && selectedLibrary.isIDEBuiltIn()) {
8687
onRemovePressed(mayInstalledLibrary.get());
8788
} else {
88-
onInstallPressed(selectedLibrary, mayInstalledLibrary);
89+
onInstallPressed(selectedLibrary);
8990
}
9091
}
9192

@@ -213,12 +214,30 @@ protected void onUpdatePressed() {
213214
installerThread.start();
214215
}
215216

216-
public void onInstallPressed(final ContributedLibrary lib, final Optional<ContributedLibrary> mayReplaced) {
217+
public void onInstallPressed(final ContributedLibrary lib) {
218+
List<ContributedLibrary> deps = BaseNoGui.librariesIndexer.getIndex().resolveDependeciesOf(lib);
219+
boolean depsInstalled = deps.stream().allMatch(l -> l.getInstalledLibrary().isPresent() || l.getName().equals(lib.getName()));
220+
Result installDeps;
221+
if (!depsInstalled) {
222+
MultiLibraryInstallDialog dialog;
223+
dialog = new MultiLibraryInstallDialog(this, lib, deps);
224+
dialog.setLocationRelativeTo(this);
225+
dialog.setVisible(true);
226+
installDeps = dialog.getInstallDepsResult();
227+
if (installDeps == Result.CANCEL)
228+
return;
229+
} else {
230+
installDeps = Result.NONE;
231+
}
217232
clearErrorMessage();
218233
installerThread = new Thread(() -> {
219234
try {
220235
setProgressVisible(true, tr("Installing..."));
221-
installer.install(lib, mayReplaced, this::setProgress);
236+
if (installDeps == Result.ALL) {
237+
installer.install(deps, this::setProgress);
238+
} else {
239+
installer.install(lib, this::setProgress);
240+
}
222241
// TODO: Do a better job in refreshing only the needed element
223242
if (contribTable.getCellEditor() != null) {
224243
contribTable.getCellEditor().stopCellEditing();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
/*
2+
* This file is part of Arduino.
3+
*
4+
* Copyright 2017 Arduino LLC (http://www.arduino.cc/)
5+
*
6+
* Arduino is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation; either version 2 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program; if not, write to the Free Software
18+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19+
*
20+
* As a special exception, you may use this file as part of a free software
21+
* library without restriction. Specifically, if other files instantiate
22+
* templates or use macros or inline functions from this file, or you compile
23+
* this file and link it with other files to produce an executable, this
24+
* file does not by itself cause the resulting executable to be covered by
25+
* the GNU General Public License. This exception does not however
26+
* invalidate any other reasons why the executable file might be covered by
27+
* the GNU General Public License.
28+
*/
29+
30+
package cc.arduino.contributions.libraries.ui;
31+
32+
import static processing.app.I18n.format;
33+
import static processing.app.I18n.tr;
34+
35+
import java.awt.BorderLayout;
36+
import java.awt.Container;
37+
import java.awt.Insets;
38+
import java.awt.Window;
39+
import java.awt.event.WindowEvent;
40+
import java.util.List;
41+
42+
import javax.swing.Box;
43+
import javax.swing.BoxLayout;
44+
import javax.swing.JButton;
45+
import javax.swing.JDialog;
46+
import javax.swing.JPanel;
47+
import javax.swing.JTextPane;
48+
import javax.swing.WindowConstants;
49+
import javax.swing.border.EmptyBorder;
50+
import javax.swing.text.Document;
51+
import javax.swing.text.html.HTMLDocument;
52+
import javax.swing.text.html.StyleSheet;
53+
54+
import cc.arduino.contributions.libraries.ContributedLibrary;
55+
import cc.arduino.contributions.libraries.UnavailableContributedLibrary;
56+
import processing.app.Base;
57+
import processing.app.Theme;
58+
59+
public class MultiLibraryInstallDialog extends JDialog {
60+
61+
enum Result {
62+
ALL, NONE, CANCEL
63+
}
64+
65+
private Result result = Result.CANCEL;
66+
67+
public MultiLibraryInstallDialog(Window parent, ContributedLibrary lib,
68+
List<ContributedLibrary> dependencies) {
69+
super(parent, format(tr("Dependencies for library {0}:{1}"), lib.getName(),
70+
lib.getParsedVersion()),
71+
ModalityType.APPLICATION_MODAL);
72+
Container pane = getContentPane();
73+
pane.setLayout(new BorderLayout());
74+
75+
pane.add(Box.createHorizontalStrut(10), BorderLayout.WEST);
76+
pane.add(Box.createHorizontalStrut(10), BorderLayout.EAST);
77+
78+
{
79+
JButton cancel = new JButton(tr("Cancel"));
80+
cancel.addActionListener(ev -> {
81+
result = Result.CANCEL;
82+
setVisible(false);
83+
});
84+
85+
JButton all = new JButton(tr("Install all"));
86+
all.addActionListener(ev -> {
87+
result = Result.ALL;
88+
setVisible(false);
89+
});
90+
91+
JButton none = new JButton(format(tr("Install '{0}' only"), lib.getName()));
92+
none.addActionListener(ev -> {
93+
result = Result.NONE;
94+
setVisible(false);
95+
});
96+
97+
Box buttonsBox = Box.createHorizontalBox();
98+
buttonsBox.add(all);
99+
buttonsBox.add(Box.createHorizontalStrut(5));
100+
buttonsBox.add(none);
101+
buttonsBox.add(Box.createHorizontalStrut(5));
102+
buttonsBox.add(cancel);
103+
104+
JPanel buttonsPanel = new JPanel();
105+
buttonsPanel.setBorder(new EmptyBorder(7, 10, 7, 10));
106+
buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.Y_AXIS));
107+
buttonsPanel.add(buttonsBox);
108+
109+
pane.add(buttonsPanel, BorderLayout.SOUTH);
110+
}
111+
112+
{
113+
String libName = format("<b>{0}:{1}</b>", lib.getName(),
114+
lib.getParsedVersion());
115+
String desc = format(tr("The library {0} needs some other library<br />dependencies currently not installed:"),
116+
libName);
117+
desc += "<br/><br/>";
118+
for (ContributedLibrary l : dependencies) {
119+
if (l.getName().equals(lib.getName()))
120+
continue;
121+
if (l.getInstalledLibrary().isPresent())
122+
continue;
123+
if (l instanceof UnavailableContributedLibrary)
124+
continue;
125+
desc += format("- <b>{0}</b><br/>", l.getName());
126+
}
127+
desc += "<br/>";
128+
desc += tr("Would you like to install also all the missing dependencies?");
129+
130+
JTextPane textArea = makeNewDescription();
131+
textArea.setContentType("text/html");
132+
textArea.setText(desc);
133+
134+
JPanel libsList = new JPanel();
135+
libsList.setLayout(new BoxLayout(libsList, BoxLayout.Y_AXIS));
136+
libsList.add(textArea);
137+
libsList.setBorder(new EmptyBorder(7, 7, 7, 7));
138+
pane.add(libsList, BorderLayout.NORTH);
139+
}
140+
141+
pack();
142+
setResizable(false);
143+
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
144+
145+
WindowEvent closing = new WindowEvent(this, WindowEvent.WINDOW_CLOSING);
146+
Base.registerWindowCloseKeys(getRootPane(), e -> dispatchEvent(closing));
147+
}
148+
149+
// TODO Make this a method of Theme
150+
private JTextPane makeNewDescription() {
151+
JTextPane description = new JTextPane();
152+
description.setInheritsPopupMenu(true);
153+
Insets margin = description.getMargin();
154+
margin.bottom = 0;
155+
description.setMargin(margin);
156+
description.setContentType("text/html");
157+
Document doc = description.getDocument();
158+
if (doc instanceof HTMLDocument) {
159+
HTMLDocument html = (HTMLDocument) doc;
160+
StyleSheet s = html.getStyleSheet();
161+
s.addRule("body { margin: 0; padding: 0;"
162+
+ "font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;"
163+
+ "color: black;" + "font-size: " + 15 * Theme.getScale() / 100
164+
+ "; }");
165+
}
166+
description.setOpaque(false);
167+
description.setBorder(new EmptyBorder(4, 7, 7, 7));
168+
description.setHighlighter(null);
169+
description.setEditable(false);
170+
add(description, 0);
171+
return description;
172+
}
173+
174+
public Result getInstallDepsResult() {
175+
return result;
176+
}
177+
}

Diff for: app/src/cc/arduino/packages/MonitorFactory.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,23 @@
3030
package cc.arduino.packages;
3131

3232
import processing.app.AbstractMonitor;
33-
import processing.app.Base;
3433
import processing.app.NetworkMonitor;
3534
import processing.app.SerialMonitor;
3635

3736
public class MonitorFactory {
3837

39-
public AbstractMonitor newMonitor(Base base, BoardPort port) {
38+
public AbstractMonitor newMonitor(BoardPort port) {
4039
if ("network".equals(port.getProtocol())) {
4140
if ("yes".equals(port.getPrefs().get("ssh_upload"))) {
4241
// the board is SSH capable
43-
return new NetworkMonitor(base, port);
42+
return new NetworkMonitor(port);
4443
} else {
4544
// SSH not supported, no monitor support
4645
return null;
4746
}
4847
}
4948

50-
return new SerialMonitor(base, port);
49+
return new SerialMonitor(port);
5150
}
5251

5352
}

Diff for: app/src/processing/app/AbstractMonitor.java

+28
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package processing.app;
22

33
import cc.arduino.packages.BoardPort;
4+
import cc.arduino.packages.DiscoveryManager;
45
import processing.app.legacy.PApplet;
56

67
import javax.swing.*;
@@ -9,6 +10,7 @@
910
import java.awt.event.ActionListener;
1011
import java.awt.event.WindowAdapter;
1112
import java.awt.event.WindowEvent;
13+
import java.util.List;
1214

1315
@SuppressWarnings("serial")
1416
public abstract class AbstractMonitor extends JFrame implements ActionListener {
@@ -17,6 +19,7 @@ public abstract class AbstractMonitor extends JFrame implements ActionListener {
1719

1820
private StringBuffer updateBuffer;
1921
private Timer updateTimer;
22+
private Timer portExistsTimer;
2023

2124
private BoardPort boardPort;
2225

@@ -73,6 +76,26 @@ public void actionPerformed(ActionEvent event) {
7376
updateTimer = new Timer(33, this); // redraw serial monitor at 30 Hz
7477
updateTimer.start();
7578

79+
ActionListener portExists = new ActionListener() {
80+
@Override
81+
public void actionPerformed(ActionEvent ae) {
82+
try {
83+
if (!Base.getDiscoveryManager().discovery().contains(boardPort)) {
84+
if (!closed) {
85+
suspend();
86+
}
87+
} else {
88+
if (closed && (Editor.avoidMultipleOperations == false)) {
89+
resume(boardPort);
90+
}
91+
}
92+
} catch (Exception e) {}
93+
}
94+
};
95+
96+
portExistsTimer = new Timer(1000, portExists); // check if the port is still there every second
97+
portExistsTimer.start();
98+
7699
closed = false;
77100
}
78101

@@ -92,6 +115,11 @@ public void suspend() throws Exception {
92115
close();
93116
}
94117

118+
public void dispose() {
119+
super.dispose();
120+
portExistsTimer.stop();
121+
}
122+
95123
public void resume(BoardPort boardPort) throws Exception {
96124
setBoardPort(boardPort);
97125

Diff for: app/src/processing/app/AbstractTextMonitor.java

+17-6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import java.awt.Font;
99
import java.awt.event.ActionEvent;
1010
import java.awt.event.ActionListener;
11+
import java.awt.event.KeyListener;
12+
import java.awt.event.MouseWheelListener;
1113
import java.awt.event.WindowAdapter;
1214
import java.awt.event.WindowEvent;
1315
import java.text.SimpleDateFormat;
@@ -46,12 +48,21 @@ public abstract class AbstractTextMonitor extends AbstractMonitor {
4648
protected JComboBox<String> lineEndings;
4749
protected JComboBox<String> serialRates;
4850

49-
public AbstractTextMonitor(Base base, BoardPort boardPort) {
51+
public AbstractTextMonitor(BoardPort boardPort) {
5052
super(boardPort);
53+
}
5154

52-
// Add font size adjustment listeners. This has to be done here due to
53-
// super(boardPort) invoking onCreateWindow(...) before we can store base.
54-
base.addEditorFontResizeListeners(textArea);
55+
@Override
56+
public synchronized void addMouseWheelListener(MouseWheelListener l) {
57+
super.addMouseWheelListener(l);
58+
textArea.addMouseWheelListener(l);
59+
}
60+
61+
@Override
62+
public synchronized void addKeyListener(KeyListener l) {
63+
super.addKeyListener(l);
64+
textArea.addKeyListener(l);
65+
textField.addKeyListener(l);
5566
}
5667

5768
@Override
@@ -125,7 +136,7 @@ public void windowGainedFocus(WindowEvent e) {
125136
minimumSize.setSize(minimumSize.getWidth() / 3, minimumSize.getHeight());
126137
noLineEndingAlert.setMinimumSize(minimumSize);
127138

128-
lineEndings = new JComboBox<String>(new String[]{tr("No line ending"), tr("Newline"), tr("Carriage return"), tr("Both NL & CR")});
139+
lineEndings = new JComboBox<>(new String[]{tr("No line ending"), tr("Newline"), tr("Carriage return"), tr("Both NL & CR")});
129140
lineEndings.addActionListener((ActionEvent event) -> {
130141
PreferencesData.setInteger("serial.line_ending", lineEndings.getSelectedIndex());
131142
noLineEndingAlert.setForeground(pane.getBackground());
@@ -135,7 +146,7 @@ public void windowGainedFocus(WindowEvent e) {
135146

136147
lineEndings.setMaximumSize(lineEndings.getMinimumSize());
137148

138-
serialRates = new JComboBox<String>();
149+
serialRates = new JComboBox<>();
139150
for (String rate : serialRateStrings) {
140151
serialRates.addItem(rate + " " + tr("baud"));
141152
}

0 commit comments

Comments
 (0)