Changeset 55


Ignore:
Timestamp:
10/11/04 17:07:05 (15 years ago)
Author:
curtis
Message:

Window position and visibility restoration is almost working.

Location:
trunk/loci/visbio
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/loci/visbio/WindowInfo.java

    r2 r55  
    9494  } 
    9595 
     96  /** Sets the window to match the given state. */ 
     97  public void setState(WindowState ws) { 
     98    ws.applyTo(window); 
     99    first = !ws.hasPosition(); 
     100    pack = !ws.hasSize(); 
     101  } 
     102 
    96103  /** Gets the associated window. */ 
    97104  public Window getWindow() { return window; } 
  • trunk/loci/visbio/WindowManager.java

    r54 r55  
    2525 
    2626import java.awt.Cursor; 
    27 import java.awt.Dialog; 
    28 import java.awt.Frame; 
    2927import java.awt.Rectangle; 
    3028import java.awt.Window; 
     
    6462  // -- Fields -- 
    6563 
    66   /** Hashtable for keeping track of registered windows. */ 
     64  /** Table for keeping track of registered windows. */ 
    6765  protected Hashtable windows = new Hashtable(); 
    6866 
     
    8179  /** Whether to distribute the menu bar across all registered frames. */ 
    8280  protected boolean distributed; 
     81 
     82 
     83  // -- Fields - initial state -- 
     84 
     85  /** Table of window states read during state restore. */ 
     86  protected Hashtable windowStates = new Hashtable(); 
    8387 
    8488 
     
    99103   */ 
    100104  public void addWindow(Window w, boolean pack) { 
    101     windows.put(w, new WindowInfo(w, pack)); 
     105    WindowInfo winfo = new WindowInfo(w, pack); 
     106    String wname = SwingUtil.getWindowTitle(w); 
     107    WindowState ws = (WindowState) windowStates.get(wname); 
     108    if (ws != null) { 
     109      winfo.setState(ws); 
     110      windowStates.remove(wname); 
     111    } 
     112    windows.put(w, winfo); 
    102113    if (distributed && w instanceof JFrame) { 
    103114      JFrame f = (JFrame) w; 
     
    231242    while (en.hasMoreElements()) { 
    232243      Window w = (Window) en.nextElement(); 
    233       String name; 
    234       if (w instanceof Frame) name = ((Frame) w).getTitle(); 
    235       else if (w instanceof Dialog) name = ((Dialog) w).getTitle(); 
    236       else name = w.getName(); 
     244      String name = SwingUtil.getWindowTitle(w); 
    237245      CAElement custom = ome.getCustomAttr(); 
    238246      custom.createElement(WINDOW_PARAMS); 
     
    257265    String[] w = custom.getAttributes(WINDOW_PARAMS, "width"); 
    258266    String[] h = custom.getAttributes(WINDOW_PARAMS, "height"); 
    259     // CTR TODO remember these positions for windows that have not yet 
    260     // been registered, and apply them when they *are* registered later on 
     267 
     268    // remember these positions for windows that have not yet been registered 
     269    windowStates.clear(); 
     270    for (int i=0; i<names.length; i++) { 
     271      WindowState ws = new WindowState(names[i], 
     272        vis[i].equalsIgnoreCase("true"), 
     273        Integer.parseInt(x[i]), Integer.parseInt(y[i]), 
     274        Integer.parseInt(w[i]), Integer.parseInt(h[i])); 
     275      WindowInfo winfo = getWindowByName(names[i]); 
     276      if (winfo == null) windowStates.put(names[i], ws); // remember position 
     277      else winfo.setState(ws); // window already exists; set position 
     278    } 
    261279  } 
    262280 
     
    300318  } 
    301319 
     320  /** 
     321   * Gets window information about the first window 
     322   * matching the specified name. 
     323   */ 
     324  protected WindowInfo getWindowByName(String name) { 
     325    Enumeration en = windows.elements(); 
     326    while (en.hasMoreElements()) { 
     327      WindowInfo winfo = (WindowInfo) en.nextElement(); 
     328      Window w = winfo.getWindow(); 
     329      if (w.getName().equals(name)) return winfo; 
     330    } 
     331    return null; 
     332  } 
     333 
    302334} 
  • trunk/loci/visbio/util/SwingUtil.java

    r50 r55  
    2424package loci.visbio.util; 
    2525 
    26 import java.awt.Component; 
    27 import java.awt.Container; 
    28 import java.awt.Cursor; 
    29 import java.awt.Dimension; 
    30 import java.awt.Toolkit; 
    31 import java.awt.Window; 
     26import java.awt.*; 
    3227 
    3328import java.awt.event.ActionListener; 
     
    131126  } 
    132127 
     128  /** Sets the title of the given window. */ 
     129  public static void setWindowTitle(Window w, String title) { 
     130    if (w instanceof Frame) ((Frame) w).setTitle(title); 
     131    else if (w instanceof Dialog) ((Dialog) w).setTitle(title); 
     132    else w.setName(title); 
     133  } 
     134 
     135  /** Gets the title of the given window. */ 
     136  public static String getWindowTitle(Window w) { 
     137    if (w instanceof Frame) return ((Frame) w).getTitle(); 
     138    else if (w instanceof Dialog) return ((Dialog) w).getTitle(); 
     139    else return w.getName(); 
     140  } 
     141 
    133142  /** Key mask for use with keyboard shortcuts on this operating system. */ 
    134143  public static final int MENU_MASK = 
Note: See TracChangeset for help on using the changeset viewer.