Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

SwingStatusBar.java 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /*
  2. * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
  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.statusbar;
  23. import com.dmdirc.addons.ui_swing.MainFrame;
  24. import com.dmdirc.addons.ui_swing.SwingController;
  25. import com.dmdirc.logger.ErrorLevel;
  26. import com.dmdirc.logger.Logger;
  27. import com.dmdirc.ui.interfaces.StatusBar;
  28. import com.dmdirc.ui.interfaces.StatusBarComponent;
  29. import com.dmdirc.ui.interfaces.StatusMessageNotifier;
  30. import java.awt.Component;
  31. import java.util.Arrays;
  32. import javax.swing.JPanel;
  33. import javax.swing.SwingUtilities;
  34. import net.miginfocom.swing.MigLayout;
  35. /** Status bar, shows message and info on the gui. */
  36. public final class SwingStatusBar extends JPanel implements StatusBar {
  37. /**
  38. * A version number for this class. It should be changed whenever the class
  39. * structure is changed (or anything else that would prevent serialized
  40. * objects being unserialized with the new class).
  41. */
  42. private static final long serialVersionUID = 5;
  43. /** message label. */
  44. private final MessageLabel messageLabel;
  45. /** error panel. */
  46. private final ErrorPanel errorPanel;
  47. /** update label. */
  48. private final UpdaterLabel updateLabel;
  49. /** Invite label. */
  50. private final InviteLabel inviteLabel;
  51. /** Swing controller. */
  52. private SwingController controller;
  53. /** Main frame. */
  54. private MainFrame mainFrame;
  55. /**
  56. * Creates a new instance of SwingStatusBar.
  57. *
  58. * @param controller Swing controller
  59. * @param mainFrame Main frame
  60. */
  61. public SwingStatusBar(final SwingController controller, final MainFrame mainFrame) {
  62. super();
  63. this.controller = controller;
  64. this.mainFrame = mainFrame;
  65. messageLabel = new MessageLabel();
  66. errorPanel = new ErrorPanel(controller, mainFrame, this);
  67. updateLabel = new UpdaterLabel(mainFrame);
  68. inviteLabel = new InviteLabel(mainFrame);
  69. setLayout(new MigLayout("fill, ins 0, hidemode 3"));
  70. add(messageLabel, "growx, pushx, sgy components, hmax 20, hmin 20");
  71. add(updateLabel, "sgy components, hmax 20, hmin 20, wmin 20, shrink 0");
  72. add(errorPanel, "sgy components, hmax 20, hmin 20, wmin 20, shrink 0");
  73. add(inviteLabel, "sgy components, hmax 20, hmin 20, wmin 20, shrink 0");
  74. }
  75. /** {@inheritDoc} */
  76. @Override
  77. public void setMessage(final String newMessage) {
  78. messageLabel.setMessage(newMessage);
  79. }
  80. /** {@inheritDoc} */
  81. @Override
  82. public void setMessage(final String newMessage,
  83. final StatusMessageNotifier newNotifier) {
  84. messageLabel.setMessage(newMessage, newNotifier);
  85. }
  86. /** {@inheritDoc} */
  87. @Override
  88. public void setMessage(final String iconType, final String newMessage) {
  89. messageLabel.setMessage(iconType, newMessage);
  90. }
  91. /** {@inheritDoc} */
  92. @Override
  93. public void setMessage(final String iconType, final String newMessage,
  94. final StatusMessageNotifier newNotifier) {
  95. messageLabel.setMessage(iconType, newMessage, newNotifier);
  96. }
  97. /** {@inheritDoc} */
  98. @Override
  99. public void setMessage(final String newMessage,
  100. final StatusMessageNotifier newNotifier, final int timeout) {
  101. messageLabel.setMessage(newMessage, newNotifier, timeout);
  102. }
  103. /** {@inheritDoc} */
  104. @Override
  105. public synchronized void setMessage(final String iconType,
  106. final String newMessage,
  107. final StatusMessageNotifier newNotifier, final int timeout) {
  108. messageLabel.setMessage(iconType, newMessage, newNotifier, timeout);
  109. }
  110. /** {@inheritDoc} */
  111. @Override
  112. public void clearMessage() {
  113. messageLabel.clearMessage();
  114. }
  115. /** {@inheritDoc} */
  116. @Override
  117. public void addComponent(final StatusBarComponent component) {
  118. if (!(component instanceof Component)) {
  119. Logger.appError(ErrorLevel.HIGH, "Error adding status bar component",
  120. new IllegalArgumentException("Component must be an " +
  121. "instance of java.awt.component"));
  122. return;
  123. }
  124. if (!Arrays.asList(getComponents()).contains(component)) {
  125. SwingUtilities.invokeLater(new Runnable() {
  126. /** {@inheritDoc} */
  127. @Override
  128. public void run() {
  129. remove(updateLabel);
  130. remove(errorPanel);
  131. remove(inviteLabel);
  132. add((Component) component,
  133. "sgy components, hmax 20, hmin 20, wmin 20, shrink 0");
  134. add(updateLabel,
  135. "sgy components, hmax 20, hmin 20, wmin 20, shrink 0");
  136. add(inviteLabel,
  137. "sgy components, hmax 20, hmin 20, wmin 20, shrink 0");
  138. add(errorPanel,
  139. "sgy components, hmax 20, hmin 20, wmin 20, shrink 0");
  140. validate();
  141. }
  142. });
  143. }
  144. }
  145. /** {@inheritDoc} */
  146. @Override
  147. public void removeComponent(final StatusBarComponent component) {
  148. if (!(component instanceof Component)) {
  149. Logger.appError(ErrorLevel.HIGH, "Error adding status bar component",
  150. new IllegalArgumentException("Component must be an " +
  151. "instance of java.awt.component"));
  152. return;
  153. }
  154. SwingUtilities.invokeLater(new Runnable() {
  155. /** {@inheritDoc} */
  156. @Override
  157. public void run() {
  158. remove((Component) component);
  159. validate();
  160. }
  161. });
  162. }
  163. /**
  164. * Returns the message label for this status bar. This is intended to be used
  165. * for advanced plugins that wish to do compliated things with messages.
  166. *
  167. * @return Message label component
  168. */
  169. public MessageLabel getMessageComponent() {
  170. return messageLabel;
  171. }
  172. }