Source for javax.swing.plaf.metal.MetalToolBarUI

   1: /* MetalToolBarUI.java
   2:    Copyright (C) 2005 Free Software Foundation, Inc.
   3: 
   4: This file is part of GNU Classpath.
   5: 
   6: GNU Classpath is free software; you can redistribute it and/or modify
   7: it under the terms of the GNU General Public License as published by
   8: the Free Software Foundation; either version 2, or (at your option)
   9: any later version.
  10: 
  11: GNU Classpath is distributed in the hope that it will be useful, but
  12: WITHOUT ANY WARRANTY; without even the implied warranty of
  13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14: General Public License for more details.
  15: 
  16: You should have received a copy of the GNU General Public License
  17: along with GNU Classpath; see the file COPYING.  If not, write to the
  18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19: 02110-1301 USA.
  20: 
  21: Linking this library statically or dynamically with other modules is
  22: making a combined work based on this library.  Thus, the terms and
  23: conditions of the GNU General Public License cover the whole
  24: combination.
  25: 
  26: As a special exception, the copyright holders of this library give you
  27: permission to link this library with independent modules to produce an
  28: executable, regardless of the license terms of these independent
  29: modules, and to copy and distribute the resulting executable under
  30: terms of your choice, provided that you also meet, for each linked
  31: independent module, the terms and conditions of the license of that
  32: module.  An independent module is a module which is not derived from
  33: or based on this library.  If you modify this library, you may extend
  34: this exception to your version of the library, but you are not
  35: obligated to do so.  If you do not wish to do so, delete this
  36: exception statement from your version. */
  37: 
  38: 
  39: package javax.swing.plaf.metal;
  40: 
  41: import java.awt.Point;
  42: import java.awt.event.ContainerListener;
  43: import java.awt.event.MouseEvent;
  44: 
  45: import java.beans.PropertyChangeListener;
  46: 
  47: import javax.swing.JComponent;
  48: import javax.swing.JToolBar;
  49: import javax.swing.border.Border;
  50: import javax.swing.event.MouseInputListener;
  51: import javax.swing.plaf.ComponentUI;
  52: import javax.swing.plaf.basic.BasicToolBarUI;
  53: 
  54: /**
  55:  * A UI delegate for the {@link JToolBar} component.
  56:  */
  57: public class MetalToolBarUI extends BasicToolBarUI
  58: {
  59:   
  60:   /**
  61:    * A listener (no longer used) that responds when components are added to or 
  62:    * removed from the {@link JToolBar}.  The required behaviour is now
  63:    * handled in the super class. 
  64:    * 
  65:    * @see MetalToolBarUI#createContainerListener()
  66:    */
  67:   protected class MetalContainerListener
  68:     extends BasicToolBarUI.ToolBarContListener
  69:   {
  70:     /**
  71:      * Creates a new instance.
  72:      */
  73:     protected MetalContainerListener()
  74:     {
  75:       // Nothing to do here.
  76:     }
  77:   }
  78: 
  79:   /**
  80:    * A listener (no longer used) that responds to property change events in a
  81:    * {@link JToolBar} component.  The required behaviour is now handled in the 
  82:    * super class. 
  83:    * 
  84:    * @see MetalToolBarUI#createRolloverListener()
  85:    */
  86:   protected class MetalRolloverListener
  87:     extends BasicToolBarUI.PropertyListener
  88:   {
  89:     /**
  90:      * Creates a new instance.
  91:      */
  92:     protected MetalRolloverListener()
  93:     {
  94:       // Nothing to do here.
  95:     }
  96:   }
  97:   
  98:   /** 
  99:    * The container listener (an implementation specific field, according to the
 100:    * spec, and not used in GNU Classpath).
 101:    */
 102:   protected ContainerListener contListener;
 103:   
 104:   /** 
 105:    * The rollover listener (an implementation specific field, according to the
 106:    * spec, and not used in GNU Classpath). 
 107:    */
 108:   protected PropertyChangeListener rolloverListener;
 109: 
 110:   /**
 111:    * Creates a new instance of this UI delegate.
 112:    */
 113:   public MetalToolBarUI()
 114:   {
 115:     super();
 116:   }
 117: 
 118:   /**
 119:    * Returns a new instance of <code>MetalToolBarUI</code>.
 120:    *
 121:    * @param component  the component for which we return an UI instance
 122:    *
 123:    * @return A new instance of <code>MetalToolBarUI</code>.
 124:    */
 125:   public static ComponentUI createUI(JComponent component)
 126:   {
 127:     return new MetalToolBarUI();
 128:   }
 129:   
 130:   /**
 131:    * Returns <code>null</code> as permitted by recent versions of the API
 132:    * specification.  Originally it seems this method returned a new instance of 
 133:    * {@link MetalRolloverListener}, but this is now redundant.
 134:    * 
 135:    * @return <code>null</code>.
 136:    */
 137:   protected PropertyChangeListener createRolloverListener()
 138:   {
 139:     return null;
 140:   }
 141:   
 142:   /**
 143:    * Returns <code>null</code> as permitted by recent versions of the API
 144:    * specification.  Originally it seems this method returned a new instance of 
 145:    * {@link MetalContainerListener}, but this is now redundant.
 146:    * 
 147:    * @return <code>null</code>.
 148:    */
 149:   protected ContainerListener createContainerListener()
 150:   {
 151:     return null;
 152:   }
 153:   
 154:   /**
 155:    * Returns a border with no rollover effect for buttons in the tool bar.
 156:    * 
 157:    * @return A border.
 158:    * 
 159:    * @see MetalBorders#getToolbarButtonBorder()
 160:    */
 161:   protected Border createNonRolloverBorder()
 162:   {
 163:     return MetalBorders.getToolbarButtonBorder();   
 164:   }
 165:   
 166:   /**
 167:    * Sets the offset for the window used for dragging the toolbar.
 168:    * It is set as long as the window is not null (it has been installed).
 169:    */
 170:   protected void setDragOffset(Point p)
 171:   {
 172:     if (dragWindow != null)
 173:       dragWindow.setOffset(p);
 174:   }
 175:   
 176:   /** 
 177:    * Creates and returns an instance of MetalDockingListener.
 178:    * 
 179:    * @return an instance of MetalDockingListener.
 180:    */
 181:   protected MouseInputListener createDockingListener()
 182:   {
 183:     return new MetalDockingListener(toolBar);
 184:   }
 185:   
 186:   /**
 187:    * This is the MouseHandler class that allows the user to drag the JToolBar
 188:    * in and out of the parent and dock it if it can.
 189:    */
 190:   protected class MetalDockingListener extends BasicToolBarUI.DockingListener
 191:   {    
 192:     /**
 193:      * Creates a new DockingListener object.
 194:      *
 195:      * @param t The JToolBar this DockingListener is being used for.
 196:      */
 197:     public MetalDockingListener(JToolBar t)
 198:     {
 199:       super(t);
 200:     }
 201:     
 202:     /**
 203:      * This method is called when the mouse is pressed in the JToolBar. If the
 204:      * press doesn't occur in a place where it causes the JToolBar to be
 205:      * dragged, it returns. Otherwise, it starts a drag session.
 206:      *
 207:      * @param e The MouseEvent.
 208:      */
 209:     public void mousePressed(MouseEvent e)
 210:     {
 211:       super.mousePressed(e);
 212:       setDragOffset(new Point(e.getX(), e.getY()));
 213:     }
 214:     
 215:     /**
 216:      * This method is called when the mouse is dragged. It delegates the drag
 217:      * painting to the dragTo method.
 218:      *
 219:      * @param e The MouseEvent.
 220:      */
 221:     public void mouseDragged(MouseEvent e)
 222:     {
 223:       // Does not do anything differently than dragging 
 224:       // BasicToolBarUI.DockingListener
 225:       super.mouseDragged(e);
 226:     }
 227:   }
 228: }