KickJava   Java API By Example, From Geeks To Geeks.

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


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.Map JavaDoc;
30
31 import org.nightlabs.editor2d.DrawComponent;
32
33 /**
34  * @author Daniel.Mazurek <at> NightLabs <dot> de
35  *
36  */

37 public class DescriptorManager
38 //implements IDrawComponentDescriptor
39
{
40
41     public DescriptorManager()
42     {
43         super();
44         addDescriptor(defaultDescriptor, DrawComponent.class);
45     }
46
47     protected IDrawComponentDescriptor defaultDescriptor = new DrawComponentDescriptor(null);
48     protected IDrawComponentDescriptor currentDescriptor = defaultDescriptor;
49         
50     protected Map JavaDoc<Class JavaDoc, IDrawComponentDescriptor> class2Descriptor = new HashMap JavaDoc<Class JavaDoc, IDrawComponentDescriptor>();
51     public void addDescriptor(IDrawComponentDescriptor desc, Class JavaDoc dcClass) {
52         class2Descriptor.put(dcClass, desc);
53     }
54         
55     protected DrawComponent drawComponent = null;
56     public void setDrawComponent(DrawComponent dc)
57     {
58         this.drawComponent = dc;
59         if (class2Descriptor.keySet().contains(dc.getClass())) {
60             IDrawComponentDescriptor desc = class2Descriptor.get(dc.getClass());
61             currentDescriptor = desc;
62         }
63         else {
64             currentDescriptor = defaultDescriptor;
65         }
66         currentDescriptor.setDrawComponent(dc);
67     }
68     public DrawComponent getDrawComponent() {
69         return drawComponent;
70     }
71     
72     public String JavaDoc getEntriesAsString(boolean lineWrap) {
73         return currentDescriptor.getEntriesAsString(lineWrap);
74     }
75     
76     public Map JavaDoc<String JavaDoc, String JavaDoc> getProperties() {
77         return currentDescriptor.getProperties();
78     }
79       
80 }
81
Popular Tags