mirror of
https://github.com/magefree/mage.git
synced 2025-12-22 11:32:00 -08:00
Minor formatting.
This commit is contained in:
parent
5a4d8c22eb
commit
2c5fbe20c0
4 changed files with 65 additions and 45 deletions
|
|
@ -21,11 +21,11 @@ import java.util.regex.Pattern;
|
|||
public class ManaSymbols {
|
||||
|
||||
private static final Logger log = Logger.getLogger(ManaSymbols.class);
|
||||
private static final Map<String, BufferedImage> manaImages = new HashMap<String, BufferedImage>();
|
||||
private static final Map<String, Image> manaImagesOriginal = new HashMap<String, Image>();
|
||||
private static final Map<String, Image> setImages = new HashMap<String, Image>();
|
||||
private static final Map<String, Dimension> setImagesExist = new HashMap<String, Dimension>();
|
||||
private static Pattern replaceSymbolsPattern = Pattern.compile("\\{([^}/]*)/?([^}]*)\\}");
|
||||
private static final Map<String, BufferedImage> manaImages = new HashMap<>();
|
||||
private static final Map<String, Image> manaImagesOriginal = new HashMap<>();
|
||||
private static final Map<String, Image> setImages = new HashMap<>();
|
||||
private static final Map<String, Dimension> setImagesExist = new HashMap<>();
|
||||
private static final Pattern replaceSymbolsPattern = Pattern.compile("\\{([^}/]*)/?([^}]*)\\}");
|
||||
private static String cachedPath;
|
||||
|
||||
public static void loadImages() {
|
||||
|
|
@ -96,7 +96,7 @@ public class ManaSymbols {
|
|||
ImageIO.write(resized, "png", newFile);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (file != null && file.exists()) {
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,13 +43,13 @@ public class DownloadGui extends JPanel {
|
|||
private final BoundedRangeModel model = new DefaultBoundedRangeModel(0, 0, 0, 0);
|
||||
private final JProgressBar progress = new JProgressBar(model);
|
||||
|
||||
private final Map<DownloadJob, DownloadPanel> progresses = new HashMap<DownloadJob, DownloadPanel>();
|
||||
private final Map<DownloadJob, DownloadPanel> progresses = new HashMap<>();
|
||||
private final JPanel panel = new JPanel();
|
||||
|
||||
public DownloadGui(Downloader d) {
|
||||
public DownloadGui(Downloader downloader) {
|
||||
super(new BorderLayout());
|
||||
this.d = d;
|
||||
d.addPropertyChangeListener(l);
|
||||
this.d = downloader;
|
||||
downloader.addPropertyChangeListener(l);
|
||||
|
||||
JPanel p = new JPanel(new BorderLayout());
|
||||
p.setBorder(BorderFactory.createTitledBorder("Progress:"));
|
||||
|
|
@ -68,8 +68,9 @@ public class DownloadGui extends JPanel {
|
|||
JScrollPane pane = new JScrollPane(panel);
|
||||
pane.setPreferredSize(new Dimension(500, 300));
|
||||
add(pane);
|
||||
for(int i = 0; i < d.getJobs().size(); i++)
|
||||
addJob(i, d.getJobs().get(i));
|
||||
for(int i = 0; i < downloader.getJobs().size(); i++) {
|
||||
addJob(i, downloader.getJobs().get(i));
|
||||
}
|
||||
}
|
||||
|
||||
public Downloader getDownloader() {
|
||||
|
|
@ -82,24 +83,23 @@ public class DownloadGui extends JPanel {
|
|||
String name = evt.getPropertyName();
|
||||
if(evt.getSource() instanceof DownloadJob) {
|
||||
DownloadPanel p = progresses.get(evt.getSource());
|
||||
if("state".equals(name)) {
|
||||
if(evt.getOldValue() == State.FINISHED || evt.getOldValue() == State.ABORTED) {
|
||||
changeProgress(-1, 0);
|
||||
}
|
||||
if(evt.getNewValue() == State.FINISHED || evt.getOldValue() == State.ABORTED) {
|
||||
switch (name) {
|
||||
case "state":
|
||||
if(evt.getOldValue() == State.FINISHED || evt.getOldValue() == State.ABORTED) {
|
||||
changeProgress(-1, 0);
|
||||
} if(evt.getNewValue() == State.FINISHED || evt.getOldValue() == State.ABORTED) {
|
||||
changeProgress(+1, 0);
|
||||
}
|
||||
if(p != null) {
|
||||
} if(p != null) {
|
||||
p.setVisible(p.getJob().getState() != State.FINISHED);
|
||||
p.revalidate();
|
||||
}
|
||||
} else if("message".equals(name)) {
|
||||
if(p != null) {
|
||||
JProgressBar bar = p.getBar();
|
||||
String message = p.getJob().getMessage();
|
||||
bar.setStringPainted(message != null);
|
||||
bar.setString(message);
|
||||
}
|
||||
} break;
|
||||
case "message":
|
||||
if(p != null) {
|
||||
JProgressBar bar = p.getBar();
|
||||
String message = p.getJob().getMessage();
|
||||
bar.setStringPainted(message != null);
|
||||
bar.setString(message);
|
||||
} break;
|
||||
}
|
||||
} else if(evt.getSource() == d) {
|
||||
if("jobs".equals(name)) {
|
||||
|
|
@ -107,10 +107,14 @@ public class DownloadGui extends JPanel {
|
|||
int index = ev.getIndex();
|
||||
|
||||
DownloadJob oldValue = (DownloadJob) ev.getOldValue();
|
||||
if(oldValue != null) removeJob(index, oldValue);
|
||||
if(oldValue != null) {
|
||||
removeJob(index, oldValue);
|
||||
}
|
||||
|
||||
DownloadJob newValue = (DownloadJob) ev.getNewValue();
|
||||
if(newValue != null) addJob(index, newValue);
|
||||
if(newValue != null) {
|
||||
addJob(index, newValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -146,8 +150,8 @@ public class DownloadGui extends JPanel {
|
|||
private class DownloadPanel extends JPanel {
|
||||
private static final long serialVersionUID = 1187986738303477168L;
|
||||
|
||||
private DownloadJob job;
|
||||
private JProgressBar bar;
|
||||
private final DownloadJob job;
|
||||
private final JProgressBar bar;
|
||||
|
||||
public DownloadPanel(DownloadJob job) {
|
||||
super(new BorderLayout());
|
||||
|
|
|
|||
|
|
@ -41,13 +41,13 @@ import org.mage.plugins.card.dl.lm.AbstractLaternaBean;
|
|||
*/
|
||||
public class Downloader extends AbstractLaternaBean implements Disposable {
|
||||
|
||||
private static final Logger log = Logger.getLogger(Downloader.class);
|
||||
private static final Logger logger = Logger.getLogger(Downloader.class);
|
||||
|
||||
private final List<DownloadJob> jobs = properties.list("jobs");
|
||||
private final Channel<DownloadJob> channel = new MemoryChannel<DownloadJob>();
|
||||
private final Channel<DownloadJob> channel = new MemoryChannel<>();
|
||||
|
||||
private final ExecutorService pool = Executors.newCachedThreadPool();
|
||||
private final List<Fiber> fibers = new ArrayList<Fiber>();
|
||||
private final List<Fiber> fibers = new ArrayList<>();
|
||||
|
||||
public Downloader() {
|
||||
PoolFiberFactory f = new PoolFiberFactory(pool);
|
||||
|
|
@ -70,11 +70,16 @@ public class Downloader extends AbstractLaternaBean implements Disposable {
|
|||
}
|
||||
}
|
||||
|
||||
for(Fiber f:fibers)
|
||||
for(Fiber f:fibers) {
|
||||
f.dispose();
|
||||
}
|
||||
pool.shutdown();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @throws Throwable
|
||||
*/
|
||||
@Override
|
||||
protected void finalize() throws Throwable {
|
||||
dispose();
|
||||
|
|
@ -82,8 +87,12 @@ public class Downloader extends AbstractLaternaBean implements Disposable {
|
|||
}
|
||||
|
||||
public void add(DownloadJob job) {
|
||||
if(job.getState() == State.WORKING) throw new IllegalArgumentException("Job already running");
|
||||
if(job.getState() == State.FINISHED) throw new IllegalArgumentException("Job already finished");
|
||||
if(job.getState() == State.WORKING) {
|
||||
throw new IllegalArgumentException("Job already running");
|
||||
}
|
||||
if(job.getState() == State.FINISHED) {
|
||||
throw new IllegalArgumentException("Job already finished");
|
||||
}
|
||||
job.setState(State.NEW);
|
||||
jobs.add(job);
|
||||
channel.publish(job);
|
||||
|
|
@ -102,7 +111,9 @@ public class Downloader extends AbstractLaternaBean implements Disposable {
|
|||
public void onMessage(DownloadJob job) {
|
||||
//the job won't be processed by multiple threads
|
||||
synchronized(job) {
|
||||
if(job.getState() != State.NEW) return;
|
||||
if(job.getState() != State.NEW) {
|
||||
return;
|
||||
}
|
||||
job.setState(State.WORKING);
|
||||
}
|
||||
try {
|
||||
|
|
@ -122,7 +133,9 @@ public class Downloader extends AbstractLaternaBean implements Disposable {
|
|||
byte[] buf = new byte[8 * 1024];
|
||||
int total = 0;
|
||||
for(int len; (len = is.read(buf)) != -1;) {
|
||||
if(job.getState() == State.ABORTED) throw new IOException("Job was aborted");
|
||||
if(job.getState() == State.ABORTED) {
|
||||
throw new IOException("Job was aborted");
|
||||
}
|
||||
progress.setValue(total += len);
|
||||
os.write(buf, 0, len);
|
||||
}
|
||||
|
|
@ -130,21 +143,21 @@ public class Downloader extends AbstractLaternaBean implements Disposable {
|
|||
try {
|
||||
dst.delete();
|
||||
} catch(IOException ex1) {
|
||||
log.warn("While deleting", ex1);
|
||||
logger.warn("While deleting", ex1);
|
||||
}
|
||||
throw ex;
|
||||
} finally {
|
||||
try {
|
||||
os.close();
|
||||
} catch(IOException ex) {
|
||||
log.warn("While closing", ex);
|
||||
logger.warn("While closing", ex);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
try {
|
||||
is.close();
|
||||
} catch(IOException ex) {
|
||||
log.warn("While closing", ex);
|
||||
logger.warn("While closing", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,14 +6,12 @@
|
|||
|
||||
package org.mage.plugins.card.dl.beans.properties;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.mage.plugins.card.dl.beans.properties.basic.BasicProperty;
|
||||
|
||||
|
||||
|
|
@ -24,22 +22,27 @@ import org.mage.plugins.card.dl.beans.properties.basic.BasicProperty;
|
|||
* @author Clemens Koza
|
||||
*/
|
||||
public abstract class AbstractProperties implements Properties {
|
||||
@Override
|
||||
public <T> Property<T> property(String name, T value) {
|
||||
return property(name, new BasicProperty<T>(value));
|
||||
return property(name, new BasicProperty<>(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Property<T> property(String name) {
|
||||
return property(name, new BasicProperty<T>());
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> List<E> list(String name) {
|
||||
return list(name, new ArrayList<E>());
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> Set<E> set(String name) {
|
||||
return set(name, new HashSet<E>());
|
||||
}
|
||||
|
||||
@Override
|
||||
public <K, V> Map<K, V> map(String name) {
|
||||
return map(name, new HashMap<K, V>());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue