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