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