mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 19:58:00 +00:00
add dated serial to layout file
Signed-off-by: Jamin W. Collins <jamin.collins@gmail.com>
This commit is contained in:
@@ -28,6 +28,7 @@ import javax.xml.stream.events.XMLEvent;
|
|||||||
|
|
||||||
import forge.FThreads;
|
import forge.FThreads;
|
||||||
import forge.Singletons;
|
import forge.Singletons;
|
||||||
|
import forge.error.BugReporter;
|
||||||
import forge.gui.SOverlayUtils;
|
import forge.gui.SOverlayUtils;
|
||||||
import forge.properties.FileLocation;
|
import forge.properties.FileLocation;
|
||||||
import forge.properties.ForgeConstants;
|
import forge.properties.ForgeConstants;
|
||||||
@@ -36,6 +37,7 @@ import forge.toolbox.SaveOpenDialog;
|
|||||||
import forge.toolbox.SaveOpenDialog.Filetypes;
|
import forge.toolbox.SaveOpenDialog.Filetypes;
|
||||||
import forge.util.CollectionSuppliers;
|
import forge.util.CollectionSuppliers;
|
||||||
import forge.util.ThreadUtil;
|
import forge.util.ThreadUtil;
|
||||||
|
import forge.util.gui.SOptionPane;
|
||||||
import forge.util.maps.HashMapOfLists;
|
import forge.util.maps.HashMapOfLists;
|
||||||
import forge.util.maps.MapOfLists;
|
import forge.util.maps.MapOfLists;
|
||||||
import forge.view.FFrame;
|
import forge.view.FFrame;
|
||||||
@@ -307,6 +309,8 @@ public final class SLayoutIO {
|
|||||||
FileOutputStream fos = null;
|
FileOutputStream fos = null;
|
||||||
XMLEventWriter writer = null;
|
XMLEventWriter writer = null;
|
||||||
try {
|
try {
|
||||||
|
String layoutSerial = getLayoutSerial(file.defaultLoc);
|
||||||
|
|
||||||
fos = new FileOutputStream(fWriteTo);
|
fos = new FileOutputStream(fWriteTo);
|
||||||
writer = out.createXMLEventWriter(fos);
|
writer = out.createXMLEventWriter(fos);
|
||||||
final List<DragCell> cells = FView.SINGLETON_INSTANCE.getDragCells();
|
final List<DragCell> cells = FView.SINGLETON_INSTANCE.getDragCells();
|
||||||
@@ -314,6 +318,7 @@ public final class SLayoutIO {
|
|||||||
writer.add(EF.createStartDocument());
|
writer.add(EF.createStartDocument());
|
||||||
writer.add(NEWLINE);
|
writer.add(NEWLINE);
|
||||||
writer.add(EF.createStartElement("", "", "layout"));
|
writer.add(EF.createStartElement("", "", "layout"));
|
||||||
|
writer.add(EF.createAttribute("serial", layoutSerial));
|
||||||
writer.add(NEWLINE);
|
writer.add(NEWLINE);
|
||||||
|
|
||||||
for (final DragCell cell : cells) {
|
for (final DragCell cell : cells) {
|
||||||
@@ -356,8 +361,63 @@ public final class SLayoutIO {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String getLayoutSerial(String layoutFileName) {
|
||||||
|
final XMLInputFactory inputFactory = XMLInputFactory.newInstance();
|
||||||
|
FileInputStream fis = null;
|
||||||
|
XMLEventReader reader = null;
|
||||||
|
XMLEvent event;
|
||||||
|
StartElement element;
|
||||||
|
Iterator<?> attributes;
|
||||||
|
Attribute attribute;
|
||||||
|
|
||||||
|
try {
|
||||||
|
fis = new FileInputStream(layoutFileName);
|
||||||
|
|
||||||
|
reader = inputFactory.createXMLEventReader(fis);
|
||||||
|
while (null != reader && reader.hasNext()) {
|
||||||
|
event = reader.nextEvent();
|
||||||
|
|
||||||
|
if (event.isStartElement()) {
|
||||||
|
element = event.asStartElement();
|
||||||
|
|
||||||
|
if (element.getName().getLocalPart().equals("layout")) {
|
||||||
|
attributes = element.getAttributes();
|
||||||
|
while (attributes.hasNext()) {
|
||||||
|
attribute = (Attribute) attributes.next();
|
||||||
|
String atrName = attribute.getName().toString();
|
||||||
|
if (atrName.equals("serial")) {
|
||||||
|
return attribute.getValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (final Exception e) { // I don't care what happened inside, the layout is wrong
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
try {
|
||||||
|
if (reader != null) {
|
||||||
|
reader.close();
|
||||||
|
}
|
||||||
|
if (fis != null) {
|
||||||
|
fis.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
public static void loadLayout(final File f) {
|
public static void loadLayout(final File f) {
|
||||||
final FView view = FView.SINGLETON_INSTANCE;
|
final FView view = FView.SINGLETON_INSTANCE;
|
||||||
|
String defaultLayoutSerial = "";
|
||||||
|
String userLayoutSerial = "";
|
||||||
|
Boolean resetLayout = false;
|
||||||
|
FScreen screen = Singletons.getControl().getCurrentScreen();
|
||||||
FAbsolutePositioner.SINGLETON_INSTANCE.hideAll();
|
FAbsolutePositioner.SINGLETON_INSTANCE.hideAll();
|
||||||
view.getPnlInsets().removeAll();
|
view.getPnlInsets().removeAll();
|
||||||
view.getPnlInsets().setLayout(new BorderLayout());
|
view.getPnlInsets().setLayout(new BorderLayout());
|
||||||
@@ -365,7 +425,7 @@ public final class SLayoutIO {
|
|||||||
view.getPnlInsets().setBorder(new EmptyBorder(SLayoutConstants.BORDER_T, SLayoutConstants.BORDER_T, 0, 0));
|
view.getPnlInsets().setBorder(new EmptyBorder(SLayoutConstants.BORDER_T, SLayoutConstants.BORDER_T, 0, 0));
|
||||||
view.removeAllDragCells();
|
view.removeAllDragCells();
|
||||||
|
|
||||||
FileLocation file = Singletons.getControl().getCurrentScreen().getLayoutFile();
|
FileLocation file = screen.getLayoutFile();
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
// Read a model for new layout
|
// Read a model for new layout
|
||||||
MapOfLists<LayoutInfo, EDocID> model = null;
|
MapOfLists<LayoutInfo, EDocID> model = null;
|
||||||
@@ -379,8 +439,27 @@ public final class SLayoutIO {
|
|||||||
else {
|
else {
|
||||||
File userSetting = new File(file.userPrefLoc);
|
File userSetting = new File(file.userPrefLoc);
|
||||||
if (userSetting.exists()) {
|
if (userSetting.exists()) {
|
||||||
usedCustomPrefsFile = true;
|
defaultLayoutSerial = getLayoutSerial(file.defaultLoc);
|
||||||
|
userLayoutSerial = getLayoutSerial(file.userPrefLoc);
|
||||||
|
if (defaultLayoutSerial.compareTo(userLayoutSerial) > 0) {
|
||||||
|
// prompt the user that their saved layout is older
|
||||||
|
resetLayout = SOptionPane.showConfirmDialog(
|
||||||
|
String.format("Your %s layout file is from an older template.",
|
||||||
|
screen.getTabCaption()
|
||||||
|
),
|
||||||
|
"Reset Layout?",
|
||||||
|
"Reset",
|
||||||
|
"Keep");
|
||||||
|
}
|
||||||
|
if (resetLayout) {
|
||||||
|
// delete the old layout file
|
||||||
|
screen.deleteLayoutFile();
|
||||||
|
fis = new FileInputStream(file.defaultLoc);
|
||||||
|
} else {
|
||||||
fis = new FileInputStream(userSetting);
|
fis = new FileInputStream(userSetting);
|
||||||
|
usedCustomPrefsFile = true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fis = new FileInputStream(file.defaultLoc);
|
fis = new FileInputStream(file.defaultLoc);
|
||||||
@@ -413,15 +492,15 @@ public final class SLayoutIO {
|
|||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
if (fis != null) {
|
|
||||||
try {
|
try {
|
||||||
|
if (fis != null) {
|
||||||
fis.close();
|
fis.close();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Apply new layout
|
// Apply new layout
|
||||||
for (Entry<LayoutInfo, Collection<EDocID>> kv : model.entrySet()) {
|
for (Entry<LayoutInfo, Collection<EDocID>> kv : model.entrySet()) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
<layout>
|
<layout serial="2018090601">
|
||||||
<cell x="0.77443" y="0.37698" w="0.22557" h="0.62302">
|
<cell x="0.77443" y="0.37698" w="0.22557" h="0.62302">
|
||||||
<doc>CARD_PICTURE</doc>
|
<doc>CARD_PICTURE</doc>
|
||||||
</cell>
|
</cell>
|
||||||
|
|||||||
Reference in New Issue
Block a user