}
public void actionPerformed(ActionEvent e) {
if (!isEnabled()) return;
DrawingView view = editorArea.getCurrentView();
JComponent comp = (JComponent) view;
File imageFile = (File) this.getValue(ConstantDefinition.FILE);
String imageType = (String) this.getValue(ConstantDefinition.IMAGE_TYPE);
Image image = null;
Graphics2D g2d = null;
//get image information
if (imageType.equalsIgnoreCase("gif")) {
Rectangle rect = GlobalFunction.checkMinimumViewport(view);
Dimension size = new Dimension(rect.width + 10, rect.height + 10);
image = comp.createImage(size.width, size.height);
g2d = (Graphics2D) image.getGraphics();
g2d.setColor(new Color(TRANSPARENT_BG_COLOR));
g2d.fillRect(0, 0, (int) size.getWidth(), (int) size.getHeight());
g2d.translate(-rect.x + 5, -rect.y + 5);
view.drawDrawing(g2d);
} else if (imageType.equalsIgnoreCase("svg")) {
// Get a DOMImplementation
DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
// Create an instance of org.w3c.dom.Document
Document document = domImpl.createDocument(null, "svg", null);
SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(document);
//ctx.setEmbeddedFontsOn(true);
// Create an instance of the SVG Generator
g2d = new SVGGraphics2D(ctx, false);
Rectangle rect = GlobalFunction.checkMinimumViewport(view);
Dimension size = new Dimension(rect.width + 10, rect.height + 10);
g2d.translate(-rect.x + 5, -rect.y + 5);
((SVGGraphics2D) g2d).setSVGCanvasSize(size);
view.drawDrawing(g2d);
} else if (imageType.equalsIgnoreCase("emf")) {
}
//write image into file
try {
if (imageType.equalsIgnoreCase("gif")) {
FileOutputStream out = new FileOutputStream(imageFile);
FilteredImageSource fis =
new FilteredImageSource(image.getSource(),
new TransFilter(TRANSPARENT_BG_COLOR));
GifEncoder ge = new GifEncoder(fis, out);
ge.encode();
out.flush();
out.close();
} else if (imageType.equalsIgnoreCase("svg")) {
FileOutputStream out = new FileOutputStream(imageFile);
boolean useCSS = true; // we want to use CSS style attribute
//Writer outer = new OutputStreamWriter(out, "iso8859-1");
Writer outer = new OutputStreamWriter(out, "UTF-8");
((SVGGraphics2D) g2d).stream(outer, useCSS);
outer.flush();
outer.close();
} else {
//version 2
Rectangle rect = GlobalFunction.checkMinimumViewport(view);
Dimension size = new Dimension((rect.x + rect.width) * 2 + 5, (rect.y + rect.height) * 2 + 5);
Dimension oldSize = view.getSize();
((SaturnDrawingView) view).setSizeTemp(size);
/**
SaveAsDialog saveAs = new SaveAsDialog();
saveAs.addAllExportFileTypes();
saveAs.showExportDialog((Component) getValue(de.FeatureModellingTool.GraphicalEditor.ConstantDefinition.UI_FRAME),
"����ͼ���ʽ", (Component) view, view.getDrawing().getTitle());
**/
exportDialog.showExportDialog((Component) getValue(de.FeatureModellingTool.GraphicalEditor.ConstantDefinition.UI_FRAME), "Export view as ...", (Component) view, view.getDrawing().getTitle());
((SaturnDrawingView) view).setSizeTemp(oldSize);
}
} catch (IOException ioe) {
System.out.println(ioe);