CPTextPane.java
01 /* This file is part of the project "Hilbert II" - http://www.qedeq.org
02  *
03  * Copyright 2000-2013,  Michael Meyling <mime@qedeq.org>.
04  *
05  * "Hilbert II" is free software; you can redistribute
06  * it and/or modify it under the terms of the GNU General Public
07  * License as published by the Free Software Foundation; either
08  * version 2 of the License, or (at your option) any later version.
09  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  */
15 
16 package org.qedeq.gui.se.element;
17 
18 import javax.swing.JMenuItem;
19 import javax.swing.JTextPane;
20 
21 
22 /**
23  * TextField with Cut and Paste.
24  *
25  @author  Michael Meyling
26  */
27 public class CPTextPane extends JTextPane {
28 
29     /** Here hides our context menu. */
30     private final ClipboardListener clipboardactivator;
31 
32     /**
33      * Constructor with initial text.
34      *
35      @param   editable    Is this text area editable.
36      */
37     public CPTextPane(final boolean editable) {
38         super();
39         setDragEnabled(true);
40         setEditable(editable);
41         clipboardactivator = new ClipboardListener(this);
42         addMouseListener(clipboardactivator);
43     }
44 
45     /**
46      * Constructor with initial text.
47      *
48      @param   initialText Initial value.
49      @param   editable    Is this text area editable.
50      */
51     public CPTextPane(final String initialText, final boolean editable) {
52         super();
53         setDragEnabled(true);
54         setEditable(editable);
55         clipboardactivator = new ClipboardListener(this);
56         addMouseListener(clipboardactivator);
57         setText(initialText);
58     }
59 
60     /**
61      * Add context menu item.
62      *
63      @param   item    Add this menu entry.
64      */
65     public void addMenuItem(final JMenuItem item) {
66         clipboardactivator.addMenuItem(item);
67     }
68 
69 }