From: <bma...@us...> - 2017-01-10 10:28:50
|
Revision: 9504 http://sourceforge.net/p/fudaa/svn/9504 Author: bmarchan Date: 2017-01-10 10:28:48 +0000 (Tue, 10 Jan 2017) Log Message: ----------- Nom par defaut de rapport de jaugeage Modified Paths: -------------- trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/PivImplementation.java trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/action/PivExportGaugingReportAction.java Modified: trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/PivImplementation.java =================================================================== --- trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/PivImplementation.java 2017-01-09 19:45:47 UTC (rev 9503) +++ trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/PivImplementation.java 2017-01-10 10:28:48 UTC (rev 9504) @@ -155,6 +155,17 @@ public File getCurrentProjectFile() { return prjFile; } + + /** + * @return Le nom par default pour la sauvegarde. Si le nom courant est null, renvoie un nom par defaut. + */ + public File getSavedProjectFile() { + if (getCurrentProjectFile()==null) + return new File("fudaa-lspiv.lspiv.zip"); + else { + return getCurrentProjectFile(); + } + } /** * Appel\xE9e quand le projet courant est modifi\xE9. Modified: trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/action/PivExportGaugingReportAction.java =================================================================== --- trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/action/PivExportGaugingReportAction.java 2017-01-09 19:45:47 UTC (rev 9503) +++ trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/action/PivExportGaugingReportAction.java 2017-01-10 10:28:48 UTC (rev 9504) @@ -12,6 +12,7 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.text.DecimalFormat; @@ -38,6 +39,7 @@ import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.fudaa.ctulu.CtuluLib; +import org.fudaa.ctulu.CtuluLibFile; import org.fudaa.ctulu.CtuluLibImage; import org.fudaa.ctulu.CtuluLog; import org.fudaa.ctulu.gui.CtuluFileChooser; @@ -56,6 +58,7 @@ import org.fudaa.fudaa.piv.metier.PivGlobalFlowResults; import org.fudaa.fudaa.piv.metier.PivOrthoParameters; import org.fudaa.fudaa.piv.metier.PivOrthoPoint; +import org.fudaa.fudaa.piv.metier.PivProject; import org.fudaa.fudaa.piv.metier.PivResultsI.ResultType; import org.fudaa.fudaa.piv.metier.PivTransect; @@ -127,6 +130,8 @@ CtuluFileChooser fcReport_; /** Les variables users (inconnues du systeme) du modele Excel. */ HashMap<String,UserCellData> userVars=new HashMap<>(); + /** Le nom fichier projet pour changer le nom du rapport. */ + File projectFile_; /** * Constructeur. @@ -314,25 +319,45 @@ sheet.enableLocking(); } - if (fcReport_ == null) { - fcReport_=new CtuluFileChooser(true); - fcReport_.setTester(new CtuluFileChooserTestWritable(impl)); - fcReport_.setAcceptAllFileFilterUsed(true); - fcReport_.setFileFilter(PivUtils.FILE_FLT_XLSX); - fcReport_.setMultiSelectionEnabled(false); - fcReport_.setDialogTitle(PivResource.getS("Ficher Excel d'export")); - } - if (fcReport_.showSaveDialog(impl.getFrame()) == JFileChooser.CANCEL_OPTION) { - return; - } - - wb.write(new FileOutputStream(fcReport_.getSelectedFile())); + saveReport(wb); } catch (Exception e) { e.printStackTrace(); } } + + /** + * Sauve le rapport sur le fichier selectionn\xE9. + * @param wb + * @throws IOException + */ + protected void saveReport(Workbook wb) throws IOException { + + if (fcReport_ == null) { + fcReport_=new CtuluFileChooser(true); + fcReport_.setTester(new CtuluFileChooserTestWritable(impl)); + fcReport_.setAcceptAllFileFilterUsed(true); + fcReport_.setFileFilter(PivUtils.FILE_FLT_XLSX); + fcReport_.setMultiSelectionEnabled(false); + fcReport_.setDialogTitle(PivResource.getS("Ficher Excel d'export")); + } + // Changement de projet => On change le nom du rapport + if (!impl.getSavedProjectFile().equals(projectFile_)) { + projectFile_=impl.getSavedProjectFile(); + + String fsave=projectFile_.getName(); + fsave=fsave.substring(0, fsave.indexOf(PivUtils.FILE_FLT_PROJ.getFirstExt()) - 1); + fcReport_.setSelectedFile(new File(fsave + "_" + PivResource.getS("rapport") + ".xlsx")); + } + + if (fcReport_.showSaveDialog(impl.getFrame()) == JFileChooser.CANCEL_OPTION) { + return; + } + + wb.write(new FileOutputStream(fcReport_.getSelectedFile())); + } + /** * Calcule les donn\xE9es non stock\xE9es dans le projet, necessaires \xE0 la r\xE9alisation du template. */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |