You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

InputHandler.java 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  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.FrameContainer;
  24. import com.dmdirc.commandparser.CommandArguments;
  25. import com.dmdirc.commandparser.CommandInfo;
  26. import com.dmdirc.commandparser.commands.Command;
  27. import com.dmdirc.commandparser.commands.ValidatingCommand;
  28. import com.dmdirc.commandparser.commands.WrappableCommand;
  29. import com.dmdirc.commandparser.parsers.CommandParser;
  30. import com.dmdirc.events.ClientUserInputEvent;
  31. import com.dmdirc.interfaces.CommandController;
  32. import com.dmdirc.interfaces.config.ConfigChangeListener;
  33. import com.dmdirc.interfaces.ui.InputField;
  34. import com.dmdirc.interfaces.ui.InputValidationListener;
  35. import com.dmdirc.parser.common.CompositionState;
  36. import com.dmdirc.plugins.ServiceManager;
  37. import com.dmdirc.ui.input.tabstyles.TabCompletionResult;
  38. import com.dmdirc.ui.input.tabstyles.TabCompletionStyle;
  39. import com.dmdirc.ui.messages.Styliser;
  40. import com.dmdirc.util.collections.ListenerList;
  41. import com.dmdirc.util.collections.RollingList;
  42. import com.dmdirc.util.validators.ValidationResponse;
  43. import java.awt.Toolkit;
  44. import java.awt.event.KeyEvent;
  45. import java.util.ArrayList;
  46. import java.util.List;
  47. import java.util.Map;
  48. import java.util.Timer;
  49. import java.util.TimerTask;
  50. import org.slf4j.LoggerFactory;
  51. import net.engio.mbassy.bus.MBassador;
  52. /**
  53. * Handles events generated by a user typing into a textfield. Allows the user to use shortcut keys
  54. * for control characters (ctrl+b, etc), to tab complete nicknames/channel names/etc, and to scroll
  55. * through their previously issued commands.
  56. */
  57. public abstract class InputHandler implements ConfigChangeListener {
  58. private static final org.slf4j.Logger log = LoggerFactory.getLogger(InputHandler.class);
  59. /**
  60. * Indicates that the caret should be moved to the start of a selection when a control code has
  61. * been inserted.
  62. */
  63. protected static final int POSITION_START = 2;
  64. /** Flag to indicate that this input handler should handle tab completion. */
  65. protected static final int HANDLE_TABCOMPLETION = 1;
  66. /** Flag to indicate that this input handler should maintain a back buffer. */
  67. protected static final int HANDLE_BACKBUFFER = 2;
  68. /** Flag to indicate that this input handler should handle formatting. */
  69. protected static final int HANDLE_FORMATTING = 4;
  70. /** Flag to indicate that this input handler should handle returns. */
  71. protected static final int HANDLE_RETURN = 8;
  72. /**
  73. * Time in milliseconds after which we switch from "typing" to"text entered" composing states.
  74. */
  75. private static final int TYPING_TIMEOUT = 5000;
  76. /**
  77. * Indicates that the caret should be moved to the end of a selection when a control code has
  78. * been inserted.
  79. */
  80. private static final int POSITION_END = 1;
  81. /** The flags for this particular input handler. */
  82. protected int flags = HANDLE_TABCOMPLETION | HANDLE_BACKBUFFER
  83. | HANDLE_FORMATTING | HANDLE_RETURN;
  84. /** The input buffer. */
  85. protected RollingList<String> buffer;
  86. /** The textfield that we're handling input for. */
  87. protected final InputField target;
  88. /** The TabCompleter to use for tab completion. */
  89. protected TabCompleter tabCompleter;
  90. /** The CommandParser to use for our input. */
  91. protected final CommandParser commandParser;
  92. /** The frame that we belong to. */
  93. protected final FrameContainer parentWindow;
  94. /** The tab completion style. */
  95. protected TabCompletionStyle style;
  96. /** Our listener list. */
  97. private final ListenerList listeners = new ListenerList();
  98. /** The current composition state. */
  99. private CompositionState state = CompositionState.IDLE;
  100. /** Timer used to manage timeouts of composition state. */
  101. private Timer compositionTimer;
  102. /** Manager to use to look up tab completion services. */
  103. private final ServiceManager serviceManager;
  104. /** The controller to use to retrieve command information. */
  105. private final CommandController commandController;
  106. /** The event bus to use to dispatch input events. */
  107. private final MBassador eventBus;
  108. /**
  109. * Creates a new instance of InputHandler. Adds listeners to the target that we need to operate.
  110. *
  111. * @param serviceManager Manager to use to look up tab completion services.
  112. * @param target The text field this input handler is dealing with.
  113. * @param commandController The controller to use to retrieve command information.
  114. * @param commandParser The command parser to use for this text field.
  115. * @param parentWindow The window that owns this input handler
  116. * @param eventBus The event bus to use to dispatch input events.
  117. */
  118. public InputHandler(
  119. final ServiceManager serviceManager,
  120. final InputField target,
  121. final CommandController commandController,
  122. final CommandParser commandParser,
  123. final FrameContainer parentWindow,
  124. final MBassador eventBus) {
  125. buffer = new RollingList<>(parentWindow.getConfigManager()
  126. .getOptionInt("ui", "inputbuffersize"), "");
  127. this.serviceManager = serviceManager;
  128. this.target = target;
  129. this.commandController = commandController;
  130. this.commandParser = commandParser;
  131. this.parentWindow = parentWindow;
  132. this.eventBus = eventBus;
  133. setStyle();
  134. parentWindow.getConfigManager().addChangeListener(
  135. "tabcompletion", "style", this);
  136. addUpHandler();
  137. addDownHandler();
  138. addTabHandler();
  139. addKeyHandler();
  140. addEnterHandler();
  141. }
  142. /**
  143. * Adds an arrow up key handler.
  144. */
  145. protected abstract void addUpHandler();
  146. /**
  147. * Adds an arrow down key handler.
  148. */
  149. protected abstract void addDownHandler();
  150. /**
  151. * Adds an tab key handler.
  152. */
  153. protected abstract void addTabHandler();
  154. /**
  155. * Adds a key handler.
  156. */
  157. protected abstract void addKeyHandler();
  158. /**
  159. * Adds an enter key handler.
  160. */
  161. protected abstract void addEnterHandler();
  162. /**
  163. * Indicates which types of input this handler should handle.
  164. *
  165. * @param handleTabCompletion Whether or not to handle tab completion
  166. * @param handleBackBuffer Whether or not to maintain an input back buffer
  167. * @param handleFormatting Whether or not to handle formatting
  168. * @param handleReturn Whether or not to handle returns
  169. */
  170. public void setTypes(final boolean handleTabCompletion,
  171. final boolean handleBackBuffer,
  172. final boolean handleFormatting, final boolean handleReturn) {
  173. flags = (handleTabCompletion ? HANDLE_TABCOMPLETION : 0)
  174. | (handleBackBuffer ? HANDLE_BACKBUFFER : 0)
  175. | (handleFormatting ? HANDLE_FORMATTING : 0)
  176. | (handleReturn ? HANDLE_RETURN : 0);
  177. }
  178. /**
  179. * Sets this inputhandler's tab completion style.
  180. */
  181. private void setStyle() {
  182. style = (TabCompletionStyle) serviceManager
  183. .getServiceProvider("tabcompletion", parentWindow
  184. .getConfigManager().getOption("tabcompletion", "style"))
  185. .getExportedService("getCompletionStyle").execute(tabCompleter,
  186. parentWindow);
  187. }
  188. /**
  189. * Sets this input handler's tab completer.
  190. *
  191. * @param newTabCompleter The new tab completer
  192. */
  193. public void setTabCompleter(final TabCompleter newTabCompleter) {
  194. tabCompleter = newTabCompleter;
  195. setStyle();
  196. }
  197. /**
  198. * Handles the pressing of a key. Inserts control chars as appropriate.
  199. *
  200. * @param line Text in the target
  201. * @param caretPosition Position of the caret after the key was pressed
  202. * @param keyCode Keycode for the pressed key
  203. * @param shiftPressed Was shift pressed
  204. * @param ctrlPressed Was ctrl key pressed
  205. */
  206. protected void handleKeyPressed(final String line, final int caretPosition,
  207. final int keyCode, final boolean shiftPressed,
  208. final boolean ctrlPressed) {
  209. target.hideColourPicker();
  210. if (keyCode == KeyEvent.VK_COMMA && caretPosition > 1) {
  211. // Reshow the colour picker dialog if the user follows a colour
  212. // or control code with a comma (so they can pick a background)
  213. final String partialLine = line.substring(0, caretPosition - 1);
  214. if (partialLine.matches("^.*" + Styliser.CODE_COLOUR + "[0-9]{0,2}$")) {
  215. target.showColourPicker(true, false);
  216. } else if (partialLine.matches("^.*" + Styliser.CODE_HEXCOLOUR + "[0-9A-Z]{6}?$")) {
  217. target.showColourPicker(false, true);
  218. }
  219. }
  220. if (ctrlPressed && (flags & HANDLE_FORMATTING) != 0) {
  221. handleControlKey(line, keyCode, shiftPressed);
  222. }
  223. if (target.getText().isEmpty()) {
  224. cancelTypingNotification();
  225. } else {
  226. updateTypingNotification();
  227. }
  228. validateText();
  229. }
  230. /**
  231. * Validates the text currently entered in the text field.
  232. */
  233. protected void validateText() {
  234. final String text = target.getText();
  235. final CommandArguments args = new CommandArguments(commandController, text);
  236. if (args.isCommand()) {
  237. final Map.Entry<CommandInfo, Command> command = commandController
  238. .getCommand(args.getCommandName());
  239. if (command != null && command.getValue() instanceof ValidatingCommand) {
  240. final ValidationResponse vr = ((ValidatingCommand) command.getValue())
  241. .validateArguments(parentWindow, args);
  242. if (vr.isFailure()) {
  243. fireCommandFailure(vr.getFailureReason());
  244. } else {
  245. fireCommandPassed();
  246. }
  247. }
  248. if (command != null && command.getValue() instanceof WrappableCommand) {
  249. final int count = ((WrappableCommand) command.getValue())
  250. .getLineCount(parentWindow, args);
  251. fireLineWrap(count);
  252. }
  253. } else {
  254. final int lines = parentWindow.getNumLines(text);
  255. fireLineWrap(lines);
  256. }
  257. }
  258. /** Resets the composition state to idle and notifies the parent if relevant. */
  259. private void cancelTypingNotification() {
  260. if (compositionTimer != null) {
  261. log.debug("Cancelling composition timer");
  262. compositionTimer.cancel();
  263. }
  264. log.debug("Cancelling typing notification");
  265. setCompositionState(CompositionState.IDLE);
  266. }
  267. /** Updates the composition state to typing and starts/resets the idle timer. */
  268. private void updateTypingNotification() {
  269. if (compositionTimer != null) {
  270. log.debug("Cancelling composition timer");
  271. compositionTimer.cancel();
  272. }
  273. compositionTimer = new Timer("Composition state timer");
  274. compositionTimer.schedule(new TimerTask() {
  275. /** {@inheritDoc} */
  276. @Override
  277. public void run() {
  278. timeoutTypingNotification();
  279. }
  280. }, TYPING_TIMEOUT);
  281. log.debug("Setting composition state to typing. Timer scheduled for {}", TYPING_TIMEOUT);
  282. setCompositionState(CompositionState.TYPING);
  283. }
  284. /** Updates the composition state to "entered text". */
  285. private void timeoutTypingNotification() {
  286. log.debug("Composition state timeout reached");
  287. setCompositionState(CompositionState.ENTERED_TEXT);
  288. }
  289. /**
  290. * Sets the composition state to the specified one. If the state has changed, the parent window
  291. * is notified of the new state.
  292. *
  293. * @param newState The new composition state
  294. */
  295. private void setCompositionState(final CompositionState newState) {
  296. if (state != newState) {
  297. state = newState;
  298. if (parentWindow != null) {
  299. parentWindow.setCompositionState(state);
  300. }
  301. }
  302. }
  303. /**
  304. * Fires the "illegalCommand" method of all validation listeners.
  305. *
  306. * @param reason The reason for the command failure
  307. */
  308. private void fireCommandFailure(final String reason) {
  309. for (InputValidationListener listener : listeners.get(InputValidationListener.class)) {
  310. listener.illegalCommand(reason);
  311. }
  312. }
  313. /**
  314. * Fires the "legalCommand" method of all validation listeners.
  315. */
  316. private void fireCommandPassed() {
  317. for (InputValidationListener listener : listeners.get(InputValidationListener.class)) {
  318. listener.legalCommand();
  319. }
  320. }
  321. /**
  322. * Fires the "wrappedText" method of all validation listeners.
  323. *
  324. * @param lines The number of lines that the text will wrap to
  325. */
  326. private void fireLineWrap(final int lines) {
  327. for (InputValidationListener listener : listeners.get(InputValidationListener.class)) {
  328. listener.wrappedText(lines);
  329. }
  330. }
  331. /**
  332. * Adds an InputValidationListener to this input handler.
  333. *
  334. * @param listener The listener to be added
  335. */
  336. public void addValidationListener(final InputValidationListener listener) {
  337. listeners.add(InputValidationListener.class, listener);
  338. }
  339. /**
  340. * Handles the pressing of a key while the control key is pressed. Inserts control chars as
  341. * appropriate.
  342. *
  343. * @param line Text in the target
  344. * @param keyCode Keycode for the pressed key
  345. * @param shiftPressed Was shift pressed
  346. */
  347. protected void handleControlKey(final String line, final int keyCode,
  348. final boolean shiftPressed) {
  349. switch (keyCode) {
  350. case KeyEvent.VK_B:
  351. addControlCode(Styliser.CODE_BOLD, POSITION_END);
  352. break;
  353. case KeyEvent.VK_U:
  354. addControlCode(Styliser.CODE_UNDERLINE, POSITION_END);
  355. break;
  356. case KeyEvent.VK_O:
  357. addControlCode(Styliser.CODE_STOP, POSITION_END);
  358. break;
  359. case KeyEvent.VK_I:
  360. addControlCode(Styliser.CODE_ITALIC, POSITION_END);
  361. break;
  362. case KeyEvent.VK_F:
  363. if (shiftPressed) {
  364. addControlCode(Styliser.CODE_FIXED, POSITION_END);
  365. }
  366. break;
  367. case KeyEvent.VK_K:
  368. if (shiftPressed) {
  369. addControlCode(Styliser.CODE_HEXCOLOUR, POSITION_START);
  370. target.showColourPicker(false, true);
  371. } else {
  372. addControlCode(Styliser.CODE_COLOUR, POSITION_START);
  373. target.showColourPicker(true, false);
  374. }
  375. break;
  376. case KeyEvent.VK_ENTER:
  377. if ((flags & HANDLE_RETURN) != 0 && !line.isEmpty()) {
  378. commandParser.parseCommandCtrl(parentWindow, line);
  379. addToBuffer(line);
  380. }
  381. break;
  382. default:
  383. /* Do nothing. */
  384. break;
  385. }
  386. }
  387. /**
  388. * Calls when the user presses the up key. Handles cycling through the input buffer.
  389. */
  390. protected void doBufferUp() {
  391. if ((flags & HANDLE_BACKBUFFER) != 0) {
  392. if (buffer.hasPrevious()) {
  393. target.setText(buffer.getPrevious());
  394. } else {
  395. Toolkit.getDefaultToolkit().beep();
  396. }
  397. }
  398. validateText();
  399. }
  400. /**
  401. * Called when the user presses the down key. Handles cycling through the input buffer, and
  402. * storing incomplete lines.
  403. */
  404. protected void doBufferDown() {
  405. if ((flags & HANDLE_BACKBUFFER) != 0) {
  406. if (buffer.hasNext()) {
  407. target.setText(buffer.getNext());
  408. } else if (target.getText().isEmpty()) {
  409. Toolkit.getDefaultToolkit().beep();
  410. } else {
  411. addToBuffer(target.getText());
  412. target.setText("");
  413. }
  414. }
  415. validateText();
  416. }
  417. /**
  418. * Retrieves a list of all known entries in the input backbuffer.
  419. *
  420. * @since 0.6
  421. * @return A copy of the input backbuffer.
  422. */
  423. public List<String> getBackBuffer() {
  424. return new ArrayList<>(buffer.getList());
  425. }
  426. /**
  427. * Handles tab completion of a string. Called when the user presses (shift) tab.
  428. *
  429. * @param shiftPressed True iff shift is pressed
  430. *
  431. * @since 0.6.3
  432. */
  433. protected void doTabCompletion(final boolean shiftPressed) {
  434. if (tabCompleter == null || (flags & HANDLE_TABCOMPLETION) == 0) {
  435. log.debug(
  436. "Aborting tab completion. Completer: {}, flags: {}",
  437. new Object[]{tabCompleter, flags});
  438. return;
  439. }
  440. final String text = target.getText();
  441. log.trace("Text for tab completion: {}", text);
  442. if (text.isEmpty()) {
  443. doNormalTabCompletion(text, 0, 0, shiftPressed, null);
  444. return;
  445. }
  446. final int pos = target.getCaretPosition() - 1;
  447. int start = (pos < 0) ? 0 : pos;
  448. int end = (pos < 0) ? 0 : pos;
  449. // Traverse backwards
  450. while (start > 0 && text.charAt(start) != ' ') {
  451. start--;
  452. }
  453. if (text.charAt(start) == ' ') {
  454. start++;
  455. }
  456. // And forwards
  457. while (end < text.length() && text.charAt(end) != ' ') {
  458. end++;
  459. }
  460. if (start > end) {
  461. end = start;
  462. }
  463. log.trace("Offsets: start: {}, end: {}",
  464. 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. TabCompleter.getIntelligentResults(parentWindow,
  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. /** {@inheritDoc} */
  574. @Override
  575. public void configChanged(final String domain, final String key) {
  576. setStyle();
  577. }
  578. /**
  579. * Inserts text to the current inputField.
  580. *
  581. * @param text The text to insert into the inputField
  582. *
  583. * @since 0.6.4
  584. */
  585. public void addToInputField(final String text) {
  586. target.setText(text);
  587. }
  588. /**
  589. * Clears the text from the inputField.
  590. *
  591. * @since 0.6.4
  592. */
  593. public void clearInputField() {
  594. target.setText("");
  595. }
  596. }