1 23 24 package org.gjt.sp.jedit.textarea; 25 26 import java.awt.event.*; 28 29 import org.gjt.sp.jedit.Registers; 30 import org.gjt.sp.jedit.OperatingSystem; 31 33 36 public class MouseHandler extends TextAreaMouseHandler 37 { 38 public MouseHandler(JEditTextArea textArea) 40 { 41 super(textArea); 42 this.textArea = textArea; 43 } 45 public void mousePressed(MouseEvent evt) 47 { 48 showCursor(); 49 50 control = (OperatingSystem.isMacOS() && evt.isMetaDown()) 51 || (!OperatingSystem.isMacOS() && evt.isControlDown()); 52 53 textArea.getInputHandler().resetLastActionCount(); 56 57 quickCopyDrag = (textArea.isQuickCopyEnabled() && 58 isMiddleButton(evt.getModifiers())); 59 60 if(!quickCopyDrag) 61 { 62 textArea.requestFocus(); 63 TextArea.focusedComponent = textArea; 64 } 65 66 if(textArea.getBuffer().isLoading()) 67 return; 68 69 int x = evt.getX(); 70 int y = evt.getY(); 71 72 dragStart = textArea.xyToOffset(x,y, 73 !(textArea.getPainter().isBlockCaretEnabled() 74 || textArea.isOverwriteEnabled())); 75 dragStartLine = textArea.getLineOfOffset(dragStart); 76 dragStartOffset = dragStart - textArea.getLineStartOffset( 77 dragStartLine); 78 79 if(isPopupTrigger(evt) 80 && textArea.getRightClickPopup() != null) 81 { 82 if(textArea.isRightClickPopupEnabled()) 83 textArea.handlePopupTrigger(evt); 84 return; 85 } 86 87 dragged = false; 88 89 textArea.blink = true; 90 textArea.invalidateLine(textArea.getCaretLine()); 91 92 clickCount = evt.getClickCount(); 93 94 if(textArea.isDragEnabled() 95 && textArea.selectionManager.insideSelection(x,y) 96 && clickCount == 1 && !evt.isShiftDown()) 97 { 98 maybeDragAndDrop = true; 99 textArea.moveCaretPosition(dragStart,false); 100 return; 101 } 102 103 maybeDragAndDrop = false; 104 105 if(quickCopyDrag) 106 { 107 doSingleClick(evt); 109 } 110 else 111 { 112 switch(clickCount) 113 { 114 case 1: 115 doSingleClick(evt); 116 break; 117 case 2: 118 doDoubleClick(); 119 break; 120 default: doTripleClick(); 122 break; 123 } 124 } 125 } 127 public void mouseReleased(MouseEvent evt) 129 { 130 Selection sel = textArea.getSelectionAtOffset(dragStart); 133 if(dragged && sel != null) 134 { 135 Registers.setRegister('%',textArea.getSelectedText(sel)); 136 if(quickCopyDrag) 137 { 138 textArea.removeFromSelection(sel); 139 Registers.paste((JEditTextArea) TextArea.focusedComponent, 140 '%',sel instanceof Selection.Rect); 141 142 TextArea.focusedComponent.requestFocus(); 143 } 144 } 145 else if(!dragged && textArea.isQuickCopyEnabled() && 146 isMiddleButton(evt.getModifiers())) 147 { 148 textArea.requestFocus(); 149 TextArea.focusedComponent = textArea; 150 151 textArea.setCaretPosition(dragStart,false); 152 if(!textArea.isEditable()) 153 textArea.getToolkit().beep(); 154 else 155 Registers.paste((JEditTextArea) textArea,'%',control); 156 } 157 else if(maybeDragAndDrop 158 && !textArea.isMultipleSelectionEnabled()) 159 { 160 textArea.selectNone(); 161 } 162 163 dragged = false; 164 } 166 private JEditTextArea textArea; 168 } 170 | Popular Tags |