1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-11-29 10:24:12 +01:00

Apply on-the-fly setFontSize to Console

Fixes #7022
This commit is contained in:
Martino Facchin 2017-12-15 12:38:24 +01:00
parent 4aec8997e2
commit b6280cfd65
3 changed files with 25 additions and 4 deletions

View File

@ -52,7 +52,7 @@ import java.io.PrintStream;
*/
public class ConsoleOutputStream extends ByteArrayOutputStream {
private final SimpleAttributeSet attributes;
private SimpleAttributeSet attributes;
private final PrintStream printStream;
private final Timer timer;
@ -73,6 +73,10 @@ public class ConsoleOutputStream extends ByteArrayOutputStream {
timer.setRepeats(false);
}
public void setAttibutes(SimpleAttributeSet attributes) {
this.attributes = attributes;
}
public void setCurrentEditorConsole(EditorConsole console) {
this.editorConsole = console;
}

View File

@ -458,8 +458,10 @@ public class Editor extends JFrame implements RunnerListener {
boolean external = PreferencesData.getBoolean("editor.external");
saveMenuItem.setEnabled(!external);
saveAsMenuItem.setEnabled(!external);
for (EditorTab tab: tabs)
for (EditorTab tab: tabs) {
tab.applyPreferences();
}
console.applyPreferences();
}

View File

@ -58,6 +58,9 @@ public class EditorConsole extends JScrollPane {
private final DefaultStyledDocument document;
private final JTextPane consoleTextPane;
private SimpleAttributeSet stdOutStyle;
private SimpleAttributeSet stdErrStyle;
public EditorConsole() {
document = new DefaultStyledDocument();
@ -74,7 +77,7 @@ public class EditorConsole extends JScrollPane {
Font editorFont = PreferencesData.getFont("editor.font");
Font actualFont = new Font(consoleFont.getName(), consoleFont.getStyle(), scale(editorFont.getSize()));
SimpleAttributeSet stdOutStyle = new SimpleAttributeSet();
stdOutStyle = new SimpleAttributeSet();
StyleConstants.setForeground(stdOutStyle, Theme.getColor("console.output.color"));
StyleConstants.setBackground(stdOutStyle, backgroundColour);
StyleConstants.setFontSize(stdOutStyle, actualFont.getSize());
@ -84,7 +87,7 @@ public class EditorConsole extends JScrollPane {
consoleTextPane.setParagraphAttributes(stdOutStyle, true);
SimpleAttributeSet stdErrStyle = new SimpleAttributeSet();
stdErrStyle = new SimpleAttributeSet();
StyleConstants.setForeground(stdErrStyle, Theme.getColor("console.error.color"));
StyleConstants.setBackground(stdErrStyle, backgroundColour);
StyleConstants.setFontSize(stdErrStyle, actualFont.getSize());
@ -109,6 +112,18 @@ public class EditorConsole extends JScrollPane {
EditorConsole.init(stdOutStyle, System.out, stdErrStyle, System.err);
}
public void applyPreferences() {
Font consoleFont = Theme.getFont("console.font");
Font editorFont = PreferencesData.getFont("editor.font");
Font actualFont = new Font(consoleFont.getName(), consoleFont.getStyle(), scale(editorFont.getSize()));
StyleConstants.setFontSize(stdOutStyle, actualFont.getSize());
StyleConstants.setFontSize(stdErrStyle, actualFont.getSize());
out.setAttibutes(stdOutStyle);
err.setAttibutes(stdErrStyle);
}
public void clear() {
try {
document.remove(0, document.getLength());