/[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.61 by rabbit78, Tue Nov 1 23:13:32 2005 UTC revision 1.62 by langel, Fri Nov 4 22:46:45 2005 UTC
# Line 803  public class Window extends Container im Line 803  public class Window extends Container im
803      return isVisible();      return isVisible();
804    }    }
805    
806    public void setLocationRelativeTo (Component c)    public void setLocationRelativeTo(Component c)
807    {    {
808      if (c == null || !c.isShowing ())      if (c == null || !c.isShowing())
809        {        {
810          int x = 0;          int x = 0;
811          int y = 0;          int y = 0;
812    
813          GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment ();          GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
814          Point center = ge.getCenterPoint ();          Point center = ge.getCenterPoint();
815          x = center.x - (width / 2);          x = center.x - (width / 2);
816          y = center.y - (height / 2);          y = center.y - (height / 2);
817          setLocation (x, y);          setLocation(x, y);
818          }
819        else
820          {
821            int x = c.getX();
822            int y = c.getY();
823    
824            int cWidth = c.getWidth();
825            int cHeight = c.getHeight();
826            Dimension screenSize = getToolkit().getScreenSize();
827    
828            // If bottom of component is cut off, window placed
829            // on the left or the right side of component
830            if ((y + cHeight) > screenSize.height)
831              {
832                // If the right side of the component is closer to the center
833                if ((screenSize.width / 2 - x) <= 0)
834                  {
835                    if ((x - width) >= 0)
836                      x -= width;
837                    else
838                      x = 0;
839                  }
840                else
841                  {
842                    if ((x + cWidth + width) <= screenSize.width)
843                      x += cWidth;
844                    else
845                      x = screenSize.width - width;
846                  }
847    
848                y = screenSize.height - height;
849              }
850            else if (cWidth > width || cHeight > height)
851              {
852                // If right side of component is cut off
853                if ((x + width) > screenSize.width)
854                  x = screenSize.width - width;
855                // If left side of component is cut off
856                else if (x < 0)
857                  x = 0;
858                else
859                  x += (cWidth - width) / 2;
860                
861                y += (cHeight - height) / 2;
862              }
863            else
864              {
865                // If right side of component is cut off
866                if ((x + width) > screenSize.width)
867                  x = screenSize.width - width;
868                // If left side of component is cut off
869                else if (x < 0)
870                  x = 0;
871                else
872                  x -= (width - cWidth) / 2;
873                
874                y -= (height - cHeight) / 2;
875              }
876    
877            setLocation(x, y);
878        }        }
     // FIXME: handle case where component is non-null.  
879    }    }
880    
881    /**    /**

Legend:
Removed from v.1.61  
changed lines
  Added in v.1.62

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