use Java Consumer

This commit is contained in:
Anthony Calosa
2025-08-26 06:34:59 +08:00
parent f27472d9bd
commit b24f536190
42 changed files with 298 additions and 308 deletions

View File

@@ -15,6 +15,7 @@ import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function; import java.util.function.Function;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
@@ -53,7 +54,6 @@ import forge.toolbox.FOptionPane;
import forge.toolbox.FSkin; import forge.toolbox.FSkin;
import forge.toolbox.FSkin.SkinImage; import forge.toolbox.FSkin.SkinImage;
import forge.util.BuildInfo; import forge.util.BuildInfo;
import forge.util.Callback;
import forge.util.FileUtil; import forge.util.FileUtil;
import forge.util.ImageFetcher; import forge.util.ImageFetcher;
import forge.util.OperatingSystem; import forge.util.OperatingSystem;
@@ -264,7 +264,7 @@ public class GuiDesktop implements IGuiBase {
} }
@Override @Override
public void download(final GuiDownloadService service, final Callback<Boolean> callback) { public void download(final GuiDownloadService service, final Consumer<Boolean> callback) {
new GuiDownloader(service, callback).show(); new GuiDownloader(service, callback).show();
} }

View File

@@ -37,9 +37,10 @@ import forge.toolbox.FRadioButton;
import forge.toolbox.FSkin; import forge.toolbox.FSkin;
import forge.toolbox.FTextField; import forge.toolbox.FTextField;
import forge.toolbox.JXButtonPanel; import forge.toolbox.JXButtonPanel;
import forge.util.Callback;
import net.miginfocom.swing.MigLayout; import net.miginfocom.swing.MigLayout;
import java.util.function.Consumer;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class GuiDownloader extends DefaultBoundedRangeModel { public class GuiDownloader extends DefaultBoundedRangeModel {
// Swing components // Swing components
@@ -57,7 +58,7 @@ public class GuiDownloader extends DefaultBoundedRangeModel {
SOverlayUtils.hideOverlay(); SOverlayUtils.hideOverlay();
if (callback != null) { if (callback != null) {
callback.run(btnStart.getText() == "OK"); //determine result based on whether download finished callback.accept(btnStart.getText() == "OK"); //determine result based on whether download finished
} }
} }
}; };
@@ -70,12 +71,12 @@ public class GuiDownloader extends DefaultBoundedRangeModel {
private final FRadioButton radProxyHTTP = new FRadioButton("HTTP Proxy"); private final FRadioButton radProxyHTTP = new FRadioButton("HTTP Proxy");
private final GuiDownloadService service; private final GuiDownloadService service;
private final Callback<Boolean> callback; private final Consumer<Boolean> callback;
public GuiDownloader(final GuiDownloadService service0) { public GuiDownloader(final GuiDownloadService service0) {
this(service0, null); this(service0, null);
} }
public GuiDownloader(final GuiDownloadService service0, final Callback<Boolean> callback0) { public GuiDownloader(final GuiDownloadService service0, final Consumer<Boolean> callback0) {
service = service0; service = service0;
callback = callback0; callback = callback0;

View File

@@ -53,6 +53,7 @@ import io.sentry.Sentry;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.*; import java.util.*;
import java.util.function.Consumer;
public class Forge implements ApplicationListener { public class Forge implements ApplicationListener {
private static ApplicationListener app = null; private static ApplicationListener app = null;
@@ -639,7 +640,7 @@ public class Forge implements ApplicationListener {
return; return;
} //don't allow exiting multiple times } //don't allow exiting multiple times
Callback<Boolean> callback = result -> { Consumer<Boolean> callback = result -> {
if (result) { if (result) {
exited = true; exited = true;
exitAnimation(true); exitAnimation(true);
@@ -648,7 +649,7 @@ public class Forge implements ApplicationListener {
if (silent) { if (silent) {
callback.run(true); callback.accept(true);
} else { } else {
FOptionPane.showConfirmDialog( FOptionPane.showConfirmDialog(
getLocalizer().getMessage("lblAreYouSureYouWishRestartForge"), getLocalizer().getMessage("lblRestartForge"), getLocalizer().getMessage("lblAreYouSureYouWishRestartForge"), getLocalizer().getMessage("lblRestartForge"),
@@ -665,7 +666,7 @@ public class Forge implements ApplicationListener {
options.add(getLocalizer().getMessage("lblExit")); options.add(getLocalizer().getMessage("lblExit"));
options.add(getLocalizer().getMessage("lblCancel")); options.add(getLocalizer().getMessage("lblCancel"));
Callback<Integer> callback = result -> { Consumer<Integer> callback = result -> {
if (result == 0) { if (result == 0) {
exited = true; exited = true;
exitAnimation(false); exitAnimation(false);
@@ -673,7 +674,7 @@ public class Forge implements ApplicationListener {
}; };
if (silent) { if (silent) {
callback.run(0); callback.accept(0);
} else { } else {
FOptionPane.showOptionDialog(getLocalizer().getMessage("lblAreYouSureYouWishExitForge"), "", FOptionPane.showOptionDialog(getLocalizer().getMessage("lblAreYouSureYouWishExitForge"), "",
FOptionPane.QUESTION_ICON, options, 0, callback); FOptionPane.QUESTION_ICON, options, 0, callback);

View File

@@ -32,6 +32,7 @@ import java.io.File;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function; import java.util.function.Function;
import org.jupnp.DefaultUpnpServiceConfiguration; import org.jupnp.DefaultUpnpServiceConfiguration;
@@ -282,7 +283,7 @@ public class GuiMobile implements IGuiBase {
} }
@Override @Override
public void download(final GuiDownloadService service, final Callback<Boolean> callback) { public void download(final GuiDownloadService service, final Consumer<Boolean> callback) {
new GuiDownloader(service, callback).show(); new GuiDownloader(service, callback).show();
} }

View File

@@ -1,10 +1,9 @@
package forge.adventure.data; package forge.adventure.data;
import forge.util.Callback;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.function.Consumer;
/** /**
* Dialog Data JSON loader class. * Dialog Data JSON loader class.
@@ -22,7 +21,7 @@ public class DialogData implements Serializable {
public DialogData[] options = new DialogData[0]; //List of sub-dialogs. Show up as options in the current one. public DialogData[] options = new DialogData[0]; //List of sub-dialogs. Show up as options in the current one.
public boolean isDisabled = false; public boolean isDisabled = false;
public transient Callback callback; public transient Consumer callback;
public DialogData(){} public DialogData(){}
public DialogData(DialogData other){ public DialogData(DialogData other){

View File

@@ -34,12 +34,12 @@ import forge.menu.FMenuItem;
import forge.menu.FPopupMenu; import forge.menu.FPopupMenu;
import forge.model.FModel; import forge.model.FModel;
import forge.toolbox.*; import forge.toolbox.*;
import forge.util.Callback;
import forge.util.ItemPool; import forge.util.ItemPool;
import forge.util.Localizer; import forge.util.Localizer;
import forge.util.Utils; import forge.util.Utils;
import java.util.*; import java.util.*;
import java.util.function.Consumer;
import java.util.function.Function; import java.util.function.Function;
public class AdventureDeckEditor extends FDeckEditor { public class AdventureDeckEditor extends FDeckEditor {
@@ -809,7 +809,7 @@ public class AdventureDeckEditor extends FDeckEditor {
} }
@Override @Override
public void onClose(final Callback<Boolean> canCloseCallback) { public void onClose(final Consumer<Boolean> canCloseCallback) {
if(canCloseCallback == null) { if(canCloseCallback == null) {
resolveClose(null, true); resolveClose(null, true);
return; return;
@@ -836,14 +836,14 @@ public class AdventureDeckEditor extends FDeckEditor {
resolveClose(canCloseCallback, true); resolveClose(canCloseCallback, true);
} }
private void resolveClose(final Callback<Boolean> canCloseCallback, boolean result) { private void resolveClose(final Consumer<Boolean> canCloseCallback, boolean result) {
if(result) { if(result) {
Current.player().newCards.clear(); Current.player().newCards.clear();
if(isDrafting()) if(isDrafting())
getCurrentEvent().eventStatus = AdventureEventController.EventStatus.Abandoned; getCurrentEvent().eventStatus = AdventureEventController.EventStatus.Abandoned;
} }
if(canCloseCallback != null) if(canCloseCallback != null)
canCloseCallback.run(result); canCloseCallback.accept(result);
} }
@Override @Override

View File

@@ -157,7 +157,7 @@ public class MenuScene extends UIScene {
loadDialog(option); loadDialog(option);
if (option.callback != null) { if (option.callback != null) {
option.callback.run(true); option.callback.accept(true);
} }
}); });
B.getTextraLabel().setWrap(true); //We want this to wrap in case it's a wordy choice. B.getTextraLabel().setWrap(true); //We want this to wrap in case it's a wordy choice.

View File

@@ -3,6 +3,7 @@ package forge.card;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.function.Consumer;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
@@ -20,12 +21,11 @@ import forge.toolbox.FEvent;
import forge.toolbox.FEvent.FEventHandler; import forge.toolbox.FEvent.FEventHandler;
import forge.toolbox.FOptionPane; import forge.toolbox.FOptionPane;
import forge.toolbox.FTextField; import forge.toolbox.FTextField;
import forge.util.Callback;
public class GameEntityPicker extends TabPageScreen<GameEntityPicker> { public class GameEntityPicker extends TabPageScreen<GameEntityPicker> {
private final FOptionPane optionPane; private final FOptionPane optionPane;
public GameEntityPicker(String title, Collection<? extends GameEntityView> choiceList, Collection<CardView> revealList, String revealListCaption, FImage revealListImage, boolean isOptional, final Callback<GameEntityView> callback) { public GameEntityPicker(String title, Collection<? extends GameEntityView> choiceList, Collection<CardView> revealList, String revealListCaption, FImage revealListImage, boolean isOptional, final Consumer<GameEntityView> callback) {
super(new PickerTab[] { super(new PickerTab[] {
new PickerTab(choiceList, Forge.getLocalizer().getMessage("lblChoices"), Forge.hdbuttons ? FSkinImage.HDCHOICE : FSkinImage.DECKLIST, 1), new PickerTab(choiceList, Forge.getLocalizer().getMessage("lblChoices"), Forge.hdbuttons ? FSkinImage.HDCHOICE : FSkinImage.DECKLIST, 1),
new PickerTab(revealList, revealListCaption, revealListImage, 0) new PickerTab(revealList, revealListCaption, revealListImage, 0)
@@ -36,10 +36,10 @@ public class GameEntityPicker extends TabPageScreen<GameEntityPicker> {
optionPane = new FOptionPane(null, null, title, null, this, optionPane = new FOptionPane(null, null, title, null, this,
isOptional ? ImmutableList.of(Forge.getLocalizer().getMessage("lblOK"), Forge.getLocalizer().getMessage("lblCancel")) : ImmutableList.of(Forge.getLocalizer().getMessage("lblOK")), 0, result -> { isOptional ? ImmutableList.of(Forge.getLocalizer().getMessage("lblOK"), Forge.getLocalizer().getMessage("lblCancel")) : ImmutableList.of(Forge.getLocalizer().getMessage("lblOK")), 0, result -> {
if (result == 0) { if (result == 0) {
callback.run(((PickerTab) tabPages.get(0)).list.getSelectedItem()); callback.accept(((PickerTab) tabPages.get(0)).list.getSelectedItem());
} }
else { else {
callback.run(null); callback.accept(null);
} }
}) { }) {
@Override @Override

View File

@@ -21,6 +21,7 @@ import java.text.NumberFormat;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.function.Consumer;
import com.badlogic.gdx.utils.Align; import com.badlogic.gdx.utils.Align;
@@ -55,7 +56,7 @@ public class AddBasicLandsDialog extends FDialog {
private final Deck currentDeck; private final Deck currentDeck;
private final Callback<CardPool> callback; private final Consumer<CardPool> callback;
private final FLabel lblLandSet = add(new FLabel.Builder().text(Forge.getLocalizer().getMessage("lblLandSet") + ":").font(FSkinFont.get(12)).textColor(FLabel.getInlineLabelColor()).build()); private final FLabel lblLandSet = add(new FLabel.Builder().text(Forge.getLocalizer().getMessage("lblLandSet") + ":").font(FSkinFont.get(12)).textColor(FLabel.getInlineLabelColor()).build());
private final FComboBox<CardEdition> cbLandSet = add(new FComboBox<>(IterableUtil.filter(StaticData.instance().getEditions(), CardEdition.Predicates.hasBasicLands))); private final FComboBox<CardEdition> cbLandSet = add(new FComboBox<>(IterableUtil.filter(StaticData.instance().getEditions(), CardEdition.Predicates.hasBasicLands)));
@@ -113,7 +114,7 @@ public class AddBasicLandsDialog extends FDialog {
private int nonLandCount, oldLandCount; private int nonLandCount, oldLandCount;
private CardEdition landSet; private CardEdition landSet;
public AddBasicLandsDialog(Deck deck, CardEdition defaultLandSet, final Callback<CardPool> callback0, List<CardEdition> editionOptions) { public AddBasicLandsDialog(Deck deck, CardEdition defaultLandSet, final Consumer<CardPool> callback0, List<CardEdition> editionOptions) {
super(Forge.getLocalizer().getMessage("lblAddBasicLandsAutoSuggest").replace("%s", deck.getName()), 2); super(Forge.getLocalizer().getMessage("lblAddBasicLandsAutoSuggest").replace("%s", deck.getName()), 2);
callback = callback0; callback = callback0;
@@ -149,7 +150,7 @@ public class AddBasicLandsDialog extends FDialog {
hide(); hide();
if (landsToAdd.countAll() > 0) { if (landsToAdd.countAll() > 0) {
callback.run(landsToAdd); callback.accept(landsToAdd);
} }
}); });
initButton(1, Forge.getLocalizer().getMessage("lblCancel"), e -> hide()); initButton(1, Forge.getLocalizer().getMessage("lblCancel"), e -> hide());

View File

@@ -52,7 +52,6 @@ import forge.toolbox.FEvent.FEventHandler;
import forge.toolbox.FOptionPane; import forge.toolbox.FOptionPane;
import forge.toolbox.GuiChoose; import forge.toolbox.GuiChoose;
import forge.toolbox.ListChooser; import forge.toolbox.ListChooser;
import forge.util.Callback;
import forge.util.Utils; import forge.util.Utils;
import forge.util.storage.IStorage; import forge.util.storage.IStorage;
@@ -62,7 +61,7 @@ public class FDeckChooser extends FScreen {
private FComboBox<DeckType> cmbDeckTypes; private FComboBox<DeckType> cmbDeckTypes;
private DeckType selectedDeckType; private DeckType selectedDeckType;
private boolean needRefreshOnActivate; private boolean needRefreshOnActivate;
private Callback<Deck> callback; private Consumer<Deck> callback;
private NetDeckCategory netDeckCategory; private NetDeckCategory netDeckCategory;
private NetDeckArchiveStandard NetDeckArchiveStandard; private NetDeckArchiveStandard NetDeckArchiveStandard;
private NetDeckArchivePioneer NetDeckArchivePioneer; private NetDeckArchivePioneer NetDeckArchivePioneer;
@@ -88,7 +87,7 @@ public class FDeckChooser extends FScreen {
private FOptionPane optionPane; private FOptionPane optionPane;
//Show dialog to select a deck //Show dialog to select a deck
public static void promptForDeck(String title, GameType gameType, boolean forAi, final Callback<Deck> callback) { public static void promptForDeck(String title, GameType gameType, boolean forAi, final Consumer<Deck> callback) {
FThreads.assertExecutedByEdt(true); FThreads.assertExecutedByEdt(true);
final FDeckChooser deckChooser = new FDeckChooser(gameType, forAi, null); final FDeckChooser deckChooser = new FDeckChooser(gameType, forAi, null);
@@ -230,7 +229,7 @@ public class FDeckChooser extends FScreen {
if (optionPane == null) { if (optionPane == null) {
Forge.back(); Forge.back();
if (callback != null) { if (callback != null) {
callback.run(getDeck()); callback.accept(getDeck());
} }
} }
else { else {
@@ -429,9 +428,7 @@ public class FDeckChooser extends FScreen {
//prompt to duplicate deck if deck doesn't exist already //prompt to duplicate deck if deck doesn't exist already
FOptionPane.showConfirmDialog(selectedDeckType + " " + Forge.getLocalizer().getMessage("lblCannotEditDuplicateCustomDeck").replace("%s", deck.getName()), FOptionPane.showConfirmDialog(selectedDeckType + " " + Forge.getLocalizer().getMessage("lblCannotEditDuplicateCustomDeck").replace("%s", deck.getName()),
Forge.getLocalizer().getMessage("lblDuplicateDeck"), Forge.getLocalizer().getMessage("lblDuplicate"), Forge.getLocalizer().getMessage("lblCancel"), new Callback<Boolean>() { Forge.getLocalizer().getMessage("lblDuplicateDeck"), Forge.getLocalizer().getMessage("lblDuplicate"), Forge.getLocalizer().getMessage("lblCancel"), result -> {
@Override
public void run(Boolean result) {
if (result) { if (result) {
Deck copiedDeck = (Deck)deck.getDeck().copyTo(deck.getName()); Deck copiedDeck = (Deck)deck.getDeck().copyTo(deck.getName());
IStorage<Deck> storage; IStorage<Deck> storage;
@@ -457,7 +454,6 @@ public class FDeckChooser extends FScreen {
setSelectedDeckType(fallbackType); setSelectedDeckType(fallbackType);
editDeck(new DeckProxy(copiedDeck, "Constructed", lstDecks.getGameType(), storage)); editDeck(new DeckProxy(copiedDeck, "Constructed", lstDecks.getGameType(), storage));
} }
}
}); });
break; break;
} }

View File

@@ -892,7 +892,7 @@ public class FDeckEditor extends TabPageScreen<FDeckEditor> {
saveHandler = saveHandler0; saveHandler = saveHandler0;
} }
public void save(final Callback<Boolean> callback) { public void save(final Consumer<Boolean> callback) {
IDeckController deckController = getDeckController(); IDeckController deckController = getDeckController();
if(deckController.supportsSave()) { if(deckController.supportsSave()) {
if (!StringUtils.isEmpty(deck.getName())) { if (!StringUtils.isEmpty(deck.getName())) {
@@ -907,7 +907,7 @@ public class FDeckEditor extends TabPageScreen<FDeckEditor> {
deckController.saveAs(result); deckController.saveAs(result);
if (callback != null) { if (callback != null) {
callback.run(true); callback.accept(true);
} }
}); });
}); });
@@ -916,7 +916,7 @@ public class FDeckEditor extends TabPageScreen<FDeckEditor> {
} }
if (callback != null) { if (callback != null) {
callback.run(true); callback.accept(true);
} }
} }
@@ -948,7 +948,7 @@ public class FDeckEditor extends TabPageScreen<FDeckEditor> {
); );
@Override @Override
public void onClose(final Callback<Boolean> canCloseCallback) { public void onClose(final Consumer<Boolean> canCloseCallback) {
if (getDeckController().isSaved() || !allowSave() || canCloseCallback == null) { if (getDeckController().isSaved() || !allowSave() || canCloseCallback == null) {
super.onClose(canCloseCallback); //can skip prompt if draft saved super.onClose(canCloseCallback); //can skip prompt if draft saved
return; return;
@@ -959,9 +959,9 @@ public class FDeckEditor extends TabPageScreen<FDeckEditor> {
save(canCloseCallback); save(canCloseCallback);
} else if (result == 1) { } else if (result == 1) {
getDeckController().exitWithoutSaving(); //reload if not saving changes getDeckController().exitWithoutSaving(); //reload if not saving changes
canCloseCallback.run(true); canCloseCallback.accept(true);
} else { } else {
canCloseCallback.run(false); canCloseCallback.accept(false);
} }
}); });
} }
@@ -1318,7 +1318,7 @@ public class FDeckEditor extends TabPageScreen<FDeckEditor> {
protected abstract void onCardActivated(PaperCard card); protected abstract void onCardActivated(PaperCard card);
protected abstract void buildMenu(final FDropDownMenu menu, final PaperCard card); protected abstract void buildMenu(final FDropDownMenu menu, final PaperCard card);
protected void addMoveCardMenuItem(FDropDownMenu menu, CardManagerPage source, CardManagerPage destination, final Callback<Integer> callback) { protected void addMoveCardMenuItem(FDropDownMenu menu, CardManagerPage source, CardManagerPage destination, final Consumer<Integer> callback) {
//Determine how many we can actually move. //Determine how many we can actually move.
ItemPool<PaperCard> selectedItemPool = parentScreen.getAllowedAdditions(cardManager.getSelectedItemPool(), source, destination); ItemPool<PaperCard> selectedItemPool = parentScreen.getAllowedAdditions(cardManager.getSelectedItemPool(), source, destination);
@@ -1381,7 +1381,7 @@ public class FDeckEditor extends TabPageScreen<FDeckEditor> {
final int max = maxMovable; final int max = maxMovable;
menu.addItem(new FMenuItem(label, icon, (e) -> { menu.addItem(new FMenuItem(label, icon, (e) -> {
if(max < 2) if(max < 2)
callback.run(1); callback.accept(1);
else else
GuiChoose.getInteger(prompt, 1, max, 20, callback); GuiChoose.getInteger(prompt, 1, max, 20, callback);
})); }));
@@ -1403,7 +1403,7 @@ public class FDeckEditor extends TabPageScreen<FDeckEditor> {
this.addMoveCardMenuItem(menu, source, destination, new MoveCardCallback(card, source, destination)); this.addMoveCardMenuItem(menu, source, destination, new MoveCardCallback(card, source, destination));
} }
protected static class MoveCardCallback implements Callback<Integer> { protected static class MoveCardCallback implements Consumer<Integer> {
public final PaperCard card; public final PaperCard card;
public final CardManagerPage from; public final CardManagerPage from;
public final CardManagerPage to; public final CardManagerPage to;
@@ -1414,7 +1414,7 @@ public class FDeckEditor extends TabPageScreen<FDeckEditor> {
this.to = to; this.to = to;
} }
@Override @Override
public void run(Integer result) { public void accept(Integer result) {
if(result == null || result == 0) if(result == null || result == 0)
return; return;
from.moveCard(card, to, result); from.moveCard(card, to, result);

View File

@@ -19,6 +19,7 @@ package forge.deck;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.function.Consumer;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
@@ -35,11 +36,10 @@ import forge.toolbox.FComboBox;
import forge.toolbox.FDialog; import forge.toolbox.FDialog;
import forge.toolbox.FOptionPane; import forge.toolbox.FOptionPane;
import forge.toolbox.FTextArea; import forge.toolbox.FTextArea;
import forge.util.Callback;
public class FDeckImportDialog extends FDialog { public class FDeckImportDialog extends FDialog {
private Callback<Deck> callback; private Consumer<Deck> callback;
private final FTextArea txtInput = add(new FTextArea(true)); private final FTextArea txtInput = add(new FTextArea(true));
private final FCheckBox newEditionCheck = add(new FCheckBox(Forge.getLocalizer().getMessage("lblImportLatestVersionCard"), false)); private final FCheckBox newEditionCheck = add(new FCheckBox(Forge.getLocalizer().getMessage("lblImportLatestVersionCard"), false));
@@ -121,7 +121,7 @@ public class FDeckImportDialog extends FDialog {
FThreads.invokeInEdtLater(() -> { FThreads.invokeInEdtLater(() -> {
hide(); hide();
if (callback != null) if (callback != null)
callback.run(deck); callback.accept(deck);
}); });
})); }));
initButton(1, Forge.getLocalizer().getMessage("lblCancel"), e -> hide()); initButton(1, Forge.getLocalizer().getMessage("lblCancel"), e -> hide());
@@ -165,7 +165,7 @@ public class FDeckImportDialog extends FDialog {
yearDropdown.setEnabled(enabled); yearDropdown.setEnabled(enabled);
} }
public void setCallback(Callback<Deck> callback0){ public void setCallback(Consumer<Deck> callback0){
callback = callback0; callback = callback0;
} }

View File

@@ -1,6 +1,7 @@
package forge.deck; package forge.deck;
import java.util.List; import java.util.List;
import java.util.function.Consumer;
import forge.Forge; import forge.Forge;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@@ -16,13 +17,12 @@ import forge.screens.FScreen;
import forge.screens.TabPageScreen; import forge.screens.TabPageScreen;
import forge.toolbox.FDialog; import forge.toolbox.FDialog;
import forge.toolbox.GuiChoose; import forge.toolbox.GuiChoose;
import forge.util.Callback;
public class FSideboardDialog extends FDialog { public class FSideboardDialog extends FDialog {
private final SideboardTabs tabs; private final SideboardTabs tabs;
private final Callback<List<PaperCard>> callback; private final Consumer<List<PaperCard>> callback;
public FSideboardDialog(CardPool sideboard, CardPool main, final Callback<List<PaperCard>> callback0, String message) { public FSideboardDialog(CardPool sideboard, CardPool main, final Consumer<List<PaperCard>> callback0, String message) {
super(String.format(Forge.getLocalizer().getMessage("lblUpdateMainFromSideboard"), message), 1); super(String.format(Forge.getLocalizer().getMessage("lblUpdateMainFromSideboard"), message), 1);
callback = callback0; callback = callback0;
@@ -37,7 +37,7 @@ public class FSideboardDialog extends FDialog {
public void setVisible(boolean visible0) { public void setVisible(boolean visible0) {
super.setVisible(visible0); super.setVisible(visible0);
if (!visible0) { //do callback when hidden to ensure you don't get stuck if Back pressed if (!visible0) { //do callback when hidden to ensure you don't get stuck if Back pressed
callback.run(tabs.getMainDeckPage().cardManager.getPool().toFlatList()); callback.accept(tabs.getMainDeckPage().cardManager.getPool().toFlatList());
} }
} }
@@ -104,7 +104,7 @@ public class FSideboardDialog extends FDialog {
updateCaption(); updateCaption();
} }
protected void addItem(FDropDownMenu menu, final String verb, String dest, FImage icon, final Callback<Integer> callback) { protected void addItem(FDropDownMenu menu, final String verb, String dest, FImage icon, final Consumer<Integer> callback) {
String label = verb; String label = verb;
if (!StringUtils.isEmpty(dest)) { if (!StringUtils.isEmpty(dest)) {
label += " " + dest; label += " " + dest;
@@ -113,7 +113,7 @@ public class FSideboardDialog extends FDialog {
PaperCard card = cardManager.getSelectedItem(); PaperCard card = cardManager.getSelectedItem();
int max = cardManager.getItemCount(card); int max = cardManager.getItemCount(card);
if (max == 1) { if (max == 1) {
callback.run(max); callback.accept(max);
} }
else { else {
GuiChoose.getInteger(card + " - " + verb + " " + Forge.getLocalizer().getMessage("lblHowMany"), 1, max, 20, callback); GuiChoose.getInteger(card + " - " + verb + " " + Forge.getLocalizer().getMessage("lblHowMany"), 1, max, 20, callback);

View File

@@ -12,10 +12,11 @@ import forge.screens.FScreen;
import forge.toolbox.FButton; import forge.toolbox.FButton;
import forge.toolbox.FScrollPane; import forge.toolbox.FScrollPane;
import forge.toolbox.FTextArea; import forge.toolbox.FTextArea;
import forge.util.Callback;
import forge.util.TextBounds; import forge.util.TextBounds;
import forge.util.Utils; import forge.util.Utils;
import java.util.function.Consumer;
public class BugReportDialog extends FScreen { //use screen rather than dialog so screen with bug isn't rendered public class BugReportDialog extends FScreen { //use screen rather than dialog so screen with bug isn't rendered
private static final float PADDING = Utils.scale(5); private static final float PADDING = Utils.scale(5);
private static final float BUTTON_HEIGHT = Utils.AVG_FINGER_HEIGHT * 0.75f; private static final float BUTTON_HEIGHT = Utils.AVG_FINGER_HEIGHT * 0.75f;
@@ -59,7 +60,7 @@ public class BugReportDialog extends FScreen { //use screen rather than dialog s
} }
@Override @Override
public void onClose(Callback<Boolean> canCloseCallback) { public void onClose(Consumer<Boolean> canCloseCallback) {
super.onClose(canCloseCallback); super.onClose(canCloseCallback);
isOpen = false; isOpen = false;
} }

View File

@@ -24,8 +24,8 @@ import forge.toolbox.FLabel;
import forge.toolbox.FList; import forge.toolbox.FList;
import forge.toolbox.FScrollPane; import forge.toolbox.FScrollPane;
import forge.toolbox.FTextField; import forge.toolbox.FTextField;
import forge.util.Callback;
import java.util.function.Consumer;
import java.util.function.Predicate; import java.util.function.Predicate;
@@ -211,7 +211,7 @@ public class AdvancedSearchFilter<T extends InventoryItem> extends ItemFilter<T>
} }
@Override @Override
public void onClose(Callback<Boolean> canCloseCallback) { public void onClose(Consumer<Boolean> canCloseCallback) {
onFilterChange.run(); onFilterChange.run();
super.onClose(canCloseCallback); super.onClose(canCloseCallback);
} }

View File

@@ -3,6 +3,7 @@ package forge.itemmanager.filters;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.function.Consumer;
import com.badlogic.gdx.utils.Align; import com.badlogic.gdx.utils.Align;
@@ -16,7 +17,6 @@ import forge.screens.FScreen;
import forge.screens.settings.SettingsScreen; import forge.screens.settings.SettingsScreen;
import forge.toolbox.FGroupList; import forge.toolbox.FGroupList;
import forge.toolbox.FList; import forge.toolbox.FList;
import forge.util.Callback;
import forge.util.Utils; import forge.util.Utils;
/** /**
@@ -95,7 +95,7 @@ public class ArchivedFormatSelect extends FScreen {
} }
@Override @Override
public void onClose(Callback<Boolean> canCloseCallback) { public void onClose(Consumer<Boolean> canCloseCallback) {
if (selectedFormat != null) { if (selectedFormat != null) {
if (onCloseCallBack != null) { if (onCloseCallBack != null) {
onCloseCallBack.run(); onCloseCallBack.run();

View File

@@ -5,6 +5,7 @@ import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.function.Consumer;
import com.badlogic.gdx.utils.Align; import com.badlogic.gdx.utils.Align;
@@ -24,7 +25,6 @@ import forge.toolbox.FComboBox;
import forge.toolbox.FDisplayObject; import forge.toolbox.FDisplayObject;
import forge.toolbox.FGroupList; import forge.toolbox.FGroupList;
import forge.toolbox.FList; import forge.toolbox.FList;
import forge.util.Callback;
import forge.util.TextUtil; import forge.util.TextUtil;
import forge.util.Utils; import forge.util.Utils;
@@ -199,7 +199,7 @@ public abstract class FormatFilter<T extends InventoryItem> extends ItemFilter<T
} }
@Override @Override
public void onClose(Callback<Boolean> canCloseCallback) { public void onClose(Consumer<Boolean> canCloseCallback) {
if (selectedSets.size() > 0) { if (selectedSets.size() > 0) {
List<String> setCodes = new ArrayList<>(); List<String> setCodes = new ArrayList<>();
List<CardEdition> sortedSets = new ArrayList<>(selectedSets); List<CardEdition> sortedSets = new ArrayList<>(selectedSets);

View File

@@ -1,6 +1,7 @@
package forge.screens; package forge.screens;
import java.util.List; import java.util.List;
import java.util.function.Consumer;
import com.badlogic.gdx.Input.Keys; import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Color;
@@ -23,7 +24,6 @@ import forge.toolbox.FDisplayObject;
import forge.toolbox.FEvent; import forge.toolbox.FEvent;
import forge.toolbox.FEvent.FEventHandler; import forge.toolbox.FEvent.FEventHandler;
import forge.toolbox.FLabel; import forge.toolbox.FLabel;
import forge.util.Callback;
import forge.util.Utils; import forge.util.Utils;
public abstract class FScreen extends FContainer { public abstract class FScreen extends FContainer {
@@ -66,13 +66,13 @@ public abstract class FScreen extends FContainer {
Forge.startContinuousRendering(); Forge.startContinuousRendering();
} }
public void onSwitchAway(Callback<Boolean> canSwitchCallback) { public void onSwitchAway(Consumer<Boolean> canSwitchCallback) {
canSwitchCallback.run(true); canSwitchCallback.accept(true);
} }
public void onClose(Callback<Boolean> canCloseCallback) { public void onClose(Consumer<Boolean> canCloseCallback) {
if (canCloseCallback != null) { //will be null if app exited if (canCloseCallback != null) { //will be null if app exited
canCloseCallback.run(true); canCloseCallback.accept(true);
} }
} }

View File

@@ -2,6 +2,7 @@ package forge.screens.constructed;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Consumer;
import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.utils.Align; import com.badlogic.gdx.utils.Align;
@@ -15,7 +16,6 @@ import forge.screens.FScreen;
import forge.toolbox.FDisplayObject; import forge.toolbox.FDisplayObject;
import forge.toolbox.FLabel; import forge.toolbox.FLabel;
import forge.toolbox.FScrollPane; import forge.toolbox.FScrollPane;
import forge.util.Callback;
import forge.util.MyRandom; import forge.util.MyRandom;
import forge.util.Utils; import forge.util.Utils;
@@ -28,7 +28,7 @@ public class AvatarSelector extends FScreen {
return random; return random;
} }
public static void show(final String playerName, final int currentIndex0, final List<Integer> usedAvatars0, final Callback<Integer> callback0) { public static void show(final String playerName, final int currentIndex0, final List<Integer> usedAvatars0, final Consumer<Integer> callback0) {
AvatarSelector selector = new AvatarSelector(playerName, currentIndex0, usedAvatars0, callback0); AvatarSelector selector = new AvatarSelector(playerName, currentIndex0, usedAvatars0, callback0);
Forge.openScreen(selector); Forge.openScreen(selector);
} }
@@ -38,7 +38,7 @@ public class AvatarSelector extends FScreen {
private final int currentIndex; private final int currentIndex;
private final List<Integer> usedAvatars; private final List<Integer> usedAvatars;
private final Callback<Integer> callback; private final Consumer<Integer> callback;
private final FScrollPane scroller = new FScrollPane() { private final FScrollPane scroller = new FScrollPane() {
@Override @Override
protected ScrollBounds layoutAndGetScrollBounds(float visibleWidth, float visibleHeight) { protected ScrollBounds layoutAndGetScrollBounds(float visibleWidth, float visibleHeight) {
@@ -60,7 +60,7 @@ public class AvatarSelector extends FScreen {
} }
}; };
private AvatarSelector(final String playerName, final int currentIndex0, final List<Integer> usedAvatars0, final Callback<Integer> callback0) { private AvatarSelector(final String playerName, final int currentIndex0, final List<Integer> usedAvatars0, final Consumer<Integer> callback0) {
super(Forge.getLocalizer().getMessage("lblSelectAvatarFor").replace("%s",playerName)); super(Forge.getLocalizer().getMessage("lblSelectAvatarFor").replace("%s",playerName));
currentIndex = currentIndex0; currentIndex = currentIndex0;
@@ -91,13 +91,13 @@ public class AvatarSelector extends FScreen {
if (index == -1) { if (index == -1) {
lbl.setCommand(e -> { lbl.setCommand(e -> {
callback.run(getRandomAvatar(usedAvatars)); callback.accept(getRandomAvatar(usedAvatars));
Forge.back(); Forge.back();
}); });
} }
else { else {
lbl.setCommand(e -> { lbl.setCommand(e -> {
callback.run(index); callback.accept(index);
Forge.back(); Forge.back();
}); });
} }

View File

@@ -3,6 +3,7 @@ package forge.screens.constructed;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.function.Consumer;
import forge.gamemodes.net.event.UpdateLobbyPlayerEvent; import forge.gamemodes.net.event.UpdateLobbyPlayerEvent;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@@ -41,7 +42,6 @@ import forge.toolbox.FList;
import forge.toolbox.FOptionPane; import forge.toolbox.FOptionPane;
import forge.toolbox.FTextField; import forge.toolbox.FTextField;
import forge.toolbox.FToggleSwitch; import forge.toolbox.FToggleSwitch;
import forge.util.Callback;
import forge.util.Lang; import forge.util.Lang;
import forge.util.NameGenerator; import forge.util.NameGenerator;
import forge.util.TextUtil; import forge.util.TextUtil;
@@ -1054,22 +1054,22 @@ public class PlayerPanel extends FContainer {
return new FLabel.Builder().text(title).font(LABEL_FONT).align(Align.right).build(); return new FLabel.Builder().text(title).font(LABEL_FONT).align(Align.right).build();
} }
private static final ImmutableList<String> genderOptions = ImmutableList.of(Forge.getLocalizer().getInstance().getMessage("lblMale"), Forge.getLocalizer().getInstance().getMessage("lblFemale"), Forge.getLocalizer().getInstance().getMessage("lblAny")); private static final ImmutableList<String> genderOptions = ImmutableList.of(Forge.getLocalizer().getMessage("lblMale"), Forge.getLocalizer().getMessage("lblFemale"), Forge.getLocalizer().getMessage("lblAny"));
private static final ImmutableList<String> typeOptions = ImmutableList.of(Forge.getLocalizer().getInstance().getMessage("lblFantasy"), Forge.getLocalizer().getInstance().getMessage("lblGeneric"), Forge.getLocalizer().getInstance().getMessage("lblAny")); private static final ImmutableList<String> typeOptions = ImmutableList.of(Forge.getLocalizer().getMessage("lblFantasy"), Forge.getLocalizer().getMessage("lblGeneric"), Forge.getLocalizer().getMessage("lblAny"));
private void getNewName(final Callback<String> callback) { private void getNewName(final Consumer<String> callback) {
final String title = Forge.getLocalizer().getMessage("lblGetNewRandomName"); final String title = Forge.getLocalizer().getMessage("lblGetNewRandomName");
final String message = Forge.getLocalizer().getMessage("lbltypeofName"); final String message = Forge.getLocalizer().getMessage("lbltypeofName");
final FSkinImage icon = FOptionPane.QUESTION_ICON; final FSkinImage icon = FOptionPane.QUESTION_ICON;
FOptionPane.showOptionDialog(message, title, icon, genderOptions, 2, genderIndex -> { FOptionPane.showOptionDialog(message, title, icon, genderOptions, 2, genderIndex -> {
if (genderIndex == null || genderIndex < 0) { if (genderIndex == null || genderIndex < 0) {
callback.run(null); callback.accept(null);
return; return;
} }
FOptionPane.showOptionDialog(message, title, icon, typeOptions, 2, typeIndex -> { FOptionPane.showOptionDialog(message, title, icon, typeOptions, 2, typeIndex -> {
if (typeIndex == null || typeIndex < 0) { if (typeIndex == null || typeIndex < 0) {
callback.run(null); callback.accept(null);
return; return;
} }
@@ -1078,12 +1078,12 @@ public class PlayerPanel extends FContainer {
}); });
} }
private void generateRandomName(final String gender, final String type, final List<String> usedNames, final String title, final Callback<String> callback) { private void generateRandomName(final String gender, final String type, final List<String> usedNames, final String title, final Consumer<String> callback) {
final String newName = NameGenerator.getRandomName(gender, type, usedNames); final String newName = NameGenerator.getRandomName(gender, type, usedNames);
String confirmMsg = Forge.getLocalizer().getMessage("lblconfirmName").replace("%s", newName); String confirmMsg = Forge.getLocalizer().getMessage("lblconfirmName").replace("%s", newName);
FOptionPane.showConfirmDialog(confirmMsg, title, Forge.getLocalizer().getMessage("lblUseThisName"), Forge.getLocalizer().getMessage("lblTryAgain"), true, result -> { FOptionPane.showConfirmDialog(confirmMsg, title, Forge.getLocalizer().getMessage("lblUseThisName"), Forge.getLocalizer().getMessage("lblTryAgain"), true, result -> {
if (result) { if (result) {
callback.run(newName); callback.accept(newName);
} }
else { else {
generateRandomName(gender, type, usedNames, title, callback); generateRandomName(gender, type, usedNames, title, callback);

View File

@@ -2,6 +2,7 @@ package forge.screens.constructed;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Consumer;
import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.utils.Align; import com.badlogic.gdx.utils.Align;
@@ -15,7 +16,6 @@ import forge.screens.FScreen;
import forge.toolbox.FDisplayObject; import forge.toolbox.FDisplayObject;
import forge.toolbox.FLabel; import forge.toolbox.FLabel;
import forge.toolbox.FScrollPane; import forge.toolbox.FScrollPane;
import forge.util.Callback;
import forge.util.MyRandom; import forge.util.MyRandom;
import forge.util.Utils; import forge.util.Utils;
@@ -28,7 +28,7 @@ public class SleevesSelector extends FScreen {
return random; return random;
} }
public static void show(final String playerName, final int currentIndex0, final List<Integer> usedSleeves0, final Callback<Integer> callback0) { public static void show(final String playerName, final int currentIndex0, final List<Integer> usedSleeves0, final Consumer<Integer> callback0) {
SleevesSelector selector = new SleevesSelector(playerName, currentIndex0, usedSleeves0, callback0); SleevesSelector selector = new SleevesSelector(playerName, currentIndex0, usedSleeves0, callback0);
Forge.openScreen(selector); Forge.openScreen(selector);
} }
@@ -38,7 +38,7 @@ public class SleevesSelector extends FScreen {
private final int currentIndex; private final int currentIndex;
private final List<Integer> usedSleeves; private final List<Integer> usedSleeves;
private final Callback<Integer> callback; private final Consumer<Integer> callback;
private final FScrollPane scroller = new FScrollPane() { private final FScrollPane scroller = new FScrollPane() {
@Override @Override
protected ScrollBounds layoutAndGetScrollBounds(float visibleWidth, float visibleHeight) { protected ScrollBounds layoutAndGetScrollBounds(float visibleWidth, float visibleHeight) {
@@ -60,7 +60,7 @@ public class SleevesSelector extends FScreen {
} }
}; };
private SleevesSelector(final String playerName, final int currentIndex0, final List<Integer> usedSleeves0, final Callback<Integer> callback0) { private SleevesSelector(final String playerName, final int currentIndex0, final List<Integer> usedSleeves0, final Consumer<Integer> callback0) {
super(Forge.getLocalizer().getMessage("lblSelectSleevesFroPlayer", playerName)); super(Forge.getLocalizer().getMessage("lblSelectSleevesFroPlayer", playerName));
currentIndex = currentIndex0; currentIndex = currentIndex0;
@@ -91,13 +91,13 @@ public class SleevesSelector extends FScreen {
if (index == -1) { if (index == -1) {
lbl.setCommand(e -> { lbl.setCommand(e -> {
callback.run(getRandomSleeves(usedSleeves)); callback.accept(getRandomSleeves(usedSleeves));
Forge.back(); Forge.back();
}); });
} }
else { else {
lbl.setCommand(e -> { lbl.setCommand(e -> {
callback.run(index); callback.accept(index);
Forge.back(); Forge.back();
}); });
} }

View File

@@ -9,9 +9,10 @@ import forge.localinstance.properties.ForgeConstants;
import forge.screens.LaunchScreen; import forge.screens.LaunchScreen;
import forge.toolbox.FLabel; import forge.toolbox.FLabel;
import forge.toolbox.FTextArea; import forge.toolbox.FTextArea;
import forge.util.Callback;
import forge.util.Utils; import forge.util.Utils;
import java.util.function.Consumer;
public class AdventureScreen extends LaunchScreen { public class AdventureScreen extends LaunchScreen {
private static final float PADDING = Utils.scale(10); private static final float PADDING = Utils.scale(10);
private boolean loaded = false; private boolean loaded = false;
@@ -46,7 +47,7 @@ public class AdventureScreen extends LaunchScreen {
} }
@Override @Override
public void onSwitchAway(Callback<Boolean> canSwitchCallback) { public void onSwitchAway(Consumer<Boolean> canSwitchCallback) {
if (animation != null) { if (animation != null) {
animation.stop(); animation.stop();
} }

View File

@@ -28,7 +28,6 @@ import forge.toolbox.FEvent.FEventHandler;
import forge.toolbox.FLabel; import forge.toolbox.FLabel;
import forge.toolbox.FOptionPane; import forge.toolbox.FOptionPane;
import forge.toolbox.FScrollPane; import forge.toolbox.FScrollPane;
import forge.util.Callback;
import forge.util.Utils; import forge.util.Utils;
public class HomeScreen extends FScreen { public class HomeScreen extends FScreen {
@@ -115,9 +114,7 @@ public class HomeScreen extends FScreen {
addButton(Forge.getLocalizer().getMessage("lblHelp"), e -> FThreads.invokeInEdtLater(() -> { addButton(Forge.getLocalizer().getMessage("lblHelp"), e -> FThreads.invokeInEdtLater(() -> {
try { try {
if (Forge.getDeviceAdapter().isConnectedToInternet()) { if (Forge.getDeviceAdapter().isConnectedToInternet()) {
FOptionPane.showOptionDialog("Join Discord option will open the invite link to join Forge Discord server. Forge Support option will open the Forge Support Channel.", "Choose option", FOptionPane.INFORMATION_ICON, ImmutableList.of("Join Discord", "Forge Support"), -1, new Callback<Integer>() { FOptionPane.showOptionDialog("Join Discord option will open the invite link to join Forge Discord server. Forge Support option will open the Forge Support Channel.", "Choose option", FOptionPane.INFORMATION_ICON, ImmutableList.of("Join Discord", "Forge Support"), -1, result -> {
@Override
public void run(Integer result) {
switch (result) { switch (result) {
case 0: case 0:
Gdx.net.openURI("https://discord.gg/3v9JCVr"); Gdx.net.openURI("https://discord.gg/3v9JCVr");
@@ -128,7 +125,6 @@ public class HomeScreen extends FScreen {
default: default:
break; break;
} }
}
}); });
} else { } else {
FOptionPane.showErrorDialog("Internet Connection required to open Forge Discord server", "No Internet"); FOptionPane.showErrorDialog("Internet Connection required to open Forge Discord server", "No Internet");

View File

@@ -14,7 +14,8 @@ import forge.gui.FThreads;
import forge.model.FModel; import forge.model.FModel;
import forge.screens.home.LoadGameMenu.LoadGameScreen; import forge.screens.home.LoadGameMenu.LoadGameScreen;
import forge.toolbox.FOptionPane; import forge.toolbox.FOptionPane;
import forge.util.Callback;
import java.util.function.Consumer;
public class DraftingProcessScreen extends FDeckEditor { public class DraftingProcessScreen extends FDeckEditor {
private boolean isDraftSaved; private boolean isDraftSaved;
@@ -54,7 +55,7 @@ public class DraftingProcessScreen extends FDeckEditor {
} }
@Override @Override
public void save(final Callback<Boolean> callback) { public void save(final Consumer<Boolean> callback) {
if (isDraftSaved) { //if draft itself is saved, let base class handle saving deck changes if (isDraftSaved) { //if draft itself is saved, let base class handle saving deck changes
super.save(callback); super.save(callback);
return; return;
@@ -63,7 +64,7 @@ public class DraftingProcessScreen extends FDeckEditor {
if (isQuestDraft()) { if (isQuestDraft()) {
finishSave(QuestEventDraft.DECK_NAME); finishSave(QuestEventDraft.DECK_NAME);
if (callback != null) { if (callback != null) {
callback.run(true); callback.accept(true);
} }
return; return;
} }
@@ -84,7 +85,7 @@ public class DraftingProcessScreen extends FDeckEditor {
if (result) { if (result) {
finishSave(name); finishSave(name);
if (callback != null) { if (callback != null) {
callback.run(true); callback.accept(true);
} }
} else { } else {
save(callback); //If no overwrite, recurse save(callback); //If no overwrite, recurse
@@ -96,7 +97,7 @@ public class DraftingProcessScreen extends FDeckEditor {
finishSave(name); finishSave(name);
if (callback != null) { if (callback != null) {
callback.run(true); callback.accept(true);
} }
}); });
}); });
@@ -131,7 +132,7 @@ public class DraftingProcessScreen extends FDeckEditor {
} }
@Override @Override
public void onClose(final Callback<Boolean> canCloseCallback) { public void onClose(final Consumer<Boolean> canCloseCallback) {
if (isDraftSaved || canCloseCallback == null) { if (isDraftSaved || canCloseCallback == null) {
super.onClose(canCloseCallback); //can skip prompt if draft saved super.onClose(canCloseCallback); //can skip prompt if draft saved
return; return;
@@ -140,7 +141,7 @@ public class DraftingProcessScreen extends FDeckEditor {
if (isQuestDraft()) { if (isQuestDraft()) {
FThreads.invokeInBackgroundThread(() -> { FThreads.invokeInBackgroundThread(() -> {
if (questDraftController.cancelDraft()) { if (questDraftController.cancelDraft()) {
FThreads.invokeInEdtLater(() -> canCloseCallback.run(true)); FThreads.invokeInEdtLater(() -> canCloseCallback.accept(true));
} }
}); });
return; return;

View File

@@ -5,6 +5,7 @@ import static forge.Forge.getLocalizer;
import forge.toolbox.FOptionPane; import forge.toolbox.FOptionPane;
import java.util.*; import java.util.*;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.function.Consumer;
import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector2;
import forge.adventure.scene.GameScene; import forge.adventure.scene.GameScene;
@@ -67,7 +68,6 @@ import forge.sound.MusicPlaylist;
import forge.sound.SoundSystem; import forge.sound.SoundSystem;
import forge.toolbox.FCardPanel; import forge.toolbox.FCardPanel;
import forge.toolbox.FScrollPane; import forge.toolbox.FScrollPane;
import forge.util.Callback;
public class MatchScreen extends FScreen { public class MatchScreen extends FScreen {
public static FSkinColor getBorderColor() { public static FSkinColor getBorderColor() {
@@ -314,7 +314,7 @@ public class MatchScreen extends FScreen {
} }
@Override @Override
public void onClose(Callback<Boolean> canCloseCallback) { public void onClose(Consumer<Boolean> canCloseCallback) {
MatchController.writeMatchPreferences(); MatchController.writeMatchPreferences();
SoundSystem.instance.setBackgroundMusic(MusicPlaylist.MENUS); SoundSystem.instance.setBackgroundMusic(MusicPlaylist.MENUS);
super.onClose(canCloseCallback); super.onClose(canCloseCallback);
@@ -1188,7 +1188,7 @@ public class MatchScreen extends FScreen {
} }
private void confirmUserConcedes() { private void confirmUserConcedes() {
final Callback<Boolean> callback = result -> { final Consumer<Boolean> callback = result -> {
if (result) { if (result) {
getGameController().concede(); getGameController().concede();
} }

View File

@@ -21,6 +21,7 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Consumer;
import com.badlogic.gdx.utils.Align; import com.badlogic.gdx.utils.Align;
@@ -44,7 +45,6 @@ import forge.toolbox.FDisplayObject;
import forge.toolbox.FLabel; import forge.toolbox.FLabel;
import forge.toolbox.FOptionPane; import forge.toolbox.FOptionPane;
import forge.toolbox.FScrollPane; import forge.toolbox.FScrollPane;
import forge.util.Callback;
import forge.util.CardTranslation; import forge.util.CardTranslation;
import forge.util.TextUtil; import forge.util.TextUtil;
import forge.util.Utils; import forge.util.Utils;
@@ -54,7 +54,7 @@ public class VAssignCombatDamage extends FDialog {
private static final float CARD_GAP_X = Utils.scale(10); private static final float CARD_GAP_X = Utils.scale(10);
private static final float ADD_BTN_HEIGHT = Utils.AVG_FINGER_HEIGHT * 0.75f; private static final float ADD_BTN_HEIGHT = Utils.AVG_FINGER_HEIGHT * 0.75f;
private final Callback<Map<CardView, Integer>> callback; private final Consumer<Map<CardView, Integer>> callback;
private final int totalDamageToAssign; private final int totalDamageToAssign;
private boolean attackerHasDeathtouch = false; private boolean attackerHasDeathtouch = false;
@@ -421,7 +421,7 @@ public class VAssignCombatDamage extends FDialog {
return; return;
} }
hide(); hide();
callback.run(getDamageMap()); callback.accept(getDamageMap());
} }
private int getDamageToKill(CardView source) { private int getDamageToKill(CardView source) {

View File

@@ -21,6 +21,7 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Consumer;
import com.badlogic.gdx.utils.Align; import com.badlogic.gdx.utils.Align;
@@ -45,7 +46,6 @@ import forge.toolbox.FDisplayObject;
import forge.toolbox.FLabel; import forge.toolbox.FLabel;
import forge.toolbox.FOptionPane; import forge.toolbox.FOptionPane;
import forge.toolbox.FScrollPane; import forge.toolbox.FScrollPane;
import forge.util.Callback;
import forge.util.CardTranslation; import forge.util.CardTranslation;
import forge.util.TextUtil; import forge.util.TextUtil;
import forge.util.Utils; import forge.util.Utils;
@@ -55,7 +55,7 @@ public class VAssignGenericAmount extends FDialog {
private static final float CARD_GAP_X = Utils.scale(10); private static final float CARD_GAP_X = Utils.scale(10);
private static final float ADD_BTN_HEIGHT = Utils.AVG_FINGER_HEIGHT * 0.75f; private static final float ADD_BTN_HEIGHT = Utils.AVG_FINGER_HEIGHT * 0.75f;
private final Callback<Map<Object, Integer>> callback; private final Consumer<Map<Object, Integer>> callback;
private final int totalAmountToAssign; private final int totalAmountToAssign;
private final String lblAmount; private final String lblAmount;
@@ -360,7 +360,7 @@ public class VAssignGenericAmount extends FDialog {
return; return;
} }
hide(); hide();
callback.run(getAssignedMap()); callback.accept(getAssignedMap());
} }
public Map<Object, Integer> getAssignedMap() { public Map<Object, Integer> getAssignedMap() {

View File

@@ -11,19 +11,20 @@ import forge.gamemodes.planarconquest.ConquestEvent.ChaosWheelOutcome;
import forge.toolbox.FOptionPane; import forge.toolbox.FOptionPane;
import forge.toolbox.FOverlay; import forge.toolbox.FOverlay;
import forge.util.Aggregates; import forge.util.Aggregates;
import forge.util.Callback;
import forge.util.PhysicsObject; import forge.util.PhysicsObject;
import java.util.function.Consumer;
public class ConquestChaosWheel extends FOverlay { public class ConquestChaosWheel extends FOverlay {
public static void spin(Callback<ChaosWheelOutcome> callback0) { public static void spin(Consumer<ChaosWheelOutcome> callback0) {
ConquestChaosWheel wheel = new ConquestChaosWheel(callback0); ConquestChaosWheel wheel = new ConquestChaosWheel(callback0);
wheel.show(); wheel.show();
} }
private final WheelSpinAnimation animation = new WheelSpinAnimation(); private final WheelSpinAnimation animation = new WheelSpinAnimation();
private final Callback<ChaosWheelOutcome> callback; private final Consumer<ChaosWheelOutcome> callback;
private ConquestChaosWheel(Callback<ChaosWheelOutcome> callback0) { private ConquestChaosWheel(Consumer<ChaosWheelOutcome> callback0) {
callback = callback0; callback = callback0;
} }
@@ -97,7 +98,7 @@ public class ConquestChaosWheel extends FOverlay {
@Override @Override
protected void onEnd(boolean endingAll) { protected void onEnd(boolean endingAll) {
hide(); hide();
callback.run(ChaosWheelOutcome.getWheelOutcome(getWheelRotation())); callback.accept(ChaosWheelOutcome.getWheelOutcome(getWheelRotation()));
} }
} }

View File

@@ -1,6 +1,7 @@
package forge.screens.planarconquest; package forge.screens.planarconquest;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.function.Consumer;
import java.util.function.Predicate; import java.util.function.Predicate;
import com.badlogic.gdx.utils.Align; import com.badlogic.gdx.utils.Align;
@@ -38,7 +39,6 @@ import forge.toolbox.FList;
import forge.toolbox.FList.CompactModeHandler; import forge.toolbox.FList.CompactModeHandler;
import forge.toolbox.FOptionPane; import forge.toolbox.FOptionPane;
import forge.toolbox.FTextField; import forge.toolbox.FTextField;
import forge.util.Callback;
public class ConquestCommandersScreen extends FScreen { public class ConquestCommandersScreen extends FScreen {
private static final float PADDING = FDeckChooser.PADDING; private static final float PADDING = FDeckChooser.PADDING;
@@ -83,19 +83,19 @@ public class ConquestCommandersScreen extends FScreen {
} }
@Override @Override
public void onClose(final Callback<Boolean> canCloseCallback) { public void onClose(final Consumer<Boolean> canCloseCallback) {
if (canCloseCallback == null) { return; } if (canCloseCallback == null) { return; }
final ConquestCommander commander = lstCommanders.getSelectedItem(); final ConquestCommander commander = lstCommanders.getSelectedItem();
if (commander == null) { if (commander == null) {
canCloseCallback.run(true); //shouldn't happen, but don't block closing screen if no commanders canCloseCallback.accept(true); //shouldn't happen, but don't block closing screen if no commanders
return; return;
} }
String problem = DeckFormat.PlanarConquest.getDeckConformanceProblem(commander.getDeck()); String problem = DeckFormat.PlanarConquest.getDeckConformanceProblem(commander.getDeck());
if (problem != null) { if (problem != null) {
//prevent selecting a commander with an invalid deck //prevent selecting a commander with an invalid deck
FOptionPane.showMessageDialog(Forge.getLocalizer().getMessage("lblCantSelectDeckBecause", commander.getName(), problem), Forge.getLocalizer().getMessage("lblInvalidDeck"), FOptionPane.INFORMATION_ICON, result -> canCloseCallback.run(false)); FOptionPane.showMessageDialog(Forge.getLocalizer().getMessage("lblCantSelectDeckBecause", commander.getName(), problem), Forge.getLocalizer().getMessage("lblInvalidDeck"), FOptionPane.INFORMATION_ICON, result -> canCloseCallback.accept(false));
return; return;
} }
@@ -104,7 +104,7 @@ public class ConquestCommandersScreen extends FScreen {
model.setSelectedCommander(commander); model.setSelectedCommander(commander);
model.saveData(); model.saveData();
} }
canCloseCallback.run(true); canCloseCallback.accept(true);
} }
private void refreshCommanders() { private void refreshCommanders() {

View File

@@ -10,7 +10,8 @@ import forge.localinstance.achievements.PlaneswalkerAchievements;
import forge.model.FModel; import forge.model.FModel;
import forge.screens.FScreen; import forge.screens.FScreen;
import forge.toolbox.FChoiceList; import forge.toolbox.FChoiceList;
import forge.util.Callback;
import java.util.function.Consumer;
public class ConquestPlaneswalkersScreen extends FScreen { public class ConquestPlaneswalkersScreen extends FScreen {
private static final float PADDING = FDeckChooser.PADDING; private static final float PADDING = FDeckChooser.PADDING;
@@ -39,12 +40,12 @@ public class ConquestPlaneswalkersScreen extends FScreen {
} }
@Override @Override
public void onClose(final Callback<Boolean> canCloseCallback) { public void onClose(final Consumer<Boolean> canCloseCallback) {
if (canCloseCallback == null) { return; } if (canCloseCallback == null) { return; }
final PaperCard planeswalker = lstPlaneswalkers.getSelectedItem(); final PaperCard planeswalker = lstPlaneswalkers.getSelectedItem();
if (planeswalker == null) { if (planeswalker == null) {
canCloseCallback.run(true); // Shouldn't happen, but don't block closing screen if no commanders canCloseCallback.accept(true); // Shouldn't happen, but don't block closing screen if no commanders
return; return;
} }
@@ -53,7 +54,7 @@ public class ConquestPlaneswalkersScreen extends FScreen {
model.setPlaneswalker(planeswalker); model.setPlaneswalker(planeswalker);
model.saveData(); model.saveData();
} }
canCloseCallback.run(true); canCloseCallback.accept(true);
} }
private void refreshPlaneswalkers() { private void refreshPlaneswalkers() {

View File

@@ -5,6 +5,7 @@ import java.text.NumberFormat;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.function.Consumer;
import com.badlogic.gdx.utils.Align; import com.badlogic.gdx.utils.Align;
@@ -32,7 +33,6 @@ import forge.toolbox.FDisplayObject;
import forge.toolbox.FLabel; import forge.toolbox.FLabel;
import forge.toolbox.FTextArea; import forge.toolbox.FTextArea;
import forge.toolbox.GuiChoose; import forge.toolbox.GuiChoose;
import forge.util.Callback;
import forge.util.ItemPool; import forge.util.ItemPool;
import forge.util.Utils; import forge.util.Utils;
@@ -80,7 +80,7 @@ public class QuestSpellShopScreen extends TabPageScreen<QuestSpellShopScreen> {
return true; return true;
} }
public void onClose(Callback<Boolean> canCloseCallback) { public void onClose(Consumer<Boolean> canCloseCallback) {
FModel.getQuest().save(); FModel.getQuest().save();
super.onClose(canCloseCallback); super.onClose(canCloseCallback);
} }
@@ -205,7 +205,7 @@ public class QuestSpellShopScreen extends TabPageScreen<QuestSpellShopScreen> {
final int max = itemManager.getItemCount(item); final int max = itemManager.getItemCount(item);
if (max == 0) { return; } if (max == 0) { return; }
final Callback<Integer> callback = result -> { final Consumer<Integer> callback = result -> {
if (result == null || result <= 0) { return; } if (result == null || result <= 0) { return; }
//invoke in background thread so other dialogs can be shown properly //invoke in background thread so other dialogs can be shown properly
@@ -217,7 +217,7 @@ public class QuestSpellShopScreen extends TabPageScreen<QuestSpellShopScreen> {
}); });
}; };
if (max == 1) { if (max == 1) {
callback.run(max); callback.accept(max);
} }
else { else {
GuiChoose.getInteger(item + " - " + getVerb() + " " + Forge.getLocalizer().getMessage("lblHowMany"), 1, max, 20, callback); GuiChoose.getInteger(item + " - " + getVerb() + " " + Forge.getLocalizer().getMessage("lblHowMany"), 1, max, 20, callback);

View File

@@ -36,7 +36,6 @@ import forge.toolbox.FGroupList;
import forge.toolbox.FList; import forge.toolbox.FList;
import forge.toolbox.FOptionPane; import forge.toolbox.FOptionPane;
import forge.toolbox.GuiChoose; import forge.toolbox.GuiChoose;
import forge.util.Callback;
import forge.util.FileUtil; import forge.util.FileUtil;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
@@ -61,9 +60,7 @@ public class FilesPage extends TabPage<SettingsScreen> {
Forge.getDeviceAdapter().requestFileAcces(); Forge.getDeviceAdapter().requestFileAcces();
return; return;
} }
FOptionPane.showOptionDialog(Forge.getLocalizer().getMessage("lblPlsSelectActions"), "", FOptionPane.QUESTION_ICON, ImmutableList.of(Forge.getLocalizer().getMessage("lblBackup"), Forge.getLocalizer().getMessage("lblRestore"), Forge.getLocalizer().getMessage("lblCancel")), 2, new Callback<Integer>() { FOptionPane.showOptionDialog(Forge.getLocalizer().getMessage("lblPlsSelectActions"), "", FOptionPane.QUESTION_ICON, ImmutableList.of(Forge.getLocalizer().getMessage("lblBackup"), Forge.getLocalizer().getMessage("lblRestore"), Forge.getLocalizer().getMessage("lblCancel")), 2, result -> {
@Override
public void run(Integer result) {
switch (result) { switch (result) {
case 0: case 0:
FThreads.invokeInEdtLater(() -> LoadingOverlay.show(Forge.getLocalizer().getMessage("lblBackupMsg"), true, () -> { FThreads.invokeInEdtLater(() -> LoadingOverlay.show(Forge.getLocalizer().getMessage("lblBackupMsg"), true, () -> {
@@ -92,7 +89,6 @@ public class FilesPage extends TabPage<SettingsScreen> {
default: default:
break; break;
} }
}
}); });
} }
}, 0); }, 0);
@@ -107,9 +103,7 @@ public class FilesPage extends TabPage<SettingsScreen> {
Pair<Integer, Integer> totalAudit = StaticData.instance().audit(nifSB, cniSB); Pair<Integer, Integer> totalAudit = StaticData.instance().audit(nifSB, cniSB);
String msg = nifSB.toString(); String msg = nifSB.toString();
String title = "Missing images: " + totalAudit.getLeft() + "\nUnimplemented cards: " + totalAudit.getRight(); String title = "Missing images: " + totalAudit.getLeft() + "\nUnimplemented cards: " + totalAudit.getRight();
FOptionPane.showOptionDialog(msg, title, FOptionPane.INFORMATION_ICON, ImmutableList.of(Forge.getLocalizer().getMessage("lblCopy"), Forge.getLocalizer().getMessage("lblClose")), -1, new Callback<Integer>() { FOptionPane.showOptionDialog(msg, title, FOptionPane.INFORMATION_ICON, ImmutableList.of(Forge.getLocalizer().getMessage("lblCopy"), Forge.getLocalizer().getMessage("lblClose")), -1, result -> {
@Override
public void run(Integer result) {
switch (result) { switch (result) {
case 0: case 0:
Forge.getClipboard().setContents(msg); Forge.getClipboard().setContents(msg);
@@ -117,7 +111,6 @@ public class FilesPage extends TabPage<SettingsScreen> {
default: default:
break; break;
} }
}
}); });
})); }));
} }

View File

@@ -18,6 +18,7 @@
package forge.screens.settings; package forge.screens.settings;
import java.net.Proxy; import java.net.Proxy;
import java.util.function.Consumer;
import forge.Forge; import forge.Forge;
import forge.gui.UiCommand; import forge.gui.UiCommand;
@@ -30,7 +31,6 @@ import forge.toolbox.FProgressBar;
import forge.toolbox.FRadioButton; import forge.toolbox.FRadioButton;
import forge.toolbox.FRadioButton.RadioButtonGroup; import forge.toolbox.FRadioButton.RadioButtonGroup;
import forge.toolbox.FTextField; import forge.toolbox.FTextField;
import forge.util.Callback;
import forge.util.Utils; import forge.util.Utils;
public class GuiDownloader extends FDialog { public class GuiDownloader extends FDialog {
@@ -58,12 +58,12 @@ public class GuiDownloader extends FDialog {
}; };
private final GuiDownloadService service; private final GuiDownloadService service;
private final Callback<Boolean> callback; private final Consumer<Boolean> callback;
public GuiDownloader(final GuiDownloadService service0) { public GuiDownloader(final GuiDownloadService service0) {
this(service0, null); this(service0, null);
} }
public GuiDownloader(final GuiDownloadService service0, final Callback<Boolean> callback0) { public GuiDownloader(final GuiDownloadService service0, final Consumer<Boolean> callback0) {
super(service0.getTitle(), 2); super(service0.getTitle(), 2);
service = service0; service = service0;
callback = callback0; callback = callback0;

View File

@@ -3,6 +3,7 @@ package forge.toolbox;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.function.Consumer;
import com.badlogic.gdx.Input.Keys; import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.utils.Align; import com.badlogic.gdx.utils.Align;
@@ -10,7 +11,6 @@ import com.badlogic.gdx.utils.Align;
import forge.Forge; import forge.Forge;
import forge.toolbox.FEvent.FEventHandler; import forge.toolbox.FEvent.FEventHandler;
import forge.toolbox.FEvent.FEventType; import forge.toolbox.FEvent.FEventType;
import forge.util.Callback;
// An input box for handling the order of choices. // An input box for handling the order of choices.
// Left box has the original choices // Left box has the original choices
@@ -36,11 +36,11 @@ public class DualListBox<T> extends FDialog {
private final int targetRemainingSourcesMin; private final int targetRemainingSourcesMin;
private final int targetRemainingSourcesMax; private final int targetRemainingSourcesMax;
public DualListBox(String title, int remainingSources, List<T> sourceElements, List<T> destElements, final Callback<List<T>> callback) { public DualListBox(String title, int remainingSources, List<T> sourceElements, List<T> destElements, final Consumer<List<T>> callback) {
this(title, remainingSources, remainingSources, sourceElements, destElements, callback); this(title, remainingSources, remainingSources, sourceElements, destElements, callback);
} }
public DualListBox(String title, int remainingSourcesMin, int remainingSourcesMax, List<T> sourceElements, List<T> destElements, final Callback<List<T>> callback) { public DualListBox(String title, int remainingSourcesMin, int remainingSourcesMax, List<T> sourceElements, List<T> destElements, final Consumer<List<T>> callback) {
super(title, 2); super(title, 2);
targetRemainingSourcesMin = remainingSourcesMin; targetRemainingSourcesMin = remainingSourcesMin;
targetRemainingSourcesMax = remainingSourcesMax; targetRemainingSourcesMax = remainingSourcesMax;
@@ -101,7 +101,7 @@ public class DualListBox<T> extends FDialog {
final FEventHandler onAccept = e -> { final FEventHandler onAccept = e -> {
hide(); hide();
callback.run(destList.extractListData()); callback.accept(destList.extractListData());
}; };
// Dual List Complete Buttons // Dual List Complete Buttons

View File

@@ -2,6 +2,7 @@ package forge.toolbox;
import java.io.File; import java.io.File;
import java.io.FilenameFilter; import java.io.FilenameFilter;
import java.util.function.Consumer;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@@ -15,7 +16,6 @@ import forge.assets.FSkinFont;
import forge.assets.FSkinImage; import forge.assets.FSkinImage;
import forge.menu.FMenuItem; import forge.menu.FMenuItem;
import forge.menu.FPopupMenu; import forge.menu.FPopupMenu;
import forge.util.Callback;
import forge.util.FileUtil; import forge.util.FileUtil;
import forge.util.Utils; import forge.util.Utils;
@@ -28,25 +28,25 @@ public class FFileChooser extends FDialog {
GetDirectory GetDirectory
} }
public static void show(String title0, ChoiceType choiceType0, Callback<String> callback0) { public static void show(String title0, ChoiceType choiceType0, Consumer<String> callback0) {
show(title0, choiceType0, "", "", callback0); show(title0, choiceType0, "", "", callback0);
} }
public static void show(String title0, ChoiceType choiceType0, String defaultFilename0, Callback<String> callback0) { public static void show(String title0, ChoiceType choiceType0, String defaultFilename0, Consumer<String> callback0) {
show(title0, choiceType0, defaultFilename0, "", callback0); show(title0, choiceType0, defaultFilename0, "", callback0);
} }
public static void show(String title0, ChoiceType choiceType0, String defaultFilename0, String baseDir0, Callback<String> callback0) { public static void show(String title0, ChoiceType choiceType0, String defaultFilename0, String baseDir0, Consumer<String> callback0) {
FFileChooser dialog = new FFileChooser(title0, choiceType0, defaultFilename0, baseDir0, callback0); FFileChooser dialog = new FFileChooser(title0, choiceType0, defaultFilename0, baseDir0, callback0);
dialog.show(); dialog.show();
} }
private final ChoiceType choiceType; private final ChoiceType choiceType;
private final String baseDir; private final String baseDir;
private final Callback<String> callback; private final Consumer<String> callback;
private final FList<File> lstFiles = add(new FileList()); private final FList<File> lstFiles = add(new FileList());
private final FTextField txtFilename = add(new FilenameField()); private final FTextField txtFilename = add(new FilenameField());
private FFileChooser(String title0, ChoiceType choiceType0, String defaultFilename0, String baseDir0, Callback<String> callback0) { private FFileChooser(String title0, ChoiceType choiceType0, String defaultFilename0, String baseDir0, Consumer<String> callback0) {
super(title0, 3); super(title0, 3);
choiceType = choiceType0; choiceType = choiceType0;
if (choiceType == ChoiceType.GetDirectory) { if (choiceType == ChoiceType.GetDirectory) {
@@ -195,7 +195,7 @@ public class FFileChooser extends FDialog {
if (returnDirectory) { if (returnDirectory) {
filename += File.separator; //re-append separator if returning directory filename += File.separator; //re-append separator if returning directory
} }
callback.run(filename); callback.accept(filename);
} }
private void back() { private void back() {

View File

@@ -1,6 +1,7 @@
package forge.toolbox; package forge.toolbox;
import java.util.List; import java.util.List;
import java.util.function.Consumer;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@@ -21,7 +22,6 @@ import forge.card.CardZoom;
import forge.game.card.CardView; import forge.game.card.CardView;
import forge.localinstance.skin.FSkinProp; import forge.localinstance.skin.FSkinProp;
import forge.screens.match.views.VPrompt; import forge.screens.match.views.VPrompt;
import forge.util.Callback;
import forge.util.Utils; import forge.util.Utils;
import forge.util.WaitCallback; import forge.util.WaitCallback;
@@ -61,40 +61,40 @@ public class FOptionPane extends FDialog {
showOptionDialog(message, messageFont, title, icon, ImmutableList.of(Forge.getLocalizer().getMessage("lblOK")), 0, null); showOptionDialog(message, messageFont, title, icon, ImmutableList.of(Forge.getLocalizer().getMessage("lblOK")), 0, null);
} }
public static void showMessageDialog(final String message, final String title, final FImage icon, final Callback<Integer> callback) { public static void showMessageDialog(final String message, final String title, final FImage icon, final Consumer<Integer> callback) {
showOptionDialog(message, title, icon, ImmutableList.of(Forge.getLocalizer().getMessage("lblOK")), 0, callback); showOptionDialog(message, title, icon, ImmutableList.of(Forge.getLocalizer().getMessage("lblOK")), 0, callback);
} }
public static void showConfirmDialog(final String message, final Callback<Boolean> callback) { public static void showConfirmDialog(final String message, final Consumer<Boolean> callback) {
showConfirmDialog(message, "", callback); showConfirmDialog(message, "", callback);
} }
public static void showConfirmDialog(final String message, final String title, final Callback<Boolean> callback) { public static void showConfirmDialog(final String message, final String title, final Consumer<Boolean> callback) {
showConfirmDialog(message, title, Forge.getLocalizer().getMessage("lblYes"), Forge.getLocalizer().getMessage("lblNo"), true, callback); showConfirmDialog(message, title, Forge.getLocalizer().getMessage("lblYes"), Forge.getLocalizer().getMessage("lblNo"), true, callback);
} }
public static void showConfirmDialog(final String message, final String title, final boolean defaultYes, final Callback<Boolean> callback) { public static void showConfirmDialog(final String message, final String title, final boolean defaultYes, final Consumer<Boolean> callback) {
showConfirmDialog(message, title, Forge.getLocalizer().getMessage("lblYes"), Forge.getLocalizer().getMessage("lblNo"), defaultYes, callback); showConfirmDialog(message, title, Forge.getLocalizer().getMessage("lblYes"), Forge.getLocalizer().getMessage("lblNo"), defaultYes, callback);
} }
public static void showConfirmDialog(final String message, final String title, final String yesButtonText, final String noButtonText, final Callback<Boolean> callback) { public static void showConfirmDialog(final String message, final String title, final String yesButtonText, final String noButtonText, final Consumer<Boolean> callback) {
showConfirmDialog(message, title, yesButtonText, noButtonText, true, callback); showConfirmDialog(message, title, yesButtonText, noButtonText, true, callback);
} }
public static void showConfirmDialog(final String message, final String title, final String yesButtonText, final String noButtonText, final boolean defaultYes, final Callback<Boolean> callback) { public static void showConfirmDialog(final String message, final String title, final String yesButtonText, final String noButtonText, final boolean defaultYes, final Consumer<Boolean> callback) {
final List<String> options = ImmutableList.of(yesButtonText, noButtonText); final List<String> options = ImmutableList.of(yesButtonText, noButtonText);
showOptionDialog(message, title, QUESTION_ICON, options, defaultYes ? 0 : 1, result -> callback.run(result == 0)); showOptionDialog(message, title, QUESTION_ICON, options, defaultYes ? 0 : 1, result -> callback.accept(result == 0));
} }
public static void showOptionDialog(final String message, final String title, final FImage icon, final List<String> options, final Callback<Integer> callback) { public static void showOptionDialog(final String message, final String title, final FImage icon, final List<String> options, final Consumer<Integer> callback) {
showOptionDialog(message, title, icon, options, 0, callback); showOptionDialog(message, title, icon, options, 0, callback);
} }
public static void showOptionDialog(final String message, final String title, final FImage icon, final List<String> options, final int defaultOption, final Callback<Integer> callback) { public static void showOptionDialog(final String message, final String title, final FImage icon, final List<String> options, final int defaultOption, final Consumer<Integer> callback) {
showOptionDialog(message, null, title, icon, options, defaultOption, callback); showOptionDialog(message, null, title, icon, options, defaultOption, callback);
} }
public static void showOptionDialog(final String message, final FSkinFont messageFont, final String title, final FImage icon, final List<String> options, final int defaultOption, final Callback<Integer> callback) { public static void showOptionDialog(final String message, final FSkinFont messageFont, final String title, final FImage icon, final List<String> options, final int defaultOption, final Consumer<Integer> callback) {
final FOptionPane optionPane = new FOptionPane(message, messageFont, title, icon, null, options, defaultOption, callback); final FOptionPane optionPane = new FOptionPane(message, messageFont, title, icon, null, options, defaultOption, callback);
optionPane.show(); optionPane.show();
} }
@@ -108,7 +108,7 @@ public class FOptionPane extends FDialog {
}.invokeAndWait(); }.invokeAndWait();
} }
public static void showCardOptionDialog(final CardView card, String message, String title, FImage icon, final List<String> options, final int defaultOption, final Callback<Integer> callback) { public static void showCardOptionDialog(final CardView card, String message, String title, FImage icon, final List<String> options, final int defaultOption, final Consumer<Integer> callback) {
final FDisplayObject cardDisplay; final FDisplayObject cardDisplay;
if (card != null) { if (card != null) {
cardDisplay = new FDisplayObject() { cardDisplay = new FDisplayObject() {
@@ -149,13 +149,13 @@ public class FOptionPane extends FDialog {
optionPane.show(); optionPane.show();
} }
public static void showInputDialog(final String title, final Callback<String> callback) { public static void showInputDialog(final String title, final Consumer<String> callback) {
showInputDialog(null, title, "", null, callback, false); showInputDialog(null, title, "", null, callback, false);
} }
public static <T> void showInputDialog(final String title, final T initialInput, final Callback<T> callback) { public static <T> void showInputDialog(final String title, final T initialInput, final Consumer<T> callback) {
showInputDialog(null, title, initialInput, null, callback, false); showInputDialog(null, title, initialInput, null, callback, false);
} }
public static <T> void showInputDialog(final String message, final String title, final T initialInput, final List<T> inputOptions, final Callback<T> callback, final boolean isNumeric) { public static <T> void showInputDialog(final String message, final String title, final T initialInput, final List<T> inputOptions, final Consumer<T> callback, final boolean isNumeric) {
final FDisplayObject inputField; final FDisplayObject inputField;
final FTextField txtInput; final FTextField txtInput;
final FComboBox<T> cbInput; final FComboBox<T> cbInput;
@@ -187,12 +187,12 @@ public class FOptionPane extends FDialog {
final FOptionPane optionPane = new FOptionPane(message, null, title, null, container, ImmutableList.of(Forge.getLocalizer().getMessage("lblOK"), Forge.getLocalizer().getMessage("lblCancel")), 0, result -> { final FOptionPane optionPane = new FOptionPane(message, null, title, null, container, ImmutableList.of(Forge.getLocalizer().getMessage("lblOK"), Forge.getLocalizer().getMessage("lblCancel")), 0, result -> {
if (result == 0) { if (result == 0) {
if (txtInput != null) { if (txtInput != null) {
callback.run((T)txtInput.getText()); callback.accept((T)txtInput.getText());
} else { } else {
callback.run(cbInput.getSelectedItem()); callback.accept(cbInput.getSelectedItem());
} }
} else { } else {
callback.run(null); callback.accept(null);
} }
}) { }) {
@Override @Override
@@ -219,11 +219,11 @@ public class FOptionPane extends FDialog {
private final FLabel lblIcon; private final FLabel lblIcon;
private final FTextArea prompt; private final FTextArea prompt;
protected final FDisplayObject displayObj; protected final FDisplayObject displayObj;
private final Callback<Integer> callback; private final Consumer<Integer> callback;
private final int defaultOption; private final int defaultOption;
private final boolean centerIcon; private final boolean centerIcon;
public FOptionPane(final String message, final FSkinFont messageFont, final String title, final FImage icon, final FDisplayObject displayObj0, final List<String> options, final int defaultOption0, final Callback<Integer> callback0) { public FOptionPane(final String message, final FSkinFont messageFont, final String title, final FImage icon, final FDisplayObject displayObj0, final List<String> options, final int defaultOption0, final Consumer<Integer> callback0) {
super(title, options.size()); super(title, options.size());
if (icon != null) { if (icon != null) {
@@ -267,7 +267,7 @@ public class FOptionPane extends FDialog {
public void setResult(final int option) { public void setResult(final int option) {
hide(); hide();
if (callback != null) { if (callback != null) {
callback.run(option); callback.accept(option);
} }
} }

View File

@@ -5,6 +5,7 @@ import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function; import java.util.function.Function;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
@@ -12,7 +13,6 @@ import forge.Forge;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import forge.game.card.CardView; import forge.game.card.CardView;
import forge.util.Callback;
public class GuiChoose { public class GuiChoose {
@@ -30,20 +30,20 @@ public class GuiChoose {
* getChoices. * getChoices.
* @see #getChoices(String, int, int, Object...) * @see #getChoices(String, int, int, Object...)
*/ */
public static <T> void oneOrNone(final String message, final T[] choices, final Callback<T> callback) { public static <T> void oneOrNone(final String message, final T[] choices, final Consumer<T> callback) {
if ((choices == null) || (choices.length == 0)) { if ((choices == null) || (choices.length == 0)) {
callback.run(null); callback.accept(null);
return; return;
} }
getChoices(message, 0, 1, choices, result -> callback.run(result.isEmpty() ? null : result.get(0))); getChoices(message, 0, 1, choices, result -> callback.accept(result.isEmpty() ? null : result.get(0)));
} }
public static <T> void oneOrNone(final String message, final Collection<T> choices, final Callback<T> callback) { public static <T> void oneOrNone(final String message, final Collection<T> choices, final Consumer<T> callback) {
if ((choices == null) || choices.isEmpty()) { if ((choices == null) || choices.isEmpty()) {
callback.run(null); callback.accept(null);
return; return;
} }
getChoices(message, 0, 1, choices, result -> callback.run(result.isEmpty() ? null : result.get(0))); getChoices(message, 0, 1, choices, result -> callback.accept(result.isEmpty() ? null : result.get(0)));
} // getChoiceOptional(String,T...) } // getChoiceOptional(String,T...)
// returned Object will never be null // returned Object will never be null
@@ -60,39 +60,39 @@ public class GuiChoose {
* a T object. * a T object.
* @return a T object. * @return a T object.
*/ */
public static <T> void one(final String message, final T[] choices, final Callback<T> callback) { public static <T> void one(final String message, final T[] choices, final Consumer<T> callback) {
if (choices == null || choices.length == 0) { if (choices == null || choices.length == 0) {
callback.run(null); callback.accept(null);
return; return;
} }
if (choices.length == 1) { if (choices.length == 1) {
callback.run(choices[0]); callback.accept(choices[0]);
return; return;
} }
getChoices(message, 1, 1, choices, result -> { getChoices(message, 1, 1, choices, result -> {
assert result.size() == 1; assert result.size() == 1;
callback.run(result.get(0)); callback.accept(result.get(0));
}); });
} }
public static <T> void one(final String message, final Collection<T> choices, final Callback<T> callback) { public static <T> void one(final String message, final Collection<T> choices, final Consumer<T> callback) {
if (choices == null || choices.isEmpty()) { if (choices == null || choices.isEmpty()) {
callback.run(null); callback.accept(null);
return; return;
} }
if (choices.size() == 1) { if (choices.size() == 1) {
callback.run(Iterables.getFirst(choices, null)); callback.accept(Iterables.getFirst(choices, null));
return; return;
} }
getChoices(message, 1, 1, choices, result -> { getChoices(message, 1, 1, choices, result -> {
assert result.size() == 1; assert result.size() == 1;
callback.run(result.get(0)); callback.accept(result.get(0));
}); });
} }
public static <T> void noneOrMany(final String message, final Collection<T> choices, final Callback<List<T>> callback) { public static <T> void noneOrMany(final String message, final Collection<T> choices, final Consumer<List<T>> callback) {
getChoices(message, 0, choices.size(), choices, null, null, callback); getChoices(message, 0, choices.size(), choices, null, null, callback);
} }
@@ -110,15 +110,15 @@ public class GuiChoose {
} }
// Get Integer in range // Get Integer in range
public static void getInteger(final String message, final Callback<Integer> callback) { public static void getInteger(final String message, final Consumer<Integer> callback) {
getInteger(message, 0, Integer.MAX_VALUE, callback); getInteger(message, 0, Integer.MAX_VALUE, callback);
} }
public static void getInteger(final String message, int min, final Callback<Integer> callback) { public static void getInteger(final String message, int min, final Consumer<Integer> callback) {
getInteger(message, min, Integer.MAX_VALUE, callback); getInteger(message, min, Integer.MAX_VALUE, callback);
} }
public static void getInteger(final String message, int min, int max, final Callback<Integer> callback) { public static void getInteger(final String message, int min, int max, final Consumer<Integer> callback) {
if (max <= min) { //just return min if max <= min if (max <= min) { //just return min if max <= min
callback.run(min); callback.accept(min);
return; return;
} }
@@ -139,9 +139,9 @@ public class GuiChoose {
} }
oneOrNone(message, choices, callback); oneOrNone(message, choices, callback);
} }
public static void getInteger(final String message, final int min, final int max, final int cutoff, final Callback<Integer> callback) { public static void getInteger(final String message, final int min, final int max, final int cutoff, final Consumer<Integer> callback) {
if (max <= min || cutoff < min) { //just return min if max <= min or cutoff < min if (max <= min || cutoff < min) { //just return min if max <= min or cutoff < min
callback.run(min); callback.accept(min);
return; return;
} }
@@ -158,7 +158,7 @@ public class GuiChoose {
oneOrNone(message, choices, choice -> { oneOrNone(message, choices, choice -> {
if (choice instanceof Integer || choice == null) { if (choice instanceof Integer || choice == null) {
callback.run((Integer)choice); callback.accept((Integer)choice);
return; return;
} }
@@ -180,16 +180,16 @@ public class GuiChoose {
}); });
} }
private static void getNumberInput(final String prompt, final String message, final int min, final int max, final Callback<Integer> callback) { private static void getNumberInput(final String prompt, final String message, final int min, final int max, final Consumer<Integer> callback) {
FOptionPane.showInputDialog(prompt, message, result -> { FOptionPane.showInputDialog(prompt, message, result -> {
if (result == null) { //that is 'cancel' if (result == null) { //that is 'cancel'
callback.run(null); callback.accept(null);
return; return;
} }
if (StringUtils.isNumeric(result)) { if (StringUtils.isNumeric(result)) {
int val = Integer.parseInt(result); int val = Integer.parseInt(result);
if (val >= min && val <= max) { if (val >= min && val <= max) {
callback.run(val); callback.accept(val);
return; return;
} }
} }
@@ -200,18 +200,18 @@ public class GuiChoose {
} }
// returned Object will never be null // returned Object will never be null
public static <T> void getChoices(final String message, final int min, final int max, final T[] choices, final Callback<List<T>> callback) { public static <T> void getChoices(final String message, final int min, final int max, final T[] choices, final Consumer<List<T>> callback) {
getChoices(message, min, max, Arrays.asList(choices), null, null, callback); getChoices(message, min, max, Arrays.asList(choices), null, null, callback);
} }
public static <T> void getChoices(final String message, final int min, final int max, final Collection<T> choices, final Callback<List<T>> callback) { public static <T> void getChoices(final String message, final int min, final int max, final Collection<T> choices, final Consumer<List<T>> callback) {
getChoices(message, min, max, choices, null, null, callback); getChoices(message, min, max, choices, null, null, callback);
} }
public static <T> void getChoices(final String message, final int min, final int max, final Collection<T> choices, final Collection<T> selected, final Function<T, String> display, final Callback<List<T>> callback) { public static <T> void getChoices(final String message, final int min, final int max, final Collection<T> choices, final Collection<T> selected, final Function<T, String> display, final Consumer<List<T>> callback) {
if (choices == null || choices.isEmpty()) { if (choices == null || choices.isEmpty()) {
if (min == 0) { if (min == 0) {
callback.run(new ArrayList<>()); callback.accept(new ArrayList<>());
return; return;
} }
throw new RuntimeException("choice required from empty list"); throw new RuntimeException("choice required from empty list");
@@ -221,22 +221,22 @@ public class GuiChoose {
c.show(selected, false); c.show(selected, false);
} }
public static <T> void many(final String title, final String topCaption, int cnt, final List<T> sourceChoices, CardView referenceCard, final Callback<List<T>> callback) { public static <T> void many(final String title, final String topCaption, int cnt, final List<T> sourceChoices, CardView referenceCard, final Consumer<List<T>> callback) {
order(title, topCaption, cnt, cnt, sourceChoices, null, referenceCard, callback); order(title, topCaption, cnt, cnt, sourceChoices, null, referenceCard, callback);
} }
public static <T> void many(final String title, final String topCaption, int min, int max, final List<T> sourceChoices, CardView referenceCard, final Callback<List<T>> callback) { public static <T> void many(final String title, final String topCaption, int min, int max, final List<T> sourceChoices, CardView referenceCard, final Consumer<List<T>> callback) {
int m1 = max >= 0 ? sourceChoices.size() - max : -1; int m1 = max >= 0 ? sourceChoices.size() - max : -1;
int m2 = min >= 0 ? sourceChoices.size() - min : -1; int m2 = min >= 0 ? sourceChoices.size() - min : -1;
order(title, topCaption, m1, m2, sourceChoices, null, referenceCard, callback); order(title, topCaption, m1, m2, sourceChoices, null, referenceCard, callback);
} }
public static <T> void order(final String title, final String top, final List<T> sourceChoices, CardView referenceCard, final Callback<List<T>> callback) { public static <T> void order(final String title, final String top, final List<T> sourceChoices, CardView referenceCard, final Consumer<List<T>> callback) {
order(title, top, 0, 0, sourceChoices, null, referenceCard, callback); order(title, top, 0, 0, sourceChoices, null, referenceCard, callback);
} }
public static <T> void order(final String title, final String top, final int remainingObjectsMin, final int remainingObjectsMax, public static <T> void order(final String title, final String top, final int remainingObjectsMin, final int remainingObjectsMax,
final List<T> sourceChoices, final List<T> destChoices, final CardView referenceCard, final Callback<List<T>> callback) { final List<T> sourceChoices, final List<T> destChoices, final CardView referenceCard, final Consumer<List<T>> callback) {
// An input box for handling the order of choices. // An input box for handling the order of choices.
DualListBox<T> dual = new DualListBox<>(title, remainingObjectsMin, remainingObjectsMax, sourceChoices, destChoices, callback); DualListBox<T> dual = new DualListBox<>(title, remainingObjectsMin, remainingObjectsMax, sourceChoices, destChoices, callback);
dual.setSecondColumnLabelText(top); dual.setSecondColumnLabelText(top);
@@ -244,61 +244,61 @@ public class GuiChoose {
} }
// If comparer is NULL, T has to be comparable. Otherwise you'll get an exception from inside the Arrays.sort() routine // If comparer is NULL, T has to be comparable. Otherwise you'll get an exception from inside the Arrays.sort() routine
public static <T> void sortedOneOrNone(final String message, final T[] choices, Comparator<T> comparer, final Callback<T> callback) { public static <T> void sortedOneOrNone(final String message, final T[] choices, Comparator<T> comparer, final Consumer<T> callback) {
if ((choices == null) || (choices.length == 0)) { if ((choices == null) || (choices.length == 0)) {
callback.run(null); callback.accept(null);
return; return;
} }
sortedGetChoices(message, 0, 1, choices, comparer, result -> callback.run(result.isEmpty() ? null : result.get(0))); sortedGetChoices(message, 0, 1, choices, comparer, result -> callback.accept(result.isEmpty() ? null : result.get(0)));
} }
// If comparer is NULL, T has to be comparable. Otherwise you'll get an exception from inside the Arrays.sort() routine // If comparer is NULL, T has to be comparable. Otherwise you'll get an exception from inside the Arrays.sort() routine
public static <T> void sortedOneOrNone(final String message, final List<T> choices, Comparator<T> comparer, final Callback<T> callback) { public static <T> void sortedOneOrNone(final String message, final List<T> choices, Comparator<T> comparer, final Consumer<T> callback) {
if ((choices == null) || choices.isEmpty()) { if ((choices == null) || choices.isEmpty()) {
callback.run(null); callback.accept(null);
return; return;
} }
sortedGetChoices(message, 0, 1, choices, comparer, result -> callback.run(result.isEmpty() ? null : result.get(0))); sortedGetChoices(message, 0, 1, choices, comparer, result -> callback.accept(result.isEmpty() ? null : result.get(0)));
} }
// If comparer is NULL, T has to be comparable. Otherwise you'll get an exception from inside the Arrays.sort() routine // If comparer is NULL, T has to be comparable. Otherwise you'll get an exception from inside the Arrays.sort() routine
public static <T> void sortedOne(final String message, final T[] choices, Comparator<T> comparer, final Callback<T> callback) { public static <T> void sortedOne(final String message, final T[] choices, Comparator<T> comparer, final Consumer<T> callback) {
if ((choices == null) || (choices.length == 0)) { if ((choices == null) || (choices.length == 0)) {
callback.run(null); callback.accept(null);
return; return;
} }
sortedGetChoices(message, 1, 1, choices, comparer, result -> { sortedGetChoices(message, 1, 1, choices, comparer, result -> {
assert result.size() == 1; assert result.size() == 1;
callback.run(result.get(0)); callback.accept(result.get(0));
}); });
} }
// If comparer is NULL, T has to be comparable. Otherwise you'll get an exception from inside the Arrays.sort() routine // If comparer is NULL, T has to be comparable. Otherwise you'll get an exception from inside the Arrays.sort() routine
public static <T> void sortedOne(final String message, final List<T> choices, Comparator<T> comparer, final Callback<T> callback) { public static <T> void sortedOne(final String message, final List<T> choices, Comparator<T> comparer, final Consumer<T> callback) {
if ((choices == null) || (choices.size() == 0)) { if ((choices == null) || (choices.size() == 0)) {
callback.run(null); callback.accept(null);
return; return;
} }
sortedGetChoices(message, 1, 1, choices, comparer, result -> { sortedGetChoices(message, 1, 1, choices, comparer, result -> {
assert result.size() == 1; assert result.size() == 1;
callback.run(result.get(0)); callback.accept(result.get(0));
}); });
} }
// If comparer is NULL, T has to be comparable. Otherwise you'll get an exception from inside the Arrays.sort() routine // If comparer is NULL, T has to be comparable. Otherwise you'll get an exception from inside the Arrays.sort() routine
public static <T> void sortedNoneOrMany(final String message, final List<T> choices, Comparator<T> comparer, final Callback<List<T>> callback) { public static <T> void sortedNoneOrMany(final String message, final List<T> choices, Comparator<T> comparer, final Consumer<List<T>> callback) {
sortedGetChoices(message, 0, choices.size(), choices, comparer, callback); sortedGetChoices(message, 0, choices.size(), choices, comparer, callback);
} }
// If comparer is NULL, T has to be comparable. Otherwise you'll get an exception from inside the Arrays.sort() routine // If comparer is NULL, T has to be comparable. Otherwise you'll get an exception from inside the Arrays.sort() routine
public static <T> void sortedGetChoices(final String message, final int min, final int max, final T[] choices, Comparator<T> comparer, final Callback<List<T>> callback) { public static <T> void sortedGetChoices(final String message, final int min, final int max, final T[] choices, Comparator<T> comparer, final Consumer<List<T>> callback) {
// You may create a copy of source array if callers expect the collection to be unchanged // You may create a copy of source array if callers expect the collection to be unchanged
Arrays.sort(choices, comparer); Arrays.sort(choices, comparer);
getChoices(message, min, max, choices, callback); getChoices(message, min, max, choices, callback);
} }
// If comparer is NULL, T has to be comparable. Otherwise you'll get an exception from inside the Arrays.sort() routine // If comparer is NULL, T has to be comparable. Otherwise you'll get an exception from inside the Arrays.sort() routine
public static <T> void sortedGetChoices(final String message, final int min, final int max, final List<T> choices, Comparator<T> comparer, final Callback<List<T>> callback) { public static <T> void sortedGetChoices(final String message, final int min, final int max, final List<T> choices, Comparator<T> comparer, final Consumer<List<T>> callback) {
// You may create a copy of source list if callers expect the collection to be unchanged // You may create a copy of source list if callers expect the collection to be unchanged
choices.sort(comparer); choices.sort(comparer);
getChoices(message, min, max, choices, callback); getChoices(message, min, max, choices, callback);

View File

@@ -1,13 +1,13 @@
package forge.toolbox; package forge.toolbox;
import java.util.List; import java.util.List;
import java.util.function.Consumer;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import forge.game.card.CardView; import forge.game.card.CardView;
import forge.util.Callback;
/** /**
* Holds player interactions using standard windows * Holds player interactions using standard windows
@@ -15,21 +15,21 @@ import forge.util.Callback;
public class GuiDialog { public class GuiDialog {
private static final ImmutableList<String> defaultConfirmOptions = ImmutableList.of("Yes", "No"); private static final ImmutableList<String> defaultConfirmOptions = ImmutableList.of("Yes", "No");
public static void confirm(final CardView c, final String question, final Callback<Boolean> callback) { public static void confirm(final CardView c, final String question, final Consumer<Boolean> callback) {
GuiDialog.confirm(c, question, true, null, callback); GuiDialog.confirm(c, question, true, null, callback);
} }
public static void confirm(final CardView c, final String question, final boolean defaultChoice, final Callback<Boolean> callback) { public static void confirm(final CardView c, final String question, final boolean defaultChoice, final Consumer<Boolean> callback) {
GuiDialog.confirm(c, question, defaultChoice, null, callback); GuiDialog.confirm(c, question, defaultChoice, null, callback);
} }
public static void confirm(final CardView c, final String question, final List<String> options, final Callback<Boolean> callback) { public static void confirm(final CardView c, final String question, final List<String> options, final Consumer<Boolean> callback) {
GuiDialog.confirm(c, question, true, options, callback); GuiDialog.confirm(c, question, true, options, callback);
} }
public static void confirm(final CardView c, final String question, final boolean defaultIsYes, final List<String> options, final Callback<Boolean> callback) { public static void confirm(final CardView c, final String question, final boolean defaultIsYes, final List<String> options, final Consumer<Boolean> callback) {
final String title = c == null ? "Question" : c + " - Ability"; final String title = c == null ? "Question" : c + " - Ability";
String questionToUse = StringUtils.isBlank(question) ? "Activate card's ability?" : question; String questionToUse = StringUtils.isBlank(question) ? "Activate card's ability?" : question;
final List<String> opts = options == null ? defaultConfirmOptions : options; final List<String> opts = options == null ? defaultConfirmOptions : options;
FOptionPane.showCardOptionDialog(c, questionToUse, title, FOptionPane.QUESTION_ICON, opts, defaultIsYes ? 0 : 1, result -> callback.run(result == 0)); FOptionPane.showCardOptionDialog(c, questionToUse, title, FOptionPane.QUESTION_ICON, opts, defaultIsYes ? 0 : 1, result -> callback.accept(result == 0));
} }
/** /**

View File

@@ -21,6 +21,7 @@ package forge.toolbox;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function; import java.util.function.Function;
import java.util.function.Predicate; import java.util.function.Predicate;
@@ -77,10 +78,10 @@ public class ListChooser<T> extends FContainer {
private FOptionPane optionPane; private FOptionPane optionPane;
private final Collection<T> list; private final Collection<T> list;
private final Function<T, String> display; private final Function<T, String> display;
private final Callback<List<T>> callback; private final Consumer<List<T>> callback;
private AdvancedSearchFilter<? extends InventoryItem> advancedSearchFilter; private AdvancedSearchFilter<? extends InventoryItem> advancedSearchFilter;
public ListChooser(final String title, final int minChoices, final int maxChoices, final Collection<T> list0, final Function<T, String> display0, final Callback<List<T>> callback0) { public ListChooser(final String title, final int minChoices, final int maxChoices, final Collection<T> list0, final Function<T, String> display0, final Consumer<List<T>> callback0) {
FThreads.assertExecutedByEdt(true); FThreads.assertExecutedByEdt(true);
list = list0; list = list0;
lstChoices = add(new ChoiceList(list, minChoices, maxChoices)); lstChoices = add(new ChoiceList(list, minChoices, maxChoices));
@@ -123,13 +124,13 @@ public class ListChooser<T> extends FContainer {
optionPane = new FOptionPane(null, null, title, null, this, options, 0, result -> { optionPane = new FOptionPane(null, null, title, null, this, options, 0, result -> {
called = false; called = false;
if (result == 0) { if (result == 0) {
callback.run(lstChoices.getSelectedItems()); callback.accept(lstChoices.getSelectedItems());
} }
else if (minChoices > 0) { else if (minChoices > 0) {
show(); //show if user tries to cancel when input is mandatory show(); //show if user tries to cancel when input is mandatory
} }
else { else {
callback.run(new ArrayList<>()); callback.accept(new ArrayList<>());
} }
}) { }) {
@Override @Override

View File

@@ -7,7 +7,6 @@ import forge.localinstance.skin.FSkinProp;
import forge.localinstance.skin.ISkinImage; import forge.localinstance.skin.ISkinImage;
import forge.sound.IAudioClip; import forge.sound.IAudioClip;
import forge.sound.IAudioMusic; import forge.sound.IAudioMusic;
import forge.util.Callback;
import forge.util.ImageFetcher; import forge.util.ImageFetcher;
import java.io.File; import java.io.File;
@@ -15,6 +14,7 @@ import java.io.IOException;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function; import java.util.function.Function;
import org.jupnp.UpnpServiceConfiguration; import org.jupnp.UpnpServiceConfiguration;
@@ -42,7 +42,7 @@ public interface IGuiBase {
<T> List<T> order(String title, String top, int remainingObjectsMin, int remainingObjectsMax, List<T> sourceChoices, List<T> destChoices); <T> List<T> order(String title, String top, int remainingObjectsMin, int remainingObjectsMax, List<T> sourceChoices, List<T> destChoices);
String showFileDialog(String title, String defaultDir); String showFileDialog(String title, String defaultDir);
File getSaveFile(File defaultFile); File getSaveFile(File defaultFile);
void download(GuiDownloadService service, Callback<Boolean> callback); void download(GuiDownloadService service, Consumer<Boolean> callback);
void refreshSkin(); void refreshSkin();
void showCardList(String title, String message, List<PaperCard> list); void showCardList(String title, String message, List<PaperCard> list);
boolean showBoxedProduct(String title, String message, List<PaperCard> list); boolean showBoxedProduct(String title, String message, List<PaperCard> list);

View File

@@ -1,6 +0,0 @@
package forge.util;
@FunctionalInterface
public interface Callback<T> {
void run(T result);
}

View File

@@ -2,7 +2,9 @@ package forge.util;
import forge.gui.FThreads; import forge.gui.FThreads;
public abstract class WaitCallback<T> implements Callback<T>, Runnable { import java.util.function.Consumer;
public abstract class WaitCallback<T> implements Consumer<T>, Runnable {
public class Lock { public class Lock {
} }
@@ -11,7 +13,7 @@ public abstract class WaitCallback<T> implements Callback<T>, Runnable {
private T result; private T result;
@Override @Override
public final void run(T result0) { public final void accept(T result0) {
result = result0; result = result0;
synchronized (lock) { synchronized (lock) {
lock.notify(); lock.notify();