39 |
package javax.swing; |
package javax.swing; |
40 |
|
|
41 |
import java.awt.Component; |
import java.awt.Component; |
42 |
|
import java.awt.Dimension; |
43 |
|
import java.awt.Point; |
44 |
|
|
45 |
|
|
46 |
/** |
/** |
57 |
/** |
/** |
58 |
* The shared factory object. |
* The shared factory object. |
59 |
* |
* |
60 |
* @see #getSharedFactory |
* @see #getSharedInstance |
61 |
* @see #setSharedFactory |
* @see #setSharedInstance |
62 |
*/ |
*/ |
63 |
private static PopupFactory sharedFactory; |
private static PopupFactory sharedFactory; |
64 |
|
|
71 |
*/ |
*/ |
72 |
public PopupFactory() |
public PopupFactory() |
73 |
{ |
{ |
74 |
|
// Nothing to do here. |
75 |
} |
} |
76 |
|
|
77 |
|
|
137 |
public Popup getPopup(Component owner, Component contents, |
public Popup getPopup(Component owner, Component contents, |
138 |
int x, int y) |
int x, int y) |
139 |
{ |
{ |
140 |
return new Popup.JWindowPopup(owner, contents, x, y); |
Popup popup = null; |
141 |
|
// By default we enable lightweight popups since they are more efficient |
142 |
|
// than heavyweight popups. |
143 |
|
boolean lightweightEnabled = true; |
144 |
|
// Special case JPopupMenu here, since it supports a lightweightEnabled |
145 |
|
// flag that we must respect. |
146 |
|
if (contents instanceof JPopupMenu) |
147 |
|
{ |
148 |
|
JPopupMenu menu = (JPopupMenu) contents; |
149 |
|
lightweightEnabled = menu.isLightWeightPopupEnabled(); |
150 |
|
} |
151 |
|
|
152 |
|
// If we have a root pane and the contents fits within the root pane and |
153 |
|
// lightweight popups are enabled, than we can use a lightweight popup. |
154 |
|
JRootPane root = SwingUtilities.getRootPane(owner); |
155 |
|
Point rootLoc = root.getLocationOnScreen(); |
156 |
|
Dimension contentsSize = contents.getSize(); |
157 |
|
Dimension rootSize = root.getSize(); |
158 |
|
if (x >= rootLoc.x && y > rootLoc.y |
159 |
|
&& (x - rootLoc.x) + contentsSize.width < rootSize.width |
160 |
|
&& (y - rootLoc.y) + contentsSize.height < rootSize.height) |
161 |
|
popup = new Popup.LightweightPopup(owner, contents, x, y); |
162 |
|
else |
163 |
|
popup = new Popup.JWindowPopup(owner, contents, x, y); |
164 |
|
return popup; |
165 |
} |
} |
166 |
} |
} |