/*
* 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.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.util.ResourceBundle;
import java.util.Vector;
import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.KeyStroke;
/*[svg]
import japlot.jaxodraw.SVG.JaxoExportSVG;
import japlot.jaxodraw.SVG.JaxoPreviewSVG;
[/svg]*/
/** The parent class for exporting: brings up a dialog to choose
* the export format and executes the corresponding actions.
*/
public class JaxoExportPanel {
//private static final String SEPARATOR = "SEPARATOR";
/** An integer specifying the LaTeX - EPS mode. */
public static final int LATEX_EPS = 0;
/** An integer specifying the LaTeX (text) mode. */
public static final int LATEX = 1;
/** An integer specifying the postscript portrait mode. */
public static final int PS_PORTRAIT = 2;
/** An integer specifying the postscript landscape mode. */
public static final int PS_LANDSCAPE = 3;
/** An integer specifying the postscript EPS mode. */
public static final int PS_EPS = 4;
/** An integer specifying the JPG export mode. */
public static final int JPG = 5;
/** An integer specifying the PNG export mode. */
public static final int PNG = 6;
/** An integer specifying the SVG export mode. */
public static final int SVG = 7;
private JaxoGraph graph;
private Dimension canvasD;
private String currentTab = "";
private JDialog dialog;
private JComboBox chooseFileFormat;
/*[svg]
private boolean includeSVG = true;
[/svg]*/
private ResourceBundle language =
ResourceBundle.getBundle(JaxoPrefs.getPref(JaxoPrefs.PREF_LANGUAGE));
/** Sets the currentTab property.
* @param newTab The name of the current tab.
*/
public final void setCurrentTab(String newTab) {
this.currentTab = newTab;
}
/** Brings a dialog to choose the export format.
* @param newGraph The graph to be exported.
* @param d The current dimension of the canvas.
*/
public final void export(JaxoGraph newGraph, Dimension d) {
this.graph = newGraph;
this.canvasD = d;
/*[svg]
try {
Class.forName("org.apache.batik.svggen.SVGGraphics2D");
} catch (ClassNotFoundException e) {
includeSVG = false;
}
[/svg]*/
Vector fileFormats = new Vector();
fileFormats.addElement("LaTeX -> EPS");
fileFormats.addElement("LaTeX");
//fileFormats.addElement(SEPARATOR); // does not work with keys
fileFormats.addElement("PS Portrait");
fileFormats.addElement("PS Landscape");
fileFormats.addElement("EPS");
fileFormats.addElement("JPG");
fileFormats.addElement("PNG");
/*[svg]
if (includeSVG) { // NOTE: SVG always has to be last in the list,
fileFormats.addElement("SVG"); // otherwise we mess up indices
}
[/svg]*/
chooseFileFormat = new JComboBox(fileFormats);
chooseFileFormat.setSelectedIndex(LATEX_EPS);
JButton previewButton = new JButton(language.getString("Preview"));
previewButton.setToolTipText(language.getString(
"Open_a_preview_window"));
previewButton.addActionListener(new ActionListener() {
public final void actionPerformed(ActionEvent e) {
preview(chooseFileFormat.getSelectedIndex());
}
});
JLabel label =
new JLabel(language.getString(
"Please_choose_an_export_file_format:"));
JPanel prevButtonPanel = new JPanel();
prevButtonPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
prevButtonPanel.add(previewButton);
JPanel comboBoxPanel = new JPanel();
comboBoxPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
comboBoxPanel.add(chooseFileFormat);
JPanel tempPanel = new JPanel(false);
tempPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
tempPanel.add(comboBoxPanel);
tempPanel.add(prevButtonPanel);
JButton exportButton = new JButton(language.getString("Export"));
exportButton.addActionListener(new ActionListener() {
public final void actionPerformed(ActionEvent e) {
exportButtonClicked();
}
});
JButton cancelButton = new JButton(language.getString("Cancel"));
cancelButton.addActionListener(new ActionListener() {
public final void actionPerformed(ActionEvent e) {
cancelButtonClicked();
}
});
JPanel buttonPanel = new JPanel(false);
buttonPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
buttonPanel.add(exportButton);
buttonPanel.add(cancelButton);
JPanel optionsPanel = new JPanel(false);
optionsPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
optionsPanel.setLayout(new BorderLayout());
optionsPanel.add(label, BorderLayout.NORTH);
optionsPanel.add(tempPanel, BorderLayout.CENTER);
optionsPanel.add(buttonPanel, BorderLayout.SOUTH);
optionsPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke
.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "pressed");
optionsPanel.getActionMap().put("pressed",
new AbstractAction() {
public final void actionPerformed(ActionEvent e) {
cancelButtonClicked();
}
});
dialog = new JDialog();
dialog.getContentPane().add(optionsPanel);
dialog.setSize(new Dimension(400, 200));
dialog.setTitle(language.getString("Export"));
dialog.setLocationRelativeTo(null);
dialog.setVisible(true);
}
private void exportButtonClicked() {
int ff = chooseFileFormat.getSelectedIndex();
switch (ff) {
case LATEX:
JaxoExportLatex exp = new JaxoExportLatex();
exp.setCurrentTab(currentTab);
exp.setMode(LATEX);
exp.export(graph);
break;
case LATEX_EPS:
JaxoExportLatexPS lps = new JaxoExportLatexPS();
lps.setCurrentTab(currentTab);
lps.setMode(LATEX_EPS);
lps.export(graph);
break;
case PS_PORTRAIT:
JaxoExportPS psPortrait = new JaxoExportPS();
psPortrait.setCurrentTab(currentTab);
psPortrait.setMode(PS_PORTRAIT);
psPortrait.setCanvasD(canvasD);
psPortrait.export(graph);
break;
case PS_LANDSCAPE:
JaxoExportPS psLandscape = new JaxoExportPS();
psLandscape.setCurrentTab(currentTab);
psLandscape.setMode(PS_LANDSCAPE);
psLandscape.setCanvasD(canvasD);
psLandscape.export(graph);
break;
case PS_EPS:
JaxoExportPS eps = new JaxoExportPS();
eps.setCurrentTab(currentTab);
eps.setMode(PS_EPS);
eps.setCanvasD(canvasD);
eps.export(graph);
break;
case JPG:
JaxoExportImg imgJPG = new JaxoExportImg();
imgJPG.setCurrentTab(currentTab);
imgJPG.setMode(JPG);
imgJPG.setCanvasD(canvasD);
imgJPG.export(graph);
break;
case PNG:
JaxoExportImg imgPNG = new JaxoExportImg();
imgPNG.setCurrentTab(currentTab);
imgPNG.setMode(PNG);
imgPNG.setCanvasD(canvasD);
imgPNG.export(graph);
break;
/*[svg]
case SVG:
if (includeSVG) {
JaxoExportSVG imgSVG = new JaxoExportSVG();
imgSVG.setCurrentTab(currentTab);
imgSVG.setMode(SVG);
imgSVG.export(graph);
}
break;
[/svg]*/
default:
break;
}
dialog.dispose();
}
private void cancelButtonClicked() {
dialog.dispose();
}
/** Called for previewing the export result.
* @param i Parameter indicating the export format that is being previewed.
*/
public final void preview(int i) {
switch (i) {
case LATEX:
JaxoPreview preLatex = new JaxoPreview();
preLatex.previewLatex(graph);
break;
case LATEX_EPS:
JaxoPreview preLatexPS = new JaxoPreview();
preLatexPS.previewLatexPS(graph, canvasD, false);
break;
case PS_PORTRAIT:
JaxoPreview prePortrait = new JaxoPreview();
prePortrait.previewPS(graph, canvasD, PS_PORTRAIT);
break;
case PS_LANDSCAPE:
JaxoPreview preLandscape = new JaxoPreview();
preLandscape.previewPS(graph, canvasD, PS_LANDSCAPE);
break;
case PS_EPS:
JaxoPreview preEPS = new JaxoPreview();
preEPS.previewEPS(graph, canvasD);
break;
case JPG:
JaxoPreview preJPG = new JaxoPreview();
preJPG.previewIMG(graph, canvasD);
break;
case PNG:
JaxoPreview prePNG = new JaxoPreview();
prePNG.previewIMG(graph, canvasD);
break;
/*[svg]
case SVG:
if (includeSVG) {
JaxoPreviewSVG preSVG = new JaxoPreviewSVG();
preSVG.previewSVG(graph);
}
break;
[/svg]*/
default:
break;
}
}
}
Ads help maintain this website.