View Javadoc
1   /*******************************************************************************
2    * Copyhacked (H) 2012-2025.
3    * This program and the accompanying materials
4    * are made available under no term at all, use it like
5    * you want, but share and discuss it
6    * every time possible with every body.
7    *
8    * Contributors:
9    *      ron190 at ymail dot com - initial implementation
10   *******************************************************************************/
11  package com.jsql.view.swing.text;
12  
13  import javax.swing.*;
14  import java.awt.*;
15  import java.awt.event.FocusAdapter;
16  import java.awt.event.FocusEvent;
17  
18  /**
19   * A JTextArea decorated with popup menu and border.
20   */
21  public class JPopupTextPane extends JPopupTextComponent<JTextPane> implements DecoratorJComponent<JTextPane> {
22      
23      /**
24       * Build new instance of JTextField to decorate.
25       */
26      public JPopupTextPane(String placeholder) {
27          this(new JTextPanePlaceholderConsole(placeholder) {
28              @Override
29              public boolean isEditable() {
30                  return false;
31              }
32          });
33      }
34  
35      /**
36       * Build new instance of JTextArea to decorate.
37       */
38      public JPopupTextPane(JTextPane proxy) {
39          super(proxy);
40  
41          this.getProxy().addFocusListener(new FocusAdapter() {
42              @Override
43              public void focusGained(FocusEvent focusEvent) {
44                  JPopupTextPane.this.getProxy().getCaret().setVisible(true);
45                  JPopupTextPane.this.getProxy().getCaret().setSelectionVisible(true);
46              }
47          });
48          this.getProxy().setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
49          this.getProxy().setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
50      }
51  }