Add any card to your quest cardpool

I added a menu option that allows you to add any card to your quest cardpool. The menu option is named "Cheat - Add Card" but feel free to rename it to whatever sounds best.
This method is probably too long since it is around 270 lines and should be broken in smaller sub-methods.
For better or worse I seem to have a knack for writing extremely long methods.
This is the whole Gui_Quest_DeckEditor_Menu.setupMenu() method with the old and updated code combined.
All of the new code is marked.
deckMenu.addSeparator();//new code
deckMenu.add(addCard); //new code
This method is probably too long since it is around 270 lines and should be broken in smaller sub-methods.
For better or worse I seem to have a knack for writing extremely long methods.

This is the whole Gui_Quest_DeckEditor_Menu.setupMenu() method with the old and updated code combined.
All of the new code is marked.
- Code: Select all
private void setupMenu()
{
JMenuItem open = new JMenuItem("Open");
JMenuItem new2 = new JMenuItem("New");
JMenuItem rename = new JMenuItem("Rename");
JMenuItem save = new JMenuItem("Save");
JMenuItem copy = new JMenuItem("Copy");
JMenuItem delete = new JMenuItem("Delete");
JMenuItem exit = new JMenuItem("Exit");
////////////////////////////////////////////
//below is new code
//adds a card to human player's cardpool
JMenuItem addCard = new JMenuItem("Cheat - Add Card");
//add card
addCard.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent a)
{
//sort cards by card name
CardList cardList = AllZone.CardFactory.getAllCards();
TableSorter sorter = new TableSorter(cardList, 1, true);
cardList.sort(sorter);
//create a new Card object with a different toString() method
//so that that JList only shows the card's name
//
//this is alot of work just to make it a little
//easier and prettier for the user, gui stuff is very complicated
class BetterCard extends Card
{
private Card card;
BetterCard(Card c)
{
card = c;
//this line is very important
//if you omit this, errors will occur
this.setName(c.getName());
}
public String toString()
{
return card.getName();
}
}//BetterCard
Card[] card = cardList.toArray();
for(int i = 0; i < card.length; i++)
{
card[i] = new BetterCard(card[i]);
}
final JList list = new JList(card);
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
//update the "card detail" on the right with the card info
list.addListSelectionListener(new ListSelectionListener()
{
public void valueChanged(ListSelectionEvent e)
{
CardDetail cd = (CardDetail)deckDisplay;
cd.updateCardDetail((Card)list.getSelectedValue());
}
});
Object[] o = {"Add Card to Your Cardpool", new JScrollPane(list)};
JOptionPane pane = new JOptionPane(o, JOptionPane.INFORMATION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
JDialog dialog = pane.createDialog(null, "Cheat - Add Card");
dialog.setModal(true);
dialog.setVisible(true);
Object choice = pane.getValue();
boolean cancel = false;
//there are a ton of ways to cancel
if(
choice == null ||
choice.equals(JOptionPane.UNINITIALIZED_VALUE)
)
cancel = true;
else
{
int n = ((Integer)choice).intValue();
if(n == JOptionPane.CANCEL_OPTION)
cancel = true;
}
if(cancel || list.getSelectedValue() == null)
{
//System.out.println("cancelled");
}
else
{
//show the choice that the user selected
//System.out.println(list.getSelectedValue());
Card c = (Card) list.getSelectedValue();
Gui_Quest_DeckEditor g = (Gui_Quest_DeckEditor)deckDisplay;
TableModel table = g.getTopTableModel();
table.addCard(c);
table.resort();
}
}//actionPerformed()
});//add card
//above is new code
///////////////////////////////////////
//human
open.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent a)
{
String deckName = getUserInput_OpenDeck(questData.getDeckNames());
//check if user selected "cancel"
if(deckName.equals(""))
return;
openHumanDeck(deckName);
}
});//open
//human
new2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent a)
{
CardList cardpool = covertToCardList(questData.getCardpool());
deckDisplay.updateDisplay(cardpool, new CardList());
setHumanPlayer("");
}
});//new
//human
rename.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent a)
{
String name = getUserInput_GetDeckName(questData.getDeckNames());
//check if user cancels
if(name.equals(""))
return;
//is the current deck already saved and in QuestData?
if(questData.getDeckNames().contains(currentDeck.getName()))
questData.removeDeck(currentDeck.getName());//remove old deck
currentDeck.setName(name);
Deck deck = convertCardListToDeck(deckDisplay.getBottom());
deck.setName(name);
questData.addDeck(deck);
setHumanPlayer(name);
}
});//rename
//human
save.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent a)
{
String name = currentDeck.getName();
//check to see if name is set
if(name.equals(""))
{
name = getUserInput_GetDeckName(questData.getDeckNames());
//check if user cancels
if(name.equals(""))
return;
}
setHumanPlayer(name);
Deck deck = convertCardListToDeck(deckDisplay.getBottom());
deck.setName(name);
questData.addDeck(deck);
}
});//save
//human
copy.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent a)
{
String name = getUserInput_GetDeckName(questData.getDeckNames());
//check if user cancels
if(name.equals(""))
return;
setHumanPlayer(name);
Deck deck = convertCardListToDeck(deckDisplay.getBottom());
deck.setName(name);
questData.addDeck(deck);
}
});//copy
//human
delete.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent a)
{
if(currentDeck.getName().equals(""))
return;
int check = JOptionPane.showConfirmDialog(null, "Do you really want to delete this deck?", "Delete", JOptionPane.YES_NO_OPTION);
if(check == JOptionPane.NO_OPTION)
return;//stop here
questData.removeDeck(currentDeck.getName());
//show card pool
CardList cardpool = covertToCardList(questData.getCardpool());
deckDisplay.updateDisplay(cardpool, new CardList());
setHumanPlayer("");
}
});//delete
//human
exit.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent a)
{
Gui_Quest_DeckEditor_Menu.this.close();
}
});
JMenu deckMenu = new JMenu("Deck");
deckMenu.add(open);
deckMenu.add(new2);
deckMenu.add(rename);
deckMenu.add(save);
deckMenu.add(copy);
deckMenu.addSeparator();//new code
deckMenu.add(addCard); //new code
deckMenu.addSeparator();
addImportExport(deckMenu, true);
deckMenu.addSeparator();
deckMenu.add(delete);
deckMenu.addSeparator();
deckMenu.add(exit);
this.add(deckMenu);
}//setupMenu()
deckMenu.addSeparator();//new code
deckMenu.add(addCard); //new code