1 22 23 package org.gjt.sp.jedit.textarea; 24 25 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 33 class TextAreaDropHandler extends DropTargetAdapter 34 { 35 private TextArea textArea; 36 private JEditBuffer savedBuffer; 37 private int savedCaret; 38 39 TextAreaDropHandler(TextArea textArea) 40 { 41 this.textArea = textArea; 42 } 43 44 public void dragEnter(DropTargetDragEvent dtde) 45 { 46 Log.log(Log.DEBUG,this,"Drag enter"); 47 savedBuffer = textArea.getBuffer(); 48 textArea.setDragInProgress(true); 49 savedCaret = textArea.getCaretPosition(); 51 } 52 53 public void dragOver(DropTargetDragEvent dtde) 54 { 55 Point p = dtde.getLocation(); 56 p = SwingUtilities.convertPoint(textArea,p, 57 textArea.getPainter()); 58 int pos = textArea.xyToOffset(p.x,p.y, 59 !(textArea.getPainter().isBlockCaretEnabled() 60 || textArea.isOverwriteEnabled())); 61 if(pos != -1) 62 { 63 textArea.moveCaretPosition(pos, 64 TextArea.ELECTRIC_SCROLL); 65 } 66 } 67 68 public void dragExit(DropTargetEvent dtde) 69 { 70 Log.log(Log.DEBUG,this,"Drag exit"); 71 textArea.setDragInProgress(false); 72 if(textArea.getBuffer() == savedBuffer) 74 { 75 textArea.moveCaretPosition(savedCaret, 76 TextArea.ELECTRIC_SCROLL); 77 } 78 savedBuffer = null; 79 } 80 81 public void drop(DropTargetDropEvent dtde) 82 { 83 Log.log(Log.DEBUG,this,"Drop"); 84 textArea.setDragInProgress(false); 85 } 87 } 88 | Popular Tags |