001: /*
002: * Copyright (C) 2005 - 2008 JasperSoft Corporation. All rights reserved.
003: * http://www.jaspersoft.com.
004: *
005: * Unless you have purchased a commercial license agreement from JasperSoft,
006: * the following license terms apply:
007: *
008: * This program is free software; you can redistribute it and/or modify
009: * it under the terms of the GNU General Public License version 2 as published by
010: * the Free Software Foundation.
011: *
012: * This program is distributed WITHOUT ANY WARRANTY; and without the
013: * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
014: * See the GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
018: * or write to:
019: *
020: * Free Software Foundation, Inc.,
021: * 59 Temple Place - Suite 330,
022: * Boston, MA USA 02111-1307
023: *
024: *
025: *
026: *
027: * TreeTransfertHandler.java
028: *
029: * Created on 15 settembre 2004, 2.19
030: *
031: */
032:
033: package it.businesslogic.ireport.gui.library;
034:
035: import it.businesslogic.ireport.gui.MainFrame;
036: import java.awt.Component;
037: import java.awt.Point;
038: import java.awt.datatransfer.Transferable;
039: import java.awt.dnd.DragSource;
040: import java.awt.dnd.DragSourceDragEvent;
041: import java.awt.dnd.DragSourceMotionListener;
042: import javax.swing.*;
043: import javax.swing.tree.*;
044:
045: /**
046: *
047: * @author Administrator
048: */
049: public class TreeTransfertHandler extends javax.swing.TransferHandler
050: //iR20 implements DragSourceMotionListener, TimingTarget
051: {
052:
053: /** Creates a new instance of TreeTransfertHandler */
054: public TreeTransfertHandler() {
055: super ();
056: }
057:
058: public int getSourceActions(JComponent c) {
059: return COPY_OR_MOVE;
060:
061: }
062:
063: protected Transferable createTransferable(JComponent c) {
064: //iR20 DragSource.getDefaultDragSource().addDragSourceMotionListener(this);
065: //iR20 glassPane = (GhostGlassPane) MainFrame.getMainInstance().getGlassPane();
066: //iR20 glassPane.setImage(imgRect.getImage(), false);
067:
068: if (c instanceof JTree) {
069: JTree tree = (JTree) c;
070: TreePath path = tree.getLeadSelectionPath();
071: DefaultMutableTreeNode dmtn = (DefaultMutableTreeNode) path
072: .getLastPathComponent();
073: return new it.businesslogic.ireport.gui.dnd.TransferableObject(
074: dmtn.getUserObject());
075: }
076:
077: return new it.businesslogic.ireport.gui.dnd.TransferableObject(
078: c);
079: }
080:
081: //iR20 GhostGlassPane glassPane = null;
082: //iR20 final public ImageIcon imgRect = new ImageIcon(DockPanel.class.getResource("/it/businesslogic/ireport/icons/palette/rectangle.png"));
083:
084: //iR20 public void dragMouseMoved(DragSourceDragEvent e) {
085: //iR20
086: //iR20 Component c = e.getDragSourceContext().getComponent();
087: //iR20
088: //iR20 if (to == null) {
089: //iR20 to = e.getDragSourceContext().getTrigger().getDragOrigin();
090: //iR20
091: //iR20 //java.awt.event.MouseEvent me = (java.awt.event.MouseEvent)ie;
092: //iR20 //Point p = me.getLocationOnScreen();
093: //iR20 to = SwingUtilities.convertPoint(e.getDragSourceContext().getTrigger().getComponent(), to, glassPane);
094: //iR20 //to.x += 12;
095: //iR20 //to.y -= 2;
096: //iR20 //to = p;
097: //iR20 }
098: //iR20
099: //iR20 Point p = (Point) e.getLocation().clone();
100: //iR20 //SwingUtilities.convertPointToScreen(p, c);
101: //iR20 glassPane.moveImageTo(p);
102: //iR20 if (!glassPane.isVisible())
103: //iR20 {
104: //iR20 glassPane.setVisible(true);
105: //iR20 }
106: //iR20 }
107:
108: //iR20 public void exportDone(JComponent source, Transferable data, int action) {
109: //iR20
110: //iR20 DragSource.getDefaultDragSource().removeDragSourceMotionListener(this);
111: //iR20 boolean accepted = (action != NONE);
112: //iR20 from = glassPane.getPoint();
113: //iR20 glassPane.setAccepted( accepted );
114: //iR20 new TimingController(300, this).start();
115: //iR20
116: //iR20 }
117:
118: //iR20 Point from;
119: //iR20 Point to;
120: //iR20
121: //iR20 public void begin() {
122: //iR20
123: //iR20 }
124:
125: //iR20 public void end() {
126: //iR20 from = null;
127: //iR20 to = null;
128: //iR20 glassPane.setImage(null, false);
129: //iR20 }
130:
131: //iR20 public void timingEvent(long l, long l0, float f) {
132: //iR20
133: //iR20 if (glassPane.isAccepted()) {
134: //iR20
135: //iR20 glassPane.moveImageTo( glassPane.getPoint(), f);
136: //iR20 } else {
137: //iR20 Point newP = new Point();
138: //iR20 newP.x = from.x + (int)((to.x - from.x) * f);
139: //iR20 newP.y = from.y + (int)((to.y - from.y) * f);
140: //iR20 glassPane.moveImageTo(newP, f);
141: //iR20 }
142: //iR20 }
143:
144: }
|