2 Copyright (C) 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
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)
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.
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
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
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. */
39 package javax.swing.plaf.metal;
41 import java.awt.Point;
42 import java.awt.event.ContainerListener;
43 import java.awt.event.MouseEvent;
45 import java.beans.PropertyChangeListener;
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;
55 * A UI delegate for the {@link JToolBar} component.
57 public class MetalToolBarUI extends BasicToolBarUI
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.
65 * @see MetalToolBarUI#createContainerListener()
67 protected class MetalContainerListener
68 extends BasicToolBarUI.ToolBarContListener
71 * Creates a new instance.
73 protected MetalContainerListener()
75 // Nothing to do here.
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
84 * @see MetalToolBarUI#createRolloverListener()
86 protected class MetalRolloverListener
87 extends BasicToolBarUI.PropertyListener
90 * Creates a new instance.
92 protected MetalRolloverListener()
94 // Nothing to do here.
99 * The container listener (an implementation specific field, according to the
100 * spec, and not used in GNU Classpath).
102 protected ContainerListener contListener;
105 * The rollover listener (an implementation specific field, according to the
106 * spec, and not used in GNU Classpath).
108 protected PropertyChangeListener rolloverListener;
111 * Creates a new instance of this UI delegate.
113 public MetalToolBarUI()
119 * Returns a new instance of <code>MetalToolBarUI</code>.
121 * @param component the component for which we return an UI instance
123 * @return A new instance of <code>MetalToolBarUI</code>.
125 public static ComponentUI createUI(JComponent component)
127 return new MetalToolBarUI();
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.
135 * @return <code>null</code>.
137 protected PropertyChangeListener createRolloverListener()
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.
147 * @return <code>null</code>.
149 protected ContainerListener createContainerListener()
155 * Returns a border with no rollover effect for buttons in the tool bar.
159 * @see MetalBorders#getToolbarButtonBorder()
161 protected Border createNonRolloverBorder()
163 return MetalBorders.getToolbarButtonBorder();
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).
170 protected void setDragOffset(Point p)
172 if (dragWindow != null)
173 dragWindow.setOffset(p);
177 * Creates and returns an instance of MetalDockingListener.
179 * @return an instance of MetalDockingListener.
181 protected MouseInputListener createDockingListener()
183 return new MetalDockingListener(toolBar);
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.
190 protected class MetalDockingListener extends BasicToolBarUI.DockingListener
193 * Creates a new DockingListener object.
195 * @param t The JToolBar this DockingListener is being used for.
197 public MetalDockingListener(JToolBar t)
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.
207 * @param e The MouseEvent.
209 public void mousePressed(MouseEvent e)
211 super.mousePressed(e);
212 setDragOffset(new Point(e.getX(), e.getY()));
216 * This method is called when the mouse is dragged. It delegates the drag
217 * painting to the dragTo method.
219 * @param e The MouseEvent.
221 public void mouseDragged(MouseEvent e)
223 // Does not do anything differently than dragging
224 // BasicToolBarUI.DockingListener
225 super.mouseDragged(e);