Skip to content

Fix text monitor tests #8714

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

Merged
merged 2 commits into from
Jul 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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);
}

}
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 @@ -43,12 +45,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 @@ -105,7 +116,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 @@ -115,7 +126,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
65 changes: 28 additions & 37 deletions app/src/processing/app/Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -1870,9 +1870,6 @@ public void handleFontSizeChange(int change) {
getEditors().forEach(Editor::applyPreferences);
}

private MouseWheelListener editorFontResizeMouseWheelListener = null;
private KeyListener editorFontResizeKeyListener = null;

/**
* Adds a {@link MouseWheelListener} and {@link KeyListener} to the given
* component that will make "CTRL scroll" and "CTRL +/-"
Expand All @@ -1884,8 +1881,8 @@ public void handleFontSizeChange(int change) {
* @param comp - The component to add the listener to.
*/
public void addEditorFontResizeListeners(Component comp) {
this.addEditorFontResizeMouseWheelListener(comp);
this.addEditorFontResizeKeyListener(comp);
addEditorFontResizeMouseWheelListener(comp);
addEditorFontResizeKeyListener(comp);
}

/**
Expand All @@ -1897,20 +1894,17 @@ public void addEditorFontResizeListeners(Component comp) {
* @param comp - The component to add the listener to.
*/
public void addEditorFontResizeMouseWheelListener(Component comp) {
if (this.editorFontResizeMouseWheelListener == null) {
this.editorFontResizeMouseWheelListener = (MouseWheelEvent e) -> {
if (e.isControlDown()) {
if (e.getWheelRotation() < 0) {
this.handleFontSizeChange(1);
} else {
this.handleFontSizeChange(-1);
}
comp.addMouseWheelListener(e -> {
if (e.isControlDown()) {
if (e.getWheelRotation() < 0) {
this.handleFontSizeChange(1);
} else {
e.getComponent().getParent().dispatchEvent(e);
this.handleFontSizeChange(-1);
}
};
}
comp.addMouseWheelListener(this.editorFontResizeMouseWheelListener);
} else {
e.getComponent().getParent().dispatchEvent(e);
}
});
}

/**
Expand All @@ -1920,29 +1914,26 @@ public void addEditorFontResizeMouseWheelListener(Component comp) {
* @param comp - The component to add the listener to.
*/
public void addEditorFontResizeKeyListener(Component comp) {
if (this.editorFontResizeKeyListener == null) {
this.editorFontResizeKeyListener = new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getModifiersEx() == KeyEvent.CTRL_DOWN_MASK
|| e.getModifiersEx() == (KeyEvent.CTRL_DOWN_MASK
| KeyEvent.SHIFT_DOWN_MASK)) {
switch (e.getKeyCode()) {
case KeyEvent.VK_PLUS:
case KeyEvent.VK_EQUALS:
Base.this.handleFontSizeChange(1);
break;
case KeyEvent.VK_MINUS:
if (!e.isShiftDown()) {
Base.this.handleFontSizeChange(-1);
}
break;
comp.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getModifiersEx() == KeyEvent.CTRL_DOWN_MASK
|| e.getModifiersEx() == (KeyEvent.CTRL_DOWN_MASK
| KeyEvent.SHIFT_DOWN_MASK)) {
switch (e.getKeyCode()) {
case KeyEvent.VK_PLUS:
case KeyEvent.VK_EQUALS:
Base.this.handleFontSizeChange(1);
break;
case KeyEvent.VK_MINUS:
if (!e.isShiftDown()) {
Base.this.handleFontSizeChange(-1);
}
break;
}
}
};
}
comp.addKeyListener(this.editorFontResizeKeyListener);
}
});
}

public List<JMenu> getBoardsCustomMenus() {
Expand Down
3 changes: 2 additions & 1 deletion app/src/processing/app/Editor.java
Original file line number Diff line number Diff line change
Expand Up @@ -2214,7 +2214,7 @@ public void handleSerial() {
return;
}

serialMonitor = new MonitorFactory().newMonitor(base, port);
serialMonitor = new MonitorFactory().newMonitor(port);

if (serialMonitor == null) {
String board = port.getPrefs().get("board");
Expand All @@ -2223,6 +2223,7 @@ public void handleSerial() {
return;
}

base.addEditorFontResizeListeners(serialMonitor);
Base.setIcon(serialMonitor);

// If currently uploading, disable the monitor (it will be later
Expand Down
2 changes: 0 additions & 2 deletions app/src/processing/app/EditorTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseWheelListener;
import java.awt.event.MouseWheelEvent;

import java.io.IOException;

Expand Down
4 changes: 2 additions & 2 deletions app/src/processing/app/NetworkMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public class NetworkMonitor extends AbstractTextMonitor implements MessageConsum
private Channel channel;
private int connectionAttempts;

public NetworkMonitor(Base base, BoardPort port) {
super(base, port);
public NetworkMonitor(BoardPort port) {
super(port);

onSendCommand(new ActionListener() {
public void actionPerformed(ActionEvent event) {
Expand Down
4 changes: 2 additions & 2 deletions app/src/processing/app/SerialMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public class SerialMonitor extends AbstractTextMonitor {
private Serial serial;
private int serialRate;

public SerialMonitor(Base base, BoardPort port) {
super(base, port);
public SerialMonitor(BoardPort port) {
super(port);

serialRate = PreferencesData.getInteger("serial.debug_rate");
serialRates.setSelectedItem(serialRate + " " + tr("baud"));
Expand Down