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.util.Collection;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;
import javax.swing.ImageIcon;
@@ -53,7 +54,6 @@ import forge.toolbox.FOptionPane;
import forge.toolbox.FSkin;
import forge.toolbox.FSkin.SkinImage;
import forge.util.BuildInfo;
import forge.util.Callback;
import forge.util.FileUtil;
import forge.util.ImageFetcher;
import forge.util.OperatingSystem;
@@ -264,7 +264,7 @@ public class GuiDesktop implements IGuiBase {
}
@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();
}

View File

@@ -37,9 +37,10 @@ import forge.toolbox.FRadioButton;
import forge.toolbox.FSkin;
import forge.toolbox.FTextField;
import forge.toolbox.JXButtonPanel;
import forge.util.Callback;
import net.miginfocom.swing.MigLayout;
import java.util.function.Consumer;
@SuppressWarnings("serial")
public class GuiDownloader extends DefaultBoundedRangeModel {
// Swing components
@@ -57,7 +58,7 @@ public class GuiDownloader extends DefaultBoundedRangeModel {
SOverlayUtils.hideOverlay();
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 GuiDownloadService service;
private final Callback<Boolean> callback;
private final Consumer<Boolean> callback;
public GuiDownloader(final GuiDownloadService service0) {
this(service0, null);
}
public GuiDownloader(final GuiDownloadService service0, final Callback<Boolean> callback0) {
public GuiDownloader(final GuiDownloadService service0, final Consumer<Boolean> callback0) {
service = service0;
callback = callback0;

View File

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

View File

@@ -32,6 +32,7 @@ import java.io.File;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;
import org.jupnp.DefaultUpnpServiceConfiguration;
@@ -282,7 +283,7 @@ public class GuiMobile implements IGuiBase {
}
@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();
}

View File

@@ -1,10 +1,9 @@
package forge.adventure.data;
import forge.util.Callback;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
/**
* 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 boolean isDisabled = false;
public transient Callback callback;
public transient Consumer callback;
public DialogData(){}
public DialogData(DialogData other){

View File

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

View File

@@ -157,7 +157,7 @@ public class MenuScene extends UIScene {
loadDialog(option);
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.

View File

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

View File

@@ -21,6 +21,7 @@ import java.text.NumberFormat;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.function.Consumer;
import com.badlogic.gdx.utils.Align;
@@ -55,7 +56,7 @@ public class AddBasicLandsDialog extends FDialog {
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 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 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);
callback = callback0;
@@ -149,7 +150,7 @@ public class AddBasicLandsDialog extends FDialog {
hide();
if (landsToAdd.countAll() > 0) {
callback.run(landsToAdd);
callback.accept(landsToAdd);
}
});
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.GuiChoose;
import forge.toolbox.ListChooser;
import forge.util.Callback;
import forge.util.Utils;
import forge.util.storage.IStorage;
@@ -62,7 +61,7 @@ public class FDeckChooser extends FScreen {
private FComboBox<DeckType> cmbDeckTypes;
private DeckType selectedDeckType;
private boolean needRefreshOnActivate;
private Callback<Deck> callback;
private Consumer<Deck> callback;
private NetDeckCategory netDeckCategory;
private NetDeckArchiveStandard NetDeckArchiveStandard;
private NetDeckArchivePioneer NetDeckArchivePioneer;
@@ -88,7 +87,7 @@ public class FDeckChooser extends FScreen {
private FOptionPane optionPane;
//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);
final FDeckChooser deckChooser = new FDeckChooser(gameType, forAi, null);
@@ -230,7 +229,7 @@ public class FDeckChooser extends FScreen {
if (optionPane == null) {
Forge.back();
if (callback != null) {
callback.run(getDeck());
callback.accept(getDeck());
}
}
else {
@@ -429,9 +428,7 @@ public class FDeckChooser extends FScreen {
//prompt to duplicate deck if deck doesn't exist already
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>() {
@Override
public void run(Boolean result) {
Forge.getLocalizer().getMessage("lblDuplicateDeck"), Forge.getLocalizer().getMessage("lblDuplicate"), Forge.getLocalizer().getMessage("lblCancel"), result -> {
if (result) {
Deck copiedDeck = (Deck)deck.getDeck().copyTo(deck.getName());
IStorage<Deck> storage;
@@ -457,7 +454,6 @@ public class FDeckChooser extends FScreen {
setSelectedDeckType(fallbackType);
editDeck(new DeckProxy(copiedDeck, "Constructed", lstDecks.getGameType(), storage));
}
}
});
break;
}

View File

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

View File

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

View File

@@ -1,6 +1,7 @@
package forge.deck;
import java.util.List;
import java.util.function.Consumer;
import forge.Forge;
import org.apache.commons.lang3.StringUtils;
@@ -16,13 +17,12 @@ import forge.screens.FScreen;
import forge.screens.TabPageScreen;
import forge.toolbox.FDialog;
import forge.toolbox.GuiChoose;
import forge.util.Callback;
public class FSideboardDialog extends FDialog {
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);
callback = callback0;
@@ -37,7 +37,7 @@ public class FSideboardDialog extends FDialog {
public void setVisible(boolean visible0) {
super.setVisible(visible0);
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();
}
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;
if (!StringUtils.isEmpty(dest)) {
label += " " + dest;
@@ -113,7 +113,7 @@ public class FSideboardDialog extends FDialog {
PaperCard card = cardManager.getSelectedItem();
int max = cardManager.getItemCount(card);
if (max == 1) {
callback.run(max);
callback.accept(max);
}
else {
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.FScrollPane;
import forge.toolbox.FTextArea;
import forge.util.Callback;
import forge.util.TextBounds;
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
private static final float PADDING = Utils.scale(5);
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
public void onClose(Callback<Boolean> canCloseCallback) {
public void onClose(Consumer<Boolean> canCloseCallback) {
super.onClose(canCloseCallback);
isOpen = false;
}

View File

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

View File

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

View File

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

View File

@@ -1,6 +1,7 @@
package forge.screens;
import java.util.List;
import java.util.function.Consumer;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.graphics.Color;
@@ -23,7 +24,6 @@ import forge.toolbox.FDisplayObject;
import forge.toolbox.FEvent;
import forge.toolbox.FEvent.FEventHandler;
import forge.toolbox.FLabel;
import forge.util.Callback;
import forge.util.Utils;
public abstract class FScreen extends FContainer {
@@ -66,13 +66,13 @@ public abstract class FScreen extends FContainer {
Forge.startContinuousRendering();
}
public void onSwitchAway(Callback<Boolean> canSwitchCallback) {
canSwitchCallback.run(true);
public void onSwitchAway(Consumer<Boolean> canSwitchCallback) {
canSwitchCallback.accept(true);
}
public void onClose(Callback<Boolean> canCloseCallback) {
public void onClose(Consumer<Boolean> canCloseCallback) {
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.Map;
import java.util.function.Consumer;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.utils.Align;
@@ -15,7 +16,6 @@ import forge.screens.FScreen;
import forge.toolbox.FDisplayObject;
import forge.toolbox.FLabel;
import forge.toolbox.FScrollPane;
import forge.util.Callback;
import forge.util.MyRandom;
import forge.util.Utils;
@@ -28,7 +28,7 @@ public class AvatarSelector extends FScreen {
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);
Forge.openScreen(selector);
}
@@ -38,7 +38,7 @@ public class AvatarSelector extends FScreen {
private final int currentIndex;
private final List<Integer> usedAvatars;
private final Callback<Integer> callback;
private final Consumer<Integer> callback;
private final FScrollPane scroller = new FScrollPane() {
@Override
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));
currentIndex = currentIndex0;
@@ -91,13 +91,13 @@ public class AvatarSelector extends FScreen {
if (index == -1) {
lbl.setCommand(e -> {
callback.run(getRandomAvatar(usedAvatars));
callback.accept(getRandomAvatar(usedAvatars));
Forge.back();
});
}
else {
lbl.setCommand(e -> {
callback.run(index);
callback.accept(index);
Forge.back();
});
}

View File

@@ -3,6 +3,7 @@ package forge.screens.constructed;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.function.Consumer;
import forge.gamemodes.net.event.UpdateLobbyPlayerEvent;
import org.apache.commons.lang3.StringUtils;
@@ -41,7 +42,6 @@ import forge.toolbox.FList;
import forge.toolbox.FOptionPane;
import forge.toolbox.FTextField;
import forge.toolbox.FToggleSwitch;
import forge.util.Callback;
import forge.util.Lang;
import forge.util.NameGenerator;
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();
}
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> typeOptions = ImmutableList.of(Forge.getLocalizer().getInstance().getMessage("lblFantasy"), Forge.getLocalizer().getInstance().getMessage("lblGeneric"), Forge.getLocalizer().getInstance().getMessage("lblAny"));
private void getNewName(final Callback<String> callback) {
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().getMessage("lblFantasy"), Forge.getLocalizer().getMessage("lblGeneric"), Forge.getLocalizer().getMessage("lblAny"));
private void getNewName(final Consumer<String> callback) {
final String title = Forge.getLocalizer().getMessage("lblGetNewRandomName");
final String message = Forge.getLocalizer().getMessage("lbltypeofName");
final FSkinImage icon = FOptionPane.QUESTION_ICON;
FOptionPane.showOptionDialog(message, title, icon, genderOptions, 2, genderIndex -> {
if (genderIndex == null || genderIndex < 0) {
callback.run(null);
callback.accept(null);
return;
}
FOptionPane.showOptionDialog(message, title, icon, typeOptions, 2, typeIndex -> {
if (typeIndex == null || typeIndex < 0) {
callback.run(null);
callback.accept(null);
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);
String confirmMsg = Forge.getLocalizer().getMessage("lblconfirmName").replace("%s", newName);
FOptionPane.showConfirmDialog(confirmMsg, title, Forge.getLocalizer().getMessage("lblUseThisName"), Forge.getLocalizer().getMessage("lblTryAgain"), true, result -> {
if (result) {
callback.run(newName);
callback.accept(newName);
}
else {
generateRandomName(gender, type, usedNames, title, callback);

View File

@@ -2,6 +2,7 @@ package forge.screens.constructed;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.utils.Align;
@@ -15,7 +16,6 @@ import forge.screens.FScreen;
import forge.toolbox.FDisplayObject;
import forge.toolbox.FLabel;
import forge.toolbox.FScrollPane;
import forge.util.Callback;
import forge.util.MyRandom;
import forge.util.Utils;
@@ -28,7 +28,7 @@ public class SleevesSelector extends FScreen {
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);
Forge.openScreen(selector);
}
@@ -38,7 +38,7 @@ public class SleevesSelector extends FScreen {
private final int currentIndex;
private final List<Integer> usedSleeves;
private final Callback<Integer> callback;
private final Consumer<Integer> callback;
private final FScrollPane scroller = new FScrollPane() {
@Override
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));
currentIndex = currentIndex0;
@@ -91,13 +91,13 @@ public class SleevesSelector extends FScreen {
if (index == -1) {
lbl.setCommand(e -> {
callback.run(getRandomSleeves(usedSleeves));
callback.accept(getRandomSleeves(usedSleeves));
Forge.back();
});
}
else {
lbl.setCommand(e -> {
callback.run(index);
callback.accept(index);
Forge.back();
});
}

View File

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

View File

@@ -28,7 +28,6 @@ import forge.toolbox.FEvent.FEventHandler;
import forge.toolbox.FLabel;
import forge.toolbox.FOptionPane;
import forge.toolbox.FScrollPane;
import forge.util.Callback;
import forge.util.Utils;
public class HomeScreen extends FScreen {
@@ -115,9 +114,7 @@ public class HomeScreen extends FScreen {
addButton(Forge.getLocalizer().getMessage("lblHelp"), e -> FThreads.invokeInEdtLater(() -> {
try {
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>() {
@Override
public void run(Integer result) {
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 -> {
switch (result) {
case 0:
Gdx.net.openURI("https://discord.gg/3v9JCVr");
@@ -128,7 +125,6 @@ public class HomeScreen extends FScreen {
default:
break;
}
}
});
} else {
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.screens.home.LoadGameMenu.LoadGameScreen;
import forge.toolbox.FOptionPane;
import forge.util.Callback;
import java.util.function.Consumer;
public class DraftingProcessScreen extends FDeckEditor {
private boolean isDraftSaved;
@@ -54,7 +55,7 @@ public class DraftingProcessScreen extends FDeckEditor {
}
@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
super.save(callback);
return;
@@ -63,7 +64,7 @@ public class DraftingProcessScreen extends FDeckEditor {
if (isQuestDraft()) {
finishSave(QuestEventDraft.DECK_NAME);
if (callback != null) {
callback.run(true);
callback.accept(true);
}
return;
}
@@ -84,7 +85,7 @@ public class DraftingProcessScreen extends FDeckEditor {
if (result) {
finishSave(name);
if (callback != null) {
callback.run(true);
callback.accept(true);
}
} else {
save(callback); //If no overwrite, recurse
@@ -96,7 +97,7 @@ public class DraftingProcessScreen extends FDeckEditor {
finishSave(name);
if (callback != null) {
callback.run(true);
callback.accept(true);
}
});
});
@@ -131,7 +132,7 @@ public class DraftingProcessScreen extends FDeckEditor {
}
@Override
public void onClose(final Callback<Boolean> canCloseCallback) {
public void onClose(final Consumer<Boolean> canCloseCallback) {
if (isDraftSaved || canCloseCallback == null) {
super.onClose(canCloseCallback); //can skip prompt if draft saved
return;
@@ -140,7 +141,7 @@ public class DraftingProcessScreen extends FDeckEditor {
if (isQuestDraft()) {
FThreads.invokeInBackgroundThread(() -> {
if (questDraftController.cancelDraft()) {
FThreads.invokeInEdtLater(() -> canCloseCallback.run(true));
FThreads.invokeInEdtLater(() -> canCloseCallback.accept(true));
}
});
return;

View File

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

View File

@@ -21,6 +21,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import com.badlogic.gdx.utils.Align;
@@ -44,7 +45,6 @@ import forge.toolbox.FDisplayObject;
import forge.toolbox.FLabel;
import forge.toolbox.FOptionPane;
import forge.toolbox.FScrollPane;
import forge.util.Callback;
import forge.util.CardTranslation;
import forge.util.TextUtil;
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 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 boolean attackerHasDeathtouch = false;
@@ -421,7 +421,7 @@ public class VAssignCombatDamage extends FDialog {
return;
}
hide();
callback.run(getDamageMap());
callback.accept(getDamageMap());
}
private int getDamageToKill(CardView source) {

View File

@@ -21,6 +21,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import com.badlogic.gdx.utils.Align;
@@ -45,7 +46,6 @@ import forge.toolbox.FDisplayObject;
import forge.toolbox.FLabel;
import forge.toolbox.FOptionPane;
import forge.toolbox.FScrollPane;
import forge.util.Callback;
import forge.util.CardTranslation;
import forge.util.TextUtil;
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 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 String lblAmount;
@@ -360,7 +360,7 @@ public class VAssignGenericAmount extends FDialog {
return;
}
hide();
callback.run(getAssignedMap());
callback.accept(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.FOverlay;
import forge.util.Aggregates;
import forge.util.Callback;
import forge.util.PhysicsObject;
import java.util.function.Consumer;
public class ConquestChaosWheel extends FOverlay {
public static void spin(Callback<ChaosWheelOutcome> callback0) {
public static void spin(Consumer<ChaosWheelOutcome> callback0) {
ConquestChaosWheel wheel = new ConquestChaosWheel(callback0);
wheel.show();
}
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;
}
@@ -97,7 +98,7 @@ public class ConquestChaosWheel extends FOverlay {
@Override
protected void onEnd(boolean endingAll) {
hide();
callback.run(ChaosWheelOutcome.getWheelOutcome(getWheelRotation()));
callback.accept(ChaosWheelOutcome.getWheelOutcome(getWheelRotation()));
}
}

View File

@@ -1,6 +1,7 @@
package forge.screens.planarconquest;
import java.util.Map.Entry;
import java.util.function.Consumer;
import java.util.function.Predicate;
import com.badlogic.gdx.utils.Align;
@@ -38,7 +39,6 @@ import forge.toolbox.FList;
import forge.toolbox.FList.CompactModeHandler;
import forge.toolbox.FOptionPane;
import forge.toolbox.FTextField;
import forge.util.Callback;
public class ConquestCommandersScreen extends FScreen {
private static final float PADDING = FDeckChooser.PADDING;
@@ -83,19 +83,19 @@ public class ConquestCommandersScreen extends FScreen {
}
@Override
public void onClose(final Callback<Boolean> canCloseCallback) {
public void onClose(final Consumer<Boolean> canCloseCallback) {
if (canCloseCallback == null) { return; }
final ConquestCommander commander = lstCommanders.getSelectedItem();
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;
}
String problem = DeckFormat.PlanarConquest.getDeckConformanceProblem(commander.getDeck());
if (problem != null) {
//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;
}
@@ -104,7 +104,7 @@ public class ConquestCommandersScreen extends FScreen {
model.setSelectedCommander(commander);
model.saveData();
}
canCloseCallback.run(true);
canCloseCallback.accept(true);
}
private void refreshCommanders() {

View File

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

View File

@@ -5,6 +5,7 @@ import java.text.NumberFormat;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.function.Consumer;
import com.badlogic.gdx.utils.Align;
@@ -32,7 +33,6 @@ import forge.toolbox.FDisplayObject;
import forge.toolbox.FLabel;
import forge.toolbox.FTextArea;
import forge.toolbox.GuiChoose;
import forge.util.Callback;
import forge.util.ItemPool;
import forge.util.Utils;
@@ -80,7 +80,7 @@ public class QuestSpellShopScreen extends TabPageScreen<QuestSpellShopScreen> {
return true;
}
public void onClose(Callback<Boolean> canCloseCallback) {
public void onClose(Consumer<Boolean> canCloseCallback) {
FModel.getQuest().save();
super.onClose(canCloseCallback);
}
@@ -205,7 +205,7 @@ public class QuestSpellShopScreen extends TabPageScreen<QuestSpellShopScreen> {
final int max = itemManager.getItemCount(item);
if (max == 0) { return; }
final Callback<Integer> callback = result -> {
final Consumer<Integer> callback = result -> {
if (result == null || result <= 0) { return; }
//invoke in background thread so other dialogs can be shown properly
@@ -217,7 +217,7 @@ public class QuestSpellShopScreen extends TabPageScreen<QuestSpellShopScreen> {
});
};
if (max == 1) {
callback.run(max);
callback.accept(max);
}
else {
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.FOptionPane;
import forge.toolbox.GuiChoose;
import forge.util.Callback;
import forge.util.FileUtil;
import org.apache.commons.lang3.tuple.Pair;
@@ -61,9 +60,7 @@ public class FilesPage extends TabPage<SettingsScreen> {
Forge.getDeviceAdapter().requestFileAcces();
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>() {
@Override
public void run(Integer result) {
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 -> {
switch (result) {
case 0:
FThreads.invokeInEdtLater(() -> LoadingOverlay.show(Forge.getLocalizer().getMessage("lblBackupMsg"), true, () -> {
@@ -92,7 +89,6 @@ public class FilesPage extends TabPage<SettingsScreen> {
default:
break;
}
}
});
}
}, 0);
@@ -107,9 +103,7 @@ public class FilesPage extends TabPage<SettingsScreen> {
Pair<Integer, Integer> totalAudit = StaticData.instance().audit(nifSB, cniSB);
String msg = nifSB.toString();
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>() {
@Override
public void run(Integer result) {
FOptionPane.showOptionDialog(msg, title, FOptionPane.INFORMATION_ICON, ImmutableList.of(Forge.getLocalizer().getMessage("lblCopy"), Forge.getLocalizer().getMessage("lblClose")), -1, result -> {
switch (result) {
case 0:
Forge.getClipboard().setContents(msg);
@@ -117,7 +111,6 @@ public class FilesPage extends TabPage<SettingsScreen> {
default:
break;
}
}
});
}));
}

View File

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

View File

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

View File

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

View File

@@ -1,6 +1,7 @@
package forge.toolbox;
import java.util.List;
import java.util.function.Consumer;
import org.apache.commons.lang3.StringUtils;
@@ -21,7 +22,6 @@ import forge.card.CardZoom;
import forge.game.card.CardView;
import forge.localinstance.skin.FSkinProp;
import forge.screens.match.views.VPrompt;
import forge.util.Callback;
import forge.util.Utils;
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
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);
}
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);
}
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);
optionPane.show();
}
@@ -108,7 +108,7 @@ public class FOptionPane extends FDialog {
}.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;
if (card != null) {
cardDisplay = new FDisplayObject() {
@@ -149,13 +149,13 @@ public class FOptionPane extends FDialog {
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);
}
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);
}
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 FTextField txtInput;
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 -> {
if (result == 0) {
if (txtInput != null) {
callback.run((T)txtInput.getText());
callback.accept((T)txtInput.getText());
} else {
callback.run(cbInput.getSelectedItem());
callback.accept(cbInput.getSelectedItem());
}
} else {
callback.run(null);
callback.accept(null);
}
}) {
@Override
@@ -219,11 +219,11 @@ public class FOptionPane extends FDialog {
private final FLabel lblIcon;
private final FTextArea prompt;
protected final FDisplayObject displayObj;
private final Callback<Integer> callback;
private final Consumer<Integer> callback;
private final int defaultOption;
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());
if (icon != null) {
@@ -267,7 +267,7 @@ public class FOptionPane extends FDialog {
public void setResult(final int option) {
hide();
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.Comparator;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;
import com.google.common.collect.Iterables;
@@ -12,7 +13,6 @@ import forge.Forge;
import org.apache.commons.lang3.StringUtils;
import forge.game.card.CardView;
import forge.util.Callback;
public class GuiChoose {
@@ -30,20 +30,20 @@ public class GuiChoose {
* getChoices.
* @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)) {
callback.run(null);
callback.accept(null);
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()) {
callback.run(null);
callback.accept(null);
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...)
// returned Object will never be null
@@ -60,39 +60,39 @@ public class GuiChoose {
* 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) {
callback.run(null);
callback.accept(null);
return;
}
if (choices.length == 1) {
callback.run(choices[0]);
callback.accept(choices[0]);
return;
}
getChoices(message, 1, 1, choices, result -> {
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()) {
callback.run(null);
callback.accept(null);
return;
}
if (choices.size() == 1) {
callback.run(Iterables.getFirst(choices, null));
callback.accept(Iterables.getFirst(choices, null));
return;
}
getChoices(message, 1, 1, choices, result -> {
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);
}
@@ -110,15 +110,15 @@ public class GuiChoose {
}
// 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);
}
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);
}
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
callback.run(min);
callback.accept(min);
return;
}
@@ -139,9 +139,9 @@ public class GuiChoose {
}
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
callback.run(min);
callback.accept(min);
return;
}
@@ -158,7 +158,7 @@ public class GuiChoose {
oneOrNone(message, choices, choice -> {
if (choice instanceof Integer || choice == null) {
callback.run((Integer)choice);
callback.accept((Integer)choice);
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 -> {
if (result == null) { //that is 'cancel'
callback.run(null);
callback.accept(null);
return;
}
if (StringUtils.isNumeric(result)) {
int val = Integer.parseInt(result);
if (val >= min && val <= max) {
callback.run(val);
callback.accept(val);
return;
}
}
@@ -200,18 +200,18 @@ public class GuiChoose {
}
// 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);
}
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);
}
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 (min == 0) {
callback.run(new ArrayList<>());
callback.accept(new ArrayList<>());
return;
}
throw new RuntimeException("choice required from empty list");
@@ -221,22 +221,22 @@ public class GuiChoose {
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);
}
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 m2 = min >= 0 ? sourceChoices.size() - min : -1;
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);
}
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.
DualListBox<T> dual = new DualListBox<>(title, remainingObjectsMin, remainingObjectsMax, sourceChoices, destChoices, callback);
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
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)) {
callback.run(null);
callback.accept(null);
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
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()) {
callback.run(null);
callback.accept(null);
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
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)) {
callback.run(null);
callback.accept(null);
return;
}
sortedGetChoices(message, 1, 1, choices, comparer, result -> {
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
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)) {
callback.run(null);
callback.accept(null);
return;
}
sortedGetChoices(message, 1, 1, choices, comparer, result -> {
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
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);
}
// 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
Arrays.sort(choices, comparer);
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
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
choices.sort(comparer);
getChoices(message, min, max, choices, callback);

View File

@@ -1,13 +1,13 @@
package forge.toolbox;
import java.util.List;
import java.util.function.Consumer;
import org.apache.commons.lang3.StringUtils;
import com.google.common.collect.ImmutableList;
import forge.game.card.CardView;
import forge.util.Callback;
/**
* Holds player interactions using standard windows
@@ -15,21 +15,21 @@ import forge.util.Callback;
public class GuiDialog {
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);
}
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);
}
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);
}
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";
String questionToUse = StringUtils.isBlank(question) ? "Activate card's ability?" : question;
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.Collection;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
@@ -77,10 +78,10 @@ public class ListChooser<T> extends FContainer {
private FOptionPane optionPane;
private final Collection<T> list;
private final Function<T, String> display;
private final Callback<List<T>> callback;
private final Consumer<List<T>> callback;
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);
list = list0;
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 -> {
called = false;
if (result == 0) {
callback.run(lstChoices.getSelectedItems());
callback.accept(lstChoices.getSelectedItems());
}
else if (minChoices > 0) {
show(); //show if user tries to cancel when input is mandatory
}
else {
callback.run(new ArrayList<>());
callback.accept(new ArrayList<>());
}
}) {
@Override

View File

@@ -7,7 +7,6 @@ import forge.localinstance.skin.FSkinProp;
import forge.localinstance.skin.ISkinImage;
import forge.sound.IAudioClip;
import forge.sound.IAudioMusic;
import forge.util.Callback;
import forge.util.ImageFetcher;
import java.io.File;
@@ -15,6 +14,7 @@ import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Collection;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;
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);
String showFileDialog(String title, String defaultDir);
File getSaveFile(File defaultFile);
void download(GuiDownloadService service, Callback<Boolean> callback);
void download(GuiDownloadService service, Consumer<Boolean> callback);
void refreshSkin();
void showCardList(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;
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 {
}
@@ -11,7 +13,7 @@ public abstract class WaitCallback<T> implements Callback<T>, Runnable {
private T result;
@Override
public final void run(T result0) {
public final void accept(T result0) {
result = result0;
synchronized (lock) {
lock.notify();