diff --git a/Mage.Client/src/main/java/mage/client/deckeditor/CardSelector.java b/Mage.Client/src/main/java/mage/client/deckeditor/CardSelector.java index b2c7bb741b3..fc674760483 100644 --- a/Mage.Client/src/main/java/mage/client/deckeditor/CardSelector.java +++ b/Mage.Client/src/main/java/mage/client/deckeditor/CardSelector.java @@ -41,6 +41,7 @@ import java.awt.event.*; import java.io.ByteArrayOutputStream; import java.io.ObjectOutputStream; import java.util.List; +import java.util.concurrent.ThreadLocalRandom; import java.util.*; import static mage.client.dialog.PreferencesDialog.*; @@ -619,6 +620,7 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene jButtonRemoveFromMain = new javax.swing.JButton(); jButtonAddToSideboard = new javax.swing.JButton(); jButtonRemoveFromSideboard = new javax.swing.JButton(); + jButtonRandomCard = new javax.swing.JButton(); jTextFieldSearch = new javax.swing.JTextField(); chkNames = new javax.swing.JCheckBox(); chkTypes = new javax.swing.JCheckBox(); @@ -1151,6 +1153,18 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene jButtonRemoveFromSideboardActionPerformed(evt); } }); + + jButtonRandomCard.setIcon(new javax.swing.ImageIcon(getClass().getResource("/buttons/dice.png"))); // NOI18N + jButtonRandomCard.setToolTipText("Add a random card from the current search to your deck."); + jButtonRandomCard.setMargin(null); + jButtonRandomCard.setMaximumSize(new java.awt.Dimension(35, 23)); + jButtonRandomCard.setMinimumSize(new java.awt.Dimension(35, 23)); + jButtonRandomCard.setPreferredSize(new java.awt.Dimension(30, 28)); + jButtonRandomCard.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButtonRandomCardActionPerformed(evt); + } + }); jTextFieldSearch.setToolTipText("Searches for card names and in the rule text of the card."); @@ -1248,6 +1262,8 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene .addComponent(jButtonAddToSideboard, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(2, 2, 2) .addComponent(jButtonRemoveFromSideboard, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(2,2,2) + .addComponent(jButtonRandomCard, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jTextFieldSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 219, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) @@ -1282,6 +1298,7 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene .addComponent(jButtonRemoveFromMain, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jButtonAddToSideboard, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jButtonRemoveFromSideboard, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jButtonRandomCard, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(cardSelectorBottomPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jTextFieldSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jButtonSearch) @@ -1431,6 +1448,14 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene } } }//GEN-LAST:event_jButtonAddToMainActionPerformed + + private void jButtonRandomCardActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAddToMainActionPerformed + int n = mainTable.getRowCount(); + mainModel.doubleClick(ThreadLocalRandom.current().nextInt(n), null, false); + if (limited) { + mainModel.fireTableDataChanged(); + } + } private void jButtonAddToSideboardActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAddToSideboardActionPerformed if (mainTable.getSelectedRowCount() > 0) { @@ -1693,6 +1718,7 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene private javax.swing.JButton jButtonClean; private javax.swing.JButton jButtonRemoveFromMain; private javax.swing.JButton jButtonRemoveFromSideboard; + private javax.swing.JButton jButtonRandomCard; private javax.swing.JButton jButtonSearch; private javax.swing.JToolBar.Separator jSeparator1; private javax.swing.JToolBar.Separator jSeparator2; diff --git a/Mage.Client/src/main/resources/buttons/dice.png b/Mage.Client/src/main/resources/buttons/dice.png new file mode 100644 index 00000000000..a2ab43d45a8 Binary files /dev/null and b/Mage.Client/src/main/resources/buttons/dice.png differ