1. /*
  2. * @(#)WindowsToolBarSeparatorUI.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 com.sun.java.swing.plaf.windows;
  8. import java.awt.*;
  9. import javax.swing.plaf.ComponentUI;
  10. import javax.swing.plaf.basic.*;
  11. import javax.swing.*;
  12. /**
  13. * Draws Windows toolbar separators.
  14. * <p>
  15. *
  16. * @version 1.15 01/23/03
  17. * @author Mark Davidson
  18. */
  19. public class WindowsToolBarSeparatorUI extends BasicToolBarSeparatorUI {
  20. public static ComponentUI createUI( JComponent c ) {
  21. return new WindowsToolBarSeparatorUI();
  22. }
  23. public Dimension getPreferredSize(JComponent c) {
  24. Dimension size = ((JToolBar.Separator)c).getSeparatorSize();
  25. if (size != null) {
  26. size = size.getSize();
  27. } else {
  28. size = new Dimension(6, 6);
  29. XPStyle xp = XPStyle.getXP();
  30. if (xp != null) {
  31. boolean vertical = ((JSeparator)c).getOrientation() == SwingConstants.VERTICAL;
  32. String category = vertical ? "toolbar.separator" : "toolbar.separatorvert";
  33. XPStyle.Skin skin = xp.getSkin(category);
  34. size.width = skin.getWidth();
  35. size.height = skin.getHeight();
  36. }
  37. if (((JSeparator)c).getOrientation() == SwingConstants.VERTICAL) {
  38. size.height = 0;
  39. } else {
  40. size.width = 0;
  41. }
  42. }
  43. return size;
  44. }
  45. public Dimension getMaximumSize(JComponent c) {
  46. Dimension pref = getPreferredSize(c);
  47. if (((JSeparator)c).getOrientation() == SwingConstants.VERTICAL) {
  48. return new Dimension(pref.width, Short.MAX_VALUE);
  49. } else {
  50. return new Dimension(Short.MAX_VALUE, pref.height);
  51. }
  52. }
  53. public void paint( Graphics g, JComponent c ) {
  54. boolean vertical = ((JSeparator)c).getOrientation() == SwingConstants.VERTICAL;
  55. Dimension size = c.getSize();
  56. XPStyle xp = XPStyle.getXP();
  57. if (xp != null) {
  58. String category = vertical ? "toolbar.separator" : "toolbar.separatorvert";
  59. XPStyle.Skin skin = xp.getSkin(category);
  60. int dx = vertical ? (size.width - skin.getWidth()) / 2 : 0;
  61. int dy = vertical ? 0 : (size.height - skin.getHeight()) / 2;
  62. int dw = vertical ? skin.getWidth() : size.width;
  63. int dh = vertical ? size.height : skin.getHeight();
  64. skin.paintSkin(g, dx, dy, dw, dh, 0);
  65. } else {
  66. Color temp = g.getColor();
  67. UIDefaults table = UIManager.getLookAndFeelDefaults();
  68. Color shadow = table.getColor("ToolBar.shadow");
  69. Color highlight = table.getColor("ToolBar.highlight");
  70. if (vertical) {
  71. int x = (size.width / 2) - 1;
  72. g.setColor(shadow);
  73. g.drawLine(x, 2, x, size.height - 2);
  74. g.setColor(highlight);
  75. g.drawLine(x + 1, 2, x + 1, size.height - 2);
  76. } else {
  77. int y = (size.height / 2) - 1;
  78. g.setColor(shadow);
  79. g.drawLine(2, y, size.width - 2, y);
  80. g.setColor(highlight);
  81. g.drawLine(2, y + 1, size.width - 2, y + 1);
  82. }
  83. g.setColor(temp);
  84. }
  85. }
  86. }