1 19 20 package org.netbeans.core.execution; 21 22 import java.awt.Window ; 23 import java.awt.event.WindowAdapter ; 24 import java.awt.event.WindowEvent ; 25 import java.awt.event.WindowListener ; 26 import java.util.Iterator ; 27 import java.util.HashMap ; 28 import java.util.ArrayList ; 29 30 34 final class WindowTable extends HashMap <Window ,TaskThreadGroup> { 35 36 static final long serialVersionUID = -1494996298725028533L; 37 38 39 private WindowListener winListener; 40 41 42 private HashMap <ThreadGroup ,ArrayList <Window >> windowMap; 43 44 47 public WindowTable () { 48 super(16); 49 windowMap = new HashMap <ThreadGroup ,ArrayList <Window >>(16); 50 winListener = new WindowAdapter () { 51 public void windowClosed(WindowEvent ev) { 52 Window win; 53 removeWindow(win = (Window )ev.getSource()); 54 win.removeWindowListener(this); 55 } 56 }; 57 } 58 59 public synchronized void putTaskWindow(Window win, TaskThreadGroup grp) { 60 ArrayList <Window > vec; 61 if ((vec = windowMap.get(grp)) == null) { 62 vec = new ArrayList <Window >(); 63 windowMap.put(grp, vec); 64 } 65 vec.add(win); 66 win.addWindowListener(winListener); 67 super.put(win, grp); 68 } 69 70 public TaskThreadGroup getThreadGroup(Window win) { 71 return super.get(win); 72 } 73 74 75 void closeGroup(ThreadGroup grp) { 76 Window win; 77 ArrayList <Window > vec = windowMap.get(grp); 78 if (vec == null) return; 79 Iterator <Window > ee = vec.iterator(); 80 while (ee.hasNext()) { 81 (win = ee.next()).setVisible(false); 82 remove(win); 83 if (win != getSharedOwnerFrame()) { 84 win.dispose(); 85 } 86 } 87 windowMap.remove(grp); 88 } 89 90 private static java.awt.Frame shOwnerFrame; 92 private static java.awt.Frame getSharedOwnerFrame() { 93 if (shOwnerFrame != null) { 94 return shOwnerFrame; 95 } 96 97 try { 98 Class swUtil = Class.forName("javax.swing.SwingUtilities"); java.lang.reflect.Method getter = swUtil.getDeclaredMethod("getSharedOwnerFrame", new Class [] {}); getter.setAccessible(true); 101 102 shOwnerFrame = (java.awt.Frame ) getter.invoke(null, new Object [] {}); 103 } catch (Exception e) { 104 } 106 107 return shOwnerFrame; 108 } 109 110 111 boolean hasWindows(ThreadGroup grp) { 112 ArrayList <Window > vec = windowMap.get(grp); 113 if ((vec == null) || (vec.size() == 0) || hiddenWindows(vec)) { 114 return false; 115 } 116 return true; 117 } 118 119 124 private boolean hiddenWindows(ArrayList <Window > vec) { 125 Iterator <Window > ee = vec.iterator(); 126 Window win; 127 while (ee.hasNext()) { 128 win = ee.next(); 129 if (win.isVisible()) return false; 130 } 131 return true; 133 } 134 135 136 private void removeWindow(Window win) { 137 Object obj = get(win); if (obj == null) return; 139 remove(win); 140 ArrayList <Window > vec = windowMap.get(obj); 141 if (vec == null) return; 142 vec.remove(win); 143 } 144 } 145 | Popular Tags |