This commit is contained in:
BetaSteward 2010-10-28 03:19:26 +00:00
parent 78e640487b
commit 3a784f59ee
88 changed files with 2521 additions and 447 deletions

View file

@ -8,7 +8,7 @@
</Border>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="new Dimension(Config.dimensions.frameWidth, Config.dimensions.frameHeight)" type="code"/>
<Connection code="(!Beans.isDesignTime())?(new Dimension(Config.dimensions.frameWidth, Config.dimensions.frameHeight)):(new Dimension(100, 100))" type="code"/>
</Property>
</Properties>
<AuxValues>

View file

@ -38,6 +38,7 @@ import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.beans.Beans;
import java.util.UUID;
import mage.client.util.Config;
import mage.client.util.Event;
@ -108,7 +109,7 @@ public class CardsList extends javax.swing.JPanel implements MouseListener {
cardArea = new javax.swing.JLayeredPane();
setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
setPreferredSize(new Dimension(Config.dimensions.frameWidth, Config.dimensions.frameHeight));
setPreferredSize((!Beans.isDesignTime())?(new Dimension(Config.dimensions.frameWidth, Config.dimensions.frameHeight)):(new Dimension(100, 100)));
setLayout(new java.awt.BorderLayout());
jScrollPane1.setViewportView(cardArea);

View file

@ -0,0 +1,70 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.client.deckeditor;
import mage.cards.decks.DeckCardLists;
import mage.sets.Sets;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class DecDeckImporter extends DeckImporterImpl {
@Override
protected void readLine(String line, DeckCardLists deckList) {
if (line.length() == 0 || line.startsWith("//")) return;
boolean sideboard = false;
if (line.startsWith("SB:")) {
line = line.substring(3).trim();
sideboard = true;
}
int delim = line.indexOf(' ');
String lineNum = line.substring(0, delim).trim();
String lineName = line.substring(delim).trim();
try {
int num = Integer.parseInt(lineNum);
String cardName = Sets.findCard(lineName);
if (cardName == null)
sbMessage.append("Could not find card: '").append(lineName).append("' at line ").append(lineCount).append("\n");
else {
for (int i = 0; i < num; i++) {
if (!sideboard)
deckList.getCards().add(cardName);
else
deckList.getSideboard().add(cardName);
}
}
}
catch (NumberFormatException nfe) {
sbMessage.append("Invalid number: ").append(lineNum).append(" at line ").append(lineCount).append("\n");
}
}
}

View file

@ -79,6 +79,10 @@
<EmptySpace max="-2" attributes="0"/>
<Component id="btnExit" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="btnImport" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
@ -99,7 +103,9 @@
<Component id="btnNew" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="btnExit" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace pref="188" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="btnImport" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="159" max="32767" attributes="0"/>
<Component id="bigCard" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
@ -157,6 +163,15 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnExitActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="btnImport">
<Properties>
<Property name="text" type="java.lang.String" value="Import"/>
<Property name="name" type="java.lang.String" value="btnImport" noResource="true"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnImportActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Container>
</SubComponents>

View file

@ -58,6 +58,7 @@ import mage.view.CardsView;
public class DeckEditorPanel extends javax.swing.JPanel {
private JFileChooser fcSelectDeck;
private JFileChooser fcImportDeck;
private Deck deck = new Deck();;
/** Creates new form DeckEditorPanel */
@ -66,6 +67,9 @@ public class DeckEditorPanel extends javax.swing.JPanel {
fcSelectDeck = new JFileChooser();
fcSelectDeck.setAcceptAllFileFilterUsed(false);
fcSelectDeck.addChoosableFileFilter(new DeckFilter());
fcImportDeck = new JFileChooser();
fcImportDeck.setAcceptAllFileFilterUsed(false);
fcImportDeck.addChoosableFileFilter(new ImportFilter());
}
public void showDeckEditor() {
@ -152,6 +156,7 @@ public class DeckEditorPanel extends javax.swing.JPanel {
btnLoad = new javax.swing.JButton();
btnNew = new javax.swing.JButton();
btnExit = new javax.swing.JButton();
btnImport = new javax.swing.JButton();
jSplitPane1.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
jSplitPane1.setResizeWeight(0.5);
@ -191,6 +196,14 @@ public class DeckEditorPanel extends javax.swing.JPanel {
}
});
btnImport.setText("Import");
btnImport.setName("btnImport"); // NOI18N
btnImport.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnImportActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
@ -211,7 +224,10 @@ public class DeckEditorPanel extends javax.swing.JPanel {
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnNew)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnExit)))
.addComponent(btnExit))
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(btnImport)))
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
@ -227,7 +243,9 @@ public class DeckEditorPanel extends javax.swing.JPanel {
.addComponent(btnLoad)
.addComponent(btnNew)
.addComponent(btnExit))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 188, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnImport)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 159, Short.MAX_VALUE)
.addComponent(bigCard, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
);
@ -306,10 +324,43 @@ public class DeckEditorPanel extends javax.swing.JPanel {
this.setVisible(false);
}//GEN-LAST:event_btnExitActionPerformed
private void btnImportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnImportActionPerformed
String lastFolder = MageFrame.getPreferences().get("lastImportFolder", "");
if (!lastFolder.isEmpty())
fcImportDeck.setCurrentDirectory(new File(lastFolder));
int ret = fcImportDeck.showOpenDialog(this);
if (ret == JFileChooser.APPROVE_OPTION) {
File file = fcImportDeck.getSelectedFile();
try {
setCursor(new Cursor(Cursor.WAIT_CURSOR));
deck = Deck.load(importDeck(file.getPath()));
} catch (Exception ex) {
Logger.getLogger(DeckEditorPanel.class.getName()).log(Level.SEVERE, null, ex);
}
finally {
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
refreshDeck();
try {
MageFrame.getPreferences().put("lastImportFolder", file.getCanonicalPath());
} catch (IOException ex) { }
}
fcImportDeck.setSelectedFile(null);
}//GEN-LAST:event_btnImportActionPerformed
public DeckCardLists importDeck(String file) {
DeckImporter importer;
if (file.endsWith("dec"))
importer = new DecDeckImporter();
else
importer = new MWSDeckImporter();
return importer.importDeck(file);
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private mage.client.cards.BigCard bigCard;
private javax.swing.JButton btnExit;
private javax.swing.JButton btnImport;
private javax.swing.JButton btnLoad;
private javax.swing.JButton btnNew;
private javax.swing.JButton btnSave;
@ -344,4 +395,31 @@ class DeckFilter extends FileFilter {
public String getDescription() {
return "Deck Files";
}
}
class ImportFilter extends FileFilter {
@Override
public boolean accept(File f) {
if (f.isDirectory())
return true;
String ext = null;
String s = f.getName();
int i = s.lastIndexOf('.');
if (i > 0 && i < s.length() - 1) {
ext = s.substring(i+1).toLowerCase();
}
if (ext != null) {
if (ext.equals("dec") || ext.equals("mwDeck"))
return true;
}
return false;
}
@Override
public String getDescription() {
return "*.dec | *.mwDeck";
}
}

View file

@ -0,0 +1,41 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.client.deckeditor;
import mage.cards.decks.DeckCardLists;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public interface DeckImporter {
public DeckCardLists importDeck(String file);
}

View file

@ -0,0 +1,78 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.client.deckeditor;
import java.io.File;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import mage.cards.decks.DeckCardLists;
import mage.client.MageFrame;
import mage.util.Logging;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public abstract class DeckImporterImpl implements DeckImporter {
private final static Logger logger = Logging.getLogger(DeckImporterImpl.class.getName());
protected StringBuilder sbMessage = new StringBuilder();
protected int lineCount;
@Override
public DeckCardLists importDeck(String file) {
File f = new File(file);
DeckCardLists deckList = new DeckCardLists();
lineCount = 0;
sbMessage.setLength(0);
try {
Scanner scanner = new Scanner(f);
try {
while (scanner.hasNextLine()) {
String line = scanner.nextLine().trim();
lineCount++;
readLine(line, deckList);
}
if (sbMessage.length() > 0) {
JOptionPane.showMessageDialog(MageFrame.getDesktop(), sbMessage.toString(), "Error importing deck", JOptionPane.ERROR_MESSAGE);
}
}
finally {
scanner.close();
}
} catch (Exception ex) {
logger.log(Level.SEVERE, null, ex);
}
return deckList;
}
protected abstract void readLine(String line, DeckCardLists deckList);
}

View file

@ -0,0 +1,44 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.client.deckeditor;
import mage.cards.decks.DeckCardLists;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class MWSDeckImporter extends DeckImporterImpl {
@Override
protected void readLine(String line, DeckCardLists deckList) {
//TODO: implement this
}
}