1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.widgets;
|
---|
3 |
|
---|
4 | import javax.swing.JTextField;
|
---|
5 | import javax.swing.text.Document;
|
---|
6 |
|
---|
7 | /**
|
---|
8 | * Subclass of {@link JTextField} that adds a "native" context menu (cut/copy/paste/select all).
|
---|
9 | * @since 5885
|
---|
10 | */
|
---|
11 | public class JosmTextField extends JTextField {
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * Constructs a new <code>JosmTextField</code> that uses the given text
|
---|
15 | * storage model and the given number of columns.
|
---|
16 | * This is the constructor through which the other constructors feed.
|
---|
17 | * If the document is <code>null</code>, a default model is created.
|
---|
18 | *
|
---|
19 | * @param doc the text storage to use; if this is <code>null</code>,
|
---|
20 | * a default will be provided by calling the
|
---|
21 | * <code>createDefaultModel</code> method
|
---|
22 | * @param text the initial string to display, or <code>null</code>
|
---|
23 | * @param columns the number of columns to use to calculate
|
---|
24 | * the preferred width >= 0; if <code>columns</code>
|
---|
25 | * is set to zero, the preferred width will be whatever
|
---|
26 | * naturally results from the component implementation
|
---|
27 | * @exception IllegalArgumentException if <code>columns</code> < 0
|
---|
28 | */
|
---|
29 | public JosmTextField(Document doc, String text, int columns) {
|
---|
30 | super(doc, text, columns);
|
---|
31 | TextContextualPopupMenu.enableMenuFor(this);
|
---|
32 | }
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * Constructs a new <code>JosmTextField</code> initialized with the
|
---|
36 | * specified text and columns. A default model is created.
|
---|
37 | *
|
---|
38 | * @param text the text to be displayed, or <code>null</code>
|
---|
39 | * @param columns the number of columns to use to calculate
|
---|
40 | * the preferred width; if columns is set to zero, the
|
---|
41 | * preferred width will be whatever naturally results from
|
---|
42 | * the component implementation
|
---|
43 | */
|
---|
44 | public JosmTextField(String text, int columns) {
|
---|
45 | this(null, text, columns);
|
---|
46 | }
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * Constructs a new <code>JosmTextField</code> initialized with the
|
---|
50 | * specified text. A default model is created and the number of
|
---|
51 | * columns is 0.
|
---|
52 | *
|
---|
53 | * @param text the text to be displayed, or <code>null</code>
|
---|
54 | */
|
---|
55 | public JosmTextField(String text) {
|
---|
56 | this(null, text, 0);
|
---|
57 | }
|
---|
58 |
|
---|
59 | /**
|
---|
60 | * Constructs a new empty <code>JosmTextField</code> with the specified
|
---|
61 | * number of columns.
|
---|
62 | * A default model is created and the initial string is set to
|
---|
63 | * <code>null</code>.
|
---|
64 | *
|
---|
65 | * @param columns the number of columns to use to calculate
|
---|
66 | * the preferred width; if columns is set to zero, the
|
---|
67 | * preferred width will be whatever naturally results from
|
---|
68 | * the component implementation
|
---|
69 | */
|
---|
70 | public JosmTextField(int columns) {
|
---|
71 | this(null, null, columns);
|
---|
72 | }
|
---|
73 |
|
---|
74 | /**
|
---|
75 | * Constructs a new <code>JosmTextField</code>. A default model is created,
|
---|
76 | * the initial string is <code>null</code>,
|
---|
77 | * and the number of columns is set to 0.
|
---|
78 | */
|
---|
79 | public JosmTextField() {
|
---|
80 | this(null, null, 0);
|
---|
81 | }
|
---|
82 | }
|
---|