SLayoutIO save should not require non-edt thread

This commit is contained in:
Maxmtg
2013-06-06 08:00:48 +00:00
parent 4d030c9524
commit ab012ed327
3 changed files with 15 additions and 11 deletions

View File

@@ -10,6 +10,7 @@ import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import javax.swing.border.EmptyBorder; 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.StartElement;
import javax.xml.stream.events.XMLEvent; import javax.xml.stream.events.XMLEvent;
import forge.FThreads;
import forge.Singletons; import forge.Singletons;
import forge.control.FControl.Screens; import forge.control.FControl.Screens;
import forge.properties.FileLocation; import forge.properties.FileLocation;
@@ -60,17 +62,23 @@ public final class SLayoutIO {
return SLayoutIO.getFileForState(mode).userPrefLoc; return SLayoutIO.getFileForState(mode).userPrefLoc;
} }
private final static AtomicBoolean saveRequested = new AtomicBoolean(false);
/** Publicly-accessible save method, to neatly handle exception handling. /** Publicly-accessible save method, to neatly handle exception handling.
* @param f0 file to save layout to, if null, saves to filePreferred * @param f0 file to save layout to, if null, saves to filePreferred
* *
* *
*/ */
public static void saveLayout(final File f0) { public static void saveLayout(final File f0) {
if (SwingUtilities.isEventDispatchThread()) { if( saveRequested.getAndSet(true) ) return;
throw new IllegalThreadStateException("This operation should be independent of the EDT."); FThreads.delay(100, new Runnable() {
}
save(f0); @Override
public void run() {
save(f0);
saveRequested.set(false);
}
});
} }
private synchronized static void save(final File f0) { private synchronized static void save(final File f0) {

View File

@@ -306,9 +306,7 @@ public final class SRearrangingUtil {
cellNew.refresh(); cellNew.refresh();
updateBorders(); updateBorders();
final Thread t = new Thread() { @Override SLayoutIO.saveLayout(null);
public void run() { SLayoutIO.saveLayout(null); } };
t.start();
} }
/** The gap created by displaced panels must be filled. /** The gap created by displaced panels must be filled.

View File

@@ -374,9 +374,7 @@ public final class SResizingUtil {
/** */ /** */
public static void endResize() { public static void endResize() {
final Thread t = new Thread() { @Override SLayoutIO.saveLayout(null);
public void run() { SLayoutIO.saveLayout(null); } };
t.start();
} }
/** @return {@link java.awt.event.MouseListener} */ /** @return {@link java.awt.event.MouseListener} */