1
0
Fork 0
mirror of https://github.com/correl/mage.git synced 2025-04-06 09:13:45 -09:00

DeckEditorPanel - Fixed some existing exceptions.

This commit is contained in:
LevelX2 2018-10-10 15:37:26 +02:00
parent 681cb4b66a
commit 189984d3d6
7 changed files with 127 additions and 114 deletions
Mage.Client/src/main/java/mage/client
Mage/src/main/java/mage/cards/repository

View file

@ -1,5 +1,15 @@
package mage.client.cards;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import javax.swing.*;
import mage.cards.Card;
import mage.cards.MageCard;
import mage.cards.decks.DeckCardInfo;
@ -20,17 +30,6 @@ import mage.view.CardsView;
import org.apache.log4j.Logger;
import org.mage.card.arcane.CardRenderer;
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
* Created by StravantUser on 2016-09-20.
*/
@ -2032,6 +2031,9 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
}
private int getCardWidth() {
if (GUISizeHelper.editorCardDimension == null) {
return 200;
}
return (int) (GUISizeHelper.editorCardDimension.width * cardSizeMod);
}

View file

@ -1,6 +1,4 @@
/*
/*
* CardSelector.java
*
* Created on Feb 18, 2010, 2:49:03 PM

View file

@ -1,6 +1,4 @@
/*
/*
* DeckEditorPane.java
*
* Created on Dec 17, 2009, 9:21:42 AM
@ -105,7 +103,6 @@ public class DeckEditorPane extends MagePane {
.addComponent(container, javax.swing.GroupLayout.DEFAULT_SIZE, 626, Short.MAX_VALUE)
);
}
public DeckEditorPanel getPanel() {

View file

@ -192,6 +192,15 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnAddLandActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="btnGenDeck">
<Properties>
<Property name="text" type="java.lang.String" value="Generate"/>
<Property name="name" type="java.lang.String" value="btnGenDeck" noResource="true"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnGenDeckActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="btnSubmit">
<Properties>
<Property name="text" type="java.lang.String" value="Submit"/>
@ -210,7 +219,7 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnSubmitTimerActionPerformed"/>
</Events>
</Component>
<Component class="JComponent" name="cardInfoPane">
<Component class="org.mage.plugins.card.info.CardInfoPaneImpl" name="cardInfoPane">
</Component>
<Component class="javax.swing.JTextField" name="txtTimeRemaining">
</Component>

View file

@ -1,6 +1,14 @@
package mage.client.deckeditor;
import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.*;
import javax.swing.*;
import javax.swing.filechooser.FileFilter;
import mage.cards.Card;
import mage.cards.Sets;
import mage.cards.decks.Deck;
@ -29,18 +37,6 @@ import mage.view.CardView;
import mage.view.SimpleCardView;
import org.apache.log4j.Logger;
import javax.swing.*;
import javax.swing.Timer;
import javax.swing.filechooser.FileFilter;
import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.*;
import java.util.List;
import java.util.concurrent.*;
/**
* @author BetaSteward_at_googlemail.com
*/
@ -55,7 +51,7 @@ public class DeckEditorPanel extends javax.swing.JPanel {
private UUID tableId;
private DeckEditorMode mode;
private int timeout;
private Timer countdown;
private javax.swing.Timer countdown;
private UpdateDeckTask updateDeckTask;
private int timeToSubmit = -1;
@ -75,7 +71,7 @@ public class DeckEditorPanel extends javax.swing.JPanel {
jPanel1.setOpaque(false);
jSplitPane1.setOpaque(false);
restoreDividerLocationsAndDeckAreaSettings();
countdown = new Timer(1000,
countdown = new javax.swing.Timer(1000,
e -> {
if (--timeout > 0) {
setTimeout(timeout);
@ -456,7 +452,7 @@ public class DeckEditorPanel extends javax.swing.JPanel {
CardView cardView = (CardView) event.getSource();
int numberToSet = event.getNumber();
int cardsFound = 0;
List<Card> toDelete = new ArrayList<>();
java.util.List<Card> toDelete = new ArrayList<>();
for (Card card : cards) {
if (card.getName().equals(cardView.getName())
&& Objects.equals(card.getCardNumber(), cardView.getCardNumber())
@ -689,7 +685,6 @@ public class DeckEditorPanel extends javax.swing.JPanel {
btnGenDeck.setText("Generate");
btnGenDeck.setName("btnGenDeck");
btnGenDeck.addActionListener(evt -> btnGenDeckActionPerformed(evt));
txtTimeRemaining.setEditable(false);
txtTimeRemaining.setForeground(java.awt.Color.red);
txtTimeRemaining.setHorizontalAlignment(javax.swing.JTextField.CENTER);
@ -779,9 +774,9 @@ public class DeckEditorPanel extends javax.swing.JPanel {
.addComponent(jSplitPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 615, Short.MAX_VALUE));
}
private void processAndShowImportErrors(StringBuilder errorMessages){
private void processAndShowImportErrors(StringBuilder errorMessages) {
// show up errors list
if (errorMessages.length() > 0){
if (errorMessages.length() > 0) {
String mes = "Founded problems with deck: \n\n" + errorMessages.toString();
JOptionPane.showMessageDialog(MageFrame.getDesktop(), mes.substring(0, Math.min(1000, mes.length())), "Errors while loading deck", JOptionPane.WARNING_MESSAGE);
}
@ -813,7 +808,7 @@ public class DeckEditorPanel extends javax.swing.JPanel {
} catch (GameException e1) {
JOptionPane.showMessageDialog(MageFrame.getDesktop(), e1.getMessage(), "Error loading deck", JOptionPane.ERROR_MESSAGE);
}finally {
} finally {
MageFrame.getDesktop().setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
}
@ -845,7 +840,7 @@ public class DeckEditorPanel extends javax.swing.JPanel {
}
} catch (GameException e1) {
JOptionPane.showMessageDialog(MageFrame.getDesktop(), e1.getMessage(), "Error loading deck", JOptionPane.ERROR_MESSAGE);
}finally {
} finally {
MageFrame.getDesktop().setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
}
@ -1063,7 +1058,6 @@ public class DeckEditorPanel extends javax.swing.JPanel {
}
refreshDeck();
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private mage.client.cards.BigCard bigCard;
private javax.swing.JButton btnExit;

View file

@ -9,6 +9,8 @@ import java.util.Map;
import mage.cards.repository.ExpansionInfo;
import mage.cards.repository.ExpansionRepository;
import mage.constants.SetType;
import static mage.constants.SetType.EXPANSION;
import static mage.constants.SetType.SUPPLEMENTAL;
import mage.deck.Standard;
/**
@ -64,6 +66,13 @@ public final class ConstructedFormats {
underlyingSetCodesPerFormat.put(CUSTOM, new ArrayList<>());
final Map<String, ExpansionInfo> expansionInfo = new HashMap<>();
formats.clear(); // prevent NPE on sorting if this is not the first try
// Because this is also called in Netbeans Design view, but the object does not exist in that case,
// we have to return here to prevent exception in design view. (Does not hurt at design time)
if (!ExpansionRepository.instance.instanceInitialized) {
return;
}
for (ExpansionInfo set : ExpansionRepository.instance.getAll()) {
expansionInfo.put(set.getName(), set);
formats.add(set.getName());

View file

@ -33,6 +33,8 @@ public enum ExpansionRepository {
private Dao<ExpansionInfo, Object> expansionDao;
public boolean instanceInitialized = false;
ExpansionRepository() {
File file = new File("db");
if (!file.exists()) {
@ -48,9 +50,11 @@ public enum ExpansionRepository {
TableUtils.createTableIfNotExists(connectionSource, ExpansionInfo.class);
expansionDao = DaoManager.createDao(connectionSource, ExpansionInfo.class);
instanceInitialized = true;
} catch (SQLException ex) {
ex.printStackTrace();
}
}
public void add(ExpansionInfo expansion) {