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.

OsdPolicy.java 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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.osd;
  18. /**
  19. * Enumerates OSD Policies.
  20. */
  21. public enum OsdPolicy {
  22. /** Spawn new windows below old ones. */
  23. DOWN("Place new windows below old ones", true) {
  24. @Override
  25. public int getYPosition(final OsdManager osdManager, final int startY) {
  26. int y = startY;
  27. for (OsdWindow window : osdManager.getWindowList()) {
  28. if (window.isVisible()) {
  29. y = Math.max(y, window.getY() + window.getHeight() + WINDOW_GAP);
  30. }
  31. }
  32. return y;
  33. }
  34. },
  35. /** Spawn new windows above old ones. */
  36. UP("Place new windows above old ones", true) {
  37. @Override
  38. public int getYPosition(final OsdManager osdManager, final int startY) {
  39. int y = startY;
  40. for (OsdWindow window : osdManager.getWindowList()) {
  41. if (window.isVisible()) {
  42. y = Math.min(y, window.getY() - window.getHeight() - WINDOW_GAP);
  43. }
  44. }
  45. return y;
  46. }
  47. },
  48. /** Close old OSD windows and display the new windows. */
  49. CLOSE("Close existing windows", false) {
  50. @Override
  51. public int getYPosition(final OsdManager osdManager, final int startY) {
  52. osdManager.closeAll();
  53. return startY;
  54. }
  55. },
  56. /** Place new windows on top of old windows. */
  57. ONTOP("Place new windows on top of existing windows", false) {
  58. @Override
  59. public int getYPosition(final OsdManager osdManager, final int startY) {
  60. return startY;
  61. }
  62. };
  63. /** The spacing between the windows. */
  64. private static final int WINDOW_GAP = 5;
  65. /** Description of policy. */
  66. private final String description;
  67. /** Does policy need to change window location */
  68. private final boolean changesPosition;
  69. /**
  70. * Creates a new instance of OsdPolicies.
  71. *
  72. * @param description Description of the behaviour of the enum value
  73. */
  74. OsdPolicy(final String description, final boolean changesPosition) {
  75. this.description = description;
  76. this.changesPosition = changesPosition;
  77. }
  78. /**
  79. * Calculates the Y position for new windows according to this policy.
  80. * <p>
  81. * In order to ensure that windows are displayed at the correct position, the calling party MUST
  82. * ensure that the window list is not altered between this method's invocation and the time at
  83. * which the window is displayed. If the window list is altered, multiple windows may appear on
  84. * top of each other instead of stacking correctly, or there may be gaps in up/down policy
  85. * layouts.
  86. *
  87. * @param osdManager OSD Manager we are using
  88. * @param startY Value of startY from the main config
  89. *
  90. * @return returns Y Value to use for new windows
  91. */
  92. public abstract int getYPosition(final OsdManager osdManager, final int startY);
  93. /**
  94. * See if this behaviour changes window position
  95. *
  96. * @return true or false depending on window behaviour
  97. */
  98. public boolean changesPosition() {
  99. return changesPosition;
  100. }
  101. /**
  102. * Return a description of what each policy does.
  103. *
  104. * @return Description of policies behaviour
  105. */
  106. public String getDescription() {
  107. return description;
  108. }
  109. }