mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 12:18:00 +00:00
Added "Save Layout" feature. Save dialog function in forge.gui.toolbox improved. Save layout functions in SIOUtil slightly modified to accept these changes.
This commit is contained in:
@@ -43,14 +43,19 @@ public final class SIOUtil {
|
|||||||
private static final XMLEvent NEWLINE = EF.createDTD("\n");
|
private static final XMLEvent NEWLINE = EF.createDTD("\n");
|
||||||
private static final XMLEvent TAB = EF.createDTD("\t");
|
private static final XMLEvent TAB = EF.createDTD("\t");
|
||||||
|
|
||||||
/** Publicly-accessible save method, to neatly handle exception handling. */
|
/** Publicly-accessible save method, to neatly handle exception handling.
|
||||||
public static void saveLayout() {
|
* @param f0 file to save layout to, if null, saves to FILE_PREFERRED
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static void saveLayout(final File f0) {
|
||||||
if (SwingUtilities.isEventDispatchThread()) {
|
if (SwingUtilities.isEventDispatchThread()) {
|
||||||
throw new IllegalThreadStateException("This operation should be independent of the EDT.");
|
throw new IllegalThreadStateException("This operation should be independent of the EDT.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try { save(f0); }
|
||||||
|
catch (final Exception e) { e.printStackTrace(); }
|
||||||
|
|
||||||
try { save(); }
|
|
||||||
catch (final Exception e) { e.printStackTrace(); }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -66,9 +71,18 @@ public final class SIOUtil {
|
|||||||
catch (final Exception e) { e.printStackTrace(); }
|
catch (final Exception e) { e.printStackTrace(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void save() throws Exception {
|
private static void save(final File f0) throws Exception {
|
||||||
|
|
||||||
|
final String fWriteTo;
|
||||||
|
if (f0==null) {
|
||||||
|
fWriteTo = FILE_PREFERRED;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
fWriteTo = f0.getPath();
|
||||||
|
}
|
||||||
|
|
||||||
final XMLOutputFactory out = XMLOutputFactory.newInstance();
|
final XMLOutputFactory out = XMLOutputFactory.newInstance();
|
||||||
final XMLEventWriter writer = out.createXMLEventWriter(new FileOutputStream(FILE_PREFERRED));
|
final XMLEventWriter writer = out.createXMLEventWriter(new FileOutputStream(fWriteTo));
|
||||||
final List<DragCell> cells = FView.SINGLETON_INSTANCE.getDragCells();
|
final List<DragCell> cells = FView.SINGLETON_INSTANCE.getDragCells();
|
||||||
final JPanel pnl = FView.SINGLETON_INSTANCE.getPnlContent();
|
final JPanel pnl = FView.SINGLETON_INSTANCE.getPnlContent();
|
||||||
double x0, y0, w0, h0;
|
double x0, y0, w0, h0;
|
||||||
|
|||||||
@@ -307,7 +307,7 @@ public final class SRearrangingUtil {
|
|||||||
updateBorders();
|
updateBorders();
|
||||||
|
|
||||||
final Thread t = new Thread() { @Override
|
final Thread t = new Thread() { @Override
|
||||||
public void run() { SIOUtil.saveLayout(); } };
|
public void run() { SIOUtil.saveLayout(null); } };
|
||||||
t.start();
|
t.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -332,7 +332,7 @@ public final class SResizingUtil {
|
|||||||
/** */
|
/** */
|
||||||
public static void endResize() {
|
public static void endResize() {
|
||||||
final Thread t = new Thread() { @Override
|
final Thread t = new Thread() { @Override
|
||||||
public void run() { SIOUtil.saveLayout(); } };
|
public void run() { SIOUtil.saveLayout(null); } };
|
||||||
t.start();
|
t.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -83,6 +83,22 @@ public enum CDock implements ICDoc {
|
|||||||
};
|
};
|
||||||
w.execute();
|
w.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void saveLayout() {
|
||||||
|
final SwingWorker<Void,Void> w = new SwingWorker<Void,Void>() {
|
||||||
|
@Override
|
||||||
|
public Void doInBackground() {
|
||||||
|
SaveOpenDialog dlgSave = new SaveOpenDialog();
|
||||||
|
File DefFile = new File(SIOUtil.FILE_PREFERRED);
|
||||||
|
File SaveFile = dlgSave.SaveDialog(DefFile, Filetypes.LAYOUT);
|
||||||
|
if (SaveFile!=null) {
|
||||||
|
SIOUtil.saveLayout(SaveFile);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
w.execute();
|
||||||
|
}
|
||||||
|
|
||||||
private void openLayout() {
|
private void openLayout() {
|
||||||
SOverlayUtils.genericOverlay();
|
SOverlayUtils.genericOverlay();
|
||||||
@@ -98,11 +114,9 @@ public enum CDock implements ICDoc {
|
|||||||
|
|
||||||
if (LoadFile!=null) {
|
if (LoadFile!=null) {
|
||||||
SIOUtil.loadLayout(LoadFile);
|
SIOUtil.loadLayout(LoadFile);
|
||||||
|
SIOUtil.saveLayout(null);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
SIOUtil.loadLayout(DefFile);
|
|
||||||
}
|
|
||||||
SIOUtil.saveLayout();
|
|
||||||
SOverlayUtils.hideOverlay();
|
SOverlayUtils.hideOverlay();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -235,6 +249,11 @@ public enum CDock implements ICDoc {
|
|||||||
.addMouseListener(new MouseAdapter() { @Override
|
.addMouseListener(new MouseAdapter() { @Override
|
||||||
public void mousePressed(final MouseEvent e) {
|
public void mousePressed(final MouseEvent e) {
|
||||||
openLayout(); } });
|
openLayout(); } });
|
||||||
|
|
||||||
|
VDock.SINGLETON_INSTANCE.getBtnSaveLayout()
|
||||||
|
.addMouseListener(new MouseAdapter() { @Override
|
||||||
|
public void mousePressed(final MouseEvent e) {
|
||||||
|
saveLayout(); } });
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
|||||||
@@ -63,6 +63,8 @@ public enum VDock implements IVDoc {
|
|||||||
new DockButton(FSkin.getIcon(FSkin.DockIcons.ICO_REVERTLAYOUT), "Revert Layout");
|
new DockButton(FSkin.getIcon(FSkin.DockIcons.ICO_REVERTLAYOUT), "Revert Layout");
|
||||||
private final JLabel btnOpenLayout =
|
private final JLabel btnOpenLayout =
|
||||||
new DockButton(FSkin.getIcon(FSkin.DockIcons.ICO_OPENLAYOUT), "Open Layout");
|
new DockButton(FSkin.getIcon(FSkin.DockIcons.ICO_OPENLAYOUT), "Open Layout");
|
||||||
|
private final JLabel btnSaveLayout =
|
||||||
|
new DockButton(FSkin.getIcon(FSkin.DockIcons.ICO_SAVELAYOUT), "Save Layout");
|
||||||
|
|
||||||
//========= Overridden methods
|
//========= Overridden methods
|
||||||
|
|
||||||
@@ -82,6 +84,7 @@ public enum VDock implements IVDoc {
|
|||||||
pnl.add(btnViewDeckList);
|
pnl.add(btnViewDeckList);
|
||||||
pnl.add(btnRevertLayout);
|
pnl.add(btnRevertLayout);
|
||||||
pnl.add(btnOpenLayout);
|
pnl.add(btnOpenLayout);
|
||||||
|
pnl.add(btnSaveLayout);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
@@ -154,6 +157,10 @@ public enum VDock implements IVDoc {
|
|||||||
public JLabel getBtnOpenLayout() {
|
public JLabel getBtnOpenLayout() {
|
||||||
return btnOpenLayout;
|
return btnOpenLayout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public JLabel getBtnSaveLayout() {
|
||||||
|
return btnSaveLayout;
|
||||||
|
}
|
||||||
|
|
||||||
//========= Custom class handling
|
//========= Custom class handling
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -215,6 +215,7 @@ public enum FSkin {
|
|||||||
ICO_CONCEDE (new int[] {240, 640, 80, 80}), /** */
|
ICO_CONCEDE (new int[] {240, 640, 80, 80}), /** */
|
||||||
ICO_REVERTLAYOUT (new int[] {400, 720, 80, 80}), /** */
|
ICO_REVERTLAYOUT (new int[] {400, 720, 80, 80}), /** */
|
||||||
ICO_OPENLAYOUT (new int[] {480, 640, 80, 80}),
|
ICO_OPENLAYOUT (new int[] {480, 640, 80, 80}),
|
||||||
|
ICO_SAVELAYOUT (new int[] {480, 720, 80, 80}),
|
||||||
ICO_DECKLIST (new int[] {400, 640, 80, 80});
|
ICO_DECKLIST (new int[] {400, 640, 80, 80});
|
||||||
|
|
||||||
private int[] coords;
|
private int[] coords;
|
||||||
|
|||||||
@@ -43,7 +43,8 @@ public class SaveOpenDialog extends JPanel {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public enum Filetypes {
|
public enum Filetypes {
|
||||||
LAYOUT ("Layout File", "xml");
|
LAYOUT ("Layout File", "xml"),
|
||||||
|
DECK ("Deck File", "dck");
|
||||||
|
|
||||||
private final String TypeName;
|
private final String TypeName;
|
||||||
private final String TypeExtension;
|
private final String TypeExtension;
|
||||||
@@ -70,39 +71,60 @@ public class SaveOpenDialog extends JPanel {
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public File OpenDialog(File defFileName, Filetypes type) {
|
public File OpenDialog(final File defFileName, final Filetypes type) {
|
||||||
File RetFile = defFileName;
|
|
||||||
fc.setCurrentDirectory(defFileName);
|
fc.setCurrentDirectory(defFileName);
|
||||||
|
|
||||||
if (type!=null) {
|
if (type!=null) {
|
||||||
fc.setAcceptAllFileFilterUsed(false);
|
fc.setAcceptAllFileFilterUsed(false);
|
||||||
FileFilter filter = new FileNameExtensionFilter(type.TypeName, type.TypeExtension);
|
final FileFilter filter = new FileNameExtensionFilter(type.TypeName, type.TypeExtension);
|
||||||
fc.addChoosableFileFilter(filter);
|
fc.addChoosableFileFilter(filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int RetValue = fc.showOpenDialog(getParent());
|
int RetValue = fc.showOpenDialog(getParent());
|
||||||
if (RetValue == JFileChooser.APPROVE_OPTION) {
|
if (RetValue == JFileChooser.APPROVE_OPTION) {
|
||||||
RetFile = fc.getSelectedFile();
|
final File RetFile = fc.getSelectedFile();
|
||||||
return RetFile;
|
return RetFile;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shows the save dialog. Not implemented anywhere yet.
|
* Shows the save dialog.
|
||||||
|
*
|
||||||
|
* @param defFileName default file name/directory to show when save dialog is opened
|
||||||
|
* @param type file types to show in dialog
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public File SaveDialog(File defFileName) {
|
public File SaveDialog(final File defFileName, final Filetypes type) {
|
||||||
File RetFile = defFileName;
|
File RetFile = defFileName;
|
||||||
fc.setCurrentDirectory(defFileName);
|
fc.setCurrentDirectory(defFileName);
|
||||||
|
|
||||||
|
/* set the file filter if desired */
|
||||||
|
if (type!=null) {
|
||||||
|
fc.setAcceptAllFileFilterUsed(false);
|
||||||
|
final FileFilter filter = new FileNameExtensionFilter(type.TypeName, type.TypeExtension);
|
||||||
|
fc.addChoosableFileFilter(filter);
|
||||||
|
}
|
||||||
|
|
||||||
int RetValue = fc.showSaveDialog(getParent());
|
int RetValue = fc.showSaveDialog(getParent());
|
||||||
|
|
||||||
|
/* user picked save */
|
||||||
if (RetValue == JFileChooser.APPROVE_OPTION) {
|
if (RetValue == JFileChooser.APPROVE_OPTION) {
|
||||||
RetFile = fc.getSelectedFile();
|
RetFile = fc.getSelectedFile();
|
||||||
|
|
||||||
|
/* Adds extension if it is known and not given */
|
||||||
|
if (type!=null & !(RetFile.getAbsolutePath().endsWith(type.TypeExtension))) {
|
||||||
|
RetFile = new File(RetFile.getAbsolutePath()+"."+type.TypeExtension);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return RetFile;
|
||||||
}
|
}
|
||||||
return RetFile;
|
|
||||||
|
/* user picked cancel */
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user