Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/arduino/Arduino into seri…
Browse files Browse the repository at this point in the history
…al-monitor-encoding-options
  • Loading branch information
Pieter12345 committed Mar 18, 2019
2 parents 79fa806 + 74f93fe commit 0dec65c
Show file tree
Hide file tree
Showing 73 changed files with 1,745 additions and 1,261 deletions.
2 changes: 1 addition & 1 deletion app/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<classpathentry kind="lib" path="lib/slf4j-api-1.7.22.jar"/>
<classpathentry kind="lib" path="lib/slf4j-simple-1.7.22.jar"/>
<classpathentry kind="lib" path="lib/jsch-0.1.50.jar"/>
<classpathentry kind="lib" path="lib/jssc-2.8.0-arduino2.jar"/>
<classpathentry kind="lib" path="lib/jssc-2.8.0-arduino3.jar"/>
<classpathentry kind="lib" path="lib/rsyntaxtextarea-3.0.3-SNAPSHOT.jar"/>
<classpathentry kind="lib" path="lib/xml-apis-1.3.04.jar"/>
<classpathentry kind="lib" path="lib/xml-apis-ext-1.3.04.jar"/>
Expand Down
Binary file not shown.
32 changes: 22 additions & 10 deletions app/src/cc/arduino/contributions/ui/FilterJTextField.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,18 @@ public class FilterJTextField extends JTextField {
private final String filterHint;

private boolean showingHint;
private Timer timer;

public FilterJTextField(String hint) {
super(hint);
filterHint = hint;

showingHint = true;
updateStyle();
timer = new Timer(1000, e -> {
applyFilter();
timer.stop();
});

addFocusListener(new FocusListener() {
public void focusLost(FocusEvent focusEvent) {
Expand All @@ -68,33 +73,40 @@ public void focusGained(FocusEvent focusEvent) {

getDocument().addDocumentListener(new DocumentListener() {
public void removeUpdate(DocumentEvent e) {
applyFilter();
spawnTimer();
}

public void insertUpdate(DocumentEvent e) {
applyFilter();
spawnTimer();
}

public void changedUpdate(DocumentEvent e) {
applyFilter();

}
});

addActionListener(e -> {
if (timer.isRunning()) {
timer.stop();
}
applyFilter();
});
}

private String lastFilter = "";
private void spawnTimer() {
if (timer.isRunning()) {
timer.stop();
}
timer.start();
}

private void applyFilter() {
public void applyFilter() {
String filter = showingHint ? "" : getText();
filter = filter.toLowerCase();

// Replace anything but 0-9, a-z, or : with a space
filter = filter.replaceAll("[^\\x30-\\x39^\\x61-\\x7a^\\x3a]", " ");

// Fire event only if the filter is changed
if (filter.equals(lastFilter))
return;

lastFilter = filter;
onFilter(filter.split(" "));
}

Expand Down
1 change: 1 addition & 0 deletions app/src/cc/arduino/contributions/ui/InstallerJDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ public void setFilterText(String filterText) {
listener.focusGained(new FocusEvent(filterField, FocusEvent.FOCUS_GAINED));
}
filterField.setText(filterText);
filterField.applyFilter();
}

public void selectDropdownItemByClassName(String dropdownItem) {
Expand Down
2 changes: 2 additions & 0 deletions app/src/processing/app/Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ public Base(String[] args) throws Exception {
splash.splashText(tr("Initializing packages..."));
BaseNoGui.initPackages();

parser.getUploadPort().ifPresent(BaseNoGui::selectSerialPort);

splash.splashText(tr("Preparing boards..."));

if (!isCommandLine()) {
Expand Down
98 changes: 63 additions & 35 deletions app/src/processing/app/Editor.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.LinkedList;
Expand Down Expand Up @@ -82,6 +81,8 @@
import javax.swing.event.MenuListener;
import javax.swing.text.BadLocationException;

import org.fife.ui.rsyntaxtextarea.folding.FoldManager;

import com.jcraft.jsch.JSchException;

import cc.arduino.CompilerProgressListener;
Expand All @@ -94,6 +95,7 @@
import cc.arduino.view.findreplace.FindReplace;
import jssc.SerialPortException;
import processing.app.debug.RunnerException;
import processing.app.debug.TargetBoard;
import processing.app.forms.PasswordAuthorizationDialog;
import processing.app.helpers.DocumentTextChangeListener;
import processing.app.helpers.Keys;
Expand Down Expand Up @@ -147,9 +149,6 @@ public boolean test(SketchController controller) {
}
}

private final static List<String> BOARD_PROTOCOLS_ORDER = Arrays.asList("serial", "network");
private final static List<String> BOARD_PROTOCOLS_ORDER_TRANSLATIONS = Arrays.asList(tr("Serial ports"), tr("Network ports"));

final Base base;

// otherwise, if the window is resized with the message label
Expand Down Expand Up @@ -1041,22 +1040,30 @@ class BoardPortJCheckBoxMenuItem extends JCheckBoxMenuItem {
private BoardPort port;

public BoardPortJCheckBoxMenuItem(BoardPort port) {
super(port.getLabel());
super();
this.port = port;
setText(toString());
addActionListener(e -> {
selectSerialPort(port.getAddress());
base.onBoardOrPortChange();
});
this.port = port;
}

@Override
public String toString() {
// This is required for serialPrompt()
return port.getLabel();
String label = port.getLabel();
if (port.getBoardName() != null && !port.getBoardName().isEmpty()) {
label += " (" + port.getBoardName() + ")";
}
return label;
}
}

private void populatePortMenu() {
final List<String> PROTOCOLS_ORDER = Arrays.asList("serial", "network");
final List<String> PROTOCOLS_LABELS = Arrays.asList(tr("Serial ports"), tr("Network ports"));

portMenu.removeAll();

String selectedPort = PreferencesData.get("serial.port");
Expand All @@ -1065,31 +1072,43 @@ private void populatePortMenu() {

ports = platform.filterPorts(ports, PreferencesData.getBoolean("serial.ports.showall"));

Collections.sort(ports, new Comparator<BoardPort>() {
@Override
public int compare(BoardPort o1, BoardPort o2) {
return (BOARD_PROTOCOLS_ORDER.indexOf(o1.getProtocol()) - BOARD_PROTOCOLS_ORDER.indexOf(o2.getProtocol())) * 10 +
o1.getAddress().compareTo(o2.getAddress());
}
ports.stream() //
.filter(port -> port.getProtocolLabel() == null || port.getProtocolLabel().isEmpty())
.forEach(port -> {
int labelIdx = PROTOCOLS_ORDER.indexOf(port.getProtocol());
if (labelIdx != -1) {
port.setProtocolLabel(PROTOCOLS_LABELS.get(labelIdx));
} else {
port.setProtocolLabel(port.getProtocol());
}
});

Collections.sort(ports, (port1, port2) -> {
String pr1 = port1.getProtocol();
String pr2 = port2.getProtocol();
int prIdx1 = PROTOCOLS_ORDER.contains(pr1) ? PROTOCOLS_ORDER.indexOf(pr1) : 999;
int prIdx2 = PROTOCOLS_ORDER.contains(pr2) ? PROTOCOLS_ORDER.indexOf(pr2) : 999;
int r = prIdx1 - prIdx2;
if (r != 0)
return r;
r = port1.getProtocolLabel().compareTo(port2.getProtocolLabel());
if (r != 0)
return r;
return port1.getAddress().compareTo(port2.getAddress());
});

String lastProtocol = null;
String lastProtocolTranslated;
String lastProtocol = "";
String lastProtocolLabel = "";
for (BoardPort port : ports) {
if (lastProtocol == null || !port.getProtocol().equals(lastProtocol)) {
if (lastProtocol != null) {
if (!port.getProtocol().equals(lastProtocol) || !port.getProtocolLabel().equals(lastProtocolLabel)) {
if (!lastProtocol.isEmpty()) {
portMenu.addSeparator();
}
lastProtocol = port.getProtocol();

if (BOARD_PROTOCOLS_ORDER.indexOf(port.getProtocol()) != -1) {
lastProtocolTranslated = BOARD_PROTOCOLS_ORDER_TRANSLATIONS.get(BOARD_PROTOCOLS_ORDER.indexOf(port.getProtocol()));
} else {
lastProtocolTranslated = port.getProtocol();
}
JMenuItem lastProtocolMenuItem = new JMenuItem(tr(lastProtocolTranslated));
lastProtocolMenuItem.setEnabled(false);
portMenu.add(lastProtocolMenuItem);
lastProtocolLabel = port.getProtocolLabel();
JMenuItem item = new JMenuItem(tr(lastProtocolLabel));
item.setEnabled(false);
portMenu.add(item);
}
String address = port.getAddress();

Expand Down Expand Up @@ -1648,8 +1667,17 @@ public void removeAllLineHighlights() {
}

public void addLineHighlight(int line) throws BadLocationException {
getCurrentTab().getTextArea().addLineHighlight(line, new Color(1, 0, 0, 0.2f));
getCurrentTab().getTextArea().setCaretPosition(getCurrentTab().getTextArea().getLineStartOffset(line));
SketchTextArea textArea = getCurrentTab().getTextArea();
FoldManager foldManager = textArea.getFoldManager();
if (foldManager.isLineHidden(line)) {
for (int i = 0; i < foldManager.getFoldCount(); i++) {
if (foldManager.getFold(i).containsLine(line)) {
foldManager.getFold(i).setCollapsed(false);
}
}
}
textArea.addLineHighlight(line, new Color(1, 0, 0, 0.2f));
textArea.setCaretPosition(textArea.getLineStartOffset(line));
}


Expand Down Expand Up @@ -2392,9 +2420,9 @@ private void handleBoardInfo() {
for (BoardPort port : ports) {
if (port.getAddress().equals(selectedPort)) {
label = port.getBoardName();
vid = port.getVID();
pid = port.getPID();
iserial = port.getISerial();
vid = port.getPrefs().get("vid");
pid = port.getPrefs().get("pid");
iserial = port.getPrefs().get("iserial");
protocol = port.getProtocol();
found = true;
break;
Expand Down Expand Up @@ -2564,12 +2592,12 @@ private void statusEmpty() {
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

protected void onBoardOrPortChange() {
Map<String, String> boardPreferences = BaseNoGui.getBoardPreferences();
if (boardPreferences != null)
lineStatus.setBoardName(boardPreferences.get("name"));
TargetBoard board = BaseNoGui.getTargetBoard();
if (board != null)
lineStatus.setBoardName(board.getName());
else
lineStatus.setBoardName("-");
lineStatus.setSerialPort(PreferencesData.get("serial.port"));
lineStatus.setPort(PreferencesData.get("serial.port"));
lineStatus.repaint();
}

Expand Down
19 changes: 7 additions & 12 deletions app/src/processing/app/EditorLineStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ public class EditorLineStatus extends JComponent {

String text = "";
String name = "";
String serialport = "";
String serialnumber = "";
String port = "";

public EditorLineStatus() {
background = Theme.getColor("linestatus.bgcolor");
Expand Down Expand Up @@ -92,13 +91,13 @@ public void set(int newStart, int newStop) {

public void paintComponent(Graphics graphics) {
Graphics2D g = Theme.setupGraphics2D(graphics);
if (name.isEmpty() && serialport.isEmpty()) {
if (name.isEmpty() && port.isEmpty()) {
PreferencesMap boardPreferences = BaseNoGui.getBoardPreferences();
if (boardPreferences != null)
setBoardName(boardPreferences.get("name"));
else
setBoardName("-");
setSerialPort(PreferencesData.get("serial.port"));
setPort(PreferencesData.get("serial.port"));
}
g.setColor(background);
Dimension size = getSize();
Expand All @@ -112,8 +111,8 @@ public void paintComponent(Graphics graphics) {
g.setColor(messageForeground);

String statusText;
if (serialport != null && !serialport.isEmpty()) {
statusText = I18n.format(tr("{0} on {1}"), name, serialport);
if (port != null && !port.isEmpty()) {
statusText = I18n.format(tr("{0} on {1}"), name, port);
} else {
statusText = name;
}
Expand All @@ -132,12 +131,8 @@ public void setBoardName(String name) {
this.name = name;
}

public void setSerialPort(String serialport) {
this.serialport = serialport;
}

public void setSerialNumber(String serialnumber) {
this.serialnumber = serialnumber;
public void setPort(String port) {
this.port = port;
}

public Dimension getPreferredSize() {
Expand Down
2 changes: 1 addition & 1 deletion app/src/processing/app/SketchController.java
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ private File saveSketchInTempFolder() throws IOException {
FileUtils.copy(sketch.getFolder(), tempFolder);

for (SketchFile file : Stream.of(sketch.getFiles()).filter(SketchFile::isModified).collect(Collectors.toList())) {
Files.write(Paths.get(tempFolder.getAbsolutePath(), file.getFileName()), file.getProgram().getBytes());
Files.write(Paths.get(tempFolder.getAbsolutePath(), file.getFileName()), file.getProgram().getBytes("UTF-8"));
}

return Paths.get(tempFolder.getAbsolutePath(), sketch.getPrimaryFile().getFileName()).toFile();
Expand Down
2 changes: 1 addition & 1 deletion arduino-core/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<classpathentry kind="lib" path="lib/jmdns-3.5.3.jar"/>
<classpathentry kind="lib" path="lib/slf4j-api-1.7.22.jar"/>
<classpathentry kind="lib" path="lib/slf4j-simple-1.7.22.jar"/>
<classpathentry kind="lib" path="lib/jssc-2.8.0-arduino2.jar"/>
<classpathentry kind="lib" path="lib/jssc-2.8.0-arduino3.jar"/>
<classpathentry kind="lib" path="lib/jsch-0.1.50.jar"/>
<classpathentry kind="lib" path="lib/commons-exec-1.1.jar"/>
<classpathentry kind="lib" path="../app/lib/commons-httpclient-3.1.jar"/>
Expand Down
Binary file not shown.
Loading

0 comments on commit 0dec65c

Please sign in to comment.