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.

StatusMessage.java 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright (c) 2006-2017 DMDirc Developers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
  5. * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
  6. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
  7. * permit persons to whom the Software is furnished to do so, subject to the following conditions:
  8. *
  9. * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
  10. * Software.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  13. * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
  14. * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  15. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  16. */
  17. package com.dmdirc.ui;
  18. import com.dmdirc.config.provider.AggregateConfigProvider;
  19. import com.dmdirc.interfaces.ui.StatusMessageNotifier;
  20. /**
  21. * Describes a status bar message to be presented to a user.
  22. */
  23. public class StatusMessage {
  24. /** Icon type for the message. */
  25. private final String iconType;
  26. /** Message to display. */
  27. private final String message;
  28. /** Message notifier. */
  29. private final StatusMessageNotifier messageNotifier;
  30. /** Timeout when initially displayed. */
  31. private final int timeout;
  32. /** Config manager to get default timeout from. */
  33. private final AggregateConfigProvider configManager;
  34. /**
  35. * Creates a new statusbar message.
  36. *
  37. * @param iconType Icon type to use for the message (can be null)
  38. * @param message Message to show
  39. * @param messageNotifier Optional notifier (can be null)
  40. * @param timeout message timeout (can be -1)
  41. * @param configManager Config manager to get default timeout from
  42. */
  43. public StatusMessage(final String iconType, final String message,
  44. final StatusMessageNotifier messageNotifier, final int timeout,
  45. final AggregateConfigProvider configManager) {
  46. this.iconType = iconType;
  47. this.message = message;
  48. this.messageNotifier = messageNotifier;
  49. this.timeout = timeout;
  50. this.configManager = configManager;
  51. }
  52. /**
  53. * Creates a new statusbar message. This will show no icon, won't have a message notifier and
  54. * will time out in the default timeout.
  55. *
  56. * @param message Message to show
  57. * @param manager Config manager to get default timeout from
  58. */
  59. public StatusMessage(final String message, final AggregateConfigProvider manager) {
  60. this(null, message, null, -1, manager);
  61. }
  62. /**
  63. * Get the value of message
  64. *
  65. * @return the value of message
  66. */
  67. public String getMessage() {
  68. return message;
  69. }
  70. /**
  71. * Get the value of iconType
  72. *
  73. * @return the value of iconType
  74. */
  75. public String getIconType() {
  76. return iconType;
  77. }
  78. /**
  79. * Get the value of messageNotifier
  80. *
  81. * @return the value of messageNotifier
  82. */
  83. public StatusMessageNotifier getMessageNotifier() {
  84. return messageNotifier;
  85. }
  86. /**
  87. * Get the value of timeout
  88. *
  89. * @return the value of timeout
  90. */
  91. public int getTimeout() {
  92. if (timeout == -1) {
  93. return configManager.getOptionInt("statusBar",
  94. "messageDisplayLength");
  95. } else {
  96. return timeout;
  97. }
  98. }
  99. }