mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 19:28:01 +00:00
SLayoutIO save should not require non-edt thread
This commit is contained in:
@@ -10,6 +10,7 @@ import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
@@ -23,6 +24,7 @@ import javax.xml.stream.events.Attribute;
|
||||
import javax.xml.stream.events.StartElement;
|
||||
import javax.xml.stream.events.XMLEvent;
|
||||
|
||||
import forge.FThreads;
|
||||
import forge.Singletons;
|
||||
import forge.control.FControl.Screens;
|
||||
import forge.properties.FileLocation;
|
||||
@@ -60,17 +62,23 @@ public final class SLayoutIO {
|
||||
return SLayoutIO.getFileForState(mode).userPrefLoc;
|
||||
}
|
||||
|
||||
|
||||
private final static AtomicBoolean saveRequested = new AtomicBoolean(false);
|
||||
/** Publicly-accessible save method, to neatly handle exception handling.
|
||||
* @param f0 file to save layout to, if null, saves to filePreferred
|
||||
*
|
||||
*
|
||||
*/
|
||||
public static void saveLayout(final File f0) {
|
||||
if (SwingUtilities.isEventDispatchThread()) {
|
||||
throw new IllegalThreadStateException("This operation should be independent of the EDT.");
|
||||
}
|
||||
if( saveRequested.getAndSet(true) ) return;
|
||||
FThreads.delay(100, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
save(f0);
|
||||
saveRequested.set(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private synchronized static void save(final File f0) {
|
||||
|
||||
@@ -306,9 +306,7 @@ public final class SRearrangingUtil {
|
||||
cellNew.refresh();
|
||||
updateBorders();
|
||||
|
||||
final Thread t = new Thread() { @Override
|
||||
public void run() { SLayoutIO.saveLayout(null); } };
|
||||
t.start();
|
||||
SLayoutIO.saveLayout(null);
|
||||
}
|
||||
|
||||
/** The gap created by displaced panels must be filled.
|
||||
|
||||
@@ -374,9 +374,7 @@ public final class SResizingUtil {
|
||||
|
||||
/** */
|
||||
public static void endResize() {
|
||||
final Thread t = new Thread() { @Override
|
||||
public void run() { SLayoutIO.saveLayout(null); } };
|
||||
t.start();
|
||||
SLayoutIO.saveLayout(null);
|
||||
}
|
||||
|
||||
/** @return {@link java.awt.event.MouseListener} */
|
||||
|
||||
Reference in New Issue
Block a user