From: <had...@us...> - 2008-10-01 16:17:06
|
Revision: 4018 http://fudaa.svn.sourceforge.net/fudaa/?rev=4018&view=rev Author: hadouxad Date: 2008-10-01 16:16:50 +0000 (Wed, 01 Oct 2008) Log Message: ----------- commit partiel Added Paths: ----------- branches/Prepro-0.92-SNAPSHOT/fudaa/src/org/fudaa/fudaa/commun/courbe/FudaaCourbeWizardImportScope.java Copied: branches/Prepro-0.92-SNAPSHOT/fudaa/src/org/fudaa/fudaa/commun/courbe/FudaaCourbeWizardImportScope.java (from rev 4017, branches/Prepro-0.92-SNAPSHOT/fudaa/src/org/fudaa/fudaa/commun/courbe/FudaaGrapheWizardImportScope.java) =================================================================== --- branches/Prepro-0.92-SNAPSHOT/fudaa/src/org/fudaa/fudaa/commun/courbe/FudaaCourbeWizardImportScope.java (rev 0) +++ branches/Prepro-0.92-SNAPSHOT/fudaa/src/org/fudaa/fudaa/commun/courbe/FudaaCourbeWizardImportScope.java 2008-10-01 16:16:50 UTC (rev 4018) @@ -0,0 +1,434 @@ +package org.fudaa.fudaa.commun.courbe; + +import java.awt.BorderLayout; +import java.awt.FlowLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; + +import javax.swing.AbstractAction; +import javax.swing.BorderFactory; +import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.filechooser.FileFilter; + +import org.fudaa.ctulu.CtuluCommandManager; +import org.fudaa.ctulu.CtuluIOOperationSynthese; +import org.fudaa.ctulu.CtuluLib; +import org.fudaa.ctulu.CtuluLibArray; +import org.fudaa.ctulu.ProgressionInterface; +import org.fudaa.ctulu.fileformat.FileFormat; +import org.fudaa.ctulu.fileformat.FileFormatUnique; +import org.fudaa.ctulu.gui.CtuluFileChooser; +import org.fudaa.ctulu.gui.CtuluLibSwing; +import org.fudaa.ctulu.gui.CtuluTaskOperationGUI; +import org.fudaa.dodico.mesure.EvolutionFileFormat; +import org.fudaa.dodico.reflux.io.CLTransitoireFileFormat; +import org.fudaa.dodico.reflux.io.CrbFileFormat; +import org.fudaa.dodico.rubar.io.RubarCLIFileFormat; +import org.fudaa.dodico.rubar.io.RubarTARFileFormat; +import org.fudaa.dodico.telemac.io.ScopeGENEFileFormat; +import org.fudaa.dodico.telemac.io.ScopeSFileFormat; +import org.fudaa.dodico.telemac.io.ScopeStructure; +import org.fudaa.dodico.telemac.io.ScopeTFileFormat; +import org.fudaa.dodico.telemac.io.TelemacLiquideFileFormat; +import org.fudaa.ebli.commun.EbliActionSimple; +import org.fudaa.ebli.courbe.EGGraphe; +import org.fudaa.fudaa.commun.FudaaLib; +import org.fudaa.fudaa.commun.courbe.FudaaCourbeImporter; +import org.fudaa.fudaa.commun.courbe.FudaaCourbeImporterScope; +import org.fudaa.fudaa.commun.impl.FudaaCommonImplementation; +import org.fudaa.fudaa.commun.impl.FudaaGuiLib; +import org.fudaa.fudaa.tr.common.TrResource; + +import com.memoire.bu.BuButton; +import com.memoire.bu.BuButtonPanel; +import com.memoire.bu.BuCharValidator; +import com.memoire.bu.BuFileFilter; +import com.memoire.bu.BuResource; +import com.memoire.bu.BuStringValidator; +import com.memoire.bu.BuTextField; +import com.memoire.bu.BuValueValidator; +import com.memoire.bu.BuWizardDialog; +import com.memoire.bu.BuWizardTask; + +/** + * Wizard qui se charge d'importer des courbes au format scope dans le post. + * + * Pour personnaliser le format final du graphe et son affichage, il faut surcharger la methode + * createGraphImported() + * @author Adrien Hadoux + * + */ +public class FudaaCourbeWizardImportScope extends BuWizardTask { + + //donnees haut niveau + FudaaCommonImplementation impl_; + + /** + * type de fomat: + * 0 => scops + * 1 =>scopT + * 2=>scopgene + */ + int typeFormat_; + File fileChoosen_=null; + ScopeStructure data_; + EGGraphe result_; + + //choix du fichier + JPanel panelFichier_; + BuTextField filePath_; + + //choix parametres s t ou gene + JPanel panelParametres_; + + //choix donnees S et T + BuTextField plageDeb_=new BuTextField(5); + BuTextField plageFin_=new BuTextField(5); + JList listVariables_; + + + public static class ImportAction extends EbliActionSimple { + final FudaaCommonImplementation ui_; + public ImportAction(final FudaaCommonImplementation _ui) { + super(BuResource.BU.getString("Importer au format scope"), BuResource.BU.getIcon("IMPORTER"), "IMPORTER"); + ui_ = _ui; + } + public void actionPerformed(final ActionEvent _e) { + FudaaCourbeWizardImportScope wizard=new FudaaCourbeWizardImportScope(ui_); + BuWizardDialog DialogWizard = new BuWizardDialog(ui_.getFrame(), wizard); + // --affichage du wizard --// + DialogWizard.setSize(600, 500); + DialogWizard.setLocationRelativeTo(ui_.getFrame()); + DialogWizard.setVisible(true); + } + } + + + public FudaaCourbeWizardImportScope(FudaaCommonImplementation impl) { + super(); + + impl_=impl; + } + + + @Override + public JComponent getStepComponent() { + switch (current_) { + case 0: { + + if(panelFichier_==null) + panelFichier_=buildFilePanel(); + return panelFichier_; + } + case 1: { + + if(data_==null){ + return new JLabel(TrResource.getS("Erreur. Veuillez choisir un fichier valide")); + } + + if(panelParametres_==null) + panelParametres_=buildPanelParametresImportation(); + return panelParametres_; + } + + } + + return null; + } + + @Override + public int getStepCount() { + // TODO Auto-generated method stub + return 2; + } + + @Override + public String getStepText() { + // TODO Auto-generated method stub + return null; + } + + ScopeStructure.SorT dataST(){ + return (ScopeStructure.SorT)data_; + } + + ScopeStructure.Gene dataG(){ + return (ScopeStructure.Gene)data_; + } + + @Override + public String getStepTitle() { + String r = null; + + switch (current_) { + case 0: + r = TrResource.getS("Choisir le fichier"); + break; + case 1: + r = TrResource.getS("Param\xE8tres de cr\xE9ation"); + break; + + } + return r; + } + + /** + * construit le panel de selection du fichier + * @return + */ + JPanel buildFilePanel(){ + JPanel content=new JPanel(new FlowLayout(FlowLayout.CENTER)); + content.add(new JLabel(TrResource.getS("Choisir le fichier:"))); + filePath_=new BuTextField(20); + filePath_.setEnabled(false); + content.add(filePath_); + BuButton parcourir =new BuButton(TrResource.getS("Parcourir...")); + parcourir.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent arg0) { + final FileFormat[] ft = getFileFormatForImport(); + Arrays.sort(ft); + final BuFileFilter[] filters = FileFormat.createFilters(ft); + final CtuluFileChooser fileChooser = FudaaGuiLib.getFileChooser(BuResource.BU.getString("Importer"), filters, + null); + fileChooser.setAcceptAllFileFilterUsed(false); + for (int i = filters.length - 1; i >= 0; i--) { + if (ft[i].getID() == EvolutionFileFormat.getInstance().getID()) { + fileChooser.setFileFilter(filters[i]); + break; + } + } + final File initFile = FudaaGuiLib.chooseFile(CtuluLibSwing.getFrameAncestor(impl_.getParentComponent()), true,fileChooser); + if (initFile == null) { + return; + } + filePath_.setText(initFile.getAbsolutePath()); + + final FileFilter filter = fileChooser.getFileFilter(); + final int i = CtuluLibArray.getIndex(filter, filters); + if (i < 0) { + return; + } + typeFormat_=i; + fileChoosen_=initFile; + importData(); + + + + } + + }); + content.add(parcourir); + return content; + } + + /** + * Retourne les formats de fichiers disponibles + * @return + */ + public static FileFormat[] getFileFormatForImport() { + final ArrayList<FileFormatUnique> r = new ArrayList<FileFormatUnique>(10); + r.add(ScopeSFileFormat.getInstance()); + r.add(ScopeTFileFormat.getInstance()); + r.add(ScopeGENEFileFormat.getInstance()); + final FileFormat[] rf = new FileFormat[r.size()]; + r.toArray(rf); + return rf; + } + + + /** + * Methode iumportante d'importation des datas en fonction du fichier choisi et du type. + * Remplit la structure scope + */ + private void importData(){ + new CtuluTaskOperationGUI(impl_, FudaaLib.getS("Importation graphe")) { + public void act() { + final ProgressionInterface prog = getMainStateReceiver(); + + switch(typeFormat_){ + case 0: + //cas s + data_=lectureScopeS(fileChoosen_,prog); + break; + case 1: + //cas scopT + data_=lectureScopeT(fileChoosen_,prog); + break; + case 2: + //cas scopGENE + data_=lectureScopeGENE(fileChoosen_,prog); + break; + } + + }}.start(); + + } + + private ScopeStructure.SorT lectureScopeS(final File _f,ProgressionInterface prog) { + final CtuluIOOperationSynthese op = ScopeSFileFormat.getInstance().getLastVersionInstance(null).read(_f, prog); + final ScopeStructure.SorT struct = (ScopeStructure.SorT) op.getSource(); + return struct; + } + private ScopeStructure.SorT lectureScopeT(final File _f,ProgressionInterface prog) { + final CtuluIOOperationSynthese op = ScopeTFileFormat.getInstance().getLastVersionInstance(null).read(_f, prog); + final ScopeStructure.SorT struct = (ScopeStructure.SorT) op.getSource(); + return struct; + } + private ScopeStructure.Gene lectureScopeGENE(final File _f,ProgressionInterface prog) { + final CtuluIOOperationSynthese op = ScopeGENEFileFormat.getInstance().getLastVersionInstance(null).read(_f, prog); + final ScopeStructure.Gene struct = (ScopeStructure.Gene) op.getSource(); + return struct; + } + + + /** + * Construit le panel de choix des donn\xE9es a importer pour les formats s et t + * @return + */ + double Xmin,Xmax; + JPanel buildPanelScopeSorT(){ + JPanel content=new JPanel(new BorderLayout()); + + String[] listeVar=new String[dataST().getNbVariables()-1]; + + //on ne prends pas les x + for(int i=1;i<dataST().getNbVariables();i++) + listeVar[i-1]=dataST().getVariable(i); + + listVariables_=new JList(listeVar); + listVariables_.setSelectedIndex(0); + content.add(listVariables_,BorderLayout.CENTER); + listVariables_.setBorder(BorderFactory.createTitledBorder(TrResource.getS("S\xE9lection des variables"))); + + plageDeb_.setCharValidator(BuCharValidator.FLOAT); + plageDeb_.setStringValidator(BuStringValidator.FLOAT); + plageDeb_.setValueValidator(BuValueValidator.FLOAT); + plageFin_.setCharValidator(BuCharValidator.FLOAT); + plageFin_.setStringValidator(BuStringValidator.FLOAT); + plageFin_.setValueValidator(BuValueValidator.FLOAT); + + //-- on init les plages --// + Xmin=dataST().getXMin(); + plageDeb_.setText(""+Xmin); + Xmax=dataST().getXMax(); + plageFin_.setText(""+Xmax); + + JPanel plages=new JPanel(new FlowLayout(FlowLayout.CENTER)); + plages.add(new JLabel(TrResource.getS("Choisir la plage des abscisses"))); + plages.add(plageDeb_); + plages.add(new JLabel("-")); + plages.add(plageFin_); + plages.add(new JLabel("(Min: "+Xmin+", Max: "+Xmax+")")); + content.add(plages,BorderLayout.SOUTH); + + return content; + } + + JPanel buildPanelScopeGENE(){ + return null; + } + + JPanel buildPanelParametresImportation(){ + switch(typeFormat_){ + case 0: + //cas s + return buildPanelScopeSorT(); + case 1: + //cas scopT + return buildPanelScopeSorT(); + case 2: + //cas scopGENE + return buildPanelScopeGENE(); + } + + return null; + } + + public String getTaskTitle() { + // TODO Auto-generated method stub + return TrResource.getS("Importation depuis les formats Scop S, T et GENE"); + } + + /** + * MEthode utilisee pour disabler ou non les boutons suivants + */ + public int getStepDisabledButtons() { + int r = super.getStepDisabledButtons(); + if (current_ == 1) { + + //cas scope s ou t + if(typeFormat_==1 || typeFormat_==0){ + if(data_==null) + r |= BuButtonPanel.TERMINER; + else + if(plageDeb_.getText().equals("") || plageFin_.getText().equals("")) + r |= BuButtonPanel.TERMINER; + else{ + //verifier que les plages ne sont pas depassees + double valDeb=Double.parseDouble(plageDeb_.getText()); + double valFin=Double.parseDouble(plageFin_.getText()); + if(valDeb<Xmin || Xmax<valFin) + r |= BuButtonPanel.TERMINER; + } + + }else{ + //cas scope gene + } + + } + return r; + } + + + public void doTask() { + done_ = true; + new CtuluTaskOperationGUI(impl_, FudaaLib.getS("Importation graphe")) { + public void act() { + final ProgressionInterface prog = getMainStateReceiver(); + //mise a jour de la structure + impl_.setMainProgression(10); + impl_.setMainMessage(CtuluLib.getS("Structure modification")); + prog.setProgression(10); + prog.setDesc(CtuluLib.getS("Structure modification")); + if(typeFormat_<=1) + dataST().restreindreStructure(listVariables_.getSelectedIndices(),Double.parseDouble(plageDeb_.getText()),Double.parseDouble(plageFin_.getText())); + + + impl_.setMainProgression(30); + impl_.setMainMessage(CtuluLib.getS("Cr\xE9ation du graphe")); + // creation du graphe + switch(typeFormat_){ + case 0: + //cas s + result_=FudaaCourbeImporterScope.createGrapheSpatialGraphe(dataST(),prog);break; + case 1: + //cas scopT + result_=FudaaCourbeImporterScope.createGrapheTemporel(dataST(),prog);break; + case 2: + //cas scopGENE + result_=FudaaCourbeImporterScope.createGrapheTemporelGENE(dataG(),prog);break; + } + + //-- mise en forme du resultata g\xE9n\xE9r\xE9 --// + createGraphImported(result_); + } + }.start(); + } + + + /** + * Methode a surcharger. + * Appel\xE9e a la toute fin, gere le resultat + */ + public void createGraphImported(EGGraphe grapheGenere){ + //placer le graphe ou vous voulez... + } + +} Property changes on: branches/Prepro-0.92-SNAPSHOT/fudaa/src/org/fudaa/fudaa/commun/courbe/FudaaCourbeWizardImportScope.java ___________________________________________________________________ Added: svn:mergeinfo + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |