diff --git a/src/main/java/forge/deck/generate/Generate2ColorDeck.java b/src/main/java/forge/deck/generate/Generate2ColorDeck.java index d8d5f0d6bd3..76e30dd93fc 100644 --- a/src/main/java/forge/deck/generate/Generate2ColorDeck.java +++ b/src/main/java/forge/deck/generate/Generate2ColorDeck.java @@ -38,12 +38,12 @@ public class Generate2ColorDeck { * Constructor for Generate2ColorDeck. *

* - * @param Clr1 + * @param clr1 * a {@link java.lang.String} object. - * @param Clr2 + * @param clr2 * 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.cardCounts = new HashMap(); @@ -62,7 +62,7 @@ public class Generate2ColorDeck { this.notColors.add("red"); this.notColors.add("green"); - if (Clr1.equals("AI")) { + if (clr1.equals("AI")) { // choose first color this.color1 = this.notColors.get(this.r.nextInt(5)); @@ -73,8 +73,8 @@ public class Generate2ColorDeck { } this.color2 = c2; } else { - this.color1 = Clr1; - this.color2 = Clr2; + this.color1 = clr1; + this.color2 = clr2; } this.notColors.remove(this.color1); @@ -93,24 +93,24 @@ public class Generate2ColorDeck { * get2ColorDeck. *

* - * @param Size + * @param size * a int. * @param pt * the pt * @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 String tmpDeck = ""; final CardList tDeck = new CardList(); - final int LandsPercentage = 42; - final int CreatPercentage = 34; - final int SpellPercentage = 24; + final int landsPercentage = 42; + final int creatPercentage = 34; + final int spellPercentage = 24; // start with all cards // 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 public boolean addCard(final Card c) { if (c.getSVar("RemRandomDeck").equals("True")) { @@ -121,9 +121,9 @@ public class Generate2ColorDeck { }); // reduce to cards that match the colors - CardList CL1 = AllCards.getColor(this.color1); - CL1.addAll(AllCards.getColor(Constant.Color.COLORLESS)); - CardList CL2 = AllCards.getColor(this.color2); + CardList cl1 = allCards.getColor(this.color1); + cl1.addAll(allCards.getColor(Constant.Color.COLORLESS)); + CardList cl2 = allCards.getColor(this.color2); // remove multicolor cards that don't match the colors final CardListFilter clrF = new CardListFilter() { @@ -138,58 +138,59 @@ public class Generate2ColorDeck { return true; } }; - CL1 = CL1.filter(clrF); - CL2 = CL2.filter(clrF); + cl1 = cl1.filter(clrF); + cl2 = cl2.filter(clrF); // build subsets based on type - final CardList Cr1 = CL1.getType("Creature"); - final CardList Cr2 = CL2.getType("Creature"); + final CardList cr1 = cl1.getType("Creature"); + final CardList cr2 = cl2.getType("Creature"); - final String[] ISE = { "Instant", "Sorcery", "Enchantment", "Planeswalker", "Artifact.nonCreature" }; - final CardList Sp1 = CL1.getValidCards(ISE, null, null); - final CardList Sp2 = CL2.getValidCards(ISE, null, null); + final String[] ise = { "Instant", "Sorcery", "Enchantment", "Planeswalker", "Artifact.nonCreature" }; + final CardList sp1 = cl1.getValidCards(ise, null, null); + final CardList sp2 = cl2.getValidCards(ise, null, null); // final card pools - final CardList Cr12 = new CardList(); - final CardList Sp12 = new CardList(); + final CardList cr12 = new CardList(); + final CardList sp12 = new CardList(); // 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() { @Override public boolean addCard(final Card c) { 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 for (int i = 4; i > 0; i--) { - final CardList Cr1CMC = Cr1.filter(cmcF); - final CardList Cr2CMC = Cr2.filter(cmcF); - final CardList Sp1CMC = Sp1.filter(cmcF); - final CardList Sp2CMC = Sp2.filter(cmcF); + final CardList cr1CMC = cr1.filter(cmcF); + final CardList cr2CMC = cr2.filter(cmcF); + final CardList sp1CMC = sp1.filter(cmcF); + final CardList sp2CMC = sp2.filter(cmcF); for (int j = 0; j < i; j++) { - Card c = Cr1CMC.get(this.r.nextInt(Cr1CMC.size())); - Cr12.add(c); + Card c = cr1CMC.get(this.r.nextInt(cr1CMC.size())); + cr12.add(c); this.cardCounts.put(c.getName(), 0); - c = Cr2CMC.get(this.r.nextInt(Cr2CMC.size())); - Cr12.add(c); + c = cr2CMC.get(this.r.nextInt(cr2CMC.size())); + cr12.add(c); this.cardCounts.put(c.getName(), 0); - c = Sp1CMC.get(this.r.nextInt(Sp1CMC.size())); - Sp12.add(c); + c = sp1CMC.get(this.r.nextInt(sp1CMC.size())); + sp12.add(c); this.cardCounts.put(c.getName(), 0); - c = Sp2CMC.get(this.r.nextInt(Sp2CMC.size())); - Sp12.add(c); + c = sp2CMC.get(this.r.nextInt(sp2CMC.size())); + sp12.add(c); this.cardCounts.put(c.getName(), 0); } - MinCMC[0] += 2; - MaxCMC[0] += 2; + minCMC[0] += 2; + maxCMC[0] += 2; // resulting mana curve of the card pool // 16x 1 - 2 // 12x 3 - 4 @@ -200,25 +201,25 @@ public class Generate2ColorDeck { } // shuffle card pools - Cr12.shuffle(); - Sp12.shuffle(); + cr12.shuffle(); + sp12.shuffle(); // calculate card counts - float p = (float) (CreatPercentage * .01); - final int CreatCnt = (int) (p * Size); - tmpDeck += "Creature Count:" + CreatCnt + "\n"; + float p = (float) (creatPercentage * .01); + final int creatCnt = (int) (p * size); + tmpDeck += "Creature Count:" + creatCnt + "\n"; - p = (float) (SpellPercentage * .01); - final int SpellCnt = (int) (p * Size); - tmpDeck += "Spell Count:" + SpellCnt + "\n"; + p = (float) (spellPercentage * .01); + final int spellCnt = (int) (p * size); + tmpDeck += "Spell Count:" + spellCnt + "\n"; // build deck from the card pools - for (int i = 0; i < CreatCnt; i++) { - Card c = Cr12.get(this.r.nextInt(Cr12.size())); + for (int i = 0; i < creatCnt; i++) { + Card c = cr12.get(this.r.nextInt(cr12.size())); lc = 0; 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++; } if (lc > 100) { @@ -231,12 +232,12 @@ public class Generate2ColorDeck { tmpDeck += c.getName() + " " + c.getManaCost() + "\n"; } - for (int i = 0; i < SpellCnt; i++) { - Card c = Sp12.get(this.r.nextInt(Sp12.size())); + for (int i = 0; i < spellCnt; i++) { + Card c = sp12.get(this.r.nextInt(sp12.size())); lc = 0; 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++; } if (lc > 100) { @@ -251,12 +252,12 @@ public class Generate2ColorDeck { // Add lands int numLands = 0; - if (LandsPercentage > 0) { - p = (float) (LandsPercentage * .01); - numLands = (int) (p * Size); + if (landsPercentage > 0) { + p = (float) (landsPercentage * .01); + numLands = (int) (p * size); } else { // otherwise, just fill in the rest of the deck with basic // lands - numLands = Size - tDeck.size(); + numLands = size - tDeck.size(); } tmpDeck += "numLands:" + numLands + "\n"; @@ -285,7 +286,7 @@ public class Generate2ColorDeck { if (numLands > 0) { // 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) }; // count each card color using mana costs @@ -298,15 +299,15 @@ public class Generate2ColorDeck { final char c = mc.charAt(j); if (c == 'W') { - ClrCnts[0].Count++; + clrCnts[0].count++; } else if (c == 'U') { - ClrCnts[1].Count++; + clrCnts[1].count++; } else if (c == 'B') { - ClrCnts[2].Count++; + clrCnts[2].count++; } else if (c == 'R') { - ClrCnts[3].Count++; + clrCnts[3].count++; } else if (c == 'G') { - ClrCnts[4].Count++; + clrCnts[4].count++; } } } @@ -314,25 +315,25 @@ public class Generate2ColorDeck { // total of all ClrCnts int totalColor = 0; for (int i = 0; i < 5; i++) { - totalColor += ClrCnts[i].Count; - tmpDeck += ClrCnts[i].Color + ":" + ClrCnts[i].Count + "\n"; + totalColor += clrCnts[i].count; + tmpDeck += clrCnts[i].color + ":" + clrCnts[i].count + "\n"; } tmpDeck += "totalColor:" + totalColor + "\n"; 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 - p = (float) ClrCnts[i].Count / (float) totalColor; + p = (float) clrCnts[i].count / (float) totalColor; 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 // code - this.cardCounts.put(ClrCnts[i].Color, nLand); + this.cardCounts.put(clrCnts[i].color, nLand); 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"; // fix under-sized or over-sized decks, due to integer arithmetic - if (tDeck.size() < Size) { - final int diff = Size - tDeck.size(); + if (tDeck.size() < size) { + final int diff = size - tDeck.size(); for (int i = 0; i < diff; i++) { Card c = tDeck.get(this.r.nextInt(tDeck.size())); 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())); lc++; } - if (lc > Size) { + if (lc > size) { throw new RuntimeException("Generate2ColorDeck : get2ColorDeck -- looped too much -- undersize"); } @@ -360,8 +361,8 @@ public class Generate2ColorDeck { this.cardCounts.put(c.getName(), n + 1); tmpDeck += "Added:" + c.getName() + "\n"; } - } else if (tDeck.size() > Size) { - final int diff = tDeck.size() - Size; + } else if (tDeck.size() > size) { + final int diff = tDeck.size() - size; for (int i = 0; i < diff; i++) { Card c = tDeck.get(this.r.nextInt(tDeck.size())); @@ -384,12 +385,12 @@ public class Generate2ColorDeck { } private class CCnt { - public String Color; - public int Count; + private String color; + private int count; public CCnt(final String clr, final int cnt) { - this.Color = clr; - this.Count = cnt; + this.color = clr; + this.count = cnt; } } } diff --git a/src/main/java/forge/deck/generate/Generate3ColorDeck.java b/src/main/java/forge/deck/generate/Generate3ColorDeck.java index 0255b87d844..e134fcffc6e 100644 --- a/src/main/java/forge/deck/generate/Generate3ColorDeck.java +++ b/src/main/java/forge/deck/generate/Generate3ColorDeck.java @@ -39,14 +39,14 @@ public class Generate3ColorDeck { * Constructor for Generate3ColorDeck. *

* - * @param Clr1 + * @param clr1 * a {@link java.lang.String} object. - * @param Clr2 + * @param clr2 * a {@link java.lang.String} object. - * @param Clr3 + * @param clr3 * 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.cardCounts = new HashMap(); @@ -65,7 +65,7 @@ public class Generate3ColorDeck { this.notColors.add("red"); this.notColors.add("green"); - if (Clr1.equals("AI")) { + if (clr1.equals("AI")) { // choose first color this.color1 = this.notColors.get(this.r.nextInt(5)); @@ -82,9 +82,9 @@ public class Generate3ColorDeck { } this.color3 = c3; } else { - this.color1 = Clr1; - this.color2 = Clr2; - this.color3 = Clr3; + this.color1 = clr1; + this.color2 = clr2; + this.color3 = clr3; } this.notColors.remove(this.color1); @@ -105,24 +105,24 @@ public class Generate3ColorDeck { * get3ColorDeck. *

* - * @param Size + * @param size * a int. * @param pt * the pt * @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 String tmpDeck = ""; final CardList tDeck = new CardList(); - final int LandsPercentage = 44; - final int CreatPercentage = 34; - final int SpellPercentage = 22; + final int landsPercentage = 44; + final int creatPercentage = 34; + final int spellPercentage = 22; // start with all cards // 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 public boolean addCard(final Card c) { if (c.getSVar("RemRandomDeck").equals("True")) { @@ -133,10 +133,10 @@ public class Generate3ColorDeck { }); // reduce to cards that match the colors - CardList CL1 = AllCards.getColor(this.color1); - CL1.addAll(AllCards.getColor(Constant.Color.COLORLESS)); - CardList CL2 = AllCards.getColor(this.color2); - CardList CL3 = AllCards.getColor(this.color3); + CardList cl1 = allCards.getColor(this.color1); + cl1.addAll(allCards.getColor(Constant.Color.COLORLESS)); + CardList cl2 = allCards.getColor(this.color2); + CardList cl3 = allCards.getColor(this.color3); // remove multicolor cards that don't match the colors final CardListFilter clrF = new CardListFilter() { @@ -151,72 +151,73 @@ public class Generate3ColorDeck { return true; } }; - CL1 = CL1.filter(clrF); - CL2 = CL2.filter(clrF); - CL3 = CL3.filter(clrF); + cl1 = cl1.filter(clrF); + cl2 = cl2.filter(clrF); + cl3 = cl3.filter(clrF); // build subsets based on type - final CardList Cr1 = CL1.getType("Creature"); - final CardList Cr2 = CL2.getType("Creature"); - final CardList Cr3 = CL3.getType("Creature"); + final CardList cr1 = cl1.getType("Creature"); + final CardList cr2 = cl2.getType("Creature"); + final CardList cr3 = cl3.getType("Creature"); - final String[] ISE = { "Instant", "Sorcery", "Enchantment", "Planeswalker", "Artifact.nonCreature" }; - final CardList Sp1 = CL1.getValidCards(ISE, null, null); - final CardList Sp2 = CL2.getValidCards(ISE, null, null); - final CardList Sp3 = CL3.getValidCards(ISE, null, null); + final String[] ise = { "Instant", "Sorcery", "Enchantment", "Planeswalker", "Artifact.nonCreature" }; + final CardList sp1 = cl1.getValidCards(ise, null, null); + final CardList sp2 = cl2.getValidCards(ise, null, null); + final CardList sp3 = cl3.getValidCards(ise, null, null); // final card pools - final CardList Cr123 = new CardList(); - final CardList Sp123 = new CardList(); + final CardList cr123 = new CardList(); + final CardList sp123 = new CardList(); // 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() { @Override public boolean addCard(final Card c) { 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 for (int i = 3; i > 0; i--) { - final CardList Cr1CMC = Cr1.filter(cmcF); - final CardList Cr2CMC = Cr2.filter(cmcF); - final CardList Cr3CMC = Cr3.filter(cmcF); + final CardList cr1CMC = cr1.filter(cmcF); + final CardList cr2CMC = cr2.filter(cmcF); + final CardList cr3CMC = cr3.filter(cmcF); - final CardList Sp1CMC = Sp1.filter(cmcF); - final CardList Sp2CMC = Sp2.filter(cmcF); - final CardList Sp3CMC = Sp3.filter(cmcF); + final CardList sp1CMC = sp1.filter(cmcF); + final CardList sp2CMC = sp2.filter(cmcF); + final CardList sp3CMC = sp3.filter(cmcF); for (int j = 0; j < i; j++) { - Card c = Cr1CMC.get(this.r.nextInt(Cr1CMC.size())); - Cr123.add(c); + Card c = cr1CMC.get(this.r.nextInt(cr1CMC.size())); + cr123.add(c); this.cardCounts.put(c.getName(), 0); - c = Cr2CMC.get(this.r.nextInt(Cr2CMC.size())); - Cr123.add(c); + c = cr2CMC.get(this.r.nextInt(cr2CMC.size())); + cr123.add(c); this.cardCounts.put(c.getName(), 0); - c = Cr3CMC.get(this.r.nextInt(Cr3CMC.size())); - Cr123.add(c); + c = cr3CMC.get(this.r.nextInt(cr3CMC.size())); + cr123.add(c); this.cardCounts.put(c.getName(), 0); - c = Sp1CMC.get(this.r.nextInt(Sp1CMC.size())); - Sp123.add(c); + c = sp1CMC.get(this.r.nextInt(sp1CMC.size())); + sp123.add(c); this.cardCounts.put(c.getName(), 0); - c = Sp2CMC.get(this.r.nextInt(Sp2CMC.size())); - Sp123.add(c); + c = sp2CMC.get(this.r.nextInt(sp2CMC.size())); + sp123.add(c); this.cardCounts.put(c.getName(), 0); - c = Sp3CMC.get(this.r.nextInt(Sp3CMC.size())); - Sp123.add(c); + c = sp3CMC.get(this.r.nextInt(sp3CMC.size())); + sp123.add(c); this.cardCounts.put(c.getName(), 0); } - MinCMC[0] += 2; - MaxCMC[0] += 2; + minCMC[0] += 2; + maxCMC[0] += 2; // resulting mana curve of the card pool // 18x 1 - 3 // 12x 3 - 5 @@ -226,25 +227,25 @@ public class Generate3ColorDeck { } // shuffle card pools - Cr123.shuffle(); - Sp123.shuffle(); + cr123.shuffle(); + sp123.shuffle(); // calculate card counts - float p = (float) (CreatPercentage * .01); - final int CreatCnt = (int) (p * Size); - tmpDeck += "Creature Count:" + CreatCnt + "\n"; + float p = (float) (creatPercentage * .01); + final int creatCnt = (int) (p * size); + tmpDeck += "Creature Count:" + creatCnt + "\n"; - p = (float) (SpellPercentage * .01); - final int SpellCnt = (int) (p * Size); - tmpDeck += "Spell Count:" + SpellCnt + "\n"; + p = (float) (spellPercentage * .01); + final int spellCnt = (int) (p * size); + tmpDeck += "Spell Count:" + spellCnt + "\n"; // build deck from the card pools - for (int i = 0; i < CreatCnt; i++) { - Card c = Cr123.get(this.r.nextInt(Cr123.size())); + for (int i = 0; i < creatCnt; i++) { + Card c = cr123.get(this.r.nextInt(cr123.size())); lc = 0; 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++; } if (lc > 100) { @@ -257,12 +258,12 @@ public class Generate3ColorDeck { tmpDeck += c.getName() + " " + c.getManaCost() + "\n"; } - for (int i = 0; i < SpellCnt; i++) { - Card c = Sp123.get(this.r.nextInt(Sp123.size())); + for (int i = 0; i < spellCnt; i++) { + Card c = sp123.get(this.r.nextInt(sp123.size())); lc = 0; 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++; } if (lc > 100) { @@ -277,12 +278,12 @@ public class Generate3ColorDeck { // Add lands int numLands = 0; - if (LandsPercentage > 0) { - p = (float) (LandsPercentage * .01); - numLands = (int) (p * Size); + if (landsPercentage > 0) { + p = (float) (landsPercentage * .01); + numLands = (int) (p * size); } else { // otherwise, just fill in the rest of the deck with basic lands - numLands = Size - tDeck.size(); + numLands = size - tDeck.size(); } tmpDeck += "numLands:" + numLands + "\n"; @@ -308,10 +309,10 @@ public class Generate3ColorDeck { numLands -= ndLands; - if (numLands > 0) // 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), + if (numLands > 0) { + // 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), new CCnt("Mountain", 0), new CCnt("Forest", 0) }; // count each card color using mana costs @@ -324,15 +325,15 @@ public class Generate3ColorDeck { final char c = mc.charAt(j); if (c == 'W') { - ClrCnts[0].Count++; + clrCnts[0].count++; } else if (c == 'U') { - ClrCnts[1].Count++; + clrCnts[1].count++; } else if (c == 'B') { - ClrCnts[2].Count++; + clrCnts[2].count++; } else if (c == 'R') { - ClrCnts[3].Count++; + clrCnts[3].count++; } else if (c == 'G') { - ClrCnts[4].Count++; + clrCnts[4].count++; } } } @@ -340,25 +341,25 @@ public class Generate3ColorDeck { // total of all ClrCnts int totalColor = 0; for (int i = 0; i < 5; i++) { - totalColor += ClrCnts[i].Count; - tmpDeck += ClrCnts[i].Color + ":" + ClrCnts[i].Count + "\n"; + totalColor += clrCnts[i].count; + tmpDeck += clrCnts[i].color + ":" + clrCnts[i].count + "\n"; } tmpDeck += "totalColor:" + totalColor + "\n"; 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 - p = (float) ClrCnts[i].Count / (float) totalColor; + p = (float) clrCnts[i].count / (float) totalColor; 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 // code - this.cardCounts.put(ClrCnts[i].Color, nLand); + this.cardCounts.put(clrCnts[i].color, nLand); 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"; // fix under-sized or over-sized decks, due to integer arithmetic - if (tDeck.size() < Size) { - final int diff = Size - tDeck.size(); + if (tDeck.size() < size) { + final int diff = size - tDeck.size(); for (int i = 0; i < diff; i++) { Card c = tDeck.get(this.r.nextInt(tDeck.size())); 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())); lc++; } - if (lc > Size) { + if (lc > size) { throw new RuntimeException("Generate3ColorDeck : get3ColorDeck -- looped too much -- undersize"); } @@ -386,8 +387,8 @@ public class Generate3ColorDeck { this.cardCounts.put(c.getName(), n + 1); tmpDeck += "Added:" + c.getName() + "\n"; } - } else if (tDeck.size() > Size) { - final int diff = tDeck.size() - Size; + } else if (tDeck.size() > size) { + final int diff = tDeck.size() - size; for (int i = 0; i < diff; i++) { Card c = tDeck.get(this.r.nextInt(tDeck.size())); @@ -411,12 +412,12 @@ public class Generate3ColorDeck { } private class CCnt { - public String Color; - public int Count; + private String color; + private int count; public CCnt(final String clr, final int cnt) { - this.Color = clr; - this.Count = cnt; + this.color = clr; + this.count = cnt; } } } diff --git a/src/main/java/forge/deck/generate/Generate5ColorDeck.java b/src/main/java/forge/deck/generate/Generate5ColorDeck.java index 2f768f1126d..df4ba8f4124 100644 --- a/src/main/java/forge/deck/generate/Generate5ColorDeck.java +++ b/src/main/java/forge/deck/generate/Generate5ColorDeck.java @@ -335,9 +335,9 @@ public class Generate5ColorDeck { numLands -= nDLands; - if (numLands > 0) // attempt to optimize basic land counts according to - // color representation - { + if (numLands > 0) { + // 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), new CCnt("Mountain", 0), new CCnt("Forest", 0) }; diff --git a/src/main/java/forge/deck/generate/GenerateConstructedMultiColorDeck.java b/src/main/java/forge/deck/generate/GenerateConstructedMultiColorDeck.java index 772b6bfcc11..39bf897c72d 100644 --- a/src/main/java/forge/deck/generate/GenerateConstructedMultiColorDeck.java +++ b/src/main/java/forge/deck/generate/GenerateConstructedMultiColorDeck.java @@ -485,9 +485,8 @@ public class GenerateConstructedMultiColorDeck { return ((CardUtil.getColors(c).size() <= 3) && !c.isLand() && // no // land - !c.getSVar("RemRandomDeck").equals("True") && !c.getSVar("RemAIDeck").equals("True")) || - // OR very important - goodLand.contains(c.getName()); + !c.getSVar("RemRandomDeck").equals("True") && !c.getSVar("RemAIDeck").equals("True")) + || goodLand.contains(c.getName()); // OR very important } }); } else if (colors == 5) { @@ -498,9 +497,8 @@ public class GenerateConstructedMultiColorDeck { // multicolored // cards !c.isLand() && // no land - !c.getSVar("RemRandomDeck").equals("True") && !c.getSVar("RemAIDeck").equals("True")) || - // OR very important - goodLand.contains(c.getName()); + !c.getSVar("RemRandomDeck").equals("True") && !c.getSVar("RemAIDeck").equals("True")) + || goodLand.contains(c.getName()); // OR very important } }); diff --git a/src/main/java/forge/deck/generate/GenerateThemeDeck.java b/src/main/java/forge/deck/generate/GenerateThemeDeck.java index e8b43c623fa..833cadad78c 100644 --- a/src/main/java/forge/deck/generate/GenerateThemeDeck.java +++ b/src/main/java/forge/deck/generate/GenerateThemeDeck.java @@ -114,17 +114,17 @@ public class GenerateThemeDeck { for (final String element : ss) { if (element.startsWith("Percentage")) { final String p = element.substring("Percentage".length() + 1); - g.Percentage = Integer.parseInt(p); + g.percentage = Integer.parseInt(p); } if (element.startsWith("MaxCnt")) { final String m = element.substring("MaxCnt".length() + 1); - g.MaxCnt = Integer.parseInt(m); + g.maxCnt = Integer.parseInt(m); } } s = this.readLine(); while (!s.equals("[/Group]")) { - g.Cardnames.add(s); + g.cardnames.add(s); cardCounts.put(s, 0); s = this.readLine(); @@ -159,21 +159,19 @@ public class GenerateThemeDeck { for (int i = 0; i < groups.size(); 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 cnSize = g.Cardnames.size(); + final int cnSize = g.cardnames.size(); tmpDeck += "Group" + i + ":" + grpCnt + "\n"; for (int j = 0; j < grpCnt; j++) { - s = g.Cardnames.get(r.nextInt(cnSize)); + s = g.cardnames.get(r.nextInt(cnSize)); int lc = 0; - while ((cardCounts.get(s) >= g.MaxCnt) || (lc > size)) // don't - // keep - // looping - // forever - { - s = g.Cardnames.get(r.nextInt(cnSize)); + while ((cardCounts.get(s) >= g.maxCnt) || (lc > size)) { + // looping + // forever + s = g.cardnames.get(r.nextInt(cnSize)); lc++; } if (lc > size) { @@ -200,9 +198,9 @@ public class GenerateThemeDeck { tmpDeck += "numBLands:" + numBLands + "\n"; - if (numBLands > 0) // attempt to optimize basic land counts according to - // color representation - { + if (numBLands > 0) { + // 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), new CCnt("Mountain", 0), new CCnt("Forest", 0) }; @@ -215,37 +213,37 @@ public class GenerateThemeDeck { final char c = mc.charAt(j); if (c == 'W') { - clrCnts[0].Count++; + clrCnts[0].count++; } else if (c == 'U') { - clrCnts[1].Count++; + clrCnts[1].count++; } else if (c == 'B') { - clrCnts[2].Count++; + clrCnts[2].count++; } else if (c == 'R') { - clrCnts[3].Count++; + clrCnts[3].count++; } else if (c == 'G') { - clrCnts[4].Count++; + clrCnts[4].count++; } } } int totalColor = 0; for (int i = 0; i < 5; i++) { - totalColor += clrCnts[i].Count; - tmpDeck += clrCnts[i].Color + ":" + clrCnts[i].Count + "\n"; + totalColor += clrCnts[i].count; + tmpDeck += clrCnts[i].color + ":" + clrCnts[i].count + "\n"; } tmpDeck += "totalColor:" + totalColor + "\n"; 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 - final float p = (float) clrCnts[i].Count / (float) totalColor; + final float p = (float) clrCnts[i].count / (float) totalColor; 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++) { - 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 { /** The Color. */ - public String Color; + private String color; /** The Count. */ - public int Count; + private int count; /** * Instantiates a new c cnt. @@ -333,8 +331,8 @@ public class GenerateThemeDeck { * the cnt */ public CCnt(final String clr, final int cnt) { - this.Color = clr; - this.Count = cnt; + this.color = clr; + this.count = cnt; } } @@ -346,12 +344,12 @@ public class GenerateThemeDeck { class Grp { /** The Cardnames. */ - public ArrayList Cardnames = new ArrayList(); + private ArrayList cardnames = new ArrayList(); /** The Max cnt. */ - public int MaxCnt; + private int maxCnt; /** The Percentage. */ - public int Percentage; + private int percentage; } } diff --git a/src/main/java/forge/error/BugzReporter.java b/src/main/java/forge/error/BugzReporter.java index 1f251b222e9..845c2b0c658 100644 --- a/src/main/java/forge/error/BugzReporter.java +++ b/src/main/java/forge/error/BugzReporter.java @@ -22,6 +22,7 @@ import javax.swing.JSeparator; import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.SwingConstants; +import javax.swing.WindowConstants; import javax.swing.border.EmptyBorder; import org.apache.log4j.Logger; @@ -53,24 +54,24 @@ public class BugzReporter extends JDialog { private ForgePreferences prefs = null; private final JPanel contentPanel = new JPanel(); - private JTextField txtUserName; - private JPasswordField txtPassword = new JPasswordField(); - private JComboBox cboCategory = new JComboBox(); - private JTextField txtSummary; - private JTextArea txtDescription = new JTextArea(); - private JTextArea txtErrorDump = new JTextArea(); - private JComboBox cboVersion = new JComboBox(); - private JComboBox cboSeverity = new JComboBox(); + private final JTextField txtUserName; + private final JPasswordField txtPassword = new JPasswordField(); + private final JComboBox cboCategory = new JComboBox(); + private final JTextField txtSummary; + private final JTextArea txtDescription = new JTextArea(); + private final JTextArea txtErrorDump = new JTextArea(); + private final JComboBox cboVersion = new JComboBox(); + private final JComboBox cboSeverity = new JComboBox(); /** The chk report anonymously. */ - final JCheckBox chkReportAnonymously = new JCheckBox("Report Anonymously"); - private JTextField txtSVN; - private JLabel lblAddInfo = new JLabel(); - private JTextArea txtSteps = new JTextArea(); + private final JCheckBox chkReportAnonymously = new JCheckBox("Report Anonymously"); + private final JTextField txtSVN; + private final JLabel lblAddInfo = new JLabel(); + private final JTextArea txtSteps = new JTextArea(); private static BugzReporter dialog = null; - private IMCAttribute[] Severities; + private IMCAttribute[] severities; /** * Launch the application. @@ -80,7 +81,7 @@ public class BugzReporter extends JDialog { */ public static void main(final String[] args) { // try { - dialog.setVisible(true); + BugzReporter.dialog.setVisible(true); // } catch (Exception e) { // System.out.println("Exception - main - " + e.getMessage()); // } @@ -93,24 +94,24 @@ public class BugzReporter extends JDialog { * the new dump text */ public final void setDumpText(final String dump) { - txtErrorDump.setText(dump); - lblAddInfo.setText("Crash Report"); - cboCategory.setSelectedItem("New Crash Report"); + this.txtErrorDump.setText(dump); + this.lblAddInfo.setText("Crash Report"); + this.cboCategory.setSelectedItem("New Crash Report"); } /** * Create the dialog. */ public BugzReporter() { - dialog = this; - setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); - setResizable(false); + BugzReporter.dialog = this; + this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); + this.setResizable(false); // 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"); - 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.setLevel(org.apache.log4j.Level.ERROR); // Init Logger @@ -123,234 +124,237 @@ public class BugzReporter extends JDialog { try { mCS = new MCSession(new URL("http://cardforge.org/bugz/api/soap/mantisconnect.php"), "ForgeGUI", "vi2ccTbfBUu^"); - } catch (MalformedURLException e1) { + } catch (final MalformedURLException e1) { System.out.println("MalFormedURLException"); - } catch (MCException e1) { + } catch (final MCException e1) { System.out.println("MCException - new MCSession"); } String[] cats = {}; try { cats = mCS.getCategories(1); - } catch (MCException e1) { + } catch (final MCException e1) { System.out.println("MCException - getCategories - " + e1.getMessage()); } try { - Severities = mCS.getEnum(Enumeration.SEVERITIES); - } catch (MCException e1) { + this.severities = mCS.getEnum(Enumeration.SEVERITIES); + } catch (final MCException e1) { System.out.println("MCException - getEnum - " + e1.getMessage()); } IProjectVersion[] vers = {}; try { vers = mCS.getVersions(1); - } catch (MCException e1) { + } catch (final MCException e1) { System.out.println("MCException - getVersions - " + e1.getMessage()); } - BuildInfo bi = Singletons.getModel().getBuildInfo(); + final BuildInfo bi = Singletons.getModel().getBuildInfo(); - setTitle("Report Issue"); - setBounds(100, 100, 442, 575); - getContentPane().setLayout(new BorderLayout()); - contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); - getContentPane().add(contentPanel, BorderLayout.CENTER); - contentPanel.setLayout(null); - JLabel lblMantisUsername = new JLabel("Username"); + this.setTitle("Report Issue"); + this.setBounds(100, 100, 442, 575); + this.getContentPane().setLayout(new BorderLayout()); + this.contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); + this.getContentPane().add(this.contentPanel, BorderLayout.CENTER); + this.contentPanel.setLayout(null); + final JLabel lblMantisUsername = new JLabel("Username"); lblMantisUsername.setHorizontalAlignment(SwingConstants.RIGHT); lblMantisUsername.setBounds(10, 16, 75, 14); - contentPanel.add(lblMantisUsername); - txtUserName = new JTextField("ForgeGUI"); - txtUserName.setBounds(90, 13, 185, 21); - txtUserName.setFont(new Font("Dialog", Font.PLAIN, 11)); - contentPanel.add(txtUserName); - txtUserName.setColumns(4); + this.contentPanel.add(lblMantisUsername); + this.txtUserName = new JTextField("ForgeGUI"); + this.txtUserName.setBounds(90, 13, 185, 21); + this.txtUserName.setFont(new Font("Dialog", Font.PLAIN, 11)); + this.contentPanel.add(this.txtUserName); + this.txtUserName.setColumns(4); try { - prefs = new ForgePreferences("forge.preferences"); - if (!prefs.BugzName.equals("")) { - txtUserName.setText(prefs.BugzName); - txtPassword.setText(prefs.BugzPwd); - chkReportAnonymously.setSelected(false); + this.prefs = new ForgePreferences("forge.preferences"); + if (!this.prefs.BugzName.equals("")) { + this.txtUserName.setText(this.prefs.BugzName); + this.txtPassword.setText(this.prefs.BugzPwd); + this.chkReportAnonymously.setSelected(false); } else { - chkReportAnonymously.setSelected(true); + this.chkReportAnonymously.setSelected(true); } - } catch (Exception e) { + } catch (final Exception e) { } - chkReportAnonymously.setBounds(284, 11, 139, 25); - chkReportAnonymously.setFont(new Font("Dialog", Font.PLAIN, 12)); - chkReportAnonymously.setHorizontalAlignment(SwingConstants.CENTER); - chkReportAnonymously.addActionListener(new java.awt.event.ActionListener() { + this.chkReportAnonymously.setBounds(284, 11, 139, 25); + this.chkReportAnonymously.setFont(new Font("Dialog", Font.PLAIN, 12)); + this.chkReportAnonymously.setHorizontalAlignment(SwingConstants.CENTER); + this.chkReportAnonymously.addActionListener(new java.awt.event.ActionListener() { + @Override public void actionPerformed(final ActionEvent e) { - if (chkReportAnonymously.isSelected()) { - txtUserName.setText("ForgeGUI"); - txtPassword.setText("vi2ccTbfBUu^"); + if (BugzReporter.this.chkReportAnonymously.isSelected()) { + BugzReporter.this.txtUserName.setText("ForgeGUI"); + BugzReporter.this.txtPassword.setText("vi2ccTbfBUu^"); } else { - if (!prefs.BugzName.equals("")) { - txtUserName.setText(prefs.BugzName); - txtPassword.setText(prefs.BugzPwd); + if (!BugzReporter.this.prefs.BugzName.equals("")) { + BugzReporter.this.txtUserName.setText(BugzReporter.this.prefs.BugzName); + BugzReporter.this.txtPassword.setText(BugzReporter.this.prefs.BugzPwd); } } } }); - contentPanel.add(chkReportAnonymously); - JLabel lblMantisPassword = new JLabel("Password"); + this.contentPanel.add(this.chkReportAnonymously); + final JLabel lblMantisPassword = new JLabel("Password"); lblMantisPassword.setHorizontalAlignment(SwingConstants.RIGHT); lblMantisPassword.setBounds(10, 45, 75, 14); - contentPanel.add(lblMantisPassword); - txtPassword.setBounds(90, 42, 185, 21); - txtPassword.setFont(new Font("Dialog", Font.PLAIN, 11)); - contentPanel.add(txtPassword); - JSeparator separator = new JSeparator(); + this.contentPanel.add(lblMantisPassword); + this.txtPassword.setBounds(90, 42, 185, 21); + this.txtPassword.setFont(new Font("Dialog", Font.PLAIN, 11)); + this.contentPanel.add(this.txtPassword); + final JSeparator separator = new JSeparator(); separator.setBounds(10, 69, 417, 2); - contentPanel.add(separator); - JLabel lblCategory = new JLabel("Category"); + this.contentPanel.add(separator); + final JLabel lblCategory = new JLabel("Category"); lblCategory.setBounds(10, 81, 75, 14); lblCategory.setFont(new Font("Tahoma", Font.BOLD, 11)); lblCategory.setHorizontalAlignment(SwingConstants.RIGHT); - contentPanel.add(lblCategory); - cboCategory.setBounds(90, 77, 223, 22); - cboCategory.setFont(new Font("Dialog", Font.BOLD, 10)); + this.contentPanel.add(lblCategory); + this.cboCategory.setBounds(90, 77, 223, 22); + this.cboCategory.setFont(new Font("Dialog", Font.BOLD, 10)); if (cats.length > 0) { - for (int i = 0; i < cats.length; i++) { - cboCategory.addItem(cats[i]); + for (final String cat : cats) { + this.cboCategory.addItem(cat); } } - cboCategory.setSelectedItem("General Bug Report"); - contentPanel.add(cboCategory); - JLabel lblSummary = new JLabel("Summary"); + this.cboCategory.setSelectedItem("General Bug Report"); + this.contentPanel.add(this.cboCategory); + final JLabel lblSummary = new JLabel("Summary"); lblSummary.setBounds(10, 108, 75, 14); lblSummary.setFont(new Font("Tahoma", Font.BOLD, 11)); lblSummary.setHorizontalAlignment(SwingConstants.RIGHT); - contentPanel.add(lblSummary); - txtSummary = new JTextField(); - txtSummary.setBounds(90, 105, 337, 21); - txtSummary.setFont(new Font("Dialog", Font.PLAIN, 11)); - contentPanel.add(txtSummary); - txtSummary.setColumns(10); - JLabel lblDescription = new JLabel("Description"); + this.contentPanel.add(lblSummary); + this.txtSummary = new JTextField(); + this.txtSummary.setBounds(90, 105, 337, 21); + this.txtSummary.setFont(new Font("Dialog", Font.PLAIN, 11)); + this.contentPanel.add(this.txtSummary); + this.txtSummary.setColumns(10); + final JLabel lblDescription = new JLabel("Description"); lblDescription.setBounds(10, 182, 75, 21); lblDescription.setFont(new Font("Tahoma", Font.BOLD, 11)); lblDescription.setHorizontalAlignment(SwingConstants.RIGHT); - contentPanel.add(lblDescription); - JScrollPane scrollPane = new JScrollPane(); + this.contentPanel.add(lblDescription); + final JScrollPane scrollPane = new JScrollPane(); scrollPane.setBounds(90, 132, 337, 120); - contentPanel.add(scrollPane); - txtDescription.setFont(new Font("Dialog", Font.PLAIN, 10)); - scrollPane.setViewportView(txtDescription); - txtDescription.setBorder(null); - txtDescription.setWrapStyleWord(true); - txtDescription.setLineWrap(true); - txtDescription.setRows(8); - lblAddInfo.setText("

Additional
Information

"); - lblAddInfo.setBounds(10, 294, 75, 40); - lblAddInfo.setFont(new Font("Dialog", Font.PLAIN, 12)); - lblAddInfo.setHorizontalAlignment(SwingConstants.RIGHT); - contentPanel.add(lblAddInfo); - JScrollPane scrollPane3 = new JScrollPane(); + this.contentPanel.add(scrollPane); + this.txtDescription.setFont(new Font("Dialog", Font.PLAIN, 10)); + scrollPane.setViewportView(this.txtDescription); + this.txtDescription.setBorder(null); + this.txtDescription.setWrapStyleWord(true); + this.txtDescription.setLineWrap(true); + this.txtDescription.setRows(8); + this.lblAddInfo.setText("

Additional
Information

"); + this.lblAddInfo.setBounds(10, 294, 75, 40); + this.lblAddInfo.setFont(new Font("Dialog", Font.PLAIN, 12)); + this.lblAddInfo.setHorizontalAlignment(SwingConstants.RIGHT); + this.contentPanel.add(this.lblAddInfo); + final JScrollPane scrollPane3 = new JScrollPane(); scrollPane3.setBounds(90, 254, 337, 120); - contentPanel.add(scrollPane3); - txtErrorDump.setFont(new Font("Monospaced", Font.PLAIN, 10)); - scrollPane.setViewportView(txtErrorDump); - txtErrorDump.setAutoscrolls(false); - txtErrorDump.setMaximumSize(new Dimension(2147483647, 300)); - txtErrorDump.setBorder(null); - txtErrorDump.setLineWrap(true); - txtErrorDump.setWrapStyleWord(true); - txtErrorDump.setRows(8); - JLabel lblVersion = new JLabel("Version"); + this.contentPanel.add(scrollPane3); + this.txtErrorDump.setFont(new Font("Monospaced", Font.PLAIN, 10)); + scrollPane.setViewportView(this.txtErrorDump); + this.txtErrorDump.setAutoscrolls(false); + this.txtErrorDump.setMaximumSize(new Dimension(2147483647, 300)); + this.txtErrorDump.setBorder(null); + this.txtErrorDump.setLineWrap(true); + this.txtErrorDump.setWrapStyleWord(true); + this.txtErrorDump.setRows(8); + final JLabel lblVersion = new JLabel("Version"); lblVersion.setHorizontalAlignment(SwingConstants.RIGHT); lblVersion.setBounds(20, 468, 65, 16); lblVersion.setFont(new Font("Dialog", Font.PLAIN, 12)); - contentPanel.add(lblVersion); - cboVersion.setBounds(90, 465, 160, 22); - cboVersion.setFont(new Font("Dialog", Font.BOLD, 10)); - cboVersion.addItem(""); + this.contentPanel.add(lblVersion); + this.cboVersion.setBounds(90, 465, 160, 22); + this.cboVersion.setFont(new Font("Dialog", Font.BOLD, 10)); + this.cboVersion.addItem(""); if (vers.length > 0) { - for (int i = 0; i < vers.length; i++) { - cboVersion.addItem(vers[i].getName()); + for (final IProjectVersion ver : vers) { + this.cboVersion.addItem(ver.getName()); // System.out.println(vers[i].getName()); } } - cboVersion.setSelectedIndex(0); - String curVer = bi.getVersion(); - String[] ss = curVer.split("-"); - String rx = "^" + ss[0].replaceAll("\\.", "\\\\.") + ".*"; + this.cboVersion.setSelectedIndex(0); + final String curVer = bi.getVersion(); + final String[] ss = curVer.split("-"); + final String rx = "^" + ss[0].replaceAll("\\.", "\\\\.") + ".*"; System.out.println(ss[0] + " -> " + rx); if (curVer.equals("SVN")) { - cboVersion.setSelectedItem("SVN"); + this.cboVersion.setSelectedItem("SVN"); } else { - for (int i = 0; i < vers.length; i++) { - System.out.println(vers[i].getName()); - if (vers[i].getName().matches(rx)) { + for (final IProjectVersion ver : vers) { + System.out.println(ver.getName()); + if (ver.getName().matches(rx)) { System.out.println("match"); - cboVersion.setSelectedItem(vers[i].getName()); + this.cboVersion.setSelectedItem(ver.getName()); } } } - contentPanel.add(cboVersion); - JLabel lblRev = new JLabel("SVN rev."); + this.contentPanel.add(this.cboVersion); + final JLabel lblRev = new JLabel("SVN rev."); lblRev.setBounds(247, 468, 66, 16); lblRev.setHorizontalAlignment(SwingConstants.RIGHT); lblRev.setFont(new Font("Dialog", Font.PLAIN, 12)); - contentPanel.add(lblRev); - txtSVN = new JTextField(); - String curRev = bi.getBuildID(); + this.contentPanel.add(lblRev); + this.txtSVN = new JTextField(); + final String curRev = bi.getBuildID(); if (curRev != null) { if (!curRev.equals("null")) { - txtSVN.setText(curRev); + this.txtSVN.setText(curRev); } } - txtSVN.setBounds(318, 465, 109, 21); - txtSVN.setFont(new Font("Dialog", Font.PLAIN, 11)); - txtSVN.setColumns(10); - contentPanel.add(txtSVN); - JLabel lblSeverity = new JLabel("Severity"); + this.txtSVN.setBounds(318, 465, 109, 21); + this.txtSVN.setFont(new Font("Dialog", Font.PLAIN, 11)); + this.txtSVN.setColumns(10); + this.contentPanel.add(this.txtSVN); + final JLabel lblSeverity = new JLabel("Severity"); lblSeverity.setBounds(10, 496, 75, 16); lblSeverity.setFont(new Font("Dialog", Font.PLAIN, 12)); lblSeverity.setHorizontalAlignment(SwingConstants.RIGHT); - contentPanel.add(lblSeverity); - cboSeverity.setBounds(90, 493, 160, 22); - cboSeverity.setFont(new Font("Dialog", Font.BOLD, 10)); - cboSeverity.addItem(""); - if (Severities.length > 0) { - for (int i = 0; i < Severities.length; i++) { - cboSeverity.addItem(Severities[i].getName()); + this.contentPanel.add(lblSeverity); + this.cboSeverity.setBounds(90, 493, 160, 22); + this.cboSeverity.setFont(new Font("Dialog", Font.BOLD, 10)); + this.cboSeverity.addItem(""); + if (this.severities.length > 0) { + for (final IMCAttribute severitie : this.severities) { + this.cboSeverity.addItem(severitie.getName()); } } - contentPanel.add(cboSeverity); - JScrollPane scrollPane2 = new JScrollPane(); + this.contentPanel.add(this.cboSeverity); + final JScrollPane scrollPane2 = new JScrollPane(); scrollPane2.setBounds(90, 380, 337, 80); - contentPanel.add(scrollPane2); - txtSteps.setWrapStyleWord(true); - txtSteps.setRows(5); - txtSteps.setMaximumSize(new Dimension(2147483647, 300)); - txtSteps.setLineWrap(true); - txtSteps.setFont(new Font("Monospaced", Font.PLAIN, 10)); - txtSteps.setAutoscrolls(false); - scrollPane.setViewportView(txtSteps); - JLabel lblSteps = new JLabel(); + this.contentPanel.add(scrollPane2); + this.txtSteps.setWrapStyleWord(true); + this.txtSteps.setRows(5); + this.txtSteps.setMaximumSize(new Dimension(2147483647, 300)); + this.txtSteps.setLineWrap(true); + this.txtSteps.setFont(new Font("Monospaced", Font.PLAIN, 10)); + this.txtSteps.setAutoscrolls(false); + scrollPane.setViewportView(this.txtSteps); + final JLabel lblSteps = new JLabel(); lblSteps.setText("

Steps to
Reproduce

"); lblSteps.setHorizontalAlignment(SwingConstants.RIGHT); lblSteps.setFont(new Font("Dialog", Font.PLAIN, 12)); lblSteps.setBounds(10, 400, 75, 40); - contentPanel.add(lblSteps); - JPanel buttonPane = new JPanel(); + this.contentPanel.add(lblSteps); + final JPanel buttonPane = new JPanel(); buttonPane.setOpaque(false); buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); - getContentPane().add(buttonPane, BorderLayout.SOUTH); - JButton cmdReport = new JButton("Report"); + this.getContentPane().add(buttonPane, BorderLayout.SOUTH); + final JButton cmdReport = new JButton("Report"); cmdReport.addActionListener(new ActionListener() { + @Override public void actionPerformed(final ActionEvent arg0) { - doReport(); + BugzReporter.this.doReport(); } }); buttonPane.add(cmdReport); - JButton cmdCancel = new JButton("Cancel"); + final JButton cmdCancel = new JButton("Cancel"); cmdCancel.addActionListener(new ActionListener() { + @Override public void actionPerformed(final ActionEvent arg0) { - dialog.dispose(); + BugzReporter.dialog.dispose(); } }); buttonPane.add(cmdCancel); @@ -359,26 +363,26 @@ public class BugzReporter extends JDialog { private void doReport() { Report: { - if (txtSummary.getText().length() < 4) { + if (this.txtSummary.getText().length() < 4) { JOptionPane.showMessageDialog(null, "Summary field must be provided", "Bug Report", JOptionPane.ERROR_MESSAGE); break Report; } - if (txtDescription.getText().length() < 10) { + if (this.txtDescription.getText().length() < 10) { JOptionPane.showMessageDialog(null, "Description field must be provided", "Bug Report", JOptionPane.ERROR_MESSAGE); break Report; } MCSession rep = null; - if (!chkReportAnonymously.isSelected()) { + if (!this.chkReportAnonymously.isSelected()) { try { rep = new MCSession(new URL("http://cardforge.org/bugz/api/soap/mantisconnect.php"), - txtUserName.getText(), String.valueOf(txtPassword.getPassword())); - } catch (MalformedURLException e) { + this.txtUserName.getText(), String.valueOf(this.txtPassword.getPassword())); + } catch (final MalformedURLException e) { System.out.println("MalFormedURLException"); - } catch (MCException e) { + } catch (final MCException e) { System.out.println("MCException - new MCSession - " + e.getMessage()); JOptionPane.showMessageDialog(null, "MCException - new MCSession - " + e.getMessage(), "Bug Report", JOptionPane.INFORMATION_MESSAGE); @@ -388,9 +392,9 @@ public class BugzReporter extends JDialog { try { rep = new MCSession(new URL("http://cardforge.org/bugz/api/soap/mantisconnect.php"), "ForgeGUI", "vi2ccTbfBUu^"); - } catch (MalformedURLException e) { + } catch (final MalformedURLException e) { System.out.println("MalformedURLException"); - } catch (MCException e) { + } catch (final MCException e) { System.out.println("MCException - new MCSession - " + e.getMessage()); JOptionPane.showMessageDialog(null, "MCException - new MCSession - " + e.getMessage(), "Bug Report", JOptionPane.INFORMATION_MESSAGE); @@ -401,52 +405,52 @@ public class BugzReporter extends JDialog { IIssue iBug = null; try { iBug = rep.newIssue(1); - } catch (MCException e) { + } catch (final MCException e) { System.out.println("MCException - newIssue - " + e.getMessage()); JOptionPane.showMessageDialog(null, "MCException - newIssue - " + e.getMessage(), "Bug Report", JOptionPane.INFORMATION_MESSAGE); break Report; } - iBug.setCategory(cboCategory.getSelectedItem().toString()); - iBug.setSummary(txtSummary.getText()); - iBug.setDescription(txtDescription.getText()); - iBug.setAdditionalInformation(txtErrorDump.getText()); - iBug.setVersion(cboVersion.getSelectedItem().toString()); + iBug.setCategory(this.cboCategory.getSelectedItem().toString()); + iBug.setSummary(this.txtSummary.getText()); + iBug.setDescription(this.txtDescription.getText()); + iBug.setAdditionalInformation(this.txtErrorDump.getText()); + iBug.setVersion(this.cboVersion.getSelectedItem().toString()); - for (int i = 0; i < Severities.length; i++) { - if (cboSeverity.getSelectedItem().toString().equals(Severities[i].getName())) { - iBug.setSeverity(Severities[i]); + for (final IMCAttribute severitie : this.severities) { + if (this.cboSeverity.getSelectedItem().toString().equals(severitie.getName())) { + iBug.setSeverity(severitie); } } - iBug.setStepsToReproduce(txtSteps.getText()); + iBug.setStepsToReproduce(this.txtSteps.getText()); - ICustomFieldValue[] icfv = {new CustomFieldValue(new MCAttribute(1, "Detected at SVN Rev"), - txtSVN.getText())}; + final ICustomFieldValue[] icfv = { new CustomFieldValue(new MCAttribute(1, "Detected at SVN Rev"), + this.txtSVN.getText()) }; iBug.setCustomFields(icfv); - DefaultSubmitter ds = new DefaultSubmitter(false); + final DefaultSubmitter ds = new DefaultSubmitter(false); try { ds.submitIssue(rep, iBug); - } catch (MCException e1) { + } catch (final MCException e1) { System.out.println("MCException - submit Issue - " + e1.getMessage()); JOptionPane.showMessageDialog(null, "MCException - submit Issue - " + e1.getMessage(), "Bug Report", JOptionPane.INFORMATION_MESSAGE); break Report; } - prefs.BugzName = txtUserName.getText(); - prefs.BugzPwd = String.valueOf(txtPassword.getPassword()); + this.prefs.BugzName = this.txtUserName.getText(); + this.prefs.BugzPwd = String.valueOf(this.txtPassword.getPassword()); try { - prefs.save(); - } catch (Exception e) { + this.prefs.save(); + } catch (final Exception e) { System.out.println("Exception - save preferences - " + e.getMessage()); } JOptionPane.showMessageDialog(null, "This Issue Has Been Reported, Thank You.", "Bug Report", JOptionPane.INFORMATION_MESSAGE); - dialog.dispose(); + BugzReporter.dialog.dispose(); } // Report: } diff --git a/src/main/java/forge/error/ErrorViewer.java b/src/main/java/forge/error/ErrorViewer.java index c18a5344c32..1597b6629d0 100644 --- a/src/main/java/forge/error/ErrorViewer.java +++ b/src/main/java/forge/error/ErrorViewer.java @@ -1,15 +1,9 @@ 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.event.ActionEvent; +import java.awt.event.InputEvent; +import java.awt.event.KeyEvent; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; @@ -30,6 +24,7 @@ import javax.swing.JTextArea; import javax.swing.KeyStroke; import forge.Singletons; +import forge.properties.ForgeProps; import forge.properties.NewConstants; /** @@ -64,7 +59,7 @@ public class ErrorViewer implements NewConstants, NewConstants.LANG.ErrorViewer * a {@link java.lang.Throwable} object. */ 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) { 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(); - PrintWriter pw = new PrintWriter(sw); - printError(pw, ex, message); + final PrintWriter pw = new PrintWriter(sw); + 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. */ 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. */ 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. */ 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) { final StringWriter sw = new StringWriter(); - PrintWriter pw = new PrintWriter(sw); - printError(pw, message); + final PrintWriter pw = new PrintWriter(sw); + 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. */ 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.setEditable(false); 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 // the dialog - Object[] options = {new JButton(new BugzAction(area)), new JButton(new SaveAction(area)), - getLocalized(BUTTON_CLOSE), new JButton(new ExitAction())}; + final Object[] options = { new JButton(new BugzAction(area)), new JButton(new SaveAction(area)), + ForgeProps.getLocalized(ErrorViewer.BUTTON_CLOSE), new JButton(new ExitAction()) }; - JOptionPane pane = new JOptionPane(new JScrollPane(area), ERROR_MESSAGE, DEFAULT_OPTION, null, options, - options[1]); - dlg = pane.createDialog(null, getLocalized(TITLE)); - dlg.setResizable(true); - dlg.setVisible(true); - dlg.dispose(); + final JOptionPane pane = new JOptionPane(new JScrollPane(area), JOptionPane.ERROR_MESSAGE, + JOptionPane.DEFAULT_OPTION, null, options, options[1]); + ErrorViewer.dlg = pane.createDialog(null, ForgeProps.getLocalized(ErrorViewer.TITLE)); + ErrorViewer.dlg.setResizable(true); + ErrorViewer.dlg.setVisible(true); + ErrorViewer.dlg.dispose(); } /** @@ -197,10 +192,12 @@ public class ErrorViewer implements NewConstants, NewConstants.LANG.ErrorViewer } 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(), - System.getProperty(NAME_OS), System.getProperty(VERSION_OS), System.getProperty(ARCHITECTURE_OS), - System.getProperty(VERSION_JAVA), System.getProperty(VENDOR_JAVA)); + System.getProperty(ErrorViewer.NAME_OS), System.getProperty(ErrorViewer.VERSION_OS), + System.getProperty(ErrorViewer.ARCHITECTURE_OS), System.getProperty(ErrorViewer.VERSION_JAVA), + System.getProperty(ErrorViewer.VENDOR_JAVA)); 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) { System.err.println(message); - pw.printf(getLocalized(MESSAGE), getProperty(HOW_TO_REPORT_BUGS_URL), message, Singletons.getModel() - .getBuildInfo().toPrettyString(), System.getProperty(NAME_OS), System.getProperty(VERSION_OS), - System.getProperty(ARCHITECTURE_OS), System.getProperty(VERSION_JAVA), System.getProperty(VENDOR_JAVA)); - Map traces = Thread.getAllStackTraces(); - for (Entry e : traces.entrySet()) { + pw.printf(ForgeProps.getLocalized(ErrorViewer.MESSAGE), + ForgeProps.getProperty(NewConstants.HOW_TO_REPORT_BUGS_URL), message, Singletons.getModel() + .getBuildInfo().toPrettyString(), System.getProperty(ErrorViewer.NAME_OS), + System.getProperty(ErrorViewer.VERSION_OS), System.getProperty(ErrorViewer.ARCHITECTURE_OS), + System.getProperty(ErrorViewer.VERSION_JAVA), System.getProperty(ErrorViewer.VENDOR_JAVA)); + final Map traces = Thread.getAllStackTraces(); + for (final Entry e : traces.entrySet()) { pw.println(); 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); } } @@ -235,37 +234,38 @@ public class ErrorViewer implements NewConstants, NewConstants.LANG.ErrorViewer private static JFileChooser c; - private JTextArea area; + private final JTextArea area; public SaveAction(final JTextArea areaParam) { - super(getLocalized(BUTTON_SAVE)); - putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(VK_S, CTRL_DOWN_MASK)); + super(ForgeProps.getLocalized(ErrorViewer.BUTTON_SAVE)); + this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK)); this.area = areaParam; } + @Override public void actionPerformed(final ActionEvent e) { - if (c == null) { - c = new JFileChooser(); + if (SaveAction.c == null) { + SaveAction.c = new JFileChooser(); } File f; 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); if (!f.exists()) { break; } } - c.setSelectedFile(f); - c.showSaveDialog(null); - f = c.getSelectedFile(); + SaveAction.c.setSelectedFile(f); + SaveAction.c.showSaveDialog(null); + f = SaveAction.c.getSelectedFile(); try { - BufferedWriter bw = new BufferedWriter(new FileWriter(f)); - bw.write(area.getText()); + final BufferedWriter bw = new BufferedWriter(new FileWriter(f)); + bw.write(this.area.getText()); bw.close(); - } catch (IOException ex) { - showError(ex, getLocalized(ERRORS.SAVE_MESSAGE)); + } catch (final IOException ex) { + 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 JTextArea area; + private final JTextArea area; public BugzAction(final JTextArea neoArea) { - putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(VK_B, CTRL_DOWN_MASK)); - putValue(NAME, "Report Bug"); + this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_B, InputEvent.CTRL_DOWN_MASK)); + this.putValue(Action.NAME, "Report Bug"); this.area = neoArea; } + @Override public void actionPerformed(final ActionEvent e) { - BugzReporter br = new BugzReporter(); - br.setDumpText(area.getText()); + final BugzReporter br = new BugzReporter(); + br.setDumpText(this.area.getText()); 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; public ExitAction() { - super(getLocalized(BUTTON_EXIT)); + super(ForgeProps.getLocalized(ErrorViewer.BUTTON_EXIT)); } + @Override public void actionPerformed(final ActionEvent e) { System.exit(0); } @@ -308,11 +310,12 @@ public class ErrorViewer implements NewConstants, NewConstants.LANG.ErrorViewer private static final long serialVersionUID = 5638147106706803363L; public ShowAllThreadsAction() { - super(getLocalized(SHOW_ERROR)); + super(ForgeProps.getLocalized(ErrorViewer.SHOW_ERROR)); } + @Override public void actionPerformed(final ActionEvent e) { - showErrorAllThreads(getLocalized(ERRORS.SHOW_MESSAGE)); + ErrorViewer.showErrorAllThreads(ForgeProps.getLocalized(ERRORS.SHOW_MESSAGE)); } } } diff --git a/src/main/java/forge/error/ExceptionHandler.java b/src/main/java/forge/error/ExceptionHandler.java index 4301ce1d547..3851c3996ee 100644 --- a/src/main/java/forge/error/ExceptionHandler.java +++ b/src/main/java/forge/error/ExceptionHandler.java @@ -34,6 +34,7 @@ public class ExceptionHandler implements UncaughtExceptionHandler { } /** {@inheritDoc} */ + @Override public final void uncaughtException(final Thread t, final Throwable ex) { ErrorViewer.showError(ex); } diff --git a/src/main/java/forge/error/package-info.java b/src/main/java/forge/error/package-info.java index 8b8e912da0a..d6285c5bbb5 100644 --- a/src/main/java/forge/error/package-info.java +++ b/src/main/java/forge/error/package-info.java @@ -1,2 +1,3 @@ /** Forge Card Game. */ package forge.error; +