KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > core > output > JdkBug4620540Hack


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.core.output;
21
22 import java.awt.Rectangle JavaDoc;
23 import javax.swing.JTabbedPane JavaDoc;
24
25 /**
26  * This class provides a few helper methods to work around JDK bug 4620540
27  * which happens in Sun JDK 1.4.0.
28  * This bug was fixed in Sun JDK 1.4.1 but this class is still necessary
29  * for Sun JDK 1.4.0.
30  * Taken from org.netbeans.core.windows to support popup menu on OutputView
31  * inner tabs.
32  *
33  * @author Tran Duc Trung
34  */

35
36 public class JdkBug4620540Hack
37 {
38     private JdkBug4620540Hack() {}
39
40     // XXX(-ttran) on JDK 1.4.0 if tabLayoutPolicy == SCROLL_TAB_LAYOUT &&
41
// tabPlacement == BOTTOM then JTabbedPane.getBoundsAt() returns incorrect
42
// value.
43

44     public static void fixGetBoundsAt(Rectangle JavaDoc b) {
45         if (b.y < 0)
46             b.y = -b.y;
47         if (b.x < 0)
48             b.x = -b.x;
49     }
50
51     // XXX(-ttran) We would like to be able to write
52
//
53
// TabbedPaneUI tabUI = tab.getUI();
54
// int click = tabUI.tabForCoordinate(tab, p.x, p.y);
55
//
56
// but this piece of code doesn't work correctly for tabLayoutPolicy ==
57
// SCROLL_TAB_LAYOUT && tabPlacement == BOTTOM. tabForCoordinate() never
58
// finds any tab, the method always returns -1.
59

60     public static int findTabForCoordinate(JTabbedPane JavaDoc tab, int x, int y) {
61         for (int i = 0; i < tab.getTabCount(); i++) {
62             Rectangle JavaDoc b = tab.getBoundsAt(i);
63             if (b != null) {
64                 b = new Rectangle JavaDoc(b);
65                 fixGetBoundsAt(b);
66                 
67                 if (b.contains(x, y)) {
68                     return i;
69                 }
70             }
71         }
72         return -1;
73     }
74 }
75
Popular Tags