1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.tagging.ac;
|
---|
3 |
|
---|
4 | import org.openstreetmap.josm.data.tagging.ac.AutoCompletionPriority;
|
---|
5 |
|
---|
6 | /**
|
---|
7 | * Describes the priority of an item in an autocompletion list.
|
---|
8 | * The selected flag is currently only used in plugins.
|
---|
9 | *
|
---|
10 | * Instances of this class are not modifiable.
|
---|
11 | * @since 1762
|
---|
12 | * @deprecated to be removed end of 2017. Use {@link AutoCompletionPriority} instead
|
---|
13 | */
|
---|
14 | @Deprecated
|
---|
15 | public class AutoCompletionItemPriority implements Comparable<AutoCompletionItemPriority> {
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * Indicates, that the value is standard and it is found in the data.
|
---|
19 | * This has higher priority than some arbitrary standard value that is
|
---|
20 | * usually not used by the user.
|
---|
21 | */
|
---|
22 | public static final AutoCompletionItemPriority IS_IN_STANDARD_AND_IN_DATASET = new AutoCompletionItemPriority(
|
---|
23 | AutoCompletionPriority.IS_IN_STANDARD_AND_IN_DATASET);
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Indicates that this is an arbitrary value from the data set, i.e.
|
---|
27 | * the value of a tag name=*.
|
---|
28 | */
|
---|
29 | public static final AutoCompletionItemPriority IS_IN_DATASET = new AutoCompletionItemPriority(AutoCompletionPriority.IS_IN_DATASET);
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * Indicates that this is a standard value, i.e. a standard tag name
|
---|
33 | * or a standard value for a given tag name (from the presets).
|
---|
34 | */
|
---|
35 | public static final AutoCompletionItemPriority IS_IN_STANDARD = new AutoCompletionItemPriority(AutoCompletionPriority.IS_IN_STANDARD);
|
---|
36 |
|
---|
37 | /**
|
---|
38 | * Indicates that this is a value from a selected object.
|
---|
39 | */
|
---|
40 | public static final AutoCompletionItemPriority IS_IN_SELECTION = new AutoCompletionItemPriority(AutoCompletionPriority.IS_IN_SELECTION);
|
---|
41 |
|
---|
42 | /** Unknown priority. This is the lowest priority. */
|
---|
43 | public static final AutoCompletionItemPriority UNKNOWN = new AutoCompletionItemPriority(AutoCompletionPriority.UNKNOWN);
|
---|
44 |
|
---|
45 | private static final int NO_USER_INPUT = Integer.MAX_VALUE;
|
---|
46 |
|
---|
47 | private final AutoCompletionPriority priority;
|
---|
48 |
|
---|
49 | /**
|
---|
50 | * Constructs a new {@code AutoCompletionItemPriority}.
|
---|
51 | *
|
---|
52 | * @param inDataSet true, if the item is found in the currently active data layer
|
---|
53 | * @param inStandard true, if the item is a standard tag, e.g. from the presets
|
---|
54 | * @param selected true, if it is found on an object that is currently selected
|
---|
55 | * @param userInput null, if the user hasn't entered this tag so far. A number when
|
---|
56 | * the tag key / value has been entered by the user before. A lower number means
|
---|
57 | * this happened more recently and beats a higher number in priority.
|
---|
58 | */
|
---|
59 | public AutoCompletionItemPriority(boolean inDataSet, boolean inStandard, boolean selected, Integer userInput) {
|
---|
60 | this(new AutoCompletionPriority(inDataSet, inStandard, selected, userInput));
|
---|
61 | }
|
---|
62 |
|
---|
63 | /**
|
---|
64 | * Constructs a new {@code AutoCompletionItemPriority}.
|
---|
65 | *
|
---|
66 | * @param inDataSet true, if the item is found in the currently active data layer
|
---|
67 | * @param inStandard true, if the item is a standard tag, e.g. from the presets
|
---|
68 | * @param selected true, if it is found on an object that is currently selected
|
---|
69 | */
|
---|
70 | public AutoCompletionItemPriority(boolean inDataSet, boolean inStandard, boolean selected) {
|
---|
71 | this(inDataSet, inStandard, selected, NO_USER_INPUT);
|
---|
72 | }
|
---|
73 |
|
---|
74 | /**
|
---|
75 | * Constructs a new {@code AutoCompletionItemPriority} from an existing {@link AutoCompletionPriority}.
|
---|
76 | * @param other {@code AutoCompletionPriority} to convert
|
---|
77 | * @since 12859
|
---|
78 | */
|
---|
79 | public AutoCompletionItemPriority(AutoCompletionPriority other) {
|
---|
80 | this.priority = other;
|
---|
81 | }
|
---|
82 |
|
---|
83 | /**
|
---|
84 | * Determines if the item is found in the currently active data layer.
|
---|
85 | * @return {@code true} if the item is found in the currently active data layer
|
---|
86 | */
|
---|
87 | public boolean isInDataSet() {
|
---|
88 | return priority.isInDataSet();
|
---|
89 | }
|
---|
90 |
|
---|
91 | /**
|
---|
92 | * Determines if the item is a standard tag, e.g. from the presets.
|
---|
93 | * @return {@code true} if the item is a standard tag, e.g. from the presets
|
---|
94 | */
|
---|
95 | public boolean isInStandard() {
|
---|
96 | return priority.isInStandard();
|
---|
97 | }
|
---|
98 |
|
---|
99 | /**
|
---|
100 | * Determines if it is found on an object that is currently selected.
|
---|
101 | * @return {@code true} if it is found on an object that is currently selected
|
---|
102 | */
|
---|
103 | public boolean isSelected() {
|
---|
104 | return priority.isSelected();
|
---|
105 | }
|
---|
106 |
|
---|
107 | /**
|
---|
108 | * Returns a number when the tag key / value has been entered by the user before.
|
---|
109 | * A lower number means this happened more recently and beats a higher number in priority.
|
---|
110 | * @return a number when the tag key / value has been entered by the user before.
|
---|
111 | * {@code null}, if the user hasn't entered this tag so far.
|
---|
112 | */
|
---|
113 | public Integer getUserInput() {
|
---|
114 | return priority.getUserInput();
|
---|
115 | }
|
---|
116 |
|
---|
117 | /**
|
---|
118 | * Imposes an ordering on the priorities.
|
---|
119 | * Currently, being in the current DataSet is worth more than being in the Presets.
|
---|
120 | */
|
---|
121 | @Override
|
---|
122 | public int compareTo(AutoCompletionItemPriority other) {
|
---|
123 | return priority.compareTo(other.priority);
|
---|
124 | }
|
---|
125 |
|
---|
126 | /**
|
---|
127 | * Merges two priorities.
|
---|
128 | * The resulting priority is always >= the original ones.
|
---|
129 | * @param other other priority
|
---|
130 | * @return the merged priority
|
---|
131 | */
|
---|
132 | public AutoCompletionItemPriority mergeWith(AutoCompletionItemPriority other) {
|
---|
133 | return new AutoCompletionItemPriority(priority.mergeWith(other.priority));
|
---|
134 | }
|
---|
135 |
|
---|
136 | @Override
|
---|
137 | public String toString() {
|
---|
138 | return priority.toString();
|
---|
139 | }
|
---|
140 |
|
---|
141 | /**
|
---|
142 | * Returns the underlying priority.
|
---|
143 | * @return the underlying priority
|
---|
144 | * @since 12859
|
---|
145 | */
|
---|
146 | public AutoCompletionPriority getPriority() {
|
---|
147 | return priority;
|
---|
148 | }
|
---|
149 | }
|
---|