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