1 | // Copyright 2012 Georg-August-Universität Göttingen, Germany
|
---|
2 | //
|
---|
3 | // Licensed under the Apache License, Version 2.0 (the "License");
|
---|
4 | // you may not use this file except in compliance with the License.
|
---|
5 | // You may obtain a copy of the License at
|
---|
6 | //
|
---|
7 | // http://www.apache.org/licenses/LICENSE-2.0
|
---|
8 | //
|
---|
9 | // Unless required by applicable law or agreed to in writing, software
|
---|
10 | // distributed under the License is distributed on an "AS IS" BASIS,
|
---|
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
12 | // See the License for the specific language governing permissions and
|
---|
13 | // limitations under the License.
|
---|
14 |
|
---|
15 | package de.ugoe.cs.autoquest.eventcore.gui;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * <p>
|
---|
19 | * Event type for selecting a value.
|
---|
20 | * </p>
|
---|
21 | *
|
---|
22 | * @version 1.0
|
---|
23 | * @author Patrick Harms
|
---|
24 | */
|
---|
25 | public class ValueSelection<T> implements IInteraction {
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * <p>
|
---|
29 | * Id for object serialization.
|
---|
30 | * </p>
|
---|
31 | */
|
---|
32 | private static final long serialVersionUID = 1L;
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * <p>
|
---|
36 | * The selected value.
|
---|
37 | * </p>
|
---|
38 | */
|
---|
39 | private T selectedValue;
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * <p>
|
---|
43 | * Constructor. Creates a new ValueSelection.
|
---|
44 | * </p>
|
---|
45 | *
|
---|
46 | * @param selectedValue
|
---|
47 | * the selected value
|
---|
48 | */
|
---|
49 | public ValueSelection(T selectedValue) {
|
---|
50 | this.selectedValue = selectedValue;
|
---|
51 | }
|
---|
52 |
|
---|
53 | /*
|
---|
54 | * (non-Javadoc)
|
---|
55 | *
|
---|
56 | * @see de.harms.attef.userinteraction.Interaction#getName()
|
---|
57 | */
|
---|
58 | public String getName() {
|
---|
59 | String result = "ValueSelection";
|
---|
60 |
|
---|
61 | if (selectedValue != null) {
|
---|
62 | result += "(\"" + selectedValue + "\")";
|
---|
63 | }
|
---|
64 |
|
---|
65 | return result;
|
---|
66 | }
|
---|
67 |
|
---|
68 | /*
|
---|
69 | * (non-Javadoc)
|
---|
70 | *
|
---|
71 | * @see java.lang.Object#toString()
|
---|
72 | */
|
---|
73 | @Override
|
---|
74 | public String toString() {
|
---|
75 | String result = "select value";
|
---|
76 |
|
---|
77 | if (selectedValue != null) {
|
---|
78 | result += " \"" + selectedValue + "\"";
|
---|
79 | }
|
---|
80 |
|
---|
81 | return result;
|
---|
82 | }
|
---|
83 |
|
---|
84 | /*
|
---|
85 | * (non-Javadoc)
|
---|
86 | *
|
---|
87 | * @see de.harms.attef.userinteraction.Interaction#startsLogicalSequence()
|
---|
88 | */
|
---|
89 | public boolean startsLogicalSequence() {
|
---|
90 | return false;
|
---|
91 | }
|
---|
92 |
|
---|
93 | /*
|
---|
94 | * (non-Javadoc)
|
---|
95 | *
|
---|
96 | * @see de.harms.attef.userinteraction.Interaction#finishesLogicalSequence()
|
---|
97 | */
|
---|
98 | public boolean finishesLogicalSequence() {
|
---|
99 | return false;
|
---|
100 | }
|
---|
101 |
|
---|
102 | /**
|
---|
103 | * <p>
|
---|
104 | * Returns the selected value associated with this event.
|
---|
105 | * </p>
|
---|
106 | *
|
---|
107 | * @return the selectedValue
|
---|
108 | */
|
---|
109 | public T getSelectedValue() {
|
---|
110 | return selectedValue;
|
---|
111 | }
|
---|
112 |
|
---|
113 | /*
|
---|
114 | * (non-Javadoc)
|
---|
115 | *
|
---|
116 | * @see java.lang.Object#equals(java.lang.Object)
|
---|
117 | */
|
---|
118 | @Override
|
---|
119 | public boolean equals(Object obj) {
|
---|
120 | if ((obj == null) || (!(obj instanceof ValueSelection<?>))) {
|
---|
121 | return false;
|
---|
122 | }
|
---|
123 |
|
---|
124 | ValueSelection<?> otherValueSelection = (ValueSelection<?>) obj;
|
---|
125 |
|
---|
126 | return ((otherValueSelection != null) && ((selectedValue == otherValueSelection.selectedValue) || ((selectedValue != null) && (selectedValue
|
---|
127 | .equals(otherValueSelection.selectedValue)))));
|
---|
128 | }
|
---|
129 |
|
---|
130 | /*
|
---|
131 | * (non-Javadoc)
|
---|
132 | *
|
---|
133 | * @see java.lang.Object#hashCode()
|
---|
134 | */
|
---|
135 | @Override
|
---|
136 | public int hashCode() {
|
---|
137 | if( selectedValue==null ) {
|
---|
138 | return 13;
|
---|
139 | }
|
---|
140 | return selectedValue.hashCode();
|
---|
141 | }
|
---|
142 |
|
---|
143 | }
|
---|