/[classpath]/classpath/javax/swing/plaf/basic/BasicScrollBarUI.java
ViewVC logotype

Diff of /classpath/javax/swing/plaf/basic/BasicScrollBarUI.java

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

revision 1.27 by rabbit78, Tue Oct 18 14:02:16 2005 UTC revision 1.28 by trebligd, Mon Oct 24 20:30:54 2005 UTC
# Line 128  public class BasicScrollBarUI extends Sc Line 128  public class BasicScrollBarUI extends Sc
128       */       */
129      public void stateChanged(ChangeEvent e)      public void stateChanged(ChangeEvent e)
130      {      {
       //       System.err.println(this + ".stateChanged()");  
131        calculatePreferredSize();        calculatePreferredSize();
132        getThumbBounds();        updateThumbRect();
133        scrollbar.repaint();        scrollbar.repaint();
134      }      }
135    }    }
# Line 151  public class BasicScrollBarUI extends Sc Line 150  public class BasicScrollBarUI extends Sc
150          {          {
151            ((BoundedRangeModel) e.getOldValue()).removeChangeListener(modelListener);            ((BoundedRangeModel) e.getOldValue()).removeChangeListener(modelListener);
152            scrollbar.getModel().addChangeListener(modelListener);            scrollbar.getModel().addChangeListener(modelListener);
153            getThumbBounds();            updateThumbRect();
154          }          }
155        else if (e.getPropertyName().equals("orientation"))        else if (e.getPropertyName().equals("orientation"))
156          {          {
# Line 173  public class BasicScrollBarUI extends Sc Line 172  public class BasicScrollBarUI extends Sc
172            decrButton.addMouseListener(buttonListener);            decrButton.addMouseListener(buttonListener);
173            calculatePreferredSize();            calculatePreferredSize();
174          }          }
175          else if (e.getPropertyName().equals("enabled"))
176            {
177              Boolean b = (Boolean) e.getNewValue();
178              if (incrButton != null)
179                incrButton.setEnabled(b.booleanValue());
180              if (decrButton != null)
181                decrButton.setEnabled(b.booleanValue());
182            }
183      }      }
184    }    }
185    
# Line 625  public class BasicScrollBarUI extends Sc Line 632  public class BasicScrollBarUI extends Sc
632     */     */
633    public Dimension getMaximumSize(JComponent c)    public Dimension getMaximumSize(JComponent c)
634    {    {
635      return getPreferredSize(c);      return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
636    }    }
637    
638    /**    /**
# Line 667  public class BasicScrollBarUI extends Sc Line 674  public class BasicScrollBarUI extends Sc
674     */     */
675    void calculatePreferredSize()    void calculatePreferredSize()
676    {    {
     // System.err.println(this + ".calculatePreferredSize()");  
677      int height;      int height;
678      int width;      int width;
679      height = width = 0;      height = width = 0;
# Line 730  public class BasicScrollBarUI extends Sc Line 736  public class BasicScrollBarUI extends Sc
736     */     */
737    protected Rectangle getThumbBounds()    protected Rectangle getThumbBounds()
738    {    {
     int max = scrollbar.getMaximum();  
     int min = scrollbar.getMinimum();  
     int value = scrollbar.getValue();  
     int extent = scrollbar.getVisibleAmount();  
   
     // System.err.println(this + ".getThumbBounds()");  
     if (max == min)  
       {  
         thumbRect.x = trackRect.x;  
         thumbRect.y = trackRect.y;  
         if (scrollbar.getOrientation() == HORIZONTAL)  
           {  
             thumbRect.width = getMinimumThumbSize().width;  
             thumbRect.height = trackRect.height;  
           }  
         else  
           {  
             thumbRect.width = trackRect.width;  
             thumbRect.height = getMinimumThumbSize().height;  
           }  
         return thumbRect;  
       }  
   
     if (scrollbar.getOrientation() == HORIZONTAL)  
       {  
         thumbRect.x = trackRect.x;  
         thumbRect.x += (value - min) * trackRect.width / (max - min);  
         thumbRect.y = trackRect.y;  
   
         thumbRect.width = Math.max(extent * trackRect.width / (max - min),  
                                    getMinimumThumbSize().width);  
         thumbRect.height = trackRect.height;  
       }  
     else  
       {  
         thumbRect.x = trackRect.x;  
         thumbRect.y = trackRect.y + value * trackRect.height / (max - min);  
   
         thumbRect.width = trackRect.width;  
         thumbRect.height = Math.max(extent * trackRect.height / (max - min),  
                                     getMinimumThumbSize().height);  
       }  
739      return thumbRect;      return thumbRect;
740    }    }
741    
# Line 783  public class BasicScrollBarUI extends Sc Line 747  public class BasicScrollBarUI extends Sc
747     */     */
748    protected Rectangle getTrackBounds()    protected Rectangle getTrackBounds()
749    {    {
     SwingUtilities.calculateInnerArea(scrollbar, trackRect);  
   
     if (scrollbar.getOrientation() == SwingConstants.HORIZONTAL)  
       {  
         trackRect.width -= incrButton.getPreferredSize().getWidth();  
         trackRect.width -= decrButton.getPreferredSize().getWidth();  
   
         trackRect.x += decrButton.getPreferredSize().getWidth();  
       }  
     else  
       {  
         trackRect.height -= incrButton.getPreferredSize().getHeight();  
         trackRect.height -= decrButton.getPreferredSize().getHeight();  
   
         trackRect.y += incrButton.getPreferredSize().getHeight();  
       }  
750      return trackRect;      return trackRect;
751    }    }
752    
# Line 896  public class BasicScrollBarUI extends Sc Line 844  public class BasicScrollBarUI extends Sc
844    
845          scrollTimer = new Timer(300, null);          scrollTimer = new Timer(300, null);
846    
847            installDefaults();
848          installComponents();          installComponents();
         installDefaults();  
849          configureScrollBarColors();          configureScrollBarColors();
850          installListeners();          installListeners();
851    
# Line 928  public class BasicScrollBarUI extends Sc Line 876  public class BasicScrollBarUI extends Sc
876     */     */
877    protected void layoutHScrollbar(JScrollBar sb)    protected void layoutHScrollbar(JScrollBar sb)
878    {    {
     // All we have to do is layout the 2 buttons?  
879      Rectangle vr = new Rectangle();      Rectangle vr = new Rectangle();
880      SwingUtilities.calculateInnerArea(scrollbar, vr);      SwingUtilities.calculateInnerArea(scrollbar, vr);
881    
     // Update the rectangles.  
     getTrackBounds();  
     getThumbBounds();  
   
882      Dimension incrDims = incrButton.getPreferredSize();      Dimension incrDims = incrButton.getPreferredSize();
883      Dimension decrDims = decrButton.getPreferredSize();      Dimension decrDims = decrButton.getPreferredSize();
884        
885        // calculate and update the track bounds
886        SwingUtilities.calculateInnerArea(scrollbar, trackRect);
887        trackRect.width -= incrDims.getWidth();
888        trackRect.width -= decrDims.getWidth();
889        trackRect.x += decrDims.getWidth();
890    
891        updateThumbRect();
892        
893      decrButton.setBounds(vr.x, vr.y, decrDims.width, trackRect.height);      decrButton.setBounds(vr.x, vr.y, decrDims.width, trackRect.height);
894      incrButton.setBounds(trackRect.x + trackRect.width, vr.y, incrDims.width,      incrButton.setBounds(trackRect.x + trackRect.width, vr.y, incrDims.width,
895                           trackRect.height);                           trackRect.height);
# Line 954  public class BasicScrollBarUI extends Sc Line 905  public class BasicScrollBarUI extends Sc
905      Rectangle vr = new Rectangle();      Rectangle vr = new Rectangle();
906      SwingUtilities.calculateInnerArea(scrollbar, vr);      SwingUtilities.calculateInnerArea(scrollbar, vr);
907    
     // Update rectangles  
     getTrackBounds();  
     getThumbBounds();  
   
908      Dimension incrDims = incrButton.getPreferredSize();      Dimension incrDims = incrButton.getPreferredSize();
909      Dimension decrDims = decrButton.getPreferredSize();      Dimension decrDims = decrButton.getPreferredSize();
910        
911        // Update rectangles
912        SwingUtilities.calculateInnerArea(scrollbar, trackRect);
913        trackRect.height -= incrDims.getHeight();
914        trackRect.height -= decrDims.getHeight();
915        trackRect.y += decrDims.getHeight();
916        
917        updateThumbRect();
918    
919      decrButton.setBounds(vr.x, vr.y, trackRect.width, decrDims.height);      decrButton.setBounds(vr.x, vr.y, trackRect.width, decrDims.height);
920      incrButton.setBounds(vr.x, trackRect.y + trackRect.height,      incrButton.setBounds(vr.x, trackRect.y + trackRect.height,
# Line 967  public class BasicScrollBarUI extends Sc Line 922  public class BasicScrollBarUI extends Sc
922    }    }
923    
924    /**    /**
925       * Updates the thumb rect.
926       */
927      void updateThumbRect()
928      {
929        int max = scrollbar.getMaximum();
930        int min = scrollbar.getMinimum();
931        int value = scrollbar.getValue();
932        int extent = scrollbar.getVisibleAmount();
933        if (max - extent <= min)
934          {
935            if (scrollbar.getOrientation() == JScrollBar.HORIZONTAL)
936              {
937                thumbRect.x = trackRect.x;
938                thumbRect.y = trackRect.y;
939                thumbRect.width = getMinimumThumbSize().width;
940                thumbRect.height = trackRect.height;
941              }
942            else
943              {
944                thumbRect.x = trackRect.x;
945                thumbRect.y = trackRect.y;
946                thumbRect.width = trackRect.width;
947                thumbRect.height = getMinimumThumbSize().height;
948              }
949          }
950        else
951          {
952            if (scrollbar.getOrientation() == JScrollBar.HORIZONTAL)
953              {
954                thumbRect.x = trackRect.x;
955                thumbRect.width = Math.max(extent * trackRect.width / (max - min),
956                    getMinimumThumbSize().width);
957                int availableWidth = trackRect.width - thumbRect.width;
958                thumbRect.x += (value - min) * availableWidth / (max - min - extent);
959                thumbRect.y = trackRect.y;
960                thumbRect.height = trackRect.height;
961              }
962            else
963              {
964                thumbRect.x = trackRect.x;
965                thumbRect.height = Math.max(extent * trackRect.height / (max - min),
966                        getMinimumThumbSize().height);
967                int availableHeight = trackRect.height - thumbRect.height;
968                thumbRect.y = trackRect.y
969                  + (value - min) * availableHeight / (max - min - extent);
970                thumbRect.width = trackRect.width;
971              }
972          }
973    
974      }
975      
976      /**
977     * This method returns the minimum size required for the layout.     * This method returns the minimum size required for the layout.
978     *     *
979     * @param scrollbarContainer The Container that is laid out.     * @param scrollbarContainer The Container that is laid out.

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

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