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