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