Dead
[official-gcc.git] / gomp-20050608-branch / libjava / classpath / javax / swing / plaf / basic / BasicSeparatorUI.java
blob97caa3af7bd3eaee76ee18ff6fd1189c54b6cd16
1 /* BasicSeparatorUI.java --
2 Copyright (C) 2004 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. */
39 package javax.swing.plaf.basic;
41 import java.awt.Color;
42 import java.awt.Dimension;
43 import java.awt.Graphics;
44 import java.awt.Rectangle;
46 import javax.swing.JComponent;
47 import javax.swing.JSeparator;
48 import javax.swing.SwingUtilities;
49 import javax.swing.UIManager;
50 import javax.swing.plaf.ComponentUI;
51 import javax.swing.plaf.SeparatorUI;
53 /**
54 * The Basic Look and Feel UI delegate for JSeparator.
56 public class BasicSeparatorUI extends SeparatorUI
58 /** The shadow color. */
59 protected Color shadow;
61 /** The highlight color. */
62 protected Color highlight;
64 /**
65 * Creates a new UI delegate for the given JComponent.
67 * @param c The JComponent to create a delegate for.
69 * @return A new BasicSeparatorUI.
71 public static ComponentUI createUI(JComponent c)
73 return new BasicSeparatorUI();
76 /**
77 * This method installs the UI for the given JComponent.
78 * This can include installing defaults, listeners, and
79 * initializing any instance data.
81 * @param c The JComponent that is having this UI installed.
83 public void installUI(JComponent c)
85 super.installUI(c);
87 if (c instanceof JSeparator)
89 JSeparator s = (JSeparator) c;
91 installDefaults(s);
92 installListeners(s);
96 /**
97 * Uninstalls the UI for the given JComponent. This
98 * method reverses what was done when installing
99 * the UI on the JComponent.
101 * @param c The JComponent that is having this UI uninstalled.
103 public void uninstallUI(JComponent c)
105 if (c instanceof JSeparator)
107 JSeparator s = (JSeparator) c;
109 uninstallListeners(s);
110 uninstallDefaults(s);
115 * This method installs the defaults that are given by
116 * the Basic Look and Feel.
118 * @param s The JSeparator that is being installed.
120 protected void installDefaults(JSeparator s)
122 shadow = UIManager.getColor("Separator.shadow");
123 highlight = UIManager.getColor("Separator.highlight");
124 s.setOpaque(false);
128 * This method removes the defaults that were given
129 * by the Basic Look and Feel.
131 * @param s The JSeparator that is being uninstalled.
133 protected void uninstallDefaults(JSeparator s)
135 shadow = null;
136 highlight = null;
140 * This method installs any listeners that need
141 * to be attached to the JSeparator or any of its
142 * components.
144 * @param s The JSeparator that is being installed.
146 protected void installListeners(JSeparator s)
148 // Separators don't receive events.
152 * This method uninstalls any listeners that
153 * were installed during the install UI process.
155 * @param s The JSeparator that is being uninstalled.
157 protected void uninstallListeners(JSeparator s)
159 // Separators don't receive events.
163 * The separator is made of two lines. The top line will be
164 * the shadow color (or left line if it's vertical). The bottom
165 * or right line will be the highlight color. The two lines will
166 * be centered inside the bounds box. If the separator is horizontal,
167 * then it will be vertically centered, or if it's vertical, it will
168 * be horizontally centered.
170 * @param g The Graphics object to paint with
171 * @param c The JComponent to paint.
173 public void paint(Graphics g, JComponent c)
175 Rectangle r = new Rectangle();
176 SwingUtilities.calculateInnerArea(c, r);
177 Color saved = g.getColor();
179 JSeparator s;
180 if (c instanceof JSeparator)
181 s = (JSeparator) c;
182 else
183 return;
185 if (s.getOrientation() == JSeparator.HORIZONTAL)
187 int midAB = r.height / 2;
188 g.setColor(shadow);
189 g.drawLine(r.x, r.y + midAB - 1, r.x + r.width, r.y + midAB - 1);
191 g.setColor(highlight);
192 g.fillRect(r.x, r.y + midAB, r.x + r.width, r.y + midAB);
194 else
196 int midAD = r.height / 2 + r.y;
197 g.setColor(shadow);
198 g.drawLine(r.x, r.y, r.x, r.y + r.height);
200 g.setColor(highlight);
201 g.fillRect(r.x + midAD, r.y + r.height, r.x + midAD, r.y + r.height);
203 g.setColor(saved);
207 * This method returns the preferred size of the
208 * JComponent.
210 * @param c The JComponent to measure.
212 * @return The preferred size.
214 public Dimension getPreferredSize(JComponent c)
216 Dimension pref = new Dimension(2, 0);
217 if (c instanceof JSeparator)
219 JSeparator s = (JSeparator) c;
220 if (s.getOrientation() == JSeparator.HORIZONTAL)
221 pref = new Dimension(0, 2);
223 return pref;
227 * This method returns the minimum size of the
228 * JComponent.
230 * @param c The JComponent to measure.
232 * @return The minimum size.
234 public Dimension getMinimumSize(JComponent c)
236 return new Dimension(0, 0);
240 * This method returns the maximum size of the
241 * JComponent.
243 * @param c The JComponent to measure.
245 * @return The maximum size.
247 public Dimension getMaximumSize(JComponent c)
249 return new Dimension(Short.MAX_VALUE,
250 Short.MAX_VALUE);