Refactored some of the new code for a general open dialog. Dock now has new button "Open Layout" along with old button with original function "Revert Layout"

This commit is contained in:
7Durandal7
2012-05-11 02:37:49 +00:00
parent 5763192b02
commit f1ec1da068
4 changed files with 63 additions and 10 deletions

View File

@@ -42,6 +42,7 @@ import forge.gui.framework.ICDoc;
import forge.gui.framework.SIOUtil;
import forge.gui.match.views.VDock;
import forge.gui.toolbox.SaveOpenDialog;
import forge.gui.toolbox.SaveOpenDialog.Filetypes;
import forge.item.CardPrinted;
import forge.properties.NewConstants;
import forge.view.FView;
@@ -72,13 +73,28 @@ public enum CDock implements ICDoc {
SOverlayUtils.genericOverlay();
FView.SINGLETON_INSTANCE.getPnlContent().removeAll();
final SwingWorker<Void, Void> w = new SwingWorker<Void, Void>() {
@Override
public Void doInBackground() {
SIOUtil.loadLayout(new File(SIOUtil.FILE_DEFAULT));
SOverlayUtils.hideOverlay();
return null;
}
};
w.execute();
}
private void openLayout() {
SOverlayUtils.genericOverlay();
FView.SINGLETON_INSTANCE.getPnlContent().removeAll();
final SwingWorker<Void,Void> w = new SwingWorker<Void,Void>() {
@Override
public Void doInBackground() {
SaveOpenDialog dlgSave = new SaveOpenDialog();
SaveOpenDialog dlgOpen = new SaveOpenDialog();
File LoadFile = new File(SIOUtil.FILE_PREFERRED);
LoadFile = dlgSave.OpenXMLDialog(LoadFile);
LoadFile = dlgOpen.OpenDialog(LoadFile, null);
SIOUtil.loadLayout(LoadFile);
SOverlayUtils.hideOverlay();
@@ -208,6 +224,11 @@ public enum CDock implements ICDoc {
.addMouseListener(new MouseAdapter() { @Override
public void mousePressed(final MouseEvent e) {
revertLayout(); } });
VDock.SINGLETON_INSTANCE.getBtnOpenLayout()
.addMouseListener(new MouseAdapter() { @Override
public void mousePressed(final MouseEvent e) {
openLayout(); } });
}
/* (non-Javadoc)

View File

@@ -60,7 +60,9 @@ public enum VDock implements IVDoc {
private final JLabel btnViewDeckList =
new DockButton(FSkin.getIcon(FSkin.DockIcons.ICO_DECKLIST), "View Deck List");
private final JLabel btnRevertLayout =
new DockButton(FSkin.getIcon(FSkin.DockIcons.ICO_REVERTLAYOUT), "Open Layout");
new DockButton(FSkin.getIcon(FSkin.DockIcons.ICO_REVERTLAYOUT), "Revert Layout");
private final JLabel btnOpenLayout =
new DockButton(FSkin.getIcon(FSkin.DockIcons.ICO_OPENLAYOUT), "Open Layout");
//========= Overridden methods
@@ -79,6 +81,7 @@ public enum VDock implements IVDoc {
pnl.add(btnEndTurn);
pnl.add(btnViewDeckList);
pnl.add(btnRevertLayout);
pnl.add(btnOpenLayout);
}
/* (non-Javadoc)
@@ -148,6 +151,10 @@ public enum VDock implements IVDoc {
return btnRevertLayout;
}
public JLabel getBtnOpenLayout() {
return btnOpenLayout;
}
//========= Custom class handling
/**
* Buttons in Dock. JLabels are used to allow hover effects.

View File

@@ -214,6 +214,7 @@ public enum FSkin {
ICO_ENDTURN (new int[] {320, 640, 80, 80}), /** */
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_DECKLIST (new int[] {400, 640, 80, 80});
private int[] coords;

View File

@@ -35,21 +35,45 @@ public class SaveOpenDialog extends JPanel {
private JFileChooser fc;
/**
* Enum to contain information for filetype filtering in the open/save dialog.
* Add more entries to enum as needed.
*
*
*/
public enum Filetypes {
LAYOUT ("Layout File", "xml");
private final String TypeName;
private final String TypeExtension;
Filetypes(String Name, String Extension) {
this.TypeName = Name;
this.TypeExtension = Extension;
}
}
public SaveOpenDialog() {
fc = new JFileChooser();
}
/**
* Shows the open dialog for xml files (layouts). If no file selected, returns default.
* Shows the open dialog for files. If no file selected, returns default. Pass null
* to Type and Extension to allow all files to be viewed/opened.
* @param defFileName pass the default file to use, also determines directory
* @param type label to tell what type of file to filter
*
*
*/
public File OpenXMLDialog(File defFileName) {
public File OpenDialog(File defFileName, Filetypes type) {
File RetFile = defFileName;
fc.setCurrentDirectory(defFileName);
fc.setAcceptAllFileFilterUsed(false);
FileFilter filter = new FileNameExtensionFilter("Layout Files", "xml");
fc.addChoosableFileFilter(filter);
if (type!=null) {
fc.setAcceptAllFileFilterUsed(false);
FileFilter filter = new FileNameExtensionFilter(type.TypeName, type.TypeExtension);
fc.addChoosableFileFilter(filter);
}
int RetValue = fc.showOpenDialog(getParent());