|
1 | | -/* |
| 1 | +/** |
2 | 2 | * Copyright 2019 Philipp Salvisberg <philipp.salvisberg@trivadis.com> |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
|
13 | 13 | * See the License for the specific language governing permissions and |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
| 16 | +package org.utplsql.sqldev.ui.runner; |
16 | 17 |
|
17 | | -package org.utplsql.sqldev.ui.runner |
| 18 | +import java.awt.Graphics; |
| 19 | +import java.awt.event.FocusEvent; |
| 20 | +import java.awt.event.FocusListener; |
| 21 | +import javax.swing.JTextPane; |
| 22 | +import javax.swing.UIManager; |
| 23 | +import javax.swing.text.Caret; |
18 | 24 |
|
19 | | -import java.awt.Graphics |
20 | | -import java.awt.event.FocusEvent |
21 | | -import java.awt.event.FocusListener |
22 | | -import javax.swing.JTextPane |
23 | | -import javax.swing.UIManager |
24 | | - |
25 | | -class RunnerTextPane extends JTextPane implements FocusListener{ |
26 | | - |
27 | | - new() { |
28 | | - super() |
29 | | - this.addFocusListener = this |
30 | | - } |
31 | | - |
32 | | - override paintComponent(Graphics g) { |
33 | | - // default for non-opaque components |
34 | | - if (!opaque) { |
35 | | - super.paintComponent(g) |
36 | | - return |
37 | | - } |
38 | | - |
39 | | - // use value of JTextField for consistency |
40 | | - g.color = UIManager.getColor("TextField.inactiveBackground") |
41 | | - g.fillRect(0, 0, width, height) |
42 | | - |
43 | | - // do rest, changing opaque to ensure background is not overwritten |
44 | | - setOpaque(false) |
45 | | - super.paintComponent(g) |
46 | | - setOpaque(true) |
47 | | - } |
48 | | - |
49 | | - override void focusGained(FocusEvent e) { |
50 | | - this.caret.visible = true |
51 | | - } |
52 | | - |
53 | | - override focusLost(FocusEvent e) { |
54 | | - this.caret.visible = false |
55 | | - } |
56 | | - |
57 | | - override setText(String t) { |
58 | | - super.setText(t) |
59 | | - // ensure left parts of long lines are always visible |
60 | | - caretPosition = 0 |
61 | | - } |
| 25 | +@SuppressWarnings("all") |
| 26 | +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; |
| 39 | + } |
| 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 | + } |
62 | 64 | } |
0 commit comments