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