1
2 package hep.wired.heprep.graphicspanel;
3
4 import java.awt.*;
5 import java.io.*;
6 import java.util.*;
7
8 import org.freehep.util.export.ExportFileType;
9
10 import hep.graphics.heprep.HepRep;
11 import hep.graphics.heprep.HepRepFactory;
12 import hep.graphics.heprep.HepRepWriter;
13 import hep.graphics.heprep.xml.XMLHepRepFactory;
14
15 import hep.wired.plot.WiredPlot;
16
17 /***
18 *
19 * @author Mark Donszelmann
20 * @version $Id: XMLHepRepExportFileType.java 2157 2005-08-02 18:47:41Z duns $
21 */
22 public class XMLHepRepExportFileType extends ExportFileType {
23
24 private HepRepFactory factory;
25
26 public XMLHepRepExportFileType() {
27 factory = new XMLHepRepFactory();
28 }
29
30 public String getDescription() {
31 return "HepRep2";
32 }
33
34 public String[] getExtensions() {
35
36 return new String[] { "heprep.zip", "heprep.gz", "heprep"
37 }
38
39 public String[] getMIMETypes() {
40 return new String[] { "application/x-heprep" };
41 }
42
43 public File adjustFilename(File file, Properties user) {
44 return super.adjustFilename(file, user);
45
46
47
48
49
50
51
52
53 }
54
55 public void exportToFile(OutputStream os, Component[] target,
56 Component parent, Properties properties, String creator) throws IOException {
57 HepRepWriter writer = factory.createHepRepWriter(os, target.length > 1, target.length > 1);
58 write(writer, target, "heprep");
59 }
60
61 public void exportToFile(File file, Component[] target,
62 Component parent, Properties properties, String creator) throws IOException {
63 String name = file.getName().toLowerCase();
64 boolean random = name.endsWith(".zip");
65 boolean compress = random || name.endsWith(".gz");
66 String type = name.endsWith(".bheprep.zip") ||
67 name.endsWith(".bheprep.gz") ||
68 name.endsWith(".bheprep") ? "bheprep" : "heprep";
69
70 type = "heprep";
71 HepRepWriter writer = factory.createHepRepWriter(new FileOutputStream(file), random, compress);
72 write(writer, target, type);
73 }
74
75 private void write(HepRepWriter writer, Component[] target, String type) throws IOException {
76 for (int i=0; i<target.length; i++) {
77 if (target[i] instanceof WiredPlot) {
78 WiredPlot plot = (WiredPlot)target[i];
79 HepRep heprep = (HepRep)plot.getRecord();
80 if (heprep != null) writer.write(heprep, plot.getName()+"-"+i+"."+type);
81 }
82 }
83 writer.close();
84 }
85 }