1. /*
  2. * @(#)MotifBorders.java 1.34 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.java.swing.plaf.motif;
  8. import javax.swing.*;
  9. import javax.swing.border.*;
  10. import javax.swing.plaf.*;
  11. import java.awt.Color;
  12. import java.awt.Component;
  13. import java.awt.Dimension;
  14. import java.awt.Font;
  15. import java.awt.FontMetrics;
  16. import java.awt.Graphics;
  17. import java.awt.Insets;
  18. import java.awt.Point;
  19. import java.awt.Rectangle;
  20. import java.io.Serializable;
  21. /**
  22. * Factory object that can vend Icons appropriate for the basic L & F.
  23. * <p>
  24. * <strong>Warning:</strong>
  25. * Serialized objects of this class will not be compatible with
  26. * future Swing releases. The current serialization support is appropriate
  27. * for short term storage or RMI between applications running the same
  28. * version of Swing. A future release of Swing will provide support for
  29. * long term persistence.
  30. *
  31. * @version 1.34 01/23/03
  32. * @author Amy Fowler
  33. */
  34. public class MotifBorders {
  35. public static class BevelBorder extends AbstractBorder implements UIResource {
  36. private Color darkShadow = UIManager.getColor("controlShadow");
  37. private Color lightShadow = UIManager.getColor("controlLtHighlight");
  38. private boolean isRaised;
  39. public BevelBorder(boolean isRaised, Color darkShadow, Color lightShadow) {
  40. this.isRaised = isRaised;
  41. this.darkShadow = darkShadow;
  42. this.lightShadow = lightShadow;
  43. }
  44. public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
  45. g.setColor((isRaised) ? lightShadow : darkShadow);
  46. g.drawLine(x, y, x+w-1, y); // top
  47. g.drawLine(x, y+h-1, x, y+1); // left
  48. g.setColor((isRaised) ? darkShadow : lightShadow);
  49. g.drawLine(x+1, y+h-1, x+w-1, y+h-1); // bottom
  50. g.drawLine(x+w-1, y+h-1, x+w-1, y+1); // right
  51. }
  52. public Insets getBorderInsets(Component c) {
  53. return getBorderInsets(c, new Insets(0,0,0,0));
  54. }
  55. public Insets getBorderInsets(Component c, Insets insets) {
  56. insets.top = insets.left = insets.bottom = insets.right = 1;
  57. return insets;
  58. }
  59. public boolean isOpaque(Component c) {
  60. return true;
  61. }
  62. }
  63. public static class FocusBorder extends AbstractBorder implements UIResource {
  64. private Color focus;
  65. private Color control;
  66. public FocusBorder(Color control, Color focus) {
  67. this.control = control;
  68. this.focus = focus;
  69. }
  70. public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
  71. if (((JComponent)c).hasFocus()) {
  72. g.setColor(focus);
  73. g.drawRect(x, y, w-1, h-1);
  74. } else {
  75. g.setColor(control);
  76. g.drawRect(x, y, w-1, h-1);
  77. }
  78. }
  79. public Insets getBorderInsets(Component c) {
  80. return getBorderInsets(c, new Insets(0,0,0,0));
  81. }
  82. public Insets getBorderInsets(Component c, Insets insets) {
  83. insets.top = insets.left = insets.bottom = insets.right = 1;
  84. return insets;
  85. }
  86. }
  87. public static class ButtonBorder extends AbstractBorder implements UIResource {
  88. protected Color focus = UIManager.getColor("activeCaptionBorder");
  89. protected Color shadow = UIManager.getColor("Button.shadow");
  90. protected Color highlight = UIManager.getColor("Button.light");
  91. protected Color darkShadow;
  92. public ButtonBorder(Color shadow, Color highlight, Color darkShadow, Color focus) {
  93. this.shadow = shadow;
  94. this.highlight = highlight;
  95. this.darkShadow = darkShadow;
  96. this.focus = focus;
  97. }
  98. public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
  99. boolean isPressed = false;
  100. boolean hasFocus = false;
  101. boolean canBeDefault = false;
  102. boolean isDefault = false;
  103. if (c instanceof AbstractButton) {
  104. AbstractButton b = (AbstractButton)c;
  105. ButtonModel model = b.getModel();
  106. isPressed = (model.isArmed() && model.isPressed());
  107. hasFocus = (model.isArmed() && isPressed) ||
  108. (b.isFocusPainted() && b.hasFocus());
  109. if (b instanceof JButton) {
  110. canBeDefault = ((JButton)b).isDefaultCapable();
  111. isDefault = ((JButton)b).isDefaultButton();
  112. }
  113. }
  114. int bx1 = x+1;
  115. int by1 = y+1;
  116. int bx2 = x+w-2;
  117. int by2 = y+h-2;
  118. if (canBeDefault) {
  119. if (isDefault) {
  120. g.setColor(shadow);
  121. g.drawLine(x+3, y+3, x+3, y+h-4);
  122. g.drawLine(x+3, y+3, x+w-4, y+3);
  123. g.setColor(highlight);
  124. g.drawLine(x+4, y+h-4, x+w-4, y+h-4);
  125. g.drawLine(x+w-4, y+3, x+w-4, y+h-4);
  126. }
  127. bx1 +=6;
  128. by1 += 6;
  129. bx2 -= 6;
  130. by2 -= 6;
  131. }
  132. if (hasFocus) {
  133. g.setColor(focus);
  134. if (isDefault) {
  135. g.drawRect(x, y, w-1, h-1);
  136. } else {
  137. g.drawRect(bx1-1, by1-1, bx2-bx1+2, by2-by1+2);
  138. }
  139. }
  140. g.setColor(isPressed? shadow : highlight);
  141. g.drawLine(bx1, by1, bx2, by1);
  142. g.drawLine(bx1, by1, bx1, by2);
  143. g.setColor(isPressed? highlight : shadow);
  144. g.drawLine(bx2, by1+1, bx2, by2);
  145. g.drawLine(bx1+1, by2, bx2, by2);
  146. }
  147. public Insets getBorderInsets(Component c) {
  148. return getBorderInsets(c, new Insets(0,0,0,0));
  149. }
  150. public Insets getBorderInsets(Component c, Insets insets) {
  151. int thickness = (c instanceof JButton && ((JButton)c).isDefaultCapable())? 8 : 2;
  152. insets.top = insets.left = insets.bottom = insets.right = thickness;
  153. return insets;
  154. }
  155. }
  156. public static class ToggleButtonBorder extends ButtonBorder {
  157. public ToggleButtonBorder(Color shadow, Color highlight, Color darkShadow, Color focus) {
  158. super(shadow, highlight, darkShadow, focus);
  159. }
  160. public void paintBorder(Component c, Graphics g, int x, int y,
  161. int width, int height) {
  162. if (c instanceof AbstractButton) {
  163. AbstractButton b = (AbstractButton)c;
  164. ButtonModel model = b.getModel();
  165. if (model.isArmed() && model.isPressed() || model.isSelected()) {
  166. drawBezel(g, x, y, width, height,
  167. (model.isPressed() || model.isSelected()),
  168. b.isFocusPainted() && b.hasFocus(), shadow, highlight, darkShadow, focus);
  169. } else {
  170. drawBezel(g, x, y, width, height,
  171. false, b.isFocusPainted() && b.hasFocus(),
  172. shadow, highlight, darkShadow, focus);
  173. }
  174. } else {
  175. drawBezel(g, x, y, width, height, false, false,
  176. shadow, highlight, darkShadow, focus);
  177. }
  178. }
  179. public Insets getBorderInsets(Component c) {
  180. return new Insets(2, 2, 3, 3);
  181. }
  182. public Insets getBorderInsets(Component c, Insets insets) {
  183. insets.top = insets.left = 2;
  184. insets.bottom = insets.right = 3;
  185. return insets;
  186. }
  187. }
  188. public static class MenuBarBorder extends ButtonBorder {
  189. public MenuBarBorder(Color shadow, Color highlight, Color darkShadow, Color focus) {
  190. super(shadow, highlight, darkShadow, focus);
  191. }
  192. public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
  193. JMenuBar menuBar = (JMenuBar)c;
  194. if (menuBar.isBorderPainted() == true) {
  195. // this draws the MenuBar border
  196. Dimension size = menuBar.getSize();
  197. drawBezel(g,x,y,size.width,size.height,false,false,
  198. shadow, highlight, darkShadow, focus);
  199. }
  200. }
  201. public Insets getBorderInsets(Component c) {
  202. return getBorderInsets(c, new Insets(0,0,0,0));
  203. }
  204. public Insets getBorderInsets(Component c, Insets insets) {
  205. insets.top = insets.left = insets.bottom = insets.right = 6;
  206. return insets;
  207. }
  208. }
  209. public static class FrameBorder extends AbstractBorder implements UIResource {
  210. JComponent jcomp;
  211. Color frameHighlight;
  212. Color frameColor;
  213. Color frameShadow;
  214. // The width of the border
  215. public final static int BORDER_SIZE = 5;
  216. /** Constructs an FrameBorder for the JComponent <b>comp</b>.
  217. */
  218. public FrameBorder(JComponent comp) {
  219. jcomp = comp;
  220. }
  221. /** Sets the FrameBorder's JComponent.
  222. */
  223. public void setComponent(JComponent comp) {
  224. jcomp = comp;
  225. }
  226. /** Returns the FrameBorder's JComponent.
  227. * @see #setComponent
  228. */
  229. public JComponent component() {
  230. return jcomp;
  231. }
  232. protected Color getFrameHighlight() {
  233. return frameHighlight;
  234. }
  235. protected Color getFrameColor() {
  236. return frameColor;
  237. }
  238. protected Color getFrameShadow() {
  239. return frameShadow;
  240. }
  241. static Insets insets = new Insets(BORDER_SIZE, BORDER_SIZE,
  242. BORDER_SIZE, BORDER_SIZE);
  243. public Insets getBorderInsets(Component c) {
  244. return insets;
  245. }
  246. public Insets getBorderInsets(Component c, Insets newInsets) {
  247. newInsets.top = insets.top;
  248. newInsets.left = insets.left;
  249. newInsets.bottom = insets.bottom;
  250. newInsets.right = insets.right;
  251. return newInsets;
  252. }
  253. /** Draws the FrameBorder's top border.
  254. */
  255. protected boolean drawTopBorder(Component c, Graphics g,
  256. int x, int y, int width, int height) {
  257. Rectangle titleBarRect = new Rectangle(x, y, width, BORDER_SIZE);
  258. if (!g.getClipBounds().intersects(titleBarRect)) {
  259. return false;
  260. }
  261. int maxX = width - 1;
  262. int maxY = BORDER_SIZE - 1;
  263. // Draw frame
  264. g.setColor(frameColor);
  265. g.drawLine(x, y + 2, maxX - 2, y + 2);
  266. g.drawLine(x, y + 3, maxX - 2, y + 3);
  267. g.drawLine(x, y + 4, maxX - 2, y + 4);
  268. // Draw highlights
  269. g.setColor(frameHighlight);
  270. g.drawLine(x, y, maxX, y);
  271. g.drawLine(x, y + 1, maxX, y + 1);
  272. g.drawLine(x, y + 2, x, y + 4);
  273. g.drawLine(x + 1, y + 2, x + 1, y + 4);
  274. // Draw shadows
  275. g.setColor(frameShadow);
  276. g.drawLine(x + 4, y + 4, maxX - 4, y + 4);
  277. g.drawLine(maxX, y + 1, maxX, maxY);
  278. g.drawLine(maxX - 1, y + 2, maxX - 1, maxY);
  279. return true;
  280. }
  281. /** Draws the FrameBorder's left border.
  282. */
  283. protected boolean drawLeftBorder(Component c, Graphics g, int x, int y,
  284. int width, int height) {
  285. Rectangle borderRect =
  286. new Rectangle(0, 0, getBorderInsets(c).left, height);
  287. if (!g.getClipBounds().intersects(borderRect)) {
  288. return false;
  289. }
  290. int startY = BORDER_SIZE;
  291. g.setColor(frameHighlight);
  292. g.drawLine(x, startY, x, height - 1);
  293. g.drawLine(x + 1, startY, x + 1, height - 2);
  294. g.setColor(frameColor);
  295. g.fillRect(x + 2, startY, x + 2, height - 3);
  296. g.setColor(frameShadow);
  297. g.drawLine(x + 4, startY, x + 4, height - 5);
  298. return true;
  299. }
  300. /** Draws the FrameBorder's right border.
  301. */
  302. protected boolean drawRightBorder(Component c, Graphics g, int x, int y,
  303. int width, int height) {
  304. Rectangle borderRect = new Rectangle(
  305. width - getBorderInsets(c).right, 0,
  306. getBorderInsets(c).right, height);
  307. if (!g.getClipBounds().intersects(borderRect)) {
  308. return false;
  309. }
  310. int startX = width - getBorderInsets(c).right;
  311. int startY = BORDER_SIZE;
  312. g.setColor(frameColor);
  313. g.fillRect(startX + 1, startY, 2, height - 1);
  314. g.setColor(frameShadow);
  315. g.fillRect(startX + 3, startY, 2, height - 1);
  316. g.setColor(frameHighlight);
  317. g.drawLine(startX, startY, startX, height - 1);
  318. return true;
  319. }
  320. /** Draws the FrameBorder's bottom border.
  321. */
  322. protected boolean drawBottomBorder(Component c, Graphics g, int x, int y,
  323. int width, int height) {
  324. Rectangle borderRect;
  325. int marginHeight, startY;
  326. borderRect = new Rectangle(0, height - getBorderInsets(c).bottom,
  327. width, getBorderInsets(c).bottom);
  328. if (!g.getClipBounds().intersects(borderRect)) {
  329. return false;
  330. }
  331. startY = height - getBorderInsets(c).bottom;
  332. g.setColor(frameShadow);
  333. g.drawLine(x + 1, height - 1, width - 1, height - 1);
  334. g.drawLine(x + 2, height - 2, width - 2, height - 2);
  335. g.setColor(frameColor);
  336. g.fillRect(x + 2, startY + 1, width - 4, 2);
  337. g.setColor(frameHighlight);
  338. g.drawLine(x + 5, startY, width - 5, startY);
  339. return true;
  340. }
  341. // Returns true if the associated component has focus.
  342. protected boolean isActiveFrame() {
  343. return jcomp.hasFocus();
  344. }
  345. /** Draws the FrameBorder in the given Rect. Calls
  346. * <b>drawTitleBar</b>, <b>drawLeftBorder</b>, <b>drawRightBorder</b> and
  347. * <b>drawBottomBorder</b>.
  348. */
  349. public void paintBorder(Component c, Graphics g,
  350. int x, int y, int width, int height) {
  351. if (isActiveFrame()) {
  352. frameColor = UIManager.getColor("activeCaptionBorder");
  353. } else {
  354. frameColor = UIManager.getColor("inactiveCaptionBorder");
  355. }
  356. frameHighlight = frameColor.brighter();
  357. frameShadow = frameColor.darker().darker();
  358. drawTopBorder(c, g, x, y, width, height);
  359. drawLeftBorder(c, g, x, y, width, height);
  360. drawRightBorder(c, g, x, y, width, height);
  361. drawBottomBorder(c, g, x, y, width, height);
  362. }
  363. }
  364. public static class InternalFrameBorder extends FrameBorder {
  365. JInternalFrame frame;
  366. // The size of the bounding box for Motif frame corners.
  367. public final static int CORNER_SIZE = 24;
  368. /** Constructs an InternalFrameBorder for the InternalFrame
  369. * <b>aFrame</b>.
  370. */
  371. public InternalFrameBorder(JInternalFrame aFrame) {
  372. super(aFrame);
  373. frame = aFrame;
  374. }
  375. /** Sets the InternalFrameBorder's InternalFrame.
  376. */
  377. public void setFrame(JInternalFrame aFrame) {
  378. frame = aFrame;
  379. }
  380. /** Returns the InternalFrameBorder's InternalFrame.
  381. * @see #setFrame
  382. */
  383. public JInternalFrame frame() {
  384. return frame;
  385. }
  386. /** Returns the width of the InternalFrameBorder's resize controls,
  387. * appearing along the InternalFrameBorder's bottom border. Clicking
  388. * and dragging within these controls lets the user change both the
  389. * InternalFrame's width and height, while dragging between the controls
  390. * constrains resizing to just the vertical dimension. Override this
  391. * method if you implement your own bottom border painting and use a
  392. * resize control with a different size.
  393. */
  394. public int resizePartWidth() {
  395. if (!frame.isResizable()) {
  396. return 0;
  397. }
  398. return FrameBorder.BORDER_SIZE;
  399. }
  400. /** Draws the InternalFrameBorder's top border.
  401. */
  402. protected boolean drawTopBorder(Component c, Graphics g,
  403. int x, int y, int width, int height) {
  404. if (super.drawTopBorder(c, g, x, y, width, height) &&
  405. frame.isResizable()) {
  406. g.setColor(getFrameShadow());
  407. g.drawLine(CORNER_SIZE - 1, y + 1, CORNER_SIZE - 1, y + 4);
  408. g.drawLine(width - CORNER_SIZE - 1, y + 1,
  409. width - CORNER_SIZE - 1, y + 4);
  410. g.setColor(getFrameHighlight());
  411. g.drawLine(CORNER_SIZE, y, CORNER_SIZE, y + 4);
  412. g.drawLine(width - CORNER_SIZE, y, width - CORNER_SIZE, y + 4);
  413. return true;
  414. }
  415. return false;
  416. }
  417. /** Draws the InternalFrameBorder's left border.
  418. */
  419. protected boolean drawLeftBorder(Component c, Graphics g, int x, int y,
  420. int width, int height) {
  421. if (super.drawLeftBorder(c, g, x, y, width, height) &&
  422. frame.isResizable()) {
  423. g.setColor(getFrameHighlight());
  424. int topY = y + CORNER_SIZE;
  425. g.drawLine(x, topY, x + 4, topY);
  426. int bottomY = height - CORNER_SIZE;
  427. g.drawLine(x + 1, bottomY, x + 5, bottomY);
  428. g.setColor(getFrameShadow());
  429. g.drawLine(x + 1, topY - 1, x + 5, topY - 1);
  430. g.drawLine(x + 1, bottomY - 1, x + 5, bottomY - 1);
  431. return true;
  432. }
  433. return false;
  434. }
  435. /** Draws the InternalFrameBorder's right border.
  436. */
  437. protected boolean drawRightBorder(Component c, Graphics g, int x, int y,
  438. int width, int height) {
  439. if (super.drawRightBorder(c, g, x, y, width, height) &&
  440. frame.isResizable()) {
  441. int startX = width - getBorderInsets(c).right;
  442. g.setColor(getFrameHighlight());
  443. int topY = y + CORNER_SIZE;
  444. g.drawLine(startX, topY, width - 2, topY);
  445. int bottomY = height - CORNER_SIZE;
  446. g.drawLine(startX + 1, bottomY, startX + 3, bottomY);
  447. g.setColor(getFrameShadow());
  448. g.drawLine(startX + 1, topY - 1, width - 2, topY - 1);
  449. g.drawLine(startX + 1, bottomY - 1, startX + 3, bottomY - 1);
  450. return true;
  451. }
  452. return false;
  453. }
  454. /** Draws the InternalFrameBorder's bottom border.
  455. */
  456. protected boolean drawBottomBorder(Component c, Graphics g, int x, int y,
  457. int width, int height) {
  458. if (super.drawBottomBorder(c, g, x, y, width, height) &&
  459. frame.isResizable()) {
  460. int startY = height - getBorderInsets(c).bottom;
  461. g.setColor(getFrameShadow());
  462. g.drawLine(CORNER_SIZE - 1, startY + 1,
  463. CORNER_SIZE - 1, height - 1);
  464. g.drawLine(width - CORNER_SIZE, startY + 1,
  465. width - CORNER_SIZE, height - 1);
  466. g.setColor(getFrameHighlight());
  467. g.drawLine(CORNER_SIZE, startY, CORNER_SIZE, height - 2);
  468. g.drawLine(width - CORNER_SIZE + 1, startY,
  469. width - CORNER_SIZE + 1, height - 2);
  470. return true;
  471. }
  472. return false;
  473. }
  474. // Returns true if the associated internal frame has focus.
  475. protected boolean isActiveFrame() {
  476. return frame.isSelected();
  477. }
  478. }
  479. public static void drawBezel(Graphics g, int x, int y, int w, int h,
  480. boolean isPressed, boolean hasFocus,
  481. Color shadow, Color highlight,
  482. Color darkShadow, Color focus) {
  483. Color oldColor = g.getColor();
  484. g.translate(x, y);
  485. if (isPressed) {
  486. if (hasFocus){
  487. g.setColor(focus);
  488. g.drawRect(0, 0, w-1, h-1);
  489. }
  490. g.setColor(shadow); // inner border
  491. g.drawRect(1, 1, w-3, h-3);
  492. g.setColor(highlight); // inner 3D border
  493. g.drawLine(2, h-3, w-3, h-3);
  494. g.drawLine(w-3, 2, w-3, h-4);
  495. } else {
  496. if (hasFocus) {
  497. g.setColor(focus);
  498. g.drawRect(0, 0, w-1, h-1);
  499. g.setColor(highlight); // inner 3D border
  500. g.drawLine(1, 1, 1, h-3);
  501. g.drawLine(2, 1, w-4, 1);
  502. g.setColor(shadow);
  503. g.drawLine(2, h-3, w-3, h-3);
  504. g.drawLine(w-3, 1, w-3, h-4);
  505. g.setColor(darkShadow); // black drop shadow __|
  506. g.drawLine(1, h-2, w-2, h-2);
  507. g.drawLine(w-2, h-2, w-2, 1);
  508. } else {
  509. g.setColor(highlight); // inner 3D border
  510. g.drawLine(1,1,1,h-3);
  511. g.drawLine(2,1,w-4,1);
  512. g.setColor(shadow);
  513. g.drawLine(2,h-3,w-3,h-3);
  514. g.drawLine(w-3,1,w-3,h-4);
  515. g.setColor(darkShadow); // black drop shadow __|
  516. g.drawLine(1,h-2,w-2,h-2);
  517. g.drawLine(w-2,h-2,w-2,0);
  518. }
  519. g.translate(-x, -y);
  520. }
  521. g.setColor(oldColor);
  522. }
  523. public static class MotifPopupMenuBorder extends AbstractBorder implements UIResource {
  524. protected Font font;
  525. protected Color background;
  526. protected Color foreground;
  527. protected Color shadowColor;
  528. protected Color highlightColor;
  529. // Space between the border and text
  530. static protected final int TEXT_SPACING = 2;
  531. // Space for the separator under the title
  532. static protected final int GROOVE_HEIGHT = 2;
  533. /**
  534. * Creates a MotifPopupMenuBorder instance
  535. *
  536. */
  537. public MotifPopupMenuBorder(
  538. Font titleFont,
  539. Color bgColor,
  540. Color fgColor,
  541. Color shadow,
  542. Color highlight) {
  543. this.font = titleFont;
  544. this.background = bgColor;
  545. this.foreground = fgColor;
  546. this.shadowColor = shadow;
  547. this.highlightColor = highlight;
  548. }
  549. /**
  550. * Paints the border for the specified component with the
  551. * specified position and size.
  552. * @param c the component for which this border is being painted
  553. * @param g the paint graphics
  554. * @param x the x position of the painted border
  555. * @param y the y position of the painted border
  556. * @param width the width of the painted border
  557. * @param height the height of the painted border
  558. */
  559. public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
  560. Font origFont = g.getFont();
  561. Color origColor = g.getColor();
  562. String title = ((JPopupMenu)c).getLabel();
  563. if (title == null) {
  564. return;
  565. }
  566. g.setFont(font);
  567. FontMetrics fm = g.getFontMetrics();
  568. int fontHeight = fm.getHeight();
  569. int descent = fm.getDescent();
  570. int ascent = fm.getAscent();
  571. Point textLoc = new Point();
  572. int stringWidth = fm.stringWidth(title);
  573. textLoc.y = y + ascent + TEXT_SPACING;
  574. textLoc.x = x + ((width - stringWidth) / 2);
  575. g.setColor(background);
  576. g.fillRect(textLoc.x - TEXT_SPACING, textLoc.y - (fontHeight-descent),
  577. stringWidth + (2 * TEXT_SPACING), fontHeight - descent);
  578. g.setColor(foreground);
  579. g.drawString(title, textLoc.x, textLoc.y);
  580. MotifGraphicsUtils.drawGroove(g, x, textLoc.y + TEXT_SPACING,
  581. width, GROOVE_HEIGHT,
  582. shadowColor, highlightColor);
  583. g.setFont(origFont);
  584. g.setColor(origColor);
  585. }
  586. /**
  587. * Returns the insets of the border.
  588. * @param c the component for which this border insets value applies
  589. */
  590. public Insets getBorderInsets(Component c) {
  591. return getBorderInsets(c, new Insets(0, 0, 0, 0));
  592. }
  593. /**
  594. * Reinitialize the insets parameter with this Border's current Insets.
  595. * @param c the component for which this border insets value applies
  596. * @param insets the object to be reinitialized
  597. */
  598. public Insets getBorderInsets(Component c, Insets insets) {
  599. FontMetrics fm;
  600. int descent = 0;
  601. int ascent = 16;
  602. String title = ((JPopupMenu)c).getLabel();
  603. if (title == null) {
  604. insets.left = insets.top = insets.right = insets.bottom = 0;
  605. return insets;
  606. }
  607. fm = c.getFontMetrics(font);
  608. if(fm != null) {
  609. descent = fm.getDescent();
  610. ascent = fm.getAscent();
  611. }
  612. insets.top += ascent + descent + TEXT_SPACING + GROOVE_HEIGHT;
  613. return insets;
  614. }
  615. }
  616. }