001    /////////////////////////////////////////////////
002    //This file is part of Sears project.
003    //Subtitle Editor And Re-Synch
004    //A tool to easily modify and resynch movies subtitles.
005    /////////////////////////////////////////////////
006    //This program is free software; 
007    //you can redistribute it and/or modify it under the terms 
008    //of the GNU General Public License 
009    //as published by the Free Software Foundation; 
010    //either version 2 of the License, or (at your option) any later version.
011    /////////////////////////////////////////////////
012    //Sears project is available under sourceforge
013    //at adress: http://sourceforge.net/projects/sears/
014    //Copyright (C) 2005 Booba Skaya
015    //Mail: booba.skaya@gmail.com
016    /////////////////////////////////////////////////
017    
018    //some suggestions about this class: floriaen@gmail.com
019    
020    package sears.search.gui;
021    
022    import java.awt.Graphics2D;
023    
024    import javax.swing.JViewport;
025    
026    import sears.gui.glassPane.DefaultViewportGlassPane;
027    import sears.gui.glassPane.ViewportGlassPane;
028    import sears.search.core.PillManager;
029    
030    /**
031     * An object of this class represents a virtual glass pane over a viewport
032     * <br>It allows to display <code>Pill</code> objects over it graphics context.
033     * @see DefaultViewportGlassPane
034     */
035    public class SearchViewportGlassPane extends DefaultViewportGlassPane {
036    
037            private static final long serialVersionUID = 2163386443816906875L;
038    
039            // to manage Pill object
040            private PillManager pm;
041    
042            /**
043             * Creates a new virtual glass pane
044             * 
045             * @param viewport              the view port, needed for display the virtual glass pane
046             * @param pillManager   a pill manager, to manage pill position over the glass pane
047             * 
048             * @throws                              NullPointerException if view port is null
049             * @throws                              NullPointerException if pillMananger is null
050             * 
051             * @see ViewportGlassPane#ViewportGlassPane(JViewport)
052             * @see DefaultViewportGlassPane
053             */
054            public SearchViewportGlassPane(JViewport viewport, PillManager pillManager) {
055                    super(viewport);
056                    if( pillManager == null ) {
057                            throw new NullPointerException("PillManager object cannot be null");
058                    }
059                    pm = pillManager;
060            }
061    
062            /*
063             * (non-Javadoc)
064             * @see sears.gui.glassPane.DefaultViewportGlassPane#paintChildrenWithGraphics(java.awt.Graphics2D)
065             */
066            protected void paintChildrenWithGraphics(Graphics2D gr) {
067                            pm.paintPill(gr);
068            }
069    
070            /**
071             * Wrap method, calls the <code>repaint()</code> method
072             * <br>Avoid confusion ( and makes sure a repaint is needed )
073             */
074            public void updatePill() {
075                    repaint();
076            }
077    }