1. /*
  2. * @(#)BasicInternalFrameUI.java 1.110 03/02/19
  3. *
  4. * Copyright 2003 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 java.awt.*;
  9. import java.awt.event.*;
  10. import java.awt.peer.LightweightPeer;
  11. import javax.swing.*;
  12. import javax.swing.border.*;
  13. import javax.swing.plaf.*;
  14. import javax.swing.event.*;
  15. import java.beans.*;
  16. import java.io.Serializable;
  17. /**
  18. * A basic L&F implementation of JInternalFrame.
  19. *
  20. * @version 1.110 02/19/03
  21. * @author David Kloba
  22. * @author Rich Schiavi
  23. */
  24. public class BasicInternalFrameUI extends InternalFrameUI
  25. {
  26. protected JInternalFrame frame;
  27. protected MouseInputAdapter borderListener;
  28. protected PropertyChangeListener propertyChangeListener;
  29. protected LayoutManager internalFrameLayout;
  30. protected ComponentListener componentListener;
  31. protected MouseInputListener glassPaneDispatcher;
  32. protected JComponent northPane;
  33. protected JComponent southPane;
  34. protected JComponent westPane;
  35. protected JComponent eastPane;
  36. protected BasicInternalFrameTitlePane titlePane; // access needs this
  37. private static DesktopManager sharedDesktopManager;
  38. private boolean componentListenerAdded = false;
  39. private Rectangle parentBounds;
  40. private boolean dragging = false;
  41. /**
  42. * As of Java 2 platform v1.3 this previously undocumented field is no
  43. * longer used.
  44. * Key bindings are now defined by the LookAndFeel, please refer to
  45. * the key bindings specification for further details.
  46. *
  47. * @deprecated As of Java 2 platform v1.3.
  48. */
  49. protected KeyStroke openMenuKey;
  50. private boolean keyBindingRegistered = false;
  51. private boolean keyBindingActive = false;
  52. private InternalFrameListener internalFrameListener = null;
  53. /////////////////////////////////////////////////////////////////////////////
  54. // ComponentUI Interface Implementation methods
  55. /////////////////////////////////////////////////////////////////////////////
  56. public static ComponentUI createUI(JComponent b) {
  57. return new BasicInternalFrameUI((JInternalFrame)b);
  58. }
  59. public BasicInternalFrameUI(JInternalFrame b) {
  60. }
  61. public void installUI(JComponent c) {
  62. frame = (JInternalFrame)c;
  63. installDefaults();
  64. installListeners();
  65. installComponents();
  66. installKeyboardActions();
  67. frame.setOpaque(true);
  68. }
  69. public void uninstallUI(JComponent c) {
  70. if(c != frame)
  71. throw new IllegalComponentStateException(
  72. this + " was asked to deinstall() "
  73. + c + " when it only knows about "
  74. + frame + ".");
  75. uninstallKeyboardActions();
  76. uninstallComponents();
  77. uninstallListeners();
  78. uninstallDefaults();
  79. frame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
  80. frame = null;
  81. }
  82. protected void installDefaults(){
  83. Icon frameIcon = frame.getFrameIcon();
  84. if (frameIcon == null || frameIcon instanceof UIResource) {
  85. frame.setFrameIcon(UIManager.getIcon("InternalFrame.icon"));
  86. }
  87. /* enable the content pane to inherit background color from its
  88. parent by setting its background color to null. Fixes bug#
  89. 4268949. */
  90. JComponent contentPane = (JComponent) frame.getContentPane();
  91. if (contentPane != null) {
  92. Color bg = contentPane.getBackground();
  93. if (bg instanceof UIResource)
  94. contentPane.setBackground(null);
  95. }
  96. frame.setLayout(internalFrameLayout = createLayoutManager());
  97. frame.setBackground(UIManager.getLookAndFeelDefaults().getColor("control"));
  98. LookAndFeel.installBorder(frame, "InternalFrame.border");
  99. }
  100. protected void installKeyboardActions(){
  101. if (internalFrameListener == null)
  102. createInternalFrameListener();
  103. frame.addInternalFrameListener(internalFrameListener);
  104. ActionMap actionMap = getActionMap();
  105. SwingUtilities.replaceUIActionMap(frame, actionMap);
  106. }
  107. ActionMap getActionMap() {
  108. ActionMap map = (ActionMap)UIManager.get("InternalFrame.actionMap");
  109. if (map == null) {
  110. map = createActionMap();
  111. if (map != null) {
  112. UIManager.getLookAndFeelDefaults().put("InternalFrame.actionMap",
  113. map);
  114. }
  115. }
  116. return map;
  117. }
  118. ActionMap createActionMap() {
  119. ActionMap map = new ActionMapUIResource();
  120. // add action for the system menu
  121. map.put("showSystemMenu", new AbstractAction(){
  122. public void actionPerformed(ActionEvent e){
  123. titlePane.showSystemMenu();
  124. }
  125. public boolean isEnabled(){
  126. return isKeyBindingActive();
  127. }
  128. });
  129. // Set the ActionMap's parent to the Auditory Feedback Action Map
  130. BasicLookAndFeel lf = (BasicLookAndFeel)UIManager.getLookAndFeel();
  131. ActionMap audioMap = lf.getAudioActionMap();
  132. map.setParent(audioMap);
  133. return map;
  134. }
  135. protected void installComponents(){
  136. setNorthPane(createNorthPane(frame));
  137. setSouthPane(createSouthPane(frame));
  138. setEastPane(createEastPane(frame));
  139. setWestPane(createWestPane(frame));
  140. }
  141. /*
  142. * @since 1.3
  143. */
  144. protected void installListeners() {
  145. borderListener = createBorderListener(frame);
  146. propertyChangeListener = createPropertyChangeListener();
  147. frame.addPropertyChangeListener(propertyChangeListener);
  148. installMouseHandlers(frame);
  149. glassPaneDispatcher = createGlassPaneDispatcher();
  150. frame.getGlassPane().addMouseListener(glassPaneDispatcher);
  151. frame.getGlassPane().addMouseMotionListener(glassPaneDispatcher);
  152. componentListener = createComponentListener();
  153. if (frame.getParent() != null) {
  154. parentBounds = frame.getParent().getBounds();
  155. }
  156. if ((frame.getParent() != null) && !componentListenerAdded) {
  157. frame.getParent().addComponentListener(componentListener);
  158. componentListenerAdded = true;
  159. }
  160. }
  161. InputMap getInputMap(int condition) {
  162. if (condition == JComponent.WHEN_IN_FOCUSED_WINDOW) {
  163. return createInputMap(condition);
  164. }
  165. return null;
  166. }
  167. InputMap createInputMap(int condition) {
  168. if (condition == JComponent.WHEN_IN_FOCUSED_WINDOW) {
  169. Object[] bindings = (Object[])UIManager.get
  170. ("InternalFrame.windowBindings");
  171. if (bindings != null) {
  172. return LookAndFeel.makeComponentInputMap(frame, bindings);
  173. }
  174. }
  175. return null;
  176. }
  177. protected void uninstallDefaults() {
  178. Icon frameIcon = frame.getFrameIcon();
  179. if (frameIcon instanceof UIResource) {
  180. frame.setFrameIcon(null);
  181. }
  182. internalFrameLayout = null;
  183. frame.setLayout(null);
  184. LookAndFeel.uninstallBorder(frame);
  185. }
  186. protected void uninstallComponents(){
  187. setNorthPane(null);
  188. setSouthPane(null);
  189. setEastPane(null);
  190. setWestPane(null);
  191. titlePane = null;
  192. }
  193. /*
  194. * @since 1.3
  195. */
  196. protected void uninstallListeners() {
  197. if ((frame.getParent() != null) && componentListenerAdded) {
  198. frame.getParent().removeComponentListener(componentListener);
  199. componentListenerAdded = false;
  200. }
  201. componentListener = null;
  202. frame.getGlassPane().removeMouseListener(glassPaneDispatcher);
  203. frame.getGlassPane().removeMouseMotionListener(glassPaneDispatcher);
  204. glassPaneDispatcher = null;
  205. deinstallMouseHandlers(frame);
  206. frame.removePropertyChangeListener(propertyChangeListener);
  207. propertyChangeListener = null;
  208. borderListener = null;
  209. }
  210. protected void uninstallKeyboardActions(){
  211. if (internalFrameListener != null) {
  212. frame.removeInternalFrameListener(internalFrameListener);
  213. }
  214. SwingUtilities.replaceUIInputMap(frame, JComponent.
  215. WHEN_IN_FOCUSED_WINDOW, null);
  216. SwingUtilities.replaceUIActionMap(frame, null);
  217. }
  218. protected LayoutManager createLayoutManager(){
  219. return new InternalFrameLayout();
  220. }
  221. protected PropertyChangeListener createPropertyChangeListener(){
  222. return new InternalFramePropertyChangeListener();
  223. }
  224. public Dimension getPreferredSize(JComponent x) {
  225. if((JComponent)frame == x)
  226. return frame.getLayout().preferredLayoutSize(x);
  227. return new Dimension(100, 100);
  228. }
  229. public Dimension getMinimumSize(JComponent x) {
  230. if((JComponent)frame == x) {
  231. return frame.getLayout().minimumLayoutSize(x);
  232. }
  233. return new Dimension(0, 0);
  234. }
  235. public Dimension getMaximumSize(JComponent x) {
  236. return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
  237. }
  238. /**
  239. * Installs necessary mouse handlers on <code>newPane</code>
  240. * and adds it to the frame.
  241. * Reverse process for the <code>currentPane</code>.
  242. */
  243. protected void replacePane(JComponent currentPane, JComponent newPane) {
  244. if(currentPane != null) {
  245. deinstallMouseHandlers(currentPane);
  246. frame.remove(currentPane);
  247. }
  248. if(newPane != null) {
  249. frame.add(newPane);
  250. installMouseHandlers(newPane);
  251. }
  252. }
  253. protected void deinstallMouseHandlers(JComponent c) {
  254. c.removeMouseListener(borderListener);
  255. c.removeMouseMotionListener(borderListener);
  256. }
  257. protected void installMouseHandlers(JComponent c) {
  258. c.addMouseListener(borderListener);
  259. c.addMouseMotionListener(borderListener);
  260. }
  261. protected JComponent createNorthPane(JInternalFrame w) {
  262. titlePane = new BasicInternalFrameTitlePane(w);
  263. return titlePane;
  264. }
  265. protected JComponent createSouthPane(JInternalFrame w) {
  266. return null;
  267. }
  268. protected JComponent createWestPane(JInternalFrame w) {
  269. return null;
  270. }
  271. protected JComponent createEastPane(JInternalFrame w) {
  272. return null;
  273. }
  274. protected MouseInputAdapter createBorderListener(JInternalFrame w) {
  275. return new BorderListener();
  276. }
  277. private InternalFrameListener getInternalFrameListener(){
  278. return internalFrameListener;
  279. }
  280. protected void createInternalFrameListener(){
  281. internalFrameListener = new BasicInternalFrameListener();
  282. }
  283. protected final boolean isKeyBindingRegistered(){
  284. return keyBindingRegistered;
  285. }
  286. protected final void setKeyBindingRegistered(boolean b){
  287. keyBindingRegistered = b;
  288. }
  289. public final boolean isKeyBindingActive(){
  290. return keyBindingActive;
  291. }
  292. protected final void setKeyBindingActive(boolean b){
  293. keyBindingActive = b;
  294. }
  295. protected void setupMenuOpenKey(){
  296. // PENDING(hania): Why are these WHEN_IN_FOCUSED_WINDOWs? Shouldn't
  297. // they be WHEN_ANCESTOR_OF_FOCUSED_COMPONENT?
  298. // Also, no longer registering on the desktopicon, the previous
  299. // action did nothing.
  300. InputMap map = getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
  301. SwingUtilities.replaceUIInputMap(frame,
  302. JComponent.WHEN_IN_FOCUSED_WINDOW, map);
  303. //ActionMap actionMap = getActionMap();
  304. //SwingUtilities.replaceUIActionMap(frame, actionMap);
  305. }
  306. protected void setupMenuCloseKey(){
  307. }
  308. public JComponent getNorthPane() {
  309. return northPane;
  310. }
  311. public void setNorthPane(JComponent c) {
  312. if (northPane != null &&
  313. northPane instanceof BasicInternalFrameTitlePane) {
  314. ((BasicInternalFrameTitlePane)northPane).uninstallListeners();
  315. }
  316. replacePane(northPane, c);
  317. northPane = c;
  318. }
  319. public JComponent getSouthPane() {
  320. return southPane;
  321. }
  322. public void setSouthPane(JComponent c) {
  323. southPane = c;
  324. }
  325. public JComponent getWestPane() {
  326. return westPane;
  327. }
  328. public void setWestPane(JComponent c) {
  329. westPane = c;
  330. }
  331. public JComponent getEastPane() {
  332. return eastPane;
  333. }
  334. public void setEastPane(JComponent c) {
  335. eastPane = c;
  336. }
  337. public class InternalFramePropertyChangeListener implements
  338. PropertyChangeListener {
  339. /**
  340. * Detects changes in state from the JInternalFrame and handles
  341. * actions.
  342. */
  343. public void propertyChange(PropertyChangeEvent evt) {
  344. String prop = (String)evt.getPropertyName();
  345. JInternalFrame f = (JInternalFrame)evt.getSource();
  346. Object newValue = evt.getNewValue();
  347. Object oldValue = evt.getOldValue();
  348. if (JInternalFrame.IS_CLOSED_PROPERTY.equals(prop)) {
  349. if (newValue == Boolean.TRUE) {
  350. if ((frame.getParent() != null) && componentListenerAdded) {
  351. frame.getParent().removeComponentListener(
  352. componentListener);
  353. }
  354. closeFrame(f);
  355. }
  356. } else if (JInternalFrame.IS_MAXIMUM_PROPERTY.equals(prop)) {
  357. if(newValue == Boolean.TRUE) {
  358. maximizeFrame(f);
  359. } else {
  360. minimizeFrame(f);
  361. }
  362. } else if(JInternalFrame.IS_ICON_PROPERTY.equals(prop)) {
  363. if (newValue == Boolean.TRUE) {
  364. iconifyFrame(f);
  365. } else {
  366. deiconifyFrame(f);
  367. }
  368. } else if (JInternalFrame.IS_SELECTED_PROPERTY.equals(prop)) {
  369. Component glassPane = f.getGlassPane();
  370. if (newValue == Boolean.TRUE && oldValue == Boolean.FALSE) {
  371. activateFrame(f);
  372. glassPane.setVisible(false);
  373. } else if (newValue == Boolean.FALSE &&
  374. oldValue == Boolean.TRUE) {
  375. deactivateFrame(f);
  376. glassPane.setVisible(true);
  377. }
  378. } else if (prop.equals("ancestor")) {
  379. if (frame.getParent() != null) {
  380. parentBounds = f.getParent().getBounds();
  381. } else {
  382. parentBounds = null;
  383. }
  384. if ((frame.getParent() != null) && !componentListenerAdded) {
  385. f.getParent().addComponentListener(componentListener);
  386. componentListenerAdded = true;
  387. } else if ((newValue == null) && componentListenerAdded) {
  388. if (f.getParent() != null) {
  389. f.getParent().removeComponentListener(
  390. componentListener);
  391. }
  392. componentListenerAdded = false;
  393. }
  394. } else if (JInternalFrame.TITLE_PROPERTY.equals(prop) ||
  395. prop.equals("closable") || prop.equals("iconable") ||
  396. prop.equals("maximizable")) {
  397. Dimension dim = frame.getMinimumSize();
  398. Dimension frame_dim = frame.getSize();
  399. if (dim.width > frame_dim.width) {
  400. frame.setSize(dim.width, frame_dim.height);
  401. }
  402. }
  403. }
  404. }
  405. public class InternalFrameLayout implements LayoutManager {
  406. public void addLayoutComponent(String name, Component c) {}
  407. public void removeLayoutComponent(Component c) {}
  408. public Dimension preferredLayoutSize(Container c) {
  409. Dimension result;
  410. Insets i = frame.getInsets();
  411. result = new Dimension(frame.getRootPane().getPreferredSize());
  412. result.width += i.left + i.right;
  413. result.height += i.top + i.bottom;
  414. if(getNorthPane() != null) {
  415. Dimension d = getNorthPane().getPreferredSize();
  416. result.width = Math.max(d.width, result.width);
  417. result.height += d.height;
  418. }
  419. if(getSouthPane() != null) {
  420. Dimension d = getSouthPane().getPreferredSize();
  421. result.width = Math.max(d.width, result.width);
  422. result.height += d.height;
  423. }
  424. if(getEastPane() != null) {
  425. Dimension d = getEastPane().getPreferredSize();
  426. result.width += d.width;
  427. result.height = Math.max(d.height, result.height);
  428. }
  429. if(getWestPane() != null) {
  430. Dimension d = getWestPane().getPreferredSize();
  431. result.width += d.width;
  432. result.height = Math.max(d.height, result.height);
  433. }
  434. return result;
  435. }
  436. public Dimension minimumLayoutSize(Container c) {
  437. // The minimum size of the internal frame only takes into account the
  438. // title pane since you are allowed to resize the frames to the point
  439. // where just the title pane is visible.
  440. Dimension result = new Dimension();
  441. if (getNorthPane() != null &&
  442. getNorthPane() instanceof BasicInternalFrameTitlePane) {
  443. result = new Dimension(getNorthPane().getMinimumSize());
  444. }
  445. Insets i = frame.getInsets();
  446. result.width += i.left + i.right;
  447. result.height += i.top + i.bottom;
  448. return result;
  449. }
  450. public void layoutContainer(Container c) {
  451. Insets i = frame.getInsets();
  452. int cx, cy, cw, ch;
  453. cx = i.left;
  454. cy = i.top;
  455. cw = frame.getWidth() - i.left - i.right;
  456. ch = frame.getHeight() - i.top - i.bottom;
  457. if(getNorthPane() != null) {
  458. Dimension size = getNorthPane().getPreferredSize();
  459. getNorthPane().setBounds(cx, cy, cw, size.height);
  460. cy += size.height;
  461. ch -= size.height;
  462. }
  463. if(getSouthPane() != null) {
  464. Dimension size = getSouthPane().getPreferredSize();
  465. getSouthPane().setBounds(cx, frame.getHeight()
  466. - i.bottom - size.height,
  467. cw, size.height);
  468. ch -= size.height;
  469. }
  470. if(getWestPane() != null) {
  471. Dimension size = getWestPane().getPreferredSize();
  472. getWestPane().setBounds(cx, cy, size.width, ch);
  473. cw -= size.width;
  474. cx += size.width;
  475. }
  476. if(getEastPane() != null) {
  477. Dimension size = getEastPane().getPreferredSize();
  478. getEastPane().setBounds(cw - size.width, cy, size.width, ch);
  479. cw -= size.width;
  480. }
  481. if(frame.getRootPane() != null) {
  482. frame.getRootPane().setBounds(cx, cy, cw, ch);
  483. }
  484. }
  485. }
  486. /// DesktopManager methods
  487. /** Returns the proper DesktopManager. Calls getDesktopPane() to
  488. * find the JDesktop component and returns the desktopManager from
  489. * it. If this fails, it will return a default DesktopManager that
  490. * should work in arbitrary parents.
  491. */
  492. protected DesktopManager getDesktopManager() {
  493. if(frame.getDesktopPane() != null
  494. && frame.getDesktopPane().getDesktopManager() != null)
  495. return frame.getDesktopPane().getDesktopManager();
  496. if(sharedDesktopManager == null)
  497. sharedDesktopManager = createDesktopManager();
  498. return sharedDesktopManager;
  499. }
  500. protected DesktopManager createDesktopManager(){
  501. return new DefaultDesktopManager();
  502. }
  503. /**
  504. * This method is called when the user wants to close the frame.
  505. * The <code>playCloseSound</code> Action is fired.
  506. * This action is delegated to the desktopManager.
  507. */
  508. protected void closeFrame(JInternalFrame f) {
  509. // Internal Frame Auditory Cue Activation
  510. fireAudioAction("InternalFrame.closeSound");
  511. // delegate to desktop manager
  512. getDesktopManager().closeFrame(f);
  513. }
  514. /**
  515. * This method is called when the user wants to maximize the frame.
  516. * The <code>playMaximizeSound</code> Action is fired.
  517. * This action is delegated to the desktopManager.
  518. */
  519. protected void maximizeFrame(JInternalFrame f) {
  520. // Internal Frame Auditory Cue Activation
  521. fireAudioAction("InternalFrame.maximizeSound");
  522. // delegate to desktop manager
  523. getDesktopManager().maximizeFrame(f);
  524. }
  525. /**
  526. * This method is called when the user wants to minimize the frame.
  527. * The <code>playRestoreDownSound</code> Action is fired.
  528. * This action is delegated to the desktopManager.
  529. */
  530. protected void minimizeFrame(JInternalFrame f) {
  531. // Internal Frame Auditory Cue Activation
  532. if ( ! f.isIcon() ) {
  533. // This method seems to regularly get called after an
  534. // internal frame is iconified. Don't play this sound then.
  535. fireAudioAction("InternalFrame.restoreDownSound");
  536. }
  537. // delegate to desktop manager
  538. getDesktopManager().minimizeFrame(f);
  539. }
  540. /**
  541. * This method is called when the user wants to iconify the frame.
  542. * The <code>playMinimizeSound</code> Action is fired.
  543. * This action is delegated to the desktopManager.
  544. */
  545. protected void iconifyFrame(JInternalFrame f) {
  546. // Internal Frame Auditory Cue Activation
  547. fireAudioAction("InternalFrame.minimizeSound");
  548. // delegate to desktop manager
  549. getDesktopManager().iconifyFrame(f);
  550. }
  551. /**
  552. * This method is called when the user wants to deiconify the frame.
  553. * The <code>playRestoreUpSound</code> Action is fired.
  554. * This action is delegated to the desktopManager.
  555. */
  556. protected void deiconifyFrame(JInternalFrame f) {
  557. // Internal Frame Auditory Cue Activation
  558. if ( ! f.isMaximum() ) {
  559. // This method seems to regularly get called after an
  560. // internal frame is maximized. Don't play this sound then.
  561. fireAudioAction("InternalFrame.restoreUpSound");
  562. }
  563. // delegate to desktop manager
  564. getDesktopManager().deiconifyFrame(f);
  565. }
  566. /** This method is called when the frame becomes selected.
  567. * This action is delegated to the desktopManager.
  568. */
  569. protected void activateFrame(JInternalFrame f) {
  570. getDesktopManager().activateFrame(f);
  571. }
  572. /** This method is called when the frame is no longer selected.
  573. * This action is delegated to the desktopManager.
  574. */
  575. protected void deactivateFrame(JInternalFrame f) {
  576. getDesktopManager().deactivateFrame(f);
  577. }
  578. /**
  579. * Convenience method for firing off the auditory cue actions.
  580. *
  581. * @since 1.4
  582. */
  583. private void fireAudioAction (String actionName) {
  584. ActionMap map = frame.getActionMap();
  585. if (map != null) {
  586. Action audioAction = map.get(actionName);
  587. if (audioAction != null) {
  588. // pass off firing the Action to a utility method
  589. BasicLookAndFeel lf = (BasicLookAndFeel)
  590. UIManager.getLookAndFeel();
  591. lf.playSound(audioAction);
  592. }
  593. }
  594. }
  595. /////////////////////////////////////////////////////////////////////////
  596. /// Border Listener Class
  597. /////////////////////////////////////////////////////////////////////////
  598. /**
  599. * Listens for border adjustments.
  600. */
  601. protected class BorderListener extends MouseInputAdapter implements SwingConstants
  602. {
  603. // _x & _y are the mousePressed location in absolute coordinate system
  604. int _x, _y;
  605. // __x & __y are the mousePressed location in source view's coordinate system
  606. int __x, __y;
  607. Rectangle startingBounds;
  608. int resizeDir;
  609. protected final int RESIZE_NONE = 0;
  610. private boolean discardRelease = false;
  611. int resizeCornerSize = 16;
  612. public void mouseClicked(MouseEvent e) {
  613. if(e.getClickCount() > 1 && e.getSource() == getNorthPane()) {
  614. if(frame.isIconifiable() && frame.isIcon()) {
  615. try { frame.setIcon(false); } catch (PropertyVetoException e2) { }
  616. } else if(frame.isMaximizable()) {
  617. if(!frame.isMaximum())
  618. try { frame.setMaximum(true); } catch (PropertyVetoException e2) { }
  619. else
  620. try { frame.setMaximum(false); } catch (PropertyVetoException e3) { }
  621. }
  622. }
  623. }
  624. public void mouseReleased(MouseEvent e) {
  625. if (discardRelease) {
  626. discardRelease = false;
  627. return;
  628. }
  629. if (resizeDir == RESIZE_NONE) {
  630. getDesktopManager().endDraggingFrame(frame);
  631. dragging = false;
  632. } else {
  633. Container c = frame.getTopLevelAncestor();
  634. if (c instanceof JFrame) {
  635. ((JFrame)frame.getTopLevelAncestor()).getGlassPane().setCursor(
  636. Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
  637. ((JFrame)frame.getTopLevelAncestor()).getGlassPane(
  638. ).setVisible(false);
  639. } else if (c instanceof JApplet) {
  640. ((JApplet)c).getGlassPane().setCursor(
  641. Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
  642. ((JApplet)c).getGlassPane().setVisible(false);
  643. } else if (c instanceof JWindow) {
  644. ((JWindow)c).getGlassPane().setCursor(
  645. Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
  646. ((JWindow)c).getGlassPane().setVisible(false);
  647. } else if (c instanceof JDialog) {
  648. ((JDialog)c).getGlassPane().setCursor(
  649. Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
  650. ((JDialog)c).getGlassPane().setVisible(false);
  651. }
  652. getDesktopManager().endResizingFrame(frame);
  653. }
  654. _x = 0;
  655. _y = 0;
  656. __x = 0;
  657. __y = 0;
  658. startingBounds = null;
  659. resizeDir = RESIZE_NONE;
  660. }
  661. public void mousePressed(MouseEvent e) {
  662. Point p = SwingUtilities.convertPoint((Component)e.getSource(),
  663. e.getX(), e.getY(), null);
  664. __x = e.getX();
  665. __y = e.getY();
  666. _x = p.x;
  667. _y = p.y;
  668. startingBounds = frame.getBounds();
  669. resizeDir = RESIZE_NONE;
  670. if(!frame.isSelected()) {
  671. try { frame.setSelected(true); }
  672. catch (PropertyVetoException e1) { }
  673. }
  674. Insets i = frame.getInsets();
  675. Point ep = new Point(__x, __y);
  676. if (e.getSource() == getNorthPane()) {
  677. Point np = getNorthPane().getLocation();
  678. ep.x += np.x;
  679. ep.y += np.y;
  680. }
  681. if (e.getSource() == getNorthPane()) {
  682. if (ep.x > i.left && ep.y > i.top && ep.x < frame.getWidth() - i.right) {
  683. getDesktopManager().beginDraggingFrame(frame);
  684. dragging = true;
  685. return;
  686. }
  687. }
  688. if (!frame.isResizable()) {
  689. return;
  690. }
  691. if (e.getSource() == frame || e.getSource() == getNorthPane()) {
  692. if (ep.x <= i.left) {
  693. if (ep.y < resizeCornerSize + i.top) {
  694. resizeDir = NORTH_WEST;
  695. } else if (ep.y > frame.getHeight()
  696. - resizeCornerSize - i.bottom) {
  697. resizeDir = SOUTH_WEST;
  698. } else {
  699. resizeDir = WEST;
  700. }
  701. } else if (ep.x >= frame.getWidth() - i.right) {
  702. if (ep.y < resizeCornerSize + i.top) {
  703. resizeDir = NORTH_EAST;
  704. } else if (ep.y > frame.getHeight()
  705. - resizeCornerSize - i.bottom) {
  706. resizeDir = SOUTH_EAST;
  707. } else {
  708. resizeDir = EAST;
  709. }
  710. } else if (ep.y <= i.top) {
  711. if (ep.x < resizeCornerSize + i.left) {
  712. resizeDir = NORTH_WEST;
  713. } else if (ep.x > frame.getWidth()
  714. - resizeCornerSize - i.right) {
  715. resizeDir = NORTH_EAST;
  716. } else {
  717. resizeDir = NORTH;
  718. }
  719. } else if (ep.y >= frame.getHeight() - i.bottom) {
  720. if (ep.x < resizeCornerSize + i.left) {
  721. resizeDir = SOUTH_WEST;
  722. } else if (ep.x > frame.getWidth()
  723. - resizeCornerSize - i.right) {
  724. resizeDir = SOUTH_EAST;
  725. } else {
  726. resizeDir = SOUTH;
  727. }
  728. } else {
  729. /* the mouse press happened inside the frame, not in the
  730. border */
  731. discardRelease = true;
  732. return;
  733. }
  734. Cursor s = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
  735. switch (resizeDir) {
  736. case SOUTH:
  737. s = Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR);
  738. break;
  739. case NORTH:
  740. s = Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR);
  741. break;
  742. case WEST:
  743. s = Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR);
  744. break;
  745. case EAST:
  746. s = Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR);
  747. break;
  748. case SOUTH_EAST:
  749. s = Cursor.getPredefinedCursor(Cursor.SE_RESIZE_CURSOR);
  750. break;
  751. case SOUTH_WEST:
  752. s = Cursor.getPredefinedCursor(Cursor.SW_RESIZE_CURSOR);
  753. break;
  754. case NORTH_WEST:
  755. s = Cursor.getPredefinedCursor(Cursor.NW_RESIZE_CURSOR);
  756. break;
  757. case NORTH_EAST:
  758. s = Cursor.getPredefinedCursor(Cursor.NE_RESIZE_CURSOR);
  759. break;
  760. }
  761. Container c = frame.getTopLevelAncestor();
  762. if (c instanceof JFrame){
  763. ((JFrame)c).getGlassPane().setVisible(true);
  764. ((JFrame)c).getGlassPane().setCursor(s);
  765. } else if (c instanceof JApplet){
  766. ((JApplet)c).getGlassPane().setVisible(true);
  767. ((JApplet)c).getGlassPane().setCursor(s);
  768. } else if (c instanceof JWindow){
  769. ((JWindow)c).getGlassPane().setVisible(true);
  770. ((JWindow)c).getGlassPane().setCursor(s);
  771. } else if (c instanceof JDialog){
  772. ((JDialog)c).getGlassPane().setVisible(true);
  773. ((JDialog)c).getGlassPane().setCursor(s);
  774. }
  775. getDesktopManager().beginResizingFrame(frame, resizeDir);
  776. return;
  777. }
  778. }
  779. public void mouseDragged(MouseEvent e) {
  780. if ( startingBounds == null ) {
  781. // (STEVE) Yucky work around for bug ID 4106552
  782. return;
  783. }
  784. Point p = SwingUtilities.convertPoint((Component)e.getSource(),
  785. e.getX(), e.getY(), null);
  786. int deltaX = _x - p.x;
  787. int deltaY = _y - p.y;
  788. Dimension min = frame.getMinimumSize();
  789. Dimension max = frame.getMaximumSize();
  790. int newX, newY, newW, newH;
  791. Insets i = frame.getInsets();
  792. // Handle a MOVE
  793. if (dragging) {
  794. if (frame.isMaximum() || ((e.getModifiers() &
  795. InputEvent.BUTTON1_MASK) !=
  796. InputEvent.BUTTON1_MASK)) {
  797. // don't allow moving of frames if maximixed or left mouse
  798. // button was not used.
  799. return;
  800. }
  801. int pWidth, pHeight;
  802. Dimension s = frame.getParent().getSize();
  803. pWidth = s.width;
  804. pHeight = s.height;
  805. newX = startingBounds.x - deltaX;
  806. newY = startingBounds.y - deltaY;
  807. // Make sure we stay in-bounds
  808. if(newX + i.left <= -__x)
  809. newX = -__x - i.left + 1;
  810. if(newY + i.top <= -__y)
  811. newY = -__y - i.top + 1;
  812. if(newX + __x + i.right >= pWidth)
  813. newX = pWidth - __x - i.right - 1;
  814. if(newY + __y + i.bottom >= pHeight)
  815. newY = pHeight - __y - i.bottom - 1;
  816. getDesktopManager().dragFrame(frame, newX, newY);
  817. return;
  818. }
  819. if(!frame.isResizable()) {
  820. return;
  821. }
  822. newX = frame.getX();
  823. newY = frame.getY();
  824. newW = frame.getWidth();
  825. newH = frame.getHeight();
  826. parentBounds = frame.getParent().getBounds();
  827. switch(resizeDir) {
  828. case RESIZE_NONE:
  829. return;
  830. case NORTH:
  831. if(startingBounds.height + deltaY < min.height)
  832. deltaY = -(startingBounds.height - min.height);
  833. else if(startingBounds.height + deltaY > max.height)
  834. deltaY = max.height - startingBounds.height;
  835. if (startingBounds.y - deltaY < 0) {deltaY = startingBounds.y;}
  836. newX = startingBounds.x;
  837. newY = startingBounds.y - deltaY;
  838. newW = startingBounds.width;
  839. newH = startingBounds.height + deltaY;
  840. break;
  841. case NORTH_EAST:
  842. if(startingBounds.height + deltaY < min.height)
  843. deltaY = -(startingBounds.height - min.height);
  844. else if(startingBounds.height + deltaY > max.height)
  845. deltaY = max.height - startingBounds.height;
  846. if (startingBounds.y - deltaY < 0) {deltaY = startingBounds.y;}
  847. if(startingBounds.width - deltaX < min.width)
  848. deltaX = startingBounds.width - min.width;
  849. else if(startingBounds.width - deltaX > max.width)
  850. deltaX = -(max.width - startingBounds.width);
  851. if (startingBounds.x + startingBounds.width - deltaX >
  852. parentBounds.width) {
  853. deltaX = startingBounds.x + startingBounds.width -
  854. parentBounds.width;
  855. }
  856. newX = startingBounds.x;
  857. newY = startingBounds.y - deltaY;
  858. newW = startingBounds.width - deltaX;
  859. newH = startingBounds.height + deltaY;
  860. break;
  861. case EAST:
  862. if(startingBounds.width - deltaX < min.width)
  863. deltaX = startingBounds.width - min.width;
  864. else if(startingBounds.width - deltaX > max.width)
  865. deltaX = -(max.width - startingBounds.width);
  866. if (startingBounds.x + startingBounds.width - deltaX >
  867. parentBounds.width) {
  868. deltaX = startingBounds.x + startingBounds.width -
  869. parentBounds.width;
  870. }
  871. newW = startingBounds.width - deltaX;
  872. newH = startingBounds.height;
  873. break;
  874. case SOUTH_EAST:
  875. if(startingBounds.width - deltaX < min.width)
  876. deltaX = startingBounds.width - min.width;
  877. else if(startingBounds.width - deltaX > max.width)
  878. deltaX = -(max.width - startingBounds.width);
  879. if (startingBounds.x + startingBounds.width - deltaX >
  880. parentBounds.width) {
  881. deltaX = startingBounds.x + startingBounds.width -
  882. parentBounds.width;
  883. }
  884. if(startingBounds.height - deltaY < min.height)
  885. deltaY = startingBounds.height - min.height;
  886. else if(startingBounds.height - deltaY > max.height)
  887. deltaY = -(max.height - startingBounds.height);
  888. if (startingBounds.y + startingBounds.height - deltaY >
  889. parentBounds.height) {
  890. deltaY = startingBounds.y + startingBounds.height -
  891. parentBounds.height ;
  892. }
  893. newW = startingBounds.width - deltaX;
  894. newH = startingBounds.height - deltaY;
  895. break;
  896. case SOUTH:
  897. if(startingBounds.height - deltaY < min.height)
  898. deltaY = startingBounds.height - min.height;
  899. else if(startingBounds.height - deltaY > max.height)
  900. deltaY = -(max.height - startingBounds.height);
  901. if (startingBounds.y + startingBounds.height - deltaY >
  902. parentBounds.height) {
  903. deltaY = startingBounds.y + startingBounds.height -
  904. parentBounds.height ;
  905. }
  906. newW = startingBounds.width;
  907. newH = startingBounds.height - deltaY;
  908. break;
  909. case SOUTH_WEST:
  910. if(startingBounds.height - deltaY < min.height)
  911. deltaY = startingBounds.height - min.height;
  912. else if(startingBounds.height - deltaY > max.height)
  913. deltaY = -(max.height - startingBounds.height);
  914. if (startingBounds.y + startingBounds.height - deltaY >
  915. parentBounds.height) {
  916. deltaY = startingBounds.y + startingBounds.height -
  917. parentBounds.height ;
  918. }
  919. if(startingBounds.width + deltaX < min.width)
  920. deltaX = -(startingBounds.width - min.width);
  921. else if(startingBounds.width + deltaX > max.width)
  922. deltaX = max.width - startingBounds.width;
  923. if (startingBounds.x - deltaX < 0) {
  924. deltaX = startingBounds.x;
  925. }
  926. newX = startingBounds.x - deltaX;
  927. newY = startingBounds.y;
  928. newW = startingBounds.width + deltaX;
  929. newH = startingBounds.height - deltaY;
  930. break;
  931. case WEST:
  932. if(startingBounds.width + deltaX < min.width)
  933. deltaX = -(startingBounds.width - min.width);
  934. else if(startingBounds.width + deltaX > max.width)
  935. deltaX = max.width - startingBounds.width;
  936. if (startingBounds.x - deltaX < 0) {
  937. deltaX = startingBounds.x;
  938. }
  939. newX = startingBounds.x - deltaX;
  940. newY = startingBounds.y;
  941. newW = startingBounds.width + deltaX;
  942. newH = startingBounds.height;
  943. break;
  944. case NORTH_WEST:
  945. if(startingBounds.width + deltaX < min.width)
  946. deltaX = -(startingBounds.width - min.width);
  947. else if(startingBounds.width + deltaX > max.width)
  948. deltaX = max.width - startingBounds.width;
  949. if (startingBounds.x - deltaX < 0) {
  950. deltaX = startingBounds.x;
  951. }
  952. if(startingBounds.height + deltaY < min.height)
  953. deltaY = -(startingBounds.height - min.height);
  954. else if(startingBounds.height + deltaY > max.height)
  955. deltaY = max.height - startingBounds.height;
  956. if (startingBounds.y - deltaY < 0) {deltaY = startingBounds.y;}
  957. newX = startingBounds.x - deltaX;
  958. newY = startingBounds.y - deltaY;
  959. newW = startingBounds.width + deltaX;
  960. newH = startingBounds.height + deltaY;
  961. break;
  962. default:
  963. return;
  964. }
  965. getDesktopManager().resizeFrame(frame, newX, newY, newW, newH);
  966. }
  967. public void mouseMoved(MouseEvent e) {
  968. if(!frame.isResizable())
  969. return;
  970. if (e.getSource() == frame || e.getSource() == getNorthPane()) {
  971. Insets i = frame.getInsets();
  972. Point ep = new Point(e.getX(), e.getY());
  973. if (e.getSource() == getNorthPane()) {
  974. Point np = getNorthPane().getLocation();
  975. ep.x += np.x;
  976. ep.y += np.y;
  977. }
  978. if(ep.x <= i.left) {
  979. if(ep.y < resizeCornerSize + i.top)
  980. frame.setCursor(Cursor.getPredefinedCursor(Cursor.NW_RESIZE_CURSOR));
  981. else if(ep.y > frame.getHeight() - resizeCornerSize - i.bottom)
  982. frame.setCursor(Cursor.getPredefinedCursor(Cursor.SW_RESIZE_CURSOR));
  983. else
  984. frame.setCursor(Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR));
  985. } else if(ep.x >= frame.getWidth() - i.right) {
  986. if(ep.y < resizeCornerSize + i.top)
  987. frame.setCursor(Cursor.getPredefinedCursor(Cursor.NE_RESIZE_CURSOR));
  988. else if(ep.y > frame.getHeight() - resizeCornerSize - i.bottom)
  989. frame.setCursor(Cursor.getPredefinedCursor(Cursor.SE_RESIZE_CURSOR));
  990. else
  991. frame.setCursor(Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR));
  992. } else if(ep.y <= i.top) {
  993. if(ep.x < resizeCornerSize + i.left)
  994. frame.setCursor(Cursor.getPredefinedCursor(Cursor.NW_RESIZE_CURSOR));
  995. else if(ep.x > frame.getWidth() - resizeCornerSize - i.right)
  996. frame.setCursor(Cursor.getPredefinedCursor(Cursor.NE_RESIZE_CURSOR));
  997. else
  998. frame.setCursor(Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR));
  999. } else if(ep.y >= frame.getHeight() - i.bottom) {
  1000. if(ep.x < resizeCornerSize + i.left)
  1001. frame.setCursor(Cursor.getPredefinedCursor(Cursor.SW_RESIZE_CURSOR));
  1002. else if(ep.x > frame.getWidth() - resizeCornerSize - i.right)
  1003. frame.setCursor(Cursor.getPredefinedCursor(Cursor.SE_RESIZE_CURSOR));
  1004. else
  1005. frame.setCursor(Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR));
  1006. }
  1007. else
  1008. frame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); return;
  1009. }
  1010. frame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
  1011. }
  1012. public void mouseExited(MouseEvent e) {
  1013. frame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
  1014. }
  1015. }; /// End BorderListener Class
  1016. protected class ComponentHandler implements ComponentListener
  1017. {
  1018. /**
  1019. * Invoked when a JInternalFrame's parent's size changes.
  1020. */
  1021. public void componentResized(ComponentEvent e) {
  1022. //
  1023. // Get the JInternalFrame's parent container size
  1024. //
  1025. Rectangle parentNewBounds = ((Component) e.getSource()).getBounds();
  1026. JInternalFrame.JDesktopIcon icon = null;
  1027. if (frame != null) {
  1028. icon = frame.getDesktopIcon();
  1029. //
  1030. // Resize the internal frame if it is maximized and relocate
  1031. // the associated icon as well.
  1032. //
  1033. if ( frame.isMaximum() ) {
  1034. frame.setBounds(0, 0, parentNewBounds.width, parentNewBounds.height);
  1035. }
  1036. }
  1037. //
  1038. // Relocate the icon base on the new parent bounds.
  1039. //
  1040. if (icon != null) {
  1041. Rectangle iconBounds = icon.getBounds();
  1042. int y = iconBounds.y + (parentNewBounds.height - parentBounds.height);
  1043. icon.setBounds(iconBounds.x,y,iconBounds.width,iconBounds.height);
  1044. }
  1045. //
  1046. // Update the new parent bounds for next resize.
  1047. //
  1048. if ( !parentBounds.equals(parentNewBounds) ) {
  1049. parentBounds = parentNewBounds;
  1050. }
  1051. //
  1052. // Validate the component tree for this container.
  1053. //
  1054. if (frame != null) frame.validate();
  1055. }
  1056. /* Unused */
  1057. public void componentMoved(ComponentEvent e) {}
  1058. /* Unused */
  1059. public void componentShown(ComponentEvent e) {}
  1060. /* Unused */
  1061. public void componentHidden(ComponentEvent e) {}
  1062. }
  1063. protected ComponentListener createComponentListener()
  1064. {
  1065. return new ComponentHandler();
  1066. }
  1067. private static boolean isDragging = false;
  1068. protected class GlassPaneDispatcher implements MouseInputListener {
  1069. private Component mouseEventTarget = null;
  1070. private Component dragSource = null;
  1071. /**
  1072. * When inactive, mouse events are forwarded as appropriate either to
  1073. * the UI to activate the frame or to the underlying child component.
  1074. */
  1075. public void mousePressed(MouseEvent e) {
  1076. // what is going on here is the GlassPane is up on the inactive
  1077. // internalframe and want's to "catch" the first mousePressed on
  1078. // the frame in order to give it to the BorderLister (and not the
  1079. // underlying component) and let it activate the frame
  1080. if (borderListener != null){
  1081. borderListener.mousePressed(e);
  1082. }
  1083. forwardMouseEvent(e);
  1084. }
  1085. /**
  1086. * Forward the mouseEntered event to the underlying child container.
  1087. * @see #mousePressed
  1088. */
  1089. public void mouseEntered(MouseEvent e) {
  1090. forwardMouseEvent(e);
  1091. }
  1092. /**
  1093. * Forward the mouseMoved event to the underlying child container.
  1094. * @see #mousePressed
  1095. */
  1096. public void mouseMoved(MouseEvent e) {
  1097. forwardMouseEvent(e);
  1098. }
  1099. /**
  1100. * Forward the mouseExited event to the underlying child container.
  1101. * @see #mousePressed
  1102. */
  1103. public void mouseExited(MouseEvent e) {
  1104. forwardMouseEvent(e);
  1105. }
  1106. /**
  1107. * Ignore mouseClicked events.
  1108. * @see #mousePressed
  1109. */
  1110. public void mouseClicked(MouseEvent e) {
  1111. }
  1112. /**
  1113. * Forward the mouseReleased event to the underlying child container.
  1114. * @see #mousePressed
  1115. */
  1116. public void mouseReleased(MouseEvent e) {
  1117. forwardMouseEvent(e);
  1118. }
  1119. /**
  1120. * Forward the mouseDragged event to the underlying child container.
  1121. * @see #mousePressed
  1122. */
  1123. public void mouseDragged(MouseEvent e) {
  1124. forwardMouseEvent(e);
  1125. }
  1126. /**
  1127. * Forward a mouse event to the current mouse target, setting it
  1128. * if necessary.
  1129. */
  1130. private void forwardMouseEvent(MouseEvent e) {
  1131. // We only want to do this for the selected internal frame.
  1132. Component target =
  1133. findComponentAt(frame.getRootPane().getLayeredPane(),
  1134. e.getX(), e.getY());
  1135. int id = e.getID();
  1136. switch(id) {
  1137. case MouseEvent.MOUSE_ENTERED:
  1138. if (isDragging && !frame.isSelected()) {
  1139. return;
  1140. }
  1141. if (target != mouseEventTarget) {
  1142. mouseEventTarget = target;
  1143. }
  1144. retargetMouseEvent(id, e, mouseEventTarget);
  1145. break;
  1146. case MouseEvent.MOUSE_PRESSED:
  1147. if (target != mouseEventTarget) {
  1148. mouseEventTarget = target;
  1149. }
  1150. retargetMouseEvent(id, e, mouseEventTarget);
  1151. // Set the drag source in case we start dragging.
  1152. dragSource = target;
  1153. break;
  1154. case MouseEvent.MOUSE_EXITED:
  1155. if (isDragging && !frame.isSelected()) {
  1156. return;
  1157. }
  1158. retargetMouseEvent(id, e, mouseEventTarget);
  1159. break;
  1160. case MouseEvent.MOUSE_CLICKED:
  1161. retargetMouseEvent(id, e, mouseEventTarget);
  1162. break;
  1163. case MouseEvent.MOUSE_MOVED:
  1164. if (target != mouseEventTarget) {
  1165. retargetMouseEvent(MouseEvent.MOUSE_EXITED, e,
  1166. mouseEventTarget);
  1167. mouseEventTarget = target;
  1168. retargetMouseEvent(MouseEvent.MOUSE_ENTERED, e,
  1169. mouseEventTarget);
  1170. }
  1171. retargetMouseEvent(id, e, mouseEventTarget);
  1172. break;
  1173. case MouseEvent.MOUSE_DRAGGED:
  1174. if (!isDragging) {
  1175. isDragging = true;
  1176. }
  1177. retargetMouseEvent(id, e, dragSource);
  1178. break;
  1179. case MouseEvent.MOUSE_RELEASED:
  1180. if (isDragging) {
  1181. retargetMouseEvent(id, e, dragSource);
  1182. isDragging = false;
  1183. } else {
  1184. retargetMouseEvent(id, e, mouseEventTarget);
  1185. }
  1186. }
  1187. }
  1188. /*
  1189. * Find the lightweight child component which corresponds to the
  1190. * specified location. This is similar to the new 1.2 API in
  1191. * Container, but we need to run on 1.1. The other changes are
  1192. * due to Container.findComponentAt's use of package-private data.
  1193. */
  1194. private Component findComponentAt(Container c, int x, int y) {
  1195. if (!c.contains(x, y)) {
  1196. return c;
  1197. }
  1198. int ncomponents = c.getComponentCount();
  1199. Component component[] = c.getComponents();
  1200. for (int i = 0 ; i < ncomponents ; i++) {
  1201. Component comp = component[i];
  1202. Point loc = comp.getLocation();
  1203. if ((comp != null) && (comp.contains(x - loc.x, y - loc.y)) &&
  1204. (comp.getPeer() instanceof LightweightPeer) &&
  1205. (comp.isVisible() == true)) {
  1206. // found a component that intersects the point, see if there
  1207. // is a deeper possibility.
  1208. if (comp instanceof Container) {
  1209. Container child = (Container) comp;
  1210. Point childLoc = child.getLocation();
  1211. Component deeper = findComponentAt(child,
  1212. x - childLoc.x, y - childLoc.y);
  1213. if (deeper != null) {
  1214. return deeper;
  1215. }
  1216. } else {
  1217. return comp;
  1218. }
  1219. }
  1220. }
  1221. return c;
  1222. }
  1223. /*
  1224. * Dispatch an event clone, retargeted for the specified target.
  1225. */
  1226. private void retargetMouseEvent(int id, MouseEvent e,
  1227. Component target) {
  1228. if (target == null) {
  1229. return;
  1230. }
  1231. // fix for bug #4202966 -- hania
  1232. // When retargetting a mouse event, we need to translate
  1233. // the event's coordinates relative to the target.
  1234. Point p = SwingUtilities.convertPoint(frame.getLayeredPane(),
  1235. e.getX(), e.getY(),
  1236. target);
  1237. MouseEvent retargeted = new MouseEvent(target,
  1238. id,
  1239. e.getWhen(),
  1240. e.getModifiers() | e.getModifiersEx(),
  1241. p.x,
  1242. p.y,
  1243. e.getClickCount(),
  1244. e.isPopupTrigger());
  1245. target.dispatchEvent(retargeted);
  1246. }
  1247. }
  1248. protected MouseInputListener createGlassPaneDispatcher(){
  1249. return new GlassPaneDispatcher();
  1250. }
  1251. protected class BasicInternalFrameListener implements InternalFrameListener {
  1252. public void internalFrameClosing(InternalFrameEvent e) {
  1253. }
  1254. public void internalFrameClosed(InternalFrameEvent e) {
  1255. frame.removeInternalFrameListener(internalFrameListener);
  1256. }
  1257. public void internalFrameOpened(InternalFrameEvent e) {
  1258. }
  1259. public void internalFrameIconified(InternalFrameEvent e) {
  1260. }
  1261. public void internalFrameDeiconified(InternalFrameEvent e) {
  1262. }
  1263. public void internalFrameActivated(InternalFrameEvent e) {
  1264. if (!isKeyBindingRegistered()){
  1265. setKeyBindingRegistered(true);
  1266. setupMenuOpenKey();
  1267. setupMenuCloseKey();
  1268. }
  1269. if (isKeyBindingRegistered())
  1270. setKeyBindingActive(true);
  1271. }
  1272. public void internalFrameDeactivated(InternalFrameEvent e) {
  1273. setKeyBindingActive(false);
  1274. }
  1275. }
  1276. } /// End BasicInternalFrameUI Class