Merge pull request #6 from magefree/master

pulling upstream
This commit is contained in:
brodee 2019-01-01 13:34:04 -08:00 committed by GitHub
commit 6f4c404727
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
690 changed files with 9247 additions and 4138 deletions

View file

@ -47,7 +47,7 @@ import net.java.truevfs.access.TConfig;
import net.java.truevfs.kernel.spec.FsAccessOption;
import org.apache.log4j.Logger;
import org.mage.card.arcane.ManaSymbols;
import org.mage.plugins.card.images.DownloadPictures;
import org.mage.plugins.card.images.DownloadPicturesService;
import org.mage.plugins.card.info.CardInfoPaneImpl;
import org.mage.plugins.card.utils.impl.ImageManagerImpl;
@ -1010,7 +1010,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
}//GEN-LAST:event_btnImagesActionPerformed
public void downloadImages() {
DownloadPictures.startDownload();
DownloadPicturesService.startDownload();
}
public void exitApp() {
@ -1380,7 +1380,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
Plugins.instance.downloadSymbols();
break;
case CLIENT_DOWNLOAD_CARD_IMAGES:
DownloadPictures.startDownload();
DownloadPicturesService.startDownload();
break;
case CLIENT_DISCONNECT:
if (SessionHandler.isConnected()) {

View file

@ -1,9 +1,8 @@
package mage.client.components.ability;
import mage.client.SessionHandler;
import mage.client.dialog.MageDialog;
import mage.client.util.ImageHelper;
import mage.client.util.SettingsManager;
import mage.client.util.gui.GuiDisplayUtil;
import mage.remote.Session;
import mage.view.AbilityPickerView;
import org.apache.log4j.Logger;
@ -17,8 +16,8 @@ import org.mage.card.arcane.UI;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.util.List;
import java.util.*;
/**
* Dialog for choosing abilities.
@ -112,10 +111,7 @@ public class AbilityPicker extends JXPanel implements MouseWheelListener {
this.selected = false; // back to false - waiting for selection
setVisible(true);
Point centered = SettingsManager.instance.getComponentPosition(DIALOG_WIDTH, DIALOG_HEIGHT);
this.setLocation(centered.x, centered.y);
GuiDisplayUtil.keepComponentInsideScreen(centered.x, centered.y, this);
MageDialog.makeWindowCentered(this, DIALOG_WIDTH, DIALOG_HEIGHT);
//startModal();
}
@ -188,28 +184,28 @@ public class AbilityPicker extends JXPanel implements MouseWheelListener {
GroupLayout.TRAILING,
layout.createSequentialGroup().addContainerGap().add(
layout.createParallelGroup(GroupLayout.TRAILING).add(GroupLayout.LEADING, jScrollPane2, GroupLayout.DEFAULT_SIZE, 422, Short.MAX_VALUE).add(GroupLayout.LEADING,
layout.createSequentialGroup().add(jLabel1).addPreferredGap(LayoutStyle.RELATED, 175, Short.MAX_VALUE).add(1, 1, 1)).add(
GroupLayout.LEADING,
layout.createSequentialGroup().add(layout.createParallelGroup(GroupLayout.LEADING)
)
.addPreferredGap(LayoutStyle.RELATED)
.add(
layout.createParallelGroup(GroupLayout.TRAILING)
.add(
GroupLayout.LEADING, layout.createParallelGroup(GroupLayout.LEADING))))).add(10, 10, 10)));
layout.createSequentialGroup().add(jLabel1).addPreferredGap(LayoutStyle.RELATED, 175, Short.MAX_VALUE).add(1, 1, 1)).add(
GroupLayout.LEADING,
layout.createSequentialGroup().add(layout.createParallelGroup(GroupLayout.LEADING)
)
.addPreferredGap(LayoutStyle.RELATED)
.add(
layout.createParallelGroup(GroupLayout.TRAILING)
.add(
GroupLayout.LEADING, layout.createParallelGroup(GroupLayout.LEADING))))).add(10, 10, 10)));
layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.LEADING).add(
layout.createSequentialGroup().add(
layout.createParallelGroup(GroupLayout.LEADING).add(
layout.createSequentialGroup().add(jLabel1, GroupLayout.PREFERRED_SIZE, 36, GroupLayout.PREFERRED_SIZE)
.add(5, 5, 5)
.add(
layout.createParallelGroup(GroupLayout.BASELINE)
)
).add(layout.createSequentialGroup().add(8, 8, 8)))
.addPreferredGap(LayoutStyle.RELATED).add(layout.createParallelGroup(GroupLayout.BASELINE)).addPreferredGap(LayoutStyle.RELATED).add(
layout.createParallelGroup(GroupLayout.BASELINE)).addPreferredGap(LayoutStyle.RELATED).add(layout.createParallelGroup(GroupLayout.LEADING)).addPreferredGap(
LayoutStyle.RELATED).add(jScrollPane2, GroupLayout.PREFERRED_SIZE, 180, GroupLayout.PREFERRED_SIZE).addContainerGap(23, Short.MAX_VALUE)));
layout.createSequentialGroup().add(jLabel1, GroupLayout.PREFERRED_SIZE, 36, GroupLayout.PREFERRED_SIZE)
.add(5, 5, 5)
.add(
layout.createParallelGroup(GroupLayout.BASELINE)
)
).add(layout.createSequentialGroup().add(8, 8, 8)))
.addPreferredGap(LayoutStyle.RELATED).add(layout.createParallelGroup(GroupLayout.BASELINE)).addPreferredGap(LayoutStyle.RELATED).add(
layout.createParallelGroup(GroupLayout.BASELINE)).addPreferredGap(LayoutStyle.RELATED).add(layout.createParallelGroup(GroupLayout.LEADING)).addPreferredGap(
LayoutStyle.RELATED).add(jScrollPane2, GroupLayout.PREFERRED_SIZE, 180, GroupLayout.PREFERRED_SIZE).addContainerGap(23, Short.MAX_VALUE)));
}
@Override

View file

@ -41,7 +41,7 @@ import mage.view.PlaneView;
import org.apache.log4j.Logger;
import org.mage.card.arcane.ManaSymbols;
import org.mage.plugins.card.images.CardDownloadData;
import static org.mage.plugins.card.images.DownloadPictures.getTokenCardUrls;
import static org.mage.plugins.card.images.DownloadPicturesService.getTokenCardUrls;
/**
* Mage book with cards and page flipping.

View file

@ -34,6 +34,8 @@ import javax.swing.DefaultComboBoxModel;
import javax.swing.JLayeredPane;
import javax.swing.JOptionPane;
import javax.swing.SwingWorker;
import mage.cards.repository.CardRepository;
import mage.choices.Choice;
import mage.choices.ChoiceImpl;
import mage.client.MageFrame;
@ -454,7 +456,8 @@ public class ConnectDialog extends MageDialog {
connection.setPort(Integer.valueOf(this.txtPort.getText().trim()));
connection.setUsername(this.txtUserName.getText().trim());
connection.setPassword(this.txtPassword.getText().trim());
connection.setForceDBComparison(this.chkForceUpdateDB.isSelected());
boolean redownloadDatabase = CardRepository.instance.findCard("Island") == null;
connection.setForceDBComparison(this.chkForceUpdateDB.isSelected() || redownloadDatabase);
String allMAC = "";
try {
allMAC = connection.getMAC();

View file

@ -0,0 +1,560 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.8" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JInternalFrameFormInfo">
<Properties>
<Property name="title" type="java.lang.String" value="Downloading images"/>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[600, 400]"/>
</Property>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
</SyntheticProperties>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,73,0,0,2,65"/>
</AuxValues>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
<SubComponents>
<Container class="javax.swing.JPanel" name="panelGlobal">
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
<BorderConstraints direction="North"/>
</Constraint>
</Constraints>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBoxLayout">
<Property name="axis" type="int" value="1"/>
</Layout>
<SubComponents>
<Component class="javax.swing.Box$Filler" name="fillerGlobal1">
<Properties>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[32767, 5]"/>
</Property>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[0, 5]"/>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[0, 5]"/>
</Property>
</Properties>
<AuxValues>
<AuxValue name="classDetails" type="java.lang.String" value="Box.Filler.VerticalStrut"/>
</AuxValues>
</Component>
<Component class="javax.swing.JLabel" name="labelGlobal">
<Properties>
<Property name="text" type="java.lang.String" value="Initializing image download..."/>
<Property name="alignmentX" type="float" value="0.5"/>
</Properties>
</Component>
<Component class="javax.swing.JButton" name="buttonStop">
<Properties>
<Property name="text" type="java.lang.String" value="Cancel"/>
<Property name="alignmentX" type="float" value="0.5"/>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[65, 30]"/>
</Property>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonStopActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.Box$Filler" name="fillerglobal2">
<Properties>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[32767, 5]"/>
</Property>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[0, 5]"/>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[0, 5]"/>
</Property>
</Properties>
<AuxValues>
<AuxValue name="classDetails" type="java.lang.String" value="Box.Filler.VerticalStrut"/>
</AuxValues>
</Component>
</SubComponents>
</Container>
<Container class="javax.swing.JTabbedPane" name="tabsList">
<Properties>
<Property name="tabLayoutPolicy" type="int" value="1"/>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
<BorderConstraints direction="Center"/>
</Constraint>
</Constraints>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout"/>
<SubComponents>
<Container class="javax.swing.JPanel" name="tabMain">
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout$JTabbedPaneConstraintsDescription">
<JTabbedPaneConstraints tabName="Standard download">
<Property name="tabTitle" type="java.lang.String" value="Standard download"/>
<Property name="tabIcon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
<Image iconType="3" name="/buttons/card_panel.png"/>
</Property>
</JTabbedPaneConstraints>
</Constraint>
</Constraints>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBoxLayout">
<Property name="axis" type="int" value="1"/>
</Layout>
<SubComponents>
<Container class="javax.swing.JPanel" name="panelInfo">
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBoxLayout">
<Property name="axis" type="int" value="1"/>
</Layout>
<SubComponents>
<Component class="javax.swing.Box$Filler" name="fillerInfo1">
<Properties>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[32767, 5]"/>
</Property>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[0, 5]"/>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[0, 5]"/>
</Property>
</Properties>
<AuxValues>
<AuxValue name="classDetails" type="java.lang.String" value="Box.Filler.VerticalStrut"/>
</AuxValues>
</Component>
<Component class="javax.swing.JLabel" name="labelInfo">
<Properties>
<Property name="text" type="java.lang.String" value="Missing stats: 12345 card images / 789 token images"/>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.EmptyBorderInfo">
<EmptyBorder bottom="0" left="7" right="0" top="0"/>
</Border>
</Property>
</Properties>
</Component>
<Component class="javax.swing.Box$Filler" name="fillerInfo2">
<Properties>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[32767, 5]"/>
</Property>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[0, 5]"/>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[0, 5]"/>
</Property>
</Properties>
<AuxValues>
<AuxValue name="classDetails" type="java.lang.String" value="Box.Filler.VerticalStrut"/>
</AuxValues>
</Component>
</SubComponents>
</Container>
<Container class="javax.swing.JPanel" name="panelSource">
<Properties>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[65536, 55]"/>
</Property>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[352, 55]"/>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[593, 55]"/>
</Property>
</Properties>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBoxLayout">
<Property name="axis" type="int" value="0"/>
</Layout>
<SubComponents>
<Container class="javax.swing.JPanel" name="panelSourceLeft">
<Properties>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[430, 30]"/>
</Property>
</Properties>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignFlowLayout">
<Property name="alignment" type="int" value="3"/>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="labelSource">
<Properties>
<Property name="text" type="java.lang.String" value="Images source to download:"/>
</Properties>
</Component>
<Component class="javax.swing.JComboBox" name="comboSource">
<Properties>
<Property name="maximumRowCount" type="int" value="15"/>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="4">
<StringItem index="0" value="Item 1"/>
<StringItem index="1" value="Item 2"/>
<StringItem index="2" value="Item 3"/>
<StringItem index="3" value="Item 4"/>
</StringArray>
</Property>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[300, 20]"/>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[400, 25]"/>
</Property>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;String&gt;"/>
</AuxValues>
</Component>
</SubComponents>
</Container>
<Container class="javax.swing.JPanel" name="panelSourceRight">
<Properties>
<Property name="alignmentX" type="float" value="0.0"/>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[130, 32767]"/>
</Property>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[130, 30]"/>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[130, 100]"/>
</Property>
</Properties>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignFlowLayout">
<Property name="alignment" type="int" value="3"/>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="labelLanguage">
<Properties>
<Property name="text" type="java.lang.String" value="Language:"/>
</Properties>
</Component>
<Component class="javax.swing.JComboBox" name="comboLanguage">
<Properties>
<Property name="maximumRowCount" type="int" value="15"/>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="4">
<StringItem index="0" value="Item 1"/>
<StringItem index="1" value="Item 2"/>
<StringItem index="2" value="Item 3"/>
<StringItem index="3" value="Item 4"/>
</StringArray>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[90, 25]"/>
</Property>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;String&gt;"/>
</AuxValues>
</Component>
</SubComponents>
</Container>
</SubComponents>
</Container>
<Container class="javax.swing.JPanel" name="panelMode">
<Properties>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[32869, 55]"/>
</Property>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[322, 55]"/>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[100, 55]"/>
</Property>
</Properties>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBoxLayout"/>
<SubComponents>
<Container class="javax.swing.JPanel" name="panelModeInner">
<Properties>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[430, 43]"/>
</Property>
</Properties>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignFlowLayout">
<Property name="alignment" type="int" value="0"/>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="labelMode">
<Properties>
<Property name="text" type="java.lang.String" value="Sets to download:"/>
<Property name="alignmentY" type="float" value="0.0"/>
</Properties>
</Component>
<Container class="javax.swing.JPanel" name="panelModeSelect">
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBoxLayout">
<Property name="axis" type="int" value="0"/>
</Layout>
<SubComponents>
<Component class="javax.swing.JComboBox" name="comboSets">
<Properties>
<Property name="maximumRowCount" type="int" value="15"/>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="4">
<StringItem index="0" value="Item 1"/>
<StringItem index="1" value="Item 2"/>
<StringItem index="2" value="Item 3"/>
<StringItem index="3" value="Item 4"/>
</StringArray>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[373, 25]"/>
</Property>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;String&gt;"/>
</AuxValues>
</Component>
<Component class="javax.swing.Box$Filler" name="fillerMode1">
<Properties>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[5, 32767]"/>
</Property>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[5, 0]"/>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[5, 0]"/>
</Property>
</Properties>
<AuxValues>
<AuxValue name="classDetails" type="java.lang.String" value="Box.Filler.HorizontalStrut"/>
</AuxValues>
</Component>
<Component class="javax.swing.JButton" name="buttonSearchSet">
<Properties>
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
<Image iconType="3" name="/buttons/search_24.png"/>
</Property>
<Property name="toolTipText" type="java.lang.String" value="Fast search your flag"/>
<Property name="alignmentX" type="float" value="1.0"/>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[25, 25]"/>
</Property>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonSearchSetActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Container>
</SubComponents>
</Container>
<Container class="javax.swing.JPanel" name="panelRedownload">
<Properties>
<Property name="alignmentX" type="float" value="0.0"/>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[130, 32767]"/>
</Property>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[130, 30]"/>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[130, 100]"/>
</Property>
</Properties>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
<SubComponents>
<Component class="javax.swing.JCheckBox" name="checkboxRedownload">
<Properties>
<Property name="text" type="java.lang.String" value="&lt;html&gt;Re-download selected images"/>
<Property name="verticalAlignment" type="int" value="3"/>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
<BorderConstraints direction="Center"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.Box$Filler" name="filler1">
<Properties>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[32767, 5]"/>
</Property>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[0, 5]"/>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[0, 3]"/>
</Property>
</Properties>
<AuxValues>
<AuxValue name="classDetails" type="java.lang.String" value="Box.Filler.VerticalStrut"/>
</AuxValues>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
<BorderConstraints direction="Last"/>
</Constraint>
</Constraints>
</Component>
</SubComponents>
</Container>
</SubComponents>
</Container>
<Component class="javax.swing.Box$Filler" name="fillerMain1">
<Properties>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[32767, 10]"/>
</Property>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[0, 10]"/>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[0, 10]"/>
</Property>
</Properties>
<AuxValues>
<AuxValue name="classDetails" type="java.lang.String" value="Box.Filler.VerticalStrut"/>
</AuxValues>
</Component>
<Container class="javax.swing.JPanel" name="panelProgress">
<Properties>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[32777, 30]"/>
</Property>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[20, 30]"/>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[564, 30]"/>
</Property>
</Properties>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBoxLayout">
<Property name="axis" type="int" value="0"/>
</Layout>
<SubComponents>
<Component class="javax.swing.Box$Filler" name="fillerProgress1">
<Properties>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[5, 32767]"/>
</Property>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[5, 0]"/>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[5, 0]"/>
</Property>
</Properties>
<AuxValues>
<AuxValue name="classDetails" type="java.lang.String" value="Box.Filler.HorizontalStrut"/>
</AuxValues>
</Component>
<Component class="javax.swing.JProgressBar" name="progress">
<Properties>
<Property name="value" type="int" value="75"/>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[32767, 25]"/>
</Property>
<Property name="string" type="java.lang.String" value="123 of 12313 (120 cards/546 tokens) image downloads finished! Please wait! [123 Mb]"/>
<Property name="stringPainted" type="boolean" value="true"/>
</Properties>
</Component>
<Component class="javax.swing.Box$Filler" name="fillerProgress2">
<Properties>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[5, 32767]"/>
</Property>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[5, 0]"/>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[5, 0]"/>
</Property>
</Properties>
<AuxValues>
<AuxValue name="classDetails" type="java.lang.String" value="Box.Filler.HorizontalStrut"/>
</AuxValues>
</Component>
</SubComponents>
</Container>
<Component class="javax.swing.Box$Filler" name="fillerMain2">
<Properties>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[32767, 32767]"/>
</Property>
</Properties>
<AuxValues>
<AuxValue name="classDetails" type="java.lang.String" value="Box.Filler.Glue"/>
</AuxValues>
</Component>
</SubComponents>
</Container>
<Container class="javax.swing.JPanel" name="tabCustom">
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout$JTabbedPaneConstraintsDescription">
<JTabbedPaneConstraints tabName="Custom download">
<Property name="tabTitle" type="java.lang.String" value="Custom download"/>
<Property name="tabIcon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
<Image iconType="3" name="/buttons/list_panel.png"/>
</Property>
</JTabbedPaneConstraints>
</Constraint>
</Constraints>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBoxLayout">
<Property name="axis" type="int" value="1"/>
</Layout>
</Container>
</SubComponents>
</Container>
<Container class="javax.swing.JPanel" name="panelCommands">
<Properties>
<Property name="alignmentX" type="float" value="0.0"/>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
<BorderConstraints direction="South"/>
</Constraint>
</Constraints>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignFlowLayout">
<Property name="alignment" type="int" value="4"/>
</Layout>
<SubComponents>
<Component class="javax.swing.JButton" name="buttonOK">
<Properties>
<Property name="text" type="java.lang.String" value="Start download"/>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[120, 30]"/>
</Property>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_AddingCodePost" type="java.lang.String" value="getRootPane().setDefaultButton(buttonOK);"/>
<AuxValue name="JavaCodeGenerator_SerializeTo" type="java.lang.String" value="DownloadImagesDialog_buttonOK"/>
</AuxValues>
</Component>
<Component class="javax.swing.JButton" name="buttonCancel">
<Properties>
<Property name="text" type="java.lang.String" value="Cancel"/>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[80, 30]"/>
</Property>
</Properties>
</Component>
</SubComponents>
</Container>
</SubComponents>
</Form>

View file

@ -0,0 +1,470 @@
package mage.client.dialog;
import mage.client.MageFrame;
import mage.client.util.gui.FastSearchUtil;
import mage.client.util.gui.MageDialogState;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.util.HashMap;
import java.util.Map;
/**
* @author JayDi85
*/
public class DownloadImagesDialog extends MageDialog {
public static final int RET_CANCEL = 0;
public static final int RET_OK = 1;
private Dimension sizeModeMessageOnly;
private Dimension sizeModeMessageAndControls;
private Map<Component, Boolean> actionsControlStates = new HashMap<>();
/**
* Creates new form DownloadImagesDialog
*/
public DownloadImagesDialog() {
initComponents();
this.setModal(true);
// fix for panelInfo (it's resets aligmentX after netbeans designer opened)
panelInfo.setAlignmentX(CENTER_ALIGNMENT);
// save default sizes
//
this.sizeModeMessageAndControls = new Dimension(580, 330); // dialog -> properties -> designer size
//
this.sizeModeMessageOnly = new Dimension(this.sizeModeMessageAndControls.getSize());
sizeModeMessageOnly.height = 25 * 4;
sizeModeMessageOnly.width = sizeModeMessageOnly.width / 2;
// Close the dialog when Esc is pressed
String cancelName = "cancel";
InputMap inputMap = getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), cancelName);
ActionMap actionMap = getRootPane().getActionMap();
actionMap.put(cancelName, new AbstractAction() {
public void actionPerformed(ActionEvent e) {
doClose(RET_CANCEL);
}
});
}
public void setWindowSize(int width, int heigth) {
this.setSize(new Dimension(width, heigth));
}
public void showDialog() {
showDialog(null);
}
public void showDialog(MageDialogState mageDialogState) {
showDownloadControls(false); // call to change window size
// window settings
if (this.isModal()) {
MageFrame.getDesktop().add(this, JLayeredPane.MODAL_LAYER);
} else {
MageFrame.getDesktop().add(this, JLayeredPane.PALETTE_LAYER);
}
if (mageDialogState != null) {
mageDialogState.setStateToDialog(this);
} else {
this.makeWindowCentered();
}
this.setVisible(true);
}
public void setGlobalInfo(String info) {
this.labelGlobal.setText(info);
}
public void setCurrentInfo(String info) {
this.labelInfo.setText(info);
}
public JComboBox getSourcesCombo() {
return this.comboSource;
}
public JComboBox getLaunguagesCombo() {
return this.comboLanguage;
}
public JComboBox getSetsCombo() {
return this.comboSets;
}
public JButton getStartButton() {
return this.buttonOK;
}
public JButton getCancelButton() {
return this.buttonCancel;
}
public JButton getStopButton() {
return this.buttonStop;
}
public JProgressBar getProgressBar() {
return this.progress;
}
public JCheckBox getRedownloadCheckbox() {
return this.checkboxRedownload;
}
public void showLanguagesSupport(boolean haveSupport) {
labelLanguage.setEnabled(haveSupport);
comboLanguage.setEnabled(haveSupport);
}
private void enableActionControl(boolean enable, Component comp) {
if (enable) {
// restore last enable state
comp.setEnabled(actionsControlStates.getOrDefault(comp, true));
} else {
// save enable state and disable it
actionsControlStates.putIfAbsent(comp, comp.isEnabled());
comp.setEnabled(false);
}
}
public void enableActionControls(boolean enable) {
// restrict user actions while downloading/processing (all buttons, comboboxes and edits)
enableActionControl(enable, tabsList);
enableActionControl(enable, comboSource);
enableActionControl(enable, comboSets);
enableActionControl(enable, buttonSearchSet);
enableActionControl(enable, comboLanguage);
enableActionControl(enable, checkboxRedownload);
}
private void setTabTitle(int tabIndex, String title, String iconResourceName) {
// tab caption with left sided icon
// https://stackoverflow.com/questions/1782224/jtabbedpane-icon-on-left-side-of-tabs
JLabel lbl = new JLabel(title);
Icon icon = new ImageIcon(getClass().getResource(iconResourceName));
lbl.setIcon(icon);
lbl.setIconTextGap(5);
lbl.setHorizontalTextPosition(SwingConstants.RIGHT);
tabsList.setTabComponentAt(tabIndex, lbl);
}
public void showDownloadControls(boolean needToShow) {
// 2 modes:
// - only message;
// - message + download controls and buttons
this.panelGlobal.setVisible(true);
this.buttonStop.setVisible(!needToShow); // stop button only for loading mode
this.tabsList.setVisible(needToShow);
this.panelCommands.setVisible(needToShow);
// auto-size form
if (needToShow) {
this.setWindowSize(this.sizeModeMessageAndControls.width, this.sizeModeMessageAndControls.height);
} else {
this.setWindowSize(this.sizeModeMessageOnly.width, this.sizeModeMessageOnly.height);
}
this.makeWindowCentered();
//this.setLocationRelativeTo(null); // center screen //FIX
// icons on tabs left side
setTabTitle(0, "Standard download", "/buttons/card_panel.png");
setTabTitle(1, "Custom download", "/buttons/list_panel.png");
// TODO: add manual mode as tab
this.tabsList.getTabComponentAt(1).setEnabled(false);
this.tabsList.setEnabledAt(1, false);
}
/**
* @return the return status of this dialog - one of RET_OK or RET_CANCEL
*/
public int getReturnStatus() {
return returnStatus;
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
panelGlobal = new javax.swing.JPanel();
fillerGlobal1 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 5), new java.awt.Dimension(0, 5), new java.awt.Dimension(32767, 5));
labelGlobal = new javax.swing.JLabel();
buttonStop = new javax.swing.JButton();
fillerglobal2 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 5), new java.awt.Dimension(0, 5), new java.awt.Dimension(32767, 5));
tabsList = new javax.swing.JTabbedPane();
tabMain = new javax.swing.JPanel();
panelInfo = new javax.swing.JPanel();
fillerInfo1 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 5), new java.awt.Dimension(0, 5), new java.awt.Dimension(32767, 5));
labelInfo = new javax.swing.JLabel();
fillerInfo2 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 5), new java.awt.Dimension(0, 5), new java.awt.Dimension(32767, 5));
panelSource = new javax.swing.JPanel();
panelSourceLeft = new javax.swing.JPanel();
labelSource = new javax.swing.JLabel();
comboSource = new javax.swing.JComboBox<>();
panelSourceRight = new javax.swing.JPanel();
labelLanguage = new javax.swing.JLabel();
comboLanguage = new javax.swing.JComboBox<>();
panelMode = new javax.swing.JPanel();
panelModeInner = new javax.swing.JPanel();
labelMode = new javax.swing.JLabel();
panelModeSelect = new javax.swing.JPanel();
comboSets = new javax.swing.JComboBox<>();
fillerMode1 = new javax.swing.Box.Filler(new java.awt.Dimension(5, 0), new java.awt.Dimension(5, 0), new java.awt.Dimension(5, 32767));
buttonSearchSet = new javax.swing.JButton();
panelRedownload = new javax.swing.JPanel();
checkboxRedownload = new javax.swing.JCheckBox();
filler1 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 5), new java.awt.Dimension(0, 3), new java.awt.Dimension(32767, 5));
fillerMain1 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 10), new java.awt.Dimension(0, 10), new java.awt.Dimension(32767, 10));
panelProgress = new javax.swing.JPanel();
fillerProgress1 = new javax.swing.Box.Filler(new java.awt.Dimension(5, 0), new java.awt.Dimension(5, 0), new java.awt.Dimension(5, 32767));
progress = new javax.swing.JProgressBar();
fillerProgress2 = new javax.swing.Box.Filler(new java.awt.Dimension(5, 0), new java.awt.Dimension(5, 0), new java.awt.Dimension(5, 32767));
fillerMain2 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 0), new java.awt.Dimension(32767, 32767));
tabCustom = new javax.swing.JPanel();
panelCommands = new javax.swing.JPanel();
buttonOK = new javax.swing.JButton();
buttonCancel = new javax.swing.JButton();
setTitle("Downloading images");
setPreferredSize(new java.awt.Dimension(600, 400));
getContentPane().setLayout(new java.awt.BorderLayout());
panelGlobal.setLayout(new javax.swing.BoxLayout(panelGlobal, javax.swing.BoxLayout.Y_AXIS));
panelGlobal.add(fillerGlobal1);
labelGlobal.setText("Initializing image download...");
labelGlobal.setAlignmentX(0.5F);
panelGlobal.add(labelGlobal);
buttonStop.setText("Cancel");
buttonStop.setAlignmentX(0.5F);
buttonStop.setPreferredSize(new java.awt.Dimension(65, 30));
buttonStop.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonStopActionPerformed(evt);
}
});
panelGlobal.add(buttonStop);
panelGlobal.add(fillerglobal2);
getContentPane().add(panelGlobal, java.awt.BorderLayout.NORTH);
tabsList.setTabLayoutPolicy(javax.swing.JTabbedPane.SCROLL_TAB_LAYOUT);
tabMain.setLayout(new javax.swing.BoxLayout(tabMain, javax.swing.BoxLayout.Y_AXIS));
panelInfo.setLayout(new javax.swing.BoxLayout(panelInfo, javax.swing.BoxLayout.Y_AXIS));
panelInfo.add(fillerInfo1);
labelInfo.setText("Missing stats: 12345 card images / 789 token images");
labelInfo.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 7, 0, 0));
panelInfo.add(labelInfo);
panelInfo.add(fillerInfo2);
tabMain.add(panelInfo);
panelSource.setMaximumSize(new java.awt.Dimension(65536, 55));
panelSource.setMinimumSize(new java.awt.Dimension(352, 55));
panelSource.setPreferredSize(new java.awt.Dimension(593, 55));
panelSource.setLayout(new javax.swing.BoxLayout(panelSource, javax.swing.BoxLayout.X_AXIS));
panelSourceLeft.setMinimumSize(new java.awt.Dimension(430, 30));
panelSourceLeft.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEADING));
labelSource.setText("Images source to download:");
panelSourceLeft.add(labelSource);
comboSource.setMaximumRowCount(15);
comboSource.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
comboSource.setMinimumSize(new java.awt.Dimension(300, 20));
comboSource.setPreferredSize(new java.awt.Dimension(400, 25));
panelSourceLeft.add(comboSource);
panelSource.add(panelSourceLeft);
panelSourceRight.setAlignmentX(0.0F);
panelSourceRight.setMaximumSize(new java.awt.Dimension(130, 32767));
panelSourceRight.setMinimumSize(new java.awt.Dimension(130, 30));
panelSourceRight.setPreferredSize(new java.awt.Dimension(130, 100));
panelSourceRight.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEADING));
labelLanguage.setText("Language:");
panelSourceRight.add(labelLanguage);
comboLanguage.setMaximumRowCount(15);
comboLanguage.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
comboLanguage.setPreferredSize(new java.awt.Dimension(90, 25));
panelSourceRight.add(comboLanguage);
panelSource.add(panelSourceRight);
tabMain.add(panelSource);
panelMode.setMaximumSize(new java.awt.Dimension(32869, 55));
panelMode.setMinimumSize(new java.awt.Dimension(322, 55));
panelMode.setPreferredSize(new java.awt.Dimension(100, 55));
panelMode.setLayout(new javax.swing.BoxLayout(panelMode, javax.swing.BoxLayout.LINE_AXIS));
panelModeInner.setMinimumSize(new java.awt.Dimension(430, 43));
panelModeInner.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));
labelMode.setText("Sets to download:");
labelMode.setAlignmentY(0.0F);
panelModeInner.add(labelMode);
panelModeSelect.setLayout(new javax.swing.BoxLayout(panelModeSelect, javax.swing.BoxLayout.X_AXIS));
comboSets.setMaximumRowCount(15);
comboSets.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
comboSets.setPreferredSize(new java.awt.Dimension(373, 25));
panelModeSelect.add(comboSets);
panelModeSelect.add(fillerMode1);
buttonSearchSet.setIcon(new javax.swing.ImageIcon(getClass().getResource("/buttons/search_24.png"))); // NOI18N
buttonSearchSet.setToolTipText("Fast search your flag");
buttonSearchSet.setAlignmentX(1.0F);
buttonSearchSet.setPreferredSize(new java.awt.Dimension(25, 25));
buttonSearchSet.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonSearchSetActionPerformed(evt);
}
});
panelModeSelect.add(buttonSearchSet);
panelModeInner.add(panelModeSelect);
panelMode.add(panelModeInner);
panelRedownload.setAlignmentX(0.0F);
panelRedownload.setMaximumSize(new java.awt.Dimension(130, 32767));
panelRedownload.setMinimumSize(new java.awt.Dimension(130, 30));
panelRedownload.setPreferredSize(new java.awt.Dimension(130, 100));
panelRedownload.setLayout(new java.awt.BorderLayout());
checkboxRedownload.setText("<html>Re-download selected images");
checkboxRedownload.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
panelRedownload.add(checkboxRedownload, java.awt.BorderLayout.CENTER);
panelRedownload.add(filler1, java.awt.BorderLayout.PAGE_END);
panelMode.add(panelRedownload);
tabMain.add(panelMode);
tabMain.add(fillerMain1);
panelProgress.setMaximumSize(new java.awt.Dimension(32777, 30));
panelProgress.setMinimumSize(new java.awt.Dimension(20, 30));
panelProgress.setPreferredSize(new java.awt.Dimension(564, 30));
panelProgress.setLayout(new javax.swing.BoxLayout(panelProgress, javax.swing.BoxLayout.X_AXIS));
panelProgress.add(fillerProgress1);
progress.setValue(75);
progress.setMaximumSize(new java.awt.Dimension(32767, 25));
progress.setString("123 of 12313 (120 cards/546 tokens) image downloads finished! Please wait! [123 Mb]");
progress.setStringPainted(true);
panelProgress.add(progress);
panelProgress.add(fillerProgress2);
tabMain.add(panelProgress);
tabMain.add(fillerMain2);
tabsList.addTab("Standard download", new javax.swing.ImageIcon(getClass().getResource("/buttons/card_panel.png")), tabMain); // NOI18N
tabCustom.setLayout(new javax.swing.BoxLayout(tabCustom, javax.swing.BoxLayout.Y_AXIS));
tabsList.addTab("Custom download", new javax.swing.ImageIcon(getClass().getResource("/buttons/list_panel.png")), tabCustom); // NOI18N
getContentPane().add(tabsList, java.awt.BorderLayout.CENTER);
panelCommands.setAlignmentX(0.0F);
panelCommands.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.TRAILING));
buttonOK.setText("Start download");
buttonOK.setPreferredSize(new java.awt.Dimension(120, 30));
panelCommands.add(buttonOK);
getRootPane().setDefaultButton(buttonOK);
buttonCancel.setText("Cancel");
buttonCancel.setPreferredSize(new java.awt.Dimension(80, 30));
panelCommands.add(buttonCancel);
getContentPane().add(panelCommands, java.awt.BorderLayout.SOUTH);
pack();
}// </editor-fold>//GEN-END:initComponents
/**
* Closes the dialog
*/
private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
doClose(RET_CANCEL);
}//GEN-LAST:event_closeDialog
private void buttonSearchSetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSearchSetActionPerformed
FastSearchUtil.showFastSearchForStringComboBox(comboSets, FastSearchUtil.DEFAULT_EXPANSION_SEARCH_MESSAGE, 400, 500);
}//GEN-LAST:event_buttonSearchSetActionPerformed
private void buttonStopActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStopActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_buttonStopActionPerformed
private void doClose(int retStatus) {
returnStatus = retStatus;
setVisible(false);
dispose();
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton buttonCancel;
private javax.swing.JButton buttonOK;
private javax.swing.JButton buttonSearchSet;
private javax.swing.JButton buttonStop;
private javax.swing.JCheckBox checkboxRedownload;
private javax.swing.JComboBox<String> comboLanguage;
private javax.swing.JComboBox<String> comboSets;
private javax.swing.JComboBox<String> comboSource;
private javax.swing.Box.Filler filler1;
private javax.swing.Box.Filler fillerGlobal1;
private javax.swing.Box.Filler fillerInfo1;
private javax.swing.Box.Filler fillerInfo2;
private javax.swing.Box.Filler fillerMain1;
private javax.swing.Box.Filler fillerMain2;
private javax.swing.Box.Filler fillerMode1;
private javax.swing.Box.Filler fillerProgress1;
private javax.swing.Box.Filler fillerProgress2;
private javax.swing.Box.Filler fillerglobal2;
private javax.swing.JLabel labelGlobal;
private javax.swing.JLabel labelInfo;
private javax.swing.JLabel labelLanguage;
private javax.swing.JLabel labelMode;
private javax.swing.JLabel labelSource;
private javax.swing.JPanel panelCommands;
private javax.swing.JPanel panelGlobal;
private javax.swing.JPanel panelInfo;
private javax.swing.JPanel panelMode;
private javax.swing.JPanel panelModeInner;
private javax.swing.JPanel panelModeSelect;
private javax.swing.JPanel panelProgress;
private javax.swing.JPanel panelRedownload;
private javax.swing.JPanel panelSource;
private javax.swing.JPanel panelSourceLeft;
private javax.swing.JPanel panelSourceRight;
private javax.swing.JProgressBar progress;
private javax.swing.JPanel tabCustom;
private javax.swing.JPanel tabMain;
private javax.swing.JTabbedPane tabsList;
// End of variables declaration//GEN-END:variables
private int returnStatus = RET_CANCEL;
}

View file

@ -1,31 +1,19 @@
/*
* MageDialog.java
*
* Created on 15-Dec-2009, 10:28:27 PM
*/
package mage.client.dialog;
import java.awt.AWTEvent;
import java.awt.ActiveEvent;
import java.awt.Component;
import java.awt.EventQueue;
import java.awt.KeyboardFocusManager;
import java.awt.MenuComponent;
import java.awt.TrayIcon;
import mage.client.MageFrame;
import mage.client.util.SettingsManager;
import mage.client.util.gui.GuiDisplayUtil;
import org.apache.log4j.Logger;
import javax.swing.*;
import java.awt.*;
import java.awt.event.InvocationEvent;
import java.awt.event.MouseEvent;
import java.beans.PropertyVetoException;
import java.lang.reflect.InvocationTargetException;
import java.util.logging.Level;
import javax.swing.*;
import mage.client.MageFrame;
import org.apache.log4j.Logger;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class MageDialog extends javax.swing.JInternalFrame {
@ -75,7 +63,7 @@ public class MageDialog extends javax.swing.JInternalFrame {
this.toFront();
if (modal){
if (modal) {
startModal();
}
}
@ -105,6 +93,7 @@ public class MageDialog extends javax.swing.JInternalFrame {
}
private synchronized void startModal() {
// modal loop -- all mouse events must be ignored by other windows
try {
if (SwingUtilities.isEventDispatchThread()) {
EventQueue theQueue = getToolkit().getSystemEventQueue();
@ -115,18 +104,46 @@ public class MageDialog extends javax.swing.JInternalFrame {
// https://github.com/magefree/mage/issues/584 - Let's hope this will fix the Linux window problem
if (event.getSource() != null && event.getSource() instanceof TrayIcon && !(event instanceof InvocationEvent)) {
return;
dispatch = false;
//return; // JayDi85: users can move mouse over try icon to disable modal mode (it's a bug but can be used in the future)
}
// ignore mouse events outside from panel, only drag and move allowed -- as example:
// combobox's popup will be selectable outside
// cards and button hints will be works
Component popupComponent = null;
MouseEvent popupEvent = null;
if (event instanceof MouseEvent && event.getSource() instanceof Component) {
MouseEvent e = (MouseEvent) event;
MouseEvent m = SwingUtilities.convertMouseEvent((Component) e.getSource(), e, this);
if (!this.contains(m.getPoint()) && e.getID() != MouseEvent.MOUSE_DRAGGED) {
dispatch = false;
// disable all outer events (except some actions)
if (!this.contains(m.getPoint())) {
boolean allowedEvent = false;
// need any mouse move (for hints)
if (e.getID() == MouseEvent.MOUSE_DRAGGED || e.getID() == MouseEvent.MOUSE_MOVED) {
allowedEvent = true;
}
// need popup clicks and mouse wheel (for out of bound actions)
if (!allowedEvent) {
popupComponent = SwingUtilities.getDeepestComponentAt(e.getComponent(), e.getX(), e.getY()); // show root component (popups creates at root)
if (popupComponent != null && popupComponent.getClass().getName().contains("BasicComboPopup")) {
popupEvent = SwingUtilities.convertMouseEvent((Component) e.getSource(), e, popupComponent);
allowedEvent = true;
}
}
dispatch = allowedEvent;
}
}
if (dispatch) {
if (event instanceof ActiveEvent) {
if (popupEvent != null) {
// process outer popup events, it's must be FIRST check
popupComponent.dispatchEvent(popupEvent);
} else if (event instanceof ActiveEvent) {
((ActiveEvent) event).dispatch();
} else if (source instanceof Component) {
((Component) source).dispatchEvent(event);
@ -174,14 +191,21 @@ public class MageDialog extends javax.swing.JInternalFrame {
java.util.logging.Logger.getLogger(MageDialog.class.getName()).log(Level.SEVERE, "setClosed(false) failed", ex);
}
MageFrame.getDesktop().remove(this);
}
public void makeWindowCentered() {
makeWindowCentered(this, getWidth(), getHeight());
}
public static void makeWindowCentered(Component component, int width, int height) {
Point centered = SettingsManager.instance.getComponentPosition(width, height);
component.setLocation(centered.x, centered.y);
GuiDisplayUtil.keepComponentInsideScreen(centered.x, centered.y, component);
}
/**
* Used to set a tooltip text on icon and titel bar
*
* used in {@link ExileZoneDialog} and {@link ShowCardsDialog}
*
* @param text
*/
public void setTitelBarToolTip(final String text) {
@ -209,12 +233,12 @@ public class MageDialog extends javax.swing.JInternalFrame {
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 394, Short.MAX_VALUE)
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 394, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 274, Short.MAX_VALUE)
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 274, Short.MAX_VALUE)
);
pack();

View file

@ -1,37 +1,17 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package mage.client.dialog;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.*;
import javax.swing.AbstractAction;
import javax.swing.ActionMap;
import javax.swing.DefaultListModel;
import javax.swing.InputMap;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JLayeredPane;
import javax.swing.KeyStroke;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import mage.choices.Choice;
import mage.client.MageFrame;
import mage.client.util.SettingsManager;
import mage.client.util.gui.GuiDisplayUtil;
import mage.client.util.gui.MageDialogState;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
/**
*
* @author JayDi85
* @author Salco
*/
@ -42,28 +22,29 @@ public class PickCheckBoxDialog extends MageDialog {
ArrayList<KeyValueItem> allItems = new ArrayList<>();
DefaultListModel<KeyValueItem> dataModel = new DefaultListModel();
CheckBoxList.CheckBoxListModel m_dataModel;
CheckBoxList tList;
final private static String HTML_TEMPLATE = "<html><div style='text-align: center;'>%s</div></html>";
private void setFocus(CheckBoxList obj){
private void setFocus(CheckBoxList obj) {
if (!(obj instanceof java.awt.Component)) {
throw new IllegalArgumentException("Must be a java.awt.Component!");
}
this.scrollList.setViewportView((java.awt.Component)obj);
}
private javax.swing.JList get_a_Jlist_from_ScrollListView(){
return ((javax.swing.JList)this.scrollList.getViewport().getView());
this.scrollList.setViewportView((java.awt.Component) obj);
}
private void restoreData(Object dataFrom){
private javax.swing.JList get_a_Jlist_from_ScrollListView() {
return ((javax.swing.JList) this.scrollList.getViewport().getView());
}
private void restoreData(Object dataFrom) {
this.allItems.forEach((item) -> {
((CheckBoxList.CheckBoxListModel)dataFrom).addElement(item.getObjectValue());
((CheckBoxList.CheckBoxListModel) dataFrom).addElement(item.getObjectValue());
});
}
public void showDialog(Choice choice) {
showDialog(choice, null, null, null);
}
@ -75,47 +56,45 @@ public class PickCheckBoxDialog extends MageDialog {
public void showDialog(Choice choice, UUID objectId, MageDialogState mageDialogState) {
showDialog(choice, objectId, mageDialogState, null);
}
public void showDialog(Choice choice, UUID objectId, MageDialogState mageDialogState, String startSelectionValue) {
this.choice = choice;
KeyValueItem tempKeyValue;
int indexInTList;
setLabelText(this.labelMessage, choice.getMessage());
setLabelText(this.labelSubMessage, choice.getSubMessage());
btCancel.setEnabled(!choice.isRequired());
// 2 modes: string or key-values
// sore data in allItems for inremental filtering
// http://logicbig.com/tutorials/core-java-tutorial/swing/list-filter/
this.allItems.clear();
if (choice.isKeyChoice()){
for (Map.Entry<String, String> entry: choice.getKeyChoices().entrySet()) {
if(tList != null){
if (choice.isKeyChoice()) {
for (Map.Entry<String, String> entry : choice.getKeyChoices().entrySet()) {
if (tList != null) {
indexInTList = m_dataModel.indexOf(entry.getKey());
tempKeyValue=new KeyValueItem(entry.getKey(), entry.getValue(),(CheckBoxList.CheckBoxListItem) this.tList.getModel().getElementAt(indexInTList));
}
else{
tempKeyValue=new KeyValueItem(entry.getKey(), entry.getValue());
tempKeyValue = new KeyValueItem(entry.getKey(), entry.getValue(), (CheckBoxList.CheckBoxListItem) this.tList.getModel().getElementAt(indexInTList));
} else {
tempKeyValue = new KeyValueItem(entry.getKey(), entry.getValue());
}
this.allItems.add(tempKeyValue);
}
} else {
for (String value: choice.getChoices()){
if(tList != null){
for (String value : choice.getChoices()) {
if (tList != null) {
indexInTList = m_dataModel.indexOf(value);
tempKeyValue=new KeyValueItem(value, value,(CheckBoxList.CheckBoxListItem) tList.getModel().getElementAt(indexInTList));
}
else{
tempKeyValue=new KeyValueItem(value, value);
tempKeyValue = new KeyValueItem(value, value, (CheckBoxList.CheckBoxListItem) tList.getModel().getElementAt(indexInTList));
} else {
tempKeyValue = new KeyValueItem(value, value);
}
this.allItems.add(tempKeyValue);
}
}
// sorting
if(choice.isSortEnabled()){
if (choice.isSortEnabled()) {
Collections.sort(this.allItems, new Comparator<KeyValueItem>() {
@Override
public int compare(KeyValueItem o1, KeyValueItem o2) {
@ -125,38 +104,37 @@ public class PickCheckBoxDialog extends MageDialog {
}
});
}
// search
if(choice.isSearchEnabled())
{
if (choice.isSearchEnabled()) {
panelSearch.setVisible(true);
this.editSearch.setText(choice.getSearchText());
}else{
} else {
panelSearch.setVisible(false);
this.editSearch.setText("");
}
// listeners for inremental filtering
editSearch.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void insertUpdate(DocumentEvent e) {
choice.setSearchText(editSearch.getText());
loadData();
}
@Override
public void insertUpdate(DocumentEvent e) {
choice.setSearchText(editSearch.getText());
loadData();
}
@Override
public void removeUpdate(DocumentEvent e) {
choice.setSearchText(editSearch.getText());
loadData();
}
@Override
public void removeUpdate(DocumentEvent e) {
choice.setSearchText(editSearch.getText());
loadData();
}
@Override
public void changedUpdate(DocumentEvent e) {
choice.setSearchText(editSearch.getText());
loadData();
}
@Override
public void changedUpdate(DocumentEvent e) {
choice.setSearchText(editSearch.getText());
loadData();
}
});
// listeners for select up and down without edit focus lost
editSearch.addKeyListener(new KeyListener() {
@Override
@ -165,10 +143,10 @@ public class PickCheckBoxDialog extends MageDialog {
}
@Override
public void keyPressed(KeyEvent e) {
if(e.getKeyCode() == KeyEvent.VK_UP){
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_UP) {
doPrevSelect();
}else if(e.getKeyCode() == KeyEvent.VK_DOWN){
} else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
doNextSelect();
}
}
@ -178,19 +156,19 @@ public class PickCheckBoxDialog extends MageDialog {
//System.out.println("released");
}
});
// listeners double click choose
listChoices.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if(e.getClickCount() == 2){
if (e.getClickCount() == 2) {
doChoose();
}
}
});
// listeners for ESC close
if(!choice.isRequired()){
if (!choice.isRequired()) {
String cancelName = "cancel";
InputMap inputMap = getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), cancelName);
@ -201,107 +179,106 @@ public class PickCheckBoxDialog extends MageDialog {
}
});
}
// window settings
if (this.isModal()){
if (this.isModal()) {
MageFrame.getDesktop().add(this, JLayeredPane.MODAL_LAYER);
}else{
} else {
MageFrame.getDesktop().add(this, JLayeredPane.PALETTE_LAYER);
}
if (mageDialogState != null) {
mageDialogState.setStateToDialog(this);
} else {
Point centered = SettingsManager.instance.getComponentPosition(getWidth(), getHeight());
this.setLocation(centered.x, centered.y);
GuiDisplayUtil.keepComponentInsideScreen(centered.x, centered.y, this);
this.makeWindowCentered();
}
// final load
loadData();
// start selection
if((startSelectionValue != null)){
if ((startSelectionValue != null)) {
javax.swing.JList currentlistChoices;// = new javax.swing.JList();
currentlistChoices=this.get_a_Jlist_from_ScrollListView();
currentlistChoices = this.get_a_Jlist_from_ScrollListView();
/*currentlistChoices = this.listChoices;*/
int selectIndex = -1;
for(int i = 0; i < this.listChoices.getModel().getSize(); i++){
for (int i = 0; i < this.listChoices.getModel().getSize(); i++) {
//KeyValueItem listItem = (KeyValueItem)currentlistChoices.getModel().getElementAt(i);
String elementOfList = currentlistChoices.getModel().getElementAt(i).toString();
if (elementOfList.equals(startSelectionValue)){
if (elementOfList.equals(startSelectionValue)) {
selectIndex = i;
break;
}
}
if(selectIndex >= 0){
// currentlistChoices=this.get_a_Jlist_from_ScrollListView();
if (selectIndex >= 0) {
// currentlistChoices=this.get_a_Jlist_from_ScrollListView();
/*currentlistChoices = this.listChoices;*/
currentlistChoices.setSelectedIndex(selectIndex);
currentlistChoices.ensureIndexIsVisible(selectIndex);
currentlistChoices.setSelectedIndex(selectIndex);
currentlistChoices.ensureIndexIsVisible(selectIndex);
}
}
this.setVisible(true);
}
public void setWindowSize(int width, int heigth){
public void setWindowSize(int width, int heigth) {
this.setSize(new Dimension(width, heigth));
}
private void loadData(){
private void loadData() {
// load data to datamodel after filter or on startup
String filter = choice.getSearchText();
if (filter == null){ filter = ""; }
String filter = choice.getSearchText();
if (filter == null) {
filter = "";
}
filter = filter.toLowerCase();
this.dataModel.clear();
this.m_dataModel.clear();
for(KeyValueItem item: this.allItems){
if(!choice.isSearchEnabled() || item.Value.toLowerCase().contains(filter)){
for (KeyValueItem item : this.allItems) {
if (!choice.isSearchEnabled() || item.Value.toLowerCase().contains(filter)) {
this.dataModel.addElement(item);
this.m_dataModel.addElement(item.getObjectValue());
}
}
}
private void setLabelText(JLabel label, String text){
if ((text != null) && !text.equals("")){
private void setLabelText(JLabel label, String text) {
if ((text != null) && !text.equals("")) {
label.setText(String.format(HTML_TEMPLATE, text));
label.setVisible(true);
}else{
} else {
label.setText("");
label.setVisible(false);
}
}
private void doNextSelect(){
int newSel = this.listChoices.getSelectedIndex() + 1;
int maxSel = this.listChoices.getModel().getSize() - 1;
if(newSel <= maxSel){
this.listChoices.setSelectedIndex(newSel);
this.listChoices.ensureIndexIsVisible(newSel);
}
}
private void doPrevSelect(){
int newSel = this.listChoices.getSelectedIndex() - 1;
if(newSel >= 0){
private void doNextSelect() {
int newSel = this.listChoices.getSelectedIndex() + 1;
int maxSel = this.listChoices.getModel().getSize() - 1;
if (newSel <= maxSel) {
this.listChoices.setSelectedIndex(newSel);
this.listChoices.ensureIndexIsVisible(newSel);
}
}
private void doChoose(){
if((tList != null)||(setChoice())){
private void doPrevSelect() {
int newSel = this.listChoices.getSelectedIndex() - 1;
if (newSel >= 0) {
this.listChoices.setSelectedIndex(newSel);
this.listChoices.ensureIndexIsVisible(newSel);
}
}
private void doChoose() {
if ((tList != null) || (setChoice())) {
this.m_dataModel.clear();
restoreData(this.m_dataModel);
this.hideDialog();
}
}
private void doCancel(){
private void doCancel() {
this.listChoices.clearSelection();
this.choice.clearChoice();
hideDialog();
@ -309,91 +286,93 @@ public class PickCheckBoxDialog extends MageDialog {
/**
* Creates new form PickChoiceDialog
* @param list
*
* @param list
*/
public PickCheckBoxDialog(CheckBoxList list) {
initComponents();
tList=list;
tList = list;
this.listChoices.setModel(dataModel);
this.setModal(true);
if(tList != null)
{
if (tList != null) {
this.listChoices.setVisible(false);
m_dataModel= ( CheckBoxList.CheckBoxListModel )tList.getModel();
m_dataModel = (CheckBoxList.CheckBoxListModel) tList.getModel();
tList.setSelectionForeground(Color.BLUE);
if(this.tList instanceof javax.swing.JList){
setFocus(tList);
}
if (this.tList instanceof javax.swing.JList) {
setFocus(tList);
}
}
}
/**
* Creates new form PickChoiceDialog
*/
public PickCheckBoxDialog() {
this(null);
}
public boolean setChoice() {
KeyValueItem item = (KeyValueItem)this.listChoices.getSelectedValue();
KeyValueItem item = (KeyValueItem) this.listChoices.getSelectedValue();
// auto select one item (after incemental filtering)
if((item == null) && (this.listChoices.getModel().getSize() == 1)){
if ((item == null) && (this.listChoices.getModel().getSize() == 1)) {
this.listChoices.setSelectedIndex(0);
item = (KeyValueItem)this.listChoices.getSelectedValue();
item = (KeyValueItem) this.listChoices.getSelectedValue();
}
if(item != null){
if(choice.isKeyChoice()){
if (item != null) {
if (choice.isKeyChoice()) {
choice.setChoiceByKey(item.getKey());
}else{
} else {
choice.setChoice(item.getKey());
}
return true;
}else{
} else {
choice.clearChoice();
return false;
}
}
class KeyValueItem
{
class KeyValueItem {
private final String Key;
private final String Value;
private final CheckBoxList.CheckBoxListItem objectValue;
public KeyValueItem(String value) {
this(value,null,null);
}
public KeyValueItem(String value, String label) {
this(value,label,null);
public KeyValueItem(String value) {
this(value, null, null);
}
public KeyValueItem(String value, String label,CheckBoxList.CheckBoxListItem object) {
public KeyValueItem(String value, String label) {
this(value, label, null);
}
public KeyValueItem(String value, String label, CheckBoxList.CheckBoxListItem object) {
this.Key = value;
this.Value = label;
this.objectValue = object;
this.objectValue = object;
}
public String getKey() {
return this.Key;
}
}
public String getValue() {
return this.Value;
}
public Object getObjectValue(){
return (CheckBoxList.CheckBoxListItem)this.objectValue;
public Object getObjectValue() {
return (CheckBoxList.CheckBoxListItem) this.objectValue;
}
@Override
public String toString() {
return this.Value;
}
}
}
/**
@ -428,20 +407,20 @@ public class PickCheckBoxDialog extends MageDialog {
javax.swing.GroupLayout panelHeaderLayout = new javax.swing.GroupLayout(panelHeader);
panelHeader.setLayout(panelHeaderLayout);
panelHeaderLayout.setHorizontalGroup(
panelHeaderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelHeaderLayout.createSequentialGroup()
.addGroup(panelHeaderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(labelMessage, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
.addComponent(labelSubMessage, javax.swing.GroupLayout.Alignment.TRAILING))
.addGap(0, 0, 0))
panelHeaderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelHeaderLayout.createSequentialGroup()
.addGroup(panelHeaderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(labelMessage, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
.addComponent(labelSubMessage, javax.swing.GroupLayout.Alignment.TRAILING))
.addGap(0, 0, 0))
);
panelHeaderLayout.setVerticalGroup(
panelHeaderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelHeaderLayout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(labelMessage)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(labelSubMessage, javax.swing.GroupLayout.DEFAULT_SIZE, 30, Short.MAX_VALUE))
panelHeaderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelHeaderLayout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(labelMessage)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(labelSubMessage, javax.swing.GroupLayout.DEFAULT_SIZE, 30, Short.MAX_VALUE))
);
labelSearch.setText("Search:");
@ -451,28 +430,34 @@ public class PickCheckBoxDialog extends MageDialog {
javax.swing.GroupLayout panelSearchLayout = new javax.swing.GroupLayout(panelSearch);
panelSearch.setLayout(panelSearchLayout);
panelSearchLayout.setHorizontalGroup(
panelSearchLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelSearchLayout.createSequentialGroup()
.addGap(0, 0, 0)
.addComponent(labelSearch)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(editSearch)
.addGap(0, 0, 0))
panelSearchLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelSearchLayout.createSequentialGroup()
.addGap(0, 0, 0)
.addComponent(labelSearch)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(editSearch)
.addGap(0, 0, 0))
);
panelSearchLayout.setVerticalGroup(
panelSearchLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelSearchLayout.createSequentialGroup()
.addGap(3, 3, 3)
.addGroup(panelSearchLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(labelSearch)
.addComponent(editSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(3, 3, 3))
panelSearchLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelSearchLayout.createSequentialGroup()
.addGap(3, 3, 3)
.addGroup(panelSearchLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(labelSearch)
.addComponent(editSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(3, 3, 3))
);
listChoices.setModel(new javax.swing.AbstractListModel() {
String[] strings = { "item1", "item2", "item3" };
public int getSize() { return strings.length; }
public Object getElementAt(int i) { return strings[i]; }
String[] strings = {"item1", "item2", "item3"};
public int getSize() {
return strings.length;
}
public Object getElementAt(int i) {
return strings[i];
}
});
scrollList.setViewportView(listChoices);
@ -501,25 +486,25 @@ public class PickCheckBoxDialog extends MageDialog {
javax.swing.GroupLayout panelCommandsLayout = new javax.swing.GroupLayout(panelCommands);
panelCommands.setLayout(panelCommandsLayout);
panelCommandsLayout.setHorizontalGroup(
panelCommandsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelCommandsLayout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btClear, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btOK)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
panelCommandsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelCommandsLayout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btClear, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btOK)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
panelCommandsLayout.setVerticalGroup(
panelCommandsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelCommandsLayout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(panelCommandsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btCancel)
.addComponent(btOK)
.addComponent(btClear, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap())
panelCommandsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelCommandsLayout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(panelCommandsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btCancel)
.addComponent(btOK)
.addComponent(btClear, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap())
);
getRootPane().setDefaultButton(btOK);
@ -528,28 +513,28 @@ public class PickCheckBoxDialog extends MageDialog {
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(scrollList, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(panelCommands, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(panelHeader, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(panelSearch, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(scrollList, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(panelCommands, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(panelHeader, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(panelSearch, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(panelHeader, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(panelSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(scrollList, javax.swing.GroupLayout.DEFAULT_SIZE, 240, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(panelCommands, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(panelHeader, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(panelSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(scrollList, javax.swing.GroupLayout.DEFAULT_SIZE, 240, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(panelCommands, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
pack();

View file

@ -1,36 +1,17 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package mage.client.dialog;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.*;
import javax.swing.AbstractAction;
import javax.swing.ActionMap;
import javax.swing.DefaultListModel;
import javax.swing.InputMap;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JLayeredPane;
import javax.swing.KeyStroke;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import mage.choices.Choice;
import mage.client.MageFrame;
import mage.client.util.SettingsManager;
import mage.client.util.gui.GuiDisplayUtil;
import mage.client.util.gui.MageDialogState;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
/**
*
* @author JayDi85
*/
@ -39,7 +20,7 @@ public class PickChoiceDialog extends MageDialog {
Choice choice;
ArrayList<KeyValueItem> allItems = new ArrayList<>();
DefaultListModel<KeyValueItem> dataModel = new DefaultListModel();
final private static String HTML_TEMPLATE = "<html><div style='text-align: center;'>%s</div></html>";
public void showDialog(Choice choice) {
@ -53,31 +34,31 @@ public class PickChoiceDialog extends MageDialog {
public void showDialog(Choice choice, UUID objectId, MageDialogState mageDialogState) {
showDialog(choice, objectId, mageDialogState, null);
}
public void showDialog(Choice choice, UUID objectId, MageDialogState mageDialogState, String startSelectionValue) {
this.choice = choice;
setLabelText(this.labelMessage, choice.getMessage());
setLabelText(this.labelSubMessage, choice.getSubMessage());
btCancel.setEnabled(!choice.isRequired());
// 2 modes: string or key-values
// sore data in allItems for inremental filtering
// http://logicbig.com/tutorials/core-java-tutorial/swing/list-filter/
this.allItems.clear();
if (choice.isKeyChoice()){
for (Map.Entry<String, String> entry: choice.getKeyChoices().entrySet()) {
this.allItems.add(new KeyValueItem(entry.getKey(), entry.getValue()));
if (choice.isKeyChoice()) {
for (Map.Entry<String, String> entry : choice.getKeyChoices().entrySet()) {
this.allItems.add(new KeyValueItem(entry.getKey(), entry.getValue()));
}
} else {
for (String value: choice.getChoices()){
this.allItems.add(new KeyValueItem(value, value));
for (String value : choice.getChoices()) {
this.allItems.add(new KeyValueItem(value, value));
}
}
// sorting
if(choice.isSortEnabled()){
if (choice.isSortEnabled()) {
Collections.sort(this.allItems, new Comparator<KeyValueItem>() {
@Override
public int compare(KeyValueItem o1, KeyValueItem o2) {
@ -87,38 +68,37 @@ public class PickChoiceDialog extends MageDialog {
}
});
}
// search
if(choice.isSearchEnabled())
{
if (choice.isSearchEnabled()) {
panelSearch.setVisible(true);
this.editSearch.setText(choice.getSearchText());
}else{
} else {
panelSearch.setVisible(false);
this.editSearch.setText("");
}
// listeners for inremental filtering
editSearch.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void insertUpdate(DocumentEvent e) {
choice.setSearchText(editSearch.getText());
loadData();
}
@Override
public void insertUpdate(DocumentEvent e) {
choice.setSearchText(editSearch.getText());
loadData();
}
@Override
public void removeUpdate(DocumentEvent e) {
choice.setSearchText(editSearch.getText());
loadData();
}
@Override
public void removeUpdate(DocumentEvent e) {
choice.setSearchText(editSearch.getText());
loadData();
}
@Override
public void changedUpdate(DocumentEvent e) {
choice.setSearchText(editSearch.getText());
loadData();
}
@Override
public void changedUpdate(DocumentEvent e) {
choice.setSearchText(editSearch.getText());
loadData();
}
});
// listeners for select up and down without edit focus lost
editSearch.addKeyListener(new KeyListener() {
@Override
@ -127,10 +107,10 @@ public class PickChoiceDialog extends MageDialog {
}
@Override
public void keyPressed(KeyEvent e) {
if(e.getKeyCode() == KeyEvent.VK_UP){
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_UP) {
doPrevSelect();
}else if(e.getKeyCode() == KeyEvent.VK_DOWN){
} else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
doNextSelect();
}
}
@ -140,19 +120,19 @@ public class PickChoiceDialog extends MageDialog {
//System.out.println("released");
}
});
// listeners double click choose
listChoices.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if(e.getClickCount() == 2){
if (e.getClickCount() == 2) {
doChoose();
}
}
});
// listeners for ESC close
if(!choice.isRequired()){
if (!choice.isRequired()) {
String cancelName = "cancel";
InputMap inputMap = getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), cancelName);
@ -163,37 +143,35 @@ public class PickChoiceDialog extends MageDialog {
}
});
}
// window settings
if (this.isModal()){
if (this.isModal()) {
MageFrame.getDesktop().add(this, JLayeredPane.MODAL_LAYER);
}else{
} else {
MageFrame.getDesktop().add(this, JLayeredPane.PALETTE_LAYER);
}
if (mageDialogState != null) {
mageDialogState.setStateToDialog(this);
} else {
Point centered = SettingsManager.instance.getComponentPosition(getWidth(), getHeight());
this.setLocation(centered.x, centered.y);
GuiDisplayUtil.keepComponentInsideScreen(centered.x, centered.y, this);
this.makeWindowCentered();
}
// final load
loadData();
// start selection
if((startSelectionValue != null)){
if ((startSelectionValue != null)) {
int selectIndex = -1;
for(int i = 0; i < this.listChoices.getModel().getSize(); i++){
KeyValueItem listItem = (KeyValueItem)this.listChoices.getModel().getElementAt(i);
if (listItem.Key.equals(startSelectionValue)){
for (int i = 0; i < this.listChoices.getModel().getSize(); i++) {
KeyValueItem listItem = (KeyValueItem) this.listChoices.getModel().getElementAt(i);
if (listItem.Key.equals(startSelectionValue)) {
selectIndex = i;
break;
}
}
if(selectIndex >= 0){
if (selectIndex >= 0) {
this.listChoices.setSelectedIndex(selectIndex);
this.listChoices.ensureIndexIsVisible(selectIndex);
}
@ -201,59 +179,61 @@ public class PickChoiceDialog extends MageDialog {
this.setVisible(true);
}
public void setWindowSize(int width, int heigth){
this.setSize(new Dimension(width, heigth));
public void setWindowSize(int width, int height) {
this.setSize(new Dimension(width, height));
}
private void loadData(){
private void loadData() {
// load data to datamodel after filter or on startup
String filter = choice.getSearchText();
if (filter == null){ filter = ""; }
if (filter == null) {
filter = "";
}
filter = filter.toLowerCase(Locale.ENGLISH);
this.dataModel.clear();
for(KeyValueItem item: this.allItems){
if(!choice.isSearchEnabled() || item.Value.toLowerCase(Locale.ENGLISH).contains(filter)){
for (KeyValueItem item : this.allItems) {
if (!choice.isSearchEnabled() || item.Value.toLowerCase(Locale.ENGLISH).contains(filter)) {
this.dataModel.addElement(item);
}
}
}
private void setLabelText(JLabel label, String text){
if ((text != null) && !text.equals("")){
private void setLabelText(JLabel label, String text) {
if ((text != null) && !text.equals("")) {
label.setText(String.format(HTML_TEMPLATE, text));
label.setVisible(true);
}else{
} else {
label.setText("");
label.setVisible(false);
}
}
private void doNextSelect(){
int newSel = this.listChoices.getSelectedIndex() + 1;
int maxSel = this.listChoices.getModel().getSize() - 1;
if(newSel <= maxSel){
this.listChoices.setSelectedIndex(newSel);
this.listChoices.ensureIndexIsVisible(newSel);
}
}
private void doPrevSelect(){
int newSel = this.listChoices.getSelectedIndex() - 1;
if(newSel >= 0){
private void doNextSelect() {
int newSel = this.listChoices.getSelectedIndex() + 1;
int maxSel = this.listChoices.getModel().getSize() - 1;
if (newSel <= maxSel) {
this.listChoices.setSelectedIndex(newSel);
this.listChoices.ensureIndexIsVisible(newSel);
}
}
private void doChoose(){
if(setChoice()){
private void doPrevSelect() {
int newSel = this.listChoices.getSelectedIndex() - 1;
if (newSel >= 0) {
this.listChoices.setSelectedIndex(newSel);
this.listChoices.ensureIndexIsVisible(newSel);
}
}
private void doChoose() {
if (setChoice()) {
this.hideDialog();
}
}
private void doCancel(){
private void doCancel() {
this.listChoices.clearSelection();
this.choice.clearChoice();
hideDialog();
@ -267,34 +247,33 @@ public class PickChoiceDialog extends MageDialog {
this.listChoices.setModel(dataModel);
this.setModal(true);
}
public boolean setChoice() {
KeyValueItem item = (KeyValueItem)this.listChoices.getSelectedValue();
KeyValueItem item = (KeyValueItem) this.listChoices.getSelectedValue();
// auto select one item (after incemental filtering)
if((item == null) && (this.listChoices.getModel().getSize() == 1)){
if ((item == null) && (this.listChoices.getModel().getSize() == 1)) {
this.listChoices.setSelectedIndex(0);
item = (KeyValueItem)this.listChoices.getSelectedValue();
item = (KeyValueItem) this.listChoices.getSelectedValue();
}
if(item != null){
if(choice.isKeyChoice()){
if (item != null) {
if (choice.isKeyChoice()) {
choice.setChoiceByKey(item.getKey());
}else{
} else {
choice.setChoice(item.getKey());
}
return true;
}else{
} else {
choice.clearChoice();
return false;
}
}
class KeyValueItem
{
class KeyValueItem {
private final String Key;
private final String Value;
public KeyValueItem(String value, String label) {
this.Key = value;
this.Value = label;
@ -311,7 +290,7 @@ public class PickChoiceDialog extends MageDialog {
@Override
public String toString() {
return this.Value;
}
}
}
/**
@ -345,20 +324,20 @@ public class PickChoiceDialog extends MageDialog {
javax.swing.GroupLayout panelHeaderLayout = new javax.swing.GroupLayout(panelHeader);
panelHeader.setLayout(panelHeaderLayout);
panelHeaderLayout.setHorizontalGroup(
panelHeaderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelHeaderLayout.createSequentialGroup()
.addGroup(panelHeaderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(labelMessage, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 210, Short.MAX_VALUE)
.addComponent(labelSubMessage, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 210, Short.MAX_VALUE))
.addGap(0, 0, 0))
panelHeaderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelHeaderLayout.createSequentialGroup()
.addGroup(panelHeaderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(labelMessage, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 210, Short.MAX_VALUE)
.addComponent(labelSubMessage, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 210, Short.MAX_VALUE))
.addGap(0, 0, 0))
);
panelHeaderLayout.setVerticalGroup(
panelHeaderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelHeaderLayout.createSequentialGroup()
.addGap(0, 0, 0)
.addComponent(labelMessage)
.addGap(0, 0, 0)
.addComponent(labelSubMessage))
panelHeaderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelHeaderLayout.createSequentialGroup()
.addGap(0, 0, 0)
.addComponent(labelMessage)
.addGap(0, 0, 0)
.addComponent(labelSubMessage))
);
labelSearch.setText("Search:");
@ -368,28 +347,34 @@ public class PickChoiceDialog extends MageDialog {
javax.swing.GroupLayout panelSearchLayout = new javax.swing.GroupLayout(panelSearch);
panelSearch.setLayout(panelSearchLayout);
panelSearchLayout.setHorizontalGroup(
panelSearchLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelSearchLayout.createSequentialGroup()
.addGap(0, 0, 0)
.addComponent(labelSearch)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(editSearch)
.addGap(0, 0, 0))
panelSearchLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelSearchLayout.createSequentialGroup()
.addGap(0, 0, 0)
.addComponent(labelSearch)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(editSearch)
.addGap(0, 0, 0))
);
panelSearchLayout.setVerticalGroup(
panelSearchLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelSearchLayout.createSequentialGroup()
.addGap(3, 3, 3)
.addGroup(panelSearchLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(labelSearch)
.addComponent(editSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(3, 3, 3))
panelSearchLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelSearchLayout.createSequentialGroup()
.addGap(3, 3, 3)
.addGroup(panelSearchLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(labelSearch)
.addComponent(editSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(3, 3, 3))
);
listChoices.setModel(new javax.swing.AbstractListModel() {
String[] strings = { "item1", "item2", "item3" };
public int getSize() { return strings.length; }
public Object getElementAt(int i) { return strings[i]; }
String[] strings = {"item1", "item2", "item3"};
public int getSize() {
return strings.length;
}
public Object getElementAt(int i) {
return strings[i];
}
});
scrollList.setViewportView(listChoices);
@ -410,25 +395,25 @@ public class PickChoiceDialog extends MageDialog {
javax.swing.GroupLayout panelCommandsLayout = new javax.swing.GroupLayout(panelCommands);
panelCommands.setLayout(panelCommandsLayout);
panelCommandsLayout.setHorizontalGroup(
panelCommandsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelCommandsLayout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btOK)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
panelCommandsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelCommandsLayout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btOK)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
panelCommandsLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btCancel, btOK});
panelCommandsLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[]{btCancel, btOK});
panelCommandsLayout.setVerticalGroup(
panelCommandsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelCommandsLayout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(panelCommandsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btCancel)
.addComponent(btOK))
.addContainerGap())
panelCommandsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelCommandsLayout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(panelCommandsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btCancel)
.addComponent(btOK))
.addContainerGap())
);
getRootPane().setDefaultButton(btOK);
@ -436,28 +421,28 @@ public class PickChoiceDialog extends MageDialog {
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(scrollList, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(panelCommands, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(panelHeader, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(panelSearch, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(scrollList, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(panelCommands, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(panelHeader, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(panelSearch, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(panelHeader, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(panelSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(scrollList, javax.swing.GroupLayout.DEFAULT_SIZE, 246, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(panelCommands, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(panelHeader, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(panelSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(scrollList, javax.swing.GroupLayout.DEFAULT_SIZE, 246, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(panelCommands, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
pack();

View file

@ -1,31 +1,21 @@
/*
* PickNumberDialog.java
*
* Created on Feb 25, 2010, 12:03:39 PM
*/
package mage.client.dialog;
import java.awt.Point;
import mage.client.MageFrame;
import javax.swing.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.*;
import mage.client.MageFrame;
import mage.client.util.SettingsManager;
import mage.client.util.gui.GuiDisplayUtil;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class PickNumberDialog extends MageDialog {
private boolean cancel;
/** Creates new form PickNumberDialog */
/**
* Creates new form PickNumberDialog
*/
public PickNumberDialog() {
initComponents();
this.setModal(true);
@ -40,16 +30,16 @@ public class PickNumberDialog extends MageDialog {
this.pack();
// window settings
if (this.isModal()){
if (this.isModal()) {
MageFrame.getDesktop().add(this, JLayeredPane.MODAL_LAYER);
}else{
} else {
MageFrame.getDesktop().add(this, JLayeredPane.PALETTE_LAYER);
}
this.getRootPane().setDefaultButton(this.btnOk); // restore default button after root panel change (no need actually)
// enable spinner's enter key like text (one enter press instead two)
// https://stackoverflow.com/questions/3873870/java-keylistener-not-firing-on-jspinner
((JSpinner.DefaultEditor)this.spnAmount.getEditor()).getTextField().addKeyListener(new KeyListener(){
((JSpinner.DefaultEditor) this.spnAmount.getEditor()).getTextField().addKeyListener(new KeyListener() {
@Override
public void keyPressed(KeyEvent e) {
@ -68,23 +58,22 @@ public class PickNumberDialog extends MageDialog {
});
Point centered = SettingsManager.instance.getComponentPosition(getWidth(), getHeight());
this.setLocation(centered.x, centered.y);
GuiDisplayUtil.keepComponentInsideScreen(centered.x, centered.y, this);
this.makeWindowCentered();
// TODO: need to fix focus restore on second popup (it's not focues, test on Manamorphose)
this.setVisible(true);
}
public int getAmount() {
return ((Number)spnAmount.getValue()).intValue();
return ((Number) spnAmount.getValue()).intValue();
}
public boolean isCancel() {
return cancel;
}
/** This method is called from within the constructor to
/**
* This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
@ -105,7 +94,7 @@ public class PickNumberDialog extends MageDialog {
lblMessage.setEditable(false);
lblMessage.setText("long text long text long text long text long text long text long text long text");
lblMessage.setCursor(null );
lblMessage.setCursor(null);
lblMessage.setFocusable(false);
lblMessage.setOpaque(false);
jScrollPane1.setViewportView(lblMessage);
@ -129,22 +118,22 @@ public class PickNumberDialog extends MageDialog {
javax.swing.GroupLayout panelCommandsLayout = new javax.swing.GroupLayout(panelCommands);
panelCommands.setLayout(panelCommandsLayout);
panelCommandsLayout.setHorizontalGroup(
panelCommandsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelCommandsLayout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnOk)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnCancel)
.addContainerGap())
panelCommandsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelCommandsLayout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnOk)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnCancel)
.addContainerGap())
);
panelCommandsLayout.setVerticalGroup(
panelCommandsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelCommandsLayout.createSequentialGroup()
.addContainerGap()
.addGroup(panelCommandsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnOk)
.addComponent(btnCancel))
.addContainerGap())
panelCommandsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelCommandsLayout.createSequentialGroup()
.addContainerGap()
.addGroup(panelCommandsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnOk)
.addComponent(btnCancel))
.addContainerGap())
);
getRootPane().setDefaultButton(btnOk);
@ -152,27 +141,27 @@ public class PickNumberDialog extends MageDialog {
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 183, Short.MAX_VALUE)
.addComponent(panelCommands, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(spnAmount, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE)))
.addContainerGap())
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 183, Short.MAX_VALUE)
.addComponent(panelCommands, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(spnAmount, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 117, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(spnAmount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(panelCommands, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 117, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(spnAmount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(panelCommands, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
pack();

View file

@ -1,23 +1,16 @@
package mage.client.dialog;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Point;
import java.util.UUID;
import javax.swing.JButton;
import javax.swing.JLayeredPane;
import javax.swing.JPanel;
import mage.client.MageFrame;
import mage.client.cards.BigCard;
import mage.client.cards.CardArea;
import mage.client.util.SettingsManager;
import mage.client.util.gui.GuiDisplayUtil;
import mage.view.CardsView;
import org.mage.card.arcane.CardPanel;
import javax.swing.*;
import java.awt.*;
import java.util.UUID;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class PickPileDialog extends MageDialog {
@ -81,18 +74,16 @@ public class PickPileDialog extends MageDialog {
}
pack();
Point centered = SettingsManager.instance.getComponentPosition(getWidth(), getHeight());
this.setLocation(centered.x, centered.y);
GuiDisplayUtil.keepComponentInsideScreen(centered.x, centered.y, this);
this.makeWindowCentered();
this.revalidate();
this.repaint();
this.setModal(true);
// window settings
if (this.isModal()){
if (this.isModal()) {
MageFrame.getDesktop().add(this, JLayeredPane.MODAL_LAYER);
}else{
} else {
MageFrame.getDesktop().add(this, JLayeredPane.PALETTE_LAYER);
}

View file

@ -236,7 +236,7 @@
<Property name="toolTipText" type="java.lang.String" value="Write the card&apos;s name on the card to make the card name more recognizable."/>
<Property name="actionCommand" type="java.lang.String" value=""/>
<Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
<Color id="Standardcursor"/>
<Color id="Default Cursor"/>
</Property>
</Properties>
<Events>
@ -267,7 +267,7 @@
<Property name="selected" type="boolean" value="true"/>
<Property name="toolTipText" type="java.lang.String" value="Show the path Xmage is expecting for this card&apos;s image (only displays if missing)"/>
<Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
<Color id="Standardcursor"/>
<Color id="Default Cursor"/>
</Property>
<Property name="label" type="java.lang.String" value="Display image path for missing images"/>
</Properties>
@ -4425,6 +4425,7 @@
</Component>
<Component class="javax.swing.JComboBox" name="cbPreferedImageLanguage">
<Properties>
<Property name="maximumRowCount" type="int" value="20"/>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="4">
<StringItem index="0" value="Item 1"/>
@ -4451,6 +4452,7 @@
</Component>
<Component class="javax.swing.JComboBox" name="cbNumberOfDownloadThreads">
<Properties>
<Property name="maximumRowCount" type="int" value="20"/>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="4">
<StringItem index="0" value="Item 1"/>

View file

@ -41,6 +41,8 @@ import mage.client.MageFrame;
import mage.client.SessionHandler;
import mage.client.components.KeyBindButton;
import static mage.client.constants.Constants.BATTLEFIELD_FEEDBACK_COLORIZING_MODE_ENABLE_BY_MULTICOLOR;
import mage.client.util.CardLanguage;
import mage.client.util.Config;
import mage.client.util.GUISizeHelper;
import mage.client.util.ImageHelper;
@ -338,6 +340,10 @@ public class PreferencesDialog extends javax.swing.JDialog {
fc_i.addChoosableFileFilter(new ImageFileFilter());
}
public static CardLanguage getPrefImagesLanguage() {
return CardLanguage.valueByCode(getCachedValue(PreferencesDialog.KEY_CARD_IMAGES_PREF_LANGUAGE, CardLanguage.ENGLISH.getCode()));
}
private static class ImageFileFilter extends FileFilter {
@Override
@ -374,7 +380,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
cbProxyType.setModel(new DefaultComboBoxModel<>(Connection.ProxyType.values()));
addAvatars();
cbPreferedImageLanguage.setModel(new DefaultComboBoxModel<>(new String[]{"en", "de", "fr", "it", "es", "pt", "jp", "cn", "ru", "tw", "ko"}));
cbPreferedImageLanguage.setModel(new DefaultComboBoxModel<>(CardLanguage.toList()));
cbNumberOfDownloadThreads.setModel(new DefaultComboBoxModel<>(new String[]{"10", "9", "8", "7", "6", "5", "4", "3", "2", "1"}));
}
@ -1558,6 +1564,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
}
});
cbPreferedImageLanguage.setMaximumRowCount(20);
cbPreferedImageLanguage.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
labelPreferedImageLanguage.setText("Prefered image language:");
@ -1565,6 +1572,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
labelNumberOfDownloadThreads.setText("Number of download threads:");
cbNumberOfDownloadThreads.setMaximumRowCount(20);
cbNumberOfDownloadThreads.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
org.jdesktop.layout.GroupLayout panelCardImagesLayout = new org.jdesktop.layout.GroupLayout(panelCardImages);
@ -3411,7 +3419,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
load(prefs, dialog.cbCheckForNewImages, KEY_CARD_IMAGES_CHECK, "true");
load(prefs, dialog.cbSaveToZipFiles, KEY_CARD_IMAGES_SAVE_TO_ZIP, "true");
dialog.cbNumberOfDownloadThreads.setSelectedItem(MageFrame.getPreferences().get(KEY_CARD_IMAGES_THREADS, "10"));
dialog.cbPreferedImageLanguage.setSelectedItem(MageFrame.getPreferences().get(KEY_CARD_IMAGES_PREF_LANGUAGE, "en"));
dialog.cbPreferedImageLanguage.setSelectedItem(MageFrame.getPreferences().get(KEY_CARD_IMAGES_PREF_LANGUAGE, CardLanguage.ENGLISH.getCode()));
// rendering settings
load(prefs, dialog.cbCardRenderImageFallback, KEY_CARD_RENDERING_FALLBACK, "true");

View file

@ -21,7 +21,6 @@ import mage.client.util.audio.AudioManager;
import mage.client.util.gui.BufferedImageBuilder;
import mage.constants.PlayerAction;
import mage.view.*;
import org.apache.log4j.Logger;
import javax.swing.*;
import javax.swing.Timer;
@ -31,21 +30,16 @@ import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.List;
/**
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class DraftPanel extends javax.swing.JPanel {
private static final Logger LOGGER = Logger.getLogger(DraftPanel.class);
private UUID draftId;
private Timer countdown;
private int timeout;
@ -63,8 +57,11 @@ public class DraftPanel extends javax.swing.JPanel {
// id of card with popup menu
protected UUID cardIdPopupMenu;
// Filename for the draft log (only updated if writing the log).
private String logFilename;
// Helper for writing the draft log.
private DraftPickLogger draftLogger;
// List of set codes (for draft log writing).
private List<String> setCodes;
// Number of the current booster (for draft log writing).
private int packNo;
@ -73,7 +70,6 @@ public class DraftPanel extends javax.swing.JPanel {
private int pickNo;
// Cached booster data to be written into the log (see logLastPick).
private String currentBoosterHeader;
private String[] currentBooster;
private static final CardsView EMPTY_VIEW = new CardsView();
@ -139,17 +135,11 @@ public class DraftPanel extends javax.swing.JPanel {
}
if (isLogging()) {
// If we are logging the draft create a file that will contain
// the log.
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
logFilename = "Draft_" + sdf.format(new Date()) + '_' + draftId + ".txt";
try {
Files.write(pathToDraftLog(), "".getBytes(), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
} catch (IOException ex) {
LOGGER.error(null, ex);
}
String logFilename = "Draft_" + sdf.format(new Date()) + '_' + draftId + ".txt";
draftLogger = new DraftPickLogger(new File("gamelogs"), logFilename);
} else {
logFilename = null;
draftLogger = new DraftPickLogger();
}
}
@ -171,6 +161,8 @@ public class DraftPanel extends javax.swing.JPanel {
packNo = draftView.getBoosterNum();
pickNo = draftView.getCardNum();
setCodes = draftView.getSetCodes();
draftLogger.updateDraft(draftId, draftView);
int right = draftView.getPlayers().size() / 2;
int left = draftView.getPlayers().size() - right;
@ -251,7 +243,7 @@ public class DraftPanel extends javax.swing.JPanel {
}
}
public void loadBooster(DraftPickView draftPickView) {
public void loadBooster(DraftPickView draftPickView) {
logLastPick(draftPickView);
// upper area that shows the picks
loadCardsToPickedCardsArea(draftPickView.getPicks());
@ -416,13 +408,21 @@ public class DraftPanel extends javax.swing.JPanel {
if (currentBooster != null) {
String lastPick = getCardName(getLastPick(pickView.getPicks().values()));
if (lastPick != null && currentBooster.length > 1) {
logPick(lastPick);
draftLogger.logPick(getCurrentSetCode(), packNo, pickNo-1, lastPick, currentBooster);
}
currentBooster = null;
}
setCurrentBoosterForLog(pickView.getBooster());
if (currentBooster.length == 1) {
logPick(currentBooster[0]);
draftLogger.logPick(getCurrentSetCode(), packNo, pickNo, currentBooster[0], currentBooster);
}
}
private String getCurrentSetCode() {
if (!setCodes.isEmpty()) {
return setCodes.get(packNo-1);
} else {
return "";
}
}
@ -440,39 +440,10 @@ public class DraftPanel extends javax.swing.JPanel {
}
}
currentBoosterHeader = "Pack " + packNo + " pick " + pickNo + ":\n";
currentBooster = cards.toArray(new String[cards.size()]);
}
private void logPick(String pick) {
StringBuilder b = new StringBuilder();
b.append(currentBoosterHeader);
for (String name : currentBooster) {
b.append(pick.equals(name) ? "--> " : " ");
b.append(name);
b.append('\n');
}
b.append('\n');
appendToDraftLog(b.toString());
}
private Path pathToDraftLog() {
File saveDir = new File("gamelogs");
if (!saveDir.exists()) {
saveDir.mkdirs();
}
return new File(saveDir, logFilename).toPath();
}
private void appendToDraftLog(String data) {
try {
Files.write(pathToDraftLog(), data.getBytes(), StandardOpenOption.APPEND);
} catch (IOException ex) {
LOGGER.error(null, ex);
}
}
private static SimpleCardView getLastPick(Collection<SimpleCardView> picks) {
private static SimpleCardView getLastPick(Collection<SimpleCardView> picks) {
SimpleCardView last = null;
for (SimpleCardView pick : picks) {
last = pick;

View file

@ -0,0 +1,85 @@
package mage.client.draft;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;
import org.apache.log4j.Logger;
import mage.view.DraftView;
public class DraftPickLogger {
private static final Logger LOGGER = Logger.getLogger(DraftPickLogger.class);
private final Path logPath;
private final boolean logging;
private boolean headerWritten = false;
public DraftPickLogger(File directory, String logFilename) {
this.logging = true;
if (!directory.exists()) {
directory.mkdirs();
}
this.logPath = new File(directory, logFilename).toPath();
try {
Files.write(logPath, new byte[0], StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
} catch (IOException ex) {
LOGGER.error(null, ex);
}
}
public DraftPickLogger() {
this.logging = false;
this.logPath = null;
}
public void updateDraft(UUID draftId, DraftView draftView) {
if (headerWritten) {
return;
}
headerWritten = true;
Date now = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("M/d/yyyy h:mm:ss a");
StringBuilder buffer = new StringBuilder()
.append("Event #: ").append(draftId).append("\n")
.append("Time: ").append(formatter.format(now)).append('\n');
buffer.append("Players:\n");
for (String player : draftView.getPlayers()) {
buffer.append(" ").append(player).append('\n');
}
buffer.append('\n');
appendToDraftLog(buffer.toString());
}
public void logPick(String setCode, int packNo, int pickNo, String pick, String[] currentBooster) {
StringBuilder b = new StringBuilder();
if (pickNo == 1) {
b.append("------ ").append(setCode).append(" ------\n\n");
}
b.append("Pack ").append(packNo).append(" pick ").append(pickNo).append(":\n");
for (String name : currentBooster) {
b.append(pick.equals(name) ? "--> " : " ");
b.append(name);
b.append('\n');
}
b.append('\n');
appendToDraftLog(b.toString());
}
private void appendToDraftLog(String data) {
if (logging) {
try {
Files.write(logPath, data.getBytes(), StandardOpenOption.APPEND);
} catch (IOException ex) {
LOGGER.error(null, ex);
}
}
}
}

View file

@ -353,8 +353,9 @@ public class CallbackClientImpl implements CallbackClient {
}
case DRAFT_UPDATE: {
DraftPanel panel = MageFrame.getDraft(callback.getObjectId());
DraftClientMessage message = (DraftClientMessage) callback.getData();
if (panel != null) {
panel.updateDraft((DraftView) callback.getData());
panel.updateDraft(message.getDraftView());
}
break;
}

View file

@ -0,0 +1,145 @@
package mage.client.table;
import mage.remote.MageRemoteException;
import mage.view.MatchView;
import javax.swing.table.AbstractTableModel;
import java.util.Collection;
import java.util.Date;
import java.util.UUID;
public class MatchesTableModel extends AbstractTableModel {
private final String[] columnNames = new String[]{"Deck Type", "Players", "Game Type", "Rating", "Result", "Duration", "Start Time", "End Time", "Action"};
public static final int COLUMN_DURATION = 5;
public static final int COLUMN_START = 6;
public static final int COLUMN_END = 7;
public static final int COLUMN_ACTION = 8; // column the action is located (starting with 0)
private MatchView[] matches = new MatchView[0];
public void loadData(Collection<MatchView> matches) throws MageRemoteException {
this.matches = matches.toArray(new MatchView[0]);
this.fireTableDataChanged();
}
MatchesTableModel() {
}
public String getTableAndGameInfo(int row) {
return this.matches[row].getTableId().toString() + ";" + (!matches[row].getGames().isEmpty() ? matches[row].getGames().get(0).toString() : "null");
}
public String findTableAndGameInfoByRow(int row) {
if (row >= 0 && row < this.matches.length) {
return getTableAndGameInfo(row);
} else {
return null;
}
}
public int findRowByTableAndGameInfo(String tableAndGame) {
for (int i = 0; i < this.matches.length; i++) {
String rowID = this.matches[i].getTableId().toString() + ";" + (!this.matches[i].getGames().isEmpty() ? this.matches[i].getGames().get(0).toString() : "null");
if (tableAndGame.equals(rowID)) {
return i;
}
}
return -1;
}
@Override
public int getRowCount() {
return matches.length;
}
@Override
public int getColumnCount() {
return columnNames.length;
}
@Override
public Object getValueAt(int arg0, int arg1) {
switch (arg1) {
case 0:
return matches[arg0].getDeckType();
case 1:
return matches[arg0].getPlayers();
case 2:
return matches[arg0].getGameType();
case 3:
return matches[arg0].isRated() ? TablesTableModel.RATED_VALUE_YES : TablesTableModel.RATED_VALUE_NO;
case 4:
return matches[arg0].getResult();
case 5:
if (matches[arg0].getEndTime() != null) {
return matches[arg0].getEndTime().getTime() - matches[arg0].getStartTime().getTime() + new Date().getTime();
} else {
return 0L;
}
case 6:
return matches[arg0].getStartTime();
case 7:
return matches[arg0].getEndTime();
case 8:
if (matches[arg0].isTournament()) {
return "Show";
} else if (matches[arg0].isReplayAvailable()) {
return "Replay";
} else {
return "None";
}
case 9:
return matches[arg0].getGames();
}
return "";
}
public java.util.List<UUID> getListofGames(int row) {
return matches[row].getGames();
}
public boolean isTournament(int row) {
return matches[row].isTournament();
}
public UUID getMatchId(int row) {
return matches[row].getMatchId();
}
public UUID getTableId(int row) {
return matches[row].getTableId();
}
@Override
public String getColumnName(int columnIndex) {
String colName = "";
if (columnIndex <= getColumnCount()) {
colName = columnNames[columnIndex];
}
return colName;
}
@Override
public Class getColumnClass(int columnIndex) {
switch (columnIndex) {
case COLUMN_DURATION:
return Long.class;
case COLUMN_START:
return Date.class;
case COLUMN_END:
return Date.class;
default:
return String.class;
}
}
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
return columnIndex == COLUMN_ACTION;
}
}

View file

@ -1,25 +1,21 @@
package mage.client.table;
package mage.client.util;
import mage.client.util.GUISizeHelper;
import java.awt.Component;
import javax.swing.*;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumnModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.AbstractCellEditor;
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JTable;
import javax.swing.UIManager;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumnModel;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class ButtonColumn extends AbstractCellEditor implements TableCellRenderer, TableCellEditor, ActionListener, MouseListener {
public class TablesButtonColumn extends AbstractCellEditor implements TableCellRenderer, TableCellEditor, ActionListener, MouseListener {
private final JTable table;
private final Action action;
@ -28,7 +24,7 @@ public class ButtonColumn extends AbstractCellEditor implements TableCellRendere
private String text;
private boolean isButtonColumnEditor;
public ButtonColumn(JTable table, Action action, int column) {
public TablesButtonColumn(JTable table, Action action, int column) {
super();
this.table = table;
this.action = action;
@ -88,7 +84,7 @@ public class ButtonColumn extends AbstractCellEditor implements TableCellRendere
if (table.getRowCount() > 0 && table.getRowCount() >= table.getEditingRow() && table.getEditingRow() >= 0) {
int row = table.convertRowIndexToModel(table.getEditingRow());
fireEditingStopped();
ActionEvent event = new ActionEvent(table, ActionEvent.ACTION_PERFORMED, String.valueOf(row));
ActionEvent event = new ActionEvent(table, ActionEvent.ACTION_PERFORMED, TablesUtil.getSearchIdFromTable(table, row));
action.actionPerformed(event);
}
}

View file

@ -6,7 +6,10 @@ import mage.client.SessionHandler;
import mage.client.chat.ChatPanelBasic;
import mage.client.components.MageComponents;
import mage.client.dialog.*;
import mage.client.util.*;
import mage.client.util.GUISizeHelper;
import mage.client.util.IgnoreList;
import mage.client.util.MageTableRowSorter;
import mage.client.util.URLHandler;
import mage.client.util.gui.GuiDisplayUtil;
import mage.client.util.gui.TableUtil;
import mage.constants.*;
@ -25,7 +28,6 @@ import org.ocpsoft.prettytime.units.JustNow;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellRenderer;
import java.awt.*;
@ -52,7 +54,7 @@ public class TablesPanel extends javax.swing.JPanel {
private static final Logger LOGGER = Logger.getLogger(TablesPanel.class);
private static final int[] DEFAULT_COLUMNS_WIDTH = {35, 150, 120, 180, 80, 120, 80, 60, 40, 40, 60};
private final TableTableModel tableModel;
private final TablesTableModel tableModel;
private final MatchesTableModel matchesModel;
private UUID roomId;
private UpdateTablesTask updateTablesTask;
@ -67,8 +69,8 @@ public class TablesPanel extends javax.swing.JPanel {
private final MageTableRowSorter activeTablesSorter;
private final MageTableRowSorter completedTablesSorter;
private final ButtonColumn actionButton1;
private final ButtonColumn actionButton2;
private final TablesButtonColumn actionButton1;
private final TablesButtonColumn actionButton2;
final JToggleButton[] filterButtons;
@ -161,7 +163,7 @@ public class TablesPanel extends javax.swing.JPanel {
*/
public TablesPanel() {
tableModel = new TableTableModel();
tableModel = new TablesTableModel();
matchesModel = new MatchesTableModel();
gameChooser = new GameChooser();
@ -179,12 +181,12 @@ public class TablesPanel extends javax.swing.JPanel {
tableTables.setRowSorter(activeTablesSorter);
// time ago
tableTables.getColumnModel().getColumn(TableTableModel.COLUMN_CREATED).setCellRenderer(timeAgoCellRenderer);
tableTables.getColumnModel().getColumn(TablesTableModel.COLUMN_CREATED).setCellRenderer(timeAgoCellRenderer);
// skill level
tableTables.getColumnModel().getColumn(TableTableModel.COLUMN_SKILL).setCellRenderer(skillCellRenderer);
tableTables.getColumnModel().getColumn(TablesTableModel.COLUMN_SKILL).setCellRenderer(skillCellRenderer);
/* date sorter (not need, default is good - see getColumnClass)
activeTablesSorter.setComparator(TableTableModel.COLUMN_CREATED, new Comparator<Date>() {
activeTablesSorter.setComparator(TablesTableModel.COLUMN_CREATED, new Comparator<Date>() {
@Override
public int compare(Date v1, Date v2) {
return v1.compareTo(v2);
@ -194,7 +196,7 @@ public class TablesPanel extends javax.swing.JPanel {
// default sort by created date (last games from above)
ArrayList list = new ArrayList();
list.add(new RowSorter.SortKey(TableTableModel.COLUMN_CREATED, SortOrder.DESCENDING));
list.add(new RowSorter.SortKey(TablesTableModel.COLUMN_CREATED, SortOrder.DESCENDING));
activeTablesSorter.setSortKeys(list);
TableUtil.setColumnWidthAndOrder(tableTables, DEFAULT_COLUMNS_WIDTH, KEY_TABLES_COLUMNS_WIDTH, KEY_TABLES_COLUMNS_ORDER);
@ -239,19 +241,18 @@ public class TablesPanel extends javax.swing.JPanel {
openTableAction = new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
// tableUUID;gameUUID
String searchID = e.getActionCommand();
int modelRow = tableModel.findRowByTableAndGameInfo(searchID);
int modelRow = TablesUtil.findTableRowFromSearchId(tableModel, searchID);
if (modelRow == -1) {
return;
}
UUID tableId = (UUID) tableModel.getValueAt(modelRow, TableTableModel.ACTION_COLUMN + 3);
UUID gameId = (UUID) tableModel.getValueAt(modelRow, TableTableModel.ACTION_COLUMN + 2);
String action = (String) tableModel.getValueAt(modelRow, TableTableModel.ACTION_COLUMN);
String deckType = (String) tableModel.getValueAt(modelRow, TableTableModel.COLUMN_DECK_TYPE);
boolean isTournament = (Boolean) tableModel.getValueAt(modelRow, TableTableModel.ACTION_COLUMN + 1);
String owner = (String) tableModel.getValueAt(modelRow, TableTableModel.COLUMN_OWNER);
String pwdColumn = (String) tableModel.getValueAt(modelRow, TableTableModel.COLUMN_PASSWORD);
UUID tableId = (UUID) tableModel.getValueAt(modelRow, TablesTableModel.ACTION_COLUMN + 3);
UUID gameId = (UUID) tableModel.getValueAt(modelRow, TablesTableModel.ACTION_COLUMN + 2);
String action = (String) tableModel.getValueAt(modelRow, TablesTableModel.ACTION_COLUMN);
String deckType = (String) tableModel.getValueAt(modelRow, TablesTableModel.COLUMN_DECK_TYPE);
boolean isTournament = (Boolean) tableModel.getValueAt(modelRow, TablesTableModel.ACTION_COLUMN + 1);
String owner = (String) tableModel.getValueAt(modelRow, TablesTableModel.COLUMN_OWNER);
String pwdColumn = (String) tableModel.getValueAt(modelRow, TablesTableModel.COLUMN_PASSWORD);
switch (action) {
case "Join":
if (owner.equals(SessionHandler.getUserName()) || owner.startsWith(SessionHandler.getUserName() + ',')) {
@ -278,7 +279,7 @@ public class TablesPanel extends javax.swing.JPanel {
if (isTournament) {
LOGGER.info("Joining tournament " + tableId);
if (deckType.startsWith("Limited")) {
if (TableTableModel.PASSWORD_VALUE_YES.equals(pwdColumn)) {
if (TablesTableModel.PASSWORD_VALUE_YES.equals(pwdColumn)) {
joinTableDialog.showDialog(roomId, tableId, true, deckType.startsWith("Limited"));
} else {
SessionHandler.joinTournamentTable(roomId, tableId, SessionHandler.getUserName(), PlayerType.HUMAN, 1, null, "");
@ -321,9 +322,8 @@ public class TablesPanel extends javax.swing.JPanel {
closedTableAction = new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
// tableUUID;gameUUID
String searchID = e.getActionCommand();
int modelRow = tableModel.findRowByTableAndGameInfo(searchID);
int modelRow = TablesUtil.findTableRowFromSearchId(matchesModel, searchID);
if (modelRow == -1) {
return;
}
@ -351,8 +351,8 @@ public class TablesPanel extends javax.swing.JPanel {
};
// !!!! adds action buttons to the table panel (don't delete this)
actionButton1 = new ButtonColumn(tableTables, openTableAction, tableTables.convertColumnIndexToView(TableTableModel.ACTION_COLUMN));
actionButton2 = new ButtonColumn(tableCompleted, closedTableAction, tableCompleted.convertColumnIndexToView(MatchesTableModel.COLUMN_ACTION));
actionButton1 = new TablesButtonColumn(tableTables, openTableAction, tableTables.convertColumnIndexToView(TablesTableModel.ACTION_COLUMN));
actionButton2 = new TablesButtonColumn(tableCompleted, closedTableAction, tableCompleted.convertColumnIndexToView(MatchesTableModel.COLUMN_ACTION));
// !!!!
addTableDoubleClickListener(tableTables, openTableAction);
addTableDoubleClickListener(tableCompleted, closedTableAction);
@ -364,7 +364,7 @@ public class TablesPanel extends javax.swing.JPanel {
public void mouseClicked(MouseEvent e) {
int row = table.getSelectedRow();
if (e.getClickCount() == 2 && row != -1) {
action.actionPerformed(new ActionEvent(table, ActionEvent.ACTION_PERFORMED, tableModel.findTableAndGameInfoByRow(row)));
action.actionPerformed(new ActionEvent(table, ActionEvent.ACTION_PERFORMED, TablesUtil.getSearchIdFromTable(table, row)));
}
}
});
@ -608,87 +608,87 @@ public class TablesPanel extends javax.swing.JPanel {
// state
java.util.List<RowFilter<Object, Object>> stateFilterList = new ArrayList<>();
if (btnStateWaiting.isSelected()) {
stateFilterList.add(RowFilter.regexFilter("Waiting", TableTableModel.COLUMN_STATUS));
stateFilterList.add(RowFilter.regexFilter("Waiting", TablesTableModel.COLUMN_STATUS));
}
if (btnStateActive.isSelected()) {
stateFilterList.add(RowFilter.regexFilter("Dueling|Constructing|Drafting|Sideboard", TableTableModel.COLUMN_STATUS));
stateFilterList.add(RowFilter.regexFilter("Dueling|Constructing|Drafting|Sideboard", TablesTableModel.COLUMN_STATUS));
}
// type
java.util.List<RowFilter<Object, Object>> typeFilterList = new ArrayList<>();
if (btnTypeMatch.isSelected()) {
typeFilterList.add(RowFilter.regexFilter("Two|Commander|Free|Tiny|Momir", TableTableModel.COLUMN_GAME_TYPE));
typeFilterList.add(RowFilter.regexFilter("Two|Commander|Free|Tiny|Momir", TablesTableModel.COLUMN_GAME_TYPE));
}
if (btnTypeTourneyConstructed.isSelected()) {
typeFilterList.add(RowFilter.regexFilter("Constructed", TableTableModel.COLUMN_GAME_TYPE));
typeFilterList.add(RowFilter.regexFilter("Constructed", TablesTableModel.COLUMN_GAME_TYPE));
}
if (btnTypeTourneyLimited.isSelected()) {
typeFilterList.add(RowFilter.regexFilter("Booster|Sealed", TableTableModel.COLUMN_GAME_TYPE));
typeFilterList.add(RowFilter.regexFilter("Booster|Sealed", TablesTableModel.COLUMN_GAME_TYPE));
}
// format
java.util.List<RowFilter<Object, Object>> formatFilterList = new ArrayList<>();
if (btnFormatBlock.isSelected()) {
formatFilterList.add(RowFilter.regexFilter("^Constructed.*Block", TableTableModel.COLUMN_DECK_TYPE));
formatFilterList.add(RowFilter.regexFilter("^Constructed.*Block", TablesTableModel.COLUMN_DECK_TYPE));
}
if (btnFormatStandard.isSelected()) {
formatFilterList.add(RowFilter.regexFilter("^Constructed - Standard", TableTableModel.COLUMN_DECK_TYPE));
formatFilterList.add(RowFilter.regexFilter("^Constructed - Standard", TablesTableModel.COLUMN_DECK_TYPE));
}
if (btnFormatModern.isSelected()) {
formatFilterList.add(RowFilter.regexFilter("^Constructed - Modern", TableTableModel.COLUMN_DECK_TYPE));
formatFilterList.add(RowFilter.regexFilter("^Constructed - Modern", TablesTableModel.COLUMN_DECK_TYPE));
}
if (btnFormatLegacy.isSelected()) {
formatFilterList.add(RowFilter.regexFilter("^Constructed - Legacy", TableTableModel.COLUMN_DECK_TYPE));
formatFilterList.add(RowFilter.regexFilter("^Constructed - Legacy", TablesTableModel.COLUMN_DECK_TYPE));
}
if (btnFormatVintage.isSelected()) {
formatFilterList.add(RowFilter.regexFilter("^Constructed - Vintage", TableTableModel.COLUMN_DECK_TYPE));
formatFilterList.add(RowFilter.regexFilter("^Constructed - Vintage", TablesTableModel.COLUMN_DECK_TYPE));
}
if (btnFormatCommander.isSelected()) {
formatFilterList.add(RowFilter.regexFilter("^Commander|^Duel Commander|^Penny Dreadful Commander|^Freeform Commander|^MTGO 1v1 Commander|^Duel Brawl|^Brawl", TableTableModel.COLUMN_DECK_TYPE));
formatFilterList.add(RowFilter.regexFilter("^Commander|^Duel Commander|^Penny Dreadful Commander|^Freeform Commander|^MTGO 1v1 Commander|^Duel Brawl|^Brawl", TablesTableModel.COLUMN_DECK_TYPE));
}
if (btnFormatTinyLeader.isSelected()) {
formatFilterList.add(RowFilter.regexFilter("^Tiny", TableTableModel.COLUMN_DECK_TYPE));
formatFilterList.add(RowFilter.regexFilter("^Tiny", TablesTableModel.COLUMN_DECK_TYPE));
}
if (btnFormatLimited.isSelected()) {
formatFilterList.add(RowFilter.regexFilter("^Limited", TableTableModel.COLUMN_DECK_TYPE));
formatFilterList.add(RowFilter.regexFilter("^Limited", TablesTableModel.COLUMN_DECK_TYPE));
}
if (btnFormatOther.isSelected()) {
formatFilterList.add(RowFilter.regexFilter("^Momir Basic|^Constructed - Pauper|^Constructed - Frontier|^Constructed - Extended|^Constructed - Eternal|^Constructed - Historical|^Constructed - Super|^Constructed - Freeform|^Australian Highlander|^Canadian Highlander|^Constructed - Old", TableTableModel.COLUMN_DECK_TYPE));
formatFilterList.add(RowFilter.regexFilter("^Momir Basic|^Constructed - Pauper|^Constructed - Frontier|^Constructed - Extended|^Constructed - Eternal|^Constructed - Historical|^Constructed - Super|^Constructed - Freeform|^Australian Highlander|^Canadian Highlander|^Constructed - Old", TablesTableModel.COLUMN_DECK_TYPE));
}
// skill
java.util.List<RowFilter<Object, Object>> skillFilterList = new ArrayList<>();
if (btnSkillBeginner.isSelected()) {
skillFilterList.add(RowFilter.regexFilter(this.tableModel.getSkillLevelAsCode(SkillLevel.BEGINNER, true), TableTableModel.COLUMN_SKILL));
skillFilterList.add(RowFilter.regexFilter(this.tableModel.getSkillLevelAsCode(SkillLevel.BEGINNER, true), TablesTableModel.COLUMN_SKILL));
}
if (btnSkillCasual.isSelected()) {
skillFilterList.add(RowFilter.regexFilter(this.tableModel.getSkillLevelAsCode(SkillLevel.CASUAL, true), TableTableModel.COLUMN_SKILL));
skillFilterList.add(RowFilter.regexFilter(this.tableModel.getSkillLevelAsCode(SkillLevel.CASUAL, true), TablesTableModel.COLUMN_SKILL));
}
if (btnSkillSerious.isSelected()) {
skillFilterList.add(RowFilter.regexFilter(this.tableModel.getSkillLevelAsCode(SkillLevel.SERIOUS, true), TableTableModel.COLUMN_SKILL));
skillFilterList.add(RowFilter.regexFilter(this.tableModel.getSkillLevelAsCode(SkillLevel.SERIOUS, true), TablesTableModel.COLUMN_SKILL));
}
String ratedMark = TableTableModel.RATED_VALUE_YES;
String ratedMark = TablesTableModel.RATED_VALUE_YES;
java.util.List<RowFilter<Object, Object>> ratingFilterList = new ArrayList<>();
if (btnRated.isSelected()) {
// yes word
ratingFilterList.add(RowFilter.regexFilter("^" + ratedMark, TableTableModel.COLUMN_RATING));
ratingFilterList.add(RowFilter.regexFilter("^" + ratedMark, TablesTableModel.COLUMN_RATING));
}
if (btnUnrated.isSelected()) {
// not yes word, see https://stackoverflow.com/a/406408/1276632
ratingFilterList.add(RowFilter.regexFilter("^((?!" + ratedMark + ").)*$", TableTableModel.COLUMN_RATING));
ratingFilterList.add(RowFilter.regexFilter("^((?!" + ratedMark + ").)*$", TablesTableModel.COLUMN_RATING));
}
// Password
String passwordMark = TableTableModel.PASSWORD_VALUE_YES;
String passwordMark = TablesTableModel.PASSWORD_VALUE_YES;
java.util.List<RowFilter<Object, Object>> passwordFilterList = new ArrayList<>();
if (btnPassword.isSelected()) {
// yes
passwordFilterList.add(RowFilter.regexFilter("^" + passwordMark, TableTableModel.COLUMN_PASSWORD));
passwordFilterList.add(RowFilter.regexFilter("^" + passwordMark, TablesTableModel.COLUMN_PASSWORD));
}
if (btnOpen.isSelected()) {
// no
passwordFilterList.add(RowFilter.regexFilter("^((?!" + passwordMark + ").)*$", TableTableModel.COLUMN_PASSWORD));
passwordFilterList.add(RowFilter.regexFilter("^((?!" + passwordMark + ").)*$", TablesTableModel.COLUMN_PASSWORD));
}
// Hide games of ignored players
@ -699,7 +699,7 @@ public class TablesPanel extends javax.swing.JPanel {
ignoreListFilterList.add(new RowFilter<Object, Object>() {
@Override
public boolean include(Entry<? extends Object, ? extends Object> entry) {
final String owner = entry.getStringValue(TableTableModel.COLUMN_OWNER);
final String owner = entry.getStringValue(TablesTableModel.COLUMN_OWNER);
return !ignoreListCopy.contains(owner);
}
});
@ -708,7 +708,7 @@ public class TablesPanel extends javax.swing.JPanel {
if (stateFilterList.isEmpty() || typeFilterList.isEmpty() || formatFilterList.isEmpty()
|| skillFilterList.isEmpty() || ratingFilterList.isEmpty()
|| passwordFilterList.isEmpty()) { // no selection
activeTablesSorter.setRowFilter(RowFilter.regexFilter("Nothing", TableTableModel.COLUMN_SKILL));
activeTablesSorter.setRowFilter(RowFilter.regexFilter("Nothing", TablesTableModel.COLUMN_SKILL));
} else {
java.util.List<RowFilter<Object, Object>> filterList = new ArrayList<>();
@ -1357,201 +1357,6 @@ public class TablesPanel extends javax.swing.JPanel {
}
class TableTableModel extends AbstractTableModel {
final ImageIcon tourneyIcon = new javax.swing.ImageIcon(getClass().getResource("/tables/tourney_icon.png"));
final ImageIcon matchIcon = new javax.swing.ImageIcon(getClass().getResource("/tables/match_icon.png"));
public static final int COLUMN_ICON = 0;
public static final int COLUMN_DECK_TYPE = 1; // column the deck type is located (starting with 0) Start string is used to check for Limited
public static final int COLUMN_OWNER = 2;
public static final int COLUMN_GAME_TYPE = 3;
public static final int COLUMN_INFO = 4;
public static final int COLUMN_STATUS = 5;
public static final int COLUMN_PASSWORD = 6;
public static final int COLUMN_CREATED = 7;
public static final int COLUMN_SKILL = 8;
public static final int COLUMN_RATING = 9;
public static final int COLUMN_QUIT_RATIO = 10;
public static final int COLUMN_MINIMUM_RATING = 11;
public static final int ACTION_COLUMN = 12; // column the action is located (starting with 0)
public static final String RATED_VALUE_YES = "YES";
public static final String RATED_VALUE_NO = "";
public static final String PASSWORD_VALUE_YES = "YES";
private final String[] columnNames = new String[]{"M/T", "Deck Type", "Owner / Players", "Game Type", "Info", "Status", "Password", "Created / Started", "Skill Level", "Rated", "Quit %", "Min Rating", "Action"};
private TableView[] tables = new TableView[0];
TableTableModel() {
}
public void loadData(Collection<TableView> tables) throws MageRemoteException {
this.tables = tables.toArray(new TableView[0]);
this.fireTableDataChanged();
}
public String getTableAndGameInfo(int row) {
return this.tables[row].getTableId().toString() + ";" + (!tables[row].getGames().isEmpty() ? tables[row].getGames().get(0) : null).toString();
}
public String findTableAndGameInfoByRow(int row) {
if (row >= 0 && this.tables.length < row) {
return getTableAndGameInfo(row);
} else {
return null;
}
}
public int findRowByTableAndGameInfo(String tableAndGame) {
for (int i = 0; i < this.tables.length; i++) {
String rowID = this.tables[i].getTableId().toString() + ";" + (!tables[i].getGames().isEmpty() ? tables[i].getGames().get(0) : null).toString();
if (tableAndGame.equals(rowID)) {
return i;
}
}
return -1;
}
public String getSkillLevelAsCode(SkillLevel skill, boolean asRegExp) {
String res;
switch (skill) {
case BEGINNER:
res = "*";
break;
case CASUAL:
res = "**";
break;
case SERIOUS:
res = "***";
break;
default:
res = "";
break;
}
// regexp format for search table rows
if (asRegExp) {
res = String.format("^%s$", res.replace("*", "\\*"));
}
return res;
}
@Override
public int getRowCount() {
return tables.length;
}
@Override
public int getColumnCount() {
return columnNames.length;
}
@Override
public Object getValueAt(int arg0, int arg1) {
switch (arg1) {
case 0:
return tables[arg0].isTournament() ? tourneyIcon : matchIcon;
case 1:
return tables[arg0].getDeckType();
case 2:
return tables[arg0].getControllerName();
case 3:
return tables[arg0].getGameType();
case 4:
return tables[arg0].getAdditionalInfo();
case 5:
return tables[arg0].getTableStateText();
case 6:
return tables[arg0].isPassworded() ? PASSWORD_VALUE_YES : "";
case 7:
return tables[arg0].getCreateTime(); // use cell render, not format here
case 8:
return this.getSkillLevelAsCode(tables[arg0].getSkillLevel(), false);
case 9:
return tables[arg0].isRated() ? RATED_VALUE_YES : RATED_VALUE_NO;
case 10:
return tables[arg0].getQuitRatio();
case 11:
return tables[arg0].getMinimumRating();
case 12:
switch (tables[arg0].getTableState()) {
case WAITING:
String owner = tables[arg0].getControllerName();
if (SessionHandler.getSession() != null && owner.equals(SessionHandler.getUserName())) {
return "";
}
return "Join";
case CONSTRUCTING:
case DRAFTING:
if (tables[arg0].isTournament()) {
return "Show";
}
case DUELING:
if (tables[arg0].isTournament()) {
return "Show";
} else {
owner = tables[arg0].getControllerName();
if (SessionHandler.getSession() != null && owner.equals(SessionHandler.getUserName())) {
return "";
}
if (tables[arg0].getSpectatorsAllowed()) {
return "Watch";
}
return "";
}
default:
return "";
}
case 13:
return tables[arg0].isTournament();
case 14:
if (!tables[arg0].getGames().isEmpty()) {
return tables[arg0].getGames().get(0);
}
return null;
case 15:
return tables[arg0].getTableId();
}
return "";
}
@Override
public String getColumnName(int columnIndex) {
String colName = "";
if (columnIndex <= getColumnCount()) {
colName = columnNames[columnIndex];
}
return colName;
}
@Override
public Class getColumnClass(int columnIndex) {
switch (columnIndex) {
case COLUMN_ICON:
return Icon.class;
case COLUMN_SKILL:
return SkillLevel.class;
case COLUMN_CREATED:
return Date.class;
default:
return String.class;
}
}
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
return columnIndex == ACTION_COLUMN;
}
}
class UpdateTablesTask extends SwingWorker<Void, Collection<TableView>> {
private final UUID roomId;
@ -1640,119 +1445,6 @@ class UpdatePlayersTask extends SwingWorker<Void, Collection<RoomUsersView>> {
}
class MatchesTableModel extends AbstractTableModel {
private final String[] columnNames = new String[]{"Deck Type", "Players", "Game Type", "Rating", "Result", "Duration", "Start Time", "End Time", "Action"};
public static final int COLUMN_DURATION = 5;
public static final int COLUMN_START = 6;
public static final int COLUMN_END = 7;
public static final int COLUMN_ACTION = 8; // column the action is located (starting with 0)
private MatchView[] matches = new MatchView[0];
public void loadData(Collection<MatchView> matches) throws MageRemoteException {
this.matches = matches.toArray(new MatchView[0]);
this.fireTableDataChanged();
}
MatchesTableModel() {
}
@Override
public int getRowCount() {
return matches.length;
}
@Override
public int getColumnCount() {
return columnNames.length;
}
@Override
public Object getValueAt(int arg0, int arg1) {
switch (arg1) {
case 0:
return matches[arg0].getDeckType();
case 1:
return matches[arg0].getPlayers();
case 2:
return matches[arg0].getGameType();
case 3:
return matches[arg0].isRated() ? TableTableModel.RATED_VALUE_YES : TableTableModel.RATED_VALUE_NO;
case 4:
return matches[arg0].getResult();
case 5:
if (matches[arg0].getEndTime() != null) {
return matches[arg0].getEndTime().getTime() - matches[arg0].getStartTime().getTime() + new Date().getTime();
} else {
return 0L;
}
case 6:
return matches[arg0].getStartTime();
case 7:
return matches[arg0].getEndTime();
case 8:
if (matches[arg0].isTournament()) {
return "Show";
} else if (matches[arg0].isReplayAvailable()) {
return "Replay";
} else {
return "None";
}
case 9:
return matches[arg0].getGames();
}
return "";
}
public java.util.List<UUID> getListofGames(int row) {
return matches[row].getGames();
}
public boolean isTournament(int row) {
return matches[row].isTournament();
}
public UUID getMatchId(int row) {
return matches[row].getMatchId();
}
public UUID getTableId(int row) {
return matches[row].getTableId();
}
@Override
public String getColumnName(int columnIndex) {
String colName = "";
if (columnIndex <= getColumnCount()) {
colName = columnNames[columnIndex];
}
return colName;
}
@Override
public Class getColumnClass(int columnIndex) {
switch (columnIndex) {
case COLUMN_DURATION:
return Long.class;
case COLUMN_START:
return Date.class;
case COLUMN_END:
return Date.class;
default:
return String.class;
}
}
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
return columnIndex == COLUMN_ACTION;
}
}
class UpdateMatchesTask extends SwingWorker<Void, Collection<MatchView>> {
private final UUID roomId;

View file

@ -0,0 +1,206 @@
package mage.client.table;
import mage.client.SessionHandler;
import mage.constants.SkillLevel;
import mage.remote.MageRemoteException;
import mage.view.TableView;
import javax.swing.*;
import javax.swing.table.AbstractTableModel;
import java.util.Collection;
import java.util.Date;
public class TablesTableModel extends AbstractTableModel {
final ImageIcon tourneyIcon = new ImageIcon(getClass().getResource("/tables/tourney_icon.png"));
final ImageIcon matchIcon = new ImageIcon(getClass().getResource("/tables/match_icon.png"));
public static final int COLUMN_ICON = 0;
public static final int COLUMN_DECK_TYPE = 1; // column the deck type is located (starting with 0) Start string is used to check for Limited
public static final int COLUMN_OWNER = 2;
public static final int COLUMN_GAME_TYPE = 3;
public static final int COLUMN_INFO = 4;
public static final int COLUMN_STATUS = 5;
public static final int COLUMN_PASSWORD = 6;
public static final int COLUMN_CREATED = 7;
public static final int COLUMN_SKILL = 8;
public static final int COLUMN_RATING = 9;
public static final int COLUMN_QUIT_RATIO = 10;
public static final int COLUMN_MINIMUM_RATING = 11;
public static final int ACTION_COLUMN = 12; // column the action is located (starting with 0)
public static final String RATED_VALUE_YES = "YES";
public static final String RATED_VALUE_NO = "";
public static final String PASSWORD_VALUE_YES = "YES";
private final String[] columnNames = new String[]{"M/T", "Deck Type", "Owner / Players", "Game Type", "Info", "Status", "Password", "Created / Started", "Skill Level", "Rated", "Quit %", "Min Rating", "Action"};
private TableView[] tables = new TableView[0];
TablesTableModel() {
}
public void loadData(Collection<TableView> tables) throws MageRemoteException {
this.tables = tables.toArray(new TableView[0]);
this.fireTableDataChanged();
}
public String getTableAndGameInfo(int row) {
return this.tables[row].getTableId().toString() + ";" + (!tables[row].getGames().isEmpty() ? tables[row].getGames().get(0).toString() : "null");
}
public String findTableAndGameInfoByRow(int row) {
if (row >= 0 && row < this.tables.length) {
return getTableAndGameInfo(row);
} else {
return null;
}
}
public int findRowByTableAndGameInfo(String tableAndGame) {
for (int i = 0; i < this.tables.length; i++) {
String rowID = this.tables[i].getTableId().toString() + ";" + (!this.tables[i].getGames().isEmpty() ? this.tables[i].getGames().get(0).toString() : "null");
if (tableAndGame.equals(rowID)) {
return i;
}
}
return -1;
}
public String getSkillLevelAsCode(SkillLevel skill, boolean asRegExp) {
String res;
switch (skill) {
case BEGINNER:
res = "*";
break;
case CASUAL:
res = "**";
break;
case SERIOUS:
res = "***";
break;
default:
res = "";
break;
}
// regexp format for search table rows
if (asRegExp) {
res = String.format("^%s$", res.replace("*", "\\*"));
}
return res;
}
@Override
public int getRowCount() {
return tables.length;
}
@Override
public int getColumnCount() {
return columnNames.length;
}
@Override
public Object getValueAt(int arg0, int arg1) {
switch (arg1) {
case 0:
return tables[arg0].isTournament() ? tourneyIcon : matchIcon;
case 1:
return tables[arg0].getDeckType();
case 2:
return tables[arg0].getControllerName();
case 3:
return tables[arg0].getGameType();
case 4:
return tables[arg0].getAdditionalInfo();
case 5:
return tables[arg0].getTableStateText();
case 6:
return tables[arg0].isPassworded() ? PASSWORD_VALUE_YES : "";
case 7:
return tables[arg0].getCreateTime(); // use cell render, not format here
case 8:
return this.getSkillLevelAsCode(tables[arg0].getSkillLevel(), false);
case 9:
return tables[arg0].isRated() ? RATED_VALUE_YES : RATED_VALUE_NO;
case 10:
return tables[arg0].getQuitRatio();
case 11:
return tables[arg0].getMinimumRating();
case 12:
switch (tables[arg0].getTableState()) {
case WAITING:
String owner = tables[arg0].getControllerName();
if (SessionHandler.getSession() != null && owner.equals(SessionHandler.getUserName())) {
return "";
}
return "Join";
case CONSTRUCTING:
case DRAFTING:
if (tables[arg0].isTournament()) {
return "Show";
}
case DUELING:
if (tables[arg0].isTournament()) {
return "Show";
} else {
owner = tables[arg0].getControllerName();
if (SessionHandler.getSession() != null && owner.equals(SessionHandler.getUserName())) {
return "";
}
if (tables[arg0].getSpectatorsAllowed()) {
return "Watch";
}
return "";
}
default:
return "";
}
case 13:
return tables[arg0].isTournament();
case 14:
if (!tables[arg0].getGames().isEmpty()) {
return tables[arg0].getGames().get(0);
}
return null;
case 15:
return tables[arg0].getTableId();
}
return "";
}
@Override
public String getColumnName(int columnIndex) {
String colName = "";
if (columnIndex <= getColumnCount()) {
colName = columnNames[columnIndex];
}
return colName;
}
@Override
public Class getColumnClass(int columnIndex) {
switch (columnIndex) {
case COLUMN_ICON:
return Icon.class;
case COLUMN_SKILL:
return SkillLevel.class;
case COLUMN_CREATED:
return Date.class;
default:
return String.class;
}
}
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
return columnIndex == ACTION_COLUMN;
}
}

View file

@ -0,0 +1,40 @@
package mage.client.table;
import org.apache.log4j.Logger;
import javax.swing.*;
/**
* @author JayDi85
*/
public class TablesUtil {
private static final Logger logger = Logger.getLogger(TablesUtil.class);
public static String getSearchIdFromTable(JTable table, int row) {
// tableUUID;gameUUID
String searchId = null;
if (table.getModel() instanceof TablesTableModel) {
searchId = ((TablesTableModel) table.getModel()).findTableAndGameInfoByRow(row);
} else if (table.getModel() instanceof MatchesTableModel) {
searchId = ((MatchesTableModel) table.getModel()).findTableAndGameInfoByRow(row);
} else {
logger.error("Not supported tables model " + table.getModel().getClass().toString());
}
return searchId;
}
public static int findTableRowFromSearchId(Object tableModel, String searchId) {
// tableUUID;gameUUID
int row = -1;
if (tableModel instanceof TablesTableModel) {
row = ((TablesTableModel) tableModel).findRowByTableAndGameInfo(searchId);
} else if (tableModel instanceof MatchesTableModel) {
row = ((MatchesTableModel) tableModel).findRowByTableAndGameInfo(searchId);
} else {
logger.error("Not supported tables model " + tableModel.getClass().toString());
}
return row;
}
}

View file

@ -1,15 +1,21 @@
/*
* TournamentPanel.java
*
* Created on 20-Jan-2011, 9:18:30 PM
*/
package mage.client.tournament;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Rectangle;
import mage.client.MageFrame;
import mage.client.SessionHandler;
import mage.client.chat.ChatPanelBasic;
import mage.client.dialog.PreferencesDialog;
import mage.client.table.TablesButtonColumn;
import mage.client.util.Format;
import mage.client.util.GUISizeHelper;
import mage.client.util.gui.TableUtil;
import mage.client.util.gui.countryBox.CountryCellRenderer;
import mage.constants.PlayerAction;
import mage.view.*;
import org.apache.log4j.Logger;
import javax.swing.*;
import javax.swing.table.AbstractTableModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.text.DateFormat;
import java.util.ArrayList;
@ -19,34 +25,10 @@ import java.util.UUID;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.SwingWorker;
import javax.swing.table.AbstractTableModel;
import mage.client.MageFrame;
import mage.client.SessionHandler;
import mage.client.chat.ChatPanelBasic;
import mage.client.dialog.PreferencesDialog;
import static mage.client.dialog.PreferencesDialog.KEY_TOURNAMENT_MATCH_COLUMNS_ORDER;
import static mage.client.dialog.PreferencesDialog.KEY_TOURNAMENT_MATCH_COLUMNS_WIDTH;
import static mage.client.dialog.PreferencesDialog.KEY_TOURNAMENT_PLAYER_COLUMNS_ORDER;
import static mage.client.dialog.PreferencesDialog.KEY_TOURNAMENT_PLAYER_COLUMNS_WIDTH;
import mage.client.util.ButtonColumn;
import mage.client.util.Format;
import mage.client.util.GUISizeHelper;
import mage.client.util.gui.TableUtil;
import mage.client.util.gui.countryBox.CountryCellRenderer;
import mage.constants.PlayerAction;
import mage.view.RoundView;
import mage.view.TournamentGameView;
import mage.view.TournamentPlayerView;
import mage.view.TournamentView;
import mage.view.UserRequestMessage;
import org.apache.log4j.Logger;
import static mage.client.dialog.PreferencesDialog.*;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class TournamentPanel extends javax.swing.JPanel {
@ -64,7 +46,7 @@ public class TournamentPanel extends javax.swing.JPanel {
private UpdateTournamentTask updateTask;
private final DateFormat df;
private final ButtonColumn actionButtonColumn1;
private final TablesButtonColumn actionButtonColumn1;
/**
* Creates new form TournamentPanel
@ -111,7 +93,7 @@ public class TournamentPanel extends javax.swing.JPanel {
};
// action button, don't delete this
actionButtonColumn1 = new ButtonColumn(tableMatches, action, tableMatches.convertColumnIndexToView(TournamentMatchesTableModel.ACTION_COLUMN));
actionButtonColumn1 = new TablesButtonColumn(tableMatches, action, tableMatches.convertColumnIndexToView(TournamentMatchesTableModel.ACTION_COLUMN));
setGUISize();
}
@ -390,67 +372,67 @@ public class TournamentPanel extends javax.swing.JPanel {
javax.swing.GroupLayout actionPanelLayout = new javax.swing.GroupLayout(actionPanel);
actionPanel.setLayout(actionPanelLayout);
actionPanelLayout.setHorizontalGroup(
actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(actionPanelLayout.createSequentialGroup()
.addContainerGap()
.addGroup(actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(lblName)
.addComponent(lblState)
.addComponent(txtName, javax.swing.GroupLayout.DEFAULT_SIZE, 260, Short.MAX_VALUE)
.addComponent(txtTournamentState))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(lblType)
.addComponent(txtType, javax.swing.GroupLayout.PREFERRED_SIZE, 440, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(actionPanelLayout.createSequentialGroup()
.addGroup(actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txtStartTime, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblStartTime))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lblEndTime)
.addComponent(txtEndTime))))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 126, Short.MAX_VALUE)
.addGroup(actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(btnQuitTournament, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnCloseWindow, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(actionPanelLayout.createSequentialGroup()
.addContainerGap()
.addGroup(actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(lblName)
.addComponent(lblState)
.addComponent(txtName, javax.swing.GroupLayout.DEFAULT_SIZE, 260, Short.MAX_VALUE)
.addComponent(txtTournamentState))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(lblType)
.addComponent(txtType, javax.swing.GroupLayout.PREFERRED_SIZE, 440, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(actionPanelLayout.createSequentialGroup()
.addGroup(actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txtStartTime, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblStartTime))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lblEndTime)
.addComponent(txtEndTime))))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 126, Short.MAX_VALUE)
.addGroup(actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(btnQuitTournament, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnCloseWindow, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
actionPanelLayout.setVerticalGroup(
actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(actionPanelLayout.createSequentialGroup()
.addGroup(actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(actionPanelLayout.createSequentialGroup()
.addGap(7, 7, 7)
.addComponent(lblName))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, actionPanelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(lblType)))
.addGroup(actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(actionPanelLayout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txtType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnQuitTournament))
.addGap(13, 13, 13)
.addComponent(btnCloseWindow))
.addGroup(actionPanelLayout.createSequentialGroup()
.addGap(6, 6, 6)
.addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblState)
.addComponent(lblStartTime)
.addComponent(lblEndTime))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(actionPanelLayout.createSequentialGroup()
.addComponent(txtTournamentState, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtStartTime)
.addComponent(txtEndTime, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
.addContainerGap())
actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(actionPanelLayout.createSequentialGroup()
.addGroup(actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(actionPanelLayout.createSequentialGroup()
.addGap(7, 7, 7)
.addComponent(lblName))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, actionPanelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(lblType)))
.addGroup(actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(actionPanelLayout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txtType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnQuitTournament))
.addGap(13, 13, 13)
.addComponent(btnCloseWindow))
.addGroup(actionPanelLayout.createSequentialGroup()
.addGap(6, 6, 6)
.addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblState)
.addComponent(lblStartTime)
.addComponent(lblEndTime))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(actionPanelLayout.createSequentialGroup()
.addComponent(txtTournamentState, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtStartTime)
.addComponent(txtEndTime, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
.addContainerGap())
);
jSplitPane2.setResizeWeight(1.0);
@ -481,17 +463,17 @@ public class TournamentPanel extends javax.swing.JPanel {
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(actionPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jSplitPane2, javax.swing.GroupLayout.Alignment.TRAILING)
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(actionPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jSplitPane2, javax.swing.GroupLayout.Alignment.TRAILING)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(actionPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jSplitPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 454, Short.MAX_VALUE)
.addContainerGap())
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(actionPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jSplitPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 454, Short.MAX_VALUE)
.addContainerGap())
);
}// </editor-fold>//GEN-END:initComponents

View file

@ -0,0 +1,68 @@
package mage.client.util;
import java.util.ArrayList;
/**
* @author JayDi85
*/
public enum CardLanguage {
ENGLISH("en", "English"),
SPANISH("es", "Spanish"),
FRENCH("fr", "French"),
GERMAN("de", "German"),
ITALIAN("it", "Italian"),
PORTUGUESE("pt", "Portuguese"),
JAPANESE("jp", "Japanese"),
KOREAN("ko", "Korean"),
RUSSIAN("ru", "Russian"),
CHINES_SIMPLE("cns", "Chinese Simplified"),
CHINES_TRADITION("cnt", "Chinese Traditional");
private final String code;
private final String text;
CardLanguage(String code, String text) {
this.code = code;
this.text = text;
}
@Override
public String toString() {
return code;
}
public String getCode() {
return code;
}
public String getText() {
return text;
}
public static String[] toList() {
ArrayList<String> res = new ArrayList<>();
for (CardLanguage l : values()) {
res.add(l.toString());
}
return res.toArray(new String[0]);
}
public static CardLanguage valueByText(String text) {
for (CardLanguage type : values()) {
if (type.text.equals(text)) {
return type;
}
}
return CardLanguage.ENGLISH;
}
public static CardLanguage valueByCode(String code) {
for (CardLanguage type : values()) {
if (type.code.equals(code)) {
return type;
}
}
return CardLanguage.ENGLISH;
}
}

View file

@ -57,7 +57,7 @@ public class AudioManager {
try {
linePool = new LinePool();
} catch (Exception e) {
log.warn("Failed to initialize AudioManager. No sounds will be played.", e);
log.warn("Failed to initialize AudioManager (can't find compatible sound device). No sounds will be played.");
}
}

View file

@ -19,12 +19,16 @@ public class FastSearchUtil {
public static String DEFAULT_EXPANSION_SEARCH_MESSAGE = "Select set or expansion";
public static String DEFAULT_EXPANSION_TOOLTIP_MESSAGE = "Fast search set or expansion";
public static void showFastSearchForStringComboBox(JComboBox combo, String chooseMessage){
showFastSearchForStringComboBox(combo, chooseMessage, 300, 500);
}
/**
* Show fast choice modal dialog with incremental searching for any string combobox components
* @param combo combobox control with default data model
* @param chooseMessage caption message for dialog
*/
public static void showFastSearchForStringComboBox(JComboBox combo, String chooseMessage){
public static void showFastSearchForStringComboBox(JComboBox combo, String chooseMessage, int windowWidth, int windowHeight){
// fast search/choice dialog for string combobox
mage.choices.Choice choice = new ChoiceImpl(false);
@ -51,7 +55,7 @@ public class FastSearchUtil {
// ask for new value
PickChoiceDialog dlg = new PickChoiceDialog();
dlg.setWindowSize(300, 500);
dlg.setWindowSize(windowWidth, windowHeight);
dlg.showDialog(choice, needSelectValue);
if(choice.isChosen()){
item = choice.getChoiceKey();

View file

@ -1,10 +1,11 @@
package org.mage.plugins.card.dl.sources;
import java.util.ArrayList;
import mage.client.util.CardLanguage;
import org.mage.plugins.card.images.CardDownloadData;
import java.util.ArrayList;
/**
*
* @author North
*/
public interface CardImageSource {
@ -31,10 +32,21 @@ public interface CardImageSource {
return false;
}
default boolean isLanguagesSupport() {
return false;
}
default void setCurrentLanguage(CardLanguage cardLanguage) {
}
default CardLanguage getCurrentLanguage() {
return CardLanguage.ENGLISH;
}
void doPause(String httpImageUrl);
default ArrayList<String> getSupportedSets() {
return null;
return new ArrayList<>();
}
default boolean isSetSupportedComplete(String setCode) {

View file

@ -1,439 +0,0 @@
package org.mage.plugins.card.dl.sources;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import mage.client.dialog.PreferencesDialog;
import org.mage.plugins.card.images.CardDownloadData;
import org.mage.plugins.card.utils.CardImageUtils;
/**
* @author North
*/
public enum MagicCardsImageSource implements CardImageSource {
instance;
private static final Set<String> supportedSets = new LinkedHashSet<String>() {
{
// add("PTC"); // Prerelease Events
add("LEA");
add("LEB");
add("2ED");
add("ARN");
add("ATQ");
add("3ED");
add("LEG");
add("DRK");
add("FEM");
add("4ED");
add("ICE");
add("CHR");
add("HML");
add("ALL");
add("MIR");
add("VIS");
add("5ED");
add("POR");
add("WTH");
add("TMP");
add("STH");
add("EXO");
add("P02");
add("UGL");
add("USG");
add("DD3DVD");
add("DD3EVG");
add("DD3GVL");
add("DD3JVC");
add("ULG");
add("6ED");
add("UDS");
add("PTK");
add("S99");
add("MMQ");
// add("BRB");Battle Royale Box Set
add("NEM");
add("S00");
add("PCY");
add("INV");
// add("BTD"); // Beatdown Boxset
add("PLS");
add("7ED");
add("APC");
add("ODY");
// add("DKM"); // Deckmasters 2001
add("TOR");
add("JUD");
add("ONS");
add("LGN");
add("SCG");
add("8ED");
add("MRD");
add("DST");
add("5DN");
add("CHK");
add("UNH");
add("BOK");
add("SOK");
add("9ED");
add("RAV");
add("GPT");
add("DIS");
add("CSP");
add("TSP");
add("TSB");
add("PLC");
add("FUT");
add("10E");
add("MED");
add("LRW");
add("EVG");
add("MOR");
add("SHM");
add("EVE");
add("DRB");
add("ME2");
add("ALA");
add("DD2");
add("CON");
add("DDC");
add("ARB");
add("M10");
// add("TD0"); // Magic Online Deck Series
add("V09");
add("HOP");
add("ME3");
add("ZEN");
add("DDD");
add("H09");
add("WWK");
add("DDE");
add("ROE");
add("DPA");
add("ARC");
add("M11");
add("V10");
add("DDF");
add("SOM");
// add("TD0"); // Commander Theme Decks
add("PD2");
add("ME4");
add("MBS");
add("DDG");
add("NPH");
add("CMD");
add("M12");
add("V11");
add("DDH");
add("ISD");
add("PD3");
add("DKA");
add("DDI");
add("AVR");
add("PC2");
add("M13");
add("V12");
add("DDJ");
add("RTR");
add("CM1");
// add("TD2"); // Duel Decks: Mirrodin Pure vs. New Phyrexia
add("GTC");
add("DDK");
add("DGM");
add("MMA");
add("M14");
add("V13");
add("DDL");
add("THS");
add("C13");
add("BNG");
add("DDM");
add("JOU");
// add("MD1"); // Modern Event Deck
add("CNS");
add("VMA");
add("M15");
add("V14");
add("DDN");
add("KTK");
add("C14");
// add("DD3"); // Duel Decks Anthology
add("FRF");
add("DDO");
add("DTK");
add("TPR");
add("MM2");
add("ORI");
add("V15");
add("DDP");
add("BFZ");
add("EXP");
add("C15");
// add("PZ1"); // Legendary Cube
add("OGW");
add("DDQ");
add("W16");
add("SOI");
add("EMA");
add("EMN");
add("V16");
add("CN2");
add("DDR");
add("KLD");
add("MPS");
// add("PZ2"); // Treasure Chests
add("C16");
add("PCA");
add("AER");
add("MM3");
add("DDS");
add("W17");
add("AKH");
add("MPS");
add("CMA");
add("E01");
add("HOU");
add("C17");
add("XLN");
add("DDT");
add("DDU");
add("IMA");
add("E02");
add("V17");
add("UST");
add("RIX");
add("A25");
add("DOM");
// add("CM2");
// add("M19");
}
};
private static final Map<String, String> setNameTokenReplacement = new HashMap<String, String>() {
{
put("10E", "tenth-edition");
put("AER", "aether-revolt");
put("AKH", "amonkhet");
put("ALA", "shards-of-alara");
put("ANB", "archenemy-nicol-bolas");
put("APAC", "asia-pacific-land-program");
put("APC", "player-rewards-2001");
put("ARB", "alara-reborn");
put("ARC", "archenemy");
put("ARENA", "arena-league");
put("AVR", "avacyn-restored");
put("BFZ", "battle-for-zendikar");
put("BNG", "born-of-the-gods");
put("C13", "commander-2013-edition");
put("C14", "commander-2014");
put("C15", "commander-2015");
put("C16", "commander-2016");
put("CLASH", "clash-pack");
put("CMA", "commander-anthology");
put("CMA", "commanders-arsenal");
put("CMD", "commander");
put("CN2", "conspiracy-take-the-crown");
put("CNS", "conspiracy");
put("CON", "conflux");
put("CP", "champs");
put("CSP", "coldsnap");
put("DD2", "duel-decks-jace-vs-chandra");
put("DD3DVD", "duel-decks-anthology-divine-vs-demonic");
put("DD3EVG", "duel-decks-anthology-elves-vs-goblins");
put("DD3GVL", "duel-decks-anthology-garruk-vs-liliana");
put("DD3JVC", "duel-decks-anthology-jace-vs-chandra");
put("DDC", "duel-decks-divine-vs-demonic");
put("DDD", "duel-decks-garruk-vs-liliana");
put("DDE", "duel-decks-phyrexia-vs-the-coalition");
put("DDF", "duel-decks-elspeth-vs-tezzeret");
put("DDG", "duel-decks-knights-vs-dragons");
put("DDH", "duel-decks-ajani-vs-nicol-bolas");
put("DDI", "duel-decks-venser-vs-koth");
put("DDJ", "duel-decks-izzet-vs-golgari");
put("DDK", "duel-decks-sorin-vs-tibalt");
put("DDL", "duel-decks-heroes-vs-monsters");
put("DDM", "duel-decks-jace-vs-vraska");
put("DDN", "duel-decks-speed-vs-cunning");
put("DDO", "duel-decks-elspeth-vs-kiora");
put("DDP", "duel-decks-zendikar-vs-eldrazi");
put("DDQ", "duel-decks-blessed-vs-cursed");
put("DDR", "duel-decks-nissa-vs-ob-nixilis");
put("DDS", "duel-decks-mind-vs-might");
put("DDT", "duel-decks-merfolk-vs-goblin");
put("DDU", "duel-decks-elves-vs-inventors");
put("DGM", "dragons-maze");
put("DKA", "dark-ascension");
put("DRB", "from-the-vault-dragons");
put("DTK", "dragons-of-tarkir");
put("EMA", "eternal-masters");
put("EMN", "eldritch-moon");
put("EURO", "european-land-program");
put("EVE", "eventide");
put("EVG", "duel-decks-elves-vs-goblins");
put("EXP", "zendikar-expeditions");
put("FNMP", "friday-night-magic");
put("FRF", "fate-reforged");
put("GPX", "grand-prix");
put("GRC", "wpngateway");
put("GTC", "gatecrash");
put("HOP", "planechase");
put("HOU", "hour-of-devastation");
put("INV", "player-rewards-2001");
put("ISD", "innistrad");
put("JOU", "journey-into-nyx");
put("JR", "judge-gift-program");
put("KLD", "kaladesh");
put("KTK", "khans-of-tarkir");
put("LRW", "lorwyn");
put("M10", "magic-2010");
put("M11", "magic-2011");
put("M12", "magic-2012");
put("M13", "magic-2013");
put("M14", "magic-2014");
put("M15", "magic-2015");
put("MBP", "media-inserts");
put("MBS", "mirrodin-besieged");
put("MGDC", "magic-game-day-cards");
put("MLP", "launch-party");
put("MM2", "modern-masters-2015");
put("MM3", "modern-masters-2017");
put("MMA", "modern-masters");
put("MOR", "morningtide");
put("MPRP", "magic-player-rewards");
put("MPS", "masterpiece-series");
put("NPH", "new-phyrexia");
put("ODY", "player-rewards-2002");
put("OGW", "oath-of-the-gatewatch");
put("ORG", "oath-of-the-gatewatch");
put("ORI", "magic-origins");
put("PC2", "planechase-2012-edition");
put("PO2", "portal-second-age");
put("PLS", "player-rewards-2001");
put("POR", "portal");
put("PTC", "prerelease-events");
put("PTK", "portal-three-kingdoms");
put("ROE", "rise-of-the-eldrazi");
put("RTR", "return-to-ravnica");
put("SHM", "shadowmoor");
put("SOI", "shadows-over-innistrad");
put("SOM", "scars-of-mirrodin");
put("SUS", "super-series");
put("THS", "theros");
put("TPR", "tempest-remastered");
put("UGIN", "ugins-fate");
put("V09", "from-the-vault-exiled");
put("V10", "from-the-vault-relics");
put("V11", "from-the-vault-legends");
put("V12", "from-the-vault-realms");
put("V13", "from-the-vault-twenty");
put("V14", "from-the-vault-annihilation");
put("V15", "from-the-vault-angels");
put("V16", "from-the-vault-lore");
put("VMA", "vintage-masters");
put("W16", "welcome-deck-2016");
put("W17", "welcome-deck-2017");
put("WMCQ", "world-magic-cup-qualifier");
put("WWK", "worldwake");
put("ZEN", "zendikar");
}
private static final long serialVersionUID = 1L;
};
@Override
public String getSourceName() {
return "magiccards.info";
}
@Override
public String getNextHttpImageUrl() {
return null;
}
@Override
public String getFileForHttpImage(String httpImageUrl) {
return null;
}
@Override
public CardImageUrls generateURL(CardDownloadData card) throws Exception {
String collectorId = card.getCollectorId();
String cardSet = card.getSet();
if (collectorId == null || cardSet == null) {
throw new Exception("Wrong parameters for image: collector id: " + collectorId + ",card set: " + cardSet);
}
String set = CardImageUtils.updateSet(cardSet, true);
String preferedLanguage = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_CARD_IMAGES_PREF_LANGUAGE, "en");
StringBuilder url = new StringBuilder("http://magiccards.info/scans/").append(preferedLanguage).append('/');
url.append(set.toLowerCase(Locale.ENGLISH)).append('/').append(collectorId);
if (card.isTwoFacedCard()) {
url.append(card.isSecondSide() ? "b" : "a");
}
if (card.isSplitCard()) {
url.append('a');
}
if (card.isFlipCard()) {
if (card.isFlippedSide()) { // download rotated by 180 degree image
url.append('b');
} else {
url.append('a');
}
}
url.append(".jpg");
return new CardImageUrls(url.toString());
}
@Override
public CardImageUrls generateTokenUrl(CardDownloadData card) {
String name = card.getName();
// add type to name if it's not 0
if (card.getType() > 0) {
name = name + ' ' + card.getType();
}
name = name.replaceAll(" ", "-").replace(",", "").toLowerCase(Locale.ENGLISH);
String set = "not-supported-set";
if (setNameTokenReplacement.containsKey(card.getSet())) {
set = setNameTokenReplacement.get(card.getSet());
} else {
set += '-' + card.getSet();
}
return new CardImageUrls("http://magiccards.info/extras/token/" + set + '/' + name + ".jpg");
}
@Override
public float getAverageSize() {
return 70.0f;
}
@Override
public int getTotalImages() {
return -1;
}
@Override
public boolean isTokenSource() {
return true;
}
@Override
public ArrayList<String> getSupportedSets() {
ArrayList<String> supportedSetsCopy = new ArrayList<>();
supportedSetsCopy.addAll(supportedSets);
return supportedSetsCopy;
}
@Override
public void doPause(String httpImageUrl) {
}
}

View file

@ -1,6 +1,6 @@
package org.mage.plugins.card.dl.sources;
import mage.client.dialog.PreferencesDialog;
import mage.client.util.CardLanguage;
import org.mage.plugins.card.images.CardDownloadData;
import java.util.*;
@ -13,21 +13,23 @@ public enum ScryfallImageSource implements CardImageSource {
instance;
private final Set<String> supportedSets;
private final Map<String, String> languageAliases;
private final Map<CardLanguage, String> languageAliases;
private CardLanguage currentLanguage = CardLanguage.ENGLISH; // working language
ScryfallImageSource() {
// https://scryfall.com/docs/api/languages
languageAliases = new HashMap<>();
languageAliases.put("en", "en");
languageAliases.put("es", "es");
languageAliases.put("jp", "ja");
languageAliases.put("it", "it");
languageAliases.put("fr", "fr");
languageAliases.put("cn", "zhs"); // Simplified Chinese
languageAliases.put("de", "de");
languageAliases.put("ko", "ko");
languageAliases.put("pt", "pt");
languageAliases.put("ru", "ru");
languageAliases.put(CardLanguage.ENGLISH, "en");
languageAliases.put(CardLanguage.SPANISH, "es");
languageAliases.put(CardLanguage.FRENCH, "fr");
languageAliases.put(CardLanguage.GERMAN, "de");
languageAliases.put(CardLanguage.ITALIAN, "it");
languageAliases.put(CardLanguage.PORTUGUESE, "pt");
languageAliases.put(CardLanguage.JAPANESE, "ja");
languageAliases.put(CardLanguage.KOREAN, "ko");
languageAliases.put(CardLanguage.RUSSIAN, "ru");
languageAliases.put(CardLanguage.CHINES_SIMPLE, "zhs");
languageAliases.put(CardLanguage.CHINES_TRADITION, "zht");
supportedSets = new LinkedHashSet<>();
// supportedSets.add("PTC"); //
@ -234,6 +236,7 @@ public enum ScryfallImageSource implements CardImageSource {
supportedSets.add("GNT");
supportedSets.add("UMA");
supportedSets.add("PUMA");
supportedSets.add("RNA");
//
supportedSets.add("EURO");
supportedSets.add("GPX");
@ -245,9 +248,9 @@ public enum ScryfallImageSource implements CardImageSource {
@Override
public CardImageUrls generateURL(CardDownloadData card) throws Exception {
String preferredLanguage = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_CARD_IMAGES_PREF_LANGUAGE, "en");
String defaultCode = "en";
String localizedCode = languageAliases.getOrDefault(preferredLanguage, defaultCode);
String preferredCode = this.getCurrentLanguage().getCode();
String defaultCode = CardLanguage.ENGLISH.getCode();
String localizedCode = languageAliases.getOrDefault(this.getCurrentLanguage(), defaultCode);
// loc example: https://api.scryfall.com/cards/xln/121/ru?format=image
// WARNING, some cards haven't direct images and uses random GUID:
@ -345,6 +348,21 @@ public enum ScryfallImageSource implements CardImageSource {
return false;
}
@Override
public boolean isLanguagesSupport() {
return true;
}
@Override
public void setCurrentLanguage(CardLanguage cardLanguage) {
this.currentLanguage = cardLanguage;
}
@Override
public CardLanguage getCurrentLanguage() {
return currentLanguage;
}
@Override
public void doPause(String httpImageUrl) {
@ -368,6 +386,7 @@ public enum ScryfallImageSource implements CardImageSource {
put("WMCQ", "pwcq");
put("EURO", "pelp");
put("GPX", "pgpx");
put("MED", "me1");
}
};

View file

@ -20,7 +20,7 @@ import java.util.logging.Level;
import mage.constants.SubType;
import org.apache.log4j.Logger;
import org.mage.plugins.card.images.CardDownloadData;
import org.mage.plugins.card.images.DownloadPictures;
import org.mage.plugins.card.images.DownloadPicturesService;
import org.mage.plugins.card.utils.CardImageUtils;
/**
@ -182,7 +182,7 @@ public enum TokensMtgImageSource implements CardImageSource {
private HashMap<String, ArrayList<TokenData>> getTokensData() throws IOException {
synchronized (tokensDataSync) {
if (tokensData == null) {
DownloadPictures.getInstance().updateAndViewMessage("Creating token data...");
DownloadPicturesService.getInstance().updateAndViewMessage("Find tokens data...");
tokensData = new HashMap<>();
// get tokens data from resource file
@ -233,10 +233,10 @@ public enum TokensMtgImageSource implements CardImageSource {
}
}
}
DownloadPictures.getInstance().updateAndViewMessage("");
DownloadPicturesService.getInstance().updateAndViewMessage("");
} catch (Exception ex) {
logger.warn("Failed to get tokens description from tokens.mtg.onl", ex);
DownloadPictures.getInstance().updateAndViewMessage(ex.getMessage());
DownloadPicturesService.getInstance().updateAndViewMessage(ex.getMessage());
}
}
}

View file

@ -1,22 +1,10 @@
package org.mage.plugins.card.dl.sources;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import mage.cards.Sets;
import mage.cards.repository.CardCriteria;
import mage.cards.repository.CardInfo;
import mage.cards.repository.CardRepository;
import mage.client.dialog.PreferencesDialog;
import mage.client.util.CardLanguage;
import org.apache.log4j.Logger;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
@ -24,6 +12,12 @@ import org.jsoup.select.Elements;
import org.mage.plugins.card.images.CardDownloadData;
import org.mage.plugins.card.utils.CardImageUtils;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
/**
* @author North
*/
@ -34,9 +28,10 @@ public enum WizardCardsImageSource implements CardImageSource {
private static final Logger logger = Logger.getLogger(WizardCardsImageSource.class);
private final Map<String, String> setsAliases;
private final Map<String, String> languageAliases;
private final Map<CardLanguage, String> languageAliases;
private final Map<String, Map<String, String>> sets;
private final Set<String> supportedSets;
private CardLanguage currentLanguage = CardLanguage.ENGLISH; // working language
@Override
public String getSourceName() {
@ -44,6 +39,20 @@ public enum WizardCardsImageSource implements CardImageSource {
}
WizardCardsImageSource() {
languageAliases = new HashMap<>();
languageAliases.put(CardLanguage.ENGLISH, "English");
languageAliases.put(CardLanguage.SPANISH, "Spanish");
languageAliases.put(CardLanguage.FRENCH, "French");
languageAliases.put(CardLanguage.GERMAN, "German");
languageAliases.put(CardLanguage.ITALIAN, "Italian");
languageAliases.put(CardLanguage.PORTUGUESE, "Portuguese (Brazil)");
languageAliases.put(CardLanguage.JAPANESE, "Japanese");
languageAliases.put(CardLanguage.KOREAN, "Korean");
languageAliases.put(CardLanguage.RUSSIAN, "Russian");
languageAliases.put(CardLanguage.CHINES_SIMPLE, "Chinese Simplified");
languageAliases.put(CardLanguage.CHINES_TRADITION, "Chinese Traditional ");
supportedSets = new LinkedHashSet<>();
// supportedSets.add("PTC"); // Prerelease Events
supportedSets.add("LEA");
@ -430,18 +439,6 @@ public enum WizardCardsImageSource implements CardImageSource {
setsAliases.put("WTH", "Weatherlight");
setsAliases.put("WWK", "Worldwake");
setsAliases.put("ZEN", "Zendikar");
languageAliases = new HashMap<>();
languageAliases.put("en", "English");
languageAliases.put("es", "Spanish");
languageAliases.put("jp", "Japanese");
languageAliases.put("it", "Italian");
languageAliases.put("fr", "French");
languageAliases.put("cn", "Chinese Simplified");
languageAliases.put("de", "German");
languageAliases.put("ko", "Korean");
languageAliases.put("pt", "Portuguese (Brazil)");
languageAliases.put("ru", "Russian");
}
@Override
@ -517,7 +514,7 @@ public enum WizardCardsImageSource implements CardImageSource {
if (setNames == null) {
setNames = Sets.getInstance().get(cardSet).getName();
}
String preferredLanguage = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_CARD_IMAGES_PREF_LANGUAGE, "en");
for (String setName : setNames.split("\\^")) {
// String URLSetName = URLEncoder.encode(setName, "UTF-8");
String URLSetName = setName.replaceAll(" ", "%20");
@ -555,7 +552,7 @@ public enum WizardCardsImageSource implements CardImageSource {
cardName = cardName.substring(0, pos1);
}
}
Integer preferredMultiverseId = getLocalizedMultiverseId(preferredLanguage, multiverseId);
Integer preferredMultiverseId = getLocalizedMultiverseId(getCurrentLanguage(), multiverseId);
setLinks.put(cardName.toLowerCase(Locale.ENGLISH) + numberChar, generateLink(preferredMultiverseId));
}
}
@ -617,8 +614,8 @@ public enum WizardCardsImageSource implements CardImageSource {
return "/Handlers/Image.ashx?multiverseid=" + landMultiverseId + "&type=card";
}
private int getLocalizedMultiverseId(String preferredLanguage, Integer multiverseId) throws IOException {
if (preferredLanguage.equals("en")) {
private int getLocalizedMultiverseId(CardLanguage preferredLanguage, Integer multiverseId) throws IOException {
if (preferredLanguage.equals(CardLanguage.ENGLISH)) {
return multiverseId;
}
@ -682,43 +679,6 @@ public enum WizardCardsImageSource implements CardImageSource {
return 60.0f;
}
// private final class GetImageLinkTask implements Runnable {
//
// private int multiverseId;
// private String cardName;
// private String preferredLanguage;
// private LinkedHashMap setLinks;
//
// public GetImageLinkTask(int multiverseId, String cardName, String preferredLanguage, LinkedHashMap setLinks) {
// try {
// this.multiverseId = multiverseId;
// this.cardName = cardName;
// this.preferredLanguage = preferredLanguage;
// this.setLinks = setLinks;
// } catch (Exception ex) {
// logger.error(ex.getMessage());
// logger.error("multiverseId: " + multiverseId);
// logger.error("cardName: " + cardName);
// logger.error("preferredLanguage: " + preferredLanguage);
// logger.error("setLinks: " + setLinks.toString());
// }
// }
//
// @Override
// public void run() {
// try {
// if (cardName.equals("Forest") || cardName.equals("Swamp") || cardName.equals("Mountain") || cardName.equals("Island") || cardName.equals("Plains")) {
// setLinks.putAll(getLandVariations(multiverseId, cardName));
// } else {
// Integer preferredMultiverseId = getLocalizedMultiverseId(preferredLanguage, multiverseId);
// setLinks.put(cardName.toLowerCase(Locale.ENGLISH), generateLink(preferredMultiverseId));
// }
// } catch (IOException | NumberFormatException ex) {
// logger.error("Exception when parsing the wizards page: " + ex.getMessage());
// }
// }
//
// }
@Override
public int getTotalImages() {
return -1;
@ -729,6 +689,21 @@ public enum WizardCardsImageSource implements CardImageSource {
return false;
}
@Override
public boolean isLanguagesSupport() {
return true;
}
@Override
public void setCurrentLanguage(CardLanguage cardLanguage) {
this.currentLanguage = cardLanguage;
}
@Override
public CardLanguage getCurrentLanguage() {
return currentLanguage;
}
@Override
public void doPause(String httpImageUrl) {
}

View file

@ -1,28 +1,14 @@
package org.mage.plugins.card.images;
import java.awt.*;
import java.awt.event.ItemEvent;
import java.io.*;
import java.net.*;
import java.nio.file.AccessDeniedException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import javax.swing.*;
import mage.cards.ExpansionSet;
import mage.cards.Sets;
import mage.cards.repository.CardCriteria;
import mage.cards.repository.CardInfo;
import mage.cards.repository.CardRepository;
import mage.client.MageFrame;
import mage.client.dialog.DownloadImagesDialog;
import mage.client.dialog.PreferencesDialog;
import mage.client.util.CardLanguage;
import mage.client.util.sets.ConstructedFormats;
import mage.remote.Connection;
import mage.util.StreamUtils;
@ -35,46 +21,49 @@ import org.mage.plugins.card.dl.sources.*;
import org.mage.plugins.card.properties.SettingsManager;
import org.mage.plugins.card.utils.CardImageUtils;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ItemEvent;
import java.io.*;
import java.net.*;
import java.nio.file.AccessDeniedException;
import java.util.List;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import static org.mage.plugins.card.utils.CardImageUtils.getImagesDir;
public class DownloadPictures extends DefaultBoundedRangeModel implements Runnable {
/**
* @author JayDi85
*/
public class DownloadPicturesService extends DefaultBoundedRangeModel implements Runnable {
// don't forget to remove new sets from ignore.urls to download (propeties file in resources)
private static DownloadPictures instance;
// don't forget to remove new sets from ignore.urls to download (properties file in resources)
private static DownloadPicturesService instance;
private static final Logger logger = Logger.getLogger(DownloadPicturesService.class);
private static final Logger logger = Logger.getLogger(DownloadPictures.class);
public static final String ALL_IMAGES = "- ALL images from selected source (can be slow)";
public static final String ALL_MODERN_IMAGES = "- MODERN images (can be slow)";
public static final String ALL_STANDARD_IMAGES = "- STANDARD images";
public static final String ALL_TOKENS = "- TOKEN images";
public static final String ALL_IMAGES = "- ALL images from selected source (CAN BE VERY SLOW)";
public static final String ALL_STANDARD_IMAGES = "- Only images from STANDARD sets";
public static final String ALL_TOKENS = "- Only token images from selected source";
private JDialog dialog;
private final JProgressBar bar;
private final JOptionPane dlg;
private boolean cancel;
private final JButton closeButton;
private final JButton startDownloadButton;
private DownloadImagesDialog uiDialog;
private boolean needCancel;
private int cardIndex;
private List<CardDownloadData> allCardsMissingImage;
private List<CardDownloadData> cardsToDownload;
private int missingCards = 0;
private int missingTokens = 0;
private List<CardInfo> cardsAll;
private List<CardDownloadData> cardsMissing;
private List<CardDownloadData> cardsDownloadQueue;
private int missingCardsCount = 0;
private int missingTokensCount = 0;
List<String> selectedSetCodes = new ArrayList<>();
private final JComboBox jComboBoxServer;
private final JLabel jLabelMessage;
private final JLabel jLabelAllMissing;
private final JLabel jLabelServer;
private final JComboBox jComboBoxSet;
private final JLabel jLabelSet;
List<String> selectedSets = new ArrayList<>();
private static CardImageSource selectedSource;
private final Object sync = new Object();
private static CardImageSource cardImageSource;
private Proxy p = Proxy.NO_PROXY;
enum DownloadSources {
@ -87,7 +76,6 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
ALTERNATIVE("7. alternative.mtg.onl", AltMtgOnlTokensImageSource.instance),
COPYPASTE("8. Copy and Paste Image URLs", CopyPasteImageSource.instance);
// MTG_ONL("mtg.onl", MtgOnlTokensImageSource.instance), Not working correctly yet
// MAGICCARDS("magiccards.info", MagicCardsImageSource.instance)
private final String text;
private final CardImageSource source;
@ -108,7 +96,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
}
public static DownloadPictures getInstance() {
public static DownloadPicturesService getInstance() {
return instance;
}
@ -117,245 +105,245 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
}
public static void startDownload() {
// load images info in background task
instance = new DownloadPicturesService(MageFrame.getInstance());
new Thread(new LoadMissingCardDataNew(instance)).start();
/*
* if (cards == null || cards.isEmpty()) {
* JOptionPane.showMessageDialog(null,
* "All card pictures have been downloaded."); return; }
*/
instance = new DownloadPictures(MageFrame.getInstance());
Thread t1 = new Thread(new LoadMissingCardData(instance));
t1.start();
instance.getDlg().setVisible(true);
instance.getDlg().dispose();
instance.cancel = true;
// show dialog
instance.setNeedCancel(false);
instance.uiDialog.showDialog();
instance.uiDialog.dispose();
instance.setNeedCancel(true);
}
public JDialog getDlg() {
return dialog;
public boolean getNeedCancel() {
return this.needCancel;
}
public void setCancel(boolean cancel) {
this.cancel = cancel;
public void setNeedCancel(boolean needCancel) {
this.needCancel = needCancel;
}
static int WIDTH = 400;
public DownloadPicturesService(JFrame frame) {
// init service and dialog
cardsAll = Collections.synchronizedList(new ArrayList<>());
cardsMissing = Collections.synchronizedList(new ArrayList<>());
cardsDownloadQueue = Collections.synchronizedList(new ArrayList<>());
uiDialog = new DownloadImagesDialog();
public DownloadPictures(JFrame frame) {
// MESSAGE
uiDialog.setGlobalInfo("Initializing image download...");
cardsToDownload = new ArrayList<>();
JPanel p0 = new JPanel();
p0.setLayout(new BoxLayout(p0, BoxLayout.Y_AXIS));
p0.add(Box.createVerticalStrut(5));
jLabelMessage = new JLabel();
jLabelMessage.setAlignmentX(Component.CENTER_ALIGNMENT);
jLabelMessage.setText("Initializing image download...");
p0.add(jLabelMessage);
p0.add(Box.createVerticalStrut(5));
jLabelAllMissing = new JLabel();
jLabelAllMissing.setAlignmentX(Component.LEFT_ALIGNMENT);
// jLabelAllMissing.setText("Computing number of missing images...");
p0.add(jLabelAllMissing);
p0.add(Box.createVerticalStrut(5));
jLabelServer = new JLabel();
jLabelServer.setText("Please select image source:");
jLabelServer.setAlignmentX(Component.LEFT_ALIGNMENT);
jLabelServer.setVisible(false);
p0.add(jLabelServer);
p0.add(Box.createVerticalStrut(5));
jComboBoxServer = new JComboBox();
jComboBoxServer.setModel(new DefaultComboBoxModel(DownloadSources.values()));
jComboBoxServer.setAlignmentX(Component.LEFT_ALIGNMENT);
jComboBoxServer.setAlignmentY(Component.LEFT_ALIGNMENT);
jComboBoxServer.addItemListener((ItemEvent event) -> {
// SOURCES - scryfall is default source
uiDialog.getSourcesCombo().setModel(new DefaultComboBoxModel(DownloadSources.values()));
uiDialog.getSourcesCombo().setSelectedItem(DownloadSources.SCRYFALL);
selectedSource = ScryfallImageSource.instance;
uiDialog.getSourcesCombo().addItemListener((ItemEvent event) -> {
if (event.getStateChange() == ItemEvent.SELECTED) {
comboBoxServerItemSelected(event);
}
});
Dimension d = jComboBoxServer.getPreferredSize();
d.width = WIDTH;
jComboBoxServer.setPreferredSize(d);
p0.add(jComboBoxServer);
jComboBoxServer.setVisible(false);
// set the first source as default
cardImageSource = WizardCardsImageSource.instance;
p0.add(Box.createVerticalStrut(5));
// Set selection ---------------------------------
jLabelSet = new JLabel();
jLabelSet.setText("Please select sets to download the images for:");
jLabelSet.setAlignmentX(Component.LEFT_ALIGNMENT);
jLabelSet.setVisible(false);
p0.add(jLabelSet);
jComboBoxSet = new JComboBox();
// jComboBoxSet.setModel(new DefaultComboBoxModel<>(getSetsForCurrentImageSource()));
jComboBoxSet.setAlignmentX(Component.LEFT_ALIGNMENT);
jComboBoxSet.addItemListener((ItemEvent event) -> {
if (event.getStateChange() == ItemEvent.SELECTED) {
comboBoxSetItemSelected(event);
comboboxSourceSelected(event);
}
});
p0.add(jComboBoxSet);
jComboBoxSet.setVisible(false);
// LANGUAGES
uiDialog.getLaunguagesCombo().setModel(new DefaultComboBoxModel(CardLanguage.values()));
uiDialog.getLaunguagesCombo().setSelectedItem(PreferencesDialog.getPrefImagesLanguage());
reloadLanguagesForSelectedSource();
p0.add(Box.createVerticalStrut(5));
// REDOWNLOAD
uiDialog.getRedownloadCheckbox().setSelected(false);
uiDialog.getRedownloadCheckbox().addItemListener(this::checkboxRedowloadChanged);
// Start
startDownloadButton = new JButton("Start download");
startDownloadButton.addActionListener(e -> {
new Thread(DownloadPictures.this).start();
startDownloadButton.setEnabled(false);
// SETS (fills after source and language select)
//uiDialog.getSetsCombo().setModel(new DefaultComboBoxModel(DownloadSources.values()));
uiDialog.getSetsCombo().addItemListener((ItemEvent event) -> {
if (event.getStateChange() == ItemEvent.SELECTED) {
comboboxSetSelected(event);
}
});
p0.add(Box.createVerticalStrut(5));
// Progress
bar = new JProgressBar(this);
p0.add(bar);
bar.setStringPainted(true);
// BUTTON START
uiDialog.getStartButton().addActionListener(e -> {
// selected language setup
if (selectedSource != null) {
if (selectedSource.isLanguagesSupport()) {
selectedSource.setCurrentLanguage((CardLanguage) uiDialog.getLaunguagesCombo().getSelectedItem());
}
}
d = bar.getPreferredSize();
d.width = WIDTH;
bar.setPreferredSize(d);
bar.setVisible(false);
// run
uiDialog.enableActionControls(false);
uiDialog.getStartButton().setEnabled(false);
new Thread(DownloadPicturesService.this).start();
});
// JOptionPane
Object[] options = {startDownloadButton, closeButton = new JButton("Cancel")};
startDownloadButton.setVisible(false);
closeButton.addActionListener(e -> dialog.setVisible(false));
closeButton.setVisible(false);
// BUTTON CANCEL (dialog and loading)
uiDialog.getCancelButton().addActionListener(e -> uiDialog.setVisible(false));
uiDialog.getStopButton().addActionListener(e -> uiDialog.setVisible(false));
dlg = new JOptionPane(p0, JOptionPane.PLAIN_MESSAGE, JOptionPane.DEFAULT_OPTION, null, options, options[1]);
dialog = this.dlg.createDialog(frame, "Downloading images");
// PROGRESS BAR
uiDialog.getProgressBar().setValue(0);
uiDialog.showDownloadControls(false);
}
public void setAllMissingCards() {
updateAndViewMessage("Get all available cards from the repository...");
List<CardInfo> cards = CardRepository.instance.findCards(new CardCriteria());
updateAndViewMessage("Check which images are missing ...");
this.allCardsMissingImage = getNeededCards(cards);
updateAndViewMessage("Check which images the current source is providing ...");
jComboBoxSet.setModel(new DefaultComboBoxModel<>(getSetsForCurrentImageSource()));
public void findMissingCards() {
updateAndViewMessage("Loading...");
this.cardsAll.clear();
this.cardsMissing.clear();
this.cardsDownloadQueue.clear();
updateCardsToDownload(jComboBoxSet.getSelectedItem().toString());
updateAndViewMessage("Loading cards list...");
this.cardsAll = Collections.synchronizedList(CardRepository.instance.findCards(new CardCriteria()));
jComboBoxServer.setVisible(true);
jLabelServer.setVisible(true);
jComboBoxSet.setVisible(true);
jLabelSet.setVisible(true);
bar.setVisible(true);
startDownloadButton.setVisible(true);
closeButton.setVisible(true);
updateAndViewMessage("Finding missing images...");
this.cardsMissing = prepareMissingCards(this.cardsAll, uiDialog.getRedownloadCheckbox().isSelected());
updateAndViewMessage("Finding available sets from selected source...");
this.uiDialog.getSetsCombo().setModel(new DefaultComboBoxModel<>(getSetsForCurrentImageSource()));
reloadCardsToDownload(this.uiDialog.getSetsCombo().getSelectedItem().toString());
this.uiDialog.showDownloadControls(true);
updateAndViewMessage("");
}
private void comboBoxServerItemSelected(ItemEvent evt) {
if (jComboBoxServer.isEnabled()) {
cardImageSource = ((DownloadSources) evt.getItem()).getSource();
// update the available sets / token comboBox
jComboBoxSet.setModel(new DefaultComboBoxModel<>(getSetsForCurrentImageSource()));
updateCardsToDownload(jComboBoxSet.getSelectedItem().toString());
private void reloadLanguagesForSelectedSource() {
this.uiDialog.showLanguagesSupport(selectedSource != null && selectedSource.isLanguagesSupport());
}
private void reloadSetsForSelectedSource() {
// update the available sets / token combobox
Object oldSelection = this.uiDialog.getSetsCombo().getSelectedItem();
this.uiDialog.getSetsCombo().setModel(new DefaultComboBoxModel<>(getSetsForCurrentImageSource()));
if (oldSelection != null) {
this.uiDialog.getSetsCombo().setSelectedItem(oldSelection);
}
reloadCardsToDownload(this.uiDialog.getSetsCombo().getSelectedItem().toString());
}
private void comboboxSourceSelected(ItemEvent evt) {
if (this.uiDialog.getSourcesCombo().isEnabled()) {
selectedSource = ((DownloadSources) evt.getItem()).getSource();
reloadSetsForSelectedSource();
reloadLanguagesForSelectedSource();
}
}
public void updateAndViewMessage(String text) {
jLabelMessage.setText(text);
if (dialog != null) {
dialog.pack();
dialog.validate();
dialog.repaint();
this.uiDialog.setGlobalInfo(text);
// auto-size on empty message (on complete)
if (text.isEmpty()) {
this.uiDialog.showDownloadControls(true);
}
}
private String getSetNameWithYear(ExpansionSet exp) {
Calendar cal = Calendar.getInstance();
cal.setTime(exp.getReleaseDate());
String year = String.valueOf(cal.get(Calendar.YEAR));
return exp.getName() + " (" + exp.getCode() + ", " + year + ")";
/*
if (!exp.getName().contains(year)) {
return exp.getName() + " (" + year + ")";
} else {
return exp.getName();
}
*/
}
private ExpansionSet findSetByNameWithYear(String name) {
return Sets.getInstance().values().stream()
.filter(exp -> getSetNameWithYear(exp).equals(name))
.findFirst()
.orElse(null);
}
private Object[] getSetsForCurrentImageSource() {
// Set the available sets to the combo box
ArrayList<String> supportedSets = cardImageSource.getSupportedSets();
ArrayList<String> supportedSets = selectedSource.getSupportedSets();
List<String> setNames = new ArrayList<>();
if (supportedSets != null) {
setNames.add(ALL_IMAGES);
setNames.add(ALL_STANDARD_IMAGES);
}
if (cardImageSource.isTokenSource()) {
// multiple sets selection
setNames.add(ALL_IMAGES);
setNames.add(ALL_MODERN_IMAGES);
setNames.add(ALL_STANDARD_IMAGES);
if (selectedSource.isTokenSource()) {
setNames.add(ALL_TOKENS);
}
if (supportedSets != null) {
for (String setCode : supportedSets) {
ExpansionSet expansionSet = Sets.findSet(setCode);
if (expansionSet != null) {
setNames.add(expansionSet.getName());
} else {
logger.warn("Source: " + cardImageSource.getSourceName() + ": Expansion set for code " + setCode + " not found in xmage sets!");
}
}
}
// single set selection
Collection<ExpansionSet> dbSets = Sets.getInstance().values();
Collection<String> comboSets = dbSets.stream()
.filter(exp -> supportedSets.contains(exp.getCode()))
.sorted(Comparator.comparing(ExpansionSet::getReleaseDate).reversed())
.map(this::getSetNameWithYear)
.collect(Collectors.toList());
setNames.addAll(comboSets);
if (setNames.isEmpty()) {
logger.error("Source " + cardImageSource.getSourceName() + " creates no selectable items.");
setNames.add("not avalable");
logger.error("Source " + selectedSource.getSourceName() + " creates no selectable items.");
setNames.add("not available");
}
return setNames.toArray(new String[0]);
}
private void updateCardsToDownload(String itemText) {
selectedSetCodes.clear();
switch (itemText) {
private void reloadCardsToDownload(String selectedItem) {
// find selected sets
selectedSets.clear();
List<String> formatSets;
List<String> sourceSets = selectedSource.getSupportedSets();
switch (selectedItem) {
case ALL_IMAGES:
if (cardImageSource.getSupportedSets() == null) {
selectedSetCodes = cardImageSource.getSupportedSets();
} else {
selectedSetCodes.addAll(cardImageSource.getSupportedSets());
}
selectedSets.addAll(selectedSource.getSupportedSets());
break;
case ALL_STANDARD_IMAGES:
List<String> standardSets = ConstructedFormats.getSetsByFormat(ConstructedFormats.STANDARD);
for (String setCode : cardImageSource.getSupportedSets()) {
if (standardSets.contains(setCode)) {
selectedSetCodes.add(setCode);
} else {
logger.debug("Set code " + setCode + " from download source " + cardImageSource.getSourceName());
}
}
formatSets = ConstructedFormats.getSetsByFormat(ConstructedFormats.STANDARD);
formatSets.stream()
.filter(sourceSets::contains)
.forEachOrdered(selectedSets::add);
break;
case ALL_MODERN_IMAGES:
formatSets = ConstructedFormats.getSetsByFormat(ConstructedFormats.MODERN);
formatSets.stream()
.filter(sourceSets::contains)
.forEachOrdered(selectedSets::add);
break;
case ALL_TOKENS:
break;
default:
int nonSetEntries = 0;
if (cardImageSource.getSupportedSets() != null) {
nonSetEntries = 2;
// selects one set
ExpansionSet selectedExp = findSetByNameWithYear(selectedItem);
if (selectedExp != null) {
selectedSets.add(selectedExp.getCode());
}
if (cardImageSource.isTokenSource()) {
nonSetEntries++;
}
selectedSetCodes.add(cardImageSource.getSupportedSets().get(jComboBoxSet.getSelectedIndex() - nonSetEntries));
break;
}
cardsToDownload.clear();
// find missing cards to download
cardsDownloadQueue.clear();
int numberTokenImagesAvailable = 0;
int numberCardImagesAvailable = 0;
for (CardDownloadData data : allCardsMissingImage) {
for (CardDownloadData data : cardsMissing) {
if (data.isToken()) {
if (cardImageSource.isTokenSource() && cardImageSource.isImageProvided(data.getSet(), data.getName())) {
if (selectedSource.isTokenSource() && selectedSource.isImageProvided(data.getSet(), data.getName())) {
numberTokenImagesAvailable++;
cardsToDownload.add(data);
cardsDownloadQueue.add(data);
} else {
//logger.warn("Source do not support token (set " + data.getSet() + ", token " + data.getName() + ")");
}
} else {
if (selectedSetCodes != null && selectedSetCodes.contains(data.getSet())) {
if (cardImageSource.isSetSupportedComplete(data.getSet()) || cardImageSource.isImageProvided(data.getSet(), data.getName())) {
if (selectedSets != null && selectedSets.contains(data.getSet())) {
if (selectedSource.isSetSupportedComplete(data.getSet()) || selectedSource.isImageProvided(data.getSet(), data.getName())) {
numberCardImagesAvailable++;
cardsToDownload.add(data);
cardsDownloadQueue.add(data);
}
}
}
@ -363,24 +351,40 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
updateProgressText(numberCardImagesAvailable, numberTokenImagesAvailable);
}
private void comboBoxSetItemSelected(ItemEvent event) {
private void comboboxSetSelected(ItemEvent event) {
// Update the cards to download related to the selected set
updateCardsToDownload(event.getItem().toString());
reloadCardsToDownload(event.getItem().toString());
}
private void checkboxRedowloadChanged(ItemEvent event) {
MageFrame.getDesktop().setCursor(new Cursor(Cursor.WAIT_CURSOR));
try {
this.cardsMissing.clear();
this.cardsMissing = prepareMissingCards(this.cardsAll, uiDialog.getRedownloadCheckbox().isSelected());
reloadCardsToDownload(uiDialog.getSetsCombo().getSelectedItem().toString());
} finally {
MageFrame.getDesktop().setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
}
private void updateProgressText(int cardCount, int tokenCount) {
missingTokens = 0;
for (CardDownloadData card : allCardsMissingImage) {
missingTokensCount = 0;
for (CardDownloadData card : cardsMissing) {
if (card.isToken()) {
missingTokens++;
missingTokensCount++;
}
}
missingCards = allCardsMissingImage.size() - missingTokens;
jLabelAllMissing.setText("Missing: " + missingCards + " card images / " + missingTokens + " token images");
missingCardsCount = cardsMissing.size() - missingTokensCount;
uiDialog.setCurrentInfo("Missing: " + missingCardsCount + " card images / " + missingTokensCount + " token images");
int imageSum = cardCount + tokenCount;
float mb = (imageSum * cardImageSource.getAverageSize()) / 1024;
bar.setString(String.format(cardIndex == imageSum ? "%d of %d (%d cards/%d tokens) image downloads finished! Please close!"
: "%d of %d (%d cards/%d tokens) image downloads finished! Please wait! [%.1f Mb]", 0, imageSum, cardCount, tokenCount, mb));
float mb = (imageSum * selectedSource.getAverageSize()) / 1024;
uiDialog.getProgressBar().setString(String.format(
cardIndex == imageSum
? "%d of %d (%d cards/%d tokens) image downloads finished! Please close!"
: "%d of %d (%d cards/%d tokens) image downloads finished! Please wait! [%.1f Mb]",
0, imageSum, cardCount, tokenCount, mb
));
}
private static String createDownloadName(CardInfo card) {
@ -388,16 +392,10 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
return className.substring(className.lastIndexOf('.') + 1);
}
private static List<CardDownloadData> getNeededCards(List<CardInfo> allCards) {
/**
* read all card names and urls
*/
private static List<CardDownloadData> prepareMissingCards(List<CardInfo> allCards, boolean redownloadMode) {
HashSet<String> ignoreUrls = SettingsManager.getIntance().getIgnoreUrls();
/**
* get filter for Standard Type 2 cards
*/
// get filter for Standard Type 2 cards
Set<String> type2SetsFilter = new HashSet<>();
List<String> constructedFormats = ConstructedFormats.getSetsByFormat(ConstructedFormats.STANDARD);
if (constructedFormats != null && !constructedFormats.isEmpty()) {
@ -406,6 +404,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
logger.warn("No formats defined. Try connecting to a server first!");
}
// prepare checking list
List<CardDownloadData> allCardsUrls = Collections.synchronizedList(new ArrayList<>());
try {
allCards.parallelStream().forEach(card -> {
@ -455,32 +454,33 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
logger.info("Card was not selected: " + card.getName());
}
});
allCardsUrls.addAll(getTokenCardUrls());
} catch (Exception e) {
logger.error(e);
}
/**
* check to see which cards we already have
*/
// find missing files
List<CardDownloadData> cardsToDownload = Collections.synchronizedList(new ArrayList<>());
allCardsUrls.parallelStream().forEach(card -> {
File file = new TFile(CardImageUtils.buildImagePathToCard(card));
logger.debug(card.getName() + " (is_token=" + card.isToken() + "). Image is here:" + file.getAbsolutePath() + " (exists=" + file.exists() + ')');
if (!file.exists()) {
logger.debug("Missing: " + file.getAbsolutePath());
// logger.info("Missing image: " + (card.isToken() ? "TOKEN " : "CARD ") + card.getSet() + "/" + card.getName() + " type: " + card.getType());
if (redownloadMode) {
// need all cards
cardsToDownload.add(card);
} else {
// need missing cards
File file = new TFile(CardImageUtils.buildImagePathToCard(card));
if (!file.exists()) {
cardsToDownload.add(card);
}
}
});
return new ArrayList<>(cardsToDownload);
return Collections.synchronizedList(new ArrayList<>(cardsToDownload));
}
public static ArrayList<CardDownloadData> getTokenCardUrls() throws RuntimeException {
ArrayList<CardDownloadData> list = new ArrayList<>();
InputStream in = DownloadPictures.class
.getClassLoader().getResourceAsStream("card-pictures-tok.txt");
InputStream in = DownloadPicturesService.class.getClassLoader().getResourceAsStream("card-pictures-tok.txt");
if (in == null) {
logger.error("resources input stream is null");
@ -545,7 +545,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
} catch (Exception ex) {
logger.error(ex);
throw new RuntimeException("DownloadPictures : readFile() error");
throw new RuntimeException("DownloadPicturesService : readFile() error");
}
return list;
}
@ -581,62 +581,62 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
Integer port = Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_PROXY_PORT, "80"));
p = new Proxy(type, new InetSocketAddress(address, port));
} catch (Exception ex) {
throw new RuntimeException("Gui_DownloadPictures : error 1 - " + ex);
throw new RuntimeException("Gui_DownloadPicturesService : error 1 - " + ex);
}
}
if (p != null) {
HashSet<String> ignoreUrls = SettingsManager.getIntance().getIgnoreUrls();
update(0, cardsToDownload.size());
logger.info("Started download of " + cardsToDownload.size() + " images from source: " + cardImageSource.getSourceName());
update(0, cardsDownloadQueue.size());
logger.info("Started download of " + cardsDownloadQueue.size() + " images"
+ " from source: " + selectedSource.getSourceName()
+ ", language: " + selectedSource.getCurrentLanguage().getCode());
int numberOfThreads = Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_CARD_IMAGES_THREADS, "10"));
ExecutorService executor = Executors.newFixedThreadPool(numberOfThreads);
for (int i = 0; i < cardsToDownload.size() && !cancel; i++) {
for (int i = 0; i < cardsDownloadQueue.size() && !this.getNeedCancel(); i++) {
try {
CardDownloadData card = cardsToDownload.get(i);
CardDownloadData card = cardsDownloadQueue.get(i);
logger.debug("Downloading image: " + card.getName() + " (" + card.getSet() + ')');
CardImageUrls urls;
if (ignoreUrls.contains(card.getSet()) || card.isToken()) {
if (!"0".equals(card.getCollectorId())) {
continue;
}
urls = cardImageSource.generateTokenUrl(card);
urls = selectedSource.generateTokenUrl(card);
} else {
urls = cardImageSource.generateURL(card);
urls = selectedSource.generateURL(card);
}
if (urls == null) {
String imageRef = cardImageSource.getNextHttpImageUrl();
String fileName = cardImageSource.getFileForHttpImage(imageRef);
String imageRef = selectedSource.getNextHttpImageUrl();
String fileName = selectedSource.getFileForHttpImage(imageRef);
if (imageRef != null && fileName != null) {
imageRef = cardImageSource.getSourceName() + imageRef;
imageRef = selectedSource.getSourceName() + imageRef;
try {
card.setToken(cardImageSource.isTokenSource());
Runnable task = new DownloadTask(card, imageRef, fileName, cardImageSource.getTotalImages());
card.setToken(selectedSource.isTokenSource());
Runnable task = new DownloadTask(card, imageRef, fileName, selectedSource.getTotalImages());
executor.execute(task);
} catch (Exception ex) {
}
} else if (cardImageSource.getTotalImages() == -1) {
logger.info("Image not available on " + cardImageSource.getSourceName() + ": " + card.getName() + " (" + card.getSet() + ')');
} else if (selectedSource.getTotalImages() == -1) {
logger.info("Image not available on " + selectedSource.getSourceName() + ": " + card.getName() + " (" + card.getSet() + ')');
synchronized (sync) {
update(cardIndex + 1, cardsToDownload.size());
update(cardIndex + 1, cardsDownloadQueue.size());
}
}
} else {
Runnable task = new DownloadTask(card, urls, cardsToDownload.size());
Runnable task = new DownloadTask(card, urls, cardsDownloadQueue.size());
executor.execute(task);
}
} catch (Exception ex) {
logger.error(ex, ex);
}
}
executor.shutdown();
while (!executor.isTerminated()) {
try {
@ -645,6 +645,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
}
}
}
try {
TVFS.umount();
} catch (FsSyncException e) {
@ -653,11 +654,15 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
} finally {
//
}
closeButton.setText("Close");
updateCardsToDownload(jComboBoxSet.getSelectedItem().toString());
// stop
reloadCardsToDownload(uiDialog.getSetsCombo().getSelectedItem().toString());
// reset images cache
ImageCache.clearCache();
}
static String convertStreamToString(java.io.InputStream is) {
static String convertStreamToString(InputStream is) {
java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A");
return s.hasNext() ? s.next() : "";
}
@ -670,10 +675,6 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
private final String actualFilename;
private final boolean useSpecifiedPaths;
DownloadTask(CardDownloadData card, String baseUrl, int count) {
this(card, new CardImageUrls(baseUrl, null), count);
}
DownloadTask(CardDownloadData card, CardImageUrls urls, int count) {
this.card = card;
this.urls = urls;
@ -692,7 +693,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
@Override
public void run() {
if (cancel) {
if (DownloadPicturesService.getInstance().getNeedCancel()) {
synchronized (sync) {
update(cardIndex + 1, count);
}
@ -736,20 +737,23 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
}
// FILE already exists (in zip or in dir)
// don't use, images can be re-downloaded
/*
if (destFile.exists()) {
synchronized (sync) {
update(cardIndex + 1, count);
}
return;
}
*/
// zip can't be read
// check zip access
TFile testArchive = destFile.getTopLevelArchive();
if (testArchive != null && testArchive.exists()) {
try {
testArchive.list();
} catch (Exception e) {
logger.error("Error reading archive, may be it was corrapted. Try to delete it: " + testArchive.toString());
logger.error("Error reading archive, it's can be corrupted. Try to delete it: " + testArchive.toString());
synchronized (sync) {
update(cardIndex + 1, count);
@ -773,12 +777,12 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
URL url = new URL(currentUrl);
// on download cancel need to stop
if (cancel) {
if (DownloadPicturesService.getInstance().getNeedCancel()) {
return;
}
// download
cardImageSource.doPause(url.getPath());
selectedSource.doPause(url.getPath());
httpConn = url.openConnection(p);
httpConn.setRequestProperty("User-Agent", "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2");
httpConn.connect();
@ -819,7 +823,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
int len;
while ((len = in.read(buf)) != -1) {
// user cancelled
if (cancel) {
if (DownloadPicturesService.getInstance().getNeedCancel()) {
// stop download, save current state and exit
TFile archive = destFile.getTopLevelArchive();
///* not need to unmout/close - it's auto action
@ -881,34 +885,38 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
}
}
private void update(int card, int count) {
this.cardIndex = card;
private void update(int lastCardIndex, int needDownloadCount) {
this.cardIndex = lastCardIndex;
if (cardIndex < count) {
float mb = ((count - card) * cardImageSource.getAverageSize()) / 1024;
bar.setString(String.format("%d of %d image downloads finished! Please wait! [%.1f Mb]",
card, count, mb));
if (cardIndex < needDownloadCount) {
// downloading
float mb = ((needDownloadCount - lastCardIndex) * selectedSource.getAverageSize()) / 1024;
uiDialog.getProgressBar().setString(String.format("%d of %d image downloads finished! Please wait! [%.1f Mb]",
lastCardIndex, needDownloadCount, mb));
} else {
List<CardDownloadData> remainingCards = Collections.synchronizedList(new ArrayList<>());
DownloadPictures.this.allCardsMissingImage.parallelStream().forEach(cardDownloadData -> {
// finished
List<CardDownloadData> downloadedCards = Collections.synchronizedList(new ArrayList<>());
DownloadPicturesService.this.cardsMissing.parallelStream().forEach(cardDownloadData -> {
TFile file = new TFile(CardImageUtils.buildImagePathToCard(cardDownloadData));
if (!file.exists()) {
remainingCards.add(cardDownloadData);
if (file.exists()) {
downloadedCards.add(cardDownloadData);
}
});
// remove the cards not downloaded to get the siccessfull downloaded cards
DownloadPictures.this.cardsToDownload.removeAll(remainingCards);
DownloadPictures.this.allCardsMissingImage.removeAll(DownloadPictures.this.cardsToDownload);
// remove all downloaded cards, missing must be remains
this.cardsDownloadQueue.removeAll(downloadedCards);
this.cardsMissing.removeAll(downloadedCards);
count = remainingCards.size();
if (count == 0) {
bar.setString("0 images remaining! Please close!");
if (this.cardsDownloadQueue.size() == 0) {
// stop download
uiDialog.getProgressBar().setString("0 images remaining. Please close.");
} else {
// bar.setString(String.format("%d cards remaining! Please choose another source!", count));
startDownloadButton.setEnabled(true);
// try download again
}
this.uiDialog.getRedownloadCheckbox().setSelected(false);
uiDialog.enableActionControls(true);
uiDialog.getStartButton().setEnabled(true);
}
}
@ -916,22 +924,21 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
}
class LoadMissingCardData implements Runnable {
class LoadMissingCardDataNew implements Runnable {
private static DownloadPictures downloadPictures;
private static DownloadPicturesService downloadPicturesService;
public LoadMissingCardData(DownloadPictures downloadPictures) {
LoadMissingCardData.downloadPictures = downloadPictures;
public LoadMissingCardDataNew(DownloadPicturesService downloadPicturesService) {
this.downloadPicturesService = downloadPicturesService;
}
@Override
public void run() {
downloadPictures.setAllMissingCards();
downloadPicturesService.findMissingCards();
}
public static void main() {
(new Thread(new LoadMissingCardData(downloadPictures))).start();
(new Thread(new LoadMissingCardDataNew(downloadPicturesService))).start();
}
}

View file

@ -3,15 +3,6 @@ package org.mage.plugins.card.images;
import com.google.common.base.Function;
import com.google.common.collect.ComputationException;
import com.google.common.collect.MapMaker;
import java.awt.*;
import java.awt.geom.RoundRectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.imageio.ImageIO;
import mage.client.constants.Constants;
import mage.client.dialog.PreferencesDialog;
import mage.client.util.TransformedImageCache;
@ -23,13 +14,23 @@ import org.apache.log4j.Logger;
import org.mage.plugins.card.dl.sources.DirectLinksForDownload;
import org.mage.plugins.card.utils.CardImageUtils;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.geom.RoundRectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* This class stores ALL card images in a cache with soft values. this means
* that the images may be garbage collected when they are not needed any more,
* but will be kept as long as possible.
*
* <p>
* Key format: "[cardname]#[setname]#[type]#[collectorID]#[param]"
*
* <p>
* where param is:
* <ul>
* <li>size of image</li>
@ -228,6 +229,10 @@ public final class ImageCache {
});
}
public static void clearCache() {
IMAGE_CACHE.clear();
}
public static String getFilePath(CardView card, int width) {
String key = getKey(card, card.getName(), Integer.toString(width));
boolean usesVariousArt = false;
@ -389,7 +394,7 @@ public final class ImageCache {
return getImage(getKey(card, card.getName(), ""));
}
// public static BufferedImage getImageFaceOriginal(CardView card) {
// public static BufferedImage getImageFaceOriginal(CardView card) {
// return getFaceImage(getFaceKey(card, card.getName(), card.getExpansionSetCode()));
// }
public static BufferedImage getImageOriginalAlternateName(CardView card) {
@ -472,6 +477,7 @@ public final class ImageCache {
// return alternateName + "#" + card.getExpansionSetCode() + "#" +card.getType()+ "#" + card.getCardNumber() + "#"
// + (card.getTokenSetCode() == null ? "":card.getTokenSetCode());
// }
/**
* Load image from file
*

View file

@ -187,6 +187,7 @@
|Generate|TOK:ALL|Graveborn|||SekKuarDeathkeeperGravebornToken|
|Generate|TOK:ALL|Hippo|||HippoToken|
|Generate|TOK:ALL|Soldier|||SoldierToken|
|Generate|TOK:ALL|Starfish|||StarfishToken|
|Generate|TOK:ALL|Zombie|||ZombieToken|
|Generate|TOK:APC|Angel|||HauntedAngelToken|
|Generate|TOK:APC|Cat|||PenumbraBobcatToken|

View file

@ -1,5 +1,7 @@
package mage.utils;
import mage.util.JarVersion;
import java.io.Serializable;
/**

View file

@ -13,21 +13,12 @@ public class DraftClientMessage implements Serializable {
private DraftView draftView;
private DraftPickView draftPickView;
private String message;
public DraftClientMessage(DraftView draftView) {
public DraftClientMessage(DraftView draftView, DraftPickView draftPickView) {
this.draftView = draftView;
}
public DraftClientMessage(DraftPickView draftPickView) {
this.draftPickView = draftPickView;
}
public DraftClientMessage(DraftView draftView, String message) {
this.message = message;
this.draftView = draftView;
}
public DraftPickView getDraftPickView() {
return draftPickView;
}

View file

@ -7,6 +7,7 @@ import java.util.ArrayList;
import java.util.List;
import mage.cards.ExpansionSet;
import mage.game.draft.Draft;
import mage.game.draft.DraftCube;
import mage.game.draft.DraftPlayer;
/**
@ -17,6 +18,7 @@ public class DraftView implements Serializable {
private static final long serialVersionUID = 1L;
private final List<String> sets = new ArrayList<>();
private final List<String> setCodes = new ArrayList<>();
private final int boosterNum;
private final int cardNum;
private final List<String> players = new ArrayList<>();
@ -24,11 +26,14 @@ public class DraftView implements Serializable {
public DraftView(Draft draft) {
if (draft.getDraftCube() != null) {
for (int i = 0; i < draft.getNumberBoosters(); i++) {
sets.add(draft.getDraftCube().getName());
DraftCube cube = draft.getDraftCube();
sets.add(cube.getName());
setCodes.add(cube.getCode());
}
} else {
for (ExpansionSet set: draft.getSets()) {
sets.add(set.getName());
setCodes.add(set.getCode());
}
}
this.boosterNum = draft.getBoosterNum();
@ -42,6 +47,10 @@ public class DraftView implements Serializable {
return sets;
}
public List<String> getSetCodes() {
return setCodes;
}
public List<String> getPlayers() {
return players;
}

View file

@ -43,7 +43,7 @@ public class TournamentGameView implements Serializable {
String duelingTime = "";
if (game.hasEnded()) {
if (game.getEndTime() != null) {
if (game.getEndTime() != null && game.getStartTime() != null) {
duelingTime = " (" + DateFormat.getDuration((game.getEndTime().getTime() - game.getStartTime().getTime())/1000) + ')';
}
this.state = "Finished" + duelingTime;

View file

@ -4,7 +4,6 @@ import mage.cards.ExpansionSet;
import mage.cards.Sets;
import mage.cards.decks.Constructed;
import mage.cards.decks.Deck;
import mage.constants.SetType;
import java.util.HashMap;
import java.util.Map;
@ -82,7 +81,7 @@ public class AusHighlander extends Constructed {
public AusHighlander() {
this("Australian Highlander");
for (ExpansionSet set : Sets.getInstance().values()) {
if (set.getSetType() != SetType.CUSTOM_SET) {
if (set.isEternalLegal()) {
setCodes.add(set.getCode());
}
}

View file

@ -4,7 +4,6 @@ import mage.cards.ExpansionSet;
import mage.cards.Sets;
import mage.cards.decks.Constructed;
import mage.cards.decks.Deck;
import mage.constants.SetType;
import java.util.HashMap;
import java.util.Map;
@ -64,7 +63,7 @@ public class CanadianHighlander extends Constructed {
public CanadianHighlander() {
this("Canadian Highlander");
for (ExpansionSet set : Sets.getInstance().values()) {
if (set.getSetType() != SetType.CUSTOM_SET) {
if (set.isEternalLegal()) {
setCodes.add(set.getCode());
}
}

View file

@ -1,6 +1,5 @@
package mage.deck;
import java.util.*;
import mage.ObjectColor;
import mage.abilities.Ability;
import mage.abilities.common.CanBeYourCommanderAbility;
@ -12,11 +11,11 @@ import mage.cards.ExpansionSet;
import mage.cards.Sets;
import mage.cards.decks.Constructed;
import mage.cards.decks.Deck;
import mage.constants.SetType;
import mage.filter.FilterMana;
import java.util.*;
/**
*
* @author Plopman
*/
public class Commander extends Constructed {
@ -27,7 +26,7 @@ public class Commander extends Constructed {
public Commander() {
this("Commander");
for (ExpansionSet set : Sets.getInstance().values()) {
if (set.getSetType() != SetType.CUSTOM_SET) {
if (set.isEternalLegal()) {
setCodes.add(set.getCode());
}
}

View file

@ -4,7 +4,6 @@ package mage.deck;
import mage.cards.ExpansionSet;
import mage.cards.Sets;
import mage.cards.decks.Constructed;
import mage.constants.SetType;
/**
* This class implements the new casual format "Eternal", which is legacy with
@ -18,7 +17,7 @@ public class Eternal extends Constructed {
public Eternal() {
super("Constructed - Eternal");
for (ExpansionSet set : Sets.getInstance().values()) {
if (set.getSetType() != SetType.CUSTOM_SET) {
if (set.isEternalLegal()) {
setCodes.add(set.getCode());
}
}

View file

@ -26,6 +26,9 @@ public class FreeformCommander extends Constructed {
for (ExpansionSet set : Sets.getInstance().values()) {
setCodes.add(set.getCode());
}
// no banned cards
this.banned.clear();
}
public FreeformCommander(String name) {

View file

@ -14,7 +14,7 @@ public class Legacy extends Constructed {
public Legacy() {
super("Constructed - Legacy");
for (ExpansionSet set : Sets.getInstance().values()) {
if (set.getSetType() != SetType.CUSTOM_SET) {
if (set.isEternalLegal()) {
setCodes.add(set.getCode());
}
}

View file

@ -9,10 +9,8 @@ import mage.cards.ExpansionSet;
import mage.cards.Sets;
import mage.cards.decks.Constructed;
import mage.constants.Rarity;
import mage.constants.SetType;
/**
*
* @author LevelX2
*/
public class Pauper extends Constructed {
@ -22,7 +20,7 @@ public class Pauper extends Constructed {
//TODO: Add only Magic Online sets for pauper
for (ExpansionSet set : Sets.getInstance().values()) {
if (set.getSetType() != SetType.CUSTOM_SET) {
if (set.isEternalLegal()) {
setCodes.add(set.getCode());
}
}

View file

@ -1,8 +1,6 @@
package mage.deck;
import java.util.*;
import java.util.Map.Entry;
import mage.abilities.Ability;
import mage.abilities.common.CanBeYourCommanderAbility;
import mage.abilities.keyword.PartnerAbility;
@ -12,11 +10,12 @@ import mage.cards.ExpansionSet;
import mage.cards.Sets;
import mage.cards.decks.Constructed;
import mage.cards.decks.Deck;
import mage.constants.SetType;
import mage.filter.FilterMana;
import java.util.*;
import java.util.Map.Entry;
/**
*
* @author spjspj
*/
public class PennyDreadfulCommander extends Constructed {
@ -28,7 +27,7 @@ public class PennyDreadfulCommander extends Constructed {
public PennyDreadfulCommander() {
this("Penny Dreadful Commander");
for (ExpansionSet set : Sets.getInstance().values()) {
if (set.getSetType() != SetType.CUSTOM_SET) {
if (set.isEternalLegal()) {
setCodes.add(set.getCode());
}
}

View file

@ -1,10 +1,6 @@
package mage.deck;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import mage.abilities.common.CanBeYourCommanderAbility;
import mage.cards.Card;
import mage.cards.ExpansionSet;
@ -12,12 +8,15 @@ import mage.cards.Sets;
import mage.cards.SplitCard;
import mage.cards.decks.Constructed;
import mage.cards.decks.Deck;
import mage.constants.SetType;
import mage.filter.FilterMana;
import mage.game.GameTinyLeadersImpl;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
*
* @author JRHerlehy
*/
public class TinyLeaders extends Constructed {
@ -27,7 +26,7 @@ public class TinyLeaders extends Constructed {
public TinyLeaders() {
this("Tiny Leaders");
for (ExpansionSet set : Sets.getInstance().values()) {
if (set.getSetType() != SetType.CUSTOM_SET) {
if (set.isEternalLegal()) {
setCodes.add(set.getCode());
}
}
@ -85,7 +84,6 @@ public class TinyLeaders extends Constructed {
}
/**
*
* @param deck
* @return - True if deck is valid
*/
@ -212,9 +210,8 @@ public class TinyLeaders extends Constructed {
}
/**
*
* @param commander FilterMana object with Color Identity of Commander set
* @param card Card to validate
* @param card Card to validate
* @return True if card has a valid color identity
*/
public boolean cardHasValideColor(FilterMana commander, Card card) {

View file

@ -4,10 +4,8 @@ package mage.deck;
import mage.cards.ExpansionSet;
import mage.cards.Sets;
import mage.cards.decks.Constructed;
import mage.constants.SetType;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class Vintage extends Constructed {
@ -15,7 +13,7 @@ public class Vintage extends Constructed {
public Vintage() {
super("Constructed - Vintage");
for (ExpansionSet set : Sets.getInstance().values()) {
if (set.getSetType() != SetType.CUSTOM_SET) {
if (set.isEternalLegal()) {
setCodes.add(set.getCode());
}
}

View file

@ -111,9 +111,8 @@ public class ComputerPlayer7 extends ComputerPlayer6 {
Game sim = createSimulation(game);
SimulationNode2.resetCount();
root = new SimulationNode2(null, sim, maxDepth, playerId);
addActionsTimed();
if (root.children != null
&& !root.children.isEmpty()) {
addActionsTimed(); // TODO: root can be null again after addActionsTimed O_o need to research (it's a CPU AI problem?)
if (root != null && root.children != null && !root.children.isEmpty()) {
logger.trace("After add actions timed: root.children.size = " + root.children.size());
root = root.children.get(0);
// prevent repeating always the same action with no cost

View file

@ -1,31 +1,26 @@
package mage.player.ai.utils;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.DamageTargetEffect;
import mage.abilities.effects.common.*;
import mage.abilities.effects.common.continuous.BoostEnchantedEffect;
import mage.abilities.effects.common.continuous.BoostTargetEffect;
import mage.cards.Card;
import mage.constants.ColoredManaSymbol;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.SubType;
import mage.target.Target;
import mage.target.TargetPermanent;
import mage.target.common.TargetAttackingCreature;
import mage.target.common.TargetAttackingOrBlockingCreature;
import mage.target.common.TargetCreaturePermanent;
import mage.target.common.TargetPlayerOrPlaneswalker;
import org.apache.log4j.Logger;
import java.io.InputStream;
import java.util.*;
import mage.abilities.Mode;
import mage.abilities.effects.common.DamageWithPowerTargetEffect;
import mage.abilities.effects.common.DestroyTargetEffect;
import mage.abilities.effects.common.ExileTargetEffect;
import mage.abilities.effects.common.ExileUntilSourceLeavesEffect;
import mage.abilities.effects.common.FightTargetsEffect;
import mage.abilities.effects.common.continuous.BoostEnchantedEffect;
import mage.abilities.effects.common.continuous.BoostTargetEffect;
import mage.constants.Rarity;
import mage.constants.SubType;
import mage.target.TargetPermanent;
import mage.target.common.TargetAttackingCreature;
import mage.target.common.TargetAttackingOrBlockingCreature;
import mage.target.common.TargetPlayerOrPlaneswalker;
/**
* Class responsible for reading ratings from resources and rating given cards.
@ -43,13 +38,12 @@ public final class RateCard {
* Rating that is given for new cards.
* Ratings are in [1,10] range, so setting it high will make new cards appear more often.
* nowadays, cards that are more rare are more powerful, lets trust that and play the shiny cards.
*
*/
private static final int DEFAULT_NOT_RATED_CARD_RATING = 40;
private static final int DEFAULT_NOT_RATED_UNCOMMON_RATING = 60;
private static final int DEFAULT_NOT_RATED_RARE_RATING = 75;
private static final int DEFAULT_NOT_RATED_MYTHIC_RATING = 90;
private static String RATINGS_DIR = "/ratings/";
private static String RATINGS_SET_LIST = RATINGS_DIR + "setsWithRatings.csv";
@ -100,54 +94,54 @@ public final class RateCard {
if (card.isEnchantment() || card.isInstant() || card.isSorcery()) {
for (Ability ability : card.getAbilities()) {
for (Effect effect : ability.getEffects()) {
if (isEffectRemoval(card, ability, effect) == 1){
for (Effect effect : ability.getEffects()) {
if (isEffectRemoval(card, ability, effect) == 1) {
return 1;
}
}
for (Mode mode: ability.getModes().values() ){
for (Effect effect: mode.getEffects()){
if (isEffectRemoval(card, ability, effect) == 1){
for (Mode mode : ability.getModes().values()) {
for (Effect effect : mode.getEffects()) {
if (isEffectRemoval(card, ability, effect) == 1) {
return 1;
}
}
}
}
}
return 0;
}
private static int isEffectRemoval(Card card, Ability ability, Effect effect){
private static int isEffectRemoval(Card card, Ability ability, Effect effect) {
if (effect.getOutcome() == Outcome.Removal) {
log.debug("Found removal: " + card.getName());
return 1;
}
//static List<Effect> removalEffects =[BoostTargetEffect,BoostEnchantedEffect]
if (effect instanceof BoostTargetEffect || effect instanceof BoostEnchantedEffect){
if (effect instanceof BoostTargetEffect || effect instanceof BoostEnchantedEffect) {
String text = effect.getText(null);
if (text.contains("/-")){
if (text.contains("/-")) {
// toughness reducer, aka removal
return 1;
}
}
if (effect instanceof FightTargetsEffect || effect instanceof DamageWithPowerTargetEffect){
if (effect instanceof FightTargetsEffect || effect instanceof DamageWithPowerTargetEffect) {
return 1;
}
if (effect.getOutcome() == Outcome.Damage || effect instanceof DamageTargetEffect) {
for (Target target : ability.getTargets()) {
if (!(target instanceof TargetPlayerOrPlaneswalker)){
if (!(target instanceof TargetPlayerOrPlaneswalker)) {
log.debug("Found damage dealer: " + card.getName());
return 1;
}
}
}
if (effect.getOutcome() == Outcome.DestroyPermanent ||
effect instanceof DestroyTargetEffect ||
effect instanceof ExileTargetEffect ||
if (effect.getOutcome() == Outcome.DestroyPermanent ||
effect instanceof DestroyTargetEffect ||
effect instanceof ExileTargetEffect ||
effect instanceof ExileUntilSourceLeavesEffect) {
for (Target target : ability.getTargets()) {
if (target instanceof TargetCreaturePermanent ||
if (target instanceof TargetCreaturePermanent ||
target instanceof TargetAttackingCreature ||
target instanceof TargetAttackingOrBlockingCreature ||
target instanceof TargetPermanent) {
@ -175,37 +169,37 @@ public final class RateCard {
}
Rarity r = card.getRarity();
if (Rarity.COMMON == r){
if (Rarity.COMMON == r) {
return DEFAULT_NOT_RATED_CARD_RATING;
}else if (Rarity.UNCOMMON == r){
} else if (Rarity.UNCOMMON == r) {
return DEFAULT_NOT_RATED_UNCOMMON_RATING;
}else if (Rarity.RARE == r){
} else if (Rarity.RARE == r) {
return DEFAULT_NOT_RATED_RARE_RATING;
}else if (Rarity.MYTHIC == r){
} else if (Rarity.MYTHIC == r) {
return DEFAULT_NOT_RATED_MYTHIC_RATING;
}
return DEFAULT_NOT_RATED_CARD_RATING;
}
/**
* reads the list of sets that have ratings csv files
* populates the setsWithRatingsToBeLoaded
*/
private synchronized static void readRatingSetList(){
private synchronized static void readRatingSetList() {
try {
if (setsWithRatingsToBeLoaded == null){
if (setsWithRatingsToBeLoaded == null) {
setsWithRatingsToBeLoaded = new LinkedList<>();
InputStream is = RateCard.class.getResourceAsStream(RATINGS_SET_LIST);
Scanner scanner = new Scanner(is);
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
if (!line.substring(0,1).equals("#")){
setsWithRatingsToBeLoaded.add(line);
}
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
if (!line.substring(0, 1).equals("#")) {
setsWithRatingsToBeLoaded.add(line);
}
}
}
}catch (Exception e) {
log.info("failed to read ratings set list file: " + RATINGS_SET_LIST );
} catch (Exception e) {
log.info("failed to read ratings set list file: " + RATINGS_SET_LIST);
e.printStackTrace();
}
}
@ -217,15 +211,16 @@ public final class RateCard {
if (ratings == null) {
ratings = new HashMap<>();
}
if (setsWithRatingsToBeLoaded.contains(expCode)){
log.info("reading draftbot ratings for the set" + expCode);
readFromFile(RATINGS_DIR + expCode + ".csv");
if (setsWithRatingsToBeLoaded.contains(expCode)) {
log.info("reading draftbot ratings for the set " + expCode);
readFromFile(RATINGS_DIR + expCode + ".csv");
setsWithRatingsToBeLoaded.remove(expCode);
}
}
/**
* reads ratings from the file
*/
* reads ratings from the file
*/
private synchronized static void readFromFile(String path) {
Integer min = Integer.MAX_VALUE, max = 0;
Map<String, Integer> thisFileRatings = new HashMap<>();
@ -248,21 +243,21 @@ public final class RateCard {
}
}
// normalize for the file to [1..100]
for (String name: thisFileRatings.keySet()){
for (String name : thisFileRatings.keySet()) {
int r = thisFileRatings.get(name);
int newrating = (int)(100.0f * (r - min) / (max - min));
if (!ratings.containsKey(name) ||
(ratings.containsKey(name) && newrating > ratings.get(name)) ){
ratings.put(name, newrating);
int newrating = (int) (100.0f * (r - min) / (max - min));
if (!ratings.containsKey(name) ||
(ratings.containsKey(name) && newrating > ratings.get(name))) {
ratings.put(name, newrating);
}
}
} catch (Exception e) {
log.info("failed to read ratings file: " + path );
log.info("failed to read ratings file: " + path);
e.printStackTrace();
}
}
private static final int SINGLE_PENALTY[] = {0, 1, 1, 3, 6, 9};
private static final int[] SINGLE_PENALTY = {0, 1, 1, 3, 6, 9};
private static final int MULTICOLOR_BONUS = 15;
/**
@ -271,7 +266,6 @@ public final class RateCard {
* If allowed colors are not chosen, then score based on converted cost is returned with penalty for heavy colored cards.
* gives bonus to multicolor cards that fit within allowed colors and if allowed colors is <5
*
*
* @param card
* @param allowedColors Can be null.
* @return
@ -282,7 +276,7 @@ public final class RateCard {
int colorPenalty = 0;
for (String symbol : card.getManaCost().getSymbols()) {
if (isColoredMana(symbol)) {
colorPenalty++;
colorPenalty++;
}
}
return 2 * (converted - colorPenalty + 1);
@ -314,22 +308,22 @@ public final class RateCard {
maxSingleCount = 5;
int rate = 2 * converted + 3 * (10 - SINGLE_PENALTY[maxSingleCount]);
if( singleCount.size() > 1 && singleCount.size() < 5){
if (singleCount.size() > 1 && singleCount.size() < 5) {
rate += MULTICOLOR_BONUS;
}
return rate;
}
/**
* Determines whether mana symbol is color.
*
* @param symbol
* @param symbol
* @return
*/
public static boolean isColoredMana(String symbol) {
String s = symbol;
if (s.length() > 1) {
s = s.replace("{","").replace("}","");
s = s.replace("{", "").replace("}", "");
}
if (s.length() > 1) {
return false;
@ -339,6 +333,7 @@ public final class RateCard {
/**
* Return number of color mana symbols in manacost.
*
* @param card
* @return
*/
@ -354,6 +349,7 @@ public final class RateCard {
/**
* Return number of different color mana symbols in manacost.
*
* @param card
* @return
*/

View file

@ -0,0 +1,556 @@
package mage.tournament.cubes;
import mage.game.draft.DraftCube;
/**
*
* @author themogwi
*/
public class VintageCubeDecember2018 extends DraftCube {
public VintageCubeDecember2018() {
super("MTGO Vintage Cube December 2018");
cubeCards.add(new DraftCube.CardIdentity("Dauntless Bodyguard", ""));
cubeCards.add(new DraftCube.CardIdentity("Kytheon, Hero of Akros", ""));
cubeCards.add(new DraftCube.CardIdentity("Mother of Runes", ""));
cubeCards.add(new DraftCube.CardIdentity("Student of Warfare", ""));
cubeCards.add(new DraftCube.CardIdentity("Adanto Vanguard", ""));
cubeCards.add(new DraftCube.CardIdentity("Leonin Relic-Warder", ""));
cubeCards.add(new DraftCube.CardIdentity("Remorseful Cleric", ""));
cubeCards.add(new DraftCube.CardIdentity("Selfless Spirit", ""));
cubeCards.add(new DraftCube.CardIdentity("Soulfire Grand Master", ""));
cubeCards.add(new DraftCube.CardIdentity("Stoneforge Mystic", ""));
cubeCards.add(new DraftCube.CardIdentity("Thalia, Guardian of Thraben", ""));
cubeCards.add(new DraftCube.CardIdentity("Wall of Omens", ""));
cubeCards.add(new DraftCube.CardIdentity("Banisher Priest", ""));
cubeCards.add(new DraftCube.CardIdentity("Blade Splicer", ""));
cubeCards.add(new DraftCube.CardIdentity("Brightling", ""));
cubeCards.add(new DraftCube.CardIdentity("Brimaz, King of Oreskos", ""));
cubeCards.add(new DraftCube.CardIdentity("Flickerwisp", ""));
cubeCards.add(new DraftCube.CardIdentity("Mirran Crusader", ""));
cubeCards.add(new DraftCube.CardIdentity("Monastery Mentor", ""));
cubeCards.add(new DraftCube.CardIdentity("Recruiter of the Guard", ""));
cubeCards.add(new DraftCube.CardIdentity("Silverblade Paladin", ""));
cubeCards.add(new DraftCube.CardIdentity("Emeria Angel", ""));
cubeCards.add(new DraftCube.CardIdentity("Hero of Bladehold", ""));
cubeCards.add(new DraftCube.CardIdentity("Linvala, Keeper of Silence", ""));
cubeCards.add(new DraftCube.CardIdentity("Palace Jailer", ""));
cubeCards.add(new DraftCube.CardIdentity("Restoration Angel", ""));
cubeCards.add(new DraftCube.CardIdentity("Angel of Invention", ""));
cubeCards.add(new DraftCube.CardIdentity("Angel of Sanctions", ""));
cubeCards.add(new DraftCube.CardIdentity("Archangel Avacyn", ""));
cubeCards.add(new DraftCube.CardIdentity("Baneslayer Angel", ""));
cubeCards.add(new DraftCube.CardIdentity("Lyra Dawnbringer", ""));
cubeCards.add(new DraftCube.CardIdentity("Reveillark", ""));
cubeCards.add(new DraftCube.CardIdentity("Sun Titan", ""));
cubeCards.add(new DraftCube.CardIdentity("Elesh Norn, Grand Cenobite", ""));
cubeCards.add(new DraftCube.CardIdentity("Avacyn, Angel of Hope", ""));
cubeCards.add(new DraftCube.CardIdentity("Iona, Shield of Emeria", ""));
cubeCards.add(new DraftCube.CardIdentity("Gideon of the Trials", ""));
cubeCards.add(new DraftCube.CardIdentity("Elspeth, Knight-Errant", ""));
cubeCards.add(new DraftCube.CardIdentity("Gideon, Ally of Zendikar", ""));
cubeCards.add(new DraftCube.CardIdentity("Gideon Jura", ""));
cubeCards.add(new DraftCube.CardIdentity("Elspeth, Sun's Champion", ""));
cubeCards.add(new DraftCube.CardIdentity("Porcelain Legionnaire", ""));
cubeCards.add(new DraftCube.CardIdentity("Condemn", ""));
cubeCards.add(new DraftCube.CardIdentity("Enlightened Tutor", ""));
cubeCards.add(new DraftCube.CardIdentity("Mana Tithe", ""));
cubeCards.add(new DraftCube.CardIdentity("Path to Exile", ""));
cubeCards.add(new DraftCube.CardIdentity("Swords to Plowshares", ""));
cubeCards.add(new DraftCube.CardIdentity("Disenchant", ""));
cubeCards.add(new DraftCube.CardIdentity("Unexpectedly Absent", ""));
cubeCards.add(new DraftCube.CardIdentity("Balance", ""));
cubeCards.add(new DraftCube.CardIdentity("Council's Judgment", ""));
cubeCards.add(new DraftCube.CardIdentity("Lingering Souls", ""));
cubeCards.add(new DraftCube.CardIdentity("Spectral Procession", ""));
cubeCards.add(new DraftCube.CardIdentity("Timely Reinforcements", ""));
cubeCards.add(new DraftCube.CardIdentity("Armageddon", ""));
cubeCards.add(new DraftCube.CardIdentity("Day of Judgment", ""));
cubeCards.add(new DraftCube.CardIdentity("Ravages of War", ""));
cubeCards.add(new DraftCube.CardIdentity("Wrath of God", ""));
cubeCards.add(new DraftCube.CardIdentity("Terminus", ""));
cubeCards.add(new DraftCube.CardIdentity("Land Tax", ""));
cubeCards.add(new DraftCube.CardIdentity("Legion's Landing", ""));
cubeCards.add(new DraftCube.CardIdentity("Honor of the Pure", ""));
cubeCards.add(new DraftCube.CardIdentity("Banishing Light", ""));
cubeCards.add(new DraftCube.CardIdentity("History of Benalia", ""));
cubeCards.add(new DraftCube.CardIdentity("Oblivion Ring", ""));
cubeCards.add(new DraftCube.CardIdentity("Faith's Fetters", ""));
cubeCards.add(new DraftCube.CardIdentity("Moat", ""));
cubeCards.add(new DraftCube.CardIdentity("Parallax Wave", ""));
cubeCards.add(new DraftCube.CardIdentity("Spear of Heliod", ""));
cubeCards.add(new DraftCube.CardIdentity("Karakas", ""));
cubeCards.add(new DraftCube.CardIdentity("Baral, Chief of Compliance", ""));
cubeCards.add(new DraftCube.CardIdentity("Jace, Vryn's Prodigy", ""));
cubeCards.add(new DraftCube.CardIdentity("Looter il-Kor", ""));
cubeCards.add(new DraftCube.CardIdentity("Phantasmal Image", ""));
cubeCards.add(new DraftCube.CardIdentity("Snapcaster Mage", ""));
cubeCards.add(new DraftCube.CardIdentity("Thing in the Ice", ""));
cubeCards.add(new DraftCube.CardIdentity("Arcane Artisan", ""));
cubeCards.add(new DraftCube.CardIdentity("Deceiver Exarch", ""));
cubeCards.add(new DraftCube.CardIdentity("Pestermite", ""));
cubeCards.add(new DraftCube.CardIdentity("Trinket Mage", ""));
cubeCards.add(new DraftCube.CardIdentity("True-Name Nemesis", ""));
cubeCards.add(new DraftCube.CardIdentity("Vendilion Clique", ""));
cubeCards.add(new DraftCube.CardIdentity("Glen Elendra Archmage", ""));
cubeCards.add(new DraftCube.CardIdentity("Sower of Temptation", ""));
cubeCards.add(new DraftCube.CardIdentity("Venser, Shaper Savant", ""));
cubeCards.add(new DraftCube.CardIdentity("Mulldrifter", ""));
cubeCards.add(new DraftCube.CardIdentity("Riftwing Cloudskate", ""));
cubeCards.add(new DraftCube.CardIdentity("Consecrated Sphinx", ""));
cubeCards.add(new DraftCube.CardIdentity("Frost Titan", ""));
cubeCards.add(new DraftCube.CardIdentity("Palinchron", ""));
cubeCards.add(new DraftCube.CardIdentity("Jace Beleren", ""));
cubeCards.add(new DraftCube.CardIdentity("Jace, Architect of Thought", ""));
cubeCards.add(new DraftCube.CardIdentity("Jace, the Mind Sculptor", ""));
cubeCards.add(new DraftCube.CardIdentity("Tamiyo, the Moon Sage", ""));
cubeCards.add(new DraftCube.CardIdentity("Tezzeret the Seeker", ""));
cubeCards.add(new DraftCube.CardIdentity("Phyrexian Metamorph", ""));
cubeCards.add(new DraftCube.CardIdentity("Torrential Gearhulk", ""));
cubeCards.add(new DraftCube.CardIdentity("Inkwell Leviathan", ""));
cubeCards.add(new DraftCube.CardIdentity("Ancestral Recall", ""));
cubeCards.add(new DraftCube.CardIdentity("Brainstorm", ""));
cubeCards.add(new DraftCube.CardIdentity("High Tide", ""));
cubeCards.add(new DraftCube.CardIdentity("Mystical Tutor", ""));
cubeCards.add(new DraftCube.CardIdentity("Spell Pierce", ""));
cubeCards.add(new DraftCube.CardIdentity("Blink of an Eye", ""));
cubeCards.add(new DraftCube.CardIdentity("Brain Freeze", ""));
cubeCards.add(new DraftCube.CardIdentity("Counterspell", ""));
cubeCards.add(new DraftCube.CardIdentity("Daze", ""));
cubeCards.add(new DraftCube.CardIdentity("Impulse", ""));
cubeCards.add(new DraftCube.CardIdentity("Mana Drain", ""));
cubeCards.add(new DraftCube.CardIdentity("Mana Leak", ""));
cubeCards.add(new DraftCube.CardIdentity("Remand", ""));
cubeCards.add(new DraftCube.CardIdentity("Disallow", ""));
cubeCards.add(new DraftCube.CardIdentity("Frantic Search", ""));
cubeCards.add(new DraftCube.CardIdentity("Thirst for Knowledge", ""));
cubeCards.add(new DraftCube.CardIdentity("Cryptic Command", ""));
cubeCards.add(new DraftCube.CardIdentity("Fact or Fiction", ""));
cubeCards.add(new DraftCube.CardIdentity("Gifts Ungiven", ""));
cubeCards.add(new DraftCube.CardIdentity("Turnabout", ""));
cubeCards.add(new DraftCube.CardIdentity("Force of Will", ""));
cubeCards.add(new DraftCube.CardIdentity("Gush", ""));
cubeCards.add(new DraftCube.CardIdentity("Mystic Confluence", ""));
cubeCards.add(new DraftCube.CardIdentity("Repeal", ""));
cubeCards.add(new DraftCube.CardIdentity("Nexus of Fate", ""));
cubeCards.add(new DraftCube.CardIdentity("Dig Through Time", ""));
cubeCards.add(new DraftCube.CardIdentity("Ancestral Vision", ""));
cubeCards.add(new DraftCube.CardIdentity("Gitaxian Probe", ""));
cubeCards.add(new DraftCube.CardIdentity("Ponder", ""));
cubeCards.add(new DraftCube.CardIdentity("Preordain", ""));
cubeCards.add(new DraftCube.CardIdentity("Chart a Course", ""));
cubeCards.add(new DraftCube.CardIdentity("Time Walk", ""));
cubeCards.add(new DraftCube.CardIdentity("Compulsive Research", ""));
cubeCards.add(new DraftCube.CardIdentity("Show and Tell", ""));
cubeCards.add(new DraftCube.CardIdentity("Timetwister", ""));
cubeCards.add(new DraftCube.CardIdentity("Tinker", ""));
cubeCards.add(new DraftCube.CardIdentity("Bribery", ""));
cubeCards.add(new DraftCube.CardIdentity("Mind's Desire", ""));
cubeCards.add(new DraftCube.CardIdentity("Time Spiral", ""));
cubeCards.add(new DraftCube.CardIdentity("Upheaval", ""));
cubeCards.add(new DraftCube.CardIdentity("Treasure Cruise", ""));
cubeCards.add(new DraftCube.CardIdentity("Search for Azcanta", ""));
cubeCards.add(new DraftCube.CardIdentity("Control Magic", ""));
cubeCards.add(new DraftCube.CardIdentity("Opposition", ""));
cubeCards.add(new DraftCube.CardIdentity("Treachery", ""));
cubeCards.add(new DraftCube.CardIdentity("Shelldock Isle", ""));
cubeCards.add(new DraftCube.CardIdentity("Tolarian Academy", ""));
cubeCards.add(new DraftCube.CardIdentity("Putrid Imp", ""));
cubeCards.add(new DraftCube.CardIdentity("Brain Maggot", ""));
cubeCards.add(new DraftCube.CardIdentity("Dark Confidant", ""));
cubeCards.add(new DraftCube.CardIdentity("Kitesail Freebooter", ""));
cubeCards.add(new DraftCube.CardIdentity("Mesmeric Fiend", ""));
cubeCards.add(new DraftCube.CardIdentity("Oona's Prowler", ""));
cubeCards.add(new DraftCube.CardIdentity("Pack Rat", ""));
cubeCards.add(new DraftCube.CardIdentity("Scrapheap Scrounger", ""));
cubeCards.add(new DraftCube.CardIdentity("Vampire Hexmage", ""));
cubeCards.add(new DraftCube.CardIdentity("Bone Shredder", ""));
cubeCards.add(new DraftCube.CardIdentity("Hypnotic Specter", ""));
cubeCards.add(new DraftCube.CardIdentity("Ophiomancer", ""));
cubeCards.add(new DraftCube.CardIdentity("Vampire Nighthawk", ""));
cubeCards.add(new DraftCube.CardIdentity("Gonti, Lord of Luxury", ""));
cubeCards.add(new DraftCube.CardIdentity("Nekrataal", ""));
cubeCards.add(new DraftCube.CardIdentity("Ravenous Chupacabra", ""));
cubeCards.add(new DraftCube.CardIdentity("Doom Whisperer", ""));
cubeCards.add(new DraftCube.CardIdentity("Puppeteer Clique", ""));
cubeCards.add(new DraftCube.CardIdentity("Shriekmaw", ""));
cubeCards.add(new DraftCube.CardIdentity("Demonlord Belzenlok", ""));
cubeCards.add(new DraftCube.CardIdentity("Grave Titan", ""));
cubeCards.add(new DraftCube.CardIdentity("Massacre Wurm", ""));
cubeCards.add(new DraftCube.CardIdentity("Tasigur, the Golden Fang", ""));
cubeCards.add(new DraftCube.CardIdentity("Sheoldred, Whispering One", ""));
cubeCards.add(new DraftCube.CardIdentity("Griselbrand", ""));
cubeCards.add(new DraftCube.CardIdentity("Liliana of the Veil", ""));
cubeCards.add(new DraftCube.CardIdentity("Liliana, Death's Majesty", ""));
cubeCards.add(new DraftCube.CardIdentity("Dark Ritual", ""));
cubeCards.add(new DraftCube.CardIdentity("Entomb", ""));
cubeCards.add(new DraftCube.CardIdentity("Fatal Push", ""));
cubeCards.add(new DraftCube.CardIdentity("Vampiric Tutor", ""));
cubeCards.add(new DraftCube.CardIdentity("Cabal Ritual", ""));
cubeCards.add(new DraftCube.CardIdentity("Cast Down", ""));
cubeCards.add(new DraftCube.CardIdentity("Go for the Throat", ""));
cubeCards.add(new DraftCube.CardIdentity("Shallow Grave", ""));
cubeCards.add(new DraftCube.CardIdentity("Ultimate Price", ""));
cubeCards.add(new DraftCube.CardIdentity("Corpse Dance", ""));
cubeCards.add(new DraftCube.CardIdentity("Dismember", ""));
cubeCards.add(new DraftCube.CardIdentity("Hero's Downfall", ""));
cubeCards.add(new DraftCube.CardIdentity("Makeshift Mannequin", ""));
cubeCards.add(new DraftCube.CardIdentity("Vraska's Contempt", ""));
cubeCards.add(new DraftCube.CardIdentity("Duress", ""));
cubeCards.add(new DraftCube.CardIdentity("Imperial Seal", ""));
cubeCards.add(new DraftCube.CardIdentity("Inquisition of Kozilek", ""));
cubeCards.add(new DraftCube.CardIdentity("Reanimate", ""));
cubeCards.add(new DraftCube.CardIdentity("Thoughtseize", ""));
cubeCards.add(new DraftCube.CardIdentity("Collective Brutality", ""));
cubeCards.add(new DraftCube.CardIdentity("Demonic Tutor", ""));
cubeCards.add(new DraftCube.CardIdentity("Exhume", ""));
cubeCards.add(new DraftCube.CardIdentity("Hymn to Tourach", ""));
cubeCards.add(new DraftCube.CardIdentity("Night's Whisper", ""));
cubeCards.add(new DraftCube.CardIdentity("Buried Alive", ""));
cubeCards.add(new DraftCube.CardIdentity("Grim Tutor", ""));
cubeCards.add(new DraftCube.CardIdentity("Toxic Deluge", ""));
cubeCards.add(new DraftCube.CardIdentity("Yawgmoth's Will", ""));
cubeCards.add(new DraftCube.CardIdentity("Damnation", ""));
cubeCards.add(new DraftCube.CardIdentity("Languish", ""));
cubeCards.add(new DraftCube.CardIdentity("Tendrils of Agony", ""));
cubeCards.add(new DraftCube.CardIdentity("Dark Petition", ""));
cubeCards.add(new DraftCube.CardIdentity("Living Death", ""));
cubeCards.add(new DraftCube.CardIdentity("Unburial Rites", ""));
cubeCards.add(new DraftCube.CardIdentity("Mind Twist", ""));
cubeCards.add(new DraftCube.CardIdentity("Animate Dead", ""));
cubeCards.add(new DraftCube.CardIdentity("Arguel's Blood Fast", ""));
cubeCards.add(new DraftCube.CardIdentity("Bitterblossom", ""));
cubeCards.add(new DraftCube.CardIdentity("Necromancy", ""));
cubeCards.add(new DraftCube.CardIdentity("Phyrexian Arena", ""));
cubeCards.add(new DraftCube.CardIdentity("Recurring Nightmare", ""));
cubeCards.add(new DraftCube.CardIdentity("Yawgmoth's Bargain", ""));
cubeCards.add(new DraftCube.CardIdentity("Urborg, Tomb of Yawgmoth", ""));
cubeCards.add(new DraftCube.CardIdentity("Firedrinker Satyr", ""));
cubeCards.add(new DraftCube.CardIdentity("Goblin Guide", ""));
cubeCards.add(new DraftCube.CardIdentity("Goblin Welder", ""));
cubeCards.add(new DraftCube.CardIdentity("Grim Lavamancer", ""));
cubeCards.add(new DraftCube.CardIdentity("Jackal Pup", ""));
cubeCards.add(new DraftCube.CardIdentity("Monastery Swiftspear", ""));
cubeCards.add(new DraftCube.CardIdentity("Zurgo Bellstriker", ""));
cubeCards.add(new DraftCube.CardIdentity("Abbot of Keral Keep", ""));
cubeCards.add(new DraftCube.CardIdentity("Dire Fleet Daredevil", ""));
cubeCards.add(new DraftCube.CardIdentity("Eidolon of the Great Revel", ""));
cubeCards.add(new DraftCube.CardIdentity("Runaway Steam-Kin", ""));
cubeCards.add(new DraftCube.CardIdentity("Young Pyromancer", ""));
cubeCards.add(new DraftCube.CardIdentity("Goblin Rabblemaster", ""));
cubeCards.add(new DraftCube.CardIdentity("Imperial Recruiter", ""));
cubeCards.add(new DraftCube.CardIdentity("Magus of the Moon", ""));
cubeCards.add(new DraftCube.CardIdentity("Manic Vandal", ""));
cubeCards.add(new DraftCube.CardIdentity("Pia Nalaar", ""));
cubeCards.add(new DraftCube.CardIdentity("Avalanche Riders", ""));
cubeCards.add(new DraftCube.CardIdentity("Flametongue Kavu", ""));
cubeCards.add(new DraftCube.CardIdentity("Hazoret the Fervent", ""));
cubeCards.add(new DraftCube.CardIdentity("Hellrider", ""));
cubeCards.add(new DraftCube.CardIdentity("Pia and Kiran Nalaar", ""));
cubeCards.add(new DraftCube.CardIdentity("Rekindling Phoenix", ""));
cubeCards.add(new DraftCube.CardIdentity("Glorybringer", ""));
cubeCards.add(new DraftCube.CardIdentity("Goblin Dark-Dwellers", ""));
cubeCards.add(new DraftCube.CardIdentity("Kiki-Jiki, Mirror Breaker", ""));
cubeCards.add(new DraftCube.CardIdentity("Siege-Gang Commander", ""));
cubeCards.add(new DraftCube.CardIdentity("Thundermaw Hellkite", ""));
cubeCards.add(new DraftCube.CardIdentity("Zealous Conscripts", ""));
cubeCards.add(new DraftCube.CardIdentity("Inferno Titan", ""));
cubeCards.add(new DraftCube.CardIdentity("Chandra, Torch of Defiance", ""));
cubeCards.add(new DraftCube.CardIdentity("Daretti, Scrap Savant", ""));
cubeCards.add(new DraftCube.CardIdentity("Koth of the Hammer", ""));
cubeCards.add(new DraftCube.CardIdentity("Chandra, Flamecaller", ""));
cubeCards.add(new DraftCube.CardIdentity("Burst Lightning", ""));
cubeCards.add(new DraftCube.CardIdentity("Lightning Bolt", ""));
cubeCards.add(new DraftCube.CardIdentity("Abrade", ""));
cubeCards.add(new DraftCube.CardIdentity("Ancient Grudge", ""));
cubeCards.add(new DraftCube.CardIdentity("Desperate Ritual", ""));
cubeCards.add(new DraftCube.CardIdentity("Incinerate", ""));
cubeCards.add(new DraftCube.CardIdentity("Lightning Strike", ""));
cubeCards.add(new DraftCube.CardIdentity("Magma Jet", ""));
cubeCards.add(new DraftCube.CardIdentity("Pyretic Ritual", ""));
cubeCards.add(new DraftCube.CardIdentity("Char", ""));
cubeCards.add(new DraftCube.CardIdentity("Seething Song", ""));
cubeCards.add(new DraftCube.CardIdentity("Through the Breach", ""));
cubeCards.add(new DraftCube.CardIdentity("Fireblast", ""));
cubeCards.add(new DraftCube.CardIdentity("Chain Lightning", ""));
cubeCards.add(new DraftCube.CardIdentity("Faithless Looting", ""));
cubeCards.add(new DraftCube.CardIdentity("Firebolt", ""));
cubeCards.add(new DraftCube.CardIdentity("Flame Slash", ""));
cubeCards.add(new DraftCube.CardIdentity("Mizzium Mortars", ""));
cubeCards.add(new DraftCube.CardIdentity("Pyroclasm", ""));
cubeCards.add(new DraftCube.CardIdentity("Collective Defiance", ""));
cubeCards.add(new DraftCube.CardIdentity("Sweltering Suns", ""));
cubeCards.add(new DraftCube.CardIdentity("Wheel of Fortune", ""));
cubeCards.add(new DraftCube.CardIdentity("Empty the Warrens", ""));
cubeCards.add(new DraftCube.CardIdentity("Fiery Confluence", ""));
cubeCards.add(new DraftCube.CardIdentity("Burning of Xinye", ""));
cubeCards.add(new DraftCube.CardIdentity("Wildfire", ""));
cubeCards.add(new DraftCube.CardIdentity("Bonfire of the Damned", ""));
cubeCards.add(new DraftCube.CardIdentity("Mana Flare", ""));
cubeCards.add(new DraftCube.CardIdentity("Sulfuric Vortex", ""));
cubeCards.add(new DraftCube.CardIdentity("Experimental Frenzy", ""));
cubeCards.add(new DraftCube.CardIdentity("Sneak Attack", ""));
cubeCards.add(new DraftCube.CardIdentity("Splinter Twin", ""));
cubeCards.add(new DraftCube.CardIdentity("Arbor Elf", ""));
cubeCards.add(new DraftCube.CardIdentity("Avacyn's Pilgrim", ""));
cubeCards.add(new DraftCube.CardIdentity("Birds of Paradise", ""));
cubeCards.add(new DraftCube.CardIdentity("Elves of Deep Shadow", ""));
cubeCards.add(new DraftCube.CardIdentity("Elvish Mystic", ""));
cubeCards.add(new DraftCube.CardIdentity("Fyndhorn Elves", ""));
cubeCards.add(new DraftCube.CardIdentity("Joraga Treespeaker", ""));
cubeCards.add(new DraftCube.CardIdentity("Llanowar Elves", ""));
cubeCards.add(new DraftCube.CardIdentity("Noble Hierarch", ""));
cubeCards.add(new DraftCube.CardIdentity("Devoted Druid", ""));
cubeCards.add(new DraftCube.CardIdentity("Fauna Shaman", ""));
cubeCards.add(new DraftCube.CardIdentity("Lotus Cobra", ""));
cubeCards.add(new DraftCube.CardIdentity("Rofellos, Llanowar Emissary", ""));
cubeCards.add(new DraftCube.CardIdentity("Sakura-Tribe Elder", ""));
cubeCards.add(new DraftCube.CardIdentity("Scavenging Ooze", ""));
cubeCards.add(new DraftCube.CardIdentity("Sylvan Caryatid", ""));
cubeCards.add(new DraftCube.CardIdentity("Wall of Blossoms", ""));
cubeCards.add(new DraftCube.CardIdentity("Wall of Roots", ""));
cubeCards.add(new DraftCube.CardIdentity("Courser of Kruphix", ""));
cubeCards.add(new DraftCube.CardIdentity("Eternal Witness", ""));
cubeCards.add(new DraftCube.CardIdentity("Manglehorn", ""));
cubeCards.add(new DraftCube.CardIdentity("Nissa, Vastwood Seer", ""));
cubeCards.add(new DraftCube.CardIdentity("Ramunap Excavator", ""));
cubeCards.add(new DraftCube.CardIdentity("Reclamation Sage", ""));
cubeCards.add(new DraftCube.CardIdentity("Tireless Tracker", ""));
cubeCards.add(new DraftCube.CardIdentity("Yavimaya Elder", ""));
cubeCards.add(new DraftCube.CardIdentity("Master of the Wild Hunt", ""));
cubeCards.add(new DraftCube.CardIdentity("Obstinate Baloth", ""));
cubeCards.add(new DraftCube.CardIdentity("Oracle of Mul Daya", ""));
cubeCards.add(new DraftCube.CardIdentity("Polukranos, World Eater", ""));
cubeCards.add(new DraftCube.CardIdentity("Thrun, the Last Troll", ""));
cubeCards.add(new DraftCube.CardIdentity("Acidic Slime", ""));
cubeCards.add(new DraftCube.CardIdentity("Deranged Hermit", ""));
cubeCards.add(new DraftCube.CardIdentity("Thragtusk", ""));
cubeCards.add(new DraftCube.CardIdentity("Whisperwood Elemental", ""));
cubeCards.add(new DraftCube.CardIdentity("Carnage Tyrant", ""));
cubeCards.add(new DraftCube.CardIdentity("Primeval Titan", ""));
cubeCards.add(new DraftCube.CardIdentity("Avenger of Zendikar", ""));
cubeCards.add(new DraftCube.CardIdentity("Craterhoof Behemoth", ""));
cubeCards.add(new DraftCube.CardIdentity("Terastodon", ""));
cubeCards.add(new DraftCube.CardIdentity("Woodfall Primus", ""));
cubeCards.add(new DraftCube.CardIdentity("Nissa, Voice of Zendikar", ""));
cubeCards.add(new DraftCube.CardIdentity("Garruk Relentless", ""));
cubeCards.add(new DraftCube.CardIdentity("Garruk Wildspeaker", ""));
cubeCards.add(new DraftCube.CardIdentity("Garruk, Primal Hunter", ""));
cubeCards.add(new DraftCube.CardIdentity("Nissa, Worldwaker", ""));
cubeCards.add(new DraftCube.CardIdentity("Vivien Reid", ""));
cubeCards.add(new DraftCube.CardIdentity("Verdurous Gearhulk", ""));
cubeCards.add(new DraftCube.CardIdentity("Nature's Claim", ""));
cubeCards.add(new DraftCube.CardIdentity("Beast Within", ""));
cubeCards.add(new DraftCube.CardIdentity("Channel", ""));
cubeCards.add(new DraftCube.CardIdentity("Regrowth", ""));
cubeCards.add(new DraftCube.CardIdentity("Kodama's Reach", ""));
cubeCards.add(new DraftCube.CardIdentity("Search for Tomorrow", ""));
cubeCards.add(new DraftCube.CardIdentity("Eureka", ""));
cubeCards.add(new DraftCube.CardIdentity("Harmonize", ""));
cubeCards.add(new DraftCube.CardIdentity("Natural Order", ""));
cubeCards.add(new DraftCube.CardIdentity("Plow Under", ""));
cubeCards.add(new DraftCube.CardIdentity("Primal Command", ""));
cubeCards.add(new DraftCube.CardIdentity("Green Sun's Zenith", ""));
cubeCards.add(new DraftCube.CardIdentity("Tooth and Nail", ""));
cubeCards.add(new DraftCube.CardIdentity("Genesis Wave", ""));
cubeCards.add(new DraftCube.CardIdentity("Fastbond", ""));
cubeCards.add(new DraftCube.CardIdentity("Oath of Druids", ""));
cubeCards.add(new DraftCube.CardIdentity("Survival of the Fittest", ""));
cubeCards.add(new DraftCube.CardIdentity("Sylvan Library", ""));
cubeCards.add(new DraftCube.CardIdentity("Heartbeat of Spring", ""));
cubeCards.add(new DraftCube.CardIdentity("Gaea's Cradle", ""));
cubeCards.add(new DraftCube.CardIdentity("Geist of Saint Traft", ""));
cubeCards.add(new DraftCube.CardIdentity("Spell Queller", ""));
cubeCards.add(new DraftCube.CardIdentity("Dragonlord Ojutai", ""));
cubeCards.add(new DraftCube.CardIdentity("Teferi, Hero of Dominaria", ""));
cubeCards.add(new DraftCube.CardIdentity("Sphinx's Revelation", ""));
cubeCards.add(new DraftCube.CardIdentity("Celestial Colonnade", ""));
cubeCards.add(new DraftCube.CardIdentity("Flooded Strand", ""));
cubeCards.add(new DraftCube.CardIdentity("Hallowed Fountain", ""));
cubeCards.add(new DraftCube.CardIdentity("Seachrome Coast", ""));
cubeCards.add(new DraftCube.CardIdentity("Tundra", ""));
cubeCards.add(new DraftCube.CardIdentity("Thief of Sanity", ""));
cubeCards.add(new DraftCube.CardIdentity("Hostage Taker", ""));
cubeCards.add(new DraftCube.CardIdentity("The Scarab God", ""));
cubeCards.add(new DraftCube.CardIdentity("Ashiok, Nightmare Weaver", ""));
cubeCards.add(new DraftCube.CardIdentity("Baleful Strix", ""));
cubeCards.add(new DraftCube.CardIdentity("Creeping Tar Pit", ""));
cubeCards.add(new DraftCube.CardIdentity("Darkslick Shores", ""));
cubeCards.add(new DraftCube.CardIdentity("Polluted Delta", ""));
cubeCards.add(new DraftCube.CardIdentity("Underground Sea", ""));
cubeCards.add(new DraftCube.CardIdentity("Watery Grave", ""));
cubeCards.add(new DraftCube.CardIdentity("Daretti, Ingenious Iconoclast", ""));
cubeCards.add(new DraftCube.CardIdentity("Terminate", ""));
cubeCards.add(new DraftCube.CardIdentity("Kolaghan's Command", ""));
cubeCards.add(new DraftCube.CardIdentity("Dreadbore", ""));
cubeCards.add(new DraftCube.CardIdentity("Rakdos's Return", ""));
cubeCards.add(new DraftCube.CardIdentity("Badlands", ""));
cubeCards.add(new DraftCube.CardIdentity("Blackcleave Cliffs", ""));
cubeCards.add(new DraftCube.CardIdentity("Blood Crypt", ""));
cubeCards.add(new DraftCube.CardIdentity("Bloodstained Mire", ""));
cubeCards.add(new DraftCube.CardIdentity("Lavaclaw Reaches", ""));
cubeCards.add(new DraftCube.CardIdentity("Bloodbraid Elf", ""));
cubeCards.add(new DraftCube.CardIdentity("Huntmaster of the Fells", ""));
cubeCards.add(new DraftCube.CardIdentity("Dragonlord Atarka", ""));
cubeCards.add(new DraftCube.CardIdentity("Xenagos, the Reveler", ""));
cubeCards.add(new DraftCube.CardIdentity("Manamorphose", ""));
cubeCards.add(new DraftCube.CardIdentity("Copperline Gorge", ""));
cubeCards.add(new DraftCube.CardIdentity("Raging Ravine", ""));
cubeCards.add(new DraftCube.CardIdentity("Stomping Ground", ""));
cubeCards.add(new DraftCube.CardIdentity("Taiga", ""));
cubeCards.add(new DraftCube.CardIdentity("Wooded Foothills", ""));
cubeCards.add(new DraftCube.CardIdentity("Kitchen Finks", ""));
cubeCards.add(new DraftCube.CardIdentity("Knight of Autumn", ""));
cubeCards.add(new DraftCube.CardIdentity("Knight of the Reliquary", ""));
cubeCards.add(new DraftCube.CardIdentity("Trostani Discordant", ""));
cubeCards.add(new DraftCube.CardIdentity("Mirari's Wake", ""));
cubeCards.add(new DraftCube.CardIdentity("Razorverge Thicket", ""));
cubeCards.add(new DraftCube.CardIdentity("Savannah", ""));
cubeCards.add(new DraftCube.CardIdentity("Stirring Wildwood", ""));
cubeCards.add(new DraftCube.CardIdentity("Temple Garden", ""));
cubeCards.add(new DraftCube.CardIdentity("Windswept Heath", ""));
cubeCards.add(new DraftCube.CardIdentity("Tidehollow Sculler", ""));
cubeCards.add(new DraftCube.CardIdentity("Anguished Unmaking", ""));
cubeCards.add(new DraftCube.CardIdentity("Vindicate", ""));
cubeCards.add(new DraftCube.CardIdentity("Concealed Courtyard", ""));
cubeCards.add(new DraftCube.CardIdentity("Godless Shrine", ""));
cubeCards.add(new DraftCube.CardIdentity("Marsh Flats", ""));
cubeCards.add(new DraftCube.CardIdentity("Scrubland", ""));
cubeCards.add(new DraftCube.CardIdentity("Shambling Vent", ""));
cubeCards.add(new DraftCube.CardIdentity("Vraska, Relic Seeker", ""));
cubeCards.add(new DraftCube.CardIdentity("Garruk, Apex Predator", ""));
cubeCards.add(new DraftCube.CardIdentity("Abrupt Decay", ""));
cubeCards.add(new DraftCube.CardIdentity("Assassin's Trophy", ""));
cubeCards.add(new DraftCube.CardIdentity("Maelstrom Pulse", ""));
cubeCards.add(new DraftCube.CardIdentity("Bayou", ""));
cubeCards.add(new DraftCube.CardIdentity("Blooming Marsh", ""));
cubeCards.add(new DraftCube.CardIdentity("Hissing Quagmire", ""));
cubeCards.add(new DraftCube.CardIdentity("Overgrown Tomb", ""));
cubeCards.add(new DraftCube.CardIdentity("Verdant Catacombs", ""));
cubeCards.add(new DraftCube.CardIdentity("Edric, Spymaster of Trest", ""));
cubeCards.add(new DraftCube.CardIdentity("Trygon Predator", ""));
cubeCards.add(new DraftCube.CardIdentity("Mystic Snake", ""));
cubeCards.add(new DraftCube.CardIdentity("Kiora, the Crashing Wave", ""));
cubeCards.add(new DraftCube.CardIdentity("Shardless Agent", ""));
cubeCards.add(new DraftCube.CardIdentity("Botanical Sanctum", ""));
cubeCards.add(new DraftCube.CardIdentity("Breeding Pool", ""));
cubeCards.add(new DraftCube.CardIdentity("Lumbering Falls", ""));
cubeCards.add(new DraftCube.CardIdentity("Misty Rainforest", ""));
cubeCards.add(new DraftCube.CardIdentity("Tropical Island", ""));
cubeCards.add(new DraftCube.CardIdentity("Goblin Electromancer", ""));
cubeCards.add(new DraftCube.CardIdentity("Dack Fayden", ""));
cubeCards.add(new DraftCube.CardIdentity("Expansion // Explosion", ""));
cubeCards.add(new DraftCube.CardIdentity("Izzet Charm", ""));
cubeCards.add(new DraftCube.CardIdentity("Thousand-Year Storm", ""));
cubeCards.add(new DraftCube.CardIdentity("Scalding Tarn", ""));
cubeCards.add(new DraftCube.CardIdentity("Spirebluff Canal", ""));
cubeCards.add(new DraftCube.CardIdentity("Steam Vents", ""));
cubeCards.add(new DraftCube.CardIdentity("Volcanic Island", ""));
cubeCards.add(new DraftCube.CardIdentity("Wandering Fumarole", ""));
cubeCards.add(new DraftCube.CardIdentity("Figure of Destiny", ""));
cubeCards.add(new DraftCube.CardIdentity("Aurelia, Exemplar of Justice", ""));
cubeCards.add(new DraftCube.CardIdentity("Ajani Vengeant", ""));
cubeCards.add(new DraftCube.CardIdentity("Nahiri, the Harbinger", ""));
cubeCards.add(new DraftCube.CardIdentity("Lightning Helix", ""));
cubeCards.add(new DraftCube.CardIdentity("Arid Mesa", ""));
cubeCards.add(new DraftCube.CardIdentity("Inspiring Vantage", ""));
cubeCards.add(new DraftCube.CardIdentity("Needle Spires", ""));
cubeCards.add(new DraftCube.CardIdentity("Plateau", ""));
cubeCards.add(new DraftCube.CardIdentity("Sacred Foundry", ""));
cubeCards.add(new DraftCube.CardIdentity("Sphinx of the Steel Wind", ""));
cubeCards.add(new DraftCube.CardIdentity("Nicol Bolas, Planeswalker", ""));
cubeCards.add(new DraftCube.CardIdentity("Leovold, Emissary of Trest", ""));
cubeCards.add(new DraftCube.CardIdentity("Progenitus", ""));
cubeCards.add(new DraftCube.CardIdentity("Kozilek, Butcher of Truth", ""));
cubeCards.add(new DraftCube.CardIdentity("Ulamog, the Ceaseless Hunger", ""));
cubeCards.add(new DraftCube.CardIdentity("Ulamog, the Infinite Gyre", ""));
cubeCards.add(new DraftCube.CardIdentity("Emrakul, the Promised End", ""));
cubeCards.add(new DraftCube.CardIdentity("Emrakul, the Aeons Torn", ""));
cubeCards.add(new DraftCube.CardIdentity("Karn, Scion of Urza", ""));
cubeCards.add(new DraftCube.CardIdentity("Karn Liberated", ""));
cubeCards.add(new DraftCube.CardIdentity("Ugin, the Spirit Dragon", ""));
cubeCards.add(new DraftCube.CardIdentity("Hangarback Walker", ""));
cubeCards.add(new DraftCube.CardIdentity("Phyrexian Revoker", ""));
cubeCards.add(new DraftCube.CardIdentity("Metalworker", ""));
cubeCards.add(new DraftCube.CardIdentity("Lodestone Golem", ""));
cubeCards.add(new DraftCube.CardIdentity("Solemn Simulacrum", ""));
cubeCards.add(new DraftCube.CardIdentity("Kuldotha Forgemaster", ""));
cubeCards.add(new DraftCube.CardIdentity("Duplicant", ""));
cubeCards.add(new DraftCube.CardIdentity("Wurmcoil Engine", ""));
cubeCards.add(new DraftCube.CardIdentity("Myr Battlesphere", ""));
cubeCards.add(new DraftCube.CardIdentity("Sundering Titan", ""));
cubeCards.add(new DraftCube.CardIdentity("Walking Ballista", ""));
cubeCards.add(new DraftCube.CardIdentity("Blightsteel Colossus", ""));
cubeCards.add(new DraftCube.CardIdentity("Black Lotus", ""));
cubeCards.add(new DraftCube.CardIdentity("Chrome Mox", ""));
cubeCards.add(new DraftCube.CardIdentity("Everflowing Chalice", ""));
cubeCards.add(new DraftCube.CardIdentity("Lion's Eye Diamond", ""));
cubeCards.add(new DraftCube.CardIdentity("Lotus Bloom", ""));
cubeCards.add(new DraftCube.CardIdentity("Lotus Petal", ""));
cubeCards.add(new DraftCube.CardIdentity("Mana Crypt", ""));
cubeCards.add(new DraftCube.CardIdentity("Mox Diamond", ""));
cubeCards.add(new DraftCube.CardIdentity("Mox Emerald", ""));
cubeCards.add(new DraftCube.CardIdentity("Mox Jet", ""));
cubeCards.add(new DraftCube.CardIdentity("Mox Pearl", ""));
cubeCards.add(new DraftCube.CardIdentity("Mox Ruby", ""));
cubeCards.add(new DraftCube.CardIdentity("Mox Sapphire", ""));
cubeCards.add(new DraftCube.CardIdentity("Mana Vault", ""));
cubeCards.add(new DraftCube.CardIdentity("Relic of Progenitus", ""));
cubeCards.add(new DraftCube.CardIdentity("Sensei's Divining Top", ""));
cubeCards.add(new DraftCube.CardIdentity("Skullclamp", ""));
cubeCards.add(new DraftCube.CardIdentity("Sol Ring", ""));
cubeCards.add(new DraftCube.CardIdentity("Azorius Signet", ""));
cubeCards.add(new DraftCube.CardIdentity("Boros Signet", ""));
cubeCards.add(new DraftCube.CardIdentity("Dimir Signet", ""));
cubeCards.add(new DraftCube.CardIdentity("Golgari Signet", ""));
cubeCards.add(new DraftCube.CardIdentity("Grim Monolith", ""));
cubeCards.add(new DraftCube.CardIdentity("Gruul Signet", ""));
cubeCards.add(new DraftCube.CardIdentity("Izzet Signet", ""));
cubeCards.add(new DraftCube.CardIdentity("Lightning Greaves", ""));
cubeCards.add(new DraftCube.CardIdentity("Orzhov Signet", ""));
cubeCards.add(new DraftCube.CardIdentity("Pentad Prism", ""));
cubeCards.add(new DraftCube.CardIdentity("Rakdos Signet", ""));
cubeCards.add(new DraftCube.CardIdentity("Selesnya Signet", ""));
cubeCards.add(new DraftCube.CardIdentity("Shrine of Burning Rage", ""));
cubeCards.add(new DraftCube.CardIdentity("Simic Signet", ""));
cubeCards.add(new DraftCube.CardIdentity("Smuggler's Copter", ""));
cubeCards.add(new DraftCube.CardIdentity("Sorcerous Spyglass", ""));
cubeCards.add(new DraftCube.CardIdentity("Umezawa's Jitte", ""));
cubeCards.add(new DraftCube.CardIdentity("Winter Orb", ""));
cubeCards.add(new DraftCube.CardIdentity("Basalt Monolith", ""));
cubeCards.add(new DraftCube.CardIdentity("Coalition Relic", ""));
cubeCards.add(new DraftCube.CardIdentity("Crucible of Worlds", ""));
cubeCards.add(new DraftCube.CardIdentity("Oblivion Stone", ""));
cubeCards.add(new DraftCube.CardIdentity("Sword of Body and Mind", ""));
cubeCards.add(new DraftCube.CardIdentity("Sword of Feast and Famine", ""));
cubeCards.add(new DraftCube.CardIdentity("Sword of Fire and Ice", ""));
cubeCards.add(new DraftCube.CardIdentity("Sword of Light and Shadow", ""));
cubeCards.add(new DraftCube.CardIdentity("Sword of War and Peace", ""));
cubeCards.add(new DraftCube.CardIdentity("Tangle Wire", ""));
cubeCards.add(new DraftCube.CardIdentity("Vedalken Shackles", ""));
cubeCards.add(new DraftCube.CardIdentity("Worn Powerstone", ""));
cubeCards.add(new DraftCube.CardIdentity("Coercive Portal", ""));
cubeCards.add(new DraftCube.CardIdentity("Smokestack", ""));
cubeCards.add(new DraftCube.CardIdentity("Thran Dynamo", ""));
cubeCards.add(new DraftCube.CardIdentity("Batterskull", ""));
cubeCards.add(new DraftCube.CardIdentity("Gilded Lotus", ""));
cubeCards.add(new DraftCube.CardIdentity("Memory Jar", ""));
cubeCards.add(new DraftCube.CardIdentity("Mindslaver", ""));
cubeCards.add(new DraftCube.CardIdentity("Academy Ruins", ""));
cubeCards.add(new DraftCube.CardIdentity("Ancient Tomb", ""));
cubeCards.add(new DraftCube.CardIdentity("Bazaar of Baghdad", ""));
cubeCards.add(new DraftCube.CardIdentity("Field of Ruin", ""));
cubeCards.add(new DraftCube.CardIdentity("Library of Alexandria", ""));
cubeCards.add(new DraftCube.CardIdentity("Mana Confluence", ""));
cubeCards.add(new DraftCube.CardIdentity("Maze of Ith", ""));
cubeCards.add(new DraftCube.CardIdentity("Mishra's Factory", ""));
cubeCards.add(new DraftCube.CardIdentity("Mishra's Workshop", ""));
cubeCards.add(new DraftCube.CardIdentity("Mutavault", ""));
cubeCards.add(new DraftCube.CardIdentity("Nykthos, Shrine to Nyx", ""));
cubeCards.add(new DraftCube.CardIdentity("Rishadan Port", ""));
cubeCards.add(new DraftCube.CardIdentity("Strip Mine", ""));
cubeCards.add(new DraftCube.CardIdentity("Wasteland", ""));
}
}

View file

@ -134,6 +134,7 @@
<draftCube name="MTGO Vintage Cube June 2017" jar="mage-tournament-booster-draft.jar" className="mage.tournament.cubes.VintageCubeJune2017"/>
<draftCube name="MTGO Vintage Cube December 2017" jar="mage-tournament-booster-draft.jar" className="mage.tournament.cubes.VintageCubeDecember2017"/>
<draftCube name="MTGO Vintage Cube June 2018" jar="mage-tournament-booster-draft-${project.version}.jar" className="mage.tournament.cubes.VintageCubeJune2018"/>
<draftCube name="MTGO Vintage Cube December 2018" jar="mage-tournament-booster-draft-${project.version}.jar" className="mage.tournament.cubes.VintageCubeDecember2018"/>
<draftCube name="The Peasant's Toolbox" jar="mage-tournament-booster-draft.jar" className="mage.tournament.cubes.PeasantsToolboxCube"/>
<draftCube name="www.MTGCube.com" jar="mage-tournament-booster-draft.jar" className="mage.tournament.cubes.MTGCube"/>
<draftCube name="Cube From Deck" jar="mage-tournament-booster-draft.jar" className="mage.tournament.cubes.CubeFromDeck"/>

View file

@ -128,6 +128,7 @@
<draftCube name="MTGO Vintage Cube June 2017" jar="mage-tournament-booster-draft-${project.version}.jar" className="mage.tournament.cubes.VintageCubeJune2017"/>
<draftCube name="MTGO Vintage Cube December 2017" jar="mage-tournament-booster-draft-${project.version}.jar" className="mage.tournament.cubes.VintageCubeDecember2017"/>
<draftCube name="MTGO Vintage Cube June 2018" jar="mage-tournament-booster-draft-${project.version}.jar" className="mage.tournament.cubes.VintageCubeJune2018"/>
<draftCube name="MTGO Vintage Cube December 2018" jar="mage-tournament-booster-draft-${project.version}.jar" className="mage.tournament.cubes.VintageCubeDecember2018"/>
<draftCube name="The Peasant's Toolbox" jar="mage-tournament-booster-draft-${project.version}.jar" className="mage.tournament.cubes.PeasantsToolboxCube"/>
<draftCube name="www.MTGCube.com" jar="mage-tournament-booster-draft-${project.version}.jar" className="mage.tournament.cubes.MTGCube"/>
<draftCube name="Cube From Deck" jar="mage-tournament-booster-draft-${project.version}.jar" className="mage.tournament.cubes.CubeFromDeck"/>

View file

@ -48,7 +48,8 @@ public class DraftSession {
if (user.isPresent()) {
if (futureTimeout != null && !futureTimeout.isDone()) {
int remaining = (int) futureTimeout.getDelay(TimeUnit.SECONDS);
user.get().fireCallback(new ClientCallback(ClientCallbackMethod.DRAFT_INIT, draft.getId(), new DraftClientMessage(getDraftPickView(remaining))));
user.get().fireCallback(new ClientCallback(ClientCallbackMethod.DRAFT_INIT, draft.getId(),
new DraftClientMessage(getDraftView(), getDraftPickView(remaining))));
}
return true;
}
@ -60,8 +61,8 @@ public class DraftSession {
if (!killed) {
UserManager.instance
.getUser(userId).
ifPresent(user -> user.fireCallback(
new ClientCallback(ClientCallbackMethod.DRAFT_UPDATE, draft.getId(), getDraftView())));
ifPresent(user -> user.fireCallback(new ClientCallback(ClientCallbackMethod.DRAFT_UPDATE, draft.getId(),
new DraftClientMessage(getDraftView(), null))));
}
}
@ -70,7 +71,6 @@ public class DraftSession {
UserManager.instance
.getUser(userId)
.ifPresent(user -> user.fireCallback(new ClientCallback(ClientCallbackMethod.DRAFT_OVER, draft.getId())));
}
}
@ -79,7 +79,8 @@ public class DraftSession {
setupTimeout(timeout);
UserManager.instance
.getUser(userId)
.ifPresent(user -> user.fireCallback(new ClientCallback(ClientCallbackMethod.DRAFT_PICK, draft.getId(), new DraftClientMessage(getDraftPickView(timeout)))));
.ifPresent(user -> user.fireCallback(new ClientCallback(ClientCallbackMethod.DRAFT_PICK, draft.getId(),
new DraftClientMessage(getDraftView(), getDraftPickView(timeout)))));
}
}

View file

@ -1,7 +1,5 @@
package mage.cards.a;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.TriggeredAbilityImpl;
@ -21,8 +19,9 @@ import mage.game.Game;
import mage.game.events.GameEvent;
import mage.target.TargetPlayer;
import java.util.UUID;
/**
*
* @author Styxo
*/
public final class AAT1 extends CardImpl {
@ -74,7 +73,8 @@ public final class AAT1 extends CardImpl {
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Card card = game.getCard(event.getTargetId());
if (event.getPlayerId().equals(game.getControllerId(sourceId))
if (card != null
&& event.getPlayerId().equals(game.getControllerId(sourceId))
&& card.isCreature()
&& game.getState().getZone(card.getId()) == Zone.GRAVEYARD
&& event.getData().equals("repair")) {

View file

@ -120,6 +120,7 @@ class AbandonedSarcophagusReplacementEffect extends ReplacementEffectImpl {
AbandonedSarcophagusWatcher watcher = (AbandonedSarcophagusWatcher) game.getState().getWatchers().get(AbandonedSarcophagusWatcher.class.getSimpleName());
Card card = game.getCard(event.getTargetId());
if (card != null
&& controller != null
&& watcher != null
&& card.isOwnedBy(controller.getId())) {
for (Ability ability : card.getAbilities()) {

View file

@ -78,6 +78,9 @@ class AbeyanceEffect extends ContinuousRuleModifyingEffectImpl {
public boolean applies(GameEvent event, Ability source, Game game) {
if (source.getFirstTarget() != null && source.getFirstTarget().equals(event.getPlayerId())) {
MageObject object = game.getObject(event.getSourceId());
if(object == null){
return false;
}
if (event.getType() == GameEvent.EventType.CAST_SPELL) {
if (object.isInstant() || object.isSorcery()) {
return true;

View file

@ -26,8 +26,8 @@ public final class Abrade extends CardImpl {
// Destroy target artifact.
Mode mode = new Mode();
mode.getEffects().add(new DestroyTargetEffect());
mode.getTargets().add(new TargetArtifactPermanent());
mode.addEffect(new DestroyTargetEffect());
mode.addTarget(new TargetArtifactPermanent());
this.getSpellAbility().addMode(mode);
}

View file

@ -29,8 +29,8 @@ public final class AbunasChant extends CardImpl {
this.getSpellAbility().addEffect(new GainLifeEffect(5));
//or prevent the next 5 damage that would be dealt to target creature this turn.
Mode mode = new Mode();
mode.getEffects().add(new PreventDamageToTargetEffect(Duration.EndOfTurn, 5));
mode.getTargets().add(new TargetCreaturePermanent());
mode.addEffect(new PreventDamageToTargetEffect(Duration.EndOfTurn, 5));
mode.addTarget(new TargetCreaturePermanent());
this.getSpellAbility().getModes().addMode(mode);
// Entwine {2}
this.addAbility(new EntwineAbility("{2}"));

View file

@ -39,14 +39,14 @@ public final class AbzanCharm extends CardImpl {
// *You draw two cards and you lose 2 life
Mode mode = new Mode();
mode.getEffects().add(new DrawCardSourceControllerEffect(2));
mode.getEffects().add(new LoseLifeSourceControllerEffect(2));
mode.addEffect(new DrawCardSourceControllerEffect(2));
mode.addEffect(new LoseLifeSourceControllerEffect(2));
this.getSpellAbility().addMode(mode);
// *Distribute two +1/+1 counters among one or two target creatures.
mode = new Mode();
mode.getEffects().add(new DistributeCountersEffect(CounterType.P1P1, 2, false, "one or two target creatures"));
mode.getTargets().add(new TargetCreaturePermanentAmount(2));
mode.addEffect(new DistributeCountersEffect(CounterType.P1P1, 2, false, "one or two target creatures"));
mode.addTarget(new TargetCreaturePermanentAmount(2));
this.getSpellAbility().addMode(mode);
}

View file

@ -98,19 +98,19 @@ class AcolytesRewardEffect extends PreventionEffectImpl {
result = true;
}
if (toPrevent > 0) {
game.informPlayers(new StringBuilder("Acolyte's Reward ").append("prevented ").append(toPrevent).append(" to ").append(targetCreature.getName()).toString());
game.informPlayers("Acolyte's Reward prevented " + toPrevent + " to " + targetCreature.getName());
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE,
source.getControllerId(), source.getSourceId(), source.getControllerId(), toPrevent));
Player targetPlayer = game.getPlayer(source.getTargets().get(1).getFirstTarget());
if (targetPlayer != null) {
targetPlayer.damage(toPrevent, source.getSourceId(), game, false, true);
game.informPlayers(new StringBuilder("Acolyte's Reward ").append("deals ").append(toPrevent).append(" damage to ").append(targetPlayer.getLogName()).toString());
game.informPlayers("Acolyte's Reward deals " + toPrevent + " damage to " + targetPlayer.getLogName());
} else {
Permanent targetDamageCreature = game.getPermanent(source.getTargets().get(1).getFirstTarget());
if (targetDamageCreature != null) {
targetDamageCreature.damage(toPrevent, source.getSourceId(), game, false, true);
game.informPlayers(new StringBuilder("Acolyte's Reward ").append("deals ").append(toPrevent).append(" damage to ").append(targetDamageCreature.getName()).toString());
game.informPlayers("Acolyte's Reward deals " + toPrevent + " damage to " + targetDamageCreature.getName());
}
}
}

View file

@ -38,8 +38,8 @@ public final class ActiveVolcano extends CardImpl {
// or return target Island to its owner's hand.
Mode mode = new Mode();
mode.getEffects().add(new ReturnToHandTargetEffect());
mode.getTargets().add(new TargetPermanent(filterIsland));
mode.addEffect(new ReturnToHandTargetEffect());
mode.addTarget(new TargetPermanent(filterIsland));
this.getSpellAbility().addMode(mode);
}

View file

@ -64,7 +64,7 @@ class AdviceFromTheFaeEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject mageObject = game.getObject(source.getSourceId());
if (controller != null) {
if (controller != null && mageObject != null) {
Set<Card> topCards = controller.getLibrary().getTopCards(game, 5);
Cards cardsFromLibrary = new CardsImpl();
for (Card card : topCards) {

View file

@ -0,0 +1,45 @@
package mage.cards.a;
import mage.MageInt;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.keyword.AdaptEffect;
import mage.abilities.keyword.FlyingAbility;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.SubType;
import java.util.UUID;
/**
* @author TheElk801
*/
public final class Aeromunculus extends CardImpl {
public Aeromunculus(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{1}{G}{U}");
this.subtype.add(SubType.HOMUNCULUS);
this.subtype.add(SubType.MUTANT);
this.power = new MageInt(2);
this.toughness = new MageInt(3);
// Flying
this.addAbility(FlyingAbility.getInstance());
// {2}{G}{U}: Adapt 1.
this.addAbility(new SimpleActivatedAbility(
new AdaptEffect(1), new ManaCostsImpl("{2}{G}{U}")
));
}
public Aeromunculus(final Aeromunculus card) {
super(card);
}
@Override
public Aeromunculus copy() {
return new Aeromunculus(this);
}
}

View file

@ -33,7 +33,7 @@ public final class AetherShockwave extends CardImpl {
this.getSpellAbility().addEffect(new TapAllEffect(filterSpirit));
Mode mode = new Mode();
mode.getEffects().add(new TapAllEffect(filterNonSpirit));
mode.addEffect(new TapAllEffect(filterNonSpirit));
this.getSpellAbility().addMode(mode);
}

View file

@ -31,8 +31,8 @@ public final class Afterburn extends CardImpl {
// Remove target creature from combat.
Mode mode = new Mode();
mode.getEffects().add(new RemoveFromCombatTargetEffect());
mode.getTargets().add(new TargetCreaturePermanent());
mode.addEffect(new RemoveFromCombatTargetEffect());
mode.addTarget(new TargetCreaturePermanent());
this.getSpellAbility().addMode(mode);
}

View file

@ -36,7 +36,7 @@ public final class AinokGuide extends CardImpl {
// * Search your library for a basic land card, reveal it, then shuffle your library and put that card on top of it.
Mode mode = new Mode();
mode.getEffects().add(new SearchLibraryPutOnLibraryEffect(new TargetCardInLibrary(StaticFilters.FILTER_CARD_BASIC_LAND), true, true));
mode.addEffect(new SearchLibraryPutOnLibraryEffect(new TargetCardInLibrary(StaticFilters.FILTER_CARD_BASIC_LAND), true, true));
ability.addMode(mode);
this.addAbility(ability);

View file

@ -26,8 +26,8 @@ public final class AlabasterPotion extends CardImpl {
this.getSpellAbility().addEffect(new GainLifeTargetEffect(new ManacostVariableValue()));
this.getSpellAbility().addTarget(new TargetPlayer());
Mode mode = new Mode();
mode.getEffects().add(new PreventDamageToTargetEffect(Duration.EndOfTurn, false, true, new ManacostVariableValue()));
mode.getTargets().add(new TargetAnyTarget());
mode.addEffect(new PreventDamageToTargetEffect(Duration.EndOfTurn, false, true, new ManacostVariableValue()));
mode.addTarget(new TargetAnyTarget());
this.getSpellAbility().addMode(mode);
}

View file

@ -65,8 +65,8 @@ class WellEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
int life = 2 * game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game);
if (player != null) {
int life = 2 * game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game);
player.gainLife(life, game, source);
}
return true;

View file

@ -27,8 +27,8 @@ public final class AlleyEvasion extends CardImpl {
// Return target creature you control to its owner's hand.
Mode mode = new Mode();
mode.getEffects().add(new ReturnToHandTargetEffect());
mode.getTargets().add(new TargetControlledCreaturePermanent());
mode.addEffect(new ReturnToHandTargetEffect());
mode.addTarget(new TargetControlledCreaturePermanent());
this.getSpellAbility().addMode(mode);
}

View file

@ -100,7 +100,7 @@ class AllianceOfArmsEffect extends OneShotEffect {
payed = true;
}
}
game.informPlayers(new StringBuilder(player.getLogName()).append(" pays {").append(xValue).append("}.").toString());
game.informPlayers(player.getLogName() + " pays {" + xValue + "}.");
return xValue;
}
}

View file

@ -1,7 +1,5 @@
package mage.cards.a;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.condition.common.SourceIsSpellCondition;
@ -17,29 +15,31 @@ import mage.filter.predicate.mageobject.ConvertedManaCostPredicate;
import mage.game.Game;
import mage.players.Player;
import java.util.UUID;
/**
* 10/4/2004 The mana cost of the creatures being cast is still the stated cost on the card,
* even though you did not pay the cost.
* 10/4/2004 The mana cost of the creatures being cast is still the stated cost on the card,
* even though you did not pay the cost.
* 10/4/2004 Aluren checks the actual printed cost on the creature card, and is not affected
* by things which allow you to cast the spell for less.
* 10/4/2004 You can't choose to cast a creature as though it had flash via Aluren and still pay the mana cost.
* You either cast the creature normally, or via Aluren without paying the mana cost.
* 10/4/2004 You can't use Aluren when casting a creature using another alternate means,
* such as the Morph ability.
* 8/1/2008 If creature with X in its cost is cast this way, X can only be 0.
*
* by things which allow you to cast the spell for less.
* 10/4/2004 You can't choose to cast a creature as though it had flash via Aluren and still pay the mana cost.
* You either cast the creature normally, or via Aluren without paying the mana cost.
* 10/4/2004 You can't use Aluren when casting a creature using another alternate means,
* such as the Morph ability.
* 8/1/2008 If creature with X in its cost is cast this way, X can only be 0.
*
* @author emerald000
*/
public final class Aluren extends CardImpl {
private static final FilterCreatureCard filter = new FilterCreatureCard("creature cards with converted mana cost 3 or less");
static {
filter.add(new ConvertedManaCostPredicate(ComparisonType.FEWER_THAN, 4));
}
public Aluren(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{2}{G}{G}");
super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{2}{G}{G}");
// Any player may play creature cards with converted mana cost 3 or less without paying their mana cost
@ -63,15 +63,15 @@ public final class Aluren extends CardImpl {
}
class AlurenRuleEffect extends ContinuousEffectImpl {
private static final FilterCreatureCard filter = new FilterCreatureCard("creature cards with converted mana cost 3 or less");
static {
filter.add(new ConvertedManaCostPredicate(ComparisonType.FEWER_THAN, 4));
}
private static AlternativeCostSourceAbility alternativeCastingCostAbility = new AlternativeCostSourceAbility(null, SourceIsSpellCondition.instance, null, filter, true);
private static AlternativeCostSourceAbility alternativeCastingCostAbility = new AlternativeCostSourceAbility(null, SourceIsSpellCondition.instance, null, filter, true);
public AlurenRuleEffect() {
super(Duration.WhileOnBattlefield, Outcome.Detriment);
staticText = "Any player may cast creature cards with converted mana cost 3 or less without paying their mana cost";
@ -90,12 +90,12 @@ class AlurenRuleEffect extends ContinuousEffectImpl {
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
for (UUID playerId: game.getState().getPlayersInRange(controller.getId(), game)){
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
player.getAlternativeSourceCosts().add(alternativeCastingCostAbility);
}
}
}
return true;
}
return false;
@ -110,47 +110,4 @@ class AlurenRuleEffect extends ContinuousEffectImpl {
public boolean hasLayer(Layer layer) {
return layer == Layer.RulesEffects;
}
}
//class AlurenEffect extends CostModificationEffectImpl {
//
// AlurenEffect() {
// super(Duration.WhileOnBattlefield, Outcome.PlayForFree, CostModificationType.SET_COST);
// this.staticText = "Any player may play creature cards with converted mana cost 3 or less without paying their mana cost";
// }
//
// AlurenEffect(final AlurenEffect effect) {
// super(effect);
// }
//
// @Override
// public boolean apply(Game game, Ability source, Ability abilityToModify) {
// SpellAbility spellAbility = (SpellAbility) abilityToModify;
// spellAbility.getManaCostsToPay().clear();
// return true;
// }
//
// @Override
// public boolean applies(Ability abilityToModify, Ability source, Game game) {
// if (abilityToModify instanceof SpellAbility) {
// Card sourceCard = game.getCard(abilityToModify.getSourceId());
// StackObject stackObject = game.getStack().getStackObject(abilityToModify.getSourceId());
// if (stackObject != null && stackObject instanceof Spell) {
// if (sourceCard != null && sourceCard.isCreature() && sourceCard.getConvertedManaCost() <= 3) {
// Player player = game.getPlayer(stackObject.getControllerId());
// String message = "Cast " + sourceCard.getName() + " without paying its mana costs?";
// if (player != null &&
// (CardUtil.isCheckPlayableMode(abilityToModify) || player.chooseUse(outcome, message, game))) {
// return true;
// }
// }
// }
// }
// return false;
// }
//
// @Override
// public AlurenEffect copy() {
// return new AlurenEffect(this);
// }
//}
}

View file

@ -1,6 +1,7 @@
package mage.cards.a;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.AttacksWithCreaturesTriggeredAbility;
@ -15,7 +16,6 @@ import mage.game.Game;
import mage.players.Player;
/**
*
* @author TheElk801
*/
public final class AncestorDragon extends CardImpl {
@ -46,8 +46,6 @@ public final class AncestorDragon extends CardImpl {
class AncestorDragonEffect extends OneShotEffect {
private int attackers;
public AncestorDragonEffect() {
super(Outcome.GainLife);
staticText = "you gain 1 life for each attacking creature";
@ -65,10 +63,9 @@ class AncestorDragonEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Player you = game.getPlayer(source.getControllerId());
attackers = game.getCombat().getAttackers().size();
if (you != null) {
int attackers = game.getCombat().getAttackers().size();
you.gainLife(attackers, game, source);
attackers = 0;
return true;
}
return false;

View file

@ -64,8 +64,8 @@ class AngelsTrumpetTapEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(game.getActivePlayerId());
int count = 0;
if (player != null) {
int count = 0;
for (Permanent creature : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, player.getId(), game)) {
// Untapped creatures are safe.
if (creature.isTapped()) {

View file

@ -1,9 +1,5 @@
package mage.cards.a;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.common.AsEntersBattlefieldAbility;
import mage.abilities.common.SimpleStaticAbility;
@ -20,8 +16,11 @@ import mage.game.stack.Spell;
import mage.game.stack.StackObject;
import mage.players.Player;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
/**
*
* @author TheElk801
*/
public final class ArcaneAdaptation extends CardImpl {
@ -70,14 +69,14 @@ class ConspyEffect extends ContinuousEffectImpl {
// in graveyard
for (UUID cardId : controller.getGraveyard()) {
Card card = game.getCard(cardId);
if (card.isCreature() && !card.hasSubtype(subType, game)) {
if (card != null && card.isCreature() && !card.hasSubtype(subType, game)) {
game.getState().getCreateCardAttribute(card, game).getSubtype().add(subType);
}
}
// on Hand
for (UUID cardId : controller.getHand()) {
Card card = game.getCard(cardId);
if (card.isCreature() && !card.hasSubtype(subType, game)) {
if (card != null && card.isCreature() && !card.hasSubtype(subType, game)) {
game.getState().getCreateCardAttribute(card, game).getSubtype().add(subType);
}
}
@ -97,13 +96,13 @@ class ConspyEffect extends ContinuousEffectImpl {
for (UUID commanderId : controller.getCommandersIds()) {
if (game.getState().getZone(commanderId) == Zone.COMMAND) {
Card card = game.getCard(commanderId);
if (card.isCreature() && !card.hasSubtype(subType, game)) {
if (card != null && card.isCreature() && !card.hasSubtype(subType, game)) {
game.getState().getCreateCardAttribute(card, game).getSubtype().add(subType);
}
}
}
// creature spells you control
for (Iterator<StackObject> iterator = game.getStack().iterator(); iterator.hasNext();) {
for (Iterator<StackObject> iterator = game.getStack().iterator(); iterator.hasNext(); ) {
StackObject stackObject = iterator.next();
if (stackObject instanceof Spell
&& stackObject.isControlledBy(source.getControllerId())

View file

@ -1,4 +1,3 @@
package mage.cards.a;
import mage.MageInt;
@ -97,26 +96,29 @@ class ArcaneArtisanCreateTokenEffect extends OneShotEffect {
return false;
}
Card card = game.getCard(target.getFirstTarget());
player.moveCards(card, Zone.EXILED, source, game);
if (!card.isCreature()) {
if (!player.moveCards(card, Zone.EXILED, source, game)) {
return false;
}
CreateTokenCopyTargetEffect effect = new CreateTokenCopyTargetEffect(player.getId());
effect.setTargetPointer(new FixedTarget(card.getId(), game));
effect.apply(game, source);
Object object = game.getState().getValue(CardUtil.getCardZoneString("_tokensCreated", source.getSourceId(), game));
Set<UUID> tokensCreated;
if (object != null) {
tokensCreated = (Set<UUID>) object;
} else {
tokensCreated = new HashSet<>();
}
for (Permanent perm : effect.getAddedPermanent()) {
if (perm != null) {
tokensCreated.add(perm.getId());
if (card.isCreature()) {
CreateTokenCopyTargetEffect effect = new CreateTokenCopyTargetEffect(player.getId());
effect.setTargetPointer(new FixedTarget(card.getId(), game));
effect.apply(game, source);
Object object = game.getState().getValue(CardUtil.getCardZoneString("_tokensCreated", source.getSourceId(), game));
Set<UUID> tokensCreated;
if (object != null) {
tokensCreated = (Set<UUID>) object;
} else {
tokensCreated = new HashSet<>();
}
for (Permanent perm : effect.getAddedPermanent()) {
if (perm != null) {
tokensCreated.add(perm.getId());
}
}
game.getState().setValue(CardUtil.getCardZoneString("_tokensCreated", source.getSourceId(), game), tokensCreated);
}
game.getState().setValue(CardUtil.getCardZoneString("_tokensCreated", source.getSourceId(), game), tokensCreated);
return true;
}
}

View file

@ -1,4 +1,3 @@
package mage.cards.a;
import java.util.UUID;
@ -26,24 +25,32 @@ import mage.watchers.Watcher;
*
* @author stravant
*
* Note, this card is pretty hacky in its implementation due to the fact that the alternative cost system doesn't
* really support "once each turn" alternative costs in an obvious way, but it should work in all scenarios as far
* as I can see.
* Note, this card is pretty hacky in its implementation due to the fact that
* the alternative cost system doesn't really support "once each turn"
* alternative costs in an obvious way, but it should work in all scenarios as
* far as I can see.
*/
public final class AsForetold extends CardImpl {
public AsForetold(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{2}{U}");
// At the beginning of your upkeep, put a time counter on As Foretold.
addAbility(
new BeginningOfUpkeepTriggeredAbility(
new AddCountersSourceEffect(CounterType.TIME.createInstance(), new StaticValue(1), true),
new AddCountersSourceEffect(
CounterType.TIME.createInstance(),
new StaticValue(1),
true),
TargetController.YOU,
/* optional = */false));
/* optional = */ false));
// Once each turn, you may pay {0} rather than pay the mana cost for a spell you cast with converted mana cost X or less, where X is the number of time counters on As Foretold.
addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new AsForetoldAddAltCostEffect()), new AsForetoldAltCostUsedWatcher());
addAbility(new SimpleStaticAbility(
Zone.BATTLEFIELD,
new AsForetoldAddAltCostEffect()),
new AsForetoldAltCostUsedWatcher());
}
public AsForetold(final AsForetold card) {
@ -60,6 +67,7 @@ public final class AsForetold extends CardImpl {
* Used to determine what cast objects to apply the alternative cost to
*/
class SpellWithManaCostLessThanOrEqualToCondition implements Condition {
private int counters;
public SpellWithManaCostLessThanOrEqualToCondition(int counters) {
@ -69,17 +77,21 @@ class SpellWithManaCostLessThanOrEqualToCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
MageObject object = game.getObject(source.getSourceId());
return object != null && !object.isLand() && object.getConvertedManaCost() <= counters;
return object != null
&& !object.isLand()
&& object.getConvertedManaCost() <= counters;
}
}
/**
* Special AlternativeCostSourceAbility implementation. We wrap the call to askToActivateAlternativeCosts in order to
* tell when the alternative cost is used, and mark it as having been used this turn in the watcher
* Special AlternativeCostSourceAbility implementation. We wrap the call to
* askToActivateAlternativeCosts in order to tell when the alternative cost is
* used, and mark it as having been used this turn in the watcher
*/
class AsForetoldAlternativeCost extends AlternativeCostSourceAbility {
private UUID sourceAsForetold;
boolean activated;
AsForetoldAlternativeCost(UUID sourceAsForetold, int timeCounters) {
super(new ManaCostsImpl("{0}"), new SpellWithManaCostLessThanOrEqualToCondition(timeCounters));
@ -89,6 +101,7 @@ class AsForetoldAlternativeCost extends AlternativeCostSourceAbility {
AsForetoldAlternativeCost(final AsForetoldAlternativeCost ability) {
super(ability);
this.sourceAsForetold = ability.sourceAsForetold;
this.activated = ability.activated;
}
@Override
@ -98,24 +111,34 @@ class AsForetoldAlternativeCost extends AlternativeCostSourceAbility {
@Override
public boolean askToActivateAlternativeCosts(Ability ability, Game game) {
boolean activated = super.askToActivateAlternativeCosts(ability, game);
if (activated) {
// Get the watcher
AsForetoldAltCostUsedWatcher asForetoldAltCostUsedWatcher =
(AsForetoldAltCostUsedWatcher)game.getState().getWatchers()
.get("asForetoldAltCostUsedWatcher", sourceAsForetold);
Player controller = game.getPlayer(ability.getControllerId());
Permanent asForetold = game.getPermanent(sourceAsForetold);
if (controller != null
&& asForetold != null) {
if (controller.chooseUse(Outcome.Neutral, "Do you wish to use " + asForetold.getLogName() + " to pay the alternative cost ?", ability, game)) {
activated = super.askToActivateAlternativeCosts(ability, game);
if (activated) {
// Get the watcher
AsForetoldAltCostUsedWatcher asForetoldAltCostUsedWatcher
= (AsForetoldAltCostUsedWatcher) game.getState().getWatchers()
.get("asForetoldAltCostUsedWatcher", sourceAsForetold);
// Mark as used
asForetoldAltCostUsedWatcher.markUsedThisTurn();
// Mark as used
asForetoldAltCostUsedWatcher.markUsedThisTurn();
}
}
}
return activated;
}
}
/**
* The continuous effect that adds the option to pay the alternative cost if we haven't used it yet this turn
* The continuous effect that adds the option to pay the alternative cost if we
* haven't used it yet this turn
*/
class AsForetoldAddAltCostEffect extends ContinuousEffectImpl {
public AsForetoldAddAltCostEffect() {
super(Duration.WhileOnBattlefield, Outcome.Benefit);
staticText = "Once each turn, you may pay {0} rather than pay the mana cost for a spell you cast with converted mana cost X or less, where X is the number of time counters on {this}.";
@ -137,8 +160,8 @@ class AsForetoldAddAltCostEffect extends ContinuousEffectImpl {
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (sourcePermanent != null) {
// Get the watcher
AsForetoldAltCostUsedWatcher asForetoldAltCostUsedWatcher =
(AsForetoldAltCostUsedWatcher)game.getState().getWatchers()
AsForetoldAltCostUsedWatcher asForetoldAltCostUsedWatcher
= (AsForetoldAltCostUsedWatcher) game.getState().getWatchers()
.get("asForetoldAltCostUsedWatcher", sourcePermanent.getId());
// If we haven't used it yet this turn, give the option of using the zero alternative cost
@ -166,13 +189,15 @@ class AsForetoldAddAltCostEffect extends ContinuousEffectImpl {
}
/**
* Watcher used as extra storage to record whether a given As Foretold has been used this turn.
* Technically speaking this watcher doesn't *watch* any GameEvents, but it does "watch" the
* alternative cost being used. That just isn't possible to watch through a game event. It's still
* helpfull to co-op the Watcher system for this since it automatically handles ZoneChangeCounter
* Watcher used as extra storage to record whether a given As Foretold has been
* used this turn. Technically speaking this watcher doesn't *watch* any
* GameEvents, but it does "watch" the alternative cost being used. That just
* isn't possible to watch through a game event. It's still helpful to co-op the
* Watcher system for this since it automatically handles ZoneChangeCounter
* stuff and resetting the condition at the end of the turn.
*/
class AsForetoldAltCostUsedWatcher extends Watcher {
public AsForetoldAltCostUsedWatcher() {
super("asForetoldAltCostUsedWatcher", WatcherScope.CARD);
}
@ -198,4 +223,4 @@ class AsForetoldAltCostUsedWatcher extends Watcher {
public AsForetoldAltCostUsedWatcher copy() {
return new AsForetoldAltCostUsedWatcher(this);
}
}
}

View file

@ -1,6 +1,7 @@
package mage.cards.a;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.DestroyTargetEffect;
@ -21,7 +22,6 @@ import mage.target.TargetPermanent;
import mage.target.common.TargetCardInLibrary;
/**
*
* @author TheElk801
*/
public final class AssassinsTrophy extends CardImpl {
@ -74,17 +74,19 @@ class AssassinsTrophyEffect extends OneShotEffect {
Permanent permanent = game.getPermanentOrLKIBattlefield(source.getFirstTarget());
if (permanent != null) {
Player controller = game.getPlayer(permanent.getControllerId());
if (controller.chooseUse(Outcome.PutLandInPlay, "Do you wish to search for a basic land, put it onto the battlefield and then shuffle your library?", source, game)) {
TargetCardInLibrary target = new TargetCardInLibrary(StaticFilters.FILTER_CARD_BASIC_LAND);
if (controller.searchLibrary(target, game)) {
Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
if (card != null) {
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
if (controller != null) {
if (controller.chooseUse(Outcome.PutLandInPlay, "Do you wish to search for a basic land, put it onto the battlefield and then shuffle your library?", source, game)) {
TargetCardInLibrary target = new TargetCardInLibrary(StaticFilters.FILTER_CARD_BASIC_LAND);
if (controller.searchLibrary(target, game)) {
Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
if (card != null) {
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
}
}
controller.shuffleLibrary(source, game);
}
controller.shuffleLibrary(source, game);
return true;
}
return true;
}
return false;
}

View file

@ -55,7 +55,7 @@ public final class AtalyaSamiteMaster extends CardImpl {
// or you gain X life
Mode mode = new Mode();
mode.getEffects().add(new GainLifeEffect(new ManacostVariableValue()).setText("You gain X life. Spend only white mana on X."));
mode.addEffect(new GainLifeEffect(new ManacostVariableValue()).setText("You gain X life. Spend only white mana on X."));
ability.addMode(mode);
this.addAbility(ability);

View file

@ -35,22 +35,22 @@ public final class AtarkasCommand extends CardImpl {
// or Atarka's Command deals 3 damage to each opponent;
Mode mode = new Mode();
mode.getEffects().add(new DamagePlayersEffect(3, TargetController.OPPONENT));
mode.addEffect(new DamagePlayersEffect(3, TargetController.OPPONENT));
this.getSpellAbility().addMode(mode);
// or You may put a land card from your hand onto the battlefield;
mode = new Mode();
mode.getEffects().add(new PutCardFromHandOntoBattlefieldEffect(StaticFilters.FILTER_CARD_LAND_A));
mode.addEffect(new PutCardFromHandOntoBattlefieldEffect(StaticFilters.FILTER_CARD_LAND_A));
this.getSpellAbility().addMode(mode);
// or Creatures you control get +1/+1 and gain reach until the end of turn.
mode = new Mode();
Effect effect = new BoostControlledEffect(1, 1, Duration.EndOfTurn);
effect.setText("Creatures you control get +1/+1");
mode.getEffects().add(effect);
mode.addEffect(effect);
effect = new GainAbilityControlledEffect(ReachAbility.getInstance(), Duration.EndOfTurn);
effect.setText("and gain reach until the end of turn");
mode.getEffects().add(effect);
mode.addEffect(effect);
this.getSpellAbility().addMode(mode);
}

View file

@ -99,7 +99,7 @@ class AthreosGodOfPassageReturnEffect extends OneShotEffect {
if (opponent != null) {
Cost cost = new PayLifeCost(3);
if (cost.canPay(source, source.getSourceId(), opponent.getId(), game)
&& opponent.chooseUse(outcome, new StringBuilder("Pay 3 live to prevent that ").append(creature.getLogName()).append(" returns to ").append(controller.getLogName()).append("'s hand?").toString(), source, game)) {
&& opponent.chooseUse(outcome, "Pay 3 life to prevent that " + creature.getLogName() + " returns to " + controller.getLogName() + "'s hand?", source, game)) {
if (cost.pay(source, game, source.getSourceId(), opponent.getId(), false, null)) {
paid = true;
}

View file

@ -37,15 +37,15 @@ public final class AustereCommand extends CardImpl {
this.getSpellAbility().addEffect(new DestroyAllEffect(new FilterArtifactPermanent("artifacts")));
// or destroy all enchantments;
Mode mode = new Mode();
mode.getEffects().add(new DestroyAllEffect(new FilterEnchantmentPermanent("enchantments")));
mode.addEffect(new DestroyAllEffect(new FilterEnchantmentPermanent("enchantments")));
this.getSpellAbility().getModes().addMode(mode);
// or destroy all creatures with converted mana cost 3 or less;
mode = new Mode();
mode.getEffects().add(new DestroyAllEffect(filter3orLess));
mode.addEffect(new DestroyAllEffect(filter3orLess));
this.getSpellAbility().getModes().addMode(mode);
// or destroy all creatures with converted mana cost 4 or greater.
mode = new Mode();
mode.getEffects().add(new DestroyAllEffect(filter4orMore));
mode.addEffect(new DestroyAllEffect(filter4orMore));
this.getSpellAbility().getModes().addMode(mode);
}

View file

@ -91,9 +91,7 @@ class AvenEffect extends ContinuousEffectImpl {
@Override
public String getText(Mode mode) {
StringBuilder sb = new StringBuilder();
sb.append("If you do, that creature has base power and toughness 3/1 and has flying for as long as it has a feather counter on it");
return sb.toString();
return "If you do, that creature has base power and toughness 3/1 and has flying for as long as it has a feather counter on it";
}
}

View file

@ -67,7 +67,7 @@ class AvenShrineTriggeredAbility extends TriggeredAbilityImpl {
public boolean checkTrigger(GameEvent event, Game game) {
Spell spell = game.getStack().getSpell(event.getTargetId());
MageObject mageObject = game.getObject(sourceId);
if (spell != null) {
if (spell != null && mageObject != null) {
game.getState().setValue("avenShrine" + mageObject, spell);
return true;
}
@ -91,21 +91,23 @@ class AvenShrineEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
int count = 0;
MageObject mageObject = game.getObject(source.getSourceId());
Spell spell = (Spell) game.getState().getValue("avenShrine" + mageObject);
if (spell != null) {
Player controller = game.getPlayer(spell.getControllerId());
if (controller != null) {
String name = spell.getName();
FilterCard filterCardName = new FilterCard();
filterCardName.add(new NamePredicate(name));
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
count += player.getGraveyard().count(filterCardName, game);
if(mageObject != null) {
Spell spell = (Spell) game.getState().getValue("avenShrine" + mageObject);
if (spell != null) {
Player controller = game.getPlayer(spell.getControllerId());
if (controller != null) {
String name = spell.getName();
FilterCard filterCardName = new FilterCard();
filterCardName.add(new NamePredicate(name));
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
count += player.getGraveyard().count(filterCardName, game);
}
}
controller.gainLife(count, game, source);
return true;
}
controller.gainLife(count, game, source);
return true;
}
}
return false;

View file

@ -38,8 +38,8 @@ public final class AvenSurveyor extends CardImpl {
// * Return target creature to its owner's hand
Mode mode = new Mode();
mode.getEffects().add(new ReturnToHandTargetEffect());
mode.getTargets().add(new TargetCreaturePermanent());
mode.addEffect(new ReturnToHandTargetEffect());
mode.addTarget(new TargetCreaturePermanent());
ability.addMode(mode);
this.addAbility(ability);
}

View file

@ -78,6 +78,9 @@ class AyliEternalPilgrimCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
return player.getLife() >= game.getLife() + 10;
if(player != null) {
return player.getLife() >= game.getLife() + 10;
}
return false;
}
}

View file

@ -29,13 +29,13 @@ public final class AzoriusCharm extends CardImpl {
// or draw a card;
Mode mode = new Mode();
mode.getEffects().add(new DrawCardSourceControllerEffect(1));
mode.addEffect(new DrawCardSourceControllerEffect(1));
this.getSpellAbility().addMode(mode);
// or put target attacking or blocking creature on top of its owner's library.
mode = new Mode();
mode.getTargets().add(new TargetAttackingOrBlockingCreature());
mode.getEffects().add(new PutOnLibraryTargetEffect(true));
mode.addTarget(new TargetAttackingOrBlockingCreature());
mode.addEffect(new PutOnLibraryTargetEffect(true));
this.getSpellAbility().addMode(mode);
}

View file

@ -106,7 +106,7 @@ class BalaGedThiefEffect extends OneShotEffect {
Card card = revealedCards.get(targetInHand.getFirstTarget(), game);
if (card != null) {
targetPlayer.discard(card, source, game);
game.informPlayers(new StringBuilder("Bala Ged Thief: ").append(targetPlayer.getLogName()).append(" discarded ").append(card.getName()).toString());
game.informPlayers("Bala Ged Thief: " + targetPlayer.getLogName() + " discarded " + card.getName());
}
}
return true;

View file

@ -33,8 +33,8 @@ public final class BalmOfRestoration extends CardImpl {
// or prevent the next 2 damage that would be dealt to any target this turn.
Mode mode = new Mode();
mode.getEffects().add(new PreventDamageToTargetEffect(Duration.EndOfTurn, 2));
mode.getTargets().add(new TargetAnyTarget());
mode.addEffect(new PreventDamageToTargetEffect(Duration.EndOfTurn, 2));
mode.addTarget(new TargetAnyTarget());
ability.addMode(mode);
this.addAbility(ability);

View file

@ -112,7 +112,7 @@ class BaneAlleyBrokerDrawExileEffect extends OneShotEffect {
Card card = game.getCard(target.getFirstTarget());
MageObject sourceObject = game.getObject(source.getSourceId());
if (card != null && sourceObject != null) {
if (card.moveToExile(CardUtil.getCardExileZoneId(game, source), new StringBuilder(sourceObject.getName()).toString(), source.getSourceId(), game)) {
if (card.moveToExile(CardUtil.getCardExileZoneId(game, source), sourceObject.getName(), source.getSourceId(), game)) {
card.setFaceDown(true, game);
return true;
}

View file

@ -36,13 +36,13 @@ public final class BantCharm extends CardImpl {
this.getSpellAbility().addTarget(new TargetArtifactPermanent());
// or put target creature on the bottom of its owner's library;
Mode mode = new Mode();
mode.getEffects().add(new PutOnLibraryTargetEffect(false));
mode.getTargets().add(new TargetCreaturePermanent());
mode.addEffect(new PutOnLibraryTargetEffect(false));
mode.addTarget(new TargetCreaturePermanent());
this.getSpellAbility().addMode(mode);
// or counter target instant spell.
mode = new Mode();
mode.getEffects().add(new CounterTargetEffect());
mode.getTargets().add(new TargetSpell(filter));
mode.addEffect(new CounterTargetEffect());
mode.addTarget(new TargetSpell(filter));
this.getSpellAbility().addMode(mode);
}

View file

@ -26,8 +26,8 @@ public final class BarbedLightning extends CardImpl {
// or Barbed Lightning deals 3 damage to target player.
Mode mode = new Mode();
mode.getEffects().add(new DamageTargetEffect(3));
mode.getTargets().add(new TargetPlayerOrPlaneswalker());
mode.addEffect(new DamageTargetEffect(3));
mode.addTarget(new TargetPlayerOrPlaneswalker());
this.getSpellAbility().getModes().addMode(mode);
// Entwine {2}

View file

@ -67,16 +67,18 @@ class BarrinsSpiteEffect extends OneShotEffect {
Permanent creature = game.getPermanent(targetId);
if (creature != null) {
Player controllerOfCreature = game.getPlayer(creature.getControllerId());
if ((count == 0
&& controllerOfCreature.chooseUse(Outcome.Sacrifice, "Sacrifice " + creature.getLogName() + '?', source, game))
|| (count == 1
&& !sacrificeDone)) {
creature.sacrifice(source.getId(), game);
sacrificeDone = true;
} else {
creature.moveToZone(Zone.HAND, source.getId(), game, false);
if(controllerOfCreature != null) {
if ((count == 0
&& controllerOfCreature.chooseUse(Outcome.Sacrifice, "Sacrifice " + creature.getLogName() + '?', source, game))
|| (count == 1
&& !sacrificeDone)) {
creature.sacrifice(source.getId(), game);
sacrificeDone = true;
} else {
creature.moveToZone(Zone.HAND, source.getId(), game, false);
}
count++;
}
count++;
}
}
return true;

View file

@ -2,6 +2,7 @@
package mage.cards.b;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
@ -17,13 +18,12 @@ import mage.game.events.GameEvent.EventType;
import mage.players.Player;
/**
*
* @author emerald000
*/
public final class BattletideAlchemist extends CardImpl {
public BattletideAlchemist(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{3}{W}{W}");
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{3}{W}{W}");
this.subtype.add(SubType.KITHKIN, SubType.CLERIC);
this.power = new MageInt(3);
this.toughness = new MageInt(4);
@ -63,7 +63,7 @@ class BattletideAlchemistEffect extends PreventionEffectImpl {
boolean result = false;
Player controller = game.getPlayer(source.getControllerId());
Player targetPlayer = game.getPlayer(event.getTargetId());
if (controller != null) {
if (controller != null && targetPlayer != null) {
int numberOfClericsControlled = new PermanentsOnBattlefieldCount(new FilterControlledCreaturePermanent(SubType.CLERIC, "Clerics")).calculate(game, source, this);
int toPrevent = Math.min(numberOfClericsControlled, event.getAmount());
if (toPrevent > 0 && controller.chooseUse(Outcome.PreventDamage, "Prevent " + toPrevent + " damage to " + targetPlayer.getName() + '?', source, game)) {
@ -71,20 +71,18 @@ class BattletideAlchemistEffect extends PreventionEffectImpl {
if (!game.replaceEvent(preventEvent)) {
if (event.getAmount() >= toPrevent) {
event.setAmount(event.getAmount() - toPrevent);
}
else {
} else {
event.setAmount(0);
result = true;
}
if (toPrevent > 0) {
game.informPlayers("Battletide Alchemist prevented " + toPrevent + " damage to " + targetPlayer.getName());
game.fireEvent(GameEvent.getEvent(
GameEvent.EventType.PREVENTED_DAMAGE,
targetPlayer.getId(),
source.getSourceId(),
source.getControllerId(),
toPrevent));
}
game.informPlayers("Battletide Alchemist prevented " + toPrevent + " damage to " + targetPlayer.getName());
game.fireEvent(GameEvent.getEvent(
GameEvent.EventType.PREVENTED_DAMAGE,
targetPlayer.getId(),
source.getSourceId(),
source.getControllerId(),
toPrevent));
}
}
}

View file

@ -6,7 +6,7 @@ import mage.abilities.effects.common.ExileTargetEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.game.permanent.token.BeckonApparitionToken;
import mage.game.permanent.token.WhiteBlackSpiritToken;
import mage.target.common.TargetCardInGraveyard;
import java.util.UUID;
@ -22,7 +22,7 @@ public final class BeckonApparition extends CardImpl {
// Exile target card from a graveyard. Create a 1/1 white and black Spirit creature token with flying.
this.getSpellAbility().addEffect(new ExileTargetEffect());
this.getSpellAbility().addTarget(new TargetCardInGraveyard());
this.getSpellAbility().addEffect(new CreateTokenEffect(new BeckonApparitionToken(), 1));
this.getSpellAbility().addEffect(new CreateTokenEffect(new WhiteBlackSpiritToken(), 1));
}
public BeckonApparition(final BeckonApparition card) {

View file

@ -0,0 +1,45 @@
package mage.cards.b;
import mage.abilities.effects.common.DestroyTargetEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.filter.FilterPermanent;
import mage.filter.predicate.Predicates;
import mage.filter.predicate.mageobject.CardTypePredicate;
import mage.target.TargetPermanent;
import java.util.UUID;
/**
* @author TheElk801
*/
public final class Bedevil extends CardImpl {
private static final FilterPermanent filter = new FilterPermanent("artifact, creature, or planeswalker");
static {
filter.add(Predicates.or(
new CardTypePredicate(CardType.ARTIFACT),
new CardTypePredicate(CardType.CREATURE),
new CardTypePredicate(CardType.PLANESWALKER)
));
}
public Bedevil(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{B}{B}{R}");
// Destroy target artifact, creature, or planeswalker.
this.getSpellAbility().addEffect(new DestroyTargetEffect());
this.getSpellAbility().addTarget(new TargetPermanent(filter));
}
public Bedevil(final Bedevil card) {
super(card);
}
@Override
public Bedevil copy() {
return new Bedevil(this);
}
}

View file

@ -34,8 +34,8 @@ public final class BetrayalOfFlesh extends CardImpl {
this.getSpellAbility().addTarget(new TargetCreaturePermanent());
// or return target creature card from your graveyard to the battlefield.
Mode mode = new Mode();
mode.getEffects().add(new ReturnFromGraveyardToBattlefieldTargetEffect());
mode.getTargets().add(new TargetCardInYourGraveyard(StaticFilters.FILTER_CARD_CREATURE_YOUR_GRAVEYARD));
mode.addEffect(new ReturnFromGraveyardToBattlefieldTargetEffect());
mode.addTarget(new TargetCardInYourGraveyard(StaticFilters.FILTER_CARD_CREATURE_YOUR_GRAVEYARD));
this.getSpellAbility().getModes().addMode(mode);
// Entwine-Sacrifice three lands.
this.addAbility(new EntwineAbility(new SacrificeTargetCost(new TargetControlledPermanent(3, 3, new FilterControlledLandPermanent("three lands"), true))));

View file

@ -105,6 +105,6 @@ class BlazeCommandoTriggeredAbility extends TriggeredAbilityImpl {
@Override
public String getRule() {
return new StringBuilder("Whenever an instant or sorcery spell you control deals damage, ").append(super.getRule()).toString();
return "Whenever an instant or sorcery spell you control deals damage, " + super.getRule();
}
}

View file

@ -75,13 +75,15 @@ class BlazingHopeTarget extends TargetCreaturePermanent {
int count = 0;
Player controller = game.getPlayer(sourceControllerId);
MageObject targetSource = game.getObject(sourceId);
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) {
if (!targets.containsKey(permanent.getId())) {
if (notTarget || permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) {
if (controller != null && permanent.getPower().getValue() >= controller.getLife()) {
count++;
if (count >= remainingTargets) {
return true;
if(targetSource != null) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) {
if (!targets.containsKey(permanent.getId())) {
if (notTarget || permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) {
if (controller != null && permanent.getPower().getValue() >= controller.getLife()) {
count++;
if (count >= remainingTargets) {
return true;
}
}
}
}

View file

@ -54,14 +54,14 @@ public final class BlessedAlliance extends CardImpl {
Mode mode = new Mode();
effect = new UntapTargetEffect();
effect.setText("Untap up to two target creatures");
mode.getEffects().add(effect);
mode.getTargets().add(new TargetCreaturePermanent(0, 2, filterCreature, false));
mode.addEffect(effect);
mode.addTarget(new TargetCreaturePermanent(0, 2, filterCreature, false));
this.getSpellAbility().addMode(mode);
// Target opponent sacrifices an attacking creature.
mode = new Mode();
mode.getEffects().add(new SacrificeEffect(new FilterAttackingCreature(), 1, "Target opponent"));
mode.getTargets().add(new TargetPlayer(1, 1, false, filterSacrifice));
mode.addEffect(new SacrificeEffect(new FilterAttackingCreature(), 1, "Target opponent"));
mode.addTarget(new TargetPlayer(1, 1, false, filterSacrifice));
this.getSpellAbility().addMode(mode);
}

View file

@ -42,8 +42,8 @@ public final class BlindingBeam extends CardImpl {
this.getSpellAbility().addTarget(new TargetCreaturePermanent(2,2));
// or creatures don't untap during target player's next untap step.
Mode mode = new Mode();
mode.getEffects().add(new BlindingBeamEffect());
mode.getTargets().add(new TargetPlayer());
mode.addEffect(new BlindingBeamEffect());
mode.addTarget(new TargetPlayer());
this.getSpellAbility().getModes().addMode(mode);
// Entwine {1}

Some files were not shown because too many files have changed in this diff Show more