1 22 23 package org.gjt.sp.jedit.gui; 24 25 import javax.swing.*; 27 import javax.swing.border.Border ; 28 import javax.swing.border.AbstractBorder ; 29 import javax.swing.border.CompoundBorder ; 30 import javax.swing.event.MouseInputAdapter ; 31 import java.awt.*; 32 import java.awt.event.*; 33 import java.util.Set ; 34 import java.util.TreeSet ; 35 import org.gjt.sp.jedit.*; 36 38 43 public class HistoryTextArea extends JTextArea 44 { 45 public HistoryTextArea(String name) 47 { 48 super(3,15); 49 controller = new HistoryText(this,name); 50 Set focusForwardTraversalKeys = new TreeSet (); 51 focusForwardTraversalKeys.add( 52 KeyStroke.getKeyStroke(KeyEvent.VK_TAB,0)); 53 Set focusBackwardTraversalKeys = new TreeSet (); 54 focusBackwardTraversalKeys.add( 55 KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 56 InputEvent.SHIFT_MASK)); 57 setFocusTraversalKeys( 58 KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, 59 focusForwardTraversalKeys); 60 setFocusTraversalKeys( 61 KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, 62 focusBackwardTraversalKeys); 63 } 65 70 public HistoryModel getModel() 71 { 72 return controller.getModel(); 73 } 75 81 public void setModel(String name) 82 { 83 controller.setModel(name); 84 } 86 91 public void setInstantPopups(boolean instantPopups) 92 { 93 controller.setInstantPopups(instantPopups); 94 } 96 101 public boolean getInstantPopups() 102 { 103 return controller.getInstantPopups(); 104 } 106 110 public void addCurrentToHistory() 111 { 112 controller.addCurrentToHistory(); 113 } 115 119 public void setText(String text) 120 { 121 super.setText(text); 122 controller.setIndex(-1); 123 } 125 127 protected void processKeyEvent(KeyEvent evt) 129 { 130 if(!isEnabled()) 131 return; 132 133 if(evt.getID() == KeyEvent.KEY_PRESSED) 134 { 135 switch(evt.getKeyCode()) 136 { 137 case KeyEvent.VK_ENTER: 138 if(evt.isControlDown()) 139 { 140 replaceSelection("\n"); 141 evt.consume(); 142 } 143 break; 144 case KeyEvent.VK_TAB: 145 if(evt.isControlDown()) 146 { 147 replaceSelection("\t"); 148 evt.consume(); 149 } 150 break; 151 case KeyEvent.VK_PAGE_UP: 152 if(evt.isShiftDown()) 153 controller.doBackwardSearch(); 154 else 155 controller.historyPrevious(); 156 evt.consume(); 157 break; 158 case KeyEvent.VK_PAGE_DOWN: 159 if(evt.isShiftDown()) 160 controller.doForwardSearch(); 161 else 162 controller.historyNext(); 163 evt.consume(); 164 break; 165 case KeyEvent.VK_UP: 166 if(evt.isAltDown()) 167 { 168 controller.showPopupMenu( 169 evt.isShiftDown()); 170 evt.consume(); 171 } 172 break; 173 } 174 } 175 176 if(!evt.isConsumed()) 177 super.processKeyEvent(evt); 178 } 180 protected void processMouseEvent(MouseEvent evt) 182 { 183 if(!isEnabled()) 184 return; 185 186 switch(evt.getID()) 187 { 188 case MouseEvent.MOUSE_PRESSED: 189 if(GUIUtilities.isPopupTrigger(evt)) 190 controller.showPopupMenu(evt.isShiftDown()); 191 else 192 super.processMouseEvent(evt); 193 194 break; 195 default: 196 super.processMouseEvent(evt); 197 break; 198 } 199 } 201 203 private HistoryText controller; 205 } 207 | Popular Tags |