01: package abbot.editor;
02:
03: import java.awt.datatransfer.*;
04: import java.util.*;
05:
06: import abbot.script.Step;
07:
08: public class StepTransferable implements Transferable {
09:
10: public static final DataFlavor STEP_FLAVOR = new DataFlavor(
11: "application/x-java-serialized-object;class=abbot.script.Step",
12: "Abbot script step");
13: public static final DataFlavor STEP_LIST_FLAVOR = new DataFlavor(
14: "application/x-java-serialized-object;class=java.util.ArrayList",
15: "List of Abbot script steps");
16:
17: // A single step is available as itself or as a list
18: private static final DataFlavor[] FLAVORS = { STEP_FLAVOR,
19: STEP_LIST_FLAVOR, };
20:
21: // Can't get a list as a single step
22: private static final DataFlavor[] LIST_FLAVORS = { STEP_LIST_FLAVOR };
23:
24: private static List FLAVOR_LIST = Arrays.asList(FLAVORS);
25: private static List LIST_FLAVOR_LIST = Arrays.asList(LIST_FLAVORS);
26:
27: private Step step;
28: private List steps;
29: private List flavorList;
30: private DataFlavor[] flavors;
31:
32: public StepTransferable(Step step) {
33: this .step = step;
34: this .steps = new ArrayList();
35: steps.add(step);
36: flavorList = FLAVOR_LIST;
37: flavors = FLAVORS;
38: }
39:
40: public StepTransferable(List steps) {
41: this .step = null;
42: this .steps = steps;
43: flavorList = LIST_FLAVOR_LIST;
44: flavors = LIST_FLAVORS;
45: }
46:
47: public DataFlavor[] getTransferDataFlavors() {
48: return flavors;
49: }
50:
51: public boolean isDataFlavorSupported(DataFlavor flavor) {
52: return flavorList.contains(flavor);
53: }
54:
55: public Object getTransferData(DataFlavor flavor)
56: throws UnsupportedFlavorException {
57: if (flavor.isMimeTypeEqual(STEP_FLAVOR.getMimeType())) {
58: if (step != null)
59: return step;
60: } else if (flavor.isMimeTypeEqual(STEP_LIST_FLAVOR
61: .getMimeType())) {
62: return steps;
63: }
64: throw new UnsupportedFlavorException(flavor);
65: }
66:
67: public String toString() {
68: return "Transferable "
69: + (step != null ? step.toString() : "List of Steps");
70: }
71: }
|