changes from trunk commited

This commit is contained in:
Maxmtg
2013-03-26 08:42:13 +00:00
3 changed files with 21 additions and 39 deletions

View File

@@ -89,41 +89,20 @@ public class GuiChoose {
}
// returned Object will never be null
/**
* <p>
* getChoices.
* </p>
*
* @param <T>
* a T object.
* @param message
* a {@link java.lang.String} object.
* @param min
* a int.
* @param max
* a int.
* @param choices
* a T object.
* @return a {@link java.util.List} object.
*/
public static <T> List<T> getChoices(final String message, final int min, final int max, final T[] choices) {
final ListChooser<T> c = new ListChooser<T>(message, min, max, choices);
return getChoices(c);
return getChoices(message, min, max, Arrays.asList(choices));
}
public static <T> List<T> getChoices(final String message, final int min, final int max, final Collection<T> choices) {
final ListChooser<T> c = new ListChooser<T>(message, min, max, choices);
return getChoices(c);
}
// Nothing to choose here. Code uses this to just show a card.
public static Card show(final String message, final Card singleChoice) {
List<Card> choices = new ArrayList<Card>();
choices.add(singleChoice);
return one(message, choices);
}
private static <T> List<T> getChoices(final ListChooser<T> c) {
if (null == choices || choices.isEmpty()) {
if (0 == min) {
return new ArrayList<T>();
} else {
throw new RuntimeException("choice required from empty list");
}
}
ListChooser<T> c = new ListChooser<T>(message, min, max, choices);
final JList list = c.getJList();
list.addListSelectionListener(new ListSelectionListener() {
@Override
@@ -142,7 +121,14 @@ public class GuiChoose {
c.show();
GuiUtils.clearPanelSelections();
return c.getSelectedValues();
} // getChoice()
}
// Nothing to choose here. Code uses this to just show a card.
public static Card show(final String message, final Card singleChoice) {
List<Card> choices = new ArrayList<Card>();
choices.add(singleChoice);
return one(message, choices);
}
public static <T> List<T> order(final String title, final String top, int remainingObjects,
final List<T> sourceChoices, List<T> destChoices, Card referenceCard) {

View File

@@ -24,7 +24,6 @@ import java.awt.event.MouseEvent;
import java.awt.event.WindowEvent;
import java.awt.event.WindowFocusListener;
import java.util.AbstractList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
@@ -84,10 +83,6 @@ public class ListChooser<T> {
private JOptionPane optionPane;
private Action ok, cancel;
public ListChooser(final String title, final int minChoices, final int maxChoices, final T[] list) {
this(title, minChoices, maxChoices, Arrays.asList(list));
}
public ListChooser(final String title, final int minChoices, final int maxChoices, final Collection<T> list) {
this.title = title;
this.minChoices = minChoices;
@@ -125,7 +120,7 @@ public class ListChooser<T> {
}
/** @return boolean */
public synchronized boolean show() {
public boolean show() {
return show(list.get(0));
}
@@ -135,7 +130,7 @@ public class ListChooser<T> {
* @param index0 index to select when shown
* @return a boolean.
*/
public synchronized boolean show(T item) {
public boolean show(T item) {
if (this.called) {
throw new IllegalStateException("Already shown");
}

View File

@@ -141,6 +141,7 @@ public class ControlWinLose {
cDeck.getMain().remove(toRemove);
if ( cDeck != oDeck )
oDeck.getMain().remove(toRemove);
losses.add(toRemove);
}
}