1 | /** |
2 | * Copyright 2005-2011 Steve McDuff d-duff@users.sourceforge.net |
3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. |
6 | * You may obtain a copy of the License at |
7 | * |
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | * |
10 | * Unless required by applicable law or agreed to in writing, software |
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. |
15 | */ |
16 | package org.deduced.viewer.web.shared; |
17 | |
18 | import com.google.gwt.user.client.ui.Image; |
19 | import com.google.gwt.user.client.ui.UIObject; |
20 | |
21 | /** |
22 | * Image Model |
23 | * |
24 | * @author Steve McDuff |
25 | */ |
26 | public class ImageModel extends WidgetModel |
27 | { |
28 | |
29 | /** |
30 | * serialVersionUID |
31 | */ |
32 | private static final long serialVersionUID = -2750706294428994631L; |
33 | |
34 | /** |
35 | * URL of the image to display |
36 | */ |
37 | private String url; |
38 | |
39 | /** |
40 | * top of the image. If null, the default image top is used |
41 | */ |
42 | private Integer top; |
43 | |
44 | /** |
45 | * left coordinate of the image. If null, the default image left coordinate |
46 | * is used |
47 | */ |
48 | private Integer left; |
49 | |
50 | /** |
51 | * width of the image. If null, the default image width is used |
52 | */ |
53 | private Integer width; |
54 | |
55 | /** |
56 | * height of the image. If null, the default image height is used |
57 | */ |
58 | private Integer height; |
59 | |
60 | /** |
61 | * |
62 | * ImageModel constructor |
63 | */ |
64 | public ImageModel() |
65 | { |
66 | |
67 | } |
68 | |
69 | /** |
70 | * (non-JSDoc) |
71 | * |
72 | * @see org.deduced.viewer.web.shared.WidgetModel#createUIObject() |
73 | */ |
74 | @Override |
75 | public UIObject createUIObject() |
76 | { |
77 | return new Image(); |
78 | } |
79 | |
80 | /** |
81 | * get Image |
82 | * |
83 | * @return the image |
84 | */ |
85 | public Image getImage() |
86 | { |
87 | return (Image) getUIObject(); |
88 | } |
89 | |
90 | /** |
91 | * (non-JSDoc) |
92 | * |
93 | * @see org.deduced.viewer.web.shared.UserInterfaceModel#internalSynchronizeWithUI() |
94 | */ |
95 | @Override |
96 | public void internalSynchronizeWithUI() |
97 | { |
98 | super.internalSynchronizeWithUI(); |
99 | Image image = getImage(); |
100 | image.setUrl(getUrl()); |
101 | if (getTop() != null && getLeft() != null && getWidth() != null |
102 | && getHeight() != null) |
103 | { |
104 | image.setVisibleRect(getLeft().intValue(), getTop().intValue(), |
105 | getWidth().intValue(), getHeight().intValue()); |
106 | } |
107 | } |
108 | |
109 | /** |
110 | * (non-JSDoc) |
111 | * |
112 | * @see org.deduced.viewer.web.shared.UserInterfaceModel#propertyChanged(org.deduced.viewer.web.shared.ChangeEvent) |
113 | */ |
114 | @Override |
115 | public void propertyChanged( |
116 | ChangeEvent event) |
117 | { |
118 | if (Utilities.equals(event.getName(), "url")) |
119 | { |
120 | setUrl((String) event.getSerializableValue()); |
121 | synchronizeWithUI(); |
122 | } |
123 | else if (Utilities.equals(event.getName(), "top")) |
124 | { |
125 | setTop((Integer) event.getSerializableValue()); |
126 | synchronizeWithUI(); |
127 | } |
128 | else if (Utilities.equals(event.getName(), "left")) |
129 | { |
130 | setLeft((Integer) event.getSerializableValue()); |
131 | synchronizeWithUI(); |
132 | } |
133 | else if (Utilities.equals(event.getName(), "width")) |
134 | { |
135 | setWidth((Integer) event.getSerializableValue()); |
136 | synchronizeWithUI(); |
137 | } |
138 | else if (Utilities.equals(event.getName(), "height")) |
139 | { |
140 | setHeight((Integer) event.getSerializableValue()); |
141 | synchronizeWithUI(); |
142 | } |
143 | else |
144 | { |
145 | super.propertyChanged(event); |
146 | } |
147 | } |
148 | |
149 | /** |
150 | * @param setUrl the url to set |
151 | */ |
152 | public void setUrl( |
153 | String setUrl) |
154 | { |
155 | url = setUrl; |
156 | } |
157 | |
158 | /** |
159 | * @return the url |
160 | */ |
161 | public String getUrl() |
162 | { |
163 | return url; |
164 | } |
165 | |
166 | /** |
167 | * @param setTop the top to set |
168 | */ |
169 | public void setTop( |
170 | Integer setTop) |
171 | { |
172 | top = setTop; |
173 | } |
174 | |
175 | /** |
176 | * @return the top |
177 | */ |
178 | public Integer getTop() |
179 | { |
180 | return top; |
181 | } |
182 | |
183 | /** |
184 | * @param setLeft the left to set |
185 | */ |
186 | public void setLeft( |
187 | Integer setLeft) |
188 | { |
189 | left = setLeft; |
190 | } |
191 | |
192 | /** |
193 | * @return the left |
194 | */ |
195 | public Integer getLeft() |
196 | { |
197 | return left; |
198 | } |
199 | |
200 | /** |
201 | * @param setWidth the width to set |
202 | */ |
203 | public void setWidth( |
204 | Integer setWidth) |
205 | { |
206 | width = setWidth; |
207 | } |
208 | |
209 | /** |
210 | * @return the width |
211 | */ |
212 | public Integer getWidth() |
213 | { |
214 | return width; |
215 | } |
216 | |
217 | /** |
218 | * @param setHeight the height to set |
219 | */ |
220 | public void setHeight( |
221 | Integer setHeight) |
222 | { |
223 | height = setHeight; |
224 | } |
225 | |
226 | /** |
227 | * @return the height |
228 | */ |
229 | public Integer getHeight() |
230 | { |
231 | return height; |
232 | } |
233 | |
234 | } |