Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

OsdPlugin.java 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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.osd;
  23. import com.dmdirc.commandparser.CommandManager;
  24. import com.dmdirc.config.IdentityManager;
  25. import com.dmdirc.config.prefs.CategoryChangeListener;
  26. import com.dmdirc.config.prefs.PreferencesCategory;
  27. import com.dmdirc.config.prefs.PreferencesInterface;
  28. import com.dmdirc.config.prefs.PreferencesManager;
  29. import com.dmdirc.config.prefs.PreferencesSetting;
  30. import com.dmdirc.config.prefs.PreferencesType;
  31. import com.dmdirc.config.prefs.SettingChangeListener;
  32. import com.dmdirc.plugins.Plugin;
  33. import java.util.HashMap;
  34. import java.util.Map;
  35. /**
  36. * Allows the user to display on-screen-display messages.
  37. * @author chris
  38. */
  39. public final class OsdPlugin extends Plugin implements CategoryChangeListener,
  40. PreferencesInterface, SettingChangeListener {
  41. /** Config OSD Window. */
  42. private OsdWindow osdWindow;
  43. /** OSD Command. */
  44. private OsdCommand command;
  45. /** X-axis position of OSD. */
  46. private int x;
  47. /** Y-axis potion of OSD. */
  48. private int y;
  49. /** Setting objects with registered change listeners. */
  50. private PreferencesSetting fontSizeSetting, backgroundSetting,
  51. foregroundSetting, widthSetting;
  52. /**
  53. * Creates a new instance of OsdPlugin.
  54. */
  55. public OsdPlugin() {
  56. super();
  57. }
  58. /** {@inheritDoc} */
  59. @Override
  60. public void onLoad() {
  61. command = new OsdCommand(this);
  62. }
  63. /** {@inheritDoc} */
  64. @Override
  65. public void onUnload() {
  66. CommandManager.unregisterCommand(command);
  67. }
  68. /** {@inheritDoc} */
  69. @Override
  70. public void showConfig(final PreferencesManager manager) {
  71. x = IdentityManager.getGlobalConfig().getOptionInt(getDomain(), "locationX");
  72. y = IdentityManager.getGlobalConfig().getOptionInt(getDomain(), "locationY");
  73. final PreferencesCategory category = new PreferencesCategory("OSD",
  74. "General configuration for OSD plugin.", "category-osd");
  75. fontSizeSetting = new PreferencesSetting(PreferencesType.INTEGER,
  76. getDomain(), "fontSize", "Font size", "Changes the font " +
  77. "size of the OSD").registerChangeListener(this);
  78. backgroundSetting = new PreferencesSetting(PreferencesType.COLOUR,
  79. getDomain(), "bgcolour", "Background colour",
  80. "Background colour for the OSD").registerChangeListener(this);
  81. foregroundSetting = new PreferencesSetting(PreferencesType.COLOUR,
  82. getDomain(), "fgcolour", "Foreground colour",
  83. "Foreground colour for the OSD").registerChangeListener(this);
  84. widthSetting = new PreferencesSetting(PreferencesType.INTEGER,
  85. getDomain(), "width", "OSD Width", "Width of the OSD Window").
  86. registerChangeListener(this);
  87. category.addSetting(fontSizeSetting);
  88. category.addSetting(backgroundSetting);
  89. category.addSetting(foregroundSetting);
  90. category.addSetting(widthSetting);
  91. category.addSetting(new PreferencesSetting(PreferencesType.INTEGER,
  92. getDomain(), "timeout", "Timeout", "Length of time in " +
  93. "seconds before the OSD window closes"));
  94. final Map<String, String> posOptions = new HashMap<String, String>();
  95. posOptions.put("down", "Place new windows below old ones");
  96. posOptions.put("up", "Place new windows above old ones");
  97. posOptions.put("close", "Close existing windows");
  98. posOptions.put("ontop", "Place new windows on top of existing window");
  99. category.addSetting(new PreferencesSetting(getDomain(), "newbehaviour",
  100. "New window policy", "What to do when an OSD Window "
  101. + "is opened when there are other, existing windows open", posOptions));
  102. category.addChangeListener(this);
  103. manager.getCategory("Plugins").addSubCategory(category);
  104. manager.registerSaveListener(this);
  105. }
  106. /** {@inheritDoc} */
  107. @Override
  108. public void categorySelected(final PreferencesCategory category) {
  109. osdWindow = new OsdWindow("Please drag this OSD to position", true, x, y, this);
  110. osdWindow.setBackgroundColour(backgroundSetting.getValue());
  111. osdWindow.setForegroundColour(foregroundSetting.getValue());
  112. osdWindow.setFontSize(Integer.parseInt(fontSizeSetting.getValue()));
  113. }
  114. /** {@inheritDoc} */
  115. @Override
  116. public void categoryDeselected(final PreferencesCategory category) {
  117. x = osdWindow.getLocationOnScreen().x;
  118. y = osdWindow.getLocationOnScreen().y;
  119. osdWindow.dispose();
  120. osdWindow = null;
  121. }
  122. /** {@inheritDoc} */
  123. @Override
  124. public void save() {
  125. IdentityManager.getConfigIdentity().setOption(getDomain(), "locationX", x);
  126. IdentityManager.getConfigIdentity().setOption(getDomain(), "locationY", y);
  127. }
  128. /** {@inheritDoc} */
  129. @Override
  130. public void settingChanged(final PreferencesSetting setting) {
  131. if (osdWindow == null) {
  132. // They've changed categories but are somehow poking settings.
  133. // Ignore the request.
  134. return;
  135. }
  136. if (setting.equals(fontSizeSetting)) {
  137. osdWindow.setFontSize(Integer.parseInt(setting.getValue()));
  138. } else if (setting.equals(backgroundSetting)) {
  139. osdWindow.setBackgroundColour(setting.getValue());
  140. } else if (setting.equals(foregroundSetting)) {
  141. osdWindow.setForegroundColour(setting.getValue());
  142. } else if (setting.equals(widthSetting)) {
  143. int width = 500;
  144. try {
  145. width = Integer.parseInt(setting.getValue());
  146. } catch (NumberFormatException e) {
  147. //Ignore
  148. }
  149. osdWindow.setSize(width, osdWindow.getHeight());
  150. }
  151. }
  152. }