PageRenderTime 36ms CodeModel.GetById 28ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-5-pre1/org/gjt/sp/jedit/textarea/TextAreaDropHandler.java

#
Java | 97 lines | 54 code | 8 blank | 35 comment | 5 complexity | d943892086615e33322626840300c267 MD5 | raw file
 1/*
 2 * TextAreaTransferHandler.java - Drag and drop support
 3 * :tabSize=8:indentSize=8:noTabs=false:
 4 * :folding=explicit:collapseFolds=1:
 5 *
 6 * Copyright (C) 2004 Slava Pestov
 7 *
 8 * This program is free software; you can redistribute it and/or
 9 * 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
23package org.gjt.sp.jedit.textarea;
24
25//{{{ Imports
26import javax.swing.*;
27import java.awt.dnd.*;
28import java.awt.*;
29import org.gjt.sp.jedit.buffer.JEditBuffer;
30import org.gjt.sp.util.Log;
31//}}}
32
33/**
34 * @author Slava Pestov
35 * @version $Id: TextAreaDropHandler.java 17040 2010-01-23 14:19:47Z k_satoda $
36 */
37class TextAreaDropHandler extends DropTargetAdapter
38{
39	private final TextArea textArea;
40	private JEditBuffer savedBuffer;
41	private int savedCaret;
42
43	//{{{ TextAreaDropHandler constructor
44	TextAreaDropHandler(TextArea textArea)
45	{
46		this.textArea = textArea;
47	} //}}}
48
49	//{{{ dragEnter() method
50	@Override
51	public void dragEnter(DropTargetDragEvent dtde)
52	{
53		Log.log(Log.DEBUG,this,"Drag enter");
54		savedBuffer = textArea.getBuffer();
55		//textArea.getBuffer().beginCompoundEdit();
56		savedCaret = textArea.getCaretPosition();
57	} //}}}
58
59	//{{{ dragOver() method
60	@Override
61	public void dragOver(DropTargetDragEvent dtde)
62	{
63		Point p = dtde.getLocation();
64		p = SwingUtilities.convertPoint(textArea,p,
65			textArea.getPainter());
66		int pos = textArea.xyToOffset(p.x,p.y,
67			!(textArea.getPainter().isBlockCaretEnabled()
68			|| textArea.isOverwriteEnabled()));
69		if(pos != -1)
70		{
71			textArea.moveCaretPosition(pos,
72				TextArea.ELECTRIC_SCROLL);
73		}
74	} //}}}
75
76	//{{{ dragExit() method
77	@Override
78	public void dragExit(DropTargetEvent dtde)
79	{
80		Log.log(Log.DEBUG,this,"Drag exit");
81		//textArea.getBuffer().endCompoundEdit();
82		if(textArea.getBuffer() == savedBuffer)
83		{
84			textArea.moveCaretPosition(savedCaret,
85				TextArea.ELECTRIC_SCROLL);
86		}
87		savedBuffer = null;
88	} //}}}
89
90	//{{{ drop() method
91	public void drop(DropTargetDropEvent dtde)
92	{
93		Log.log(Log.DEBUG,this,"Drop");
94		//textArea.getBuffer().endCompoundEdit();
95		savedBuffer = null;
96	} //}}}
97}