/*

 * Title: japlot.jaxodraw
 * Description: Graphical user interface for drawing Feynman diagrams
 * @author Daniele Binosi 
 * @author Lukas Theussl  

 Copyright (C) 2003-2006,  Daniele Binosi and Lukas Theussl

 See the file LICENSE in the source distribution home directory
 for a full copy of the GPL (GNU General Public License).

    This file is part of japlot.jaxodraw.

    japlot.jaxodraw is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    japlot.jaxodraw is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA


 */
package japlot.jaxodraw;

import java.io.File;

import java.util.ResourceBundle;

import javax.swing.JOptionPane;


/** An abstract superclass for all exporting classes. */
public abstract class JaxoExport {
    private static final String[] SUFFICES =
    {"eps", "tex", "ps", "ps", "eps", "jpg", "png", "svg"};
    private static final String[] DESCRIPTION =
    {
        "Encapsulated_Postscript_file_(*.eps)", "LaTex_file_(*.tex)",
        "Postscript_file_(*.ps)", "Postscript_file_(*.ps)",
        "Encapsulated_Postscript_file_(*.eps)", "JPG_Image_file_(*.jpg)",
        "PNG_Image_file_(*.png)", "Scalable_Vector_Graphics_file_(*.svg)"
    };
    private ResourceBundle language =
        ResourceBundle.getBundle(JaxoPrefs.getPref(JaxoPrefs.PREF_LANGUAGE));
    private JaxoGraph graph;
    private String currentTab = "";
    private int mode;
    public   static String ExportFile=null;

    /** Sets the currentTab property.
     * @param newTab The name of the current tab.
     */
    public final void setCurrentTab(String newTab) {
        this.currentTab = newTab;
    }

    
    public void setExportFile(String exportFile) {
		ExportFile = exportFile;
	}
    
    public String getExportFile() {
		return ExportFile;
	}
    
    
    /** Sets the export mode.
     * @param newMode The new export mode (as defined in JaxoExportPanel).
     */
    public final void setMode(int newMode) {
        this.mode = newMode;
    }

    /** Returns the current export mode.
     * @return The current export mode (as defined in JaxoExportPanel).
     */
    public final int getMode() {
        return mode;
    }

    /** Sets the graph to export.
     * @param newGraph The graph to export.
     */
    public final void setGraph(JaxoGraph newGraph) {
        this.graph = newGraph;
    }

    /** Returns the current graph to export.
     * @return The graph to export.
     */
    public final JaxoGraph getGraph() {
        return graph;
    }

    /** Brings up a file chooser dialog to determine the file for exporting.
     * @return The chosen export file name
     */
    public final String getExportFileName() {
       
    	
    	// this is only in case if export file was set via script
    	if (ExportFile != null ) {
    		
    		return ExportFile;
    	}
    	
    	String suffix = SUFFICES[mode];

        String describe = language.getString(DESCRIPTION[mode]);
        String[] suff = {suffix};
        JaxoChooseFile c = new JaxoChooseFile();
        String exportFileName =
            c.chooseFile(suff, language.getString("Export"), describe,
                currentTab);

        if (exportFileName.trim().length() > 0) {
            if (!exportFileName.trim().endsWith("." + suffix)) {
                exportFileName = exportFileName.trim() + "." + suffix;
            }

            File testfile = new File(exportFileName);

            if (testfile.exists()) { // Check if file exists
                String s1 = language.getString("Overwrite");
                String s2 = language.getString("Cancel");
                Object[] options = {s1, s2};
                int n =
                    JOptionPane.showOptionDialog(null,
                        exportFileName + " "
                        + language.getString("_exists!_Overwrite?"),
                        language.getString("Overwrite_Confirmation"),
                        JOptionPane.YES_NO_OPTION,
                        JOptionPane.QUESTION_MESSAGE, null, options, s1);

                if (n != JOptionPane.YES_OPTION) {
                    exportFileName = "";
                }
            }
        } else {
            exportFileName = "";
        }

        return exportFileName;
    }

    /** Checks if there are LatexText objects present in the current graph,
     * and if yes, displays a warning message.
     */
    public final void checkforLatexText() {
        if (graph.containsLatexText()) {
            Object[] message =
            {
                language.getString(
                    "There_are_LaTeX_text_objects_in_this_graph."),
                language.getString("They_will_not_be_exported_to_this_format!")
            };

            JOptionPane.showMessageDialog(null, message,
                language.getString("Warning"), JOptionPane.WARNING_MESSAGE);
        }
    }

    /** Checks if there are PSText objects present in the current graph,
     * and if yes, displays a warning message.
     */
    public final void checkforPSText() {
        if (graph.containsPSText()) {
            Object[] message =
            {
                language.getString(
                    "There_are_Postscript_text_objects_in_this_graph."),
                language.getString("They_will_not_be_exported_to_LaTeX!")
            };

            JOptionPane.showMessageDialog(null, message,
                language.getString("Warning"), JOptionPane.WARNING_MESSAGE);
        }
    }

    /** Exports a JaxoGraph to some file format.
     * @param aGraph The graph to export.
     */
    public abstract void export(JaxoGraph aGraph);
}

 

Ads help maintain this website.