| 19 |
19 |
|
| 20 |
20 |
import javax.swing.JApplet;
|
| 21 |
21 |
import javax.swing.JComponent;
|
|
22 |
import javax.swing.SwingUtilities;
|
| 22 |
23 |
import javax.swing.border.LineBorder;
|
| 23 |
24 |
|
| 24 |
25 |
import org.eclipse.swt.awt.SWT_AWT;
|
| ... | ... | |
| 27 |
28 |
import org.txm.chartsengine.rcp.IChartComponent;
|
| 28 |
29 |
import org.txm.chartsengine.rcp.editors.ChartEditor;
|
| 29 |
30 |
import org.txm.chartsengine.rcp.events.EventCallBackHandler;
|
|
31 |
import org.txm.core.messages.TXMCoreMessages;
|
| 30 |
32 |
import org.txm.core.preferences.TBXPreferences;
|
| 31 |
33 |
import org.txm.rcp.preferences.RCPPreferences;
|
| 32 |
34 |
import org.txm.utils.logger.Log;
|
| ... | ... | |
| 58 |
60 |
//FIXME: tests
|
| 59 |
61 |
//protected Panel rootPanel;
|
| 60 |
62 |
//protected JRootPane rootPanel;
|
| 61 |
|
//protected JPanel rootPanel;
|
|
63 |
// protected JPanel rootPanel;
|
|
64 |
|
| 62 |
65 |
protected JComponent rootPanel;
|
| 63 |
66 |
|
| 64 |
67 |
|
| ... | ... | |
| 73 |
76 |
public SwingChartComposite(ChartEditor<ChartResult> chartEditor, Composite parent, int style) {
|
| 74 |
77 |
super(chartEditor, parent, style);
|
| 75 |
78 |
|
|
79 |
// Disabling Swing focus manager
|
|
80 |
//FocusManager.disableSwingFocusManager();
|
|
81 |
|
| 76 |
82 |
this.frame = SWT_AWT.new_Frame(this);
|
| 77 |
83 |
|
| 78 |
84 |
// 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)
|
| 79 |
|
//this.rootPanel = new JPanel(new BorderLayout());
|
| 80 |
|
|
|
85 |
// this.rootPanel = new JPanel(new BorderLayout());
|
|
86 |
// this.frame.add(this.rootPanel);
|
|
87 |
|
| 81 |
88 |
// FIXME: tests with Applet, see: https://www.eclipse.org/articles/article.php?file=Article-Swing-SWT-Integration/index.html
|
| 82 |
89 |
final JApplet applet = new JApplet();
|
| 83 |
90 |
this.rootPanel = (JComponent) applet.getRootPane().getContentPane();
|
| 84 |
|
|
| 85 |
91 |
this.frame.add(applet);
|
| 86 |
92 |
|
|
93 |
// this.frame.setAutoRequestFocus(false);
|
|
94 |
// this.frame.setFocusTraversalPolicyProvider(true);
|
|
95 |
// this.frame.setFocusTraversalPolicy(new FocusTraversalPolicy() {
|
|
96 |
//
|
|
97 |
// @Override
|
|
98 |
// public Component getLastComponent(Container aContainer) {
|
|
99 |
// // TODO Auto-generated method stub
|
|
100 |
// return null;
|
|
101 |
// }
|
|
102 |
//
|
|
103 |
// @Override
|
|
104 |
// public Component getFirstComponent(Container aContainer) {
|
|
105 |
// // TODO Auto-generated method stub
|
|
106 |
// return null;
|
|
107 |
// }
|
|
108 |
//
|
|
109 |
// @Override
|
|
110 |
// public Component getDefaultComponent(Container aContainer) {
|
|
111 |
// // TODO Auto-generated method stub
|
|
112 |
// return null;
|
|
113 |
// }
|
|
114 |
//
|
|
115 |
// @Override
|
|
116 |
// public Component getComponentBefore(Container aContainer, Component aComponent) {
|
|
117 |
// // TODO Auto-generated method stub
|
|
118 |
// return null;
|
|
119 |
// }
|
|
120 |
//
|
|
121 |
// @Override
|
|
122 |
// public Component getComponentAfter(Container aContainer, Component aComponent) {
|
|
123 |
// // TODO Auto-generated method stub
|
|
124 |
// return null;
|
|
125 |
// }
|
|
126 |
// });
|
|
127 |
|
|
128 |
|
|
129 |
|
| 87 |
130 |
//this.frame.pack();
|
| 88 |
131 |
|
| 89 |
132 |
//this.frame.setVisible(true);
|
| ... | ... | |
| 240 |
283 |
if(RCPPreferences.getInstance().getBoolean(TBXPreferences.EXPERT_USER)) {
|
| 241 |
284 |
((JComponent) rootPanel).setBorder(new LineBorder(Color.red, 1));
|
| 242 |
285 |
}
|
| 243 |
|
|
| 244 |
286 |
|
|
287 |
// SWT thread
|
|
288 |
// getDisplay().asyncExec(new Runnable() {
|
|
289 |
// @Override
|
|
290 |
// public void run() {
|
|
291 |
//
|
|
292 |
// //SwingChartComposite.this.notifyListeners(SWT.MouseDown, SWTChartsComponentsProvider.swingEventToSWT(chartEditor.getComposite(), swingComponent, e, SWT.MouseDown));
|
|
293 |
//
|
|
294 |
// // FIXME: Debug
|
|
295 |
//// System.out.println("SWTChartsComponentProvider.initializeAWTDelegationListeners(...).new MouseListener() {...}.mousePressed(...).new Runnable() {...}.run()");
|
|
296 |
// // Activate the editor part on AWT mouse pressed event
|
|
297 |
// //SwingChartComposite.this.chartEditor.activate();
|
|
298 |
// //chartEditor.getShell().setFocus();
|
|
299 |
//// chartEditor.setFocus();
|
|
300 |
// //chartEditor.getParent().setFocus();
|
|
301 |
//// chartEditor.forceFocus();
|
|
302 |
// SwingChartComposite.this.chartEditor.setFocus();
|
|
303 |
// //notifyListeners(SWT.FocusIn, null); // Needed to force the composite listener to handle the focus event
|
|
304 |
// }
|
|
305 |
// });
|
|
306 |
//
|
|
307 |
|
|
308 |
|
| 245 |
309 |
}
|
| 246 |
310 |
});
|
| 247 |
311 |
|
| ... | ... | |
| 378 |
442 |
}
|
| 379 |
443 |
|
| 380 |
444 |
|
| 381 |
|
//
|
| 382 |
|
// @Override
|
| 383 |
|
// public boolean setFocus() {
|
| 384 |
|
//
|
| 385 |
|
// if (this.isDisposed()) {
|
| 386 |
|
// return false;
|
|
445 |
|
|
446 |
@Override
|
|
447 |
public boolean setFocus() {
|
|
448 |
|
|
449 |
if (this.isDisposed()) {
|
|
450 |
return false;
|
|
451 |
}
|
|
452 |
|
|
453 |
// Debug
|
|
454 |
Log.finest("SwingChartComposite.setFocus(): trying to give focus to SWT composite and AWT component..."); //$NON-NLS-1$
|
|
455 |
|
|
456 |
boolean focusState = super.setFocus();
|
|
457 |
|
|
458 |
// Debug
|
|
459 |
Log.finest(TXMCoreMessages.bind("SwingChartComposite.setFocus(): SWT composite focus given state = {0}.", this.isFocusControl())); //$NON-NLS-1$
|
|
460 |
|
|
461 |
this.requestFocusInChartComponent();
|
|
462 |
|
|
463 |
return focusState;
|
|
464 |
}
|
|
465 |
|
|
466 |
|
|
467 |
|
|
468 |
/**
|
|
469 |
* Requests the focus in chart component.
|
|
470 |
*/
|
|
471 |
public void requestFocusInChartComponent() {
|
|
472 |
|
|
473 |
|
|
474 |
if(chartComponent != null) {
|
|
475 |
|
|
476 |
// try {
|
|
477 |
SwingUtilities.invokeLater(new Runnable () {
|
|
478 |
public void run () {
|
|
479 |
// if(!((Component) chartComponent).isFocusOwner()) {
|
|
480 |
|
|
481 |
//((Component) chartComponent).requestFocus();
|
|
482 |
((JComponent) chartComponent).grabFocus();
|
|
483 |
boolean focusState = ((Component) chartComponent).requestFocusInWindow();
|
|
484 |
|
|
485 |
// Debug
|
|
486 |
//Log.finest(TXMCoreMessages.bind("SwingChartComposite.requestFocusInChartComponent(): AWT component focus given state = {0}.", ((Component) chartComponent).isFocusOwner())); //$NON-NLS-1$
|
|
487 |
Log.finest(TXMCoreMessages.bind("SwingChartComposite.requestFocusInChartComponent(): AWT component focus given state = {0}.", focusState)); //$NON-NLS-1$
|
|
488 |
|
|
489 |
// // FIXME: For Swing focus debug tests
|
|
490 |
// if(RCPPreferences.getInstance().getBoolean(TBXPreferences.EXPERT_USER)) {
|
|
491 |
// if(((Component) chartComponent).isFocusOwner()) {
|
|
492 |
// ((JComponent) chartComponent).setBorder(new LineBorder(Color.red, 1));
|
|
493 |
// }
|
|
494 |
// else {
|
|
495 |
// ((JComponent) chartComponent).setBorder(javax.swing.BorderFactory.createEmptyBorder());
|
|
496 |
// }
|
|
497 |
// }
|
|
498 |
|
|
499 |
|
|
500 |
// }
|
|
501 |
}
|
|
502 |
});
|
|
503 |
// }
|
|
504 |
// catch (InvocationTargetException e) {
|
|
505 |
// // TODO Auto-generated catch block
|
|
506 |
// e.printStackTrace();
|
| 387 |
507 |
// }
|
| 388 |
|
//
|
| 389 |
|
// // Debug
|
| 390 |
|
// Log.finest("SwingChartComposite.setFocus(): trying to give focus to SWT composite and AWT component..."); //$NON-NLS-1$
|
| 391 |
|
//
|
| 392 |
|
// boolean focusState = super.setFocus();
|
| 393 |
|
//
|
| 394 |
|
// // Debug
|
| 395 |
|
// Log.finest(TXMCoreMessages.bind("SwingChartComposite.setFocus(): SWT composite focus given state = {0}.", this.isFocusControl())); //$NON-NLS-1$
|
| 396 |
|
//
|
| 397 |
|
// this.requestFocusInChartComponent();
|
| 398 |
|
//
|
| 399 |
|
// return focusState;
|
| 400 |
|
// }
|
| 401 |
|
//
|
| 402 |
|
//
|
| 403 |
|
//
|
| 404 |
|
// /**
|
| 405 |
|
// * Requests the focus in chart component.
|
| 406 |
|
// */
|
| 407 |
|
// public void requestFocusInChartComponent() {
|
| 408 |
|
//
|
| 409 |
|
//
|
| 410 |
|
// if(chartComponent != null) {
|
| 411 |
|
//
|
| 412 |
|
//// try {
|
| 413 |
|
// SwingUtilities.invokeLater(new Runnable () {
|
| 414 |
|
// public void run () {
|
| 415 |
|
//// if(!((Component) chartComponent).isFocusOwner()) {
|
| 416 |
|
//
|
| 417 |
|
// //((Component) chartComponent).requestFocus();
|
| 418 |
|
// ((JComponent) chartComponent).grabFocus();
|
| 419 |
|
// boolean focusState = ((Component) chartComponent).requestFocusInWindow();
|
| 420 |
|
//
|
| 421 |
|
// // Debug
|
| 422 |
|
// //Log.finest(TXMCoreMessages.bind("SwingChartComposite.requestFocusInChartComponent(): AWT component focus given state = {0}.", ((Component) chartComponent).isFocusOwner())); //$NON-NLS-1$
|
| 423 |
|
// Log.finest(TXMCoreMessages.bind("SwingChartComposite.requestFocusInChartComponent(): AWT component focus given state = {0}.", focusState)); //$NON-NLS-1$
|
| 424 |
|
//
|
| 425 |
|
//// // FIXME: For Swing focus debug tests
|
| 426 |
|
//// if(RCPPreferences.getInstance().getBoolean(TBXPreferences.EXPERT_USER)) {
|
| 427 |
|
//// if(((Component) chartComponent).isFocusOwner()) {
|
| 428 |
|
//// ((JComponent) chartComponent).setBorder(new LineBorder(Color.red, 1));
|
| 429 |
|
//// }
|
| 430 |
|
//// else {
|
| 431 |
|
//// ((JComponent) chartComponent).setBorder(javax.swing.BorderFactory.createEmptyBorder());
|
| 432 |
|
//// }
|
| 433 |
|
//// }
|
| 434 |
|
//
|
| 435 |
|
//
|
| 436 |
|
//// }
|
| 437 |
|
// }
|
| 438 |
|
// });
|
| 439 |
|
// // }
|
| 440 |
|
//// catch (InvocationTargetException e) {
|
| 441 |
|
//// // TODO Auto-generated catch block
|
| 442 |
|
//// e.printStackTrace();
|
| 443 |
|
//// }
|
| 444 |
|
//// catch (InterruptedException e) {
|
| 445 |
|
//// // TODO Auto-generated catch block
|
| 446 |
|
//// e.printStackTrace();
|
| 447 |
|
//// }
|
| 448 |
|
//
|
|
508 |
// catch (InterruptedException e) {
|
|
509 |
// // TODO Auto-generated catch block
|
|
510 |
// e.printStackTrace();
|
| 449 |
511 |
// }
|
| 450 |
|
// }
|
|
512 |
|
|
513 |
}
|
|
514 |
}
|
| 451 |
515 |
|
| 452 |
516 |
|
| 453 |
517 |
|
| ... | ... | |
| 492 |
556 |
|
| 493 |
557 |
@Override
|
| 494 |
558 |
public void copyChartViewToClipboard() {
|
|
559 |
|
| 495 |
560 |
int w = ((Component) this.chartComponent).getWidth();
|
| 496 |
561 |
int h = ((Component) this.chartComponent).getHeight();
|
| 497 |
562 |
final BufferedImage bufferedImg = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
|
| 498 |
563 |
Graphics2D g = bufferedImg.createGraphics();
|
|
564 |
|
|
565 |
|
| 499 |
566 |
((Component) this.chartComponent).paint(g);
|
| 500 |
567 |
|
| 501 |
568 |
Transferable img = new Transferable() {
|