001 package sears.gui.glassPane; 002 003 import java.awt.Component; 004 import java.awt.event.AdjustmentEvent; 005 import java.awt.event.AdjustmentListener; 006 007 import javax.swing.JScrollPane; 008 import javax.swing.JViewport; 009 010 011 /** 012 * Defines a generic view port glass pane module 013 */ 014 public abstract class ViewportGlassPaneModule { 015 016 protected Component view; 017 protected JViewport viewport; 018 protected boolean isViewportChanged; 019 020 /** 021 * Constructs a new <code>ViewportGlassPaneModule</code> object. 022 * @param scrollPane the scroll pane 023 * @throws NullPointerException if <tt>scrollPane</tt> is null 024 * @throws NullPointerException if its view port is null 025 * @throws NullPointerException if the view of the view port is null 026 * @see JScrollPane 027 * @see JViewport 028 */ 029 public ViewportGlassPaneModule(JScrollPane scrollPane) { 030 if( scrollPane == null ) { 031 throw new NullPointerException("JScrollPane object cannot be null"); 032 } 033 034 viewport = scrollPane.getViewport(); 035 if( viewport == null ) { 036 throw new NullPointerException("JScrollPane object have not a valid viewport"); 037 } 038 039 view = viewport.getView(); 040 if( view == null ) { 041 throw new NullPointerException("JScrollPane object viewport have not a valid view"); 042 } 043 isViewportChanged = false; 044 scrollPane.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener() { 045 046 public void adjustmentValueChanged(AdjustmentEvent e) { 047 fireAdjustmentValueChanged(e); 048 } 049 }); 050 } 051 052 /** 053 * Use when view change 054 */ 055 public void fireViewChange() { 056 isViewportChanged = true; 057 } 058 059 public abstract void fireAdjustmentValueChanged(AdjustmentEvent e); 060 061 }