KickJava   Java API By Example, From Geeks To Geeks.

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


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.TextDrawComponent;
31 import org.nightlabs.editor2d.impl.TextDrawComponentImpl;
32
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 TextDrawComponentConverter
39 extends ShapeDrawComponentConverter
40 {
41     public static final String JavaDoc BOLD = TextDrawComponent.PROP_BOLD;
42     public static final String JavaDoc ITALIC = TextDrawComponent.PROP_ITALIC;
43     public static final String JavaDoc FONT_NAME = TextDrawComponent.PROP_FONT_NAME;
44     public static final String JavaDoc FONT_SIZE = TextDrawComponent.PROP_FONT_SIZE;
45     public static final String JavaDoc TEXT = TextDrawComponent.PROP_TEXT;
46     
47     public TextDrawComponentConverter() {
48         super();
49     }
50
51     public boolean canConvert(Class JavaDoc type)
52     {
53         if (type.equals(TextDrawComponentImpl.class)) {
54             return true;
55         }
56         return false;
57     }
58     
59     protected void readAdditional(DrawComponent dc, HierarchicalStreamReader reader, UnmarshallingContext context)
60     {
61         TextDrawComponent tdc = (TextDrawComponent) dc;
62         tdc.setText(reader.getAttribute(TEXT));
63         tdc.setFontName(reader.getAttribute(FONT_NAME));
64         tdc.setFontSize(Integer.parseInt(reader.getAttribute(FONT_SIZE)));
65         tdc.setBold(Boolean.parseBoolean(reader.getAttribute(BOLD)));
66         tdc.setItalic(Boolean.parseBoolean(reader.getAttribute(ITALIC)));
67     }
68     
69     protected void writeAdditional(DrawComponent dc, HierarchicalStreamWriter writer, MarshallingContext context)
70     {
71         TextDrawComponent tdc = (TextDrawComponent) dc;
72     writer.addAttribute(TEXT, ""+tdc.getText());
73     writer.addAttribute(FONT_NAME, ""+tdc.getFontName());
74     writer.addAttribute(FONT_SIZE, ""+tdc.getFontSize());
75     writer.addAttribute(BOLD, ""+tdc.isBold());
76     writer.addAttribute(ITALIC, ""+tdc.isItalic());
77     }
78     
79     protected String JavaDoc getNodeName() {
80         return "TextDrawComponent";
81     }
82         
83     public Class JavaDoc getImpl() {
84         return TextDrawComponentImpl.class;
85     }
86 }
87
Popular Tags