| 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.serializer; |
| 17 | |
| 18 | import java.io.Serializable; |
| 19 | |
| 20 | import org.deduced.PropertyCollection; |
| 21 | import org.deduced.viewer.model.implementation.ImageImplementation; |
| 22 | import org.deduced.viewer.model.implementation.PositionedElementImplementation; |
| 23 | import org.deduced.viewer.web.shared.ImageModel; |
| 24 | import org.deduced.viewer.web.shared.Model; |
| 25 | |
| 26 | /** |
| 27 | * ImageModel Serializer |
| 28 | * |
| 29 | * @author Steve McDuff |
| 30 | * |
| 31 | */ |
| 32 | public class ImageModelSerializer extends WidgetModelSerializer |
| 33 | { |
| 34 | /** |
| 35 | * fill ImageModel |
| 36 | * |
| 37 | * @param model model to serialize |
| 38 | * @param imageModel model to fill |
| 39 | */ |
| 40 | public static void fillImageModel( |
| 41 | PropertyCollection<?, ?> model, ImageModel imageModel) |
| 42 | { |
| 43 | imageModel.setUrl(ImageImplementation.getUrl(model)); |
| 44 | |
| 45 | fillPositionedElement(model, imageModel); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * fill Positioned Element fields |
| 50 | * |
| 51 | * @param model the model to serialize |
| 52 | * @param imageModel the image model to fill |
| 53 | */ |
| 54 | public static void fillPositionedElement( |
| 55 | PropertyCollection<?, ?> model, ImageModel imageModel) |
| 56 | { |
| 57 | imageModel.setTop(PositionedElementImplementation.getTop(model)); |
| 58 | imageModel.setWidth(PositionedElementImplementation.getWidth(model)); |
| 59 | imageModel.setHeight(PositionedElementImplementation.getHeight(model)); |
| 60 | imageModel.setLeft(PositionedElementImplementation.getLeft(model)); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * (non-JSDoc) |
| 65 | * |
| 66 | * @see org.deduced.viewer.web.serializer.WidgetModelSerializer#createSerializedObject(org.deduced.PropertyCollection) |
| 67 | */ |
| 68 | @Override |
| 69 | public Model createSerializedObject( |
| 70 | PropertyCollection<?, ?> collection) |
| 71 | { |
| 72 | return new ImageModel(); |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * (non-JSDoc) |
| 77 | * |
| 78 | * @see org.deduced.viewer.web.serializer.UserInterfaceModelSerializer#fillSerializedObject(java.io.Serializable, |
| 79 | * org.deduced.PropertyCollection, |
| 80 | * org.deduced.viewer.web.serializer.MasterWebSerializer) |
| 81 | */ |
| 82 | @Override |
| 83 | public void fillSerializedObject( |
| 84 | Serializable serializedObject, PropertyCollection<?, ?> collection, |
| 85 | MasterWebSerializer masterSerializer) |
| 86 | { |
| 87 | fillImageModel(collection, (ImageModel) serializedObject); |
| 88 | super.fillSerializedObject(serializedObject, collection, |
| 89 | masterSerializer); |
| 90 | } |
| 91 | } |