Skip to content

Commit

Permalink
Merge branch 'master' into add-file-cache
Browse files Browse the repository at this point in the history
  • Loading branch information
facchinm authored Jul 18, 2019
2 parents 3c5dbe6 + ba34eb6 commit 9ce5101
Show file tree
Hide file tree
Showing 65 changed files with 1,006 additions and 227 deletions.
Binary file removed app/lib/jssc-2.8.0-arduino3.jar
Binary file not shown.
Binary file added app/lib/jssc-2.8.0-arduino4.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ public ContributedLibraryTableCellJPanel(JTable parentTable, Object value,
}
}

// TODO Make this a method of Theme
private JTextPane makeNewDescription() {
if (getComponentCount() > 0) {
remove(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import cc.arduino.contributions.libraries.ContributedLibraryReleases;
import cc.arduino.contributions.libraries.LibraryInstaller;
import cc.arduino.contributions.libraries.LibraryTypeComparator;
import cc.arduino.contributions.libraries.ui.MultiLibraryInstallDialog.Result;
import cc.arduino.contributions.ui.DropdownItem;
import cc.arduino.contributions.ui.FilteredAbstractTableModel;
import cc.arduino.contributions.ui.InstallerJDialog;
Expand Down Expand Up @@ -85,7 +86,7 @@ protected void onInstall(ContributedLibrary selectedLibrary, Optional<Contribute
if (mayInstalledLibrary.isPresent() && selectedLibrary.isIDEBuiltIn()) {
onRemovePressed(mayInstalledLibrary.get());
} else {
onInstallPressed(selectedLibrary, mayInstalledLibrary);
onInstallPressed(selectedLibrary);
}
}

Expand Down Expand Up @@ -213,12 +214,30 @@ protected void onUpdatePressed() {
installerThread.start();
}

public void onInstallPressed(final ContributedLibrary lib, final Optional<ContributedLibrary> mayReplaced) {
public void onInstallPressed(final ContributedLibrary lib) {
List<ContributedLibrary> deps = BaseNoGui.librariesIndexer.getIndex().resolveDependeciesOf(lib);
boolean depsInstalled = deps.stream().allMatch(l -> l.getInstalledLibrary().isPresent() || l.getName().equals(lib.getName()));
Result installDeps;
if (!depsInstalled) {
MultiLibraryInstallDialog dialog;
dialog = new MultiLibraryInstallDialog(this, lib, deps);
dialog.setLocationRelativeTo(this);
dialog.setVisible(true);
installDeps = dialog.getInstallDepsResult();
if (installDeps == Result.CANCEL)
return;
} else {
installDeps = Result.NONE;
}
clearErrorMessage();
installerThread = new Thread(() -> {
try {
setProgressVisible(true, tr("Installing..."));
installer.install(lib, mayReplaced, this::setProgress);
if (installDeps == Result.ALL) {
installer.install(deps, this::setProgress);
} else {
installer.install(lib, this::setProgress);
}
// TODO: Do a better job in refreshing only the needed element
if (contribTable.getCellEditor() != null) {
contribTable.getCellEditor().stopCellEditing();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
/*
* This file is part of Arduino.
*
* Copyright 2017 Arduino LLC (http://www.arduino.cc/)
*
* Arduino is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*/

package cc.arduino.contributions.libraries.ui;

import static processing.app.I18n.format;
import static processing.app.I18n.tr;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Insets;
import java.awt.Window;
import java.awt.event.WindowEvent;
import java.util.List;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JTextPane;
import javax.swing.WindowConstants;
import javax.swing.border.EmptyBorder;
import javax.swing.text.Document;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.StyleSheet;

import cc.arduino.contributions.libraries.ContributedLibrary;
import cc.arduino.contributions.libraries.UnavailableContributedLibrary;
import processing.app.Base;
import processing.app.Theme;

public class MultiLibraryInstallDialog extends JDialog {

enum Result {
ALL, NONE, CANCEL
}

private Result result = Result.CANCEL;

public MultiLibraryInstallDialog(Window parent, ContributedLibrary lib,
List<ContributedLibrary> dependencies) {
super(parent, format(tr("Dependencies for library {0}:{1}"), lib.getName(),
lib.getParsedVersion()),
ModalityType.APPLICATION_MODAL);
Container pane = getContentPane();
pane.setLayout(new BorderLayout());

pane.add(Box.createHorizontalStrut(10), BorderLayout.WEST);
pane.add(Box.createHorizontalStrut(10), BorderLayout.EAST);

{
JButton cancel = new JButton(tr("Cancel"));
cancel.addActionListener(ev -> {
result = Result.CANCEL;
setVisible(false);
});

JButton all = new JButton(tr("Install all"));
all.addActionListener(ev -> {
result = Result.ALL;
setVisible(false);
});

JButton none = new JButton(format(tr("Install '{0}' only"), lib.getName()));
none.addActionListener(ev -> {
result = Result.NONE;
setVisible(false);
});

Box buttonsBox = Box.createHorizontalBox();
buttonsBox.add(all);
buttonsBox.add(Box.createHorizontalStrut(5));
buttonsBox.add(none);
buttonsBox.add(Box.createHorizontalStrut(5));
buttonsBox.add(cancel);

JPanel buttonsPanel = new JPanel();
buttonsPanel.setBorder(new EmptyBorder(7, 10, 7, 10));
buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.Y_AXIS));
buttonsPanel.add(buttonsBox);

pane.add(buttonsPanel, BorderLayout.SOUTH);
}

{
String libName = format("<b>{0}:{1}</b>", lib.getName(),
lib.getParsedVersion());
String desc = format(tr("The library {0} needs some other library<br />dependencies currently not installed:"),
libName);
desc += "<br/><br/>";
for (ContributedLibrary l : dependencies) {
if (l.getName().equals(lib.getName()))
continue;
if (l.getInstalledLibrary().isPresent())
continue;
if (l instanceof UnavailableContributedLibrary)
continue;
desc += format("- <b>{0}</b><br/>", l.getName());
}
desc += "<br/>";
desc += tr("Would you like to install also all the missing dependencies?");

JTextPane textArea = makeNewDescription();
textArea.setContentType("text/html");
textArea.setText(desc);

JPanel libsList = new JPanel();
libsList.setLayout(new BoxLayout(libsList, BoxLayout.Y_AXIS));
libsList.add(textArea);
libsList.setBorder(new EmptyBorder(7, 7, 7, 7));
pane.add(libsList, BorderLayout.NORTH);
}

pack();
setResizable(false);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

WindowEvent closing = new WindowEvent(this, WindowEvent.WINDOW_CLOSING);
Base.registerWindowCloseKeys(getRootPane(), e -> dispatchEvent(closing));
}

// TODO Make this a method of Theme
private JTextPane makeNewDescription() {
JTextPane description = new JTextPane();
description.setInheritsPopupMenu(true);
Insets margin = description.getMargin();
margin.bottom = 0;
description.setMargin(margin);
description.setContentType("text/html");
Document doc = description.getDocument();
if (doc instanceof HTMLDocument) {
HTMLDocument html = (HTMLDocument) doc;
StyleSheet s = html.getStyleSheet();
s.addRule("body { margin: 0; padding: 0;"
+ "font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;"
+ "color: black;" + "font-size: " + 15 * Theme.getScale() / 100
+ "; }");
}
description.setOpaque(false);
description.setBorder(new EmptyBorder(4, 7, 7, 7));
description.setHighlighter(null);
description.setEditable(false);
add(description, 0);
return description;
}

public Result getInstallDepsResult() {
return result;
}
}
7 changes: 3 additions & 4 deletions app/src/cc/arduino/packages/MonitorFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,23 @@
package cc.arduino.packages;

import processing.app.AbstractMonitor;
import processing.app.Base;
import processing.app.NetworkMonitor;
import processing.app.SerialMonitor;

public class MonitorFactory {

public AbstractMonitor newMonitor(Base base, BoardPort port) {
public AbstractMonitor newMonitor(BoardPort port) {
if ("network".equals(port.getProtocol())) {
if ("yes".equals(port.getPrefs().get("ssh_upload"))) {
// the board is SSH capable
return new NetworkMonitor(base, port);
return new NetworkMonitor(port);
} else {
// SSH not supported, no monitor support
return null;
}
}

return new SerialMonitor(base, port);
return new SerialMonitor(port);
}

}
28 changes: 28 additions & 0 deletions app/src/processing/app/AbstractMonitor.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package processing.app;

import cc.arduino.packages.BoardPort;
import cc.arduino.packages.DiscoveryManager;
import processing.app.legacy.PApplet;

import javax.swing.*;
Expand All @@ -9,6 +10,7 @@
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.List;

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

private StringBuffer updateBuffer;
private Timer updateTimer;
private Timer portExistsTimer;

private BoardPort boardPort;

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

ActionListener portExists = new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
try {
if (!Base.getDiscoveryManager().discovery().contains(boardPort)) {
if (!closed) {
suspend();
}
} else {
if (closed && (Editor.avoidMultipleOperations == false)) {
resume(boardPort);
}
}
} catch (Exception e) {}
}
};

portExistsTimer = new Timer(1000, portExists); // check if the port is still there every second
portExistsTimer.start();

closed = false;
}

Expand All @@ -92,6 +115,11 @@ public void suspend() throws Exception {
close();
}

public void dispose() {
super.dispose();
portExistsTimer.stop();
}

public void resume(BoardPort boardPort) throws Exception {
setBoardPort(boardPort);

Expand Down
23 changes: 17 additions & 6 deletions app/src/processing/app/AbstractTextMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyListener;
import java.awt.event.MouseWheelListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.text.SimpleDateFormat;
Expand Down Expand Up @@ -46,12 +48,21 @@ public abstract class AbstractTextMonitor extends AbstractMonitor {
protected JComboBox<String> lineEndings;
protected JComboBox<String> serialRates;

public AbstractTextMonitor(Base base, BoardPort boardPort) {
public AbstractTextMonitor(BoardPort boardPort) {
super(boardPort);
}

// Add font size adjustment listeners. This has to be done here due to
// super(boardPort) invoking onCreateWindow(...) before we can store base.
base.addEditorFontResizeListeners(textArea);
@Override
public synchronized void addMouseWheelListener(MouseWheelListener l) {
super.addMouseWheelListener(l);
textArea.addMouseWheelListener(l);
}

@Override
public synchronized void addKeyListener(KeyListener l) {
super.addKeyListener(l);
textArea.addKeyListener(l);
textField.addKeyListener(l);
}

@Override
Expand Down Expand Up @@ -125,7 +136,7 @@ public void windowGainedFocus(WindowEvent e) {
minimumSize.setSize(minimumSize.getWidth() / 3, minimumSize.getHeight());
noLineEndingAlert.setMinimumSize(minimumSize);

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

lineEndings.setMaximumSize(lineEndings.getMinimumSize());

serialRates = new JComboBox<String>();
serialRates = new JComboBox<>();
for (String rate : serialRateStrings) {
serialRates.addItem(rate + " " + tr("baud"));
}
Expand Down
Loading

0 comments on commit 9ce5101

Please sign in to comment.