/[schmitzm]/trunk/src/skrueger/swing/DialogManager.java
ViewVC logotype

Diff of /trunk/src/skrueger/swing/DialogManager.java

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

revision 421 by alfonx, Thu Oct 1 21:06:37 2009 UTC revision 459 by alfonx, Sun Oct 11 22:45:44 2009 UTC
# Line 3  package skrueger.swing; Line 3  package skrueger.swing;
3  import java.awt.Component;  import java.awt.Component;
4  import java.awt.event.WindowAdapter;  import java.awt.event.WindowAdapter;
5  import java.awt.event.WindowEvent;  import java.awt.event.WindowEvent;
6    import java.util.Collection;
7  import java.util.HashMap;  import java.util.HashMap;
8  import java.util.HashSet;  import java.util.HashSet;
9    
# Line 16  public abstract class DialogManager<KEY, Line 17  public abstract class DialogManager<KEY,
17          public abstract class FactoryInterface {          public abstract class FactoryInterface {
18    
19                  public abstract DIALOG create();                  public abstract DIALOG create();
20                    
21                    /** May be overridden to add Listeners **/
22                    public void afterCreation(DIALOG newInstance){};
23    
24                    /** May be overridden to remove Listeners added earlier **/
25                    public void beforeDispose(DIALOG newInstance){};
26    
27          }          }
28    
29          private HashMap<KEY, DIALOG> dialogCache = new HashMap<KEY, DIALOG>();          protected HashMap<KEY, DIALOG> dialogCache = new HashMap<KEY, DIALOG>();
30    
31          /**          /**
32           * A {@link DialogManager} instance can be created for any extension of           * A {@link DialogManager} instance can be created for any extension of
# Line 95  public abstract class DialogManager<KEY, Line 102  public abstract class DialogManager<KEY,
102           * @return Always a visible and inFront instance of DIALOG for the given           * @return Always a visible and inFront instance of DIALOG for the given
103           *         key.           *         key.
104           */           */
105          public DIALOG getInstanceFor(final KEY key, FactoryInterface factory) {          public DIALOG getInstanceFor(final KEY key, final FactoryInterface factory) {
106                  DIALOG dialog;                  final DIALOG dialog;
107                  if (isVisibleFor(key)) {                  if (isVisibleFor(key)) {
108                          dialog = dialogCache.get(key);                          dialog = dialogCache.get(key);
109                  } else {                  } else {
110    
111                          dialog = factory.create();                          dialog = factory.create();
   
112                          dialogCache.put(key, dialog);                          dialogCache.put(key, dialog);
113                            dialog.setVisible(true);
114                            dialog.toFront();
115    
116                          dialog.addWindowListener(new WindowAdapter() {                          dialog.addWindowListener(new WindowAdapter() {
117                                  @Override                                  @Override
118                                  public void windowClosed(final WindowEvent e) {                                  public void windowClosed(final WindowEvent e) {
119                                            factory.beforeDispose(dialog);
120                                          disposeInstanceFor(key);                                          disposeInstanceFor(key);
121                                  }                                  }
122                          });                          });
123                            
124                            factory.afterCreation(dialog);
125                  }                  }
126                    
127    
128                  return dialog;                  return dialog;
129          }          }
130    
# Line 136  public abstract class DialogManager<KEY, Line 149  public abstract class DialogManager<KEY,
149                  return atLeastOne;                  return atLeastOne;
150          }          }
151    
152            /**
153             * @return All instances of DIALOG as they are cached.
154             */
155            public Collection<DIALOG> getAllInstances() {
156                    return dialogCache.values();
157            }
158    
159    
160  }  }

Legend:
Removed from v.421  
changed lines
  Added in v.459

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26