1. /*
  2. * @(#)GTKPainter.java 1.58 04/01/13
  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 java.awt.*;
  9. import javax.swing.*;
  10. import javax.swing.border.*;
  11. import javax.swing.plaf.*;
  12. /**
  13. * @version 1.58, 01/13/04
  14. * @author Joshua Outwater
  15. * @author Scott Violet
  16. */
  17. // Need to support:
  18. // default_outside_border: Insets when default.
  19. // interior_focus: Indicates if focus should appear inside border, or
  20. // outside border.
  21. // focus-line-width: Integer giving size of focus border
  22. // focus-padding: Integer giving padding between border and focus
  23. // indicator.
  24. // focus-line-pattern:
  25. //
  26. class GTKPainter extends SynthPainter {
  27. static final GTKPainter INSTANCE = new GTKPainter();
  28. static final Insets EMPTY_INSETS = new Insets(0, 0, 0, 0);
  29. private static final Insets TEMP_INSETS = new Insets(0, 0, 0, 0);
  30. /**
  31. * Space for the default border.
  32. */
  33. private static final Insets BUTTON_DEFAULT_BORDER_INSETS =
  34. new Insets(1, 1, 1, 1);
  35. public void paint(SynthContext context, Object paintKey, Graphics g,
  36. int x, int y, int w, int h) {
  37. Region id = context.getRegion();
  38. String name = (id.isSubregion()) ? null :
  39. context.getComponent().getName();
  40. GTKEngine engine = ((GTKStyle)context.getStyle()).getEngine(context);
  41. if (paintKey == "background") {
  42. if (!id.isSubregion()) {
  43. // Offset by the insets, if necessary.
  44. Border border = context.getComponent().getBorder();
  45. if (border != null && !(border instanceof UIResource)) {
  46. Insets insets = context.getComponent().getInsets(
  47. TEMP_INSETS);
  48. if (insets != null) {
  49. x += insets.left;
  50. y += insets.right;
  51. w -= (insets.left + insets.right);
  52. h -= (insets.top + insets.bottom);
  53. }
  54. }
  55. }
  56. if (id == Region.ARROW_BUTTON) {
  57. paintArrowButtonBackground(context, engine, g, x, y, w, h);
  58. }
  59. else if (id == Region.BUTTON) {
  60. if (name != null &&
  61. name.startsWith("InternalFrameTitlePane.")) {
  62. Metacity.INSTANCE.paintButtonBackground(context,
  63. g, x, y, w, h);
  64. } else {
  65. paintButtonBackground(context, engine, g, x, y, w, h,
  66. "button");
  67. }
  68. }
  69. else if (id == Region.FORMATTED_TEXT_FIELD) {
  70. paintTextFieldBackground(context, engine, g, x, y, w, h);
  71. }
  72. else if (id == Region.LABEL) {
  73. if ("TableHeader.renderer" == name ||
  74. name == "GTKFileChooser.directoryListLabel" ||
  75. name == "GTKFileChooser.fileListLabel") {
  76. paintButtonBackground(context, engine, g, x, y, w, h,
  77. "button");
  78. }
  79. else if (name == "ComboBox.renderer") {
  80. paintTextFieldBackground(context, engine, g, x, y, w, h);
  81. }
  82. }
  83. else if (id == Region.LIST) {
  84. paintListBackground(context, engine, g, x, y, w, h);
  85. }
  86. else if (id == Region.MENU) {
  87. paintMenuBackground(context, engine, g, x, y, w, h);
  88. }
  89. else if (id == Region.MENU_BAR) {
  90. paintMenuBarBackground(context, engine, g, x, y, w, h);
  91. }
  92. else if (id == Region.MENU_ITEM) {
  93. paintMenuItemBackground(context, engine, g, x, y, w, h);
  94. }
  95. else if (id == Region.POPUP_MENU) {
  96. paintPopupMenuBackground(context, engine, g, x, y, w, h);
  97. }
  98. else if (id == Region.PROGRESS_BAR) {
  99. paintProgressBarBackground(context, engine, g, x, y, w, h);
  100. }
  101. else if (id == Region.CHECK_BOX || id == Region.RADIO_BUTTON) {
  102. paintCheckButtonBackground(context, engine, g, x, y, w, h);
  103. }
  104. else if (id == Region.CHECK_BOX_MENU_ITEM
  105. || id == Region.RADIO_BUTTON_MENU_ITEM) {
  106. paintCheckButtonMenuItemBackground(context, engine, g,
  107. x, y, w, h);
  108. }
  109. else if (id == Region.ROOT_PANE) {
  110. paintRootPaneBackground(context, engine, g, x, y, w, h);
  111. }
  112. else if (id == Region.SCROLL_BAR) {
  113. paintScrollBarBackground(context, engine, g, x, y, w, h);
  114. }
  115. else if (id == Region.SCROLL_BAR_THUMB) {
  116. paintScrollBarThumbBackground(context, engine, g, x, y, w, h);
  117. }
  118. /*
  119. else if (id == Region.SCROLL_PANE) {
  120. paintScrollPaneBackground(context, engine, g, x, y, w, h);
  121. }
  122. */
  123. else if (id == Region.SEPARATOR) {
  124. paintSeparatorBackground(context, engine, g, x, y, w, h);
  125. }
  126. else if (id == Region.SLIDER_TRACK) {
  127. paintSliderTrackBackground(context, engine, g, x, y, w, h);
  128. }
  129. else if (id == Region.SLIDER_THUMB) {
  130. paintSliderThumbBackground(context, engine, g, x, y, w, h);
  131. }
  132. else if (id == Region.SPINNER) {
  133. paintSpinnerBackground(context, engine, g, x, y, w, h);
  134. }
  135. else if (id == Region.SPLIT_PANE_DIVIDER) {
  136. paintSplitPaneDividerBackground(context, engine, g, x, y, w, h);
  137. }
  138. else if (id == Region.TABBED_PANE_CONTENT) {
  139. paintTabbedPaneContentBackground(context,
  140. engine, g, x, y, w, h);
  141. }
  142. else if (id == Region.TABBED_PANE_TAB) {
  143. paintTabbedPaneTabBackground(context, engine, g, x, y, w, h);
  144. }
  145. else if (id == Region.TEXT_AREA) {
  146. paintTextAreaBackground(context, engine, g, x, y, w, h);
  147. }
  148. else if (id == Region.TEXT_FIELD) {
  149. if (name == "Tree.cellEditor") {
  150. paintTreeCellEditorBackground(context, engine, g, x, y, w,
  151. h);
  152. }
  153. else {
  154. paintTextFieldBackground(context, engine, g, x, y, w, h);
  155. }
  156. }
  157. else if (id == Region.TOGGLE_BUTTON) {
  158. paintToggleButtonBackground(context, engine, g, x, y, w, h);
  159. }
  160. else if (id == Region.TOOL_BAR ||
  161. id == Region.TOOL_BAR_DRAG_WINDOW) {
  162. paintToolBarBackground(context, engine, g, x, y, w, h);
  163. }
  164. else if (id == Region.TOOL_BAR_CONTENT) {
  165. paintToolBarContentBackground(context, engine, g, x, y, w, h);
  166. }
  167. else if (id == Region.TOOL_TIP) {
  168. paintToolTipBackground(context, engine, g, x, y, w, h);
  169. }
  170. else if (id == Region.TREE) {
  171. paintTreeBackground(context, engine, g, x, y, w, h);
  172. }
  173. else if (id == Region.TREE_CELL) {
  174. paintTreeCellBackground(context, engine, g, x, y, w, h);
  175. }
  176. else if (id == Region.VIEWPORT) {
  177. paintViewportBackground(context, engine, g, x, y, w, h);
  178. }
  179. } else if (paintKey == "border") {
  180. if (id == Region.INTERNAL_FRAME) {
  181. Metacity.INSTANCE.paintFrameBorder(context, g, x, y, w, h);
  182. }
  183. else if (id == Region.VIEWPORT) {
  184. paintScrollPaneBackground(context, engine, g, x, y, w, h);
  185. }
  186. }
  187. else if (paintKey == "foreground") {
  188. if (id == Region.ARROW_BUTTON) {
  189. paintArrowButtonForeground(context, engine, g, x, y, w, h);
  190. }
  191. else if (id == Region.PROGRESS_BAR) {
  192. paintProgressBarForeground(context, engine, g, x, y, w, h);
  193. }
  194. else if (id == Region.SPLIT_PANE_DIVIDER) {
  195. paintSplitPaneDividerDragBackground(context, engine, g, x, y,
  196. w,h);
  197. }
  198. }
  199. else if (paintKey == "focus") {
  200. if (id == Region.TREE_CELL) {
  201. paintTreeCellFocus(context, engine, g, x, y, w, h);
  202. }
  203. }
  204. }
  205. Insets getInsets(SynthContext state, Insets insets) {
  206. Region id = state.getRegion();
  207. String name = (id.isSubregion()) ? null :
  208. state.getComponent().getName();
  209. if (insets == null) {
  210. insets = new Insets(0, 0, 0, 0);
  211. }
  212. else {
  213. insets.top = insets.bottom = insets.left = insets.right = 0;
  214. }
  215. if (id == Region.BUTTON || id == Region.TOGGLE_BUTTON
  216. || id == Region.CHECK_BOX || id == Region.RADIO_BUTTON
  217. || id == Region.ARROW_BUTTON || id == Region.TOGGLE_BUTTON
  218. || id == Region.MENU
  219. || id == Region.MENU_ITEM
  220. || id == Region.RADIO_BUTTON_MENU_ITEM
  221. || id == Region.CHECK_BOX_MENU_ITEM) {
  222. if ("Spinner.previousButton" == name ||
  223. "Spinner.nextButton" == name) {
  224. return getSpinnerButtonInsets(state, insets);
  225. } else {
  226. return getButtonInsets(state, insets);
  227. }
  228. }
  229. else if (id == Region.FORMATTED_TEXT_FIELD) {
  230. return getTextFieldInsets(state, insets);
  231. }
  232. else if (id == Region.INTERNAL_FRAME) {
  233. insets = Metacity.INSTANCE.getBorderInsets(state, insets);
  234. }
  235. else if (id == Region.LABEL) {
  236. if ("TableHeader.renderer" == name) {
  237. return getButtonInsets(state, insets);
  238. }
  239. else if ("ComboBox.renderer" == name) {
  240. return getTextFieldInsets(state, insets);
  241. }
  242. else if ("Tree.cellRenderer" == name) {
  243. return getTreeCellRendererInsets(state, insets);
  244. }
  245. }
  246. else if (id == Region.MENU_BAR) {
  247. return getMenuBarInsets(state, insets);
  248. }
  249. else if (id == Region.OPTION_PANE) {
  250. return getOptionPaneInsets(state, insets);
  251. }
  252. else if (id == Region.POPUP_MENU) {
  253. return getPopupMenuInsets(state, insets);
  254. }
  255. else if (id == Region.PROGRESS_BAR) {
  256. return getProgressBarInsets(state, insets);
  257. }
  258. else if (id == Region.SCROLL_BAR) {
  259. return getScrollBarInsets(state, insets);
  260. }
  261. else if (id == Region.SEPARATOR) {
  262. return getSeparatorInsets(state, insets);
  263. }
  264. else if (id == Region.SLIDER) {
  265. return getSliderInsets(state, insets);
  266. }
  267. else if (id == Region.SLIDER_TRACK) {
  268. return getSliderTrackInsets(state, insets);
  269. }
  270. else if (id == Region.SPINNER) {
  271. return getSpinnerInsets(state, insets);
  272. }
  273. else if (id == Region.TABBED_PANE) {
  274. return getTabbedPaneInsets(state, insets);
  275. }
  276. else if (id == Region.TABBED_PANE_CONTENT) {
  277. return getTabbedPaneContentInsets(state, insets);
  278. }
  279. else if (id == Region.TABBED_PANE_TAB) {
  280. return getTabbedPaneTabInsets(state, insets);
  281. }
  282. else if (id == Region.TEXT_FIELD) {
  283. if (name == "Tree.cellEditor") {
  284. return getTreeCellEditorInsets(state, insets);
  285. }
  286. return getTextFieldInsets(state, insets);
  287. }
  288. else if (id == Region.TOOL_BAR) {
  289. return getToolBarInsets(state, insets);
  290. }
  291. else if (id == Region.TOOL_TIP) {
  292. return getToolTipInsets(state, insets);
  293. }
  294. return insets;
  295. }
  296. //
  297. // BUTTON
  298. //
  299. private Insets getButtonInsets(SynthContext context, Insets insets) {
  300. GTKStyle style = (GTKStyle)context.getStyle();
  301. int focusSize = style.getClassSpecificIntValue(context,
  302. "focus-line-width",1);
  303. int focusPad = style.getClassSpecificIntValue(context,
  304. "focus-padding", 1);
  305. int xThickness = style.getXThickness();
  306. int yThickness = style.getYThickness();
  307. int w = focusSize + focusPad + xThickness;
  308. int h = focusSize + focusPad + yThickness;
  309. Component component = context.getComponent();
  310. insets.left = insets.right = w;
  311. insets.top = insets.bottom = h;
  312. if ((component instanceof JButton) &&
  313. ((JButton)component).isDefaultCapable()) {
  314. Insets defaultInsets = style.getClassSpecificInsetsValue(context,
  315. "default-border", BUTTON_DEFAULT_BORDER_INSETS);
  316. insets.left += defaultInsets.left;
  317. insets.right += defaultInsets.right;
  318. insets.top += defaultInsets.top;
  319. insets.bottom += defaultInsets.bottom;
  320. }
  321. return insets;
  322. }
  323. private void paintButtonBackground(SynthContext context, GTKEngine engine,
  324. Graphics g, int x, int y, int w, int h,
  325. String detail) {
  326. // paing the default shadow
  327. int state = context.getComponentState();
  328. int gtkState = GTKLookAndFeel.synthStateToGTKState(
  329. context.getRegion(), state);
  330. GTKStyle style = (GTKStyle)context.getStyle();
  331. boolean interiorFocus = style.getClassSpecificBoolValue(context,
  332. "interior-focus", true);
  333. int focusSize = style.getClassSpecificIntValue(context,
  334. "focus-line-width",1);
  335. int focusPad = style.getClassSpecificIntValue(context, "focus-padding",
  336. 1);
  337. int totalFocusSize = focusSize + focusPad;
  338. int xThickness = style.getXThickness();
  339. int yThickness = style.getYThickness();
  340. Component component = context.getComponent();
  341. // Paint the default indicator
  342. if ((component instanceof JButton) &&
  343. ((JButton)component).isDefaultCapable()) {
  344. Insets defaultInsets = (Insets)style.getClassSpecificInsetsValue(
  345. context, "default-border", BUTTON_DEFAULT_BORDER_INSETS);
  346. if ((state & SynthConstants.DEFAULT) == SynthConstants.DEFAULT) {
  347. engine.paintBox(context, g, SynthConstants.ENABLED,
  348. GTKConstants.SHADOW_IN, "buttondefault",
  349. x, y, w, h);
  350. }
  351. x += defaultInsets.left;
  352. y += defaultInsets.top;
  353. w -= (defaultInsets.left + defaultInsets.right);
  354. h -= (defaultInsets.top + defaultInsets.bottom);
  355. }
  356. // Render the box.
  357. if (!interiorFocus && (state & SynthConstants.FOCUSED) ==
  358. SynthConstants.FOCUSED) {
  359. x += totalFocusSize;
  360. y += totalFocusSize;
  361. w -= 2 * totalFocusSize;
  362. h -= 2 * totalFocusSize;
  363. }
  364. if (!(component.getParent() instanceof JToolBar) ||
  365. gtkState != SynthConstants.ENABLED) {
  366. int shadowType;
  367. if ((state & SynthConstants.PRESSED) == SynthConstants.PRESSED) {
  368. shadowType = GTKConstants.SHADOW_IN;
  369. }
  370. else {
  371. shadowType = GTKConstants.SHADOW_OUT;
  372. }
  373. engine.paintBox(context, g, gtkState, shadowType, detail,
  374. x, y, w, h);
  375. }
  376. // focus
  377. if ((state & SynthConstants.FOCUSED) == SynthConstants.FOCUSED) {
  378. if (interiorFocus) {
  379. x += xThickness + focusPad;
  380. y += yThickness + focusPad;
  381. w -= 2 * (xThickness + focusPad);
  382. h -= 2 * (yThickness + focusPad);
  383. }
  384. else {
  385. x -= totalFocusSize;
  386. y -= totalFocusSize;
  387. w += 2 * totalFocusSize;
  388. h += 2 * totalFocusSize;
  389. }
  390. engine.paintFocus(context, g, gtkState, detail, x, y, w, h);
  391. }
  392. }
  393. //
  394. // ARROW_BUTTON
  395. //
  396. private void paintArrowButtonForeground(SynthContext context,
  397. GTKEngine engine, Graphics g,
  398. int x, int y, int w, int h) {
  399. int state = GTKLookAndFeel.synthStateToGTKState(
  400. Region.ARROW_BUTTON, context.getComponentState());
  401. int shadowType;
  402. if (state == SynthConstants.PRESSED) {
  403. shadowType = GTKConstants.SHADOW_IN;
  404. }
  405. else {
  406. shadowType = GTKConstants.SHADOW_OUT;
  407. }
  408. int direction = ((SynthArrowButton)context.getComponent()).
  409. getDirection();
  410. switch (direction) {
  411. case SwingConstants.NORTH:
  412. direction = GTKConstants.ARROW_UP;
  413. break;
  414. case SwingConstants.SOUTH:
  415. direction = GTKConstants.ARROW_DOWN;
  416. break;
  417. case SwingConstants.EAST:
  418. direction = GTKConstants.ARROW_RIGHT;
  419. break;
  420. case SwingConstants.WEST:
  421. direction = GTKConstants.ARROW_LEFT;
  422. break;
  423. }
  424. Component c = context.getComponent();
  425. String name = c.getName();
  426. String detail = "arrow";
  427. if (name == "ScrollBar.button") {
  428. if (c.getParent() instanceof JScrollBar) {
  429. if (((JScrollBar)c.getParent()).getOrientation() ==
  430. SwingConstants.HORIZONTAL) {
  431. detail = "hscrollbar";
  432. }
  433. else {
  434. detail = "vscrollbar";
  435. }
  436. }
  437. }
  438. else if (name == "Spinner.nextButton" ||
  439. name == "Spinner.previousButton") {
  440. detail = "spinbutton";
  441. }
  442. // Note quite sure what their algorithm is, but this works pretty
  443. // good.
  444. int size = Math.min(w / 2, h / 2);
  445. x += (w - size) / 2;
  446. y += (h - size) / 2;
  447. engine.paintArrow(context, g, state, shadowType, direction,
  448. detail, x, y, size, size);
  449. }
  450. private void paintArrowButtonBackground(SynthContext context,
  451. GTKEngine engine, Graphics g,
  452. int x, int y, int w, int h) {
  453. Component c = context.getComponent();
  454. String name = c.getName();
  455. String detail = "button";
  456. if (name == "ScrollBar.button") {
  457. if (c.getParent() instanceof JScrollBar) {
  458. if (((JScrollBar)c.getParent()).getOrientation() ==
  459. SwingConstants.HORIZONTAL) {
  460. detail = "hscrollbar";
  461. }
  462. else {
  463. detail = "vscrollbar";
  464. }
  465. }
  466. } else if ("Spinner.previousButton" == name ||
  467. "Spinner.nextButton" == name) {
  468. detail = "spinbutton";
  469. }
  470. paintButtonBackground(context, engine, g, x, y, w, h, detail);
  471. }
  472. //
  473. // CHECK_BUTTON
  474. //
  475. private void paintCheckButtonBackground(SynthContext context,
  476. GTKEngine engine, Graphics g,
  477. int x, int y, int w, int h) {
  478. int gtkState = GTKLookAndFeel.synthStateToGTKState(
  479. context.getRegion(), context.getComponentState());
  480. if ((gtkState & SynthConstants.MOUSE_OVER) != 0) {
  481. engine.paintFlatBoxNormal(context, g, SynthConstants.MOUSE_OVER,
  482. "checkbutton", x, y, w, h);
  483. }
  484. }
  485. //
  486. // CHECK_BUTTON_MENU_ITEM
  487. //
  488. public void paintCheckButtonMenuItemBackground(SynthContext context,
  489. GTKEngine engine, Graphics g,
  490. int x, int y, int w, int h) {
  491. int gtkState = GTKLookAndFeel.synthStateToGTKState(
  492. context.getRegion(), context.getComponentState());
  493. if ((context.getComponentState() & SynthConstants.MOUSE_OVER) != 0) {
  494. if (GTKLookAndFeel.is2_2()) {
  495. engine.paintBox(context, g, gtkState, GTKConstants.SHADOW_NONE,
  496. "menuitem", x, y, w, h);
  497. }
  498. else {
  499. engine.paintBox(context, g, gtkState, GTKConstants.SHADOW_OUT,
  500. "menuitem", x, y, w, h);
  501. }
  502. }
  503. }
  504. //
  505. // LIST
  506. //
  507. private void paintListBackground(SynthContext context,
  508. GTKEngine engine, Graphics g,
  509. int x, int y, int w, int h) {
  510. int state = GTKLookAndFeel.synthStateToGTKState(
  511. Region.LIST, context.getComponentState());
  512. if (context.getComponent().getName() == "ComboBox.list") {
  513. // Paint it's shadow.
  514. }
  515. engine.paintFlatBoxText(context, g, state, "base", x, y, w, h);
  516. }
  517. //
  518. // MENU_BAR
  519. //
  520. private Insets getMenuBarInsets(SynthContext context, Insets insets) {
  521. GTKStyle style = (GTKStyle)context.getStyle();
  522. int internalPadding = style.getClassSpecificIntValue(context,
  523. "internal-padding", 1);
  524. int xThickness = style.getXThickness();
  525. int yThickness = style.getYThickness();
  526. insets.top = insets.bottom = internalPadding + yThickness;
  527. insets.left = insets.right = internalPadding + xThickness;
  528. return insets;
  529. }
  530. private void paintMenuBarBackground(SynthContext context,
  531. GTKEngine engine, Graphics g,
  532. int x, int y, int w, int h) {
  533. GTKStyle style = (GTKStyle)context.getStyle();
  534. int shadowType = style.getClassSpecificIntValue(context,
  535. "shadow-type", GTKConstants.SHADOW_OUT);
  536. int gtkState = GTKLookAndFeel.synthStateToGTKState(
  537. context.getRegion(), context.getComponentState());
  538. engine.paintBox(context, g, gtkState, shadowType, "menubar",
  539. x, y, w, h);
  540. }
  541. //
  542. // MENU
  543. //
  544. private void paintMenuBackground(SynthContext context,
  545. GTKEngine engine, Graphics g,
  546. int x, int y, int w, int h) {
  547. int gtkState = GTKLookAndFeel.synthStateToGTKState(
  548. context.getRegion(), context.getComponentState());
  549. if (gtkState == SynthConstants.MOUSE_OVER) {
  550. if (GTKLookAndFeel.is2_2()) {
  551. engine.paintBox(context, g, gtkState, GTKConstants.SHADOW_NONE,
  552. "menuitem", x, y, w, h);
  553. }
  554. else {
  555. engine.paintBox(context, g, gtkState, GTKConstants.SHADOW_OUT,
  556. "menuitem", x, y, w, h);
  557. }
  558. }
  559. }
  560. //
  561. // MENU_ITEM
  562. //
  563. private Insets getMenuItemInsets(SynthContext context, Insets insets) {
  564. GTKStyle style = (GTKStyle)context.getStyle();
  565. int internalPadding = style.getClassSpecificIntValue(context,
  566. "internal-padding", 1);
  567. int xThickness = style.getXThickness();
  568. int yThickness = style.getYThickness();
  569. insets.top = insets.bottom = internalPadding + yThickness;
  570. insets.left = insets.right = internalPadding + xThickness;
  571. return insets;
  572. }
  573. private void paintMenuItemBackground(SynthContext context,
  574. GTKEngine engine, Graphics g,
  575. int x, int y, int w, int h) {
  576. int gtkState = GTKLookAndFeel.synthStateToGTKState(
  577. context.getRegion(), context.getComponentState());
  578. if ((context.getComponentState() & SynthConstants.MOUSE_OVER) != 0) {
  579. if (GTKLookAndFeel.is2_2()) {
  580. engine.paintBox(context, g, gtkState, GTKConstants.SHADOW_NONE,
  581. "menuitem", x, y, w, h);
  582. }
  583. else {
  584. engine.paintBox(context, g, gtkState, GTKConstants.SHADOW_OUT,
  585. "menuitem", x, y, w, h);
  586. }
  587. }
  588. }
  589. private Insets getPopupMenuInsets(SynthContext context, Insets insets) {
  590. insets.left = insets.right = insets.top = insets.bottom = 2;
  591. return insets;
  592. }
  593. private void paintPopupMenuBackground(SynthContext context,
  594. GTKEngine engine, Graphics g,
  595. int x, int y, int w, int h) {
  596. int gtkState = GTKLookAndFeel.synthStateToGTKState(
  597. context.getRegion(), context.getComponentState());
  598. engine.paintBox(context, g, gtkState, GTKConstants.SHADOW_OUT,
  599. "menu", x, y, w, h);
  600. GTKStyle style = (GTKStyle)context.getStyle();
  601. int xThickness = style.getXThickness();
  602. int yThickness = style.getYThickness();
  603. engine.paintBackground(context, g, gtkState, style.getGTKColor(
  604. context.getComponent(), context.getRegion(), gtkState,
  605. GTKColorType.BACKGROUND), x + xThickness, y + yThickness,
  606. w - xThickness - xThickness, h - yThickness - yThickness);
  607. }
  608. //
  609. // PROGRESS_BAR
  610. //
  611. private Insets getProgressBarInsets(SynthContext context, Insets insets) {
  612. GTKStyle style = (GTKStyle)context.getStyle();
  613. insets.left = insets.right = style.getXThickness();
  614. insets.top = insets.bottom = style.getYThickness();
  615. return insets;
  616. }
  617. private void paintProgressBarBackground(SynthContext context,
  618. GTKEngine engine, Graphics g,
  619. int x, int y, int w, int h) {
  620. GTKStyle style = (GTKStyle)context.getStyle();
  621. // Draw the trough.
  622. engine.paintBox(context, g, SynthConstants.ENABLED,
  623. GTKConstants.SHADOW_IN, "trough", x, y, w, h);
  624. }
  625. private void paintProgressBarForeground(SynthContext context,
  626. GTKEngine engine, Graphics g,
  627. int x, int y, int w, int h) {
  628. // Draw the actual progress of the progress bar.
  629. if (w != 0 || h != 0) {
  630. engine.paintBox(context, g, SynthConstants.MOUSE_OVER,
  631. GTKConstants.SHADOW_OUT, "bar", x, y, w, h);
  632. }
  633. }
  634. private void paintScrollPaneBackground(SynthContext context,
  635. GTKEngine engine, Graphics g,
  636. int x, int y, int w, int h) {
  637. engine.paintShadow(context, g, SynthConstants.ENABLED,
  638. GTKConstants.SHADOW_IN, "scrolled_window",
  639. x, y, w, h);
  640. }
  641. Insets getScrollPaneInsets(SynthContext context, Insets insets) {
  642. GTKStyle style = (GTKStyle)context.getStyle();
  643. insets.right = insets.left = style.getXThickness();
  644. insets.top = insets.bottom = style.getYThickness();
  645. return insets;
  646. }
  647. //
  648. // SEPARATOR
  649. //
  650. private Insets getSeparatorInsets(SynthContext context, Insets insets) {
  651. return insets;
  652. }
  653. private void paintSeparatorBackground(SynthContext context,
  654. GTKEngine engine, Graphics g,
  655. int x, int y, int w, int h) {
  656. if (((JSeparator)context.getComponent()).getOrientation() ==
  657. JSeparator.HORIZONTAL) {
  658. engine.paintHline(context, g, SynthConstants.ENABLED,
  659. "hseparator", x, y, w, h);
  660. } else {
  661. engine.paintVline(context, g, SynthConstants.ENABLED,
  662. "vseparator", x, y, w, h);
  663. }
  664. }
  665. //
  666. // SLIDER
  667. //
  668. private Insets getSliderInsets(SynthContext context, Insets insets) {
  669. GTKStyle style = (GTKStyle)context.getStyle();
  670. int xThickness = style.getXThickness();
  671. int yThickness = style.getYThickness();
  672. insets.top = insets.bottom = yThickness;
  673. insets.right = insets.left = xThickness;
  674. return insets;
  675. }
  676. private Insets getSliderTrackInsets(SynthContext context, Insets insets) {
  677. GTKStyle style = (GTKStyle)context.getStyle();
  678. int focusSize = style.getClassSpecificIntValue(context,
  679. "focus-line-width", 1);
  680. int focusPad = style.getClassSpecificIntValue(context,
  681. "focus-padding", 1);
  682. insets.top = insets.bottom = insets.left = insets.right =
  683. focusSize + focusPad;
  684. return insets;
  685. }
  686. private void paintSliderTrackBackground(SynthContext context,
  687. GTKEngine engine, Graphics g,
  688. int x, int y, int w,int h) {
  689. GTKStyle style = (GTKStyle)context.getStyle();
  690. int state = context.getComponentState();
  691. int gtkState = GTKLookAndFeel.synthStateToGTKState(context.getRegion(),
  692. state);
  693. engine.paintBox(context, g, gtkState,
  694. GTKConstants.SHADOW_IN, "trough", x, y, w, h);
  695. if ((state & SynthConstants.FOCUSED) == SynthConstants.FOCUSED) {
  696. int focusSize = style.getClassSpecificIntValue(context,
  697. "focus-line-width", 1);
  698. focusSize += style.getClassSpecificIntValue(context,
  699. "focus-padding", 1);
  700. x -= focusSize;
  701. y -= focusSize;
  702. w += 2 * focusSize;
  703. h += 2 * focusSize;
  704. engine.paintFocus(context, g, SynthConstants.ENABLED,
  705. "trough", x, y, w, h);
  706. }
  707. }
  708. private void paintSliderThumbBackground(SynthContext context,
  709. GTKEngine engine, Graphics g,
  710. int x, int y, int w, int h) {
  711. int orientation;
  712. if (((JSlider)context.getComponent()).getOrientation() ==
  713. JSlider.HORIZONTAL) {
  714. orientation = GTKConstants.HORIZONTAL;
  715. }
  716. else {
  717. orientation = GTKConstants.VERTICAL;
  718. }
  719. engine.paintSlider(context, g, GTKLookAndFeel.synthStateToGTKState(
  720. context.getRegion(), context.getComponentState()),
  721. GTKConstants.SHADOW_OUT, "slider", x, y, w, h, orientation);
  722. }
  723. //
  724. // SPINNER
  725. //
  726. private void paintSpinnerBackground(SynthContext context,
  727. GTKEngine engine, Graphics g,
  728. int x, int y, int w, int h) {
  729. // This is handled in paintTextFieldBackground
  730. }
  731. private Insets getSpinnerInsets(SynthContext context, Insets insets) {
  732. // Spinner's have no insets, the text field gets the insets.
  733. return insets;
  734. }
  735. private Insets getSpinnerButtonInsets(SynthContext context, Insets insets) {
  736. insets.top = insets.bottom = 1;
  737. insets.right = insets.left = 1;
  738. return insets;
  739. }
  740. //
  741. // SPLIT_PANE_DIVIDER
  742. //
  743. private void paintSplitPaneDividerBackground(SynthContext context,
  744. GTKEngine engine, Graphics g,
  745. int x, int y, int w, int h) {
  746. int orientation;
  747. if (((JSplitPane)context.getComponent()).getOrientation() ==
  748. JSplitPane.VERTICAL_SPLIT) {
  749. orientation = GTKConstants.HORIZONTAL;
  750. }
  751. else {
  752. orientation = GTKConstants.VERTICAL;
  753. }
  754. engine.paintHandle(context, g, GTKLookAndFeel.synthStateToGTKState(
  755. context.getRegion(), context.getComponentState()),
  756. GTKConstants.UNDEFINED, "paned", x, y, w, h, orientation);
  757. }
  758. private void paintSplitPaneDividerDragBackground(SynthContext context,
  759. GTKEngine engine, Graphics g,
  760. int x, int y, int w, int h) {
  761. g.setColor(context.getStyle().getColor(context,
  762. GTKColorType.BACKGROUND));
  763. g.fillRect(x, y, w, h);
  764. paintSplitPaneDividerBackground(context, engine, g, x, y, w, h);
  765. }
  766. //
  767. // TABBED_PANE
  768. //
  769. private Insets getTabbedPaneInsets(SynthContext context, Insets insets) {
  770. GTKStyle style = (GTKStyle)context.getStyle();
  771. int xThickness = style.getXThickness();
  772. int yThickness = style.getYThickness();
  773. insets.top = insets.bottom = yThickness;
  774. insets.right = insets.left = xThickness;
  775. return insets;
  776. }
  777. //
  778. // TABBED_PANE_CONTENT
  779. //
  780. private Insets getTabbedPaneContentInsets(SynthContext context,
  781. Insets insets) {
  782. GTKStyle style = (GTKStyle)context.getStyle();
  783. int xThickness = style.getXThickness();
  784. int yThickness = style.getYThickness();
  785. insets.top = insets.bottom = yThickness;
  786. insets.right = insets.left = xThickness;
  787. return insets;
  788. }
  789. private void paintTabbedPaneContentBackground(SynthContext context,
  790. GTKEngine engine, Graphics g,
  791. int x, int y, int w, int h) {
  792. JTabbedPane tabPane = (JTabbedPane)context.getComponent();
  793. GTKStyle style = (GTKStyle)context.getStyle();
  794. Region region = context.getRegion();
  795. int placement = GTKLookAndFeel.SwingOrientationConstantToGTK(
  796. tabPane.getTabPlacement());
  797. int start = 0;
  798. int size = 0;
  799. int selectedIndex = tabPane.getSelectedIndex();
  800. if (selectedIndex != -1) {
  801. Rectangle tabBounds = tabPane.getBoundsAt(selectedIndex);
  802. if (placement == GTKConstants.TOP ||
  803. placement == GTKConstants.BOTTOM) {
  804. start = tabBounds.x - 1;
  805. size = tabBounds.width;
  806. }
  807. else {
  808. start = tabBounds.y - 1;
  809. size = tabBounds.height;
  810. }
  811. }
  812. engine.paintBoxGap(context, g, GTKLookAndFeel.synthStateToGTKState(
  813. context.getRegion(), context.getComponentState()),
  814. GTKConstants.SHADOW_OUT, "notebook", x, y, w, h,
  815. placement, start, size);
  816. }
  817. //
  818. // TABBED_PANE_TAB
  819. //
  820. private Insets getTabbedPaneTabInsets(SynthContext context,
  821. Insets insets) {
  822. GTKStyle style = (GTKStyle)context.getStyle();
  823. int xThickness = style.getXThickness();
  824. int yThickness = style.getYThickness();
  825. int focusSize = 0;
  826. int pad = 2;
  827. focusSize = style.getClassSpecificIntValue(context,
  828. "focus-line-width",1);
  829. insets.left = insets.right = focusSize + pad + xThickness;
  830. insets.top = insets.bottom = focusSize + pad + yThickness;
  831. return insets;
  832. }
  833. private void paintTabbedPaneTabBackground(SynthContext context,
  834. GTKEngine engine, Graphics g,
  835. int x, int y, int w, int h) {
  836. GTKStyle style = (GTKStyle)context.getStyle();
  837. int state = context.getComponentState();
  838. int tabIndex = ((TabContext)context).getTabIndex();
  839. int selectedIndex = ((JTabbedPane)context.getComponent()).
  840. getSelectedIndex();
  841. int offset = (selectedIndex == tabIndex) ? 0 : 2;
  842. int side;
  843. state = GTKLookAndFeel.synthStateToGTKState(context.getRegion(), state);
  844. switch (((JTabbedPane)context.getComponent()).getTabPlacement()) {
  845. case SwingConstants.TOP:
  846. side = GTKConstants.BOTTOM;
  847. y += offset;
  848. h -= offset;
  849. break;
  850. case SwingConstants.BOTTOM:
  851. h -= offset;
  852. side = GTKConstants.TOP;
  853. break;
  854. case SwingConstants.LEFT:
  855. x += offset;
  856. w -= offset;
  857. side = GTKConstants.RIGHT;
  858. break;
  859. default:
  860. w -= offset;
  861. side = GTKConstants.LEFT;
  862. break;
  863. }
  864. engine.paintExtension(context, g, state, GTKConstants.SHADOW_OUT,
  865. "tab", x, y, w, h, side);
  866. }
  867. //
  868. // TEXT_AREA
  869. //
  870. private void paintTextAreaBackground(SynthContext context,
  871. GTKEngine engine, Graphics g,
  872. int x, int y, int w, int h) {
  873. GTKStyle style = (GTKStyle)context.getStyle();
  874. int state = context.getComponentState();
  875. engine.paintFlatBoxText(context, g, state, "base", x, y, w, h);
  876. }
  877. //
  878. // TEXT_FIELD
  879. //
  880. // NOTE: comobobox and FormattedTextField calls this too.
  881. private void paintTextFieldBackground(SynthContext context,
  882. GTKEngine engine, Graphics g,
  883. int x, int y, int w, int h) {
  884. GTKStyle style = (GTKStyle)context.getStyle();
  885. boolean interiorFocus = style.getClassSpecificBoolValue(context,
  886. "interior-focus", true);
  887. int state = context.getComponentState();
  888. int gtkState = GTKLookAndFeel.synthStateToGTKState(
  889. context.getRegion(), state);
  890. int focusSize;
  891. int xThickness = style.getXThickness();
  892. int yThickness = style.getYThickness();
  893. paintTextBackground(context, engine, g, x, y, w, h);
  894. state = GTKLookAndFeel.synthStateToGTKState(context.getRegion(),state);
  895. if (!interiorFocus && (state & SynthConstants.FOCUSED) ==
  896. SynthConstants.FOCUSED) {
  897. focusSize = style.getClassSpecificIntValue(context,
  898. "focus-line-width",1);
  899. x += focusSize;
  900. y += focusSize;
  901. w -= 2 * focusSize;
  902. h -= 2 * focusSize;
  903. }
  904. else {
  905. focusSize = 0;
  906. }
  907. engine.paintShadow(context, g, SynthConstants.ENABLED,
  908. GTKConstants.SHADOW_IN, "entry", x, y, w, h);
  909. g.setColor(style.getGTKColor(context.getComponent(),
  910. context.getRegion(), SynthConstants.ENABLED,
  911. GTKColorType.TEXT_BACKGROUND));
  912. g.fillRect(x + xThickness, y + yThickness, w - (2 * xThickness),
  913. h - (2 * yThickness));
  914. engine.paintFlatBoxText(context, g, SynthConstants.ENABLED, "entry_bg",
  915. x + xThickness, y + yThickness, w - (2 * xThickness),
  916. h - (2 * yThickness));
  917. if (focusSize > 0) {
  918. x -= focusSize;
  919. y -= focusSize;
  920. w += 2 * focusSize;
  921. h += 2 * focusSize;
  922. engine.paintFocus(context, g, gtkState, "entry", x, y, w, h);
  923. }
  924. }
  925. // NOTE: this is called for ComboBox, and FormattedTextField. too.
  926. private Insets getTextFieldInsets(SynthContext context, Insets insets) {
  927. GTKStyle style = (GTKStyle)context.getStyle();
  928. int xThickness = style.getXThickness();
  929. int yThickness = style.getYThickness();
  930. boolean interiorFocus = style.getClassSpecificBoolValue(context,
  931. "interior-focus", true);
  932. int focusSize = 0;
  933. int pad = 2;
  934. if (!interiorFocus) {
  935. focusSize = style.getClassSpecificIntValue(context,
  936. "focus-line-width",1);
  937. }
  938. insets.left = insets.right = focusSize + pad + xThickness;
  939. insets.top = insets.bottom = focusSize + pad + yThickness;
  940. return insets;
  941. }
  942. private void paintTextBackground(SynthContext context,
  943. GTKEngine engine, Graphics g,
  944. int x, int y, int w,int h) {
  945. // Text is odd, the background is filled in with
  946. // TEXT_BACKGROUND
  947. JComponent c = context.getComponent();
  948. // Text is odd in that it uses the TEXT_BACKGROUND vs BACKGROUND.
  949. if (c.isOpaque() && c.getBackground() instanceof ColorUIResource) {
  950. g.setColor(((GTKStyle)context.getStyle()).getGTKColor(
  951. context.getComponent(), context.getRegion(),
  952. SynthConstants.ENABLED, GTKColorType.TEXT_BACKGROUND));
  953. g.fillRect(x, y, w, h);
  954. }
  955. }
  956. //
  957. // OPTION_Pane
  958. //
  959. private Insets getOptionPaneInsets(SynthContext context, Insets insets) {
  960. insets.left = insets.right = insets.top = insets.bottom = 6;
  961. return insets;
  962. }
  963. //
  964. // TOGGLE_BUTTON
  965. //
  966. public void paintToggleButtonBackground(SynthContext context,
  967. GTKEngine engine, Graphics g,
  968. int x, int y, int w, int h) {
  969. int state = context.getComponentState();
  970. int gtkState = GTKLookAndFeel.synthStateToGTKState(context.getRegion(),
  971. state);
  972. GTKStyle style = (GTKStyle)context.getStyle();
  973. boolean interiorFocus = style.getClassSpecificBoolValue(context,
  974. "interior-focus", true);
  975. int focusSize = style.getClassSpecificIntValue(context,
  976. "focus-line-width",1);
  977. int focusPad = style.getClassSpecificIntValue(context, "focus-padding",
  978. 1);
  979. int totalFocusSize = focusSize + focusPad;
  980. int xThickness = style.getXThickness();
  981. int yThickness = style.getYThickness();
  982. JToggleButton toggleButton = (JToggleButton)context.getComponent();
  983. if (!interiorFocus && (state & SynthConstants.FOCUSED) ==
  984. SynthConstants.FOCUSED) {
  985. x += totalFocusSize;
  986. y += totalFocusSize;
  987. w -= 2 * totalFocusSize;
  988. h -= 2 * totalFocusSize;
  989. }
  990. int shadow = GTKConstants.SHADOW_OUT;
  991. if (toggleButton.isSelected() ||
  992. ((state & SynthConstants.PRESSED) != 0)) {
  993. shadow = GTKConstants.SHADOW_IN;
  994. }
  995. engine.paintBox(context, g, gtkState, shadow, "button", x, y, w, h);
  996. // focus
  997. if ((state & SynthConstants.FOCUSED) == SynthConstants.FOCUSED) {
  998. if (interiorFocus) {
  999. x += xThickness + focusPad;
  1000. y += yThickness + focusPad;
  1001. w -= 2 * (xThickness + focusPad);
  1002. h -= 2 * (yThickness + focusPad);
  1003. }
  1004. else {
  1005. x -= totalFocusSize;
  1006. y -= totalFocusSize;
  1007. w += 2 * totalFocusSize;
  1008. h += 2 * totalFocusSize;
  1009. }
  1010. engine.paintFocus(context, g, gtkState, "button", x, y, w, h);
  1011. }
  1012. }
  1013. //
  1014. // ROOT_PANE
  1015. //
  1016. public void paintRootPaneBackground(SynthContext context,
  1017. GTKEngine engine, Graphics g,
  1018. int x, int y, int w, int h) {
  1019. int gtkState = GTKLookAndFeel.synthStateToGTKState(
  1020. context.getRegion(), context.getComponentState());
  1021. engine.paintFlatBoxNormal(context, g, gtkState, "base", x, y, w, h);
  1022. }
  1023. //
  1024. // SCROLL_BAR
  1025. //
  1026. private void paintScrollBarBackground(SynthContext context,
  1027. GTKEngine engine, Graphics g,
  1028. int x, int y, int w,int h) {
  1029. GTKStyle style = (GTKStyle)context.getStyle();
  1030. int state = context.getComponentState();
  1031. int gtkState = GTKLookAndFeel.synthStateToGTKState(context.getRegion(),
  1032. state);
  1033. int focusSize = style.getClassSpecificIntValue(context,
  1034. "focus-line-width",1);
  1035. int focusPad = style.getClassSpecificIntValue(context,
  1036. "focus-padding", 1);
  1037. int totalFocus = focusSize + focusPad;
  1038. engine.paintBox(context, g, SynthConstants.PRESSED,
  1039. GTKConstants.SHADOW_IN, "trough", x + totalFocus,
  1040. y + totalFocus, w - 2 * totalFocus,
  1041. h - 2 * totalFocus);
  1042. if ((state & SynthConstants.FOCUSED) == SynthConstants.FOCUSED) {
  1043. engine.paintFocus(context, g, SynthConstants.ENABLED,
  1044. "trough", x, y, w, h);
  1045. }
  1046. }
  1047. private Insets getScrollBarInsets(SynthContext context, Insets insets) {
  1048. GTKStyle style = (GTKStyle)context.getStyle();
  1049. if (context.getComponent().isFocusable()) {
  1050. int focusSize = style.getClassSpecificIntValue(context,
  1051. "focus-line-width",1);
  1052. int focusPad = style.getClassSpecificIntValue(context,
  1053. "focus-padding", 1);
  1054. int w = focusSize + focusPad;
  1055. int h = focusSize + focusPad;
  1056. insets.left = insets.right = w;
  1057. insets.top = insets.bottom = h;
  1058. }
  1059. int troughBorder = style.getClassSpecificIntValue(context,
  1060. "trough-border", 1);
  1061. insets.left += troughBorder;
  1062. insets.right += troughBorder;
  1063. insets.top += troughBorder;
  1064. insets.bottom += troughBorder;
  1065. return insets;
  1066. }
  1067. //
  1068. // SCROLL_BAR_THUMB
  1069. //
  1070. private void paintScrollBarThumbBackground(SynthContext context,
  1071. GTKEngine engine, Graphics g,
  1072. int x, int y, int w, int h) {
  1073. int orientation;
  1074. if (((JScrollBar)context.getComponent()).getOrientation() ==
  1075. JScrollBar.VERTICAL) {
  1076. orientation = GTKConstants.VERTICAL;
  1077. }
  1078. else {
  1079. orientation = GTKConstants.HORIZONTAL;
  1080. }
  1081. engine.paintSlider(context, g, GTKLookAndFeel.synthStateToGTKState(
  1082. context.getRegion(), context.getComponentState()),
  1083. GTKConstants.SHADOW_OUT, "slider", x, y, w, h, orientation);
  1084. }
  1085. //
  1086. // TOOL_BAR
  1087. //
  1088. private void paintToolBarBackground(SynthContext context, GTKEngine engine,
  1089. Graphics g, int x, int y,
  1090. int w, int h) {
  1091. int state = context.getComponentState();
  1092. int gtkState = GTKLookAndFeel.synthStateToGTKState(context.getRegion(),
  1093. state);
  1094. GTKStyle style = (GTKStyle)context.getStyle();
  1095. g.setColor(style.getGTKColor(context.getComponent(),
  1096. context.getRegion(), state, GTKColorType.BACKGROUND));
  1097. engine.paintFlatBox(context, g, gtkState, "handlebox_bin", x, y, w, h);
  1098. }
  1099. private Insets getToolBarInsets(SynthContext context, Insets insets) {
  1100. GTKStyle style = (GTKStyle)context.getStyle();
  1101. int xThickness = style.getXThickness();
  1102. int yThickness = style.getYThickness();
  1103. insets.top = insets.bottom = yThickness;
  1104. insets.right = insets.left = xThickness;
  1105. return insets;
  1106. }
  1107. private void paintToolBarContentBackground(SynthContext context,
  1108. GTKEngine engine, Graphics g, int x, int y, int w, int h) {
  1109. int state = context.getComponentState();
  1110. int gtkState = GTKLookAndFeel.synthStateToGTKState(context.getRegion(),
  1111. state);
  1112. engine.paintShadow(context, g, SynthConstants.ENABLED,
  1113. GTKConstants.SHADOW_OUT, "handlebox_bin", x, y, w, h);
  1114. }
  1115. //
  1116. // TOOL_TIP
  1117. //
  1118. private void paintToolTipBackground(SynthContext context,
  1119. GTKEngine engine, Graphics g,
  1120. int x, int y, int w,int h) {
  1121. engine.paintFlatBoxNormal(context, g, SynthConstants.ENABLED,"tooltip",
  1122. x, y, w, h);
  1123. }
  1124. private Insets getToolTipInsets(SynthContext context, Insets insets) {
  1125. GTKStyle style = (GTKStyle)context.getStyle();
  1126. insets.left = insets.right = style.getXThickness();
  1127. insets.top = insets.bottom = style.getYThickness();
  1128. return insets;
  1129. }
  1130. //
  1131. // TREE_CELL
  1132. //
  1133. private void paintTreeCellBackground(SynthContext context,
  1134. GTKEngine engine, Graphics g,
  1135. int x, int y, int w,int h) {
  1136. int gtkState = GTKLookAndFeel.synthStateToGTKState(
  1137. context.getRegion(), context.getComponentState());
  1138. // the string arg should alternate based on row being painted, but
  1139. // we currently don't pass that in.
  1140. engine.paintFlatBoxText(context, g, gtkState, "cell_odd", x, y, w, h);
  1141. }
  1142. private void paintTreeCellFocus(SynthContext context,
  1143. GTKEngine engine, Graphics g,
  1144. int x, int y, int w,int h) {
  1145. int gtkState = GTKLookAndFeel.synthStateToGTKState(
  1146. context.getRegion(), context.getComponentState());
  1147. engine.paintFocus(context, g, gtkState, "treeview", x, y, w, h);
  1148. }
  1149. //
  1150. // TREE_CELL_RENDERER
  1151. //
  1152. private Insets getTreeCellRendererInsets(SynthContext context,
  1153. Insets insets) {
  1154. insets.left = insets.right = insets.top = insets.bottom = 1;
  1155. return insets;
  1156. }
  1157. //
  1158. // TREE_CELL_EDITOR
  1159. //
  1160. private Insets getTreeCellEditorInsets(SynthContext context,
  1161. Insets insets) {
  1162. insets.left = insets.right = insets.top = insets.bottom = 1;
  1163. return insets;
  1164. }
  1165. private void paintTreeCellEditorBackground(SynthContext context,
  1166. GTKEngine engine, Graphics g,
  1167. int x, int y, int w,int h) {
  1168. int gtkState = GTKLookAndFeel.synthStateToGTKState(
  1169. context.getRegion(), context.getComponentState());
  1170. engine.paintFlatBoxText(context, g, gtkState, "entry_bg", x, y, w, h);
  1171. }
  1172. //
  1173. // TREE
  1174. //
  1175. private void paintTreeBackground(SynthContext context,
  1176. GTKEngine engine, Graphics g,
  1177. int x, int y, int w,int h) {
  1178. // As far as I can tell, these don't call into the engine.
  1179. int gtkState = GTKLookAndFeel.synthStateToGTKState(
  1180. context.getRegion(), context.getComponentState());
  1181. g.setColor(((GTKStyle)context.getStyle()).getGTKColor(
  1182. context.getComponent(), context.getRegion(), gtkState,
  1183. GTKColorType.TEXT_BACKGROUND));
  1184. g.fillRect(x, y, w, h);
  1185. }
  1186. //
  1187. // VIEWPORT
  1188. //
  1189. private void paintViewportBackground(SynthContext context,
  1190. GTKEngine engine, Graphics g,
  1191. int x, int y, int w,int h) {
  1192. // As far as I can tell, these don't call into the engine.
  1193. // Also note that you don't want this to call into the engine
  1194. // as if it where to paint a background JViewport wouldn't scroll
  1195. // correctly.
  1196. int gtkState = GTKLookAndFeel.synthStateToGTKState(
  1197. context.getRegion(), context.getComponentState());
  1198. g.setColor(((GTKStyle)context.getStyle()).getGTKColor(
  1199. context.getComponent(), context.getRegion(), gtkState,
  1200. GTKColorType.TEXT_BACKGROUND));
  1201. g.fillRect(x, y, w, h);
  1202. }
  1203. // Refer to GTKLookAndFeel for details on this.
  1204. static class ListTableFocusBorder extends AbstractBorder implements
  1205. UIResource {
  1206. public void paintBorder(Component c, Graphics g, int x, int y,
  1207. int w, int h) {
  1208. g.setColor(Color.BLACK);
  1209. GTKEngine.INSTANCE._paintFocus(g, x, y, w, h,
  1210. GTKEngine.DEFAULT_FOCUS_PATTERN, 1);
  1211. }
  1212. public Insets getBorderInsets(Component c) {
  1213. return new Insets(1, 1, 1, 1);
  1214. }
  1215. public Insets getBorderInsets(Component c, Insets i) {
  1216. if (i == null) {
  1217. return getBorderInsets(c);
  1218. }
  1219. i.left = i.right = i.top = i.bottom = 1;
  1220. return i;
  1221. }
  1222. public boolean isBorderOpaque() {
  1223. return true;
  1224. }
  1225. }
  1226. }