|
| 1 | +/* |
| 2 | + * Copyright 2019 Philipp Salvisberg <philipp.salvisberg@trivadis.com> |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.utplsql.sqldev.ui.runner |
| 18 | + |
| 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 | +} |
0 commit comments