1. /*
  2. * @(#)MetalSeparatorUI.java 1.11 01/11/29
  3. *
  4. * Copyright 2002 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 appropriate
  23. * for short term storage or RMI between applications running the same
  24. * version of Swing. A future release of Swing will provide support for
  25. * long term persistence.
  26. *
  27. * @version 1.11 11/29/01
  28. * @author Jeff Shapiro
  29. */
  30. public class MetalSeparatorUI extends BasicSeparatorUI
  31. {
  32. public static ComponentUI createUI( JComponent c )
  33. {
  34. return new MetalSeparatorUI();
  35. }
  36. protected void installDefaults( JSeparator s )
  37. {
  38. LookAndFeel.installColors( s, "Separator.background", "Separator.foreground" );
  39. }
  40. public void paint( Graphics g, JComponent c )
  41. {
  42. Dimension s = c.getSize();
  43. if ( ((JSeparator)c).getOrientation() == JSeparator.VERTICAL )
  44. {
  45. g.setColor( c.getForeground() );
  46. g.drawLine( 0, 0, 0, s.height );
  47. g.setColor( c.getBackground() );
  48. g.drawLine( 1, 0, 1, s.height );
  49. }
  50. else // HORIZONTAL
  51. {
  52. g.setColor( c.getForeground() );
  53. g.drawLine( 0, 0, s.width, 0 );
  54. g.setColor( c.getBackground() );
  55. g.drawLine( 0, 1, s.width, 1 );
  56. }
  57. }
  58. public Dimension getPreferredSize( JComponent c )
  59. {
  60. if ( ((JSeparator)c).getOrientation() == JSeparator.VERTICAL )
  61. return new Dimension( 2, 0 );
  62. else
  63. return new Dimension( 0, 2 );
  64. }
  65. }