01: package jimm.datavision.gui;
02:
03: import jimm.datavision.*;
04: import jimm.datavision.field.SpecialField;
05: import jimm.datavision.source.Column;
06: import java.awt.dnd.*;
07: import java.awt.datatransfer.*;
08: import javax.swing.JTextArea;
09:
10: /**
11: * A text area that accepts drags containing report fields. Used by
12: * {@link CodeEditorWin}s.
13: *
14: * @author Jim Menard, <a href="mailto:jimm@io.com">jimm@io.com</a>
15: */
16: public class DropListenerTextArea extends JTextArea implements
17: DropTargetListener {
18:
19: protected Report report;
20:
21: public DropListenerTextArea(Report report, String text) {
22: super (text);
23: this .report = report;
24: new DropTarget(this , // component
25: DnDConstants.ACTION_COPY_OR_MOVE, // actions
26: this ); // DropTargetListener
27: }
28:
29: public void drop(DropTargetDropEvent e) {
30: try {
31: DataFlavor stringFlavor = DataFlavor.stringFlavor;
32: Transferable tr = e.getTransferable();
33: if (e.isDataFlavorSupported(stringFlavor)) {
34: String str = (String) tr.getTransferData(stringFlavor);
35: if (str.startsWith("column:")) {
36: Column col = report.findColumn(str.substring(7));
37: replaceSelection("{" + col.fullName() + "}");
38: } else if (str.startsWith("parameter:")) {
39: Parameter param = report.findParameter(str
40: .substring(10));
41: replaceSelection(param.designLabel());
42: } else if (str.startsWith("formula:")) {
43: Formula formula = report.findFormula(str
44: .substring(8));
45: replaceSelection(formula.designLabel());
46: } else if (str.startsWith("usercol:")) {
47: UserColumn uc = report.findUserColumn(str
48: .substring(8));
49: replaceSelection(uc.designLabel());
50: } else if (str.startsWith("special:")) {
51: SpecialField sf = new SpecialField(null, report,
52: null, str.substring(8), false);
53: replaceSelection(sf.formulaString());
54: } else
55: replaceSelection(str);
56:
57: e.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
58: e.dropComplete(true);
59: } else
60: e.rejectDrop();
61: } catch (Exception ex) {
62: ErrorHandler.error(ex);
63: }
64: }
65:
66: public void dragEnter(DropTargetDragEvent e) {
67: }
68:
69: public void dragExit(DropTargetEvent e) {
70: }
71:
72: public void dragOver(DropTargetDragEvent e) {
73: }
74:
75: public void dropActionChanged(DropTargetDragEvent e) {
76: }
77: }
|