Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/yaftp/utils/SimplePositionner.java


1    /**
2    *
3    * CopyRights Jean-Yves MENGANT 1999,2000,2001,2002
4    *
5    * This program is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU General Public License
7    * as published by the Free Software Foundation; either version 2
8    * of the License, or any later version.
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   *
15   * You should have received a copy of the GNU General Public License
16   * along with this program; if not, write to the Free Software
17   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18   */
19  package com.yaftp.utils ;
20  
21  import java.awt.* ;
22  
23  /**
24  
25    Copyright Jean-Yves MENGANT 1998,1999,2000
26  
27    This class simply help components (mainly frames) to be positionned on the
28    screen using :
29    center ,
30    northWest , (0,0)
31    southWest ,
32    northEast ,
33    southEast
34  
35    @author Jean-Yves MENGANT
36  
37  */
38  
39  public class SimplePositionner {
40  
41    public static final int CENTER    = 0 ;
42    public static final int NORTHWEST = 1 ;
43    public static final int SOUTHWEST = 2 ;
44    public static final int NORTHEAST = 3 ;
45    public static final int SOUTHEAST = 4 ;
46  
47    public static void install (  Component c , int position )
48    {
49    Dimension d = Toolkit.getDefaultToolkit().getScreenSize() ;
50  
51      switch ( position )
52      {
53        case CENTER :
54          c.setLocation((d.width-c.getBounds().width)/2 ,
55                        (d.height-c.getBounds().height)/2
56                       ) ;
57          break ;
58  
59        case NORTHWEST :
60          c.setLocation(0,0)  ;
61          break ;
62  
63        case SOUTHWEST :
64          c.setLocation( 0 ,
65                        (d.height-c.getBounds().height)
66                       ) ;
67          break ;
68  
69        case NORTHEAST :
70          c.setLocation( (d.width-c.getBounds().width) ,
71                         0
72                       ) ;
73          break ;
74  
75        case SOUTHEAST :
76          c.setLocation( (d.width-c.getBounds().width) ,
77                         (d.height-c.getBounds().height)
78                       ) ;
79          break ;
80      }
81    }
82  
83  
84  }