/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Copyright @ 2015 Atlassian Pty Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.java.sip.communicator.impl.osdependent.jdic;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.net.*;
import java.util.HashMap;
import java.util.Map;
import javax.swing.*;
import javax.swing.event.*;
import net.java.sip.communicator.impl.osdependent.*;
import net.java.sip.communicator.impl.osdependent.systemtray.SystemTray;
import net.java.sip.communicator.impl.osdependent.systemtray.TrayIcon;
import net.java.sip.communicator.impl.osdependent.windows.*;
import net.java.sip.communicator.service.gui.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.systray.*;
import net.java.sip.communicator.service.systray.event.*;
import net.java.sip.communicator.util.Logger;
import org.apache.commons.lang3.tuple.Pair;
import org.jitsi.util.*;
import org.osgi.framework.*;
import com.apple.eawt.*;
/**
* The Systray provides a Icon and the associated TrayMenu
* in the system tray using the Jdic library.
*
* @author Nicolas Chamouard
* @author Yana Stamcheva
* @author Lyubomir Marinov
* @author Symphorien Wanko
* @author Pawel Domas
*/
public class SystrayServiceJdicImpl
extends AbstractSystrayService
{
/**
* The systray.
*/
private final SystemTray systray;
/**
* The icon in the system tray.
*/
private TrayIcon trayIcon;
/**
* The menu that spring with a right click.
*/
private Object menu;
/**
* The Logger used by the SystrayServiceJdicImpl class and
* its instances for logging output.
*/
private static final Logger logger
= Logger.getLogger(SystrayServiceJdicImpl.class);
/**
* The various icons used on the systray
*/
private ImageIcon currentIcon;
private ImageIcon logoIcon;
private ImageIcon logoIconOffline;
private ImageIcon logoIconAway;
private ImageIcon logoIconExtendedAway;
private ImageIcon logoIconFFC;
private ImageIcon logoIconDND;
private ImageIcon logoIconWhite;
/**
* The dock Icons used only in Mac version
*/
private URL dockIconOnline;
private URL dockIconOffline;
private URL dockIconAway;
private URL dockIconExtendedAway;
private URL dockIconFFC;
private URL dockIconDND;
private Image originalDockImage = null;
private boolean initialized = false;
/**
* The listener which gets notified about pop-up message events (e.g. clicks
* on the pop-up).
*/
private final SystrayPopupMessageListener popupMessageListener
= new SystrayPopupMessageListenerImpl();
/**
* Initializes a new SystrayServiceJdicImpl instance.
*/
public SystrayServiceJdicImpl()
{
super(OsDependentActivator.bundleContext);
SystemTray systray;
try
{
systray = SystemTray.getSystemTray();
}
catch (Throwable t)
{
if (t instanceof ThreadDeath)
throw (ThreadDeath) t;
else
{
systray = null;
if (!GraphicsEnvironment.isHeadless())
logger.error("Failed to create a systray!", t);
}
}
this.systray = systray;
if (this.systray != null)
{
initSystray();
}
}
@Override
public Map getSystrayModes()
{
return new HashMap()
{{
put("disabled", "service.systray.mode.DISABLED");
if (java.awt.SystemTray.isSupported())
{
put("native", "service.systray.mode.NATIVE");
}
if (!OSUtils.IS_MAC && !OSUtils.IS_WINDOWS)
{
put("appindicator",
"service.systray.mode.APPINDICATOR");
put("appindicator_static",
"service.systray.mode.APPINDICATOR_STATIC");
}
}};
}
@Override
public String getActiveSystrayMode()
{
return SystemTray.getSystemTrayMode();
}
/**
* Initializes the systray icon and related listeners.
*/
private void initSystray()
{
UIService uiService = OsDependentActivator.getUIService();
if (uiService == null)
{
/*
* Delay the call to the #initSystray() method until the UIService
* implementation becomes available.
*/
try
{
OsDependentActivator.bundleContext.addServiceListener(
new DelayedInitSystrayServiceListener(),
'('
+ Constants.OBJECTCLASS
+ '='
+ UIService.class.getName()
+ ')');
}
catch (InvalidSyntaxException ise)
{
/*
* Oh, it should not really happen. Besides, it is not clear at
* the time of this writing what is supposed to happen in the
* case of such an exception here.
*/
}
return;
}
Pair