KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nightlabs > editor2d > viewer > descriptor > DrawComponentDescriptor


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 package org.nightlabs.editor2d.viewer.descriptor;
27
28 import java.util.HashMap JavaDoc;
29 import java.util.Iterator JavaDoc;
30 import java.util.LinkedList JavaDoc;
31 import java.util.List JavaDoc;
32 import java.util.Map JavaDoc;
33
34 import org.nightlabs.editor2d.DrawComponent;
35 import org.nightlabs.editor2d.viewer.ViewerPlugin;
36
37 /**
38  * the Implementation of the {@link IDrawComponentDescriptor} Interface
39  * @author Daniel.Mazurek <at> NightLabs <dot> de
40  *
41  */

42 public class DrawComponentDescriptor
43 implements IDrawComponentDescriptor
44 {
45     public DrawComponentDescriptor(DrawComponent dc)
46     {
47         super();
48         setDrawComponent(dc);
49     }
50     
51     protected DrawComponent dc = null;
52     
53     /**
54      * @see IDrawComponentDescriptor#getDrawComponent()
55      */

56     public DrawComponent getDrawComponent() {
57         return dc;
58     }
59     
60     /**
61      * resets all entries for the new DrawComponent
62      * @see IDrawComponentDescriptor#setDrawComponent(DrawComponent)
63      */

64     public void setDrawComponent(DrawComponent dc)
65     {
66         this.dc = dc;
67         if (dc != null) {
68             addEntry(ViewerPlugin.getResourceString("descriptor.id.name"), ""+getDrawComponent().getId());
69             addEntry(ViewerPlugin.getResourceString("descriptor.name.name"), getDrawComponent().getName());
70             addEntry(ViewerPlugin.getResourceString("descriptor.x.name"), ""+getDrawComponent().getX());
71             addEntry(ViewerPlugin.getResourceString("descriptor.y.name"), ""+getDrawComponent().getY());
72             addEntry(ViewerPlugin.getResourceString("descriptor.width.name"), ""+getDrawComponent().getWidth());
73             addEntry(ViewerPlugin.getResourceString("descriptor.height.name"), ""+getDrawComponent().getHeight());
74             addEntry(ViewerPlugin.getResourceString("descriptor.rotation.name"), ""+(int)getDrawComponent().getRotation());
75         }
76     }
77     
78     protected List JavaDoc<String JavaDoc> names = new LinkedList JavaDoc<String JavaDoc>();
79     public List JavaDoc<String JavaDoc> getNames() {
80         return names;
81     }
82         
83     protected Map JavaDoc<String JavaDoc, String JavaDoc> properties = new HashMap JavaDoc<String JavaDoc, String JavaDoc>();
84     
85     /**
86      * @see IDrawComponentDescriptor#getProperties()
87      */

88     public Map JavaDoc<String JavaDoc, String JavaDoc> getProperties() {
89         return properties;
90     }
91     
92     /**
93      * @see IDrawComponentDescriptor#addEntry(String, String)
94      */

95     public void addEntry(String JavaDoc name, String JavaDoc value)
96     {
97         if (!names.contains(name))
98             names.add(name);
99         properties.put(name, value);
100     }
101     
102     protected StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
103     
104 // /**
105
// * @see IDrawComponentDescriptor#getEntriesAsString(boolean)
106
// */
107
// public String getEntriesAsString(boolean lineWrap)
108
// {
109
// sb = new StringBuffer();
110
// if (!lineWrap)
111
// {
112
// for (Iterator<String> it = names.iterator(); it.hasNext(); )
113
// {
114
// String name = it.next();
115
// String value = properties.get(name);
116
// sb.append(name);
117
// sb.append(" = ");
118
// sb.append(value);
119
// sb.append(", ");
120
// }
121
// }
122
// else {
123
// for (Iterator<String> it = names.iterator(); it.hasNext(); )
124
// {
125
// String name = it.next();
126
// String value = properties.get(name);
127
// sb.append(name);
128
// sb.append(" = ");
129
// sb.append(value);
130
// sb.append("\n");
131
// }
132
// }
133
// return sb.toString();
134
// }
135

136     /**
137      * @see IDrawComponentDescriptor#getEntriesAsString(boolean)
138      */

139     public String JavaDoc getEntriesAsString(boolean lineWrap)
140     {
141         sb = new StringBuffer JavaDoc();
142         if (!lineWrap)
143         {
144             int lastIndex = names.size()-1;
145             for (int i=0; i<lastIndex; i++)
146             {
147                 String JavaDoc name = names.get(i);
148                 String JavaDoc value = properties.get(name);
149                 sb.append(name);
150                 sb.append(" = ");
151                 sb.append(value);
152                 if (i != lastIndex)
153                     sb.append(", ");
154             }
155         }
156         else {
157             for (Iterator JavaDoc<String JavaDoc> it = names.iterator(); it.hasNext(); )
158             {
159                 String JavaDoc name = it.next();
160                 String JavaDoc value = properties.get(name);
161                 sb.append(name);
162                 sb.append(" = ");
163                 sb.append(value);
164                 sb.append("\n");
165             }
166         }
167         return sb.toString();
168     }
169     
170 }
171
Popular Tags