PageRenderTime 44ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-5-pre1/org/gjt/sp/jedit/gui/tray/JTrayIconManager.java

#
Java | 111 lines | 72 code | 9 blank | 30 comment | 12 complexity | 2cfb7d259e7c1e8549295418b46bd09e MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  1. /*
  2. * jEdit - Programmer's Text Editor
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright Š 2011 jEdit contributors
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or any later version.
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  20. */
  21. package org.gjt.sp.jedit.gui.tray;
  22. //{{{ Imports
  23. import org.gjt.sp.jedit.EBComponent;
  24. import org.gjt.sp.jedit.EditBus;
  25. import org.gjt.sp.jedit.ServiceManager;
  26. import org.gjt.sp.jedit.jEdit;
  27. import org.gjt.sp.util.Log;
  28. import java.awt.*;
  29. //}}}
  30. /**
  31. * @author Matthieu Casanova
  32. * @since jEdit 4.5pre1
  33. *
  34. */
  35. public class JTrayIconManager
  36. {
  37. private static JEditTrayIcon trayIcon;
  38. private static boolean restore;
  39. private static String userDir;
  40. private static String[] args;
  41. //{{{ setTrayIconArgs() method
  42. public static void setTrayIconArgs(boolean restore, String userDir, String[] args)
  43. {
  44. JTrayIconManager.restore = restore;
  45. JTrayIconManager.userDir = userDir;
  46. JTrayIconManager.args = args;
  47. } //}}}
  48. //{{{ addTrayIcon() method
  49. public static void addTrayIcon()
  50. {
  51. if (trayIcon == null && SystemTray.isSupported())
  52. {
  53. SystemTray systemTray = SystemTray.getSystemTray();
  54. String trayIconName = jEdit.getProperty("systrayicon.service", "swing");
  55. trayIcon = ServiceManager.getService(JEditTrayIcon.class, trayIconName);
  56. if (trayIcon == null)
  57. {
  58. if ("swing".equals(trayIconName))
  59. {
  60. Log.log(Log.ERROR, JTrayIconManager.class, "No service " +
  61. JEditTrayIcon.class.getName() + " with name swing");
  62. return;
  63. }
  64. Log.log(Log.WARNING, JTrayIconManager.class, "No service " +
  65. JEditTrayIcon.class.getName() + " with name "+ trayIconName);
  66. trayIcon = ServiceManager.getService(JEditTrayIcon.class, "swing");
  67. }
  68. if (trayIcon == null)
  69. {
  70. Log.log(Log.ERROR, JTrayIconManager.class, "No service " +
  71. JEditTrayIcon.class.getName() + " with name swing");
  72. return;
  73. }
  74. trayIcon.setTrayIconArgs(restore, userDir, args);
  75. try
  76. {
  77. systemTray.add(trayIcon);
  78. }
  79. catch (AWTException e)
  80. {
  81. Log.log(Log.ERROR, JEditSwingTrayIcon.class, "Unable to add Tray icon", e);
  82. trayIcon = null;
  83. return;
  84. }
  85. if (trayIcon instanceof EBComponent) {
  86. EditBus.addToBus(trayIcon);
  87. }
  88. }
  89. } //}}}
  90. //{{{ removeTrayIcon() method
  91. public static void removeTrayIcon()
  92. {
  93. if (trayIcon != null)
  94. {
  95. SystemTray.getSystemTray().remove(trayIcon);
  96. if (trayIcon instanceof EBComponent) {
  97. EditBus.removeFromBus(trayIcon);
  98. }
  99. trayIcon = null;
  100. }
  101. } //}}}
  102. }