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