aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/equalparts
diff options
context:
space:
mode:
authorEduardo Pedroni <e.pedroni91@gmail.com>2015-06-11 18:12:24 +0200
committerEduardo Pedroni <e.pedroni91@gmail.com>2015-06-11 18:12:24 +0200
commitff08a196fe98790d78ee7f5b26b9f367f9fa5a68 (patch)
treea2f6261fda4d69b685d83a5deb76f2d3b2069e0a /src/eu/equalparts
parent27be2dd797fc7087c5e362c22c1f30fc377ea0e9 (diff)
Started work on the GUI, and added imageCode field to card, now need to update own collection
Diffstat (limited to 'src/eu/equalparts')
-rw-r--r--src/eu/equalparts/cardbase/Cardbase.java1
-rw-r--r--src/eu/equalparts/cardbase/cli/CardbaseCLI.java (renamed from src/eu/equalparts/cardbase/standalone/CardbaseCLI.java)12
-rw-r--r--src/eu/equalparts/cardbase/data/Card.java1
-rw-r--r--src/eu/equalparts/cardbase/data/FullCardSet.java145
-rw-r--r--src/eu/equalparts/cardbase/gui/CardImageView.java18
-rw-r--r--src/eu/equalparts/cardbase/gui/CardbaseGUI.java36
-rw-r--r--src/eu/equalparts/cardbase/gui/CardbaseViewer.java11
-rw-r--r--src/eu/equalparts/cardbase/utils/JSON.java2
-rw-r--r--src/eu/equalparts/cardbase/utils/MTGUniverse.java46
9 files changed, 108 insertions, 164 deletions
diff --git a/src/eu/equalparts/cardbase/Cardbase.java b/src/eu/equalparts/cardbase/Cardbase.java
index c5efc85..9251d4c 100644
--- a/src/eu/equalparts/cardbase/Cardbase.java
+++ b/src/eu/equalparts/cardbase/Cardbase.java
@@ -1,4 +1,5 @@
package eu.equalparts.cardbase;
+
import java.io.File;
import java.io.IOException;
import java.util.Collection;
diff --git a/src/eu/equalparts/cardbase/standalone/CardbaseCLI.java b/src/eu/equalparts/cardbase/cli/CardbaseCLI.java
index be3616a..7a2e581 100644
--- a/src/eu/equalparts/cardbase/standalone/CardbaseCLI.java
+++ b/src/eu/equalparts/cardbase/cli/CardbaseCLI.java
@@ -1,4 +1,4 @@
-package eu.equalparts.cardbase.standalone;
+package eu.equalparts.cardbase.cli;
import java.io.BufferedReader;
import java.io.File;
@@ -151,7 +151,7 @@ public class CardbaseCLI {
// the main loop
while (!exit) {
// print prompt
- System.out.print(selectedSet == null ? "> " : selectedSet.getCode() + " > ");
+ System.out.print(selectedSet == null ? "> " : selectedSet.code + " > ");
// condition input and interpret
String[] raw = consoleReader.readLine().trim().split("[ \t]+");
String command = raw[0];
@@ -266,7 +266,7 @@ public class CardbaseCLI {
selectedSet = MTGUniverse.getFullCardSet(args[0]);
// if the set code is invalid, null is returned
if (selectedSet != null) {
- System.out.println("Selected set: " + selectedSet.getName() + ".");
+ System.out.println("Selected set: " + selectedSet.name + ".");
// undoing is not allowed if the set is changed - it would get tricky
lastAction = null;
} else {
@@ -308,7 +308,7 @@ public class CardbaseCLI {
// if a card is specified, peruse only that
if (args.length > 0) {
if (selectedSet != null) {
- Card card = cardbase.getCard(selectedSet.getCode(), args[0]);
+ Card card = cardbase.getCard(selectedSet.code, args[0]);
if (card != null) {
printPerusal(card);
} else {
@@ -365,7 +365,7 @@ public class CardbaseCLI {
}
removeCard(cardToRemove, count);
} else {
- System.out.println(args[0] + " does not correspond to a card in " + selectedSet.getName() + ".");
+ System.out.println(args[0] + " does not correspond to a card in " + selectedSet.name + ".");
}
} else {
System.out.println("Please specify a card number to remove.");
@@ -400,7 +400,7 @@ public class CardbaseCLI {
}
addCard(cardToAdd, count);
} else {
- System.out.println(number + " does not correspond to a card in " + selectedSet.getName() + ".");
+ System.out.println(number + " does not correspond to a card in " + selectedSet.name + ".");
}
}
} else {
diff --git a/src/eu/equalparts/cardbase/data/Card.java b/src/eu/equalparts/cardbase/data/Card.java
index cca1747..2810564 100644
--- a/src/eu/equalparts/cardbase/data/Card.java
+++ b/src/eu/equalparts/cardbase/data/Card.java
@@ -22,6 +22,7 @@ public class Card {
// Not part of upstream JSON
public String setCode;
+ public String imageCode;
public Integer count;
} \ No newline at end of file
diff --git a/src/eu/equalparts/cardbase/data/FullCardSet.java b/src/eu/equalparts/cardbase/data/FullCardSet.java
index e831b74..a7f3ea5 100644
--- a/src/eu/equalparts/cardbase/data/FullCardSet.java
+++ b/src/eu/equalparts/cardbase/data/FullCardSet.java
@@ -1,77 +1,20 @@
package eu.equalparts.cardbase.data;
-import java.util.Collections;
import java.util.Map;
public class FullCardSet {
- private String name;
- private String code;
- private String magicCardsInfoCode;
- private String releaseDate;
- private String border;
- private String type;
- private String block;
- private String gathererCode;
- private Map<String, Card> cards;
+ public String name;
+ public String code;
+ public String magicCardsInfoCode;
+ public String releaseDate;
+ public String border;
+ public String type;
+ public String block;
+ public String gathererCode;
+ public Map<String, Card> cards;
/**
- * @return the set's name.
- */
- public String getName() {
- return name;
- }
-
- /**
- * @return the set code.
- */
- public String getCode() {
- return code;
- }
-
- /**
- * @return the set's release date.
- */
- public String getReleaseDate() {
- return releaseDate;
- }
-
- /**
- * @return the set's border type.
- */
- public String getBorder() {
- return border;
- }
-
- /**
- * @return the type of the set.
- */
- public String getType() {
- return type;
- }
-
- /**
- * @return the set's block.
- */
- public String getBlock() {
- return block;
- }
-
- /**
- * @return the set's Gatherer code.
- */
- public String getGathererCode() {
- return gathererCode;
- }
-
- /**
- * @return a full unmodifiable map of the set's cards.
- */
- public Map<String, Card> getCards() {
- return Collections.unmodifiableMap(cards);
- }
-
- /**
* Searches for a card by number (the one shown on the card itself).
*
* @param number the number of the card to search.
@@ -80,74 +23,4 @@ public class FullCardSet {
public Card getCardByNumber(String number) {
return cards.get(number);
}
-
- /**
- * @param name the name to set
- */
- public void setName(String name) {
- this.name = name;
- }
-
- /**
- * @param code the code to set
- */
- public void setCode(String code) {
- this.code = code;
- }
-
- /**
- * @param releaseDate the releaseDate to set
- */
- public void setReleaseDate(String releaseDate) {
- this.releaseDate = releaseDate;
- }
-
- /**
- * @param border the border to set
- */
- public void setBorder(String border) {
- this.border = border;
- }
-
- /**
- * @param type the type to set
- */
- public void setType(String type) {
- this.type = type;
- }
-
- /**
- * @param block the block to set
- */
- public void setBlock(String block) {
- this.block = block;
- }
-
- /**
- * @param gathererCode the gathererCode to set
- */
- public void setGathererCode(String gathererCode) {
- this.gathererCode = gathererCode;
- }
-
- /**
- * @param cards the cards to set
- */
- public void setCards(Map<String, Card> cards) {
- this.cards = cards;
- }
-
- /**
- * @return the magicCardsInfoCode
- */
- public String getMagicCardsInfoCode() {
- return magicCardsInfoCode;
- }
-
- /**
- * @param magicCardsInfoCode the magicCardsInfoCode to set
- */
- public void setMagicCardsInfoCode(String magicCardsInfoCode) {
- this.magicCardsInfoCode = magicCardsInfoCode;
- }
} \ No newline at end of file
diff --git a/src/eu/equalparts/cardbase/gui/CardImageView.java b/src/eu/equalparts/cardbase/gui/CardImageView.java
new file mode 100644
index 0000000..7c79c6a
--- /dev/null
+++ b/src/eu/equalparts/cardbase/gui/CardImageView.java
@@ -0,0 +1,18 @@
+package eu.equalparts.cardbase.gui;
+
+import eu.equalparts.cardbase.data.Card;
+import javafx.scene.image.ImageView;
+
+public class CardImageView extends ImageView {
+
+ private static final String BASE_IMG_URL = "http://magiccards.info/scans/en/";
+
+ public CardImageView(Card card) {
+ super(makeUrl(card));
+ }
+
+ public static String makeUrl(Card card) {
+ return BASE_IMG_URL + card.imageCode + "/" + card.number + ".jpg";
+ }
+
+}
diff --git a/src/eu/equalparts/cardbase/gui/CardbaseGUI.java b/src/eu/equalparts/cardbase/gui/CardbaseGUI.java
new file mode 100644
index 0000000..46d3c55
--- /dev/null
+++ b/src/eu/equalparts/cardbase/gui/CardbaseGUI.java
@@ -0,0 +1,36 @@
+package eu.equalparts.cardbase.gui;
+
+import javafx.application.Application;
+import javafx.scene.Scene;
+import javafx.scene.image.ImageView;
+import javafx.scene.layout.Pane;
+import javafx.stage.Stage;
+import eu.equalparts.cardbase.data.Card;
+import eu.equalparts.cardbase.utils.MTGUniverse;
+
+public class CardbaseGUI extends Application {
+
+ /**
+ * Run the GUI.
+ *
+ * @param args arguments passed down to {@code Application.launch()}.
+ */
+ public static void main(String... args) {
+ launch(args);
+ }
+
+ @Override
+ public void start(Stage primaryStage) throws Exception {
+ Card card = MTGUniverse.getCard("M15", "281");
+ ImageView test = new ImageView(CardImageView.makeUrl(card));
+
+ Pane parent = new Pane();
+
+ parent.getChildren().add(test);
+
+ primaryStage.setScene(new Scene(parent));
+
+ primaryStage.setTitle("Cardbase");
+ primaryStage.show();
+ }
+}
diff --git a/src/eu/equalparts/cardbase/gui/CardbaseViewer.java b/src/eu/equalparts/cardbase/gui/CardbaseViewer.java
new file mode 100644
index 0000000..30b32fb
--- /dev/null
+++ b/src/eu/equalparts/cardbase/gui/CardbaseViewer.java
@@ -0,0 +1,11 @@
+package eu.equalparts.cardbase.gui;
+
+import javafx.scene.Parent;
+
+public class CardbaseViewer extends Parent {
+
+
+
+
+
+}
diff --git a/src/eu/equalparts/cardbase/utils/JSON.java b/src/eu/equalparts/cardbase/utils/JSON.java
index a5992c7..17e8392 100644
--- a/src/eu/equalparts/cardbase/utils/JSON.java
+++ b/src/eu/equalparts/cardbase/utils/JSON.java
@@ -28,7 +28,7 @@ public final class JSON {
*/
private static ObjectMapper createMapper() {
ObjectMapper objectMapper = new ObjectMapper();
- // TODO decide what to do about this
+ // classes don't necessarily use all json fields
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
return objectMapper;
}
diff --git a/src/eu/equalparts/cardbase/utils/MTGUniverse.java b/src/eu/equalparts/cardbase/utils/MTGUniverse.java
index 8c77032..51959aa 100644
--- a/src/eu/equalparts/cardbase/utils/MTGUniverse.java
+++ b/src/eu/equalparts/cardbase/utils/MTGUniverse.java
@@ -32,7 +32,7 @@ public final class MTGUniverse {
/**
* The base URL from where the information is fetched.
*/
- private static final String BASE_URL = "http://mtgjson.com/json/";
+ private static final String BASE_DATA_URL = "http://mtgjson.com/json/";
/**
* If the upstream set code list can't be loaded, this is loaded instead.
*/
@@ -100,7 +100,7 @@ public final class MTGUniverse {
}
// not cached; fetch, cache and return it
else {
- requestedSet = parseFullSet(JSON.mapper.readValue(new URL(BASE_URL + validCode + ".json"), JsonNode.class));
+ requestedSet = parseFullSet(JSON.mapper.readValue(new URL(BASE_DATA_URL + validCode + ".json"), JsonNode.class));
cardSetCache.put(validCode, requestedSet);
}
}
@@ -114,7 +114,7 @@ public final class MTGUniverse {
// if the list isn't cached, fetch and cache it
if (cardSets == null) {
try {
- cardSets = JSON.mapper.readValue(new URL(BASE_URL + "SetList.json"), new TypeReference<ArrayList<CardSetInformation>>() {});
+ cardSets = JSON.mapper.readValue(new URL(BASE_DATA_URL + "SetList.json"), new TypeReference<ArrayList<CardSetInformation>>() {});
} catch (Exception e) {
System.out.println("Error: could not fetch/parse set code list from upstream, loading fallback json...");
e.printStackTrace();
@@ -170,7 +170,7 @@ public final class MTGUniverse {
* These fields are critical, if any of them is not present an exception is thrown.
*/
if (jsonTree.hasNonNull("name")) {
- fcs.setName(jsonTree.get("name").asText());
+ fcs.name = jsonTree.get("name").asText();
} else {
throw new JsonMappingException("Field \"name\" not found.");
}
@@ -178,45 +178,49 @@ public final class MTGUniverse {
String setCode;
if (jsonTree.hasNonNull("code")) {
setCode = jsonTree.get("code").asText();
- fcs.setCode(setCode);
+ fcs.code = setCode;
} else {
throw new JsonMappingException("Field \"code\" not found.");
}
+ String imageCode;
+ if (jsonTree.hasNonNull("magicCardsInfoCode")) {
+ imageCode = jsonTree.get("magicCardsInfoCode").asText();
+ fcs.magicCardsInfoCode = imageCode;
+ } else {
+ throw new JsonMappingException("Field \"magicCardsInfoCode\" not found.");
+ }
+
if (jsonTree.hasNonNull("releaseDate")) {
- fcs.setReleaseDate(jsonTree.get("releaseDate").asText());
+ fcs.releaseDate = jsonTree.get("releaseDate").asText();
} else {
throw new JsonMappingException("Field \"releaseDate\" not found.");
}
- /*
- * These fields are optional and are set to null if not present.
- */
- fcs.setGathererCode(jsonTree.hasNonNull("gathererCode") ? jsonTree.get("gathererCode").asText() : null);
- fcs.setBorder(jsonTree.hasNonNull("border") ? jsonTree.get("border").asText() : null);
- fcs.setType(jsonTree.hasNonNull("type") ? jsonTree.get("type").asText() : null);
- fcs.setMagicCardsInfoCode(jsonTree.hasNonNull("magicCardsInfoCode") ? jsonTree.get("magicCardsInfoCode").asText() : null);
- fcs.setBlock(jsonTree.hasNonNull("block") ? jsonTree.get("block").asText() : null);
-
- /*
- * This is a critical field which must be present, if not an exception is thrown.
- */
if (jsonTree.hasNonNull("cards")) {
- // attempt to card list as POJO
+ // attempt to read card list as a POJO using the standard mapper
List<Card> rawList = jsonTree.get("cards").traverse(JSON.mapper).readValueAs(new TypeReference<List<Card>>() {});
-
// generate the map
Map<String, Card> cardMap = new HashMap<String, Card>();
for (Card card : rawList) {
// add set code for convenience
card.setCode = setCode;
+ card.imageCode = imageCode;
cardMap.put(card.number, card);
}
- fcs.setCards(cardMap);
+ fcs.cards = cardMap;
} else {
throw new JsonMappingException("Field \"cards\" not found.");
}
+ /*
+ * These fields are optional and are set to null if not present.
+ */
+ fcs.gathererCode = jsonTree.hasNonNull("gathererCode") ? jsonTree.get("gathererCode").asText() : null;
+ fcs.border = jsonTree.hasNonNull("border") ? jsonTree.get("border").asText() : null;
+ fcs.type = jsonTree.hasNonNull("type") ? jsonTree.get("type").asText() : null;
+ fcs.block = jsonTree.hasNonNull("block") ? jsonTree.get("block").asText() : null;
+
return fcs;
}