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
29
30
31 private static final Logger LOGGER = LogManager.getRootLogger();
32
33
34
35
36 public JPopupTextArea() {
37 this(StringUtils.EMPTY);
38 }
39
40
41
42
43
44 public JPopupTextArea(String placeholder) {
45 this(new JTextAreaPlaceholder(placeholder) {
46 @Override
47 public boolean isEditable() {
48 return false;
49 }
50 });
51 }
52
53
54
55
56 public JPopupTextArea(JTextArea proxy) {
57 super(proxy);
58
59
60 this.getProxy().addFocusListener(new FocusAdapter() {
61 @Override
62 public void focusGained(FocusEvent focusEvent) {
63
64 try {
65 JPopupTextArea.this.getProxy().getCaret().setVisible(true);
66 } catch (IllegalArgumentException e) {
67 LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e);
68 }
69 JPopupTextArea.this.getProxy().getCaret().setSelectionVisible(true);
70 }
71 });
72
73 this.getProxy().setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
74 this.getProxy().setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
75 }
76 }