package org.limewire.ui.swing.tray;

import java.util.EventObject;

import org.limewire.ui.swing.settings.SwingUiSettings;
import org.limewire.util.OSUtils;

import com.google.inject.Inject;
import com.google.inject.Singleton;


/** This class acts as a proxy for a platform-specific user notification class. */
@Singleton
class TrayNotifierProxy implements TrayNotifier {

    /** The NotifyUser object that this class is serving as a proxy for. */
    private TrayNotifier notifier;

    /** Flag for whether or not the application is currently in the tray. */
    private boolean inTray;

    @Inject
    TrayNotifierProxy() {
        notifier = new SystemTrayNotifier();
    }


    @Override
	public boolean supportsSystemTray() {
        return notifier.supportsSystemTray();
    }

    @Override
	public boolean showTrayIcon() {
        if (inTray)
            return true;
        boolean notify = notifier.showTrayIcon();
        inTray = notify;
        return notify;
    }

    @Override
	public void hideTrayIcon() {
        if (!inTray)
            return;
        notifier.hideTrayIcon();
        inTray = false;
    }
    
    @Override
	public void showMessage(Notification notification) {
        if (!SwingUiSettings.SHOW_NOTIFICATIONS.getValue()) {
            return;
        }
        
        notifier.showMessage(notification);
    }
    
    @Override
    public boolean isExitEvent(EventObject event) {
        return notifier.isExitEvent(event);
    }

}
