1. /*
  2. * @(#)SynthBorder.java 1.9 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.awt.*;
  9. import javax.swing.*;
  10. import javax.swing.border.*;
  11. import javax.swing.plaf.UIResource;
  12. /**
  13. * SynthBorder is a border that delegates to a Painter. The Insets
  14. * are determined at construction time.
  15. *
  16. * @version 1.9, 01/23/03
  17. * @author Scott Violet
  18. */
  19. class SynthBorder extends AbstractBorder implements UIResource {
  20. private SynthUI ui;
  21. private Insets insets;
  22. SynthBorder(SynthUI ui, Insets insets) {
  23. this.ui = ui;
  24. this.insets = insets;
  25. }
  26. SynthBorder(SynthUI ui) {
  27. this(ui, null);
  28. }
  29. public void paintBorder(Component c, Graphics g, int x, int y,
  30. int width, int height) {
  31. JComponent jc = (JComponent)c;
  32. SynthContext context = ui.getContext(jc);
  33. SynthStyle style = context.getStyle();
  34. if (style == null) {
  35. assert false: "SynthBorder is being used outside after the UI " +
  36. "has been uninstalled";
  37. return;
  38. }
  39. SynthPainter painter = style.getBorderPainter(context);
  40. if (painter != null) {
  41. painter.paint(context, "border", g, x, y, width, height);
  42. }
  43. context.dispose();
  44. }
  45. /**
  46. * This default implementation returns a new <code>Insets</code>
  47. * instance where the <code>top</code>, <code>left</code>,
  48. * <code>bottom</code>, and
  49. * <code>right</code> fields are set to <code>0</code>.
  50. * @param c the component for which this border insets value applies
  51. * @return the new <code>Insets</code> object initialized to 0
  52. */
  53. public Insets getBorderInsets(Component c) {
  54. return getBorderInsets(c, null);
  55. }
  56. /**
  57. * Reinitializes the insets parameter with this Border's current Insets.
  58. * @param c the component for which this border insets value applies
  59. * @param insets the object to be reinitialized
  60. * @return the <code>insets</code> object
  61. */
  62. public Insets getBorderInsets(Component c, Insets insets) {
  63. if (this.insets != null) {
  64. if (insets == null) {
  65. return new Insets(this.insets.top, this.insets.left,
  66. this.insets.bottom, this.insets.right);
  67. }
  68. insets.top = this.insets.top;
  69. insets.bottom = this.insets.bottom;
  70. insets.left = this.insets.left;
  71. insets.right = this.insets.left;
  72. return insets;
  73. }
  74. if (insets == null) {
  75. insets = new Insets(0, 0, 0, 0);
  76. }
  77. return insets;
  78. }
  79. /**
  80. * This default implementation returns false.
  81. * @return false
  82. */
  83. public boolean isBorderOpaque() {
  84. return false;
  85. }
  86. }