001: /*
002: * DocumentStructureExportHandler.java
003: *
004: * Created on May 17, 2007, 1:36:29 PM
005: *
006: * To change this template, choose Tools | Template Manager
007: * and open the template in the editor.
008: */
009:
010: package it.businesslogic.ireport.gui.documentstructure;
011:
012: import java.awt.datatransfer.Transferable;
013: import javax.swing.JComponent;
014: import javax.swing.JTree;
015: import javax.swing.tree.DefaultMutableTreeNode;
016: import javax.swing.tree.TreePath;
017:
018: /**
019: *
020: * @author gtoffoli
021: */
022: public class DocumentStructureExportHandler extends
023: javax.swing.TransferHandler
024: //iR20 implements DragSourceMotionListener, TimingTarget
025: {
026:
027: /** Creates a new instance of TreeTransfertHandler */
028: public DocumentStructureExportHandler() {
029: super ();
030: }
031:
032: public int getSourceActions(JComponent c) {
033: return COPY_OR_MOVE;
034:
035: }
036:
037: protected Transferable createTransferable(JComponent c) {
038: //iR20 DragSource.getDefaultDragSource().addDragSourceMotionListener(this);
039: //iR20 glassPane = (GhostGlassPane) MainFrame.getMainInstance().getGlassPane();
040: //iR20 glassPane.setImage(imgRect.getImage(), false);
041:
042: if (c instanceof JTree) {
043: JTree tree = (JTree) c;
044: TreePath path = tree.getLeadSelectionPath();
045: DefaultMutableTreeNode dmtn = (DefaultMutableTreeNode) path
046: .getLastPathComponent();
047: return new it.businesslogic.ireport.gui.dnd.TransferableObject(
048: dmtn.getUserObject());
049: }
050:
051: return new it.businesslogic.ireport.gui.dnd.TransferableObject(
052: c);
053: }
054:
055: //iR20 GhostGlassPane glassPane = null;
056: //iR20 final public ImageIcon imgRect = new ImageIcon(DockPanel.class.getResource("/it/businesslogic/ireport/icons/palette/rectangle.png"));
057:
058: //iR20 public void dragMouseMoved(DragSourceDragEvent e) {
059: //iR20
060: //iR20 Component c = e.getDragSourceContext().getComponent();
061: //iR20
062: //iR20 if (to == null) {
063: //iR20 to = e.getDragSourceContext().getTrigger().getDragOrigin();
064: //iR20
065: //iR20 //java.awt.event.MouseEvent me = (java.awt.event.MouseEvent)ie;
066: //iR20 //Point p = me.getLocationOnScreen();
067: //iR20 to = SwingUtilities.convertPoint(e.getDragSourceContext().getTrigger().getComponent(), to, glassPane);
068: //iR20 //to.x += 12;
069: //iR20 //to.y -= 2;
070: //iR20 //to = p;
071: //iR20 }
072: //iR20
073: //iR20 Point p = (Point) e.getLocation().clone();
074: //iR20 //SwingUtilities.convertPointToScreen(p, c);
075: //iR20 glassPane.moveImageTo(p);
076: //iR20 if (!glassPane.isVisible())
077: //iR20 {
078: //iR20 glassPane.setVisible(true);
079: //iR20 }
080: //iR20 }
081:
082: //iR20 public void exportDone(JComponent source, Transferable data, int action) {
083: //iR20
084: //iR20 DragSource.getDefaultDragSource().removeDragSourceMotionListener(this);
085: //iR20 boolean accepted = (action != NONE);
086: //iR20 from = glassPane.getPoint();
087: //iR20 glassPane.setAccepted( accepted );
088: //iR20 new TimingController(300, this).start();
089: //iR20
090: //iR20 }
091:
092: //iR20 Point from;
093: //iR20 Point to;
094: //iR20
095: //iR20 public void begin() {
096: //iR20
097: //iR20 }
098:
099: //iR20 public void end() {
100: //iR20 from = null;
101: //iR20 to = null;
102: //iR20 glassPane.setImage(null, false);
103: //iR20 }
104:
105: //iR20 public void timingEvent(long l, long l0, float f) {
106: //iR20
107: //iR20 if (glassPane.isAccepted()) {
108: //iR20
109: //iR20 glassPane.moveImageTo( glassPane.getPoint(), f);
110: //iR20 } else {
111: //iR20 Point newP = new Point();
112: //iR20 newP.x = from.x + (int)((to.x - from.x) * f);
113: //iR20 newP.y = from.y + (int)((to.y - from.y) * f);
114: //iR20 glassPane.moveImageTo(newP, f);
115: //iR20 }
116: //iR20 }
117:
118: }
|