Révision 1793
| tmp/org.txm.chartsengine.svgbatik.rcp/src/org/txm/chartsengine/svgbatik/rcp/swt/SVGComposite.java (revision 1793) | ||
|---|---|---|
| 6 | 6 |
import org.eclipse.swt.widgets.Composite; |
| 7 | 7 |
import org.txm.chartsengine.rcp.editors.ChartEditor; |
| 8 | 8 |
import org.txm.chartsengine.rcp.swt.SwingChartComposite; |
| 9 |
import org.txm.chartsengine.svgbatik.rcp.swing.SVGPanel;
|
|
| 9 |
import org.txm.chartsengine.svgbatik.rcp.swing.SVGCanvas;
|
|
| 10 | 10 |
import org.txm.core.messages.TXMCoreMessages; |
| 11 | 11 |
import org.txm.utils.logger.Log; |
| 12 | 12 |
import org.w3c.dom.svg.SVGDocument; |
| ... | ... | |
| 34 | 34 |
*/ |
| 35 | 35 |
public SVGComposite(ChartEditor chartEditor, Composite parent, int style) {
|
| 36 | 36 |
super(chartEditor, parent, style); |
| 37 |
|
|
| 38 | 37 |
this.file = null; |
| 39 | 38 |
} |
| 40 | 39 |
|
| 41 |
|
|
| 42 |
|
|
| 43 | 40 |
|
| 44 | 41 |
@Override |
| 45 | 42 |
public void loadChart(Object data) {
|
| ... | ... | |
| 67 | 64 |
public void run() {
|
| 68 | 65 |
|
| 69 | 66 |
try {
|
| 70 |
getPanel().loadSVGDocument(file.toURL().toExternalForm());
|
|
| 67 |
getSVGCanvas().loadSVGDocument(file.toURL().toExternalForm());
|
|
| 71 | 68 |
} |
| 72 | 69 |
catch (Exception e) {
|
| 73 | 70 |
Log.severe(TXMCoreMessages.bind("Can't load SVG document from file {0}.", file));
|
| ... | ... | |
| 79 | 76 |
} |
| 80 | 77 |
|
| 81 | 78 |
|
| 82 |
|
|
| 83 | 79 |
/** |
| 84 | 80 |
* Gets the SVG document. |
| 85 | 81 |
* @return |
| 86 | 82 |
*/ |
| 87 | 83 |
public SVGDocument getSVGDocument() {
|
| 88 |
return this.getPanel().getSVGDocument();
|
|
| 84 |
return this.getSVGCanvas().getSVGDocument();
|
|
| 89 | 85 |
} |
| 90 | 86 |
|
| 91 | 87 |
/** |
| 92 |
* Gets the SVG panel. |
|
| 93 |
* @return the panel |
|
| 88 |
* Gets the SVG canvas chart component. |
|
| 89 |
* Convenience method for getChartComponent(). |
|
| 90 |
* |
|
| 91 |
* @return the SVG canvas |
|
| 94 | 92 |
*/ |
| 95 |
public SVGPanel getPanel() {
|
|
| 96 |
return (SVGPanel) this.chartComponent;
|
|
| 93 |
public SVGCanvas getSVGCanvas() {
|
|
| 94 |
return (SVGCanvas) this.chartComponent;
|
|
| 97 | 95 |
} |
| 98 | 96 |
|
| 99 | 97 |
|
| 100 |
|
|
| 101 |
|
|
| 102 |
|
|
| 103 |
|
|
| 104 |
|
|
| 105 |
|
|
| 106 | 98 |
@Override |
| 107 | 99 |
public Object getChart() {
|
| 108 | 100 |
return this.file; |
| tmp/org.txm.chartsengine.svgbatik.rcp/src/org/txm/chartsengine/svgbatik/rcp/SVGSWTChartsComponentsProvider.java (revision 1793) | ||
|---|---|---|
| 22 | 22 |
import org.txm.chartsengine.rcp.editors.ChartEditorInput; |
| 23 | 23 |
import org.txm.chartsengine.rcp.editors.ChartEditor; |
| 24 | 24 |
import org.txm.chartsengine.rcp.swt.ChartComposite; |
| 25 |
import org.txm.chartsengine.svgbatik.rcp.swing.SVGPanel;
|
|
| 25 |
import org.txm.chartsengine.svgbatik.rcp.swing.SVGCanvas;
|
|
| 26 | 26 |
import org.txm.chartsengine.svgbatik.rcp.swt.SVGComposite; |
| 27 | 27 |
import org.w3c.dom.Element; |
| 28 | 28 |
|
| ... | ... | |
| 53 | 53 |
|
| 54 | 54 |
if (!chartEditorInput.getResult().isChartDirty()) {
|
| 55 | 55 |
|
| 56 |
chartEditorInput.setChartContainer(new SVGPanel());
|
|
| 56 |
chartEditorInput.setChartContainer(new SVGCanvas());
|
|
| 57 | 57 |
|
| 58 | 58 |
// sets and updates the local preferences node qualifier from the result data |
| 59 | 59 |
chartEditorInput.syncLocalPreferencesNode(); |
| ... | ... | |
| 152 | 152 |
//((Element)this.composite.getSVGDocument().getFirstChild()).setAttribute("viewBox", "20 20 400 350"); // FIXME : how to get the correct area after the charts has been zoomed or moved ?
|
| 153 | 153 |
|
| 154 | 154 |
// Adjust dimensions from component |
| 155 |
((Element)composite.getSVGDocument().getFirstChild()).setAttribute("width", String.valueOf(composite.getPanel().getWidth()));
|
|
| 156 |
((Element)composite.getSVGDocument().getFirstChild()).setAttribute("height", String.valueOf(composite.getPanel().getHeight()));
|
|
| 155 |
((Element)composite.getSVGDocument().getFirstChild()).setAttribute("width", String.valueOf(composite.getSVGCanvas().getWidth()));
|
|
| 156 |
((Element)composite.getSVGDocument().getFirstChild()).setAttribute("height", String.valueOf(composite.getSVGCanvas().getHeight()));
|
|
| 157 | 157 |
|
| 158 | 158 |
|
| 159 | 159 |
TranscoderInput input = new TranscoderInput(composite.getSVGDocument()); |
| ... | ... | |
| 273 | 273 |
// PDF (using Lowagie iTtext lib) |
| 274 | 274 |
else if(fileFormat == ChartsEngine.OUTPUT_FORMAT_PDF) {
|
| 275 | 275 |
|
| 276 |
Document document = new Document(new Rectangle(0, 0, composite.getPanel().getWidth(), composite.getPanel().getHeight()));
|
|
| 276 |
Document document = new Document(new Rectangle(0, 0, composite.getSVGCanvas().getWidth(), composite.getSVGCanvas().getHeight()));
|
|
| 277 | 277 |
try {
|
| 278 | 278 |
|
| 279 | 279 |
PdfWriter writer = PdfWriter.getInstance(document, new BufferedOutputStream(new FileOutputStream(file))); |
| 280 | 280 |
document.open(); |
| 281 | 281 |
PdfContentByte cb = writer.getDirectContent(); |
| 282 | 282 |
|
| 283 |
Graphics2D g = cb.createGraphics(composite.getPanel().getWidth(), composite.getPanel().getHeight());
|
|
| 284 |
composite.getPanel().printAll(g);
|
|
| 283 |
Graphics2D g = cb.createGraphics(composite.getSVGCanvas().getWidth(), composite.getSVGCanvas().getHeight());
|
|
| 284 |
composite.getSVGCanvas().printAll(g);
|
|
| 285 | 285 |
g.dispose(); |
| 286 | 286 |
} |
| 287 | 287 |
catch (Exception e) {
|
| ... | ... | |
| 291 | 291 |
} |
| 292 | 292 |
// Raster (using AWT/Swing methods) |
| 293 | 293 |
else {
|
| 294 |
BufferedImage image = new BufferedImage(composite.getPanel().getWidth(), composite.getPanel().getHeight(), BufferedImage.TYPE_INT_RGB);
|
|
| 294 |
BufferedImage image = new BufferedImage(composite.getSVGCanvas().getWidth(), composite.getSVGCanvas().getHeight(), BufferedImage.TYPE_INT_RGB);
|
|
| 295 | 295 |
Graphics2D g = image.createGraphics(); |
| 296 |
composite.getPanel().printAll(g);
|
|
| 296 |
composite.getSVGCanvas().printAll(g);
|
|
| 297 | 297 |
g.dispose(); |
| 298 | 298 |
try {
|
| 299 | 299 |
javax.imageio.ImageIO.write(image, fileFormat, file); |
| tmp/org.txm.chartsengine.svgbatik.rcp/src/org/txm/chartsengine/svgbatik/rcp/swing/SVGPanel.java (revision 1793) | ||
|---|---|---|
| 1 |
// Copyright © 2010-2013 ENS de Lyon. |
|
| 2 |
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of |
|
| 3 |
// Lyon 2, University of Franche-Comté, University of Nice |
|
| 4 |
// Sophia Antipolis, University of Paris 3. |
|
| 5 |
// |
|
| 6 |
// The TXM platform is free software: you can redistribute it |
|
| 7 |
// and/or modify it under the terms of the GNU General Public |
|
| 8 |
// License as published by the Free Software Foundation, |
|
| 9 |
// either version 2 of the License, or (at your option) any |
|
| 10 |
// later version. |
|
| 11 |
// |
|
| 12 |
// The TXM platform is distributed in the hope that it will be |
|
| 13 |
// useful, but WITHOUT ANY WARRANTY; without even the implied |
|
| 14 |
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
|
| 15 |
// PURPOSE. See the GNU General Public License for more |
|
| 16 |
// details. |
|
| 17 |
// |
|
| 18 |
// You should have received a copy of the GNU General |
|
| 19 |
// Public License along with the TXM platform. If not, see |
|
| 20 |
// http://www.gnu.org/licenses. |
|
| 21 |
// |
|
| 22 |
// |
|
| 23 |
// |
|
| 24 |
// $LastChangedDate:$ |
|
| 25 |
// $LastChangedRevision:$ |
|
| 26 |
// $LastChangedBy:$ |
|
| 27 |
// |
|
| 28 |
package org.txm.chartsengine.svgbatik.rcp.swing; |
|
| 29 |
|
|
| 30 |
|
|
| 31 |
import java.awt.event.InputEvent; |
|
| 32 |
import java.awt.event.MouseEvent; |
|
| 33 |
import java.awt.event.MouseWheelEvent; |
|
| 34 |
import java.awt.event.MouseWheelListener; |
|
| 35 |
import java.awt.geom.AffineTransform; |
|
| 36 |
import java.util.List; |
|
| 37 |
|
|
| 38 |
import org.apache.batik.swing.JSVGCanvas; |
|
| 39 |
import org.apache.batik.swing.gvt.AbstractImageZoomInteractor; |
|
| 40 |
import org.apache.batik.swing.gvt.AbstractPanInteractor; |
|
| 41 |
import org.apache.batik.swing.gvt.AbstractResetTransformInteractor; |
|
| 42 |
import org.apache.batik.swing.gvt.AbstractZoomInteractor; |
|
| 43 |
import org.apache.batik.swing.gvt.Interactor; |
|
| 44 |
import org.txm.chartsengine.rcp.IChartComponent; |
|
| 45 |
import org.txm.chartsengine.rcp.SWTChartsComponentsProvider; |
|
| 46 |
import org.txm.chartsengine.rcp.editors.ChartEditor; |
|
| 47 |
import org.txm.chartsengine.rcp.events.ChartKeyListener; |
|
| 48 |
|
|
| 49 |
/** |
|
| 50 |
* SVG Batik SVG canvas swing panel. |
|
| 51 |
*/ |
|
| 52 |
public class SVGPanel extends JSVGCanvas implements IChartComponent {
|
|
| 53 |
|
|
| 54 |
/** |
|
| 55 |
* The linked editor. |
|
| 56 |
*/ |
|
| 57 |
protected ChartEditor editor; |
|
| 58 |
|
|
| 59 |
/** |
|
| 60 |
* The Constant serialVersionUID. |
|
| 61 |
*/ |
|
| 62 |
private static final long serialVersionUID = -4381954167495751486L; |
|
| 63 |
|
|
| 64 |
/** |
|
| 65 |
* Current zoom value. |
|
| 66 |
*/ |
|
| 67 |
int zoom = 0; |
|
| 68 |
|
|
| 69 |
/** |
|
| 70 |
* Key pressed pan factor. |
|
| 71 |
*/ |
|
| 72 |
protected double keyPressedPanFactor = 0.5; |
|
| 73 |
|
|
| 74 |
|
|
| 75 |
/** |
|
| 76 |
* Instantiates a new SVG panel. |
|
| 77 |
* |
|
| 78 |
* @param frame the frame |
|
| 79 |
*/ |
|
| 80 |
public SVGPanel() {
|
|
| 81 |
//super(new BorderLayout()); |
|
| 82 |
super(null, true, false); |
|
| 83 |
|
|
| 84 |
//this.svgCanvas = new JSVGCanvas(null, true, false); |
|
| 85 |
//this.add("Center", svgCanvas); //$NON-NLS-1$
|
|
| 86 |
|
|
| 87 |
// TODO: needed for automatic refresh after dynamically modifying the SVG DOM |
|
| 88 |
//svgCanvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC); |
|
| 89 |
|
|
| 90 |
List<Interactor> list = this.getInteractors(); |
|
| 91 |
list.clear(); |
|
| 92 |
|
|
| 93 |
|
|
| 94 |
// FIXME : test for constant text label font size (only work with the SVG produced by the SVGGraphicsDevice of R, not with CairoSVG because it doesn't produces text tag, only glyph paths) |
|
| 95 |
//svgCanvas.addMouseWheelListener(new ___AbstractImageZoomInteractor()); |
|
| 96 |
|
|
| 97 |
list.add(zoomInteractor); |
|
| 98 |
list.add(imageZoomInteractor); |
|
| 99 |
list.add(panInteractor); |
|
| 100 |
list.add(resetTransformInteractor); |
|
| 101 |
|
|
| 102 |
this.addMouseWheelListener(new MouseWheelListener() {
|
|
| 103 |
|
|
| 104 |
@Override |
|
| 105 |
public void mouseWheelMoved(MouseWheelEvent e) {
|
|
| 106 |
|
|
| 107 |
|
|
| 108 |
// FIXME : test zoom by viewbox attribute |
|
| 109 |
// final MouseWheelEvent mwe = e; |
|
| 110 |
// svgCanvas.getUpdateManager().getUpdateRunnableQueue().invokeLater(new Runnable() {
|
|
| 111 |
// |
|
| 112 |
// @Override |
|
| 113 |
// public void run() {
|
|
| 114 |
// // TODO Auto-generated method stub |
|
| 115 |
// |
|
| 116 |
// //System.out.println("SVGPanel.SVGPanel(...).new MouseWheelListener() {...}.mouseWheelMoved(): " + ((Element)getSVGDocument().getFirstChild()).getAttribute("viewBox"));
|
|
| 117 |
// |
|
| 118 |
// String[] viewBox = ((Element)getSVGDocument().getFirstChild()).getAttribute("viewBox").split(" ");
|
|
| 119 |
// |
|
| 120 |
// int x = Integer.valueOf(viewBox[0]); |
|
| 121 |
// int y = Integer.valueOf(viewBox[1]); |
|
| 122 |
// int width = Integer.valueOf(viewBox[2]); |
|
| 123 |
// int height = Integer.valueOf(viewBox[3]); |
|
| 124 |
// |
|
| 125 |
// if (mwe.getUnitsToScroll() < 0) {
|
|
| 126 |
// |
|
| 127 |
// x += 10; |
|
| 128 |
// y += 10; |
|
| 129 |
// width -= 10; |
|
| 130 |
// height -= 10; |
|
| 131 |
// |
|
| 132 |
// |
|
| 133 |
// |
|
| 134 |
// } |
|
| 135 |
// else {
|
|
| 136 |
// |
|
| 137 |
// x -= 10; |
|
| 138 |
// y -= 10; |
|
| 139 |
// width += 10; |
|
| 140 |
// height += 10; |
|
| 141 |
// |
|
| 142 |
// } |
|
| 143 |
// ((Element)getSVGDocument().getFirstChild()).setAttribute("viewBox", x + " " + y + " " + width + " " + height);
|
|
| 144 |
// } |
|
| 145 |
// }); |
|
| 146 |
|
|
| 147 |
|
|
| 148 |
|
|
| 149 |
|
|
| 150 |
// FIXME : tests for constant text font size |
|
| 151 |
// FIXME : only work with SVG generated with text tag |
|
| 152 |
// FIXME : do not work properly |
|
| 153 |
// NodeList elements = svgCanvas.getSVGDocument().getElementsByTagName("text");
|
|
| 154 |
// Element element; |
|
| 155 |
// for (int i = 0; i < elements.getLength(); i++) {
|
|
| 156 |
// element = (Element) elements.item(i); |
|
| 157 |
// |
|
| 158 |
// // TODO : Debug : Affichage des attributs de l'�l�ment |
|
| 159 |
//// NamedNodeMap attributes = element.getAttributes(); |
|
| 160 |
//// int numAttrs = attributes.getLength(); |
|
| 161 |
//// System.out.println("");
|
|
| 162 |
//// for (int j = 0; j < numAttrs; j++) {
|
|
| 163 |
//// |
|
| 164 |
//// Attr attr = (Attr) attributes.item(j); |
|
| 165 |
//// |
|
| 166 |
//// String attrName = attr.getNodeName(); |
|
| 167 |
//// String attrValue = attr.getNodeValue(); |
|
| 168 |
//// System.out.print(" " + attrName + "=" + attrValue);
|
|
| 169 |
//// } |
|
| 170 |
// |
|
| 171 |
// // TODO : test de modif de l'attribut font-size du texte |
|
| 172 |
// // TODO : Fonctionne mais prend beaucoup plus de ressources que la modification directe de la shape GVT |
|
| 173 |
// element.removeAttribute("style");
|
|
| 174 |
// //element.setAttribute("style", "font-size:" + (8 * 1d / zoom));
|
|
| 175 |
// |
|
| 176 |
// if(zoom != 0) {
|
|
| 177 |
// double fontSize = (8 * 1d / zoom); |
|
| 178 |
// element.setAttribute("font-size", fontSize + "px");
|
|
| 179 |
// } |
|
| 180 |
// |
|
| 181 |
// } |
|
| 182 |
|
|
| 183 |
|
|
| 184 |
// FIXME : old version by matrix transformation |
|
| 185 |
if (e.getUnitsToScroll() < 0) {
|
|
| 186 |
zoom(e.getX(), e.getY(), true); |
|
| 187 |
} |
|
| 188 |
else {
|
|
| 189 |
zoom(e.getX(), e.getY(), false); |
|
| 190 |
} |
|
| 191 |
|
|
| 192 |
|
|
| 193 |
} |
|
| 194 |
}); |
|
| 195 |
|
|
| 196 |
// add default chart key listener |
|
| 197 |
this.addKeyListener(new ChartKeyListener(SWTChartsComponentsProvider.getCurrent(), this, 10.5)); |
|
| 198 |
|
|
| 199 |
//this.setChartEditor(editor); |
|
| 200 |
|
|
| 201 |
|
|
| 202 |
} |
|
| 203 |
|
|
| 204 |
// ---------------------------------------------------------------------- |
|
| 205 |
// Interactors |
|
| 206 |
// ---------------------------------------------------------------------- |
|
| 207 |
|
|
| 208 |
/** |
|
| 209 |
* An interactor to perform a zoom. |
|
| 210 |
* <p>Binding: BUTTON1 + CTRL Key</p> |
|
| 211 |
*/ |
|
| 212 |
protected Interactor zoomInteractor = new AbstractZoomInteractor() {
|
|
| 213 |
@Override |
|
| 214 |
public boolean startInteraction(InputEvent ie) {
|
|
| 215 |
int mods = ie.getModifiers(); |
|
| 216 |
return |
|
| 217 |
ie.getID() == MouseEvent.MOUSE_PRESSED && |
|
| 218 |
(mods & InputEvent.BUTTON1_MASK) != 0 && |
|
| 219 |
(mods & InputEvent.CTRL_MASK) != 0; |
|
| 220 |
} |
|
| 221 |
}; |
|
| 222 |
|
|
| 223 |
/** |
|
| 224 |
* An interactor to perform a realtime zoom. |
|
| 225 |
* <p>Binding: BUTTON3 + SHif T Key</p> |
|
| 226 |
*/ |
|
| 227 |
protected Interactor imageZoomInteractor = new AbstractImageZoomInteractor() {
|
|
| 228 |
@Override |
|
| 229 |
public boolean startInteraction(InputEvent ie) {
|
|
| 230 |
int mods = ie.getModifiers(); |
|
| 231 |
return |
|
| 232 |
ie.getID() == MouseEvent.MOUSE_PRESSED && |
|
| 233 |
(mods & InputEvent.BUTTON3_MASK) != 0 && |
|
| 234 |
(mods & InputEvent.SHIFT_MASK) != 0; |
|
| 235 |
} |
|
| 236 |
}; |
|
| 237 |
|
|
| 238 |
/** |
|
| 239 |
* An interactor to perform a translation. |
|
| 240 |
* <p>Binding: BUTTON1 + SHif T Key</p> |
|
| 241 |
*/ |
|
| 242 |
protected Interactor panInteractor = new AbstractPanInteractor() {
|
|
| 243 |
@Override |
|
| 244 |
public boolean startInteraction(InputEvent ie) {
|
|
| 245 |
int mods = ie.getModifiers(); |
|
| 246 |
return |
|
| 247 |
ie.getID() == MouseEvent.MOUSE_PRESSED && |
|
| 248 |
(mods & InputEvent.BUTTON1_MASK) != 0 && |
|
| 249 |
(mods & InputEvent.SHIFT_MASK) != 1; |
|
| 250 |
} |
|
| 251 |
}; |
|
| 252 |
|
|
| 253 |
/** |
|
| 254 |
* An interactor to reset the rendering transform. |
|
| 255 |
* <p>Binding: CTRL+SHif T+BUTTON3</p> |
|
| 256 |
*/ |
|
| 257 |
protected Interactor resetTransformInteractor = new AbstractResetTransformInteractor() {
|
|
| 258 |
@Override |
|
| 259 |
public boolean startInteraction(InputEvent ie) {
|
|
| 260 |
int mods = ie.getModifiers(); |
|
| 261 |
return |
|
| 262 |
ie.getID() == MouseEvent.MOUSE_CLICKED && |
|
| 263 |
(mods & InputEvent.BUTTON2_MASK) != 0 && |
|
| 264 |
(mods & InputEvent.SHIFT_MASK) != 1 && |
|
| 265 |
(mods & InputEvent.CTRL_MASK) != 1; |
|
| 266 |
} |
|
| 267 |
}; |
|
| 268 |
|
|
| 269 |
/** |
|
| 270 |
* Resets pan and zoom. |
|
| 271 |
*/ |
|
| 272 |
public void resetView() {
|
|
| 273 |
this.zoom = 0; |
|
| 274 |
AffineTransform trans = AffineTransform.getTranslateInstance(0, 0); |
|
| 275 |
trans.scale(1, 1); |
|
| 276 |
this.setRenderingTransform(trans); |
|
| 277 |
} |
|
| 278 |
|
|
| 279 |
|
|
| 280 |
|
|
| 281 |
@Override |
|
| 282 |
public void zoom(double x, double y, boolean zoomIn) {
|
|
| 283 |
|
|
| 284 |
// FIXME: zoom tests. reset the pan |
|
| 285 |
|
|
| 286 |
// TODO Auto-generated method stub |
|
| 287 |
// x += this.svgCanvas.getRenderingTransform().getTranslateX(); |
|
| 288 |
// y += this.svgCanvas.getRenderingTransform().getTranslateY(); |
|
| 289 |
|
|
| 290 |
|
|
| 291 |
AffineTransform trans = AffineTransform.getTranslateInstance(x, y); |
|
| 292 |
|
|
| 293 |
|
|
| 294 |
if(zoomIn) {
|
|
| 295 |
trans.scale(this.getRenderingTransform().getScaleX() * 1.1, this.getRenderingTransform().getScaleY() * 1.1); |
|
| 296 |
} |
|
| 297 |
else {
|
|
| 298 |
trans.scale(this.getRenderingTransform().getScaleX() * 0.9, this.getRenderingTransform().getScaleY() * 0.9); |
|
| 299 |
} |
|
| 300 |
|
|
| 301 |
// trans.translate(-x + this.svgCanvas.getRenderingTransform().getTranslateX(), -y + this.svgCanvas.getRenderingTransform().getTranslateY()); |
|
| 302 |
|
|
| 303 |
// System.out.println("SVGPanel.zoom2(): " + this.svgCanvas.getRenderingTransform().getTranslateX());
|
|
| 304 |
|
|
| 305 |
trans.translate(-x, -y); |
|
| 306 |
|
|
| 307 |
|
|
| 308 |
if(trans.getDeterminant() != 0) {
|
|
| 309 |
this.setRenderingTransform(trans); |
|
| 310 |
} |
|
| 311 |
} |
|
| 312 |
|
|
| 313 |
// FIXME: tests zoom |
|
| 314 |
/** |
|
| 315 |
* Zoom in or zoom out the panel at the specified origin point coordinates. |
|
| 316 |
* @param x |
|
| 317 |
* @param y |
|
| 318 |
* @param zoom |
|
| 319 |
*/ |
|
| 320 |
public void zoom(double x, double y, int zoom) {
|
|
| 321 |
|
|
| 322 |
// FIXME: SJ: the zoom does nothing when zoom is equal to 0 and 1. |
|
| 323 |
|
|
| 324 |
AffineTransform trans = AffineTransform.getTranslateInstance(x, y); |
|
| 325 |
|
|
| 326 |
int dy = zoom; |
|
| 327 |
double s; |
|
| 328 |
if(dy < 0) {
|
|
| 329 |
s = -1f / dy; |
|
| 330 |
} |
|
| 331 |
else {
|
|
| 332 |
s = dy; |
|
| 333 |
} |
|
| 334 |
|
|
| 335 |
trans.scale(s, s); |
|
| 336 |
|
|
| 337 |
trans.translate(-x, -y); |
|
| 338 |
|
|
| 339 |
if(trans.getDeterminant() != 0) {
|
|
| 340 |
this.setRenderingTransform(trans); |
|
| 341 |
} |
|
| 342 |
} |
|
| 343 |
|
|
| 344 |
|
|
| 345 |
@Override |
|
| 346 |
public void pan(double srcX, double srcY, double dstX, double dstY, double panFactor) {
|
|
| 347 |
|
|
| 348 |
AffineTransform trans = this.getRenderingTransform(); |
|
| 349 |
trans.translate(-dstX * panFactor, dstY * panFactor); |
|
| 350 |
this.setRenderingTransform(trans); |
|
| 351 |
|
|
| 352 |
} |
|
| 353 |
|
|
| 354 |
@Override |
|
| 355 |
public ChartEditor getChartEditor() {
|
|
| 356 |
return this.editor; |
|
| 357 |
} |
|
| 358 |
|
|
| 359 |
@Override |
|
| 360 |
public void setChartEditor(ChartEditor editor) {
|
|
| 361 |
this.editor = editor; |
|
| 362 |
} |
|
| 363 |
|
|
| 364 |
@Override |
|
| 365 |
public void updateMouseOverItem(MouseEvent event) {
|
|
| 366 |
// TODO Auto-generated method stub |
|
| 367 |
|
|
| 368 |
} |
|
| 369 |
|
|
| 370 |
@Override |
|
| 371 |
public void squareOff() {
|
|
| 372 |
// not needed in this implementation |
|
| 373 |
} |
|
| 374 |
|
|
| 375 |
} |
|
| tmp/org.txm.chartsengine.svgbatik.rcp/src/org/txm/chartsengine/svgbatik/rcp/swing/SVGCanvas.java (revision 1793) | ||
|---|---|---|
| 1 |
// Copyright © 2010-2013 ENS de Lyon. |
|
| 2 |
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of |
|
| 3 |
// Lyon 2, University of Franche-Comté, University of Nice |
|
| 4 |
// Sophia Antipolis, University of Paris 3. |
|
| 5 |
// |
|
| 6 |
// The TXM platform is free software: you can redistribute it |
|
| 7 |
// and/or modify it under the terms of the GNU General Public |
|
| 8 |
// License as published by the Free Software Foundation, |
|
| 9 |
// either version 2 of the License, or (at your option) any |
|
| 10 |
// later version. |
|
| 11 |
// |
|
| 12 |
// The TXM platform is distributed in the hope that it will be |
|
| 13 |
// useful, but WITHOUT ANY WARRANTY; without even the implied |
|
| 14 |
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
|
| 15 |
// PURPOSE. See the GNU General Public License for more |
|
| 16 |
// details. |
|
| 17 |
// |
|
| 18 |
// You should have received a copy of the GNU General |
|
| 19 |
// Public License along with the TXM platform. If not, see |
|
| 20 |
// http://www.gnu.org/licenses. |
|
| 21 |
// |
|
| 22 |
// |
|
| 23 |
// |
|
| 24 |
// $LastChangedDate:$ |
|
| 25 |
// $LastChangedRevision:$ |
|
| 26 |
// $LastChangedBy:$ |
|
| 27 |
// |
|
| 28 |
package org.txm.chartsengine.svgbatik.rcp.swing; |
|
| 29 |
|
|
| 30 |
|
|
| 31 |
import java.awt.event.InputEvent; |
|
| 32 |
import java.awt.event.MouseEvent; |
|
| 33 |
import java.awt.event.MouseWheelEvent; |
|
| 34 |
import java.awt.event.MouseWheelListener; |
|
| 35 |
import java.awt.geom.AffineTransform; |
|
| 36 |
import java.util.List; |
|
| 37 |
|
|
| 38 |
import org.apache.batik.swing.JSVGCanvas; |
|
| 39 |
import org.apache.batik.swing.gvt.AbstractImageZoomInteractor; |
|
| 40 |
import org.apache.batik.swing.gvt.AbstractPanInteractor; |
|
| 41 |
import org.apache.batik.swing.gvt.AbstractResetTransformInteractor; |
|
| 42 |
import org.apache.batik.swing.gvt.AbstractZoomInteractor; |
|
| 43 |
import org.apache.batik.swing.gvt.Interactor; |
|
| 44 |
import org.txm.chartsengine.rcp.IChartComponent; |
|
| 45 |
import org.txm.chartsengine.rcp.SWTChartsComponentsProvider; |
|
| 46 |
import org.txm.chartsengine.rcp.editors.ChartEditor; |
|
| 47 |
import org.txm.chartsengine.rcp.events.ChartKeyListener; |
|
| 48 |
|
|
| 49 |
/** |
|
| 50 |
* Batik SVG canvas swing component. |
|
| 51 |
* |
|
| 52 |
* @author sjacquot |
|
| 53 |
* |
|
| 54 |
*/ |
|
| 55 |
public class SVGCanvas extends JSVGCanvas implements IChartComponent {
|
|
| 56 |
|
|
| 57 |
/** |
|
| 58 |
* The linked editor. |
|
| 59 |
*/ |
|
| 60 |
protected ChartEditor editor; |
|
| 61 |
|
|
| 62 |
/** |
|
| 63 |
* The Constant serialVersionUID. |
|
| 64 |
*/ |
|
| 65 |
private static final long serialVersionUID = -4381954167495751486L; |
|
| 66 |
|
|
| 67 |
/** |
|
| 68 |
* Current zoom value. |
|
| 69 |
*/ |
|
| 70 |
int zoom = 0; |
|
| 71 |
|
|
| 72 |
/** |
|
| 73 |
* Key pressed pan factor. |
|
| 74 |
*/ |
|
| 75 |
protected double keyPressedPanFactor = 0.5; |
|
| 76 |
|
|
| 77 |
|
|
| 78 |
/** |
|
| 79 |
* Instantiates a new SVG panel. |
|
| 80 |
* |
|
| 81 |
* @param frame the frame |
|
| 82 |
*/ |
|
| 83 |
public SVGCanvas() {
|
|
| 84 |
//super(new BorderLayout()); |
|
| 85 |
super(null, true, false); |
|
| 86 |
|
|
| 87 |
//this.svgCanvas = new JSVGCanvas(null, true, false); |
|
| 88 |
//this.add("Center", svgCanvas); //$NON-NLS-1$
|
|
| 89 |
|
|
| 90 |
// TODO: needed for automatic refresh after dynamically modifying the SVG DOM |
|
| 91 |
//svgCanvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC); |
|
| 92 |
|
|
| 93 |
List<Interactor> list = this.getInteractors(); |
|
| 94 |
list.clear(); |
|
| 95 |
|
|
| 96 |
|
|
| 97 |
// FIXME : test for constant text label font size (only work with the SVG produced by the SVGGraphicsDevice of R, not with CairoSVG because it doesn't produces text tag, only glyph paths) |
|
| 98 |
//svgCanvas.addMouseWheelListener(new ___AbstractImageZoomInteractor()); |
|
| 99 |
|
|
| 100 |
list.add(zoomInteractor); |
|
| 101 |
list.add(imageZoomInteractor); |
|
| 102 |
list.add(panInteractor); |
|
| 103 |
list.add(resetTransformInteractor); |
|
| 104 |
|
|
| 105 |
this.addMouseWheelListener(new MouseWheelListener() {
|
|
| 106 |
|
|
| 107 |
@Override |
|
| 108 |
public void mouseWheelMoved(MouseWheelEvent e) {
|
|
| 109 |
|
|
| 110 |
|
|
| 111 |
// FIXME : test zoom by viewbox attribute |
|
| 112 |
// final MouseWheelEvent mwe = e; |
|
| 113 |
// svgCanvas.getUpdateManager().getUpdateRunnableQueue().invokeLater(new Runnable() {
|
|
| 114 |
// |
|
| 115 |
// @Override |
|
| 116 |
// public void run() {
|
|
| 117 |
// // TODO Auto-generated method stub |
|
| 118 |
// |
|
| 119 |
// //System.out.println("SVGPanel.SVGPanel(...).new MouseWheelListener() {...}.mouseWheelMoved(): " + ((Element)getSVGDocument().getFirstChild()).getAttribute("viewBox"));
|
|
| 120 |
// |
|
| 121 |
// String[] viewBox = ((Element)getSVGDocument().getFirstChild()).getAttribute("viewBox").split(" ");
|
|
| 122 |
// |
|
| 123 |
// int x = Integer.valueOf(viewBox[0]); |
|
| 124 |
// int y = Integer.valueOf(viewBox[1]); |
|
| 125 |
// int width = Integer.valueOf(viewBox[2]); |
|
| 126 |
// int height = Integer.valueOf(viewBox[3]); |
|
| 127 |
// |
|
| 128 |
// if (mwe.getUnitsToScroll() < 0) {
|
|
| 129 |
// |
|
| 130 |
// x += 10; |
|
| 131 |
// y += 10; |
|
| 132 |
// width -= 10; |
|
| 133 |
// height -= 10; |
|
| 134 |
// |
|
| 135 |
// |
|
| 136 |
// |
|
| 137 |
// } |
|
| 138 |
// else {
|
|
| 139 |
// |
|
| 140 |
// x -= 10; |
|
| 141 |
// y -= 10; |
|
| 142 |
// width += 10; |
|
| 143 |
// height += 10; |
|
| 144 |
// |
|
| 145 |
// } |
|
| 146 |
// ((Element)getSVGDocument().getFirstChild()).setAttribute("viewBox", x + " " + y + " " + width + " " + height);
|
|
| 147 |
// } |
|
| 148 |
// }); |
|
| 149 |
|
|
| 150 |
|
|
| 151 |
|
|
| 152 |
|
|
| 153 |
// FIXME : tests for constant text font size |
|
| 154 |
// FIXME : only work with SVG generated with text tag |
|
| 155 |
// FIXME : do not work properly |
|
| 156 |
// NodeList elements = svgCanvas.getSVGDocument().getElementsByTagName("text");
|
|
| 157 |
// Element element; |
|
| 158 |
// for (int i = 0; i < elements.getLength(); i++) {
|
|
| 159 |
// element = (Element) elements.item(i); |
|
| 160 |
// |
|
| 161 |
// // TODO : Debug : Affichage des attributs de l'�l�ment |
|
| 162 |
//// NamedNodeMap attributes = element.getAttributes(); |
|
| 163 |
//// int numAttrs = attributes.getLength(); |
|
| 164 |
//// System.out.println("");
|
|
| 165 |
//// for (int j = 0; j < numAttrs; j++) {
|
|
| 166 |
//// |
|
| 167 |
//// Attr attr = (Attr) attributes.item(j); |
|
| 168 |
//// |
|
| 169 |
//// String attrName = attr.getNodeName(); |
|
| 170 |
//// String attrValue = attr.getNodeValue(); |
|
| 171 |
//// System.out.print(" " + attrName + "=" + attrValue);
|
|
| 172 |
//// } |
|
| 173 |
// |
|
| 174 |
// // TODO : test de modif de l'attribut font-size du texte |
|
| 175 |
// // TODO : Fonctionne mais prend beaucoup plus de ressources que la modification directe de la shape GVT |
|
| 176 |
// element.removeAttribute("style");
|
|
| 177 |
// //element.setAttribute("style", "font-size:" + (8 * 1d / zoom));
|
|
| 178 |
// |
|
| 179 |
// if(zoom != 0) {
|
|
| 180 |
// double fontSize = (8 * 1d / zoom); |
|
| 181 |
// element.setAttribute("font-size", fontSize + "px");
|
|
| 182 |
// } |
|
| 183 |
// |
|
| 184 |
// } |
|
| 185 |
|
|
| 186 |
|
|
| 187 |
// FIXME : old version by matrix transformation |
|
| 188 |
if (e.getUnitsToScroll() < 0) {
|
|
| 189 |
zoom(e.getX(), e.getY(), true); |
|
| 190 |
} |
|
| 191 |
else {
|
|
| 192 |
zoom(e.getX(), e.getY(), false); |
|
| 193 |
} |
|
| 194 |
|
|
| 195 |
|
|
| 196 |
} |
|
| 197 |
}); |
|
| 198 |
|
|
| 199 |
// add default chart key listener |
|
| 200 |
this.addKeyListener(new ChartKeyListener(SWTChartsComponentsProvider.getCurrent(), this, 10.5)); |
|
| 201 |
|
|
| 202 |
//this.setChartEditor(editor); |
|
| 203 |
|
|
| 204 |
|
|
| 205 |
} |
|
| 206 |
|
|
| 207 |
// ---------------------------------------------------------------------- |
|
| 208 |
// Interactors |
|
| 209 |
// ---------------------------------------------------------------------- |
|
| 210 |
|
|
| 211 |
/** |
|
| 212 |
* An interactor to perform a zoom. |
|
| 213 |
* <p>Binding: BUTTON1 + CTRL Key</p> |
|
| 214 |
*/ |
|
| 215 |
protected Interactor zoomInteractor = new AbstractZoomInteractor() {
|
|
| 216 |
@Override |
|
| 217 |
public boolean startInteraction(InputEvent ie) {
|
|
| 218 |
int mods = ie.getModifiers(); |
|
| 219 |
return |
|
| 220 |
ie.getID() == MouseEvent.MOUSE_PRESSED && |
|
| 221 |
(mods & InputEvent.BUTTON1_MASK) != 0 && |
|
| 222 |
(mods & InputEvent.CTRL_MASK) != 0; |
|
| 223 |
} |
|
| 224 |
}; |
|
| 225 |
|
|
| 226 |
/** |
|
| 227 |
* An interactor to perform a realtime zoom. |
|
| 228 |
* <p>Binding: BUTTON3 + SHif T Key</p> |
|
| 229 |
*/ |
|
| 230 |
protected Interactor imageZoomInteractor = new AbstractImageZoomInteractor() {
|
|
| 231 |
@Override |
|
| 232 |
public boolean startInteraction(InputEvent ie) {
|
|
| 233 |
int mods = ie.getModifiers(); |
|
| 234 |
return |
|
| 235 |
ie.getID() == MouseEvent.MOUSE_PRESSED && |
|
| 236 |
(mods & InputEvent.BUTTON3_MASK) != 0 && |
|
| 237 |
(mods & InputEvent.SHIFT_MASK) != 0; |
|
| 238 |
} |
|
| 239 |
}; |
|
| 240 |
|
|
| 241 |
/** |
|
| 242 |
* An interactor to perform a translation. |
|
| 243 |
* <p>Binding: BUTTON1 + SHif T Key</p> |
|
| 244 |
*/ |
|
| 245 |
protected Interactor panInteractor = new AbstractPanInteractor() {
|
|
| 246 |
@Override |
|
| 247 |
public boolean startInteraction(InputEvent ie) {
|
|
| 248 |
int mods = ie.getModifiers(); |
|
| 249 |
return |
|
| 250 |
ie.getID() == MouseEvent.MOUSE_PRESSED && |
|
| 251 |
(mods & InputEvent.BUTTON1_MASK) != 0 && |
|
| 252 |
(mods & InputEvent.SHIFT_MASK) != 1; |
|
| 253 |
} |
|
| 254 |
}; |
|
| 255 |
|
|
| 256 |
/** |
|
| 257 |
* An interactor to reset the rendering transform. |
|
| 258 |
* <p>Binding: CTRL+SHif T+BUTTON3</p> |
|
| 259 |
*/ |
|
| 260 |
protected Interactor resetTransformInteractor = new AbstractResetTransformInteractor() {
|
|
| 261 |
@Override |
|
| 262 |
public boolean startInteraction(InputEvent ie) {
|
|
| 263 |
int mods = ie.getModifiers(); |
|
| 264 |
return |
|
| 265 |
ie.getID() == MouseEvent.MOUSE_CLICKED && |
|
| 266 |
(mods & InputEvent.BUTTON2_MASK) != 0 && |
|
| 267 |
(mods & InputEvent.SHIFT_MASK) != 1 && |
|
| 268 |
(mods & InputEvent.CTRL_MASK) != 1; |
|
| 269 |
} |
|
| 270 |
}; |
|
| 271 |
|
|
| 272 |
/** |
|
| 273 |
* Resets pan and zoom. |
|
| 274 |
*/ |
|
| 275 |
public void resetView() {
|
|
| 276 |
this.zoom = 0; |
|
| 277 |
AffineTransform trans = AffineTransform.getTranslateInstance(0, 0); |
|
| 278 |
trans.scale(1, 1); |
|
| 279 |
this.setRenderingTransform(trans); |
|
| 280 |
} |
|
| 281 |
|
|
| 282 |
|
|
| 283 |
|
|
| 284 |
@Override |
|
| 285 |
public void zoom(double x, double y, boolean zoomIn) {
|
|
| 286 |
|
|
| 287 |
// FIXME: zoom tests. reset the pan |
|
| 288 |
|
|
| 289 |
// TODO Auto-generated method stub |
|
| 290 |
// x += this.svgCanvas.getRenderingTransform().getTranslateX(); |
|
| 291 |
// y += this.svgCanvas.getRenderingTransform().getTranslateY(); |
|
| 292 |
|
|
| 293 |
|
|
| 294 |
AffineTransform trans = AffineTransform.getTranslateInstance(x, y); |
|
| 295 |
|
|
| 296 |
|
|
| 297 |
if(zoomIn) {
|
|
| 298 |
trans.scale(this.getRenderingTransform().getScaleX() * 1.1, this.getRenderingTransform().getScaleY() * 1.1); |
|
| 299 |
} |
|
| 300 |
else {
|
|
| 301 |
trans.scale(this.getRenderingTransform().getScaleX() * 0.9, this.getRenderingTransform().getScaleY() * 0.9); |
|
| 302 |
} |
|
| 303 |
|
|
| 304 |
// trans.translate(-x + this.svgCanvas.getRenderingTransform().getTranslateX(), -y + this.svgCanvas.getRenderingTransform().getTranslateY()); |
|
| 305 |
|
|
| 306 |
// System.out.println("SVGPanel.zoom2(): " + this.svgCanvas.getRenderingTransform().getTranslateX());
|
|
| 307 |
|
|
| 308 |
trans.translate(-x, -y); |
|
| 309 |
|
|
| 310 |
|
|
| 311 |
if(trans.getDeterminant() != 0) {
|
|
| 312 |
this.setRenderingTransform(trans); |
|
| 313 |
} |
|
| 314 |
} |
|
| 315 |
|
|
| 316 |
// FIXME: tests zoom |
|
| 317 |
/** |
|
| 318 |
* Zoom in or zoom out the panel at the specified origin point coordinates. |
|
| 319 |
* @param x |
|
| 320 |
* @param y |
|
| 321 |
* @param zoom |
|
| 322 |
*/ |
|
| 323 |
public void zoom(double x, double y, int zoom) {
|
|
| 324 |
|
|
| 325 |
// FIXME: SJ: the zoom does nothing when zoom is equal to 0 and 1. |
|
| 326 |
|
|
| 327 |
AffineTransform trans = AffineTransform.getTranslateInstance(x, y); |
|
| 328 |
|
|
| 329 |
int dy = zoom; |
|
| 330 |
double s; |
|
| 331 |
if(dy < 0) {
|
|
| 332 |
s = -1f / dy; |
|
| 333 |
} |
|
| 334 |
else {
|
|
| 335 |
s = dy; |
|
| 336 |
} |
|
| 337 |
|
|
| 338 |
trans.scale(s, s); |
|
| 339 |
|
|
| 340 |
trans.translate(-x, -y); |
|
| 341 |
|
|
| 342 |
if(trans.getDeterminant() != 0) {
|
|
| 343 |
this.setRenderingTransform(trans); |
|
| 344 |
} |
|
| 345 |
} |
|
| 346 |
|
|
| 347 |
|
|
| 348 |
@Override |
|
| 349 |
public void pan(double srcX, double srcY, double dstX, double dstY, double panFactor) {
|
|
| 350 |
|
|
| 351 |
AffineTransform trans = this.getRenderingTransform(); |
|
| 352 |
trans.translate(-dstX * panFactor, dstY * panFactor); |
|
| 353 |
this.setRenderingTransform(trans); |
|
| 354 |
|
|
| 355 |
} |
|
| 356 |
|
|
| 357 |
@Override |
|
| 358 |
public ChartEditor getChartEditor() {
|
|
| 359 |
return this.editor; |
|
| 360 |
} |
|
| 361 |
|
|
| 362 |
@Override |
|
| 363 |
public void setChartEditor(ChartEditor editor) {
|
|
| 364 |
this.editor = editor; |
|
| 365 |
} |
|
| 366 |
|
|
| 367 |
@Override |
|
| 368 |
public void updateMouseOverItem(MouseEvent event) {
|
|
| 369 |
// TODO Auto-generated method stub |
|
| 370 |
|
|
| 371 |
} |
|
| 372 |
|
|
| 373 |
@Override |
|
| 374 |
public void squareOff() {
|
|
| 375 |
// not needed in this implementation |
|
| 376 |
} |
|
| 377 |
|
|
| 378 |
} |
|
| 0 | 379 | |
| tmp/org.txm.rcp/src/main/java/org/txm/rcp/svg/SVGPanel.java (revision 1793) | ||
|---|---|---|
| 48 | 48 |
/** |
| 49 | 49 |
* The Class SVGPanel. |
| 50 | 50 |
*/ |
| 51 |
//FIXME: SJ: this class should be linked to /org.txm.chartsengine.svgbatik.rcp/src/org/txm/chartsengine/svgbatik/rcp/swing/SVGPanel.java (inheritance of the charts engine class from this one)
|
|
| 51 |
//FIXME: SJ: this class should be linked to /org.txm.chartsengine.svgbatik.rcp/src/org/txm/chartsengine/svgbatik/rcp/swing/SVGCanvas.java (inheritance of the charts engine class from this one)
|
|
| 52 | 52 |
@Deprecated |
| 53 | 53 |
public class SVGPanel extends JPanel{
|
| 54 | 54 |
|
Formats disponibles : Unified diff