home *** CD-ROM | disk | FTP | other *** search
- package javax.swing;
-
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Dialog;
- import java.awt.Frame;
- import java.awt.Point;
- import java.awt.Rectangle;
- import java.awt.Window;
- import java.util.Hashtable;
- import java.util.Vector;
-
- class DefaultPopupFactory implements PopupFactory {
- private transient Component component;
- protected transient Component invoker;
- private transient Popup popup;
- private transient Frame frame;
- private int desiredLocationX;
- private int desiredLocationY;
- private int lastPopupType = 0;
- private static final Object heavyPopupCacheKey = new StringBuffer("PopupFactory.heavyPopupCache");
- private static final Object lightPopupCacheKey = new StringBuffer("PopupFactory.lightPopupCache");
- private static final Object mediumPopupCacheKey = new StringBuffer("PopupFactory.mediumPopupCache");
- private static final Object defaultLWPopupEnabledKey = new StringBuffer("PopupFactory.defaultLWPopupEnabledKey");
- private static final int MAX_CACHE_SIZE = 5;
- private boolean lightWeightPopupEnabled = true;
- private static final int LIGHT_WEIGHT_POPUP = 0;
- private static final int MEDIUM_WEIGHT_POPUP = 1;
- private static final int HEAVY_WEIGHT_POPUP = 2;
- private static final Object classLock = new Object();
-
- public static void setDefaultLightWeightPopupEnabled(boolean var0) {
- SwingUtilities.appContextPut(defaultLWPopupEnabledKey, new Boolean(var0));
- }
-
- public static boolean getDefaultLightWeightPopupEnabled() {
- Boolean var0 = (Boolean)SwingUtilities.appContextGet(defaultLWPopupEnabledKey);
- if (var0 == null) {
- SwingUtilities.appContextPut(defaultLWPopupEnabledKey, Boolean.TRUE);
- return true;
- } else {
- return var0;
- }
- }
-
- public void setLightWeightPopupEnabled(boolean var1) {
- this.lightWeightPopupEnabled = var1;
- }
-
- public boolean isLightWeightPopupEnabled() {
- return this.lightWeightPopupEnabled;
- }
-
- private static Hashtable getHeavyPopupCache() {
- Hashtable var0 = (Hashtable)SwingUtilities.appContextGet(heavyPopupCacheKey);
- if (var0 == null) {
- var0 = new Hashtable(2);
- SwingUtilities.appContextPut(heavyPopupCacheKey, var0);
- }
-
- return var0;
- }
-
- private static Vector getLightPopupCache() {
- Vector var0 = (Vector)SwingUtilities.appContextGet(lightPopupCacheKey);
- if (var0 == null) {
- var0 = new Vector();
- SwingUtilities.appContextPut(lightPopupCacheKey, var0);
- }
-
- return var0;
- }
-
- private static Vector getMediumPopupCache() {
- Vector var0 = (Vector)SwingUtilities.appContextGet(mediumPopupCacheKey);
- if (var0 == null) {
- var0 = new Vector();
- SwingUtilities.appContextPut(mediumPopupCacheKey, var0);
- }
-
- return var0;
- }
-
- static void recycleHeavyPopup(Popup var0) {
- Object var1 = classLock;
- synchronized(var1) {
- Window var3 = SwingUtilities.getWindowAncestor((Component)var0);
- Hashtable var4 = getHeavyPopupCache();
- Vector var2;
- if (var4.containsKey(var3)) {
- var2 = (Vector)var4.get(var3);
- } else {
- var2 = new Vector();
- var4.put(var3, var2);
- var3.addWindowListener(new 1(var3));
- }
-
- if (var2.size() < 5) {
- var2.addElement(var0);
- }
-
- }
- }
-
- static Popup getRecycledHeavyPopup(Window var0) {
- Object var1 = classLock;
- synchronized(var1) {
- Hashtable var3 = getHeavyPopupCache();
- if (var3.containsKey(var0)) {
- Vector var2 = (Vector)var3.get(var0);
- if (var2.size() > 0) {
- Popup var9 = (Popup)var2.elementAt(0);
- var2.removeElementAt(0);
- return var9;
- } else {
- Object var5 = null;
- return (Popup)var5;
- }
- } else {
- Object var4 = null;
- return (Popup)var4;
- }
- }
- }
-
- static void recycleLightPopup(Popup var0) {
- Object var1 = classLock;
- synchronized(var1) {
- Vector var2 = getLightPopupCache();
- if (var2.size() < 5) {
- var2.addElement(var0);
- }
-
- }
- }
-
- static Popup getRecycledLightPopup() {
- Object var0 = classLock;
- synchronized(var0) {
- Vector var1 = getLightPopupCache();
- if (var1.size() > 0) {
- Popup var7 = (Popup)var1.elementAt(0);
- var1.removeElementAt(0);
- return var7;
- } else {
- Object var3 = null;
- return (Popup)var3;
- }
- }
- }
-
- static void recycleMediumPopup(Popup var0) {
- Object var1 = classLock;
- synchronized(var1) {
- Vector var2 = getMediumPopupCache();
- if (var2.size() < 5) {
- var2.addElement(var0);
- }
-
- }
- }
-
- static Popup getRecycledMediumPopup() {
- Object var0 = classLock;
- synchronized(var0) {
- Vector var1 = getMediumPopupCache();
- if (var1.size() > 0) {
- Popup var7 = (Popup)var1.elementAt(0);
- var1.removeElementAt(0);
- return var7;
- } else {
- Object var3 = null;
- return (Popup)var3;
- }
- }
- }
-
- static void recyclePopup(Popup var0) {
- if (var0 instanceof JPanelPopup) {
- recycleLightPopup(var0);
- } else if (var0 instanceof WindowPopup) {
- recycleHeavyPopup(var0);
- } else if (var0 instanceof PanelPopup) {
- recycleMediumPopup(var0);
- }
-
- }
-
- protected Popup createLightWeightPopup() {
- Object var1 = getRecycledLightPopup();
- if (var1 == null) {
- var1 = new JPanelPopup(this);
- }
-
- return (Popup)var1;
- }
-
- protected Popup createMediumWeightPopup() {
- Object var1 = getRecycledMediumPopup();
- if (var1 == null) {
- var1 = new PanelPopup(this);
- }
-
- return (Popup)var1;
- }
-
- protected Popup createHeavyWeightPopup() {
- Object var1 = this.invoker != null ? SwingUtilities.getWindowAncestor(this.invoker) : null;
- if (var1 != null) {
- this.popup = getRecycledHeavyPopup((Window)var1);
- } else {
- var1 = new Frame();
- }
-
- if (this.popup == null) {
- this.popup = new WindowPopup(this, (Window)var1);
- }
-
- return this.popup;
- }
-
- private boolean popupFit(Rectangle var1) {
- if (this.invoker != null) {
- for(Container var2 = this.invoker.getParent(); var2 != null; var2 = ((Component)var2).getParent()) {
- if (var2 instanceof JFrame || var2 instanceof JDialog || var2 instanceof JWindow) {
- return SwingUtilities.isRectangleContainingRectangle(((Component)var2).getBounds(), var1);
- }
-
- if (var2 instanceof JApplet) {
- Rectangle var3 = ((Component)var2).getBounds();
- Point var4 = ((Component)var2).getLocationOnScreen();
- var3.x = var4.x;
- var3.y = var4.y;
- return SwingUtilities.isRectangleContainingRectangle(var3, var1);
- }
-
- if (var2 instanceof Frame) {
- return SwingUtilities.isRectangleContainingRectangle(((Component)var2).getBounds(), var1);
- }
- }
- }
-
- return false;
- }
-
- private boolean ancestorIsModalDialog(Component var1) {
- Object var2 = null;
- if (var1 != null) {
- for(Container var3 = var1.getParent(); var3 != null; var3 = ((Component)var3).getParent()) {
- if (var3 instanceof Dialog && ((Dialog)var3).isModal()) {
- return true;
- }
- }
- }
-
- return false;
- }
-
- private void replacePopup(int var1) {
- this.popup.removeComponent(this.component);
- recyclePopup(this.popup);
- this.popup = null;
- switch (var1) {
- case 0:
- this.popup = this.createLightWeightPopup();
- break;
- case 1:
- this.popup = this.createMediumWeightPopup();
- break;
- case 2:
- this.popup = this.createHeavyWeightPopup();
- }
-
- this.popup.setLocationOnScreen(this.desiredLocationX, this.desiredLocationY);
- this.popup.addComponent(this.component, "Center");
- this.component.invalidate();
- this.popup.pack();
- }
-
- private boolean invokerInHeavyWeightPopup(Component var1) {
- if (var1 != null) {
- for(Container var2 = var1.getParent(); var2 != null; var2 = ((Component)var2).getParent()) {
- if (var2 instanceof WindowPopup) {
- return true;
- }
-
- if (var2 instanceof PanelPopup || var2 instanceof JPanelPopup) {
- break;
- }
- }
- }
-
- return false;
- }
-
- public Popup getPopup(Component var1, Component var2, int var3, int var4) {
- this.invoker = var2;
- this.component = var1;
- this.desiredLocationX = var3;
- this.desiredLocationY = var4;
- switch (this.lastPopupType) {
- case 0:
- this.popup = this.createLightWeightPopup();
- break;
- case 1:
- this.popup = this.createMediumWeightPopup();
- break;
- case 2:
- this.popup = this.createHeavyWeightPopup();
- }
-
- int var5 = this.lastPopupType;
- this.popup.setLocationOnScreen(this.desiredLocationX, this.desiredLocationY);
- this.popup.addComponent(this.component, "Center");
- this.popup.pack();
- Rectangle var7 = new Rectangle(this.desiredLocationX, this.desiredLocationY, this.popup.getWidth(), this.popup.getHeight());
- byte var6;
- if (this.popupFit(var7)) {
- if ((var1 instanceof JToolTip || var1 instanceof JPopupMenu && ((JPopupMenu)var1).isLightWeightPopupEnabled()) && this.lightWeightPopupEnabled) {
- var6 = 0;
- } else {
- var6 = 1;
- }
- } else {
- var6 = 2;
- }
-
- if (this.invokerInHeavyWeightPopup(var2)) {
- var6 = 2;
- }
-
- if (var2 == null) {
- var6 = 2;
- }
-
- if (var6 != var5) {
- this.replacePopup(var6);
- var5 = var6;
- }
-
- this.lastPopupType = var5;
- return this.popup;
- }
-
- // $FF: synthetic method
- static Hashtable access$000() {
- return getHeavyPopupCache();
- }
- }
-