commit | author | age
|
ef2fb2
|
1 |
/* |
U |
2 |
neon-image - Image extensions to Neon |
|
3 |
Copyright (C) 2024 Ulrich Hilger |
|
4 |
|
|
5 |
This program is free software: you can redistribute it and/or modify |
|
6 |
it under the terms of the GNU Affero General Public License as |
|
7 |
published by the Free Software Foundation, either version 3 of the |
|
8 |
License, or (at your option) any later version. |
|
9 |
|
|
10 |
This program is distributed in the hope that it will be useful, |
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
GNU Affero General Public License for more details. |
|
14 |
|
|
15 |
You should have received a copy of the GNU Affero General Public License |
|
16 |
along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
17 |
*/ |
|
18 |
package de.uhilger.neon.image; |
|
19 |
|
|
20 |
import java.io.File; |
|
21 |
import java.io.IOException; |
|
22 |
import java.util.ArrayList; |
|
23 |
import java.util.Iterator; |
|
24 |
import java.util.List; |
|
25 |
|
|
26 |
/** |
|
27 |
* Eine Klasse zur Erzeugung verkleinerter sowie Base64-enkodierter Fassungen |
|
28 |
* einer Bilddatei innerhalb eines Threads. |
|
29 |
* |
|
30 |
* @author Ulrich Hilger |
|
31 |
* @version 1, 14.06.2021 |
|
32 |
*/ |
|
33 |
public class ImageThread extends Thread { |
|
34 |
|
|
35 |
private List<ThreadListener> listeners; |
|
36 |
private final File dir; |
|
37 |
private final File toFile; |
|
38 |
private final String relName; |
|
39 |
private final String indicator; |
|
40 |
private final int size; |
|
41 |
private final Datei datei; |
|
42 |
private final String ext; |
|
43 |
|
|
44 |
public ImageThread(File dir, String relName, String indicator, int size, File toFile, Datei datei, String ext) { |
|
45 |
super(); |
|
46 |
listeners = new ArrayList(); |
|
47 |
this.dir = dir; |
|
48 |
this.relName = relName; |
|
49 |
this.indicator = indicator; |
|
50 |
this.size = size; |
|
51 |
this.toFile = toFile; |
|
52 |
this.datei = datei; |
|
53 |
this.ext = ext; |
|
54 |
} |
|
55 |
|
|
56 |
protected void sendFinished() { |
|
57 |
Iterator<ThreadListener> i = listeners.iterator(); |
|
58 |
while (i.hasNext()) { |
|
59 |
ThreadListener listener = i.next(); |
|
60 |
listener.finished(); |
|
61 |
} |
|
62 |
} |
|
63 |
|
|
64 |
protected void clear() { |
|
65 |
sendFinished(); |
|
66 |
listeners.clear(); |
|
67 |
listeners = null; |
|
68 |
} |
|
69 |
|
|
70 |
/** |
|
71 |
* starten mit |
|
72 |
* |
|
73 |
* <pre> |
|
74 |
* Thread p = new ImageThread(..); |
|
75 |
* p.start(); |
|
76 |
* </pre> |
|
77 |
*/ |
|
78 |
@Override |
|
79 |
public void run() { |
|
80 |
try { |
|
81 |
ImageWorker be = new ImageWorker(); |
|
82 |
be.createImage(dir, relName, indicator, size, toFile); |
|
83 |
be.setImgSrc(datei, ext, toFile); |
|
84 |
clear(); |
|
85 |
} catch (IOException ex) { |
|
86 |
//Logger.getLogger(ImageThread.class.getName()).log(Level.SEVERE, null, ex); |
|
87 |
clear(); |
|
88 |
} |
|
89 |
} |
|
90 |
|
|
91 |
public void addListener(ThreadListener listener) { |
|
92 |
listeners.add(listener); |
|
93 |
} |
|
94 |
|
|
95 |
public void removeListener(ThreadListener listener) { |
|
96 |
listeners.remove(listener); |
|
97 |
} |
|
98 |
|
|
99 |
public interface ThreadListener { |
|
100 |
|
|
101 |
public void finished(); |
|
102 |
} |
|
103 |
|
|
104 |
} |