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
19 import javax.swing.JMenuItem;
20 import javax.swing.JTextArea;
21
22
23 /**
24 * TextField with Cut and Paste.
25 *
26 * @author Michael Meyling
27 */
28 public class CPTextArea extends JTextArea {
29
30 /** Here is our context menu. */
31 private final ClipboardListener clipboardactivator;
32
33 /**
34 * Constructor with initial text.
35 *
36 * @param editable Is this text area editable.
37 */
38 public CPTextArea(final boolean editable) {
39 super();
40 setDragEnabled(true);
41 setEditable(editable);
42 clipboardactivator = new ClipboardListener(this);
43 addMouseListener(clipboardactivator);
44 }
45
46 /**
47 * Constructor with initial text.
48 *
49 * @param initialText Initial value.
50 * @param editable Is this text area editable.
51 */
52 public CPTextArea(final String initialText, final boolean editable) {
53 super();
54 setDragEnabled(true);
55 setEditable(editable);
56 clipboardactivator = new ClipboardListener(this);
57 addMouseListener(clipboardactivator);
58 setText(initialText);
59 }
60
61 /**
62 * Add context menu item.
63 *
64 * @param item Add this menu entry.
65 */
66 public void addMenuItem(final JMenuItem item) {
67 clipboardactivator.addMenuItem(item);
68 }
69
70 }
|