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

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

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

revision 1.10 by brawer, Mon Jun 23 08:49:45 2003 UTC revision 1.11 by brawer, Mon Jun 23 10:02:50 2003 UTC
# Line 1192  public class BasicBorders Line 1192  public class BasicBorders
1192    }    }
1193    
1194    
1195      /**
1196       * A one-pixel thick border for rollover buttons, for example in
1197       * tool bars.
1198       *
1199       * @since 1.4
1200       * @author Sascha Brawer (brawer@dandelis.ch)
1201       */
1202    public static class RolloverButtonBorder    public static class RolloverButtonBorder
1203        extends ButtonBorder
1204    {    {
1205    } // class RolloverButtonBorder      /**
1206         * Determined using the <code>serialver</code> tool
1207         * of Sun JDK 1.4.1_01 on GNU/Linux 2.4.20 for x86.
1208         */
1209        static final long serialVersionUID = 1976364864896996846L;
1210    
1211    
1212        /**
1213         * Constructs a new border for drawing a roll-over button
1214         * in the Basic look and feel.
1215         *
1216         * @param shadow the shadow color.
1217         * @param darkShadow a darker variant of the shadow color.
1218         * @param highlight the highlight color.
1219         * @param lightHighlight a brighter variant of the highlight  color.
1220         */
1221        public RolloverButtonBorder(Color shadow, Color darkShadow,
1222                                    Color highlight, Color lightHighlight)
1223        {
1224          super(shadow, darkShadow, highlight, lightHighlight);
1225        }
1226    
1227    
1228        /**
1229         * Paints the border around a rollover button.  If <code>c</code>
1230         * is not an {@link javax.swing.AbstractButton} whose model
1231         * returns <code>true</code> for {@link
1232         * javax.swing.ButtonModel#isRollver}, nothing gets painted at
1233         * all.
1234         *
1235         * @param c the button whose border is to be painted.
1236         * @param g the graphics for painting.
1237         * @param x the horizontal position for painting the border.
1238         * @param y the vertical position for painting the border.
1239         * @param width the width of the available area for painting the border.
1240         * @param height the height of the available area for painting the border.
1241         */
1242        public void paintBorder(Component c, Graphics  g,
1243                                int x, int y, int width, int height)
1244        {
1245          ButtonModel bmodel = null;
1246          boolean drawPressed;
1247          Color oldColor = g.getColor();
1248          int x2, y2;
1249    
1250          if (c instanceof AbstractButton)
1251            bmodel = ((AbstractButton) c).getModel();
1252    
1253          /* Draw nothing if c is not a rollover button. */
1254          if ((bmodel == null) || !bmodel.isRollover())
1255            return;
1256    
1257          /* Draw nothing if the mouse is pressed, but outside the button. */
1258          if (bmodel.isPressed() && !bmodel.isArmed())
1259            return;
1260    
1261          drawPressed = bmodel.isSelected() || bmodel.isPressed();
1262          x2 = x + width - 1;
1263          y2 = y + height - 1;
1264    
1265          try
1266          {
1267            g.setColor(drawPressed ? shadow : lightHighlight);
1268            g.drawLine(x, y, x2 - 1, y);     // top edge
1269            g.drawLine(x, y + 1, x, y2 - 1); // left edge
1270    
1271            g.setColor(drawPressed ? lightHighlight : shadow);
1272            g.drawLine(x, y2, x2, y2);       // bottom edge
1273            g.drawLine(x2, y, x2, y2 - 1);   // right edge
1274          }
1275          finally
1276          {
1277            g.setColor(oldColor);
1278          }
1279        }
1280      }
1281    
1282    
1283    /**    /**

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.11

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