01: /*
02: * TextAreaTransferHandler.java - Drag and drop support
03: * :tabSize=8:indentSize=8:noTabs=false:
04: * :folding=explicit:collapseFolds=1:
05: *
06: * Copyright (C) 2004 Slava Pestov
07: *
08: * This program is free software; you can redistribute it and/or
09: * modify it under the terms of the GNU General Public License
10: * as published by the Free Software Foundation; either version 2
11: * of the License, or any later version.
12: *
13: * This program is distributed in the hope that it will be useful,
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16: * GNU General Public License for more details.
17: *
18: * You should have received a copy of the GNU General Public License
19: * along with this program; if not, write to the Free Software
20: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21: */
22:
23: package org.gjt.sp.jedit.textarea;
24:
25: //{{{ Imports
26: import javax.swing.*;
27: import java.awt.dnd.*;
28: import java.awt.*;
29: import org.gjt.sp.jedit.buffer.JEditBuffer;
30: import org.gjt.sp.util.Log;
31:
32: //}}}
33:
34: class TextAreaDropHandler extends DropTargetAdapter {
35: private TextArea textArea;
36: private JEditBuffer savedBuffer;
37: private int savedCaret;
38:
39: TextAreaDropHandler(TextArea textArea) {
40: this .textArea = textArea;
41: }
42:
43: public void dragEnter(DropTargetDragEvent dtde) {
44: Log.log(Log.DEBUG, this , "Drag enter");
45: savedBuffer = textArea.getBuffer();
46: textArea.setDragInProgress(true);
47: //textArea.getBuffer().beginCompoundEdit();
48: savedCaret = textArea.getCaretPosition();
49: }
50:
51: public void dragOver(DropTargetDragEvent dtde) {
52: Point p = dtde.getLocation();
53: p = SwingUtilities.convertPoint(textArea, p, textArea
54: .getPainter());
55: int pos = textArea
56: .xyToOffset(p.x, p.y, !(textArea.getPainter()
57: .isBlockCaretEnabled() || textArea
58: .isOverwriteEnabled()));
59: if (pos != -1) {
60: textArea.moveCaretPosition(pos, TextArea.ELECTRIC_SCROLL);
61: }
62: }
63:
64: public void dragExit(DropTargetEvent dtde) {
65: Log.log(Log.DEBUG, this , "Drag exit");
66: textArea.setDragInProgress(false);
67: //textArea.getBuffer().endCompoundEdit();
68: if (textArea.getBuffer() == savedBuffer) {
69: textArea.moveCaretPosition(savedCaret,
70: TextArea.ELECTRIC_SCROLL);
71: }
72: savedBuffer = null;
73: }
74:
75: public void drop(DropTargetDropEvent dtde) {
76: Log.log(Log.DEBUG, this , "Drop");
77: textArea.setDragInProgress(false);
78: //textArea.getBuffer().endCompoundEdit();
79: }
80: }
|