KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > explorer > core > dnd > lib > BasicDnDDescriptions


1 /*====================================================================
2
3 Objectweb Explorer Framework
4 Copyright (C) 2000-2004 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, Philippe Merle.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26 package org.objectweb.util.explorer.core.dnd.lib;
27
28 import java.util.HashMap JavaDoc;
29 import java.util.List JavaDoc;
30 import java.util.Map JavaDoc;
31 import java.util.Vector JavaDoc;
32
33 import org.objectweb.util.explorer.core.common.api.Description;
34 import org.objectweb.util.explorer.core.dnd.api.DnDDescription;
35 import org.objectweb.util.explorer.core.dnd.api.DnDDescriptions;
36
37 /**
38  * Basic implementation of the DnDDescription interface.
39  *
40  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jérôme Moroy</a>,
41  * <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>.
42  *
43  * @version 0.1
44  */

45 public class BasicDnDDescriptions
46   implements DnDDescriptions
47 {
48
49     //==================================================================
50
//
51
// Internal States.
52
//
53
// ==================================================================
54

55     /** The map where storing the drop actions. */
56     protected Map JavaDoc dropActions_;
57     
58     // ==================================================================
59
//
60
// Constructors.
61
//
62
// ==================================================================
63

64     /**
65      * Default constructor
66      */

67     public BasicDnDDescriptions(){
68         dropActions_ = new HashMap JavaDoc();
69     }
70     
71     // ==================================================================
72
//
73
// Internal methods.
74
//
75
// ==================================================================
76

77     /**
78      * Add the description of the drop action into the given list if the given dndDesc is not null.
79      */

80     protected void addDescription(DnDDescription dndDesc, List JavaDoc l){
81         if(dndDesc!=null && !"".equals(dndDesc.getLabel().trim())){
82             l.add("[" + dndDesc.getType() + "] " + dndDesc.getLabel());
83         }
84     }
85
86     protected String JavaDoc getDnDDescription(DnDDescription dndDesc){
87         if(dndDesc!=null){
88             return dndDesc.toString();
89         }
90         return "null";
91     }
92     
93     // ==================================================================
94
//
95
// Public methods for Description interface.
96
//
97
// ==================================================================
98

99     /* (non-Javadoc)
100      * @see org.objectweb.util.explorer.core.common.api.Description#getDescriptionType()
101      */

102     public String JavaDoc getDescriptionType() {
103         return Description.DND_DESCRIPTION;
104     }
105
106     /* (non-Javadoc)
107      * @see org.objectweb.util.explorer.core.common.api.Description#isEmpty()
108      */

109     public boolean isEmpty() {
110         return dropActions_.isEmpty();
111     }
112     
113     // ==================================================================
114
//
115
// Public methods for DnDDescription interface.
116
//
117
// ==================================================================
118

119     /* (non-Javadoc)
120      * @see org.objectweb.util.explorer.core.dnd.api.DnDDescription#addDropAction(int, org.objectweb.util.explorer.core.code.api.CodeDescription)
121      */

122     public void addDropAction(DnDDescription dndDesc) {
123         if (dndDesc!=null && !dndDesc.isEmpty()
124                 && (DnDDescription.MOVE_ACTION.equals(dndDesc.getType())
125                 || DnDDescription.COPY_ACTION.equals(dndDesc.getType())
126                 || DnDDescription.LINK_ACTION.equals(dndDesc.getType()))){
127             dropActions_.put(dndDesc.getType(), dndDesc);
128         }
129     }
130
131     /* (non-Javadoc)
132      * @see org.objectweb.util.explorer.core.dnd.api.DnDDescription#getDropAction(int)
133      */

134     public DnDDescription getDropAction(String JavaDoc actionType) {
135         return (DnDDescription)dropActions_.get(actionType);
136     }
137
138     /* (non-Javadoc)
139      * @see org.objectweb.util.explorer.core.dnd.api.DnDDescriptions#getActionsDescription()
140      */

141     public String JavaDoc[] getActionsDescription() {
142         Vector JavaDoc l = new Vector JavaDoc();
143         addDescription(getDropAction(DnDDescription.MOVE_ACTION),l);
144         addDescription(getDropAction(DnDDescription.COPY_ACTION),l);
145         addDescription(getDropAction(DnDDescription.LINK_ACTION),l);
146         return (String JavaDoc[])l.toArray(new String JavaDoc[l.size()]);
147     }
148
149     // ==================================================================
150
//
151
// Public methods surcharging Object class.
152
//
153
// ==================================================================
154

155     /**
156      * Surcharging the Object.equals method.
157      * @see DefaultKey#equals(DefaultKey)
158      */

159     public boolean equals(Object JavaDoc o){
160         if(o!=null && o instanceof BasicDnDDescription)
161             return equals((BasicDnDDescription)o);
162         return false;
163     }
164     
165     /**
166      * Return a String representation of a BasicItemDescription
167      */

168     public String JavaDoc toString(){
169         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
170         buf.append("BasicDnDDescriptions[dropActions=[");
171         buf.append("move=" + getDnDDescription(getDropAction(DnDDescription.MOVE_ACTION)) + ", ");
172         buf.append("copy=" + getDnDDescription(getDropAction(DnDDescription.COPY_ACTION)) + ", ");
173         buf.append("link=" + getDnDDescription(getDropAction(DnDDescription.LINK_ACTION)));
174         buf.append("]]");
175         return buf.toString();
176     }
177     
178 }
179  
180
Popular Tags