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

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

Integrates new changes in jiwigo-ws-api
(Exception management)

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