checkstyle

This commit is contained in:
jendave
2011-10-31 16:58:56 +00:00
parent cb362a6e60
commit 9dc114afc4
9 changed files with 472 additions and 465 deletions

View File

@@ -38,12 +38,12 @@ public class Generate2ColorDeck {
* Constructor for Generate2ColorDeck. * Constructor for Generate2ColorDeck.
* </p> * </p>
* *
* @param Clr1 * @param clr1
* a {@link java.lang.String} object. * a {@link java.lang.String} object.
* @param Clr2 * @param clr2
* a {@link java.lang.String} object. * a {@link java.lang.String} object.
*/ */
public Generate2ColorDeck(final String Clr1, final String Clr2) { public Generate2ColorDeck(final String clr1, final String clr2) {
this.r = MyRandom.getRandom(); this.r = MyRandom.getRandom();
this.cardCounts = new HashMap<String, Integer>(); this.cardCounts = new HashMap<String, Integer>();
@@ -62,7 +62,7 @@ public class Generate2ColorDeck {
this.notColors.add("red"); this.notColors.add("red");
this.notColors.add("green"); this.notColors.add("green");
if (Clr1.equals("AI")) { if (clr1.equals("AI")) {
// choose first color // choose first color
this.color1 = this.notColors.get(this.r.nextInt(5)); this.color1 = this.notColors.get(this.r.nextInt(5));
@@ -73,8 +73,8 @@ public class Generate2ColorDeck {
} }
this.color2 = c2; this.color2 = c2;
} else { } else {
this.color1 = Clr1; this.color1 = clr1;
this.color2 = Clr2; this.color2 = clr2;
} }
this.notColors.remove(this.color1); this.notColors.remove(this.color1);
@@ -93,24 +93,24 @@ public class Generate2ColorDeck {
* get2ColorDeck. * get2ColorDeck.
* </p> * </p>
* *
* @param Size * @param size
* a int. * a int.
* @param pt * @param pt
* the pt * the pt
* @return a {@link forge.CardList} object. * @return a {@link forge.CardList} object.
*/ */
public final CardList get2ColorDeck(final int Size, final PlayerType pt) { public final CardList get2ColorDeck(final int size, final PlayerType pt) {
int lc = 0; // loop counter to prevent infinite card selection loops int lc = 0; // loop counter to prevent infinite card selection loops
String tmpDeck = ""; String tmpDeck = "";
final CardList tDeck = new CardList(); final CardList tDeck = new CardList();
final int LandsPercentage = 42; final int landsPercentage = 42;
final int CreatPercentage = 34; final int creatPercentage = 34;
final int SpellPercentage = 24; final int spellPercentage = 24;
// start with all cards // start with all cards
// remove cards that generated decks don't like // remove cards that generated decks don't like
final CardList AllCards = CardFilter.filter(AllZone.getCardFactory(), new CardListFilter() { final CardList allCards = CardFilter.filter(AllZone.getCardFactory(), new CardListFilter() {
@Override @Override
public boolean addCard(final Card c) { public boolean addCard(final Card c) {
if (c.getSVar("RemRandomDeck").equals("True")) { if (c.getSVar("RemRandomDeck").equals("True")) {
@@ -121,9 +121,9 @@ public class Generate2ColorDeck {
}); });
// reduce to cards that match the colors // reduce to cards that match the colors
CardList CL1 = AllCards.getColor(this.color1); CardList cl1 = allCards.getColor(this.color1);
CL1.addAll(AllCards.getColor(Constant.Color.COLORLESS)); cl1.addAll(allCards.getColor(Constant.Color.COLORLESS));
CardList CL2 = AllCards.getColor(this.color2); CardList cl2 = allCards.getColor(this.color2);
// remove multicolor cards that don't match the colors // remove multicolor cards that don't match the colors
final CardListFilter clrF = new CardListFilter() { final CardListFilter clrF = new CardListFilter() {
@@ -138,58 +138,59 @@ public class Generate2ColorDeck {
return true; return true;
} }
}; };
CL1 = CL1.filter(clrF); cl1 = cl1.filter(clrF);
CL2 = CL2.filter(clrF); cl2 = cl2.filter(clrF);
// build subsets based on type // build subsets based on type
final CardList Cr1 = CL1.getType("Creature"); final CardList cr1 = cl1.getType("Creature");
final CardList Cr2 = CL2.getType("Creature"); final CardList cr2 = cl2.getType("Creature");
final String[] ISE = { "Instant", "Sorcery", "Enchantment", "Planeswalker", "Artifact.nonCreature" }; final String[] ise = { "Instant", "Sorcery", "Enchantment", "Planeswalker", "Artifact.nonCreature" };
final CardList Sp1 = CL1.getValidCards(ISE, null, null); final CardList sp1 = cl1.getValidCards(ise, null, null);
final CardList Sp2 = CL2.getValidCards(ISE, null, null); final CardList sp2 = cl2.getValidCards(ise, null, null);
// final card pools // final card pools
final CardList Cr12 = new CardList(); final CardList cr12 = new CardList();
final CardList Sp12 = new CardList(); final CardList sp12 = new CardList();
// used for mana curve in the card pool // used for mana curve in the card pool
final int MinCMC[] = { 1 }, MaxCMC[] = { 2 }; final int[] minCMC = { 1 };
final int[] maxCMC = { 2 };
final CardListFilter cmcF = new CardListFilter() { final CardListFilter cmcF = new CardListFilter() {
@Override @Override
public boolean addCard(final Card c) { public boolean addCard(final Card c) {
final int cCMC = c.getCMC(); final int cCMC = c.getCMC();
return (cCMC >= MinCMC[0]) && (cCMC <= MaxCMC[0]); return (cCMC >= minCMC[0]) && (cCMC <= maxCMC[0]);
} }
}; };
// select cards to build card pools using a mana curve // select cards to build card pools using a mana curve
for (int i = 4; i > 0; i--) { for (int i = 4; i > 0; i--) {
final CardList Cr1CMC = Cr1.filter(cmcF); final CardList cr1CMC = cr1.filter(cmcF);
final CardList Cr2CMC = Cr2.filter(cmcF); final CardList cr2CMC = cr2.filter(cmcF);
final CardList Sp1CMC = Sp1.filter(cmcF); final CardList sp1CMC = sp1.filter(cmcF);
final CardList Sp2CMC = Sp2.filter(cmcF); final CardList sp2CMC = sp2.filter(cmcF);
for (int j = 0; j < i; j++) { for (int j = 0; j < i; j++) {
Card c = Cr1CMC.get(this.r.nextInt(Cr1CMC.size())); Card c = cr1CMC.get(this.r.nextInt(cr1CMC.size()));
Cr12.add(c); cr12.add(c);
this.cardCounts.put(c.getName(), 0); this.cardCounts.put(c.getName(), 0);
c = Cr2CMC.get(this.r.nextInt(Cr2CMC.size())); c = cr2CMC.get(this.r.nextInt(cr2CMC.size()));
Cr12.add(c); cr12.add(c);
this.cardCounts.put(c.getName(), 0); this.cardCounts.put(c.getName(), 0);
c = Sp1CMC.get(this.r.nextInt(Sp1CMC.size())); c = sp1CMC.get(this.r.nextInt(sp1CMC.size()));
Sp12.add(c); sp12.add(c);
this.cardCounts.put(c.getName(), 0); this.cardCounts.put(c.getName(), 0);
c = Sp2CMC.get(this.r.nextInt(Sp2CMC.size())); c = sp2CMC.get(this.r.nextInt(sp2CMC.size()));
Sp12.add(c); sp12.add(c);
this.cardCounts.put(c.getName(), 0); this.cardCounts.put(c.getName(), 0);
} }
MinCMC[0] += 2; minCMC[0] += 2;
MaxCMC[0] += 2; maxCMC[0] += 2;
// resulting mana curve of the card pool // resulting mana curve of the card pool
// 16x 1 - 2 // 16x 1 - 2
// 12x 3 - 4 // 12x 3 - 4
@@ -200,25 +201,25 @@ public class Generate2ColorDeck {
} }
// shuffle card pools // shuffle card pools
Cr12.shuffle(); cr12.shuffle();
Sp12.shuffle(); sp12.shuffle();
// calculate card counts // calculate card counts
float p = (float) (CreatPercentage * .01); float p = (float) (creatPercentage * .01);
final int CreatCnt = (int) (p * Size); final int creatCnt = (int) (p * size);
tmpDeck += "Creature Count:" + CreatCnt + "\n"; tmpDeck += "Creature Count:" + creatCnt + "\n";
p = (float) (SpellPercentage * .01); p = (float) (spellPercentage * .01);
final int SpellCnt = (int) (p * Size); final int spellCnt = (int) (p * size);
tmpDeck += "Spell Count:" + SpellCnt + "\n"; tmpDeck += "Spell Count:" + spellCnt + "\n";
// build deck from the card pools // build deck from the card pools
for (int i = 0; i < CreatCnt; i++) { for (int i = 0; i < creatCnt; i++) {
Card c = Cr12.get(this.r.nextInt(Cr12.size())); Card c = cr12.get(this.r.nextInt(cr12.size()));
lc = 0; lc = 0;
while ((this.cardCounts.get(c.getName()) > 3) || (lc > 100)) { while ((this.cardCounts.get(c.getName()) > 3) || (lc > 100)) {
c = Cr12.get(this.r.nextInt(Cr12.size())); c = cr12.get(this.r.nextInt(cr12.size()));
lc++; lc++;
} }
if (lc > 100) { if (lc > 100) {
@@ -231,12 +232,12 @@ public class Generate2ColorDeck {
tmpDeck += c.getName() + " " + c.getManaCost() + "\n"; tmpDeck += c.getName() + " " + c.getManaCost() + "\n";
} }
for (int i = 0; i < SpellCnt; i++) { for (int i = 0; i < spellCnt; i++) {
Card c = Sp12.get(this.r.nextInt(Sp12.size())); Card c = sp12.get(this.r.nextInt(sp12.size()));
lc = 0; lc = 0;
while ((this.cardCounts.get(c.getName()) > 3) || (lc > 100)) { while ((this.cardCounts.get(c.getName()) > 3) || (lc > 100)) {
c = Sp12.get(this.r.nextInt(Sp12.size())); c = sp12.get(this.r.nextInt(sp12.size()));
lc++; lc++;
} }
if (lc > 100) { if (lc > 100) {
@@ -251,12 +252,12 @@ public class Generate2ColorDeck {
// Add lands // Add lands
int numLands = 0; int numLands = 0;
if (LandsPercentage > 0) { if (landsPercentage > 0) {
p = (float) (LandsPercentage * .01); p = (float) (landsPercentage * .01);
numLands = (int) (p * Size); numLands = (int) (p * size);
} else { // otherwise, just fill in the rest of the deck with basic } else { // otherwise, just fill in the rest of the deck with basic
// lands // lands
numLands = Size - tDeck.size(); numLands = size - tDeck.size();
} }
tmpDeck += "numLands:" + numLands + "\n"; tmpDeck += "numLands:" + numLands + "\n";
@@ -285,7 +286,7 @@ public class Generate2ColorDeck {
if (numLands > 0) { if (numLands > 0) {
// attempt to optimize basic land counts according to // attempt to optimize basic land counts according to
// color representation // color representation
final CCnt[] ClrCnts = { new CCnt("Plains", 0), new CCnt("Island", 0), new CCnt("Swamp", 0), final CCnt[] clrCnts = { new CCnt("Plains", 0), new CCnt("Island", 0), new CCnt("Swamp", 0),
new CCnt("Mountain", 0), new CCnt("Forest", 0) }; new CCnt("Mountain", 0), new CCnt("Forest", 0) };
// count each card color using mana costs // count each card color using mana costs
@@ -298,15 +299,15 @@ public class Generate2ColorDeck {
final char c = mc.charAt(j); final char c = mc.charAt(j);
if (c == 'W') { if (c == 'W') {
ClrCnts[0].Count++; clrCnts[0].count++;
} else if (c == 'U') { } else if (c == 'U') {
ClrCnts[1].Count++; clrCnts[1].count++;
} else if (c == 'B') { } else if (c == 'B') {
ClrCnts[2].Count++; clrCnts[2].count++;
} else if (c == 'R') { } else if (c == 'R') {
ClrCnts[3].Count++; clrCnts[3].count++;
} else if (c == 'G') { } else if (c == 'G') {
ClrCnts[4].Count++; clrCnts[4].count++;
} }
} }
} }
@@ -314,25 +315,25 @@ public class Generate2ColorDeck {
// total of all ClrCnts // total of all ClrCnts
int totalColor = 0; int totalColor = 0;
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
totalColor += ClrCnts[i].Count; totalColor += clrCnts[i].count;
tmpDeck += ClrCnts[i].Color + ":" + ClrCnts[i].Count + "\n"; tmpDeck += clrCnts[i].color + ":" + clrCnts[i].count + "\n";
} }
tmpDeck += "totalColor:" + totalColor + "\n"; tmpDeck += "totalColor:" + totalColor + "\n";
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
if (ClrCnts[i].Count > 0) { // calculate number of lands for if (clrCnts[i].count > 0) { // calculate number of lands for
// each color // each color
p = (float) ClrCnts[i].Count / (float) totalColor; p = (float) clrCnts[i].count / (float) totalColor;
final int nLand = (int) (numLands * p); final int nLand = (int) (numLands * p);
tmpDeck += "nLand-" + ClrCnts[i].Color + ":" + nLand + "\n"; tmpDeck += "nLand-" + clrCnts[i].color + ":" + nLand + "\n";
// just to prevent a null exception by the deck size fixing // just to prevent a null exception by the deck size fixing
// code // code
this.cardCounts.put(ClrCnts[i].Color, nLand); this.cardCounts.put(clrCnts[i].color, nLand);
for (int j = 0; j <= nLand; j++) { for (int j = 0; j <= nLand; j++) {
tDeck.add(AllZone.getCardFactory().getCard(ClrCnts[i].Color, AllZone.getComputerPlayer())); tDeck.add(AllZone.getCardFactory().getCard(clrCnts[i].color, AllZone.getComputerPlayer()));
} }
} }
} }
@@ -340,18 +341,18 @@ public class Generate2ColorDeck {
tmpDeck += "DeckSize:" + tDeck.size() + "\n"; tmpDeck += "DeckSize:" + tDeck.size() + "\n";
// fix under-sized or over-sized decks, due to integer arithmetic // fix under-sized or over-sized decks, due to integer arithmetic
if (tDeck.size() < Size) { if (tDeck.size() < size) {
final int diff = Size - tDeck.size(); final int diff = size - tDeck.size();
for (int i = 0; i < diff; i++) { for (int i = 0; i < diff; i++) {
Card c = tDeck.get(this.r.nextInt(tDeck.size())); Card c = tDeck.get(this.r.nextInt(tDeck.size()));
lc = 0; lc = 0;
while ((this.cardCounts.get(c.getName()) > 3) || (lc > Size)) { while ((this.cardCounts.get(c.getName()) > 3) || (lc > size)) {
c = tDeck.get(this.r.nextInt(tDeck.size())); c = tDeck.get(this.r.nextInt(tDeck.size()));
lc++; lc++;
} }
if (lc > Size) { if (lc > size) {
throw new RuntimeException("Generate2ColorDeck : get2ColorDeck -- looped too much -- undersize"); throw new RuntimeException("Generate2ColorDeck : get2ColorDeck -- looped too much -- undersize");
} }
@@ -360,8 +361,8 @@ public class Generate2ColorDeck {
this.cardCounts.put(c.getName(), n + 1); this.cardCounts.put(c.getName(), n + 1);
tmpDeck += "Added:" + c.getName() + "\n"; tmpDeck += "Added:" + c.getName() + "\n";
} }
} else if (tDeck.size() > Size) { } else if (tDeck.size() > size) {
final int diff = tDeck.size() - Size; final int diff = tDeck.size() - size;
for (int i = 0; i < diff; i++) { for (int i = 0; i < diff; i++) {
Card c = tDeck.get(this.r.nextInt(tDeck.size())); Card c = tDeck.get(this.r.nextInt(tDeck.size()));
@@ -384,12 +385,12 @@ public class Generate2ColorDeck {
} }
private class CCnt { private class CCnt {
public String Color; private String color;
public int Count; private int count;
public CCnt(final String clr, final int cnt) { public CCnt(final String clr, final int cnt) {
this.Color = clr; this.color = clr;
this.Count = cnt; this.count = cnt;
} }
} }
} }

View File

@@ -39,14 +39,14 @@ public class Generate3ColorDeck {
* Constructor for Generate3ColorDeck. * Constructor for Generate3ColorDeck.
* </p> * </p>
* *
* @param Clr1 * @param clr1
* a {@link java.lang.String} object. * a {@link java.lang.String} object.
* @param Clr2 * @param clr2
* a {@link java.lang.String} object. * a {@link java.lang.String} object.
* @param Clr3 * @param clr3
* a {@link java.lang.String} object. * a {@link java.lang.String} object.
*/ */
public Generate3ColorDeck(final String Clr1, final String Clr2, final String Clr3) { public Generate3ColorDeck(final String clr1, final String clr2, final String clr3) {
this.r = MyRandom.getRandom(); this.r = MyRandom.getRandom();
this.cardCounts = new HashMap<String, Integer>(); this.cardCounts = new HashMap<String, Integer>();
@@ -65,7 +65,7 @@ public class Generate3ColorDeck {
this.notColors.add("red"); this.notColors.add("red");
this.notColors.add("green"); this.notColors.add("green");
if (Clr1.equals("AI")) { if (clr1.equals("AI")) {
// choose first color // choose first color
this.color1 = this.notColors.get(this.r.nextInt(5)); this.color1 = this.notColors.get(this.r.nextInt(5));
@@ -82,9 +82,9 @@ public class Generate3ColorDeck {
} }
this.color3 = c3; this.color3 = c3;
} else { } else {
this.color1 = Clr1; this.color1 = clr1;
this.color2 = Clr2; this.color2 = clr2;
this.color3 = Clr3; this.color3 = clr3;
} }
this.notColors.remove(this.color1); this.notColors.remove(this.color1);
@@ -105,24 +105,24 @@ public class Generate3ColorDeck {
* get3ColorDeck. * get3ColorDeck.
* </p> * </p>
* *
* @param Size * @param size
* a int. * a int.
* @param pt * @param pt
* the pt * the pt
* @return a {@link forge.CardList} object. * @return a {@link forge.CardList} object.
*/ */
public final CardList get3ColorDeck(final int Size, final PlayerType pt) { public final CardList get3ColorDeck(final int size, final PlayerType pt) {
int lc = 0; // loop counter to prevent infinite card selection loops int lc = 0; // loop counter to prevent infinite card selection loops
String tmpDeck = ""; String tmpDeck = "";
final CardList tDeck = new CardList(); final CardList tDeck = new CardList();
final int LandsPercentage = 44; final int landsPercentage = 44;
final int CreatPercentage = 34; final int creatPercentage = 34;
final int SpellPercentage = 22; final int spellPercentage = 22;
// start with all cards // start with all cards
// remove cards that generated decks don't like // remove cards that generated decks don't like
final CardList AllCards = CardFilter.filter(AllZone.getCardFactory(), new CardListFilter() { final CardList allCards = CardFilter.filter(AllZone.getCardFactory(), new CardListFilter() {
@Override @Override
public boolean addCard(final Card c) { public boolean addCard(final Card c) {
if (c.getSVar("RemRandomDeck").equals("True")) { if (c.getSVar("RemRandomDeck").equals("True")) {
@@ -133,10 +133,10 @@ public class Generate3ColorDeck {
}); });
// reduce to cards that match the colors // reduce to cards that match the colors
CardList CL1 = AllCards.getColor(this.color1); CardList cl1 = allCards.getColor(this.color1);
CL1.addAll(AllCards.getColor(Constant.Color.COLORLESS)); cl1.addAll(allCards.getColor(Constant.Color.COLORLESS));
CardList CL2 = AllCards.getColor(this.color2); CardList cl2 = allCards.getColor(this.color2);
CardList CL3 = AllCards.getColor(this.color3); CardList cl3 = allCards.getColor(this.color3);
// remove multicolor cards that don't match the colors // remove multicolor cards that don't match the colors
final CardListFilter clrF = new CardListFilter() { final CardListFilter clrF = new CardListFilter() {
@@ -151,72 +151,73 @@ public class Generate3ColorDeck {
return true; return true;
} }
}; };
CL1 = CL1.filter(clrF); cl1 = cl1.filter(clrF);
CL2 = CL2.filter(clrF); cl2 = cl2.filter(clrF);
CL3 = CL3.filter(clrF); cl3 = cl3.filter(clrF);
// build subsets based on type // build subsets based on type
final CardList Cr1 = CL1.getType("Creature"); final CardList cr1 = cl1.getType("Creature");
final CardList Cr2 = CL2.getType("Creature"); final CardList cr2 = cl2.getType("Creature");
final CardList Cr3 = CL3.getType("Creature"); final CardList cr3 = cl3.getType("Creature");
final String[] ISE = { "Instant", "Sorcery", "Enchantment", "Planeswalker", "Artifact.nonCreature" }; final String[] ise = { "Instant", "Sorcery", "Enchantment", "Planeswalker", "Artifact.nonCreature" };
final CardList Sp1 = CL1.getValidCards(ISE, null, null); final CardList sp1 = cl1.getValidCards(ise, null, null);
final CardList Sp2 = CL2.getValidCards(ISE, null, null); final CardList sp2 = cl2.getValidCards(ise, null, null);
final CardList Sp3 = CL3.getValidCards(ISE, null, null); final CardList sp3 = cl3.getValidCards(ise, null, null);
// final card pools // final card pools
final CardList Cr123 = new CardList(); final CardList cr123 = new CardList();
final CardList Sp123 = new CardList(); final CardList sp123 = new CardList();
// used for mana curve in the card pool // used for mana curve in the card pool
final int MinCMC[] = { 1 }, MaxCMC[] = { 3 }; final int[] minCMC = { 1 };
final int[] maxCMC = { 3 };
final CardListFilter cmcF = new CardListFilter() { final CardListFilter cmcF = new CardListFilter() {
@Override @Override
public boolean addCard(final Card c) { public boolean addCard(final Card c) {
final int cCMC = c.getCMC(); final int cCMC = c.getCMC();
return (cCMC >= MinCMC[0]) && (cCMC <= MaxCMC[0]); return (cCMC >= minCMC[0]) && (cCMC <= maxCMC[0]);
} }
}; };
// select cards to build card pools using a mana curve // select cards to build card pools using a mana curve
for (int i = 3; i > 0; i--) { for (int i = 3; i > 0; i--) {
final CardList Cr1CMC = Cr1.filter(cmcF); final CardList cr1CMC = cr1.filter(cmcF);
final CardList Cr2CMC = Cr2.filter(cmcF); final CardList cr2CMC = cr2.filter(cmcF);
final CardList Cr3CMC = Cr3.filter(cmcF); final CardList cr3CMC = cr3.filter(cmcF);
final CardList Sp1CMC = Sp1.filter(cmcF); final CardList sp1CMC = sp1.filter(cmcF);
final CardList Sp2CMC = Sp2.filter(cmcF); final CardList sp2CMC = sp2.filter(cmcF);
final CardList Sp3CMC = Sp3.filter(cmcF); final CardList sp3CMC = sp3.filter(cmcF);
for (int j = 0; j < i; j++) { for (int j = 0; j < i; j++) {
Card c = Cr1CMC.get(this.r.nextInt(Cr1CMC.size())); Card c = cr1CMC.get(this.r.nextInt(cr1CMC.size()));
Cr123.add(c); cr123.add(c);
this.cardCounts.put(c.getName(), 0); this.cardCounts.put(c.getName(), 0);
c = Cr2CMC.get(this.r.nextInt(Cr2CMC.size())); c = cr2CMC.get(this.r.nextInt(cr2CMC.size()));
Cr123.add(c); cr123.add(c);
this.cardCounts.put(c.getName(), 0); this.cardCounts.put(c.getName(), 0);
c = Cr3CMC.get(this.r.nextInt(Cr3CMC.size())); c = cr3CMC.get(this.r.nextInt(cr3CMC.size()));
Cr123.add(c); cr123.add(c);
this.cardCounts.put(c.getName(), 0); this.cardCounts.put(c.getName(), 0);
c = Sp1CMC.get(this.r.nextInt(Sp1CMC.size())); c = sp1CMC.get(this.r.nextInt(sp1CMC.size()));
Sp123.add(c); sp123.add(c);
this.cardCounts.put(c.getName(), 0); this.cardCounts.put(c.getName(), 0);
c = Sp2CMC.get(this.r.nextInt(Sp2CMC.size())); c = sp2CMC.get(this.r.nextInt(sp2CMC.size()));
Sp123.add(c); sp123.add(c);
this.cardCounts.put(c.getName(), 0); this.cardCounts.put(c.getName(), 0);
c = Sp3CMC.get(this.r.nextInt(Sp3CMC.size())); c = sp3CMC.get(this.r.nextInt(sp3CMC.size()));
Sp123.add(c); sp123.add(c);
this.cardCounts.put(c.getName(), 0); this.cardCounts.put(c.getName(), 0);
} }
MinCMC[0] += 2; minCMC[0] += 2;
MaxCMC[0] += 2; maxCMC[0] += 2;
// resulting mana curve of the card pool // resulting mana curve of the card pool
// 18x 1 - 3 // 18x 1 - 3
// 12x 3 - 5 // 12x 3 - 5
@@ -226,25 +227,25 @@ public class Generate3ColorDeck {
} }
// shuffle card pools // shuffle card pools
Cr123.shuffle(); cr123.shuffle();
Sp123.shuffle(); sp123.shuffle();
// calculate card counts // calculate card counts
float p = (float) (CreatPercentage * .01); float p = (float) (creatPercentage * .01);
final int CreatCnt = (int) (p * Size); final int creatCnt = (int) (p * size);
tmpDeck += "Creature Count:" + CreatCnt + "\n"; tmpDeck += "Creature Count:" + creatCnt + "\n";
p = (float) (SpellPercentage * .01); p = (float) (spellPercentage * .01);
final int SpellCnt = (int) (p * Size); final int spellCnt = (int) (p * size);
tmpDeck += "Spell Count:" + SpellCnt + "\n"; tmpDeck += "Spell Count:" + spellCnt + "\n";
// build deck from the card pools // build deck from the card pools
for (int i = 0; i < CreatCnt; i++) { for (int i = 0; i < creatCnt; i++) {
Card c = Cr123.get(this.r.nextInt(Cr123.size())); Card c = cr123.get(this.r.nextInt(cr123.size()));
lc = 0; lc = 0;
while ((this.cardCounts.get(c.getName()) > 3) || (lc > 100)) { while ((this.cardCounts.get(c.getName()) > 3) || (lc > 100)) {
c = Cr123.get(this.r.nextInt(Cr123.size())); c = cr123.get(this.r.nextInt(cr123.size()));
lc++; lc++;
} }
if (lc > 100) { if (lc > 100) {
@@ -257,12 +258,12 @@ public class Generate3ColorDeck {
tmpDeck += c.getName() + " " + c.getManaCost() + "\n"; tmpDeck += c.getName() + " " + c.getManaCost() + "\n";
} }
for (int i = 0; i < SpellCnt; i++) { for (int i = 0; i < spellCnt; i++) {
Card c = Sp123.get(this.r.nextInt(Sp123.size())); Card c = sp123.get(this.r.nextInt(sp123.size()));
lc = 0; lc = 0;
while ((this.cardCounts.get(c.getName()) > 3) || (lc > 100)) { while ((this.cardCounts.get(c.getName()) > 3) || (lc > 100)) {
c = Sp123.get(this.r.nextInt(Sp123.size())); c = sp123.get(this.r.nextInt(sp123.size()));
lc++; lc++;
} }
if (lc > 100) { if (lc > 100) {
@@ -277,12 +278,12 @@ public class Generate3ColorDeck {
// Add lands // Add lands
int numLands = 0; int numLands = 0;
if (LandsPercentage > 0) { if (landsPercentage > 0) {
p = (float) (LandsPercentage * .01); p = (float) (landsPercentage * .01);
numLands = (int) (p * Size); numLands = (int) (p * size);
} else { } else {
// otherwise, just fill in the rest of the deck with basic lands // otherwise, just fill in the rest of the deck with basic lands
numLands = Size - tDeck.size(); numLands = size - tDeck.size();
} }
tmpDeck += "numLands:" + numLands + "\n"; tmpDeck += "numLands:" + numLands + "\n";
@@ -308,10 +309,10 @@ public class Generate3ColorDeck {
numLands -= ndLands; numLands -= ndLands;
if (numLands > 0) // attempt to optimize basic land counts according to if (numLands > 0) {
// color representation // attempt to optimize basic land counts according to
{ // color representation
final CCnt[] ClrCnts = { new CCnt("Plains", 0), new CCnt("Island", 0), new CCnt("Swamp", 0), final CCnt[] clrCnts = { new CCnt("Plains", 0), new CCnt("Island", 0), new CCnt("Swamp", 0),
new CCnt("Mountain", 0), new CCnt("Forest", 0) }; new CCnt("Mountain", 0), new CCnt("Forest", 0) };
// count each card color using mana costs // count each card color using mana costs
@@ -324,15 +325,15 @@ public class Generate3ColorDeck {
final char c = mc.charAt(j); final char c = mc.charAt(j);
if (c == 'W') { if (c == 'W') {
ClrCnts[0].Count++; clrCnts[0].count++;
} else if (c == 'U') { } else if (c == 'U') {
ClrCnts[1].Count++; clrCnts[1].count++;
} else if (c == 'B') { } else if (c == 'B') {
ClrCnts[2].Count++; clrCnts[2].count++;
} else if (c == 'R') { } else if (c == 'R') {
ClrCnts[3].Count++; clrCnts[3].count++;
} else if (c == 'G') { } else if (c == 'G') {
ClrCnts[4].Count++; clrCnts[4].count++;
} }
} }
} }
@@ -340,25 +341,25 @@ public class Generate3ColorDeck {
// total of all ClrCnts // total of all ClrCnts
int totalColor = 0; int totalColor = 0;
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
totalColor += ClrCnts[i].Count; totalColor += clrCnts[i].count;
tmpDeck += ClrCnts[i].Color + ":" + ClrCnts[i].Count + "\n"; tmpDeck += clrCnts[i].color + ":" + clrCnts[i].count + "\n";
} }
tmpDeck += "totalColor:" + totalColor + "\n"; tmpDeck += "totalColor:" + totalColor + "\n";
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
if (ClrCnts[i].Count > 0) { // calculate number of lands for if (clrCnts[i].count > 0) { // calculate number of lands for
// each color // each color
p = (float) ClrCnts[i].Count / (float) totalColor; p = (float) clrCnts[i].count / (float) totalColor;
final int nLand = (int) (numLands * p); final int nLand = (int) (numLands * p);
tmpDeck += "nLand-" + ClrCnts[i].Color + ":" + nLand + "\n"; tmpDeck += "nLand-" + clrCnts[i].color + ":" + nLand + "\n";
// just to prevent a null exception by the deck size fixing // just to prevent a null exception by the deck size fixing
// code // code
this.cardCounts.put(ClrCnts[i].Color, nLand); this.cardCounts.put(clrCnts[i].color, nLand);
for (int j = 0; j <= nLand; j++) { for (int j = 0; j <= nLand; j++) {
tDeck.add(AllZone.getCardFactory().getCard(ClrCnts[i].Color, AllZone.getComputerPlayer())); tDeck.add(AllZone.getCardFactory().getCard(clrCnts[i].color, AllZone.getComputerPlayer()));
} }
} }
} }
@@ -366,18 +367,18 @@ public class Generate3ColorDeck {
tmpDeck += "DeckSize:" + tDeck.size() + "\n"; tmpDeck += "DeckSize:" + tDeck.size() + "\n";
// fix under-sized or over-sized decks, due to integer arithmetic // fix under-sized or over-sized decks, due to integer arithmetic
if (tDeck.size() < Size) { if (tDeck.size() < size) {
final int diff = Size - tDeck.size(); final int diff = size - tDeck.size();
for (int i = 0; i < diff; i++) { for (int i = 0; i < diff; i++) {
Card c = tDeck.get(this.r.nextInt(tDeck.size())); Card c = tDeck.get(this.r.nextInt(tDeck.size()));
lc = 0; lc = 0;
while ((this.cardCounts.get(c.getName()) > 3) || (lc > Size)) { while ((this.cardCounts.get(c.getName()) > 3) || (lc > size)) {
c = tDeck.get(this.r.nextInt(tDeck.size())); c = tDeck.get(this.r.nextInt(tDeck.size()));
lc++; lc++;
} }
if (lc > Size) { if (lc > size) {
throw new RuntimeException("Generate3ColorDeck : get3ColorDeck -- looped too much -- undersize"); throw new RuntimeException("Generate3ColorDeck : get3ColorDeck -- looped too much -- undersize");
} }
@@ -386,8 +387,8 @@ public class Generate3ColorDeck {
this.cardCounts.put(c.getName(), n + 1); this.cardCounts.put(c.getName(), n + 1);
tmpDeck += "Added:" + c.getName() + "\n"; tmpDeck += "Added:" + c.getName() + "\n";
} }
} else if (tDeck.size() > Size) { } else if (tDeck.size() > size) {
final int diff = tDeck.size() - Size; final int diff = tDeck.size() - size;
for (int i = 0; i < diff; i++) { for (int i = 0; i < diff; i++) {
Card c = tDeck.get(this.r.nextInt(tDeck.size())); Card c = tDeck.get(this.r.nextInt(tDeck.size()));
@@ -411,12 +412,12 @@ public class Generate3ColorDeck {
} }
private class CCnt { private class CCnt {
public String Color; private String color;
public int Count; private int count;
public CCnt(final String clr, final int cnt) { public CCnt(final String clr, final int cnt) {
this.Color = clr; this.color = clr;
this.Count = cnt; this.count = cnt;
} }
} }
} }

View File

@@ -335,9 +335,9 @@ public class Generate5ColorDeck {
numLands -= nDLands; numLands -= nDLands;
if (numLands > 0) // attempt to optimize basic land counts according to if (numLands > 0) {
// color representation // attempt to optimize basic land counts according to
{ // color representation
final CCnt[] clrCnts = { new CCnt("Plains", 0), new CCnt("Island", 0), new CCnt("Swamp", 0), final CCnt[] clrCnts = { new CCnt("Plains", 0), new CCnt("Island", 0), new CCnt("Swamp", 0),
new CCnt("Mountain", 0), new CCnt("Forest", 0) }; new CCnt("Mountain", 0), new CCnt("Forest", 0) };

View File

@@ -485,9 +485,8 @@ public class GenerateConstructedMultiColorDeck {
return ((CardUtil.getColors(c).size() <= 3) && !c.isLand() && // no return ((CardUtil.getColors(c).size() <= 3) && !c.isLand() && // no
// land // land
!c.getSVar("RemRandomDeck").equals("True") && !c.getSVar("RemAIDeck").equals("True")) || !c.getSVar("RemRandomDeck").equals("True") && !c.getSVar("RemAIDeck").equals("True"))
// OR very important || goodLand.contains(c.getName()); // OR very important
goodLand.contains(c.getName());
} }
}); });
} else if (colors == 5) { } else if (colors == 5) {
@@ -498,9 +497,8 @@ public class GenerateConstructedMultiColorDeck {
// multicolored // multicolored
// cards // cards
!c.isLand() && // no land !c.isLand() && // no land
!c.getSVar("RemRandomDeck").equals("True") && !c.getSVar("RemAIDeck").equals("True")) || !c.getSVar("RemRandomDeck").equals("True") && !c.getSVar("RemAIDeck").equals("True"))
// OR very important || goodLand.contains(c.getName()); // OR very important
goodLand.contains(c.getName());
} }
}); });

View File

@@ -114,17 +114,17 @@ public class GenerateThemeDeck {
for (final String element : ss) { for (final String element : ss) {
if (element.startsWith("Percentage")) { if (element.startsWith("Percentage")) {
final String p = element.substring("Percentage".length() + 1); final String p = element.substring("Percentage".length() + 1);
g.Percentage = Integer.parseInt(p); g.percentage = Integer.parseInt(p);
} }
if (element.startsWith("MaxCnt")) { if (element.startsWith("MaxCnt")) {
final String m = element.substring("MaxCnt".length() + 1); final String m = element.substring("MaxCnt".length() + 1);
g.MaxCnt = Integer.parseInt(m); g.maxCnt = Integer.parseInt(m);
} }
} }
s = this.readLine(); s = this.readLine();
while (!s.equals("[/Group]")) { while (!s.equals("[/Group]")) {
g.Cardnames.add(s); g.cardnames.add(s);
cardCounts.put(s, 0); cardCounts.put(s, 0);
s = this.readLine(); s = this.readLine();
@@ -159,21 +159,19 @@ public class GenerateThemeDeck {
for (int i = 0; i < groups.size(); i++) { for (int i = 0; i < groups.size(); i++) {
final Grp g = groups.get(i); final Grp g = groups.get(i);
final float p = (float) (g.Percentage * .01); final float p = (float) (g.percentage * .01);
final int grpCnt = (int) (p * size); final int grpCnt = (int) (p * size);
final int cnSize = g.Cardnames.size(); final int cnSize = g.cardnames.size();
tmpDeck += "Group" + i + ":" + grpCnt + "\n"; tmpDeck += "Group" + i + ":" + grpCnt + "\n";
for (int j = 0; j < grpCnt; j++) { for (int j = 0; j < grpCnt; j++) {
s = g.Cardnames.get(r.nextInt(cnSize)); s = g.cardnames.get(r.nextInt(cnSize));
int lc = 0; int lc = 0;
while ((cardCounts.get(s) >= g.MaxCnt) || (lc > size)) // don't while ((cardCounts.get(s) >= g.maxCnt) || (lc > size)) {
// keep // looping
// looping // forever
// forever s = g.cardnames.get(r.nextInt(cnSize));
{
s = g.Cardnames.get(r.nextInt(cnSize));
lc++; lc++;
} }
if (lc > size) { if (lc > size) {
@@ -200,9 +198,9 @@ public class GenerateThemeDeck {
tmpDeck += "numBLands:" + numBLands + "\n"; tmpDeck += "numBLands:" + numBLands + "\n";
if (numBLands > 0) // attempt to optimize basic land counts according to if (numBLands > 0) {
// color representation // attempt to optimize basic land counts according to
{ // color representation
final CCnt[] clrCnts = { new CCnt("Plains", 0), new CCnt("Island", 0), new CCnt("Swamp", 0), final CCnt[] clrCnts = { new CCnt("Plains", 0), new CCnt("Island", 0), new CCnt("Swamp", 0),
new CCnt("Mountain", 0), new CCnt("Forest", 0) }; new CCnt("Mountain", 0), new CCnt("Forest", 0) };
@@ -215,37 +213,37 @@ public class GenerateThemeDeck {
final char c = mc.charAt(j); final char c = mc.charAt(j);
if (c == 'W') { if (c == 'W') {
clrCnts[0].Count++; clrCnts[0].count++;
} else if (c == 'U') { } else if (c == 'U') {
clrCnts[1].Count++; clrCnts[1].count++;
} else if (c == 'B') { } else if (c == 'B') {
clrCnts[2].Count++; clrCnts[2].count++;
} else if (c == 'R') { } else if (c == 'R') {
clrCnts[3].Count++; clrCnts[3].count++;
} else if (c == 'G') { } else if (c == 'G') {
clrCnts[4].Count++; clrCnts[4].count++;
} }
} }
} }
int totalColor = 0; int totalColor = 0;
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
totalColor += clrCnts[i].Count; totalColor += clrCnts[i].count;
tmpDeck += clrCnts[i].Color + ":" + clrCnts[i].Count + "\n"; tmpDeck += clrCnts[i].color + ":" + clrCnts[i].count + "\n";
} }
tmpDeck += "totalColor:" + totalColor + "\n"; tmpDeck += "totalColor:" + totalColor + "\n";
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
if (clrCnts[i].Count > 0) { // calculate number of lands for if (clrCnts[i].count > 0) { // calculate number of lands for
// each color // each color
final float p = (float) clrCnts[i].Count / (float) totalColor; final float p = (float) clrCnts[i].count / (float) totalColor;
final int nLand = (int) (numBLands * p); final int nLand = (int) (numBLands * p);
tmpDeck += "numLand-" + clrCnts[i].Color + ":" + nLand + "\n"; tmpDeck += "numLand-" + clrCnts[i].color + ":" + nLand + "\n";
cardCounts.put(clrCnts[i].Color, 2); cardCounts.put(clrCnts[i].color, 2);
for (int j = 0; j < nLand; j++) { for (int j = 0; j < nLand; j++) {
tDeck.add(AllZone.getCardFactory().getCard(clrCnts[i].Color, AllZone.getComputerPlayer())); tDeck.add(AllZone.getCardFactory().getCard(clrCnts[i].color, AllZone.getComputerPlayer()));
} }
} }
} }
@@ -319,10 +317,10 @@ public class GenerateThemeDeck {
class CCnt { class CCnt {
/** The Color. */ /** The Color. */
public String Color; private String color;
/** The Count. */ /** The Count. */
public int Count; private int count;
/** /**
* Instantiates a new c cnt. * Instantiates a new c cnt.
@@ -333,8 +331,8 @@ public class GenerateThemeDeck {
* the cnt * the cnt
*/ */
public CCnt(final String clr, final int cnt) { public CCnt(final String clr, final int cnt) {
this.Color = clr; this.color = clr;
this.Count = cnt; this.count = cnt;
} }
} }
@@ -346,12 +344,12 @@ public class GenerateThemeDeck {
class Grp { class Grp {
/** The Cardnames. */ /** The Cardnames. */
public ArrayList<String> Cardnames = new ArrayList<String>(); private ArrayList<String> cardnames = new ArrayList<String>();
/** The Max cnt. */ /** The Max cnt. */
public int MaxCnt; private int maxCnt;
/** The Percentage. */ /** The Percentage. */
public int Percentage; private int percentage;
} }
} }

View File

@@ -22,6 +22,7 @@ import javax.swing.JSeparator;
import javax.swing.JTextArea; import javax.swing.JTextArea;
import javax.swing.JTextField; import javax.swing.JTextField;
import javax.swing.SwingConstants; import javax.swing.SwingConstants;
import javax.swing.WindowConstants;
import javax.swing.border.EmptyBorder; import javax.swing.border.EmptyBorder;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
@@ -53,24 +54,24 @@ public class BugzReporter extends JDialog {
private ForgePreferences prefs = null; private ForgePreferences prefs = null;
private final JPanel contentPanel = new JPanel(); private final JPanel contentPanel = new JPanel();
private JTextField txtUserName; private final JTextField txtUserName;
private JPasswordField txtPassword = new JPasswordField(); private final JPasswordField txtPassword = new JPasswordField();
private JComboBox cboCategory = new JComboBox(); private final JComboBox cboCategory = new JComboBox();
private JTextField txtSummary; private final JTextField txtSummary;
private JTextArea txtDescription = new JTextArea(); private final JTextArea txtDescription = new JTextArea();
private JTextArea txtErrorDump = new JTextArea(); private final JTextArea txtErrorDump = new JTextArea();
private JComboBox cboVersion = new JComboBox(); private final JComboBox cboVersion = new JComboBox();
private JComboBox cboSeverity = new JComboBox(); private final JComboBox cboSeverity = new JComboBox();
/** The chk report anonymously. */ /** The chk report anonymously. */
final JCheckBox chkReportAnonymously = new JCheckBox("Report Anonymously"); private final JCheckBox chkReportAnonymously = new JCheckBox("Report Anonymously");
private JTextField txtSVN; private final JTextField txtSVN;
private JLabel lblAddInfo = new JLabel(); private final JLabel lblAddInfo = new JLabel();
private JTextArea txtSteps = new JTextArea(); private final JTextArea txtSteps = new JTextArea();
private static BugzReporter dialog = null; private static BugzReporter dialog = null;
private IMCAttribute[] Severities; private IMCAttribute[] severities;
/** /**
* Launch the application. * Launch the application.
@@ -80,7 +81,7 @@ public class BugzReporter extends JDialog {
*/ */
public static void main(final String[] args) { public static void main(final String[] args) {
// try { // try {
dialog.setVisible(true); BugzReporter.dialog.setVisible(true);
// } catch (Exception e) { // } catch (Exception e) {
// System.out.println("Exception - main - " + e.getMessage()); // System.out.println("Exception - main - " + e.getMessage());
// } // }
@@ -93,24 +94,24 @@ public class BugzReporter extends JDialog {
* the new dump text * the new dump text
*/ */
public final void setDumpText(final String dump) { public final void setDumpText(final String dump) {
txtErrorDump.setText(dump); this.txtErrorDump.setText(dump);
lblAddInfo.setText("Crash Report"); this.lblAddInfo.setText("Crash Report");
cboCategory.setSelectedItem("New Crash Report"); this.cboCategory.setSelectedItem("New Crash Report");
} }
/** /**
* Create the dialog. * Create the dialog.
*/ */
public BugzReporter() { public BugzReporter() {
dialog = this; BugzReporter.dialog = this;
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
setResizable(false); this.setResizable(false);
// Init Logger for Axis, which is used by Mantis Library // Init Logger for Axis, which is used by Mantis Library
org.apache.log4j.ConsoleAppender appCON = new org.apache.log4j.ConsoleAppender( final org.apache.log4j.ConsoleAppender appCON = new org.apache.log4j.ConsoleAppender(
new org.apache.log4j.SimpleLayout(), "System.out"); new org.apache.log4j.SimpleLayout(), "System.out");
org.apache.log4j.Logger logAxis = Logger.getLogger("org.apache.axis"); final org.apache.log4j.Logger logAxis = Logger.getLogger("org.apache.axis");
logAxis.addAppender(appCON); logAxis.addAppender(appCON);
logAxis.setLevel(org.apache.log4j.Level.ERROR); logAxis.setLevel(org.apache.log4j.Level.ERROR);
// Init Logger // Init Logger
@@ -123,234 +124,237 @@ public class BugzReporter extends JDialog {
try { try {
mCS = new MCSession(new URL("http://cardforge.org/bugz/api/soap/mantisconnect.php"), "ForgeGUI", mCS = new MCSession(new URL("http://cardforge.org/bugz/api/soap/mantisconnect.php"), "ForgeGUI",
"vi2ccTbfBUu^"); "vi2ccTbfBUu^");
} catch (MalformedURLException e1) { } catch (final MalformedURLException e1) {
System.out.println("MalFormedURLException"); System.out.println("MalFormedURLException");
} catch (MCException e1) { } catch (final MCException e1) {
System.out.println("MCException - new MCSession"); System.out.println("MCException - new MCSession");
} }
String[] cats = {}; String[] cats = {};
try { try {
cats = mCS.getCategories(1); cats = mCS.getCategories(1);
} catch (MCException e1) { } catch (final MCException e1) {
System.out.println("MCException - getCategories - " + e1.getMessage()); System.out.println("MCException - getCategories - " + e1.getMessage());
} }
try { try {
Severities = mCS.getEnum(Enumeration.SEVERITIES); this.severities = mCS.getEnum(Enumeration.SEVERITIES);
} catch (MCException e1) { } catch (final MCException e1) {
System.out.println("MCException - getEnum - " + e1.getMessage()); System.out.println("MCException - getEnum - " + e1.getMessage());
} }
IProjectVersion[] vers = {}; IProjectVersion[] vers = {};
try { try {
vers = mCS.getVersions(1); vers = mCS.getVersions(1);
} catch (MCException e1) { } catch (final MCException e1) {
System.out.println("MCException - getVersions - " + e1.getMessage()); System.out.println("MCException - getVersions - " + e1.getMessage());
} }
BuildInfo bi = Singletons.getModel().getBuildInfo(); final BuildInfo bi = Singletons.getModel().getBuildInfo();
setTitle("Report Issue"); this.setTitle("Report Issue");
setBounds(100, 100, 442, 575); this.setBounds(100, 100, 442, 575);
getContentPane().setLayout(new BorderLayout()); this.getContentPane().setLayout(new BorderLayout());
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); this.contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
getContentPane().add(contentPanel, BorderLayout.CENTER); this.getContentPane().add(this.contentPanel, BorderLayout.CENTER);
contentPanel.setLayout(null); this.contentPanel.setLayout(null);
JLabel lblMantisUsername = new JLabel("Username"); final JLabel lblMantisUsername = new JLabel("Username");
lblMantisUsername.setHorizontalAlignment(SwingConstants.RIGHT); lblMantisUsername.setHorizontalAlignment(SwingConstants.RIGHT);
lblMantisUsername.setBounds(10, 16, 75, 14); lblMantisUsername.setBounds(10, 16, 75, 14);
contentPanel.add(lblMantisUsername); this.contentPanel.add(lblMantisUsername);
txtUserName = new JTextField("ForgeGUI"); this.txtUserName = new JTextField("ForgeGUI");
txtUserName.setBounds(90, 13, 185, 21); this.txtUserName.setBounds(90, 13, 185, 21);
txtUserName.setFont(new Font("Dialog", Font.PLAIN, 11)); this.txtUserName.setFont(new Font("Dialog", Font.PLAIN, 11));
contentPanel.add(txtUserName); this.contentPanel.add(this.txtUserName);
txtUserName.setColumns(4); this.txtUserName.setColumns(4);
try { try {
prefs = new ForgePreferences("forge.preferences"); this.prefs = new ForgePreferences("forge.preferences");
if (!prefs.BugzName.equals("")) { if (!this.prefs.BugzName.equals("")) {
txtUserName.setText(prefs.BugzName); this.txtUserName.setText(this.prefs.BugzName);
txtPassword.setText(prefs.BugzPwd); this.txtPassword.setText(this.prefs.BugzPwd);
chkReportAnonymously.setSelected(false); this.chkReportAnonymously.setSelected(false);
} else { } else {
chkReportAnonymously.setSelected(true); this.chkReportAnonymously.setSelected(true);
} }
} catch (Exception e) { } catch (final Exception e) {
} }
chkReportAnonymously.setBounds(284, 11, 139, 25); this.chkReportAnonymously.setBounds(284, 11, 139, 25);
chkReportAnonymously.setFont(new Font("Dialog", Font.PLAIN, 12)); this.chkReportAnonymously.setFont(new Font("Dialog", Font.PLAIN, 12));
chkReportAnonymously.setHorizontalAlignment(SwingConstants.CENTER); this.chkReportAnonymously.setHorizontalAlignment(SwingConstants.CENTER);
chkReportAnonymously.addActionListener(new java.awt.event.ActionListener() { this.chkReportAnonymously.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) { public void actionPerformed(final ActionEvent e) {
if (chkReportAnonymously.isSelected()) { if (BugzReporter.this.chkReportAnonymously.isSelected()) {
txtUserName.setText("ForgeGUI"); BugzReporter.this.txtUserName.setText("ForgeGUI");
txtPassword.setText("vi2ccTbfBUu^"); BugzReporter.this.txtPassword.setText("vi2ccTbfBUu^");
} else { } else {
if (!prefs.BugzName.equals("")) { if (!BugzReporter.this.prefs.BugzName.equals("")) {
txtUserName.setText(prefs.BugzName); BugzReporter.this.txtUserName.setText(BugzReporter.this.prefs.BugzName);
txtPassword.setText(prefs.BugzPwd); BugzReporter.this.txtPassword.setText(BugzReporter.this.prefs.BugzPwd);
} }
} }
} }
}); });
contentPanel.add(chkReportAnonymously); this.contentPanel.add(this.chkReportAnonymously);
JLabel lblMantisPassword = new JLabel("Password"); final JLabel lblMantisPassword = new JLabel("Password");
lblMantisPassword.setHorizontalAlignment(SwingConstants.RIGHT); lblMantisPassword.setHorizontalAlignment(SwingConstants.RIGHT);
lblMantisPassword.setBounds(10, 45, 75, 14); lblMantisPassword.setBounds(10, 45, 75, 14);
contentPanel.add(lblMantisPassword); this.contentPanel.add(lblMantisPassword);
txtPassword.setBounds(90, 42, 185, 21); this.txtPassword.setBounds(90, 42, 185, 21);
txtPassword.setFont(new Font("Dialog", Font.PLAIN, 11)); this.txtPassword.setFont(new Font("Dialog", Font.PLAIN, 11));
contentPanel.add(txtPassword); this.contentPanel.add(this.txtPassword);
JSeparator separator = new JSeparator(); final JSeparator separator = new JSeparator();
separator.setBounds(10, 69, 417, 2); separator.setBounds(10, 69, 417, 2);
contentPanel.add(separator); this.contentPanel.add(separator);
JLabel lblCategory = new JLabel("Category"); final JLabel lblCategory = new JLabel("Category");
lblCategory.setBounds(10, 81, 75, 14); lblCategory.setBounds(10, 81, 75, 14);
lblCategory.setFont(new Font("Tahoma", Font.BOLD, 11)); lblCategory.setFont(new Font("Tahoma", Font.BOLD, 11));
lblCategory.setHorizontalAlignment(SwingConstants.RIGHT); lblCategory.setHorizontalAlignment(SwingConstants.RIGHT);
contentPanel.add(lblCategory); this.contentPanel.add(lblCategory);
cboCategory.setBounds(90, 77, 223, 22); this.cboCategory.setBounds(90, 77, 223, 22);
cboCategory.setFont(new Font("Dialog", Font.BOLD, 10)); this.cboCategory.setFont(new Font("Dialog", Font.BOLD, 10));
if (cats.length > 0) { if (cats.length > 0) {
for (int i = 0; i < cats.length; i++) { for (final String cat : cats) {
cboCategory.addItem(cats[i]); this.cboCategory.addItem(cat);
} }
} }
cboCategory.setSelectedItem("General Bug Report"); this.cboCategory.setSelectedItem("General Bug Report");
contentPanel.add(cboCategory); this.contentPanel.add(this.cboCategory);
JLabel lblSummary = new JLabel("Summary"); final JLabel lblSummary = new JLabel("Summary");
lblSummary.setBounds(10, 108, 75, 14); lblSummary.setBounds(10, 108, 75, 14);
lblSummary.setFont(new Font("Tahoma", Font.BOLD, 11)); lblSummary.setFont(new Font("Tahoma", Font.BOLD, 11));
lblSummary.setHorizontalAlignment(SwingConstants.RIGHT); lblSummary.setHorizontalAlignment(SwingConstants.RIGHT);
contentPanel.add(lblSummary); this.contentPanel.add(lblSummary);
txtSummary = new JTextField(); this.txtSummary = new JTextField();
txtSummary.setBounds(90, 105, 337, 21); this.txtSummary.setBounds(90, 105, 337, 21);
txtSummary.setFont(new Font("Dialog", Font.PLAIN, 11)); this.txtSummary.setFont(new Font("Dialog", Font.PLAIN, 11));
contentPanel.add(txtSummary); this.contentPanel.add(this.txtSummary);
txtSummary.setColumns(10); this.txtSummary.setColumns(10);
JLabel lblDescription = new JLabel("Description"); final JLabel lblDescription = new JLabel("Description");
lblDescription.setBounds(10, 182, 75, 21); lblDescription.setBounds(10, 182, 75, 21);
lblDescription.setFont(new Font("Tahoma", Font.BOLD, 11)); lblDescription.setFont(new Font("Tahoma", Font.BOLD, 11));
lblDescription.setHorizontalAlignment(SwingConstants.RIGHT); lblDescription.setHorizontalAlignment(SwingConstants.RIGHT);
contentPanel.add(lblDescription); this.contentPanel.add(lblDescription);
JScrollPane scrollPane = new JScrollPane(); final JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(90, 132, 337, 120); scrollPane.setBounds(90, 132, 337, 120);
contentPanel.add(scrollPane); this.contentPanel.add(scrollPane);
txtDescription.setFont(new Font("Dialog", Font.PLAIN, 10)); this.txtDescription.setFont(new Font("Dialog", Font.PLAIN, 10));
scrollPane.setViewportView(txtDescription); scrollPane.setViewportView(this.txtDescription);
txtDescription.setBorder(null); this.txtDescription.setBorder(null);
txtDescription.setWrapStyleWord(true); this.txtDescription.setWrapStyleWord(true);
txtDescription.setLineWrap(true); this.txtDescription.setLineWrap(true);
txtDescription.setRows(8); this.txtDescription.setRows(8);
lblAddInfo.setText("<html><p align=\"right\">Additional<br>Information</p></html>"); this.lblAddInfo.setText("<html><p align=\"right\">Additional<br>Information</p></html>");
lblAddInfo.setBounds(10, 294, 75, 40); this.lblAddInfo.setBounds(10, 294, 75, 40);
lblAddInfo.setFont(new Font("Dialog", Font.PLAIN, 12)); this.lblAddInfo.setFont(new Font("Dialog", Font.PLAIN, 12));
lblAddInfo.setHorizontalAlignment(SwingConstants.RIGHT); this.lblAddInfo.setHorizontalAlignment(SwingConstants.RIGHT);
contentPanel.add(lblAddInfo); this.contentPanel.add(this.lblAddInfo);
JScrollPane scrollPane3 = new JScrollPane(); final JScrollPane scrollPane3 = new JScrollPane();
scrollPane3.setBounds(90, 254, 337, 120); scrollPane3.setBounds(90, 254, 337, 120);
contentPanel.add(scrollPane3); this.contentPanel.add(scrollPane3);
txtErrorDump.setFont(new Font("Monospaced", Font.PLAIN, 10)); this.txtErrorDump.setFont(new Font("Monospaced", Font.PLAIN, 10));
scrollPane.setViewportView(txtErrorDump); scrollPane.setViewportView(this.txtErrorDump);
txtErrorDump.setAutoscrolls(false); this.txtErrorDump.setAutoscrolls(false);
txtErrorDump.setMaximumSize(new Dimension(2147483647, 300)); this.txtErrorDump.setMaximumSize(new Dimension(2147483647, 300));
txtErrorDump.setBorder(null); this.txtErrorDump.setBorder(null);
txtErrorDump.setLineWrap(true); this.txtErrorDump.setLineWrap(true);
txtErrorDump.setWrapStyleWord(true); this.txtErrorDump.setWrapStyleWord(true);
txtErrorDump.setRows(8); this.txtErrorDump.setRows(8);
JLabel lblVersion = new JLabel("Version"); final JLabel lblVersion = new JLabel("Version");
lblVersion.setHorizontalAlignment(SwingConstants.RIGHT); lblVersion.setHorizontalAlignment(SwingConstants.RIGHT);
lblVersion.setBounds(20, 468, 65, 16); lblVersion.setBounds(20, 468, 65, 16);
lblVersion.setFont(new Font("Dialog", Font.PLAIN, 12)); lblVersion.setFont(new Font("Dialog", Font.PLAIN, 12));
contentPanel.add(lblVersion); this.contentPanel.add(lblVersion);
cboVersion.setBounds(90, 465, 160, 22); this.cboVersion.setBounds(90, 465, 160, 22);
cboVersion.setFont(new Font("Dialog", Font.BOLD, 10)); this.cboVersion.setFont(new Font("Dialog", Font.BOLD, 10));
cboVersion.addItem(""); this.cboVersion.addItem("");
if (vers.length > 0) { if (vers.length > 0) {
for (int i = 0; i < vers.length; i++) { for (final IProjectVersion ver : vers) {
cboVersion.addItem(vers[i].getName()); this.cboVersion.addItem(ver.getName());
// System.out.println(vers[i].getName()); // System.out.println(vers[i].getName());
} }
} }
cboVersion.setSelectedIndex(0); this.cboVersion.setSelectedIndex(0);
String curVer = bi.getVersion(); final String curVer = bi.getVersion();
String[] ss = curVer.split("-"); final String[] ss = curVer.split("-");
String rx = "^" + ss[0].replaceAll("\\.", "\\\\.") + ".*"; final String rx = "^" + ss[0].replaceAll("\\.", "\\\\.") + ".*";
System.out.println(ss[0] + " -> " + rx); System.out.println(ss[0] + " -> " + rx);
if (curVer.equals("SVN")) { if (curVer.equals("SVN")) {
cboVersion.setSelectedItem("SVN"); this.cboVersion.setSelectedItem("SVN");
} else { } else {
for (int i = 0; i < vers.length; i++) { for (final IProjectVersion ver : vers) {
System.out.println(vers[i].getName()); System.out.println(ver.getName());
if (vers[i].getName().matches(rx)) { if (ver.getName().matches(rx)) {
System.out.println("match"); System.out.println("match");
cboVersion.setSelectedItem(vers[i].getName()); this.cboVersion.setSelectedItem(ver.getName());
} }
} }
} }
contentPanel.add(cboVersion); this.contentPanel.add(this.cboVersion);
JLabel lblRev = new JLabel("SVN rev."); final JLabel lblRev = new JLabel("SVN rev.");
lblRev.setBounds(247, 468, 66, 16); lblRev.setBounds(247, 468, 66, 16);
lblRev.setHorizontalAlignment(SwingConstants.RIGHT); lblRev.setHorizontalAlignment(SwingConstants.RIGHT);
lblRev.setFont(new Font("Dialog", Font.PLAIN, 12)); lblRev.setFont(new Font("Dialog", Font.PLAIN, 12));
contentPanel.add(lblRev); this.contentPanel.add(lblRev);
txtSVN = new JTextField(); this.txtSVN = new JTextField();
String curRev = bi.getBuildID(); final String curRev = bi.getBuildID();
if (curRev != null) { if (curRev != null) {
if (!curRev.equals("null")) { if (!curRev.equals("null")) {
txtSVN.setText(curRev); this.txtSVN.setText(curRev);
} }
} }
txtSVN.setBounds(318, 465, 109, 21); this.txtSVN.setBounds(318, 465, 109, 21);
txtSVN.setFont(new Font("Dialog", Font.PLAIN, 11)); this.txtSVN.setFont(new Font("Dialog", Font.PLAIN, 11));
txtSVN.setColumns(10); this.txtSVN.setColumns(10);
contentPanel.add(txtSVN); this.contentPanel.add(this.txtSVN);
JLabel lblSeverity = new JLabel("Severity"); final JLabel lblSeverity = new JLabel("Severity");
lblSeverity.setBounds(10, 496, 75, 16); lblSeverity.setBounds(10, 496, 75, 16);
lblSeverity.setFont(new Font("Dialog", Font.PLAIN, 12)); lblSeverity.setFont(new Font("Dialog", Font.PLAIN, 12));
lblSeverity.setHorizontalAlignment(SwingConstants.RIGHT); lblSeverity.setHorizontalAlignment(SwingConstants.RIGHT);
contentPanel.add(lblSeverity); this.contentPanel.add(lblSeverity);
cboSeverity.setBounds(90, 493, 160, 22); this.cboSeverity.setBounds(90, 493, 160, 22);
cboSeverity.setFont(new Font("Dialog", Font.BOLD, 10)); this.cboSeverity.setFont(new Font("Dialog", Font.BOLD, 10));
cboSeverity.addItem(""); this.cboSeverity.addItem("");
if (Severities.length > 0) { if (this.severities.length > 0) {
for (int i = 0; i < Severities.length; i++) { for (final IMCAttribute severitie : this.severities) {
cboSeverity.addItem(Severities[i].getName()); this.cboSeverity.addItem(severitie.getName());
} }
} }
contentPanel.add(cboSeverity); this.contentPanel.add(this.cboSeverity);
JScrollPane scrollPane2 = new JScrollPane(); final JScrollPane scrollPane2 = new JScrollPane();
scrollPane2.setBounds(90, 380, 337, 80); scrollPane2.setBounds(90, 380, 337, 80);
contentPanel.add(scrollPane2); this.contentPanel.add(scrollPane2);
txtSteps.setWrapStyleWord(true); this.txtSteps.setWrapStyleWord(true);
txtSteps.setRows(5); this.txtSteps.setRows(5);
txtSteps.setMaximumSize(new Dimension(2147483647, 300)); this.txtSteps.setMaximumSize(new Dimension(2147483647, 300));
txtSteps.setLineWrap(true); this.txtSteps.setLineWrap(true);
txtSteps.setFont(new Font("Monospaced", Font.PLAIN, 10)); this.txtSteps.setFont(new Font("Monospaced", Font.PLAIN, 10));
txtSteps.setAutoscrolls(false); this.txtSteps.setAutoscrolls(false);
scrollPane.setViewportView(txtSteps); scrollPane.setViewportView(this.txtSteps);
JLabel lblSteps = new JLabel(); final JLabel lblSteps = new JLabel();
lblSteps.setText("<html><p align=\"right\">Steps to<br>Reproduce</p></html>"); lblSteps.setText("<html><p align=\"right\">Steps to<br>Reproduce</p></html>");
lblSteps.setHorizontalAlignment(SwingConstants.RIGHT); lblSteps.setHorizontalAlignment(SwingConstants.RIGHT);
lblSteps.setFont(new Font("Dialog", Font.PLAIN, 12)); lblSteps.setFont(new Font("Dialog", Font.PLAIN, 12));
lblSteps.setBounds(10, 400, 75, 40); lblSteps.setBounds(10, 400, 75, 40);
contentPanel.add(lblSteps); this.contentPanel.add(lblSteps);
JPanel buttonPane = new JPanel(); final JPanel buttonPane = new JPanel();
buttonPane.setOpaque(false); buttonPane.setOpaque(false);
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
getContentPane().add(buttonPane, BorderLayout.SOUTH); this.getContentPane().add(buttonPane, BorderLayout.SOUTH);
JButton cmdReport = new JButton("Report"); final JButton cmdReport = new JButton("Report");
cmdReport.addActionListener(new ActionListener() { cmdReport.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent arg0) { public void actionPerformed(final ActionEvent arg0) {
doReport(); BugzReporter.this.doReport();
} }
}); });
buttonPane.add(cmdReport); buttonPane.add(cmdReport);
JButton cmdCancel = new JButton("Cancel"); final JButton cmdCancel = new JButton("Cancel");
cmdCancel.addActionListener(new ActionListener() { cmdCancel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent arg0) { public void actionPerformed(final ActionEvent arg0) {
dialog.dispose(); BugzReporter.dialog.dispose();
} }
}); });
buttonPane.add(cmdCancel); buttonPane.add(cmdCancel);
@@ -359,26 +363,26 @@ public class BugzReporter extends JDialog {
private void doReport() { private void doReport() {
Report: { Report: {
if (txtSummary.getText().length() < 4) { if (this.txtSummary.getText().length() < 4) {
JOptionPane.showMessageDialog(null, "Summary field must be provided", "Bug Report", JOptionPane.showMessageDialog(null, "Summary field must be provided", "Bug Report",
JOptionPane.ERROR_MESSAGE); JOptionPane.ERROR_MESSAGE);
break Report; break Report;
} }
if (txtDescription.getText().length() < 10) { if (this.txtDescription.getText().length() < 10) {
JOptionPane.showMessageDialog(null, "Description field must be provided", "Bug Report", JOptionPane.showMessageDialog(null, "Description field must be provided", "Bug Report",
JOptionPane.ERROR_MESSAGE); JOptionPane.ERROR_MESSAGE);
break Report; break Report;
} }
MCSession rep = null; MCSession rep = null;
if (!chkReportAnonymously.isSelected()) { if (!this.chkReportAnonymously.isSelected()) {
try { try {
rep = new MCSession(new URL("http://cardforge.org/bugz/api/soap/mantisconnect.php"), rep = new MCSession(new URL("http://cardforge.org/bugz/api/soap/mantisconnect.php"),
txtUserName.getText(), String.valueOf(txtPassword.getPassword())); this.txtUserName.getText(), String.valueOf(this.txtPassword.getPassword()));
} catch (MalformedURLException e) { } catch (final MalformedURLException e) {
System.out.println("MalFormedURLException"); System.out.println("MalFormedURLException");
} catch (MCException e) { } catch (final MCException e) {
System.out.println("MCException - new MCSession - " + e.getMessage()); System.out.println("MCException - new MCSession - " + e.getMessage());
JOptionPane.showMessageDialog(null, "MCException - new MCSession - " + e.getMessage(), JOptionPane.showMessageDialog(null, "MCException - new MCSession - " + e.getMessage(),
"Bug Report", JOptionPane.INFORMATION_MESSAGE); "Bug Report", JOptionPane.INFORMATION_MESSAGE);
@@ -388,9 +392,9 @@ public class BugzReporter extends JDialog {
try { try {
rep = new MCSession(new URL("http://cardforge.org/bugz/api/soap/mantisconnect.php"), "ForgeGUI", rep = new MCSession(new URL("http://cardforge.org/bugz/api/soap/mantisconnect.php"), "ForgeGUI",
"vi2ccTbfBUu^"); "vi2ccTbfBUu^");
} catch (MalformedURLException e) { } catch (final MalformedURLException e) {
System.out.println("MalformedURLException"); System.out.println("MalformedURLException");
} catch (MCException e) { } catch (final MCException e) {
System.out.println("MCException - new MCSession - " + e.getMessage()); System.out.println("MCException - new MCSession - " + e.getMessage());
JOptionPane.showMessageDialog(null, "MCException - new MCSession - " + e.getMessage(), JOptionPane.showMessageDialog(null, "MCException - new MCSession - " + e.getMessage(),
"Bug Report", JOptionPane.INFORMATION_MESSAGE); "Bug Report", JOptionPane.INFORMATION_MESSAGE);
@@ -401,52 +405,52 @@ public class BugzReporter extends JDialog {
IIssue iBug = null; IIssue iBug = null;
try { try {
iBug = rep.newIssue(1); iBug = rep.newIssue(1);
} catch (MCException e) { } catch (final MCException e) {
System.out.println("MCException - newIssue - " + e.getMessage()); System.out.println("MCException - newIssue - " + e.getMessage());
JOptionPane.showMessageDialog(null, "MCException - newIssue - " + e.getMessage(), "Bug Report", JOptionPane.showMessageDialog(null, "MCException - newIssue - " + e.getMessage(), "Bug Report",
JOptionPane.INFORMATION_MESSAGE); JOptionPane.INFORMATION_MESSAGE);
break Report; break Report;
} }
iBug.setCategory(cboCategory.getSelectedItem().toString()); iBug.setCategory(this.cboCategory.getSelectedItem().toString());
iBug.setSummary(txtSummary.getText()); iBug.setSummary(this.txtSummary.getText());
iBug.setDescription(txtDescription.getText()); iBug.setDescription(this.txtDescription.getText());
iBug.setAdditionalInformation(txtErrorDump.getText()); iBug.setAdditionalInformation(this.txtErrorDump.getText());
iBug.setVersion(cboVersion.getSelectedItem().toString()); iBug.setVersion(this.cboVersion.getSelectedItem().toString());
for (int i = 0; i < Severities.length; i++) { for (final IMCAttribute severitie : this.severities) {
if (cboSeverity.getSelectedItem().toString().equals(Severities[i].getName())) { if (this.cboSeverity.getSelectedItem().toString().equals(severitie.getName())) {
iBug.setSeverity(Severities[i]); iBug.setSeverity(severitie);
} }
} }
iBug.setStepsToReproduce(txtSteps.getText()); iBug.setStepsToReproduce(this.txtSteps.getText());
ICustomFieldValue[] icfv = {new CustomFieldValue(new MCAttribute(1, "Detected at SVN Rev"), final ICustomFieldValue[] icfv = { new CustomFieldValue(new MCAttribute(1, "Detected at SVN Rev"),
txtSVN.getText())}; this.txtSVN.getText()) };
iBug.setCustomFields(icfv); iBug.setCustomFields(icfv);
DefaultSubmitter ds = new DefaultSubmitter(false); final DefaultSubmitter ds = new DefaultSubmitter(false);
try { try {
ds.submitIssue(rep, iBug); ds.submitIssue(rep, iBug);
} catch (MCException e1) { } catch (final MCException e1) {
System.out.println("MCException - submit Issue - " + e1.getMessage()); System.out.println("MCException - submit Issue - " + e1.getMessage());
JOptionPane.showMessageDialog(null, "MCException - submit Issue - " + e1.getMessage(), "Bug Report", JOptionPane.showMessageDialog(null, "MCException - submit Issue - " + e1.getMessage(), "Bug Report",
JOptionPane.INFORMATION_MESSAGE); JOptionPane.INFORMATION_MESSAGE);
break Report; break Report;
} }
prefs.BugzName = txtUserName.getText(); this.prefs.BugzName = this.txtUserName.getText();
prefs.BugzPwd = String.valueOf(txtPassword.getPassword()); this.prefs.BugzPwd = String.valueOf(this.txtPassword.getPassword());
try { try {
prefs.save(); this.prefs.save();
} catch (Exception e) { } catch (final Exception e) {
System.out.println("Exception - save preferences - " + e.getMessage()); System.out.println("Exception - save preferences - " + e.getMessage());
} }
JOptionPane.showMessageDialog(null, "This Issue Has Been Reported, Thank You.", "Bug Report", JOptionPane.showMessageDialog(null, "This Issue Has Been Reported, Thank You.", "Bug Report",
JOptionPane.INFORMATION_MESSAGE); JOptionPane.INFORMATION_MESSAGE);
dialog.dispose(); BugzReporter.dialog.dispose();
} // Report: } // Report:
} }

View File

@@ -1,15 +1,9 @@
package forge.error; package forge.error;
import static forge.properties.ForgeProps.getLocalized;
import static forge.properties.ForgeProps.getProperty;
import static java.awt.event.InputEvent.CTRL_DOWN_MASK;
import static java.awt.event.KeyEvent.VK_B;
import static java.awt.event.KeyEvent.VK_S;
import static javax.swing.JOptionPane.DEFAULT_OPTION;
import static javax.swing.JOptionPane.ERROR_MESSAGE;
import java.awt.Font; import java.awt.Font;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
@@ -30,6 +24,7 @@ import javax.swing.JTextArea;
import javax.swing.KeyStroke; import javax.swing.KeyStroke;
import forge.Singletons; import forge.Singletons;
import forge.properties.ForgeProps;
import forge.properties.NewConstants; import forge.properties.NewConstants;
/** /**
@@ -64,7 +59,7 @@ public class ErrorViewer implements NewConstants, NewConstants.LANG.ErrorViewer
* a {@link java.lang.Throwable} object. * a {@link java.lang.Throwable} object.
*/ */
public static void showError(final Throwable ex) { public static void showError(final Throwable ex) {
showError(ex, null); ErrorViewer.showError(ex, null);
} }
/** /**
@@ -82,7 +77,7 @@ public class ErrorViewer implements NewConstants, NewConstants.LANG.ErrorViewer
if (ex == null) { if (ex == null) {
return; return;
} }
showError(ex, String.format(format, args)); ErrorViewer.showError(ex, String.format(format, args));
} }
/** /**
@@ -99,10 +94,10 @@ public class ErrorViewer implements NewConstants, NewConstants.LANG.ErrorViewer
} }
final StringWriter sw = new StringWriter(); final StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw); final PrintWriter pw = new PrintWriter(sw);
printError(pw, ex, message); ErrorViewer.printError(pw, ex, message);
showDialog(sw.toString()); ErrorViewer.showDialog(sw.toString());
} }
/** /**
@@ -114,7 +109,7 @@ public class ErrorViewer implements NewConstants, NewConstants.LANG.ErrorViewer
* a {@link java.lang.Object} object. * a {@link java.lang.Object} object.
*/ */
public static void showError(final String format, final Object... args) { public static void showError(final String format, final Object... args) {
showError(String.format(format, args)); ErrorViewer.showError(String.format(format, args));
} }
/** /**
@@ -124,7 +119,7 @@ public class ErrorViewer implements NewConstants, NewConstants.LANG.ErrorViewer
* a {@link java.lang.String} object. * a {@link java.lang.String} object.
*/ */
public static void showError(final String message) { public static void showError(final String message) {
showError(new Exception(), message); ErrorViewer.showError(new Exception(), message);
} }
/** /**
@@ -136,7 +131,7 @@ public class ErrorViewer implements NewConstants, NewConstants.LANG.ErrorViewer
* a {@link java.lang.Object} object. * a {@link java.lang.Object} object.
*/ */
public static void showErrorAllThreads(final String format, final Object... args) { public static void showErrorAllThreads(final String format, final Object... args) {
showErrorAllThreads(String.format(format, args)); ErrorViewer.showErrorAllThreads(String.format(format, args));
} }
/** /**
@@ -147,10 +142,10 @@ public class ErrorViewer implements NewConstants, NewConstants.LANG.ErrorViewer
*/ */
public static void showErrorAllThreads(final String message) { public static void showErrorAllThreads(final String message) {
final StringWriter sw = new StringWriter(); final StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw); final PrintWriter pw = new PrintWriter(sw);
printError(pw, message); ErrorViewer.printError(pw, message);
showDialog(sw.toString()); ErrorViewer.showDialog(sw.toString());
} }
/** /**
@@ -162,7 +157,7 @@ public class ErrorViewer implements NewConstants, NewConstants.LANG.ErrorViewer
* a {@link java.lang.String} object. * a {@link java.lang.String} object.
*/ */
private static void showDialog(final String fullMessage) { private static void showDialog(final String fullMessage) {
JTextArea area = new JTextArea(fullMessage, 40, 90); final JTextArea area = new JTextArea(fullMessage, 40, 90);
area.setFont(new Font("Monospaced", Font.PLAIN, 10)); area.setFont(new Font("Monospaced", Font.PLAIN, 10));
area.setEditable(false); area.setEditable(false);
area.setLineWrap(true); area.setLineWrap(true);
@@ -170,15 +165,15 @@ public class ErrorViewer implements NewConstants, NewConstants.LANG.ErrorViewer
// Button is not modified, String gets the automatic listener to hide // Button is not modified, String gets the automatic listener to hide
// the dialog // the dialog
Object[] options = {new JButton(new BugzAction(area)), new JButton(new SaveAction(area)), final Object[] options = { new JButton(new BugzAction(area)), new JButton(new SaveAction(area)),
getLocalized(BUTTON_CLOSE), new JButton(new ExitAction())}; ForgeProps.getLocalized(ErrorViewer.BUTTON_CLOSE), new JButton(new ExitAction()) };
JOptionPane pane = new JOptionPane(new JScrollPane(area), ERROR_MESSAGE, DEFAULT_OPTION, null, options, final JOptionPane pane = new JOptionPane(new JScrollPane(area), JOptionPane.ERROR_MESSAGE,
options[1]); JOptionPane.DEFAULT_OPTION, null, options, options[1]);
dlg = pane.createDialog(null, getLocalized(TITLE)); ErrorViewer.dlg = pane.createDialog(null, ForgeProps.getLocalized(ErrorViewer.TITLE));
dlg.setResizable(true); ErrorViewer.dlg.setResizable(true);
dlg.setVisible(true); ErrorViewer.dlg.setVisible(true);
dlg.dispose(); ErrorViewer.dlg.dispose();
} }
/** /**
@@ -197,10 +192,12 @@ public class ErrorViewer implements NewConstants, NewConstants.LANG.ErrorViewer
} }
ex.printStackTrace(); ex.printStackTrace();
pw.printf(getLocalized(MESSAGE), getProperty(HOW_TO_REPORT_BUGS_URL), pw.printf(ForgeProps.getLocalized(ErrorViewer.MESSAGE),
ForgeProps.getProperty(NewConstants.HOW_TO_REPORT_BUGS_URL),
message != null ? message : ex.getMessage(), Singletons.getModel().getBuildInfo().toPrettyString(), message != null ? message : ex.getMessage(), Singletons.getModel().getBuildInfo().toPrettyString(),
System.getProperty(NAME_OS), System.getProperty(VERSION_OS), System.getProperty(ARCHITECTURE_OS), System.getProperty(ErrorViewer.NAME_OS), System.getProperty(ErrorViewer.VERSION_OS),
System.getProperty(VERSION_JAVA), System.getProperty(VENDOR_JAVA)); System.getProperty(ErrorViewer.ARCHITECTURE_OS), System.getProperty(ErrorViewer.VERSION_JAVA),
System.getProperty(ErrorViewer.VENDOR_JAVA));
ex.printStackTrace(pw); ex.printStackTrace(pw);
} }
@@ -216,14 +213,16 @@ public class ErrorViewer implements NewConstants, NewConstants.LANG.ErrorViewer
private static void printError(final PrintWriter pw, final String message) { private static void printError(final PrintWriter pw, final String message) {
System.err.println(message); System.err.println(message);
pw.printf(getLocalized(MESSAGE), getProperty(HOW_TO_REPORT_BUGS_URL), message, Singletons.getModel() pw.printf(ForgeProps.getLocalized(ErrorViewer.MESSAGE),
.getBuildInfo().toPrettyString(), System.getProperty(NAME_OS), System.getProperty(VERSION_OS), ForgeProps.getProperty(NewConstants.HOW_TO_REPORT_BUGS_URL), message, Singletons.getModel()
System.getProperty(ARCHITECTURE_OS), System.getProperty(VERSION_JAVA), System.getProperty(VENDOR_JAVA)); .getBuildInfo().toPrettyString(), System.getProperty(ErrorViewer.NAME_OS),
Map<Thread, StackTraceElement[]> traces = Thread.getAllStackTraces(); System.getProperty(ErrorViewer.VERSION_OS), System.getProperty(ErrorViewer.ARCHITECTURE_OS),
for (Entry<Thread, StackTraceElement[]> e : traces.entrySet()) { System.getProperty(ErrorViewer.VERSION_JAVA), System.getProperty(ErrorViewer.VENDOR_JAVA));
final Map<Thread, StackTraceElement[]> traces = Thread.getAllStackTraces();
for (final Entry<Thread, StackTraceElement[]> e : traces.entrySet()) {
pw.println(); pw.println();
pw.printf("%s (%s):%n", e.getKey().getName(), e.getKey().getId()); pw.printf("%s (%s):%n", e.getKey().getName(), e.getKey().getId());
for (StackTraceElement el : e.getValue()) { for (final StackTraceElement el : e.getValue()) {
pw.println(el); pw.println(el);
} }
} }
@@ -235,37 +234,38 @@ public class ErrorViewer implements NewConstants, NewConstants.LANG.ErrorViewer
private static JFileChooser c; private static JFileChooser c;
private JTextArea area; private final JTextArea area;
public SaveAction(final JTextArea areaParam) { public SaveAction(final JTextArea areaParam) {
super(getLocalized(BUTTON_SAVE)); super(ForgeProps.getLocalized(ErrorViewer.BUTTON_SAVE));
putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(VK_S, CTRL_DOWN_MASK)); this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK));
this.area = areaParam; this.area = areaParam;
} }
@Override
public void actionPerformed(final ActionEvent e) { public void actionPerformed(final ActionEvent e) {
if (c == null) { if (SaveAction.c == null) {
c = new JFileChooser(); SaveAction.c = new JFileChooser();
} }
File f; File f;
for (int i = 0;; i++) { for (int i = 0;; i++) {
String name = String.format("%TF-%02d.txt", System.currentTimeMillis(), i); final String name = String.format("%TF-%02d.txt", System.currentTimeMillis(), i);
f = new File(name); f = new File(name);
if (!f.exists()) { if (!f.exists()) {
break; break;
} }
} }
c.setSelectedFile(f); SaveAction.c.setSelectedFile(f);
c.showSaveDialog(null); SaveAction.c.showSaveDialog(null);
f = c.getSelectedFile(); f = SaveAction.c.getSelectedFile();
try { try {
BufferedWriter bw = new BufferedWriter(new FileWriter(f)); final BufferedWriter bw = new BufferedWriter(new FileWriter(f));
bw.write(area.getText()); bw.write(this.area.getText());
bw.close(); bw.close();
} catch (IOException ex) { } catch (final IOException ex) {
showError(ex, getLocalized(ERRORS.SAVE_MESSAGE)); ErrorViewer.showError(ex, ForgeProps.getLocalized(ERRORS.SAVE_MESSAGE));
} }
} }
} }
@@ -274,19 +274,20 @@ public class ErrorViewer implements NewConstants, NewConstants.LANG.ErrorViewer
private static final long serialVersionUID = 914634661273525959L; private static final long serialVersionUID = 914634661273525959L;
private JTextArea area; private final JTextArea area;
public BugzAction(final JTextArea neoArea) { public BugzAction(final JTextArea neoArea) {
putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(VK_B, CTRL_DOWN_MASK)); this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_B, InputEvent.CTRL_DOWN_MASK));
putValue(NAME, "Report Bug"); this.putValue(Action.NAME, "Report Bug");
this.area = neoArea; this.area = neoArea;
} }
@Override
public void actionPerformed(final ActionEvent e) { public void actionPerformed(final ActionEvent e) {
BugzReporter br = new BugzReporter(); final BugzReporter br = new BugzReporter();
br.setDumpText(area.getText()); br.setDumpText(this.area.getText());
br.setVisible(true); br.setVisible(true);
dlg.dispose(); ErrorViewer.dlg.dispose();
} }
} }
@@ -295,9 +296,10 @@ public class ErrorViewer implements NewConstants, NewConstants.LANG.ErrorViewer
private static final long serialVersionUID = 276202595758381626L; private static final long serialVersionUID = 276202595758381626L;
public ExitAction() { public ExitAction() {
super(getLocalized(BUTTON_EXIT)); super(ForgeProps.getLocalized(ErrorViewer.BUTTON_EXIT));
} }
@Override
public void actionPerformed(final ActionEvent e) { public void actionPerformed(final ActionEvent e) {
System.exit(0); System.exit(0);
} }
@@ -308,11 +310,12 @@ public class ErrorViewer implements NewConstants, NewConstants.LANG.ErrorViewer
private static final long serialVersionUID = 5638147106706803363L; private static final long serialVersionUID = 5638147106706803363L;
public ShowAllThreadsAction() { public ShowAllThreadsAction() {
super(getLocalized(SHOW_ERROR)); super(ForgeProps.getLocalized(ErrorViewer.SHOW_ERROR));
} }
@Override
public void actionPerformed(final ActionEvent e) { public void actionPerformed(final ActionEvent e) {
showErrorAllThreads(getLocalized(ERRORS.SHOW_MESSAGE)); ErrorViewer.showErrorAllThreads(ForgeProps.getLocalized(ERRORS.SHOW_MESSAGE));
} }
} }
} }

View File

@@ -34,6 +34,7 @@ public class ExceptionHandler implements UncaughtExceptionHandler {
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public final void uncaughtException(final Thread t, final Throwable ex) { public final void uncaughtException(final Thread t, final Throwable ex) {
ErrorViewer.showError(ex); ErrorViewer.showError(ex);
} }

View File

@@ -1,2 +1,3 @@
/** Forge Card Game. */ /** Forge Card Game. */
package forge.error; package forge.error;