/[classpath]/classpath/javax/swing/JViewport.java
ViewVC logotype

Diff of /classpath/javax/swing/JViewport.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.28 by rabbit78, Thu Sep 22 14:35:30 2005 UTC revision 1.29 by rabbit78, Wed Oct 12 12:31:34 2005 UTC
# Line 130  public class JViewport extends JComponen Line 130  public class JViewport extends JComponen
130    
131    /**    /**
132     * A {@link java.awt.event.ComponentListener} that listens for     * A {@link java.awt.event.ComponentListener} that listens for
133     * changes of the view's size. This class forbids changes of the view     * changes of the view's size. This triggers a revalidate() call on the
134     * component's size that would exceed the viewport's size.     * viewport.
135     */     */
136    protected class ViewListener    protected class ViewListener extends ComponentAdapter implements Serializable
     extends ComponentAdapter  
     implements Serializable  
137    {    {
138      private static final long serialVersionUID = -2812489404285958070L;      private static final long serialVersionUID = -2812489404285958070L;
139    
# Line 148  public class JViewport extends JComponen Line 146  public class JViewport extends JComponen
146    
147      /**      /**
148       * Receives notification when a component (in this case: the view       * Receives notification when a component (in this case: the view
149       * component) changes it's size.       * component) changes it's size. This simply triggers a revalidate() on the
150         * viewport.
151       *       *
152       * @param ev the ComponentEvent describing the change       * @param ev the ComponentEvent describing the change
153       */       */
154      public void componentResized(ComponentEvent ev)      public void componentResized(ComponentEvent ev)
155      {      {
156        // According to some tests that I did with Sun's implementation        revalidate();
       // this class is supposed to make sure that the view component  
       // is not resized to a larger size than the viewport.  
       // This is not documented anywhere. What I did is: I subclassed JViewport  
       // and ViewListener and 'disabled' the componentResized method by  
       // overriding it and not calling super.componentResized().  
       // When this method is disabled I can set the size on the view component  
       // normally, when it is enabled, it gets immediatly resized back,  
       // after a resize attempt that would exceed the Viewport's size.  
       Component comp = ev.getComponent();  
       Dimension newSize = comp.getSize();  
       Dimension viewportSize = getSize();  
       boolean revert = false;  
       if (newSize.width > viewportSize.width)  
         {  
           newSize.width = viewportSize.width;  
           revert = true;  
         }  
       if (newSize.height > viewportSize.height)  
         {  
           newSize.height = viewportSize.height;  
           revert = true;  
         }  
       if (revert == true)  
         comp.setSize(newSize);  
157      }      }
158    }    }
159    
# Line 264  public class JViewport extends JComponen Line 239  public class JViewport extends JComponen
239    {    {
240      setOpaque(true);      setOpaque(true);
241      setScrollMode(BLIT_SCROLL_MODE);      setScrollMode(BLIT_SCROLL_MODE);
     setLayout(createLayoutManager());  
242      updateUI();      updateUI();
243        setLayout(createLayoutManager());
244      lastPaintPosition = new Point();      lastPaintPosition = new Point();
245      cachedBlitFrom = new Point();      cachedBlitFrom = new Point();
246      cachedBlitTo = new Point();      cachedBlitTo = new Point();
# Line 356  public class JViewport extends JComponen Line 331  public class JViewport extends JComponen
331    
332    public void setViewPosition(Point p)    public void setViewPosition(Point p)
333    {    {
334        if (getViewPosition().equals(p))
335          return;
336      Component view = getView();      Component view = getView();
337      if (view != null)      if (view != null)
338        {        {
# Line 418  public class JViewport extends JComponen Line 395  public class JViewport extends JComponen
395        {        {
396          if (viewListener != null)          if (viewListener != null)
397            getView().removeComponentListener(viewListener);            getView().removeComponentListener(viewListener);
398          remove(0);          //remove(0);
399        }        }
400    
401      if (v != null)      if (v != null)
# Line 429  public class JViewport extends JComponen Line 406  public class JViewport extends JComponen
406          add(v);          add(v);
407          fireStateChanged();          fireStateChanged();
408        }        }
409        revalidate();
410    }    }
411    
412    public void revalidate()    public void revalidate()

Legend:
Removed from v.1.28  
changed lines
  Added in v.1.29

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26