mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-07 01:54:26 +01:00
Make text monitor output area font size dynamically adjustable
Add CTRL +/- and CTRL scroll shortcuts to increase/decrease serial/network monitor output text size. This font size is shared with the editor and adjusting either will update both. Partially fixes #8615
This commit is contained in:
parent
49242bed02
commit
1a6d55480c
@ -30,23 +30,24 @@
|
|||||||
package cc.arduino.packages;
|
package cc.arduino.packages;
|
||||||
|
|
||||||
import processing.app.AbstractMonitor;
|
import processing.app.AbstractMonitor;
|
||||||
|
import processing.app.Base;
|
||||||
import processing.app.NetworkMonitor;
|
import processing.app.NetworkMonitor;
|
||||||
import processing.app.SerialMonitor;
|
import processing.app.SerialMonitor;
|
||||||
|
|
||||||
public class MonitorFactory {
|
public class MonitorFactory {
|
||||||
|
|
||||||
public AbstractMonitor newMonitor(BoardPort port) {
|
public AbstractMonitor newMonitor(Base base, BoardPort port) {
|
||||||
if ("network".equals(port.getProtocol())) {
|
if ("network".equals(port.getProtocol())) {
|
||||||
if ("yes".equals(port.getPrefs().get("ssh_upload"))) {
|
if ("yes".equals(port.getPrefs().get("ssh_upload"))) {
|
||||||
// the board is SSH capable
|
// the board is SSH capable
|
||||||
return new NetworkMonitor(port);
|
return new NetworkMonitor(base, port);
|
||||||
} else {
|
} else {
|
||||||
// SSH not supported, no monitor support
|
// SSH not supported, no monitor support
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new SerialMonitor(port);
|
return new SerialMonitor(base, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -173,4 +173,13 @@ public abstract class AbstractMonitor extends JFrame implements ActionListener {
|
|||||||
message(s);
|
message(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read and apply new values from the preferences, either because
|
||||||
|
* the app is just starting up, or the user just finished messing
|
||||||
|
* with things in the Preferences window.
|
||||||
|
*/
|
||||||
|
public void applyPreferences() {
|
||||||
|
// Empty.
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,9 @@ import java.awt.Dimension;
|
|||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.event.KeyEvent;
|
||||||
|
import java.awt.event.KeyAdapter;
|
||||||
|
import java.awt.event.MouseWheelEvent;
|
||||||
import java.awt.event.WindowAdapter;
|
import java.awt.event.WindowAdapter;
|
||||||
import java.awt.event.WindowEvent;
|
import java.awt.event.WindowEvent;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
@ -32,6 +35,8 @@ import cc.arduino.packages.BoardPort;
|
|||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public abstract class AbstractTextMonitor extends AbstractMonitor {
|
public abstract class AbstractTextMonitor extends AbstractMonitor {
|
||||||
|
|
||||||
|
private final Base base;
|
||||||
|
|
||||||
protected JLabel noLineEndingAlert;
|
protected JLabel noLineEndingAlert;
|
||||||
protected TextAreaFIFO textArea;
|
protected TextAreaFIFO textArea;
|
||||||
protected JScrollPane scrollPane;
|
protected JScrollPane scrollPane;
|
||||||
@ -43,14 +48,12 @@ public abstract class AbstractTextMonitor extends AbstractMonitor {
|
|||||||
protected JComboBox lineEndings;
|
protected JComboBox lineEndings;
|
||||||
protected JComboBox serialRates;
|
protected JComboBox serialRates;
|
||||||
|
|
||||||
public AbstractTextMonitor(BoardPort boardPort) {
|
public AbstractTextMonitor(Base base, BoardPort boardPort) {
|
||||||
super(boardPort);
|
super(boardPort);
|
||||||
|
this.base = base;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onCreateWindow(Container mainPane) {
|
protected void onCreateWindow(Container mainPane) {
|
||||||
Font consoleFont = Theme.getFont("console.font");
|
|
||||||
Font editorFont = PreferencesData.getFont("editor.font");
|
|
||||||
Font font = Theme.scale(new Font(consoleFont.getName(), consoleFont.getStyle(), editorFont.getSize()));
|
|
||||||
|
|
||||||
mainPane.setLayout(new BorderLayout());
|
mainPane.setLayout(new BorderLayout());
|
||||||
|
|
||||||
@ -58,12 +61,45 @@ public abstract class AbstractTextMonitor extends AbstractMonitor {
|
|||||||
textArea.setRows(16);
|
textArea.setRows(16);
|
||||||
textArea.setColumns(40);
|
textArea.setColumns(40);
|
||||||
textArea.setEditable(false);
|
textArea.setEditable(false);
|
||||||
textArea.setFont(font);
|
|
||||||
|
|
||||||
// don't automatically update the caret. that way we can manually decide
|
// don't automatically update the caret. that way we can manually decide
|
||||||
// whether or not to do so based on the autoscroll checkbox.
|
// whether or not to do so based on the autoscroll checkbox.
|
||||||
((DefaultCaret) textArea.getCaret()).setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
|
((DefaultCaret) textArea.getCaret()).setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
|
||||||
|
|
||||||
|
// Add "CTRL scroll" hotkey for font size adjustment.
|
||||||
|
textArea.addMouseWheelListener((MouseWheelEvent e) -> {
|
||||||
|
if (e.isControlDown()) {
|
||||||
|
if (e.getWheelRotation() < 0) {
|
||||||
|
base.handleFontSizeChange(1);
|
||||||
|
} else {
|
||||||
|
base.handleFontSizeChange(-1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
e.getComponent().getParent().dispatchEvent(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Add "CTRL (SHIFT) =/+" and "CTRL -" hotkeys for font size adjustment.
|
||||||
|
textArea.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.handleFontSizeChange(1);
|
||||||
|
break;
|
||||||
|
case KeyEvent.VK_MINUS:
|
||||||
|
if (!e.isShiftDown()) {
|
||||||
|
base.handleFontSizeChange(-1);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
scrollPane = new JScrollPane(textArea);
|
scrollPane = new JScrollPane(textArea);
|
||||||
|
|
||||||
mainPane.add(scrollPane, BorderLayout.CENTER);
|
mainPane.add(scrollPane, BorderLayout.CENTER);
|
||||||
@ -110,12 +146,6 @@ public abstract class AbstractTextMonitor extends AbstractMonitor {
|
|||||||
noLineEndingAlert.setForeground(pane.getBackground());
|
noLineEndingAlert.setForeground(pane.getBackground());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (PreferencesData.get("serial.line_ending") != null) {
|
|
||||||
lineEndings.setSelectedIndex(PreferencesData.getInteger("serial.line_ending"));
|
|
||||||
}
|
|
||||||
if (PreferencesData.get("serial.show_timestamp") != null) {
|
|
||||||
addTimeStampBox.setSelected(PreferencesData.getBoolean("serial.show_timestamp"));
|
|
||||||
}
|
|
||||||
addTimeStampBox.addActionListener(new ActionListener() {
|
addTimeStampBox.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
PreferencesData.setBoolean("serial.show_timestamp", addTimeStampBox.isSelected());
|
PreferencesData.setBoolean("serial.show_timestamp", addTimeStampBox.isSelected());
|
||||||
@ -142,6 +172,8 @@ public abstract class AbstractTextMonitor extends AbstractMonitor {
|
|||||||
pane.add(Box.createRigidArea(new Dimension(8, 0)));
|
pane.add(Box.createRigidArea(new Dimension(8, 0)));
|
||||||
pane.add(clearButton);
|
pane.add(clearButton);
|
||||||
|
|
||||||
|
applyPreferences();
|
||||||
|
|
||||||
mainPane.add(pane, BorderLayout.SOUTH);
|
mainPane.add(pane, BorderLayout.SOUTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,6 +221,26 @@ public abstract class AbstractTextMonitor extends AbstractMonitor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void applyPreferences() {
|
||||||
|
|
||||||
|
// Apply font.
|
||||||
|
Font consoleFont = Theme.getFont("console.font");
|
||||||
|
Font editorFont = PreferencesData.getFont("editor.font");
|
||||||
|
textArea.setFont(Theme.scale(new Font(
|
||||||
|
consoleFont.getName(), consoleFont.getStyle(), editorFont.getSize())));
|
||||||
|
|
||||||
|
// Apply line endings.
|
||||||
|
if (PreferencesData.get("serial.line_ending") != null) {
|
||||||
|
lineEndings.setSelectedIndex(PreferencesData.getInteger("serial.line_ending"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply timestamp visibility.
|
||||||
|
if (PreferencesData.get("serial.show_timestamp") != null) {
|
||||||
|
addTimeStampBox.setSelected(PreferencesData.getBoolean("serial.show_timestamp"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private String addTimestamps(String text) {
|
private String addTimestamps(String text) {
|
||||||
String now = new SimpleDateFormat("HH:mm:ss.SSS -> ").format(new Date());
|
String now = new SimpleDateFormat("HH:mm:ss.SSS -> ").format(new Date());
|
||||||
final StringBuilder sb = new StringBuilder(text.length() + now.length());
|
final StringBuilder sb = new StringBuilder(text.length() + now.length());
|
||||||
|
@ -495,6 +495,9 @@ public class Editor extends JFrame implements RunnerListener {
|
|||||||
tab.applyPreferences();
|
tab.applyPreferences();
|
||||||
}
|
}
|
||||||
console.applyPreferences();
|
console.applyPreferences();
|
||||||
|
if (serialMonitor != null) {
|
||||||
|
serialMonitor.applyPreferences();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -2211,7 +2214,7 @@ public class Editor extends JFrame implements RunnerListener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
serialMonitor = new MonitorFactory().newMonitor(port);
|
serialMonitor = new MonitorFactory().newMonitor(base, port);
|
||||||
|
|
||||||
if (serialMonitor == null) {
|
if (serialMonitor == null) {
|
||||||
String board = port.getPrefs().get("board");
|
String board = port.getPrefs().get("board");
|
||||||
|
@ -31,8 +31,8 @@ public class NetworkMonitor extends AbstractTextMonitor implements MessageConsum
|
|||||||
private Channel channel;
|
private Channel channel;
|
||||||
private int connectionAttempts;
|
private int connectionAttempts;
|
||||||
|
|
||||||
public NetworkMonitor(BoardPort port) {
|
public NetworkMonitor(Base base, BoardPort port) {
|
||||||
super(port);
|
super(base, port);
|
||||||
|
|
||||||
onSendCommand(new ActionListener() {
|
onSendCommand(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent event) {
|
public void actionPerformed(ActionEvent event) {
|
||||||
|
@ -33,8 +33,8 @@ public class SerialMonitor extends AbstractTextMonitor {
|
|||||||
private Serial serial;
|
private Serial serial;
|
||||||
private int serialRate;
|
private int serialRate;
|
||||||
|
|
||||||
public SerialMonitor(BoardPort port) {
|
public SerialMonitor(Base base, BoardPort port) {
|
||||||
super(port);
|
super(base, port);
|
||||||
|
|
||||||
serialRate = PreferencesData.getInteger("serial.debug_rate");
|
serialRate = PreferencesData.getInteger("serial.debug_rate");
|
||||||
serialRates.setSelectedItem(serialRate + " " + tr("baud"));
|
serialRates.setSelectedItem(serialRate + " " + tr("baud"));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user