Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

InputHandler.java 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  1. /*
  2. * Copyright (c) 2006-2014 DMDirc Developers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. package com.dmdirc.ui.input;
  23. import com.dmdirc.DMDircMBassador;
  24. import com.dmdirc.FrameContainer;
  25. import com.dmdirc.commandparser.CommandArguments;
  26. import com.dmdirc.commandparser.CommandInfo;
  27. import com.dmdirc.commandparser.commands.Command;
  28. import com.dmdirc.commandparser.commands.ValidatingCommand;
  29. import com.dmdirc.commandparser.commands.WrappableCommand;
  30. import com.dmdirc.commandparser.parsers.CommandParser;
  31. import com.dmdirc.events.ClientUserInputEvent;
  32. import com.dmdirc.interfaces.CommandController;
  33. import com.dmdirc.interfaces.config.ConfigChangeListener;
  34. import com.dmdirc.interfaces.ui.InputField;
  35. import com.dmdirc.interfaces.ui.InputValidationListener;
  36. import com.dmdirc.parser.common.CompositionState;
  37. import com.dmdirc.plugins.ServiceManager;
  38. import com.dmdirc.ui.input.tabstyles.TabCompletionResult;
  39. import com.dmdirc.ui.input.tabstyles.TabCompletionStyle;
  40. import com.dmdirc.ui.messages.Styliser;
  41. import com.dmdirc.util.collections.ListenerList;
  42. import com.dmdirc.util.collections.RollingList;
  43. import com.dmdirc.util.validators.ValidationResponse;
  44. import java.awt.Toolkit;
  45. import java.awt.event.KeyEvent;
  46. import java.util.ArrayList;
  47. import java.util.List;
  48. import java.util.Map;
  49. import java.util.Timer;
  50. import java.util.TimerTask;
  51. import org.slf4j.Logger;
  52. import org.slf4j.LoggerFactory;
  53. /**
  54. * Handles events generated by a user typing into a textfield. Allows the user to use shortcut keys
  55. * for control characters (ctrl+b, etc), to tab complete nicknames/channel names/etc, and to scroll
  56. * through their previously issued commands.
  57. */
  58. public abstract class InputHandler implements ConfigChangeListener {
  59. private static final Logger LOG = LoggerFactory.getLogger(InputHandler.class);
  60. /**
  61. * Indicates that the caret should be moved to the start of a selection when a control code has
  62. * been inserted.
  63. */
  64. protected static final int POSITION_START = 2;
  65. /** Flag to indicate that this input handler should handle tab completion. */
  66. protected static final int HANDLE_TABCOMPLETION = 1;
  67. /** Flag to indicate that this input handler should maintain a back buffer. */
  68. protected static final int HANDLE_BACKBUFFER = 2;
  69. /** Flag to indicate that this input handler should handle formatting. */
  70. protected static final int HANDLE_FORMATTING = 4;
  71. /** Flag to indicate that this input handler should handle returns. */
  72. protected static final int HANDLE_RETURN = 8;
  73. /**
  74. * Time in milliseconds after which we switch from "typing" to"text entered" composing states.
  75. */
  76. private static final int TYPING_TIMEOUT = 5000;
  77. /**
  78. * Indicates that the caret should be moved to the end of a selection when a control code has
  79. * been inserted.
  80. */
  81. private static final int POSITION_END = 1;
  82. /** Tab-completer utilities. */
  83. private final TabCompleterUtils tabCompleterUtils;
  84. /** The flags for this particular input handler. */
  85. protected int flags = HANDLE_TABCOMPLETION | HANDLE_BACKBUFFER
  86. | HANDLE_FORMATTING | HANDLE_RETURN;
  87. /** The input buffer. */
  88. protected RollingList<String> buffer;
  89. /** The textfield that we're handling input for. */
  90. protected final InputField target;
  91. /** The TabCompleter to use for tab completion. */
  92. protected TabCompleter tabCompleter;
  93. /** The CommandParser to use for our input. */
  94. protected final CommandParser commandParser;
  95. /** The frame that we belong to. */
  96. protected final FrameContainer parentWindow;
  97. /** The tab completion style. */
  98. protected TabCompletionStyle style;
  99. /** Our listener list. */
  100. private final ListenerList listeners = new ListenerList();
  101. /** The current composition state. */
  102. private CompositionState state = CompositionState.IDLE;
  103. /** Timer used to manage timeouts of composition state. */
  104. private Timer compositionTimer;
  105. /** Manager to use to look up tab completion services. */
  106. private final ServiceManager serviceManager;
  107. /** The controller to use to retrieve command information. */
  108. private final CommandController commandController;
  109. /** The event bus to use to dispatch input events. */
  110. private final DMDircMBassador eventBus;
  111. /**
  112. * Creates a new instance of InputHandler. Adds listeners to the target that we need to operate.
  113. *
  114. * @param serviceManager Manager to use to look up tab completion services.
  115. * @param target The text field this input handler is dealing with.
  116. * @param commandController The controller to use to retrieve command information.
  117. * @param commandParser The command parser to use for this text field.
  118. * @param parentWindow The window that owns this input handler
  119. * @param eventBus The event bus to use to dispatch input events.
  120. */
  121. public InputHandler(
  122. final ServiceManager serviceManager,
  123. final InputField target,
  124. final CommandController commandController,
  125. final CommandParser commandParser,
  126. final FrameContainer parentWindow,
  127. final TabCompleterUtils tabCompleterUtils,
  128. final DMDircMBassador eventBus) {
  129. buffer = new RollingList<>(parentWindow.getConfigManager()
  130. .getOptionInt("ui", "inputbuffersize"), "");
  131. this.serviceManager = serviceManager;
  132. this.target = target;
  133. this.commandController = commandController;
  134. this.commandParser = commandParser;
  135. this.parentWindow = parentWindow;
  136. this.tabCompleterUtils = tabCompleterUtils;
  137. this.eventBus = eventBus;
  138. setStyle();
  139. parentWindow.getConfigManager().addChangeListener(
  140. "tabcompletion", "style", this);
  141. addUpHandler();
  142. addDownHandler();
  143. addTabHandler();
  144. addKeyHandler();
  145. addEnterHandler();
  146. }
  147. /**
  148. * Adds an arrow up key handler.
  149. */
  150. protected abstract void addUpHandler();
  151. /**
  152. * Adds an arrow down key handler.
  153. */
  154. protected abstract void addDownHandler();
  155. /**
  156. * Adds an tab key handler.
  157. */
  158. protected abstract void addTabHandler();
  159. /**
  160. * Adds a key handler.
  161. */
  162. protected abstract void addKeyHandler();
  163. /**
  164. * Adds an enter key handler.
  165. */
  166. protected abstract void addEnterHandler();
  167. /**
  168. * Indicates which types of input this handler should handle.
  169. *
  170. * @param handleTabCompletion Whether or not to handle tab completion
  171. * @param handleBackBuffer Whether or not to maintain an input back buffer
  172. * @param handleFormatting Whether or not to handle formatting
  173. * @param handleReturn Whether or not to handle returns
  174. */
  175. public void setTypes(final boolean handleTabCompletion,
  176. final boolean handleBackBuffer,
  177. final boolean handleFormatting, final boolean handleReturn) {
  178. flags = (handleTabCompletion ? HANDLE_TABCOMPLETION : 0)
  179. | (handleBackBuffer ? HANDLE_BACKBUFFER : 0)
  180. | (handleFormatting ? HANDLE_FORMATTING : 0)
  181. | (handleReturn ? HANDLE_RETURN : 0);
  182. }
  183. /**
  184. * Sets this inputhandler's tab completion style.
  185. */
  186. private void setStyle() {
  187. style = (TabCompletionStyle) serviceManager
  188. .getServiceProvider("tabcompletion", parentWindow
  189. .getConfigManager().getOption("tabcompletion", "style"))
  190. .getExportedService("getCompletionStyle").execute(tabCompleter,
  191. parentWindow);
  192. }
  193. /**
  194. * Sets this input handler's tab completer.
  195. *
  196. * @param newTabCompleter The new tab completer
  197. */
  198. public void setTabCompleter(final TabCompleter newTabCompleter) {
  199. tabCompleter = newTabCompleter;
  200. setStyle();
  201. }
  202. /**
  203. * Handles the pressing of a key. Inserts control chars as appropriate.
  204. *
  205. * @param line Text in the target
  206. * @param caretPosition Position of the caret after the key was pressed
  207. * @param keyCode Keycode for the pressed key
  208. * @param shiftPressed Was shift pressed
  209. * @param ctrlPressed Was ctrl key pressed
  210. */
  211. protected void handleKeyPressed(final String line, final int caretPosition,
  212. final int keyCode, final boolean shiftPressed,
  213. final boolean ctrlPressed) {
  214. target.hideColourPicker();
  215. if (keyCode == KeyEvent.VK_COMMA && caretPosition > 1) {
  216. // Reshow the colour picker dialog if the user follows a colour
  217. // or control code with a comma (so they can pick a background)
  218. final String partialLine = line.substring(0, caretPosition - 1);
  219. if (partialLine.matches("^.*" + Styliser.CODE_COLOUR + "[0-9]{0,2}$")) {
  220. target.showColourPicker(true, false);
  221. } else if (partialLine.matches("^.*" + Styliser.CODE_HEXCOLOUR + "[0-9A-Z]{6}?$")) {
  222. target.showColourPicker(false, true);
  223. }
  224. }
  225. if (ctrlPressed && (flags & HANDLE_FORMATTING) != 0) {
  226. handleControlKey(line, keyCode, shiftPressed);
  227. }
  228. if (target.getText().isEmpty()) {
  229. cancelTypingNotification();
  230. } else {
  231. updateTypingNotification();
  232. }
  233. validateText();
  234. }
  235. /**
  236. * Validates the text currently entered in the text field.
  237. */
  238. protected void validateText() {
  239. final String text = target.getText();
  240. final CommandArguments args = new CommandArguments(commandController, text);
  241. if (args.isCommand()) {
  242. final Map.Entry<CommandInfo, Command> command = commandController
  243. .getCommand(args.getCommandName());
  244. if (command != null && command.getValue() instanceof ValidatingCommand) {
  245. final ValidationResponse vr = ((ValidatingCommand) command.getValue())
  246. .validateArguments(parentWindow, args);
  247. if (vr.isFailure()) {
  248. fireCommandFailure(vr.getFailureReason());
  249. } else {
  250. fireCommandPassed();
  251. }
  252. }
  253. if (command != null && command.getValue() instanceof WrappableCommand) {
  254. final int count = ((WrappableCommand) command.getValue())
  255. .getLineCount(parentWindow, args);
  256. fireLineWrap(count);
  257. }
  258. } else {
  259. final int lines = parentWindow.getNumLines(text);
  260. fireLineWrap(lines);
  261. }
  262. }
  263. /** Resets the composition state to idle and notifies the parent if relevant. */
  264. private void cancelTypingNotification() {
  265. if (compositionTimer != null) {
  266. LOG.debug("Cancelling composition timer");
  267. compositionTimer.cancel();
  268. }
  269. LOG.debug("Cancelling typing notification");
  270. setCompositionState(CompositionState.IDLE);
  271. }
  272. /** Updates the composition state to typing and starts/resets the idle timer. */
  273. private void updateTypingNotification() {
  274. if (compositionTimer != null) {
  275. LOG.debug("Cancelling composition timer");
  276. compositionTimer.cancel();
  277. }
  278. compositionTimer = new Timer("Composition state timer");
  279. compositionTimer.schedule(new TimerTask() {
  280. @Override
  281. public void run() {
  282. timeoutTypingNotification();
  283. }
  284. }, TYPING_TIMEOUT);
  285. LOG.debug("Setting composition state to typing. Timer scheduled for {}", TYPING_TIMEOUT);
  286. setCompositionState(CompositionState.TYPING);
  287. }
  288. /** Updates the composition state to "entered text". */
  289. private void timeoutTypingNotification() {
  290. LOG.debug("Composition state timeout reached");
  291. setCompositionState(CompositionState.ENTERED_TEXT);
  292. }
  293. /**
  294. * Sets the composition state to the specified one. If the state has changed, the parent window
  295. * is notified of the new state.
  296. *
  297. * @param newState The new composition state
  298. */
  299. private void setCompositionState(final CompositionState newState) {
  300. if (state != newState) {
  301. state = newState;
  302. parentWindow.setCompositionState(state);
  303. }
  304. }
  305. /**
  306. * Fires the "illegalCommand" method of all validation listeners.
  307. *
  308. * @param reason The reason for the command failure
  309. */
  310. private void fireCommandFailure(final String reason) {
  311. for (InputValidationListener listener : listeners.get(InputValidationListener.class)) {
  312. listener.illegalCommand(reason);
  313. }
  314. }
  315. /**
  316. * Fires the "legalCommand" method of all validation listeners.
  317. */
  318. private void fireCommandPassed() {
  319. for (InputValidationListener listener : listeners.get(InputValidationListener.class)) {
  320. listener.legalCommand();
  321. }
  322. }
  323. /**
  324. * Fires the "wrappedText" method of all validation listeners.
  325. *
  326. * @param lines The number of lines that the text will wrap to
  327. */
  328. private void fireLineWrap(final int lines) {
  329. for (InputValidationListener listener : listeners.get(InputValidationListener.class)) {
  330. listener.wrappedText(lines);
  331. }
  332. }
  333. /**
  334. * Adds an InputValidationListener to this input handler.
  335. *
  336. * @param listener The listener to be added
  337. */
  338. public void addValidationListener(final InputValidationListener listener) {
  339. listeners.add(InputValidationListener.class, listener);
  340. }
  341. /**
  342. * Handles the pressing of a key while the control key is pressed. Inserts control chars as
  343. * appropriate.
  344. *
  345. * @param line Text in the target
  346. * @param keyCode Keycode for the pressed key
  347. * @param shiftPressed Was shift pressed
  348. */
  349. protected void handleControlKey(final String line, final int keyCode,
  350. final boolean shiftPressed) {
  351. switch (keyCode) {
  352. case KeyEvent.VK_B:
  353. addControlCode(Styliser.CODE_BOLD, POSITION_END);
  354. break;
  355. case KeyEvent.VK_U:
  356. addControlCode(Styliser.CODE_UNDERLINE, POSITION_END);
  357. break;
  358. case KeyEvent.VK_O:
  359. addControlCode(Styliser.CODE_STOP, POSITION_END);
  360. break;
  361. case KeyEvent.VK_I:
  362. addControlCode(Styliser.CODE_ITALIC, POSITION_END);
  363. break;
  364. case KeyEvent.VK_F:
  365. if (shiftPressed) {
  366. addControlCode(Styliser.CODE_FIXED, POSITION_END);
  367. }
  368. break;
  369. case KeyEvent.VK_K:
  370. if (shiftPressed) {
  371. addControlCode(Styliser.CODE_HEXCOLOUR, POSITION_START);
  372. target.showColourPicker(false, true);
  373. } else {
  374. addControlCode(Styliser.CODE_COLOUR, POSITION_START);
  375. target.showColourPicker(true, false);
  376. }
  377. break;
  378. case KeyEvent.VK_ENTER:
  379. if ((flags & HANDLE_RETURN) != 0 && !line.isEmpty()) {
  380. commandParser.parseCommandCtrl(parentWindow, line);
  381. addToBuffer(line);
  382. }
  383. break;
  384. default:
  385. /* Do nothing. */
  386. break;
  387. }
  388. }
  389. /**
  390. * Calls when the user presses the up key. Handles cycling through the input buffer.
  391. */
  392. protected void doBufferUp() {
  393. if ((flags & HANDLE_BACKBUFFER) != 0) {
  394. if (buffer.hasPrevious()) {
  395. target.setText(buffer.getPrevious());
  396. } else {
  397. Toolkit.getDefaultToolkit().beep();
  398. }
  399. }
  400. validateText();
  401. }
  402. /**
  403. * Called when the user presses the down key. Handles cycling through the input buffer, and
  404. * storing incomplete lines.
  405. */
  406. protected void doBufferDown() {
  407. if ((flags & HANDLE_BACKBUFFER) != 0) {
  408. if (buffer.hasNext()) {
  409. target.setText(buffer.getNext());
  410. } else if (target.getText().isEmpty()) {
  411. Toolkit.getDefaultToolkit().beep();
  412. } else {
  413. addToBuffer(target.getText());
  414. target.setText("");
  415. }
  416. }
  417. validateText();
  418. }
  419. /**
  420. * Retrieves a list of all known entries in the input backbuffer.
  421. *
  422. * @since 0.6
  423. * @return A copy of the input backbuffer.
  424. */
  425. public List<String> getBackBuffer() {
  426. return new ArrayList<>(buffer.getList());
  427. }
  428. /**
  429. * Handles tab completion of a string. Called when the user presses (shift) tab.
  430. *
  431. * @param shiftPressed True iff shift is pressed
  432. *
  433. * @since 0.6.3
  434. */
  435. protected void doTabCompletion(final boolean shiftPressed) {
  436. if (tabCompleter == null || (flags & HANDLE_TABCOMPLETION) == 0) {
  437. LOG.debug("Aborting tab completion. Completer: {}, flags: {}",
  438. new Object[]{tabCompleter, flags});
  439. return;
  440. }
  441. final String text = target.getText();
  442. LOG.trace("Text for tab completion: {}", text);
  443. if (text.isEmpty()) {
  444. doNormalTabCompletion(text, 0, 0, shiftPressed, null);
  445. return;
  446. }
  447. final int pos = target.getCaretPosition() - 1;
  448. int start = pos < 0 ? 0 : pos;
  449. int end = pos < 0 ? 0 : pos;
  450. // Traverse backwards
  451. while (start > 0 && text.charAt(start) != ' ') {
  452. start--;
  453. }
  454. if (text.charAt(start) == ' ') {
  455. start++;
  456. }
  457. // And forwards
  458. while (end < text.length() && text.charAt(end) != ' ') {
  459. end++;
  460. }
  461. if (start > end) {
  462. end = start;
  463. }
  464. LOG.trace("Offsets: start: {}, end: {}", new Object[]{start, end});
  465. if (start > 0 && text.charAt(0) == commandController.getCommandChar()) {
  466. doCommandTabCompletion(text, start, end, shiftPressed);
  467. } else {
  468. doNormalTabCompletion(text, start, end, shiftPressed, null);
  469. }
  470. }
  471. /**
  472. * Handles potentially intelligent tab completion.
  473. *
  474. * @param text The text that is being completed
  475. * @param start The start index of the word we're completing
  476. * @param end The end index of the word we're completing
  477. * @param shiftPressed True iff shift is pressed
  478. */
  479. private void doCommandTabCompletion(final String text, final int start,
  480. final int end, final boolean shiftPressed) {
  481. doNormalTabCompletion(text, start, end, shiftPressed,
  482. tabCompleterUtils.getIntelligentResults(parentWindow, commandController,
  483. text.substring(0, start), text.substring(start, end)));
  484. }
  485. /**
  486. * Handles normal (non-intelligent-command) tab completion.
  487. *
  488. * @param text The text that is being completed
  489. * @param start The start index of the word we're completing
  490. * @param end The end index of the word we're completing
  491. * @param additional A list of additional strings to use
  492. * @param shiftPressed True iff shift is pressed
  493. */
  494. private void doNormalTabCompletion(final String text, final int start,
  495. final int end, final boolean shiftPressed,
  496. final AdditionalTabTargets additional) {
  497. final TabCompletionResult res = style.getResult(text, start, end,
  498. shiftPressed, additional);
  499. if (res != null) {
  500. target.setText(res.getText());
  501. target.setCaretPosition(res.getPosition());
  502. }
  503. }
  504. /**
  505. * Called when the user presses return in the text area. The line they typed is added to the
  506. * buffer for future use.
  507. *
  508. * @param line The event that was fired
  509. */
  510. public void enterPressed(final String line) {
  511. if (!line.isEmpty()) {
  512. final StringBuffer bufferedLine = new StringBuffer(line);
  513. eventBus.publishAsync(new ClientUserInputEvent(parentWindow, bufferedLine));
  514. addToBuffer(bufferedLine.toString());
  515. commandParser.parseCommand(parentWindow, bufferedLine.toString());
  516. }
  517. cancelTypingNotification();
  518. fireLineWrap(0);
  519. fireCommandPassed();
  520. }
  521. /**
  522. * Adds the specified control code to the textarea. If the user has a range of text selected,
  523. * the characters are added before and after, and the caret is positioned based on the position
  524. * argument.
  525. *
  526. * @param code The control code to add
  527. * @param position The position of the caret after a selection is altered
  528. */
  529. protected void addControlCode(final int code, final int position) {
  530. final String insert = String.valueOf((char) code);
  531. final int selectionEnd = target.getSelectionEnd();
  532. final int selectionStart = target.getSelectionStart();
  533. if (selectionStart < selectionEnd) {
  534. final String source = target.getText();
  535. final String before = source.substring(0, selectionStart);
  536. final String selected = target.getSelectedText();
  537. final String after = source.substring(selectionEnd, source.length());
  538. target.setText(before + insert + selected + insert + after);
  539. if (position == POSITION_START) {
  540. target.setCaretPosition(selectionStart + 1);
  541. } else if (position == POSITION_END) {
  542. target.setCaretPosition(selectionEnd + 2);
  543. }
  544. } else {
  545. final int offset = target.getCaretPosition();
  546. final String source = target.getText();
  547. final String before = target.getText().substring(0, offset);
  548. final String after = target.getText().substring(offset,
  549. source.length());
  550. target.setText(before + insert + after);
  551. target.setCaretPosition(offset + 1);
  552. }
  553. }
  554. /**
  555. * Adds all items in the string array to the buffer.
  556. *
  557. * @param lines lines to add to the buffer
  558. */
  559. public void addToBuffer(final String[] lines) {
  560. for (String line : lines) {
  561. addToBuffer(line);
  562. }
  563. }
  564. /**
  565. * Adds the specified string to the buffer.
  566. *
  567. * @param line The line to be added to the buffer
  568. */
  569. public void addToBuffer(final String line) {
  570. buffer.add(line);
  571. buffer.seekToEnd();
  572. }
  573. @Override
  574. public void configChanged(final String domain, final String key) {
  575. setStyle();
  576. }
  577. /**
  578. * Inserts text to the current inputField.
  579. *
  580. * @param text The text to insert into the inputField
  581. *
  582. * @since 0.6.4
  583. */
  584. public void addToInputField(final String text) {
  585. target.setText(text);
  586. }
  587. /**
  588. * Clears the text from the inputField.
  589. *
  590. * @since 0.6.4
  591. */
  592. public void clearInputField() {
  593. target.setText("");
  594. }
  595. }