001/*
002 * Copyright 2010-2015 Institut Pasteur.
003 * 
004 * This file is part of Icy.
005 * 
006 * Icy is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 * 
011 * Icy is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014 * GNU General Public License for more details.
015 * 
016 * You should have received a copy of the GNU General Public License
017 * along with Icy. If not, see <http://www.gnu.org/licenses/>.
018 */
019package icy.common.listener.weak;
020
021import java.awt.Component;
022import java.awt.event.ComponentEvent;
023import java.awt.event.ComponentListener;
024
025/**
026 * Weak wrapper for ComponentListener.
027 * 
028 * @author Stephane
029 */
030public class WeakComponentListener extends WeakListener<ComponentListener> implements ComponentListener
031{
032    public WeakComponentListener(ComponentListener listener)
033    {
034        super(listener);
035    }
036
037    @Override
038    public void removeListener(Object source)
039    {
040        if (source != null)
041            ((Component) source).removeComponentListener(this);
042    }
043
044    @Override
045    public void componentResized(ComponentEvent e)
046    {
047        final ComponentListener listener = getListener(e.getComponent());
048
049        if (listener != null)
050            listener.componentResized(e);
051    }
052
053    @Override
054    public void componentMoved(ComponentEvent e)
055    {
056        final ComponentListener listener = getListener(e.getComponent());
057
058        if (listener != null)
059            listener.componentMoved(e);
060    }
061
062    @Override
063    public void componentShown(ComponentEvent e)
064    {
065        final ComponentListener listener = getListener(e.getComponent());
066
067        if (listener != null)
068            listener.componentShown(e);
069    }
070
071    @Override
072    public void componentHidden(ComponentEvent e)
073    {
074        final ComponentListener listener = getListener(e.getComponent());
075
076        if (listener != null)
077            listener.componentHidden(e);
078    }
079}