001: /*
002: * ============================================================================
003: * GNU Lesser General Public License
004: * ============================================================================
005: *
006: * JasperReports - Free Java report-generating library.
007: * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
022: *
023: * JasperSoft Corporation
024: * 303 Second Street, Suite 450 North
025: * San Francisco, CA 94107
026: * http://www.jaspersoft.com
027: */
028: package net.sf.jasperreports.view.save;
029:
030: import java.io.File;
031: import java.text.MessageFormat;
032:
033: import javax.swing.JOptionPane;
034:
035: import net.sf.jasperreports.engine.JRException;
036: import net.sf.jasperreports.engine.JasperPrint;
037: import net.sf.jasperreports.engine.util.JRSaver;
038: import net.sf.jasperreports.view.JRSaveContributor;
039:
040: /**
041: * @author Teodor Danciu (teodord@users.sourceforge.net)
042: * @version $Id: JRPrintSaveContributor.java 1229 2006-04-19 10:27:35Z teodord $
043: */
044: public class JRPrintSaveContributor extends JRSaveContributor {
045:
046: /**
047: *
048: */
049: private static final String EXTENSION_JRPRINT = ".jrprint";
050: public static final JRPrintSaveContributor INSTANCE = new JRPrintSaveContributor();
051:
052: /**
053: *
054: */
055: public static JRPrintSaveContributor getInstance() {
056: return INSTANCE;
057: }
058:
059: /**
060: *
061: */
062: public boolean accept(File file) {
063: if (file.isDirectory()) {
064: return true;
065: }
066: return file.getName().toLowerCase().endsWith(EXTENSION_JRPRINT);
067: }
068:
069: /**
070: *
071: */
072: public String getDescription() {
073: return "JasperReports (*.jrprint)";
074: }
075:
076: /**
077: *
078: */
079: public void save(JasperPrint jasperPrint, File file)
080: throws JRException {
081: if (!file.getName().endsWith(EXTENSION_JRPRINT)) {
082: file = new File(file.getAbsolutePath() + EXTENSION_JRPRINT);
083: }
084:
085: if (!file.exists()
086: || JOptionPane.OK_OPTION == JOptionPane
087: .showConfirmDialog(
088: null,
089: MessageFormat
090: .format(
091: java.util.ResourceBundle
092: .getBundle(
093: "net/sf/jasperreports/view/viewer")
094: .getString(
095: "file.exists"),
096: new Object[] { file
097: .getName() }),
098: java.util.ResourceBundle
099: .getBundle(
100: "net/sf/jasperreports/view/viewer")
101: .getString("save"),
102: JOptionPane.OK_CANCEL_OPTION)) {
103: JRSaver.saveObject(jasperPrint, file);
104: }
105: }
106:
107: }
|