jdk/src/share/classes/javax/swing/plaf/metal/MetalScrollBarUI.java
changeset 24163 d56df89854c4
parent 23715 54ae9dd9df73
child 25178 dbab904451e9
equal deleted inserted replaced
24162:0fe6fb6759ab 24163:d56df89854c4
     1 /*
     1 /*
     2  * Copyright (c) 1998, 2004, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    23  * questions.
    23  * questions.
    24  */
    24  */
    25 
    25 
    26 package javax.swing.plaf.metal;
    26 package javax.swing.plaf.metal;
    27 
    27 
    28 import java.awt.Component;
    28 import java.awt.Color;
    29 import java.awt.Container;
    29 import java.awt.Dimension;
    30 import java.awt.LayoutManager;
       
    31 import java.awt.Adjustable;
       
    32 import java.awt.event.AdjustmentListener;
       
    33 import java.awt.event.AdjustmentEvent;
       
    34 import java.awt.event.ActionListener;
       
    35 import java.awt.event.ActionEvent;
       
    36 import java.awt.event.MouseListener;
       
    37 import java.awt.event.MouseMotionListener;
       
    38 import java.awt.event.MouseAdapter;
       
    39 import java.awt.event.MouseEvent;
       
    40 import java.awt.Graphics;
    30 import java.awt.Graphics;
    41 import java.awt.Dimension;
       
    42 import java.awt.Rectangle;
    31 import java.awt.Rectangle;
    43 import java.awt.Point;
    32 import java.beans.PropertyChangeEvent;
    44 import java.awt.Insets;
    33 import java.beans.PropertyChangeListener;
    45 import java.awt.Color;
    34 
    46 import java.awt.IllegalComponentStateException;
    35 import javax.swing.JButton;
    47 
    36 import javax.swing.JComponent;
    48 import java.beans.*;
    37 import javax.swing.JScrollBar;
    49 
    38 import javax.swing.UIManager;
    50 import javax.swing.*;
    39 import javax.swing.plaf.ComponentUI;
    51 import javax.swing.event.*;
       
    52 
       
    53 import javax.swing.plaf.*;
       
    54 import javax.swing.plaf.basic.BasicScrollBarUI;
    40 import javax.swing.plaf.basic.BasicScrollBarUI;
       
    41 
       
    42 import static sun.swing.SwingUtilities2.drawHLine;
       
    43 import static sun.swing.SwingUtilities2.drawRect;
       
    44 import static sun.swing.SwingUtilities2.drawVLine;
    55 
    45 
    56 
    46 
    57 /**
    47 /**
    58  * Implementation of ScrollBarUI for the Metal Look and Feel
    48  * Implementation of ScrollBarUI for the Metal Look and Feel
    59  *
    49  *
   156                 }
   146                 }
   157             }
   147             }
   158 
   148 
   159             if ( c.isEnabled() ) {
   149             if ( c.isEnabled() ) {
   160                 g.setColor( darkShadowColor );
   150                 g.setColor( darkShadowColor );
   161                 g.drawLine( 0, 0, 0, trackBounds.height - 1 );
   151                 drawVLine(g, 0, 0, trackBounds.height - 1);
   162                 g.drawLine( trackBounds.width - 2, 0, trackBounds.width - 2, trackBounds.height - 1 );
   152                 drawVLine(g, trackBounds.width - 2, 0, trackBounds.height - 1);
   163                 g.drawLine( 2, trackBounds.height - 1, trackBounds.width - 1, trackBounds.height - 1);
   153                 drawHLine(g, 2, trackBounds.width - 1, trackBounds.height - 1);
   164                 g.drawLine( 2, 0, trackBounds.width - 2, 0 );
   154                 drawHLine(g, 2, trackBounds.width - 2, 0);
   165 
   155 
   166                 g.setColor( shadowColor );
   156                 g.setColor( shadowColor );
   167                 //      g.setColor( Color.red);
   157                 //      g.setColor( Color.red);
   168                 g.drawLine( 1, 1, 1, trackBounds.height - 2 );
   158                 drawVLine(g, 1, 1, trackBounds.height - 2);
   169                 g.drawLine( 1, 1, trackBounds.width - 3, 1 );
   159                 drawHLine(g, 1, trackBounds.width - 3, 1);
   170                 if (scrollbar.getValue() != scrollbar.getMaximum()) {  // thumb shadow
   160                 if (scrollbar.getValue() != scrollbar.getMaximum()) {  // thumb shadow
   171                     int y = thumbRect.y + thumbRect.height - trackBounds.y;
   161                     int y = thumbRect.y + thumbRect.height - trackBounds.y;
   172                     g.drawLine( 1, y, trackBounds.width-1, y);
   162                     drawHLine(g, 1, trackBounds.width - 1, y);
   173                 }
   163                 }
   174                 g.setColor(highlightColor);
   164                 g.setColor(highlightColor);
   175                 g.drawLine( trackBounds.width - 1, 0, trackBounds.width - 1, trackBounds.height - 1 );
   165                 drawVLine(g, trackBounds.width - 1, 0, trackBounds.height - 1);
   176             } else {
   166             } else {
   177                 MetalUtils.drawDisabledBorder(g, 0, 0, trackBounds.width, trackBounds.height );
   167                 MetalUtils.drawDisabledBorder(g, 0, 0, trackBounds.width, trackBounds.height );
   178             }
   168             }
   179 
   169 
   180             if ( !isFreeStanding ) {
   170             if ( !isFreeStanding ) {
   190                 trackBounds.height += 2;
   180                 trackBounds.height += 2;
   191             }
   181             }
   192 
   182 
   193             if ( c.isEnabled() ) {
   183             if ( c.isEnabled() ) {
   194                 g.setColor( darkShadowColor );
   184                 g.setColor( darkShadowColor );
   195                 g.drawLine( 0, 0, trackBounds.width - 1, 0 );  // top
   185                 drawHLine(g, 0, trackBounds.width - 1, 0);  // top
   196                 g.drawLine( 0, 2, 0, trackBounds.height - 2 ); // left
   186                 drawVLine(g, 0, 2, trackBounds.height - 2); // left
   197                 g.drawLine( 0, trackBounds.height - 2, trackBounds.width - 1, trackBounds.height - 2 ); // bottom
   187                 drawHLine(g, 0, trackBounds.width - 1, trackBounds.height - 2 ); // bottom
   198                 g.drawLine( trackBounds.width - 1, 2, trackBounds.width - 1, trackBounds.height - 1 ); // right
   188                 drawVLine(g, trackBounds.width - 1, 2,  trackBounds.height - 1 ); // right
   199 
   189 
   200                 g.setColor( shadowColor );
   190                 g.setColor( shadowColor );
   201                 //      g.setColor( Color.red);
   191                 //      g.setColor( Color.red);
   202                 g.drawLine( 1, 1, trackBounds.width - 2, 1 );  // top
   192                 drawHLine(g, 1, trackBounds.width - 2, 1 );  // top
   203                 g.drawLine( 1, 1, 1, trackBounds.height - 3 ); // left
   193                 drawVLine(g, 1, 1, trackBounds.height - 3 ); // left
   204                 g.drawLine( 0, trackBounds.height - 1, trackBounds.width - 1, trackBounds.height - 1 ); // bottom
   194                 drawHLine(g, 0, trackBounds.width - 1, trackBounds.height - 1 ); // bottom
   205                 if (scrollbar.getValue() != scrollbar.getMaximum()) {  // thumb shadow
   195                 if (scrollbar.getValue() != scrollbar.getMaximum()) {  // thumb shadow
   206                     int x = thumbRect.x + thumbRect.width - trackBounds.x;
   196                     int x = thumbRect.x + thumbRect.width - trackBounds.x;
   207                     g.drawLine( x, 1, x, trackBounds.height-1);
   197                     drawVLine(g, x, 1, trackBounds.height-1);
   208                 }
   198                 }
   209             } else {
   199             } else {
   210                 MetalUtils.drawDisabledBorder(g, 0, 0, trackBounds.width, trackBounds.height );
   200                 MetalUtils.drawDisabledBorder(g, 0, 0, trackBounds.width, trackBounds.height );
   211             }
   201             }
   212 
   202 
   244 
   234 
   245             g.setColor( thumbColor );
   235             g.setColor( thumbColor );
   246             g.fillRect( 0, 0, thumbBounds.width - 2, thumbBounds.height - 1 );
   236             g.fillRect( 0, 0, thumbBounds.width - 2, thumbBounds.height - 1 );
   247 
   237 
   248             g.setColor( thumbShadow );
   238             g.setColor( thumbShadow );
   249             g.drawRect( 0, 0, thumbBounds.width - 2, thumbBounds.height - 1 );
   239             drawRect(g, 0, 0, thumbBounds.width - 2, thumbBounds.height - 1);
   250 
   240 
   251             g.setColor( thumbHighlightColor );
   241             g.setColor( thumbHighlightColor );
   252             g.drawLine( 1, 1, thumbBounds.width - 3, 1 );
   242             drawHLine(g, 1, thumbBounds.width - 3, 1);
   253             g.drawLine( 1, 1, 1, thumbBounds.height - 2 );
   243             drawVLine(g, 1, 1, thumbBounds.height - 2);
   254 
   244 
   255             bumps.setBumpArea( thumbBounds.width - 6, thumbBounds.height - 7 );
   245             bumps.setBumpArea( thumbBounds.width - 6, thumbBounds.height - 7 );
   256             bumps.paintIcon( c, g, 3, 4 );
   246             bumps.paintIcon( c, g, 3, 4 );
   257 
   247 
   258             if ( !isFreeStanding ) {
   248             if ( !isFreeStanding ) {
   270 
   260 
   271             g.setColor( thumbColor );
   261             g.setColor( thumbColor );
   272             g.fillRect( 0, 0, thumbBounds.width - 1, thumbBounds.height - 2 );
   262             g.fillRect( 0, 0, thumbBounds.width - 1, thumbBounds.height - 2 );
   273 
   263 
   274             g.setColor( thumbShadow );
   264             g.setColor( thumbShadow );
   275             g.drawRect( 0, 0, thumbBounds.width - 1, thumbBounds.height - 2 );
   265             drawRect(g, 0, 0, thumbBounds.width - 1, thumbBounds.height - 2);
   276 
   266 
   277             g.setColor( thumbHighlightColor );
   267             g.setColor( thumbHighlightColor );
   278             g.drawLine( 1, 1, thumbBounds.width - 3, 1 );
   268             drawHLine(g, 1, thumbBounds.width - 3, 1);
   279             g.drawLine( 1, 1, 1, thumbBounds.height - 3 );
   269             drawVLine(g, 1, 1, thumbBounds.height - 3);
   280 
   270 
   281             bumps.setBumpArea( thumbBounds.width - 7, thumbBounds.height - 6 );
   271             bumps.setBumpArea( thumbBounds.width - 7, thumbBounds.height - 6 );
   282             bumps.paintIcon( c, g, 4, 3 );
   272             bumps.paintIcon( c, g, 4, 3 );
   283 
   273 
   284             if ( !isFreeStanding ) {
   274             if ( !isFreeStanding ) {
   307                 g.setColor(thumbColor);
   297                 g.setColor(thumbColor);
   308                 g.fillRect(0, 0, thumbBounds.width - 2,thumbBounds.height - 1);
   298                 g.fillRect(0, 0, thumbBounds.width - 2,thumbBounds.height - 1);
   309             }
   299             }
   310 
   300 
   311             g.setColor(thumbShadow);
   301             g.setColor(thumbShadow);
   312             g.drawRect(0, 0, thumbBounds.width - 2, thumbBounds.height - 1);
   302             drawRect(g, 0, 0, thumbBounds.width - 2, thumbBounds.height - 1);
   313 
   303 
   314             g.setColor(thumbHighlightColor);
   304             g.setColor(thumbHighlightColor);
   315             g.drawLine(1, 1, thumbBounds.width - 3, 1);
   305             drawHLine(g, 1, thumbBounds.width - 3, 1);
   316             g.drawLine(1, 1, 1, thumbBounds.height - 2);
   306             drawVLine(g, 1, 1, thumbBounds.height - 2);
   317 
   307 
   318             MetalUtils.drawGradient(c, g, "ScrollBar.gradient", 2, 2,
   308             MetalUtils.drawGradient(c, g, "ScrollBar.gradient", 2, 2,
   319                                     thumbBounds.width - 4,
   309                                     thumbBounds.width - 4,
   320                                     thumbBounds.height - 3, false);
   310                                     thumbBounds.height - 3, false);
   321 
   311 
   349                 g.setColor(thumbColor);
   339                 g.setColor(thumbColor);
   350                 g.fillRect(0, 0, thumbBounds.width - 1,thumbBounds.height - 2);
   340                 g.fillRect(0, 0, thumbBounds.width - 1,thumbBounds.height - 2);
   351             }
   341             }
   352 
   342 
   353             g.setColor(thumbShadow);
   343             g.setColor(thumbShadow);
   354             g.drawRect(0, 0, thumbBounds.width - 1, thumbBounds.height - 2);
   344             drawRect(g, 0, 0, thumbBounds.width - 1, thumbBounds.height - 2);
   355 
   345 
   356             g.setColor(thumbHighlightColor);
   346             g.setColor(thumbHighlightColor);
   357             g.drawLine(1, 1, thumbBounds.width - 2, 1);
   347             drawHLine(g, 1, thumbBounds.width - 2, 1);
   358             g.drawLine(1, 1, 1, thumbBounds.height - 3);
   348             drawVLine(g, 1, 1, thumbBounds.height - 3);
   359 
   349 
   360             MetalUtils.drawGradient(c, g, "ScrollBar.gradient", 2, 2,
   350             MetalUtils.drawGradient(c, g, "ScrollBar.gradient", 2, 2,
   361                                     thumbBounds.width - 3,
   351                                     thumbBounds.width - 3,
   362                                     thumbBounds.height - 4, true);
   352                                     thumbBounds.height - 4, true);
   363 
   353