/*
 * @(#)SeaGlassArrowButton.java	1.20 08/05/22
 *
 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.seaglass;

import java.awt.Dimension;
import java.awt.Graphics;

import javax.swing.AbstractButton;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.SwingConstants;
import javax.swing.plaf.UIResource;

/**
 * JButton object that draws a scaled Arrow in one of the cardinal directions.
 *
 * @version 1.20, 05/22/08
 * @author Scott Violet
 */
class SeaGlassArrowButton extends JButton implements SwingConstants, UIResource {
    private int direction;

    public SeaGlassArrowButton(int direction) {
        super();
        super.setFocusable(false);
        setDirection(direction);
        setDefaultCapable(false);
    }

    public String getUIClassID() {
        return "ArrowButtonUI";
    }

    public void updateUI() {
        setUI(new SeaGlassArrowButtonUI());
    }

    public void setDirection(int dir) {
        direction = dir;
        putClientProperty("__arrow_direction__", new Integer(dir));
        repaint();
    }

    public int getDirection() {
        return direction;
    }

    public void setFocusable(boolean focusable) {} 
    
    private static class SeaGlassArrowButtonUI extends SeaGlassButtonUI {
        protected void installDefaults(AbstractButton b) {
            super.installDefaults(b);
            updateStyle(b);
        }

        protected void paint(SeaGlassContext context, Graphics g) {
            SeaGlassArrowButton button = (SeaGlassArrowButton)context.
                                      getComponent();
            context.getPainter().paintArrowButtonForeground(
                context, g, 0, 0, button.getWidth(), button.getHeight(),
                button.getDirection());
        }

        void paintBackground(SeaGlassContext context, Graphics g, JComponent c) {
            context.getPainter().paintArrowButtonBackground(context, g, 0, 0,
                                                c.getWidth(), c.getHeight());
        }

        public void paintBorder(SeaGlassContext context, Graphics g, int x,
                                int y, int w, int h) {
            context.getPainter().paintArrowButtonBorder(context, g, x, y, w,h);
        }

        public Dimension getMinimumSize() {
            return new Dimension(5, 5);
        }

        public Dimension getMaximumSize() {
            return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
        }

        public Dimension getPreferredSize(JComponent c) {
            SeaGlassContext context = getContext(c);
            Dimension dim = null;
            if (context.getComponent().getName() == "ScrollBar.button") {
                // ScrollBar arrow buttons can be non-square when
                // the ScrollBar.squareButtons property is set to FALSE
                // and the ScrollBar.buttonSize property is non-null
                dim = (Dimension)
                    context.getStyle().get(context, "ScrollBar.buttonSize");
            }
            if (dim == null) {
                // For all other cases (including Spinner, ComboBox), we will
                // fall back on the single ArrowButton.size value to create
                // a square return value
                int size =
                    context.getStyle().getInt(context, "ArrowButton.size", 16);
                dim = new Dimension(size, size);
            }

            // handle scaling for sizeVarients for special case components. The
            // key "JComponent.sizeVariant" scales for large/small/mini
            // components are based on Apples LAF
            JComponent parent = (JComponent)context.getComponent().getParent();
            if (parent != null && !(parent instanceof JComboBox)){
                String scaleKey = (String)parent.getClientProperty("JComponent.sizeVariant");
                if (scaleKey != null){
                    if ("large".equals(scaleKey)){
                        dim = new Dimension(
                                (int)(dim.width * 1.15),
                                (int)(dim.height * 1.15));
                    } else if ("small".equals(scaleKey)){
                        dim = new Dimension(
                                (int)(dim.width * 0.857),
                                (int)(dim.height * 0.857));
                    } else if ("mini".equals(scaleKey)){
                        dim = new Dimension(
                                (int)(dim.width * 0.714),
                                (int)(dim.height * 0.714));
                    }
                }
            }

            context.dispose();
            return dim;
        }
    }
}

@@ -539,64 +539,119 @@
 .%0A *
+ 
 %0A * 
-@version 1.20, 05/22/08%0A * @author Scott Violet%0A */%0A
+Based on SynthArrowButton by Scott Violet.%0A * %0A * @see javax.swing.plaf.synth.SynthArrowButton%0A */%0Apublic 
 clas
@@ -1361,15 +1361,15 @@
 e) %7B
-%7D 
 %0A    
+%7D%0A
 %0A   
@@ -1705,24 +1705,25 @@
 wButton)
+ 
 context.
 %0A       
@@ -1718,47 +1718,8 @@
 ext.
-%0A                                      
 getC
@@ -1790,33 +1790,16 @@
 eground(
-%0A                
 context,
@@ -2061,56 +2061,8 @@
 , 0,
-%0A                                               
  c.g
@@ -2178,40 +2178,8 @@
 t x,
-%0A                               
  int
@@ -2274,16 +2274,17 @@
 x, y, w,
+ 
 h);%0A    
@@ -2971,36 +2971,16 @@
 mension)
-%0A                   
  context
@@ -3295,36 +3295,16 @@
 t size =
-%0A                   
  context
@@ -3666,16 +3666,17 @@
 mponent)
+ 
 context.
@@ -3768,16 +3768,17 @@
 mboBox))
+ 
 %7B%0A      
@@ -3813,16 +3813,17 @@
 (String)
+ 
 parent.g
@@ -3903,16 +3903,17 @@
 != null)
+ 
 %7B%0A      
@@ -3947,32 +3947,33 @@
 quals(scaleKey))
+ 
 %7B%0A              
@@ -4006,46 +4006,14 @@
 ion(
-%0A                                
 (int)
+ 
 (dim
@@ -4031,46 +4031,15 @@
 15),
-%0A                               
  (int)
+ 
 (dim
@@ -4104,32 +4104,33 @@
 quals(scaleKey))
+ 
 %7B%0A              
@@ -4163,46 +4163,14 @@
 ion(
-%0A                                
 (int)
+ 
 (dim
@@ -4189,46 +4189,15 @@
 57),
-%0A                               
  (int)
+ 
 (dim
@@ -4270,16 +4270,17 @@
 aleKey))
+ 
 %7B%0A      
@@ -4321,46 +4321,14 @@
 ion(
-%0A                                
 (int)
+ 
 (dim
@@ -4347,46 +4347,15 @@
 14),
-%0A                               
  (int)
+ 
 (dim

Make SeaGlassArrowButton public. I hate private classes.