707 |
707 |
public static void initializeAWTDelegationListeners(final ChartEditor chartEditor, final JComponent swingComponent) {
|
708 |
708 |
|
709 |
709 |
|
710 |
|
//
|
711 |
|
// // AWT to SWT
|
712 |
|
// swingComponent.addMouseMotionListener(new MouseMotionListener() {
|
713 |
|
//
|
714 |
|
// @Override
|
715 |
|
// public void mouseMoved(final MouseEvent e) {
|
716 |
|
// if(!chartEditor.getComposite().isDisposed()) {
|
717 |
|
// chartEditor.getComposite().getDisplay().asyncExec(new Runnable () {
|
718 |
|
// public void run() {
|
719 |
|
// chartEditor.getComposite().notifyListeners(SWT.MouseMove, SWTChartsComponentsProvider.swingEventToSWT(chartEditor.getComposite(), swingComponent, e, SWT.MouseMove));
|
720 |
|
// }
|
721 |
|
// });
|
722 |
|
// }
|
723 |
|
// }
|
724 |
|
//
|
725 |
|
// @Override
|
726 |
|
// public void mouseDragged(MouseEvent e) {
|
727 |
|
// // TODO Auto-generated method stub
|
728 |
|
//
|
729 |
|
// }
|
730 |
|
// });
|
731 |
|
//
|
732 |
|
// swingComponent.addMouseListener(new MouseListener() {
|
733 |
|
//
|
734 |
|
// @Override
|
735 |
|
// public void mouseReleased(final MouseEvent e) {
|
736 |
|
// chartEditor.getComposite().getDisplay().asyncExec(new Runnable () {
|
737 |
|
// public void run() {
|
738 |
|
//
|
739 |
|
// // FIXME: context menu
|
740 |
|
// if(e.isPopupTrigger()) {
|
741 |
|
//
|
742 |
|
// //System.err.println("SWTChartsComponentsProvider.initializeAWTDelegationListeners(...).new MouseListener() {...}.mouseReleased(...).new Runnable() {...}.run(): AWT popup trigger detected");
|
743 |
|
//
|
744 |
|
//
|
745 |
|
//
|
746 |
|
// // update the mouse over item selection according to the mouse event
|
747 |
|
// chartEditor.getComposite().getChartComponent().updateMouseOverItem(e);
|
748 |
|
//
|
749 |
|
// // manually pop up the menu
|
750 |
|
// if(chartEditor.getComposite().getMenu() != null) {
|
751 |
|
// chartEditor.getComposite().getMenu().setLocation(new Point(e.getXOnScreen(), e.getYOnScreen()));
|
752 |
|
// chartEditor.getComposite().getMenu().setVisible(true);
|
753 |
|
// }
|
754 |
|
//
|
755 |
|
// // FIXME: the SWT.MenuDetect event delegation doesn't work, it would be better than manually pop up the menu (but other problem is the dynamic menu on chart entity item)
|
756 |
|
// //chartEditor.getComposite().notifyListeners(SWT.MenuDetect, SWTChartsComponentProvider.swingEventToSWT(chartEditor.getComposite(), swingComponent, e, SWT.MenuDetect));
|
757 |
|
// // FIXME: try to delegate the Menu detect event, DOES NOT SEEM TO WORK
|
758 |
|
// //chartEditor.getComposite().notifyListeners(SWT.MenuDetect, SWTChartsComponentsProvider.swingEventToSWT(chartEditor.getComposite(), swingComponent, e, SWT.MenuDetect));
|
759 |
|
// //chartEditor.getComposite().notifyListeners(SWT.Show, SWTChartsComponentsProvider.swingEventToSWT(chartEditor.getComposite(), swingComponent, e, SWT.Show));
|
760 |
|
//
|
761 |
|
// }
|
762 |
|
// //chartEditor.getComposite().notifyListeners(SWT.MouseUp, SWTChartsComponentsProvider.swingEventToSWT(chartEditor.getComposite(), swingComponent, e, SWT.MouseUp));
|
763 |
|
// //chartEditor.activate();
|
764 |
|
// }
|
765 |
|
// });
|
766 |
|
// }
|
767 |
|
//
|
768 |
|
// @Override
|
769 |
|
// public void mousePressed(final MouseEvent e) {
|
770 |
|
//
|
|
710 |
|
|
711 |
// AWT to SWT
|
|
712 |
swingComponent.addMouseMotionListener(new MouseMotionListener() {
|
|
713 |
|
|
714 |
@Override
|
|
715 |
public void mouseMoved(final MouseEvent e) {
|
|
716 |
if(!chartEditor.getComposite().isDisposed()) {
|
|
717 |
chartEditor.getComposite().getDisplay().asyncExec(new Runnable () {
|
|
718 |
public void run() {
|
|
719 |
chartEditor.getComposite().notifyListeners(SWT.MouseMove, SWTChartsComponentsProvider.swingEventToSWT(chartEditor.getComposite(), swingComponent, e, SWT.MouseMove));
|
|
720 |
}
|
|
721 |
});
|
|
722 |
}
|
|
723 |
}
|
|
724 |
|
|
725 |
@Override
|
|
726 |
public void mouseDragged(MouseEvent e) {
|
|
727 |
// TODO Auto-generated method stub
|
|
728 |
|
|
729 |
}
|
|
730 |
});
|
|
731 |
|
|
732 |
swingComponent.addMouseListener(new MouseListener() {
|
|
733 |
|
|
734 |
@Override
|
|
735 |
public void mouseReleased(final MouseEvent e) {
|
|
736 |
chartEditor.getComposite().getDisplay().asyncExec(new Runnable () {
|
|
737 |
public void run() {
|
|
738 |
|
|
739 |
// FIXME: context menu
|
|
740 |
if(e.isPopupTrigger()) {
|
|
741 |
|
|
742 |
//System.err.println("SWTChartsComponentsProvider.initializeAWTDelegationListeners(...).new MouseListener() {...}.mouseReleased(...).new Runnable() {...}.run(): AWT popup trigger detected");
|
|
743 |
|
|
744 |
|
|
745 |
|
|
746 |
// update the mouse over item selection according to the mouse event
|
|
747 |
chartEditor.getComposite().getChartComponent().updateMouseOverItem(e);
|
|
748 |
|
|
749 |
// manually pop up the menu
|
|
750 |
if(chartEditor.getComposite().getMenu() != null) {
|
|
751 |
chartEditor.getComposite().getMenu().setLocation(new Point(e.getXOnScreen(), e.getYOnScreen()));
|
|
752 |
chartEditor.getComposite().getMenu().setVisible(true);
|
|
753 |
|
|
754 |
}
|
|
755 |
|
|
756 |
// FIXME: the SWT.MenuDetect event delegation doesn't work, it would be better than manually pop up the menu (but other problem is the dynamic menu on chart entity item)
|
|
757 |
//chartEditor.getComposite().notifyListeners(SWT.MenuDetect, SWTChartsComponentProvider.swingEventToSWT(chartEditor.getComposite(), swingComponent, e, SWT.MenuDetect));
|
|
758 |
// FIXME: try to delegate the Menu detect event, DOES NOT SEEM TO WORK
|
|
759 |
//chartEditor.getComposite().notifyListeners(SWT.MenuDetect, SWTChartsComponentsProvider.swingEventToSWT(chartEditor.getComposite(), swingComponent, e, SWT.MenuDetect));
|
|
760 |
//chartEditor.getComposite().notifyListeners(SWT.Show, SWTChartsComponentsProvider.swingEventToSWT(chartEditor.getComposite(), swingComponent, e, SWT.Show));
|
|
761 |
|
|
762 |
}
|
|
763 |
//chartEditor.getComposite().notifyListeners(SWT.MouseUp, SWTChartsComponentsProvider.swingEventToSWT(chartEditor.getComposite(), swingComponent, e, SWT.MouseUp));
|
|
764 |
//chartEditor.activate();
|
|
765 |
}
|
|
766 |
});
|
|
767 |
}
|
|
768 |
|
|
769 |
@Override
|
|
770 |
public void mousePressed(final MouseEvent e) {
|
|
771 |
|
771 |
772 |
// // SWT thread
|
772 |
773 |
// chartEditor.getComposite().getDisplay().asyncExec(new Runnable() {
|
773 |
774 |
// @Override
|
... | ... | |
785 |
786 |
//// chartEditor.forceFocus();
|
786 |
787 |
// }
|
787 |
788 |
// });
|
788 |
|
//
|
789 |
|
// }
|
790 |
|
//
|
791 |
|
// @Override
|
792 |
|
// public void mouseExited(java.awt.event.MouseEvent e) {
|
793 |
|
// // TODO Auto-generated method stub
|
794 |
|
//
|
795 |
|
// }
|
796 |
|
//
|
797 |
|
// @Override
|
798 |
|
// public void mouseEntered(java.awt.event.MouseEvent e) {
|
799 |
|
//
|
800 |
|
// // TODO: DEbug
|
801 |
|
// //System.err.println("SWTChartsComponentProvider.initializeSwingDelegationListeners(...) AWT mouse entered");
|
802 |
|
//
|
803 |
|
// // Force the focus in the component on mouse enter
|
804 |
|
// /*if(!swingComponent.isFocusOwner()) {
|
805 |
|
//
|
806 |
|
// // SWT thread
|
807 |
|
// if(!chartEditor.getComposite().isDisposed()) {
|
808 |
|
// chartEditor.getComposite().getDisplay().asyncExec(new Runnable() {
|
809 |
|
// public void run() {
|
810 |
|
//
|
811 |
|
//
|
812 |
|
// // FIXME: this code works on Windows and Linux but activate() the chart editor when mouse enters
|
813 |
|
// //chartEditor.activate();
|
814 |
|
//
|
815 |
|
// EventQueue.invokeLater(new Runnable () {
|
816 |
|
// public void run () {
|
817 |
|
//
|
818 |
|
// // TODO: this code forces to give the focus to the embedded AWT Frame under Windows (#1127 related)
|
819 |
|
// // For unknown reason Frame.requestFocusInWindow() doesn't work and always return false here
|
820 |
|
// // This code is not sufficient for Linux
|
821 |
|
// System.out.println("SWTChartsComponentProvider.initializeAWTDelegationListeners(...) trying to give focus to root embedded frame");
|
822 |
|
// try {
|
823 |
|
// Frame frame = (Frame) swingComponent.getFocusCycleRootAncestor();
|
824 |
|
// //frame.synthesizeWindowActivation(true);
|
825 |
|
// Class clazz = frame.getClass();
|
826 |
|
// Method method = clazz.getMethod("synthesizeWindowActivation", new Class[]{boolean.class});
|
827 |
|
// if(method != null) {
|
828 |
|
// method.invoke(frame, new Object[]{new Boolean(true)});
|
829 |
|
// System.out.println("SWTChartsComponentProvider.initializeSwingDelegationListeners(...).new MouseListener() {...}.mouseEntered(...).new Runnable() {...}.run(): " + frame);
|
830 |
|
//
|
831 |
|
// }
|
832 |
|
//
|
833 |
|
// //frame.requestFocusInWindow();
|
834 |
|
//
|
835 |
|
// }
|
836 |
|
// catch (Throwable e) {
|
837 |
|
// Log.printStackTrace(e);
|
838 |
|
// }
|
839 |
|
// }
|
840 |
|
// });
|
841 |
|
//
|
842 |
|
//
|
843 |
|
// //System.out.println("SWTChartsComponentProvider.initializeSwingDelegationListeners) AWT give focus to frame = " + ((JFCComposite)chartEditor.getComposite()).frame.requestFocusInWindow());
|
844 |
|
//
|
845 |
|
//
|
846 |
|
// // chartEditor.setFocus();
|
847 |
|
// // System.out.println("SWTChartsComponentProvider.initializeSwingDelegationListeners() SWT got focus = " + chartEditor.getComposite().setFocus());
|
848 |
|
//
|
849 |
|
// // EventQueue.invokeLater(new Runnable () {
|
850 |
|
// // public void run () {
|
851 |
|
// //swingComponent.requestFocusInWindow();
|
852 |
|
//
|
853 |
|
// // System.out.println("SWTChartsComponentProvider.initializeSwingDelegationListeners() AWT got focus = " + swingComponent.requestFocusInWindow());
|
854 |
|
// // }
|
855 |
|
// // });
|
856 |
|
//
|
857 |
|
//
|
858 |
|
//
|
859 |
|
// }
|
860 |
|
// });
|
861 |
|
// }
|
862 |
|
// }*/
|
863 |
|
// }
|
864 |
|
//
|
865 |
|
// @Override
|
866 |
|
// public void mouseClicked(java.awt.event.MouseEvent e) {
|
867 |
|
// // TODO Auto-generated method stub
|
868 |
|
//
|
869 |
|
// }
|
870 |
|
// });
|
871 |
|
//
|
|
789 |
|
|
790 |
}
|
|
791 |
|
|
792 |
@Override
|
|
793 |
public void mouseExited(java.awt.event.MouseEvent e) {
|
|
794 |
// TODO Auto-generated method stub
|
|
795 |
|
|
796 |
}
|
|
797 |
|
|
798 |
@Override
|
|
799 |
public void mouseEntered(java.awt.event.MouseEvent e) {
|
|
800 |
|
|
801 |
// TODO: DEbug
|
|
802 |
//System.err.println("SWTChartsComponentProvider.initializeSwingDelegationListeners(...) AWT mouse entered");
|
|
803 |
|
|
804 |
// Force the focus in the component on mouse enter
|
|
805 |
/*if(!swingComponent.isFocusOwner()) {
|
|
806 |
|
|
807 |
// SWT thread
|
|
808 |
if(!chartEditor.getComposite().isDisposed()) {
|
|
809 |
chartEditor.getComposite().getDisplay().asyncExec(new Runnable() {
|
|
810 |
public void run() {
|
|
811 |
|
|
812 |
|
|
813 |
// FIXME: this code works on Windows and Linux but activate() the chart editor when mouse enters
|
|
814 |
//chartEditor.activate();
|
|
815 |
|
|
816 |
EventQueue.invokeLater(new Runnable () {
|
|
817 |
public void run () {
|
|
818 |
|
|
819 |
// TODO: this code forces to give the focus to the embedded AWT Frame under Windows (#1127 related)
|
|
820 |
// For unknown reason Frame.requestFocusInWindow() doesn't work and always return false here
|
|
821 |
// This code is not sufficient for Linux
|
|
822 |
System.out.println("SWTChartsComponentProvider.initializeAWTDelegationListeners(...) trying to give focus to root embedded frame");
|
|
823 |
try {
|
|
824 |
Frame frame = (Frame) swingComponent.getFocusCycleRootAncestor();
|
|
825 |
//frame.synthesizeWindowActivation(true);
|
|
826 |
Class clazz = frame.getClass();
|
|
827 |
Method method = clazz.getMethod("synthesizeWindowActivation", new Class[]{boolean.class});
|
|
828 |
if(method != null) {
|
|
829 |
method.invoke(frame, new Object[]{new Boolean(true)});
|
|
830 |
System.out.println("SWTChartsComponentProvider.initializeSwingDelegationListeners(...).new MouseListener() {...}.mouseEntered(...).new Runnable() {...}.run(): " + frame);
|
|
831 |
|
|
832 |
}
|
|
833 |
|
|
834 |
//frame.requestFocusInWindow();
|
|
835 |
|
|
836 |
}
|
|
837 |
catch (Throwable e) {
|
|
838 |
Log.printStackTrace(e);
|
|
839 |
}
|
|
840 |
}
|
|
841 |
});
|
|
842 |
|
|
843 |
|
|
844 |
//System.out.println("SWTChartsComponentProvider.initializeSwingDelegationListeners) AWT give focus to frame = " + ((JFCComposite)chartEditor.getComposite()).frame.requestFocusInWindow());
|
|
845 |
|
|
846 |
|
|
847 |
// chartEditor.setFocus();
|
|
848 |
// System.out.println("SWTChartsComponentProvider.initializeSwingDelegationListeners() SWT got focus = " + chartEditor.getComposite().setFocus());
|
|
849 |
|
|
850 |
// EventQueue.invokeLater(new Runnable () {
|
|
851 |
// public void run () {
|
|
852 |
//swingComponent.requestFocusInWindow();
|
|
853 |
|
|
854 |
// System.out.println("SWTChartsComponentProvider.initializeSwingDelegationListeners() AWT got focus = " + swingComponent.requestFocusInWindow());
|
|
855 |
// }
|
|
856 |
// });
|
|
857 |
|
|
858 |
|
|
859 |
|
|
860 |
}
|
|
861 |
});
|
|
862 |
}
|
|
863 |
}*/
|
|
864 |
}
|
|
865 |
|
|
866 |
@Override
|
|
867 |
public void mouseClicked(java.awt.event.MouseEvent e) {
|
|
868 |
// TODO Auto-generated method stub
|
|
869 |
|
|
870 |
}
|
|
871 |
});
|
|
872 |
|
872 |
873 |
// // Swing component focus delegation to the SWT chart composite
|
873 |
874 |
// swingComponent.addFocusListener(new FocusListener() {
|
874 |
875 |
//
|