1 /*
2 * Created on Nov 1, 2003
3 *
4 * To change the template for this generated file go to
5 * Window>Preferences>Java>Code Generation>Code and Comments
6 */
7 package portaview.dnd;
8
9 import java.awt.datatransfer.DataFlavor;
10 import java.awt.datatransfer.Transferable;
11 import java.util.List;
12
13 import javax.swing.JComponent;
14 import javax.swing.TransferHandler;
15
16 import portaview.model.SlideSettings;
17 import portaview.view.AlbumIconView;
18 import portaview.view.PortaViewView;
19
20 /***
21 * The transfer handler of for the DnD from the album to the portaview.
22 * @author William Lee
23 */
24 public class AlbumTransferHandler extends TransferHandler
25 {
26 /***
27 * From the transferable object, import the data to the PortaView icons.
28 * This actually changes the model for the PortaView that the user tries
29 * to drop to.
30 */
31 public boolean importData(JComponent c, Transferable t)
32 {
33 if (!(c instanceof PortaViewView))
34 return false;
35 PortaViewView pvv = (PortaViewView) c;
36 try
37 {
38 // check the source object
39 Object obj = t.getTransferData(AlbumTransfer.FLAVOUR);
40 if (!(obj instanceof AlbumTransfer))
41 return false;
42 AlbumTransfer at = (AlbumTransfer) obj;
43 // block dnd to self
44 if (c.equals(at.getSource()))
45 return false;
46 AlbumIconView aiv = (AlbumIconView) at.getSource();
47 SlideSettings ss = pvv.getPortaViewModel().getSlideSettings();
48 ss.setIndex(0);
49 List photos = aiv.getAlbumModel().getPhotos();
50 int total = 0;
51 if (photos == null)
52 total = 0;
53 else
54 total = photos.size();
55
56 ss.setTotal(total);
57 ss.setSlide(aiv.getAlbumModel().getName());
58 // notify everything about the change.
59 pvv.getPortaViewModel().setSlideSettings(ss);
60 return true;
61 }
62 catch (Exception e)
63 {
64 e.printStackTrace();
65 return false;
66 }
67 }
68
69 /***
70 * Returns true if this handler can handle this event.
71 */
72 public boolean canImport(JComponent c, DataFlavor[] transferFlavors)
73 {
74 if (!(c instanceof AlbumIconView))
75 return false;
76 for (int i = 0; i < transferFlavors.length; i++)
77 {
78 if (transferFlavors[i].equals(AlbumTransfer.FLAVOUR))
79 return true;
80 }
81 return false;
82 }
83
84 /***
85 * Returns the source actions.
86 */
87 public int getSourceActions(JComponent c)
88 {
89 if (!(c instanceof AlbumIconView)) return NONE;
90 return COPY_OR_MOVE;
91 }
92
93 protected Transferable createTransferable(JComponent c)
94 {
95 if (!(c instanceof AlbumIconView)) return null;
96 return new AlbumTransfer(c);
97 }
98
99 /***
100 * Action performed after the drop is completed
101 */
102 protected void exportDone(JComponent source, Transferable t, int action)
103 {
104 // we don't really have to do anything here.
105 return;
106 }
107
108 }
This page was automatically generated by Maven