/* neon-image - Image extensions to Neon Copyright (C) 2024 Ulrich Hilger This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package de.uhilger.neon.image; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; /** * Eine Klasse zur Erzeugung verkleinerter sowie Base64-enkodierter Fassungen * einer Bilddatei innerhalb eines Threads. * * @author Ulrich Hilger * @version 1, 14.06.2021 */ public class ImageThread extends Thread { private List listeners; private final File dir; private final File toFile; private final String relName; private final String indicator; private final int size; private final Datei datei; private final String ext; public ImageThread(File dir, String relName, String indicator, int size, File toFile, Datei datei, String ext) { super(); listeners = new ArrayList(); this.dir = dir; this.relName = relName; this.indicator = indicator; this.size = size; this.toFile = toFile; this.datei = datei; this.ext = ext; } protected void sendFinished() { Iterator i = listeners.iterator(); while (i.hasNext()) { ThreadListener listener = i.next(); listener.finished(); } } protected void clear() { sendFinished(); listeners.clear(); listeners = null; } /** * starten mit * *
   * Thread p = new ImageThread(..); 
   * p.start();
   * 
*/ @Override public void run() { try { ImageWorker be = new ImageWorker(); be.createImage(dir, relName, indicator, size, toFile); be.setImgSrc(datei, ext, toFile); clear(); } catch (IOException ex) { //Logger.getLogger(ImageThread.class.getName()).log(Level.SEVERE, null, ex); clear(); } } public void addListener(ThreadListener listener) { listeners.add(listener); } public void removeListener(ThreadListener listener) { listeners.remove(listener); } public interface ThreadListener { public void finished(); } }