Changeset 4189


Ignore:
Timestamp:
07/10/08 15:38:36 (12 years ago)
Author:
curtis
Message:

Move window placement utility method into common utility class.

Location:
trunk/loci/plugins
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/loci/plugins/Util.java

    r4178 r4189  
    538538  } 
    539539 
     540  /** 
     541   * Places the given window at a nice location on screen, either centered 
     542   * below the ImageJ window if there is one, or else centered on screen. 
     543   */ 
     544  public static void placeWindow(Window w) { 
     545    Dimension size = w.getSize(); 
     546 
     547    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); 
     548 
     549    ImageJ ij = IJ.getInstance(); 
     550 
     551    Point p = new Point(); 
     552 
     553    if (ij == null) { 
     554      // center config window on screen 
     555      p.x = (screen.width - size.width) / 2; 
     556      p.y = (screen.height - size.height) / 2; 
     557    } 
     558    else { 
     559      // place config window below ImageJ window 
     560      Rectangle ijBounds = ij.getBounds(); 
     561      p.x = ijBounds.x + (ijBounds.width - size.width) / 2; 
     562      p.y = ijBounds.y + ijBounds.height + 5; 
     563    } 
     564 
     565    // nudge config window away from screen edges 
     566    final int pad = 10; 
     567    if (p.x < pad) p.x = pad; 
     568    else if (p.x + size.width + pad > screen.width) { 
     569      p.x = screen.width - size.width - pad; 
     570    } 
     571    if (p.y < pad) p.y = pad; 
     572    else if (p.y + size.height + pad > screen.height) { 
     573      p.y = screen.height - size.height - pad; 
     574    } 
     575 
     576    w.setLocation(p); 
     577  } 
     578 
    540579} 
  • trunk/loci/plugins/config/LociConfig.java

    r4055 r4189  
    2626package loci.plugins.config; 
    2727 
    28 import ij.IJ; 
    29 import ij.ImageJ; 
    3028import ij.plugin.PlugIn; 
    31 import java.awt.*; 
     29import loci.plugins.Util; 
    3230 
    3331/** 
     
    4745  public void run(String arg) { 
    4846    ConfigWindow cw = new ConfigWindow(); 
    49     placeWindow(cw); 
     47    Util.placeWindow(cw); 
    5048    cw.setVisible(true); 
    51   } 
    52  
    53   // -- Utility methods -- 
    54  
    55   /** 
    56    * Places the given window at a nice location on screen, either centered 
    57    * below the ImageJ window if there is one, or else centered on screen. 
    58    */ 
    59   public static void placeWindow(Window w) { 
    60     Dimension size = w.getSize(); 
    61  
    62     Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); 
    63  
    64     ImageJ ij = IJ.getInstance(); 
    65  
    66     Point p = new Point(); 
    67  
    68     if (ij == null) { 
    69       // center config window on screen 
    70       p.x = (screen.width - size.width) / 2; 
    71       p.y = (screen.height - size.height) / 2; 
    72     } 
    73     else { 
    74       // place config window below ImageJ window 
    75       Rectangle ijBounds = ij.getBounds(); 
    76       p.x = ijBounds.x + (ijBounds.width - size.width) / 2; 
    77       p.y = ijBounds.y + ijBounds.height + 5; 
    78     } 
    79  
    80     // nudge config window away from screen edges 
    81     final int pad = 10; 
    82     if (p.x < pad) p.x = pad; 
    83     else if (p.x + size.width + pad > screen.width) { 
    84       p.x = screen.width - size.width - pad; 
    85     } 
    86     if (p.y < pad) p.y = pad; 
    87     else if (p.y + size.height + pad > screen.height) { 
    88       p.y = screen.height - size.height - pad; 
    89     } 
    90  
    91     w.setLocation(p); 
    9249  } 
    9350 
  • trunk/loci/plugins/config/LociInstaller.java

    r4055 r4189  
    2727 
    2828import ij.plugin.PlugIn; 
     29import loci.plugins.Util; 
    2930 
    3031/** 
     
    4546  public void run(String arg) { 
    4647    InstallWizard iw = new InstallWizard(); 
    47     LociConfig.placeWindow(iw); 
     48    Util.placeWindow(iw); 
    4849    iw.setVisible(true); 
    4950  } 
Note: See TracChangeset for help on using the changeset viewer.