001    /*
002     * $Id: ContextMenuAuxScrollBarUI.java,v 1.4 2005/10/13 08:59:57 kleopatra Exp $
003     *
004     * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
005     * Santa Clara, California 95054, U.S.A. All rights reserved.
006     *
007     * This library is free software; you can redistribute it and/or
008     * modify it under the terms of the GNU Lesser General Public
009     * License as published by the Free Software Foundation; either
010     * version 2.1 of the License, or (at your option) any later version.
011     * 
012     * This library is distributed in the hope that it will be useful,
013     * but WITHOUT ANY WARRANTY; without even the implied warranty of
014     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015     * Lesser General Public License for more details.
016     * 
017     * You should have received a copy of the GNU Lesser General Public
018     * License along with this library; if not, write to the Free Software
019     * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
020     */
021    package org.jdesktop.swingx.plaf;
022    
023    import java.awt.Graphics;
024    import java.awt.event.MouseListener;
025    
026    import javax.swing.JComponent;
027    import javax.swing.JScrollBar;
028    import javax.swing.plaf.ComponentUI;
029    import javax.swing.plaf.ScrollBarUI;
030    
031    /**
032     * @author Jeanette Winzenburg
033     */
034    public class ContextMenuAuxScrollBarUI extends ScrollBarUI {
035        
036        private MouseListener mouseHandler;
037        private JScrollBar scrollBar;
038        
039        public static ComponentUI createUI(JComponent c) {
040            return new ContextMenuAuxScrollBarUI(); 
041        }
042    
043        // PENDING: need to listen to orientation changes
044        // 
045        public void installUI(JComponent comp) {
046            this.scrollBar = (JScrollBar) comp;
047            comp.addMouseListener(getMouseListener());
048        }
049    
050        // PENDING: need to cleanup references - 
051        // DelegateAction holds a reference to the comp!
052        public void uninstallUI(JComponent comp) {
053            comp.removeMouseListener(getMouseListener());
054            this.scrollBar = null;
055        }
056    
057    
058    
059        private MouseListener getMouseListener() {
060            if (mouseHandler == null) {
061                mouseHandler = createPopupHandler();
062            }
063            return mouseHandler;
064        }
065    
066        private MouseListener createPopupHandler() {
067            return new ContextMenuHandler(createContextSource());
068        }
069    
070        private ContextMenuSource createContextSource() {
071            return new ScrollBarContextMenuSource(scrollBar.getOrientation());
072        }
073    
074        public void update(Graphics g, JComponent c) {
075        }
076        
077    
078    }