PageRenderTime 42ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-3-pre5/org/gjt/sp/jedit/gui/HistoryTextArea.java

#
Java | 206 lines | 124 code | 18 blank | 64 comment | 11 complexity | 3cfa2becc65b674ae398019e1db18b24 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. * HistoryTextArea.java - Text area with a history
  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.gui;
  23. //{{{ Imports
  24. import javax.swing.*;
  25. import javax.swing.border.Border;
  26. import javax.swing.border.AbstractBorder;
  27. import javax.swing.border.CompoundBorder;
  28. import javax.swing.event.MouseInputAdapter;
  29. import java.awt.*;
  30. import java.awt.event.*;
  31. import java.util.Set;
  32. import java.util.TreeSet;
  33. import org.gjt.sp.jedit.*;
  34. //}}}
  35. /**
  36. * Text area with a history.
  37. * @author Slava Pestov
  38. * @version $Id: HistoryTextArea.java 5136 2004-10-17 04:36:32Z spestov $
  39. */
  40. public class HistoryTextArea extends JTextArea
  41. {
  42. //{{{ HistoryTextArea constructor
  43. public HistoryTextArea(String name)
  44. {
  45. super(3,15);
  46. controller = new HistoryText(this,name);
  47. Set focusForwardTraversalKeys = new TreeSet();
  48. focusForwardTraversalKeys.add(
  49. KeyStroke.getKeyStroke(KeyEvent.VK_TAB,0));
  50. Set focusBackwardTraversalKeys = new TreeSet();
  51. focusBackwardTraversalKeys.add(
  52. KeyStroke.getKeyStroke(KeyEvent.VK_TAB,
  53. InputEvent.SHIFT_MASK));
  54. setFocusTraversalKeys(
  55. KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
  56. focusForwardTraversalKeys);
  57. setFocusTraversalKeys(
  58. KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
  59. focusBackwardTraversalKeys);
  60. } //}}}
  61. //{{{ getModel() method
  62. /**
  63. * Returns the underlying history controller.
  64. * @since jEdit 4.3pre1
  65. */
  66. public HistoryModel getModel()
  67. {
  68. return controller.getModel();
  69. } //}}}
  70. //{{{ setModel() method
  71. /**
  72. * Sets the history list controller.
  73. * @param name The model name
  74. * @since jEdit 4.3pre1
  75. */
  76. public void setModel(String name)
  77. {
  78. controller.setModel(name);
  79. } //}}}
  80. //{{{ setInstantPopups() method
  81. /**
  82. * Sets if selecting a value from the popup should immediately fire
  83. * an ActionEvent.
  84. */
  85. public void setInstantPopups(boolean instantPopups)
  86. {
  87. controller.setInstantPopups(instantPopups);
  88. } //}}}
  89. //{{{ getInstantPopups() method
  90. /**
  91. * Returns if selecting a value from the popup should immediately fire
  92. * an ActionEvent.
  93. */
  94. public boolean getInstantPopups()
  95. {
  96. return controller.getInstantPopups();
  97. } //}}}
  98. //{{{ addCurrentToHistory() method
  99. /**
  100. * Adds the currently entered item to the history.
  101. */
  102. public void addCurrentToHistory()
  103. {
  104. controller.addCurrentToHistory();
  105. } //}}}
  106. //{{{ setText() method
  107. /**
  108. * Sets the displayed text.
  109. */
  110. public void setText(String text)
  111. {
  112. super.setText(text);
  113. controller.setIndex(-1);
  114. } //}}}
  115. //{{{ Protected members
  116. //{{{ processKeyEvent() method
  117. protected void processKeyEvent(KeyEvent evt)
  118. {
  119. if(!isEnabled())
  120. return;
  121. if(evt.getID() == KeyEvent.KEY_PRESSED)
  122. {
  123. switch(evt.getKeyCode())
  124. {
  125. case KeyEvent.VK_ENTER:
  126. if(evt.isControlDown())
  127. {
  128. replaceSelection("\n");
  129. evt.consume();
  130. }
  131. break;
  132. case KeyEvent.VK_TAB:
  133. if(evt.isControlDown())
  134. {
  135. replaceSelection("\t");
  136. evt.consume();
  137. }
  138. break;
  139. case KeyEvent.VK_PAGE_UP:
  140. if(evt.isShiftDown())
  141. controller.doBackwardSearch();
  142. else
  143. controller.historyPrevious();
  144. evt.consume();
  145. break;
  146. case KeyEvent.VK_PAGE_DOWN:
  147. if(evt.isShiftDown())
  148. controller.doForwardSearch();
  149. else
  150. controller.historyNext();
  151. evt.consume();
  152. break;
  153. case KeyEvent.VK_UP:
  154. if(evt.isAltDown())
  155. {
  156. controller.showPopupMenu(
  157. evt.isShiftDown());
  158. evt.consume();
  159. }
  160. break;
  161. }
  162. }
  163. if(!evt.isConsumed())
  164. super.processKeyEvent(evt);
  165. } //}}}
  166. //{{{ processMouseEvent() method
  167. protected void processMouseEvent(MouseEvent evt)
  168. {
  169. if(!isEnabled())
  170. return;
  171. switch(evt.getID())
  172. {
  173. case MouseEvent.MOUSE_PRESSED:
  174. if(GUIUtilities.isPopupTrigger(evt))
  175. controller.showPopupMenu(evt.isShiftDown());
  176. else
  177. super.processMouseEvent(evt);
  178. break;
  179. default:
  180. super.processMouseEvent(evt);
  181. break;
  182. }
  183. } //}}}
  184. //}}}
  185. //{{{ Private variables
  186. private HistoryText controller;
  187. //}}}
  188. }