Révision 1811
tmp/org.txm.chartsengine.rcp/src/org/txm/chartsengine/rcp/swt/SwingChartComposite.java (revision 1811) | ||
---|---|---|
13 | 13 |
import java.awt.datatransfer.DataFlavor; |
14 | 14 |
import java.awt.datatransfer.Transferable; |
15 | 15 |
import java.awt.datatransfer.UnsupportedFlavorException; |
16 |
import java.awt.event.FocusEvent; |
|
17 |
import java.awt.event.FocusListener; |
|
18 |
import java.awt.event.WindowEvent; |
|
19 |
import java.awt.event.WindowFocusListener; |
|
16 | 20 |
import java.awt.image.BufferedImage; |
17 | 21 |
import java.io.IOException; |
18 | 22 |
import java.lang.reflect.Method; |
... | ... | |
111 | 115 |
// SJ: Workaround to fix a bug with some Java version and some OS where the focus of an embedded Swing component does not delegate to SWT, eg. the Part is not activated. |
112 | 116 |
// see: https://bugs.eclipse.org/bugs/show_bug.cgi?id=377104 |
113 | 117 |
// see: https://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8203855 |
114 |
this.frame.addWindowListener(new java.awt.event.WindowAdapter() { |
|
118 |
// this.frame.addWindowListener(new java.awt.event.WindowAdapter() { |
|
119 |
// @Override |
|
120 |
// public void windowActivated(java.awt.event.WindowEvent e) { |
|
121 |
// SwingChartComposite.this.getDisplay().asyncExec(new Runnable() { |
|
122 |
// @Override |
|
123 |
// public void run() { |
|
124 |
// if (Display.getCurrent().getFocusControl() == SwingChartComposite.this) { |
|
125 |
// Stack<Control> stack = new Stack<Control>(); |
|
126 |
// Control starter = SwingChartComposite.this; |
|
127 |
// Shell shell = SwingChartComposite.this.getShell(); |
|
128 |
// while (starter != null && !(starter instanceof Shell)) { |
|
129 |
// stack.push(starter.getParent()); |
|
130 |
// starter = starter.getParent(); |
|
131 |
// } |
|
132 |
// |
|
133 |
// Method m = null; |
|
134 |
// try { |
|
135 |
// // instead of calling the originally proposed |
|
136 |
// // workaround solution (below), |
|
137 |
// // |
|
138 |
// // Event event = new Event(); |
|
139 |
// // event.display = Display.getCurrent(); |
|
140 |
// // event.type = SWT.Activate; |
|
141 |
// // event.widget = stack.pop(); |
|
142 |
// // event.widget.notifyListeners(SWT.Activate, event); |
|
143 |
// // |
|
144 |
// // which should but does NOT set the active |
|
145 |
// // widget/control on the shell, we had |
|
146 |
// // to call the setActiveControl method directly. |
|
147 |
// // Updating the active control on the shell is |
|
148 |
// // important so that the last active |
|
149 |
// // control, when selected again, get the proper |
|
150 |
// // activation events fired. |
|
151 |
// |
|
152 |
// m = shell.getClass().getDeclaredMethod("setActiveControl", Control.class);// $NON-NLS-1$ |
|
153 |
// m.setAccessible(true); |
|
154 |
// while (!stack.isEmpty()) { |
|
155 |
// m.invoke(shell, stack.pop()); |
|
156 |
// } |
|
157 |
// |
|
158 |
// // force the Swing component focus |
|
159 |
// //setFocus(); |
|
160 |
// |
|
161 |
// } |
|
162 |
// catch (Exception e) { |
|
163 |
// Log.severe("** Embedded part was not able to set active control on Shell. This will result in other workbench parts not getting activated."); //$NON-NLS-1$ |
|
164 |
// Log.printStackTrace(e); |
|
165 |
// } |
|
166 |
// finally { |
|
167 |
// if (m != null) { |
|
168 |
// m.setAccessible(false); |
|
169 |
// } |
|
170 |
// } |
|
171 |
// } |
|
172 |
// } |
|
173 |
// }); |
|
174 |
// } |
|
175 |
// }); |
|
176 |
|
|
177 |
|
|
178 |
this.frame.addFocusListener(new FocusListener() { |
|
179 |
|
|
115 | 180 |
@Override |
116 |
public void windowActivated(java.awt.event.WindowEvent e) { |
|
117 |
SwingChartComposite.this.getDisplay().asyncExec(new Runnable() { |
|
118 |
@Override |
|
119 |
public void run() { |
|
120 |
if (Display.getCurrent().getFocusControl() == SwingChartComposite.this) { |
|
121 |
Stack<Control> stack = new Stack<Control>(); |
|
122 |
Control starter = SwingChartComposite.this; |
|
123 |
Shell shell = SwingChartComposite.this.getShell(); |
|
124 |
while (starter != null && !(starter instanceof Shell)) { |
|
125 |
stack.push(starter.getParent()); |
|
126 |
starter = starter.getParent(); |
|
127 |
} |
|
181 |
public void focusLost(FocusEvent e) { |
|
182 |
// TODO Auto-generated method stub |
|
183 |
System.out.println("SwingChartComposite.SwingChartComposite(...).new FocusListener() {...}.focusLost()"); |
|
184 |
} |
|
185 |
|
|
186 |
@Override |
|
187 |
public void focusGained(FocusEvent e) { |
|
188 |
// TODO Auto-generated method stub |
|
189 |
System.out.println("SwingChartComposite.SwingChartComposite(...).new FocusListener() {...}.focusGained()"); |
|
190 |
} |
|
191 |
}); |
|
128 | 192 |
|
129 |
Method m = null; |
|
130 |
try { |
|
131 |
// instead of calling the originally proposed |
|
132 |
// workaround solution (below), |
|
133 |
// |
|
134 |
// Event event = new Event(); |
|
135 |
// event.display = Display.getCurrent(); |
|
136 |
// event.type = SWT.Activate; |
|
137 |
// event.widget = stack.pop(); |
|
138 |
// event.widget.notifyListeners(SWT.Activate, |
|
139 |
// event); |
|
140 |
// |
|
141 |
// which should but does NOT set the active |
|
142 |
// widget/control on the shell, we had |
|
143 |
// to call the setActiveControl method directly. |
|
144 |
// Updating the active control on the shell is |
|
145 |
// important so that the last active |
|
146 |
// control, when selected again, get the proper |
|
147 |
// activation events fired. |
|
148 |
|
|
149 |
m = shell.getClass().getDeclaredMethod("setActiveControl", Control.class);// $NON-NLS-1$ |
|
150 |
m.setAccessible(true); |
|
151 |
while (!stack.isEmpty()) { |
|
152 |
m.invoke(shell, stack.pop()); |
|
153 |
} |
|
154 |
|
|
155 |
// force the Swing component focus |
|
156 |
//setFocus(); |
|
157 |
|
|
158 |
} |
|
159 |
catch (Exception e) { |
|
160 |
Log.severe("** Embedded part was not able to set active control on Shell. This will result in other workbench parts not getting activated."); //$NON-NLS-1$ |
|
161 |
Log.printStackTrace(e); |
|
162 |
} |
|
163 |
finally { |
|
164 |
if (m != null) { |
|
165 |
m.setAccessible(false); |
|
166 |
} |
|
167 |
} |
|
168 |
} |
|
169 |
} |
|
170 |
}); |
|
193 |
|
|
194 |
this.frame.addWindowFocusListener(new WindowFocusListener() { |
|
195 |
|
|
196 |
@Override |
|
197 |
public void windowLostFocus(WindowEvent e) { |
|
198 |
// TODO Auto-generated method stub |
|
199 |
System.out.println("SwingChartComposite.SwingChartComposite(...).new WindowFocusListener() {...}.windowLostFocus()"); |
|
171 | 200 |
} |
201 |
|
|
202 |
@Override |
|
203 |
public void windowGainedFocus(WindowEvent e) { |
|
204 |
// TODO Auto-generated method stub |
|
205 |
System.out.println("SwingChartComposite.SwingChartComposite(...).new WindowFocusListener() {...}.windowGainedFocus()"); |
|
206 |
} |
|
172 | 207 |
}); |
173 | 208 |
|
174 | 209 |
|
210 |
|
|
175 | 211 |
} |
176 | 212 |
|
177 | 213 |
@Override |
Formats disponibles : Unified diff