1 26 27 package org.objectweb.util.browser.core.dnd; 28 29 import java.awt.dnd.DnDConstants ; 30 import java.util.HashMap ; 31 import java.util.Map ; 32 33 import org.objectweb.util.browser.api.DropAction; 34 import org.objectweb.util.browser.core.api.DropActionFactory; 35 36 43 public class DefaultDropActionFactory 44 implements DropActionFactory { 45 46 52 53 protected Map labels_ = null; 54 55 56 protected Map classes_ = null; 57 58 64 public DefaultDropActionFactory(){ 65 labels_ = new HashMap (); 66 classes_ = new HashMap (); 67 } 68 69 75 81 84 public DropAction newDropAction(Object object, int dropAction) { 85 Class theClass = (Class )classes_.get(new Integer (dropAction)); 86 if (theClass != null) { 87 try { 88 return (DropAction) theClass.newInstance(); 89 } catch (java.lang.InstantiationException e) { 90 System.out.println(theClass.getName() + " : Instanciation exception"); 91 } catch (java.lang.IllegalAccessException e) { 92 System.out.println(theClass.getName() + " : Illegal access exception"); 93 } 94 } 95 return null; 96 } 97 98 101 public void setClassName(Class theClass, int dropAction) { 102 classes_.put(new Integer (dropAction), theClass); 103 } 104 105 108 public void setLabel(String label, int dropAction){ 109 labels_.put(new Integer (dropAction), label); 110 } 111 112 115 119 public String getLabel(int dropAction) { 120 if(dropAction==-1) { 121 StringBuffer sb = new StringBuffer (); 122 String copyLabel = (String )labels_.get(new Integer (DnDConstants.ACTION_COPY)); 123 if(copyLabel!=null && !copyLabel.equals("")) 124 sb.append("<br> - Drag-copy: " + copyLabel); 125 String moveLabel = (String )labels_.get(new Integer (DnDConstants.ACTION_MOVE)); 126 if(moveLabel!=null && !moveLabel.equals("")) 127 sb.append("<br> - Drag-move: " + moveLabel); 128 String linkLabel = (String )labels_.get(new Integer (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 )labels_.get(new Integer (dropAction)); 134 } 135 136 } | Popular Tags |