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 5886
|
---|
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 | // Fix minimum size when columns are specified
|
---|
33 | if (columns > 0) {
|
---|
34 | setMinimumSize(getPreferredSize());
|
---|
35 | }
|
---|
36 | }
|
---|
37 |
|
---|
38 | /**
|
---|
39 | * Constructs a new <code>JosmTextField</code> initialized with the
|
---|
40 | * specified text and columns. A default model is created.
|
---|
41 | *
|
---|
42 | * @param text the text to be displayed, or <code>null</code>
|
---|
43 | * @param columns the number of columns to use to calculate
|
---|
44 | * the preferred width; if columns is set to zero, the
|
---|
45 | * preferred width will be whatever naturally results from
|
---|
46 | * the component implementation
|
---|
47 | */
|
---|
48 | public JosmTextField(String text, int columns) {
|
---|
49 | this(null, text, columns);
|
---|
50 | }
|
---|
51 |
|
---|
52 | /**
|
---|
53 | * Constructs a new <code>JosmTextField</code> initialized with the
|
---|
54 | * specified text. A default model is created and the number of
|
---|
55 | * columns is 0.
|
---|
56 | *
|
---|
57 | * @param text the text to be displayed, or <code>null</code>
|
---|
58 | */
|
---|
59 | public JosmTextField(String text) {
|
---|
60 | this(null, text, 0);
|
---|
61 | }
|
---|
62 |
|
---|
63 | /**
|
---|
64 | * Constructs a new empty <code>JosmTextField</code> with the specified
|
---|
65 | * number of columns.
|
---|
66 | * A default model is created and the initial string is set to
|
---|
67 | * <code>null</code>.
|
---|
68 | *
|
---|
69 | * @param columns the number of columns to use to calculate
|
---|
70 | * the preferred width; if columns is set to zero, the
|
---|
71 | * preferred width will be whatever naturally results from
|
---|
72 | * the component implementation
|
---|
73 | */
|
---|
74 | public JosmTextField(int columns) {
|
---|
75 | this(null, null, columns);
|
---|
76 | }
|
---|
77 |
|
---|
78 | /**
|
---|
79 | * Constructs a new <code>JosmTextField</code>. A default model is created,
|
---|
80 | * the initial string is <code>null</code>,
|
---|
81 | * and the number of columns is set to 0.
|
---|
82 | */
|
---|
83 | public JosmTextField() {
|
---|
84 | this(null, null, 0);
|
---|
85 | }
|
---|
86 | }
|
---|