|
From: <bma...@us...> - 2011-10-07 12:17:24
|
Revision: 6489
http://fudaa.svn.sourceforge.net/fudaa/?rev=6489&view=rev
Author: bmarchan
Date: 2011-10-07 12:17:14 +0000 (Fri, 07 Oct 2011)
Log Message:
-----------
Add : Sauvegarde du projet sur un fichier .zip
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/PivProgressionPanel.java
trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/action/PivImportGRPAction.java
trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/action/PivImportGridAction.java
trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/action/PivImportTransectAction.java
trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/action/PivSelectImagesAction.java
trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/metier/PivProject.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 2011-10-07 10:33:42 UTC (rev 6488)
+++ trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/PivImplementation.java 2011-10-07 12:17:14 UTC (rev 6489)
@@ -17,7 +17,6 @@
import java.util.List;
import javax.swing.JOptionPane;
-import javax.swing.filechooser.FileFilter;
import com.memoire.bu.*;
import com.memoire.fu.FuLog;
@@ -29,7 +28,12 @@
import javax.swing.JFileChooser;
import javax.swing.SwingUtilities;
+import org.fudaa.ctulu.CtuluLibFile;
+import org.fudaa.ctulu.gui.CtuluDialog;
+import org.fudaa.ctulu.gui.CtuluFileChooser;
+import org.fudaa.ctulu.gui.CtuluFileChooserTestWritable;
import org.fudaa.ctulu.gui.CtuluLibDialog;
+import org.fudaa.ctulu.gui.CtuluTaskOperationGUI;
import org.fudaa.ebli.commun.EbliComponentFactory;
import org.fudaa.ebli.impression.EbliMiseEnPagePreferencesPanel;
import org.fudaa.fudaa.commun.impl.FudaaCommonImplementation;
@@ -40,7 +44,6 @@
import org.fudaa.fudaa.piv.action.PivComputeLaunchAction;
import org.fudaa.fudaa.piv.action.PivComputeParamAction;
import org.fudaa.fudaa.piv.action.PivFlowParamAction;
-import org.fudaa.fudaa.piv.action.PivNewTransectAction;
import org.fudaa.fudaa.piv.action.PivImportGRPAction;
import org.fudaa.fudaa.piv.action.PivImportGridAction;
import org.fudaa.fudaa.piv.action.PivImportTransectAction;
@@ -76,15 +79,18 @@
}
- /** Le dernier projet ouvert */
- private File rootPath;
+ /** Le dernier projet ouvert, null si nouveau */
+ private File prjFile;
/** Le projet en cours. */
private PivProject project;
/** Le lanceur des exe */
private PivExeLauncher exeLauncher;
/** La fenetre 2D */
private PivFille2d piv2dFrame;
+ /** Une fenetre de progression */
+ private CtuluDialog diProgress;
+
/**
* Retourne les informations de l'application pour affichage dans "a propos".
* @return Les infos.
@@ -94,75 +100,35 @@
}
/**
- * Une classe de filtrage des r\xE9pertoires projet, utilis\xE9e lors d'ouverture
+ * Un filtre des fichiers projets, utilis\xE9e lors d'ouverture
* d'un projet par boite de dialogue.
*/
- public static class PivProjFileFilter extends FileFilter {
- public boolean accept(File _f) {
- return _f != null && _f.isDirectory();
- }
-
- public String getDescription() {
- return PivResource.getS("R\xE9pertoire projet");
- }
- }
-
+ public static BuFileFilter FILE_FLT_PROJ=new BuFileFilter("lspiv.zip",PivResource.getS("Fichier projet"));
+
/**
- * Une classe de filtrage des fichiers images, utilis\xE9e lors de la selection
+ * Un filtre des fichiers images, utilis\xE9e lors de la selection
* des fichiers par boite de dialogue.
*/
- public static class PivSrcImgFileFilter extends FileFilter {
- public boolean accept(File _f) {
- return _f != null && (_f.isDirectory() || _f.getName().endsWith(".pgm"));
- }
+ public static BuFileFilter FILE_FLT_PGM=new BuFileFilter("pgm",PivResource.getS("Fichiers images en niveaux de gris"));
- public String getDescription() {
- return PivResource.getS("Fichiers images en niveaux de gris (*.pgm)");
- }
- }
-
/**
- * Une classe de filtrage des fichiers grid.dat, utilis\xE9e lors de l'import
+ * Un filtre des fichiers grid.dat, utilis\xE9e lors de l'import
* par boite de dialogue.
*/
- public static class PivGridFileFilter extends FileFilter {
- public boolean accept(File _f) {
- return _f != null && (_f.isDirectory() || _f.getName().endsWith(".dat"));
- }
+ public static BuFileFilter FILE_FLT_GRID=new BuFileFilter("dat",PivResource.getS("Fichier grid"));
- public String getDescription() {
- return PivResource.getS("Fichier grid (*.dat)");
- }
- }
-
/**
- * Une classe de filtrage des fichiers GRP.dat, utilis\xE9e lors de l'import
+ * Un filtre des fichiers GRP.dat, utilis\xE9e lors de l'import
* par boite de dialogue.
*/
- public static class PivGRPFileFilter extends FileFilter {
- public boolean accept(File _f) {
- return _f != null && (_f.isDirectory() || _f.getName().endsWith(".dat"));
- }
+ public static BuFileFilter FILE_FLT_GRP=new BuFileFilter("dat",PivResource.getS("Fichier GRP"));
- public String getDescription() {
- return PivResource.getS("Fichier GRP (*.dat)");
- }
- }
-
/**
- * Une classe de filtrage des fichiers bathy.dat, utilis\xE9e lors de l'import
+ * Un filtre des fichiers bathy.dat, utilis\xE9e lors de l'import
* par boite de dialogue.
*/
- public static class PivTransectFileFilter extends FileFilter {
- public boolean accept(File _f) {
- return _f != null && (_f.isDirectory() || _f.getName().endsWith(".dat"));
- }
+ public static BuFileFilter FILE_FLT_BATHY=new BuFileFilter("dat",PivResource.getS("Fichier bathy"));
- public String getDescription() {
- return PivResource.getS("Fichier bathy (*.dat)");
- }
- }
-
/**
* Constructeur.
*/
@@ -209,6 +175,7 @@
boolean bprjHasTransfImg=bprjOpen && project.hasTransfImages();
setEnabledForAction("ENREGISTRER", bprjMod);
+ setEnabledForAction("ENREGISTRERSOUS", bprjOpen);
setEnabledForAction("FERMER", bprjOpen);
setEnabledForAction("SELECT_IMAGES", bprjOpen);
setEnabledForAction("CREATE_GRP", bprjOpen && bprjHasOriginalImg);
@@ -248,7 +215,11 @@
public void refreshTitle() {
String title=isPIV_.name+" "+isPIV_.version;
if (project!=null) {
- title+=" "+project.getRoot();
+ title+=" - ";
+ if (prjFile==null)
+ title+=PivResource.getS("Nouveau projet");
+ else
+ title+=prjFile;
if (project.isParamsModified())
title+="*";
}
@@ -286,9 +257,9 @@
if ("OUVRIR".equals(action)) {
ouvrir(null);
} else if ("ENREGISTRER".equals(action)) {
- save();
-// } else if ("ENREGISTRERSOUS".equals(action)) {
-// saveAs();
+ save(prjFile);
+ } else if ("ENREGISTRERSOUS".equals(action)) {
+ save(null);
} else if ("FERMER".equals(action)) {
saveAndCloseProjet();
} else if ("CREER".equals(action)) {
@@ -349,37 +320,19 @@
return;
}
- JFileChooser fc = new JFileChooser(rootPath);
- fc.setFileFilter(new PivProjFileFilter());
- fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
- fc.setAcceptAllFileFilterUsed(false);
- fc.setDialogTitle(PivResource.getS("Nouveau projet"));
- if (fc.showSaveDialog(this.getFrame()) == JFileChooser.CANCEL_OPTION) {
- return;
- }
-
- rootPath = fc.getSelectedFile();
-
- // Controle que le r\xE9pertoire selectionn\xE9 n'existe pas ou est vide.
- if (rootPath.exists() && rootPath.list().length!=0) {
- error(PivResource.getS("Ce r\xE9pertoire n'est pas vide. Vous ne pouvez pas l'utiliser pour cr\xE9er un projet."));
- return;
- }
-
- if (!new File(rootPath,PivProject.OUTPUT_DIR).mkdirs()) {
+ prjFile=null;
+ project=new PivProject();
+ if (!project.init()) {
error(PivResource.getS("Probl\xE8me de cr\xE9ation du projet."));
+ project=null;
return;
}
-
- project=new PivProject();
project.addListener(this);
- project.setRoot(rootPath);
open2dFrame();
- updateRecentFiles(rootPath);
updateActionsState();
}
-
+
/**
* Pr\xE9cise que l'action "Fermer" concerne la fermeture d'un projet et
* non une fenetre interne s\xE9lectionn\xE9e.
@@ -489,71 +442,124 @@
// Choix du r\xE9pertoire
if (_f == null) {
-// FolderChooser fc = new FolderChooser();
-// fc.setSelectedFolder(rootPath);
-// fc.setDialogTitle(PivResource.getS("Ouverture d'un projet"));
-// if (fc.showOpenDialog(this.getFrame()) == FolderChooser.CANCEL_OPTION) {
-// return;
-// }
- JFileChooser fc = new JFileChooser(rootPath);
- fc.setFileFilter(new PivProjFileFilter());
- fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
+ CtuluFileChooser fc = new CtuluFileChooser(true);
+ fc.setFileFilter(FILE_FLT_PROJ);
+ fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
fc.setAcceptAllFileFilterUsed(false);
fc.setDialogTitle(PivResource.getS("Ouverture d'un projet"));
if (fc.showOpenDialog(this.getFrame()) == JFileChooser.CANCEL_OPTION) {
return;
}
- rootPath = fc.getSelectedFile();
+ prjFile = fc.getSelectedFile();
}
else {
- rootPath=_f;
+ prjFile=_f;
}
- // Controle que le r\xE9pertoire est bien un r\xE9pertoire projet.
- if (!new File(rootPath,PivProject.OUTPUT_DIR).exists()) {
- error(PivResource.getS("Le r\xE9pertoire ne semble pas \xEAtre un projet Fudaa-LSPIV\n(Pas de pr\xE9sence du r\xE9pertoire '{0}' )",PivProject.OUTPUT_DIR));
- return;
- }
-
project = new PivProject();
- project.addListener(this);
- project.setRoot(rootPath);
- project.load();
- open2dFrame();
+
+ // L'ouverture est lanc\xE9e en tache de fond.
+ CtuluTaskOperationGUI r=new CtuluTaskOperationGUI(this, PivResource.getS("Chargement du projet")) {
+ @Override
+ public void act() {
+ boolean b=true;
+ try {
+ b=project.load(prjFile, this);
+ }
+ finally {
+ final boolean b2=b;
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ diProgress.dispose();
+ if (!b2) {
+ error(PivResource.getS("Le fichier ne semble pas \xEAtre un projet Fudaa-LSPIV\n(Pas de pr\xE9sence du r\xE9pertoire '{0}' )", PivProject.OUTPUT_DIR));
+ project=null;
+ }
+ else {
+ project.addListener(PivImplementation.this);
+ open2dFrame();
+
+ updateRecentFiles(prjFile);
+ updateActionsState();
+ }
+ }
+ });
+ }
+ }
+ };
- updateActionsState();
- updateRecentFiles(project.getRoot());
-
+ PivProgressionPanel pnProgress_=new PivProgressionPanel(r,false);
+ diProgress = pnProgress_.createDialog(this.getParentComponent());
+ diProgress.setOption(CtuluDialog.ZERO_OPTION);
+ diProgress.setDefaultCloseOperation(CtuluDialog.DO_NOTHING_ON_CLOSE);
+ diProgress.setTitle(r.getName());
+
+ r.start();
+ diProgress.afficheDialogModal();
}
/**
* Sauve le projet courant sur l'emplacement choisi \xE0 sa cr\xE9ation.
+ * @param _f Le nom du fichier sur lequel sauver le projet. null, si le
+ * fichier doit etre choisi par l'utilisateur.
*/
- public void save() {
- if (isProjectModified())
- project.save();
- updateActionsState();
+ public void save(File _f) {
+ // Pas de sauvegarde si aucune modification
+ if (_f!=null && !isProjectModified()) return;
+
+ if (_f==null) {
+ CtuluFileChooser fc = new CtuluFileChooser(true);
+ fc.setTester(new CtuluFileChooserTestWritable(this));
+ fc.setFileFilter(FILE_FLT_PROJ);
+ fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
+ fc.setAcceptAllFileFilterUsed(false);
+ fc.setDialogTitle(PivResource.getS("Sauvegarde du projet"));
+ if (fc.showSaveDialog(this.getFrame()) == JFileChooser.CANCEL_OPTION) {
+ return;
+ }
+ _f=CtuluLibFile.appendExtensionIfNeeded(fc.getSelectedFile(),FILE_FLT_PROJ.getFirstExt());
+ }
+ final File f=_f;
+
+ // La sauvegarde est lanc\xE9e en tache de fond.
+ CtuluTaskOperationGUI r=new CtuluTaskOperationGUI(this, PivResource.getS("Sauvegarde du projet")) {
+ @Override
+ public void act() {
+ boolean b=true;
+ try {
+ b=project.save(f, this);
+
+ prjFile=f;
+ }
+ finally {
+ final boolean b2=b;
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ diProgress.dispose();
+ if (!b2) {
+ error(PivResource.getS("Erreur lors de la sauvegarde du fichier projet.\nIl ne sera pas sauvegard\xE9"));
+ }
+ else {
+ updateRecentFiles(prjFile);
+ updateActionsState();
+ }
+ }
+ });
+ }
+ }
+ };
+
+ PivProgressionPanel pnProgress_=new PivProgressionPanel(r,false);
+ diProgress = pnProgress_.createDialog(this.getParentComponent());
+ diProgress.setOption(CtuluDialog.ZERO_OPTION);
+ diProgress.setDefaultCloseOperation(CtuluDialog.DO_NOTHING_ON_CLOSE);
+ diProgress.setTitle(r.getName());
+
+ r.start();
+ diProgress.afficheDialogModal();
}
-// public void saveAs() {
-// final File f = chooseNewFile(true);
-// if (f == null) return;
-//
-// CtuluRunnable act = new CtuluRunnable(FudaaSaveLib.getActionSaveTitle(), this) {
-//
-// public boolean run(ProgressionInterface _proj) {
-// if (FSigProjectPersistence.saveProject(PivImplementation.this, project_, f, _proj)) {
-// updateRecentFiles(f);
-// return true;
-// }
-// return false;
-// }
-// };
-// act.setAfterRunnable(getSaveSwingRunnable(f), true);
-// act.run();
-// }
-
/**
* Teste si le projet courant a \xE9t\xE9 modifi\xE9 depius la derni\xE8re sauvegarde.
* @return True : Le projet courant a \xE9t\xE9 modifi\xE9.
@@ -576,7 +582,7 @@
return false;
}
else if (ret == JOptionPane.OK_OPTION) {
- project.save();
+ save(prjFile);
}
}
close();
Modified: trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/PivProgressionPanel.java
===================================================================
--- trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/PivProgressionPanel.java 2011-10-07 10:33:42 UTC (rev 6488)
+++ trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/PivProgressionPanel.java 2011-10-07 12:17:14 UTC (rev 6489)
@@ -30,11 +30,21 @@
BuTaskView taskView_;
/**
+ * Le constructeur, avec bouton stop actif.
+ * @param _task La tache pour laquelle visualiser la progression au travers
+ * du panneau.
+ */
+ public PivProgressionPanel(CtuluTaskOperationGUI _task) {
+ this(_task,true);
+ }
+
+ /**
* Le constructeur.
* @param _task La tache pour laquelle visualiser la progression au travers
* du panneau.
+ * @param _showStop True : Le bouton d'interruption est visible.
*/
- public PivProgressionPanel(CtuluTaskOperationGUI _task) {
+ public PivProgressionPanel(CtuluTaskOperationGUI _task, boolean _showStop) {
setLayout(new BorderLayout(5,5));
taskView_ = new BuTaskView();
@@ -47,7 +57,9 @@
});
JPanel pnButtons=new JPanel();
pnButtons.setLayout(new BorderLayout(5,5));
- pnButtons.add(btStop,BorderLayout.EAST);
+ if (_showStop) {
+ pnButtons.add(btStop,BorderLayout.EAST);
+ }
add(taskView_,BorderLayout.CENTER);
add(pnButtons,BorderLayout.SOUTH);
Modified: trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/action/PivImportGRPAction.java
===================================================================
--- trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/action/PivImportGRPAction.java 2011-10-07 10:33:42 UTC (rev 6488)
+++ trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/action/PivImportGRPAction.java 2011-10-07 12:17:14 UTC (rev 6489)
@@ -45,6 +45,7 @@
* d'import.
* @param _e L'evenement pour l'action.
*/
+ @Override
public void actionPerformed(final ActionEvent _e) {
if (!isValide()) {
return;
@@ -54,7 +55,7 @@
if (fcGRP==null)
fcGRP = new JFileChooser();
fcGRP.setAcceptAllFileFilterUsed(true);
- fcGRP.setFileFilter(new PivImplementation.PivGRPFileFilter());
+ fcGRP.setFileFilter(PivImplementation.FILE_FLT_GRP);
fcGRP.setMultiSelectionEnabled(false);
fcGRP.setDialogTitle(PivResource.getS("S\xE9lection d'un fichier GRP"));
if (fcGRP.showOpenDialog(impl.getFrame()) == JFileChooser.CANCEL_OPTION) {
@@ -82,6 +83,7 @@
return true;
}
+ @Override
public String getEnableCondition() {
return PivResource.getS("Il doit exister au moins une image reconditionn\xE9e");
}
Modified: trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/action/PivImportGridAction.java
===================================================================
--- trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/action/PivImportGridAction.java 2011-10-07 10:33:42 UTC (rev 6488)
+++ trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/action/PivImportGridAction.java 2011-10-07 12:17:14 UTC (rev 6489)
@@ -46,6 +46,7 @@
* combiner les nouveaux points.
* @param _e L'evenement pour l'action.
*/
+ @Override
public void actionPerformed(final ActionEvent _e) {
if (!isValide()) {
return;
@@ -62,7 +63,7 @@
if (fcGrid==null)
fcGrid = new JFileChooser();
fcGrid.setAcceptAllFileFilterUsed(true);
- fcGrid.setFileFilter(new PivImplementation.PivGridFileFilter());
+ fcGrid.setFileFilter(PivImplementation.FILE_FLT_GRID);
fcGrid.setMultiSelectionEnabled(false);
fcGrid.setDialogTitle(PivResource.getS("S\xE9lection d'un fichier de grille"));
if (fcGrid.showOpenDialog(impl.getFrame()) == JFileChooser.CANCEL_OPTION) {
@@ -93,6 +94,7 @@
return true;
}
+ @Override
public String getEnableCondition() {
return PivResource.getS("Il doit exister au moins une image transform\xE9e");
}
Modified: trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/action/PivImportTransectAction.java
===================================================================
--- trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/action/PivImportTransectAction.java 2011-10-07 10:33:42 UTC (rev 6488)
+++ trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/action/PivImportTransectAction.java 2011-10-07 12:17:14 UTC (rev 6489)
@@ -38,6 +38,7 @@
* d'import.
* @param _e L'evenement pour l'action.
*/
+ @Override
public void actionPerformed(final ActionEvent _e) {
if (!isValide()) {
return;
@@ -47,7 +48,7 @@
if (fcTransect==null)
fcTransect = new JFileChooser();
fcTransect.setAcceptAllFileFilterUsed(true);
- fcTransect.setFileFilter(new PivImplementation.PivTransectFileFilter());
+ fcTransect.setFileFilter(PivImplementation.FILE_FLT_BATHY);
fcTransect.setMultiSelectionEnabled(false);
fcTransect.setDialogTitle(PivResource.getS("S\xE9lection d'un fichier transect"));
if (fcTransect.showOpenDialog(impl.getFrame()) == JFileChooser.CANCEL_OPTION) {
@@ -75,6 +76,7 @@
return true;
}
+ @Override
public String getEnableCondition() {
return PivResource.getS("Il doit exister au moins une image transform\xE9e");
}
Modified: trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/action/PivSelectImagesAction.java
===================================================================
--- trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/action/PivSelectImagesAction.java 2011-10-07 10:33:42 UTC (rev 6488)
+++ trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/action/PivSelectImagesAction.java 2011-10-07 12:17:14 UTC (rev 6489)
@@ -52,6 +52,7 @@
* Selectionne les images, pour les reconditionne dans un thread s\xE9par\xE9.
* @param _e L'evenement pour l'action.
*/
+ @Override
public void actionPerformed(final ActionEvent _e) {
if (!isValide()) {
return;
@@ -73,7 +74,7 @@
// Selection des images
if (fcImages==null)
fcImages = new JFileChooser();
- fcImages.setFileFilter(new PivImplementation.PivSrcImgFileFilter());
+ fcImages.setFileFilter(PivImplementation.FILE_FLT_PGM);
fcImages.setMultiSelectionEnabled(true);
fcImages.setAcceptAllFileFilterUsed(false);
fcImages.setDialogTitle(PivResource.getS("S\xE9lection des images sources"));
@@ -85,6 +86,7 @@
// La tache a ex\xE9cuter.
CtuluTaskOperationGUI r=new CtuluTaskOperationGUI(impl, PivResource.getS("Reconditionnement des images")) {
+ @Override
public void act() {
try {
CtuluAnalyze ana=new CtuluAnalyze();
@@ -145,6 +147,7 @@
return true;
}
+ @Override
public String getEnableCondition() {
return PivResource.getS("Le projet doit \xEAtre cr\xE9\xE9");
}
Modified: trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/metier/PivProject.java
===================================================================
--- trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/metier/PivProject.java 2011-10-07 10:33:42 UTC (rev 6488)
+++ trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/metier/PivProject.java 2011-10-07 12:17:14 UTC (rev 6489)
@@ -8,13 +8,16 @@
import java.io.IOException;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.zip.ZipFile;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;
import org.fudaa.ctulu.CtuluIOOperationSynthese;
import org.fudaa.ctulu.CtuluLibFile;
+import org.fudaa.ctulu.ProgressionInterface;
import org.fudaa.ctulu.fileformat.FileReadOperationAbstract;
import org.fudaa.ctulu.fileformat.FileWriteOperationAbstract;
+import org.fudaa.fudaa.piv.PivResource;
import org.fudaa.fudaa.piv.io.PivAverageVelFileFormat;
import org.fudaa.fudaa.piv.io.PivGRPFileFormat;
import org.fudaa.fudaa.piv.io.PivGridFileFormat;
@@ -42,7 +45,7 @@
/** Le r\xE9pertoire des vitesses brutes */
public static final String VEL_RAW_DIR="vel_raw";
- /** Le r\xE9pertoire localisation du projet. */
+ /** Le r\xE9pertoire temporaire du projet. */
protected File rootPath;
/** Les points GRP */
protected PivOrthoPoint[] orthoPoints;
@@ -83,7 +86,25 @@
ImageInputStream cacheRealInputStream_;
/**
- * Retourne la racine du projet.
+ * Cree l'espace temporaire de stockage des fichiers
+ * @return True si l'espace a pu \xEAtre cr\xE9\xE9. False sinon.
+ */
+ public boolean init() {
+ boolean bcreate=false;
+ try {
+ rootPath=CtuluLibFile.createTempDir();
+ rootPath.deleteOnExit();
+ File outdir=new File(rootPath,PivProject.OUTPUT_DIR);
+ outdir.deleteOnExit();
+ bcreate=outdir.mkdirs();
+ }
+ catch (IOException ex) {}
+
+ return bcreate;
+ }
+
+ /**
+ * Retourne la racine de l'espace temporaire du projet.
* @return La racine du projet.
*/
public File getRoot() {
@@ -91,14 +112,6 @@
}
/**
- * Definit la racine du projet.
- * @param _root La racine du projet.
- */
- public void setRoot(File _root) {
- rootPath=_root;
- }
-
- /**
* Le projet contient-il au moins une image reconditionn\xE9e ?
* @return true si le projet contient au moins 1 image reconditionn\xE9e.
*/
@@ -403,12 +416,43 @@
cacheTransfInputStream_=null;
}
catch (IOException ex) {}
+
+ // Supprime aussi le repertoire temporaire
+ CtuluLibFile.deleteDir(rootPath);
}
/**
- * Charge le projet depuis les fichiers projets.
+ * Charge le projet depuis le fichier projet donn\xE9. Le fichier projet est
+ * d\xE9zipp\xE9, puis il est charg\xE9 s'il est conforme.
+ *
+ * @param _prjFile Le fichier contenant le projet.
+ * @param _prog L'interface de progression. Peut etre <tt>null</tt>
+ * @return True Si le fichier donn\xE9 est bien un fichier projet.
*/
- public void load() {
+ public boolean load(File _prjFile, ProgressionInterface _prog) {
+ if (_prog!=null)
+ _prog.setDesc(PivResource.getS("Chargement du projet"));
+
+ // Controle que le fichier archive est bien un fichier PIV.
+ try {
+ ZipFile zf=new ZipFile(_prjFile);
+ if (zf.getEntry(OUTPUT_DIR)==null) return false;
+ zf.close();
+ }
+ catch (IOException ex) {
+ return false;
+ }
+
+ // Cr\xE9ation du r\xE9pertoire temporaire de travail pour le unzip.
+ init();
+ // Unzip
+ try {
+ CtuluLibFile.unzip(_prjFile, rootPath, _prog);
+ }
+ catch (IOException ex) {
+ return false;
+ }
+
File outputDir=new File(rootPath,OUTPUT_DIR);
// Le fichier GRP
@@ -552,14 +596,23 @@
FuLog.trace("*** Fin du chargement ***");
isModified=false;
+
+ return true;
}
/**
- * Sauve le projet sur les fichiers projets.
+ * Sauve le projet sur le fichier projet. Les infos sont sauv\xE9es sur le
+ * r\xE9pertoire temporaire, puis zip\xE9es.
+ * @param _prjFile Le fichier de sauvegarde.
+ * @param _prog L'interface de progression. Peut etre <tt>null</tt>
+ * @return True si le projet a bien \xE9t\xE9 sauv\xE9.
*/
- public void save() {
+ public boolean save(File _prjFile, ProgressionInterface _prog) {
File outputDir=new File(rootPath,OUTPUT_DIR);
+ if (_prog!=null)
+ _prog.setDesc(PivResource.getS("Sauvegarde du projet"));
+
// Le fichier GRP
if (orthoPoints!=null) {
File grpFile=new File(outputDir,"GRP.dat");
@@ -607,8 +660,15 @@
FileWriteOperationAbstract writer=PivBathyFileFormat.getInstance().createWriter();
CtuluIOOperationSynthese ret=writer.write(transect, transectFile, null);
}
+ try {
+ CtuluLibFile.zip(rootPath, _prjFile, _prog);
+ }
+ catch (IOException ex) {
+ return false;
+ }
isModified=false;
+ return true;
}
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|