1. /*
  2. * @(#)MetacityBluecurve.java 1.5 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.awt.geom.*;
  10. import java.io.*;
  11. import java.net.*;
  12. import java.security.*;
  13. import java.util.*;
  14. import javax.swing.*;
  15. import javax.swing.border.*;
  16. /**
  17. * @version 1.5, 01/23/03
  18. */
  19. class MetacityBluecurve extends Metacity {
  20. protected MetacityBluecurve(String themeDir) {
  21. super(themeDir, normalFrameGeometry);
  22. }
  23. // Constants from Bluecurve/metacity-theme-1.xml 2002-05-29 (use same variable names)
  24. /*
  25. <!-- define constants -->
  26. <constant name="ArrowWidth" value="7"/>
  27. <constant name="ArrowHeight" value="5"/>
  28. <constant name="ButtonIPad" value="3"/>
  29. <constant name="ThickLineWidth" value="3"/>
  30. <constant name="IconTitleSpacing" value="2"/>
  31. <constant name="LeftTitleTextPad" value="6"/>
  32. <constant name="IconShadowOffset" value="1"/>
  33. */
  34. private static final int ArrowWidth = 7;
  35. private static final int ArrowHeight = 5;
  36. private static final int ButtonIPad = 3;
  37. private static final int ThickLineWidth = 3;
  38. private static final int IconTitleSpacing = 2;
  39. private static final int LeftTitleTextPad = 6;
  40. private static final int IconShadowOffset = 1;
  41. /*
  42. <frame_geometry name="normal" rounded_top_left="true" rounded_top_right="true" rounded_bottom_left="true" rounded_bottom_right="true">
  43. <distance name="left_width" value="6"/>
  44. <distance name="right_width" value="6"/>
  45. <distance name="bottom_height" value="6"/>
  46. <distance name="left_titlebar_edge" value="0"/>
  47. <distance name="right_titlebar_edge" value="0"/>
  48. <distance name="title_vertical_pad" value="3"/>
  49. <border name="title_border" left="0" right="0" top="1" bottom="0"/>
  50. <border name="button_border" left="0" right="0" top="1" bottom="0"/>
  51. <aspect_ratio name="button" value="0.9"/>
  52. </frame_geometry>
  53. */
  54. private static class NormalFrameGeometry extends FrameGeometry {
  55. NormalFrameGeometry() {
  56. left_width = 6;
  57. right_width = 6;
  58. bottom_height = 6;
  59. left_titlebar_edge = 0;
  60. right_titlebar_edge = 0;
  61. title_vertical_pad = 3;
  62. title_border = new Insets(1, 0, 0, 0);
  63. button_border = new Insets(1, 0, 0, 0);
  64. aspect_ratio = 0.9F;
  65. }
  66. };
  67. /*
  68. <!-- strip borders off the normal geometry -->
  69. <frame_geometry name="normal_maximized" parent="normal" rounded_top_left="false" rounded_top_right="false" rounded_bottom_left="false" rounded_bottom_right="false">
  70. <distance name="left_width" value="0"/>
  71. <distance name="right_width" value="0"/>
  72. <distance name="bottom_height" value="0"/>
  73. <distance name="left_titlebar_edge" value="0"/>
  74. <distance name="right_titlebar_edge" value="0"/>
  75. </frame_geometry>
  76. */
  77. private static class NormalMaximizedFrameGeometry extends NormalFrameGeometry {
  78. NormalMaximizedFrameGeometry() {
  79. left_width = 0;
  80. right_width = 0;
  81. bottom_height = 0;
  82. left_titlebar_edge = 0;
  83. right_titlebar_edge = 0;
  84. }
  85. };
  86. private static final FrameGeometry normalFrameGeometry = new NormalFrameGeometry();
  87. private static final FrameGeometry normalMaximizedFrameGeometry = new NormalMaximizedFrameGeometry();
  88. // draw_ops
  89. private void titlebar_bg_unfocused(Graphics g, int width, int height) {
  90. /*
  91. <gradient type="vertical" x="0" y="0" width="width" height="height">
  92. <color value="shade/gtk:bg[INSENSITIVE]/1.0"/>
  93. <color value="shade/gtk:bg[INSENSITIVE]/0.9"/>
  94. </gradient>
  95. */
  96. drawVerticalGradient(g,
  97. shadeColor(getColor(DISABLED, GTKColorType.BACKGROUND), 1.0F),
  98. shadeColor(getColor(DISABLED, GTKColorType.BACKGROUND), 0.9F),
  99. 0, 0, width, height);
  100. /*
  101. <line color="shade/gtk:bg[INSENSITIVE]/0.6" x1="0" y1="height-1" x2="width" y2="height-1"/>
  102. */
  103. g.setColor(shadeColor(getColor(DISABLED, GTKColorType.BACKGROUND), 0.6F));
  104. g.drawLine(0, height-1, width, height-1);
  105. /*
  106. <!-- Highlight on top edge -->
  107. <line color="shade/gtk:bg[INSENSITIVE]/1.2" x1="0" y1="0" x2="width" y2="0"/>
  108. */
  109. g.setColor(shadeColor(getColor(DISABLED, GTKColorType.BACKGROUND), 1.2F));
  110. g.drawLine(0, 0, width, 0);
  111. }
  112. /*
  113. <!-- Buttons -->
  114. */
  115. private void button_generic_bg_before(Graphics g, int width, int height) {
  116. /*
  117. <!-- gradient from slightly darker than normal to slightly lighter -->
  118. <gradient type="diagonal" x="0" y="1" width="width" height="height">
  119. <color value="shade/gtk:bg[NORMAL]/1.3"/>
  120. <color value="shade/gtk:bg[NORMAL]/0.9"/>
  121. </gradient>
  122. <gradient type="diagonal" x="1" y="1" width="width-2" height="height-2">
  123. <color value="shade/gtk:bg[NORMAL]/0.9"/>
  124. <color value="shade/gtk:bg[NORMAL]/1.3"/>
  125. </gradient>
  126. */
  127. drawDiagonalGradient(g,
  128. shadeColor(getColor(ENABLED, GTKColorType.BACKGROUND), 1.3F),
  129. shadeColor(getColor(ENABLED, GTKColorType.BACKGROUND), 0.9F),
  130. 0, 1, width, height);
  131. drawDiagonalGradient(g,
  132. shadeColor(getColor(ENABLED, GTKColorType.BACKGROUND), 0.9F),
  133. shadeColor(getColor(ENABLED, GTKColorType.BACKGROUND), 1.3F),
  134. 1, 1, width-2, height-2);
  135. }
  136. private void button_generic_bg_before_unfocused(Graphics g, int width, int height) {
  137. /*
  138. <include name="titlebar_bg_unfocused"/>
  139. <gradient type="vertical" x="0" y="1" width="width" height="height-2" alpha="0.1">
  140. <color value="shade/gtk:bg[NORMAL]/1.5"/>
  141. <color value="shade/gtk:bg[NORMAL]/0.95"/>
  142. </gradient>
  143. */
  144. titlebar_bg_unfocused(g, width, height);
  145. drawVerticalGradient(g,
  146. shadeColor(getColor(ENABLED, GTKColorType.BACKGROUND), 1.5F),
  147. shadeColor(getColor(ENABLED, GTKColorType.BACKGROUND), 0.95F),
  148. 0, 1, width, height-2, 0.1F);
  149. }
  150. private void button_generic_bg_after(Graphics g, int width, int height) {
  151. /*
  152. <!-- line on bottom edge -->
  153. <line color="shade/gtk:dark[NORMAL]/0.9" x1="0" y1="height-1" x2="width" y2="height-1"/>
  154. */
  155. g.setColor(shadeColor(getColor(ENABLED, GTKColorType.DARK), 0.9F));
  156. g.drawLine(0, height-1, width, height-1);
  157. }
  158. private void center_button_bg(Graphics g, int width, int height) {
  159. /*
  160. <include name="button_generic_bg_before"/>
  161. <include name="button_generic_bg_after"/>
  162. <!-- highlight on top edge -->
  163. <line color="shade/gtk:bg[NORMAL]/1.2" x1="0" y1="0" x2="width" y2="0"/>
  164. <!-- dark line to separate from other buttons -->
  165. <line color="gtk:dark[NORMAL]" x1="width-1" y1="0" x2="width-1" y2="height"/>
  166. */
  167. button_generic_bg_before(g, width, height);
  168. button_generic_bg_after(g, width, height);
  169. g.setColor(shadeColor(getColor(ENABLED, GTKColorType.BACKGROUND), 1.2F));
  170. g.drawLine(0, 0, width, 0);
  171. g.setColor(getColor(ENABLED, GTKColorType.DARK));
  172. g.drawLine(width-1, 0, width-1, height);
  173. }
  174. private void center_button_bg_unfocused(Graphics g, int width, int height) {
  175. /*
  176. <include name="button_generic_bg_before_unfocused"/>
  177. */
  178. button_generic_bg_before_unfocused(g, width, height);
  179. }
  180. private void right_corner_outline(Graphics g, int width, int height) {
  181. /*
  182. <draw_ops name="right_corner_outline">
  183. <!-- fix up the black edging -->
  184. <line color="#000000" x1="width-1" y1="0" x2="width-1" y2="height"/>
  185. <line color="#000000" x1="width-5" y1="0" x2="width-4" y2="0"/>
  186. <line color="#000000" x1="width-3" y1="1" x2="width-2" y2="1"/>
  187. <line color="#000000" x1="width-2" y1="2" x2="width-2" y2="3"/>
  188. </draw_ops>
  189. */
  190. g.setColor(Color.black);
  191. // Adjusted because button isn't clipped
  192. g.drawLine(width-1, 4, width-1, height);
  193. g.drawLine(width-5, 0, width-4, 0);
  194. g.drawLine(width-3, 1, width-3, 1);
  195. g.drawLine(width-2, 2, width-2, 3);
  196. }
  197. private void right_corner_button_bg(Graphics g, int width, int height) {
  198. /*
  199. <include name="button_generic_bg_before"/>
  200. <include name="button_generic_bg_after"/>
  201. <include name="right_corner_outline"/>
  202. <!-- highlight on top edge -->
  203. <line color="shade/gtk:bg[NORMAL]/1.2" x1="0" y1="0" x2="width-6" y2="0"/>
  204. <!-- do some shading around the edges -->
  205. <line color="shade/gtk:bg[NORMAL]/1.1" x1="width-4" y1="1" x2="width-5" y2="1"/>
  206. <line color="shade/gtk:bg[NORMAL]/0.9" x1="width-3" y1="2" x2="width-3" y2="3"/>
  207. <line color="shade/gtk:bg[NORMAL]/0.8" x1="width-2" y1="4" x2="width-2" y2="height-2"/>
  208. */
  209. button_generic_bg_before(g, width, height);
  210. button_generic_bg_after(g, width, height);
  211. right_corner_outline(g, width, height);
  212. g.setColor(shadeColor(getColor(ENABLED, GTKColorType.BACKGROUND), 1.2F));
  213. g.drawLine(0, 0, width-6, 0);
  214. g.setColor(shadeColor(getColor(ENABLED, GTKColorType.BACKGROUND), 1.1F));
  215. g.drawLine(width-4, 1, width-5, 1);
  216. g.setColor(shadeColor(getColor(ENABLED, GTKColorType.BACKGROUND), 0.9F));
  217. g.drawLine(width-3, 2, width-3, 3);
  218. g.setColor(shadeColor(getColor(ENABLED, GTKColorType.BACKGROUND), 0.8F));
  219. g.drawLine(width-2, 4, width-2, height-2);
  220. }
  221. private void right_corner_button_bg_unfocused(Graphics g, int width, int height) {
  222. /*
  223. <include name="button_generic_bg_before_unfocused"/>
  224. <include name="right_corner_outline"/>
  225. <!-- highlight on top edge -->
  226. <line color="shade/gtk:bg[INSENSITIVE]/1.2" x1="0" y1="0" x2="width-6" y2="0"/>
  227. <!-- do some shading around the edges -->
  228. <line color="shade/gtk:bg[INSENSITIVE]/1.1" x1="width-4" y1="1" x2="width-5" y2="1"/>
  229. <line color="shade/gtk:bg[INSENSITIVE]/0.9" x1="width-3" y1="2" x2="width-3" y2="3"/>
  230. <line color="shade/gtk:bg[INSENSITIVE]/0.8" x1="width-2" y1="4" x2="width-2" y2="height-2"/>
  231. */
  232. button_generic_bg_before_unfocused(g, width, height);
  233. right_corner_outline(g, width, height);
  234. g.setColor(shadeColor(getColor(DISABLED, GTKColorType.BACKGROUND), 1.2F));
  235. g.drawLine(0, 0, width-6, 0);
  236. g.setColor(shadeColor(getColor(DISABLED, GTKColorType.BACKGROUND), 1.1F));
  237. g.drawLine(width-4, 1, width-5, 1);
  238. g.setColor(shadeColor(getColor(DISABLED, GTKColorType.BACKGROUND), 0.9F));
  239. g.drawLine(width-3, 2, width-3, 3);
  240. g.setColor(shadeColor(getColor(DISABLED, GTKColorType.BACKGROUND), 0.8F));
  241. g.drawLine(width-2, 4, width-2, height-2);
  242. }
  243. private void left_corner_outline(Graphics g, int width, int height) {
  244. /*
  245. <draw_ops name="left_corner_outline">
  246. <!-- fix up the black edging -->
  247. <line color="#000000" x1="0" y1="0" x2="0" y2="height"/>
  248. <line color="#000000" x1="1" y1="2" x2="1" y2="3"/>
  249. <line color="#000000" x1="2" y1="1" x2="2" y2="1"/>
  250. <line color="#000000" x1="3" y1="0" x2="4" y2="0"/>
  251. </draw_ops>
  252. */
  253. g.setColor(Color.black);
  254. // adjusted because button isn't clipped
  255. g.drawLine(0, 4, 0, height);
  256. g.drawLine(1, 2, 1, 3);
  257. g.drawLine(2, 1, 2, 1);
  258. g.drawLine(3, 0, 4, 0);
  259. }
  260. private void left_corner_button_bg(Graphics g, int width, int height) {
  261. /*
  262. <include name="button_generic_bg_before"/>
  263. <include name="button_generic_bg_after"/>
  264. <include name="left_corner_outline"/>
  265. <!-- highlight on top edge -->
  266. <line color="shade/gtk:bg[NORMAL]/1.2" x1="5" y1="0" x2="width" y2="0"/>
  267. <!-- shading around the edges -->
  268. <line color="shade/gtk:light[NORMAL]/1.2" x1="1" y1="4" x2="1" y2="height-2"/>
  269. <line color="shade/gtk:light[NORMAL]/1.1" x1="3" y1="1" x2="4" y2="1"/>
  270. <line color="shade/gtk:light[NORMAL]/1.1" x1="2" y1="2" x2="2" y2="3"/>
  271. */
  272. button_generic_bg_before(g, width, height);
  273. button_generic_bg_after(g, width, height);
  274. left_corner_outline(g, width, height);
  275. g.setColor(shadeColor(getColor(ENABLED, GTKColorType.BACKGROUND), 1.2F));
  276. g.drawLine(5, 0, width, 0);
  277. g.setColor(shadeColor(getColor(ENABLED, GTKColorType.LIGHT), 1.2F));
  278. g.drawLine(1, 4, 1, height-2);
  279. g.setColor(shadeColor(getColor(ENABLED, GTKColorType.LIGHT), 1.1F));
  280. g.drawLine(3, 1, 4, 1);
  281. g.drawLine(2, 2, 2, 3);
  282. }
  283. private void left_corner_button_bg_unfocused(Graphics g, int width, int height) {
  284. /*
  285. <include name="button_generic_bg_before_unfocused"/>
  286. <include name="left_corner_outline"/>
  287. <!-- highlight on top edge -->
  288. <line color="shade/gtk:bg[INSENSITIVE]/1.2" x1="5" y1="0" x2="width" y2="0"/>
  289. <!-- shading around the edges -->
  290. <line color="shade/gtk:light[INSENSITIVE]/1.2" x1="1" y1="4" x2="1" y2="height-2"/>
  291. <line color="shade/gtk:light[INSENSITIVE]/1.1" x1="3" y1="1" x2="4" y2="1"/>
  292. <line color="shade/gtk:light[INSENSITIVE]/1.1" x1="2" y1="2" x2="2" y2="3"/>
  293. */
  294. button_generic_bg_before_unfocused(g, width, height);
  295. left_corner_outline(g, width, height);
  296. g.setColor(shadeColor(getColor(DISABLED, GTKColorType.BACKGROUND), 1.2F));
  297. g.drawLine(5, 0, width, 0);
  298. g.setColor(shadeColor(getColor(DISABLED, GTKColorType.LIGHT), 1.2F));
  299. g.drawLine(1, 4, 1, height-2);
  300. g.setColor(shadeColor(getColor(DISABLED, GTKColorType.LIGHT), 1.1F));
  301. g.drawLine(3, 1, 4, 1);
  302. g.drawLine(2, 2, 2, 3);
  303. }
  304. private void darken_tint(Graphics g, int width, int height) {
  305. /*
  306. <tint color="shade/gtk:bg[normal]/0.75" alpha="0.5"
  307. x="0" y="0" width="width" height="height"/>
  308. */
  309. tintRect(g, 0, 0, width, height,
  310. shadeColor(getColor(ENABLED, GTKColorType.BACKGROUND), 0.75F),
  311. 0.5F);
  312. }
  313. private void prelight_tint(Graphics g, int width, int height) {
  314. /*
  315. <tint color="gtk:bg[PRELIGHT]" alpha="0.4"
  316. x="1" y="1" width="width-2" height="height-2"/>
  317. */
  318. tintRect(g, 1, 1, width-2, height-2, getColor(MOUSE_OVER, GTKColorType.BACKGROUND), 0.4F);
  319. }
  320. private void minimize_icon(Graphics g, int width, int height) {
  321. /*
  322. <image filename="minimize.png"
  323. colorize="gtk:fg[NORMAL]"
  324. alpha="0.7"
  325. x="(width - object_width) / 2"
  326. y="(height - object_height) / 2"
  327. width="object_width"
  328. height="object_height"/>
  329. */
  330. Image object = getImage("minimize", getColor(ENABLED, GTKColorType.FOREGROUND));
  331. drawImage(g, object,
  332. getColor(ENABLED, GTKColorType.FOREGROUND),
  333. 0.7F,
  334. (width - object.getWidth(null)) / 2,
  335. (height - object.getHeight(null)) / 2);
  336. }
  337. private void menu_icon(Graphics g, int width, int height) {
  338. /*
  339. <image filename="menu.png"
  340. colorize="gtk:fg[NORMAL]"
  341. alpha="0.7"
  342. x="(width - object_width - 1) / 2"
  343. y="(height - object_height) / 2"
  344. width="object_width"
  345. height="object_height"/>
  346. */
  347. Image object = getImage("menu", getColor(ENABLED, GTKColorType.FOREGROUND));
  348. drawImage(g, object,
  349. getColor(ENABLED, GTKColorType.FOREGROUND),
  350. 0.7F,
  351. (width - object.getWidth(null) - 1) / 2,
  352. (height - object.getHeight(null)) / 2);
  353. }
  354. private void maximize_icon(Graphics g, int width, int height) {
  355. /*
  356. <image filename="maximize.png"
  357. colorize="gtk:fg[NORMAL]"
  358. alpha="0.7"
  359. x="(width - object_width) / 2"
  360. y="(height - object_height) / 2"
  361. width="object_width"
  362. height="object_height"/>
  363. */
  364. Image object = getImage("maximize", getColor(ENABLED, GTKColorType.FOREGROUND));
  365. drawImage(g, object,
  366. getColor(ENABLED, GTKColorType.FOREGROUND),
  367. 0.7F,
  368. (width - object.getWidth(null)) / 2,
  369. (height - object.getHeight(null)) / 2);
  370. }
  371. private void close_icon(Graphics g, int width, int height) {
  372. /*
  373. <image filename="close.png"
  374. colorize="gtk:fg[NORMAL]"
  375. alpha="0.7"
  376. x="(width - object_width) / 2"
  377. y="(height - object_height) / 2"
  378. width="object_width"
  379. height="object_height"/>
  380. */
  381. Image object = getImage("close", getColor(ENABLED, GTKColorType.FOREGROUND));
  382. drawImage(g, object,
  383. getColor(ENABLED, GTKColorType.FOREGROUND),
  384. 0.7F,
  385. (width - object.getWidth(null)) / 2,
  386. (height - object.getHeight(null)) / 2);
  387. }
  388. private void close_button(Graphics g, int width, int height) {
  389. /*
  390. <include name="right_corner_button_bg"/>
  391. <include name="close_icon"/>
  392. */
  393. right_corner_button_bg(g, width, height);
  394. close_icon(g, width, height);
  395. }
  396. private void close_button_prelight(Graphics g, int width, int height) {
  397. /*
  398. <include name="right_corner_button_bg"/>
  399. <include name="prelight_tint"/>
  400. <include name="close_icon"/>
  401. <include name="close_icon"/>
  402. <include name="right_corner_outline"/>
  403. */
  404. right_corner_button_bg(g, width, height);
  405. prelight_tint(g, width, height);
  406. close_icon(g, width, height);
  407. right_corner_outline(g, width, height);
  408. }
  409. private void close_button_pressed(Graphics g, int width, int height) {
  410. /*
  411. <include name="right_corner_button_bg"/>
  412. <include name="darken_tint"/>
  413. <include name="close_icon"/>
  414. */
  415. right_corner_button_bg(g, width, height);
  416. darken_tint(g, width, height);
  417. close_icon(g, width, height);
  418. }
  419. private void menu_button(Graphics g, int width, int height) {
  420. /*
  421. <include name="left_corner_button_bg"/>
  422. <include name="menu_icon" x="2"/>
  423. */
  424. left_corner_button_bg(g, width, height);
  425. g.translate(2, 0);
  426. menu_icon(g, width, height);
  427. g.translate(-2, 0);
  428. }
  429. private void menu_button_prelight(Graphics g, int width, int height) {
  430. /*
  431. <include name="left_corner_button_bg"/>
  432. <include name="prelight_tint"/>
  433. <include name="menu_icon" x="2"/>
  434. <include name="menu_icon" x="2"/>
  435. <include name="left_corner_outline"/>
  436. */
  437. left_corner_button_bg(g, width, height);
  438. prelight_tint(g, width, height);
  439. g.translate(2, 0);
  440. menu_icon(g, width, height);
  441. g.translate(-2, 0);
  442. left_corner_outline(g, width, height);
  443. }
  444. private void menu_button_pressed(Graphics g, int width, int height) {
  445. /*
  446. <include name="left_corner_button_bg"/>
  447. <include name="darken_tint"/>
  448. <include name="menu_icon" x="2"/>
  449. */
  450. left_corner_button_bg(g, width, height);
  451. darken_tint(g, width, height);
  452. g.translate(2, 0);
  453. menu_icon(g, width, height);
  454. g.translate(-2, 0);
  455. }
  456. private void minimize_button(Graphics g, int width, int height, boolean corner) {
  457. /*
  458. <include name="center_button_bg"/>
  459. <include name="minimize_icon"/>
  460. */
  461. if (corner) {
  462. right_corner_button_bg(g, width, height);
  463. } else {
  464. center_button_bg(g, width, height);
  465. }
  466. minimize_icon(g, width, height);
  467. }
  468. private void minimize_button_prelight(Graphics g, int width, int height, boolean corner) {
  469. /*
  470. <include name="center_button_bg"/>
  471. <include name="prelight_tint"/>
  472. <include name="minimize_icon"/>
  473. <include name="minimize_icon"/>
  474. */
  475. if (corner) {
  476. right_corner_button_bg(g, width, height);
  477. } else {
  478. center_button_bg(g, width, height);
  479. }
  480. prelight_tint(g, width, height);
  481. minimize_icon(g, width, height);
  482. }
  483. private void minimize_button_pressed(Graphics g, int width, int height, boolean corner) {
  484. /*
  485. <include name="center_button_bg"/>
  486. <include name="darken_tint"/>
  487. <include name="minimize_icon"/>
  488. */
  489. if (corner) {
  490. right_corner_button_bg(g, width, height);
  491. } else {
  492. center_button_bg(g, width, height);
  493. }
  494. darken_tint(g, width, height);
  495. minimize_icon(g, width, height);
  496. }
  497. private void maximize_button(Graphics g, int width, int height, boolean corner) {
  498. /*
  499. <include name="center_button_bg"/>
  500. <include name="maximize_icon"/>
  501. */
  502. if (corner) {
  503. right_corner_button_bg(g, width, height);
  504. } else {
  505. center_button_bg(g, width, height);
  506. }
  507. maximize_icon(g, width, height);
  508. }
  509. private void maximize_button_prelight(Graphics g, int width, int height, boolean corner) {
  510. /*
  511. <include name="center_button_bg"/>
  512. <include name="prelight_tint"/>
  513. <include name="maximize_icon"/>
  514. <include name="maximize_icon"/>
  515. */
  516. if (corner) {
  517. right_corner_button_bg(g, width, height);
  518. } else {
  519. center_button_bg(g, width, height);
  520. }
  521. prelight_tint(g, width, height);
  522. maximize_icon(g, width, height);
  523. }
  524. private void maximize_button_pressed(Graphics g, int width, int height, boolean corner) {
  525. /*
  526. <include name="center_button_bg"/>
  527. <include name="darken_tint"/>
  528. <include name="maximize_icon"/>
  529. */
  530. if (corner) {
  531. right_corner_button_bg(g, width, height);
  532. } else {
  533. center_button_bg(g, width, height);
  534. }
  535. darken_tint(g, width, height);
  536. maximize_icon(g, width, height);
  537. }
  538. void paintButtonBackground(SynthContext context, Graphics g, int x, int y, int w, int h) {
  539. this.context = context;
  540. JButton button = (JButton)context.getComponent();
  541. String buttonName = button.getName();
  542. int buttonState = context.getComponentState();
  543. JComponent titlePane = (JComponent)button.getParent();
  544. Container titlePaneParent = titlePane.getParent();
  545. JInternalFrame frame;
  546. if (titlePaneParent instanceof JInternalFrame) {
  547. frame = (JInternalFrame)titlePaneParent;
  548. } else if (titlePaneParent instanceof JInternalFrame.JDesktopIcon) {
  549. frame = ((JInternalFrame.JDesktopIcon)titlePaneParent).getInternalFrame();
  550. } else {
  551. return;
  552. }
  553. boolean active = frame.isSelected();
  554. setFrameGeometry(titlePane, frame.isMaximum() ? normalMaximizedFrameGeometry
  555. : normalFrameGeometry);
  556. if (buttonName.equals("InternalFrameTitlePane.menuButton")) {
  557. if ((buttonState & PRESSED) != 0) {
  558. menu_button_pressed(g, w, h);
  559. } else if ((buttonState & MOUSE_OVER) != 0) {
  560. menu_button_prelight(g, w, h);
  561. } else {
  562. menu_button(g, w, h);
  563. }
  564. } else if (buttonName.equals("InternalFrameTitlePane.iconifyButton")) {
  565. boolean corner = !(frame.isClosable() || frame.isMaximizable());
  566. if ((buttonState & PRESSED) != 0) {
  567. minimize_button_pressed(g, w, h, corner);
  568. } else if ((buttonState & MOUSE_OVER) != 0) {
  569. minimize_button_prelight(g, w, h, corner);
  570. } else {
  571. minimize_button(g, w, h, corner);
  572. }
  573. } else if (buttonName.equals("InternalFrameTitlePane.maximizeButton")) {
  574. boolean corner = !frame.isClosable();
  575. if ((buttonState & PRESSED) != 0) {
  576. maximize_button_pressed(g, w, h, corner);
  577. } else if ((buttonState & MOUSE_OVER) != 0) {
  578. maximize_button_prelight(g, w, h, corner);
  579. } else {
  580. maximize_button(g, w, h, corner);
  581. }
  582. } else if (buttonName.equals("InternalFrameTitlePane.closeButton")) {
  583. if ((buttonState & PRESSED) != 0) {
  584. close_button_pressed(g, w, h);
  585. } else if ((buttonState & MOUSE_OVER) != 0) {
  586. close_button_prelight(g, w, h);
  587. } else {
  588. close_button(g, w, h);
  589. }
  590. }
  591. }
  592. private void outer_bevel(Graphics g, int width, int height) {
  593. FrameGeometry gm = getFrameGeometry();
  594. /*
  595. <draw_ops name="outer_bevel">
  596. <!-- black edging -->
  597. <rectangle color="#000000" x="0" y="0" width="width-1" height="height-1"/>
  598. */
  599. g.setColor(Color.black);
  600. //g.drawRect(0, 0, width-1, height-1);
  601. //Adjusted because we have no clipping set
  602. g.drawLine(5, 0, width-6, 0);
  603. g.drawLine(5, height-1, width-6, height-1);
  604. g.drawLine(0, 5, 0, height-6);
  605. g.drawLine(width-1, 5, width-1, height-6);
  606. /*
  607. <!-- left outside -->
  608. <line color="blend/gtk:light[NORMAL]/#FFFFFF/0.7" x1="1" y1="1" x2="1" y2="height-2"/>
  609. */
  610. g.setColor(blendColor(getColor(ENABLED, GTKColorType.LIGHT), Color.white, 0.7F));
  611. //g.drawLine(1, 1, 1, height-2);
  612. g.drawLine(1, 3, 1, height-4);
  613. /*
  614. <!-- left inside -->
  615. <line color="gtk:dark[NORMAL]"
  616. x1="left_width-1" y1="top_height-1" x2="left_width-1" y2="height-bottom_height"/>
  617. */
  618. g.setColor(getColor(ENABLED, GTKColorType.DARK));
  619. g.drawLine(gm.left_width-1, gm.top_height-1, gm.left_width-1, height-gm.bottom_height);
  620. /*
  621. <!-- outside of bottom -->
  622. <line color="blend/gtk:bg[NORMAL]/#000000/0.2" x1="2" y1="height-2" x2="width-2" y2="height-2"/>
  623. */
  624. g.setColor(blendColor(getColor(ENABLED, GTKColorType.BACKGROUND), Color.black, 0.2F));
  625. //g.drawLine(2, height-2, width-2, height-2);
  626. g.drawLine(3, height-2, width-4, height-2);
  627. /*
  628. <!-- inside of bottom (in two lines, one dark one light) -->
  629. <line color="gtk:dark[NORMAL]"
  630. x1="left_width" y1="height-bottom_height" x2="width-right_width" y2="height-bottom_height"/>
  631. <line color="blend/gtk:light[NORMAL]/#FFFFFF/0.7"
  632. x1="left_width" y1="height-bottom_height+1" x2="width-right_width" y2="height-bottom_height+1"/>
  633. */
  634. g.setColor(getColor(ENABLED, GTKColorType.DARK));
  635. g.drawLine(gm.left_width, height-gm.bottom_height, width-gm.right_width, height-gm.bottom_height);
  636. g.setColor(blendColor(getColor(ENABLED, GTKColorType.LIGHT), Color.white, 0.7F));
  637. g.drawLine(gm.left_width, height-gm.bottom_height+1, width-gm.right_width, height-gm.bottom_height+1);
  638. /*
  639. <!-- right inside, again in two lines -->
  640. <line color="gtk:dark[NORMAL]"
  641. x1="width-right_width" y1="top_height-1" x2="width-right_width" y2="height-bottom_height"/>
  642. <line color="blend/gtk:light[NORMAL]/#FFFFFF/0.7"
  643. x1="width-right_width+1" y1="top_height-1" x2="width-right_width+1" y2="height-bottom_height+1"/>
  644. */
  645. g.setColor(getColor(ENABLED, GTKColorType.DARK));
  646. g.drawLine(width-gm.right_width, gm.top_height-1, width-gm.right_width, height-gm.bottom_height);
  647. g.setColor(blendColor(getColor(ENABLED, GTKColorType.LIGHT), Color.white, 0.7F));
  648. g.drawLine(width-gm.right_width+1, gm.top_height-1, width-gm.right_width+1, height-gm.bottom_height+1);
  649. /*
  650. <!-- right outside -->
  651. <line color="blend/gtk:bg[NORMAL]/#000000/0.2" x1="width-2" y1="top_height-1" x2="width-2" y2="height-2"/>
  652. </draw_ops>
  653. */
  654. g.setColor(blendColor(getColor(ENABLED, GTKColorType.BACKGROUND), Color.black, 0.2F));
  655. //g.drawLine(width-2, top_height-1, width-2, height-2);
  656. g.drawLine(width-2, 3, width-2, height-4);
  657. }
  658. private void corners_unfocused(Graphics g, int width, int height) {
  659. Image object;
  660. /*
  661. <!-- corners (unfocused) -->
  662. <image filename="bottom_left.png" colorize="shade/gtk:bg[INSENSITIVE]/0.8" x="0" y="height-object_height" width="object_width" height="object_height"/>
  663. <image filename="bottom_right.png" colorize="shade/gtk:bg[INSENSITIVE]/0.8" x="width-object_width" y="height-object_height" width="object_width" height="object_height"/>
  664. */
  665. Color c = shadeColor(getColor(DISABLED, GTKColorType.BACKGROUND), 0.8F);
  666. object = getImage("bottom_left", c);
  667. g.drawImage(object, 0, height-object.getHeight(null), null);
  668. object = getImage("bottom_right", c);
  669. g.drawImage(object, width-object.getWidth(null), height-object.getHeight(null), null);
  670. }
  671. private void corners_focused(Graphics g, int width, int height) {
  672. Image object;
  673. /*
  674. <!-- corners -->
  675. <image filename="bottom_left.png" colorize="shade/gtk:bg[SELECTED]/1.0" x="0" y="height-object_height" width="object_width" height="object_height"/>
  676. <image filename="bottom_right.png" colorize="shade/gtk:bg[SELECTED]/1.0" x="width-object_width" y="height-object_height" width="object_width" height="object_height"/>
  677. */
  678. Color c = shadeColor(getColor(SELECTED, GTKColorType.BACKGROUND), 1.0F);
  679. object = getImage("bottom_left", c);
  680. g.drawImage(object, 0, height-object.getHeight(null), null);
  681. object = getImage("bottom_right", c);
  682. g.drawImage(object, width-object.getWidth(null), height-object.getHeight(null), null);
  683. }
  684. private void unfocus_background(Graphics g, int width, int height) {
  685. /*
  686. <include name="outer_bevel"/>
  687. <include name="corners_unfocused"/>
  688. */
  689. outer_bevel(g, width, height);
  690. corners_unfocused(g, width, height);
  691. }
  692. private void focus_background(Graphics g, int width, int height) {
  693. /*
  694. <include name="outer_bevel"/>
  695. <include name="corners_focused"/>
  696. */
  697. outer_bevel(g, width, height);
  698. corners_focused(g, width, height);
  699. }
  700. private void title_gradient(Graphics g, int width, int height, JInternalFrame frame) {
  701. Image object;
  702. int title_width = calculateTitleWidth(g, frame);
  703. /*
  704. <!-- Normally, there would be buttons placed over the outlines. This is to handle windows w/o buttons -->
  705. <include name="left_corner_outline"/>
  706. <include name="right_corner_outline"/>
  707. */
  708. left_corner_outline(g, width, height);
  709. right_corner_outline(g, width, height);
  710. /*
  711. <!-- base vertical gradient -->
  712. <gradient type="vertical" x="0" y="0" width="width" height="height-1">
  713. <color value="shade/gtk:bg[SELECTED]/1.4"/>
  714. <color value="shade/gtk:bg[SELECTED]/1.0"/>
  715. <color value="shade/gtk:bg[SELECTED]/0.8"/>
  716. </gradient>
  717. */
  718. drawVerticalGradient(g,
  719. shadeColor(getColor(SELECTED, GTKColorType.BACKGROUND), 1.4F),
  720. shadeColor(getColor(SELECTED, GTKColorType.BACKGROUND), 1.0F),
  721. shadeColor(getColor(SELECTED, GTKColorType.BACKGROUND), 0.8F),
  722. 0, 0, width, height-1);
  723. /*
  724. <!-- stripes -->
  725. <image filename="white_stripes_tile.png" fill_type="tile"
  726. x="(LeftTitleTextPad+title_width-40) `max` 1"
  727. y="1+1" width="width-(LeftTitleTextPad+title_width-40)-2" height="height-4"
  728. alpha="0.0:0.3:0.4:0.4"/>
  729. */
  730. object = getImage("white_stripes_tile");
  731. tileImage(g, object,
  732. Math.max(LeftTitleTextPad+title_width-40, 1), 1+1,
  733. width-(LeftTitleTextPad+title_width-40)-2, height-4,
  734. new float[] { 0.0F, 0.3F, 0.4F, 0.4F });
  735. /*
  736. <!-- top title shine -->
  737. <gradient type="diagonal" x="0" y="0" width="width" height="2" alpha="0.2">
  738. <color value="shade/gtk:bg[SELECTED]/2.0"/>
  739. <color value="shade/gtk:bg[SELECTED]/1.7"/>
  740. </gradient>
  741. <gradient type="vertical" x="0" y="0" width="width" height="1" alpha="0.4">
  742. <color value="shade/gtk:bg[SELECTED]/2.0"/>
  743. <color value="shade/gtk:bg[SELECTED]/1.4"/>
  744. </gradient>
  745. */
  746. drawDiagonalGradient(g,
  747. shadeColor(getColor(SELECTED, GTKColorType.BACKGROUND), 2.0F),
  748. shadeColor(getColor(SELECTED, GTKColorType.BACKGROUND), 1.7F),
  749. 0, 0, width, 2, 0.2F);
  750. drawVerticalGradient(g,
  751. shadeColor(getColor(SELECTED, GTKColorType.BACKGROUND), 2.0F),
  752. shadeColor(getColor(SELECTED, GTKColorType.BACKGROUND), 1.4F),
  753. 0, 0, width, 1, 0.4F);
  754. /*
  755. <!-- bottom title darken -->
  756. <gradient type="diagonal" x="0" y="height-2" width="width" height="2" alpha="0.2">
  757. <color value="shade/gtk:bg[SELECTED]/0.8"/>
  758. <color value="shade/gtk:bg[SELECTED]/0.5"/>
  759. </gradient>
  760. <gradient type="vertical" x="0" y="height-2" width="width" height="1" alpha="0.9">
  761. <color value="shade/gtk:bg[SELECTED]/1.0"/>
  762. <color value="shade/gtk:bg[SELECTED]/0.7"/>
  763. </gradient>
  764. */
  765. drawDiagonalGradient(g,
  766. shadeColor(getColor(SELECTED, GTKColorType.BACKGROUND), 0.8F),
  767. shadeColor(getColor(SELECTED, GTKColorType.BACKGROUND), 0.5F),
  768. 0, height-2, width, 2, 0.2F);
  769. drawVerticalGradient(g,
  770. shadeColor(getColor(SELECTED, GTKColorType.BACKGROUND), 1.0F),
  771. shadeColor(getColor(SELECTED, GTKColorType.BACKGROUND), 0.7F),
  772. 0, height-2, width, 1, 0.9F);
  773. /*
  774. <!-- bottom seperator line -->
  775. <line color="shade/gtk:bg[SELECTED]/0.1" x1="0" y1="height-1" x2="width" y2="height-1"/>
  776. */
  777. g.setColor(shadeColor(getColor(SELECTED, GTKColorType.BACKGROUND), 0.1F));
  778. g.drawLine(0, height-1, width, height-1);
  779. }
  780. private void title_text_focused_no_icon(Graphics g, int width, int height, JInternalFrame frame) {
  781. FontMetrics fm = g.getFontMetrics();
  782. int title_height = fm.getAscent() + fm.getDescent();
  783. /*
  784. <clip x="0" y="0" width="width-8" height="height"/>
  785. <title color="blend/gtk:fg[NORMAL]/gtk:bg[SELECTED]/0.7"
  786. x="LeftTitleTextPad+1"
  787. y="(((height - title_height) / 2) `max` 0)+1"/>
  788. <title color="gtk:fg[SELECTED]"
  789. x="LeftTitleTextPad"
  790. y="((height - title_height) / 2) `max` 0"/>
  791. */
  792. Rectangle clipRect = g.getClipBounds();
  793. g.setClip(0, 0, width-8, height);
  794. g.setColor(blendColor(getColor(ENABLED, GTKColorType.TEXT_FOREGROUND),
  795. getColor(SELECTED, GTKColorType.BACKGROUND), 0.7F));
  796. paintTitle(g, LeftTitleTextPad+1, Math.max((height - title_height) / 2, 0)+1, frame);
  797. g.setColor(getColor(SELECTED, ColorType.TEXT_FOREGROUND));
  798. paintTitle(g, LeftTitleTextPad, Math.max((height - title_height) / 2, 0), frame);
  799. g.setClip(clipRect);
  800. }
  801. private void title_text_no_icon(Graphics g, int width, int height, JInternalFrame frame) {
  802. FontMetrics fm = g.getFontMetrics();
  803. int title_height = fm.getAscent() + fm.getDescent();
  804. /*
  805. <clip x="0" y="0" width="width-8" height="height"/>
  806. <title color="blend/gtk:fg[INSENSITIVE]/gtk:bg[INSENSITIVE]/0.0"
  807. x="LeftTitleTextPad"
  808. y="((height - title_height) / 2) `max` 0"/>
  809. */
  810. Rectangle clipRect = g.getClipBounds();
  811. g.setClip(0, 0, width-8, height);
  812. g.setColor(blendColor(getColor(DISABLED, GTKColorType.TEXT_FOREGROUND),
  813. getColor(DISABLED, GTKColorType.BACKGROUND), 0.0F));
  814. paintTitle(g, LeftTitleTextPad, Math.max((height - title_height) / 2, 0), frame);
  815. g.setClip(clipRect);
  816. }
  817. private void title_normal(Graphics g, int width, int height, JInternalFrame frame) {
  818. /*
  819. <include name="titlebar_bg_unfocused"/>
  820. <include name="title_text_no_icon"/>
  821. <line color="blend/gtk:bg[INSENSITIVE]/gtk:fg[INSENSITIVE]/0.3" x1="0" y1="0" x2="0" y2="height-2"/>
  822. <line color="blend/gtk:bg[INSENSITIVE]/gtk:fg[INSENSITIVE]/0.3" x1="width-1" y1="0" x2="width-1" y2="height-2"/>
  823. */
  824. titlebar_bg_unfocused(g, width, height);
  825. title_text_no_icon(g, width, height, frame);
  826. g.setColor(blendColor(getColor(DISABLED, GTKColorType.BACKGROUND),
  827. getColor(DISABLED, GTKColorType.FOREGROUND), 0.3F));
  828. g.drawLine(0, 0, 0, height-2);
  829. g.drawLine(width-1, 0, width-1, height-2);
  830. }
  831. private void title_focused(Graphics g, int width, int height, JInternalFrame frame) {
  832. /*
  833. <include name="title_gradient"/>
  834. <include name="title_text_focused_no_icon"/>
  835. <line color="blend/gtk:bg[SELECTED]/#000000/0.4" x1="0" y1="0" x2="0" y2="height"/>
  836. <line color="blend/gtk:bg[SELECTED]/#000000/0.4" x1="width-1" y1="0" x2="width-1" y2="height"/>
  837. */
  838. title_gradient(g, width, height, frame);
  839. title_text_focused_no_icon(g, width, height, frame);
  840. g.setColor(blendColor(getColor(SELECTED, GTKColorType.BACKGROUND),
  841. getColor(SELECTED, GTKColorType.FOREGROUND), 0.4F));
  842. g.drawLine(0, 0, 0, height);
  843. g.drawLine(width-1, 0, width-1, height);
  844. }
  845. private void paintTitle(Graphics g, int x0, int y0, JInternalFrame frame) {
  846. String title = frame.getTitle();
  847. if (title != null) {
  848. if (frame.getComponentOrientation().isLeftToRight()) {
  849. title = getTitle(title, g.getFontMetrics(), calculateTitleWidth(g, frame));
  850. }
  851. g.drawString(title, x0, y0 + g.getFontMetrics().getAscent());
  852. }
  853. }
  854. private int calculateTitleWidth(Graphics g, JInternalFrame frame) {
  855. FrameGeometry gm = getFrameGeometry();
  856. String title = frame.getTitle();
  857. if (title != null) {
  858. JComponent titlePane = findChild(frame, "InternalFrame.northPane");
  859. JComponent button = null;
  860. if (frame.isIconifiable()) {
  861. button = findChild(titlePane, "InternalFrameTitlePane.iconifyButton");
  862. }
  863. if (button == null && frame.isMaximizable()) {
  864. button = findChild(titlePane, "InternalFrameTitlePane.maximizeButton");
  865. }
  866. if (button == null && frame.isClosable()) {
  867. button = findChild(titlePane, "InternalFrameTitlePane.closeButton");
  868. }
  869. int buttonX = (button != null) ? button.getX() : (titlePane.getWidth() - gm.right_titlebar_edge);
  870. // return Math.min(SwingUtilities.computeStringWidth(fm, title),
  871. // buttonX - (left_width + ButtonWidth + IconTitleSpacing) - 3);
  872. return SwingUtilities.computeStringWidth(g.getFontMetrics(), title);
  873. }
  874. return 0;
  875. }
  876. private String getTitle(String text, FontMetrics fm, int availTextWidth) {
  877. if ((text == null) || (text.equals(""))) {
  878. return "";
  879. }
  880. int textWidth = SwingUtilities.computeStringWidth(fm, text);
  881. String clipString = "...";
  882. if (textWidth > availTextWidth) {
  883. int totalWidth = SwingUtilities.computeStringWidth(fm, clipString);
  884. int nChars;
  885. for (nChars = 0; nChars < text.length(); nChars++) {
  886. totalWidth += fm.charWidth(text.charAt(nChars));
  887. if (totalWidth > availTextWidth) {
  888. break;
  889. }
  890. }
  891. text = text.substring(0, nChars) + clipString;
  892. }
  893. return text;
  894. }
  895. void paintFrameBorder(SynthContext context, Graphics g, int x0, int y0, int width, int height) {
  896. this.context = context;
  897. JInternalFrame frame = (JInternalFrame)context.getComponent();
  898. JComponent titlePane = findChild(frame, "InternalFrame.northPane");
  899. frame.setOpaque(false);
  900. findChild(titlePane, "InternalFrameTitlePane.closeButton").setOpaque(false);
  901. //boolean active = ((context.getComponentState() & SELECTED) != 0);
  902. boolean active = frame.isSelected();
  903. FrameGeometry gm = frame.isMaximum() ? normalMaximizedFrameGeometry
  904. : normalFrameGeometry;
  905. setFrameGeometry(titlePane, gm);
  906. Font oldFont = g.getFont();
  907. g.setFont(titlePane.getFont());
  908. g.translate(x0, y0);
  909. // Shape oldClip = g.getClip();
  910. // g.setClip(new RoundRectangle2D.Float(0F, 0F,
  911. // (float)width, (float)height,
  912. // 12F, 12F));
  913. // Paint border background because we are not opaque and have no rounded clip
  914. g.setColor(frame.getBackground());
  915. g.fillRect(0, gm.top_height,
  916. gm.left_width, height - gm.top_height - gm.bottom_height);
  917. g.fillRect(width - gm.right_width - 1, gm.top_height,
  918. gm.right_width, height - gm.top_height - gm.bottom_height);
  919. g.fillRect(gm.left_width, height - gm.bottom_height - 1,
  920. width - gm.left_width - gm.right_width, gm.bottom_height);
  921. int titleX = 0;
  922. int titleWidth = width;
  923. JComponent menuButton = findChild(titlePane, "InternalFrameTitlePane.menuButton");
  924. if (menuButton != null) {
  925. int x = menuButton.getX() + menuButton.getWidth() - x0;
  926. titleX += x;
  927. titleWidth -= x;
  928. }
  929. JComponent button = null;
  930. if (frame.isIconifiable()) {
  931. button = findChild(titlePane, "InternalFrameTitlePane.iconifyButton");
  932. }
  933. if (button == null && frame.isMaximizable()) {
  934. button = findChild(titlePane, "InternalFrameTitlePane.maximizeButton");
  935. }
  936. if (button == null && frame.isClosable()) {
  937. button = findChild(titlePane, "InternalFrameTitlePane.closeButton");
  938. }
  939. if (button != null) {
  940. titleWidth = Math.min(width, button.getX() - x0);
  941. }
  942. if (!active) {
  943. /*
  944. <frame focus="no" state="normal" resize="both" style="normal_unfocused"/>
  945. <piece position="entire_background" draw_ops="unfocus_background"/>
  946. <piece position="title" draw_ops="title_normal"/>
  947. */
  948. unfocus_background(g, width, height);
  949. g.translate(titleX, 1);
  950. title_normal(g, titleWidth, titlePane.getHeight()-1, frame);
  951. g.translate(-titleX, -1);
  952. } else {
  953. /*
  954. <frame focus="yes" state="normal" resize="both" style="normal_focused"/>
  955. <piece position="entire_background" draw_ops="focus_background"/>
  956. <piece position="title" draw_ops="title_focused"/>
  957. */
  958. focus_background(g, width, height);
  959. g.translate(titleX, 1);
  960. title_focused(g, titleWidth, titlePane.getHeight()-1, frame);
  961. g.translate(-titleX, -1);
  962. }
  963. // g.setClip(oldClip);
  964. g.translate(-x0, -y0);
  965. g.setFont(oldFont);
  966. }
  967. Insets getBorderInsets(SynthContext context, Insets insets) {
  968. FrameGeometry gm = getFrameGeometry();
  969. if (insets == null) {
  970. insets = new Insets(0, 0, 0, 0);
  971. }
  972. insets.top = gm.title_border.top;
  973. insets.bottom = gm.bottom_height;
  974. insets.left = gm.left_width;
  975. insets.right = gm.right_width;
  976. return insets;
  977. }
  978. private HashMap images = new HashMap();
  979. private Image getImage(String key, Color c) {
  980. Image image = (Image)images.get(key+"-"+c.getRGB());
  981. if (image == null) {
  982. image = colorizeImage(getImage(key), c);
  983. if (image != null) {
  984. images.put(key+"-"+c.getRGB(), image);
  985. }
  986. }
  987. return image;
  988. }
  989. private Image getImage(String key) {
  990. Image image = (Image)images.get(key);
  991. if (image == null) {
  992. if (themeDir != null) {
  993. final String file = themeDir + File.separator + key + ".png";
  994. image = (Image)AccessController.doPrivileged(new PrivilegedAction() {
  995. public Object run() {
  996. return new ImageIcon(file).getImage();
  997. }
  998. });
  999. } else {
  1000. String filename = "resources/metacity/"+key+".png";
  1001. URL url = getClass().getResource(filename);
  1002. if (url != null) {
  1003. image = new ImageIcon(url).getImage();
  1004. }
  1005. }
  1006. if (image != null) {
  1007. images.put(key, image);
  1008. }
  1009. }
  1010. return image;
  1011. }
  1012. private void drawImage(Graphics g, Image im, Color colorize, float alpha, int x, int y) {
  1013. if (g instanceof Graphics2D) {
  1014. Graphics2D g2 = (Graphics2D)g;
  1015. Composite oldComp = g2.getComposite();
  1016. g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
  1017. g2.drawImage(im, x, y, null);
  1018. g2.setComposite(oldComp);
  1019. }
  1020. }
  1021. }