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 |
|
|
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 |
|
|
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; |
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; |
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; |
135 |
dialogCache.clear(); |
dialogCache.clear(); |
136 |
return atLeastOne; |
return atLeastOne; |
137 |
} |
} |
138 |
|
|
139 |
} |
} |