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:
7Durandal7
2012-05-11 22:22:09 +00:00
parent 45e17ebda7
commit ac503cff3a
7 changed files with 83 additions and 20 deletions

View File

@@ -43,14 +43,19 @@ public final class SIOUtil {
private static final XMLEvent NEWLINE = EF.createDTD("\n");
private static final XMLEvent TAB = EF.createDTD("\t");
/** Publicly-accessible save method, to neatly handle exception handling. */
public static void saveLayout() {
/** Publicly-accessible save method, to neatly handle exception handling.
* @param f0 file to save layout to, if null, saves to FILE_PREFERRED
*
*
*/
public static void saveLayout(final File f0) {
if (SwingUtilities.isEventDispatchThread()) {
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(); }
}
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 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 JPanel pnl = FView.SINGLETON_INSTANCE.getPnlContent();
double x0, y0, w0, h0;

View File

@@ -307,7 +307,7 @@ public final class SRearrangingUtil {
updateBorders();
final Thread t = new Thread() { @Override
public void run() { SIOUtil.saveLayout(); } };
public void run() { SIOUtil.saveLayout(null); } };
t.start();
}

View File

@@ -332,7 +332,7 @@ public final class SResizingUtil {
/** */
public static void endResize() {
final Thread t = new Thread() { @Override
public void run() { SIOUtil.saveLayout(); } };
public void run() { SIOUtil.saveLayout(null); } };
t.start();
}

View File

@@ -83,6 +83,22 @@ public enum CDock implements ICDoc {
};
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() {
SOverlayUtils.genericOverlay();
@@ -98,11 +114,9 @@ public enum CDock implements ICDoc {
if (LoadFile!=null) {
SIOUtil.loadLayout(LoadFile);
SIOUtil.saveLayout(null);
}
else {
SIOUtil.loadLayout(DefFile);
}
SIOUtil.saveLayout();
SOverlayUtils.hideOverlay();
return null;
}
@@ -235,6 +249,11 @@ public enum CDock implements ICDoc {
.addMouseListener(new MouseAdapter() { @Override
public void mousePressed(final MouseEvent e) {
openLayout(); } });
VDock.SINGLETON_INSTANCE.getBtnSaveLayout()
.addMouseListener(new MouseAdapter() { @Override
public void mousePressed(final MouseEvent e) {
saveLayout(); } });
}
/* (non-Javadoc)

View File

@@ -63,6 +63,8 @@ public enum VDock implements IVDoc {
new DockButton(FSkin.getIcon(FSkin.DockIcons.ICO_REVERTLAYOUT), "Revert Layout");
private final JLabel btnOpenLayout =
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
@@ -82,6 +84,7 @@ public enum VDock implements IVDoc {
pnl.add(btnViewDeckList);
pnl.add(btnRevertLayout);
pnl.add(btnOpenLayout);
pnl.add(btnSaveLayout);
}
/* (non-Javadoc)
@@ -154,6 +157,10 @@ public enum VDock implements IVDoc {
public JLabel getBtnOpenLayout() {
return btnOpenLayout;
}
public JLabel getBtnSaveLayout() {
return btnSaveLayout;
}
//========= Custom class handling
/**

View File

@@ -215,6 +215,7 @@ public enum FSkin {
ICO_CONCEDE (new int[] {240, 640, 80, 80}), /** */
ICO_REVERTLAYOUT (new int[] {400, 720, 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});
private int[] coords;

View File

@@ -43,7 +43,8 @@ public class SaveOpenDialog extends JPanel {
*
*/
public enum Filetypes {
LAYOUT ("Layout File", "xml");
LAYOUT ("Layout File", "xml"),
DECK ("Deck File", "dck");
private final String TypeName;
private final String TypeExtension;
@@ -70,39 +71,60 @@ public class SaveOpenDialog extends JPanel {
*
*
*/
public File OpenDialog(File defFileName, Filetypes type) {
File RetFile = defFileName;
public File OpenDialog(final File defFileName, final Filetypes type) {
fc.setCurrentDirectory(defFileName);
if (type!=null) {
fc.setAcceptAllFileFilterUsed(false);
FileFilter filter = new FileNameExtensionFilter(type.TypeName, type.TypeExtension);
final FileFilter filter = new FileNameExtensionFilter(type.TypeName, type.TypeExtension);
fc.addChoosableFileFilter(filter);
}
int RetValue = fc.showOpenDialog(getParent());
if (RetValue == JFileChooser.APPROVE_OPTION) {
RetFile = fc.getSelectedFile();
final File RetFile = fc.getSelectedFile();
return RetFile;
}
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;
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());
/* user picked save */
if (RetValue == JFileChooser.APPROVE_OPTION) {
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;
}
}