1. /*
  2. * @(#)BluecurveEngine.java 1.6 04/01/09
  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 javax.swing.*;
  11. import javax.swing.plaf.*;
  12. /**
  13. * A bluecurve like engine.
  14. *
  15. * @version 1.6, 01/09/04
  16. * @author Scott Violet
  17. */
  18. class BluecurveEngine extends GTKEngine {
  19. public void paintSlider(SynthContext context, Graphics g, int state,
  20. int shadowType, String info,
  21. int x, int y, int w, int h, int orientation) {
  22. Region region = context.getRegion();
  23. if (region == Region.SLIDER_THUMB) {
  24. BluecurveStyle style = (BluecurveStyle)context.getStyle();
  25. JComponent c = context.getComponent();
  26. paintBackground(context, g, state, style.getGTKColor(
  27. c, region, state, GTKColorType.BACKGROUND), x, y, w, h);
  28. g.setColor(style.getGTKColor(c, region, state,
  29. BluecurveColorType.OUTER3));
  30. g.drawLine(x + 2, y, x + w - 3, y);
  31. g.drawLine(x, y + 2, x, y + h - 3);
  32. g.drawLine(x + w - 1, y + 2, x + w - 1, y + h - 3);
  33. g.drawLine(x + 2, y + h - 1, x + w - 3, y + h - 1);
  34. g.fillRect(x + 1, y + 1, 1, 1);
  35. g.fillRect(x + w - 2, y + 1, 1, 1);
  36. g.fillRect(x + 1, y + h - 2, 1, 1);
  37. g.fillRect(x + w - 2, y + h - 2, 1, 1);
  38. g.setColor(style.getGTKColor(c, region, state,
  39. BluecurveColorType.WHITE));
  40. g.drawLine(x + 2, y + 1, x + w - 3, y + 1);
  41. g.drawLine(x + 1, y + 2, x + 1, y + h - 3);
  42. g.setColor(style.getGTKColor(c, region, state,
  43. BluecurveColorType.INNER_RIGHT2));
  44. g.drawLine(x + 2, y + h - 2, x + w - 3, y + h - 2);
  45. g.drawLine(x + w - 2, y + 2, x + w - 2, y + h - 3);
  46. g.drawLine(x, y + 1, x + 1, y);
  47. g.drawLine(x, y + h - 2, x + 1, y + h - 1);
  48. g.drawLine(x + w - 2, y + h - 1, x + w - 1, y + h - 2);
  49. g.drawLine(x + w - 2, y, x + w - 1, y + 1);
  50. if (((JSlider)c).getOrientation() == SwingConstants.HORIZONTAL &&
  51. w > 12) {
  52. paintHash(context, g, state, x + w / 2 - 5, y + h / 2 - 2, 3);
  53. paintHash(context, g, state, x + w / 2 - 3, y + h / 2 - 3, 6);
  54. paintHash(context, g, state, x + w / 2 +2, y + h / 2 - 1, 3);
  55. }
  56. else if (((JSlider)c).getOrientation() ==
  57. SwingConstants.VERTICAL && h > 12) {
  58. paintHash(context, g, state, x + w / 2 - 2, y + h / 2 - 5, 3);
  59. paintHash(context, g, state, x + w / 2 - 3, y + h / 2 - 3, 6);
  60. paintHash(context, g, state, x + w / 2 - 1, y + h / 2 + 2, 3);
  61. }
  62. }
  63. else {
  64. super.paintSlider(context, g, state, shadowType, info, x, y, w, h,
  65. orientation);
  66. if (context.getRegion() == Region.SCROLL_BAR_THUMB) {
  67. paintHashes(context, g, state, x, y, w, h, orientation, 3, 5);
  68. }
  69. }
  70. }
  71. private void paintHash(SynthContext context, Graphics g, int state,
  72. int x, int y, int size) {
  73. GTKStyle style = (GTKStyle)context.getStyle();
  74. g.setColor(style.getGTKColor(context.getComponent(),
  75. context.getRegion(), state,
  76. BluecurveColorType.OUTER2));
  77. g.drawLine(x, y + size, x + size, y);
  78. g.setColor(style.getGTKColor(context.getComponent(),
  79. context.getRegion(), state,
  80. GTKColorType.WHITE));
  81. g.drawLine(x + 1, y + size, x + size, y + 1);
  82. }
  83. private void paintHashes(SynthContext context, Graphics g, int state,
  84. int x, int y, int w, int h, int orientation,
  85. int count, int size) {
  86. // 3 diagonal lines 5x5
  87. GTKStyle style = (GTKStyle)context.getStyle();
  88. if (orientation == GTKConstants.HORIZONTAL) {
  89. if (w < size * count + 4) {
  90. return;
  91. }
  92. int x0 = x + (w - size * count) / 2;
  93. int y0 = y + (h - size) / 2;
  94. g.setColor(style.getGTKColor(context.getComponent(),
  95. context.getRegion(), state,
  96. BluecurveColorType.OUTER2));
  97. for (int counter = 0; counter < count; counter++) {
  98. g.drawLine(x0 + counter * size, y0 + size,
  99. x0 + (counter + 1) * size, y0);
  100. }
  101. g.setColor(style.getGTKColor(context.getComponent(),
  102. context.getRegion(), state,
  103. GTKColorType.WHITE));
  104. for (int counter = 0; counter < count; counter++) {
  105. g.drawLine(x0 + counter * size + 1, y0 + size,
  106. x0 + (counter + 1) * size, y0 + 1);
  107. }
  108. }
  109. else if (orientation == GTKConstants.VERTICAL) {
  110. if (h < size * count + 4) {
  111. return;
  112. }
  113. int x0 = x + (w - size) / 2;
  114. int y0 = y + (h - size * count) / 2;
  115. g.setColor(style.getGTKColor(context.getComponent(),
  116. context.getRegion(), state,
  117. BluecurveColorType.OUTER2));
  118. for (int counter = 0; counter < count; counter++) {
  119. g.drawLine(x0, y0 + (counter + 1) * size, x0 + size,
  120. y0 + (counter * size));
  121. }
  122. g.setColor(style.getGTKColor(context.getComponent(),
  123. context.getRegion(), state,
  124. GTKColorType.WHITE));
  125. for (int counter = 0; counter < count; counter++) {
  126. g.drawLine(x0 + 1, y0 + (counter + 1) * size, x0 + size,
  127. y0 + counter * size + 1);
  128. }
  129. }
  130. }
  131. public void paintBox(SynthContext context, Graphics g, int state,
  132. int shadowType, String info, int x, int y,
  133. int w, int h) {
  134. GTKStyle style = (GTKStyle)context.getStyle();
  135. Region region = context.getRegion();
  136. if (info != "trough" || region != Region.SLIDER_TRACK) {
  137. paintBackground(context, g, state,
  138. style.getGTKColor(context.getComponent(), region, state,
  139. GTKColorType.BACKGROUND), x, y, w, h);
  140. }
  141. paintShadow(context, g, state, shadowType, info, x, y, w, h);
  142. }
  143. public void paintShadow(SynthContext context, Graphics g, int state,
  144. int shadowType, String info, int x, int y,
  145. int w, int h) {
  146. if (info == "menubar") {
  147. // This isn't really dark, but not sure what color they're using
  148. // here
  149. g.setColor(((GTKStyle)context.getStyle()).getGTKColor(
  150. context.getComponent(), context.getRegion(), state,
  151. BluecurveColorType.OUTER4));
  152. g.drawLine(x, y + h - 1, x + w, y + h - 1);
  153. return;
  154. }
  155. if (info == "buttondefault") {
  156. // YES, this appears to be special cased.
  157. g.setColor(((GTKStyle)context.getStyle()).getGTKColor(
  158. context.getComponent(), context.getRegion(),
  159. state, GTKColorType.BLACK));
  160. g.drawRect(x, y, w - 1, h - 1);
  161. return;
  162. }
  163. BluecurveStyle style = (BluecurveStyle)context.getStyle();
  164. JComponent c = context.getComponent();
  165. Region region = context.getRegion();
  166. int xThickness = style.getXThickness();
  167. int yThickness = style.getYThickness();
  168. if (info == "trough") {
  169. // YES, this appears to be special cased.
  170. xThickness = yThickness = 1;
  171. if (region == Region.SLIDER_TRACK) {
  172. if (((JSlider)c).getOrientation() ==SwingConstants.HORIZONTAL){
  173. if (h > 5) {
  174. y = y + h / 2 - 2;
  175. h = 5;
  176. }
  177. }
  178. else if (w > 5) {
  179. x = x + w / 2 - 2;
  180. w = 5;
  181. }
  182. }
  183. }
  184. else if (info == "bar") {
  185. if (xThickness < 2) {
  186. x -= xThickness;
  187. y -= yThickness;
  188. w += xThickness + xThickness;
  189. h += yThickness + yThickness;
  190. xThickness = yThickness = 2;
  191. }
  192. }
  193. if (xThickness < 0 && yThickness < 0) {
  194. // nothing to paint.
  195. return;
  196. }
  197. Color upperLeft = null, innerLeft = null, bottomRight = null,
  198. innerRight = null;
  199. if (info == "menu" || (info == "trough" &&
  200. (region == Region.PROGRESS_BAR || region ==
  201. Region.SLIDER_TRACK)) || info == "entry") {
  202. if (info != "menu" && info != "entry") {
  203. g.setColor(style.getGTKColor(c, region, state,
  204. BluecurveColorType.OUTER4));
  205. g.fillRect(x, y, w, h);
  206. }
  207. upperLeft = bottomRight = style.getGTKColor(c, region, state,
  208. BluecurveColorType.OUTER2);
  209. if (shadowType == GTKConstants.SHADOW_OUT) {
  210. innerLeft = style.getGTKColor(c, region, state,
  211. BluecurveColorType.WHITE);
  212. innerRight = style.getGTKColor(c, region, state,
  213. BluecurveColorType.INNER_RIGHT2);
  214. }
  215. else {
  216. innerLeft = style.getGTKColor(c, region, state,
  217. BluecurveColorType.INNER_RIGHT2);
  218. innerRight = style.getGTKColor(c, region, state,
  219. BluecurveColorType.WHITE);
  220. }
  221. }
  222. else if (info != "menuitem" && info != "bar") {
  223. upperLeft = bottomRight = style.getGTKColor(c, region, state,
  224. BluecurveColorType.OUTER3);
  225. if (shadowType == GTKConstants.SHADOW_OUT) {
  226. innerLeft = style.getGTKColor(c, region, state,
  227. BluecurveColorType.WHITE);
  228. innerRight = style.getGTKColor(c, region, state,
  229. BluecurveColorType.INNER_RIGHT2);
  230. }
  231. else {
  232. innerLeft = style.getGTKColor(c, region, state,
  233. BluecurveColorType.INNER_RIGHT2);
  234. innerRight = style.getGTKColor(c, region, state,
  235. BluecurveColorType.WHITE);
  236. }
  237. }
  238. else {
  239. upperLeft = bottomRight = style.getGTKColor(c, region,
  240. SynthConstants.SELECTED, BluecurveColorType.OUTER);
  241. switch (shadowType) {
  242. case GTKConstants.SHADOW_OUT:
  243. innerLeft = style.getGTKColor(c, region,
  244. SynthConstants.SELECTED, BluecurveColorType.INNER_LEFT);
  245. innerRight = style.getGTKColor(c, region,
  246. SynthConstants.SELECTED, BluecurveColorType.INNER_RIGHT);
  247. break;
  248. case GTKConstants.SHADOW_IN:
  249. innerRight = style.getGTKColor(c, region,
  250. SynthConstants.SELECTED, BluecurveColorType.INNER_LEFT);
  251. innerLeft = style.getGTKColor(c, region,
  252. SynthConstants.SELECTED, BluecurveColorType.INNER_RIGHT);
  253. break;
  254. default:
  255. assert true : "Unknown shadow type!";
  256. }
  257. }
  258. _paintShadow(g, x, y, w, h, xThickness, yThickness, upperLeft,
  259. innerLeft, bottomRight, innerRight);
  260. if (info == "menuitem" || info == "bar") {
  261. // Draw the GradientPaint
  262. int gw = Math.min(2, xThickness);
  263. int gh = Math.min(2, yThickness);
  264. Color topColor = style.getGTKColor(c, region,
  265. SynthConstants.SELECTED,BluecurveColorType. TOP_GRADIENT);
  266. Color bottomColor = style.getGTKColor(c, region,
  267. SynthConstants.SELECTED,BluecurveColorType. BOTTOM_GRADIENT);
  268. GradientPaint paint = new GradientPaint((float)gw, (float)gh,
  269. topColor, (float)gw, (float)(h - gh - gh), bottomColor);
  270. g.translate(x, y);
  271. ((Graphics2D)g).setPaint(paint);
  272. g.fillRect(gw, gh, w - gw - gw, h - gh - gh);
  273. ((Graphics2D)g).setPaint(null);
  274. g.translate(-x, -y);
  275. }
  276. }
  277. public void paintArrow(SynthContext context, Graphics g, int state,
  278. int shadowType, int direction, String info,
  279. int x, int y, int w, int h) {
  280. // Draw the arrow
  281. int sizeW = w / 4 + 1;
  282. int sizeH = h / 4 + 1;
  283. int size = Math.max(2, Math.min(sizeW, sizeH));
  284. switch (direction) {
  285. case GTKConstants.ARROW_UP:
  286. x += w / 2 - 1;
  287. y += (h - size) / 2;
  288. break;
  289. case GTKConstants.ARROW_DOWN:
  290. x += w / 2 - 1;
  291. y += (h - size) / 2 + 1;
  292. break;
  293. case GTKConstants.ARROW_LEFT:
  294. x += (w - size) / 2;
  295. y += h / 2 - 1;
  296. break;
  297. case GTKConstants.ARROW_RIGHT:
  298. x += (w - size) / 2 + 1;
  299. y += h / 2 - 1;
  300. break;
  301. }
  302. GTKStyle style = (GTKStyle)context.getStyle();
  303. int mid, i, j;
  304. j = 0;
  305. mid = (size / 2) - 1;
  306. g.translate(x, y);
  307. // PENDING: this isn't the right color.
  308. g.setColor(style.getGTKColor(context.getComponent(),
  309. context.getRegion(), state, BluecurveColorType.OUTER5));
  310. switch(direction) {
  311. case GTKConstants.ARROW_UP:
  312. for(i = 0; i < size; i++) {
  313. g.drawLine(mid-i, i, mid+i, i);
  314. }
  315. g.fillRect(mid - size + 2, size, 1, 1);
  316. g.fillRect(mid + size - 2, size, 1, 1);
  317. break;
  318. case GTKConstants.ARROW_DOWN:
  319. j = 0;
  320. for (i = size-1; i >= 0; i--) {
  321. g.drawLine(mid-i, j, mid+i, j);
  322. j++;
  323. }
  324. g.fillRect(mid - size + 2, -1, 1, 1);
  325. g.fillRect(mid + size - 2, -1, 1, 1);
  326. break;
  327. case GTKConstants.ARROW_LEFT:
  328. for (i = 0; i < size; i++) {
  329. g.drawLine(i, mid-i, i, mid+i);
  330. }
  331. g.fillRect(size, mid - size + 2, 1, 1);
  332. g.fillRect(size, mid + size - 2, 1, 1);
  333. break;
  334. case GTKConstants.ARROW_RIGHT:
  335. j = 0;
  336. for (i = size-1; i >= 0; i--) {
  337. g.drawLine(j, mid-i, j, mid+i);
  338. j++;
  339. }
  340. g.fillRect(-1, mid - size + 2, 1, 1);
  341. g.fillRect(-1, mid + size - 2, 1, 1);
  342. break;
  343. }
  344. g.translate(-x, -y);
  345. }
  346. public void paintHandle(SynthContext context, Graphics g, int paintState,
  347. int shadowType, String info, int x, int y,
  348. int w, int h, int orientation) {
  349. paintHashes(context, g, paintState, x, y, w, h, orientation, 5, 4);
  350. }
  351. public void paintOption(SynthContext context, Graphics g, int paintState,
  352. int shadowType, String info, int x, int y,
  353. int w, int h) {
  354. if (info == "option") {
  355. int componentState = context.getComponentState();
  356. if ((componentState & SynthConstants.SELECTED) != 0) {
  357. g.translate(x, y);
  358. int centerY = h / 2 - 1;
  359. JComponent component = context.getComponent();
  360. Region region = context.getRegion();
  361. GTKStyle style = (GTKStyle)context.getStyle();
  362. if ((componentState & SynthConstants.MOUSE_OVER) != 0) {
  363. g.setColor(style.getGTKColor(component, region, paintState,
  364. GTKColorType.WHITE));
  365. }
  366. else {
  367. g.setColor(style.getGTKColor(component, region, paintState,
  368. GTKColorType.BLACK));
  369. }
  370. g.fillRect(5, centerY, 5, 3);
  371. g.drawLine(6, centerY - 1, 8, centerY - 1);
  372. g.drawLine(6, centerY + 3, 8, centerY + 3);
  373. g.translate(-x, -y);
  374. }
  375. return;
  376. }
  377. super.paintOption(context, g, paintState, shadowType, info, x, y,
  378. w, h);
  379. if (info == "radiobutton") {
  380. if ((context.getComponentState() & SynthConstants.SELECTED) != 0) {
  381. // PENDING: this should be a gradient.
  382. int centerY = h / 2 - 1;
  383. g.translate(x, y);
  384. g.setColor(((GTKStyle)context.getStyle()).getGTKColor(context.
  385. getComponent(), context.getRegion(), paintState,
  386. BluecurveColorType.OUTER));
  387. g.fillRect(5, centerY, 5, 3);
  388. g.drawLine(6, centerY - 1, 8, centerY - 1);
  389. g.drawLine(6, centerY + 3, 8, centerY + 3);
  390. g.translate(-x, -y);
  391. }
  392. }
  393. }
  394. public void paintExtension(SynthContext context, Graphics g, int state,
  395. int shadowType, String info, int x, int y,
  396. int w, int h, int placement, int tabIndex) {
  397. _paintExtension(context, g, state, shadowType, x, y, w, h, placement,
  398. BluecurveColorType.OUTER3, GTKColorType.BACKGROUND,
  399. BluecurveColorType.OUTER3, BluecurveColorType.INNER_RIGHT2,
  400. true, tabIndex);
  401. }
  402. public void paintBoxGap(SynthContext context, Graphics g, int state,
  403. int shadowType, String info, int x, int y,
  404. int w, int h, int boxGapType, int tabBegin,
  405. int size) {
  406. _paintBoxGap(context, g, state, shadowType, x, y, w, h, boxGapType,
  407. tabBegin, size, GTKColorType.BACKGROUND,
  408. BluecurveColorType.OUTER3, BluecurveColorType.OUTER3,
  409. BluecurveColorType.INNER_RIGHT2, true);
  410. }
  411. Color getFocusColor(SynthContext context, int state) {
  412. return ((BluecurveStyle)context.getStyle()).getGTKColor(
  413. context.getComponent(), context.getRegion(),
  414. SynthConstants.SELECTED, BluecurveColorType.OUTER3);
  415. }
  416. }