KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > editor2d > model > ModelCreationFactory


1 /**
2  * <p> Project: com.nightlabs.editor2d </p>
3  * <p> Copyright: Copyright (c) 2004 </p>
4  * <p> Company: NightLabs GmbH (Germany) </p>
5  * <p> Creation Date: 26.10.2004 </p>
6  * <p> Author: Daniel Mazurek </p>
7 **/

8 package com.nightlabs.editor2d.model;
9
10 import org.eclipse.gef.requests.CreationFactory;
11
12 import com.nightlabs.editor2d.DrawComponentContainer;
13 import com.nightlabs.editor2d.Editor2DFactory;
14 import com.nightlabs.editor2d.EditorGuide;
15 import com.nightlabs.editor2d.EditorRuler;
16 import com.nightlabs.editor2d.EllipseDrawComponent;
17 import com.nightlabs.editor2d.ImageDrawComponent;
18 import com.nightlabs.editor2d.Layer;
19 import com.nightlabs.editor2d.LineDrawComponent;
20 import com.nightlabs.editor2d.MultiLayerDrawComponent;
21 import com.nightlabs.editor2d.RectangleDrawComponent;
22 import com.nightlabs.editor2d.TextDrawComponent;
23
24 public class ModelCreationFactory
25 implements CreationFactory
26 {
27     protected Class JavaDoc targetClass;
28     
29     public ModelCreationFactory( Class JavaDoc targetClass ) {
30         this.targetClass = targetClass;
31     }
32     
33     /*
34      * @see org.eclipse.gef.requests.CreationFactory#getNewObject()
35      */

36     public Object JavaDoc getNewObject()
37     {
38 // Map registry = EPackage.Registry.INSTANCE;
39
// String editor2DURI = Editor2DPackage.eNS_URI;
40
// Editor2DPackage editor2DPackage =
41
// (Editor2DPackage) registry.get(editor2DURI);
42
// Editor2DFactory factory = editor2DPackage.getEditor2DFactory();
43

44       Editor2DFactory factory = Editor2DFactory.eINSTANCE;
45           
46         Object JavaDoc result = null;
47             
48         if( targetClass.equals(RectangleDrawComponent.class)) {
49             result = factory.createRectangleDrawComponent();
50         }
51         else if( targetClass.equals(Layer.class)) {
52             result = factory.createLayer();
53         }
54         else if( targetClass.equals(EllipseDrawComponent.class)) {
55             result = factory.createEllipseDrawComponent();
56         }
57         else if( targetClass.equals(MultiLayerDrawComponent.class)) {
58           result = factory.createMultiLayerDrawComponent();
59         }
60         else if (targetClass.equals(DrawComponentContainer.class)) {
61           result = factory.createDrawComponentContainer();
62         }
63         else if( targetClass.equals(EditorGuide.class)) {
64           result = factory.createEditorGuide();
65         }
66         else if ( targetClass.equals(EditorRuler.class)) {
67           result = factory.createEditorRuler();
68         }
69         else if ( targetClass.equals(LineDrawComponent.class)) {
70           result = factory.createLineDrawComponent();
71         }
72     else if ( targetClass.equals(TextDrawComponent.class)) {
73       result = factory.createTextDrawComponent();
74     }
75     else if ( targetClass.equals(ImageDrawComponent.class)) {
76       result = factory.createImageDrawComponent();
77     }
78             
79         return result;
80     }
81
82     /*
83      * @see org.eclipse.gef.requests.CreationFactory#getObjectType()
84      */

85     public Object JavaDoc getObjectType()
86     {
87         return targetClass;
88     }
89 }
90
91
Popular Tags