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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * Copyright (c) 2006-2015 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;
  23. import com.dmdirc.interfaces.config.AggregateConfigProvider;
  24. import com.dmdirc.interfaces.ui.StatusMessageNotifier;
  25. /**
  26. * Describes a status bar message to be presented to a user.
  27. */
  28. public class StatusMessage {
  29. /** Icon type for the message. */
  30. private final String iconType;
  31. /** Message to display. */
  32. private final String message;
  33. /** Message notifier. */
  34. private final StatusMessageNotifier messageNotifier;
  35. /** Timeout when initially displayed. */
  36. private final int timeout;
  37. /** Config manager to get default timeout from. */
  38. private final AggregateConfigProvider configManager;
  39. /**
  40. * Creates a new statusbar message.
  41. *
  42. * @param iconType Icon type to use for the message (can be null)
  43. * @param message Message to show
  44. * @param messageNotifier Optional notifier (can be null)
  45. * @param timeout message timeout (can be -1)
  46. * @param configManager Config manager to get default timeout from
  47. */
  48. public StatusMessage(final String iconType, final String message,
  49. final StatusMessageNotifier messageNotifier, final int timeout,
  50. final AggregateConfigProvider configManager) {
  51. this.iconType = iconType;
  52. this.message = message;
  53. this.messageNotifier = messageNotifier;
  54. this.timeout = timeout;
  55. this.configManager = configManager;
  56. }
  57. /**
  58. * Creates a new statusbar message. This will show no icon, won't have a message notifier and
  59. * will time out in the default timeout.
  60. *
  61. * @param message Message to show
  62. * @param manager Config manager to get default timeout from
  63. */
  64. public StatusMessage(final String message, final AggregateConfigProvider manager) {
  65. this(null, message, null, -1, manager);
  66. }
  67. /**
  68. * Get the value of message
  69. *
  70. * @return the value of message
  71. */
  72. public String getMessage() {
  73. return message;
  74. }
  75. /**
  76. * Get the value of iconType
  77. *
  78. * @return the value of iconType
  79. */
  80. public String getIconType() {
  81. return iconType;
  82. }
  83. /**
  84. * Get the value of messageNotifier
  85. *
  86. * @return the value of messageNotifier
  87. */
  88. public StatusMessageNotifier getMessageNotifier() {
  89. return messageNotifier;
  90. }
  91. /**
  92. * Get the value of timeout
  93. *
  94. * @return the value of timeout
  95. */
  96. public int getTimeout() {
  97. if (timeout == -1) {
  98. return configManager.getOptionInt("statusBar",
  99. "messageDisplayLength");
  100. } else {
  101. return timeout;
  102. }
  103. }
  104. }