Révision 1827

tmp/org.txm.chartsengine.jfreechart.rcp/src/org/txm/chartsengine/jfreechart/rcp/swt/JFCComposite.java (revision 1827)
28 28
	 * @param panel
29 29
	 */
30 30
	public JFCComposite(ChartEditor chartEditor, Composite parent) {
31
		//super(chartEditor, parent, SWT.EMBEDDED | SWT.NO_BACKGROUND);
32
		super(chartEditor, parent, SWT.EMBEDDED);
31
		super(chartEditor, parent, SWT.EMBEDDED | SWT.NO_BACKGROUND);
32
		//super(chartEditor, parent, SWT.EMBEDDED);
33 33
		//super(parent, SWT.EMBEDDED | SWT.NO_MERGE_PAINTS | SWT.NO_BACKGROUND); // do not fix the tooltips transparency problem
34 34
	}
35 35
	
tmp/org.txm.chartsengine.rcp/src/org/txm/chartsengine/rcp/swt/SwingChartComposite.java (revision 1827)
23 23
import java.lang.reflect.Method;
24 24
import java.util.Stack;
25 25

  
26
import javax.swing.JApplet;
26 27
import javax.swing.JComponent;
27 28
import javax.swing.JPanel;
28 29
import javax.swing.border.LineBorder;
......
68 69
	//FIXME: tests
69 70
	//protected Panel rootPanel;
70 71
	//protected JRootPane rootPanel;
71
	protected JPanel rootPanel;
72
	//protected JPanel rootPanel;
73
	protected JComponent rootPanel;
74
	
75
    
72 76

  
73 77
	
74 78

  
......
81 85
		super(chartEditor, parent, style);
82 86
		
83 87
		this.frame = SWT_AWT.new_Frame(this);
84
		
85 88
	
86
		// Need to add an AWT/Swing Panel to fix mouse events and mouse cursors changes on AWT/Swing chart component panel
87
		this.rootPanel = new JPanel(new BorderLayout());
89
		// Need to add an AWT/Swing Panel to fix mouse events and mouse cursors changes on AWT/Swing chart component panel (see: https://bugs.java.com/bugdatabase/view_bug.do?bug_id=4982522)
90
		//this.rootPanel = new JPanel(new BorderLayout());
91

  
92
		// FIXME: tests with Applet, see: https://www.eclipse.org/articles/article.php?file=Article-Swing-SWT-Integration/index.html
93
		JApplet applet = new JApplet(); 
94
		this.rootPanel = (JComponent) applet.getRootPane().getContentPane();
88 95
		
89
		this.frame.add(this.rootPanel);
96
		this.frame.add(applet);
90 97
		
91 98
		//this.frame.pack();
92 99

  
......
101 108
		// 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.
102 109
		// see: https://bugs.eclipse.org/bugs/show_bug.cgi?id=377104
103 110
		// see: https://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8203855
104
		this.frame.addWindowListener(new java.awt.event.WindowAdapter() {
105
			@Override
106
			public void windowActivated(java.awt.event.WindowEvent e) {
107
				SwingChartComposite.this.getDisplay().asyncExec(new Runnable() {
108
					@Override
109
					public void run() {
110
						if (Display.getCurrent().getFocusControl() == SwingChartComposite.this) {
111
							Stack<Control> stack = new Stack<Control>();
112
							Control starter = SwingChartComposite.this;
113
							Shell shell = SwingChartComposite.this.getShell();
114
							while (starter != null && !(starter instanceof Shell)) {
115
								stack.push(starter.getParent());
116
								starter = starter.getParent();
117
							}
118

  
119
							Method m = null;
120
							try {
121
								// instead of calling the originally proposed
122
								// workaround solution (below),
123
								//
124
								// Event event = new Event();
125
								// event.display = Display.getCurrent();
126
								// event.type = SWT.Activate;
127
								// event.widget = stack.pop();
128
								// event.widget.notifyListeners(SWT.Activate, event);
129
								//
130
								// which should but does NOT set the active
131
								// widget/control on the shell, we had
132
								// to call the setActiveControl method directly.
133
								// Updating the active control on the shell is
134
								// important so that the last active
135
								// control, when selected again, get the proper
136
								// activation events fired.
137

  
138
								m = shell.getClass().getDeclaredMethod("setActiveControl", Control.class);// $NON-NLS-1$
139
								m.setAccessible(true);
140
								while (!stack.isEmpty()) {
141
									m.invoke(shell, stack.pop());
142
								}
143
								
144
								// force the Swing component focus
145
								//setFocus();
146
								
147
							}
148
							catch (Exception e) {
149
								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$
150
								Log.printStackTrace(e);
151
							}
152
							finally {
153
								if (m != null) {
154
									m.setAccessible(false);
155
								}
156
							}
157
						}
158
					}
159
				});
160
			}
161
		});
111
//		this.frame.addWindowListener(new java.awt.event.WindowAdapter() {
112
//			@Override
113
//			public void windowActivated(java.awt.event.WindowEvent e) {
114
//				SwingChartComposite.this.getDisplay().asyncExec(new Runnable() {
115
//					@Override
116
//					public void run() {
117
//						if (Display.getCurrent().getFocusControl() == SwingChartComposite.this) {
118
//							Stack<Control> stack = new Stack<Control>();
119
//							Control starter = SwingChartComposite.this;
120
//							Shell shell = SwingChartComposite.this.getShell();
121
//							while (starter != null && !(starter instanceof Shell)) {
122
//								stack.push(starter.getParent());
123
//								starter = starter.getParent();
124
//							}
125
//
126
//							Method m = null;
127
//							try {
128
//								// instead of calling the originally proposed
129
//								// workaround solution (below),
130
//								//
131
//								// Event event = new Event();
132
//								// event.display = Display.getCurrent();
133
//								// event.type = SWT.Activate;
134
//								// event.widget = stack.pop();
135
//								// event.widget.notifyListeners(SWT.Activate, event);
136
//								//
137
//								// which should but does NOT set the active
138
//								// widget/control on the shell, we had
139
//								// to call the setActiveControl method directly.
140
//								// Updating the active control on the shell is
141
//								// important so that the last active
142
//								// control, when selected again, get the proper
143
//								// activation events fired.
144
//
145
//								m = shell.getClass().getDeclaredMethod("setActiveControl", Control.class);// $NON-NLS-1$
146
//								m.setAccessible(true);
147
//								while (!stack.isEmpty()) {
148
//									m.invoke(shell, stack.pop());
149
//								}
150
//								
151
//								// force the Swing component focus
152
//								//setFocus();
153
//								
154
//							}
155
//							catch (Exception e) {
156
//								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$
157
//								Log.printStackTrace(e);
158
//							}
159
//							finally {
160
//								if (m != null) {
161
//									m.setAccessible(false);
162
//								}
163
//							}
164
//						}
165
//					}
166
//				});
167
//			}
168
//		});
162 169
		
163 170
		this.frame.addWindowListener(new WindowListener() {
164 171
			

Formats disponibles : Unified diff