Révision 1840
tmp/org.txm.chartsengine.rcp/src/org/txm/chartsengine/rcp/swt/SwingChartComposite.java (revision 1840) | ||
---|---|---|
20 | 20 |
import java.awt.event.WindowListener; |
21 | 21 |
import java.awt.image.BufferedImage; |
22 | 22 |
import java.io.IOException; |
23 |
import java.lang.reflect.Method; |
|
24 |
import java.util.Stack; |
|
23 | 25 |
|
24 | 26 |
import javax.swing.JComponent; |
25 | 27 |
import javax.swing.JPanel; |
... | ... | |
32 | 34 |
import org.eclipse.swt.awt.SWT_AWT; |
33 | 35 |
import org.eclipse.swt.graphics.Point; |
34 | 36 |
import org.eclipse.swt.widgets.Composite; |
37 |
import org.eclipse.swt.widgets.Control; |
|
38 |
import org.eclipse.swt.widgets.Display; |
|
35 | 39 |
import org.eclipse.swt.widgets.Event; |
40 |
import org.eclipse.swt.widgets.Shell; |
|
36 | 41 |
import org.txm.chartsengine.core.preferences.ChartsEnginePreferences; |
37 | 42 |
import org.txm.chartsengine.core.results.ChartResult; |
38 | 43 |
import org.txm.chartsengine.rcp.IChartComponent; |
... | ... | |
87 | 92 |
public SwingChartComposite(ChartEditor<ChartResult> chartEditor, Composite parent, int style) { |
88 | 93 |
super(chartEditor, parent, style); |
89 | 94 |
|
90 |
// Disabling Swing focus manager |
|
91 |
//FocusManager.disableSwingFocusManager(); |
|
92 |
|
|
93 | 95 |
this.frame = SWT_AWT.new_Frame(this); |
94 | 96 |
|
95 | 97 |
// 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) |
... | ... | |
102 | 104 |
// this.rootPanel = (JComponent) applet.getRootPane().getContentPane(); |
103 | 105 |
// this.frame.add(applet); |
104 | 106 |
|
105 |
|
|
106 |
//this.frame.pack(); |
|
107 |
|
|
108 | 107 |
this.frame.setVisible(true); |
109 |
//this.frame.setVisible(false); |
|
110 | 108 |
|
111 |
|
|
112 | 109 |
this.rootPanel.setBackground(Color.WHITE); |
113 | 110 |
|
114 | 111 |
|
115 |
// final sun.awt.EmbeddedFrame ef = (sun.awt.EmbeddedFrame)this.frame; |
|
116 |
// ef.addWindowListener(new WindowAdapter() { |
|
117 |
// public void windowActivated(WindowEvent e) { |
|
118 |
// ef.synthesizeWindowActivation(true); |
|
119 |
// } |
|
120 |
// }); |
|
121 |
// |
|
122 |
// SwingUtilities.invokeLater(new Runnable() { |
|
123 |
// public void run() { |
|
124 |
// applet.requestFocusInWindow(); |
|
125 |
// } |
|
126 |
// }); |
|
127 | 112 |
|
113 |
// 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. |
|
114 |
// After some tests, doesn't seem to work on Linux and Mac |
|
115 |
// see: https://bugs.eclipse.org/bugs/show_bug.cgi?id=377104 |
|
116 |
// see: https://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8203855 |
|
117 |
// this.frame.addWindowListener(new java.awt.event.WindowAdapter() { |
|
118 |
// @Override |
|
119 |
// public void windowActivated(java.awt.event.WindowEvent e) { |
|
120 |
// SwingChartComposite.this.getDisplay().asyncExec(new Runnable() { |
|
121 |
// @Override |
|
122 |
// public void run() { |
|
123 |
// if (Display.getCurrent().getFocusControl() == SwingChartComposite.this) { |
|
124 |
// Stack<Control> stack = new Stack<Control>(); |
|
125 |
// Control starter = SwingChartComposite.this; |
|
126 |
// Shell shell = SwingChartComposite.this.getShell(); |
|
127 |
// while (starter != null && !(starter instanceof Shell)) { |
|
128 |
// stack.push(starter.getParent()); |
|
129 |
// starter = starter.getParent(); |
|
130 |
// } |
|
131 |
// |
|
132 |
// Method m = null; |
|
133 |
// try { |
|
134 |
// // instead of calling the originally proposed |
|
135 |
// // workaround solution (below), |
|
136 |
// // |
|
137 |
// // Event event = new Event(); |
|
138 |
// // event.display = Display.getCurrent(); |
|
139 |
// // event.type = SWT.Activate; |
|
140 |
// // event.widget = stack.pop(); |
|
141 |
// // event.widget.notifyListeners(SWT.Activate, event); |
|
142 |
// // |
|
143 |
// // which should but does NOT set the active |
|
144 |
// // widget/control on the shell, we had |
|
145 |
// // to call the setActiveControl method directly. |
|
146 |
// // Updating the active control on the shell is |
|
147 |
// // important so that the last active |
|
148 |
// // control, when selected again, get the proper |
|
149 |
// // activation events fired. |
|
150 |
// |
|
151 |
// m = shell.getClass().getDeclaredMethod("setActiveControl", Control.class);// $NON-NLS-1$ |
|
152 |
// m.setAccessible(true); |
|
153 |
// while (!stack.isEmpty()) { |
|
154 |
// m.invoke(shell, stack.pop()); |
|
155 |
// } |
|
156 |
// |
|
157 |
// // force the Swing component focus |
|
158 |
// //setFocus(); |
|
159 |
// |
|
160 |
// } |
|
161 |
// catch (Exception e) { |
|
162 |
// 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$ |
|
163 |
// Log.printStackTrace(e); |
|
164 |
// } |
|
165 |
// finally { |
|
166 |
// if (m != null) { |
|
167 |
// m.setAccessible(false); |
|
168 |
// } |
|
169 |
// } |
|
170 |
// } |
|
171 |
// } |
|
172 |
// }); |
|
173 |
// } |
|
174 |
// }); |
|
128 | 175 |
|
129 |
|
|
130 |
// // 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. |
|
131 |
// // see: https://bugs.eclipse.org/bugs/show_bug.cgi?id=377104 |
|
132 |
// // see: https://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8203855 |
|
133 |
//// this.frame.addWindowListener(new java.awt.event.WindowAdapter() { |
|
134 |
//// @Override |
|
135 |
//// public void windowActivated(java.awt.event.WindowEvent e) { |
|
136 |
//// SwingChartComposite.this.getDisplay().asyncExec(new Runnable() { |
|
137 |
//// @Override |
|
138 |
//// public void run() { |
|
139 |
//// if (Display.getCurrent().getFocusControl() == SwingChartComposite.this) { |
|
140 |
//// Stack<Control> stack = new Stack<Control>(); |
|
141 |
//// Control starter = SwingChartComposite.this; |
|
142 |
//// Shell shell = SwingChartComposite.this.getShell(); |
|
143 |
//// while (starter != null && !(starter instanceof Shell)) { |
|
144 |
//// stack.push(starter.getParent()); |
|
145 |
//// starter = starter.getParent(); |
|
146 |
//// } |
|
147 |
//// |
|
148 |
//// Method m = null; |
|
149 |
//// try { |
|
150 |
//// // instead of calling the originally proposed |
|
151 |
//// // workaround solution (below), |
|
152 |
//// // |
|
153 |
//// // Event event = new Event(); |
|
154 |
//// // event.display = Display.getCurrent(); |
|
155 |
//// // event.type = SWT.Activate; |
|
156 |
//// // event.widget = stack.pop(); |
|
157 |
//// // event.widget.notifyListeners(SWT.Activate, event); |
|
158 |
//// // |
|
159 |
//// // which should but does NOT set the active |
|
160 |
//// // widget/control on the shell, we had |
|
161 |
//// // to call the setActiveControl method directly. |
|
162 |
//// // Updating the active control on the shell is |
|
163 |
//// // important so that the last active |
|
164 |
//// // control, when selected again, get the proper |
|
165 |
//// // activation events fired. |
|
166 |
//// |
|
167 |
//// m = shell.getClass().getDeclaredMethod("setActiveControl", Control.class);// $NON-NLS-1$ |
|
168 |
//// m.setAccessible(true); |
|
169 |
//// while (!stack.isEmpty()) { |
|
170 |
//// m.invoke(shell, stack.pop()); |
|
171 |
//// } |
|
172 |
//// |
|
173 |
//// // force the Swing component focus |
|
174 |
//// //setFocus(); |
|
175 |
//// |
|
176 |
//// } |
|
177 |
//// catch (Exception e) { |
|
178 |
//// 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$ |
|
179 |
//// Log.printStackTrace(e); |
|
180 |
//// } |
|
181 |
//// finally { |
|
182 |
//// if (m != null) { |
|
183 |
//// m.setAccessible(false); |
|
184 |
//// } |
|
185 |
//// } |
|
186 |
//// } |
|
187 |
//// } |
|
188 |
//// }); |
|
189 |
//// } |
|
190 |
//// }); |
|
191 |
// |
|
192 | 176 |
this.frame.addWindowListener(new WindowListener() { |
193 | 177 |
|
194 | 178 |
@Override |
tmp/org.txm.chartsengine.rcp/src/org/txm/chartsengine/rcp/SWTChartsComponentsProvider.java (revision 1840) | ||
---|---|---|
550 | 550 |
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); |
551 | 551 |
IWorkbenchPage page = window.getActivePage(); |
552 | 552 |
|
553 |
// IWorkbenchWindow window = PlatformUI.getWorkbench().getWorkbenchWindows()[0]; |
|
554 |
// IWorkbenchPage page = window.getActivePage(); |
|
555 |
|
|
556 | 553 |
boolean isAlreadyOpened = page.findEditors(chartEditorInput, editorPartId, IWorkbenchPage.MATCH_INPUT | IWorkbenchPage.MATCH_ID).length > 0; |
557 | 554 |
|
558 | 555 |
Log.finest("SWTChartsComponentsProvider.openEditor(): opening editor with id " + editorPartId); |
... | ... | |
561 | 558 |
if(isAlreadyOpened || this.chartsEngine.canCreateChart(chartEditorInput.getResult())) { |
562 | 559 |
|
563 | 560 |
//Log.finest(this.name + " - Opening editor for result data type " + chartEditorInput.getResultData().getClass() + " and editor id " + editorPartId); |
564 |
|
|
565 | 561 |
|
566 | 562 |
try { |
567 | 563 |
|
... | ... | |
573 | 569 |
if(isAlreadyOpened) { |
574 | 570 |
return openedChartEditorPart; |
575 | 571 |
} |
576 |
|
|
577 |
// compute the chart |
|
578 |
//openedChartEditorPart.computeChart(false); |
|
579 |
|
|
580 |
|
|
581 |
// FIXME: directly close the editor if it contains no chart |
|
582 |
// if(openedChartEditorPart.getChart() == null) { |
|
583 |
// page.closeEditor(openedChartEditorPart, false); |
|
584 |
// return openedChartEditorPart; |
|
585 |
// } |
|
586 |
|
|
587 |
// FIXME: tests with reuseEditor() |
|
588 |
//openedChartEditorPart = (ChartEditor) page.reuseEditor(editorPart, editorPart.getEditorInput()); |
|
589 |
|
|
590 |
|
|
591 |
//openedChartEditorPart.refreshCorporaView(); |
|
592 |
|
|
593 |
//openedChartEditorPart.forceFocus(); |
|
594 |
|
|
595 | 572 |
} |
596 | 573 |
catch(PartInitException e) { |
597 | 574 |
e.printStackTrace(); |
tmp/org.txm.chartsengine.svgbatik.rcp/src/org/txm/chartsengine/svgbatik/rcp/swt/SVGComposite.java (revision 1840) | ||
---|---|---|
1 |
package org.txm.chartsengine.svgbatik.rcp.swt; |
|
2 |
import java.io.File; |
|
3 |
|
|
4 |
import javax.swing.SwingUtilities; |
|
5 |
|
|
6 |
import org.eclipse.swt.widgets.Composite; |
|
7 |
import org.txm.chartsengine.rcp.editors.ChartEditor; |
|
8 |
import org.txm.chartsengine.rcp.swt.SwingChartComposite; |
|
9 |
import org.txm.chartsengine.svgbatik.rcp.swing.SVGCanvas; |
|
10 |
import org.txm.core.messages.TXMCoreMessages; |
|
11 |
import org.txm.utils.logger.Log; |
|
12 |
import org.w3c.dom.svg.SVGDocument; |
|
13 |
|
|
14 |
|
|
15 |
/** |
|
16 |
* Batik SVG SWT composite. |
|
17 |
* |
|
18 |
* @author sjacquot |
|
19 |
* |
|
20 |
*/ |
|
21 |
public class SVGComposite extends SwingChartComposite { |
|
22 |
|
|
23 |
|
|
24 |
/** |
|
25 |
* The loaded SVG file. |
|
26 |
*/ |
|
27 |
protected File file; |
|
28 |
|
|
29 |
|
|
30 |
/** |
|
31 |
* Creates a Batik SVG composite. |
|
32 |
* @param parent |
|
33 |
* @param style |
|
34 |
*/ |
|
35 |
public SVGComposite(ChartEditor chartEditor, Composite parent, int style) { |
|
36 |
super(chartEditor, parent, style); |
|
37 |
this.file = null; |
|
38 |
} |
|
39 |
|
|
40 |
|
|
41 |
@Override |
|
42 |
public void loadChart(Object data) { |
|
43 |
this.loadSVGDocument((File) data); |
|
44 |
} |
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
/** |
|
49 |
* Loads a SVG document from the specified file. |
|
50 |
* @param file the file to load |
|
51 |
*/ |
|
52 |
// FIXME: SJ: we should use Batik listener system to check if the file has been well loaded |
|
53 |
public void loadSVGDocument(final File file) { |
|
54 |
if (file == null) { |
|
55 |
Log.severe("SVG file doesn't exist."); |
|
56 |
return; |
|
57 |
} |
|
58 |
if (file.length() == 0) { |
|
59 |
Log.severe(TXMCoreMessages.bind("SVG file {0} is empty.", file)); |
|
60 |
return; |
|
61 |
} |
|
62 |
|
|
63 |
this.file = file; |
|
64 |
|
|
65 |
Log.fine(TXMCoreMessages.bind("Loading SVG document from file: {0}...", file.getAbsolutePath())); |
|
66 |
|
|
67 |
SwingUtilities.invokeLater(new Runnable() { |
|
68 |
|
|
69 |
@Override |
|
70 |
public void run() { |
|
71 |
|
|
72 |
try { |
|
73 |
getSVGCanvas().loadSVGDocument(file.toURL().toExternalForm()); |
|
74 |
} |
|
75 |
catch (Exception e) { |
|
76 |
Log.severe(TXMCoreMessages.bind("Can't load SVG document from file {0}.", file)); |
|
77 |
Log.printStackTrace(e); |
|
78 |
} |
|
79 |
|
|
80 |
} |
|
81 |
}); |
|
82 |
} |
|
83 |
|
|
84 |
|
|
85 |
/** |
|
86 |
* Gets the SVG document. |
|
87 |
* @return |
|
88 |
*/ |
|
89 |
public SVGDocument getSVGDocument() { |
|
90 |
return this.getSVGCanvas().getSVGDocument(); |
|
91 |
} |
|
92 |
|
|
93 |
/** |
|
94 |
* Gets the SVG canvas chart component. |
|
95 |
* Convenience method for getChartComponent(). |
|
96 |
* |
|
97 |
* @return the SVG canvas |
|
98 |
*/ |
|
99 |
public SVGCanvas getSVGCanvas() { |
|
100 |
return (SVGCanvas) this.chartComponent; |
|
101 |
} |
|
102 |
|
|
103 |
|
|
104 |
@Override |
|
105 |
public Object getChart() { |
|
106 |
return this.file; |
|
107 |
} |
|
108 |
|
|
109 |
|
|
110 |
@Override |
|
111 |
public void clearChartItemsSelection() { |
|
112 |
System.err.println("SVGComposite.clearChartItemsSelection(): not implemented."); |
|
113 |
} |
|
114 |
|
|
115 |
|
|
116 |
|
|
117 |
} |
tmp/org.txm.chartsengine.svgbatik.rcp/src/org/txm/chartsengine/svgbatik/rcp/swt/SVGChartComposite.java (revision 1840) | ||
---|---|---|
1 |
package org.txm.chartsengine.svgbatik.rcp.swt; |
|
2 |
import java.io.File; |
|
3 |
|
|
4 |
import javax.swing.SwingUtilities; |
|
5 |
|
|
6 |
import org.eclipse.swt.widgets.Composite; |
|
7 |
import org.txm.chartsengine.rcp.editors.ChartEditor; |
|
8 |
import org.txm.chartsengine.rcp.swt.SwingChartComposite; |
|
9 |
import org.txm.chartsengine.svgbatik.rcp.swing.SVGCanvas; |
|
10 |
import org.txm.core.messages.TXMCoreMessages; |
|
11 |
import org.txm.utils.logger.Log; |
|
12 |
import org.w3c.dom.svg.SVGDocument; |
|
13 |
|
|
14 |
|
|
15 |
/** |
|
16 |
* Batik SVG SWT composite. |
|
17 |
* |
|
18 |
* @author sjacquot |
|
19 |
* |
|
20 |
*/ |
|
21 |
public class SVGChartComposite extends SwingChartComposite { |
|
22 |
|
|
23 |
|
|
24 |
/** |
|
25 |
* The loaded SVG file. |
|
26 |
*/ |
|
27 |
protected File file; |
|
28 |
|
|
29 |
|
|
30 |
/** |
|
31 |
* Creates a Batik SVG composite. |
|
32 |
* @param parent |
|
33 |
* @param style |
|
34 |
*/ |
|
35 |
public SVGChartComposite(ChartEditor chartEditor, Composite parent, int style) { |
|
36 |
super(chartEditor, parent, style); |
|
37 |
this.file = null; |
|
38 |
} |
|
39 |
|
|
40 |
|
|
41 |
@Override |
|
42 |
public void loadChart(Object data) { |
|
43 |
this.loadSVGDocument((File) data); |
|
44 |
} |
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
/** |
|
49 |
* Loads a SVG document from the specified file. |
|
50 |
* @param file the file to load |
|
51 |
*/ |
|
52 |
// FIXME: SJ: we should use Batik listener system to check if the file has been well loaded |
|
53 |
public void loadSVGDocument(final File file) { |
|
54 |
if (file == null) { |
|
55 |
Log.severe("SVG file doesn't exist."); |
|
56 |
return; |
|
57 |
} |
|
58 |
if (file.length() == 0) { |
|
59 |
Log.severe(TXMCoreMessages.bind("SVG file {0} is empty.", file)); |
|
60 |
return; |
|
61 |
} |
|
62 |
|
|
63 |
this.file = file; |
|
64 |
|
|
65 |
Log.fine(TXMCoreMessages.bind("Loading SVG document from file: {0}...", file.getAbsolutePath())); |
|
66 |
|
|
67 |
SwingUtilities.invokeLater(new Runnable() { |
|
68 |
|
|
69 |
@Override |
|
70 |
public void run() { |
|
71 |
|
|
72 |
try { |
|
73 |
getSVGCanvas().loadSVGDocument(file.toURL().toExternalForm()); |
|
74 |
} |
|
75 |
catch (Exception e) { |
|
76 |
Log.severe(TXMCoreMessages.bind("Can't load SVG document from file {0}.", file)); |
|
77 |
Log.printStackTrace(e); |
|
78 |
} |
|
79 |
|
|
80 |
} |
|
81 |
}); |
|
82 |
} |
|
83 |
|
|
84 |
|
|
85 |
/** |
|
86 |
* Gets the SVG document. |
|
87 |
* @return |
|
88 |
*/ |
|
89 |
public SVGDocument getSVGDocument() { |
|
90 |
return this.getSVGCanvas().getSVGDocument(); |
|
91 |
} |
|
92 |
|
|
93 |
/** |
|
94 |
* Gets the SVG canvas chart component. |
|
95 |
* Convenience method for getChartComponent(). |
|
96 |
* |
|
97 |
* @return the SVG canvas |
|
98 |
*/ |
|
99 |
public SVGCanvas getSVGCanvas() { |
|
100 |
return (SVGCanvas) this.chartComponent; |
|
101 |
} |
|
102 |
|
|
103 |
|
|
104 |
@Override |
|
105 |
public Object getChart() { |
|
106 |
return this.file; |
|
107 |
} |
|
108 |
|
|
109 |
|
|
110 |
@Override |
|
111 |
public void clearChartItemsSelection() { |
|
112 |
System.err.println("SVGComposite.clearChartItemsSelection(): not implemented."); |
|
113 |
} |
|
114 |
|
|
115 |
|
|
116 |
|
|
117 |
} |
|
0 | 118 |
tmp/org.txm.chartsengine.svgbatik.rcp/src/org/txm/chartsengine/svgbatik/rcp/SVGSWTChartsComponentsProvider.java (revision 1840) | ||
---|---|---|
23 | 23 |
import org.txm.chartsengine.rcp.editors.ChartEditor; |
24 | 24 |
import org.txm.chartsengine.rcp.swt.ChartComposite; |
25 | 25 |
import org.txm.chartsengine.svgbatik.rcp.swing.SVGCanvas; |
26 |
import org.txm.chartsengine.svgbatik.rcp.swt.SVGComposite; |
|
26 |
import org.txm.chartsengine.svgbatik.rcp.swt.SVGChartComposite;
|
|
27 | 27 |
import org.w3c.dom.Element; |
28 | 28 |
|
29 | 29 |
import com.lowagie.text.Document; |
... | ... | |
76 | 76 |
* @param parent |
77 | 77 |
* @return |
78 | 78 |
*/ |
79 |
public static SVGComposite createCompositeStatic(ChartEditor chartEditor, Composite parent) { |
|
80 |
return new SVGComposite(chartEditor, parent, SWT.EMBEDDED | SWT.NO_BACKGROUND); |
|
79 |
public static SVGChartComposite createCompositeStatic(ChartEditor chartEditor, Composite parent) {
|
|
80 |
return new SVGChartComposite(chartEditor, parent, SWT.EMBEDDED | SWT.NO_BACKGROUND);
|
|
81 | 81 |
} |
82 | 82 |
|
83 | 83 |
|
... | ... | |
121 | 121 |
*/ |
122 | 122 |
public static File exportViewStatic(ChartEditor chartEditor, File file, String fileFormat) { |
123 | 123 |
|
124 |
SVGComposite composite = ((SVGComposite) chartEditor.getComposite());
|
|
124 |
SVGChartComposite composite = ((SVGChartComposite) chartEditor.getComposite());
|
|
125 | 125 |
|
126 | 126 |
// SVG |
127 | 127 |
if(fileFormat == ChartsEngine.OUTPUT_FORMAT_SVG) { |
Formats disponibles : Unified diff