01: package net.sourceforge.squirrel_sql.client.gui.util;
02:
03: import java.awt.Component;
04:
05: import javax.swing.JComponent;
06: import javax.swing.RepaintManager;
07: import javax.swing.SwingUtilities;
08:
09: import net.sourceforge.squirrel_sql.fw.util.StringManager;
10: import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
11: import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
12: import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
13:
14: public class ThreadCheckingRepaintManager extends RepaintManager {
15: /** Logger for this class. */
16: private static final ILogger s_log = LoggerController
17: .createLogger(ThreadCheckingRepaintManager.class);
18:
19: /** Internationalized strings for this class. */
20: private static final StringManager s_stringMgr = StringManagerFactory
21: .getStringManager(ThreadCheckingRepaintManager.class);
22:
23: public synchronized void addInvalidComponent(JComponent comp) {
24: try {
25: checkThread(comp);
26: } catch (Exception ex) {
27: // i18n[ThreadCheckingRepaintManager.workinwrongthread=GUI work done in wrong thread]
28: s_log
29: .debug(
30: s_stringMgr
31: .getString("ThreadCheckingRepaintManager.workinwrongthread"),
32: ex);
33: }
34: super .addInvalidComponent(comp);
35: }
36:
37: private void checkThread(JComponent comp) throws Exception {
38: if (comp.isVisible()) {
39: final Component root = comp.getRootPane();
40: if (root != null && root.isVisible()) {
41: if (!SwingUtilities.isEventDispatchThread()) {
42: // i18n[ThreadCheckingRepaintManager.workinwrongthread=GUI work done in wrong thread]
43: throw new Exception(
44: s_stringMgr
45: .getString("ThreadCheckingRepaintManager.workinwrongthread"));
46: }
47: }
48: }
49: }
50:
51: public synchronized void addDirtyRegion(JComponent comp, int i,
52: int i1, int i2, int i3) {
53: try {
54: checkThread(comp);
55: } catch (Exception ex) {
56: // i18n[ThreadCheckingRepaintManager.workinwrongthread=GUI work done in wrong thread]
57: s_log
58: .debug(
59: s_stringMgr
60: .getString("ThreadCheckingRepaintManager.workinwrongthread"),
61: ex);
62: }
63: super.addDirtyRegion(comp, i, i1, i2, i3);
64: }
65: }
|