Skip to content

Commit 4e67595

Browse files
authored
Merge pull request #26 from acardona/adjust-fonts
Adjust fonts of the screen and error window when adjusting the editor's font
2 parents 580fb32 + 92128e4 commit 4e67595

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</parent>
1111

1212
<artifactId>script-editor</artifactId>
13-
<version>0.3.2-SNAPSHOT</version>
13+
<version>0.4.0-SNAPSHOT</version>
1414

1515
<name>SciJava Script Editor</name>
1616
<description>Script Editor and Interpreter for SciJava script languages.</description>

src/main/java/org/scijava/ui/swing/script/TextEditor.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,7 @@ public TextEditor(final Context context) {
305305

306306
@Override
307307
public void actionPerformed(final ActionEvent event) {
308-
getEditorPane().setFontSize(size);
309-
updateTabAndFontSize(false);
308+
setFontSize(size);
310309
}
311310
});
312311
for (final char c : ("" + size).toCharArray()) {
@@ -1204,7 +1203,7 @@ else if (source == openInGitweb) {
12041203
else if (source == increaseFontSize || source == decreaseFontSize) {
12051204
getEditorPane().increaseFontSize(
12061205
(float) (source == increaseFontSize ? 1.2 : 1 / 1.2));
1207-
updateTabAndFontSize(false);
1206+
setFontSize(getEditorPane().getFontSize());
12081207
}
12091208
else if (source == nextTab) switchTabRelative(1);
12101209
else if (source == previousTab) switchTabRelative(-1);
@@ -2454,4 +2453,15 @@ public void changedUpdate(final DocumentEvent e) {
24542453
setTitle();
24552454
}
24562455

2456+
public void setFontSize(final float size) {
2457+
if (getEditorPane().getFontSize() != size)
2458+
getEditorPane().setFontSize(size);
2459+
changeFontSize(errorScreen, size);
2460+
changeFontSize(getTab().screen, size);
2461+
updateTabAndFontSize(false);
2462+
}
2463+
2464+
private void changeFontSize(final JTextArea a, final float size) {
2465+
a.setFont(a.getFont().deriveFont(size));
2466+
}
24572467
}

src/main/java/org/scijava/ui/swing/script/TextEditorTab.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,10 @@ public JTextArea getScreen() {
217217
return showingErrors ? textEditor.getErrorScreen() : screen;
218218
}
219219

220+
public JTextArea getScreenInstance() {
221+
return screen;
222+
}
223+
220224
boolean isExecuting() {
221225
return null != getExecuter();
222226
}

src/main/java/org/scijava/ui/swing/script/commands/ChooseFontSize.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131

3232
package org.scijava.ui.swing.script.commands;
3333

34+
import javax.swing.JTextArea;
35+
3436
import org.scijava.command.ContextCommand;
3537
import org.scijava.plugin.Parameter;
3638
import org.scijava.ui.swing.script.TextEditor;
@@ -51,9 +53,16 @@ public class ChooseFontSize extends ContextCommand {
5153
@Override
5254
public void run() {
5355
editor.getEditorPane().setFontSize(fontSize);
56+
final float size = editor.getEditorPane().getFontSize();
57+
changeFontSize(editor.getErrorScreen(), size);
58+
changeFontSize(editor.getTab().getScreenInstance(), size);
5459
editor.updateTabAndFontSize(false);
5560
}
5661

62+
private void changeFontSize(final JTextArea a, final float size) {
63+
a.setFont(a.getFont().deriveFont(size));
64+
}
65+
5766
protected void initializeChoice() {
5867
fontSize = (int) editor.getEditorPane().getFontSize();
5968
}

0 commit comments

Comments
 (0)