/[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 420 by alfonx, Thu Oct 1 20:22:48 2009 UTC revision 421 by alfonx, Thu Oct 1 21:06:37 2009 UTC
# Line 10  import javax.swing.JDialog; Line 10  import javax.swing.JDialog;
10    
11  import org.apache.log4j.Logger;  import org.apache.log4j.Logger;
12    
13  public abstract class DialogManager<KEY, DIALOG extends JDialog> extends  public abstract class DialogManager<KEY, DIALOG extends JDialog> {
14                  JDialog {          final static private Logger LOGGER = Logger.getLogger(DialogManager.class);
15    
16          public abstract class FactoryInterface {          public abstract class FactoryInterface {
17    
# Line 19  public abstract class DialogManager<KEY, Line 19  public abstract class DialogManager<KEY,
19    
20          }          }
21    
         final Logger LOGGER = Logger.getLogger(DialogManager.class);  
   
22          private HashMap<KEY, DIALOG> dialogCache = new HashMap<KEY, DIALOG>();          private HashMap<KEY, DIALOG> dialogCache = new HashMap<KEY, DIALOG>();
23    
24            /**
25             * A {@link DialogManager} instance can be created for any extension of
26             * {@link JDialog} that will implement the
27             * {@link #getInstanceFor(Object, Component, Object...)} method.
28             */
29          public DialogManager() {          public DialogManager() {
30          }          }
31    
# Line 74  public abstract class DialogManager<KEY, Line 77  public abstract class DialogManager<KEY,
77                          final DIALOG dialog = dialogCache.get(chartId);                          final DIALOG dialog = dialogCache.get(chartId);
78                          if (dialog != null) {                          if (dialog != null) {
79                                  dialog.dispose();                                  dialog.dispose();
80                                  if (dialogCache.remove(chartId) == null) {                                  dialogCache.remove(chartId);
                                         LOGGER.warn("Hae?!?!"); //TODO cleanup  
                                 }  
81                                  return true;                                  return true;
82                          }                          }
83                          return false;                          return false;
# Line 88  public abstract class DialogManager<KEY, Line 89  public abstract class DialogManager<KEY,
89           * will create the instance by invoking the {@link FactoryInterface} #create           * will create the instance by invoking the {@link FactoryInterface} #create
90           * method.           * method.
91           *           *
          * @param key  
92           * @param factory           * @param factory
93           *            {@link FactoryInterface} that creates the DIALOG           *            {@link FactoryInterface} that creates the DIALOG
94           *           *
95           * @return Always a visible and inFront instance for the given key.           * @return Always a visible and inFront instance of DIALOG for the given
96             *         key.
97           */           */
98          public DIALOG getInstanceFor(final KEY key, FactoryInterface factory) {          public DIALOG getInstanceFor(final KEY key, FactoryInterface factory) {
99                  DIALOG dialog;                  DIALOG dialog;
# Line 113  public abstract class DialogManager<KEY, Line 114  public abstract class DialogManager<KEY,
114                  }                  }
115                  return dialog;                  return dialog;
116          }          }
           
117    
118          /**          /**
119           * Disposes all open instances.           * Disposes all open instances and removes them from the cache.
120           *           *
121           * @return <code>true</code> if at least one window has been disposed.           * @return <code>true</code> if at least one window has been disposed.
122           */           */
123          public boolean disposeAll() {          public boolean disposeAll() {
124                    
125                  boolean atLeastOne = false;                  boolean atLeastOne = false;
126                  HashSet<KEY> tempKeys = new HashSet<KEY>(dialogCache.keySet());                  HashSet<KEY> tempKeys = new HashSet<KEY>(dialogCache.keySet());
127                  for (KEY key : tempKeys) {                  for (KEY key : tempKeys) {
128                          DIALOG dialog = dialogCache                          DIALOG dialog = dialogCache.get(key);
                                         .get(key);  
129                          if (dialog != null) {                          if (dialog != null) {
130                                  dialog.dispose();                                  dialog.dispose();
131                                  atLeastOne = true;                                  atLeastOne = true;
# Line 136  public abstract class DialogManager<KEY, Line 135  public abstract class DialogManager<KEY,
135                  dialogCache.clear();                  dialogCache.clear();
136                  return atLeastOne;                  return atLeastOne;
137          }          }
138            
139  }  }

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26