1
2
3
4
5
6
7
8
9
10
11 package com.jsql.view.swing.text;
12
13 import com.jsql.util.LogLevelUtil;
14 import org.apache.commons.lang3.StringUtils;
15 import org.apache.logging.log4j.LogManager;
16 import org.apache.logging.log4j.Logger;
17
18 import javax.swing.*;
19 import java.awt.*;
20 import java.awt.event.FocusAdapter;
21 import java.awt.event.FocusEvent;
22
23
24
25
26 public class JPopupTextArea extends JPopupTextComponent<JTextArea> implements DecoratorJComponent<JTextArea> {
27
28 private static final Logger LOGGER = LogManager.getRootLogger();
29
30
31
32
33 public JPopupTextArea() {
34 this(StringUtils.EMPTY);
35 }
36
37
38
39
40
41 public JPopupTextArea(String placeholder) {
42 this(new JTextAreaPlaceholder(placeholder) {
43 @Override
44 public boolean isEditable() {
45 return false;
46 }
47 });
48 }
49
50
51
52
53 public JPopupTextArea(JTextArea proxy) {
54 super(proxy);
55
56
57 this.getProxy().addFocusListener(new FocusAdapter() {
58 @Override
59 public void focusGained(FocusEvent focusEvent) {
60
61 try {
62 JPopupTextArea.this.getProxy().getCaret().setVisible(true);
63 } catch (IllegalArgumentException e) {
64 LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e);
65 }
66 JPopupTextArea.this.getProxy().getCaret().setSelectionVisible(true);
67 }
68 });
69
70 this.getProxy().setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
71 this.getProxy().setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
72 }
73 }