PageRenderTime 53ms CodeModel.GetById 27ms 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
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  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. package org.gjt.sp.jedit.textarea;
  23. //{{{ Imports
  24. import javax.swing.*;
  25. import java.awt.dnd.*;
  26. import java.awt.*;
  27. import org.gjt.sp.jedit.buffer.JEditBuffer;
  28. import org.gjt.sp.util.Log;
  29. //}}}
  30. /**
  31. * @author Slava Pestov
  32. * @version $Id: TextAreaDropHandler.java 17040 2010-01-23 14:19:47Z k_satoda $
  33. */
  34. class TextAreaDropHandler extends DropTargetAdapter
  35. {
  36. private final TextArea textArea;
  37. private JEditBuffer savedBuffer;
  38. private int savedCaret;
  39. //{{{ TextAreaDropHandler constructor
  40. TextAreaDropHandler(TextArea textArea)
  41. {
  42. this.textArea = textArea;
  43. } //}}}
  44. //{{{ dragEnter() method
  45. @Override
  46. public void dragEnter(DropTargetDragEvent dtde)
  47. {
  48. Log.log(Log.DEBUG,this,"Drag enter");
  49. savedBuffer = textArea.getBuffer();
  50. //textArea.getBuffer().beginCompoundEdit();
  51. savedCaret = textArea.getCaretPosition();
  52. } //}}}
  53. //{{{ dragOver() method
  54. @Override
  55. public void dragOver(DropTargetDragEvent dtde)
  56. {
  57. Point p = dtde.getLocation();
  58. p = SwingUtilities.convertPoint(textArea,p,
  59. textArea.getPainter());
  60. int pos = textArea.xyToOffset(p.x,p.y,
  61. !(textArea.getPainter().isBlockCaretEnabled()
  62. || textArea.isOverwriteEnabled()));
  63. if(pos != -1)
  64. {
  65. textArea.moveCaretPosition(pos,
  66. TextArea.ELECTRIC_SCROLL);
  67. }
  68. } //}}}
  69. //{{{ dragExit() method
  70. @Override
  71. public void dragExit(DropTargetEvent dtde)
  72. {
  73. Log.log(Log.DEBUG,this,"Drag exit");
  74. //textArea.getBuffer().endCompoundEdit();
  75. if(textArea.getBuffer() == savedBuffer)
  76. {
  77. textArea.moveCaretPosition(savedCaret,
  78. TextArea.ELECTRIC_SCROLL);
  79. }
  80. savedBuffer = null;
  81. } //}}}
  82. //{{{ drop() method
  83. public void drop(DropTargetDropEvent dtde)
  84. {
  85. Log.log(Log.DEBUG,this,"Drop");
  86. //textArea.getBuffer().endCompoundEdit();
  87. savedBuffer = null;
  88. } //}}}
  89. }