PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-5-pre1/org/gjt/sp/jedit/gui/HistoryTextArea.java

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