r330 - in trunk: coser-business/src/main/java/fr/ifremer/coser coser-business/src/main/java/fr/ifremer/coser/control coser-business/src/main/java/fr/ifremer/coser/services coser-business/src/main/java/fr/ifremer/coser/util coser-business/src/test/java/fr/ifremer/coser/services coser-ui/src/main/java/fr/ifremer/coser/ui coser-ui/src/main/java/fr/ifremer/coser/ui/control coser-ui/src/main/java/fr/ifremer/coser/ui/project coser-ui/src/main/java/fr/ifremer/coser/ui/util
Author: chatellier Date: 2010-12-02 10:34:35 +0000 (Thu, 02 Dec 2010) New Revision: 330 Log: Rend les barres de progression indenpendant de l'utilsation. Ajout de la progression pour la creation d'un projet. Added: trunk/coser-business/src/main/java/fr/ifremer/coser/util/ trunk/coser-business/src/main/java/fr/ifremer/coser/util/ProgressMonitor.java trunk/coser-business/src/main/java/fr/ifremer/coser/util/ProgressReader.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/util/CoserProgressBar.java Removed: trunk/coser-business/src/main/java/fr/ifremer/coser/control/ProgressMonitor.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlProgressBar.java Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/services/ControlService.java trunk/coser-business/src/main/java/fr/ifremer/coser/services/ImportService.java trunk/coser-business/src/main/java/fr/ifremer/coser/services/ProjectService.java trunk/coser-business/src/test/java/fr/ifremer/coser/services/CoserTestAbstract.java trunk/coser-business/src/test/java/fr/ifremer/coser/services/ImportServiceTest.java trunk/coser-business/src/test/java/fr/ifremer/coser/services/ProjectServiceTest.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/CoserFrameHandler.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlHandler.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlView.jaxx trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/project/ProjectCreationView.jaxx Deleted: trunk/coser-business/src/main/java/fr/ifremer/coser/control/ProgressMonitor.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/control/ProgressMonitor.java 2010-12-01 17:33:19 UTC (rev 329) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/control/ProgressMonitor.java 2010-12-02 10:34:35 UTC (rev 330) @@ -1,50 +0,0 @@ -/* - * #%L - * - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2010 Ifremer, Codelutin, Chatellier Eric - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -package fr.ifremer.coser.control; - -/** - * Progress monitor. - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - */ -public interface ProgressMonitor { - - void setStepCount(int stepCount); - - void setStep(int step); - - void nextStep(); - - void setCurrent(int current); - - void setTotal(int total); - - void setText(String text); -} Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/services/ControlService.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/services/ControlService.java 2010-12-01 17:33:19 UTC (rev 329) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/services/ControlService.java 2010-12-02 10:34:35 UTC (rev 330) @@ -65,13 +65,13 @@ import fr.ifremer.coser.bean.Project; import fr.ifremer.coser.control.ControlError; import fr.ifremer.coser.control.DiffCatchLengthControlError; -import fr.ifremer.coser.control.ProgressMonitor; import fr.ifremer.coser.data.AbstractDataEntity; import fr.ifremer.coser.data.Catch; import fr.ifremer.coser.data.Haul; import fr.ifremer.coser.data.Length; import fr.ifremer.coser.data.Strata; import fr.ifremer.coser.storage.DataStorage; +import fr.ifremer.coser.util.ProgressMonitor; /** * Validation service. Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/services/ImportService.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/services/ImportService.java 2010-12-01 17:33:19 UTC (rev 329) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/services/ImportService.java 2010-12-02 10:34:35 UTC (rev 330) @@ -59,6 +59,8 @@ import fr.ifremer.coser.data.Strata; import fr.ifremer.coser.storage.DataStorage; import fr.ifremer.coser.storage.MemoryDataStorage; +import fr.ifremer.coser.util.ProgressMonitor; +import fr.ifremer.coser.util.ProgressReader; /** * File import/export service. @@ -83,12 +85,40 @@ * @param project project * @param category category * @param file file to load + * @return project + * @throws CoserBusinessException + */ + public DataStorage loadCSVFile(Project project, Category category, File file) throws CoserBusinessException { + return loadCSVFile(project, category, file, null); + } + + /** + * Load file as csv. Check and affect data in project depending on category type. + * + * @param project project + * @param category category + * @param file file to load + * @param progress progress monitor (can be null) + * @return project + * @throws CoserBusinessException + */ + public DataStorage loadCSVFile(Project project, Category category, File file, ProgressMonitor progress) throws CoserBusinessException { + return loadCSVFile(project, category, file, null, false); + } + + /** + * Load file as csv. Check and affect data in project depending on category type. + * + * @param project project + * @param category category + * @param file file to load + * @param progress progress monitor (can be null) * @param originalLoading dans le cas d'un reload, la colonne "line" est a prendre en compte * pour les data (elle est absente dans les jeux de données originaux) * @return project * @throws CoserBusinessException */ - public DataStorage loadCSVFile(Project project, Category category, File file, boolean originalLoading) throws CoserBusinessException { + public DataStorage loadCSVFile(Project project, Category category, File file, ProgressMonitor progress, boolean originalLoading) throws CoserBusinessException { DataStorage content = new MemoryDataStorage(); @@ -97,6 +127,9 @@ try { reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), CoserConstants.CSV_FILE_ENCODING)); + if (progress != null) { + reader = new ProgressReader(reader, progress); + } csvReader = new CSVReader(reader, CoserConstants.CSV_SEPARATOR_CHAR); // check header @@ -128,8 +161,6 @@ content.add(line); } } - } catch (FileNotFoundException ex) { - throw new CoserBusinessException("Can't read file", ex); } catch (IOException ex) { throw new CoserBusinessException("Can't read file", ex); } Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/services/ProjectService.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/services/ProjectService.java 2010-12-01 17:33:19 UTC (rev 329) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/services/ProjectService.java 2010-12-02 10:34:35 UTC (rev 330) @@ -82,6 +82,7 @@ import fr.ifremer.coser.data.Length; import fr.ifremer.coser.data.Strata; import fr.ifremer.coser.storage.DataStorage; +import fr.ifremer.coser.util.ProgressMonitor; /** * Service business method relative to project. @@ -136,10 +137,11 @@ * * @param project project to create * @param categoriesAndFiles additional files to load + * @param progress progress monitor (can be null) * @return project with filled data * @throws CoserBusinessException if project can't be created */ - public Project createProject(Project project, Map<Category, File> categoriesAndFiles) throws CoserBusinessException { + public Project createProject(Project project, Map<Category, File> categoriesAndFiles, ProgressMonitor progress) throws CoserBusinessException { File projectsDirectory = config.getProjectsDirectory(); if (!projectsDirectory.isDirectory()) { projectsDirectory.mkdirs(); @@ -155,6 +157,16 @@ // first free memory, clear all data project.clearData(); + // get number of total byte to read + if (progress != null) { + progress.setCurrent(0); + int total = 0; + for (Map.Entry<Category, File> categoryAndFile : categoriesAndFiles.entrySet()) { + total += categoryAndFile.getValue().length(); + } + progress.setTotal(total); + } + Control control = new Control(); // load each files @@ -169,7 +181,7 @@ throw new CoserBusinessException(_("Can't read file %s for category %s", dataFile.getAbsolutePath(), _(category.getTranslationKey()))); } - DataStorage dataStorage = importService.loadCSVFile(project, category, dataFile, true); + DataStorage dataStorage = importService.loadCSVFile(project, category, dataFile, progress, true); addProjectContent(project, control, category, dataStorage, false); // init empty deleted collection @@ -319,7 +331,7 @@ category.getStorageFileName()); if (inputFile.isFile()) { - DataStorage dataStorage = importService.loadCSVFile(project, category, inputFile, false); + DataStorage dataStorage = importService.loadCSVFile(project, category, inputFile); addProjectContent(project, null, category, dataStorage, false); } else { @@ -492,7 +504,7 @@ File inputFile = new File(controlDirectory, storageFileName); if (inputFile.isFile()) { - DataStorage dataStorage = importService.loadCSVFile(project, category, inputFile, false); + DataStorage dataStorage = importService.loadCSVFile(project, category, inputFile); addProjectContent(project, control, category, dataStorage, false); fileLoaded++; } @@ -507,7 +519,7 @@ inputFile = new File(controlDirectory, storageFileName); DataStorage dataStorage = null; if (inputFile.isFile()) { - dataStorage = importService.loadCSVFile(project, category, inputFile, false); + dataStorage = importService.loadCSVFile(project, category, inputFile); } else { dataStorage = importService.getEmptyStorage(project, category); @@ -530,7 +542,7 @@ // main data if (storageDataFile.isFile()) { - DataStorage dataStorage = importService.loadCSVFile(project, category, storageDataFile, true); + DataStorage dataStorage = importService.loadCSVFile(project, category, storageDataFile, null, true); addProjectContent(project, control, category, dataStorage, false); } else { @@ -605,7 +617,7 @@ File inputFile = new File(selectionDirectory, storageFileName); if (inputFile.isFile()) { - DataStorage dataStorage = importService.loadCSVFile(project, category, inputFile, false); + DataStorage dataStorage = importService.loadCSVFile(project, category, inputFile); addProjectContent(project, selection, category, dataStorage, false); fileLoaded++; } Copied: trunk/coser-business/src/main/java/fr/ifremer/coser/util/ProgressMonitor.java (from rev 320, trunk/coser-business/src/main/java/fr/ifremer/coser/control/ProgressMonitor.java) =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/util/ProgressMonitor.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/util/ProgressMonitor.java 2010-12-02 10:34:35 UTC (rev 330) @@ -0,0 +1,52 @@ +/* + * #%L + * + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2010 Ifremer, Codelutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +package fr.ifremer.coser.util; + +/** + * Progress monitor. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public interface ProgressMonitor { + + void setStepCount(int stepCount); + + void setStep(int step); + + void nextStep(); + + void setCurrent(int current); + + void addCurrent(int addition); + + void setTotal(int total); + + void setText(String text); +} Added: trunk/coser-business/src/main/java/fr/ifremer/coser/util/ProgressReader.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/util/ProgressReader.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/util/ProgressReader.java 2010-12-02 10:34:35 UTC (rev 330) @@ -0,0 +1,72 @@ +/* + * #%L + * + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2010 Codelutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +package fr.ifremer.coser.util; + +import java.io.IOException; +import java.io.Reader; + +/** + * Reader that notify read progression. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class ProgressReader extends Reader { + + public Reader delegateReader; + + public ProgressMonitor delegateProgress; + + public ProgressReader(Reader delegateReader, ProgressMonitor delegateProgress) { + super(); + this.delegateReader = delegateReader; + this.delegateProgress = delegateProgress; + } + + /* + * @see java.io.Reader#read(char[], int, int) + */ + @Override + public int read(char[] cbuf, int off, int len) throws IOException { + + int nb = delegateReader.read(cbuf, off, len); + if (nb >= 0) { + delegateProgress.addCurrent(nb); + } + return nb; + } + + /* + * @see java.io.Reader#close() + */ + @Override + public void close() throws IOException { + delegateReader.close(); + } +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/util/ProgressReader.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Modified: trunk/coser-business/src/test/java/fr/ifremer/coser/services/CoserTestAbstract.java =================================================================== --- trunk/coser-business/src/test/java/fr/ifremer/coser/services/CoserTestAbstract.java 2010-12-01 17:33:19 UTC (rev 329) +++ trunk/coser-business/src/test/java/fr/ifremer/coser/services/CoserTestAbstract.java 2010-12-02 10:34:35 UTC (rev 330) @@ -128,7 +128,7 @@ project.setHaulFileName(testHaul.getName()); project.setStrataFileName(testStrata.getName()); - project = projectService.createProject(project, categoriesAndFile); + project = projectService.createProject(project, categoriesAndFile, null); project = projectService.loadControlData(project); // sans la sauvegarde des données de control, on ne pas creer de Modified: trunk/coser-business/src/test/java/fr/ifremer/coser/services/ImportServiceTest.java =================================================================== --- trunk/coser-business/src/test/java/fr/ifremer/coser/services/ImportServiceTest.java 2010-12-01 17:33:19 UTC (rev 329) +++ trunk/coser-business/src/test/java/fr/ifremer/coser/services/ImportServiceTest.java 2010-12-02 10:34:35 UTC (rev 330) @@ -59,7 +59,7 @@ URL url = ImportServiceTest.class.getResource("/csv/badformat/capturesbadseparator.csv"); File file = new File(url.getFile()); - service.loadCSVFile(p, Category.CATCH, file, true); + service.loadCSVFile(p, Category.CATCH, file, null, true); } @Test(expected=CoserBusinessException.class) @@ -68,7 +68,7 @@ URL url = ImportServiceTest.class.getResource("/csv/badformat/stratesheadername.csv"); File file = new File(url.getFile()); - service.loadCSVFile(p, Category.STRATA, file, true); + service.loadCSVFile(p, Category.STRATA, file, null, true); } @Test(expected=CoserBusinessException.class) @@ -77,6 +77,6 @@ URL url = ImportServiceTest.class.getResource("/csv/badformat/traitsheaderorder.csv"); File file = new File(url.getFile()); - service.loadCSVFile(p, Category.HAUL, file, true); + service.loadCSVFile(p, Category.HAUL, file, null, true); } } Modified: trunk/coser-business/src/test/java/fr/ifremer/coser/services/ProjectServiceTest.java =================================================================== --- trunk/coser-business/src/test/java/fr/ifremer/coser/services/ProjectServiceTest.java 2010-12-01 17:33:19 UTC (rev 329) +++ trunk/coser-business/src/test/java/fr/ifremer/coser/services/ProjectServiceTest.java 2010-12-02 10:34:35 UTC (rev 330) @@ -78,7 +78,7 @@ public void testDuplicatedProject() throws CoserBusinessException { Project p = new Project(); p.setName("project2"); // il existe deja dans src/test/resources - projectService.createProject(p, new HashMap<CoserConstants.Category, File>()); + projectService.createProject(p, new HashMap<CoserConstants.Category, File>(), null); } /** Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/CoserFrameHandler.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/CoserFrameHandler.java 2010-12-01 17:33:19 UTC (rev 329) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/CoserFrameHandler.java 2010-12-02 10:34:35 UTC (rev 330) @@ -296,7 +296,7 @@ ProjectService projectService = projectView.getContextValue(ProjectService.class); Project resultProject = null; try { - resultProject = projectService.createProject(project, fileToLoad); + resultProject = projectService.createProject(project, fileToLoad, projectView.getLoadProgressBar()); } catch (CoserBusinessException ex) { if (log.isErrorEnabled()) { log.error("Can't create project", ex); Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlHandler.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlHandler.java 2010-12-01 17:33:19 UTC (rev 329) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlHandler.java 2010-12-02 10:34:35 UTC (rev 330) @@ -87,6 +87,7 @@ import fr.ifremer.coser.services.ControlService; import fr.ifremer.coser.services.ProjectService; import fr.ifremer.coser.services.PublicationService; +import fr.ifremer.coser.ui.util.CoserProgressBar; /** * Control handler for control view. @@ -372,7 +373,7 @@ final ControlService validationService = view.getContextValue(ControlService.class); final Project project = view.getContextValue(Project.class); //final Category category = (Category)view.getCategoryComboBox().getSelectedItem(); - final ControlProgressBar progressBar = view.getCheckProgressBar(); + final CoserProgressBar progressBar = view.getCheckProgressBar(); SwingWorker<List<ControlError>, Void> task = new SwingWorker<List<ControlError>, Void>() { Deleted: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlProgressBar.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlProgressBar.java 2010-12-01 17:33:19 UTC (rev 329) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlProgressBar.java 2010-12-02 10:34:35 UTC (rev 330) @@ -1,93 +0,0 @@ -/* - * #%L - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2010 Codelutin, Chatellier Eric - * %% - * This program 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 3 of the - * License, or (at your option) any later version. - * - * This program 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, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package fr.ifremer.coser.ui.control; - -import static org.nuiton.i18n.I18n._; - -import javax.swing.JProgressBar; -import fr.ifremer.coser.control.ProgressMonitor; - -/** - * Control progress bar. - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - */ -public class ControlProgressBar extends JProgressBar implements ProgressMonitor { - - /** serialVersionUID. */ - private static final long serialVersionUID = 3383288562693714316L; - - protected int stepCount; - - protected int step; - - /* - * @see fr.ifremer.coser.control.ProgressMonitor#setStepCount(int) - */ - @Override - public void setStepCount(int stepCount) { - this.stepCount = stepCount; - } - - /* - * @see fr.ifremer.coser.control.ProgressMonitor#setStep(int) - */ - @Override - public void setStep(int step) { - this.step = step; - } - - /* - * @see fr.ifremer.coser.control.ProgressMonitor#nextStep() - */ - @Override - public void nextStep() { - step++; - } - - /* - * @see fr.ifremer.coser.control.ProgressMonitor#setCurrent(double) - */ - @Override - public void setCurrent(int current) { - setValue(current); - } - - /* - * @see fr.ifremer.coser.control.ProgressMonitor#setTotal(double) - */ - @Override - public void setTotal(int total) { - setMaximum(total); - } - - @Override - public void setText(String text) { - setString(_("coser.ui.control.progressStep", step +1, stepCount, text)); - } -} Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlView.jaxx =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlView.jaxx 2010-12-01 17:33:19 UTC (rev 329) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlView.jaxx 2010-12-02 10:34:35 UTC (rev 330) @@ -178,7 +178,7 @@ </row> <row> <cell anchor="center" weightx="1" fill="horizontal" columns="2"> - <ControlProgressBar id="checkProgressBar" stringPainted="true" /> + <fr.ifremer.coser.ui.util.CoserProgressBar id="checkProgressBar" stringPainted="true" /> </cell> </row> </Table> Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/project/ProjectCreationView.jaxx =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/project/ProjectCreationView.jaxx 2010-12-01 17:33:19 UTC (rev 329) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/project/ProjectCreationView.jaxx 2010-12-02 10:34:35 UTC (rev 330) @@ -193,6 +193,11 @@ onActionPerformed="getHandler().createProject(this)" /> </cell> </row> + <row> + <cell columns="4" fill="horizontal"> + <fr.ifremer.coser.ui.util.CoserProgressBar id="loadProgressBar" stringPainted="true" /> + </cell> + </row> </Table> </cell> </row> Copied: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/util/CoserProgressBar.java (from rev 320, trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlProgressBar.java) =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/util/CoserProgressBar.java (rev 0) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/util/CoserProgressBar.java 2010-12-02 10:34:35 UTC (rev 330) @@ -0,0 +1,109 @@ +/* + * #%L + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2010 Codelutin, Chatellier Eric + * %% + * This program 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 3 of the + * License, or (at your option) any later version. + * + * This program 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, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +package fr.ifremer.coser.ui.util; + +import static org.nuiton.i18n.I18n._; + +import javax.swing.JProgressBar; + +import fr.ifremer.coser.util.ProgressMonitor; + +/** + * Control progress bar. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class CoserProgressBar extends JProgressBar implements ProgressMonitor { + + /** serialVersionUID. */ + private static final long serialVersionUID = 3383288562693714316L; + + /** Default to 1 (= no step). */ + protected int stepCount = 1; + + protected int step; + + /* + * @see fr.ifremer.coser.control.ProgressMonitor#setStepCount(int) + */ + @Override + public void setStepCount(int stepCount) { + this.stepCount = stepCount; + } + + /* + * @see fr.ifremer.coser.control.ProgressMonitor#setStep(int) + */ + @Override + public void setStep(int step) { + this.step = step; + } + + /* + * @see fr.ifremer.coser.control.ProgressMonitor#nextStep() + */ + @Override + public void nextStep() { + step++; + } + + /* + * @see fr.ifremer.coser.control.ProgressMonitor#setCurrent(double) + */ + @Override + public void setCurrent(int current) { + setValue(current); + } + + /* + * @see fr.ifremer.coser.control.ProgressMonitor#setTotal(double) + */ + @Override + public void setTotal(int total) { + setMaximum(total); + } + + @Override + public void setText(String text) { + if (stepCount <= 1) { + setString(text); + } else { + setString(_("coser.ui.control.progressStep", step +1, stepCount, text)); + } + } + + /* + * @see fr.ifremer.coser.util.ProgressMonitor#addCurrent(int) + */ + @Override + public void addCurrent(int addition) { + int current = getValue(); + current += addition; + setValue(current); + } +}
participants (1)
-
chatellier@users.labs.libre-entreprise.org