1. /*
  2. * @(#)MetalSeparatorUI.java 1.15 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.swing.plaf.metal;
  8. import javax.swing.*;
  9. import java.awt.Color;
  10. import java.awt.Dimension;
  11. import java.awt.Graphics;
  12. import java.awt.Insets;
  13. import java.awt.Rectangle;
  14. import javax.swing.plaf.*;
  15. import javax.swing.plaf.basic.BasicSeparatorUI;
  16. /**
  17. * A Metal L&F implementation of SeparatorUI. This implementation
  18. * is a "combined" view/controller.
  19. * <p>
  20. * <strong>Warning:</strong>
  21. * Serialized objects of this class will not be compatible with
  22. * future Swing releases. The current serialization support is
  23. * appropriate for short term storage or RMI between applications running
  24. * the same version of Swing. As of 1.4, support for long term storage
  25. * of all JavaBeans<sup><font size="-2">TM</font></sup>
  26. * has been added to the <code>java.beans</code> package.
  27. * Please see {@link java.beans.XMLEncoder}.
  28. *
  29. * @version 1.15 01/23/03
  30. * @author Jeff Shapiro
  31. */
  32. public class MetalSeparatorUI extends BasicSeparatorUI
  33. {
  34. public static ComponentUI createUI( JComponent c )
  35. {
  36. return new MetalSeparatorUI();
  37. }
  38. protected void installDefaults( JSeparator s )
  39. {
  40. LookAndFeel.installColors( s, "Separator.background", "Separator.foreground" );
  41. }
  42. public void paint( Graphics g, JComponent c )
  43. {
  44. Dimension s = c.getSize();
  45. if ( ((JSeparator)c).getOrientation() == JSeparator.VERTICAL )
  46. {
  47. g.setColor( c.getForeground() );
  48. g.drawLine( 0, 0, 0, s.height );
  49. g.setColor( c.getBackground() );
  50. g.drawLine( 1, 0, 1, s.height );
  51. }
  52. else // HORIZONTAL
  53. {
  54. g.setColor( c.getForeground() );
  55. g.drawLine( 0, 0, s.width, 0 );
  56. g.setColor( c.getBackground() );
  57. g.drawLine( 0, 1, s.width, 1 );
  58. }
  59. }
  60. public Dimension getPreferredSize( JComponent c )
  61. {
  62. if ( ((JSeparator)c).getOrientation() == JSeparator.VERTICAL )
  63. return new Dimension( 2, 0 );
  64. else
  65. return new Dimension( 0, 2 );
  66. }
  67. }