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.

StatusbarPopupPanel.java 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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.addons.ui_swing.components.statusbar;
  18. import java.awt.Point;
  19. import java.awt.event.MouseEvent;
  20. import javax.swing.JComponent;
  21. /**
  22. * A panel shown in the status bar which displays a {@link StatusbarPopupWindow} when the user
  23. * mouses over it.
  24. *
  25. * @param <T> Type of component used to trigger this panel
  26. *
  27. * @since 0.6.3m1
  28. */
  29. public abstract class StatusbarPopupPanel<T extends JComponent> extends StatusbarPanel<T> {
  30. /** A version number for this class. */
  31. private static final long serialVersionUID = 2;
  32. /**
  33. * Creates a new {@link StatusbarPopupPanel}, using the specified label.
  34. *
  35. * @param label The label to be displayed in the status bar
  36. */
  37. public StatusbarPopupPanel(final T label) {
  38. super(label);
  39. }
  40. @Override
  41. public void mouseClicked(final MouseEvent e) {
  42. // Don't care
  43. }
  44. @Override
  45. public void mousePressed(final MouseEvent e) {
  46. // Don't care
  47. }
  48. @Override
  49. public void mouseReleased(final MouseEvent e) {
  50. // Don't care
  51. }
  52. @Override
  53. public void mouseEntered(final MouseEvent e) {
  54. openDialog();
  55. }
  56. @Override
  57. public void mouseExited(final MouseEvent e) {
  58. Point point = getMousePosition();
  59. if (point == null && getDialog() != null) {
  60. point = getDialog().getMousePosition();
  61. }
  62. if (point == null || (!contains(point)
  63. && (getDialog() == null || !getDialog().contains(point)))) {
  64. closeDialog();
  65. }
  66. }
  67. @Override
  68. protected void openDialog() {
  69. super.openDialog();
  70. getDialog().addMouseListener(this);
  71. }
  72. @Override
  73. protected void closeDialog() {
  74. if (getDialog() != null) {
  75. getDialog().removeMouseListener(this);
  76. }
  77. super.closeDialog();
  78. }
  79. }