Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

TypingLabel.java 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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.addons.ui_swing.components;
  23. import com.dmdirc.FrameContainer;
  24. import com.dmdirc.addons.ui_swing.EdtHandlerInvocation;
  25. import com.dmdirc.addons.ui_swing.UIUtilities;
  26. import com.dmdirc.events.FrameComponentAddedEvent;
  27. import com.dmdirc.events.FrameComponentRemovedEvent;
  28. import com.dmdirc.interfaces.config.ConfigChangeListener;
  29. import com.dmdirc.ui.core.components.WindowComponent;
  30. import javax.swing.JLabel;
  31. import net.engio.mbassy.listener.Handler;
  32. /**
  33. * Simple panel to show when a user is typing.
  34. */
  35. public class TypingLabel extends JLabel implements ConfigChangeListener {
  36. /** A version number for this class. */
  37. private static final long serialVersionUID = 2;
  38. /** typingindicator string for compiler optimisation. */
  39. private static final String CONFIG_KEY = "typingindicator";
  40. /** Parent frame container. */
  41. private final FrameContainer container;
  42. /** Whether or not to show the typing indicator. */
  43. private boolean useTypingIndicator;
  44. /**
  45. * Creates a new typing label for the specified container.
  46. *
  47. * @param container Parent frame container
  48. */
  49. public TypingLabel(final FrameContainer container) {
  50. super("[Typing...]");
  51. this.container = container;
  52. container.getConfigManager().addChangeListener("ui", CONFIG_KEY, this);
  53. setVisible(false);
  54. useTypingIndicator = container.getConfigManager().getOptionBool("ui", CONFIG_KEY);
  55. if (container.getComponents().contains(WindowComponent.TYPING_INDICATOR.getIdentifier())) {
  56. setVisible(true);
  57. }
  58. }
  59. @Override
  60. public void configChanged(final String domain, final String key) {
  61. useTypingIndicator = container.getConfigManager().getOptionBool("ui", CONFIG_KEY);
  62. if (!useTypingIndicator) {
  63. UIUtilities.invokeLater(() -> setVisible(false));
  64. }
  65. }
  66. @Handler(invocation = EdtHandlerInvocation.class)
  67. public void componentAdded(final FrameComponentAddedEvent event) {
  68. if (event.getContainer().equals(container) &&
  69. WindowComponent.TYPING_INDICATOR.getIdentifier().equals(event.getComponent()) &&
  70. useTypingIndicator) {
  71. setVisible(true);
  72. }
  73. }
  74. @Handler(invocation = EdtHandlerInvocation.class)
  75. public void componentRemoved(final FrameComponentRemovedEvent event) {
  76. if (event.getContainer().equals(container) &&
  77. WindowComponent.TYPING_INDICATOR.getIdentifier().equals(event.getComponent()) &&
  78. useTypingIndicator) {
  79. setVisible(false);
  80. }
  81. }
  82. }