1. /*
  2. * @(#)BluecurveStyle.java 1.5 03/12/19
  3. *
  4. * Copyright 2004 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 javax.swing.plaf.synth.*;
  9. import java.awt.*;
  10. import java.util.*;
  11. import javax.swing.*;
  12. import javax.swing.plaf.*;
  13. import sun.swing.plaf.synth.*;
  14. /**
  15. * @version 1.5, 12/19/03
  16. * @author Scott Violet
  17. */
  18. class BluecurveStyle extends GTKStyle implements GTKConstants {
  19. /**
  20. * There should only ever be one pixmap engine.
  21. */
  22. private static final GTKEngine BLUECURVE_ENGINE = new BluecurveEngine();
  23. private static final Color DEFAULT_COLOR = new ColorUIResource(0, 0, 0);
  24. /**
  25. * Colors specific to blue curve. These don't appear to be specific
  26. * to a state, hence they are stored here.
  27. */
  28. private Color[] blueColors;
  29. /**
  30. * Creates a duplicate of the passed in style.
  31. */
  32. public BluecurveStyle(DefaultSynthStyle style) {
  33. super(style);
  34. }
  35. /**
  36. * Creates a PixmapStyle from the passed in arguments.
  37. */
  38. public BluecurveStyle(StateInfo[] states,
  39. CircularIdentityList classSpecificValues,
  40. Font font,
  41. int xThickness, int yThickness,
  42. GTKStockIconInfo[] icons) {
  43. super(states, classSpecificValues, font, xThickness, yThickness,icons);
  44. }
  45. /**
  46. * Adds the state of this PixmapStyle to that of <code>s</code>
  47. * returning a combined SynthStyle.
  48. */
  49. public DefaultSynthStyle addTo(DefaultSynthStyle s) {
  50. if (!(s instanceof BluecurveStyle)) {
  51. s = new BluecurveStyle(s);
  52. }
  53. BluecurveStyle style = (BluecurveStyle)super.addTo(s);
  54. return style;
  55. }
  56. /**
  57. * Creates a copy of the reciever and returns it.
  58. */
  59. public Object clone() {
  60. return super.clone();
  61. }
  62. /**
  63. * Returns a GTKEngine to use for rendering.
  64. */
  65. public GTKEngine getEngine(SynthContext context) {
  66. return BLUECURVE_ENGINE;
  67. }
  68. Color getDefaultColor(JComponent c, Region id, int state,
  69. ColorType type) {
  70. int colorID = type.getID();
  71. if (colorID >= BluecurveColorType.MIN_ID &&
  72. colorID <= BluecurveColorType.MAX_ID) {
  73. if (blueColors == null) {
  74. int min = BluecurveColorType.MIN_ID;
  75. Color base = getGTKColor(c, id, SynthConstants.SELECTED,
  76. GTKColorType.TEXT_BACKGROUND);
  77. Color bg = getGTKColor(c, id, SynthConstants.ENABLED,
  78. GTKColorType.BACKGROUND);
  79. blueColors = new Color[BluecurveColorType.MAX_ID - min + 1];
  80. blueColors[BluecurveColorType.OUTER.getID() - min] =
  81. GTKColorType.adjustColor(base, 1.0f, .72f, .7f);
  82. blueColors[BluecurveColorType.INNER_LEFT.getID() - min] =
  83. GTKColorType.adjustColor(base, 1.0f, 1.63f, 1.53f);
  84. blueColors[BluecurveColorType.TOP_GRADIENT.getID() - min] =
  85. GTKColorType.adjustColor(base, 1.0f, .93f, .88f);
  86. blueColors[BluecurveColorType.BOTTOM_GRADIENT.getID() - min] =
  87. GTKColorType.adjustColor(base, 1f, 1.16f,1.13f);
  88. blueColors[BluecurveColorType.INNER_RIGHT.getID() - min] =
  89. GTKColorType.adjustColor(base, 1.0f, 1.06f, 1.08f);
  90. blueColors[BluecurveColorType.OUTER2.getID() - min] =
  91. GTKColorType.adjustColor(bg, 1.0f, .67f, .67f);
  92. blueColors[BluecurveColorType.INNER_RIGHT2.getID() - min] =
  93. GTKColorType.adjustColor(bg, 1.0f, .92f, .92f);
  94. blueColors[BluecurveColorType.OUTER3.getID() - min] =
  95. GTKColorType.adjustColor(bg, 1.0f, .4f, .4f);
  96. blueColors[BluecurveColorType.OUTER4.getID() - min] =
  97. GTKColorType.adjustColor(bg, 1.0f, .84f, .84f);
  98. blueColors[BluecurveColorType.OUTER5.getID() - min] =
  99. GTKColorType.adjustColor(bg, 1.0f, .245f, .192f);
  100. }
  101. return blueColors[colorID - BluecurveColorType.MIN_ID];
  102. }
  103. return super.getDefaultColor(c, id, state, type);
  104. }
  105. public String toString() {
  106. StringBuffer buf = new StringBuffer(super.toString());
  107. if (blueColors != null) {
  108. buf.append("\t" + BluecurveColorType.OUTER + "=" +
  109. blueColors[BluecurveColorType.OUTER.getID() -
  110. BluecurveColorType.MIN_ID] + "\n");
  111. buf.append("\t" + BluecurveColorType.INNER_LEFT + "=" +
  112. blueColors[BluecurveColorType.INNER_LEFT.getID() -
  113. BluecurveColorType.MIN_ID] + "\n");
  114. buf.append("\t" + BluecurveColorType.INNER_RIGHT + "=" +
  115. blueColors[BluecurveColorType.INNER_RIGHT.getID() -
  116. BluecurveColorType.MIN_ID] + "\n");
  117. buf.append("\t" + BluecurveColorType.TOP_GRADIENT + "=" +
  118. blueColors[BluecurveColorType.TOP_GRADIENT.getID() -
  119. BluecurveColorType.MIN_ID] + "\n");
  120. buf.append("\t" + BluecurveColorType.BOTTOM_GRADIENT + "=" +
  121. blueColors[BluecurveColorType.BOTTOM_GRADIENT.getID() -
  122. BluecurveColorType.MIN_ID] + "\n");
  123. buf.append("\t" + BluecurveColorType.OUTER2 + "=" +
  124. blueColors[BluecurveColorType.OUTER2.getID() -
  125. BluecurveColorType.MIN_ID] + "\n");
  126. buf.append("\t" + BluecurveColorType.INNER_RIGHT2 + "=" +
  127. blueColors[BluecurveColorType.INNER_RIGHT2.getID() -
  128. BluecurveColorType.MIN_ID] + "\n");
  129. buf.append("\t" + BluecurveColorType.OUTER3 + "=" +
  130. blueColors[BluecurveColorType.OUTER3.getID() -
  131. BluecurveColorType.MIN_ID] + "\n");
  132. buf.append("\t" + BluecurveColorType.OUTER4 + "=" +
  133. blueColors[BluecurveColorType.OUTER4.getID() -
  134. BluecurveColorType.MIN_ID] + "\n");
  135. buf.append("\t" + BluecurveColorType.OUTER5 + "=" +
  136. blueColors[BluecurveColorType.OUTER5.getID() -
  137. BluecurveColorType.MIN_ID] + "\n");
  138. }
  139. return buf.toString();
  140. }
  141. }