KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nightlabs > editor2d > iofilter > xstream > EllipseDrawComponentConverter


1 /* *****************************************************************************
2  * NightLabs Editor2D - Graphical editor framework *
3  * Copyright (C) 2004-2005 NightLabs - http://NightLabs.org *
4  * *
5  * This library is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU Lesser General Public *
7  * License as published by the Free Software Foundation; either *
8  * version 2.1 of the License, or (at your option) any later version. *
9  * *
10  * This library is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
13  * Lesser General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU Lesser General Public *
16  * License along with this library; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 51 Franklin St, Fifth Floor, *
19  * Boston, MA 02110-1301 USA *
20  * *
21  * Or get it online : *
22  * http://www.gnu.org/copyleft/lesser.html *
23  * *
24  * *
25  ******************************************************************************/

26
27 package org.nightlabs.editor2d.iofilter.xstream;
28
29 import org.nightlabs.editor2d.DrawComponent;
30 import org.nightlabs.editor2d.EllipseDrawComponent;
31 import org.nightlabs.editor2d.IConnectable;
32 import org.nightlabs.editor2d.impl.EllipseDrawComponentImpl;
33 import com.thoughtworks.xstream.converters.MarshallingContext;
34 import com.thoughtworks.xstream.converters.UnmarshallingContext;
35 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
36 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
37
38 public class EllipseDrawComponentConverter
39 extends ShapeDrawComponentConverter
40 {
41     public static final String JavaDoc CONNECT = IConnectable.PROP_CONNECT;
42     public static final String JavaDoc START_ANGLE = EllipseDrawComponent.PROP_START_ANGLE;
43     public static final String JavaDoc END_ANGLE = EllipseDrawComponent.PROP_END_ANGLE;
44         
45     public EllipseDrawComponentConverter() {
46         super();
47     }
48
49     public boolean canConvert(Class JavaDoc type)
50     {
51         if (type.equals(EllipseDrawComponentImpl.class)) {
52             return true;
53         }
54         return false;
55     }
56     
57     protected void readAdditional(DrawComponent dc, HierarchicalStreamReader reader, UnmarshallingContext context)
58     {
59         EllipseDrawComponent edc = (EllipseDrawComponent) dc;
60         edc.setConnect(Boolean.parseBoolean(reader.getAttribute(CONNECT)));
61         edc.setStartAngle(Integer.parseInt(reader.getAttribute(START_ANGLE)));
62         edc.setEndAngle(Integer.parseInt(reader.getAttribute(END_ANGLE)));
63     }
64     
65     protected void writeAdditional(DrawComponent dc, HierarchicalStreamWriter writer, MarshallingContext context)
66     {
67         EllipseDrawComponent edc = (EllipseDrawComponent) dc;
68     writer.addAttribute(CONNECT, ""+edc.isConnect());
69     writer.addAttribute(START_ANGLE, ""+edc.getStartAngle());
70     writer.addAttribute(END_ANGLE, ""+edc.getEndAngle());
71   }
72     
73     protected String JavaDoc getNodeName() {
74         return "EllipseDrawComponent";
75     }
76     
77     public Class JavaDoc getImpl() {
78         return EllipseDrawComponentImpl.class;
79     }
80 }
81
Popular Tags