source: extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/ui/mainframe/thread/ThreadPhotoSending.java @ 9921

Last change on this file since 9921 was 9921, checked in by mlg, 13 years ago

Adds spring for the dependency injection
Deletion of jdom (not useful just for a class that manipulates a simple XML file)

File size: 4.5 KB
Line 
1package fr.mael.jiwigo.ui.mainframe.thread;
2
3import java.io.File;
4
5import javax.swing.JOptionPane;
6
7import fr.mael.jiwigo.transverse.ImagesManagement;
8import fr.mael.jiwigo.transverse.enumeration.PreferencesEnum;
9import fr.mael.jiwigo.transverse.exception.FileAlreadyExistsException;
10import fr.mael.jiwigo.transverse.exception.WrongChunkSizeException;
11import fr.mael.jiwigo.transverse.util.Messages;
12import fr.mael.jiwigo.transverse.util.preferences.PreferencesManagement;
13import fr.mael.jiwigo.transverse.util.spring.SpringUtils;
14import fr.mael.jiwigo.ui.mainframe.MainFrame;
15import fr.mael.jiwigo.ui.mainframe.ThumbnailCategoryPanel;
16
17/**
18   Copyright (c) 2010, Mael
19   All rights reserved.
20
21   Redistribution and use in source and binary forms, with or without
22   modification, are permitted provided that the following conditions are met:
23    * Redistributions of source code must retain the above copyright
24      notice, this list of conditions and the following disclaimer.
25    * Redistributions in binary form must reproduce the above copyright
26      notice, this list of conditions and the following disclaimer in the
27      documentation and/or other materials provided with the distribution.
28    * Neither the name of jiwigo nor the
29      names of its contributors may be used to endorse or promote products
30      derived from this software without specific prior written permission.
31
32   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
33   ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
34   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
35   DISCLAIMED. IN NO EVENT SHALL Mael BE LIABLE FOR ANY
36   DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
37   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
38   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
39   ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
40   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
41   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 * @author mael
43 * Thread that send the photos
44 */
45public class ThreadPhotoSending implements Runnable {
46    private File[] files;
47    private ThumbnailCategoryPanel thumbPanel;
48
49    public ThreadPhotoSending(File[] files, ThumbnailCategoryPanel thumbPanel) {
50        this.files = files;
51        this.thumbPanel = thumbPanel;
52    }
53
54    @Override
55    public void run() {
56
57        for (int i = 0; i < files.length; i++) {
58            int nbProgressBar = ((i + 1) * 100) / files.length;
59            try {
60                Integer widthOriginal = Integer.valueOf(PreferencesManagement.getValue(PreferencesEnum.WIDTH_ORIGINALE
61                        .getLabel()));
62                Integer heightOriginal = Integer.valueOf(PreferencesManagement.getValue(PreferencesEnum.HEIGHT_ORIGINAL
63                        .getLabel()));
64                Double chunkSize = Double
65                        .valueOf(PreferencesManagement.getValue(PreferencesEnum.CHUNK_SIZE.getLabel()));
66                MainFrame.getInstance().setAdditionalMessage(
67                        Messages.getMessage("file") + " " + (i + 1) + "/" + files.length + " : ");
68                SpringUtils.getImageService().create(files[i].getCanonicalPath(), thumbPanel.getCategoryId(),
69                        widthOriginal, heightOriginal, chunkSize, ImagesManagement.getInstance().getPrivacyLevel());
70                MainFrame.getInstance().setMessage(files[i].getName() + " " + Messages.getMessage("sendingSuccess"));
71            } catch (FileAlreadyExistsException e) {
72                //displays a dialog if there is a FileAlreadyExistsException
73                JOptionPane.showMessageDialog(null, Messages.getMessage("fileAlreadyExistsError"), Messages
74                        .getMessage("error"), JOptionPane.ERROR_MESSAGE);
75                MainFrame.getInstance().setMessage(Messages.getMessage("sendingError") + " " + files[i].getName());
76            } catch (WrongChunkSizeException e) {
77                JOptionPane.showMessageDialog(null, Messages.getMessage("wrongChunkSizeError") + files[i].getName(),
78                        Messages.getMessage("error"), JOptionPane.ERROR_MESSAGE);
79                MainFrame.getInstance().setMessage(Messages.getMessage("sendingError") + " " + files[i].getName());
80            } catch (Exception e) {
81                JOptionPane.showMessageDialog(null, Messages.getMessage("sendingError") + files[i].getName(), Messages
82                        .getMessage("error"), JOptionPane.ERROR_MESSAGE);
83                MainFrame.getInstance().setMessage(Messages.getMessage("sendingError") + " " + files[i].getName());
84            } finally {
85                MainFrame.getInstance().getProgressBar().setValue(nbProgressBar);
86            }
87        }
88        MainFrame.getInstance().setAdditionalMessage("");
89        //refresh
90        thumbPanel.rafraichir(thumbPanel.getCategoryId(), true);
91        MainFrame.getInstance().getProgressBar().setValue(0);
92    }
93}
Note: See TracBrowser for help on using the repository browser.