mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 04:38:00 +00:00
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:
@@ -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;
|
||||
@@ -67,18 +68,33 @@ public enum CDock implements ICDoc {
|
||||
public void endTurn() {
|
||||
Singletons.getModel().getGameState().getPhaseHandler().autoPassToCleanup();
|
||||
}
|
||||
|
||||
|
||||
private void revertLayout() {
|
||||
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)
|
||||
|
||||
@@ -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)
|
||||
@@ -147,6 +150,10 @@ public enum VDock implements IVDoc {
|
||||
public JLabel getBtnRevertLayout() {
|
||||
return btnRevertLayout;
|
||||
}
|
||||
|
||||
public JLabel getBtnOpenLayout() {
|
||||
return btnOpenLayout;
|
||||
}
|
||||
|
||||
//========= Custom class handling
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user