KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > browser > core > dnd > DefaultDropActionFactory


1 /*====================================================================
2
3 Objectweb Browser framework
4 Copyright (C) 2000-2003 INRIA & USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Jerome Moroy.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26
27 package org.objectweb.util.browser.core.dnd;
28
29 import java.awt.dnd.DnDConstants JavaDoc;
30 import java.util.HashMap JavaDoc;
31 import java.util.Map JavaDoc;
32
33 import org.objectweb.util.browser.api.DropAction;
34 import org.objectweb.util.browser.core.api.DropActionFactory;
35
36 /**
37  * Basic implementation for DropAction factories
38  *
39  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jerome Moroy</a>
40  *
41  * @version 0.1
42  */

43 public class DefaultDropActionFactory
44     implements DropActionFactory {
45
46     //==================================================================
47
//
48
// Internal state.
49
//
50
//==================================================================
51

52     /** The descriptions of the actions */
53     protected Map JavaDoc labels_ = null;
54
55     /** The class to instantiate */
56     protected Map JavaDoc classes_ = null;
57
58     //==================================================================
59
//
60
// Constructor.
61
//
62
//==================================================================
63

64     public DefaultDropActionFactory(){
65         labels_ = new HashMap JavaDoc();
66         classes_ = new HashMap JavaDoc();
67     }
68     
69     //==================================================================
70
//
71
// No internal method.
72
//
73
//==================================================================
74

75     //==================================================================
76
//
77
// Public methods for DropActionFactory interface.
78
//
79
//==================================================================
80

81     /*
82      * @see org.objectweb.util.browser.api.DropActionFactory#newDropAction(java.lang.Object)
83      */

84     public DropAction newDropAction(Object JavaDoc object, int dropAction) {
85         Class JavaDoc theClass = (Class JavaDoc)classes_.get(new Integer JavaDoc(dropAction));
86         if (theClass != null) {
87             try {
88                 return (DropAction) theClass.newInstance();
89             } catch (java.lang.InstantiationException JavaDoc e) {
90                 System.out.println(theClass.getName() + " : Instanciation exception");
91             } catch (java.lang.IllegalAccessException JavaDoc e) {
92                 System.out.println(theClass.getName() + " : Illegal access exception");
93             }
94         }
95         return null;
96     }
97
98     /*
99      * @see org.objectweb.util.browser.api.DropActionFactory#setClassName(java.lang.Class)
100      */

101     public void setClassName(Class JavaDoc theClass, int dropAction) {
102         classes_.put(new Integer JavaDoc(dropAction), theClass);
103     }
104
105     /*
106      * @see org.objectweb.util.browser.api.DropActionFactory#setLabel(java.lang.String)
107      */

108     public void setLabel(String JavaDoc label, int dropAction){
109         labels_.put(new Integer JavaDoc(dropAction), label);
110     }
111     
112     /*
113      * @see org.objectweb.util.browser.api.DropActionFactory#getLabel()
114      */

115     /**
116      * @param dropAction The code of the dropAction (copy/move/link).
117      * -1 to display all available drag and drop labels.
118      */

119     public String JavaDoc getLabel(int dropAction) {
120         if(dropAction==-1) {
121             StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
122             String JavaDoc copyLabel = (String JavaDoc)labels_.get(new Integer JavaDoc(DnDConstants.ACTION_COPY));
123             if(copyLabel!=null && !copyLabel.equals(""))
124                 sb.append("<br> - Drag-copy: " + copyLabel);
125             String JavaDoc moveLabel = (String JavaDoc)labels_.get(new Integer JavaDoc(DnDConstants.ACTION_MOVE));
126             if(moveLabel!=null && !moveLabel.equals(""))
127                 sb.append("<br> - Drag-move: " + moveLabel);
128             String JavaDoc linkLabel = (String JavaDoc)labels_.get(new Integer JavaDoc(DnDConstants.ACTION_LINK));
129             if(linkLabel!=null && !linkLabel.equals(""))
130                 sb.append("<br> - Drag-link: " + linkLabel);
131             return sb.toString();
132         } else
133             return (String JavaDoc)labels_.get(new Integer JavaDoc(dropAction));
134     }
135
136 }
Popular Tags