1. /*
  2. * @(#)BasicInternalFrameTitlePane.java 1.61 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 javax.swing.plaf.basic;
  8. import com.sun.java.swing.SwingUtilities2;
  9. import java.awt.*;
  10. import java.awt.event.*;
  11. import javax.accessibility.AccessibleContext;
  12. import javax.swing.*;
  13. import javax.swing.plaf.*;
  14. import javax.swing.border.*;
  15. import javax.swing.event.InternalFrameEvent;
  16. import java.util.EventListener;
  17. import java.beans.PropertyChangeListener;
  18. import java.beans.PropertyChangeEvent;
  19. import java.beans.VetoableChangeListener;
  20. import java.beans.PropertyVetoException;
  21. import sun.swing.DefaultLookup;
  22. import sun.swing.UIAction;
  23. /**
  24. * The class that manages a basic title bar
  25. * <p>
  26. * <strong>Warning:</strong>
  27. * Serialized objects of this class will not be compatible with
  28. * future Swing releases. The current serialization support is
  29. * appropriate for short term storage or RMI between applications running
  30. * the same version of Swing. As of 1.4, support for long term storage
  31. * of all JavaBeans<sup><font size="-2">TM</font></sup>
  32. * has been added to the <code>java.beans</code> package.
  33. * Please see {@link java.beans.XMLEncoder}.
  34. *
  35. * @version 1.41 01/18/01
  36. * @author David Kloba
  37. * @author Steve Wilson
  38. */
  39. public class BasicInternalFrameTitlePane extends JComponent
  40. {
  41. protected JMenuBar menuBar;
  42. protected JButton iconButton;
  43. protected JButton maxButton;
  44. protected JButton closeButton;
  45. protected JMenu windowMenu;
  46. protected JInternalFrame frame;
  47. protected Color selectedTitleColor;
  48. protected Color selectedTextColor;
  49. protected Color notSelectedTitleColor;
  50. protected Color notSelectedTextColor;
  51. protected Icon maxIcon;
  52. protected Icon minIcon;
  53. protected Icon iconIcon;
  54. protected Icon closeIcon;
  55. protected PropertyChangeListener propertyChangeListener;
  56. protected Action closeAction;
  57. protected Action maximizeAction;
  58. protected Action iconifyAction;
  59. protected Action restoreAction;
  60. protected Action moveAction;
  61. protected Action sizeAction;
  62. protected static final String CLOSE_CMD =
  63. UIManager.getString("InternalFrameTitlePane.closeButtonText");
  64. protected static final String ICONIFY_CMD =
  65. UIManager.getString("InternalFrameTitlePane.minimizeButtonText");
  66. protected static final String RESTORE_CMD =
  67. UIManager.getString("InternalFrameTitlePane.restoreButtonText");
  68. protected static final String MAXIMIZE_CMD =
  69. UIManager.getString("InternalFrameTitlePane.maximizeButtonText");
  70. protected static final String MOVE_CMD =
  71. UIManager.getString("InternalFrameTitlePane.moveButtonText");
  72. protected static final String SIZE_CMD =
  73. UIManager.getString("InternalFrameTitlePane.sizeButtonText");
  74. private String closeButtonToolTip;
  75. private String iconButtonToolTip;
  76. private String restoreButtonToolTip;
  77. private String maxButtonToolTip;
  78. private Handler handler;
  79. public BasicInternalFrameTitlePane(JInternalFrame f) {
  80. frame = f;
  81. installTitlePane();
  82. }
  83. protected void installTitlePane() {
  84. installDefaults();
  85. installListeners();
  86. createActions();
  87. enableActions();
  88. createActionMap();
  89. setLayout(createLayout());
  90. assembleSystemMenu();
  91. createButtons();
  92. addSubComponents();
  93. }
  94. protected void addSubComponents() {
  95. add(menuBar);
  96. add(iconButton);
  97. add(maxButton);
  98. add(closeButton);
  99. }
  100. protected void createActions() {
  101. maximizeAction = new MaximizeAction();
  102. iconifyAction = new IconifyAction();
  103. closeAction = new CloseAction();
  104. restoreAction = new RestoreAction();
  105. moveAction = new MoveAction();
  106. sizeAction = new SizeAction();
  107. }
  108. ActionMap createActionMap() {
  109. ActionMap map = new ActionMapUIResource();
  110. map.put("showSystemMenu", new ShowSystemMenuAction(true));
  111. map.put("hideSystemMenu", new ShowSystemMenuAction(false));
  112. return map;
  113. }
  114. protected void installListeners() {
  115. if( propertyChangeListener == null ) {
  116. propertyChangeListener = createPropertyChangeListener();
  117. }
  118. frame.addPropertyChangeListener(propertyChangeListener);
  119. }
  120. protected void uninstallListeners() {
  121. frame.removePropertyChangeListener(propertyChangeListener);
  122. handler = null;
  123. }
  124. protected void installDefaults() {
  125. maxIcon = UIManager.getIcon("InternalFrame.maximizeIcon");
  126. minIcon = UIManager.getIcon("InternalFrame.minimizeIcon");
  127. iconIcon = UIManager.getIcon("InternalFrame.iconifyIcon");
  128. closeIcon = UIManager.getIcon("InternalFrame.closeIcon");
  129. selectedTitleColor = UIManager.getColor("InternalFrame.activeTitleBackground");
  130. selectedTextColor = UIManager.getColor("InternalFrame.activeTitleForeground");
  131. notSelectedTitleColor = UIManager.getColor("InternalFrame.inactiveTitleBackground");
  132. notSelectedTextColor = UIManager.getColor("InternalFrame.inactiveTitleForeground");
  133. setFont(UIManager.getFont("InternalFrame.titleFont"));
  134. closeButtonToolTip =
  135. UIManager.getString("InternalFrame.closeButtonToolTip");
  136. iconButtonToolTip =
  137. UIManager.getString("InternalFrame.iconButtonToolTip");
  138. restoreButtonToolTip =
  139. UIManager.getString("InternalFrame.restoreButtonToolTip");
  140. maxButtonToolTip =
  141. UIManager.getString("InternalFrame.maxButtonToolTip");
  142. }
  143. protected void uninstallDefaults() {
  144. }
  145. protected void createButtons() {
  146. iconButton = new NoFocusButton(
  147. "InternalFrameTitlePane.iconifyButtonAccessibleName");
  148. iconButton.addActionListener(iconifyAction);
  149. if (iconButtonToolTip != null && iconButtonToolTip.length() != 0) {
  150. iconButton.setToolTipText(iconButtonToolTip);
  151. }
  152. maxButton = new NoFocusButton(
  153. "InternalFrameTitlePane.maximizeButtonAccessibleName");
  154. maxButton.addActionListener(maximizeAction);
  155. closeButton = new NoFocusButton(
  156. "InternalFrameTitlePane.closeButtonAccessibleName");
  157. closeButton.addActionListener(closeAction);
  158. if (closeButtonToolTip != null && closeButtonToolTip.length() != 0) {
  159. closeButton.setToolTipText(closeButtonToolTip);
  160. }
  161. setButtonIcons();
  162. }
  163. protected void setButtonIcons() {
  164. if(frame.isIcon()) {
  165. if (minIcon != null) {
  166. iconButton.setIcon(minIcon);
  167. }
  168. if (restoreButtonToolTip != null &&
  169. restoreButtonToolTip.length() != 0) {
  170. iconButton.setToolTipText(restoreButtonToolTip);
  171. }
  172. if (maxIcon != null) {
  173. maxButton.setIcon(maxIcon);
  174. }
  175. if (maxButtonToolTip != null && maxButtonToolTip.length() != 0) {
  176. maxButton.setToolTipText(maxButtonToolTip);
  177. }
  178. } else if (frame.isMaximum()) {
  179. if (iconIcon != null) {
  180. iconButton.setIcon(iconIcon);
  181. }
  182. if (iconButtonToolTip != null && iconButtonToolTip.length() != 0) {
  183. iconButton.setToolTipText(iconButtonToolTip);
  184. }
  185. if (minIcon != null) {
  186. maxButton.setIcon(minIcon);
  187. }
  188. if (restoreButtonToolTip != null &&
  189. restoreButtonToolTip.length() != 0) {
  190. maxButton.setToolTipText(restoreButtonToolTip);
  191. }
  192. } else {
  193. if (iconIcon != null) {
  194. iconButton.setIcon(iconIcon);
  195. }
  196. if (iconButtonToolTip != null && iconButtonToolTip.length() != 0) {
  197. iconButton.setToolTipText(iconButtonToolTip);
  198. }
  199. if (maxIcon != null) {
  200. maxButton.setIcon(maxIcon);
  201. }
  202. if (maxButtonToolTip != null && maxButtonToolTip.length() != 0) {
  203. maxButton.setToolTipText(maxButtonToolTip);
  204. }
  205. }
  206. if (closeIcon != null) {
  207. closeButton.setIcon(closeIcon);
  208. }
  209. }
  210. protected void assembleSystemMenu() {
  211. menuBar = createSystemMenuBar();
  212. windowMenu = createSystemMenu();
  213. menuBar.add(windowMenu);
  214. addSystemMenuItems(windowMenu);
  215. enableActions();
  216. }
  217. protected void addSystemMenuItems(JMenu systemMenu) {
  218. JMenuItem mi = (JMenuItem)systemMenu.add(restoreAction);
  219. mi.setMnemonic('R');
  220. mi = (JMenuItem)systemMenu.add(moveAction);
  221. mi.setMnemonic('M');
  222. mi = (JMenuItem)systemMenu.add(sizeAction);
  223. mi.setMnemonic('S');
  224. mi = (JMenuItem)systemMenu.add(iconifyAction);
  225. mi.setMnemonic('n');
  226. mi = (JMenuItem)systemMenu.add(maximizeAction);
  227. mi.setMnemonic('x');
  228. systemMenu.add(new JSeparator());
  229. mi = (JMenuItem)systemMenu.add(closeAction);
  230. mi.setMnemonic('C');
  231. }
  232. protected JMenu createSystemMenu() {
  233. return new JMenu(" ");
  234. }
  235. protected JMenuBar createSystemMenuBar() {
  236. menuBar = new SystemMenuBar();
  237. menuBar.setBorderPainted(false);
  238. return menuBar;
  239. }
  240. protected void showSystemMenu(){
  241. // windowMenu.setPopupMenuVisible(true);
  242. // windowMenu.setVisible(true);
  243. windowMenu.doClick();
  244. }
  245. public void paintComponent(Graphics g) {
  246. paintTitleBackground(g);
  247. if(frame.getTitle() != null) {
  248. boolean isSelected = frame.isSelected();
  249. Font f = g.getFont();
  250. g.setFont(getFont());
  251. if(isSelected)
  252. g.setColor(selectedTextColor);
  253. else
  254. g.setColor(notSelectedTextColor);
  255. // Center text vertically.
  256. FontMetrics fm = SwingUtilities2.getFontMetrics(frame, g);
  257. int baseline = (getHeight() + fm.getAscent() - fm.getLeading() -
  258. fm.getDescent()) / 2;
  259. int titleX;
  260. Rectangle r = new Rectangle(0, 0, 0, 0);
  261. if (frame.isIconifiable()) r = iconButton.getBounds();
  262. else if (frame.isMaximizable()) r = maxButton.getBounds();
  263. else if (frame.isClosable()) r = closeButton.getBounds();
  264. int titleW;
  265. String title = frame.getTitle();
  266. if( BasicGraphicsUtils.isLeftToRight(frame) ) {
  267. if (r.x == 0) r.x = frame.getWidth()-frame.getInsets().right;
  268. titleX = menuBar.getX() + menuBar.getWidth() + 2;
  269. titleW = r.x - titleX - 3;
  270. title = getTitle(frame.getTitle(), fm, titleW);
  271. } else {
  272. titleX = menuBar.getX() - 2
  273. - SwingUtilities2.stringWidth(frame,fm,title);
  274. }
  275. SwingUtilities2.drawString(frame, g, title, titleX, baseline);
  276. g.setFont(f);
  277. }
  278. }
  279. /**
  280. * Invoked from paintComponent.
  281. * Paints the background of the titlepane. All text and icons will
  282. * then be rendered on top of this background.
  283. * @param g the graphics to use to render the background
  284. * @since 1.4
  285. */
  286. protected void paintTitleBackground(Graphics g) {
  287. boolean isSelected = frame.isSelected();
  288. if(isSelected)
  289. g.setColor(selectedTitleColor);
  290. else
  291. g.setColor(notSelectedTitleColor);
  292. g.fillRect(0, 0, getWidth(), getHeight());
  293. }
  294. protected String getTitle(String text, FontMetrics fm, int availTextWidth) {
  295. return SwingUtilities2.clipStringIfNecessary(
  296. frame, fm, text, availTextWidth);
  297. }
  298. /**
  299. * Post a WINDOW_CLOSING-like event to the frame, so that it can
  300. * be treated like a regular Frame.
  301. */
  302. protected void postClosingEvent(JInternalFrame frame) {
  303. InternalFrameEvent e = new InternalFrameEvent(
  304. frame, InternalFrameEvent.INTERNAL_FRAME_CLOSING);
  305. // Try posting event, unless there's a SecurityManager.
  306. if (JInternalFrame.class.getClassLoader() == null) {
  307. try {
  308. Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(e);
  309. return;
  310. } catch (SecurityException se) {
  311. // Use dispatchEvent instead.
  312. }
  313. }
  314. frame.dispatchEvent(e);
  315. }
  316. protected void enableActions() {
  317. restoreAction.setEnabled(frame.isMaximum() || frame.isIcon());
  318. maximizeAction.setEnabled(
  319. (frame.isMaximizable() && !frame.isMaximum() && !frame.isIcon()) ||
  320. (frame.isMaximizable() && frame.isIcon()));
  321. iconifyAction.setEnabled(frame.isIconifiable() && !frame.isIcon());
  322. closeAction.setEnabled(frame.isClosable());
  323. sizeAction.setEnabled(false);
  324. moveAction.setEnabled(false);
  325. }
  326. private Handler getHandler() {
  327. if (handler == null) {
  328. handler = new Handler();
  329. }
  330. return handler;
  331. }
  332. protected PropertyChangeListener createPropertyChangeListener() {
  333. return getHandler();
  334. }
  335. protected LayoutManager createLayout() {
  336. return getHandler();
  337. }
  338. private class Handler implements LayoutManager, PropertyChangeListener {
  339. //
  340. // PropertyChangeListener
  341. //
  342. public void propertyChange(PropertyChangeEvent evt) {
  343. String prop = (String)evt.getPropertyName();
  344. if (prop == JInternalFrame.IS_SELECTED_PROPERTY) {
  345. repaint();
  346. return;
  347. }
  348. if (prop == JInternalFrame.IS_ICON_PROPERTY ||
  349. prop == JInternalFrame.IS_MAXIMUM_PROPERTY) {
  350. setButtonIcons();
  351. enableActions();
  352. return;
  353. }
  354. if ("closable" == prop) {
  355. if ((Boolean)evt.getNewValue() == Boolean.TRUE) {
  356. add(closeButton);
  357. } else {
  358. remove(closeButton);
  359. }
  360. } else if ("maximizable" == prop) {
  361. if ((Boolean)evt.getNewValue() == Boolean.TRUE) {
  362. add(maxButton);
  363. } else {
  364. remove(maxButton);
  365. }
  366. } else if ("iconable" == prop) {
  367. if ((Boolean)evt.getNewValue() == Boolean.TRUE) {
  368. add(iconButton);
  369. } else {
  370. remove(iconButton);
  371. }
  372. }
  373. enableActions();
  374. revalidate();
  375. repaint();
  376. }
  377. //
  378. // LayoutManager
  379. //
  380. public void addLayoutComponent(String name, Component c) {}
  381. public void removeLayoutComponent(Component c) {}
  382. public Dimension preferredLayoutSize(Container c) {
  383. return minimumLayoutSize(c);
  384. }
  385. public Dimension minimumLayoutSize(Container c) {
  386. // Calculate width.
  387. int width = 22;
  388. if (frame.isClosable()) {
  389. width += 19;
  390. }
  391. if (frame.isMaximizable()) {
  392. width += 19;
  393. }
  394. if (frame.isIconifiable()) {
  395. width += 19;
  396. }
  397. FontMetrics fm = frame.getFontMetrics(getFont());
  398. String frameTitle = frame.getTitle();
  399. int title_w = frameTitle != null ? SwingUtilities2.stringWidth(
  400. frame, fm, frameTitle) : 0;
  401. int title_length = frameTitle != null ? frameTitle.length() : 0;
  402. // Leave room for three characters in the title.
  403. if (title_length > 3) {
  404. int subtitle_w = SwingUtilities2.stringWidth(
  405. frame, fm, frameTitle.substring(0, 3) + "...");
  406. width += (title_w < subtitle_w) ? title_w : subtitle_w;
  407. } else {
  408. width += title_w;
  409. }
  410. // Calculate height.
  411. Icon icon = frame.getFrameIcon();
  412. int fontHeight = fm.getHeight();
  413. fontHeight += 2;
  414. int iconHeight = 0;
  415. if (icon != null) {
  416. // SystemMenuBar forces the icon to be 16x16 or less.
  417. iconHeight = Math.min(icon.getIconHeight(), 16);
  418. }
  419. iconHeight += 2;
  420. int height = Math.max( fontHeight, iconHeight );
  421. Dimension dim = new Dimension(width, height);
  422. // Take into account the border insets if any.
  423. if (getBorder() != null) {
  424. Insets insets = getBorder().getBorderInsets(c);
  425. dim.height += insets.top + insets.bottom;
  426. dim.width += insets.left + insets.right;
  427. }
  428. return dim;
  429. }
  430. public void layoutContainer(Container c) {
  431. boolean leftToRight = BasicGraphicsUtils.isLeftToRight(frame);
  432. int w = getWidth();
  433. int h = getHeight();
  434. int x;
  435. int buttonHeight = closeButton.getIcon().getIconHeight();
  436. Icon icon = frame.getFrameIcon();
  437. int iconHeight = 0;
  438. if (icon != null) {
  439. iconHeight = icon.getIconHeight();
  440. }
  441. x = (leftToRight) ? 2 : w - 16 - 2;
  442. menuBar.setBounds(x, (h - iconHeight) / 2, 16, 16);
  443. x = (leftToRight) ? w - 16 - 2 : 2;
  444. if (frame.isClosable()) {
  445. closeButton.setBounds(x, (h - buttonHeight) / 2, 16, 14);
  446. x += (leftToRight) ? -(16 + 2) : 16 + 2;
  447. }
  448. if (frame.isMaximizable()) {
  449. maxButton.setBounds(x, (h - buttonHeight) / 2, 16, 14);
  450. x += (leftToRight) ? -(16 + 2) : 16 + 2;
  451. }
  452. if (frame.isIconifiable()) {
  453. iconButton.setBounds(x, (h - buttonHeight) / 2, 16, 14);
  454. }
  455. }
  456. }
  457. /**
  458. * This class should be treated as a "protected" inner class.
  459. * Instantiate it only within subclasses of <Foo>.
  460. */
  461. public class PropertyChangeHandler implements PropertyChangeListener {
  462. // NOTE: This class exists only for backward compatability. All
  463. // its functionality has been moved into Handler. If you need to add
  464. // new functionality add it to the Handler, but make sure this
  465. // class calls into the Handler.
  466. public void propertyChange(PropertyChangeEvent evt) {
  467. getHandler().propertyChange(evt);
  468. }
  469. }
  470. /**
  471. * This class should be treated as a "protected" inner class.
  472. * Instantiate it only within subclasses of <Foo>.
  473. */
  474. public class TitlePaneLayout implements LayoutManager {
  475. // NOTE: This class exists only for backward compatability. All
  476. // its functionality has been moved into Handler. If you need to add
  477. // new functionality add it to the Handler, but make sure this
  478. // class calls into the Handler.
  479. public void addLayoutComponent(String name, Component c) {
  480. getHandler().addLayoutComponent(name, c);
  481. }
  482. public void removeLayoutComponent(Component c) {
  483. getHandler().removeLayoutComponent(c);
  484. }
  485. public Dimension preferredLayoutSize(Container c) {
  486. return getHandler().preferredLayoutSize(c);
  487. }
  488. public Dimension minimumLayoutSize(Container c) {
  489. return getHandler().minimumLayoutSize(c);
  490. }
  491. public void layoutContainer(Container c) {
  492. getHandler().layoutContainer(c);
  493. }
  494. }
  495. /**
  496. * This class should be treated as a "protected" inner class.
  497. * Instantiate it only within subclasses of <Foo>.
  498. */
  499. public class CloseAction extends AbstractAction {
  500. public CloseAction() {
  501. super(CLOSE_CMD);
  502. }
  503. public void actionPerformed(ActionEvent e) {
  504. if(frame.isClosable()) {
  505. frame.doDefaultCloseAction();
  506. }
  507. }
  508. } // end CloseAction
  509. /**
  510. * This class should be treated as a "protected" inner class.
  511. * Instantiate it only within subclasses of <Foo>.
  512. */
  513. public class MaximizeAction extends AbstractAction {
  514. public MaximizeAction() {
  515. super(MAXIMIZE_CMD);
  516. }
  517. public void actionPerformed(ActionEvent evt) {
  518. if (frame.isMaximizable()) {
  519. if (frame.isMaximum() && frame.isIcon()) {
  520. try {
  521. frame.setIcon(false);
  522. } catch (PropertyVetoException e) { }
  523. } else if (!frame.isMaximum()) {
  524. try {
  525. frame.setMaximum(true);
  526. } catch (PropertyVetoException e) { }
  527. } else {
  528. try {
  529. frame.setMaximum(false);
  530. } catch (PropertyVetoException e) { }
  531. }
  532. }
  533. }
  534. }
  535. /**
  536. * This class should be treated as a "protected" inner class.
  537. * Instantiate it only within subclasses of <Foo>.
  538. */
  539. public class IconifyAction extends AbstractAction {
  540. public IconifyAction() {
  541. super(ICONIFY_CMD);
  542. }
  543. public void actionPerformed(ActionEvent e) {
  544. if(frame.isIconifiable()) {
  545. if(!frame.isIcon()) {
  546. try { frame.setIcon(true); } catch (PropertyVetoException e1) { }
  547. } else{
  548. try { frame.setIcon(false); } catch (PropertyVetoException e1) { }
  549. }
  550. }
  551. }
  552. } // end IconifyAction
  553. /**
  554. * This class should be treated as a "protected" inner class.
  555. * Instantiate it only within subclasses of <Foo>.
  556. */
  557. public class RestoreAction extends AbstractAction {
  558. public RestoreAction() {
  559. super(RESTORE_CMD);
  560. }
  561. public void actionPerformed(ActionEvent evt) {
  562. if (frame.isMaximizable() && frame.isMaximum() && frame.isIcon()) {
  563. try {
  564. frame.setIcon(false);
  565. } catch (PropertyVetoException e) { }
  566. } else if (frame.isMaximizable() && frame.isMaximum()) {
  567. try {
  568. frame.setMaximum(false);
  569. } catch (PropertyVetoException e) { }
  570. } else if (frame.isIconifiable() && frame.isIcon()) {
  571. try {
  572. frame.setIcon(false);
  573. } catch (PropertyVetoException e) { }
  574. }
  575. }
  576. }
  577. /**
  578. * This class should be treated as a "protected" inner class.
  579. * Instantiate it only within subclasses of <Foo>.
  580. */
  581. public class MoveAction extends AbstractAction {
  582. public MoveAction() {
  583. super(MOVE_CMD);
  584. }
  585. public void actionPerformed(ActionEvent e) {
  586. // This action is currently undefined
  587. }
  588. } // end MoveAction
  589. /*
  590. * Handles showing and hiding the system menu.
  591. */
  592. private class ShowSystemMenuAction extends AbstractAction {
  593. private boolean show; // whether to show the menu
  594. public ShowSystemMenuAction(boolean show) {
  595. this.show = show;
  596. }
  597. public void actionPerformed(ActionEvent e) {
  598. if (show) {
  599. windowMenu.doClick();
  600. } else {
  601. windowMenu.setVisible(false);
  602. }
  603. }
  604. }
  605. /**
  606. * This class should be treated as a "protected" inner class.
  607. * Instantiate it only within subclasses of <Foo>.
  608. */
  609. public class SizeAction extends AbstractAction {
  610. public SizeAction() {
  611. super(SIZE_CMD);
  612. }
  613. public void actionPerformed(ActionEvent e) {
  614. // This action is currently undefined
  615. }
  616. } // end SizeAction
  617. /**
  618. * This class should be treated as a "protected" inner class.
  619. * Instantiate it only within subclasses of <Foo>.
  620. */
  621. public class SystemMenuBar extends JMenuBar {
  622. public boolean isFocusTraversable() { return false; }
  623. public void requestFocus() {}
  624. public void paint(Graphics g) {
  625. Icon icon = frame.getFrameIcon();
  626. if (icon == null) {
  627. icon = (Icon)DefaultLookup.get(frame, frame.getUI(),
  628. "InternalFrame.icon");
  629. }
  630. if (icon != null) {
  631. // Resize to 16x16 if necessary.
  632. if (icon instanceof ImageIcon && (icon.getIconWidth() > 16 || icon.getIconHeight() > 16)) {
  633. Image img = ((ImageIcon)icon).getImage();
  634. ((ImageIcon)icon).setImage(img.getScaledInstance(16, 16, Image.SCALE_SMOOTH));
  635. }
  636. icon.paintIcon(this, g, 0, 0);
  637. }
  638. }
  639. public boolean isOpaque() {
  640. return true;
  641. }
  642. } // end SystemMenuBar
  643. private class NoFocusButton extends JButton {
  644. private String uiKey;
  645. public NoFocusButton(String uiKey) {
  646. setFocusPainted(false);
  647. setMargin(new Insets(0,0,0,0));
  648. setOpaque(true);
  649. this.uiKey = uiKey;
  650. }
  651. public boolean isFocusTraversable() { return false; }
  652. public void requestFocus() {};
  653. public AccessibleContext getAccessibleContext() {
  654. AccessibleContext ac = super.getAccessibleContext();
  655. if (uiKey != null) {
  656. ac.setAccessibleName(UIManager.getString(uiKey));
  657. uiKey = null;
  658. }
  659. return ac;
  660. }
  661. }; // end NoFocusButton
  662. } // End Title Pane Class