Save This Page
Home » openjdk-7 » javax » swing » plaf » synth » [javadoc | source]
    1   /*
    2    * Copyright 2002-2003 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   
   26   package javax.swing.plaf.synth;
   27   
   28   import javax.swing;
   29   import javax.swing.event;
   30   import javax.swing.border;
   31   import javax.swing.plaf;
   32   import javax.swing.plaf.basic;
   33   
   34   import java.beans.PropertyChangeListener;
   35   import java.beans.PropertyChangeEvent;
   36   
   37   import java.awt;
   38   import java.awt.event;
   39   import sun.swing.plaf.synth.SynthUI;
   40   
   41   
   42   /**
   43    * Synth's ScrollPaneUI.
   44    *
   45    * @author Scott Violet
   46    */
   47   class SynthScrollPaneUI extends BasicScrollPaneUI implements
   48                    PropertyChangeListener, SynthUI {
   49       private SynthStyle style;
   50   
   51       public static ComponentUI createUI(JComponent x) {
   52           return new SynthScrollPaneUI();
   53       }
   54   
   55       public void update(Graphics g, JComponent c) {
   56           SynthContext context = getContext(c);
   57   
   58           SynthLookAndFeel.update(context, g);
   59           context.getPainter().paintScrollPaneBackground(context,
   60                             g, 0, 0, c.getWidth(), c.getHeight());
   61           paint(context, g);
   62           context.dispose();
   63       }
   64   
   65       public void paint(Graphics g, JComponent c) {
   66           SynthContext context = getContext(c);
   67   
   68           paint(context, g);
   69           context.dispose();
   70       }
   71   
   72       protected void paint(SynthContext context, Graphics g) {
   73           Border vpBorder = scrollpane.getViewportBorder();
   74           if (vpBorder != null) {
   75               Rectangle r = scrollpane.getViewportBorderBounds();
   76               vpBorder.paintBorder(scrollpane, g, r.x, r.y, r.width, r.height);
   77           }
   78       }
   79   
   80   
   81       public void paintBorder(SynthContext context, Graphics g, int x,
   82                               int y, int w, int h) {
   83           context.getPainter().paintScrollPaneBorder(context, g, x, y, w, h);
   84       }
   85   
   86       protected void installDefaults(JScrollPane scrollpane) {
   87           updateStyle(scrollpane);
   88       }
   89   
   90       private void updateStyle(JScrollPane c) {
   91           SynthContext context = getContext(c, ENABLED);
   92           SynthStyle oldStyle = style;
   93   
   94           style = SynthLookAndFeel.updateStyle(context, this);
   95           if (style != oldStyle) {
   96               Border vpBorder = scrollpane.getViewportBorder();
   97               if ((vpBorder == null) ||( vpBorder instanceof UIResource)) {
   98                   scrollpane.setViewportBorder(new ViewportBorder(context));
   99               }
  100               if (oldStyle != null) {
  101                   uninstallKeyboardActions(c);
  102                   installKeyboardActions(c);
  103               }
  104           }
  105           context.dispose();
  106       }
  107   
  108   
  109       protected void installListeners(JScrollPane c) {
  110           super.installListeners(c);
  111           c.addPropertyChangeListener(this);
  112       }
  113   
  114       protected void uninstallDefaults(JScrollPane c) {
  115           SynthContext context = getContext(c, ENABLED);
  116   
  117           style.uninstallDefaults(context);
  118           context.dispose();
  119   
  120           if (scrollpane.getViewportBorder() instanceof UIResource) {
  121               scrollpane.setViewportBorder(null);
  122           }
  123       }
  124   
  125   
  126       protected void uninstallListeners(JComponent c) {
  127           super.uninstallListeners(c);
  128           c.removePropertyChangeListener(this);
  129       }
  130   
  131   
  132       public SynthContext getContext(JComponent c) {
  133           return getContext(c, getComponentState(c));
  134       }
  135   
  136       private SynthContext getContext(JComponent c, int state) {
  137           return SynthContext.getContext(SynthContext.class, c,
  138                       SynthLookAndFeel.getRegion(c), style, state);
  139       }
  140   
  141   
  142       private Region getRegion(JComponent c) {
  143           return SynthLookAndFeel.getRegion(c);
  144       }
  145   
  146   
  147       private int getComponentState(JComponent c) {
  148           return SynthLookAndFeel.getComponentState(c);
  149       }
  150   
  151       public void propertyChange(PropertyChangeEvent e) {
  152           if (SynthLookAndFeel.shouldUpdateStyle(e)) {
  153               updateStyle(scrollpane);
  154           }
  155       }
  156   
  157   
  158   
  159       private class ViewportBorder extends AbstractBorder implements UIResource {
  160           private Insets insets;
  161   
  162           ViewportBorder(SynthContext context) {
  163               this.insets = (Insets)context.getStyle().get(context,
  164                                               "ScrollPane.viewportBorderInsets");
  165               if (this.insets == null) {
  166                   this.insets = SynthLookAndFeel.EMPTY_UIRESOURCE_INSETS;
  167               }
  168           }
  169   
  170           public void paintBorder(Component c, Graphics g, int x, int y,
  171                               int width, int height) {
  172               JComponent jc = (JComponent)c;
  173               SynthContext context = getContext(jc);
  174               SynthStyle style = context.getStyle();
  175               if (style == null) {
  176                   assert false: "SynthBorder is being used outside after the " +
  177                                 " UI has been uninstalled";
  178                   return;
  179               }
  180               context.getPainter().paintViewportBorder(context, g, x, y, width,
  181                                                        height);
  182               context.dispose();
  183           }
  184   
  185           public Insets getBorderInsets(Component c, Insets insets) {
  186               if (insets == null) {
  187                   return new Insets(this.insets.top, this.insets.left,
  188                                     this.insets.bottom, this.insets.right);
  189               }
  190               insets.top = this.insets.top;
  191               insets.bottom = this.insets.bottom;
  192               insets.left = this.insets.left;
  193               insets.right = this.insets.left;
  194               return insets;
  195           }
  196   
  197           public boolean isBorderOpaque() {
  198               return false;
  199           }
  200       }
  201   }

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