pom.xml0000644000175000017500000000401111322712201011402 0ustar user03user03 global org.freehep 8 4.0.0 org.freehep freehep-export 2.1.1 FreeHEP Export FreeHEP Export and Save As Library freehep-maven Maven FreeHEP http://java.freehep.org/maven2 org.freehep freehep-swing 2.0.3 org.freehep jas-plotter 2.2 test maven-surefire-plugin **/ExportTest.java org.codehaus.mojo exec-maven-plugin 1.0.2 java org.freehep.util.export.test.ExportFileTypeTest scm:svn:svn://svn.freehep.org/svn/freehep/tags/freehep-export-2.1.1 scm:svn:svn://svn.freehep.org/svn/freehep/tags/freehep-export-2.1.1 src/0000755000175000017500000000000011322712201010660 5ustar user03user03src/test/0000755000175000017500000000000011322712200011636 5ustar user03user03src/test/resources/0000755000175000017500000000000011322712200013650 5ustar user03user03src/test/resources/org/0000755000175000017500000000000011322712200014437 5ustar user03user03src/test/resources/org/freehep/0000755000175000017500000000000011322712200016055 5ustar user03user03src/test/resources/org/freehep/util/0000755000175000017500000000000011322712200017032 5ustar user03user03src/test/resources/org/freehep/util/export/0000755000175000017500000000000011322712200020353 5ustar user03user03src/test/resources/org/freehep/util/export/test/0000755000175000017500000000000011322712200021332 5ustar user03user03src/test/resources/org/freehep/util/export/test/ExportTest.plotml0000644000175000017500000001234411322712200024710 0ustar user03user03 <border type="None"/> <label text="Export Test! μ"> <font style="BOLD" points="14" face="SansSerif"/> </label> 0.0,0.0,0.0 0.0,0.0,0.0 0.0,0.0,0.0 5.0,2.23606797749979,2.23606797749979 15.0,3.872983346207417,3.872983346207417 32.0,5.656854249492381,5.656854249492381 52.0,7.211102550927978,7.211102550927978 145.0,12.041594578792296,12.041594578792296 184.0,13.564659966250536,13.564659966250536 315.0,17.74823934929885,17.74823934929885 392.0,19.79898987322333,19.79898987322333 503.0,22.427661492005804,22.427661492005804 607.0,24.63736998950984,24.63736998950984 620.0,24.899799195977465,24.899799195977465 605.0,24.596747752497688,24.596747752497688 581.0,24.1039415863879,24.1039415863879 421.0,20.518284528683193,20.518284528683193 321.0,17.916472867168917,17.916472867168917 214.0,14.628738838327793,14.628738838327793 131.0,11.445523142259598,11.445523142259598 74.0,8.602325267042627,8.602325267042627 38.0,6.164414002968976,6.164414002968976 11.0,3.3166247903554,3.3166247903554 1.0,1.0,1.0 2.0,1.4142135623730951,1.4142135623730951 0.0,0.0,0.0 0.0,0.0,0.0 0.0,0.0,0.0 0.0,0.0,0.0 0.0,0.0,0.0 0.0,0.0,0.0 0.0,0.0,0.0 0.0,0.0,0.0 0.0,0.0,0.0 0.0,0.0,0.0 0.0,0.0,0.0 0.0,0.0,0.0 0.0,0.0,0.0 0.0,0.0,0.0 0.0,0.0,0.0 0.0,0.0,0.0 0.0,0.0,0.0 0.0,0.0,0.0 0.0,0.0,0.0 0.0,0.0,0.0 0.0,0.0,0.0 0.0,0.0,0.0 0.0,0.0,0.0 0.0,0.0,0.0 0.0,0.0,0.0 -100.0,10.0,10.0 -100.0,10.0,10.0 -100.0,10.0,10.0 -100.0,10.0,10.0 -100.0,10.0,10.0 -100.0,10.0,10.0 -100.0,10.0,10.0 -100.0,10.0,10.0 -100.0,10.0,10.0 -100.0,10.0,10.0 -100.0,10.0,10.0 -100.0,10.0,10.0 -100.0,10.0,10.0 -100.0,10.0,10.0 -100.0,10.0,10.0 -100.0,10.0,10.0 -99.0,9.9498743710662,9.9498743710662 -92.0,9.591663046625438,9.591663046625438 -84.0,9.16515138991168,9.16515138991168 -52.0,7.211102550927978,7.211102550927978 -21.0,4.58257569495584,4.58257569495584 46.0,6.782329983125268,6.782329983125268 137.0,11.704699910719626,11.704699910719626 256.0,16.0,16.0 372.0,19.28730152198591,19.28730152198591 485.0,22.02271554554524,22.02271554554524 535.0,23.130067012440755,23.130067012440755 497.0,22.293496809607955,22.293496809607955 460.0,21.447610589527216,21.447610589527216 396.0,19.8997487421324,19.8997487421324 275.0,16.583123951777,16.583123951777 186.0,13.638181696985855,13.638181696985855 81.0,9.0,9.0 1.0,1.0,1.0 -48.0,6.928203230275509,6.928203230275509 -74.0,8.602325267042627,8.602325267042627 -91.0,9.539392014169456,9.539392014169456 -97.0,9.848857801796104,9.848857801796104 -100.0,10.0,10.0 -100.0,10.0,10.0 -100.0,10.0,10.0 -100.0,10.0,10.0 -100.0,10.0,10.0 -100.0,10.0,10.0 -100.0,10.0,10.0 -100.0,10.0,10.0 -100.0,10.0,10.0 -100.0,10.0,10.0 -100.0,10.0,10.0 -100.0,10.0,10.0 src/test/resources/org/freehep/util/export/test/ScatterPlot.plotml0000644000175000017500000001503211322712200025030 0ustar user03user03 -0.4693173067107428,1.4507571682744322 -1.3217292066238562,1.4120753467362162 -0.1782965414092353,-3.90579391916613 1.5477465215019357,-1.5523128985981833 1.0893215320112681,0.3348217075131298 0.6373002735012927,-1.0246865042243467 -0.5361453077340237,1.6252980897582934 -0.06473648001765062,-1.317082125024132 1.0651568430905645,-1.4491236050379737 -0.6773687506744815,-0.20721178400517903 -1.3563248817764677,0.7300730047501636 1.1248927652599123,3.2899552567912904 -0.7692406915197973,-1.880664858425788 1.094921639619024,-0.6622652602679983 -1.2019768509166826,0.7657992903540801 -1.3690936782561283,0.6936944384580837 -1.1279040767971142,1.3187942976864144 1.2277563133977125,1.457781483938408 1.4370720522210036,-1.8531164082935883 0.5626706975933735,-1.3226131623742734 2.817159713871892,0.0977223767911643 -0.979027874449507,0.9428032388374741 0.08987639871575612,-0.4992569860349499 -0.3939445849200504,-2.2871490773404015 1.0348559380716813,0.0263055936972878 0.2778454421287697,3.9273334626637078 -0.3154261563493612,-4.115682943164374 0.5218314592977508,-2.425496020169122 -0.8545676698613766,0.539187287778295 0.2242223580751516,-1.5842095079042715 0.27532087856757914,0.3511187559053843 0.5135736140022226,0.47627627470698064 -0.08430396342936998,-0.6992830334829044 0.10642314563750581,0.01582861179138544 -1.3898218943177105,-0.7934627239856774 -2.278593042342753,0.6222928272812792 0.32837799241161814,-3.2637992691640063 1.5980171045386835,4.3766989565635654 0.11920889182865735,1.098005367807387 1.6770590197485273,-1.3513332460648206 0.3470636265188826,0.33793879086965384 1.8385374693375773,-0.12058492588591217 -0.5848476093280867,-1.6114472369623252 0.06876149732467421,1.6623882910640142 -0.24602984878279668,1.5988790672134778 -2.587764728194532,-3.1343668085501584 0.23088477729748702,-0.9595274239637085 -1.2040656070780669,-2.0171932162063158 0.9147268639102263,0.7998804786840025 -0.17599680582203872,1.9836538547339704 1.7721399220778513,-0.019612364625663996 -1.4336500134013228,-1.228266459560451 -1.0913720721973466,-3.4810752643894007 -1.0781630534294262,3.8663183483204464 -0.3634926846639631,3.9187002408397063 2.703615605266103,0.29417706661132215 -1.1428585320915923,-1.5907433907487643 0.881756446941027,0.6884426492481082 1.4168155715790605,1.819857454565582 2.069223505015872,-2.23506085887413 -0.9711770790168925,-2.9939765111888867 -0.2128157587986599,-1.3228175506950892 -2.538866868199523,-1.032781746075059 -0.8009679855239124,-2.2872993384842957 -1.678952149926298,-0.593107491171919 -0.4025645526213656,-1.9527982534741821 0.823221859739095,1.2553582024609389 -0.3763272666454619,-1.8472802889066415 -0.5038014961672489,-1.9031797516048177 1.3681178495134336,0.3458505278597183 1.6629171877601736,0.823885794362927 -0.0643107027709961,1.021161352976564 -0.9772794299638242,-0.22835066640442553 -0.25547672688570255,-0.4228264603359086 0.22644474503540898,-2.4414961438047214 0.5611525918097685,1.1037117567494923 -1.0608085350444567,0.9078512035113291 -0.40490116293313955,3.5913212693954 1.4523449821423022,-0.4523393068323611 0.05642293121149568,0.5408242066586324 -0.4783481127800394,-0.7009500215864932 0.5915169950496205,-3.4992405833392213 0.8576386802351222,-1.79641696457765 -0.6703624050033888,4.20113333631501 1.3098886403991212,-4.613284010470776 0.27962542042998173,-0.8813584486511554 -0.010943679904536196,0.9642147209617313 0.07163110600220936,-0.9443666496996307 -2.1589691812836818,-0.6694221426644025 -1.1846836200293756,0.9438215884582392 -0.44719223725641,-0.506111474564947 0.0010845938213999095,-0.5230665075088343 0.27715447423146716,0.7520032614798163 2.0356242456261113,1.5452145489298892 -1.205325000396752,1.1762148188264026 -1.3893304742459964,0.3891533267423198 0.6870051074073796,-0.6603598814330203 1.7542621382337604,-0.2013753253876956 -1.4848201494094855,2.0683214160257886 0.8829502215048612,1.8807893880157462 0.7314292062649644,-2.5152421636486455 0.20596956748780654,0.4552093301901957 -0.370214884989625,-2.5884727207175064 0.4361728968021604,2.0867353656327956 -1.4369664834455238,0.3760200100582617 -0.583258822070287,-0.41408182393966286 -0.3808262398866877,-0.7191993106534107 0.2756769389991029,-1.6379682999471787 -1.1183840181555331,1.9192770392792455 0.42736034966478564,-1.1231768171395247 -0.41884921795835633,-1.4833874481053977 -1.8910869937786714,3.8471115787021835 src/test/resources/org/freehep/util/export/test/ExportTest.ini0000644000175000017500000000210311322712200024150 0ustar user03user03EPS Test, ExportTest.eps, eps, org.freehep.graphicsio.ps.PSGraphics2D.EmbedFonts=false EPS Test type1, ExportTest-t1.eps, eps, org.freehep.graphicsio.ps.PSGraphics2D.EmbedFonts=true,org.freehep.graphicsio.ps.PSGraphics2D.EmbedFontsAs=Type1 EPS Test type3, ExportTest-t3.eps, eps, org.freehep.graphicsio.ps.PSGraphics2D.EmbedFonts=true,org.freehep.graphicsio.ps.PSGraphics2D.EmbedFontsAs=Type3 PDF Test, ExportTest.pdf, pdf, org.freehep.graphicsio.pdf.PDFGraphics2D.EmbedFonts=false PDF Test type1, ExportTest-t1.pdf, pdf, org.freehep.graphicsio.pdf.PDFGraphics2D.EmbedFonts=true,org.freehep.graphicsio.pdf.PDFGraphics2D.EmbedFontsAs=Type1 PDF Test type3, ExportTest-t3.pdf, pdf, org.freehep.graphicsio.pdf.PDFGraphics2D.EmbedFonts=true,org.freehep.graphicsio.pdf.PDFGraphics2D.EmbedFontsAs=Type3 SVG Test, ExportTest.svg, svg SWF Test, ExportTest.swf, swf EMF Test, ExportTest.emf, emf CGM Test, ExportTest.cgm, cgm PNG Test, ExportTest.png, png JPEG Test, ExportTest.jpg, jpg PPM Test, ExportTest.ppm, ppm GIF Test, ExportTest.gif, gif #PLOTML Test, ExportTest.plotml, jas.hist.SaveAsPlotMLsrc/test/java/0000755000175000017500000000000011322712200012557 5ustar user03user03src/test/java/org/0000755000175000017500000000000011322712200013346 5ustar user03user03src/test/java/org/freehep/0000755000175000017500000000000011322712200014764 5ustar user03user03src/test/java/org/freehep/util/0000755000175000017500000000000011322712200015741 5ustar user03user03src/test/java/org/freehep/util/export/0000755000175000017500000000000011322712200017262 5ustar user03user03src/test/java/org/freehep/util/export/test/0000755000175000017500000000000011322712200020241 5ustar user03user03src/test/java/org/freehep/util/export/test/ExportTest.java0000644000175000017500000000605611322712200023234 0ustar user03user03package org.freehep.util.export.test; import jas.hist.JASHist; import jas.hist.XMLHistBuilder; import java.io.BufferedReader; import java.io.File; import java.io.InputStream; import java.io.InputStreamReader; import java.util.Collection; import java.util.Properties; import java.util.StringTokenizer; import javax.swing.JFrame; import javax.swing.SwingUtilities; import javax.swing.WindowConstants; import org.freehep.util.export.ExportFileType; public class ExportTest extends JFrame implements Runnable { private JASHist plot; public ExportTest(String plotml) throws Exception { super("Export Test"); setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); InputStream in = getClass().getResourceAsStream(plotml); XMLHistBuilder xhb = new XMLHistBuilder(new InputStreamReader(in), "ExportTest.plotml"); plot = xhb.getSoloPlot(); plot.setAllowUserInteraction(false); getContentPane().add(plot); } public static void main(String[] args) throws Exception { String plotml = args.length == 0 ? "ExportTest.plotml" : args[0]; ExportTest xhv = new ExportTest(plotml); xhv.pack(); xhv.setVisible(true); Thread.sleep(500); SwingUtilities.invokeAndWait(xhv); System.exit(0); } public void run() { try { BufferedReader control = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("ExportTest.ini"))); for (;;) { String line = control.readLine(); if (line == null) break; if (line.startsWith("#")) continue; StringTokenizer st = new StringTokenizer(line, ",="); String title = st.nextToken().trim(); String file = st.nextToken().trim(); String klass = st.nextToken().trim(); Properties props = new Properties(); while (st.hasMoreTokens()) { String key = st.nextToken().trim(); if (!st.hasMoreTokens()) break; String value = st.nextToken().trim(); props.setProperty(key, value); } test(title, file, klass, props); } control.close(); } catch (Exception x) { x.printStackTrace(); } } private void test(String title, String file, String exported, Properties options) throws Exception { Collection c = ExportFileType.getExportFileTypes(exported); if ((c == null) || c.isEmpty()) { System.out.println("No driver for \"" + exported + "\" found"); } else { ExportFileType type = (ExportFileType) c.iterator().next(); File f = new File(file); System.out.println(title + " running..."); long start = System.currentTimeMillis(); type.exportToFile(f, plot, this, options, getName()); long stop = System.currentTimeMillis(); System.out.println(title + " done, time=" + (stop - start) + "ms size=" + f.length()); } } } src/test/java/org/freehep/util/export/test/ExportFileTypeTest.java0000644000175000017500000000100411322712200024662 0ustar user03user03package org.freehep.util.export.test; import java.util.Iterator; import org.freehep.util.export.ExportFileTypeRegistry; public class ExportFileTypeTest { public static void main(String[] args) { ExportFileTypeRegistry r = ExportFileTypeRegistry.getDefaultInstance(null); System.out.println("All ExportFileTypes"); Iterator providers = r.get().iterator(); while (providers.hasNext()) { System.out.println(" "+providers.next()); } } } src/main/0000755000175000017500000000000011322712201011604 5ustar user03user03src/main/resources/0000755000175000017500000000000011322712201013616 5ustar user03user03src/main/java/0000755000175000017500000000000011322712200012524 5ustar user03user03src/main/java/org/0000755000175000017500000000000011322712200013313 5ustar user03user03src/main/java/org/freehep/0000755000175000017500000000000011322712200014731 5ustar user03user03src/main/java/org/freehep/util/0000755000175000017500000000000011322712200015706 5ustar user03user03src/main/java/org/freehep/util/export/0000755000175000017500000000000011322712201017230 5ustar user03user03src/main/java/org/freehep/util/export/ExportDialog.java0000644000175000017500000002650511322712201022504 0ustar user03user03// Copyrigh 2003-2007, FreeHEP. package org.freehep.util.export; import java.awt.Component; import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import java.io.IOException; import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Properties; import java.util.Vector; import javax.swing.DefaultListCellRenderer; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JDialog; import javax.swing.JFileChooser; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.SwingConstants; import org.freehep.swing.ErrorDialog; import org.freehep.swing.layout.TableLayout; /** * An "Export" dialog for saving components as graphic files. * * @author tonyj * @version $Id: ExportDialog.java 12746 2007-06-12 22:18:45Z duns $ */ public class ExportDialog extends JOptionPane { private static final String rootKey = ExportDialog.class.getName(); private static final String SAVE_AS_TYPE = rootKey +".SaveAsType"; private static final String SAVE_AS_FILE = rootKey +".SaveAsFile"; /** * Set the Properties object to be used for storing/restoring * user preferences. If not called user preferences will not be * saved. * @param properties The Properties to use for user preferences */ public void setUserProperties(Properties properties) { props = properties; } /** * Register an export file type. */ public void addExportFileType(ExportFileType fileType) { list.addElement(fileType); } public void addAllExportFileTypes() { ExportFileTypeGroups groups = new ExportFileTypeGroups(ExportFileType.getExportFileTypes()); for (Iterator i=groups.getGroupNames().iterator(); i.hasNext(); ) { String group = (String)i.next(); List exportTypes = groups.getExportFileTypes(group); if (exportTypes.size() > 0) { list.add(new JLabel(groups.getLabel(group), SwingConstants.CENTER)); Collections.sort(exportTypes); for (Iterator j=exportTypes.iterator(); j.hasNext(); ) { addExportFileType((ExportFileType)j.next()); } } } } /** * Creates a new instance of ExportDialog with all the standard export filetypes. */ public ExportDialog() { this(null); } /** * Creates a new instance of ExportDialog with all the standard export filetypes. * @param creator The "creator" to be written into the header of the file (may be null) */ public ExportDialog(String creator) { this(creator, true); } /** * Creates a new instance of ExportDialog. * @param creator The "creator" to be written into the header of the file (may be null) * @param addAllExportFileTypes If true registers all the standard export filetypes */ public ExportDialog(String creator, boolean addAllExportFileTypes) { super(null,JOptionPane.PLAIN_MESSAGE,JOptionPane.OK_CANCEL_OPTION); this.creator = creator; try { baseDir = System.getProperty("user.home"); } catch (SecurityException x) { trusted = false; } ButtonListener bl = new ButtonListener(); JPanel panel = new JPanel(new TableLayout()); if (trusted) { panel.add("* * [5 5 5 5] w", file); panel.add("* * * 1 [5 5 5 5] wh", browse); } type = new JComboBox(list); type.setMaximumRowCount(16); // rather than 8 panel.add("* * 1 1 [5 5 5 5] w", type); panel.add("* * * 1 [5 5 5 5] wh", advanced); browse.addActionListener(bl); advanced.addActionListener(bl); type.setRenderer(new SaveAsRenderer()); type.addActionListener(bl); setMessage(panel); if (addAllExportFileTypes) addAllExportFileTypes(); } /** * Show the dialog. * @param parent The parent for the dialog * @param title The title for the dialog * @param target The component to be saved. * @param size The target size to be used for export. * @param defFile The default file name to use. */ public void showExportDialog(Component parent, String title, Component target, Dimension size, String defFile) { // NOTE: same, and used in AbstractExportFileType props.setProperty("size-w", String.valueOf(size.width)); props.setProperty("size-h", String.valueOf(size.height)); showExportDialog(parent, title, target, defFile); } /** * Show the dialog. * @param parent The parent for the dialog * @param title The title for the dialog * @param target The component to be saved. * @param defFile The default file name to use. */ public void showExportDialog(Component parent, String title, Component target, String defFile) { this.component = target; // NOTE: a label is always first if (list.size() > 0) type.setSelectedIndex(1); String dType = props.getProperty(SAVE_AS_TYPE); if (dType != null) { for (int i=0; i*/ extraTypes; private static final Collection categories = new ArrayList(2); static { categories.add(ExportFileType.class); categories.add(RegisterableService.class); } private ExportFileTypeRegistry() { service = new ServiceRegistry(categories.iterator()); extraTypes = new ArrayList(); } public static synchronized ExportFileTypeRegistry getDefaultInstance(ClassLoader loader) { if ((loader != null) && (loader != ExportFileTypeRegistry.loader)) { if (ExportFileTypeRegistry.loader != null) throw new RuntimeException(ExportFileTypeRegistry.class.getName() + ": Different classloader was already used in getDefaultInstance"); ExportFileTypeRegistry.loader = loader; } if (registry == null) { registry = new ExportFileTypeRegistry(); // NOTE: not in constructor to avoid recursive calls. If such call comes in // as a result of something on the classpath needing the registry inside // the onRegistration call. Such call would just return the already created // registry. addApplicationClasspathExportFileTypes(registry); } return registry; } /** * Returns a list of all registered ExportFileTypes in the order in which * they are found in jar files on the classpath. */ public List get() { return get(null); } /** * Returns a list of all registered ExportFileTypes in the order in which * they are found in jar files on the classpath, followed by all the extra * registered ExportFileTypes as long as they do not duplicate any * ExportFileType in the list. The list is for a particular * format, or all if format is null. */ public List/**/ get(String format) { List export = new ArrayList(); // add all ExportFileTypes found in service addExportFileTypeToList(export, format, service.getServiceProviders(ExportFileType.class, true)); // add all ExportFileTypes on extraTypes addExportFileTypeToList(export, format, extraTypes.iterator()); return export; } /** * Adds ExportFile. * * @param exportFileType */ public void add(ExportFileType exportFileType) { extraTypes.add(exportFileType); } private void addExportFileTypeToList(List list, String format, Iterator iterator) { while (iterator.hasNext()) { ExportFileType type = (ExportFileType)iterator.next(); if (format == null) { if (!list.contains(type)) { list.add(type); } } else { String[] ext = type.getExtensions(); for (int i=0; i extension.length())) { extension = acceptableExtensions[i]; } } } return extension; } /** * A utility function that checks a file's extension. */ public static boolean checkExtension(File file, String[] acceptableExtensions) { return getExtension(file, acceptableExtensions).length() > 0; } /** * Change the extension of a file if it is not of the appropriate * type. * * @deprecated use adjustExtension(File, String, String[], String) */ public static File adjustExtension(File file, String preferredExtension, String[] acceptableExtensions) { return adjustExtension(file, preferredExtension, acceptableExtensions, ""); } /** * Change the extension of a file if it is not of the appropriate * type. * @param extension ext to be removed. */ public static File adjustExtension(File file, String preferredExtension, String[] acceptableExtensions, String extension) { File returnValue = file; if (file!=null) { // Get first the filename without the extension and the // extension itself. String originalParent = file.getParent(); String originalName = file.getName(); String mainName = ""; if (originalParent!=null) { mainName = originalParent+File.separator; } if ((extension.length() > 0) && originalName.endsWith(extension)) { mainName += originalName.substring(0, originalName.length()-extension.length()-1); } else { // calculate extension as last part of name int dotIndex = originalName.lastIndexOf('.'); if(dotIndex>0 && dotIndex<(originalName.length()-1)) { mainName += originalName.substring(0,dotIndex); extension = originalName.substring(dotIndex+1); } else { mainName += originalName; extension = ""; } } // Check to see if the extension is one of the acceptable // extensions. returnValue = new File(mainName+"."+extension); // If the extension isn't an acceptable one, then change // the extension to the preferred one. if (!checkExtension(returnValue, acceptableExtensions)) returnValue = new File(mainName+"."+preferredExtension); } return returnValue; } } src/main/java/org/freehep/util/export/VectorGraphicsTransferable.java0000644000175000017500000001235611322712201025356 0ustar user03user03package org.freehep.util.export; import java.awt.Component; import java.awt.Graphics; import java.awt.Image; import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.ClipboardOwner; import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.SystemFlavorMap; import java.awt.datatransfer.Transferable; import java.awt.datatransfer.UnsupportedFlavorException; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.HashMap; import java.util.Map; /** * A Transferable for putting vector graphics onto the system clipboard. * This is particularly useful on Windows where EMF format can be used to copy * vector graphics onto the system clipboard, from where it can be pasted into * many applications, including PowerPoint and Word. VectorGraphicsTranferable * will fall back to using a bitmap image format if no suitable VectorGraphics * format is registered. *

* Note: This only works with JDK 1.4 or later. * @author tonyj * @version $Id: VectorGraphicsTransferable.java 8584 2006-08-10 23:06:37Z duns $ */ public class VectorGraphicsTransferable implements ClipboardOwner, Transferable { private Component component; private DataFlavor imageFlavor = new DataFlavor("image/x-java-image; class=java.awt.Image", "Image"); private Map types = new HashMap(); private static Map defaultTypes; /** * Create a VectorGraphicsTransferable with the built-in flavor/ExportFileType associations * @param c The Component whose graphics will be transfered */ public VectorGraphicsTransferable(Component c) { this(c,true); } /** * Create a VectorGraphicsTransferable. * @param c The Component whose graphics will be transfered * @param addDefaultAssociations Add the standard flavor/ExportFileType associations */ public VectorGraphicsTransferable(Component c, boolean addDefaultAssociations) { this.component = c; if (addDefaultAssociations) addDefaultFileTypes(); } public Object getTransferData(DataFlavor dataFlavor) throws UnsupportedFlavorException, IOException { // System.out.println(dataFlavor); if (dataFlavor.match(imageFlavor)) { Image img = component.createImage(component.getWidth(),component.getHeight()); Graphics g = img.getGraphics(); component.print(g); g.dispose(); return img; } else { ExportFileType type = (ExportFileType) types.get(dataFlavor); if (type != null) { ByteArrayOutputStream out = new ByteArrayOutputStream(); type.exportToFile(out,component,component,null,component.getName()); out.close(); return new ByteArrayInputStream(out.toByteArray()); } } throw new UnsupportedFlavorException(dataFlavor); } public DataFlavor[] getTransferDataFlavors() { DataFlavor[] result = new DataFlavor[types.size() + 1]; types.keySet().toArray(result); result[types.size()] = imageFlavor; return result; } public boolean isDataFlavorSupported(DataFlavor dataFlavor) { if (dataFlavor.match(imageFlavor)) return true; if (types.containsKey(dataFlavor)) return true; return false; } public void lostOwnership(Clipboard clipboard, Transferable transferable) { } /** * Associate a DataFlavor with the ExportFileType */ public void addExportFileType(DataFlavor flavor, ExportFileType type) { types.put(flavor,type); } private void addDefaultFileTypes() { if (defaultTypes == null) defaultTypes = createDefaultTypes(); types.putAll(defaultTypes); } private static Map createDefaultTypes() { Map result = new HashMap(); // TODO: It would make sense to check for services which implement some // interface, rather than having this hardwired here. addType(result, "ENHMETAFILE", "image/emf", "Enhanced Meta File", "org.freehep.graphicsio.emf.EMFExportFileType"); // DISABLED for now, MacOS X does not pick up PDF and or PNG // addType(result, "PDF", "application/pdf", // "Portable Document Format", // "org.freehep.graphicsio.pdf.PDFExportFileType"); // addType(result, "PNG", "application/pdf", // "Portable Network Graphics", // "org.freehep.graphicsio.png.PNGExportFileType"); return result; } private static void addType(Map result, String atom, String mimeType, String description, String className) { try { DataFlavor df = new DataFlavor(mimeType, description); SystemFlavorMap map = (SystemFlavorMap) SystemFlavorMap.getDefaultFlavorMap(); map.addUnencodedNativeForFlavor(df, atom); ClassLoader loader = Thread.currentThread().getContextClassLoader(); Class cls = loader == null ? Class.forName(className) : loader.loadClass(className); ExportFileType type = (ExportFileType) cls.newInstance(); result.put(df,type); } catch (Throwable x) { System.err.println("Unable to install flavor for mime type '"+mimeType+"' (this is expected if not using JDK 1.4)"); } } }src/main/java/org/freehep/util/export/MimeTypes.java0000644000175000017500000000366311322712201022017 0ustar user03user03// Copyright 2006, FreeHEP package org.freehep.util.export; import java.util.HashSet; import java.util.Set; /** * * @author duns * @version $Id$ */ public class MimeTypes { private static Set bitmaps; private static Set vectors; private static Set others; static { bitmaps = new HashSet(); bitmaps.add("image/bmp"); bitmaps.add("image/x-bmp"); bitmaps.add("image/gif"); bitmaps.add("image/x-gif"); bitmaps.add("image/jpeg"); bitmaps.add("image/jpeg2000"); bitmaps.add("image/jp2"); bitmaps.add("image/png"); bitmaps.add("image/portable-anymap"); bitmaps.add("image/x-portable-anymap"); bitmaps.add("image/portable-bitmap"); bitmaps.add("image/x-portable-bitmap"); bitmaps.add("image/portable-graymap"); bitmaps.add("image/x-portable-graymap"); bitmaps.add("image/portable-pixmap"); bitmaps.add("image/x-portable-pixmap"); bitmaps.add("image/tiff"); bitmaps.add("image/x-raw"); bitmaps.add("image/x-windows-bmp"); bitmaps.add("image/vnd.wap.wbmp"); vectors = new HashSet(); vectors.add("image/cgm"); vectors.add("image/x-emf"); vectors.add("image/tex"); vectors.add("application/pdf"); vectors.add("application/postscript"); vectors.add("image/svg+xml"); vectors.add("application/x-shockwave-flash"); others = new HashSet(); others.add("application/java"); } private MimeTypes() { } public static boolean isBitmap(String mimeType) { return bitmaps.contains(mimeType); } public static boolean isVector(String mimeType) { return vectors.contains(mimeType); } public static boolean isOther(String mimeType) { return others.contains(mimeType) || (!isBitmap(mimeType) && !isVector(mimeType)); } } src/main/java/org/freehep/util/export/ExportFileTypeGroups.java0000644000175000017500000000524211322712201024221 0ustar user03user03// Copyright 2006, FreeHEP. package org.freehep.util.export; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; /** * * @author duns * @version $Id$ */ public class ExportFileTypeGroups { public static final String VECTOR = "vector"; public static final String BITMAP = "bitmap"; public static final String OTHER = "other"; public static final String ALTERNATIVE = "alternative"; private List/**/ groupNames; private Map/*>*/ groups; private List/**/ alternatives; private Map/**/ labels; public ExportFileTypeGroups(List/**/ exportFileTypes) { groupNames = new ArrayList(); groupNames.add(VECTOR); groupNames.add(BITMAP); groupNames.add(OTHER); groupNames.add(ALTERNATIVE); labels = new HashMap(); labels.put(VECTOR, "Vector Formats"); labels.put(BITMAP, "Bitmap Formats"); labels.put(OTHER, "Other"); labels.put(ALTERNATIVE, "Alternative Formats"); groups = new HashMap(); alternatives = new ArrayList(); for (Iterator i = exportFileTypes.iterator(); i.hasNext(); ) { ExportFileType exportFileType = (ExportFileType)i.next(); String mimeType = exportFileType.getMIMETypes()[0]; String key; if (MimeTypes.isBitmap(mimeType)) { key = BITMAP; } else if (MimeTypes.isVector(mimeType)) { key = VECTOR; } else { key = OTHER; } Map fileTypes = (Map)groups.get(key); if (fileTypes == null) { fileTypes = new HashMap(); groups.put(key, fileTypes); } String extension = exportFileType.getExtensions()[0]; if (fileTypes.get(extension) == null) { fileTypes.put(extension, exportFileType); } else { alternatives.add(exportFileType); } } } /** * Return all registered ExportFileTypes for a certain group. */ public List getExportFileTypes(String group) { List result = new ArrayList(); if (group.equals(ALTERNATIVE)) { result.addAll(alternatives); } else { Map fileTypes = (Map)groups.get(group); if (fileTypes != null) result.addAll(fileTypes.values()); } return result; } public List getGroupNames() { return groupNames; } public String getLabel(String group) { return (String)labels.get(group); } } src/site/0000755000175000017500000000000011322712201011624 5ustar user03user03src/site/apt/0000755000175000017500000000000011322712201012410 5ustar user03user03src/site/apt/index.apt0000644000175000017500000000047011322712201014226 0ustar user03user03 --- FreeHEP Export --- --- Mark Donszelmann --- Introduction Library to register filetypes (which can be loaded as plugin modules). This library is used by {{{http://java.freehep.org/vectorgraphics}VectorGraphics}} to allow new output formats to be added by adding new jar files to the classpath. src/site/site.xml0000644000175000017500000000316211322712201013314 0ustar user03user03 FreeHEP Export http://java.freehep.org/freehep-export FreeHEP http://java.freehep.org/images/sm-freehep.gif http://java.freehep.org/