1. /*
  2. * @(#)SynthSeparatorUI.java 1.11 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.gtk;
  8. import java.beans.*;
  9. import javax.swing.*;
  10. import java.awt.Dimension;
  11. import java.awt.Graphics;
  12. import java.awt.Insets;
  13. import javax.swing.plaf.ComponentUI;
  14. import javax.swing.plaf.SeparatorUI;
  15. import javax.swing.plaf.UIResource;
  16. /**
  17. * A Synth L&F implementation of SeparatorUI. This implementation
  18. * is a "combined" view/controller.
  19. *
  20. * @version 1.11 01/23/03 (based on revision 1.21 of BasicSeparatorUI)
  21. * @author Shannon Hickey
  22. */
  23. class SynthSeparatorUI extends SeparatorUI implements
  24. PropertyChangeListener, SynthUI {
  25. private SynthStyle style;
  26. public static ComponentUI createUI(JComponent c) {
  27. return new SynthSeparatorUI();
  28. }
  29. public void installUI(JComponent c) {
  30. installDefaults((JSeparator)c);
  31. installListeners((JSeparator)c);
  32. }
  33. public void uninstallUI(JComponent c) {
  34. uninstallDefaults((JSeparator)c);
  35. uninstallListeners((JSeparator)c);
  36. }
  37. public void installDefaults(JSeparator c) {
  38. fetchStyle(c);
  39. }
  40. private void fetchStyle(JSeparator sep) {
  41. SynthContext context = getContext(sep, ENABLED);
  42. SynthStyle oldStyle = style;
  43. style = SynthLookAndFeel.updateStyle(context, this);
  44. if (style != oldStyle) {
  45. if (sep instanceof JToolBar.Separator) {
  46. Dimension size = ((JToolBar.Separator)sep).getSeparatorSize();
  47. if (size == null || size instanceof UIResource) {
  48. size = (Dimension)style.get(
  49. context, "ToolBar.separatorSize");
  50. ((JToolBar.Separator)sep).setSeparatorSize(size);
  51. }
  52. }
  53. }
  54. context.dispose();
  55. }
  56. public void uninstallDefaults(JSeparator c) {
  57. SynthContext context = getContext(c, ENABLED);
  58. style.uninstallDefaults(context);
  59. context.dispose();
  60. style = null;
  61. }
  62. public void installListeners(JSeparator c) {
  63. c.addPropertyChangeListener(this);
  64. }
  65. public void uninstallListeners(JSeparator c) {
  66. c.removePropertyChangeListener(this);
  67. }
  68. public void update(Graphics g, JComponent c) {
  69. SynthContext context = getContext(c);
  70. SynthLookAndFeel.update(context, g);
  71. paint(context, g);
  72. context.dispose();
  73. }
  74. public void paint(Graphics g, JComponent c) {
  75. SynthContext context = getContext(c);
  76. paint(context, g);
  77. context.dispose();
  78. }
  79. protected void paint(SynthContext context, Graphics g) {
  80. SynthLookAndFeel.paintForeground(context, g, null);
  81. }
  82. public Dimension getPreferredSize(JComponent c) {
  83. SynthContext context = getContext(c);
  84. int thickness = ((Integer)context.getStyle().get(
  85. context, "Separator.thickness")).intValue();
  86. Insets insets = c.getInsets();
  87. Dimension size;
  88. if (((JSeparator)c).getOrientation() == JSeparator.VERTICAL) {
  89. size = new Dimension(insets.left + insets.right + thickness,
  90. insets.top + insets.bottom);
  91. } else {
  92. size = new Dimension(insets.left + insets.right,
  93. insets.top + insets.bottom + thickness);
  94. }
  95. context.dispose();
  96. return size;
  97. }
  98. public Dimension getMinimumSize(JComponent c) {
  99. return getPreferredSize(c);
  100. }
  101. public Dimension getMaximumSize(JComponent c) {
  102. return new Dimension(Short.MAX_VALUE, Short.MAX_VALUE);
  103. }
  104. public SynthContext getContext(JComponent c) {
  105. return getContext(c, getComponentState(c));
  106. }
  107. private SynthContext getContext(JComponent c, int state) {
  108. return SynthContext.getContext(SynthContext.class, c,
  109. SynthLookAndFeel.getRegion(c), style, state);
  110. }
  111. private Region getRegion(JComponent c) {
  112. return SynthLookAndFeel.getRegion(c);
  113. }
  114. private int getComponentState(JComponent c) {
  115. return SynthLookAndFeel.getComponentState(c);
  116. }
  117. public void propertyChange(PropertyChangeEvent evt) {
  118. if (SynthLookAndFeel.shouldUpdateStyle(evt)) {
  119. fetchStyle((JSeparator)evt.getSource());
  120. }
  121. }
  122. }