/[classpath]/classpath/java/awt/Window.java
ViewVC logotype

Diff of /classpath/java/awt/Window.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.35.2.14 by gnu_andrew, Wed Nov 2 00:43:30 2005 UTC revision 1.35.2.15 by gnu_andrew, Sun Nov 27 21:00:36 2005 UTC
# Line 809  public class Window extends Container im Line 809  public class Window extends Container im
809      return isVisible();      return isVisible();
810    }    }
811    
812    public void setLocationRelativeTo (Component c)    public void setLocationRelativeTo(Component c)
813    {    {
814      if (c == null || !c.isShowing ())      int x = 0;
815        int y = 0;
816        
817        if (c == null || !c.isShowing())
818        {        {
819          int x = 0;          GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
820          int y = 0;          Point center = ge.getCenterPoint();
   
         GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment ();  
         Point center = ge.getCenterPoint ();  
821          x = center.x - (width / 2);          x = center.x - (width / 2);
822          y = center.y - (height / 2);          y = center.y - (height / 2);
         setLocation (x, y);  
823        }        }
824      // FIXME: handle case where component is non-null.      else
825          {
826            int cWidth = c.getWidth();
827            int cHeight = c.getHeight();
828            Dimension screenSize = getToolkit().getScreenSize();
829    
830            x = c.getLocationOnScreen().x;
831            y = c.getLocationOnScreen().y;
832            
833            // If bottom of component is cut off, window placed
834            // on the left or the right side of component
835            if ((y + cHeight) > screenSize.height)
836              {
837                // If the right side of the component is closer to the center
838                if ((screenSize.width / 2 - x) <= 0)
839                  {
840                    if ((x - width) >= 0)
841                      x -= width;
842                    else
843                      x = 0;
844                  }
845                else
846                  {
847                    if ((x + cWidth + width) <= screenSize.width)
848                      x += cWidth;
849                    else
850                      x = screenSize.width - width;
851                  }
852    
853                y = screenSize.height - height;
854              }
855            else if (cWidth > width || cHeight > height)
856              {
857                // If right side of component is cut off
858                if ((x + width) > screenSize.width)
859                  x = screenSize.width - width;
860                // If left side of component is cut off
861                else if (x < 0)
862                  x = 0;
863                else
864                  x += (cWidth - width) / 2;
865                
866                y += (cHeight - height) / 2;
867              }
868            else
869              {
870                // If right side of component is cut off
871                if ((x + width) > screenSize.width)
872                  x = screenSize.width - width;
873                // If left side of component is cut off
874                else if (x < 0 || (x - (width - cWidth) / 2) < 0)
875                  x = 0;
876                else
877                  x -= (width - cWidth) / 2;
878    
879                if ((y - (height - cHeight) / 2) > 0)
880                  y -= (height - cHeight) / 2;
881                else
882                  y = 0;
883              }
884          }
885    
886        setLocation(x, y);
887    }    }
888    
889    /**    /**

Legend:
Removed from v.1.35.2.14  
changed lines
  Added in v.1.35.2.15

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26