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