Source code: org/mitre/cvw/DnDJTabbedPane.java
1 /*
2 * Copyright (c) 1996-2000. The MITRE Corporation (http://www.mitre.org/).
3 * All rights reserved.
4 * CVW comes with ABSOLUTELY NO WARRANTY. See license for details.
5 */
6
7 package org.mitre.cvw;
8
9 import javax.swing.*;
10 import java.awt.*;
11
12 /**
13 * This fixes the bug where a JTabbedPane does not do drag and drop to
14 * the correct target if the target is on a pane other than the first
15 * pane. This workaround was reported at the following web site
16 * http://developer.java.sun.com/developer/bugParade/bugs/4193463.html
17 * it was submitted by bazyl@process.com
18 * @version 1.0
19 * @author Deb Ercolini
20 */
21 public class DnDJTabbedPane extends JTabbedPane {
22
23
24 /**
25 * Constructor
26 */
27 public DnDJTabbedPane() {
28 super();
29 }
30
31 /**
32 * Locates the visible child component that contains the specified
33 * position. Fixes the dnd bug where the component must be visible,
34 * (i.e., on the current tab).
35 *
36 * @param x the <i>x</i> coordinate
37 * @param y the <i>y</i> coordinate
38 * @return null if the component does not contain the position.
39 * If there is no child component at the requested point and the
40 * point is within the bounds of the container the container itself
41 * is returned.
42 * @see java.awt.Container#findComponentAt
43 * @since JDK1.2
44 */
45 public Component findComponentAt(int x, int y) {
46 if (!contains(x, y)) {
47 return null;
48 }
49 int ncomponents = getComponentCount();
50 for (int i = 0 ; i < ncomponents ; i++) {
51 Component comp = getComponentAt(i);
52 if (comp != null) {
53 if (comp instanceof Container) {
54 if (comp.isVisible()) //make sure it is on the current tab
55 comp = ((Container)comp).findComponentAt(x - comp.getX(),
56 y - comp.getY());
57 } else {
58 comp = comp.locate(x - comp.getX(), y - comp.getY());
59 }
60 if (comp != null && comp.isVisible()) {
61 return comp;
62 }
63 }
64 }
65 return this;
66 }
67
68 }