Dead
[official-gcc.git] / gomp-20050608-branch / libjava / classpath / javax / swing / plaf / metal / MetalSplitPaneDivider.java
blob34a964cb339187f8ce1e6aa2b2341fd788b9a76d
1 /* MetalSplitPaneDivider.java
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)
9 any later version.
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
19 02110-1301 USA.
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.
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. */
38 package javax.swing.plaf.metal;
40 import java.awt.Color;
41 import java.awt.Component;
42 import java.awt.Container;
43 import java.awt.Dimension;
44 import java.awt.Graphics;
45 import java.awt.LayoutManager;
46 import java.awt.Point;
48 import javax.swing.JSplitPane;
49 import javax.swing.SwingConstants;
50 import javax.swing.plaf.basic.BasicArrowButton;
51 import javax.swing.plaf.basic.BasicSplitPaneDivider;
53 /**
54 * The divider that is used by the MetalSplitPaneUI.
56 * @author Roman Kennke (roman@kennke.org)
59 class MetalSplitPaneDivider extends BasicSplitPaneDivider
61 /** The dark color in the pattern. */
62 Color dark;
64 /** The light color in the pattern. */
65 Color light;
67 /** The JSplitPane the divider is on. */
68 JSplitPane splitPane;
70 /** The split pane orientation. */
71 int orientation;
73 /**
74 * Creates a new instance of MetalSplitPaneDivider.
76 * @param ui the <code>MetalSplitPaneUI</code> that uses this divider
78 public MetalSplitPaneDivider(MetalSplitPaneUI ui, Color light, Color dark)
80 super(ui);
81 setLayout(new MetalDividerLayout());
82 this.splitPane = super.splitPane;
83 this.orientation = super.orientation;
84 this.light = light;
85 this.dark = dark;
88 /**
89 * Paints the divider.
91 * @param g the <code>Graphics</code> context to use for painting
93 public void paint(Graphics g)
95 Dimension s = getSize();
96 MetalUtils.fillMetalPattern(splitPane, g, 2, 2, s.width - 4, s.height - 4,
97 light, dark);
98 if (splitPane.isOneTouchExpandable())
100 ((BasicArrowButton) rightButton).paint(g);
101 ((BasicArrowButton) leftButton).paint(g);
106 * This helper class acts as the Layout Manager for the divider.
108 public class MetalDividerLayout implements LayoutManager
110 /** The right button. */
111 BasicArrowButton rb;
113 /** The left button. */
114 BasicArrowButton lb;
117 * Creates a new DividerLayout object.
119 public MetalDividerLayout()
121 // Nothing to do here
125 * This method is called when a Component is added.
127 * @param string The constraints string.
128 * @param c The Component to add.
130 public void addLayoutComponent(String string, Component c)
132 // Nothing to do here, constraints are set depending on
133 // orientation in layoutContainer
137 * This method is called to lay out the container.
139 * @param c The container to lay out.
141 public void layoutContainer(Container c)
143 // The only components we care about setting up are the
144 // one touch buttons.
145 if (splitPane.isOneTouchExpandable())
147 if (c.getComponentCount() == 2)
149 Component c1 = c.getComponent(0);
150 Component c2 = c.getComponent(1);
151 if ((c1 instanceof BasicArrowButton)
152 && (c2 instanceof BasicArrowButton))
154 lb = ((BasicArrowButton) c1);
155 rb = ((BasicArrowButton) c2);
158 if (rb != null && lb != null)
160 Point p = getLocation();
161 lb.setSize(lb.getPreferredSize());
162 rb.setSize(rb.getPreferredSize());
163 lb.setLocation(p.x, p.y);
165 if (orientation == JSplitPane.HORIZONTAL_SPLIT)
167 rb.setDirection(SwingConstants.EAST);
168 lb.setDirection(SwingConstants.WEST);
169 rb.setLocation(p.x, p.y + lb.getHeight());
171 else
173 rb.setDirection(SwingConstants.SOUTH);
174 lb.setDirection(SwingConstants.NORTH);
175 rb.setLocation(p.x + lb.getWidth(), p.y);
182 * This method returns the minimum layout size.
184 * @param c The container to calculate for.
186 * @return The minimum layout size.
188 public Dimension minimumLayoutSize(Container c)
190 return preferredLayoutSize(c);
194 * This method returns the preferred layout size.
196 * @param c The container to calculate for.
198 * @return The preferred layout size.
200 public Dimension preferredLayoutSize(Container c)
202 int dividerSize = getDividerSize();
203 return new Dimension(dividerSize, dividerSize);
207 * This method is called when a component is removed.
209 * @param c The component to remove.
211 public void removeLayoutComponent(Component c)
213 // Nothing to do here. If buttons are removed
214 // they will not be layed out when layoutContainer is
215 // called.