1 package jimm.datavision.gui; 2 import jimm.datavision.*; 3 import jimm.datavision.field.SpecialField; 4 import jimm.datavision.source.Column; 5 import java.awt.dnd.*; 6 import java.awt.datatransfer.*; 7 import javax.swing.JTextArea ; 8 9 15 public class DropListenerTextArea 16 extends JTextArea 17 implements DropTargetListener 18 { 19 20 protected Report report; 21 22 public DropListenerTextArea(Report report, String text) { 23 super(text); 24 this.report = report; 25 new DropTarget(this, DnDConstants.ACTION_COPY_OR_MOVE, this); } 29 30 public void drop(DropTargetDropEvent e) { 31 try { 32 DataFlavor stringFlavor = DataFlavor.stringFlavor; 33 Transferable tr = e.getTransferable(); 34 if (e.isDataFlavorSupported(stringFlavor)) { 35 String str = (String )tr.getTransferData(stringFlavor); 36 if (str.startsWith("column:")) { 37 Column col = report.findColumn(str.substring(7)); 38 replaceSelection("{" + col.fullName() + "}"); 39 } 40 else if (str.startsWith("parameter:")) { 41 Parameter param = report.findParameter(str.substring(10)); 42 replaceSelection(param.designLabel()); 43 } 44 else if (str.startsWith("formula:")) { 45 Formula formula = report.findFormula(str.substring(8)); 46 replaceSelection(formula.designLabel()); 47 } 48 else if (str.startsWith("usercol:")) { 49 UserColumn uc = report.findUserColumn(str.substring(8)); 50 replaceSelection(uc.designLabel()); 51 } 52 else if (str.startsWith("special:")) { 53 SpecialField sf = new SpecialField(null, report, null, 54 str.substring(8), false); 55 replaceSelection(sf.formulaString()); 56 } 57 else 58 replaceSelection(str); 59 60 e.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); 61 e.dropComplete(true); 62 } 63 else 64 e.rejectDrop(); 65 } 66 catch(Exception ex) { 67 ErrorHandler.error(ex); 68 } 69 } 70 71 public void dragEnter(DropTargetDragEvent e) { } 72 public void dragExit(DropTargetEvent e) { } 73 public void dragOver(DropTargetDragEvent e) { } 74 public void dropActionChanged(DropTargetDragEvent e) { } 75 } 76 | Popular Tags |