Skip to content

Commit d03ba66

Browse files
convert RunnerTextPane to Java, removing Xtend dependencies
1 parent 3d51f9f commit d03ba66

File tree

1 file changed

+42
-39
lines changed

1 file changed

+42
-39
lines changed
Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright 2019 Philipp Salvisberg <philipp.salvisberg@trivadis.com>
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,47 +18,50 @@
1818
import java.awt.Graphics;
1919
import java.awt.event.FocusEvent;
2020
import java.awt.event.FocusListener;
21+
2122
import javax.swing.JTextPane;
2223
import javax.swing.UIManager;
23-
import javax.swing.text.Caret;
2424

25-
@SuppressWarnings("all")
2625
public class RunnerTextPane extends JTextPane implements FocusListener {
27-
public RunnerTextPane() {
28-
super();
29-
this.addFocusListener(this);
30-
}
31-
32-
@Override
33-
public void paintComponent(final Graphics g) {
34-
boolean _isOpaque = this.isOpaque();
35-
boolean _not = (!_isOpaque);
36-
if (_not) {
37-
super.paintComponent(g);
38-
return;
26+
private static final long serialVersionUID = 1089473481444949272L;
27+
28+
public RunnerTextPane() {
29+
super();
30+
addFocusListener(this);
31+
}
32+
33+
@Override
34+
public void paintComponent(final Graphics g) {
35+
// default for non-opaque components
36+
if (isOpaque()) {
37+
super.paintComponent(g);
38+
return;
39+
}
40+
41+
// use value of JTextField for consistency
42+
g.setColor(UIManager.getColor("TextField.inactiveBackground"));
43+
g.fillRect(0, 0, getWidth(), getHeight());
44+
setOpaque(false);
45+
46+
// do rest, changing opaque to ensure background is not overwritten
47+
super.paintComponent(g);
48+
setOpaque(true);
49+
}
50+
51+
@Override
52+
public void focusGained(final FocusEvent e) {
53+
getCaret().setVisible(true);
54+
}
55+
56+
@Override
57+
public void focusLost(final FocusEvent e) {
58+
getCaret().setVisible(false);
59+
}
60+
61+
@Override
62+
public void setText(final String t) {
63+
super.setText(t);
64+
// ensure left parts of long lines are always visible
65+
setCaretPosition(0);
3966
}
40-
g.setColor(UIManager.getColor("TextField.inactiveBackground"));
41-
g.fillRect(0, 0, this.getWidth(), this.getHeight());
42-
this.setOpaque(false);
43-
super.paintComponent(g);
44-
this.setOpaque(true);
45-
}
46-
47-
@Override
48-
public void focusGained(final FocusEvent e) {
49-
Caret _caret = this.getCaret();
50-
_caret.setVisible(true);
51-
}
52-
53-
@Override
54-
public void focusLost(final FocusEvent e) {
55-
Caret _caret = this.getCaret();
56-
_caret.setVisible(false);
57-
}
58-
59-
@Override
60-
public void setText(final String t) {
61-
super.setText(t);
62-
this.setCaretPosition(0);
63-
}
6467
}

0 commit comments

Comments
 (0)