Save This Page
Home » openjdk-7 » javax » swing » plaf » synth » [javadoc | source]
    1   /*
    2    * Copyright 2002-2006 Sun Microsystems, Inc.  All Rights Reserved.
    3    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    4    *
    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
    7    * published by the Free Software Foundation.  Sun designates this
    8    * particular file as subject to the "Classpath" exception as provided
    9    * by Sun in the LICENSE file that accompanied this code.
   10    *
   11    * This code is distributed in the hope that it will be useful, but WITHOUT
   12    * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   13    * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   14    * version 2 for more details (a copy is included in the LICENSE file that
   15    * accompanied this code).
   16    *
   17    * You should have received a copy of the GNU General Public License version
   18    * 2 along with this work; if not, write to the Free Software Foundation,
   19    * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   20    *
   21    * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   22    * CA 95054 USA or visit www.sun.com if you need additional information or
   23    * have any questions.
   24    */
   25   package javax.swing.plaf.synth;
   26   
   27   import java.awt;
   28   import javax.swing;
   29   import javax.swing.plaf.UIResource;
   30   
   31   /**
   32    * JButton object that draws a scaled Arrow in one of the cardinal directions.
   33    *
   34    * @author Scott Violet
   35    */
   36   class SynthArrowButton extends JButton implements SwingConstants, UIResource {
   37       private int direction;
   38   
   39       public SynthArrowButton(int direction) {
   40           super();
   41           super.setFocusable(false);
   42           setDirection(direction);
   43           setDefaultCapable(false);
   44       }
   45   
   46       public String getUIClassID() {
   47           return "ArrowButtonUI";
   48       }
   49   
   50       public void updateUI() {
   51           setUI(new SynthArrowButtonUI());
   52       }
   53   
   54       public void setDirection(int dir) {
   55           direction = dir;
   56           putClientProperty("__arrow_direction__", Integer.valueOf(dir));
   57           repaint();
   58       }
   59   
   60       public int getDirection() {
   61           return direction;
   62       }
   63   
   64       public void setFocusable(boolean focusable) {}
   65   
   66       private static class SynthArrowButtonUI extends SynthButtonUI {
   67           protected void installDefaults(AbstractButton b) {
   68               super.installDefaults(b);
   69               updateStyle(b);
   70           }
   71   
   72           protected void paint(SynthContext context, Graphics g) {
   73               SynthArrowButton button = (SynthArrowButton)context.
   74                                         getComponent();
   75               context.getPainter().paintArrowButtonForeground(
   76                   context, g, 0, 0, button.getWidth(), button.getHeight(),
   77                   button.getDirection());
   78           }
   79   
   80           void paintBackground(SynthContext context, Graphics g, JComponent c) {
   81               context.getPainter().paintArrowButtonBackground(context, g, 0, 0,
   82                                                   c.getWidth(), c.getHeight());
   83           }
   84   
   85           public void paintBorder(SynthContext context, Graphics g, int x,
   86                                   int y, int w, int h) {
   87               context.getPainter().paintArrowButtonBorder(context, g, x, y, w,h);
   88           }
   89   
   90           public Dimension getMinimumSize() {
   91               return new Dimension(5, 5);
   92           }
   93   
   94           public Dimension getMaximumSize() {
   95               return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
   96           }
   97   
   98           public Dimension getPreferredSize(JComponent c) {
   99               SynthContext context = getContext(c);
  100               Dimension dim = null;
  101               if (context.getComponent().getName() == "ScrollBar.button") {
  102                   // ScrollBar arrow buttons can be non-square when
  103                   // the ScrollBar.squareButtons property is set to FALSE
  104                   // and the ScrollBar.buttonSize property is non-null
  105                   dim = (Dimension)
  106                       context.getStyle().get(context, "ScrollBar.buttonSize");
  107               }
  108               if (dim == null) {
  109                   // For all other cases (including Spinner, ComboBox), we will
  110                   // fall back on the single ArrowButton.size value to create
  111                   // a square return value
  112                   int size =
  113                       context.getStyle().getInt(context, "ArrowButton.size", 16);
  114                   dim = new Dimension(size, size);
  115               }
  116               context.dispose();
  117               return dim;
  118           }
  119       }
  120   }

Save This Page
Home » openjdk-7 » javax » swing » plaf » synth » [javadoc | source]