bugged
stringlengths
6
599k
fixed
stringlengths
10
599k
__index_level_0__
int64
0
1.13M
public Contact(Partner partner, Credential credential, int internalNumber, int priority) { this.partner = partner; this.credential = credential; this.internalNumber = internalNumber; this.priority = priority; }
public Contact(Partner partner, Credential credential, int internalNumber, int priority) { this.partner = partner; this.credential = credential; this.internalNumber = internalNumber; this.priority = priority; }
1,115,243
public Controller(View aView) { myView = aView; aView.setController(this); }
public Controller(View aView, Recipe aRecipe) { myView = aView; aView.setController(this); }
1,115,244
public void addStep(){ MashStep step = new MashStep(); steps.add(step); calcMashSchedule(); }
public void addStep(){ MashStep step = new MashStep(); steps.add(step); calcMashSchedule(); }
1,115,246
public double getStepStartTemp(int i) { if (tempUnits.equals("C")) return fToC(((MashStep)steps.get(i)).getStartTemp()); else return ((MashStep)steps.get(i)).getStartTemp(); }
public double getStepStartTemp(int i) { if (tempUnits.equals("C")) return BrewCalcs.fToC(((MashStep)steps.get(i)).getStartTemp()); else return ((MashStep)steps.get(i)).getStartTemp(); }
1,115,247
public double getStepEndTemp(int i) { if (tempUnits.equals("C")) return fToC(((MashStep)steps.get(i)).getEndTemp()); else return ((MashStep)steps.get(i)).getEndTemp(); }
public double getStepEndTemp(int i) { if (tempUnits.equals("C")) return BrewCalcs.fToC(((MashStep)steps.get(i)).getEndTemp()); else return ((MashStep)steps.get(i)).getEndTemp(); }
1,115,248
public void setStepStartTemp(int i, double t){ if (tempUnits.equals("C")){ t = cToF(t); } ((MashStep)steps.get(i)).setStartTemp(t); ((MashStep)steps.get(i)).setEndTemp(t); ((MashStep)steps.get(i)).setType(calcStepType(t)); calcMashSchedule(); }
public void setStepStartTemp(int i, double t){ if (tempUnits.equals("C")){ t = BrewCalcs.cToF(t); } ((MashStep)steps.get(i)).setStartTemp(t); ((MashStep)steps.get(i)).setEndTemp(t); ((MashStep)steps.get(i)).setType(calcStepType(t)); calcMashSchedule(); }
1,115,249
public void setStepEndTemp(int i, double t){ if (tempUnits.equals("C")) ((MashStep)steps.get(i)).setEndTemp(cToF(t)); else ((MashStep)steps.get(i)).setEndTemp(t); calcMashSchedule(); }
public void setStepEndTemp(int i, double t){ if (tempUnits.equals("C")) ((MashStep)steps.get(i)).setEndTemp(BrewCalcs.cToF(t)); else ((MashStep)steps.get(i)).setEndTemp(t); calcMashSchedule(); }
1,115,250
public void calcMashSchedule() { // Method to run through the mash table and calculate values if (!myRecipe.allowRecalcs) return; double strikeTemp = 0; double targetTemp = 0; double waterAddedQTS = 0; double waterEquiv = 0; double mr = mashRatio; double currentTemp = grainTempF; double displTemp = 0; double tunLoss; // figure out a better way to do this, eg: themal mass double decoct = 0; int totalMashTime = 0; int totalSpargeTime = 0; double mashWaterQTS = 0; double mashVolQTS = 0; int numSparge = 0; double totalWeightLbs = 0; double totalCerealLbs = 0; maltWeightLbs = myRecipe.getTotalMashLbs(); // convert mash ratio to qts/lb if in l/kg if (mashRatioU.equalsIgnoreCase("l/kg")) { mr *= 0.479325; } // convert CurrentTemp to F if (tempUnits == "C") { currentTemp = cToF(currentTemp); tunLoss = tunLossF * 1.8; } else tunLoss = tunLossF; // perform calcs on first record if (steps.isEmpty()) return; // sort the list Collections.sort(steps, new stepComparator()); // add up the cereal mash lbs for (int i=0; i<steps.size(); i++){ MashStep stp = ((MashStep) steps.get(i)); if (stp.method.equals("cereal mash")){ totalCerealLbs += stp.weightLbs; } } totalWeightLbs = maltWeightLbs - totalCerealLbs; // the first step is always an infusion MashStep stp = ((MashStep) steps.get(0)); targetTemp = stp.startTemp; strikeTemp = calcStrikeTemp(targetTemp, currentTemp, mr, tunLoss); waterAddedQTS = mr * totalWeightLbs; waterEquiv = totalWeightLbs * (0.192 + mr); mashVolQTS = calcMashVol(totalWeightLbs, mr); totalMashTime += stp.minutes; mashWaterQTS += waterAddedQTS; stp.vol.setUnits("qt"); stp.vol.setAmount(waterAddedQTS); stp.temp = strikeTemp; stp.method = "infusion"; stp.weightLbs = totalWeightLbs; // subtract the water added from the Water Equiv so that they are correct when added in the next part of the loop waterEquiv -= waterAddedQTS; // Updated the water added if (tempUnits == "C") strikeTemp = fToC(strikeTemp); stp.directions = "Mash in with " + SBStringUtils.format(stp.vol.getValueAs(volUnits),1 ) + " " + volUnits + " of water at " + SBStringUtils.format(strikeTemp, 1) + " " + tempUnits; // set TargetTemp to the end temp targetTemp = stp.endTemp; for (int i = 1; i < steps.size(); i++) { stp = ((MashStep) steps.get(i)); currentTemp = targetTemp; // switch targetTemp = stp.startTemp; // if this is a former sparge step that's been changed, change // the method to infusion if (!stp.type.equals("sparge") && ( stp.method.equals("fly") || stp.method.equals("batch"))) stp.method = "infusion"; // do calcs if (stp.method.equals("infusion")) { // calculate an infusion step decoct = 0; waterEquiv += waterAddedQTS; // add previous addition to get WE strikeTemp = boilTempF; // boiling water // Updated the water added waterAddedQTS = calcWaterAddition(targetTemp, currentTemp, waterEquiv, boilTempF); stp.vol.setUnits("qt"); stp.vol.setAmount(waterAddedQTS); stp.temp = strikeTemp; stp.weightLbs = totalWeightLbs; if (tempUnits == "C") strikeTemp = 100; stp.directions = "Add " + SBStringUtils.format(stp.vol.getValueAs(volUnits), 1) + " " + volUnits + " of water at " + SBStringUtils.format(strikeTemp, 1) + " " + tempUnits; mashWaterQTS += waterAddedQTS; mashVolQTS += waterAddedQTS; } else if (stp.method.indexOf("decoction") > -1) { // calculate a decoction step waterEquiv += waterAddedQTS; // add previous addition to get WE waterAddedQTS = 0; strikeTemp = boilTempF; // boiling water double ratio=0.75; if (stp.method.indexOf("thick") > -1) ratio = thickDecoctRatio; else if (stp.method.indexOf("thin") > -1) ratio = thinDecoctRatio; // Calculate volume (qts) of mash to remove decoct = calcDecoction2(targetTemp, currentTemp, mashWaterQTS, ratio, totalWeightLbs); stp.vol.setUnits("qt"); stp.vol.setAmount(decoct); stp.temp = boilTempF; stp.weightLbs = totalWeightLbs; // Updated the decoction, convert to right units & make directions stp.directions = "Remove " + SBStringUtils.format(stp.vol.getValueAs(volUnits), 1) + " " + volUnits + " of mash, boil, and return to mash."; } else if (stp.method.equals("direct")) { // calculate a direct heat step decoct = 0; waterEquiv += waterAddedQTS; // add previous addition to get WE waterAddedQTS = 0; displTemp = stp.startTemp; if (tempUnits.equals("C")) displTemp = fToC(displTemp); stp.directions = "Add direct heat until mash reaches " + displTemp + " " + tempUnits + "."; stp.vol.setAmount(0); stp.temp = 0; stp.weightLbs = totalWeightLbs; } else if (stp.method.indexOf("cereal mash") > -1) { // calculate a cereal mash step waterEquiv += waterAddedQTS; // add previous addition to get WE waterAddedQTS = 0; targetTemp = stp.startTemp; double extraWaterQTS = 0; double cerealTemp = boilTempF; double cerealTargTemp = cerealMashTemp; String addStr = ""; /* * 1. check the temp of the mash when you add the boiling cereal mash @ default ratio back * 2. if it's > than the step temp, adjust the step temp * 3. if it's < than the step temp, add extra water to increase the "heat equivalencey" of the cereal mash */ double cerealWaterEquiv = stp.weightLbs * (0.192 + mr); waterAddedQTS = mr * stp.weightLbs; strikeTemp = calcStrikeTemp(cerealMashTemp, grainTempF, mr, 0); double newTemp = ((waterEquiv * currentTemp) + (cerealWaterEquiv * cerealTemp)) / (waterEquiv + cerealWaterEquiv); if (newTemp > targetTemp){ stp.startTemp = newTemp; } if (newTemp < targetTemp){ double addQts = ((waterEquiv * (targetTemp - currentTemp)) / (cerealTemp - targetTemp)) - 0.192; extraWaterQTS = addQts - waterAddedQTS; addStr = " Add " + SBStringUtils.format(Quantity.convertUnit("qt", volUnits, extraWaterQTS), 1) + " " + volUnits + " water to the cereal mash."; } // Calculate final temp of cereal mash // cerealTemp = (targetTemp * (waterEquiv + cerealWaterEquiv) - (waterEquiv * currentTemp)) / cerealWaterEquiv; totalMashTime += stp.minutes; mashWaterQTS += waterAddedQTS + extraWaterQTS; stp.vol.setUnits("qt"); stp.vol.setAmount(waterAddedQTS); stp.temp = strikeTemp; // make directions String weightStr = SBStringUtils.format(Quantity.convertUnit("lb", myRecipe.getMaltUnits(), stp.weightLbs), 1) + " " + myRecipe.getMaltUnits(); String volStr = SBStringUtils.format(Quantity.convertUnit("qt", volUnits, waterAddedQTS), 1) + " " + volUnits; if (tempUnits == "C"){ strikeTemp = fToC(strikeTemp); cerealTemp = fToC(cerealTemp); targetTemp = fToC(targetTemp); cerealTargTemp = fToC(cerealTargTemp); } String tempStr = SBStringUtils.format(strikeTemp, 1) + tempUnits; String tempStr2 = SBStringUtils.format(cerealTemp, 1) + tempUnits; String tempStr3 = SBStringUtils.format(targetTemp, 1) + tempUnits; String tempStr4 = SBStringUtils.format(cerealTargTemp, 1) + tempUnits; stp.directions = "Cereal mash: mash " + weightStr + " grain with " + volStr + " water at " + tempStr + " to hit " + tempStr4 + " and rest."; stp.directions += addStr; stp.directions += " Raise to " + tempStr2 + " and add to the main mash to reach " + tempStr3; // add cereal mash to total weight totalWeightLbs += stp.weightLbs; } if (stp.type.equals("sparge")) numSparge++; else { totalMashTime += stp.minutes; } // set target temp to end temp for next step targetTemp = stp.endTemp; } // for steps.size() waterEquiv += waterAddedQTS; // add previous addition to get WE totalTime = totalMashTime; volQts = mashVolQTS; // water use stats: absorbedQTS = totalWeightLbs * 0.55; // figure from HBD // spargeTotalQTS = (myRecipe.getPreBoilVol("qt")) - (mashWaterQTS - absorbedQTS); totalWaterQTS = mashWaterQTS; spargeQTS = myRecipe.getPreBoilVol("qt") - (mashWaterQTS - absorbedQTS); // Now let's figure out the sparging: if (numSparge == 0) return; double col = myRecipe.getPreBoilVol("qt") / numSparge; double charge[] = new double[numSparge]; double collect[] = new double[numSparge]; double totalCollectQts = myRecipe.getPreBoilVol("qt"); if (col < mashWaterQTS - absorbedQTS) { charge[0] = 0; collect[0] = mashWaterQTS - absorbedQTS; totalCollectQts = totalCollectQts - collect[0]; } else { charge[0] = col - (mashWaterQTS - absorbedQTS); collect[0] = col; totalCollectQts = totalCollectQts - collect[0]; } // do we need any more steps? if (numSparge > 1) { col = totalCollectQts / (numSparge - 1); for (int i = 1; i < numSparge; i++) { charge[i] = col; collect[i] = col; } } int j=0; for (int i = 1; i < steps.size(); i++) { stp = ((MashStep) steps.get(i)); if (stp.getType().equals("sparge")){ stp.vol.setUnits("qt"); stp.vol.setAmount(collect[j]); stp.temp = SPARGETMPF; totalSpargeTime += stp.getMinutes(); String collectStr = SBStringUtils.format(Quantity.convertUnit("qt", volUnits, collect[j]), 1) + " " + volUnits; String tempStr; if (tempUnits.equals("F")){ tempStr = "" + SBStringUtils.format(SPARGETMPF, 1) + "F"; } else { tempStr = SBStringUtils.format(fToC(SPARGETMPF), 1) + "C"; } if (numSparge > 1){ stp.setMethod("batch"); String add = SBStringUtils.format(Quantity.convertUnit("qt", volUnits, charge[j]), 1) + " " + volUnits; stp.setDirections("Add " + add + " at " + tempStr + " to collect " + collectStr); } else { stp.vol.setUnits("qt"); stp.vol.setAmount(spargeQTS); stp.setMethod("fly"); stp.setDirections("Sparge with " + SBStringUtils.format(Quantity.convertUnit("qt", volUnits, spargeQTS), 1) + " " + volUnits + " at " + tempStr + " to collect " + collectStr); } j++; } } }
public void calcMashSchedule() { // Method to run through the mash table and calculate values if (!myRecipe.allowRecalcs) return; double strikeTemp = 0; double targetTemp = 0; double waterAddedQTS = 0; double waterEquiv = 0; double mr = mashRatio; double currentTemp = grainTempF; double displTemp = 0; double tunLoss; // figure out a better way to do this, eg: themal mass double decoct = 0; int totalMashTime = 0; int totalSpargeTime = 0; double mashWaterQTS = 0; double mashVolQTS = 0; int numSparge = 0; double totalWeightLbs = 0; double totalCerealLbs = 0; maltWeightLbs = myRecipe.getTotalMashLbs(); // convert mash ratio to qts/lb if in l/kg if (mashRatioU.equalsIgnoreCase("l/kg")) { mr *= 0.479325; } // convert CurrentTemp to F if (tempUnits == "C") { currentTemp = BrewCalcs.cToF(currentTemp); tunLoss = tunLossF * 1.8; } else tunLoss = tunLossF; // perform calcs on first record if (steps.isEmpty()) return; // sort the list Collections.sort(steps, new stepComparator()); // add up the cereal mash lbs for (int i=0; i<steps.size(); i++){ MashStep stp = ((MashStep) steps.get(i)); if (stp.method.equals("cereal mash")){ totalCerealLbs += stp.weightLbs; } } totalWeightLbs = maltWeightLbs - totalCerealLbs; // the first step is always an infusion MashStep stp = ((MashStep) steps.get(0)); targetTemp = stp.startTemp; strikeTemp = calcStrikeTemp(targetTemp, currentTemp, mr, tunLoss); waterAddedQTS = mr * totalWeightLbs; waterEquiv = totalWeightLbs * (0.192 + mr); mashVolQTS = calcMashVol(totalWeightLbs, mr); totalMashTime += stp.minutes; mashWaterQTS += waterAddedQTS; stp.vol.setUnits("qt"); stp.vol.setAmount(waterAddedQTS); stp.temp = strikeTemp; stp.method = "infusion"; stp.weightLbs = totalWeightLbs; // subtract the water added from the Water Equiv so that they are correct when added in the next part of the loop waterEquiv -= waterAddedQTS; // Updated the water added if (tempUnits == "C") strikeTemp = fToC(strikeTemp); stp.directions = "Mash in with " + SBStringUtils.format(stp.vol.getValueAs(volUnits),1 ) + " " + volUnits + " of water at " + SBStringUtils.format(strikeTemp, 1) + " " + tempUnits; // set TargetTemp to the end temp targetTemp = stp.endTemp; for (int i = 1; i < steps.size(); i++) { stp = ((MashStep) steps.get(i)); currentTemp = targetTemp; // switch targetTemp = stp.startTemp; // if this is a former sparge step that's been changed, change // the method to infusion if (!stp.type.equals("sparge") && ( stp.method.equals("fly") || stp.method.equals("batch"))) stp.method = "infusion"; // do calcs if (stp.method.equals("infusion")) { // calculate an infusion step decoct = 0; waterEquiv += waterAddedQTS; // add previous addition to get WE strikeTemp = boilTempF; // boiling water // Updated the water added waterAddedQTS = calcWaterAddition(targetTemp, currentTemp, waterEquiv, boilTempF); stp.vol.setUnits("qt"); stp.vol.setAmount(waterAddedQTS); stp.temp = strikeTemp; stp.weightLbs = totalWeightLbs; if (tempUnits == "C") strikeTemp = 100; stp.directions = "Add " + SBStringUtils.format(stp.vol.getValueAs(volUnits), 1) + " " + volUnits + " of water at " + SBStringUtils.format(strikeTemp, 1) + " " + tempUnits; mashWaterQTS += waterAddedQTS; mashVolQTS += waterAddedQTS; } else if (stp.method.indexOf("decoction") > -1) { // calculate a decoction step waterEquiv += waterAddedQTS; // add previous addition to get WE waterAddedQTS = 0; strikeTemp = boilTempF; // boiling water double ratio=0.75; if (stp.method.indexOf("thick") > -1) ratio = thickDecoctRatio; else if (stp.method.indexOf("thin") > -1) ratio = thinDecoctRatio; // Calculate volume (qts) of mash to remove decoct = calcDecoction2(targetTemp, currentTemp, mashWaterQTS, ratio, totalWeightLbs); stp.vol.setUnits("qt"); stp.vol.setAmount(decoct); stp.temp = boilTempF; stp.weightLbs = totalWeightLbs; // Updated the decoction, convert to right units & make directions stp.directions = "Remove " + SBStringUtils.format(stp.vol.getValueAs(volUnits), 1) + " " + volUnits + " of mash, boil, and return to mash."; } else if (stp.method.equals("direct")) { // calculate a direct heat step decoct = 0; waterEquiv += waterAddedQTS; // add previous addition to get WE waterAddedQTS = 0; displTemp = stp.startTemp; if (tempUnits.equals("C")) displTemp = fToC(displTemp); stp.directions = "Add direct heat until mash reaches " + displTemp + " " + tempUnits + "."; stp.vol.setAmount(0); stp.temp = 0; stp.weightLbs = totalWeightLbs; } else if (stp.method.indexOf("cereal mash") > -1) { // calculate a cereal mash step waterEquiv += waterAddedQTS; // add previous addition to get WE waterAddedQTS = 0; targetTemp = stp.startTemp; double extraWaterQTS = 0; double cerealTemp = boilTempF; double cerealTargTemp = cerealMashTemp; String addStr = ""; /* * 1. check the temp of the mash when you add the boiling cereal mash @ default ratio back * 2. if it's > than the step temp, adjust the step temp * 3. if it's < than the step temp, add extra water to increase the "heat equivalencey" of the cereal mash */ double cerealWaterEquiv = stp.weightLbs * (0.192 + mr); waterAddedQTS = mr * stp.weightLbs; strikeTemp = calcStrikeTemp(cerealMashTemp, grainTempF, mr, 0); double newTemp = ((waterEquiv * currentTemp) + (cerealWaterEquiv * cerealTemp)) / (waterEquiv + cerealWaterEquiv); if (newTemp > targetTemp){ stp.startTemp = newTemp; } if (newTemp < targetTemp){ double addQts = ((waterEquiv * (targetTemp - currentTemp)) / (cerealTemp - targetTemp)) - 0.192; extraWaterQTS = addQts - waterAddedQTS; addStr = " Add " + SBStringUtils.format(Quantity.convertUnit("qt", volUnits, extraWaterQTS), 1) + " " + volUnits + " water to the cereal mash."; } // Calculate final temp of cereal mash // cerealTemp = (targetTemp * (waterEquiv + cerealWaterEquiv) - (waterEquiv * currentTemp)) / cerealWaterEquiv; totalMashTime += stp.minutes; mashWaterQTS += waterAddedQTS + extraWaterQTS; stp.vol.setUnits("qt"); stp.vol.setAmount(waterAddedQTS); stp.temp = strikeTemp; // make directions String weightStr = SBStringUtils.format(Quantity.convertUnit("lb", myRecipe.getMaltUnits(), stp.weightLbs), 1) + " " + myRecipe.getMaltUnits(); String volStr = SBStringUtils.format(Quantity.convertUnit("qt", volUnits, waterAddedQTS), 1) + " " + volUnits; if (tempUnits == "C"){ strikeTemp = fToC(strikeTemp); cerealTemp = fToC(cerealTemp); targetTemp = fToC(targetTemp); cerealTargTemp = fToC(cerealTargTemp); } String tempStr = SBStringUtils.format(strikeTemp, 1) + tempUnits; String tempStr2 = SBStringUtils.format(cerealTemp, 1) + tempUnits; String tempStr3 = SBStringUtils.format(targetTemp, 1) + tempUnits; String tempStr4 = SBStringUtils.format(cerealTargTemp, 1) + tempUnits; stp.directions = "Cereal mash: mash " + weightStr + " grain with " + volStr + " water at " + tempStr + " to hit " + tempStr4 + " and rest."; stp.directions += addStr; stp.directions += " Raise to " + tempStr2 + " and add to the main mash to reach " + tempStr3; // add cereal mash to total weight totalWeightLbs += stp.weightLbs; } if (stp.type.equals("sparge")) numSparge++; else { totalMashTime += stp.minutes; } // set target temp to end temp for next step targetTemp = stp.endTemp; } // for steps.size() waterEquiv += waterAddedQTS; // add previous addition to get WE totalTime = totalMashTime; volQts = mashVolQTS; // water use stats: absorbedQTS = totalWeightLbs * 0.55; // figure from HBD // spargeTotalQTS = (myRecipe.getPreBoilVol("qt")) - (mashWaterQTS - absorbedQTS); totalWaterQTS = mashWaterQTS; spargeQTS = myRecipe.getPreBoilVol("qt") - (mashWaterQTS - absorbedQTS); // Now let's figure out the sparging: if (numSparge == 0) return; double col = myRecipe.getPreBoilVol("qt") / numSparge; double charge[] = new double[numSparge]; double collect[] = new double[numSparge]; double totalCollectQts = myRecipe.getPreBoilVol("qt"); if (col < mashWaterQTS - absorbedQTS) { charge[0] = 0; collect[0] = mashWaterQTS - absorbedQTS; totalCollectQts = totalCollectQts - collect[0]; } else { charge[0] = col - (mashWaterQTS - absorbedQTS); collect[0] = col; totalCollectQts = totalCollectQts - collect[0]; } // do we need any more steps? if (numSparge > 1) { col = totalCollectQts / (numSparge - 1); for (int i = 1; i < numSparge; i++) { charge[i] = col; collect[i] = col; } } int j=0; for (int i = 1; i < steps.size(); i++) { stp = ((MashStep) steps.get(i)); if (stp.getType().equals("sparge")){ stp.vol.setUnits("qt"); stp.vol.setAmount(collect[j]); stp.temp = SPARGETMPF; totalSpargeTime += stp.getMinutes(); String collectStr = SBStringUtils.format(Quantity.convertUnit("qt", volUnits, collect[j]), 1) + " " + volUnits; String tempStr; if (tempUnits.equals("F")){ tempStr = "" + SBStringUtils.format(SPARGETMPF, 1) + "F"; } else { tempStr = SBStringUtils.format(fToC(SPARGETMPF), 1) + "C"; } if (numSparge > 1){ stp.setMethod("batch"); String add = SBStringUtils.format(Quantity.convertUnit("qt", volUnits, charge[j]), 1) + " " + volUnits; stp.setDirections("Add " + add + " at " + tempStr + " to collect " + collectStr); } else { stp.vol.setUnits("qt"); stp.vol.setAmount(spargeQTS); stp.setMethod("fly"); stp.setDirections("Sparge with " + SBStringUtils.format(Quantity.convertUnit("qt", volUnits, spargeQTS), 1) + " " + volUnits + " at " + tempStr + " to collect " + collectStr); } j++; } } }
1,115,251
public void calcMashSchedule() { // Method to run through the mash table and calculate values if (!myRecipe.allowRecalcs) return; double strikeTemp = 0; double targetTemp = 0; double waterAddedQTS = 0; double waterEquiv = 0; double mr = mashRatio; double currentTemp = grainTempF; double displTemp = 0; double tunLoss; // figure out a better way to do this, eg: themal mass double decoct = 0; int totalMashTime = 0; int totalSpargeTime = 0; double mashWaterQTS = 0; double mashVolQTS = 0; int numSparge = 0; double totalWeightLbs = 0; double totalCerealLbs = 0; maltWeightLbs = myRecipe.getTotalMashLbs(); // convert mash ratio to qts/lb if in l/kg if (mashRatioU.equalsIgnoreCase("l/kg")) { mr *= 0.479325; } // convert CurrentTemp to F if (tempUnits == "C") { currentTemp = cToF(currentTemp); tunLoss = tunLossF * 1.8; } else tunLoss = tunLossF; // perform calcs on first record if (steps.isEmpty()) return; // sort the list Collections.sort(steps, new stepComparator()); // add up the cereal mash lbs for (int i=0; i<steps.size(); i++){ MashStep stp = ((MashStep) steps.get(i)); if (stp.method.equals("cereal mash")){ totalCerealLbs += stp.weightLbs; } } totalWeightLbs = maltWeightLbs - totalCerealLbs; // the first step is always an infusion MashStep stp = ((MashStep) steps.get(0)); targetTemp = stp.startTemp; strikeTemp = calcStrikeTemp(targetTemp, currentTemp, mr, tunLoss); waterAddedQTS = mr * totalWeightLbs; waterEquiv = totalWeightLbs * (0.192 + mr); mashVolQTS = calcMashVol(totalWeightLbs, mr); totalMashTime += stp.minutes; mashWaterQTS += waterAddedQTS; stp.vol.setUnits("qt"); stp.vol.setAmount(waterAddedQTS); stp.temp = strikeTemp; stp.method = "infusion"; stp.weightLbs = totalWeightLbs; // subtract the water added from the Water Equiv so that they are correct when added in the next part of the loop waterEquiv -= waterAddedQTS; // Updated the water added if (tempUnits == "C") strikeTemp = fToC(strikeTemp); stp.directions = "Mash in with " + SBStringUtils.format(stp.vol.getValueAs(volUnits),1 ) + " " + volUnits + " of water at " + SBStringUtils.format(strikeTemp, 1) + " " + tempUnits; // set TargetTemp to the end temp targetTemp = stp.endTemp; for (int i = 1; i < steps.size(); i++) { stp = ((MashStep) steps.get(i)); currentTemp = targetTemp; // switch targetTemp = stp.startTemp; // if this is a former sparge step that's been changed, change // the method to infusion if (!stp.type.equals("sparge") && ( stp.method.equals("fly") || stp.method.equals("batch"))) stp.method = "infusion"; // do calcs if (stp.method.equals("infusion")) { // calculate an infusion step decoct = 0; waterEquiv += waterAddedQTS; // add previous addition to get WE strikeTemp = boilTempF; // boiling water // Updated the water added waterAddedQTS = calcWaterAddition(targetTemp, currentTemp, waterEquiv, boilTempF); stp.vol.setUnits("qt"); stp.vol.setAmount(waterAddedQTS); stp.temp = strikeTemp; stp.weightLbs = totalWeightLbs; if (tempUnits == "C") strikeTemp = 100; stp.directions = "Add " + SBStringUtils.format(stp.vol.getValueAs(volUnits), 1) + " " + volUnits + " of water at " + SBStringUtils.format(strikeTemp, 1) + " " + tempUnits; mashWaterQTS += waterAddedQTS; mashVolQTS += waterAddedQTS; } else if (stp.method.indexOf("decoction") > -1) { // calculate a decoction step waterEquiv += waterAddedQTS; // add previous addition to get WE waterAddedQTS = 0; strikeTemp = boilTempF; // boiling water double ratio=0.75; if (stp.method.indexOf("thick") > -1) ratio = thickDecoctRatio; else if (stp.method.indexOf("thin") > -1) ratio = thinDecoctRatio; // Calculate volume (qts) of mash to remove decoct = calcDecoction2(targetTemp, currentTemp, mashWaterQTS, ratio, totalWeightLbs); stp.vol.setUnits("qt"); stp.vol.setAmount(decoct); stp.temp = boilTempF; stp.weightLbs = totalWeightLbs; // Updated the decoction, convert to right units & make directions stp.directions = "Remove " + SBStringUtils.format(stp.vol.getValueAs(volUnits), 1) + " " + volUnits + " of mash, boil, and return to mash."; } else if (stp.method.equals("direct")) { // calculate a direct heat step decoct = 0; waterEquiv += waterAddedQTS; // add previous addition to get WE waterAddedQTS = 0; displTemp = stp.startTemp; if (tempUnits.equals("C")) displTemp = fToC(displTemp); stp.directions = "Add direct heat until mash reaches " + displTemp + " " + tempUnits + "."; stp.vol.setAmount(0); stp.temp = 0; stp.weightLbs = totalWeightLbs; } else if (stp.method.indexOf("cereal mash") > -1) { // calculate a cereal mash step waterEquiv += waterAddedQTS; // add previous addition to get WE waterAddedQTS = 0; targetTemp = stp.startTemp; double extraWaterQTS = 0; double cerealTemp = boilTempF; double cerealTargTemp = cerealMashTemp; String addStr = ""; /* * 1. check the temp of the mash when you add the boiling cereal mash @ default ratio back * 2. if it's > than the step temp, adjust the step temp * 3. if it's < than the step temp, add extra water to increase the "heat equivalencey" of the cereal mash */ double cerealWaterEquiv = stp.weightLbs * (0.192 + mr); waterAddedQTS = mr * stp.weightLbs; strikeTemp = calcStrikeTemp(cerealMashTemp, grainTempF, mr, 0); double newTemp = ((waterEquiv * currentTemp) + (cerealWaterEquiv * cerealTemp)) / (waterEquiv + cerealWaterEquiv); if (newTemp > targetTemp){ stp.startTemp = newTemp; } if (newTemp < targetTemp){ double addQts = ((waterEquiv * (targetTemp - currentTemp)) / (cerealTemp - targetTemp)) - 0.192; extraWaterQTS = addQts - waterAddedQTS; addStr = " Add " + SBStringUtils.format(Quantity.convertUnit("qt", volUnits, extraWaterQTS), 1) + " " + volUnits + " water to the cereal mash."; } // Calculate final temp of cereal mash // cerealTemp = (targetTemp * (waterEquiv + cerealWaterEquiv) - (waterEquiv * currentTemp)) / cerealWaterEquiv; totalMashTime += stp.minutes; mashWaterQTS += waterAddedQTS + extraWaterQTS; stp.vol.setUnits("qt"); stp.vol.setAmount(waterAddedQTS); stp.temp = strikeTemp; // make directions String weightStr = SBStringUtils.format(Quantity.convertUnit("lb", myRecipe.getMaltUnits(), stp.weightLbs), 1) + " " + myRecipe.getMaltUnits(); String volStr = SBStringUtils.format(Quantity.convertUnit("qt", volUnits, waterAddedQTS), 1) + " " + volUnits; if (tempUnits == "C"){ strikeTemp = fToC(strikeTemp); cerealTemp = fToC(cerealTemp); targetTemp = fToC(targetTemp); cerealTargTemp = fToC(cerealTargTemp); } String tempStr = SBStringUtils.format(strikeTemp, 1) + tempUnits; String tempStr2 = SBStringUtils.format(cerealTemp, 1) + tempUnits; String tempStr3 = SBStringUtils.format(targetTemp, 1) + tempUnits; String tempStr4 = SBStringUtils.format(cerealTargTemp, 1) + tempUnits; stp.directions = "Cereal mash: mash " + weightStr + " grain with " + volStr + " water at " + tempStr + " to hit " + tempStr4 + " and rest."; stp.directions += addStr; stp.directions += " Raise to " + tempStr2 + " and add to the main mash to reach " + tempStr3; // add cereal mash to total weight totalWeightLbs += stp.weightLbs; } if (stp.type.equals("sparge")) numSparge++; else { totalMashTime += stp.minutes; } // set target temp to end temp for next step targetTemp = stp.endTemp; } // for steps.size() waterEquiv += waterAddedQTS; // add previous addition to get WE totalTime = totalMashTime; volQts = mashVolQTS; // water use stats: absorbedQTS = totalWeightLbs * 0.55; // figure from HBD // spargeTotalQTS = (myRecipe.getPreBoilVol("qt")) - (mashWaterQTS - absorbedQTS); totalWaterQTS = mashWaterQTS; spargeQTS = myRecipe.getPreBoilVol("qt") - (mashWaterQTS - absorbedQTS); // Now let's figure out the sparging: if (numSparge == 0) return; double col = myRecipe.getPreBoilVol("qt") / numSparge; double charge[] = new double[numSparge]; double collect[] = new double[numSparge]; double totalCollectQts = myRecipe.getPreBoilVol("qt"); if (col < mashWaterQTS - absorbedQTS) { charge[0] = 0; collect[0] = mashWaterQTS - absorbedQTS; totalCollectQts = totalCollectQts - collect[0]; } else { charge[0] = col - (mashWaterQTS - absorbedQTS); collect[0] = col; totalCollectQts = totalCollectQts - collect[0]; } // do we need any more steps? if (numSparge > 1) { col = totalCollectQts / (numSparge - 1); for (int i = 1; i < numSparge; i++) { charge[i] = col; collect[i] = col; } } int j=0; for (int i = 1; i < steps.size(); i++) { stp = ((MashStep) steps.get(i)); if (stp.getType().equals("sparge")){ stp.vol.setUnits("qt"); stp.vol.setAmount(collect[j]); stp.temp = SPARGETMPF; totalSpargeTime += stp.getMinutes(); String collectStr = SBStringUtils.format(Quantity.convertUnit("qt", volUnits, collect[j]), 1) + " " + volUnits; String tempStr; if (tempUnits.equals("F")){ tempStr = "" + SBStringUtils.format(SPARGETMPF, 1) + "F"; } else { tempStr = SBStringUtils.format(fToC(SPARGETMPF), 1) + "C"; } if (numSparge > 1){ stp.setMethod("batch"); String add = SBStringUtils.format(Quantity.convertUnit("qt", volUnits, charge[j]), 1) + " " + volUnits; stp.setDirections("Add " + add + " at " + tempStr + " to collect " + collectStr); } else { stp.vol.setUnits("qt"); stp.vol.setAmount(spargeQTS); stp.setMethod("fly"); stp.setDirections("Sparge with " + SBStringUtils.format(Quantity.convertUnit("qt", volUnits, spargeQTS), 1) + " " + volUnits + " at " + tempStr + " to collect " + collectStr); } j++; } } }
public void calcMashSchedule() { // Method to run through the mash table and calculate values if (!myRecipe.allowRecalcs) return; double strikeTemp = 0; double targetTemp = 0; double waterAddedQTS = 0; double waterEquiv = 0; double mr = mashRatio; double currentTemp = grainTempF; double displTemp = 0; double tunLoss; // figure out a better way to do this, eg: themal mass double decoct = 0; int totalMashTime = 0; int totalSpargeTime = 0; double mashWaterQTS = 0; double mashVolQTS = 0; int numSparge = 0; double totalWeightLbs = 0; double totalCerealLbs = 0; maltWeightLbs = myRecipe.getTotalMashLbs(); // convert mash ratio to qts/lb if in l/kg if (mashRatioU.equalsIgnoreCase("l/kg")) { mr *= 0.479325; } // convert CurrentTemp to F if (tempUnits == "C") { currentTemp = cToF(currentTemp); tunLoss = tunLossF * 1.8; } else tunLoss = tunLossF; // perform calcs on first record if (steps.isEmpty()) return; // sort the list Collections.sort(steps, new stepComparator()); // add up the cereal mash lbs for (int i=0; i<steps.size(); i++){ MashStep stp = ((MashStep) steps.get(i)); if (stp.method.equals("cereal mash")){ totalCerealLbs += stp.weightLbs; } } totalWeightLbs = maltWeightLbs - totalCerealLbs; // the first step is always an infusion MashStep stp = ((MashStep) steps.get(0)); targetTemp = stp.startTemp; strikeTemp = calcStrikeTemp(targetTemp, currentTemp, mr, tunLoss); waterAddedQTS = mr * totalWeightLbs; waterEquiv = totalWeightLbs * (0.192 + mr); mashVolQTS = calcMashVol(totalWeightLbs, mr); totalMashTime += stp.minutes; mashWaterQTS += waterAddedQTS; stp.vol.setUnits("qt"); stp.vol.setAmount(waterAddedQTS); stp.temp = strikeTemp; stp.method = "infusion"; stp.weightLbs = totalWeightLbs; // subtract the water added from the Water Equiv so that they are correct when added in the next part of the loop waterEquiv -= waterAddedQTS; // Updated the water added if (tempUnits == "C") strikeTemp = BrewCalcs.fToC(strikeTemp); stp.directions = "Mash in with " + SBStringUtils.format(stp.vol.getValueAs(volUnits),1 ) + " " + volUnits + " of water at " + SBStringUtils.format(strikeTemp, 1) + " " + tempUnits; // set TargetTemp to the end temp targetTemp = stp.endTemp; for (int i = 1; i < steps.size(); i++) { stp = ((MashStep) steps.get(i)); currentTemp = targetTemp; // switch targetTemp = stp.startTemp; // if this is a former sparge step that's been changed, change // the method to infusion if (!stp.type.equals("sparge") && ( stp.method.equals("fly") || stp.method.equals("batch"))) stp.method = "infusion"; // do calcs if (stp.method.equals("infusion")) { // calculate an infusion step decoct = 0; waterEquiv += waterAddedQTS; // add previous addition to get WE strikeTemp = boilTempF; // boiling water // Updated the water added waterAddedQTS = calcWaterAddition(targetTemp, currentTemp, waterEquiv, boilTempF); stp.vol.setUnits("qt"); stp.vol.setAmount(waterAddedQTS); stp.temp = strikeTemp; stp.weightLbs = totalWeightLbs; if (tempUnits == "C") strikeTemp = 100; stp.directions = "Add " + SBStringUtils.format(stp.vol.getValueAs(volUnits), 1) + " " + volUnits + " of water at " + SBStringUtils.format(strikeTemp, 1) + " " + tempUnits; mashWaterQTS += waterAddedQTS; mashVolQTS += waterAddedQTS; } else if (stp.method.indexOf("decoction") > -1) { // calculate a decoction step waterEquiv += waterAddedQTS; // add previous addition to get WE waterAddedQTS = 0; strikeTemp = boilTempF; // boiling water double ratio=0.75; if (stp.method.indexOf("thick") > -1) ratio = thickDecoctRatio; else if (stp.method.indexOf("thin") > -1) ratio = thinDecoctRatio; // Calculate volume (qts) of mash to remove decoct = calcDecoction2(targetTemp, currentTemp, mashWaterQTS, ratio, totalWeightLbs); stp.vol.setUnits("qt"); stp.vol.setAmount(decoct); stp.temp = boilTempF; stp.weightLbs = totalWeightLbs; // Updated the decoction, convert to right units & make directions stp.directions = "Remove " + SBStringUtils.format(stp.vol.getValueAs(volUnits), 1) + " " + volUnits + " of mash, boil, and return to mash."; } else if (stp.method.equals("direct")) { // calculate a direct heat step decoct = 0; waterEquiv += waterAddedQTS; // add previous addition to get WE waterAddedQTS = 0; displTemp = stp.startTemp; if (tempUnits.equals("C")) displTemp = fToC(displTemp); stp.directions = "Add direct heat until mash reaches " + displTemp + " " + tempUnits + "."; stp.vol.setAmount(0); stp.temp = 0; stp.weightLbs = totalWeightLbs; } else if (stp.method.indexOf("cereal mash") > -1) { // calculate a cereal mash step waterEquiv += waterAddedQTS; // add previous addition to get WE waterAddedQTS = 0; targetTemp = stp.startTemp; double extraWaterQTS = 0; double cerealTemp = boilTempF; double cerealTargTemp = cerealMashTemp; String addStr = ""; /* * 1. check the temp of the mash when you add the boiling cereal mash @ default ratio back * 2. if it's > than the step temp, adjust the step temp * 3. if it's < than the step temp, add extra water to increase the "heat equivalencey" of the cereal mash */ double cerealWaterEquiv = stp.weightLbs * (0.192 + mr); waterAddedQTS = mr * stp.weightLbs; strikeTemp = calcStrikeTemp(cerealMashTemp, grainTempF, mr, 0); double newTemp = ((waterEquiv * currentTemp) + (cerealWaterEquiv * cerealTemp)) / (waterEquiv + cerealWaterEquiv); if (newTemp > targetTemp){ stp.startTemp = newTemp; } if (newTemp < targetTemp){ double addQts = ((waterEquiv * (targetTemp - currentTemp)) / (cerealTemp - targetTemp)) - 0.192; extraWaterQTS = addQts - waterAddedQTS; addStr = " Add " + SBStringUtils.format(Quantity.convertUnit("qt", volUnits, extraWaterQTS), 1) + " " + volUnits + " water to the cereal mash."; } // Calculate final temp of cereal mash // cerealTemp = (targetTemp * (waterEquiv + cerealWaterEquiv) - (waterEquiv * currentTemp)) / cerealWaterEquiv; totalMashTime += stp.minutes; mashWaterQTS += waterAddedQTS + extraWaterQTS; stp.vol.setUnits("qt"); stp.vol.setAmount(waterAddedQTS); stp.temp = strikeTemp; // make directions String weightStr = SBStringUtils.format(Quantity.convertUnit("lb", myRecipe.getMaltUnits(), stp.weightLbs), 1) + " " + myRecipe.getMaltUnits(); String volStr = SBStringUtils.format(Quantity.convertUnit("qt", volUnits, waterAddedQTS), 1) + " " + volUnits; if (tempUnits == "C"){ strikeTemp = BrewCalcs.fToC(strikeTemp); cerealTemp = fToC(cerealTemp); targetTemp = fToC(targetTemp); cerealTargTemp = fToC(cerealTargTemp); } String tempStr = SBStringUtils.format(strikeTemp, 1) + tempUnits; String tempStr2 = SBStringUtils.format(cerealTemp, 1) + tempUnits; String tempStr3 = SBStringUtils.format(targetTemp, 1) + tempUnits; String tempStr4 = SBStringUtils.format(cerealTargTemp, 1) + tempUnits; stp.directions = "Cereal mash: mash " + weightStr + " grain with " + volStr + " water at " + tempStr + " to hit " + tempStr4 + " and rest."; stp.directions += addStr; stp.directions += " Raise to " + tempStr2 + " and add to the main mash to reach " + tempStr3; // add cereal mash to total weight totalWeightLbs += stp.weightLbs; } if (stp.type.equals("sparge")) numSparge++; else { totalMashTime += stp.minutes; } // set target temp to end temp for next step targetTemp = stp.endTemp; } // for steps.size() waterEquiv += waterAddedQTS; // add previous addition to get WE totalTime = totalMashTime; volQts = mashVolQTS; // water use stats: absorbedQTS = totalWeightLbs * 0.55; // figure from HBD // spargeTotalQTS = (myRecipe.getPreBoilVol("qt")) - (mashWaterQTS - absorbedQTS); totalWaterQTS = mashWaterQTS; spargeQTS = myRecipe.getPreBoilVol("qt") - (mashWaterQTS - absorbedQTS); // Now let's figure out the sparging: if (numSparge == 0) return; double col = myRecipe.getPreBoilVol("qt") / numSparge; double charge[] = new double[numSparge]; double collect[] = new double[numSparge]; double totalCollectQts = myRecipe.getPreBoilVol("qt"); if (col < mashWaterQTS - absorbedQTS) { charge[0] = 0; collect[0] = mashWaterQTS - absorbedQTS; totalCollectQts = totalCollectQts - collect[0]; } else { charge[0] = col - (mashWaterQTS - absorbedQTS); collect[0] = col; totalCollectQts = totalCollectQts - collect[0]; } // do we need any more steps? if (numSparge > 1) { col = totalCollectQts / (numSparge - 1); for (int i = 1; i < numSparge; i++) { charge[i] = col; collect[i] = col; } } int j=0; for (int i = 1; i < steps.size(); i++) { stp = ((MashStep) steps.get(i)); if (stp.getType().equals("sparge")){ stp.vol.setUnits("qt"); stp.vol.setAmount(collect[j]); stp.temp = SPARGETMPF; totalSpargeTime += stp.getMinutes(); String collectStr = SBStringUtils.format(Quantity.convertUnit("qt", volUnits, collect[j]), 1) + " " + volUnits; String tempStr; if (tempUnits.equals("F")){ tempStr = "" + SBStringUtils.format(SPARGETMPF, 1) + "F"; } else { tempStr = SBStringUtils.format(fToC(SPARGETMPF), 1) + "C"; } if (numSparge > 1){ stp.setMethod("batch"); String add = SBStringUtils.format(Quantity.convertUnit("qt", volUnits, charge[j]), 1) + " " + volUnits; stp.setDirections("Add " + add + " at " + tempStr + " to collect " + collectStr); } else { stp.vol.setUnits("qt"); stp.vol.setAmount(spargeQTS); stp.setMethod("fly"); stp.setDirections("Sparge with " + SBStringUtils.format(Quantity.convertUnit("qt", volUnits, spargeQTS), 1) + " " + volUnits + " at " + tempStr + " to collect " + collectStr); } j++; } } }
1,115,252
public void calcMashSchedule() { // Method to run through the mash table and calculate values if (!myRecipe.allowRecalcs) return; double strikeTemp = 0; double targetTemp = 0; double waterAddedQTS = 0; double waterEquiv = 0; double mr = mashRatio; double currentTemp = grainTempF; double displTemp = 0; double tunLoss; // figure out a better way to do this, eg: themal mass double decoct = 0; int totalMashTime = 0; int totalSpargeTime = 0; double mashWaterQTS = 0; double mashVolQTS = 0; int numSparge = 0; double totalWeightLbs = 0; double totalCerealLbs = 0; maltWeightLbs = myRecipe.getTotalMashLbs(); // convert mash ratio to qts/lb if in l/kg if (mashRatioU.equalsIgnoreCase("l/kg")) { mr *= 0.479325; } // convert CurrentTemp to F if (tempUnits == "C") { currentTemp = cToF(currentTemp); tunLoss = tunLossF * 1.8; } else tunLoss = tunLossF; // perform calcs on first record if (steps.isEmpty()) return; // sort the list Collections.sort(steps, new stepComparator()); // add up the cereal mash lbs for (int i=0; i<steps.size(); i++){ MashStep stp = ((MashStep) steps.get(i)); if (stp.method.equals("cereal mash")){ totalCerealLbs += stp.weightLbs; } } totalWeightLbs = maltWeightLbs - totalCerealLbs; // the first step is always an infusion MashStep stp = ((MashStep) steps.get(0)); targetTemp = stp.startTemp; strikeTemp = calcStrikeTemp(targetTemp, currentTemp, mr, tunLoss); waterAddedQTS = mr * totalWeightLbs; waterEquiv = totalWeightLbs * (0.192 + mr); mashVolQTS = calcMashVol(totalWeightLbs, mr); totalMashTime += stp.minutes; mashWaterQTS += waterAddedQTS; stp.vol.setUnits("qt"); stp.vol.setAmount(waterAddedQTS); stp.temp = strikeTemp; stp.method = "infusion"; stp.weightLbs = totalWeightLbs; // subtract the water added from the Water Equiv so that they are correct when added in the next part of the loop waterEquiv -= waterAddedQTS; // Updated the water added if (tempUnits == "C") strikeTemp = fToC(strikeTemp); stp.directions = "Mash in with " + SBStringUtils.format(stp.vol.getValueAs(volUnits),1 ) + " " + volUnits + " of water at " + SBStringUtils.format(strikeTemp, 1) + " " + tempUnits; // set TargetTemp to the end temp targetTemp = stp.endTemp; for (int i = 1; i < steps.size(); i++) { stp = ((MashStep) steps.get(i)); currentTemp = targetTemp; // switch targetTemp = stp.startTemp; // if this is a former sparge step that's been changed, change // the method to infusion if (!stp.type.equals("sparge") && ( stp.method.equals("fly") || stp.method.equals("batch"))) stp.method = "infusion"; // do calcs if (stp.method.equals("infusion")) { // calculate an infusion step decoct = 0; waterEquiv += waterAddedQTS; // add previous addition to get WE strikeTemp = boilTempF; // boiling water // Updated the water added waterAddedQTS = calcWaterAddition(targetTemp, currentTemp, waterEquiv, boilTempF); stp.vol.setUnits("qt"); stp.vol.setAmount(waterAddedQTS); stp.temp = strikeTemp; stp.weightLbs = totalWeightLbs; if (tempUnits == "C") strikeTemp = 100; stp.directions = "Add " + SBStringUtils.format(stp.vol.getValueAs(volUnits), 1) + " " + volUnits + " of water at " + SBStringUtils.format(strikeTemp, 1) + " " + tempUnits; mashWaterQTS += waterAddedQTS; mashVolQTS += waterAddedQTS; } else if (stp.method.indexOf("decoction") > -1) { // calculate a decoction step waterEquiv += waterAddedQTS; // add previous addition to get WE waterAddedQTS = 0; strikeTemp = boilTempF; // boiling water double ratio=0.75; if (stp.method.indexOf("thick") > -1) ratio = thickDecoctRatio; else if (stp.method.indexOf("thin") > -1) ratio = thinDecoctRatio; // Calculate volume (qts) of mash to remove decoct = calcDecoction2(targetTemp, currentTemp, mashWaterQTS, ratio, totalWeightLbs); stp.vol.setUnits("qt"); stp.vol.setAmount(decoct); stp.temp = boilTempF; stp.weightLbs = totalWeightLbs; // Updated the decoction, convert to right units & make directions stp.directions = "Remove " + SBStringUtils.format(stp.vol.getValueAs(volUnits), 1) + " " + volUnits + " of mash, boil, and return to mash."; } else if (stp.method.equals("direct")) { // calculate a direct heat step decoct = 0; waterEquiv += waterAddedQTS; // add previous addition to get WE waterAddedQTS = 0; displTemp = stp.startTemp; if (tempUnits.equals("C")) displTemp = fToC(displTemp); stp.directions = "Add direct heat until mash reaches " + displTemp + " " + tempUnits + "."; stp.vol.setAmount(0); stp.temp = 0; stp.weightLbs = totalWeightLbs; } else if (stp.method.indexOf("cereal mash") > -1) { // calculate a cereal mash step waterEquiv += waterAddedQTS; // add previous addition to get WE waterAddedQTS = 0; targetTemp = stp.startTemp; double extraWaterQTS = 0; double cerealTemp = boilTempF; double cerealTargTemp = cerealMashTemp; String addStr = ""; /* * 1. check the temp of the mash when you add the boiling cereal mash @ default ratio back * 2. if it's > than the step temp, adjust the step temp * 3. if it's < than the step temp, add extra water to increase the "heat equivalencey" of the cereal mash */ double cerealWaterEquiv = stp.weightLbs * (0.192 + mr); waterAddedQTS = mr * stp.weightLbs; strikeTemp = calcStrikeTemp(cerealMashTemp, grainTempF, mr, 0); double newTemp = ((waterEquiv * currentTemp) + (cerealWaterEquiv * cerealTemp)) / (waterEquiv + cerealWaterEquiv); if (newTemp > targetTemp){ stp.startTemp = newTemp; } if (newTemp < targetTemp){ double addQts = ((waterEquiv * (targetTemp - currentTemp)) / (cerealTemp - targetTemp)) - 0.192; extraWaterQTS = addQts - waterAddedQTS; addStr = " Add " + SBStringUtils.format(Quantity.convertUnit("qt", volUnits, extraWaterQTS), 1) + " " + volUnits + " water to the cereal mash."; } // Calculate final temp of cereal mash // cerealTemp = (targetTemp * (waterEquiv + cerealWaterEquiv) - (waterEquiv * currentTemp)) / cerealWaterEquiv; totalMashTime += stp.minutes; mashWaterQTS += waterAddedQTS + extraWaterQTS; stp.vol.setUnits("qt"); stp.vol.setAmount(waterAddedQTS); stp.temp = strikeTemp; // make directions String weightStr = SBStringUtils.format(Quantity.convertUnit("lb", myRecipe.getMaltUnits(), stp.weightLbs), 1) + " " + myRecipe.getMaltUnits(); String volStr = SBStringUtils.format(Quantity.convertUnit("qt", volUnits, waterAddedQTS), 1) + " " + volUnits; if (tempUnits == "C"){ strikeTemp = fToC(strikeTemp); cerealTemp = fToC(cerealTemp); targetTemp = fToC(targetTemp); cerealTargTemp = fToC(cerealTargTemp); } String tempStr = SBStringUtils.format(strikeTemp, 1) + tempUnits; String tempStr2 = SBStringUtils.format(cerealTemp, 1) + tempUnits; String tempStr3 = SBStringUtils.format(targetTemp, 1) + tempUnits; String tempStr4 = SBStringUtils.format(cerealTargTemp, 1) + tempUnits; stp.directions = "Cereal mash: mash " + weightStr + " grain with " + volStr + " water at " + tempStr + " to hit " + tempStr4 + " and rest."; stp.directions += addStr; stp.directions += " Raise to " + tempStr2 + " and add to the main mash to reach " + tempStr3; // add cereal mash to total weight totalWeightLbs += stp.weightLbs; } if (stp.type.equals("sparge")) numSparge++; else { totalMashTime += stp.minutes; } // set target temp to end temp for next step targetTemp = stp.endTemp; } // for steps.size() waterEquiv += waterAddedQTS; // add previous addition to get WE totalTime = totalMashTime; volQts = mashVolQTS; // water use stats: absorbedQTS = totalWeightLbs * 0.55; // figure from HBD // spargeTotalQTS = (myRecipe.getPreBoilVol("qt")) - (mashWaterQTS - absorbedQTS); totalWaterQTS = mashWaterQTS; spargeQTS = myRecipe.getPreBoilVol("qt") - (mashWaterQTS - absorbedQTS); // Now let's figure out the sparging: if (numSparge == 0) return; double col = myRecipe.getPreBoilVol("qt") / numSparge; double charge[] = new double[numSparge]; double collect[] = new double[numSparge]; double totalCollectQts = myRecipe.getPreBoilVol("qt"); if (col < mashWaterQTS - absorbedQTS) { charge[0] = 0; collect[0] = mashWaterQTS - absorbedQTS; totalCollectQts = totalCollectQts - collect[0]; } else { charge[0] = col - (mashWaterQTS - absorbedQTS); collect[0] = col; totalCollectQts = totalCollectQts - collect[0]; } // do we need any more steps? if (numSparge > 1) { col = totalCollectQts / (numSparge - 1); for (int i = 1; i < numSparge; i++) { charge[i] = col; collect[i] = col; } } int j=0; for (int i = 1; i < steps.size(); i++) { stp = ((MashStep) steps.get(i)); if (stp.getType().equals("sparge")){ stp.vol.setUnits("qt"); stp.vol.setAmount(collect[j]); stp.temp = SPARGETMPF; totalSpargeTime += stp.getMinutes(); String collectStr = SBStringUtils.format(Quantity.convertUnit("qt", volUnits, collect[j]), 1) + " " + volUnits; String tempStr; if (tempUnits.equals("F")){ tempStr = "" + SBStringUtils.format(SPARGETMPF, 1) + "F"; } else { tempStr = SBStringUtils.format(fToC(SPARGETMPF), 1) + "C"; } if (numSparge > 1){ stp.setMethod("batch"); String add = SBStringUtils.format(Quantity.convertUnit("qt", volUnits, charge[j]), 1) + " " + volUnits; stp.setDirections("Add " + add + " at " + tempStr + " to collect " + collectStr); } else { stp.vol.setUnits("qt"); stp.vol.setAmount(spargeQTS); stp.setMethod("fly"); stp.setDirections("Sparge with " + SBStringUtils.format(Quantity.convertUnit("qt", volUnits, spargeQTS), 1) + " " + volUnits + " at " + tempStr + " to collect " + collectStr); } j++; } } }
public void calcMashSchedule() { // Method to run through the mash table and calculate values if (!myRecipe.allowRecalcs) return; double strikeTemp = 0; double targetTemp = 0; double waterAddedQTS = 0; double waterEquiv = 0; double mr = mashRatio; double currentTemp = grainTempF; double displTemp = 0; double tunLoss; // figure out a better way to do this, eg: themal mass double decoct = 0; int totalMashTime = 0; int totalSpargeTime = 0; double mashWaterQTS = 0; double mashVolQTS = 0; int numSparge = 0; double totalWeightLbs = 0; double totalCerealLbs = 0; maltWeightLbs = myRecipe.getTotalMashLbs(); // convert mash ratio to qts/lb if in l/kg if (mashRatioU.equalsIgnoreCase("l/kg")) { mr *= 0.479325; } // convert CurrentTemp to F if (tempUnits == "C") { currentTemp = cToF(currentTemp); tunLoss = tunLossF * 1.8; } else tunLoss = tunLossF; // perform calcs on first record if (steps.isEmpty()) return; // sort the list Collections.sort(steps, new stepComparator()); // add up the cereal mash lbs for (int i=0; i<steps.size(); i++){ MashStep stp = ((MashStep) steps.get(i)); if (stp.method.equals("cereal mash")){ totalCerealLbs += stp.weightLbs; } } totalWeightLbs = maltWeightLbs - totalCerealLbs; // the first step is always an infusion MashStep stp = ((MashStep) steps.get(0)); targetTemp = stp.startTemp; strikeTemp = calcStrikeTemp(targetTemp, currentTemp, mr, tunLoss); waterAddedQTS = mr * totalWeightLbs; waterEquiv = totalWeightLbs * (0.192 + mr); mashVolQTS = calcMashVol(totalWeightLbs, mr); totalMashTime += stp.minutes; mashWaterQTS += waterAddedQTS; stp.vol.setUnits("qt"); stp.vol.setAmount(waterAddedQTS); stp.temp = strikeTemp; stp.method = "infusion"; stp.weightLbs = totalWeightLbs; // subtract the water added from the Water Equiv so that they are correct when added in the next part of the loop waterEquiv -= waterAddedQTS; // Updated the water added if (tempUnits == "C") strikeTemp = fToC(strikeTemp); stp.directions = "Mash in with " + SBStringUtils.format(stp.vol.getValueAs(volUnits),1 ) + " " + volUnits + " of water at " + SBStringUtils.format(strikeTemp, 1) + " " + tempUnits; // set TargetTemp to the end temp targetTemp = stp.endTemp; for (int i = 1; i < steps.size(); i++) { stp = ((MashStep) steps.get(i)); currentTemp = targetTemp; // switch targetTemp = stp.startTemp; // if this is a former sparge step that's been changed, change // the method to infusion if (!stp.type.equals("sparge") && ( stp.method.equals("fly") || stp.method.equals("batch"))) stp.method = "infusion"; // do calcs if (stp.method.equals("infusion")) { // calculate an infusion step decoct = 0; waterEquiv += waterAddedQTS; // add previous addition to get WE strikeTemp = boilTempF; // boiling water // Updated the water added waterAddedQTS = calcWaterAddition(targetTemp, currentTemp, waterEquiv, boilTempF); stp.vol.setUnits("qt"); stp.vol.setAmount(waterAddedQTS); stp.temp = strikeTemp; stp.weightLbs = totalWeightLbs; if (tempUnits == "C") strikeTemp = 100; stp.directions = "Add " + SBStringUtils.format(stp.vol.getValueAs(volUnits), 1) + " " + volUnits + " of water at " + SBStringUtils.format(strikeTemp, 1) + " " + tempUnits; mashWaterQTS += waterAddedQTS; mashVolQTS += waterAddedQTS; } else if (stp.method.indexOf("decoction") > -1) { // calculate a decoction step waterEquiv += waterAddedQTS; // add previous addition to get WE waterAddedQTS = 0; strikeTemp = boilTempF; // boiling water double ratio=0.75; if (stp.method.indexOf("thick") > -1) ratio = thickDecoctRatio; else if (stp.method.indexOf("thin") > -1) ratio = thinDecoctRatio; // Calculate volume (qts) of mash to remove decoct = calcDecoction2(targetTemp, currentTemp, mashWaterQTS, ratio, totalWeightLbs); stp.vol.setUnits("qt"); stp.vol.setAmount(decoct); stp.temp = boilTempF; stp.weightLbs = totalWeightLbs; // Updated the decoction, convert to right units & make directions stp.directions = "Remove " + SBStringUtils.format(stp.vol.getValueAs(volUnits), 1) + " " + volUnits + " of mash, boil, and return to mash."; } else if (stp.method.equals("direct")) { // calculate a direct heat step decoct = 0; waterEquiv += waterAddedQTS; // add previous addition to get WE waterAddedQTS = 0; displTemp = stp.startTemp; if (tempUnits.equals("C")) displTemp = BrewCalcs.fToC(displTemp); stp.directions = "Add direct heat until mash reaches " + displTemp + " " + tempUnits + "."; stp.vol.setAmount(0); stp.temp = 0; stp.weightLbs = totalWeightLbs; } else if (stp.method.indexOf("cereal mash") > -1) { // calculate a cereal mash step waterEquiv += waterAddedQTS; // add previous addition to get WE waterAddedQTS = 0; targetTemp = stp.startTemp; double extraWaterQTS = 0; double cerealTemp = boilTempF; double cerealTargTemp = cerealMashTemp; String addStr = ""; /* * 1. check the temp of the mash when you add the boiling cereal mash @ default ratio back * 2. if it's > than the step temp, adjust the step temp * 3. if it's < than the step temp, add extra water to increase the "heat equivalencey" of the cereal mash */ double cerealWaterEquiv = stp.weightLbs * (0.192 + mr); waterAddedQTS = mr * stp.weightLbs; strikeTemp = calcStrikeTemp(cerealMashTemp, grainTempF, mr, 0); double newTemp = ((waterEquiv * currentTemp) + (cerealWaterEquiv * cerealTemp)) / (waterEquiv + cerealWaterEquiv); if (newTemp > targetTemp){ stp.startTemp = newTemp; } if (newTemp < targetTemp){ double addQts = ((waterEquiv * (targetTemp - currentTemp)) / (cerealTemp - targetTemp)) - 0.192; extraWaterQTS = addQts - waterAddedQTS; addStr = " Add " + SBStringUtils.format(Quantity.convertUnit("qt", volUnits, extraWaterQTS), 1) + " " + volUnits + " water to the cereal mash."; } // Calculate final temp of cereal mash // cerealTemp = (targetTemp * (waterEquiv + cerealWaterEquiv) - (waterEquiv * currentTemp)) / cerealWaterEquiv; totalMashTime += stp.minutes; mashWaterQTS += waterAddedQTS + extraWaterQTS; stp.vol.setUnits("qt"); stp.vol.setAmount(waterAddedQTS); stp.temp = strikeTemp; // make directions String weightStr = SBStringUtils.format(Quantity.convertUnit("lb", myRecipe.getMaltUnits(), stp.weightLbs), 1) + " " + myRecipe.getMaltUnits(); String volStr = SBStringUtils.format(Quantity.convertUnit("qt", volUnits, waterAddedQTS), 1) + " " + volUnits; if (tempUnits == "C"){ strikeTemp = fToC(strikeTemp); cerealTemp = fToC(cerealTemp); targetTemp = fToC(targetTemp); cerealTargTemp = fToC(cerealTargTemp); } String tempStr = SBStringUtils.format(strikeTemp, 1) + tempUnits; String tempStr2 = SBStringUtils.format(cerealTemp, 1) + tempUnits; String tempStr3 = SBStringUtils.format(targetTemp, 1) + tempUnits; String tempStr4 = SBStringUtils.format(cerealTargTemp, 1) + tempUnits; stp.directions = "Cereal mash: mash " + weightStr + " grain with " + volStr + " water at " + tempStr + " to hit " + tempStr4 + " and rest."; stp.directions += addStr; stp.directions += " Raise to " + tempStr2 + " and add to the main mash to reach " + tempStr3; // add cereal mash to total weight totalWeightLbs += stp.weightLbs; } if (stp.type.equals("sparge")) numSparge++; else { totalMashTime += stp.minutes; } // set target temp to end temp for next step targetTemp = stp.endTemp; } // for steps.size() waterEquiv += waterAddedQTS; // add previous addition to get WE totalTime = totalMashTime; volQts = mashVolQTS; // water use stats: absorbedQTS = totalWeightLbs * 0.55; // figure from HBD // spargeTotalQTS = (myRecipe.getPreBoilVol("qt")) - (mashWaterQTS - absorbedQTS); totalWaterQTS = mashWaterQTS; spargeQTS = myRecipe.getPreBoilVol("qt") - (mashWaterQTS - absorbedQTS); // Now let's figure out the sparging: if (numSparge == 0) return; double col = myRecipe.getPreBoilVol("qt") / numSparge; double charge[] = new double[numSparge]; double collect[] = new double[numSparge]; double totalCollectQts = myRecipe.getPreBoilVol("qt"); if (col < mashWaterQTS - absorbedQTS) { charge[0] = 0; collect[0] = mashWaterQTS - absorbedQTS; totalCollectQts = totalCollectQts - collect[0]; } else { charge[0] = col - (mashWaterQTS - absorbedQTS); collect[0] = col; totalCollectQts = totalCollectQts - collect[0]; } // do we need any more steps? if (numSparge > 1) { col = totalCollectQts / (numSparge - 1); for (int i = 1; i < numSparge; i++) { charge[i] = col; collect[i] = col; } } int j=0; for (int i = 1; i < steps.size(); i++) { stp = ((MashStep) steps.get(i)); if (stp.getType().equals("sparge")){ stp.vol.setUnits("qt"); stp.vol.setAmount(collect[j]); stp.temp = SPARGETMPF; totalSpargeTime += stp.getMinutes(); String collectStr = SBStringUtils.format(Quantity.convertUnit("qt", volUnits, collect[j]), 1) + " " + volUnits; String tempStr; if (tempUnits.equals("F")){ tempStr = "" + SBStringUtils.format(SPARGETMPF, 1) + "F"; } else { tempStr = SBStringUtils.format(fToC(SPARGETMPF), 1) + "C"; } if (numSparge > 1){ stp.setMethod("batch"); String add = SBStringUtils.format(Quantity.convertUnit("qt", volUnits, charge[j]), 1) + " " + volUnits; stp.setDirections("Add " + add + " at " + tempStr + " to collect " + collectStr); } else { stp.vol.setUnits("qt"); stp.vol.setAmount(spargeQTS); stp.setMethod("fly"); stp.setDirections("Sparge with " + SBStringUtils.format(Quantity.convertUnit("qt", volUnits, spargeQTS), 1) + " " + volUnits + " at " + tempStr + " to collect " + collectStr); } j++; } } }
1,115,253
public void calcMashSchedule() { // Method to run through the mash table and calculate values if (!myRecipe.allowRecalcs) return; double strikeTemp = 0; double targetTemp = 0; double waterAddedQTS = 0; double waterEquiv = 0; double mr = mashRatio; double currentTemp = grainTempF; double displTemp = 0; double tunLoss; // figure out a better way to do this, eg: themal mass double decoct = 0; int totalMashTime = 0; int totalSpargeTime = 0; double mashWaterQTS = 0; double mashVolQTS = 0; int numSparge = 0; double totalWeightLbs = 0; double totalCerealLbs = 0; maltWeightLbs = myRecipe.getTotalMashLbs(); // convert mash ratio to qts/lb if in l/kg if (mashRatioU.equalsIgnoreCase("l/kg")) { mr *= 0.479325; } // convert CurrentTemp to F if (tempUnits == "C") { currentTemp = cToF(currentTemp); tunLoss = tunLossF * 1.8; } else tunLoss = tunLossF; // perform calcs on first record if (steps.isEmpty()) return; // sort the list Collections.sort(steps, new stepComparator()); // add up the cereal mash lbs for (int i=0; i<steps.size(); i++){ MashStep stp = ((MashStep) steps.get(i)); if (stp.method.equals("cereal mash")){ totalCerealLbs += stp.weightLbs; } } totalWeightLbs = maltWeightLbs - totalCerealLbs; // the first step is always an infusion MashStep stp = ((MashStep) steps.get(0)); targetTemp = stp.startTemp; strikeTemp = calcStrikeTemp(targetTemp, currentTemp, mr, tunLoss); waterAddedQTS = mr * totalWeightLbs; waterEquiv = totalWeightLbs * (0.192 + mr); mashVolQTS = calcMashVol(totalWeightLbs, mr); totalMashTime += stp.minutes; mashWaterQTS += waterAddedQTS; stp.vol.setUnits("qt"); stp.vol.setAmount(waterAddedQTS); stp.temp = strikeTemp; stp.method = "infusion"; stp.weightLbs = totalWeightLbs; // subtract the water added from the Water Equiv so that they are correct when added in the next part of the loop waterEquiv -= waterAddedQTS; // Updated the water added if (tempUnits == "C") strikeTemp = fToC(strikeTemp); stp.directions = "Mash in with " + SBStringUtils.format(stp.vol.getValueAs(volUnits),1 ) + " " + volUnits + " of water at " + SBStringUtils.format(strikeTemp, 1) + " " + tempUnits; // set TargetTemp to the end temp targetTemp = stp.endTemp; for (int i = 1; i < steps.size(); i++) { stp = ((MashStep) steps.get(i)); currentTemp = targetTemp; // switch targetTemp = stp.startTemp; // if this is a former sparge step that's been changed, change // the method to infusion if (!stp.type.equals("sparge") && ( stp.method.equals("fly") || stp.method.equals("batch"))) stp.method = "infusion"; // do calcs if (stp.method.equals("infusion")) { // calculate an infusion step decoct = 0; waterEquiv += waterAddedQTS; // add previous addition to get WE strikeTemp = boilTempF; // boiling water // Updated the water added waterAddedQTS = calcWaterAddition(targetTemp, currentTemp, waterEquiv, boilTempF); stp.vol.setUnits("qt"); stp.vol.setAmount(waterAddedQTS); stp.temp = strikeTemp; stp.weightLbs = totalWeightLbs; if (tempUnits == "C") strikeTemp = 100; stp.directions = "Add " + SBStringUtils.format(stp.vol.getValueAs(volUnits), 1) + " " + volUnits + " of water at " + SBStringUtils.format(strikeTemp, 1) + " " + tempUnits; mashWaterQTS += waterAddedQTS; mashVolQTS += waterAddedQTS; } else if (stp.method.indexOf("decoction") > -1) { // calculate a decoction step waterEquiv += waterAddedQTS; // add previous addition to get WE waterAddedQTS = 0; strikeTemp = boilTempF; // boiling water double ratio=0.75; if (stp.method.indexOf("thick") > -1) ratio = thickDecoctRatio; else if (stp.method.indexOf("thin") > -1) ratio = thinDecoctRatio; // Calculate volume (qts) of mash to remove decoct = calcDecoction2(targetTemp, currentTemp, mashWaterQTS, ratio, totalWeightLbs); stp.vol.setUnits("qt"); stp.vol.setAmount(decoct); stp.temp = boilTempF; stp.weightLbs = totalWeightLbs; // Updated the decoction, convert to right units & make directions stp.directions = "Remove " + SBStringUtils.format(stp.vol.getValueAs(volUnits), 1) + " " + volUnits + " of mash, boil, and return to mash."; } else if (stp.method.equals("direct")) { // calculate a direct heat step decoct = 0; waterEquiv += waterAddedQTS; // add previous addition to get WE waterAddedQTS = 0; displTemp = stp.startTemp; if (tempUnits.equals("C")) displTemp = fToC(displTemp); stp.directions = "Add direct heat until mash reaches " + displTemp + " " + tempUnits + "."; stp.vol.setAmount(0); stp.temp = 0; stp.weightLbs = totalWeightLbs; } else if (stp.method.indexOf("cereal mash") > -1) { // calculate a cereal mash step waterEquiv += waterAddedQTS; // add previous addition to get WE waterAddedQTS = 0; targetTemp = stp.startTemp; double extraWaterQTS = 0; double cerealTemp = boilTempF; double cerealTargTemp = cerealMashTemp; String addStr = ""; /* * 1. check the temp of the mash when you add the boiling cereal mash @ default ratio back * 2. if it's > than the step temp, adjust the step temp * 3. if it's < than the step temp, add extra water to increase the "heat equivalencey" of the cereal mash */ double cerealWaterEquiv = stp.weightLbs * (0.192 + mr); waterAddedQTS = mr * stp.weightLbs; strikeTemp = calcStrikeTemp(cerealMashTemp, grainTempF, mr, 0); double newTemp = ((waterEquiv * currentTemp) + (cerealWaterEquiv * cerealTemp)) / (waterEquiv + cerealWaterEquiv); if (newTemp > targetTemp){ stp.startTemp = newTemp; } if (newTemp < targetTemp){ double addQts = ((waterEquiv * (targetTemp - currentTemp)) / (cerealTemp - targetTemp)) - 0.192; extraWaterQTS = addQts - waterAddedQTS; addStr = " Add " + SBStringUtils.format(Quantity.convertUnit("qt", volUnits, extraWaterQTS), 1) + " " + volUnits + " water to the cereal mash."; } // Calculate final temp of cereal mash // cerealTemp = (targetTemp * (waterEquiv + cerealWaterEquiv) - (waterEquiv * currentTemp)) / cerealWaterEquiv; totalMashTime += stp.minutes; mashWaterQTS += waterAddedQTS + extraWaterQTS; stp.vol.setUnits("qt"); stp.vol.setAmount(waterAddedQTS); stp.temp = strikeTemp; // make directions String weightStr = SBStringUtils.format(Quantity.convertUnit("lb", myRecipe.getMaltUnits(), stp.weightLbs), 1) + " " + myRecipe.getMaltUnits(); String volStr = SBStringUtils.format(Quantity.convertUnit("qt", volUnits, waterAddedQTS), 1) + " " + volUnits; if (tempUnits == "C"){ strikeTemp = fToC(strikeTemp); cerealTemp = fToC(cerealTemp); targetTemp = fToC(targetTemp); cerealTargTemp = fToC(cerealTargTemp); } String tempStr = SBStringUtils.format(strikeTemp, 1) + tempUnits; String tempStr2 = SBStringUtils.format(cerealTemp, 1) + tempUnits; String tempStr3 = SBStringUtils.format(targetTemp, 1) + tempUnits; String tempStr4 = SBStringUtils.format(cerealTargTemp, 1) + tempUnits; stp.directions = "Cereal mash: mash " + weightStr + " grain with " + volStr + " water at " + tempStr + " to hit " + tempStr4 + " and rest."; stp.directions += addStr; stp.directions += " Raise to " + tempStr2 + " and add to the main mash to reach " + tempStr3; // add cereal mash to total weight totalWeightLbs += stp.weightLbs; } if (stp.type.equals("sparge")) numSparge++; else { totalMashTime += stp.minutes; } // set target temp to end temp for next step targetTemp = stp.endTemp; } // for steps.size() waterEquiv += waterAddedQTS; // add previous addition to get WE totalTime = totalMashTime; volQts = mashVolQTS; // water use stats: absorbedQTS = totalWeightLbs * 0.55; // figure from HBD // spargeTotalQTS = (myRecipe.getPreBoilVol("qt")) - (mashWaterQTS - absorbedQTS); totalWaterQTS = mashWaterQTS; spargeQTS = myRecipe.getPreBoilVol("qt") - (mashWaterQTS - absorbedQTS); // Now let's figure out the sparging: if (numSparge == 0) return; double col = myRecipe.getPreBoilVol("qt") / numSparge; double charge[] = new double[numSparge]; double collect[] = new double[numSparge]; double totalCollectQts = myRecipe.getPreBoilVol("qt"); if (col < mashWaterQTS - absorbedQTS) { charge[0] = 0; collect[0] = mashWaterQTS - absorbedQTS; totalCollectQts = totalCollectQts - collect[0]; } else { charge[0] = col - (mashWaterQTS - absorbedQTS); collect[0] = col; totalCollectQts = totalCollectQts - collect[0]; } // do we need any more steps? if (numSparge > 1) { col = totalCollectQts / (numSparge - 1); for (int i = 1; i < numSparge; i++) { charge[i] = col; collect[i] = col; } } int j=0; for (int i = 1; i < steps.size(); i++) { stp = ((MashStep) steps.get(i)); if (stp.getType().equals("sparge")){ stp.vol.setUnits("qt"); stp.vol.setAmount(collect[j]); stp.temp = SPARGETMPF; totalSpargeTime += stp.getMinutes(); String collectStr = SBStringUtils.format(Quantity.convertUnit("qt", volUnits, collect[j]), 1) + " " + volUnits; String tempStr; if (tempUnits.equals("F")){ tempStr = "" + SBStringUtils.format(SPARGETMPF, 1) + "F"; } else { tempStr = SBStringUtils.format(fToC(SPARGETMPF), 1) + "C"; } if (numSparge > 1){ stp.setMethod("batch"); String add = SBStringUtils.format(Quantity.convertUnit("qt", volUnits, charge[j]), 1) + " " + volUnits; stp.setDirections("Add " + add + " at " + tempStr + " to collect " + collectStr); } else { stp.vol.setUnits("qt"); stp.vol.setAmount(spargeQTS); stp.setMethod("fly"); stp.setDirections("Sparge with " + SBStringUtils.format(Quantity.convertUnit("qt", volUnits, spargeQTS), 1) + " " + volUnits + " at " + tempStr + " to collect " + collectStr); } j++; } } }
public void calcMashSchedule() { // Method to run through the mash table and calculate values if (!myRecipe.allowRecalcs) return; double strikeTemp = 0; double targetTemp = 0; double waterAddedQTS = 0; double waterEquiv = 0; double mr = mashRatio; double currentTemp = grainTempF; double displTemp = 0; double tunLoss; // figure out a better way to do this, eg: themal mass double decoct = 0; int totalMashTime = 0; int totalSpargeTime = 0; double mashWaterQTS = 0; double mashVolQTS = 0; int numSparge = 0; double totalWeightLbs = 0; double totalCerealLbs = 0; maltWeightLbs = myRecipe.getTotalMashLbs(); // convert mash ratio to qts/lb if in l/kg if (mashRatioU.equalsIgnoreCase("l/kg")) { mr *= 0.479325; } // convert CurrentTemp to F if (tempUnits == "C") { currentTemp = cToF(currentTemp); tunLoss = tunLossF * 1.8; } else tunLoss = tunLossF; // perform calcs on first record if (steps.isEmpty()) return; // sort the list Collections.sort(steps, new stepComparator()); // add up the cereal mash lbs for (int i=0; i<steps.size(); i++){ MashStep stp = ((MashStep) steps.get(i)); if (stp.method.equals("cereal mash")){ totalCerealLbs += stp.weightLbs; } } totalWeightLbs = maltWeightLbs - totalCerealLbs; // the first step is always an infusion MashStep stp = ((MashStep) steps.get(0)); targetTemp = stp.startTemp; strikeTemp = calcStrikeTemp(targetTemp, currentTemp, mr, tunLoss); waterAddedQTS = mr * totalWeightLbs; waterEquiv = totalWeightLbs * (0.192 + mr); mashVolQTS = calcMashVol(totalWeightLbs, mr); totalMashTime += stp.minutes; mashWaterQTS += waterAddedQTS; stp.vol.setUnits("qt"); stp.vol.setAmount(waterAddedQTS); stp.temp = strikeTemp; stp.method = "infusion"; stp.weightLbs = totalWeightLbs; // subtract the water added from the Water Equiv so that they are correct when added in the next part of the loop waterEquiv -= waterAddedQTS; // Updated the water added if (tempUnits == "C") strikeTemp = fToC(strikeTemp); stp.directions = "Mash in with " + SBStringUtils.format(stp.vol.getValueAs(volUnits),1 ) + " " + volUnits + " of water at " + SBStringUtils.format(strikeTemp, 1) + " " + tempUnits; // set TargetTemp to the end temp targetTemp = stp.endTemp; for (int i = 1; i < steps.size(); i++) { stp = ((MashStep) steps.get(i)); currentTemp = targetTemp; // switch targetTemp = stp.startTemp; // if this is a former sparge step that's been changed, change // the method to infusion if (!stp.type.equals("sparge") && ( stp.method.equals("fly") || stp.method.equals("batch"))) stp.method = "infusion"; // do calcs if (stp.method.equals("infusion")) { // calculate an infusion step decoct = 0; waterEquiv += waterAddedQTS; // add previous addition to get WE strikeTemp = boilTempF; // boiling water // Updated the water added waterAddedQTS = calcWaterAddition(targetTemp, currentTemp, waterEquiv, boilTempF); stp.vol.setUnits("qt"); stp.vol.setAmount(waterAddedQTS); stp.temp = strikeTemp; stp.weightLbs = totalWeightLbs; if (tempUnits == "C") strikeTemp = 100; stp.directions = "Add " + SBStringUtils.format(stp.vol.getValueAs(volUnits), 1) + " " + volUnits + " of water at " + SBStringUtils.format(strikeTemp, 1) + " " + tempUnits; mashWaterQTS += waterAddedQTS; mashVolQTS += waterAddedQTS; } else if (stp.method.indexOf("decoction") > -1) { // calculate a decoction step waterEquiv += waterAddedQTS; // add previous addition to get WE waterAddedQTS = 0; strikeTemp = boilTempF; // boiling water double ratio=0.75; if (stp.method.indexOf("thick") > -1) ratio = thickDecoctRatio; else if (stp.method.indexOf("thin") > -1) ratio = thinDecoctRatio; // Calculate volume (qts) of mash to remove decoct = calcDecoction2(targetTemp, currentTemp, mashWaterQTS, ratio, totalWeightLbs); stp.vol.setUnits("qt"); stp.vol.setAmount(decoct); stp.temp = boilTempF; stp.weightLbs = totalWeightLbs; // Updated the decoction, convert to right units & make directions stp.directions = "Remove " + SBStringUtils.format(stp.vol.getValueAs(volUnits), 1) + " " + volUnits + " of mash, boil, and return to mash."; } else if (stp.method.equals("direct")) { // calculate a direct heat step decoct = 0; waterEquiv += waterAddedQTS; // add previous addition to get WE waterAddedQTS = 0; displTemp = stp.startTemp; if (tempUnits.equals("C")) displTemp = fToC(displTemp); stp.directions = "Add direct heat until mash reaches " + displTemp + " " + tempUnits + "."; stp.vol.setAmount(0); stp.temp = 0; stp.weightLbs = totalWeightLbs; } else if (stp.method.indexOf("cereal mash") > -1) { // calculate a cereal mash step waterEquiv += waterAddedQTS; // add previous addition to get WE waterAddedQTS = 0; targetTemp = stp.startTemp; double extraWaterQTS = 0; double cerealTemp = boilTempF; double cerealTargTemp = cerealMashTemp; String addStr = ""; /* * 1. check the temp of the mash when you add the boiling cereal mash @ default ratio back * 2. if it's > than the step temp, adjust the step temp * 3. if it's < than the step temp, add extra water to increase the "heat equivalencey" of the cereal mash */ double cerealWaterEquiv = stp.weightLbs * (0.192 + mr); waterAddedQTS = mr * stp.weightLbs; strikeTemp = calcStrikeTemp(cerealMashTemp, grainTempF, mr, 0); double newTemp = ((waterEquiv * currentTemp) + (cerealWaterEquiv * cerealTemp)) / (waterEquiv + cerealWaterEquiv); if (newTemp > targetTemp){ stp.startTemp = newTemp; } if (newTemp < targetTemp){ double addQts = ((waterEquiv * (targetTemp - currentTemp)) / (cerealTemp - targetTemp)) - 0.192; extraWaterQTS = addQts - waterAddedQTS; addStr = " Add " + SBStringUtils.format(Quantity.convertUnit("qt", volUnits, extraWaterQTS), 1) + " " + volUnits + " water to the cereal mash."; } // Calculate final temp of cereal mash // cerealTemp = (targetTemp * (waterEquiv + cerealWaterEquiv) - (waterEquiv * currentTemp)) / cerealWaterEquiv; totalMashTime += stp.minutes; mashWaterQTS += waterAddedQTS + extraWaterQTS; stp.vol.setUnits("qt"); stp.vol.setAmount(waterAddedQTS); stp.temp = strikeTemp; // make directions String weightStr = SBStringUtils.format(Quantity.convertUnit("lb", myRecipe.getMaltUnits(), stp.weightLbs), 1) + " " + myRecipe.getMaltUnits(); String volStr = SBStringUtils.format(Quantity.convertUnit("qt", volUnits, waterAddedQTS), 1) + " " + volUnits; if (tempUnits == "C"){ strikeTemp = fToC(strikeTemp); cerealTemp = fToC(cerealTemp); targetTemp = fToC(targetTemp); cerealTargTemp = fToC(cerealTargTemp); } String tempStr = SBStringUtils.format(strikeTemp, 1) + tempUnits; String tempStr2 = SBStringUtils.format(cerealTemp, 1) + tempUnits; String tempStr3 = SBStringUtils.format(targetTemp, 1) + tempUnits; String tempStr4 = SBStringUtils.format(cerealTargTemp, 1) + tempUnits; stp.directions = "Cereal mash: mash " + weightStr + " grain with " + volStr + " water at " + tempStr + " to hit " + tempStr4 + " and rest."; stp.directions += addStr; stp.directions += " Raise to " + tempStr2 + " and add to the main mash to reach " + tempStr3; // add cereal mash to total weight totalWeightLbs += stp.weightLbs; } if (stp.type.equals("sparge")) numSparge++; else { totalMashTime += stp.minutes; } // set target temp to end temp for next step targetTemp = stp.endTemp; } // for steps.size() waterEquiv += waterAddedQTS; // add previous addition to get WE totalTime = totalMashTime; volQts = mashVolQTS; // water use stats: absorbedQTS = totalWeightLbs * 0.55; // figure from HBD // spargeTotalQTS = (myRecipe.getPreBoilVol("qt")) - (mashWaterQTS - absorbedQTS); totalWaterQTS = mashWaterQTS; spargeQTS = myRecipe.getPreBoilVol("qt") - (mashWaterQTS - absorbedQTS); // Now let's figure out the sparging: if (numSparge == 0) return; double col = myRecipe.getPreBoilVol("qt") / numSparge; double charge[] = new double[numSparge]; double collect[] = new double[numSparge]; double totalCollectQts = myRecipe.getPreBoilVol("qt"); if (col < mashWaterQTS - absorbedQTS) { charge[0] = 0; collect[0] = mashWaterQTS - absorbedQTS; totalCollectQts = totalCollectQts - collect[0]; } else { charge[0] = col - (mashWaterQTS - absorbedQTS); collect[0] = col; totalCollectQts = totalCollectQts - collect[0]; } // do we need any more steps? if (numSparge > 1) { col = totalCollectQts / (numSparge - 1); for (int i = 1; i < numSparge; i++) { charge[i] = col; collect[i] = col; } } int j=0; for (int i = 1; i < steps.size(); i++) { stp = ((MashStep) steps.get(i)); if (stp.getType().equals("sparge")){ stp.vol.setUnits("qt"); stp.vol.setAmount(collect[j]); stp.temp = SPARGETMPF; totalSpargeTime += stp.getMinutes(); String collectStr = SBStringUtils.format(Quantity.convertUnit("qt", volUnits, collect[j]), 1) + " " + volUnits; String tempStr; if (tempUnits.equals("F")){ tempStr = "" + SBStringUtils.format(SPARGETMPF, 1) + "F"; } else { tempStr = SBStringUtils.format(fToC(SPARGETMPF), 1) + "C"; } if (numSparge > 1){ stp.setMethod("batch"); String add = SBStringUtils.format(Quantity.convertUnit("qt", volUnits, charge[j]), 1) + " " + volUnits; stp.setDirections("Add " + add + " at " + tempStr + " to collect " + collectStr); } else { stp.vol.setUnits("qt"); stp.vol.setAmount(spargeQTS); stp.setMethod("fly"); stp.setDirections("Sparge with " + SBStringUtils.format(Quantity.convertUnit("qt", volUnits, spargeQTS), 1) + " " + volUnits + " at " + tempStr + " to collect " + collectStr); } j++; } } }
1,115,254
public void calcMashSchedule() { // Method to run through the mash table and calculate values if (!myRecipe.allowRecalcs) return; double strikeTemp = 0; double targetTemp = 0; double waterAddedQTS = 0; double waterEquiv = 0; double mr = mashRatio; double currentTemp = grainTempF; double displTemp = 0; double tunLoss; // figure out a better way to do this, eg: themal mass double decoct = 0; int totalMashTime = 0; int totalSpargeTime = 0; double mashWaterQTS = 0; double mashVolQTS = 0; int numSparge = 0; double totalWeightLbs = 0; double totalCerealLbs = 0; maltWeightLbs = myRecipe.getTotalMashLbs(); // convert mash ratio to qts/lb if in l/kg if (mashRatioU.equalsIgnoreCase("l/kg")) { mr *= 0.479325; } // convert CurrentTemp to F if (tempUnits == "C") { currentTemp = cToF(currentTemp); tunLoss = tunLossF * 1.8; } else tunLoss = tunLossF; // perform calcs on first record if (steps.isEmpty()) return; // sort the list Collections.sort(steps, new stepComparator()); // add up the cereal mash lbs for (int i=0; i<steps.size(); i++){ MashStep stp = ((MashStep) steps.get(i)); if (stp.method.equals("cereal mash")){ totalCerealLbs += stp.weightLbs; } } totalWeightLbs = maltWeightLbs - totalCerealLbs; // the first step is always an infusion MashStep stp = ((MashStep) steps.get(0)); targetTemp = stp.startTemp; strikeTemp = calcStrikeTemp(targetTemp, currentTemp, mr, tunLoss); waterAddedQTS = mr * totalWeightLbs; waterEquiv = totalWeightLbs * (0.192 + mr); mashVolQTS = calcMashVol(totalWeightLbs, mr); totalMashTime += stp.minutes; mashWaterQTS += waterAddedQTS; stp.vol.setUnits("qt"); stp.vol.setAmount(waterAddedQTS); stp.temp = strikeTemp; stp.method = "infusion"; stp.weightLbs = totalWeightLbs; // subtract the water added from the Water Equiv so that they are correct when added in the next part of the loop waterEquiv -= waterAddedQTS; // Updated the water added if (tempUnits == "C") strikeTemp = fToC(strikeTemp); stp.directions = "Mash in with " + SBStringUtils.format(stp.vol.getValueAs(volUnits),1 ) + " " + volUnits + " of water at " + SBStringUtils.format(strikeTemp, 1) + " " + tempUnits; // set TargetTemp to the end temp targetTemp = stp.endTemp; for (int i = 1; i < steps.size(); i++) { stp = ((MashStep) steps.get(i)); currentTemp = targetTemp; // switch targetTemp = stp.startTemp; // if this is a former sparge step that's been changed, change // the method to infusion if (!stp.type.equals("sparge") && ( stp.method.equals("fly") || stp.method.equals("batch"))) stp.method = "infusion"; // do calcs if (stp.method.equals("infusion")) { // calculate an infusion step decoct = 0; waterEquiv += waterAddedQTS; // add previous addition to get WE strikeTemp = boilTempF; // boiling water // Updated the water added waterAddedQTS = calcWaterAddition(targetTemp, currentTemp, waterEquiv, boilTempF); stp.vol.setUnits("qt"); stp.vol.setAmount(waterAddedQTS); stp.temp = strikeTemp; stp.weightLbs = totalWeightLbs; if (tempUnits == "C") strikeTemp = 100; stp.directions = "Add " + SBStringUtils.format(stp.vol.getValueAs(volUnits), 1) + " " + volUnits + " of water at " + SBStringUtils.format(strikeTemp, 1) + " " + tempUnits; mashWaterQTS += waterAddedQTS; mashVolQTS += waterAddedQTS; } else if (stp.method.indexOf("decoction") > -1) { // calculate a decoction step waterEquiv += waterAddedQTS; // add previous addition to get WE waterAddedQTS = 0; strikeTemp = boilTempF; // boiling water double ratio=0.75; if (stp.method.indexOf("thick") > -1) ratio = thickDecoctRatio; else if (stp.method.indexOf("thin") > -1) ratio = thinDecoctRatio; // Calculate volume (qts) of mash to remove decoct = calcDecoction2(targetTemp, currentTemp, mashWaterQTS, ratio, totalWeightLbs); stp.vol.setUnits("qt"); stp.vol.setAmount(decoct); stp.temp = boilTempF; stp.weightLbs = totalWeightLbs; // Updated the decoction, convert to right units & make directions stp.directions = "Remove " + SBStringUtils.format(stp.vol.getValueAs(volUnits), 1) + " " + volUnits + " of mash, boil, and return to mash."; } else if (stp.method.equals("direct")) { // calculate a direct heat step decoct = 0; waterEquiv += waterAddedQTS; // add previous addition to get WE waterAddedQTS = 0; displTemp = stp.startTemp; if (tempUnits.equals("C")) displTemp = fToC(displTemp); stp.directions = "Add direct heat until mash reaches " + displTemp + " " + tempUnits + "."; stp.vol.setAmount(0); stp.temp = 0; stp.weightLbs = totalWeightLbs; } else if (stp.method.indexOf("cereal mash") > -1) { // calculate a cereal mash step waterEquiv += waterAddedQTS; // add previous addition to get WE waterAddedQTS = 0; targetTemp = stp.startTemp; double extraWaterQTS = 0; double cerealTemp = boilTempF; double cerealTargTemp = cerealMashTemp; String addStr = ""; /* * 1. check the temp of the mash when you add the boiling cereal mash @ default ratio back * 2. if it's > than the step temp, adjust the step temp * 3. if it's < than the step temp, add extra water to increase the "heat equivalencey" of the cereal mash */ double cerealWaterEquiv = stp.weightLbs * (0.192 + mr); waterAddedQTS = mr * stp.weightLbs; strikeTemp = calcStrikeTemp(cerealMashTemp, grainTempF, mr, 0); double newTemp = ((waterEquiv * currentTemp) + (cerealWaterEquiv * cerealTemp)) / (waterEquiv + cerealWaterEquiv); if (newTemp > targetTemp){ stp.startTemp = newTemp; } if (newTemp < targetTemp){ double addQts = ((waterEquiv * (targetTemp - currentTemp)) / (cerealTemp - targetTemp)) - 0.192; extraWaterQTS = addQts - waterAddedQTS; addStr = " Add " + SBStringUtils.format(Quantity.convertUnit("qt", volUnits, extraWaterQTS), 1) + " " + volUnits + " water to the cereal mash."; } // Calculate final temp of cereal mash // cerealTemp = (targetTemp * (waterEquiv + cerealWaterEquiv) - (waterEquiv * currentTemp)) / cerealWaterEquiv; totalMashTime += stp.minutes; mashWaterQTS += waterAddedQTS + extraWaterQTS; stp.vol.setUnits("qt"); stp.vol.setAmount(waterAddedQTS); stp.temp = strikeTemp; // make directions String weightStr = SBStringUtils.format(Quantity.convertUnit("lb", myRecipe.getMaltUnits(), stp.weightLbs), 1) + " " + myRecipe.getMaltUnits(); String volStr = SBStringUtils.format(Quantity.convertUnit("qt", volUnits, waterAddedQTS), 1) + " " + volUnits; if (tempUnits == "C"){ strikeTemp = fToC(strikeTemp); cerealTemp = fToC(cerealTemp); targetTemp = fToC(targetTemp); cerealTargTemp = fToC(cerealTargTemp); } String tempStr = SBStringUtils.format(strikeTemp, 1) + tempUnits; String tempStr2 = SBStringUtils.format(cerealTemp, 1) + tempUnits; String tempStr3 = SBStringUtils.format(targetTemp, 1) + tempUnits; String tempStr4 = SBStringUtils.format(cerealTargTemp, 1) + tempUnits; stp.directions = "Cereal mash: mash " + weightStr + " grain with " + volStr + " water at " + tempStr + " to hit " + tempStr4 + " and rest."; stp.directions += addStr; stp.directions += " Raise to " + tempStr2 + " and add to the main mash to reach " + tempStr3; // add cereal mash to total weight totalWeightLbs += stp.weightLbs; } if (stp.type.equals("sparge")) numSparge++; else { totalMashTime += stp.minutes; } // set target temp to end temp for next step targetTemp = stp.endTemp; } // for steps.size() waterEquiv += waterAddedQTS; // add previous addition to get WE totalTime = totalMashTime; volQts = mashVolQTS; // water use stats: absorbedQTS = totalWeightLbs * 0.55; // figure from HBD // spargeTotalQTS = (myRecipe.getPreBoilVol("qt")) - (mashWaterQTS - absorbedQTS); totalWaterQTS = mashWaterQTS; spargeQTS = myRecipe.getPreBoilVol("qt") - (mashWaterQTS - absorbedQTS); // Now let's figure out the sparging: if (numSparge == 0) return; double col = myRecipe.getPreBoilVol("qt") / numSparge; double charge[] = new double[numSparge]; double collect[] = new double[numSparge]; double totalCollectQts = myRecipe.getPreBoilVol("qt"); if (col < mashWaterQTS - absorbedQTS) { charge[0] = 0; collect[0] = mashWaterQTS - absorbedQTS; totalCollectQts = totalCollectQts - collect[0]; } else { charge[0] = col - (mashWaterQTS - absorbedQTS); collect[0] = col; totalCollectQts = totalCollectQts - collect[0]; } // do we need any more steps? if (numSparge > 1) { col = totalCollectQts / (numSparge - 1); for (int i = 1; i < numSparge; i++) { charge[i] = col; collect[i] = col; } } int j=0; for (int i = 1; i < steps.size(); i++) { stp = ((MashStep) steps.get(i)); if (stp.getType().equals("sparge")){ stp.vol.setUnits("qt"); stp.vol.setAmount(collect[j]); stp.temp = SPARGETMPF; totalSpargeTime += stp.getMinutes(); String collectStr = SBStringUtils.format(Quantity.convertUnit("qt", volUnits, collect[j]), 1) + " " + volUnits; String tempStr; if (tempUnits.equals("F")){ tempStr = "" + SBStringUtils.format(SPARGETMPF, 1) + "F"; } else { tempStr = SBStringUtils.format(fToC(SPARGETMPF), 1) + "C"; } if (numSparge > 1){ stp.setMethod("batch"); String add = SBStringUtils.format(Quantity.convertUnit("qt", volUnits, charge[j]), 1) + " " + volUnits; stp.setDirections("Add " + add + " at " + tempStr + " to collect " + collectStr); } else { stp.vol.setUnits("qt"); stp.vol.setAmount(spargeQTS); stp.setMethod("fly"); stp.setDirections("Sparge with " + SBStringUtils.format(Quantity.convertUnit("qt", volUnits, spargeQTS), 1) + " " + volUnits + " at " + tempStr + " to collect " + collectStr); } j++; } } }
public void calcMashSchedule() { // Method to run through the mash table and calculate values if (!myRecipe.allowRecalcs) return; double strikeTemp = 0; double targetTemp = 0; double waterAddedQTS = 0; double waterEquiv = 0; double mr = mashRatio; double currentTemp = grainTempF; double displTemp = 0; double tunLoss; // figure out a better way to do this, eg: themal mass double decoct = 0; int totalMashTime = 0; int totalSpargeTime = 0; double mashWaterQTS = 0; double mashVolQTS = 0; int numSparge = 0; double totalWeightLbs = 0; double totalCerealLbs = 0; maltWeightLbs = myRecipe.getTotalMashLbs(); // convert mash ratio to qts/lb if in l/kg if (mashRatioU.equalsIgnoreCase("l/kg")) { mr *= 0.479325; } // convert CurrentTemp to F if (tempUnits == "C") { currentTemp = cToF(currentTemp); tunLoss = tunLossF * 1.8; } else tunLoss = tunLossF; // perform calcs on first record if (steps.isEmpty()) return; // sort the list Collections.sort(steps, new stepComparator()); // add up the cereal mash lbs for (int i=0; i<steps.size(); i++){ MashStep stp = ((MashStep) steps.get(i)); if (stp.method.equals("cereal mash")){ totalCerealLbs += stp.weightLbs; } } totalWeightLbs = maltWeightLbs - totalCerealLbs; // the first step is always an infusion MashStep stp = ((MashStep) steps.get(0)); targetTemp = stp.startTemp; strikeTemp = calcStrikeTemp(targetTemp, currentTemp, mr, tunLoss); waterAddedQTS = mr * totalWeightLbs; waterEquiv = totalWeightLbs * (0.192 + mr); mashVolQTS = calcMashVol(totalWeightLbs, mr); totalMashTime += stp.minutes; mashWaterQTS += waterAddedQTS; stp.vol.setUnits("qt"); stp.vol.setAmount(waterAddedQTS); stp.temp = strikeTemp; stp.method = "infusion"; stp.weightLbs = totalWeightLbs; // subtract the water added from the Water Equiv so that they are correct when added in the next part of the loop waterEquiv -= waterAddedQTS; // Updated the water added if (tempUnits == "C") strikeTemp = fToC(strikeTemp); stp.directions = "Mash in with " + SBStringUtils.format(stp.vol.getValueAs(volUnits),1 ) + " " + volUnits + " of water at " + SBStringUtils.format(strikeTemp, 1) + " " + tempUnits; // set TargetTemp to the end temp targetTemp = stp.endTemp; for (int i = 1; i < steps.size(); i++) { stp = ((MashStep) steps.get(i)); currentTemp = targetTemp; // switch targetTemp = stp.startTemp; // if this is a former sparge step that's been changed, change // the method to infusion if (!stp.type.equals("sparge") && ( stp.method.equals("fly") || stp.method.equals("batch"))) stp.method = "infusion"; // do calcs if (stp.method.equals("infusion")) { // calculate an infusion step decoct = 0; waterEquiv += waterAddedQTS; // add previous addition to get WE strikeTemp = boilTempF; // boiling water // Updated the water added waterAddedQTS = calcWaterAddition(targetTemp, currentTemp, waterEquiv, boilTempF); stp.vol.setUnits("qt"); stp.vol.setAmount(waterAddedQTS); stp.temp = strikeTemp; stp.weightLbs = totalWeightLbs; if (tempUnits == "C") strikeTemp = 100; stp.directions = "Add " + SBStringUtils.format(stp.vol.getValueAs(volUnits), 1) + " " + volUnits + " of water at " + SBStringUtils.format(strikeTemp, 1) + " " + tempUnits; mashWaterQTS += waterAddedQTS; mashVolQTS += waterAddedQTS; } else if (stp.method.indexOf("decoction") > -1) { // calculate a decoction step waterEquiv += waterAddedQTS; // add previous addition to get WE waterAddedQTS = 0; strikeTemp = boilTempF; // boiling water double ratio=0.75; if (stp.method.indexOf("thick") > -1) ratio = thickDecoctRatio; else if (stp.method.indexOf("thin") > -1) ratio = thinDecoctRatio; // Calculate volume (qts) of mash to remove decoct = calcDecoction2(targetTemp, currentTemp, mashWaterQTS, ratio, totalWeightLbs); stp.vol.setUnits("qt"); stp.vol.setAmount(decoct); stp.temp = boilTempF; stp.weightLbs = totalWeightLbs; // Updated the decoction, convert to right units & make directions stp.directions = "Remove " + SBStringUtils.format(stp.vol.getValueAs(volUnits), 1) + " " + volUnits + " of mash, boil, and return to mash."; } else if (stp.method.equals("direct")) { // calculate a direct heat step decoct = 0; waterEquiv += waterAddedQTS; // add previous addition to get WE waterAddedQTS = 0; displTemp = stp.startTemp; if (tempUnits.equals("C")) displTemp = fToC(displTemp); stp.directions = "Add direct heat until mash reaches " + displTemp + " " + tempUnits + "."; stp.vol.setAmount(0); stp.temp = 0; stp.weightLbs = totalWeightLbs; } else if (stp.method.indexOf("cereal mash") > -1) { // calculate a cereal mash step waterEquiv += waterAddedQTS; // add previous addition to get WE waterAddedQTS = 0; targetTemp = stp.startTemp; double extraWaterQTS = 0; double cerealTemp = boilTempF; double cerealTargTemp = cerealMashTemp; String addStr = ""; /* * 1. check the temp of the mash when you add the boiling cereal mash @ default ratio back * 2. if it's > than the step temp, adjust the step temp * 3. if it's < than the step temp, add extra water to increase the "heat equivalencey" of the cereal mash */ double cerealWaterEquiv = stp.weightLbs * (0.192 + mr); waterAddedQTS = mr * stp.weightLbs; strikeTemp = calcStrikeTemp(cerealMashTemp, grainTempF, mr, 0); double newTemp = ((waterEquiv * currentTemp) + (cerealWaterEquiv * cerealTemp)) / (waterEquiv + cerealWaterEquiv); if (newTemp > targetTemp){ stp.startTemp = newTemp; } if (newTemp < targetTemp){ double addQts = ((waterEquiv * (targetTemp - currentTemp)) / (cerealTemp - targetTemp)) - 0.192; extraWaterQTS = addQts - waterAddedQTS; addStr = " Add " + SBStringUtils.format(Quantity.convertUnit("qt", volUnits, extraWaterQTS), 1) + " " + volUnits + " water to the cereal mash."; } // Calculate final temp of cereal mash // cerealTemp = (targetTemp * (waterEquiv + cerealWaterEquiv) - (waterEquiv * currentTemp)) / cerealWaterEquiv; totalMashTime += stp.minutes; mashWaterQTS += waterAddedQTS + extraWaterQTS; stp.vol.setUnits("qt"); stp.vol.setAmount(waterAddedQTS); stp.temp = strikeTemp; // make directions String weightStr = SBStringUtils.format(Quantity.convertUnit("lb", myRecipe.getMaltUnits(), stp.weightLbs), 1) + " " + myRecipe.getMaltUnits(); String volStr = SBStringUtils.format(Quantity.convertUnit("qt", volUnits, waterAddedQTS), 1) + " " + volUnits; if (tempUnits == "C"){ strikeTemp = fToC(strikeTemp); cerealTemp = fToC(cerealTemp); targetTemp = fToC(targetTemp); cerealTargTemp = fToC(cerealTargTemp); } String tempStr = SBStringUtils.format(strikeTemp, 1) + tempUnits; String tempStr2 = SBStringUtils.format(cerealTemp, 1) + tempUnits; String tempStr3 = SBStringUtils.format(targetTemp, 1) + tempUnits; String tempStr4 = SBStringUtils.format(cerealTargTemp, 1) + tempUnits; stp.directions = "Cereal mash: mash " + weightStr + " grain with " + volStr + " water at " + tempStr + " to hit " + tempStr4 + " and rest."; stp.directions += addStr; stp.directions += " Raise to " + tempStr2 + " and add to the main mash to reach " + tempStr3; // add cereal mash to total weight totalWeightLbs += stp.weightLbs; } if (stp.type.equals("sparge")) numSparge++; else { totalMashTime += stp.minutes; } // set target temp to end temp for next step targetTemp = stp.endTemp; } // for steps.size() waterEquiv += waterAddedQTS; // add previous addition to get WE totalTime = totalMashTime; volQts = mashVolQTS; // water use stats: absorbedQTS = totalWeightLbs * 0.55; // figure from HBD // spargeTotalQTS = (myRecipe.getPreBoilVol("qt")) - (mashWaterQTS - absorbedQTS); totalWaterQTS = mashWaterQTS; spargeQTS = myRecipe.getPreBoilVol("qt") - (mashWaterQTS - absorbedQTS); // Now let's figure out the sparging: if (numSparge == 0) return; double col = myRecipe.getPreBoilVol("qt") / numSparge; double charge[] = new double[numSparge]; double collect[] = new double[numSparge]; double totalCollectQts = myRecipe.getPreBoilVol("qt"); if (col < mashWaterQTS - absorbedQTS) { charge[0] = 0; collect[0] = mashWaterQTS - absorbedQTS; totalCollectQts = totalCollectQts - collect[0]; } else { charge[0] = col - (mashWaterQTS - absorbedQTS); collect[0] = col; totalCollectQts = totalCollectQts - collect[0]; } // do we need any more steps? if (numSparge > 1) { col = totalCollectQts / (numSparge - 1); for (int i = 1; i < numSparge; i++) { charge[i] = col; collect[i] = col; } } int j=0; for (int i = 1; i < steps.size(); i++) { stp = ((MashStep) steps.get(i)); if (stp.getType().equals("sparge")){ stp.vol.setUnits("qt"); stp.vol.setAmount(collect[j]); stp.temp = SPARGETMPF; totalSpargeTime += stp.getMinutes(); String collectStr = SBStringUtils.format(Quantity.convertUnit("qt", volUnits, collect[j]), 1) + " " + volUnits; String tempStr; if (tempUnits.equals("F")){ tempStr = "" + SBStringUtils.format(SPARGETMPF, 1) + "F"; } else { tempStr = SBStringUtils.format(BrewCalcs.fToC(SPARGETMPF), 1) + "C"; } if (numSparge > 1){ stp.setMethod("batch"); String add = SBStringUtils.format(Quantity.convertUnit("qt", volUnits, charge[j]), 1) + " " + volUnits; stp.setDirections("Add " + add + " at " + tempStr + " to collect " + collectStr); } else { stp.vol.setUnits("qt"); stp.vol.setAmount(spargeQTS); stp.setMethod("fly"); stp.setDirections("Sparge with " + SBStringUtils.format(Quantity.convertUnit("qt", volUnits, spargeQTS), 1) + " " + volUnits + " at " + tempStr + " to collect " + collectStr); } j++; } } }
1,115,255
public Object visit(ASTVarNode node, Object data) { String message = "Could not evaluate " + node.getName() + ": "; if (symTab == null) { message += "the symbol table is null"; addToErrorList(message); } else if (!symTab.containsKey(node.getName())) { message += "the variable was not found in the symbol table"; addToErrorList(message); } else { // all is fine // push the value on the stack stack.push(symTab.get(node.getName())); } return data; }
public Object visit(ASTVarNode node, Object data) { String message = "Could not evaluate " + node.getName() + ": "; if (symTab == null) { message += "the symbol table is null"; addToErrorList(message); } else if (!symTab.containsKey(node.getName())) { message += "the variable was not found in the symbol table"; addToErrorList(message); } else { // all is fine // push the value on the stack stack.push(symTab.get(node.getName())); } return data; }
1,115,256
private boolean calcChangeLog(Build build, File changelogFile, Launcher launcher, BuildListener listener) throws IOException { if(build.getPreviousBuild()==null) { // nothing to compare against return createEmptyChangeLog(changelogFile, listener, "log"); } PrintStream logger = listener.getLogger(); Map<String,String> previousRevisions = parseRevisionFile(build.getPreviousBuild()); Map env = createEnvVarMap(); for( String module : getModuleDirNames() ) { String prevRev = previousRevisions.get(module); if(prevRev==null) { logger.println("no revision recorded for "+module+" in the previous build"); continue; } String cmd = DESCRIPTOR.getSvnExe()+" log -v --xml --non-interactive -r "+prevRev+":BASE "+module; OutputStream os = new BufferedOutputStream(new FileOutputStream(changelogFile)); try { int r = launcher.launch(cmd,env,os,build.getProject().getWorkspace()).join(); if(r!=0) { listener.fatalError("revision check failed"); return false; } } finally { os.close(); } } return true; }
private boolean calcChangeLog(Build build, File changelogFile, Launcher launcher, BuildListener listener) throws IOException { if(build.getPreviousBuild()==null) { // nothing to compare against return createEmptyChangeLog(changelogFile, listener, "log"); } PrintStream logger = listener.getLogger(); Map<String,Integer> previousRevisions = parseRevisionFile(build.getPreviousBuild()); Map env = createEnvVarMap(); for( String module : getModuleDirNames() ) { String prevRev = previousRevisions.get(module); if(prevRev==null) { logger.println("no revision recorded for "+module+" in the previous build"); continue; } String cmd = DESCRIPTOR.getSvnExe()+" log -v --xml --non-interactive -r "+prevRev+":BASE "+module; OutputStream os = new BufferedOutputStream(new FileOutputStream(changelogFile)); try { int r = launcher.launch(cmd,env,os,build.getProject().getWorkspace()).join(); if(r!=0) { listener.fatalError("revision check failed"); return false; } } finally { os.close(); } } return true; }
1,115,257
private boolean calcChangeLog(Build build, File changelogFile, Launcher launcher, BuildListener listener) throws IOException { if(build.getPreviousBuild()==null) { // nothing to compare against return createEmptyChangeLog(changelogFile, listener, "log"); } PrintStream logger = listener.getLogger(); Map<String,String> previousRevisions = parseRevisionFile(build.getPreviousBuild()); Map env = createEnvVarMap(); for( String module : getModuleDirNames() ) { String prevRev = previousRevisions.get(module); if(prevRev==null) { logger.println("no revision recorded for "+module+" in the previous build"); continue; } String cmd = DESCRIPTOR.getSvnExe()+" log -v --xml --non-interactive -r "+prevRev+":BASE "+module; OutputStream os = new BufferedOutputStream(new FileOutputStream(changelogFile)); try { int r = launcher.launch(cmd,env,os,build.getProject().getWorkspace()).join(); if(r!=0) { listener.fatalError("revision check failed"); return false; } } finally { os.close(); } } return true; }
private boolean calcChangeLog(Build build, File changelogFile, Launcher launcher, BuildListener listener) throws IOException { if(build.getPreviousBuild()==null) { // nothing to compare against return createEmptyChangeLog(changelogFile, listener, "log"); } PrintStream logger = listener.getLogger(); Map<String,String> previousRevisions = parseRevisionFile(build.getPreviousBuild()); Map env = createEnvVarMap(); for( String module : getModuleDirNames() ) { Integer prevRev = previousRevisions.get(module); if(prevRev==null) { logger.println("no revision recorded for "+module+" in the previous build"); continue; } String cmd = DESCRIPTOR.getSvnExe()+" log -v --xml --non-interactive -r "+prevRev+":BASE "+module; OutputStream os = new BufferedOutputStream(new FileOutputStream(changelogFile)); try { int r = launcher.launch(cmd,env,os,build.getProject().getWorkspace()).join(); if(r!=0) { listener.fatalError("revision check failed"); return false; } } finally { os.close(); } } return true; }
1,115,258
private boolean calcChangeLog(Build build, File changelogFile, Launcher launcher, BuildListener listener) throws IOException { if(build.getPreviousBuild()==null) { // nothing to compare against return createEmptyChangeLog(changelogFile, listener, "log"); } PrintStream logger = listener.getLogger(); Map<String,String> previousRevisions = parseRevisionFile(build.getPreviousBuild()); Map env = createEnvVarMap(); for( String module : getModuleDirNames() ) { String prevRev = previousRevisions.get(module); if(prevRev==null) { logger.println("no revision recorded for "+module+" in the previous build"); continue; } String cmd = DESCRIPTOR.getSvnExe()+" log -v --xml --non-interactive -r "+prevRev+":BASE "+module; OutputStream os = new BufferedOutputStream(new FileOutputStream(changelogFile)); try { int r = launcher.launch(cmd,env,os,build.getProject().getWorkspace()).join(); if(r!=0) { listener.fatalError("revision check failed"); return false; } } finally { os.close(); } } return true; }
private boolean calcChangeLog(Build build, File changelogFile, Launcher launcher, BuildListener listener) throws IOException { if(build.getPreviousBuild()==null) { // nothing to compare against return createEmptyChangeLog(changelogFile, listener, "log"); } PrintStream logger = listener.getLogger(); Map<String,String> previousRevisions = parseRevisionFile(build.getPreviousBuild()); Map env = createEnvVarMap(); for( String module : getModuleDirNames() ) { String prevRev = previousRevisions.get(module); if(prevRev==null) { logger.println("no revision recorded for "+module+" in the previous build"); continue; } String cmd = DESCRIPTOR.getSvnExe()+" log -v --xml --non-interactive -r "+(prevRev+1)+":BASE "+module; OutputStream os = new BufferedOutputStream(new FileOutputStream(changelogFile)); try { int r = launcher.launch(cmd,env,os,build.getProject().getWorkspace()).join(); if(r!=0) { listener.fatalError("revision check failed"); return false; } } finally { os.close(); } } return true; }
1,115,259
/*package*/ static Map<String,String> parseRevisionFile(Build build) throws IOException { Map<String,String> revisions = new HashMap<String,String>(); // module -> revision {// read the revision file of the last build File file = getRevisionFile(build); if(!file.exists()) // nothing to compare against return revisions; BufferedReader br = new BufferedReader(new FileReader(file)); String line; while((line=br.readLine())!=null) { int index = line.indexOf('/'); if(index<0) { continue; // invalid line? } revisions.put(line.substring(0,index), line.substring(index+1)); } } return revisions; }
/*package*/ static Map<String,String> parseRevisionFile(Build build) throws IOException { Map<String,String> revisions = new HashMap<String,String>(); // module -> revision {// read the revision file of the last build File file = getRevisionFile(build); if(!file.exists()) // nothing to compare against return revisions; BufferedReader br = new BufferedReader(new FileReader(file)); String line; while((line=br.readLine())!=null) { int index = line.indexOf('/'); if(index<0) { continue; // invalid line? } revisions.put(line.substring(0,index), line.substring(index+1)); } } return revisions; }
1,115,260
/*package*/ static Map<String,String> parseRevisionFile(Build build) throws IOException { Map<String,String> revisions = new HashMap<String,String>(); // module -> revision {// read the revision file of the last build File file = getRevisionFile(build); if(!file.exists()) // nothing to compare against return revisions; BufferedReader br = new BufferedReader(new FileReader(file)); String line; while((line=br.readLine())!=null) { int index = line.indexOf('/'); if(index<0) { continue; // invalid line? } revisions.put(line.substring(0,index), line.substring(index+1)); } } return revisions; }
/*package*/ static Map<String,String> parseRevisionFile(Build build) throws IOException { Map<String,String> revisions = new HashMap<String,String>(); // module -> revision {// read the revision file of the last build File file = getRevisionFile(build); if(!file.exists()) // nothing to compare against return revisions; BufferedReader br = new BufferedReader(new FileReader(file)); String line; while((line=br.readLine())!=null) { int index = line.indexOf('/'); if(index<0) { continue; // invalid line? } try { revisions.put(line.substring(0,index), Integer.parseInt(line.substring(index+1))); } catch (NumberFormatException e) { } } } return revisions; }
1,115,261
public Node getChild(int i) { return (Node)m_children.get(i); }
public Node getChild() { return (Node)m_children.get(i); }
1,115,262
public Node getChild(int i) { return (Node)m_children.get(i); }
public Node getChild(int i) { if (getNumberChildren() == 0) return null; return getChild(0); }
1,115,263
@Test public void insert1000() throws SQLException { assertEquals(stat.executeUpdate("create temp table in1000 (a);"), 0); conn.setAutoCommit(false); for (int i=0; i < 1000; i++) assertEquals(stat.executeUpdate( "insert into in1000 values ("+i+");"), 1); conn.commit(); ResultSet rs = stat.executeQuery("select count(a) from in1000;"); assertTrue(rs.next()); assertEquals(rs.getInt(1), 1000); rs.close(); assertEquals(stat.executeUpdate("drop table in1000;"), 1); }
@Test public void insert1000() throws SQLException { assertEquals(stat.executeUpdate("create table in1000 (a);"), 0); conn.setAutoCommit(false); for (int i=0; i < 1000; i++) assertEquals(stat.executeUpdate( "insert into in1000 values ("+i+");"), 1); conn.commit(); ResultSet rs = stat.executeQuery("select count(a) from in1000;"); assertTrue(rs.next()); assertEquals(rs.getInt(1), 1000); rs.close(); assertEquals(stat.executeUpdate("drop table in1000;"), 1); }
1,115,264
public ChangeLogSet getChangeSet() { if(scm==null) scm = new CVSChangeLogParser(); File changelogFile = new File(getRootDir(), "changelog.xml"); if(!changelogFile.exists()) return ChangeLogSet.EMPTY; try { return scm.parse(changelogFile); } catch (IOException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } return ChangeLogSet.EMPTY; }
public ChangeLogSet getChangeSet() { if(scm==null) scm = new CVSChangeLogParser(); File changelogFile = new File(getRootDir(), "changelog.xml"); if(!changelogFile.exists()) return ChangeLogSet.EMPTY; try { return scm.parse(this,changelogFile); } catch (IOException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } return ChangeLogSet.EMPTY; }
1,115,265
public Complex(double re_in) { re = re_in; im = 0; }
public Complex(double re_in) { re = re_in; im = 0; }
1,115,267
public ChannelId getChannelId() { String keyStr = new String(); keyStr = getNet() + "." + getStation() + "." + getSite() + "." + getChannel(); System.out.println("The key is "+keyStr); if( mychannelchooser.allchanMap.containsKey(keyStr)) { System.out.println("Found the channelID "); return (ChannelId)(mychannelchooser.allchanMap.get(keyStr)); } else { System.out.println("The channelID is not Found"); return null; } }
public ChannelId getChannelId() { String keyStr = new String(); keyStr = getNet() + "." + getStation() + "." + getSite() + "." + getChannel(); System.out.println("The key is "+keyStr); if( mychannelchooser.allchanMap.containsKey(keyStr)) { System.out.println("Found the channelID "); return (ChannelId)(mychannelchooser.allchanMap.get(keyStr)); } else { System.out.println("The channelID is not Found"); return null; } }
1,115,268
protected AbstractCasFilter(final String serverName, final String serviceUrl, final boolean useSession) { CommonUtils.assertTrue(CommonUtils.isNotBlank(serverName) || CommonUtils.isNotBlank(serviceUrl), "either serverName or serviceUrl must be set"); this.serverName = serverName; this.serviceUrl = serviceUrl; this.useSession = useSession; }
protected AbstractCasFilter(final String serverName, final String serviceUrl, final boolean useSession) { CommonUtils.assertTrue(CommonUtils.isNotBlank(serverName) || CommonUtils.isNotBlank(serviceUrl), "either serverName or serviceUrl must be set"); this.serverName = serverName; this.serviceUrl = serviceUrl; this.useSession = useSession; }
1,115,271
public void displayRecipe() { if (myRecipe == null) return; txtName.setText(myRecipe.getName()); brewerNameText.setText(myRecipe.getBrewer()); txtPreBoil.setValue(new Double(myRecipe.getPreBoilVol(myRecipe.getVolUnits()))); lblSizeUnits.setText(myRecipe.getVolUnits()); postBoilText.setValue(new Double(myRecipe.getPostBoilVol(myRecipe.getVolUnits()))); boilMinText.setText(SBStringUtils.format(myRecipe.getBoilMinutes(), 0)); evapText.setText(SBStringUtils.format(myRecipe.getEvap(), 1)); spnEffic.setValue(new Double(myRecipe.getEfficiency())); spnAtten.setValue(new Double(myRecipe.getAttenuation())); spnOG.setValue(new Double(myRecipe.getEstOg())); spnFG.setValue(new Double(myRecipe.getEstFg())); txtComments.setText(myRecipe.getComments()); lblIBUvalue.setText(SBStringUtils.format(myRecipe.getIbu(), 1)); lblColourValue.setText(SBStringUtils.format(myRecipe.getSrm(), 1)); lblAlcValue.setText(SBStringUtils.format(myRecipe.getAlcohol(), 1)); try { txtDate.setDate(myRecipe.getCreated().getTime()); } catch (PropertyVetoException e) { // TODO Auto-generated catch block e.printStackTrace(); } // setText(SBStringUtils.dateFormat1.format(myRecipe.getCreated().getTime())); Costs = SBStringUtils.myNF.format(myRecipe.getTotalMaltCost()); tblMaltTotalsModel.setDataVector(new String[][]{{"Totals:", "" + SBStringUtils.format(myRecipe.getTotalMalt(), 1), myRecipe.getMaltUnits(), "" + SBStringUtils.format(myRecipe.getEstOg(), 3), "" + SBStringUtils.format(myRecipe.getSrm(), 1), Costs, "100"}}, new String[]{"", "", "", "", "", "", ""}); Costs = SBStringUtils.myNF.format(myRecipe.getTotalHopsCost()); tblHopsTotalsModel.setDataVector(new String[][]{{"Totals:", "", "", "" + SBStringUtils.format(myRecipe.getTotalHops(), 1), myRecipe.getHopUnits(), "", "", "" + SBStringUtils.format(myRecipe.getIbu(), 1), Costs}}, new String[]{"", "", "", "", "", "", "", "", ""}); String fileName = "not saved"; if (currentFile != null) { fileName = currentFile.getName(); } fileNameLabel.setText("File: " + fileName); ibuMethodLabel.setText("IBU method: " + myRecipe.getIBUMethod()); alcMethodLabel.setText("Alc method: " + myRecipe.getAlcMethod()); double colour = myRecipe.getSrm(); // convert from ebc if that's our mode: if (myRecipe.getColourMethod().equals("EBC")) { // From Greg Noonan's article at // http://brewingtechniques.com/bmg/noonan.html colour = (colour + 1.2) / 2.65; } if (preferences.getProperty("optRGBMethod").equals("1")) colourPanel.setBackground(Recipe.calcRGB(1, colour, preferences.getIProperty("optRed"), preferences.getIProperty("optGreen"), preferences.getIProperty("optBlue"), preferences.getIProperty("optAlpha"))); else colourPanel.setBackground(Recipe.calcRGB(2, colour, preferences.getIProperty("optRed"), preferences.getIProperty("optGreen"), preferences.getIProperty("optBlue"), preferences.getIProperty("optAlpha"))); // update the panels stylePanel.setStyleData(); costPanel.displayCost(); waterPanel.displayWater(); mashPanel.displayMash(); }
public void displayRecipe() { if (myRecipe == null) return; txtName.setText(myRecipe.getName()); brewerNameText.setText(myRecipe.getBrewer()); txtPreBoil.setValue(new Double(myRecipe.getPreBoilVol(myRecipe.getVolUnits()))); lblSizeUnits.setText(myRecipe.getVolUnits()); postBoilText.setValue(new Double(myRecipe.getPostBoilVol(myRecipe.getVolUnits()))); boilMinText.setText(SBStringUtils.format(myRecipe.getBoilMinutes(), 0)); evapText.setText(SBStringUtils.format(myRecipe.getEvap(), 1)); spnEffic.setValue(new Double(myRecipe.getEfficiency())); spnAtten.setValue(new Double(myRecipe.getAttenuation())); spnOG.setValue(new Double(myRecipe.getEstOg())); spnFG.setValue(new Double(myRecipe.getEstFg())); txtComments.setText(myRecipe.getComments()); lblIBUvalue.setText(SBStringUtils.format(myRecipe.getIbu(), 1)); lblColourValue.setText(SBStringUtils.format(myRecipe.getSrm(), 1)); lblAlcValue.setText(SBStringUtils.format(myRecipe.getAlcohol(), 1)); try { txtDate.setDate(myRecipe.getCreated().getTime()); } catch (PropertyVetoException e) { // TODO Auto-generated catch block e.printStackTrace(); } // setText(SBStringUtils.dateFormat1.format(myRecipe.getCreated().getTime())); Costs = SBStringUtils.myNF.format(myRecipe.getTotalMaltCost()); tblMaltTotalsModel.setDataVector(new String[][]{{"", "", "Totals:", "" + SBStringUtils.format(myRecipe.getTotalMalt(), 1), myRecipe.getMaltUnits(), "" + SBStringUtils.format(myRecipe.getEstOg(), 3), "" + SBStringUtils.format(myRecipe.getSrm(), 1), Costs, "100"}}, new String[]{"", "", "", "", "", "", ""}); Costs = SBStringUtils.myNF.format(myRecipe.getTotalHopsCost()); tblHopsTotalsModel.setDataVector(new String[][]{{"Totals:", "", "", "" + SBStringUtils.format(myRecipe.getTotalHops(), 1), myRecipe.getHopUnits(), "", "", "" + SBStringUtils.format(myRecipe.getIbu(), 1), Costs}}, new String[]{"", "", "", "", "", "", "", "", ""}); String fileName = "not saved"; if (currentFile != null) { fileName = currentFile.getName(); } fileNameLabel.setText("File: " + fileName); ibuMethodLabel.setText("IBU method: " + myRecipe.getIBUMethod()); alcMethodLabel.setText("Alc method: " + myRecipe.getAlcMethod()); double colour = myRecipe.getSrm(); // convert from ebc if that's our mode: if (myRecipe.getColourMethod().equals("EBC")) { // From Greg Noonan's article at // http://brewingtechniques.com/bmg/noonan.html colour = (colour + 1.2) / 2.65; } if (preferences.getProperty("optRGBMethod").equals("1")) colourPanel.setBackground(Recipe.calcRGB(1, colour, preferences.getIProperty("optRed"), preferences.getIProperty("optGreen"), preferences.getIProperty("optBlue"), preferences.getIProperty("optAlpha"))); else colourPanel.setBackground(Recipe.calcRGB(2, colour, preferences.getIProperty("optRed"), preferences.getIProperty("optGreen"), preferences.getIProperty("optBlue"), preferences.getIProperty("optAlpha"))); // update the panels stylePanel.setStyleData(); costPanel.displayCost(); waterPanel.displayWater(); mashPanel.displayMash(); }
1,115,273
public void displayRecipe() { if (myRecipe == null) return; txtName.setText(myRecipe.getName()); brewerNameText.setText(myRecipe.getBrewer()); txtPreBoil.setValue(new Double(myRecipe.getPreBoilVol(myRecipe.getVolUnits()))); lblSizeUnits.setText(myRecipe.getVolUnits()); postBoilText.setValue(new Double(myRecipe.getPostBoilVol(myRecipe.getVolUnits()))); boilMinText.setText(SBStringUtils.format(myRecipe.getBoilMinutes(), 0)); evapText.setText(SBStringUtils.format(myRecipe.getEvap(), 1)); spnEffic.setValue(new Double(myRecipe.getEfficiency())); spnAtten.setValue(new Double(myRecipe.getAttenuation())); spnOG.setValue(new Double(myRecipe.getEstOg())); spnFG.setValue(new Double(myRecipe.getEstFg())); txtComments.setText(myRecipe.getComments()); lblIBUvalue.setText(SBStringUtils.format(myRecipe.getIbu(), 1)); lblColourValue.setText(SBStringUtils.format(myRecipe.getSrm(), 1)); lblAlcValue.setText(SBStringUtils.format(myRecipe.getAlcohol(), 1)); try { txtDate.setDate(myRecipe.getCreated().getTime()); } catch (PropertyVetoException e) { // TODO Auto-generated catch block e.printStackTrace(); } // setText(SBStringUtils.dateFormat1.format(myRecipe.getCreated().getTime())); Costs = SBStringUtils.myNF.format(myRecipe.getTotalMaltCost()); tblMaltTotalsModel.setDataVector(new String[][]{{"Totals:", "" + SBStringUtils.format(myRecipe.getTotalMalt(), 1), myRecipe.getMaltUnits(), "" + SBStringUtils.format(myRecipe.getEstOg(), 3), "" + SBStringUtils.format(myRecipe.getSrm(), 1), Costs, "100"}}, new String[]{"", "", "", "", "", "", ""}); Costs = SBStringUtils.myNF.format(myRecipe.getTotalHopsCost()); tblHopsTotalsModel.setDataVector(new String[][]{{"Totals:", "", "", "" + SBStringUtils.format(myRecipe.getTotalHops(), 1), myRecipe.getHopUnits(), "", "", "" + SBStringUtils.format(myRecipe.getIbu(), 1), Costs}}, new String[]{"", "", "", "", "", "", "", "", ""}); String fileName = "not saved"; if (currentFile != null) { fileName = currentFile.getName(); } fileNameLabel.setText("File: " + fileName); ibuMethodLabel.setText("IBU method: " + myRecipe.getIBUMethod()); alcMethodLabel.setText("Alc method: " + myRecipe.getAlcMethod()); double colour = myRecipe.getSrm(); // convert from ebc if that's our mode: if (myRecipe.getColourMethod().equals("EBC")) { // From Greg Noonan's article at // http://brewingtechniques.com/bmg/noonan.html colour = (colour + 1.2) / 2.65; } if (preferences.getProperty("optRGBMethod").equals("1")) colourPanel.setBackground(Recipe.calcRGB(1, colour, preferences.getIProperty("optRed"), preferences.getIProperty("optGreen"), preferences.getIProperty("optBlue"), preferences.getIProperty("optAlpha"))); else colourPanel.setBackground(Recipe.calcRGB(2, colour, preferences.getIProperty("optRed"), preferences.getIProperty("optGreen"), preferences.getIProperty("optBlue"), preferences.getIProperty("optAlpha"))); // update the panels stylePanel.setStyleData(); costPanel.displayCost(); waterPanel.displayWater(); mashPanel.displayMash(); }
public void displayRecipe() { if (myRecipe == null) return; txtName.setText(myRecipe.getName()); brewerNameText.setText(myRecipe.getBrewer()); txtPreBoil.setValue(new Double(myRecipe.getPreBoilVol(myRecipe.getVolUnits()))); lblSizeUnits.setText(myRecipe.getVolUnits()); postBoilText.setValue(new Double(myRecipe.getPostBoilVol(myRecipe.getVolUnits()))); boilMinText.setText(SBStringUtils.format(myRecipe.getBoilMinutes(), 0)); evapText.setText(SBStringUtils.format(myRecipe.getEvap(), 1)); spnEffic.setValue(new Double(myRecipe.getEfficiency())); spnAtten.setValue(new Double(myRecipe.getAttenuation())); spnOG.setValue(new Double(myRecipe.getEstOg())); spnFG.setValue(new Double(myRecipe.getEstFg())); txtComments.setText(myRecipe.getComments()); lblIBUvalue.setText(SBStringUtils.format(myRecipe.getIbu(), 1)); lblColourValue.setText(SBStringUtils.format(myRecipe.getSrm(), 1)); lblAlcValue.setText(SBStringUtils.format(myRecipe.getAlcohol(), 1)); try { txtDate.setDate(myRecipe.getCreated().getTime()); } catch (PropertyVetoException e) { // TODO Auto-generated catch block e.printStackTrace(); } // setText(SBStringUtils.dateFormat1.format(myRecipe.getCreated().getTime())); Costs = SBStringUtils.myNF.format(myRecipe.getTotalMaltCost()); tblMaltTotalsModel.setDataVector(new String[][]{{"Totals:", "" + SBStringUtils.format(myRecipe.getTotalMalt(), 1), myRecipe.getMaltUnits(), "" + SBStringUtils.format(myRecipe.getEstOg(), 3), "" + SBStringUtils.format(myRecipe.getSrm(), 1), Costs, "100"}}, new String[]{"", "", "", "", "", "", "", "", ""}); Costs = SBStringUtils.myNF.format(myRecipe.getTotalHopsCost()); tblHopsTotalsModel.setDataVector(new String[][]{{"Totals:", "", "", "" + SBStringUtils.format(myRecipe.getTotalHops(), 1), myRecipe.getHopUnits(), "", "", "" + SBStringUtils.format(myRecipe.getIbu(), 1), Costs}}, new String[]{"", "", "", "", "", "", "", "", ""}); String fileName = "not saved"; if (currentFile != null) { fileName = currentFile.getName(); } fileNameLabel.setText("File: " + fileName); ibuMethodLabel.setText("IBU method: " + myRecipe.getIBUMethod()); alcMethodLabel.setText("Alc method: " + myRecipe.getAlcMethod()); double colour = myRecipe.getSrm(); // convert from ebc if that's our mode: if (myRecipe.getColourMethod().equals("EBC")) { // From Greg Noonan's article at // http://brewingtechniques.com/bmg/noonan.html colour = (colour + 1.2) / 2.65; } if (preferences.getProperty("optRGBMethod").equals("1")) colourPanel.setBackground(Recipe.calcRGB(1, colour, preferences.getIProperty("optRed"), preferences.getIProperty("optGreen"), preferences.getIProperty("optBlue"), preferences.getIProperty("optAlpha"))); else colourPanel.setBackground(Recipe.calcRGB(2, colour, preferences.getIProperty("optRed"), preferences.getIProperty("optGreen"), preferences.getIProperty("optBlue"), preferences.getIProperty("optAlpha"))); // update the panels stylePanel.setStyleData(); costPanel.displayCost(); waterPanel.displayWater(); mashPanel.displayMash(); }
1,115,274
private void initGUI() { try { // restore the saved size and location: this.setSize(preferences.getIProperty("winWidth"), preferences.getIProperty("winHeight")); this.setLocation(preferences.getIProperty("winX"), preferences.getIProperty("winY")); imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/sb2.gif"); icon = new ImageIcon(imgURL); this.setIconImage(icon.getImage()); this.setTitle("StrangeBrew " + version); this.addWindowListener(new WindowAdapter() { public void windowClosed(WindowEvent evt) { System.exit(1); } }); { pnlMain = new JPanel(); GridBagLayout jPanel2Layout = new GridBagLayout(); jPanel2Layout.columnWeights = new double[]{0.1}; jPanel2Layout.columnWidths = new int[]{7}; jPanel2Layout.rowWeights = new double[]{0.1, 0.1, 0.9, 0.1}; jPanel2Layout.rowHeights = new int[]{7, 7, 7, 7}; pnlMain.setLayout(jPanel2Layout); this.getContentPane().add(pnlMain, BorderLayout.CENTER); { jTabbedPane1 = new JTabbedPane(); pnlMain.add(jTabbedPane1, new GridBagConstraints(0, 1, 1, 1, 0.1, 0.1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); { pnlDetails = new JPanel(); GridBagLayout pnlDetailsLayout = new GridBagLayout(); pnlDetailsLayout.columnWeights = new double[]{0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1}; pnlDetailsLayout.columnWidths = new int[]{7, 7, 7, 7, 7, 7, 7, 7, 7, 7}; pnlDetailsLayout.rowWeights = new double[]{0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1}; pnlDetailsLayout.rowHeights = new int[]{7, 7, 7, 7, 7, 7, 7}; pnlDetails.setLayout(pnlDetailsLayout); jTabbedPane1.addTab("Details", null, pnlDetails, null); pnlDetails.setPreferredSize(new java.awt.Dimension(20, 16)); { lblBrewer = new JLabel(); pnlDetails.add(lblBrewer, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblBrewer.setText("Brewer:"); } { brewerNameText = new JTextField(); pnlDetails.add(brewerNameText, new GridBagConstraints(1, 0, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); brewerNameText.setPreferredSize(new java.awt.Dimension(69, 20)); brewerNameText.setText("Brewer"); } { lblDate = new JLabel(); pnlDetails.add(lblDate, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblDate.setText("Date:"); } { lblStyle = new JLabel(); pnlDetails.add(lblStyle, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblStyle.setText("Style:"); } { lblYeast = new JLabel(); pnlDetails.add(lblYeast, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblYeast.setText("Yeast:"); } { lblPreBoil = new JLabel(); pnlDetails.add(lblPreBoil, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblPreBoil.setText("Pre boil:"); } { lblPostBoil = new JLabel(); pnlDetails.add(lblPostBoil, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblPostBoil.setText("Post boil:"); } { lblEffic = new JLabel(); pnlDetails.add(lblEffic, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblEffic.setText("Effic:"); lblEffic.setPreferredSize(new java.awt.Dimension(31, 14)); } { lblAtten = new JLabel(); pnlDetails.add(lblAtten, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblAtten.setText("Atten:"); lblAtten.setPreferredSize(new java.awt.Dimension(34, 14)); } { lblOG = new JLabel(); pnlDetails.add(lblOG, new GridBagConstraints(5, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblOG.setText("OG:"); } { lblFG = new JLabel(); pnlDetails.add(lblFG, new GridBagConstraints(5, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblFG.setText("FG:"); } { lblIBU = new JLabel(); pnlDetails.add(lblIBU, new GridBagConstraints(7, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblIBU.setText("IBU:"); } { lblAlc = new JLabel(); pnlDetails.add(lblAlc, new GridBagConstraints(7, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblAlc.setText("%Alc:"); } { lblColour = new JLabel(); pnlDetails.add(lblColour, new GridBagConstraints(7, 2, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblColour.setText("Colour:"); } { //txtDate = new JFormattedTextField(); txtDate = new DatePicker(); pnlDetails.add(txtDate, new GridBagConstraints(1, 1, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); // txtDate.setText("Date"); txtDate.setPreferredSize(new java.awt.Dimension(73, 20)); txtDate.setDateStyle(DateFormat.SHORT); } { cmbStyleModel = new ComboModel(); cmbStyle = new JComboBox(); pnlDetails.add(cmbStyle, new GridBagConstraints(1, 2, 5, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cmbStyle.setModel(cmbStyleModel); cmbStyle.setMaximumSize(new java.awt.Dimension(100, 32767)); cmbStyle.setPreferredSize(new java.awt.Dimension(190, 20)); } { txtPreBoil = new JFormattedTextField(); pnlDetails.add(txtPreBoil, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); txtPreBoil.setText("Pre Boil"); txtPreBoil.setPreferredSize(new java.awt.Dimension(37, 20)); } { postBoilText = new JFormattedTextField(); pnlDetails.add(postBoilText, new GridBagConstraints(1, 5, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); postBoilText.setText("Post Boil"); postBoilText.setPreferredSize(new java.awt.Dimension(46, 20)); } { lblComments = new JLabel(); pnlDetails.add(lblComments, new GridBagConstraints(6, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblComments.setText("Comments:"); } { SpinnerNumberModel spnEfficModel = new SpinnerNumberModel(75.0, 0.0, 100.0, 1.0); spnEffic = new JSpinner(); pnlDetails.add(spnEffic, new GridBagConstraints(4, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnEffic.setModel(spnEfficModel); spnEffic.setMaximumSize(new java.awt.Dimension(70, 32767)); spnEffic.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { myRecipe.setEfficiency(Double.parseDouble(spnEffic.getValue() .toString())); displayRecipe(); } }); spnEffic.setEditor(new JSpinner.NumberEditor(spnEffic, "00.#")); spnEffic.getEditor().setPreferredSize(new java.awt.Dimension(28, 16)); spnEffic.setPreferredSize(new java.awt.Dimension(53, 18)); } { SpinnerNumberModel spnAttenModel = new SpinnerNumberModel(75.0, 0.0, 100.0, 1.0); spnAtten = new JSpinner(); pnlDetails.add(spnAtten, new GridBagConstraints(4, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnAtten.setModel(spnAttenModel); spnAtten.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { myRecipe.setAttenuation(Double.parseDouble(spnAtten.getValue() .toString())); displayRecipe(); } }); spnAtten.setEditor(new JSpinner.NumberEditor(spnAtten, "00.#")); spnAtten.setPreferredSize(new java.awt.Dimension(49, 20)); } { SpinnerNumberModel spnOgModel = new SpinnerNumberModel(1.000, 0.900, 2.000, 0.001); spnOG = new JSpinner(); pnlDetails.add(spnOG, new GridBagConstraints(6, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnOG.setModel(spnOgModel); spnOG.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { myRecipe.setEstOg(Double.parseDouble(spnOG.getValue() .toString())); displayRecipe(); } }); spnOG.setEditor(new JSpinner.NumberEditor(spnOG, "0.000")); spnOG.getEditor().setPreferredSize(new java.awt.Dimension(20, 16)); spnOG.setPreferredSize(new java.awt.Dimension(67, 18)); } { SpinnerNumberModel spnFgModel = new SpinnerNumberModel(1.000, 0.900, 2.000, 0.001); spnFG = new JSpinner(); pnlDetails.add(spnFG, new GridBagConstraints(6, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnFG.setModel(spnFgModel); spnFG.setEditor(new JSpinner.NumberEditor(spnFG, "0.000")); spnFG.setPreferredSize(new java.awt.Dimension(69, 20)); spnFG.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { // set the new FG, and update alc: myRecipe.setEstFg(Double.parseDouble(spnFG.getValue() .toString())); displayRecipe(); } }); } { lblIBUvalue = new JLabel(); pnlDetails.add(lblIBUvalue, new GridBagConstraints(8, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblIBUvalue.setText("IBUs"); } { lblColourValue = new JLabel(); pnlDetails.add(lblColourValue, new GridBagConstraints(8, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblColourValue.setText("Colour"); } { lblAlcValue = new JLabel(); pnlDetails.add(lblAlcValue, new GridBagConstraints(8, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblAlcValue.setText("Alc"); } { scpComments = new JScrollPane(); pnlDetails.add(scpComments, new GridBagConstraints(7, 4, 3, 2, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); { txtComments = new JTextArea(); scpComments.setViewportView(txtComments); txtComments.setText("Comments"); txtComments.setWrapStyleWord(true); // txtComments.setPreferredSize(new java.awt.Dimension(117, 42)); txtComments.setLineWrap(true); txtComments.setPreferredSize(new java.awt.Dimension(263, 40)); txtComments.addFocusListener(new FocusAdapter() { public void focusLost(FocusEvent evt) { if (!txtComments.getText().equals(myRecipe.getComments())) { myRecipe.setComments(txtComments.getText()); } } }); } } { cmbYeastModel = new ComboModel(); cmbYeast = new JComboBox(); pnlDetails.add(cmbYeast, new GridBagConstraints(1, 3, 5, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cmbYeast.setModel(cmbYeastModel); cmbYeast.setPreferredSize(new java.awt.Dimension(193, 20)); } { cmbSizeUnitsModel = new ComboModel(); cmbSizeUnits = new JComboBox(); pnlDetails.add(cmbSizeUnits, new GridBagConstraints(2, 4, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cmbSizeUnits.setModel(cmbSizeUnitsModel); } { lblSizeUnits = new JLabel(); pnlDetails.add(lblSizeUnits, new GridBagConstraints(2, 5, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); lblSizeUnits.setText("Size Units"); } { boilTimeLable = new JLabel(); pnlDetails.add(boilTimeLable, new GridBagConstraints(4, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); boilTimeLable.setText("Boil Min:"); } { evapLabel = new JLabel(); pnlDetails.add(evapLabel, new GridBagConstraints(4, 5, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); evapLabel.setText("Evap/hr:"); } { boilMinText = new JTextField(); pnlDetails.add(boilMinText, new GridBagConstraints(5, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); boilMinText.setText("60"); boilMinText.setPreferredSize(new java.awt.Dimension(22, 20)); } { evapText = new JTextField(); pnlDetails.add(evapText, new GridBagConstraints(5, 5, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); evapText.setText("4"); evapText.setPreferredSize(new java.awt.Dimension(23, 20)); } { alcMethodComboModel = new DefaultComboBoxModel(new String[]{"Volume", "Weight"}); alcMethodCombo = new JComboBox(alcMethodComboModel); pnlDetails.add(alcMethodCombo, new GridBagConstraints(9, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); alcMethodCombo.setPreferredSize(new java.awt.Dimension(58, 20)); } { ibuMethodComboModel = new DefaultComboBoxModel(new String[]{"Tinseth", "Garetz", "Rager"}); ibuMethodCombo = new JComboBox(ibuMethodComboModel); pnlDetails.add(ibuMethodCombo, new GridBagConstraints(9, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); ibuMethodCombo.setPreferredSize(new java.awt.Dimension(59, 20)); } { colourMethodComboModel = new DefaultComboBoxModel(new String[]{"SRM", "EBC"}); colourMethodCombo = new JComboBox(colourMethodComboModel); pnlDetails.add(colourMethodCombo, new GridBagConstraints(9, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); colourMethodCombo.setPreferredSize(new java.awt.Dimension(44, 20)); } ComboBoxModel evapMethodComboModel = new DefaultComboBoxModel(new String[] { "Constant", "Percent" }); { jPanel1 = new JPanel(); pnlMain.add(jPanel1, new GridBagConstraints( 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); FlowLayout jPanel1Layout = new FlowLayout(); jPanel1Layout.setAlignment(FlowLayout.LEFT); jPanel1.setLayout(jPanel1Layout); jToolBar1 = new JToolBar(); getContentPane().add(jToolBar1, BorderLayout.NORTH); jToolBar1.setFloatable(false); jToolBar1.setRollover(true); jButton1 = new JButton(); jToolBar1.add(jButton1); jButton1.setMnemonic(java.awt.event.KeyEvent.VK_S); jButton1.setIcon(new ImageIcon(getClass().getClassLoader().getResource( "ca/strangebrew/icons/save.gif"))); jButton1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { System.out.println("jButton1.actionPerformed, event=" + evt); //TODO add your code for jButton1.actionPerformed } }); jButton2 = new JButton(); jToolBar1.add(jButton2); jButton2.setIcon(new ImageIcon(getClass().getClassLoader().getResource( "ca/strangebrew/icons/find.gif"))); jButton2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { System.out.println("jButton2.actionPerformed, event=" + evt); //TODO add your code for jButton2.actionPerformed } }); { lblName = new JLabel(); jPanel1.add(lblName); lblName.setText("Name:"); } { txtName = new JTextField(); jPanel1.add(txtName); txtName.setText("Name"); txtName.setPreferredSize(new java.awt.Dimension(297, 20)); } } evapMethodCombo = new JComboBox(); pnlDetails.add(evapMethodCombo, new GridBagConstraints(6, 5, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); evapMethodCombo.setModel(evapMethodComboModel); evapMethodCombo.setPreferredSize(new java.awt.Dimension(64, 20)); colourPanel = new JPanel(); pnlDetails.add(colourPanel, new GridBagConstraints(9, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); colourPanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); } { SBNotifier sbn = new SBNotifier(); stylePanel = new StylePanel(sbn); jTabbedPane1.addTab("Style", null, stylePanel, null); miscPanel = new MiscPanel(myRecipe); jTabbedPane1.addTab("Misc", null, miscPanel, null); notesPanel = new NotesPanel(); jTabbedPane1.addTab("Notes", null, notesPanel, null); dilutionPanel = new DilutionPanel(); jTabbedPane1.addTab("Dilution", null, dilutionPanel, null); mashPanel = new MashPanel(myRecipe); jTabbedPane1.addTab("Mash", null, mashPanel, null); waterPanel = new WaterPanel(); jTabbedPane1.addTab("Water", null, waterPanel, null); costPanel = new CostPanel(); jTabbedPane1.addTab("Cost", null, costPanel, null); // SBNotifier sbn = new SBNotifier(); settingsPanel = new SettingsPanel(sbn); jTabbedPane1.addTab("Settings", null, settingsPanel, null); } } { pnlTables = new JPanel(); BoxLayout pnlMaltsLayout = new BoxLayout(pnlTables, javax.swing.BoxLayout.Y_AXIS); pnlMain.add(pnlTables, new GridBagConstraints(0, 2, 1, 1, 0.5, 0.5, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); pnlTables.setLayout(pnlMaltsLayout); { pnlMalt = new JPanel(); pnlTables.add(pnlMalt); BorderLayout pnlMaltLayout1 = new BorderLayout(); pnlMalt.setBorder(BorderFactory.createTitledBorder(new LineBorder( new java.awt.Color(0, 0, 0), 1, false), "Fermentables", TitledBorder.LEADING, TitledBorder.TOP, new java.awt.Font("Dialog", 1, 12), new java.awt.Color(51, 51, 51))); pnlMalt.setLayout(pnlMaltLayout1); { jScrollPane1 = new JScrollPane(); pnlMalt.add(jScrollPane1, BorderLayout.CENTER); { maltTableModel = new MaltTableModel(this); maltTable = new JTable() { public String getToolTipText(MouseEvent e) { java.awt.Point p = e.getPoint(); int rowIndex = rowAtPoint(p); return SBStringUtils.multiLineToolTip(40, maltTableModel .getDescriptionAt(rowIndex)); } }; jScrollPane1.setViewportView(maltTable); maltTable.setModel(maltTableModel); // maltTable.setAutoCreateColumnsFromModel(false); maltTable.getTableHeader().setReorderingAllowed(false); TableColumn maltColumn = maltTable.getColumnModel().getColumn(0); // set up malt list combo maltComboBox = new JComboBox(); cmbMaltModel = new ComboModel(); maltComboBox.setModel(cmbMaltModel); maltColumn.setCellEditor(new DefaultCellEditor(maltComboBox)); // set up malt amount editor amountEditor = new SBCellEditor(new JTextField()); maltColumn = maltTable.getColumnModel().getColumn(1); maltColumn.setCellEditor(amountEditor); // set up malt units combo maltUnitsComboBox = new JComboBox(); cmbMaltUnitsModel = new ComboModel(); maltUnitsComboBox.setModel(cmbMaltUnitsModel); maltColumn = maltTable.getColumnModel().getColumn(2); maltColumn.setCellEditor(new DefaultCellEditor(maltUnitsComboBox)); } } { tblMaltTotalsModel = new DefaultTableModel(new String[][]{{""}}, new String[]{"Malt", "Amount", "Units", "Points", "Lov", "Cost/U", "%"}); tblMaltTotals = new JTable(); pnlMalt.add(tblMaltTotals, BorderLayout.SOUTH); tblMaltTotals.setModel(tblMaltTotalsModel); tblMaltTotals.getTableHeader().setEnabled(false); tblMaltTotals.setAutoCreateColumnsFromModel(false); // set up the units combobox maltTotalUnitsComboBox = new JComboBox(); maltTotalUnitsComboModel = new ComboModel(); maltTotalUnitsComboModel.setList(new Quantity().getListofUnits("weight")); maltTotalUnitsComboBox.setModel(maltTotalUnitsComboModel); TableColumn t = tblMaltTotals.getColumnModel().getColumn(2); t.setCellEditor(new DefaultCellEditor(maltTotalUnitsComboBox)); maltTotalUnitsComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { String u = (String) maltTotalUnitsComboModel.getSelectedItem(); if (myRecipe != null) { myRecipe.setMaltUnits(u); displayRecipe(); } } }); } } { pnlMaltButtons = new JPanel(); pnlTables.add(pnlMaltButtons); FlowLayout pnlMaltButtonsLayout = new FlowLayout(); pnlMaltButtonsLayout.setAlignment(FlowLayout.LEFT); pnlMaltButtonsLayout.setVgap(0); pnlMaltButtons.setLayout(pnlMaltButtonsLayout); pnlMaltButtons.setPreferredSize(new java.awt.Dimension(592, 27)); { tlbMalt = new JToolBar(); pnlMaltButtons.add(tlbMalt); tlbMalt.setPreferredSize(new java.awt.Dimension(386, 20)); tlbMalt.setFloatable(false); { btnAddMalt = new JButton(); tlbMalt.add(btnAddMalt); btnAddMalt.setText("+"); btnAddMalt.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { Fermentable f = new Fermentable(myRecipe.getMaltUnits()); myRecipe.addMalt(f); maltTable.updateUI(); displayRecipe(); } } }); } { btnDelMalt = new JButton(); tlbMalt.add(btnDelMalt); btnDelMalt.setText("-"); btnDelMalt.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { int i = maltTable.getSelectedRow(); myRecipe.delMalt(i); maltTable.updateUI(); displayRecipe(); } } }); } } } { pnlHops = new JPanel(); BorderLayout pnlHopsLayout = new BorderLayout(); pnlHops.setBorder(BorderFactory.createTitledBorder(new LineBorder( new java.awt.Color(0, 0, 0), 1, false), "Hops", TitledBorder.LEADING, TitledBorder.TOP, new java.awt.Font("Dialog", 1, 12), new java.awt.Color(51, 51, 51))); pnlHops.setLayout(pnlHopsLayout); pnlTables.add(pnlHops); { tblHopsTotalsModel = new DefaultTableModel(new String[][]{{""}}, new String[]{"1", "2", "3", "4", "5", "6", "7", "8", "9"}); tblHopsTotals = new JTable(); pnlHops.add(tblHopsTotals, BorderLayout.SOUTH); tblHopsTotals.setModel(tblHopsTotalsModel); tblHopsTotals.setAutoCreateColumnsFromModel(false); // set up the units combobox hopsTotalUnitsComboBox = new JComboBox(); hopsTotalUnitsComboModel = new ComboModel(); hopsTotalUnitsComboModel.setList(new Quantity().getListofUnits("weight")); hopsTotalUnitsComboBox.setModel(hopsTotalUnitsComboModel); TableColumn t = tblHopsTotals.getColumnModel().getColumn(4); t.setCellEditor(new DefaultCellEditor(hopsTotalUnitsComboBox)); hopsTotalUnitsComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { String u = (String) hopsTotalUnitsComboModel.getSelectedItem(); if (myRecipe != null) { myRecipe.setHopsUnits(u); displayRecipe(); } } }); } { jScrollPane2 = new JScrollPane(); pnlHops.add(jScrollPane2, BorderLayout.CENTER); { hopsTableModel = new HopsTableModel(this); hopsTable = new JTable() { public String getToolTipText(MouseEvent e) { java.awt.Point p = e.getPoint(); int rowIndex = rowAtPoint(p); return SBStringUtils.multiLineToolTip(40, hopsTableModel .getDescriptionAt(rowIndex)); } }; jScrollPane2.setViewportView(hopsTable); hopsTable.setModel(hopsTableModel); hopsTable.getTableHeader().setReorderingAllowed(false); TableColumn hopColumn = hopsTable.getColumnModel().getColumn(0); hopComboBox = new JComboBox(); cmbHopsModel = new ComboModel(); hopComboBox.setModel(cmbHopsModel); hopColumn.setCellEditor(new DefaultCellEditor(hopComboBox)); // set up hop units combo hopsUnitsComboBox = new JComboBox(); cmbHopsUnitsModel = new ComboModel(); hopsUnitsComboBox.setModel(cmbHopsUnitsModel); hopColumn = hopsTable.getColumnModel().getColumn(4); hopColumn.setCellEditor(new DefaultCellEditor(hopsUnitsComboBox)); // set up hop type combo String[] forms = {"Leaf", "Pellet", "Plug"}; JComboBox hopsFormComboBox = new JComboBox(forms); hopColumn = hopsTable.getColumnModel().getColumn(1); hopColumn.setCellEditor(new DefaultCellEditor(hopsFormComboBox)); // set up hop add combo String[] add = {"Boil", "FWH", "Dry", "Mash"}; JComboBox hopsAddComboBox = new JComboBox(add); hopColumn = hopsTable.getColumnModel().getColumn(5); hopColumn.setCellEditor(new DefaultCellEditor(hopsAddComboBox)); } } } { pnlHopsButtons = new JPanel(); FlowLayout pnlHopsButtonsLayout = new FlowLayout(); pnlHopsButtonsLayout.setAlignment(FlowLayout.LEFT); pnlHopsButtonsLayout.setVgap(0); pnlHopsButtons.setLayout(pnlHopsButtonsLayout); pnlTables.add(pnlHopsButtons); pnlHopsButtons.setPreferredSize(new java.awt.Dimension(512, 16)); { tlbHops = new JToolBar(); pnlHopsButtons.add(tlbHops); tlbHops.setPreferredSize(new java.awt.Dimension(413, 19)); tlbHops.setFloatable(false); { btnAddHop = new JButton(); tlbHops.add(btnAddHop); btnAddHop.setText("+"); btnAddHop.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { Hop h = new Hop(myRecipe.getHopUnits()); myRecipe.addHop(h); hopsTable.updateUI(); displayRecipe(); } } }); } { btnDelHop = new JButton(); tlbHops.add(btnDelHop); btnDelHop.setText("-"); btnDelHop.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { int i = hopsTable.getSelectedRow(); myRecipe.delHop(i); hopsTable.updateUI(); displayRecipe(); } } }); } } } } { statusPanel = new JPanel(); FlowLayout statusPanelLayout = new FlowLayout(); statusPanelLayout.setAlignment(FlowLayout.LEFT); statusPanelLayout.setHgap(2); statusPanelLayout.setVgap(2); statusPanel.setLayout(statusPanelLayout); pnlMain.add(statusPanel, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); { fileNamePanel = new JPanel(); statusPanel.add(fileNamePanel); fileNamePanel.setBorder(BorderFactory .createBevelBorder(BevelBorder.LOWERED)); { fileNameLabel = new JLabel(); fileNamePanel.add(fileNameLabel); fileNameLabel.setText("File Name"); fileNameLabel.setFont(new java.awt.Font("Dialog", 1, 10)); } } { ibuMethodPanel = new JPanel(); statusPanel.add(ibuMethodPanel); ibuMethodPanel.setBorder(BorderFactory .createBevelBorder(BevelBorder.LOWERED)); { ibuMethodLabel = new JLabel(); ibuMethodPanel.add(ibuMethodLabel); ibuMethodLabel.setText("IBU Method:"); ibuMethodLabel.setFont(new java.awt.Font("Dialog", 1, 10)); } } { alcMethodPanel = new JPanel(); statusPanel.add(alcMethodPanel); alcMethodPanel.setBorder(BorderFactory .createBevelBorder(BevelBorder.LOWERED)); { alcMethodLabel = new JLabel(); alcMethodPanel.add(alcMethodLabel); alcMethodLabel.setText("Alc Method:"); alcMethodLabel.setFont(new java.awt.Font("Dialog", 1, 10)); } } } } { jMenuBar1 = new JMenuBar(); setJMenuBar(jMenuBar1); { fileMenu = new JMenu(); jMenuBar1.add(fileMenu); fileMenu.setText("File"); { newFileMenuItem = new JMenuItem(); fileMenu.add(newFileMenuItem); newFileMenuItem.setText("New"); newFileMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // This is just a test right now to see that // stuff is changed. myRecipe = new Recipe(); myRecipe.setVersion(version); currentFile = null; attachRecipeData(); displayRecipe(); } }); } { openFileMenuItem = new JMenuItem(); fileMenu.add(openFileMenuItem); openFileMenuItem.setText("Open"); openFileMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_O, ActionEvent.CTRL_MASK)); openFileMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Show open dialog; this method does // not return until the dialog is closed String[] ext = {"xml", "qbrew", "rec"}; String desc = "StrangBrew and importable formats"; sbFileFilter openFileFilter = new sbFileFilter(ext, desc); // fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); fileChooser.setFileFilter(openFileFilter); int returnVal = fileChooser.showOpenDialog(jMenuBar1); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); Debug.print("Opening: " + file.getName() + ".\n"); OpenImport oi = new OpenImport(); myRecipe = oi.openFile(file); if (oi.getFileType().equals("")){ JOptionPane.showMessageDialog( null, "The file you've tried to open isn't a recognized format. \n" + "You can open: \n" + "StrangeBrew 1.x and Java files (.xml)\n" + "QBrew files (.qbrew)\n" + "BeerXML files (.xml)\n" + "Promash files (.rec)", "Unrecognized Format!", JOptionPane.INFORMATION_MESSAGE); } if (oi.getFileType().equals("beerxml")){ JOptionPane.showMessageDialog( null, "The file you've opened is in BeerXML format. It may contain \n" + "several recipes. Only the first recipe is opened. Use the Find \n" + "dialog to open other recipes in a BeerXML file.", "BeerXML!", JOptionPane.INFORMATION_MESSAGE); } myRecipe.setVersion(version); myRecipe.calcMaltTotals(); myRecipe.calcHopsTotals(); myRecipe.mash.calcMashSchedule(); checkIngredientsInDB(); attachRecipeData(); currentFile = file; displayRecipe(); } else { Debug.print("Open command cancelled by user.\n"); } } }); } { imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/find.gif"); icon = new ImageIcon(imgURL); findFileMenuItem = new JMenuItem("Find", icon); findFileMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_F, ActionEvent.CTRL_MASK)); fileMenu.add(findFileMenuItem); final JFrame owner = this; findFileMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // open the find dialog FindDialog fd = new FindDialog(owner); fd.setVisible(true); } }); } { imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/save.gif"); icon = new ImageIcon(imgURL); saveMenuItem = new JMenuItem("Save", icon); fileMenu.add(saveMenuItem); saveMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_S, ActionEvent.CTRL_MASK)); saveMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { int choice = 1; if (currentFile != null) { File file = currentFile; //This is where a real application would save the file. try { FileWriter out = new FileWriter(file); out.write(myRecipe.toXML()); out.close(); Debug.print("Saved: " + file.getAbsoluteFile()); currentFile = file; } catch (Exception e) { showError(e); } } // prompt to save if not already saved else { choice = JOptionPane.showConfirmDialog(null, "File not saved. Do you wish to save it?", "File note saved", JOptionPane.YES_NO_OPTION); } if (choice == 0) { // same as save as: saveAs(); } } }); } { imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/saveas.gif"); icon = new ImageIcon(imgURL); saveAsMenuItem = new JMenuItem("Save As ...", icon); fileMenu.add(saveAsMenuItem); saveAsMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // This is just a test right now to see that // stuff is changed. Debug.print(myRecipe.toXML()); saveAs(); } }); } { exportMenu = new JMenu(); fileMenu.add(exportMenu); exportMenu.setText("Export"); { exportHTMLmenu = new JMenuItem(); exportMenu.add(exportHTMLmenu); exportHTMLmenu.setText("HTML"); exportHTMLmenu.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Show save dialog; this method does // not return until the dialog is closed String[] ext = {"html", "htm"}; sbFileFilter saveFileFilter = new sbFileFilter(ext, "HTML"); fileChooser.setFileFilter(saveFileFilter); fileChooser.setSelectedFile(new File(myRecipe.getName() + ".html")); int returnVal = fileChooser.showSaveDialog(jMenuBar1); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); //This is where a real application would save the file. try { saveAsHTML(file, "ca/strangebrew/data/recipeToHtml.xslt"); } catch (Exception e) { showError(e); } } else { Debug.print("Save command cancelled by user.\n"); } } }); exportTextMenuItem = new JMenuItem(); exportMenu.add(exportTextMenuItem); exportTextMenuItem.setText("Text"); exportTextMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Show save dialog; this method does // not return until the dialog is closed String[] ext = {"txt"}; sbFileFilter saveFileFilter = new sbFileFilter(ext, "Text"); fileChooser.setFileFilter(saveFileFilter); fileChooser.setSelectedFile(new File(myRecipe.getName() + ".txt")); int returnVal = fileChooser.showSaveDialog(jMenuBar1); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); //This is where a real application would save the file. try { FileWriter out = new FileWriter(file); out.write(myRecipe.toText()); out.close(); } catch (Exception e) { showError(e); } } else { Debug.print("Export text command cancelled by user.\n"); } } }); } } { JMenuItem clipboardMenuItem = new JMenuItem("Copy to Clipboard"); fileMenu.add(clipboardMenuItem); clipboardMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Copy current recipe to clipboard Clipboard clipboard = getToolkit ().getSystemClipboard (); StringSelection s = new StringSelection(myRecipe.toText()); clipboard.setContents(s, s); } }); JMenuItem printMenuItem = new JMenuItem("Print..."); fileMenu.add(printMenuItem); final JFrame owner = this; printMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Copy current recipe to clipboard// save file as xml, then transform it to html File tmp = new File("tmp.html"); try { saveAsHTML(tmp, "ca/strangebrew/data/recipeToSimpleHtml.xslt"); HTMLViewer view = new HTMLViewer(owner, tmp.toURL()); view.setModal(true); view.setVisible(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } tmp.delete(); } }); } { jSeparator2 = new JSeparator(); fileMenu.add(jSeparator2); } { exitMenuItem = new JMenuItem(); fileMenu.add(exitMenuItem); exitMenuItem.setText("Exit"); exitMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_Q, ActionEvent.CTRL_MASK)); final JFrame owner = this; exitMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // exit program processWindowEvent(new WindowEvent(owner,WindowEvent.WINDOW_CLOSING)); System.exit(0); } }); } } { jMenu4 = new JMenu(); jMenuBar1.add(jMenu4); jMenu4.setText("Edit"); { final JFrame owner = this; editPrefsMenuItem = new JMenuItem(); jMenu4.add(editPrefsMenuItem); editPrefsMenuItem.setText("Preferences..."); editPrefsMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { PreferencesDialog d = new PreferencesDialog(owner, preferences); d.setVisible(true); } }); } { jSeparator1 = new JSeparator(); jMenu4.add(jSeparator1); } { deleteMenuItem = new JMenuItem(); jMenu4.add(deleteMenuItem); deleteMenuItem.setText("Delete"); deleteMenuItem.setEnabled(false); } } { mnuTools = new JMenu(); jMenuBar1.add(mnuTools); mnuTools.setText("Tools"); { final JFrame owner = this; JMenuItem scalRecipeMenuItem = new JMenuItem(); mnuTools.add(scalRecipeMenuItem); scalRecipeMenuItem.setText("Scale Recipe..."); scalRecipeMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_R, ActionEvent.CTRL_MASK)); scalRecipeMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { ScaleRecipeDialog scaleRecipe = new ScaleRecipeDialog(owner); scaleRecipe.setModal(true); scaleRecipe.setVisible(true); } }); JMenuItem maltPercentMenuItem = new JMenuItem(); mnuTools.add(maltPercentMenuItem); maltPercentMenuItem.setText("Malt Percent..."); maltPercentMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_M, ActionEvent.CTRL_MASK)); maltPercentMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { MaltPercentDialog maltPercent = new MaltPercentDialog(owner); maltPercent.setModal(true); maltPercent.setVisible(true); } }); } } { jMenu5 = new JMenu(); jMenuBar1.add(jMenu5); jMenu5.setText("Help"); { helpMenuItem = new JMenuItem(); jMenu5.add(helpMenuItem); helpMenuItem.setText("Help"); final JFrame owner = this; helpMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { URL help; try { help = new File(appRoot + "/help/index.html").toURL(); HTMLViewer view = new HTMLViewer(owner, help); view.setModal(true); view.setVisible(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); } { aboutMenuItem = new JMenuItem(); jMenu5.add(aboutMenuItem); aboutMenuItem.setText("About..."); final JFrame owner = this; aboutMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { aboutDlg = new AboutDialog(owner, version); aboutDlg.setVisible(true); } }); } } } } catch (Exception e) { e.printStackTrace(); } }
private void initGUI() { try { // restore the saved size and location: this.setSize(preferences.getIProperty("winWidth"), preferences.getIProperty("winHeight")); this.setLocation(preferences.getIProperty("winX"), preferences.getIProperty("winY")); imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/sb2.gif"); icon = new ImageIcon(imgURL); this.setIconImage(icon.getImage()); this.setTitle("StrangeBrew " + version); this.addWindowListener(new WindowAdapter() { public void windowClosed(WindowEvent evt) { System.exit(1); } }); { pnlMain = new JPanel(); GridBagLayout jPanel2Layout = new GridBagLayout(); jPanel2Layout.columnWeights = new double[]{0.1}; jPanel2Layout.columnWidths = new int[]{7}; jPanel2Layout.rowWeights = new double[]{0.1, 0.1, 0.9, 0.1}; jPanel2Layout.rowHeights = new int[]{7, 7, 7, 7}; pnlMain.setLayout(jPanel2Layout); this.getContentPane().add(pnlMain, BorderLayout.CENTER); { jTabbedPane1 = new JTabbedPane(); pnlMain.add(jTabbedPane1, new GridBagConstraints(0, 1, 1, 1, 0.1, 0.1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); { pnlDetails = new JPanel(); GridBagLayout pnlDetailsLayout = new GridBagLayout(); pnlDetailsLayout.columnWeights = new double[]{0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1}; pnlDetailsLayout.columnWidths = new int[]{7, 7, 7, 7, 7, 7, 7, 7, 7, 7}; pnlDetailsLayout.rowWeights = new double[]{0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1}; pnlDetailsLayout.rowHeights = new int[]{7, 7, 7, 7, 7, 7, 7}; pnlDetails.setLayout(pnlDetailsLayout); jTabbedPane1.addTab("Details", null, pnlDetails, null); pnlDetails.setPreferredSize(new java.awt.Dimension(20, 16)); { lblBrewer = new JLabel(); pnlDetails.add(lblBrewer, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblBrewer.setText("Brewer:"); } { brewerNameText = new JTextField(); pnlDetails.add(brewerNameText, new GridBagConstraints(1, 0, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); brewerNameText.setPreferredSize(new java.awt.Dimension(69, 20)); brewerNameText.setText("Brewer"); } { lblDate = new JLabel(); pnlDetails.add(lblDate, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblDate.setText("Date:"); } { lblStyle = new JLabel(); pnlDetails.add(lblStyle, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblStyle.setText("Style:"); } { lblYeast = new JLabel(); pnlDetails.add(lblYeast, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblYeast.setText("Yeast:"); } { lblPreBoil = new JLabel(); pnlDetails.add(lblPreBoil, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblPreBoil.setText("Pre boil:"); } { lblPostBoil = new JLabel(); pnlDetails.add(lblPostBoil, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblPostBoil.setText("Post boil:"); } { lblEffic = new JLabel(); pnlDetails.add(lblEffic, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblEffic.setText("Effic:"); lblEffic.setPreferredSize(new java.awt.Dimension(31, 14)); } { lblAtten = new JLabel(); pnlDetails.add(lblAtten, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblAtten.setText("Atten:"); lblAtten.setPreferredSize(new java.awt.Dimension(34, 14)); } { lblOG = new JLabel(); pnlDetails.add(lblOG, new GridBagConstraints(5, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblOG.setText("OG:"); } { lblFG = new JLabel(); pnlDetails.add(lblFG, new GridBagConstraints(5, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblFG.setText("FG:"); } { lblIBU = new JLabel(); pnlDetails.add(lblIBU, new GridBagConstraints(7, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblIBU.setText("IBU:"); } { lblAlc = new JLabel(); pnlDetails.add(lblAlc, new GridBagConstraints(7, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblAlc.setText("%Alc:"); } { lblColour = new JLabel(); pnlDetails.add(lblColour, new GridBagConstraints(7, 2, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblColour.setText("Colour:"); } { //txtDate = new JFormattedTextField(); txtDate = new DatePicker(); pnlDetails.add(txtDate, new GridBagConstraints(1, 1, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); // txtDate.setText("Date"); txtDate.setPreferredSize(new java.awt.Dimension(73, 20)); txtDate.setDateStyle(DateFormat.SHORT); } { cmbStyleModel = new ComboModel(); cmbStyle = new JComboBox(); pnlDetails.add(cmbStyle, new GridBagConstraints(1, 2, 5, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cmbStyle.setModel(cmbStyleModel); cmbStyle.setMaximumSize(new java.awt.Dimension(100, 32767)); cmbStyle.setPreferredSize(new java.awt.Dimension(190, 20)); } { txtPreBoil = new JFormattedTextField(); pnlDetails.add(txtPreBoil, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); txtPreBoil.setText("Pre Boil"); txtPreBoil.setPreferredSize(new java.awt.Dimension(37, 20)); } { postBoilText = new JFormattedTextField(); pnlDetails.add(postBoilText, new GridBagConstraints(1, 5, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); postBoilText.setText("Post Boil"); postBoilText.setPreferredSize(new java.awt.Dimension(46, 20)); } { lblComments = new JLabel(); pnlDetails.add(lblComments, new GridBagConstraints(6, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblComments.setText("Comments:"); } { SpinnerNumberModel spnEfficModel = new SpinnerNumberModel(75.0, 0.0, 100.0, 1.0); spnEffic = new JSpinner(); pnlDetails.add(spnEffic, new GridBagConstraints(4, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnEffic.setModel(spnEfficModel); spnEffic.setMaximumSize(new java.awt.Dimension(70, 32767)); spnEffic.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { myRecipe.setEfficiency(Double.parseDouble(spnEffic.getValue() .toString())); displayRecipe(); } }); spnEffic.setEditor(new JSpinner.NumberEditor(spnEffic, "00.#")); spnEffic.getEditor().setPreferredSize(new java.awt.Dimension(28, 16)); spnEffic.setPreferredSize(new java.awt.Dimension(53, 18)); } { SpinnerNumberModel spnAttenModel = new SpinnerNumberModel(75.0, 0.0, 100.0, 1.0); spnAtten = new JSpinner(); pnlDetails.add(spnAtten, new GridBagConstraints(4, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnAtten.setModel(spnAttenModel); spnAtten.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { myRecipe.setAttenuation(Double.parseDouble(spnAtten.getValue() .toString())); displayRecipe(); } }); spnAtten.setEditor(new JSpinner.NumberEditor(spnAtten, "00.#")); spnAtten.setPreferredSize(new java.awt.Dimension(49, 20)); } { SpinnerNumberModel spnOgModel = new SpinnerNumberModel(1.000, 0.900, 2.000, 0.001); spnOG = new JSpinner(); pnlDetails.add(spnOG, new GridBagConstraints(6, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnOG.setModel(spnOgModel); spnOG.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { myRecipe.setEstOg(Double.parseDouble(spnOG.getValue() .toString())); displayRecipe(); } }); spnOG.setEditor(new JSpinner.NumberEditor(spnOG, "0.000")); spnOG.getEditor().setPreferredSize(new java.awt.Dimension(20, 16)); spnOG.setPreferredSize(new java.awt.Dimension(67, 18)); } { SpinnerNumberModel spnFgModel = new SpinnerNumberModel(1.000, 0.900, 2.000, 0.001); spnFG = new JSpinner(); pnlDetails.add(spnFG, new GridBagConstraints(6, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnFG.setModel(spnFgModel); spnFG.setEditor(new JSpinner.NumberEditor(spnFG, "0.000")); spnFG.setPreferredSize(new java.awt.Dimension(69, 20)); spnFG.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { // set the new FG, and update alc: myRecipe.setEstFg(Double.parseDouble(spnFG.getValue() .toString())); displayRecipe(); } }); } { lblIBUvalue = new JLabel(); pnlDetails.add(lblIBUvalue, new GridBagConstraints(8, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblIBUvalue.setText("IBUs"); } { lblColourValue = new JLabel(); pnlDetails.add(lblColourValue, new GridBagConstraints(8, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblColourValue.setText("Colour"); } { lblAlcValue = new JLabel(); pnlDetails.add(lblAlcValue, new GridBagConstraints(8, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblAlcValue.setText("Alc"); } { scpComments = new JScrollPane(); pnlDetails.add(scpComments, new GridBagConstraints(7, 4, 3, 2, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); { txtComments = new JTextArea(); scpComments.setViewportView(txtComments); txtComments.setText("Comments"); txtComments.setWrapStyleWord(true); // txtComments.setPreferredSize(new java.awt.Dimension(117, 42)); txtComments.setLineWrap(true); txtComments.setPreferredSize(new java.awt.Dimension(263, 40)); txtComments.addFocusListener(new FocusAdapter() { public void focusLost(FocusEvent evt) { if (!txtComments.getText().equals(myRecipe.getComments())) { myRecipe.setComments(txtComments.getText()); } } }); } } { cmbYeastModel = new ComboModel(); cmbYeast = new JComboBox(); pnlDetails.add(cmbYeast, new GridBagConstraints(1, 3, 5, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cmbYeast.setModel(cmbYeastModel); cmbYeast.setPreferredSize(new java.awt.Dimension(193, 20)); } { cmbSizeUnitsModel = new ComboModel(); cmbSizeUnits = new JComboBox(); pnlDetails.add(cmbSizeUnits, new GridBagConstraints(2, 4, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cmbSizeUnits.setModel(cmbSizeUnitsModel); } { lblSizeUnits = new JLabel(); pnlDetails.add(lblSizeUnits, new GridBagConstraints(2, 5, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); lblSizeUnits.setText("Size Units"); } { boilTimeLable = new JLabel(); pnlDetails.add(boilTimeLable, new GridBagConstraints(4, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); boilTimeLable.setText("Boil Min:"); } { evapLabel = new JLabel(); pnlDetails.add(evapLabel, new GridBagConstraints(4, 5, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); evapLabel.setText("Evap/hr:"); } { boilMinText = new JTextField(); pnlDetails.add(boilMinText, new GridBagConstraints(5, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); boilMinText.setText("60"); boilMinText.setPreferredSize(new java.awt.Dimension(22, 20)); } { evapText = new JTextField(); pnlDetails.add(evapText, new GridBagConstraints(5, 5, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); evapText.setText("4"); evapText.setPreferredSize(new java.awt.Dimension(23, 20)); } { alcMethodComboModel = new DefaultComboBoxModel(new String[]{"Volume", "Weight"}); alcMethodCombo = new JComboBox(alcMethodComboModel); pnlDetails.add(alcMethodCombo, new GridBagConstraints(9, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); alcMethodCombo.setPreferredSize(new java.awt.Dimension(58, 20)); } { ibuMethodComboModel = new DefaultComboBoxModel(new String[]{"Tinseth", "Garetz", "Rager"}); ibuMethodCombo = new JComboBox(ibuMethodComboModel); pnlDetails.add(ibuMethodCombo, new GridBagConstraints(9, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); ibuMethodCombo.setPreferredSize(new java.awt.Dimension(59, 20)); } { colourMethodComboModel = new DefaultComboBoxModel(new String[]{"SRM", "EBC"}); colourMethodCombo = new JComboBox(colourMethodComboModel); pnlDetails.add(colourMethodCombo, new GridBagConstraints(9, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); colourMethodCombo.setPreferredSize(new java.awt.Dimension(44, 20)); } ComboBoxModel evapMethodComboModel = new DefaultComboBoxModel(new String[] { "Constant", "Percent" }); { jPanel1 = new JPanel(); pnlMain.add(jPanel1, new GridBagConstraints( 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); FlowLayout jPanel1Layout = new FlowLayout(); jPanel1Layout.setAlignment(FlowLayout.LEFT); jPanel1.setLayout(jPanel1Layout); jToolBar1 = new JToolBar(); getContentPane().add(jToolBar1, BorderLayout.NORTH); jToolBar1.setFloatable(false); jToolBar1.setRollover(true); jButton1 = new JButton(); jToolBar1.add(jButton1); jButton1.setMnemonic(java.awt.event.KeyEvent.VK_S); jButton1.setIcon(new ImageIcon(getClass().getClassLoader().getResource( "ca/strangebrew/icons/save.gif"))); jButton1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { System.out.println("jButton1.actionPerformed, event=" + evt); //TODO add your code for jButton1.actionPerformed } }); jButton2 = new JButton(); jToolBar1.add(jButton2); jButton2.setIcon(new ImageIcon(getClass().getClassLoader().getResource( "ca/strangebrew/icons/find.gif"))); jButton2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { System.out.println("jButton2.actionPerformed, event=" + evt); //TODO add your code for jButton2.actionPerformed } }); { lblName = new JLabel(); jPanel1.add(lblName); lblName.setText("Name:"); } { txtName = new JTextField(); jPanel1.add(txtName); txtName.setText("Name"); txtName.setPreferredSize(new java.awt.Dimension(297, 20)); } } evapMethodCombo = new JComboBox(); pnlDetails.add(evapMethodCombo, new GridBagConstraints(6, 5, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); evapMethodCombo.setModel(evapMethodComboModel); evapMethodCombo.setPreferredSize(new java.awt.Dimension(64, 20)); colourPanel = new JPanel(); pnlDetails.add(colourPanel, new GridBagConstraints(9, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); colourPanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); } { SBNotifier sbn = new SBNotifier(); stylePanel = new StylePanel(sbn); jTabbedPane1.addTab("Style", null, stylePanel, null); miscPanel = new MiscPanel(myRecipe); jTabbedPane1.addTab("Misc", null, miscPanel, null); notesPanel = new NotesPanel(); jTabbedPane1.addTab("Notes", null, notesPanel, null); dilutionPanel = new DilutionPanel(); jTabbedPane1.addTab("Dilution", null, dilutionPanel, null); mashPanel = new MashPanel(myRecipe); jTabbedPane1.addTab("Mash", null, mashPanel, null); waterPanel = new WaterPanel(); jTabbedPane1.addTab("Water", null, waterPanel, null); costPanel = new CostPanel(); jTabbedPane1.addTab("Cost", null, costPanel, null); // SBNotifier sbn = new SBNotifier(); settingsPanel = new SettingsPanel(sbn); jTabbedPane1.addTab("Settings", null, settingsPanel, null); } } { pnlTables = new JPanel(); BoxLayout pnlMaltsLayout = new BoxLayout(pnlTables, javax.swing.BoxLayout.Y_AXIS); pnlMain.add(pnlTables, new GridBagConstraints(0, 2, 1, 1, 0.5, 0.5, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); pnlTables.setLayout(pnlMaltsLayout); { pnlMalt = new JPanel(); pnlTables.add(pnlMalt); BorderLayout pnlMaltLayout1 = new BorderLayout(); pnlMalt.setBorder(BorderFactory.createTitledBorder(new LineBorder( new java.awt.Color(0, 0, 0), 1, false), "Fermentables", TitledBorder.LEADING, TitledBorder.TOP, new java.awt.Font("Dialog", 1, 12), new java.awt.Color(51, 51, 51))); pnlMalt.setLayout(pnlMaltLayout1); { jScrollPane1 = new JScrollPane(); pnlMalt.add(jScrollPane1, BorderLayout.CENTER); { maltTableModel = new MaltTableModel(this); maltTable = new JTable() { public String getToolTipText(MouseEvent e) { java.awt.Point p = e.getPoint(); int rowIndex = rowAtPoint(p); return SBStringUtils.multiLineToolTip(40, maltTableModel .getDescriptionAt(rowIndex)); } }; jScrollPane1.setViewportView(maltTable); maltTable.setModel(maltTableModel); // maltTable.setAutoCreateColumnsFromModel(false); maltTable.getTableHeader().setReorderingAllowed(false); TableColumn maltColumn = maltTable.getColumnModel().getColumn(2); // set up malt list combo maltComboBox = new JComboBox(); cmbMaltModel = new ComboModel(); maltComboBox.setModel(cmbMaltModel); maltColumn.setCellEditor(new DefaultCellEditor(maltComboBox)); // set up malt amount editor amountEditor = new SBCellEditor(new JTextField()); maltColumn = maltTable.getColumnModel().getColumn(1); maltColumn.setCellEditor(amountEditor); // set up malt units combo maltUnitsComboBox = new JComboBox(); cmbMaltUnitsModel = new ComboModel(); maltUnitsComboBox.setModel(cmbMaltUnitsModel); maltColumn = maltTable.getColumnModel().getColumn(2); maltColumn.setCellEditor(new DefaultCellEditor(maltUnitsComboBox)); } } { tblMaltTotalsModel = new DefaultTableModel(new String[][]{{""}}, new String[]{"Malt", "Amount", "Units", "Points", "Lov", "Cost/U", "%"}); tblMaltTotals = new JTable(); pnlMalt.add(tblMaltTotals, BorderLayout.SOUTH); tblMaltTotals.setModel(tblMaltTotalsModel); tblMaltTotals.getTableHeader().setEnabled(false); tblMaltTotals.setAutoCreateColumnsFromModel(false); // set up the units combobox maltTotalUnitsComboBox = new JComboBox(); maltTotalUnitsComboModel = new ComboModel(); maltTotalUnitsComboModel.setList(new Quantity().getListofUnits("weight")); maltTotalUnitsComboBox.setModel(maltTotalUnitsComboModel); TableColumn t = tblMaltTotals.getColumnModel().getColumn(2); t.setCellEditor(new DefaultCellEditor(maltTotalUnitsComboBox)); maltTotalUnitsComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { String u = (String) maltTotalUnitsComboModel.getSelectedItem(); if (myRecipe != null) { myRecipe.setMaltUnits(u); displayRecipe(); } } }); } } { pnlMaltButtons = new JPanel(); pnlTables.add(pnlMaltButtons); FlowLayout pnlMaltButtonsLayout = new FlowLayout(); pnlMaltButtonsLayout.setAlignment(FlowLayout.LEFT); pnlMaltButtonsLayout.setVgap(0); pnlMaltButtons.setLayout(pnlMaltButtonsLayout); pnlMaltButtons.setPreferredSize(new java.awt.Dimension(592, 27)); { tlbMalt = new JToolBar(); pnlMaltButtons.add(tlbMalt); tlbMalt.setPreferredSize(new java.awt.Dimension(386, 20)); tlbMalt.setFloatable(false); { btnAddMalt = new JButton(); tlbMalt.add(btnAddMalt); btnAddMalt.setText("+"); btnAddMalt.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { Fermentable f = new Fermentable(myRecipe.getMaltUnits()); myRecipe.addMalt(f); maltTable.updateUI(); displayRecipe(); } } }); } { btnDelMalt = new JButton(); tlbMalt.add(btnDelMalt); btnDelMalt.setText("-"); btnDelMalt.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { int i = maltTable.getSelectedRow(); myRecipe.delMalt(i); maltTable.updateUI(); displayRecipe(); } } }); } } } { pnlHops = new JPanel(); BorderLayout pnlHopsLayout = new BorderLayout(); pnlHops.setBorder(BorderFactory.createTitledBorder(new LineBorder( new java.awt.Color(0, 0, 0), 1, false), "Hops", TitledBorder.LEADING, TitledBorder.TOP, new java.awt.Font("Dialog", 1, 12), new java.awt.Color(51, 51, 51))); pnlHops.setLayout(pnlHopsLayout); pnlTables.add(pnlHops); { tblHopsTotalsModel = new DefaultTableModel(new String[][]{{""}}, new String[]{"1", "2", "3", "4", "5", "6", "7", "8", "9"}); tblHopsTotals = new JTable(); pnlHops.add(tblHopsTotals, BorderLayout.SOUTH); tblHopsTotals.setModel(tblHopsTotalsModel); tblHopsTotals.setAutoCreateColumnsFromModel(false); // set up the units combobox hopsTotalUnitsComboBox = new JComboBox(); hopsTotalUnitsComboModel = new ComboModel(); hopsTotalUnitsComboModel.setList(new Quantity().getListofUnits("weight")); hopsTotalUnitsComboBox.setModel(hopsTotalUnitsComboModel); TableColumn t = tblHopsTotals.getColumnModel().getColumn(4); t.setCellEditor(new DefaultCellEditor(hopsTotalUnitsComboBox)); hopsTotalUnitsComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { String u = (String) hopsTotalUnitsComboModel.getSelectedItem(); if (myRecipe != null) { myRecipe.setHopsUnits(u); displayRecipe(); } } }); } { jScrollPane2 = new JScrollPane(); pnlHops.add(jScrollPane2, BorderLayout.CENTER); { hopsTableModel = new HopsTableModel(this); hopsTable = new JTable() { public String getToolTipText(MouseEvent e) { java.awt.Point p = e.getPoint(); int rowIndex = rowAtPoint(p); return SBStringUtils.multiLineToolTip(40, hopsTableModel .getDescriptionAt(rowIndex)); } }; jScrollPane2.setViewportView(hopsTable); hopsTable.setModel(hopsTableModel); hopsTable.getTableHeader().setReorderingAllowed(false); TableColumn hopColumn = hopsTable.getColumnModel().getColumn(0); hopComboBox = new JComboBox(); cmbHopsModel = new ComboModel(); hopComboBox.setModel(cmbHopsModel); hopColumn.setCellEditor(new DefaultCellEditor(hopComboBox)); // set up hop units combo hopsUnitsComboBox = new JComboBox(); cmbHopsUnitsModel = new ComboModel(); hopsUnitsComboBox.setModel(cmbHopsUnitsModel); hopColumn = hopsTable.getColumnModel().getColumn(4); hopColumn.setCellEditor(new DefaultCellEditor(hopsUnitsComboBox)); // set up hop type combo String[] forms = {"Leaf", "Pellet", "Plug"}; JComboBox hopsFormComboBox = new JComboBox(forms); hopColumn = hopsTable.getColumnModel().getColumn(1); hopColumn.setCellEditor(new DefaultCellEditor(hopsFormComboBox)); // set up hop add combo String[] add = {"Boil", "FWH", "Dry", "Mash"}; JComboBox hopsAddComboBox = new JComboBox(add); hopColumn = hopsTable.getColumnModel().getColumn(5); hopColumn.setCellEditor(new DefaultCellEditor(hopsAddComboBox)); } } } { pnlHopsButtons = new JPanel(); FlowLayout pnlHopsButtonsLayout = new FlowLayout(); pnlHopsButtonsLayout.setAlignment(FlowLayout.LEFT); pnlHopsButtonsLayout.setVgap(0); pnlHopsButtons.setLayout(pnlHopsButtonsLayout); pnlTables.add(pnlHopsButtons); pnlHopsButtons.setPreferredSize(new java.awt.Dimension(512, 16)); { tlbHops = new JToolBar(); pnlHopsButtons.add(tlbHops); tlbHops.setPreferredSize(new java.awt.Dimension(413, 19)); tlbHops.setFloatable(false); { btnAddHop = new JButton(); tlbHops.add(btnAddHop); btnAddHop.setText("+"); btnAddHop.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { Hop h = new Hop(myRecipe.getHopUnits()); myRecipe.addHop(h); hopsTable.updateUI(); displayRecipe(); } } }); } { btnDelHop = new JButton(); tlbHops.add(btnDelHop); btnDelHop.setText("-"); btnDelHop.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { int i = hopsTable.getSelectedRow(); myRecipe.delHop(i); hopsTable.updateUI(); displayRecipe(); } } }); } } } } { statusPanel = new JPanel(); FlowLayout statusPanelLayout = new FlowLayout(); statusPanelLayout.setAlignment(FlowLayout.LEFT); statusPanelLayout.setHgap(2); statusPanelLayout.setVgap(2); statusPanel.setLayout(statusPanelLayout); pnlMain.add(statusPanel, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); { fileNamePanel = new JPanel(); statusPanel.add(fileNamePanel); fileNamePanel.setBorder(BorderFactory .createBevelBorder(BevelBorder.LOWERED)); { fileNameLabel = new JLabel(); fileNamePanel.add(fileNameLabel); fileNameLabel.setText("File Name"); fileNameLabel.setFont(new java.awt.Font("Dialog", 1, 10)); } } { ibuMethodPanel = new JPanel(); statusPanel.add(ibuMethodPanel); ibuMethodPanel.setBorder(BorderFactory .createBevelBorder(BevelBorder.LOWERED)); { ibuMethodLabel = new JLabel(); ibuMethodPanel.add(ibuMethodLabel); ibuMethodLabel.setText("IBU Method:"); ibuMethodLabel.setFont(new java.awt.Font("Dialog", 1, 10)); } } { alcMethodPanel = new JPanel(); statusPanel.add(alcMethodPanel); alcMethodPanel.setBorder(BorderFactory .createBevelBorder(BevelBorder.LOWERED)); { alcMethodLabel = new JLabel(); alcMethodPanel.add(alcMethodLabel); alcMethodLabel.setText("Alc Method:"); alcMethodLabel.setFont(new java.awt.Font("Dialog", 1, 10)); } } } } { jMenuBar1 = new JMenuBar(); setJMenuBar(jMenuBar1); { fileMenu = new JMenu(); jMenuBar1.add(fileMenu); fileMenu.setText("File"); { newFileMenuItem = new JMenuItem(); fileMenu.add(newFileMenuItem); newFileMenuItem.setText("New"); newFileMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // This is just a test right now to see that // stuff is changed. myRecipe = new Recipe(); myRecipe.setVersion(version); currentFile = null; attachRecipeData(); displayRecipe(); } }); } { openFileMenuItem = new JMenuItem(); fileMenu.add(openFileMenuItem); openFileMenuItem.setText("Open"); openFileMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_O, ActionEvent.CTRL_MASK)); openFileMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Show open dialog; this method does // not return until the dialog is closed String[] ext = {"xml", "qbrew", "rec"}; String desc = "StrangBrew and importable formats"; sbFileFilter openFileFilter = new sbFileFilter(ext, desc); // fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); fileChooser.setFileFilter(openFileFilter); int returnVal = fileChooser.showOpenDialog(jMenuBar1); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); Debug.print("Opening: " + file.getName() + ".\n"); OpenImport oi = new OpenImport(); myRecipe = oi.openFile(file); if (oi.getFileType().equals("")){ JOptionPane.showMessageDialog( null, "The file you've tried to open isn't a recognized format. \n" + "You can open: \n" + "StrangeBrew 1.x and Java files (.xml)\n" + "QBrew files (.qbrew)\n" + "BeerXML files (.xml)\n" + "Promash files (.rec)", "Unrecognized Format!", JOptionPane.INFORMATION_MESSAGE); } if (oi.getFileType().equals("beerxml")){ JOptionPane.showMessageDialog( null, "The file you've opened is in BeerXML format. It may contain \n" + "several recipes. Only the first recipe is opened. Use the Find \n" + "dialog to open other recipes in a BeerXML file.", "BeerXML!", JOptionPane.INFORMATION_MESSAGE); } myRecipe.setVersion(version); myRecipe.calcMaltTotals(); myRecipe.calcHopsTotals(); myRecipe.mash.calcMashSchedule(); checkIngredientsInDB(); attachRecipeData(); currentFile = file; displayRecipe(); } else { Debug.print("Open command cancelled by user.\n"); } } }); } { imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/find.gif"); icon = new ImageIcon(imgURL); findFileMenuItem = new JMenuItem("Find", icon); findFileMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_F, ActionEvent.CTRL_MASK)); fileMenu.add(findFileMenuItem); final JFrame owner = this; findFileMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // open the find dialog FindDialog fd = new FindDialog(owner); fd.setVisible(true); } }); } { imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/save.gif"); icon = new ImageIcon(imgURL); saveMenuItem = new JMenuItem("Save", icon); fileMenu.add(saveMenuItem); saveMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_S, ActionEvent.CTRL_MASK)); saveMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { int choice = 1; if (currentFile != null) { File file = currentFile; //This is where a real application would save the file. try { FileWriter out = new FileWriter(file); out.write(myRecipe.toXML()); out.close(); Debug.print("Saved: " + file.getAbsoluteFile()); currentFile = file; } catch (Exception e) { showError(e); } } // prompt to save if not already saved else { choice = JOptionPane.showConfirmDialog(null, "File not saved. Do you wish to save it?", "File note saved", JOptionPane.YES_NO_OPTION); } if (choice == 0) { // same as save as: saveAs(); } } }); } { imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/saveas.gif"); icon = new ImageIcon(imgURL); saveAsMenuItem = new JMenuItem("Save As ...", icon); fileMenu.add(saveAsMenuItem); saveAsMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // This is just a test right now to see that // stuff is changed. Debug.print(myRecipe.toXML()); saveAs(); } }); } { exportMenu = new JMenu(); fileMenu.add(exportMenu); exportMenu.setText("Export"); { exportHTMLmenu = new JMenuItem(); exportMenu.add(exportHTMLmenu); exportHTMLmenu.setText("HTML"); exportHTMLmenu.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Show save dialog; this method does // not return until the dialog is closed String[] ext = {"html", "htm"}; sbFileFilter saveFileFilter = new sbFileFilter(ext, "HTML"); fileChooser.setFileFilter(saveFileFilter); fileChooser.setSelectedFile(new File(myRecipe.getName() + ".html")); int returnVal = fileChooser.showSaveDialog(jMenuBar1); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); //This is where a real application would save the file. try { saveAsHTML(file, "ca/strangebrew/data/recipeToHtml.xslt"); } catch (Exception e) { showError(e); } } else { Debug.print("Save command cancelled by user.\n"); } } }); exportTextMenuItem = new JMenuItem(); exportMenu.add(exportTextMenuItem); exportTextMenuItem.setText("Text"); exportTextMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Show save dialog; this method does // not return until the dialog is closed String[] ext = {"txt"}; sbFileFilter saveFileFilter = new sbFileFilter(ext, "Text"); fileChooser.setFileFilter(saveFileFilter); fileChooser.setSelectedFile(new File(myRecipe.getName() + ".txt")); int returnVal = fileChooser.showSaveDialog(jMenuBar1); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); //This is where a real application would save the file. try { FileWriter out = new FileWriter(file); out.write(myRecipe.toText()); out.close(); } catch (Exception e) { showError(e); } } else { Debug.print("Export text command cancelled by user.\n"); } } }); } } { JMenuItem clipboardMenuItem = new JMenuItem("Copy to Clipboard"); fileMenu.add(clipboardMenuItem); clipboardMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Copy current recipe to clipboard Clipboard clipboard = getToolkit ().getSystemClipboard (); StringSelection s = new StringSelection(myRecipe.toText()); clipboard.setContents(s, s); } }); JMenuItem printMenuItem = new JMenuItem("Print..."); fileMenu.add(printMenuItem); final JFrame owner = this; printMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Copy current recipe to clipboard// save file as xml, then transform it to html File tmp = new File("tmp.html"); try { saveAsHTML(tmp, "ca/strangebrew/data/recipeToSimpleHtml.xslt"); HTMLViewer view = new HTMLViewer(owner, tmp.toURL()); view.setModal(true); view.setVisible(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } tmp.delete(); } }); } { jSeparator2 = new JSeparator(); fileMenu.add(jSeparator2); } { exitMenuItem = new JMenuItem(); fileMenu.add(exitMenuItem); exitMenuItem.setText("Exit"); exitMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_Q, ActionEvent.CTRL_MASK)); final JFrame owner = this; exitMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // exit program processWindowEvent(new WindowEvent(owner,WindowEvent.WINDOW_CLOSING)); System.exit(0); } }); } } { jMenu4 = new JMenu(); jMenuBar1.add(jMenu4); jMenu4.setText("Edit"); { final JFrame owner = this; editPrefsMenuItem = new JMenuItem(); jMenu4.add(editPrefsMenuItem); editPrefsMenuItem.setText("Preferences..."); editPrefsMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { PreferencesDialog d = new PreferencesDialog(owner, preferences); d.setVisible(true); } }); } { jSeparator1 = new JSeparator(); jMenu4.add(jSeparator1); } { deleteMenuItem = new JMenuItem(); jMenu4.add(deleteMenuItem); deleteMenuItem.setText("Delete"); deleteMenuItem.setEnabled(false); } } { mnuTools = new JMenu(); jMenuBar1.add(mnuTools); mnuTools.setText("Tools"); { final JFrame owner = this; JMenuItem scalRecipeMenuItem = new JMenuItem(); mnuTools.add(scalRecipeMenuItem); scalRecipeMenuItem.setText("Scale Recipe..."); scalRecipeMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_R, ActionEvent.CTRL_MASK)); scalRecipeMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { ScaleRecipeDialog scaleRecipe = new ScaleRecipeDialog(owner); scaleRecipe.setModal(true); scaleRecipe.setVisible(true); } }); JMenuItem maltPercentMenuItem = new JMenuItem(); mnuTools.add(maltPercentMenuItem); maltPercentMenuItem.setText("Malt Percent..."); maltPercentMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_M, ActionEvent.CTRL_MASK)); maltPercentMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { MaltPercentDialog maltPercent = new MaltPercentDialog(owner); maltPercent.setModal(true); maltPercent.setVisible(true); } }); } } { jMenu5 = new JMenu(); jMenuBar1.add(jMenu5); jMenu5.setText("Help"); { helpMenuItem = new JMenuItem(); jMenu5.add(helpMenuItem); helpMenuItem.setText("Help"); final JFrame owner = this; helpMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { URL help; try { help = new File(appRoot + "/help/index.html").toURL(); HTMLViewer view = new HTMLViewer(owner, help); view.setModal(true); view.setVisible(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); } { aboutMenuItem = new JMenuItem(); jMenu5.add(aboutMenuItem); aboutMenuItem.setText("About..."); final JFrame owner = this; aboutMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { aboutDlg = new AboutDialog(owner, version); aboutDlg.setVisible(true); } }); } } } } catch (Exception e) { e.printStackTrace(); } }
1,115,275
private void initGUI() { try { // restore the saved size and location: this.setSize(preferences.getIProperty("winWidth"), preferences.getIProperty("winHeight")); this.setLocation(preferences.getIProperty("winX"), preferences.getIProperty("winY")); imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/sb2.gif"); icon = new ImageIcon(imgURL); this.setIconImage(icon.getImage()); this.setTitle("StrangeBrew " + version); this.addWindowListener(new WindowAdapter() { public void windowClosed(WindowEvent evt) { System.exit(1); } }); { pnlMain = new JPanel(); GridBagLayout jPanel2Layout = new GridBagLayout(); jPanel2Layout.columnWeights = new double[]{0.1}; jPanel2Layout.columnWidths = new int[]{7}; jPanel2Layout.rowWeights = new double[]{0.1, 0.1, 0.9, 0.1}; jPanel2Layout.rowHeights = new int[]{7, 7, 7, 7}; pnlMain.setLayout(jPanel2Layout); this.getContentPane().add(pnlMain, BorderLayout.CENTER); { jTabbedPane1 = new JTabbedPane(); pnlMain.add(jTabbedPane1, new GridBagConstraints(0, 1, 1, 1, 0.1, 0.1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); { pnlDetails = new JPanel(); GridBagLayout pnlDetailsLayout = new GridBagLayout(); pnlDetailsLayout.columnWeights = new double[]{0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1}; pnlDetailsLayout.columnWidths = new int[]{7, 7, 7, 7, 7, 7, 7, 7, 7, 7}; pnlDetailsLayout.rowWeights = new double[]{0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1}; pnlDetailsLayout.rowHeights = new int[]{7, 7, 7, 7, 7, 7, 7}; pnlDetails.setLayout(pnlDetailsLayout); jTabbedPane1.addTab("Details", null, pnlDetails, null); pnlDetails.setPreferredSize(new java.awt.Dimension(20, 16)); { lblBrewer = new JLabel(); pnlDetails.add(lblBrewer, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblBrewer.setText("Brewer:"); } { brewerNameText = new JTextField(); pnlDetails.add(brewerNameText, new GridBagConstraints(1, 0, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); brewerNameText.setPreferredSize(new java.awt.Dimension(69, 20)); brewerNameText.setText("Brewer"); } { lblDate = new JLabel(); pnlDetails.add(lblDate, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblDate.setText("Date:"); } { lblStyle = new JLabel(); pnlDetails.add(lblStyle, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblStyle.setText("Style:"); } { lblYeast = new JLabel(); pnlDetails.add(lblYeast, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblYeast.setText("Yeast:"); } { lblPreBoil = new JLabel(); pnlDetails.add(lblPreBoil, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblPreBoil.setText("Pre boil:"); } { lblPostBoil = new JLabel(); pnlDetails.add(lblPostBoil, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblPostBoil.setText("Post boil:"); } { lblEffic = new JLabel(); pnlDetails.add(lblEffic, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblEffic.setText("Effic:"); lblEffic.setPreferredSize(new java.awt.Dimension(31, 14)); } { lblAtten = new JLabel(); pnlDetails.add(lblAtten, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblAtten.setText("Atten:"); lblAtten.setPreferredSize(new java.awt.Dimension(34, 14)); } { lblOG = new JLabel(); pnlDetails.add(lblOG, new GridBagConstraints(5, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblOG.setText("OG:"); } { lblFG = new JLabel(); pnlDetails.add(lblFG, new GridBagConstraints(5, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblFG.setText("FG:"); } { lblIBU = new JLabel(); pnlDetails.add(lblIBU, new GridBagConstraints(7, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblIBU.setText("IBU:"); } { lblAlc = new JLabel(); pnlDetails.add(lblAlc, new GridBagConstraints(7, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblAlc.setText("%Alc:"); } { lblColour = new JLabel(); pnlDetails.add(lblColour, new GridBagConstraints(7, 2, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblColour.setText("Colour:"); } { //txtDate = new JFormattedTextField(); txtDate = new DatePicker(); pnlDetails.add(txtDate, new GridBagConstraints(1, 1, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); // txtDate.setText("Date"); txtDate.setPreferredSize(new java.awt.Dimension(73, 20)); txtDate.setDateStyle(DateFormat.SHORT); } { cmbStyleModel = new ComboModel(); cmbStyle = new JComboBox(); pnlDetails.add(cmbStyle, new GridBagConstraints(1, 2, 5, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cmbStyle.setModel(cmbStyleModel); cmbStyle.setMaximumSize(new java.awt.Dimension(100, 32767)); cmbStyle.setPreferredSize(new java.awt.Dimension(190, 20)); } { txtPreBoil = new JFormattedTextField(); pnlDetails.add(txtPreBoil, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); txtPreBoil.setText("Pre Boil"); txtPreBoil.setPreferredSize(new java.awt.Dimension(37, 20)); } { postBoilText = new JFormattedTextField(); pnlDetails.add(postBoilText, new GridBagConstraints(1, 5, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); postBoilText.setText("Post Boil"); postBoilText.setPreferredSize(new java.awt.Dimension(46, 20)); } { lblComments = new JLabel(); pnlDetails.add(lblComments, new GridBagConstraints(6, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblComments.setText("Comments:"); } { SpinnerNumberModel spnEfficModel = new SpinnerNumberModel(75.0, 0.0, 100.0, 1.0); spnEffic = new JSpinner(); pnlDetails.add(spnEffic, new GridBagConstraints(4, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnEffic.setModel(spnEfficModel); spnEffic.setMaximumSize(new java.awt.Dimension(70, 32767)); spnEffic.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { myRecipe.setEfficiency(Double.parseDouble(spnEffic.getValue() .toString())); displayRecipe(); } }); spnEffic.setEditor(new JSpinner.NumberEditor(spnEffic, "00.#")); spnEffic.getEditor().setPreferredSize(new java.awt.Dimension(28, 16)); spnEffic.setPreferredSize(new java.awt.Dimension(53, 18)); } { SpinnerNumberModel spnAttenModel = new SpinnerNumberModel(75.0, 0.0, 100.0, 1.0); spnAtten = new JSpinner(); pnlDetails.add(spnAtten, new GridBagConstraints(4, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnAtten.setModel(spnAttenModel); spnAtten.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { myRecipe.setAttenuation(Double.parseDouble(spnAtten.getValue() .toString())); displayRecipe(); } }); spnAtten.setEditor(new JSpinner.NumberEditor(spnAtten, "00.#")); spnAtten.setPreferredSize(new java.awt.Dimension(49, 20)); } { SpinnerNumberModel spnOgModel = new SpinnerNumberModel(1.000, 0.900, 2.000, 0.001); spnOG = new JSpinner(); pnlDetails.add(spnOG, new GridBagConstraints(6, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnOG.setModel(spnOgModel); spnOG.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { myRecipe.setEstOg(Double.parseDouble(spnOG.getValue() .toString())); displayRecipe(); } }); spnOG.setEditor(new JSpinner.NumberEditor(spnOG, "0.000")); spnOG.getEditor().setPreferredSize(new java.awt.Dimension(20, 16)); spnOG.setPreferredSize(new java.awt.Dimension(67, 18)); } { SpinnerNumberModel spnFgModel = new SpinnerNumberModel(1.000, 0.900, 2.000, 0.001); spnFG = new JSpinner(); pnlDetails.add(spnFG, new GridBagConstraints(6, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnFG.setModel(spnFgModel); spnFG.setEditor(new JSpinner.NumberEditor(spnFG, "0.000")); spnFG.setPreferredSize(new java.awt.Dimension(69, 20)); spnFG.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { // set the new FG, and update alc: myRecipe.setEstFg(Double.parseDouble(spnFG.getValue() .toString())); displayRecipe(); } }); } { lblIBUvalue = new JLabel(); pnlDetails.add(lblIBUvalue, new GridBagConstraints(8, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblIBUvalue.setText("IBUs"); } { lblColourValue = new JLabel(); pnlDetails.add(lblColourValue, new GridBagConstraints(8, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblColourValue.setText("Colour"); } { lblAlcValue = new JLabel(); pnlDetails.add(lblAlcValue, new GridBagConstraints(8, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblAlcValue.setText("Alc"); } { scpComments = new JScrollPane(); pnlDetails.add(scpComments, new GridBagConstraints(7, 4, 3, 2, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); { txtComments = new JTextArea(); scpComments.setViewportView(txtComments); txtComments.setText("Comments"); txtComments.setWrapStyleWord(true); // txtComments.setPreferredSize(new java.awt.Dimension(117, 42)); txtComments.setLineWrap(true); txtComments.setPreferredSize(new java.awt.Dimension(263, 40)); txtComments.addFocusListener(new FocusAdapter() { public void focusLost(FocusEvent evt) { if (!txtComments.getText().equals(myRecipe.getComments())) { myRecipe.setComments(txtComments.getText()); } } }); } } { cmbYeastModel = new ComboModel(); cmbYeast = new JComboBox(); pnlDetails.add(cmbYeast, new GridBagConstraints(1, 3, 5, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cmbYeast.setModel(cmbYeastModel); cmbYeast.setPreferredSize(new java.awt.Dimension(193, 20)); } { cmbSizeUnitsModel = new ComboModel(); cmbSizeUnits = new JComboBox(); pnlDetails.add(cmbSizeUnits, new GridBagConstraints(2, 4, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cmbSizeUnits.setModel(cmbSizeUnitsModel); } { lblSizeUnits = new JLabel(); pnlDetails.add(lblSizeUnits, new GridBagConstraints(2, 5, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); lblSizeUnits.setText("Size Units"); } { boilTimeLable = new JLabel(); pnlDetails.add(boilTimeLable, new GridBagConstraints(4, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); boilTimeLable.setText("Boil Min:"); } { evapLabel = new JLabel(); pnlDetails.add(evapLabel, new GridBagConstraints(4, 5, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); evapLabel.setText("Evap/hr:"); } { boilMinText = new JTextField(); pnlDetails.add(boilMinText, new GridBagConstraints(5, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); boilMinText.setText("60"); boilMinText.setPreferredSize(new java.awt.Dimension(22, 20)); } { evapText = new JTextField(); pnlDetails.add(evapText, new GridBagConstraints(5, 5, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); evapText.setText("4"); evapText.setPreferredSize(new java.awt.Dimension(23, 20)); } { alcMethodComboModel = new DefaultComboBoxModel(new String[]{"Volume", "Weight"}); alcMethodCombo = new JComboBox(alcMethodComboModel); pnlDetails.add(alcMethodCombo, new GridBagConstraints(9, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); alcMethodCombo.setPreferredSize(new java.awt.Dimension(58, 20)); } { ibuMethodComboModel = new DefaultComboBoxModel(new String[]{"Tinseth", "Garetz", "Rager"}); ibuMethodCombo = new JComboBox(ibuMethodComboModel); pnlDetails.add(ibuMethodCombo, new GridBagConstraints(9, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); ibuMethodCombo.setPreferredSize(new java.awt.Dimension(59, 20)); } { colourMethodComboModel = new DefaultComboBoxModel(new String[]{"SRM", "EBC"}); colourMethodCombo = new JComboBox(colourMethodComboModel); pnlDetails.add(colourMethodCombo, new GridBagConstraints(9, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); colourMethodCombo.setPreferredSize(new java.awt.Dimension(44, 20)); } ComboBoxModel evapMethodComboModel = new DefaultComboBoxModel(new String[] { "Constant", "Percent" }); { jPanel1 = new JPanel(); pnlMain.add(jPanel1, new GridBagConstraints( 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); FlowLayout jPanel1Layout = new FlowLayout(); jPanel1Layout.setAlignment(FlowLayout.LEFT); jPanel1.setLayout(jPanel1Layout); jToolBar1 = new JToolBar(); getContentPane().add(jToolBar1, BorderLayout.NORTH); jToolBar1.setFloatable(false); jToolBar1.setRollover(true); jButton1 = new JButton(); jToolBar1.add(jButton1); jButton1.setMnemonic(java.awt.event.KeyEvent.VK_S); jButton1.setIcon(new ImageIcon(getClass().getClassLoader().getResource( "ca/strangebrew/icons/save.gif"))); jButton1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { System.out.println("jButton1.actionPerformed, event=" + evt); //TODO add your code for jButton1.actionPerformed } }); jButton2 = new JButton(); jToolBar1.add(jButton2); jButton2.setIcon(new ImageIcon(getClass().getClassLoader().getResource( "ca/strangebrew/icons/find.gif"))); jButton2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { System.out.println("jButton2.actionPerformed, event=" + evt); //TODO add your code for jButton2.actionPerformed } }); { lblName = new JLabel(); jPanel1.add(lblName); lblName.setText("Name:"); } { txtName = new JTextField(); jPanel1.add(txtName); txtName.setText("Name"); txtName.setPreferredSize(new java.awt.Dimension(297, 20)); } } evapMethodCombo = new JComboBox(); pnlDetails.add(evapMethodCombo, new GridBagConstraints(6, 5, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); evapMethodCombo.setModel(evapMethodComboModel); evapMethodCombo.setPreferredSize(new java.awt.Dimension(64, 20)); colourPanel = new JPanel(); pnlDetails.add(colourPanel, new GridBagConstraints(9, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); colourPanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); } { SBNotifier sbn = new SBNotifier(); stylePanel = new StylePanel(sbn); jTabbedPane1.addTab("Style", null, stylePanel, null); miscPanel = new MiscPanel(myRecipe); jTabbedPane1.addTab("Misc", null, miscPanel, null); notesPanel = new NotesPanel(); jTabbedPane1.addTab("Notes", null, notesPanel, null); dilutionPanel = new DilutionPanel(); jTabbedPane1.addTab("Dilution", null, dilutionPanel, null); mashPanel = new MashPanel(myRecipe); jTabbedPane1.addTab("Mash", null, mashPanel, null); waterPanel = new WaterPanel(); jTabbedPane1.addTab("Water", null, waterPanel, null); costPanel = new CostPanel(); jTabbedPane1.addTab("Cost", null, costPanel, null); // SBNotifier sbn = new SBNotifier(); settingsPanel = new SettingsPanel(sbn); jTabbedPane1.addTab("Settings", null, settingsPanel, null); } } { pnlTables = new JPanel(); BoxLayout pnlMaltsLayout = new BoxLayout(pnlTables, javax.swing.BoxLayout.Y_AXIS); pnlMain.add(pnlTables, new GridBagConstraints(0, 2, 1, 1, 0.5, 0.5, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); pnlTables.setLayout(pnlMaltsLayout); { pnlMalt = new JPanel(); pnlTables.add(pnlMalt); BorderLayout pnlMaltLayout1 = new BorderLayout(); pnlMalt.setBorder(BorderFactory.createTitledBorder(new LineBorder( new java.awt.Color(0, 0, 0), 1, false), "Fermentables", TitledBorder.LEADING, TitledBorder.TOP, new java.awt.Font("Dialog", 1, 12), new java.awt.Color(51, 51, 51))); pnlMalt.setLayout(pnlMaltLayout1); { jScrollPane1 = new JScrollPane(); pnlMalt.add(jScrollPane1, BorderLayout.CENTER); { maltTableModel = new MaltTableModel(this); maltTable = new JTable() { public String getToolTipText(MouseEvent e) { java.awt.Point p = e.getPoint(); int rowIndex = rowAtPoint(p); return SBStringUtils.multiLineToolTip(40, maltTableModel .getDescriptionAt(rowIndex)); } }; jScrollPane1.setViewportView(maltTable); maltTable.setModel(maltTableModel); // maltTable.setAutoCreateColumnsFromModel(false); maltTable.getTableHeader().setReorderingAllowed(false); TableColumn maltColumn = maltTable.getColumnModel().getColumn(0); // set up malt list combo maltComboBox = new JComboBox(); cmbMaltModel = new ComboModel(); maltComboBox.setModel(cmbMaltModel); maltColumn.setCellEditor(new DefaultCellEditor(maltComboBox)); // set up malt amount editor amountEditor = new SBCellEditor(new JTextField()); maltColumn = maltTable.getColumnModel().getColumn(1); maltColumn.setCellEditor(amountEditor); // set up malt units combo maltUnitsComboBox = new JComboBox(); cmbMaltUnitsModel = new ComboModel(); maltUnitsComboBox.setModel(cmbMaltUnitsModel); maltColumn = maltTable.getColumnModel().getColumn(2); maltColumn.setCellEditor(new DefaultCellEditor(maltUnitsComboBox)); } } { tblMaltTotalsModel = new DefaultTableModel(new String[][]{{""}}, new String[]{"Malt", "Amount", "Units", "Points", "Lov", "Cost/U", "%"}); tblMaltTotals = new JTable(); pnlMalt.add(tblMaltTotals, BorderLayout.SOUTH); tblMaltTotals.setModel(tblMaltTotalsModel); tblMaltTotals.getTableHeader().setEnabled(false); tblMaltTotals.setAutoCreateColumnsFromModel(false); // set up the units combobox maltTotalUnitsComboBox = new JComboBox(); maltTotalUnitsComboModel = new ComboModel(); maltTotalUnitsComboModel.setList(new Quantity().getListofUnits("weight")); maltTotalUnitsComboBox.setModel(maltTotalUnitsComboModel); TableColumn t = tblMaltTotals.getColumnModel().getColumn(2); t.setCellEditor(new DefaultCellEditor(maltTotalUnitsComboBox)); maltTotalUnitsComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { String u = (String) maltTotalUnitsComboModel.getSelectedItem(); if (myRecipe != null) { myRecipe.setMaltUnits(u); displayRecipe(); } } }); } } { pnlMaltButtons = new JPanel(); pnlTables.add(pnlMaltButtons); FlowLayout pnlMaltButtonsLayout = new FlowLayout(); pnlMaltButtonsLayout.setAlignment(FlowLayout.LEFT); pnlMaltButtonsLayout.setVgap(0); pnlMaltButtons.setLayout(pnlMaltButtonsLayout); pnlMaltButtons.setPreferredSize(new java.awt.Dimension(592, 27)); { tlbMalt = new JToolBar(); pnlMaltButtons.add(tlbMalt); tlbMalt.setPreferredSize(new java.awt.Dimension(386, 20)); tlbMalt.setFloatable(false); { btnAddMalt = new JButton(); tlbMalt.add(btnAddMalt); btnAddMalt.setText("+"); btnAddMalt.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { Fermentable f = new Fermentable(myRecipe.getMaltUnits()); myRecipe.addMalt(f); maltTable.updateUI(); displayRecipe(); } } }); } { btnDelMalt = new JButton(); tlbMalt.add(btnDelMalt); btnDelMalt.setText("-"); btnDelMalt.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { int i = maltTable.getSelectedRow(); myRecipe.delMalt(i); maltTable.updateUI(); displayRecipe(); } } }); } } } { pnlHops = new JPanel(); BorderLayout pnlHopsLayout = new BorderLayout(); pnlHops.setBorder(BorderFactory.createTitledBorder(new LineBorder( new java.awt.Color(0, 0, 0), 1, false), "Hops", TitledBorder.LEADING, TitledBorder.TOP, new java.awt.Font("Dialog", 1, 12), new java.awt.Color(51, 51, 51))); pnlHops.setLayout(pnlHopsLayout); pnlTables.add(pnlHops); { tblHopsTotalsModel = new DefaultTableModel(new String[][]{{""}}, new String[]{"1", "2", "3", "4", "5", "6", "7", "8", "9"}); tblHopsTotals = new JTable(); pnlHops.add(tblHopsTotals, BorderLayout.SOUTH); tblHopsTotals.setModel(tblHopsTotalsModel); tblHopsTotals.setAutoCreateColumnsFromModel(false); // set up the units combobox hopsTotalUnitsComboBox = new JComboBox(); hopsTotalUnitsComboModel = new ComboModel(); hopsTotalUnitsComboModel.setList(new Quantity().getListofUnits("weight")); hopsTotalUnitsComboBox.setModel(hopsTotalUnitsComboModel); TableColumn t = tblHopsTotals.getColumnModel().getColumn(4); t.setCellEditor(new DefaultCellEditor(hopsTotalUnitsComboBox)); hopsTotalUnitsComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { String u = (String) hopsTotalUnitsComboModel.getSelectedItem(); if (myRecipe != null) { myRecipe.setHopsUnits(u); displayRecipe(); } } }); } { jScrollPane2 = new JScrollPane(); pnlHops.add(jScrollPane2, BorderLayout.CENTER); { hopsTableModel = new HopsTableModel(this); hopsTable = new JTable() { public String getToolTipText(MouseEvent e) { java.awt.Point p = e.getPoint(); int rowIndex = rowAtPoint(p); return SBStringUtils.multiLineToolTip(40, hopsTableModel .getDescriptionAt(rowIndex)); } }; jScrollPane2.setViewportView(hopsTable); hopsTable.setModel(hopsTableModel); hopsTable.getTableHeader().setReorderingAllowed(false); TableColumn hopColumn = hopsTable.getColumnModel().getColumn(0); hopComboBox = new JComboBox(); cmbHopsModel = new ComboModel(); hopComboBox.setModel(cmbHopsModel); hopColumn.setCellEditor(new DefaultCellEditor(hopComboBox)); // set up hop units combo hopsUnitsComboBox = new JComboBox(); cmbHopsUnitsModel = new ComboModel(); hopsUnitsComboBox.setModel(cmbHopsUnitsModel); hopColumn = hopsTable.getColumnModel().getColumn(4); hopColumn.setCellEditor(new DefaultCellEditor(hopsUnitsComboBox)); // set up hop type combo String[] forms = {"Leaf", "Pellet", "Plug"}; JComboBox hopsFormComboBox = new JComboBox(forms); hopColumn = hopsTable.getColumnModel().getColumn(1); hopColumn.setCellEditor(new DefaultCellEditor(hopsFormComboBox)); // set up hop add combo String[] add = {"Boil", "FWH", "Dry", "Mash"}; JComboBox hopsAddComboBox = new JComboBox(add); hopColumn = hopsTable.getColumnModel().getColumn(5); hopColumn.setCellEditor(new DefaultCellEditor(hopsAddComboBox)); } } } { pnlHopsButtons = new JPanel(); FlowLayout pnlHopsButtonsLayout = new FlowLayout(); pnlHopsButtonsLayout.setAlignment(FlowLayout.LEFT); pnlHopsButtonsLayout.setVgap(0); pnlHopsButtons.setLayout(pnlHopsButtonsLayout); pnlTables.add(pnlHopsButtons); pnlHopsButtons.setPreferredSize(new java.awt.Dimension(512, 16)); { tlbHops = new JToolBar(); pnlHopsButtons.add(tlbHops); tlbHops.setPreferredSize(new java.awt.Dimension(413, 19)); tlbHops.setFloatable(false); { btnAddHop = new JButton(); tlbHops.add(btnAddHop); btnAddHop.setText("+"); btnAddHop.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { Hop h = new Hop(myRecipe.getHopUnits()); myRecipe.addHop(h); hopsTable.updateUI(); displayRecipe(); } } }); } { btnDelHop = new JButton(); tlbHops.add(btnDelHop); btnDelHop.setText("-"); btnDelHop.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { int i = hopsTable.getSelectedRow(); myRecipe.delHop(i); hopsTable.updateUI(); displayRecipe(); } } }); } } } } { statusPanel = new JPanel(); FlowLayout statusPanelLayout = new FlowLayout(); statusPanelLayout.setAlignment(FlowLayout.LEFT); statusPanelLayout.setHgap(2); statusPanelLayout.setVgap(2); statusPanel.setLayout(statusPanelLayout); pnlMain.add(statusPanel, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); { fileNamePanel = new JPanel(); statusPanel.add(fileNamePanel); fileNamePanel.setBorder(BorderFactory .createBevelBorder(BevelBorder.LOWERED)); { fileNameLabel = new JLabel(); fileNamePanel.add(fileNameLabel); fileNameLabel.setText("File Name"); fileNameLabel.setFont(new java.awt.Font("Dialog", 1, 10)); } } { ibuMethodPanel = new JPanel(); statusPanel.add(ibuMethodPanel); ibuMethodPanel.setBorder(BorderFactory .createBevelBorder(BevelBorder.LOWERED)); { ibuMethodLabel = new JLabel(); ibuMethodPanel.add(ibuMethodLabel); ibuMethodLabel.setText("IBU Method:"); ibuMethodLabel.setFont(new java.awt.Font("Dialog", 1, 10)); } } { alcMethodPanel = new JPanel(); statusPanel.add(alcMethodPanel); alcMethodPanel.setBorder(BorderFactory .createBevelBorder(BevelBorder.LOWERED)); { alcMethodLabel = new JLabel(); alcMethodPanel.add(alcMethodLabel); alcMethodLabel.setText("Alc Method:"); alcMethodLabel.setFont(new java.awt.Font("Dialog", 1, 10)); } } } } { jMenuBar1 = new JMenuBar(); setJMenuBar(jMenuBar1); { fileMenu = new JMenu(); jMenuBar1.add(fileMenu); fileMenu.setText("File"); { newFileMenuItem = new JMenuItem(); fileMenu.add(newFileMenuItem); newFileMenuItem.setText("New"); newFileMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // This is just a test right now to see that // stuff is changed. myRecipe = new Recipe(); myRecipe.setVersion(version); currentFile = null; attachRecipeData(); displayRecipe(); } }); } { openFileMenuItem = new JMenuItem(); fileMenu.add(openFileMenuItem); openFileMenuItem.setText("Open"); openFileMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_O, ActionEvent.CTRL_MASK)); openFileMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Show open dialog; this method does // not return until the dialog is closed String[] ext = {"xml", "qbrew", "rec"}; String desc = "StrangBrew and importable formats"; sbFileFilter openFileFilter = new sbFileFilter(ext, desc); // fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); fileChooser.setFileFilter(openFileFilter); int returnVal = fileChooser.showOpenDialog(jMenuBar1); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); Debug.print("Opening: " + file.getName() + ".\n"); OpenImport oi = new OpenImport(); myRecipe = oi.openFile(file); if (oi.getFileType().equals("")){ JOptionPane.showMessageDialog( null, "The file you've tried to open isn't a recognized format. \n" + "You can open: \n" + "StrangeBrew 1.x and Java files (.xml)\n" + "QBrew files (.qbrew)\n" + "BeerXML files (.xml)\n" + "Promash files (.rec)", "Unrecognized Format!", JOptionPane.INFORMATION_MESSAGE); } if (oi.getFileType().equals("beerxml")){ JOptionPane.showMessageDialog( null, "The file you've opened is in BeerXML format. It may contain \n" + "several recipes. Only the first recipe is opened. Use the Find \n" + "dialog to open other recipes in a BeerXML file.", "BeerXML!", JOptionPane.INFORMATION_MESSAGE); } myRecipe.setVersion(version); myRecipe.calcMaltTotals(); myRecipe.calcHopsTotals(); myRecipe.mash.calcMashSchedule(); checkIngredientsInDB(); attachRecipeData(); currentFile = file; displayRecipe(); } else { Debug.print("Open command cancelled by user.\n"); } } }); } { imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/find.gif"); icon = new ImageIcon(imgURL); findFileMenuItem = new JMenuItem("Find", icon); findFileMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_F, ActionEvent.CTRL_MASK)); fileMenu.add(findFileMenuItem); final JFrame owner = this; findFileMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // open the find dialog FindDialog fd = new FindDialog(owner); fd.setVisible(true); } }); } { imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/save.gif"); icon = new ImageIcon(imgURL); saveMenuItem = new JMenuItem("Save", icon); fileMenu.add(saveMenuItem); saveMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_S, ActionEvent.CTRL_MASK)); saveMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { int choice = 1; if (currentFile != null) { File file = currentFile; //This is where a real application would save the file. try { FileWriter out = new FileWriter(file); out.write(myRecipe.toXML()); out.close(); Debug.print("Saved: " + file.getAbsoluteFile()); currentFile = file; } catch (Exception e) { showError(e); } } // prompt to save if not already saved else { choice = JOptionPane.showConfirmDialog(null, "File not saved. Do you wish to save it?", "File note saved", JOptionPane.YES_NO_OPTION); } if (choice == 0) { // same as save as: saveAs(); } } }); } { imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/saveas.gif"); icon = new ImageIcon(imgURL); saveAsMenuItem = new JMenuItem("Save As ...", icon); fileMenu.add(saveAsMenuItem); saveAsMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // This is just a test right now to see that // stuff is changed. Debug.print(myRecipe.toXML()); saveAs(); } }); } { exportMenu = new JMenu(); fileMenu.add(exportMenu); exportMenu.setText("Export"); { exportHTMLmenu = new JMenuItem(); exportMenu.add(exportHTMLmenu); exportHTMLmenu.setText("HTML"); exportHTMLmenu.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Show save dialog; this method does // not return until the dialog is closed String[] ext = {"html", "htm"}; sbFileFilter saveFileFilter = new sbFileFilter(ext, "HTML"); fileChooser.setFileFilter(saveFileFilter); fileChooser.setSelectedFile(new File(myRecipe.getName() + ".html")); int returnVal = fileChooser.showSaveDialog(jMenuBar1); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); //This is where a real application would save the file. try { saveAsHTML(file, "ca/strangebrew/data/recipeToHtml.xslt"); } catch (Exception e) { showError(e); } } else { Debug.print("Save command cancelled by user.\n"); } } }); exportTextMenuItem = new JMenuItem(); exportMenu.add(exportTextMenuItem); exportTextMenuItem.setText("Text"); exportTextMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Show save dialog; this method does // not return until the dialog is closed String[] ext = {"txt"}; sbFileFilter saveFileFilter = new sbFileFilter(ext, "Text"); fileChooser.setFileFilter(saveFileFilter); fileChooser.setSelectedFile(new File(myRecipe.getName() + ".txt")); int returnVal = fileChooser.showSaveDialog(jMenuBar1); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); //This is where a real application would save the file. try { FileWriter out = new FileWriter(file); out.write(myRecipe.toText()); out.close(); } catch (Exception e) { showError(e); } } else { Debug.print("Export text command cancelled by user.\n"); } } }); } } { JMenuItem clipboardMenuItem = new JMenuItem("Copy to Clipboard"); fileMenu.add(clipboardMenuItem); clipboardMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Copy current recipe to clipboard Clipboard clipboard = getToolkit ().getSystemClipboard (); StringSelection s = new StringSelection(myRecipe.toText()); clipboard.setContents(s, s); } }); JMenuItem printMenuItem = new JMenuItem("Print..."); fileMenu.add(printMenuItem); final JFrame owner = this; printMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Copy current recipe to clipboard// save file as xml, then transform it to html File tmp = new File("tmp.html"); try { saveAsHTML(tmp, "ca/strangebrew/data/recipeToSimpleHtml.xslt"); HTMLViewer view = new HTMLViewer(owner, tmp.toURL()); view.setModal(true); view.setVisible(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } tmp.delete(); } }); } { jSeparator2 = new JSeparator(); fileMenu.add(jSeparator2); } { exitMenuItem = new JMenuItem(); fileMenu.add(exitMenuItem); exitMenuItem.setText("Exit"); exitMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_Q, ActionEvent.CTRL_MASK)); final JFrame owner = this; exitMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // exit program processWindowEvent(new WindowEvent(owner,WindowEvent.WINDOW_CLOSING)); System.exit(0); } }); } } { jMenu4 = new JMenu(); jMenuBar1.add(jMenu4); jMenu4.setText("Edit"); { final JFrame owner = this; editPrefsMenuItem = new JMenuItem(); jMenu4.add(editPrefsMenuItem); editPrefsMenuItem.setText("Preferences..."); editPrefsMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { PreferencesDialog d = new PreferencesDialog(owner, preferences); d.setVisible(true); } }); } { jSeparator1 = new JSeparator(); jMenu4.add(jSeparator1); } { deleteMenuItem = new JMenuItem(); jMenu4.add(deleteMenuItem); deleteMenuItem.setText("Delete"); deleteMenuItem.setEnabled(false); } } { mnuTools = new JMenu(); jMenuBar1.add(mnuTools); mnuTools.setText("Tools"); { final JFrame owner = this; JMenuItem scalRecipeMenuItem = new JMenuItem(); mnuTools.add(scalRecipeMenuItem); scalRecipeMenuItem.setText("Scale Recipe..."); scalRecipeMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_R, ActionEvent.CTRL_MASK)); scalRecipeMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { ScaleRecipeDialog scaleRecipe = new ScaleRecipeDialog(owner); scaleRecipe.setModal(true); scaleRecipe.setVisible(true); } }); JMenuItem maltPercentMenuItem = new JMenuItem(); mnuTools.add(maltPercentMenuItem); maltPercentMenuItem.setText("Malt Percent..."); maltPercentMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_M, ActionEvent.CTRL_MASK)); maltPercentMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { MaltPercentDialog maltPercent = new MaltPercentDialog(owner); maltPercent.setModal(true); maltPercent.setVisible(true); } }); } } { jMenu5 = new JMenu(); jMenuBar1.add(jMenu5); jMenu5.setText("Help"); { helpMenuItem = new JMenuItem(); jMenu5.add(helpMenuItem); helpMenuItem.setText("Help"); final JFrame owner = this; helpMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { URL help; try { help = new File(appRoot + "/help/index.html").toURL(); HTMLViewer view = new HTMLViewer(owner, help); view.setModal(true); view.setVisible(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); } { aboutMenuItem = new JMenuItem(); jMenu5.add(aboutMenuItem); aboutMenuItem.setText("About..."); final JFrame owner = this; aboutMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { aboutDlg = new AboutDialog(owner, version); aboutDlg.setVisible(true); } }); } } } } catch (Exception e) { e.printStackTrace(); } }
private void initGUI() { try { // restore the saved size and location: this.setSize(preferences.getIProperty("winWidth"), preferences.getIProperty("winHeight")); this.setLocation(preferences.getIProperty("winX"), preferences.getIProperty("winY")); imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/sb2.gif"); icon = new ImageIcon(imgURL); this.setIconImage(icon.getImage()); this.setTitle("StrangeBrew " + version); this.addWindowListener(new WindowAdapter() { public void windowClosed(WindowEvent evt) { System.exit(1); } }); { pnlMain = new JPanel(); GridBagLayout jPanel2Layout = new GridBagLayout(); jPanel2Layout.columnWeights = new double[]{0.1}; jPanel2Layout.columnWidths = new int[]{7}; jPanel2Layout.rowWeights = new double[]{0.1, 0.1, 0.9, 0.1}; jPanel2Layout.rowHeights = new int[]{7, 7, 7, 7}; pnlMain.setLayout(jPanel2Layout); this.getContentPane().add(pnlMain, BorderLayout.CENTER); { jTabbedPane1 = new JTabbedPane(); pnlMain.add(jTabbedPane1, new GridBagConstraints(0, 1, 1, 1, 0.1, 0.1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); { pnlDetails = new JPanel(); GridBagLayout pnlDetailsLayout = new GridBagLayout(); pnlDetailsLayout.columnWeights = new double[]{0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1}; pnlDetailsLayout.columnWidths = new int[]{7, 7, 7, 7, 7, 7, 7, 7, 7, 7}; pnlDetailsLayout.rowWeights = new double[]{0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1}; pnlDetailsLayout.rowHeights = new int[]{7, 7, 7, 7, 7, 7, 7}; pnlDetails.setLayout(pnlDetailsLayout); jTabbedPane1.addTab("Details", null, pnlDetails, null); pnlDetails.setPreferredSize(new java.awt.Dimension(20, 16)); { lblBrewer = new JLabel(); pnlDetails.add(lblBrewer, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblBrewer.setText("Brewer:"); } { brewerNameText = new JTextField(); pnlDetails.add(brewerNameText, new GridBagConstraints(1, 0, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); brewerNameText.setPreferredSize(new java.awt.Dimension(69, 20)); brewerNameText.setText("Brewer"); } { lblDate = new JLabel(); pnlDetails.add(lblDate, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblDate.setText("Date:"); } { lblStyle = new JLabel(); pnlDetails.add(lblStyle, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblStyle.setText("Style:"); } { lblYeast = new JLabel(); pnlDetails.add(lblYeast, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblYeast.setText("Yeast:"); } { lblPreBoil = new JLabel(); pnlDetails.add(lblPreBoil, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblPreBoil.setText("Pre boil:"); } { lblPostBoil = new JLabel(); pnlDetails.add(lblPostBoil, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblPostBoil.setText("Post boil:"); } { lblEffic = new JLabel(); pnlDetails.add(lblEffic, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblEffic.setText("Effic:"); lblEffic.setPreferredSize(new java.awt.Dimension(31, 14)); } { lblAtten = new JLabel(); pnlDetails.add(lblAtten, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblAtten.setText("Atten:"); lblAtten.setPreferredSize(new java.awt.Dimension(34, 14)); } { lblOG = new JLabel(); pnlDetails.add(lblOG, new GridBagConstraints(5, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblOG.setText("OG:"); } { lblFG = new JLabel(); pnlDetails.add(lblFG, new GridBagConstraints(5, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblFG.setText("FG:"); } { lblIBU = new JLabel(); pnlDetails.add(lblIBU, new GridBagConstraints(7, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblIBU.setText("IBU:"); } { lblAlc = new JLabel(); pnlDetails.add(lblAlc, new GridBagConstraints(7, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblAlc.setText("%Alc:"); } { lblColour = new JLabel(); pnlDetails.add(lblColour, new GridBagConstraints(7, 2, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblColour.setText("Colour:"); } { //txtDate = new JFormattedTextField(); txtDate = new DatePicker(); pnlDetails.add(txtDate, new GridBagConstraints(1, 1, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); // txtDate.setText("Date"); txtDate.setPreferredSize(new java.awt.Dimension(73, 20)); txtDate.setDateStyle(DateFormat.SHORT); } { cmbStyleModel = new ComboModel(); cmbStyle = new JComboBox(); pnlDetails.add(cmbStyle, new GridBagConstraints(1, 2, 5, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cmbStyle.setModel(cmbStyleModel); cmbStyle.setMaximumSize(new java.awt.Dimension(100, 32767)); cmbStyle.setPreferredSize(new java.awt.Dimension(190, 20)); } { txtPreBoil = new JFormattedTextField(); pnlDetails.add(txtPreBoil, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); txtPreBoil.setText("Pre Boil"); txtPreBoil.setPreferredSize(new java.awt.Dimension(37, 20)); } { postBoilText = new JFormattedTextField(); pnlDetails.add(postBoilText, new GridBagConstraints(1, 5, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); postBoilText.setText("Post Boil"); postBoilText.setPreferredSize(new java.awt.Dimension(46, 20)); } { lblComments = new JLabel(); pnlDetails.add(lblComments, new GridBagConstraints(6, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblComments.setText("Comments:"); } { SpinnerNumberModel spnEfficModel = new SpinnerNumberModel(75.0, 0.0, 100.0, 1.0); spnEffic = new JSpinner(); pnlDetails.add(spnEffic, new GridBagConstraints(4, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnEffic.setModel(spnEfficModel); spnEffic.setMaximumSize(new java.awt.Dimension(70, 32767)); spnEffic.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { myRecipe.setEfficiency(Double.parseDouble(spnEffic.getValue() .toString())); displayRecipe(); } }); spnEffic.setEditor(new JSpinner.NumberEditor(spnEffic, "00.#")); spnEffic.getEditor().setPreferredSize(new java.awt.Dimension(28, 16)); spnEffic.setPreferredSize(new java.awt.Dimension(53, 18)); } { SpinnerNumberModel spnAttenModel = new SpinnerNumberModel(75.0, 0.0, 100.0, 1.0); spnAtten = new JSpinner(); pnlDetails.add(spnAtten, new GridBagConstraints(4, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnAtten.setModel(spnAttenModel); spnAtten.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { myRecipe.setAttenuation(Double.parseDouble(spnAtten.getValue() .toString())); displayRecipe(); } }); spnAtten.setEditor(new JSpinner.NumberEditor(spnAtten, "00.#")); spnAtten.setPreferredSize(new java.awt.Dimension(49, 20)); } { SpinnerNumberModel spnOgModel = new SpinnerNumberModel(1.000, 0.900, 2.000, 0.001); spnOG = new JSpinner(); pnlDetails.add(spnOG, new GridBagConstraints(6, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnOG.setModel(spnOgModel); spnOG.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { myRecipe.setEstOg(Double.parseDouble(spnOG.getValue() .toString())); displayRecipe(); } }); spnOG.setEditor(new JSpinner.NumberEditor(spnOG, "0.000")); spnOG.getEditor().setPreferredSize(new java.awt.Dimension(20, 16)); spnOG.setPreferredSize(new java.awt.Dimension(67, 18)); } { SpinnerNumberModel spnFgModel = new SpinnerNumberModel(1.000, 0.900, 2.000, 0.001); spnFG = new JSpinner(); pnlDetails.add(spnFG, new GridBagConstraints(6, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnFG.setModel(spnFgModel); spnFG.setEditor(new JSpinner.NumberEditor(spnFG, "0.000")); spnFG.setPreferredSize(new java.awt.Dimension(69, 20)); spnFG.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { // set the new FG, and update alc: myRecipe.setEstFg(Double.parseDouble(spnFG.getValue() .toString())); displayRecipe(); } }); } { lblIBUvalue = new JLabel(); pnlDetails.add(lblIBUvalue, new GridBagConstraints(8, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblIBUvalue.setText("IBUs"); } { lblColourValue = new JLabel(); pnlDetails.add(lblColourValue, new GridBagConstraints(8, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblColourValue.setText("Colour"); } { lblAlcValue = new JLabel(); pnlDetails.add(lblAlcValue, new GridBagConstraints(8, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblAlcValue.setText("Alc"); } { scpComments = new JScrollPane(); pnlDetails.add(scpComments, new GridBagConstraints(7, 4, 3, 2, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); { txtComments = new JTextArea(); scpComments.setViewportView(txtComments); txtComments.setText("Comments"); txtComments.setWrapStyleWord(true); // txtComments.setPreferredSize(new java.awt.Dimension(117, 42)); txtComments.setLineWrap(true); txtComments.setPreferredSize(new java.awt.Dimension(263, 40)); txtComments.addFocusListener(new FocusAdapter() { public void focusLost(FocusEvent evt) { if (!txtComments.getText().equals(myRecipe.getComments())) { myRecipe.setComments(txtComments.getText()); } } }); } } { cmbYeastModel = new ComboModel(); cmbYeast = new JComboBox(); pnlDetails.add(cmbYeast, new GridBagConstraints(1, 3, 5, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cmbYeast.setModel(cmbYeastModel); cmbYeast.setPreferredSize(new java.awt.Dimension(193, 20)); } { cmbSizeUnitsModel = new ComboModel(); cmbSizeUnits = new JComboBox(); pnlDetails.add(cmbSizeUnits, new GridBagConstraints(2, 4, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cmbSizeUnits.setModel(cmbSizeUnitsModel); } { lblSizeUnits = new JLabel(); pnlDetails.add(lblSizeUnits, new GridBagConstraints(2, 5, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); lblSizeUnits.setText("Size Units"); } { boilTimeLable = new JLabel(); pnlDetails.add(boilTimeLable, new GridBagConstraints(4, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); boilTimeLable.setText("Boil Min:"); } { evapLabel = new JLabel(); pnlDetails.add(evapLabel, new GridBagConstraints(4, 5, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); evapLabel.setText("Evap/hr:"); } { boilMinText = new JTextField(); pnlDetails.add(boilMinText, new GridBagConstraints(5, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); boilMinText.setText("60"); boilMinText.setPreferredSize(new java.awt.Dimension(22, 20)); } { evapText = new JTextField(); pnlDetails.add(evapText, new GridBagConstraints(5, 5, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); evapText.setText("4"); evapText.setPreferredSize(new java.awt.Dimension(23, 20)); } { alcMethodComboModel = new DefaultComboBoxModel(new String[]{"Volume", "Weight"}); alcMethodCombo = new JComboBox(alcMethodComboModel); pnlDetails.add(alcMethodCombo, new GridBagConstraints(9, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); alcMethodCombo.setPreferredSize(new java.awt.Dimension(58, 20)); } { ibuMethodComboModel = new DefaultComboBoxModel(new String[]{"Tinseth", "Garetz", "Rager"}); ibuMethodCombo = new JComboBox(ibuMethodComboModel); pnlDetails.add(ibuMethodCombo, new GridBagConstraints(9, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); ibuMethodCombo.setPreferredSize(new java.awt.Dimension(59, 20)); } { colourMethodComboModel = new DefaultComboBoxModel(new String[]{"SRM", "EBC"}); colourMethodCombo = new JComboBox(colourMethodComboModel); pnlDetails.add(colourMethodCombo, new GridBagConstraints(9, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); colourMethodCombo.setPreferredSize(new java.awt.Dimension(44, 20)); } ComboBoxModel evapMethodComboModel = new DefaultComboBoxModel(new String[] { "Constant", "Percent" }); { jPanel1 = new JPanel(); pnlMain.add(jPanel1, new GridBagConstraints( 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); FlowLayout jPanel1Layout = new FlowLayout(); jPanel1Layout.setAlignment(FlowLayout.LEFT); jPanel1.setLayout(jPanel1Layout); jToolBar1 = new JToolBar(); getContentPane().add(jToolBar1, BorderLayout.NORTH); jToolBar1.setFloatable(false); jToolBar1.setRollover(true); jButton1 = new JButton(); jToolBar1.add(jButton1); jButton1.setMnemonic(java.awt.event.KeyEvent.VK_S); jButton1.setIcon(new ImageIcon(getClass().getClassLoader().getResource( "ca/strangebrew/icons/save.gif"))); jButton1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { System.out.println("jButton1.actionPerformed, event=" + evt); //TODO add your code for jButton1.actionPerformed } }); jButton2 = new JButton(); jToolBar1.add(jButton2); jButton2.setIcon(new ImageIcon(getClass().getClassLoader().getResource( "ca/strangebrew/icons/find.gif"))); jButton2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { System.out.println("jButton2.actionPerformed, event=" + evt); //TODO add your code for jButton2.actionPerformed } }); { lblName = new JLabel(); jPanel1.add(lblName); lblName.setText("Name:"); } { txtName = new JTextField(); jPanel1.add(txtName); txtName.setText("Name"); txtName.setPreferredSize(new java.awt.Dimension(297, 20)); } } evapMethodCombo = new JComboBox(); pnlDetails.add(evapMethodCombo, new GridBagConstraints(6, 5, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); evapMethodCombo.setModel(evapMethodComboModel); evapMethodCombo.setPreferredSize(new java.awt.Dimension(64, 20)); colourPanel = new JPanel(); pnlDetails.add(colourPanel, new GridBagConstraints(9, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); colourPanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); } { SBNotifier sbn = new SBNotifier(); stylePanel = new StylePanel(sbn); jTabbedPane1.addTab("Style", null, stylePanel, null); miscPanel = new MiscPanel(myRecipe); jTabbedPane1.addTab("Misc", null, miscPanel, null); notesPanel = new NotesPanel(); jTabbedPane1.addTab("Notes", null, notesPanel, null); dilutionPanel = new DilutionPanel(); jTabbedPane1.addTab("Dilution", null, dilutionPanel, null); mashPanel = new MashPanel(myRecipe); jTabbedPane1.addTab("Mash", null, mashPanel, null); waterPanel = new WaterPanel(); jTabbedPane1.addTab("Water", null, waterPanel, null); costPanel = new CostPanel(); jTabbedPane1.addTab("Cost", null, costPanel, null); // SBNotifier sbn = new SBNotifier(); settingsPanel = new SettingsPanel(sbn); jTabbedPane1.addTab("Settings", null, settingsPanel, null); } } { pnlTables = new JPanel(); BoxLayout pnlMaltsLayout = new BoxLayout(pnlTables, javax.swing.BoxLayout.Y_AXIS); pnlMain.add(pnlTables, new GridBagConstraints(0, 2, 1, 1, 0.5, 0.5, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); pnlTables.setLayout(pnlMaltsLayout); { pnlMalt = new JPanel(); pnlTables.add(pnlMalt); BorderLayout pnlMaltLayout1 = new BorderLayout(); pnlMalt.setBorder(BorderFactory.createTitledBorder(new LineBorder( new java.awt.Color(0, 0, 0), 1, false), "Fermentables", TitledBorder.LEADING, TitledBorder.TOP, new java.awt.Font("Dialog", 1, 12), new java.awt.Color(51, 51, 51))); pnlMalt.setLayout(pnlMaltLayout1); { jScrollPane1 = new JScrollPane(); pnlMalt.add(jScrollPane1, BorderLayout.CENTER); { maltTableModel = new MaltTableModel(this); maltTable = new JTable() { public String getToolTipText(MouseEvent e) { java.awt.Point p = e.getPoint(); int rowIndex = rowAtPoint(p); return SBStringUtils.multiLineToolTip(40, maltTableModel .getDescriptionAt(rowIndex)); } }; jScrollPane1.setViewportView(maltTable); maltTable.setModel(maltTableModel); // maltTable.setAutoCreateColumnsFromModel(false); maltTable.getTableHeader().setReorderingAllowed(false); TableColumn maltColumn = maltTable.getColumnModel().getColumn(0); // set up malt list combo maltComboBox = new JComboBox(); cmbMaltModel = new ComboModel(); maltComboBox.setModel(cmbMaltModel); maltColumn.setCellEditor(new DefaultCellEditor(maltComboBox)); // set up malt amount editor amountEditor = new SBCellEditor(new JTextField()); maltColumn = maltTable.getColumnModel().getColumn(3); maltColumn.setCellEditor(amountEditor); // set up malt units combo maltUnitsComboBox = new JComboBox(); cmbMaltUnitsModel = new ComboModel(); maltUnitsComboBox.setModel(cmbMaltUnitsModel); maltColumn = maltTable.getColumnModel().getColumn(2); maltColumn.setCellEditor(new DefaultCellEditor(maltUnitsComboBox)); } } { tblMaltTotalsModel = new DefaultTableModel(new String[][]{{""}}, new String[]{"Malt", "Amount", "Units", "Points", "Lov", "Cost/U", "%"}); tblMaltTotals = new JTable(); pnlMalt.add(tblMaltTotals, BorderLayout.SOUTH); tblMaltTotals.setModel(tblMaltTotalsModel); tblMaltTotals.getTableHeader().setEnabled(false); tblMaltTotals.setAutoCreateColumnsFromModel(false); // set up the units combobox maltTotalUnitsComboBox = new JComboBox(); maltTotalUnitsComboModel = new ComboModel(); maltTotalUnitsComboModel.setList(new Quantity().getListofUnits("weight")); maltTotalUnitsComboBox.setModel(maltTotalUnitsComboModel); TableColumn t = tblMaltTotals.getColumnModel().getColumn(2); t.setCellEditor(new DefaultCellEditor(maltTotalUnitsComboBox)); maltTotalUnitsComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { String u = (String) maltTotalUnitsComboModel.getSelectedItem(); if (myRecipe != null) { myRecipe.setMaltUnits(u); displayRecipe(); } } }); } } { pnlMaltButtons = new JPanel(); pnlTables.add(pnlMaltButtons); FlowLayout pnlMaltButtonsLayout = new FlowLayout(); pnlMaltButtonsLayout.setAlignment(FlowLayout.LEFT); pnlMaltButtonsLayout.setVgap(0); pnlMaltButtons.setLayout(pnlMaltButtonsLayout); pnlMaltButtons.setPreferredSize(new java.awt.Dimension(592, 27)); { tlbMalt = new JToolBar(); pnlMaltButtons.add(tlbMalt); tlbMalt.setPreferredSize(new java.awt.Dimension(386, 20)); tlbMalt.setFloatable(false); { btnAddMalt = new JButton(); tlbMalt.add(btnAddMalt); btnAddMalt.setText("+"); btnAddMalt.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { Fermentable f = new Fermentable(myRecipe.getMaltUnits()); myRecipe.addMalt(f); maltTable.updateUI(); displayRecipe(); } } }); } { btnDelMalt = new JButton(); tlbMalt.add(btnDelMalt); btnDelMalt.setText("-"); btnDelMalt.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { int i = maltTable.getSelectedRow(); myRecipe.delMalt(i); maltTable.updateUI(); displayRecipe(); } } }); } } } { pnlHops = new JPanel(); BorderLayout pnlHopsLayout = new BorderLayout(); pnlHops.setBorder(BorderFactory.createTitledBorder(new LineBorder( new java.awt.Color(0, 0, 0), 1, false), "Hops", TitledBorder.LEADING, TitledBorder.TOP, new java.awt.Font("Dialog", 1, 12), new java.awt.Color(51, 51, 51))); pnlHops.setLayout(pnlHopsLayout); pnlTables.add(pnlHops); { tblHopsTotalsModel = new DefaultTableModel(new String[][]{{""}}, new String[]{"1", "2", "3", "4", "5", "6", "7", "8", "9"}); tblHopsTotals = new JTable(); pnlHops.add(tblHopsTotals, BorderLayout.SOUTH); tblHopsTotals.setModel(tblHopsTotalsModel); tblHopsTotals.setAutoCreateColumnsFromModel(false); // set up the units combobox hopsTotalUnitsComboBox = new JComboBox(); hopsTotalUnitsComboModel = new ComboModel(); hopsTotalUnitsComboModel.setList(new Quantity().getListofUnits("weight")); hopsTotalUnitsComboBox.setModel(hopsTotalUnitsComboModel); TableColumn t = tblHopsTotals.getColumnModel().getColumn(4); t.setCellEditor(new DefaultCellEditor(hopsTotalUnitsComboBox)); hopsTotalUnitsComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { String u = (String) hopsTotalUnitsComboModel.getSelectedItem(); if (myRecipe != null) { myRecipe.setHopsUnits(u); displayRecipe(); } } }); } { jScrollPane2 = new JScrollPane(); pnlHops.add(jScrollPane2, BorderLayout.CENTER); { hopsTableModel = new HopsTableModel(this); hopsTable = new JTable() { public String getToolTipText(MouseEvent e) { java.awt.Point p = e.getPoint(); int rowIndex = rowAtPoint(p); return SBStringUtils.multiLineToolTip(40, hopsTableModel .getDescriptionAt(rowIndex)); } }; jScrollPane2.setViewportView(hopsTable); hopsTable.setModel(hopsTableModel); hopsTable.getTableHeader().setReorderingAllowed(false); TableColumn hopColumn = hopsTable.getColumnModel().getColumn(0); hopComboBox = new JComboBox(); cmbHopsModel = new ComboModel(); hopComboBox.setModel(cmbHopsModel); hopColumn.setCellEditor(new DefaultCellEditor(hopComboBox)); // set up hop units combo hopsUnitsComboBox = new JComboBox(); cmbHopsUnitsModel = new ComboModel(); hopsUnitsComboBox.setModel(cmbHopsUnitsModel); hopColumn = hopsTable.getColumnModel().getColumn(4); hopColumn.setCellEditor(new DefaultCellEditor(hopsUnitsComboBox)); // set up hop type combo String[] forms = {"Leaf", "Pellet", "Plug"}; JComboBox hopsFormComboBox = new JComboBox(forms); hopColumn = hopsTable.getColumnModel().getColumn(1); hopColumn.setCellEditor(new DefaultCellEditor(hopsFormComboBox)); // set up hop add combo String[] add = {"Boil", "FWH", "Dry", "Mash"}; JComboBox hopsAddComboBox = new JComboBox(add); hopColumn = hopsTable.getColumnModel().getColumn(5); hopColumn.setCellEditor(new DefaultCellEditor(hopsAddComboBox)); } } } { pnlHopsButtons = new JPanel(); FlowLayout pnlHopsButtonsLayout = new FlowLayout(); pnlHopsButtonsLayout.setAlignment(FlowLayout.LEFT); pnlHopsButtonsLayout.setVgap(0); pnlHopsButtons.setLayout(pnlHopsButtonsLayout); pnlTables.add(pnlHopsButtons); pnlHopsButtons.setPreferredSize(new java.awt.Dimension(512, 16)); { tlbHops = new JToolBar(); pnlHopsButtons.add(tlbHops); tlbHops.setPreferredSize(new java.awt.Dimension(413, 19)); tlbHops.setFloatable(false); { btnAddHop = new JButton(); tlbHops.add(btnAddHop); btnAddHop.setText("+"); btnAddHop.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { Hop h = new Hop(myRecipe.getHopUnits()); myRecipe.addHop(h); hopsTable.updateUI(); displayRecipe(); } } }); } { btnDelHop = new JButton(); tlbHops.add(btnDelHop); btnDelHop.setText("-"); btnDelHop.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { int i = hopsTable.getSelectedRow(); myRecipe.delHop(i); hopsTable.updateUI(); displayRecipe(); } } }); } } } } { statusPanel = new JPanel(); FlowLayout statusPanelLayout = new FlowLayout(); statusPanelLayout.setAlignment(FlowLayout.LEFT); statusPanelLayout.setHgap(2); statusPanelLayout.setVgap(2); statusPanel.setLayout(statusPanelLayout); pnlMain.add(statusPanel, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); { fileNamePanel = new JPanel(); statusPanel.add(fileNamePanel); fileNamePanel.setBorder(BorderFactory .createBevelBorder(BevelBorder.LOWERED)); { fileNameLabel = new JLabel(); fileNamePanel.add(fileNameLabel); fileNameLabel.setText("File Name"); fileNameLabel.setFont(new java.awt.Font("Dialog", 1, 10)); } } { ibuMethodPanel = new JPanel(); statusPanel.add(ibuMethodPanel); ibuMethodPanel.setBorder(BorderFactory .createBevelBorder(BevelBorder.LOWERED)); { ibuMethodLabel = new JLabel(); ibuMethodPanel.add(ibuMethodLabel); ibuMethodLabel.setText("IBU Method:"); ibuMethodLabel.setFont(new java.awt.Font("Dialog", 1, 10)); } } { alcMethodPanel = new JPanel(); statusPanel.add(alcMethodPanel); alcMethodPanel.setBorder(BorderFactory .createBevelBorder(BevelBorder.LOWERED)); { alcMethodLabel = new JLabel(); alcMethodPanel.add(alcMethodLabel); alcMethodLabel.setText("Alc Method:"); alcMethodLabel.setFont(new java.awt.Font("Dialog", 1, 10)); } } } } { jMenuBar1 = new JMenuBar(); setJMenuBar(jMenuBar1); { fileMenu = new JMenu(); jMenuBar1.add(fileMenu); fileMenu.setText("File"); { newFileMenuItem = new JMenuItem(); fileMenu.add(newFileMenuItem); newFileMenuItem.setText("New"); newFileMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // This is just a test right now to see that // stuff is changed. myRecipe = new Recipe(); myRecipe.setVersion(version); currentFile = null; attachRecipeData(); displayRecipe(); } }); } { openFileMenuItem = new JMenuItem(); fileMenu.add(openFileMenuItem); openFileMenuItem.setText("Open"); openFileMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_O, ActionEvent.CTRL_MASK)); openFileMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Show open dialog; this method does // not return until the dialog is closed String[] ext = {"xml", "qbrew", "rec"}; String desc = "StrangBrew and importable formats"; sbFileFilter openFileFilter = new sbFileFilter(ext, desc); // fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); fileChooser.setFileFilter(openFileFilter); int returnVal = fileChooser.showOpenDialog(jMenuBar1); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); Debug.print("Opening: " + file.getName() + ".\n"); OpenImport oi = new OpenImport(); myRecipe = oi.openFile(file); if (oi.getFileType().equals("")){ JOptionPane.showMessageDialog( null, "The file you've tried to open isn't a recognized format. \n" + "You can open: \n" + "StrangeBrew 1.x and Java files (.xml)\n" + "QBrew files (.qbrew)\n" + "BeerXML files (.xml)\n" + "Promash files (.rec)", "Unrecognized Format!", JOptionPane.INFORMATION_MESSAGE); } if (oi.getFileType().equals("beerxml")){ JOptionPane.showMessageDialog( null, "The file you've opened is in BeerXML format. It may contain \n" + "several recipes. Only the first recipe is opened. Use the Find \n" + "dialog to open other recipes in a BeerXML file.", "BeerXML!", JOptionPane.INFORMATION_MESSAGE); } myRecipe.setVersion(version); myRecipe.calcMaltTotals(); myRecipe.calcHopsTotals(); myRecipe.mash.calcMashSchedule(); checkIngredientsInDB(); attachRecipeData(); currentFile = file; displayRecipe(); } else { Debug.print("Open command cancelled by user.\n"); } } }); } { imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/find.gif"); icon = new ImageIcon(imgURL); findFileMenuItem = new JMenuItem("Find", icon); findFileMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_F, ActionEvent.CTRL_MASK)); fileMenu.add(findFileMenuItem); final JFrame owner = this; findFileMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // open the find dialog FindDialog fd = new FindDialog(owner); fd.setVisible(true); } }); } { imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/save.gif"); icon = new ImageIcon(imgURL); saveMenuItem = new JMenuItem("Save", icon); fileMenu.add(saveMenuItem); saveMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_S, ActionEvent.CTRL_MASK)); saveMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { int choice = 1; if (currentFile != null) { File file = currentFile; //This is where a real application would save the file. try { FileWriter out = new FileWriter(file); out.write(myRecipe.toXML()); out.close(); Debug.print("Saved: " + file.getAbsoluteFile()); currentFile = file; } catch (Exception e) { showError(e); } } // prompt to save if not already saved else { choice = JOptionPane.showConfirmDialog(null, "File not saved. Do you wish to save it?", "File note saved", JOptionPane.YES_NO_OPTION); } if (choice == 0) { // same as save as: saveAs(); } } }); } { imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/saveas.gif"); icon = new ImageIcon(imgURL); saveAsMenuItem = new JMenuItem("Save As ...", icon); fileMenu.add(saveAsMenuItem); saveAsMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // This is just a test right now to see that // stuff is changed. Debug.print(myRecipe.toXML()); saveAs(); } }); } { exportMenu = new JMenu(); fileMenu.add(exportMenu); exportMenu.setText("Export"); { exportHTMLmenu = new JMenuItem(); exportMenu.add(exportHTMLmenu); exportHTMLmenu.setText("HTML"); exportHTMLmenu.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Show save dialog; this method does // not return until the dialog is closed String[] ext = {"html", "htm"}; sbFileFilter saveFileFilter = new sbFileFilter(ext, "HTML"); fileChooser.setFileFilter(saveFileFilter); fileChooser.setSelectedFile(new File(myRecipe.getName() + ".html")); int returnVal = fileChooser.showSaveDialog(jMenuBar1); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); //This is where a real application would save the file. try { saveAsHTML(file, "ca/strangebrew/data/recipeToHtml.xslt"); } catch (Exception e) { showError(e); } } else { Debug.print("Save command cancelled by user.\n"); } } }); exportTextMenuItem = new JMenuItem(); exportMenu.add(exportTextMenuItem); exportTextMenuItem.setText("Text"); exportTextMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Show save dialog; this method does // not return until the dialog is closed String[] ext = {"txt"}; sbFileFilter saveFileFilter = new sbFileFilter(ext, "Text"); fileChooser.setFileFilter(saveFileFilter); fileChooser.setSelectedFile(new File(myRecipe.getName() + ".txt")); int returnVal = fileChooser.showSaveDialog(jMenuBar1); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); //This is where a real application would save the file. try { FileWriter out = new FileWriter(file); out.write(myRecipe.toText()); out.close(); } catch (Exception e) { showError(e); } } else { Debug.print("Export text command cancelled by user.\n"); } } }); } } { JMenuItem clipboardMenuItem = new JMenuItem("Copy to Clipboard"); fileMenu.add(clipboardMenuItem); clipboardMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Copy current recipe to clipboard Clipboard clipboard = getToolkit ().getSystemClipboard (); StringSelection s = new StringSelection(myRecipe.toText()); clipboard.setContents(s, s); } }); JMenuItem printMenuItem = new JMenuItem("Print..."); fileMenu.add(printMenuItem); final JFrame owner = this; printMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Copy current recipe to clipboard// save file as xml, then transform it to html File tmp = new File("tmp.html"); try { saveAsHTML(tmp, "ca/strangebrew/data/recipeToSimpleHtml.xslt"); HTMLViewer view = new HTMLViewer(owner, tmp.toURL()); view.setModal(true); view.setVisible(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } tmp.delete(); } }); } { jSeparator2 = new JSeparator(); fileMenu.add(jSeparator2); } { exitMenuItem = new JMenuItem(); fileMenu.add(exitMenuItem); exitMenuItem.setText("Exit"); exitMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_Q, ActionEvent.CTRL_MASK)); final JFrame owner = this; exitMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // exit program processWindowEvent(new WindowEvent(owner,WindowEvent.WINDOW_CLOSING)); System.exit(0); } }); } } { jMenu4 = new JMenu(); jMenuBar1.add(jMenu4); jMenu4.setText("Edit"); { final JFrame owner = this; editPrefsMenuItem = new JMenuItem(); jMenu4.add(editPrefsMenuItem); editPrefsMenuItem.setText("Preferences..."); editPrefsMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { PreferencesDialog d = new PreferencesDialog(owner, preferences); d.setVisible(true); } }); } { jSeparator1 = new JSeparator(); jMenu4.add(jSeparator1); } { deleteMenuItem = new JMenuItem(); jMenu4.add(deleteMenuItem); deleteMenuItem.setText("Delete"); deleteMenuItem.setEnabled(false); } } { mnuTools = new JMenu(); jMenuBar1.add(mnuTools); mnuTools.setText("Tools"); { final JFrame owner = this; JMenuItem scalRecipeMenuItem = new JMenuItem(); mnuTools.add(scalRecipeMenuItem); scalRecipeMenuItem.setText("Scale Recipe..."); scalRecipeMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_R, ActionEvent.CTRL_MASK)); scalRecipeMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { ScaleRecipeDialog scaleRecipe = new ScaleRecipeDialog(owner); scaleRecipe.setModal(true); scaleRecipe.setVisible(true); } }); JMenuItem maltPercentMenuItem = new JMenuItem(); mnuTools.add(maltPercentMenuItem); maltPercentMenuItem.setText("Malt Percent..."); maltPercentMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_M, ActionEvent.CTRL_MASK)); maltPercentMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { MaltPercentDialog maltPercent = new MaltPercentDialog(owner); maltPercent.setModal(true); maltPercent.setVisible(true); } }); } } { jMenu5 = new JMenu(); jMenuBar1.add(jMenu5); jMenu5.setText("Help"); { helpMenuItem = new JMenuItem(); jMenu5.add(helpMenuItem); helpMenuItem.setText("Help"); final JFrame owner = this; helpMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { URL help; try { help = new File(appRoot + "/help/index.html").toURL(); HTMLViewer view = new HTMLViewer(owner, help); view.setModal(true); view.setVisible(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); } { aboutMenuItem = new JMenuItem(); jMenu5.add(aboutMenuItem); aboutMenuItem.setText("About..."); final JFrame owner = this; aboutMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { aboutDlg = new AboutDialog(owner, version); aboutDlg.setVisible(true); } }); } } } } catch (Exception e) { e.printStackTrace(); } }
1,115,276
private void initGUI() { try { // restore the saved size and location: this.setSize(preferences.getIProperty("winWidth"), preferences.getIProperty("winHeight")); this.setLocation(preferences.getIProperty("winX"), preferences.getIProperty("winY")); imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/sb2.gif"); icon = new ImageIcon(imgURL); this.setIconImage(icon.getImage()); this.setTitle("StrangeBrew " + version); this.addWindowListener(new WindowAdapter() { public void windowClosed(WindowEvent evt) { System.exit(1); } }); { pnlMain = new JPanel(); GridBagLayout jPanel2Layout = new GridBagLayout(); jPanel2Layout.columnWeights = new double[]{0.1}; jPanel2Layout.columnWidths = new int[]{7}; jPanel2Layout.rowWeights = new double[]{0.1, 0.1, 0.9, 0.1}; jPanel2Layout.rowHeights = new int[]{7, 7, 7, 7}; pnlMain.setLayout(jPanel2Layout); this.getContentPane().add(pnlMain, BorderLayout.CENTER); { jTabbedPane1 = new JTabbedPane(); pnlMain.add(jTabbedPane1, new GridBagConstraints(0, 1, 1, 1, 0.1, 0.1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); { pnlDetails = new JPanel(); GridBagLayout pnlDetailsLayout = new GridBagLayout(); pnlDetailsLayout.columnWeights = new double[]{0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1}; pnlDetailsLayout.columnWidths = new int[]{7, 7, 7, 7, 7, 7, 7, 7, 7, 7}; pnlDetailsLayout.rowWeights = new double[]{0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1}; pnlDetailsLayout.rowHeights = new int[]{7, 7, 7, 7, 7, 7, 7}; pnlDetails.setLayout(pnlDetailsLayout); jTabbedPane1.addTab("Details", null, pnlDetails, null); pnlDetails.setPreferredSize(new java.awt.Dimension(20, 16)); { lblBrewer = new JLabel(); pnlDetails.add(lblBrewer, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblBrewer.setText("Brewer:"); } { brewerNameText = new JTextField(); pnlDetails.add(brewerNameText, new GridBagConstraints(1, 0, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); brewerNameText.setPreferredSize(new java.awt.Dimension(69, 20)); brewerNameText.setText("Brewer"); } { lblDate = new JLabel(); pnlDetails.add(lblDate, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblDate.setText("Date:"); } { lblStyle = new JLabel(); pnlDetails.add(lblStyle, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblStyle.setText("Style:"); } { lblYeast = new JLabel(); pnlDetails.add(lblYeast, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblYeast.setText("Yeast:"); } { lblPreBoil = new JLabel(); pnlDetails.add(lblPreBoil, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblPreBoil.setText("Pre boil:"); } { lblPostBoil = new JLabel(); pnlDetails.add(lblPostBoil, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblPostBoil.setText("Post boil:"); } { lblEffic = new JLabel(); pnlDetails.add(lblEffic, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblEffic.setText("Effic:"); lblEffic.setPreferredSize(new java.awt.Dimension(31, 14)); } { lblAtten = new JLabel(); pnlDetails.add(lblAtten, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblAtten.setText("Atten:"); lblAtten.setPreferredSize(new java.awt.Dimension(34, 14)); } { lblOG = new JLabel(); pnlDetails.add(lblOG, new GridBagConstraints(5, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblOG.setText("OG:"); } { lblFG = new JLabel(); pnlDetails.add(lblFG, new GridBagConstraints(5, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblFG.setText("FG:"); } { lblIBU = new JLabel(); pnlDetails.add(lblIBU, new GridBagConstraints(7, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblIBU.setText("IBU:"); } { lblAlc = new JLabel(); pnlDetails.add(lblAlc, new GridBagConstraints(7, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblAlc.setText("%Alc:"); } { lblColour = new JLabel(); pnlDetails.add(lblColour, new GridBagConstraints(7, 2, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblColour.setText("Colour:"); } { //txtDate = new JFormattedTextField(); txtDate = new DatePicker(); pnlDetails.add(txtDate, new GridBagConstraints(1, 1, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); // txtDate.setText("Date"); txtDate.setPreferredSize(new java.awt.Dimension(73, 20)); txtDate.setDateStyle(DateFormat.SHORT); } { cmbStyleModel = new ComboModel(); cmbStyle = new JComboBox(); pnlDetails.add(cmbStyle, new GridBagConstraints(1, 2, 5, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cmbStyle.setModel(cmbStyleModel); cmbStyle.setMaximumSize(new java.awt.Dimension(100, 32767)); cmbStyle.setPreferredSize(new java.awt.Dimension(190, 20)); } { txtPreBoil = new JFormattedTextField(); pnlDetails.add(txtPreBoil, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); txtPreBoil.setText("Pre Boil"); txtPreBoil.setPreferredSize(new java.awt.Dimension(37, 20)); } { postBoilText = new JFormattedTextField(); pnlDetails.add(postBoilText, new GridBagConstraints(1, 5, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); postBoilText.setText("Post Boil"); postBoilText.setPreferredSize(new java.awt.Dimension(46, 20)); } { lblComments = new JLabel(); pnlDetails.add(lblComments, new GridBagConstraints(6, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblComments.setText("Comments:"); } { SpinnerNumberModel spnEfficModel = new SpinnerNumberModel(75.0, 0.0, 100.0, 1.0); spnEffic = new JSpinner(); pnlDetails.add(spnEffic, new GridBagConstraints(4, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnEffic.setModel(spnEfficModel); spnEffic.setMaximumSize(new java.awt.Dimension(70, 32767)); spnEffic.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { myRecipe.setEfficiency(Double.parseDouble(spnEffic.getValue() .toString())); displayRecipe(); } }); spnEffic.setEditor(new JSpinner.NumberEditor(spnEffic, "00.#")); spnEffic.getEditor().setPreferredSize(new java.awt.Dimension(28, 16)); spnEffic.setPreferredSize(new java.awt.Dimension(53, 18)); } { SpinnerNumberModel spnAttenModel = new SpinnerNumberModel(75.0, 0.0, 100.0, 1.0); spnAtten = new JSpinner(); pnlDetails.add(spnAtten, new GridBagConstraints(4, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnAtten.setModel(spnAttenModel); spnAtten.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { myRecipe.setAttenuation(Double.parseDouble(spnAtten.getValue() .toString())); displayRecipe(); } }); spnAtten.setEditor(new JSpinner.NumberEditor(spnAtten, "00.#")); spnAtten.setPreferredSize(new java.awt.Dimension(49, 20)); } { SpinnerNumberModel spnOgModel = new SpinnerNumberModel(1.000, 0.900, 2.000, 0.001); spnOG = new JSpinner(); pnlDetails.add(spnOG, new GridBagConstraints(6, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnOG.setModel(spnOgModel); spnOG.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { myRecipe.setEstOg(Double.parseDouble(spnOG.getValue() .toString())); displayRecipe(); } }); spnOG.setEditor(new JSpinner.NumberEditor(spnOG, "0.000")); spnOG.getEditor().setPreferredSize(new java.awt.Dimension(20, 16)); spnOG.setPreferredSize(new java.awt.Dimension(67, 18)); } { SpinnerNumberModel spnFgModel = new SpinnerNumberModel(1.000, 0.900, 2.000, 0.001); spnFG = new JSpinner(); pnlDetails.add(spnFG, new GridBagConstraints(6, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnFG.setModel(spnFgModel); spnFG.setEditor(new JSpinner.NumberEditor(spnFG, "0.000")); spnFG.setPreferredSize(new java.awt.Dimension(69, 20)); spnFG.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { // set the new FG, and update alc: myRecipe.setEstFg(Double.parseDouble(spnFG.getValue() .toString())); displayRecipe(); } }); } { lblIBUvalue = new JLabel(); pnlDetails.add(lblIBUvalue, new GridBagConstraints(8, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblIBUvalue.setText("IBUs"); } { lblColourValue = new JLabel(); pnlDetails.add(lblColourValue, new GridBagConstraints(8, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblColourValue.setText("Colour"); } { lblAlcValue = new JLabel(); pnlDetails.add(lblAlcValue, new GridBagConstraints(8, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblAlcValue.setText("Alc"); } { scpComments = new JScrollPane(); pnlDetails.add(scpComments, new GridBagConstraints(7, 4, 3, 2, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); { txtComments = new JTextArea(); scpComments.setViewportView(txtComments); txtComments.setText("Comments"); txtComments.setWrapStyleWord(true); // txtComments.setPreferredSize(new java.awt.Dimension(117, 42)); txtComments.setLineWrap(true); txtComments.setPreferredSize(new java.awt.Dimension(263, 40)); txtComments.addFocusListener(new FocusAdapter() { public void focusLost(FocusEvent evt) { if (!txtComments.getText().equals(myRecipe.getComments())) { myRecipe.setComments(txtComments.getText()); } } }); } } { cmbYeastModel = new ComboModel(); cmbYeast = new JComboBox(); pnlDetails.add(cmbYeast, new GridBagConstraints(1, 3, 5, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cmbYeast.setModel(cmbYeastModel); cmbYeast.setPreferredSize(new java.awt.Dimension(193, 20)); } { cmbSizeUnitsModel = new ComboModel(); cmbSizeUnits = new JComboBox(); pnlDetails.add(cmbSizeUnits, new GridBagConstraints(2, 4, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cmbSizeUnits.setModel(cmbSizeUnitsModel); } { lblSizeUnits = new JLabel(); pnlDetails.add(lblSizeUnits, new GridBagConstraints(2, 5, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); lblSizeUnits.setText("Size Units"); } { boilTimeLable = new JLabel(); pnlDetails.add(boilTimeLable, new GridBagConstraints(4, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); boilTimeLable.setText("Boil Min:"); } { evapLabel = new JLabel(); pnlDetails.add(evapLabel, new GridBagConstraints(4, 5, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); evapLabel.setText("Evap/hr:"); } { boilMinText = new JTextField(); pnlDetails.add(boilMinText, new GridBagConstraints(5, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); boilMinText.setText("60"); boilMinText.setPreferredSize(new java.awt.Dimension(22, 20)); } { evapText = new JTextField(); pnlDetails.add(evapText, new GridBagConstraints(5, 5, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); evapText.setText("4"); evapText.setPreferredSize(new java.awt.Dimension(23, 20)); } { alcMethodComboModel = new DefaultComboBoxModel(new String[]{"Volume", "Weight"}); alcMethodCombo = new JComboBox(alcMethodComboModel); pnlDetails.add(alcMethodCombo, new GridBagConstraints(9, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); alcMethodCombo.setPreferredSize(new java.awt.Dimension(58, 20)); } { ibuMethodComboModel = new DefaultComboBoxModel(new String[]{"Tinseth", "Garetz", "Rager"}); ibuMethodCombo = new JComboBox(ibuMethodComboModel); pnlDetails.add(ibuMethodCombo, new GridBagConstraints(9, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); ibuMethodCombo.setPreferredSize(new java.awt.Dimension(59, 20)); } { colourMethodComboModel = new DefaultComboBoxModel(new String[]{"SRM", "EBC"}); colourMethodCombo = new JComboBox(colourMethodComboModel); pnlDetails.add(colourMethodCombo, new GridBagConstraints(9, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); colourMethodCombo.setPreferredSize(new java.awt.Dimension(44, 20)); } ComboBoxModel evapMethodComboModel = new DefaultComboBoxModel(new String[] { "Constant", "Percent" }); { jPanel1 = new JPanel(); pnlMain.add(jPanel1, new GridBagConstraints( 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); FlowLayout jPanel1Layout = new FlowLayout(); jPanel1Layout.setAlignment(FlowLayout.LEFT); jPanel1.setLayout(jPanel1Layout); jToolBar1 = new JToolBar(); getContentPane().add(jToolBar1, BorderLayout.NORTH); jToolBar1.setFloatable(false); jToolBar1.setRollover(true); jButton1 = new JButton(); jToolBar1.add(jButton1); jButton1.setMnemonic(java.awt.event.KeyEvent.VK_S); jButton1.setIcon(new ImageIcon(getClass().getClassLoader().getResource( "ca/strangebrew/icons/save.gif"))); jButton1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { System.out.println("jButton1.actionPerformed, event=" + evt); //TODO add your code for jButton1.actionPerformed } }); jButton2 = new JButton(); jToolBar1.add(jButton2); jButton2.setIcon(new ImageIcon(getClass().getClassLoader().getResource( "ca/strangebrew/icons/find.gif"))); jButton2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { System.out.println("jButton2.actionPerformed, event=" + evt); //TODO add your code for jButton2.actionPerformed } }); { lblName = new JLabel(); jPanel1.add(lblName); lblName.setText("Name:"); } { txtName = new JTextField(); jPanel1.add(txtName); txtName.setText("Name"); txtName.setPreferredSize(new java.awt.Dimension(297, 20)); } } evapMethodCombo = new JComboBox(); pnlDetails.add(evapMethodCombo, new GridBagConstraints(6, 5, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); evapMethodCombo.setModel(evapMethodComboModel); evapMethodCombo.setPreferredSize(new java.awt.Dimension(64, 20)); colourPanel = new JPanel(); pnlDetails.add(colourPanel, new GridBagConstraints(9, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); colourPanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); } { SBNotifier sbn = new SBNotifier(); stylePanel = new StylePanel(sbn); jTabbedPane1.addTab("Style", null, stylePanel, null); miscPanel = new MiscPanel(myRecipe); jTabbedPane1.addTab("Misc", null, miscPanel, null); notesPanel = new NotesPanel(); jTabbedPane1.addTab("Notes", null, notesPanel, null); dilutionPanel = new DilutionPanel(); jTabbedPane1.addTab("Dilution", null, dilutionPanel, null); mashPanel = new MashPanel(myRecipe); jTabbedPane1.addTab("Mash", null, mashPanel, null); waterPanel = new WaterPanel(); jTabbedPane1.addTab("Water", null, waterPanel, null); costPanel = new CostPanel(); jTabbedPane1.addTab("Cost", null, costPanel, null); // SBNotifier sbn = new SBNotifier(); settingsPanel = new SettingsPanel(sbn); jTabbedPane1.addTab("Settings", null, settingsPanel, null); } } { pnlTables = new JPanel(); BoxLayout pnlMaltsLayout = new BoxLayout(pnlTables, javax.swing.BoxLayout.Y_AXIS); pnlMain.add(pnlTables, new GridBagConstraints(0, 2, 1, 1, 0.5, 0.5, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); pnlTables.setLayout(pnlMaltsLayout); { pnlMalt = new JPanel(); pnlTables.add(pnlMalt); BorderLayout pnlMaltLayout1 = new BorderLayout(); pnlMalt.setBorder(BorderFactory.createTitledBorder(new LineBorder( new java.awt.Color(0, 0, 0), 1, false), "Fermentables", TitledBorder.LEADING, TitledBorder.TOP, new java.awt.Font("Dialog", 1, 12), new java.awt.Color(51, 51, 51))); pnlMalt.setLayout(pnlMaltLayout1); { jScrollPane1 = new JScrollPane(); pnlMalt.add(jScrollPane1, BorderLayout.CENTER); { maltTableModel = new MaltTableModel(this); maltTable = new JTable() { public String getToolTipText(MouseEvent e) { java.awt.Point p = e.getPoint(); int rowIndex = rowAtPoint(p); return SBStringUtils.multiLineToolTip(40, maltTableModel .getDescriptionAt(rowIndex)); } }; jScrollPane1.setViewportView(maltTable); maltTable.setModel(maltTableModel); // maltTable.setAutoCreateColumnsFromModel(false); maltTable.getTableHeader().setReorderingAllowed(false); TableColumn maltColumn = maltTable.getColumnModel().getColumn(0); // set up malt list combo maltComboBox = new JComboBox(); cmbMaltModel = new ComboModel(); maltComboBox.setModel(cmbMaltModel); maltColumn.setCellEditor(new DefaultCellEditor(maltComboBox)); // set up malt amount editor amountEditor = new SBCellEditor(new JTextField()); maltColumn = maltTable.getColumnModel().getColumn(1); maltColumn.setCellEditor(amountEditor); // set up malt units combo maltUnitsComboBox = new JComboBox(); cmbMaltUnitsModel = new ComboModel(); maltUnitsComboBox.setModel(cmbMaltUnitsModel); maltColumn = maltTable.getColumnModel().getColumn(2); maltColumn.setCellEditor(new DefaultCellEditor(maltUnitsComboBox)); } } { tblMaltTotalsModel = new DefaultTableModel(new String[][]{{""}}, new String[]{"Malt", "Amount", "Units", "Points", "Lov", "Cost/U", "%"}); tblMaltTotals = new JTable(); pnlMalt.add(tblMaltTotals, BorderLayout.SOUTH); tblMaltTotals.setModel(tblMaltTotalsModel); tblMaltTotals.getTableHeader().setEnabled(false); tblMaltTotals.setAutoCreateColumnsFromModel(false); // set up the units combobox maltTotalUnitsComboBox = new JComboBox(); maltTotalUnitsComboModel = new ComboModel(); maltTotalUnitsComboModel.setList(new Quantity().getListofUnits("weight")); maltTotalUnitsComboBox.setModel(maltTotalUnitsComboModel); TableColumn t = tblMaltTotals.getColumnModel().getColumn(2); t.setCellEditor(new DefaultCellEditor(maltTotalUnitsComboBox)); maltTotalUnitsComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { String u = (String) maltTotalUnitsComboModel.getSelectedItem(); if (myRecipe != null) { myRecipe.setMaltUnits(u); displayRecipe(); } } }); } } { pnlMaltButtons = new JPanel(); pnlTables.add(pnlMaltButtons); FlowLayout pnlMaltButtonsLayout = new FlowLayout(); pnlMaltButtonsLayout.setAlignment(FlowLayout.LEFT); pnlMaltButtonsLayout.setVgap(0); pnlMaltButtons.setLayout(pnlMaltButtonsLayout); pnlMaltButtons.setPreferredSize(new java.awt.Dimension(592, 27)); { tlbMalt = new JToolBar(); pnlMaltButtons.add(tlbMalt); tlbMalt.setPreferredSize(new java.awt.Dimension(386, 20)); tlbMalt.setFloatable(false); { btnAddMalt = new JButton(); tlbMalt.add(btnAddMalt); btnAddMalt.setText("+"); btnAddMalt.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { Fermentable f = new Fermentable(myRecipe.getMaltUnits()); myRecipe.addMalt(f); maltTable.updateUI(); displayRecipe(); } } }); } { btnDelMalt = new JButton(); tlbMalt.add(btnDelMalt); btnDelMalt.setText("-"); btnDelMalt.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { int i = maltTable.getSelectedRow(); myRecipe.delMalt(i); maltTable.updateUI(); displayRecipe(); } } }); } } } { pnlHops = new JPanel(); BorderLayout pnlHopsLayout = new BorderLayout(); pnlHops.setBorder(BorderFactory.createTitledBorder(new LineBorder( new java.awt.Color(0, 0, 0), 1, false), "Hops", TitledBorder.LEADING, TitledBorder.TOP, new java.awt.Font("Dialog", 1, 12), new java.awt.Color(51, 51, 51))); pnlHops.setLayout(pnlHopsLayout); pnlTables.add(pnlHops); { tblHopsTotalsModel = new DefaultTableModel(new String[][]{{""}}, new String[]{"1", "2", "3", "4", "5", "6", "7", "8", "9"}); tblHopsTotals = new JTable(); pnlHops.add(tblHopsTotals, BorderLayout.SOUTH); tblHopsTotals.setModel(tblHopsTotalsModel); tblHopsTotals.setAutoCreateColumnsFromModel(false); // set up the units combobox hopsTotalUnitsComboBox = new JComboBox(); hopsTotalUnitsComboModel = new ComboModel(); hopsTotalUnitsComboModel.setList(new Quantity().getListofUnits("weight")); hopsTotalUnitsComboBox.setModel(hopsTotalUnitsComboModel); TableColumn t = tblHopsTotals.getColumnModel().getColumn(4); t.setCellEditor(new DefaultCellEditor(hopsTotalUnitsComboBox)); hopsTotalUnitsComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { String u = (String) hopsTotalUnitsComboModel.getSelectedItem(); if (myRecipe != null) { myRecipe.setHopsUnits(u); displayRecipe(); } } }); } { jScrollPane2 = new JScrollPane(); pnlHops.add(jScrollPane2, BorderLayout.CENTER); { hopsTableModel = new HopsTableModel(this); hopsTable = new JTable() { public String getToolTipText(MouseEvent e) { java.awt.Point p = e.getPoint(); int rowIndex = rowAtPoint(p); return SBStringUtils.multiLineToolTip(40, hopsTableModel .getDescriptionAt(rowIndex)); } }; jScrollPane2.setViewportView(hopsTable); hopsTable.setModel(hopsTableModel); hopsTable.getTableHeader().setReorderingAllowed(false); TableColumn hopColumn = hopsTable.getColumnModel().getColumn(0); hopComboBox = new JComboBox(); cmbHopsModel = new ComboModel(); hopComboBox.setModel(cmbHopsModel); hopColumn.setCellEditor(new DefaultCellEditor(hopComboBox)); // set up hop units combo hopsUnitsComboBox = new JComboBox(); cmbHopsUnitsModel = new ComboModel(); hopsUnitsComboBox.setModel(cmbHopsUnitsModel); hopColumn = hopsTable.getColumnModel().getColumn(4); hopColumn.setCellEditor(new DefaultCellEditor(hopsUnitsComboBox)); // set up hop type combo String[] forms = {"Leaf", "Pellet", "Plug"}; JComboBox hopsFormComboBox = new JComboBox(forms); hopColumn = hopsTable.getColumnModel().getColumn(1); hopColumn.setCellEditor(new DefaultCellEditor(hopsFormComboBox)); // set up hop add combo String[] add = {"Boil", "FWH", "Dry", "Mash"}; JComboBox hopsAddComboBox = new JComboBox(add); hopColumn = hopsTable.getColumnModel().getColumn(5); hopColumn.setCellEditor(new DefaultCellEditor(hopsAddComboBox)); } } } { pnlHopsButtons = new JPanel(); FlowLayout pnlHopsButtonsLayout = new FlowLayout(); pnlHopsButtonsLayout.setAlignment(FlowLayout.LEFT); pnlHopsButtonsLayout.setVgap(0); pnlHopsButtons.setLayout(pnlHopsButtonsLayout); pnlTables.add(pnlHopsButtons); pnlHopsButtons.setPreferredSize(new java.awt.Dimension(512, 16)); { tlbHops = new JToolBar(); pnlHopsButtons.add(tlbHops); tlbHops.setPreferredSize(new java.awt.Dimension(413, 19)); tlbHops.setFloatable(false); { btnAddHop = new JButton(); tlbHops.add(btnAddHop); btnAddHop.setText("+"); btnAddHop.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { Hop h = new Hop(myRecipe.getHopUnits()); myRecipe.addHop(h); hopsTable.updateUI(); displayRecipe(); } } }); } { btnDelHop = new JButton(); tlbHops.add(btnDelHop); btnDelHop.setText("-"); btnDelHop.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { int i = hopsTable.getSelectedRow(); myRecipe.delHop(i); hopsTable.updateUI(); displayRecipe(); } } }); } } } } { statusPanel = new JPanel(); FlowLayout statusPanelLayout = new FlowLayout(); statusPanelLayout.setAlignment(FlowLayout.LEFT); statusPanelLayout.setHgap(2); statusPanelLayout.setVgap(2); statusPanel.setLayout(statusPanelLayout); pnlMain.add(statusPanel, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); { fileNamePanel = new JPanel(); statusPanel.add(fileNamePanel); fileNamePanel.setBorder(BorderFactory .createBevelBorder(BevelBorder.LOWERED)); { fileNameLabel = new JLabel(); fileNamePanel.add(fileNameLabel); fileNameLabel.setText("File Name"); fileNameLabel.setFont(new java.awt.Font("Dialog", 1, 10)); } } { ibuMethodPanel = new JPanel(); statusPanel.add(ibuMethodPanel); ibuMethodPanel.setBorder(BorderFactory .createBevelBorder(BevelBorder.LOWERED)); { ibuMethodLabel = new JLabel(); ibuMethodPanel.add(ibuMethodLabel); ibuMethodLabel.setText("IBU Method:"); ibuMethodLabel.setFont(new java.awt.Font("Dialog", 1, 10)); } } { alcMethodPanel = new JPanel(); statusPanel.add(alcMethodPanel); alcMethodPanel.setBorder(BorderFactory .createBevelBorder(BevelBorder.LOWERED)); { alcMethodLabel = new JLabel(); alcMethodPanel.add(alcMethodLabel); alcMethodLabel.setText("Alc Method:"); alcMethodLabel.setFont(new java.awt.Font("Dialog", 1, 10)); } } } } { jMenuBar1 = new JMenuBar(); setJMenuBar(jMenuBar1); { fileMenu = new JMenu(); jMenuBar1.add(fileMenu); fileMenu.setText("File"); { newFileMenuItem = new JMenuItem(); fileMenu.add(newFileMenuItem); newFileMenuItem.setText("New"); newFileMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // This is just a test right now to see that // stuff is changed. myRecipe = new Recipe(); myRecipe.setVersion(version); currentFile = null; attachRecipeData(); displayRecipe(); } }); } { openFileMenuItem = new JMenuItem(); fileMenu.add(openFileMenuItem); openFileMenuItem.setText("Open"); openFileMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_O, ActionEvent.CTRL_MASK)); openFileMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Show open dialog; this method does // not return until the dialog is closed String[] ext = {"xml", "qbrew", "rec"}; String desc = "StrangBrew and importable formats"; sbFileFilter openFileFilter = new sbFileFilter(ext, desc); // fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); fileChooser.setFileFilter(openFileFilter); int returnVal = fileChooser.showOpenDialog(jMenuBar1); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); Debug.print("Opening: " + file.getName() + ".\n"); OpenImport oi = new OpenImport(); myRecipe = oi.openFile(file); if (oi.getFileType().equals("")){ JOptionPane.showMessageDialog( null, "The file you've tried to open isn't a recognized format. \n" + "You can open: \n" + "StrangeBrew 1.x and Java files (.xml)\n" + "QBrew files (.qbrew)\n" + "BeerXML files (.xml)\n" + "Promash files (.rec)", "Unrecognized Format!", JOptionPane.INFORMATION_MESSAGE); } if (oi.getFileType().equals("beerxml")){ JOptionPane.showMessageDialog( null, "The file you've opened is in BeerXML format. It may contain \n" + "several recipes. Only the first recipe is opened. Use the Find \n" + "dialog to open other recipes in a BeerXML file.", "BeerXML!", JOptionPane.INFORMATION_MESSAGE); } myRecipe.setVersion(version); myRecipe.calcMaltTotals(); myRecipe.calcHopsTotals(); myRecipe.mash.calcMashSchedule(); checkIngredientsInDB(); attachRecipeData(); currentFile = file; displayRecipe(); } else { Debug.print("Open command cancelled by user.\n"); } } }); } { imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/find.gif"); icon = new ImageIcon(imgURL); findFileMenuItem = new JMenuItem("Find", icon); findFileMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_F, ActionEvent.CTRL_MASK)); fileMenu.add(findFileMenuItem); final JFrame owner = this; findFileMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // open the find dialog FindDialog fd = new FindDialog(owner); fd.setVisible(true); } }); } { imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/save.gif"); icon = new ImageIcon(imgURL); saveMenuItem = new JMenuItem("Save", icon); fileMenu.add(saveMenuItem); saveMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_S, ActionEvent.CTRL_MASK)); saveMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { int choice = 1; if (currentFile != null) { File file = currentFile; //This is where a real application would save the file. try { FileWriter out = new FileWriter(file); out.write(myRecipe.toXML()); out.close(); Debug.print("Saved: " + file.getAbsoluteFile()); currentFile = file; } catch (Exception e) { showError(e); } } // prompt to save if not already saved else { choice = JOptionPane.showConfirmDialog(null, "File not saved. Do you wish to save it?", "File note saved", JOptionPane.YES_NO_OPTION); } if (choice == 0) { // same as save as: saveAs(); } } }); } { imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/saveas.gif"); icon = new ImageIcon(imgURL); saveAsMenuItem = new JMenuItem("Save As ...", icon); fileMenu.add(saveAsMenuItem); saveAsMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // This is just a test right now to see that // stuff is changed. Debug.print(myRecipe.toXML()); saveAs(); } }); } { exportMenu = new JMenu(); fileMenu.add(exportMenu); exportMenu.setText("Export"); { exportHTMLmenu = new JMenuItem(); exportMenu.add(exportHTMLmenu); exportHTMLmenu.setText("HTML"); exportHTMLmenu.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Show save dialog; this method does // not return until the dialog is closed String[] ext = {"html", "htm"}; sbFileFilter saveFileFilter = new sbFileFilter(ext, "HTML"); fileChooser.setFileFilter(saveFileFilter); fileChooser.setSelectedFile(new File(myRecipe.getName() + ".html")); int returnVal = fileChooser.showSaveDialog(jMenuBar1); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); //This is where a real application would save the file. try { saveAsHTML(file, "ca/strangebrew/data/recipeToHtml.xslt"); } catch (Exception e) { showError(e); } } else { Debug.print("Save command cancelled by user.\n"); } } }); exportTextMenuItem = new JMenuItem(); exportMenu.add(exportTextMenuItem); exportTextMenuItem.setText("Text"); exportTextMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Show save dialog; this method does // not return until the dialog is closed String[] ext = {"txt"}; sbFileFilter saveFileFilter = new sbFileFilter(ext, "Text"); fileChooser.setFileFilter(saveFileFilter); fileChooser.setSelectedFile(new File(myRecipe.getName() + ".txt")); int returnVal = fileChooser.showSaveDialog(jMenuBar1); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); //This is where a real application would save the file. try { FileWriter out = new FileWriter(file); out.write(myRecipe.toText()); out.close(); } catch (Exception e) { showError(e); } } else { Debug.print("Export text command cancelled by user.\n"); } } }); } } { JMenuItem clipboardMenuItem = new JMenuItem("Copy to Clipboard"); fileMenu.add(clipboardMenuItem); clipboardMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Copy current recipe to clipboard Clipboard clipboard = getToolkit ().getSystemClipboard (); StringSelection s = new StringSelection(myRecipe.toText()); clipboard.setContents(s, s); } }); JMenuItem printMenuItem = new JMenuItem("Print..."); fileMenu.add(printMenuItem); final JFrame owner = this; printMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Copy current recipe to clipboard// save file as xml, then transform it to html File tmp = new File("tmp.html"); try { saveAsHTML(tmp, "ca/strangebrew/data/recipeToSimpleHtml.xslt"); HTMLViewer view = new HTMLViewer(owner, tmp.toURL()); view.setModal(true); view.setVisible(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } tmp.delete(); } }); } { jSeparator2 = new JSeparator(); fileMenu.add(jSeparator2); } { exitMenuItem = new JMenuItem(); fileMenu.add(exitMenuItem); exitMenuItem.setText("Exit"); exitMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_Q, ActionEvent.CTRL_MASK)); final JFrame owner = this; exitMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // exit program processWindowEvent(new WindowEvent(owner,WindowEvent.WINDOW_CLOSING)); System.exit(0); } }); } } { jMenu4 = new JMenu(); jMenuBar1.add(jMenu4); jMenu4.setText("Edit"); { final JFrame owner = this; editPrefsMenuItem = new JMenuItem(); jMenu4.add(editPrefsMenuItem); editPrefsMenuItem.setText("Preferences..."); editPrefsMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { PreferencesDialog d = new PreferencesDialog(owner, preferences); d.setVisible(true); } }); } { jSeparator1 = new JSeparator(); jMenu4.add(jSeparator1); } { deleteMenuItem = new JMenuItem(); jMenu4.add(deleteMenuItem); deleteMenuItem.setText("Delete"); deleteMenuItem.setEnabled(false); } } { mnuTools = new JMenu(); jMenuBar1.add(mnuTools); mnuTools.setText("Tools"); { final JFrame owner = this; JMenuItem scalRecipeMenuItem = new JMenuItem(); mnuTools.add(scalRecipeMenuItem); scalRecipeMenuItem.setText("Scale Recipe..."); scalRecipeMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_R, ActionEvent.CTRL_MASK)); scalRecipeMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { ScaleRecipeDialog scaleRecipe = new ScaleRecipeDialog(owner); scaleRecipe.setModal(true); scaleRecipe.setVisible(true); } }); JMenuItem maltPercentMenuItem = new JMenuItem(); mnuTools.add(maltPercentMenuItem); maltPercentMenuItem.setText("Malt Percent..."); maltPercentMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_M, ActionEvent.CTRL_MASK)); maltPercentMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { MaltPercentDialog maltPercent = new MaltPercentDialog(owner); maltPercent.setModal(true); maltPercent.setVisible(true); } }); } } { jMenu5 = new JMenu(); jMenuBar1.add(jMenu5); jMenu5.setText("Help"); { helpMenuItem = new JMenuItem(); jMenu5.add(helpMenuItem); helpMenuItem.setText("Help"); final JFrame owner = this; helpMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { URL help; try { help = new File(appRoot + "/help/index.html").toURL(); HTMLViewer view = new HTMLViewer(owner, help); view.setModal(true); view.setVisible(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); } { aboutMenuItem = new JMenuItem(); jMenu5.add(aboutMenuItem); aboutMenuItem.setText("About..."); final JFrame owner = this; aboutMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { aboutDlg = new AboutDialog(owner, version); aboutDlg.setVisible(true); } }); } } } } catch (Exception e) { e.printStackTrace(); } }
private void initGUI() { try { // restore the saved size and location: this.setSize(preferences.getIProperty("winWidth"), preferences.getIProperty("winHeight")); this.setLocation(preferences.getIProperty("winX"), preferences.getIProperty("winY")); imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/sb2.gif"); icon = new ImageIcon(imgURL); this.setIconImage(icon.getImage()); this.setTitle("StrangeBrew " + version); this.addWindowListener(new WindowAdapter() { public void windowClosed(WindowEvent evt) { System.exit(1); } }); { pnlMain = new JPanel(); GridBagLayout jPanel2Layout = new GridBagLayout(); jPanel2Layout.columnWeights = new double[]{0.1}; jPanel2Layout.columnWidths = new int[]{7}; jPanel2Layout.rowWeights = new double[]{0.1, 0.1, 0.9, 0.1}; jPanel2Layout.rowHeights = new int[]{7, 7, 7, 7}; pnlMain.setLayout(jPanel2Layout); this.getContentPane().add(pnlMain, BorderLayout.CENTER); { jTabbedPane1 = new JTabbedPane(); pnlMain.add(jTabbedPane1, new GridBagConstraints(0, 1, 1, 1, 0.1, 0.1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); { pnlDetails = new JPanel(); GridBagLayout pnlDetailsLayout = new GridBagLayout(); pnlDetailsLayout.columnWeights = new double[]{0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1}; pnlDetailsLayout.columnWidths = new int[]{7, 7, 7, 7, 7, 7, 7, 7, 7, 7}; pnlDetailsLayout.rowWeights = new double[]{0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1}; pnlDetailsLayout.rowHeights = new int[]{7, 7, 7, 7, 7, 7, 7}; pnlDetails.setLayout(pnlDetailsLayout); jTabbedPane1.addTab("Details", null, pnlDetails, null); pnlDetails.setPreferredSize(new java.awt.Dimension(20, 16)); { lblBrewer = new JLabel(); pnlDetails.add(lblBrewer, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblBrewer.setText("Brewer:"); } { brewerNameText = new JTextField(); pnlDetails.add(brewerNameText, new GridBagConstraints(1, 0, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); brewerNameText.setPreferredSize(new java.awt.Dimension(69, 20)); brewerNameText.setText("Brewer"); } { lblDate = new JLabel(); pnlDetails.add(lblDate, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblDate.setText("Date:"); } { lblStyle = new JLabel(); pnlDetails.add(lblStyle, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblStyle.setText("Style:"); } { lblYeast = new JLabel(); pnlDetails.add(lblYeast, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblYeast.setText("Yeast:"); } { lblPreBoil = new JLabel(); pnlDetails.add(lblPreBoil, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblPreBoil.setText("Pre boil:"); } { lblPostBoil = new JLabel(); pnlDetails.add(lblPostBoil, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblPostBoil.setText("Post boil:"); } { lblEffic = new JLabel(); pnlDetails.add(lblEffic, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblEffic.setText("Effic:"); lblEffic.setPreferredSize(new java.awt.Dimension(31, 14)); } { lblAtten = new JLabel(); pnlDetails.add(lblAtten, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblAtten.setText("Atten:"); lblAtten.setPreferredSize(new java.awt.Dimension(34, 14)); } { lblOG = new JLabel(); pnlDetails.add(lblOG, new GridBagConstraints(5, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblOG.setText("OG:"); } { lblFG = new JLabel(); pnlDetails.add(lblFG, new GridBagConstraints(5, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblFG.setText("FG:"); } { lblIBU = new JLabel(); pnlDetails.add(lblIBU, new GridBagConstraints(7, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblIBU.setText("IBU:"); } { lblAlc = new JLabel(); pnlDetails.add(lblAlc, new GridBagConstraints(7, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblAlc.setText("%Alc:"); } { lblColour = new JLabel(); pnlDetails.add(lblColour, new GridBagConstraints(7, 2, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblColour.setText("Colour:"); } { //txtDate = new JFormattedTextField(); txtDate = new DatePicker(); pnlDetails.add(txtDate, new GridBagConstraints(1, 1, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); // txtDate.setText("Date"); txtDate.setPreferredSize(new java.awt.Dimension(73, 20)); txtDate.setDateStyle(DateFormat.SHORT); } { cmbStyleModel = new ComboModel(); cmbStyle = new JComboBox(); pnlDetails.add(cmbStyle, new GridBagConstraints(1, 2, 5, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cmbStyle.setModel(cmbStyleModel); cmbStyle.setMaximumSize(new java.awt.Dimension(100, 32767)); cmbStyle.setPreferredSize(new java.awt.Dimension(190, 20)); } { txtPreBoil = new JFormattedTextField(); pnlDetails.add(txtPreBoil, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); txtPreBoil.setText("Pre Boil"); txtPreBoil.setPreferredSize(new java.awt.Dimension(37, 20)); } { postBoilText = new JFormattedTextField(); pnlDetails.add(postBoilText, new GridBagConstraints(1, 5, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); postBoilText.setText("Post Boil"); postBoilText.setPreferredSize(new java.awt.Dimension(46, 20)); } { lblComments = new JLabel(); pnlDetails.add(lblComments, new GridBagConstraints(6, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblComments.setText("Comments:"); } { SpinnerNumberModel spnEfficModel = new SpinnerNumberModel(75.0, 0.0, 100.0, 1.0); spnEffic = new JSpinner(); pnlDetails.add(spnEffic, new GridBagConstraints(4, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnEffic.setModel(spnEfficModel); spnEffic.setMaximumSize(new java.awt.Dimension(70, 32767)); spnEffic.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { myRecipe.setEfficiency(Double.parseDouble(spnEffic.getValue() .toString())); displayRecipe(); } }); spnEffic.setEditor(new JSpinner.NumberEditor(spnEffic, "00.#")); spnEffic.getEditor().setPreferredSize(new java.awt.Dimension(28, 16)); spnEffic.setPreferredSize(new java.awt.Dimension(53, 18)); } { SpinnerNumberModel spnAttenModel = new SpinnerNumberModel(75.0, 0.0, 100.0, 1.0); spnAtten = new JSpinner(); pnlDetails.add(spnAtten, new GridBagConstraints(4, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnAtten.setModel(spnAttenModel); spnAtten.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { myRecipe.setAttenuation(Double.parseDouble(spnAtten.getValue() .toString())); displayRecipe(); } }); spnAtten.setEditor(new JSpinner.NumberEditor(spnAtten, "00.#")); spnAtten.setPreferredSize(new java.awt.Dimension(49, 20)); } { SpinnerNumberModel spnOgModel = new SpinnerNumberModel(1.000, 0.900, 2.000, 0.001); spnOG = new JSpinner(); pnlDetails.add(spnOG, new GridBagConstraints(6, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnOG.setModel(spnOgModel); spnOG.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { myRecipe.setEstOg(Double.parseDouble(spnOG.getValue() .toString())); displayRecipe(); } }); spnOG.setEditor(new JSpinner.NumberEditor(spnOG, "0.000")); spnOG.getEditor().setPreferredSize(new java.awt.Dimension(20, 16)); spnOG.setPreferredSize(new java.awt.Dimension(67, 18)); } { SpinnerNumberModel spnFgModel = new SpinnerNumberModel(1.000, 0.900, 2.000, 0.001); spnFG = new JSpinner(); pnlDetails.add(spnFG, new GridBagConstraints(6, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnFG.setModel(spnFgModel); spnFG.setEditor(new JSpinner.NumberEditor(spnFG, "0.000")); spnFG.setPreferredSize(new java.awt.Dimension(69, 20)); spnFG.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { // set the new FG, and update alc: myRecipe.setEstFg(Double.parseDouble(spnFG.getValue() .toString())); displayRecipe(); } }); } { lblIBUvalue = new JLabel(); pnlDetails.add(lblIBUvalue, new GridBagConstraints(8, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblIBUvalue.setText("IBUs"); } { lblColourValue = new JLabel(); pnlDetails.add(lblColourValue, new GridBagConstraints(8, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblColourValue.setText("Colour"); } { lblAlcValue = new JLabel(); pnlDetails.add(lblAlcValue, new GridBagConstraints(8, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblAlcValue.setText("Alc"); } { scpComments = new JScrollPane(); pnlDetails.add(scpComments, new GridBagConstraints(7, 4, 3, 2, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); { txtComments = new JTextArea(); scpComments.setViewportView(txtComments); txtComments.setText("Comments"); txtComments.setWrapStyleWord(true); // txtComments.setPreferredSize(new java.awt.Dimension(117, 42)); txtComments.setLineWrap(true); txtComments.setPreferredSize(new java.awt.Dimension(263, 40)); txtComments.addFocusListener(new FocusAdapter() { public void focusLost(FocusEvent evt) { if (!txtComments.getText().equals(myRecipe.getComments())) { myRecipe.setComments(txtComments.getText()); } } }); } } { cmbYeastModel = new ComboModel(); cmbYeast = new JComboBox(); pnlDetails.add(cmbYeast, new GridBagConstraints(1, 3, 5, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cmbYeast.setModel(cmbYeastModel); cmbYeast.setPreferredSize(new java.awt.Dimension(193, 20)); } { cmbSizeUnitsModel = new ComboModel(); cmbSizeUnits = new JComboBox(); pnlDetails.add(cmbSizeUnits, new GridBagConstraints(2, 4, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cmbSizeUnits.setModel(cmbSizeUnitsModel); } { lblSizeUnits = new JLabel(); pnlDetails.add(lblSizeUnits, new GridBagConstraints(2, 5, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); lblSizeUnits.setText("Size Units"); } { boilTimeLable = new JLabel(); pnlDetails.add(boilTimeLable, new GridBagConstraints(4, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); boilTimeLable.setText("Boil Min:"); } { evapLabel = new JLabel(); pnlDetails.add(evapLabel, new GridBagConstraints(4, 5, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); evapLabel.setText("Evap/hr:"); } { boilMinText = new JTextField(); pnlDetails.add(boilMinText, new GridBagConstraints(5, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); boilMinText.setText("60"); boilMinText.setPreferredSize(new java.awt.Dimension(22, 20)); } { evapText = new JTextField(); pnlDetails.add(evapText, new GridBagConstraints(5, 5, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); evapText.setText("4"); evapText.setPreferredSize(new java.awt.Dimension(23, 20)); } { alcMethodComboModel = new DefaultComboBoxModel(new String[]{"Volume", "Weight"}); alcMethodCombo = new JComboBox(alcMethodComboModel); pnlDetails.add(alcMethodCombo, new GridBagConstraints(9, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); alcMethodCombo.setPreferredSize(new java.awt.Dimension(58, 20)); } { ibuMethodComboModel = new DefaultComboBoxModel(new String[]{"Tinseth", "Garetz", "Rager"}); ibuMethodCombo = new JComboBox(ibuMethodComboModel); pnlDetails.add(ibuMethodCombo, new GridBagConstraints(9, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); ibuMethodCombo.setPreferredSize(new java.awt.Dimension(59, 20)); } { colourMethodComboModel = new DefaultComboBoxModel(new String[]{"SRM", "EBC"}); colourMethodCombo = new JComboBox(colourMethodComboModel); pnlDetails.add(colourMethodCombo, new GridBagConstraints(9, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); colourMethodCombo.setPreferredSize(new java.awt.Dimension(44, 20)); } ComboBoxModel evapMethodComboModel = new DefaultComboBoxModel(new String[] { "Constant", "Percent" }); { jPanel1 = new JPanel(); pnlMain.add(jPanel1, new GridBagConstraints( 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); FlowLayout jPanel1Layout = new FlowLayout(); jPanel1Layout.setAlignment(FlowLayout.LEFT); jPanel1.setLayout(jPanel1Layout); jToolBar1 = new JToolBar(); getContentPane().add(jToolBar1, BorderLayout.NORTH); jToolBar1.setFloatable(false); jToolBar1.setRollover(true); jButton1 = new JButton(); jToolBar1.add(jButton1); jButton1.setMnemonic(java.awt.event.KeyEvent.VK_S); jButton1.setIcon(new ImageIcon(getClass().getClassLoader().getResource( "ca/strangebrew/icons/save.gif"))); jButton1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { System.out.println("jButton1.actionPerformed, event=" + evt); //TODO add your code for jButton1.actionPerformed } }); jButton2 = new JButton(); jToolBar1.add(jButton2); jButton2.setIcon(new ImageIcon(getClass().getClassLoader().getResource( "ca/strangebrew/icons/find.gif"))); jButton2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { System.out.println("jButton2.actionPerformed, event=" + evt); //TODO add your code for jButton2.actionPerformed } }); { lblName = new JLabel(); jPanel1.add(lblName); lblName.setText("Name:"); } { txtName = new JTextField(); jPanel1.add(txtName); txtName.setText("Name"); txtName.setPreferredSize(new java.awt.Dimension(297, 20)); } } evapMethodCombo = new JComboBox(); pnlDetails.add(evapMethodCombo, new GridBagConstraints(6, 5, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); evapMethodCombo.setModel(evapMethodComboModel); evapMethodCombo.setPreferredSize(new java.awt.Dimension(64, 20)); colourPanel = new JPanel(); pnlDetails.add(colourPanel, new GridBagConstraints(9, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); colourPanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); } { SBNotifier sbn = new SBNotifier(); stylePanel = new StylePanel(sbn); jTabbedPane1.addTab("Style", null, stylePanel, null); miscPanel = new MiscPanel(myRecipe); jTabbedPane1.addTab("Misc", null, miscPanel, null); notesPanel = new NotesPanel(); jTabbedPane1.addTab("Notes", null, notesPanel, null); dilutionPanel = new DilutionPanel(); jTabbedPane1.addTab("Dilution", null, dilutionPanel, null); mashPanel = new MashPanel(myRecipe); jTabbedPane1.addTab("Mash", null, mashPanel, null); waterPanel = new WaterPanel(); jTabbedPane1.addTab("Water", null, waterPanel, null); costPanel = new CostPanel(); jTabbedPane1.addTab("Cost", null, costPanel, null); // SBNotifier sbn = new SBNotifier(); settingsPanel = new SettingsPanel(sbn); jTabbedPane1.addTab("Settings", null, settingsPanel, null); } } { pnlTables = new JPanel(); BoxLayout pnlMaltsLayout = new BoxLayout(pnlTables, javax.swing.BoxLayout.Y_AXIS); pnlMain.add(pnlTables, new GridBagConstraints(0, 2, 1, 1, 0.5, 0.5, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); pnlTables.setLayout(pnlMaltsLayout); { pnlMalt = new JPanel(); pnlTables.add(pnlMalt); BorderLayout pnlMaltLayout1 = new BorderLayout(); pnlMalt.setBorder(BorderFactory.createTitledBorder(new LineBorder( new java.awt.Color(0, 0, 0), 1, false), "Fermentables", TitledBorder.LEADING, TitledBorder.TOP, new java.awt.Font("Dialog", 1, 12), new java.awt.Color(51, 51, 51))); pnlMalt.setLayout(pnlMaltLayout1); { jScrollPane1 = new JScrollPane(); pnlMalt.add(jScrollPane1, BorderLayout.CENTER); { maltTableModel = new MaltTableModel(this); maltTable = new JTable() { public String getToolTipText(MouseEvent e) { java.awt.Point p = e.getPoint(); int rowIndex = rowAtPoint(p); return SBStringUtils.multiLineToolTip(40, maltTableModel .getDescriptionAt(rowIndex)); } }; jScrollPane1.setViewportView(maltTable); maltTable.setModel(maltTableModel); // maltTable.setAutoCreateColumnsFromModel(false); maltTable.getTableHeader().setReorderingAllowed(false); TableColumn maltColumn = maltTable.getColumnModel().getColumn(0); // set up malt list combo maltComboBox = new JComboBox(); cmbMaltModel = new ComboModel(); maltComboBox.setModel(cmbMaltModel); maltColumn.setCellEditor(new DefaultCellEditor(maltComboBox)); // set up malt amount editor amountEditor = new SBCellEditor(new JTextField()); maltColumn = maltTable.getColumnModel().getColumn(1); maltColumn.setCellEditor(amountEditor); // set up malt units combo maltUnitsComboBox = new JComboBox(); cmbMaltUnitsModel = new ComboModel(); maltUnitsComboBox.setModel(cmbMaltUnitsModel); maltColumn = maltTable.getColumnModel().getColumn(4); maltColumn.setCellEditor(new DefaultCellEditor(maltUnitsComboBox)); } } { tblMaltTotalsModel = new DefaultTableModel(new String[][]{{""}}, new String[]{"Malt", "Amount", "Units", "Points", "Lov", "Cost/U", "%"}); tblMaltTotals = new JTable(); pnlMalt.add(tblMaltTotals, BorderLayout.SOUTH); tblMaltTotals.setModel(tblMaltTotalsModel); tblMaltTotals.getTableHeader().setEnabled(false); tblMaltTotals.setAutoCreateColumnsFromModel(false); // set up the units combobox maltTotalUnitsComboBox = new JComboBox(); maltTotalUnitsComboModel = new ComboModel(); maltTotalUnitsComboModel.setList(new Quantity().getListofUnits("weight")); maltTotalUnitsComboBox.setModel(maltTotalUnitsComboModel); TableColumn t = tblMaltTotals.getColumnModel().getColumn(2); t.setCellEditor(new DefaultCellEditor(maltTotalUnitsComboBox)); maltTotalUnitsComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { String u = (String) maltTotalUnitsComboModel.getSelectedItem(); if (myRecipe != null) { myRecipe.setMaltUnits(u); displayRecipe(); } } }); } } { pnlMaltButtons = new JPanel(); pnlTables.add(pnlMaltButtons); FlowLayout pnlMaltButtonsLayout = new FlowLayout(); pnlMaltButtonsLayout.setAlignment(FlowLayout.LEFT); pnlMaltButtonsLayout.setVgap(0); pnlMaltButtons.setLayout(pnlMaltButtonsLayout); pnlMaltButtons.setPreferredSize(new java.awt.Dimension(592, 27)); { tlbMalt = new JToolBar(); pnlMaltButtons.add(tlbMalt); tlbMalt.setPreferredSize(new java.awt.Dimension(386, 20)); tlbMalt.setFloatable(false); { btnAddMalt = new JButton(); tlbMalt.add(btnAddMalt); btnAddMalt.setText("+"); btnAddMalt.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { Fermentable f = new Fermentable(myRecipe.getMaltUnits()); myRecipe.addMalt(f); maltTable.updateUI(); displayRecipe(); } } }); } { btnDelMalt = new JButton(); tlbMalt.add(btnDelMalt); btnDelMalt.setText("-"); btnDelMalt.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { int i = maltTable.getSelectedRow(); myRecipe.delMalt(i); maltTable.updateUI(); displayRecipe(); } } }); } } } { pnlHops = new JPanel(); BorderLayout pnlHopsLayout = new BorderLayout(); pnlHops.setBorder(BorderFactory.createTitledBorder(new LineBorder( new java.awt.Color(0, 0, 0), 1, false), "Hops", TitledBorder.LEADING, TitledBorder.TOP, new java.awt.Font("Dialog", 1, 12), new java.awt.Color(51, 51, 51))); pnlHops.setLayout(pnlHopsLayout); pnlTables.add(pnlHops); { tblHopsTotalsModel = new DefaultTableModel(new String[][]{{""}}, new String[]{"1", "2", "3", "4", "5", "6", "7", "8", "9"}); tblHopsTotals = new JTable(); pnlHops.add(tblHopsTotals, BorderLayout.SOUTH); tblHopsTotals.setModel(tblHopsTotalsModel); tblHopsTotals.setAutoCreateColumnsFromModel(false); // set up the units combobox hopsTotalUnitsComboBox = new JComboBox(); hopsTotalUnitsComboModel = new ComboModel(); hopsTotalUnitsComboModel.setList(new Quantity().getListofUnits("weight")); hopsTotalUnitsComboBox.setModel(hopsTotalUnitsComboModel); TableColumn t = tblHopsTotals.getColumnModel().getColumn(4); t.setCellEditor(new DefaultCellEditor(hopsTotalUnitsComboBox)); hopsTotalUnitsComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { String u = (String) hopsTotalUnitsComboModel.getSelectedItem(); if (myRecipe != null) { myRecipe.setHopsUnits(u); displayRecipe(); } } }); } { jScrollPane2 = new JScrollPane(); pnlHops.add(jScrollPane2, BorderLayout.CENTER); { hopsTableModel = new HopsTableModel(this); hopsTable = new JTable() { public String getToolTipText(MouseEvent e) { java.awt.Point p = e.getPoint(); int rowIndex = rowAtPoint(p); return SBStringUtils.multiLineToolTip(40, hopsTableModel .getDescriptionAt(rowIndex)); } }; jScrollPane2.setViewportView(hopsTable); hopsTable.setModel(hopsTableModel); hopsTable.getTableHeader().setReorderingAllowed(false); TableColumn hopColumn = hopsTable.getColumnModel().getColumn(0); hopComboBox = new JComboBox(); cmbHopsModel = new ComboModel(); hopComboBox.setModel(cmbHopsModel); hopColumn.setCellEditor(new DefaultCellEditor(hopComboBox)); // set up hop units combo hopsUnitsComboBox = new JComboBox(); cmbHopsUnitsModel = new ComboModel(); hopsUnitsComboBox.setModel(cmbHopsUnitsModel); hopColumn = hopsTable.getColumnModel().getColumn(4); hopColumn.setCellEditor(new DefaultCellEditor(hopsUnitsComboBox)); // set up hop type combo String[] forms = {"Leaf", "Pellet", "Plug"}; JComboBox hopsFormComboBox = new JComboBox(forms); hopColumn = hopsTable.getColumnModel().getColumn(1); hopColumn.setCellEditor(new DefaultCellEditor(hopsFormComboBox)); // set up hop add combo String[] add = {"Boil", "FWH", "Dry", "Mash"}; JComboBox hopsAddComboBox = new JComboBox(add); hopColumn = hopsTable.getColumnModel().getColumn(5); hopColumn.setCellEditor(new DefaultCellEditor(hopsAddComboBox)); } } } { pnlHopsButtons = new JPanel(); FlowLayout pnlHopsButtonsLayout = new FlowLayout(); pnlHopsButtonsLayout.setAlignment(FlowLayout.LEFT); pnlHopsButtonsLayout.setVgap(0); pnlHopsButtons.setLayout(pnlHopsButtonsLayout); pnlTables.add(pnlHopsButtons); pnlHopsButtons.setPreferredSize(new java.awt.Dimension(512, 16)); { tlbHops = new JToolBar(); pnlHopsButtons.add(tlbHops); tlbHops.setPreferredSize(new java.awt.Dimension(413, 19)); tlbHops.setFloatable(false); { btnAddHop = new JButton(); tlbHops.add(btnAddHop); btnAddHop.setText("+"); btnAddHop.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { Hop h = new Hop(myRecipe.getHopUnits()); myRecipe.addHop(h); hopsTable.updateUI(); displayRecipe(); } } }); } { btnDelHop = new JButton(); tlbHops.add(btnDelHop); btnDelHop.setText("-"); btnDelHop.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { int i = hopsTable.getSelectedRow(); myRecipe.delHop(i); hopsTable.updateUI(); displayRecipe(); } } }); } } } } { statusPanel = new JPanel(); FlowLayout statusPanelLayout = new FlowLayout(); statusPanelLayout.setAlignment(FlowLayout.LEFT); statusPanelLayout.setHgap(2); statusPanelLayout.setVgap(2); statusPanel.setLayout(statusPanelLayout); pnlMain.add(statusPanel, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); { fileNamePanel = new JPanel(); statusPanel.add(fileNamePanel); fileNamePanel.setBorder(BorderFactory .createBevelBorder(BevelBorder.LOWERED)); { fileNameLabel = new JLabel(); fileNamePanel.add(fileNameLabel); fileNameLabel.setText("File Name"); fileNameLabel.setFont(new java.awt.Font("Dialog", 1, 10)); } } { ibuMethodPanel = new JPanel(); statusPanel.add(ibuMethodPanel); ibuMethodPanel.setBorder(BorderFactory .createBevelBorder(BevelBorder.LOWERED)); { ibuMethodLabel = new JLabel(); ibuMethodPanel.add(ibuMethodLabel); ibuMethodLabel.setText("IBU Method:"); ibuMethodLabel.setFont(new java.awt.Font("Dialog", 1, 10)); } } { alcMethodPanel = new JPanel(); statusPanel.add(alcMethodPanel); alcMethodPanel.setBorder(BorderFactory .createBevelBorder(BevelBorder.LOWERED)); { alcMethodLabel = new JLabel(); alcMethodPanel.add(alcMethodLabel); alcMethodLabel.setText("Alc Method:"); alcMethodLabel.setFont(new java.awt.Font("Dialog", 1, 10)); } } } } { jMenuBar1 = new JMenuBar(); setJMenuBar(jMenuBar1); { fileMenu = new JMenu(); jMenuBar1.add(fileMenu); fileMenu.setText("File"); { newFileMenuItem = new JMenuItem(); fileMenu.add(newFileMenuItem); newFileMenuItem.setText("New"); newFileMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // This is just a test right now to see that // stuff is changed. myRecipe = new Recipe(); myRecipe.setVersion(version); currentFile = null; attachRecipeData(); displayRecipe(); } }); } { openFileMenuItem = new JMenuItem(); fileMenu.add(openFileMenuItem); openFileMenuItem.setText("Open"); openFileMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_O, ActionEvent.CTRL_MASK)); openFileMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Show open dialog; this method does // not return until the dialog is closed String[] ext = {"xml", "qbrew", "rec"}; String desc = "StrangBrew and importable formats"; sbFileFilter openFileFilter = new sbFileFilter(ext, desc); // fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); fileChooser.setFileFilter(openFileFilter); int returnVal = fileChooser.showOpenDialog(jMenuBar1); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); Debug.print("Opening: " + file.getName() + ".\n"); OpenImport oi = new OpenImport(); myRecipe = oi.openFile(file); if (oi.getFileType().equals("")){ JOptionPane.showMessageDialog( null, "The file you've tried to open isn't a recognized format. \n" + "You can open: \n" + "StrangeBrew 1.x and Java files (.xml)\n" + "QBrew files (.qbrew)\n" + "BeerXML files (.xml)\n" + "Promash files (.rec)", "Unrecognized Format!", JOptionPane.INFORMATION_MESSAGE); } if (oi.getFileType().equals("beerxml")){ JOptionPane.showMessageDialog( null, "The file you've opened is in BeerXML format. It may contain \n" + "several recipes. Only the first recipe is opened. Use the Find \n" + "dialog to open other recipes in a BeerXML file.", "BeerXML!", JOptionPane.INFORMATION_MESSAGE); } myRecipe.setVersion(version); myRecipe.calcMaltTotals(); myRecipe.calcHopsTotals(); myRecipe.mash.calcMashSchedule(); checkIngredientsInDB(); attachRecipeData(); currentFile = file; displayRecipe(); } else { Debug.print("Open command cancelled by user.\n"); } } }); } { imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/find.gif"); icon = new ImageIcon(imgURL); findFileMenuItem = new JMenuItem("Find", icon); findFileMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_F, ActionEvent.CTRL_MASK)); fileMenu.add(findFileMenuItem); final JFrame owner = this; findFileMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // open the find dialog FindDialog fd = new FindDialog(owner); fd.setVisible(true); } }); } { imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/save.gif"); icon = new ImageIcon(imgURL); saveMenuItem = new JMenuItem("Save", icon); fileMenu.add(saveMenuItem); saveMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_S, ActionEvent.CTRL_MASK)); saveMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { int choice = 1; if (currentFile != null) { File file = currentFile; //This is where a real application would save the file. try { FileWriter out = new FileWriter(file); out.write(myRecipe.toXML()); out.close(); Debug.print("Saved: " + file.getAbsoluteFile()); currentFile = file; } catch (Exception e) { showError(e); } } // prompt to save if not already saved else { choice = JOptionPane.showConfirmDialog(null, "File not saved. Do you wish to save it?", "File note saved", JOptionPane.YES_NO_OPTION); } if (choice == 0) { // same as save as: saveAs(); } } }); } { imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/saveas.gif"); icon = new ImageIcon(imgURL); saveAsMenuItem = new JMenuItem("Save As ...", icon); fileMenu.add(saveAsMenuItem); saveAsMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // This is just a test right now to see that // stuff is changed. Debug.print(myRecipe.toXML()); saveAs(); } }); } { exportMenu = new JMenu(); fileMenu.add(exportMenu); exportMenu.setText("Export"); { exportHTMLmenu = new JMenuItem(); exportMenu.add(exportHTMLmenu); exportHTMLmenu.setText("HTML"); exportHTMLmenu.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Show save dialog; this method does // not return until the dialog is closed String[] ext = {"html", "htm"}; sbFileFilter saveFileFilter = new sbFileFilter(ext, "HTML"); fileChooser.setFileFilter(saveFileFilter); fileChooser.setSelectedFile(new File(myRecipe.getName() + ".html")); int returnVal = fileChooser.showSaveDialog(jMenuBar1); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); //This is where a real application would save the file. try { saveAsHTML(file, "ca/strangebrew/data/recipeToHtml.xslt"); } catch (Exception e) { showError(e); } } else { Debug.print("Save command cancelled by user.\n"); } } }); exportTextMenuItem = new JMenuItem(); exportMenu.add(exportTextMenuItem); exportTextMenuItem.setText("Text"); exportTextMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Show save dialog; this method does // not return until the dialog is closed String[] ext = {"txt"}; sbFileFilter saveFileFilter = new sbFileFilter(ext, "Text"); fileChooser.setFileFilter(saveFileFilter); fileChooser.setSelectedFile(new File(myRecipe.getName() + ".txt")); int returnVal = fileChooser.showSaveDialog(jMenuBar1); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); //This is where a real application would save the file. try { FileWriter out = new FileWriter(file); out.write(myRecipe.toText()); out.close(); } catch (Exception e) { showError(e); } } else { Debug.print("Export text command cancelled by user.\n"); } } }); } } { JMenuItem clipboardMenuItem = new JMenuItem("Copy to Clipboard"); fileMenu.add(clipboardMenuItem); clipboardMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Copy current recipe to clipboard Clipboard clipboard = getToolkit ().getSystemClipboard (); StringSelection s = new StringSelection(myRecipe.toText()); clipboard.setContents(s, s); } }); JMenuItem printMenuItem = new JMenuItem("Print..."); fileMenu.add(printMenuItem); final JFrame owner = this; printMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Copy current recipe to clipboard// save file as xml, then transform it to html File tmp = new File("tmp.html"); try { saveAsHTML(tmp, "ca/strangebrew/data/recipeToSimpleHtml.xslt"); HTMLViewer view = new HTMLViewer(owner, tmp.toURL()); view.setModal(true); view.setVisible(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } tmp.delete(); } }); } { jSeparator2 = new JSeparator(); fileMenu.add(jSeparator2); } { exitMenuItem = new JMenuItem(); fileMenu.add(exitMenuItem); exitMenuItem.setText("Exit"); exitMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_Q, ActionEvent.CTRL_MASK)); final JFrame owner = this; exitMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // exit program processWindowEvent(new WindowEvent(owner,WindowEvent.WINDOW_CLOSING)); System.exit(0); } }); } } { jMenu4 = new JMenu(); jMenuBar1.add(jMenu4); jMenu4.setText("Edit"); { final JFrame owner = this; editPrefsMenuItem = new JMenuItem(); jMenu4.add(editPrefsMenuItem); editPrefsMenuItem.setText("Preferences..."); editPrefsMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { PreferencesDialog d = new PreferencesDialog(owner, preferences); d.setVisible(true); } }); } { jSeparator1 = new JSeparator(); jMenu4.add(jSeparator1); } { deleteMenuItem = new JMenuItem(); jMenu4.add(deleteMenuItem); deleteMenuItem.setText("Delete"); deleteMenuItem.setEnabled(false); } } { mnuTools = new JMenu(); jMenuBar1.add(mnuTools); mnuTools.setText("Tools"); { final JFrame owner = this; JMenuItem scalRecipeMenuItem = new JMenuItem(); mnuTools.add(scalRecipeMenuItem); scalRecipeMenuItem.setText("Scale Recipe..."); scalRecipeMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_R, ActionEvent.CTRL_MASK)); scalRecipeMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { ScaleRecipeDialog scaleRecipe = new ScaleRecipeDialog(owner); scaleRecipe.setModal(true); scaleRecipe.setVisible(true); } }); JMenuItem maltPercentMenuItem = new JMenuItem(); mnuTools.add(maltPercentMenuItem); maltPercentMenuItem.setText("Malt Percent..."); maltPercentMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_M, ActionEvent.CTRL_MASK)); maltPercentMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { MaltPercentDialog maltPercent = new MaltPercentDialog(owner); maltPercent.setModal(true); maltPercent.setVisible(true); } }); } } { jMenu5 = new JMenu(); jMenuBar1.add(jMenu5); jMenu5.setText("Help"); { helpMenuItem = new JMenuItem(); jMenu5.add(helpMenuItem); helpMenuItem.setText("Help"); final JFrame owner = this; helpMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { URL help; try { help = new File(appRoot + "/help/index.html").toURL(); HTMLViewer view = new HTMLViewer(owner, help); view.setModal(true); view.setVisible(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); } { aboutMenuItem = new JMenuItem(); jMenu5.add(aboutMenuItem); aboutMenuItem.setText("About..."); final JFrame owner = this; aboutMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { aboutDlg = new AboutDialog(owner, version); aboutDlg.setVisible(true); } }); } } } } catch (Exception e) { e.printStackTrace(); } }
1,115,277
private void initGUI() { try { // restore the saved size and location: this.setSize(preferences.getIProperty("winWidth"), preferences.getIProperty("winHeight")); this.setLocation(preferences.getIProperty("winX"), preferences.getIProperty("winY")); imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/sb2.gif"); icon = new ImageIcon(imgURL); this.setIconImage(icon.getImage()); this.setTitle("StrangeBrew " + version); this.addWindowListener(new WindowAdapter() { public void windowClosed(WindowEvent evt) { System.exit(1); } }); { pnlMain = new JPanel(); GridBagLayout jPanel2Layout = new GridBagLayout(); jPanel2Layout.columnWeights = new double[]{0.1}; jPanel2Layout.columnWidths = new int[]{7}; jPanel2Layout.rowWeights = new double[]{0.1, 0.1, 0.9, 0.1}; jPanel2Layout.rowHeights = new int[]{7, 7, 7, 7}; pnlMain.setLayout(jPanel2Layout); this.getContentPane().add(pnlMain, BorderLayout.CENTER); { jTabbedPane1 = new JTabbedPane(); pnlMain.add(jTabbedPane1, new GridBagConstraints(0, 1, 1, 1, 0.1, 0.1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); { pnlDetails = new JPanel(); GridBagLayout pnlDetailsLayout = new GridBagLayout(); pnlDetailsLayout.columnWeights = new double[]{0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1}; pnlDetailsLayout.columnWidths = new int[]{7, 7, 7, 7, 7, 7, 7, 7, 7, 7}; pnlDetailsLayout.rowWeights = new double[]{0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1}; pnlDetailsLayout.rowHeights = new int[]{7, 7, 7, 7, 7, 7, 7}; pnlDetails.setLayout(pnlDetailsLayout); jTabbedPane1.addTab("Details", null, pnlDetails, null); pnlDetails.setPreferredSize(new java.awt.Dimension(20, 16)); { lblBrewer = new JLabel(); pnlDetails.add(lblBrewer, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblBrewer.setText("Brewer:"); } { brewerNameText = new JTextField(); pnlDetails.add(brewerNameText, new GridBagConstraints(1, 0, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); brewerNameText.setPreferredSize(new java.awt.Dimension(69, 20)); brewerNameText.setText("Brewer"); } { lblDate = new JLabel(); pnlDetails.add(lblDate, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblDate.setText("Date:"); } { lblStyle = new JLabel(); pnlDetails.add(lblStyle, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblStyle.setText("Style:"); } { lblYeast = new JLabel(); pnlDetails.add(lblYeast, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblYeast.setText("Yeast:"); } { lblPreBoil = new JLabel(); pnlDetails.add(lblPreBoil, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblPreBoil.setText("Pre boil:"); } { lblPostBoil = new JLabel(); pnlDetails.add(lblPostBoil, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblPostBoil.setText("Post boil:"); } { lblEffic = new JLabel(); pnlDetails.add(lblEffic, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblEffic.setText("Effic:"); lblEffic.setPreferredSize(new java.awt.Dimension(31, 14)); } { lblAtten = new JLabel(); pnlDetails.add(lblAtten, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblAtten.setText("Atten:"); lblAtten.setPreferredSize(new java.awt.Dimension(34, 14)); } { lblOG = new JLabel(); pnlDetails.add(lblOG, new GridBagConstraints(5, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblOG.setText("OG:"); } { lblFG = new JLabel(); pnlDetails.add(lblFG, new GridBagConstraints(5, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblFG.setText("FG:"); } { lblIBU = new JLabel(); pnlDetails.add(lblIBU, new GridBagConstraints(7, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblIBU.setText("IBU:"); } { lblAlc = new JLabel(); pnlDetails.add(lblAlc, new GridBagConstraints(7, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblAlc.setText("%Alc:"); } { lblColour = new JLabel(); pnlDetails.add(lblColour, new GridBagConstraints(7, 2, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblColour.setText("Colour:"); } { //txtDate = new JFormattedTextField(); txtDate = new DatePicker(); pnlDetails.add(txtDate, new GridBagConstraints(1, 1, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); // txtDate.setText("Date"); txtDate.setPreferredSize(new java.awt.Dimension(73, 20)); txtDate.setDateStyle(DateFormat.SHORT); } { cmbStyleModel = new ComboModel(); cmbStyle = new JComboBox(); pnlDetails.add(cmbStyle, new GridBagConstraints(1, 2, 5, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cmbStyle.setModel(cmbStyleModel); cmbStyle.setMaximumSize(new java.awt.Dimension(100, 32767)); cmbStyle.setPreferredSize(new java.awt.Dimension(190, 20)); } { txtPreBoil = new JFormattedTextField(); pnlDetails.add(txtPreBoil, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); txtPreBoil.setText("Pre Boil"); txtPreBoil.setPreferredSize(new java.awt.Dimension(37, 20)); } { postBoilText = new JFormattedTextField(); pnlDetails.add(postBoilText, new GridBagConstraints(1, 5, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); postBoilText.setText("Post Boil"); postBoilText.setPreferredSize(new java.awt.Dimension(46, 20)); } { lblComments = new JLabel(); pnlDetails.add(lblComments, new GridBagConstraints(6, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblComments.setText("Comments:"); } { SpinnerNumberModel spnEfficModel = new SpinnerNumberModel(75.0, 0.0, 100.0, 1.0); spnEffic = new JSpinner(); pnlDetails.add(spnEffic, new GridBagConstraints(4, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnEffic.setModel(spnEfficModel); spnEffic.setMaximumSize(new java.awt.Dimension(70, 32767)); spnEffic.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { myRecipe.setEfficiency(Double.parseDouble(spnEffic.getValue() .toString())); displayRecipe(); } }); spnEffic.setEditor(new JSpinner.NumberEditor(spnEffic, "00.#")); spnEffic.getEditor().setPreferredSize(new java.awt.Dimension(28, 16)); spnEffic.setPreferredSize(new java.awt.Dimension(53, 18)); } { SpinnerNumberModel spnAttenModel = new SpinnerNumberModel(75.0, 0.0, 100.0, 1.0); spnAtten = new JSpinner(); pnlDetails.add(spnAtten, new GridBagConstraints(4, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnAtten.setModel(spnAttenModel); spnAtten.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { myRecipe.setAttenuation(Double.parseDouble(spnAtten.getValue() .toString())); displayRecipe(); } }); spnAtten.setEditor(new JSpinner.NumberEditor(spnAtten, "00.#")); spnAtten.setPreferredSize(new java.awt.Dimension(49, 20)); } { SpinnerNumberModel spnOgModel = new SpinnerNumberModel(1.000, 0.900, 2.000, 0.001); spnOG = new JSpinner(); pnlDetails.add(spnOG, new GridBagConstraints(6, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnOG.setModel(spnOgModel); spnOG.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { myRecipe.setEstOg(Double.parseDouble(spnOG.getValue() .toString())); displayRecipe(); } }); spnOG.setEditor(new JSpinner.NumberEditor(spnOG, "0.000")); spnOG.getEditor().setPreferredSize(new java.awt.Dimension(20, 16)); spnOG.setPreferredSize(new java.awt.Dimension(67, 18)); } { SpinnerNumberModel spnFgModel = new SpinnerNumberModel(1.000, 0.900, 2.000, 0.001); spnFG = new JSpinner(); pnlDetails.add(spnFG, new GridBagConstraints(6, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnFG.setModel(spnFgModel); spnFG.setEditor(new JSpinner.NumberEditor(spnFG, "0.000")); spnFG.setPreferredSize(new java.awt.Dimension(69, 20)); spnFG.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { // set the new FG, and update alc: myRecipe.setEstFg(Double.parseDouble(spnFG.getValue() .toString())); displayRecipe(); } }); } { lblIBUvalue = new JLabel(); pnlDetails.add(lblIBUvalue, new GridBagConstraints(8, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblIBUvalue.setText("IBUs"); } { lblColourValue = new JLabel(); pnlDetails.add(lblColourValue, new GridBagConstraints(8, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblColourValue.setText("Colour"); } { lblAlcValue = new JLabel(); pnlDetails.add(lblAlcValue, new GridBagConstraints(8, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblAlcValue.setText("Alc"); } { scpComments = new JScrollPane(); pnlDetails.add(scpComments, new GridBagConstraints(7, 4, 3, 2, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); { txtComments = new JTextArea(); scpComments.setViewportView(txtComments); txtComments.setText("Comments"); txtComments.setWrapStyleWord(true); // txtComments.setPreferredSize(new java.awt.Dimension(117, 42)); txtComments.setLineWrap(true); txtComments.setPreferredSize(new java.awt.Dimension(263, 40)); txtComments.addFocusListener(new FocusAdapter() { public void focusLost(FocusEvent evt) { if (!txtComments.getText().equals(myRecipe.getComments())) { myRecipe.setComments(txtComments.getText()); } } }); } } { cmbYeastModel = new ComboModel(); cmbYeast = new JComboBox(); pnlDetails.add(cmbYeast, new GridBagConstraints(1, 3, 5, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cmbYeast.setModel(cmbYeastModel); cmbYeast.setPreferredSize(new java.awt.Dimension(193, 20)); } { cmbSizeUnitsModel = new ComboModel(); cmbSizeUnits = new JComboBox(); pnlDetails.add(cmbSizeUnits, new GridBagConstraints(2, 4, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cmbSizeUnits.setModel(cmbSizeUnitsModel); } { lblSizeUnits = new JLabel(); pnlDetails.add(lblSizeUnits, new GridBagConstraints(2, 5, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); lblSizeUnits.setText("Size Units"); } { boilTimeLable = new JLabel(); pnlDetails.add(boilTimeLable, new GridBagConstraints(4, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); boilTimeLable.setText("Boil Min:"); } { evapLabel = new JLabel(); pnlDetails.add(evapLabel, new GridBagConstraints(4, 5, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); evapLabel.setText("Evap/hr:"); } { boilMinText = new JTextField(); pnlDetails.add(boilMinText, new GridBagConstraints(5, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); boilMinText.setText("60"); boilMinText.setPreferredSize(new java.awt.Dimension(22, 20)); } { evapText = new JTextField(); pnlDetails.add(evapText, new GridBagConstraints(5, 5, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); evapText.setText("4"); evapText.setPreferredSize(new java.awt.Dimension(23, 20)); } { alcMethodComboModel = new DefaultComboBoxModel(new String[]{"Volume", "Weight"}); alcMethodCombo = new JComboBox(alcMethodComboModel); pnlDetails.add(alcMethodCombo, new GridBagConstraints(9, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); alcMethodCombo.setPreferredSize(new java.awt.Dimension(58, 20)); } { ibuMethodComboModel = new DefaultComboBoxModel(new String[]{"Tinseth", "Garetz", "Rager"}); ibuMethodCombo = new JComboBox(ibuMethodComboModel); pnlDetails.add(ibuMethodCombo, new GridBagConstraints(9, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); ibuMethodCombo.setPreferredSize(new java.awt.Dimension(59, 20)); } { colourMethodComboModel = new DefaultComboBoxModel(new String[]{"SRM", "EBC"}); colourMethodCombo = new JComboBox(colourMethodComboModel); pnlDetails.add(colourMethodCombo, new GridBagConstraints(9, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); colourMethodCombo.setPreferredSize(new java.awt.Dimension(44, 20)); } ComboBoxModel evapMethodComboModel = new DefaultComboBoxModel(new String[] { "Constant", "Percent" }); { jPanel1 = new JPanel(); pnlMain.add(jPanel1, new GridBagConstraints( 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); FlowLayout jPanel1Layout = new FlowLayout(); jPanel1Layout.setAlignment(FlowLayout.LEFT); jPanel1.setLayout(jPanel1Layout); jToolBar1 = new JToolBar(); getContentPane().add(jToolBar1, BorderLayout.NORTH); jToolBar1.setFloatable(false); jToolBar1.setRollover(true); jButton1 = new JButton(); jToolBar1.add(jButton1); jButton1.setMnemonic(java.awt.event.KeyEvent.VK_S); jButton1.setIcon(new ImageIcon(getClass().getClassLoader().getResource( "ca/strangebrew/icons/save.gif"))); jButton1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { System.out.println("jButton1.actionPerformed, event=" + evt); //TODO add your code for jButton1.actionPerformed } }); jButton2 = new JButton(); jToolBar1.add(jButton2); jButton2.setIcon(new ImageIcon(getClass().getClassLoader().getResource( "ca/strangebrew/icons/find.gif"))); jButton2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { System.out.println("jButton2.actionPerformed, event=" + evt); //TODO add your code for jButton2.actionPerformed } }); { lblName = new JLabel(); jPanel1.add(lblName); lblName.setText("Name:"); } { txtName = new JTextField(); jPanel1.add(txtName); txtName.setText("Name"); txtName.setPreferredSize(new java.awt.Dimension(297, 20)); } } evapMethodCombo = new JComboBox(); pnlDetails.add(evapMethodCombo, new GridBagConstraints(6, 5, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); evapMethodCombo.setModel(evapMethodComboModel); evapMethodCombo.setPreferredSize(new java.awt.Dimension(64, 20)); colourPanel = new JPanel(); pnlDetails.add(colourPanel, new GridBagConstraints(9, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); colourPanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); } { SBNotifier sbn = new SBNotifier(); stylePanel = new StylePanel(sbn); jTabbedPane1.addTab("Style", null, stylePanel, null); miscPanel = new MiscPanel(myRecipe); jTabbedPane1.addTab("Misc", null, miscPanel, null); notesPanel = new NotesPanel(); jTabbedPane1.addTab("Notes", null, notesPanel, null); dilutionPanel = new DilutionPanel(); jTabbedPane1.addTab("Dilution", null, dilutionPanel, null); mashPanel = new MashPanel(myRecipe); jTabbedPane1.addTab("Mash", null, mashPanel, null); waterPanel = new WaterPanel(); jTabbedPane1.addTab("Water", null, waterPanel, null); costPanel = new CostPanel(); jTabbedPane1.addTab("Cost", null, costPanel, null); // SBNotifier sbn = new SBNotifier(); settingsPanel = new SettingsPanel(sbn); jTabbedPane1.addTab("Settings", null, settingsPanel, null); } } { pnlTables = new JPanel(); BoxLayout pnlMaltsLayout = new BoxLayout(pnlTables, javax.swing.BoxLayout.Y_AXIS); pnlMain.add(pnlTables, new GridBagConstraints(0, 2, 1, 1, 0.5, 0.5, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); pnlTables.setLayout(pnlMaltsLayout); { pnlMalt = new JPanel(); pnlTables.add(pnlMalt); BorderLayout pnlMaltLayout1 = new BorderLayout(); pnlMalt.setBorder(BorderFactory.createTitledBorder(new LineBorder( new java.awt.Color(0, 0, 0), 1, false), "Fermentables", TitledBorder.LEADING, TitledBorder.TOP, new java.awt.Font("Dialog", 1, 12), new java.awt.Color(51, 51, 51))); pnlMalt.setLayout(pnlMaltLayout1); { jScrollPane1 = new JScrollPane(); pnlMalt.add(jScrollPane1, BorderLayout.CENTER); { maltTableModel = new MaltTableModel(this); maltTable = new JTable() { public String getToolTipText(MouseEvent e) { java.awt.Point p = e.getPoint(); int rowIndex = rowAtPoint(p); return SBStringUtils.multiLineToolTip(40, maltTableModel .getDescriptionAt(rowIndex)); } }; jScrollPane1.setViewportView(maltTable); maltTable.setModel(maltTableModel); // maltTable.setAutoCreateColumnsFromModel(false); maltTable.getTableHeader().setReorderingAllowed(false); TableColumn maltColumn = maltTable.getColumnModel().getColumn(0); // set up malt list combo maltComboBox = new JComboBox(); cmbMaltModel = new ComboModel(); maltComboBox.setModel(cmbMaltModel); maltColumn.setCellEditor(new DefaultCellEditor(maltComboBox)); // set up malt amount editor amountEditor = new SBCellEditor(new JTextField()); maltColumn = maltTable.getColumnModel().getColumn(1); maltColumn.setCellEditor(amountEditor); // set up malt units combo maltUnitsComboBox = new JComboBox(); cmbMaltUnitsModel = new ComboModel(); maltUnitsComboBox.setModel(cmbMaltUnitsModel); maltColumn = maltTable.getColumnModel().getColumn(2); maltColumn.setCellEditor(new DefaultCellEditor(maltUnitsComboBox)); } } { tblMaltTotalsModel = new DefaultTableModel(new String[][]{{""}}, new String[]{"Malt", "Amount", "Units", "Points", "Lov", "Cost/U", "%"}); tblMaltTotals = new JTable(); pnlMalt.add(tblMaltTotals, BorderLayout.SOUTH); tblMaltTotals.setModel(tblMaltTotalsModel); tblMaltTotals.getTableHeader().setEnabled(false); tblMaltTotals.setAutoCreateColumnsFromModel(false); // set up the units combobox maltTotalUnitsComboBox = new JComboBox(); maltTotalUnitsComboModel = new ComboModel(); maltTotalUnitsComboModel.setList(new Quantity().getListofUnits("weight")); maltTotalUnitsComboBox.setModel(maltTotalUnitsComboModel); TableColumn t = tblMaltTotals.getColumnModel().getColumn(2); t.setCellEditor(new DefaultCellEditor(maltTotalUnitsComboBox)); maltTotalUnitsComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { String u = (String) maltTotalUnitsComboModel.getSelectedItem(); if (myRecipe != null) { myRecipe.setMaltUnits(u); displayRecipe(); } } }); } } { pnlMaltButtons = new JPanel(); pnlTables.add(pnlMaltButtons); FlowLayout pnlMaltButtonsLayout = new FlowLayout(); pnlMaltButtonsLayout.setAlignment(FlowLayout.LEFT); pnlMaltButtonsLayout.setVgap(0); pnlMaltButtons.setLayout(pnlMaltButtonsLayout); pnlMaltButtons.setPreferredSize(new java.awt.Dimension(592, 27)); { tlbMalt = new JToolBar(); pnlMaltButtons.add(tlbMalt); tlbMalt.setPreferredSize(new java.awt.Dimension(386, 20)); tlbMalt.setFloatable(false); { btnAddMalt = new JButton(); tlbMalt.add(btnAddMalt); btnAddMalt.setText("+"); btnAddMalt.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { Fermentable f = new Fermentable(myRecipe.getMaltUnits()); myRecipe.addMalt(f); maltTable.updateUI(); displayRecipe(); } } }); } { btnDelMalt = new JButton(); tlbMalt.add(btnDelMalt); btnDelMalt.setText("-"); btnDelMalt.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { int i = maltTable.getSelectedRow(); myRecipe.delMalt(i); maltTable.updateUI(); displayRecipe(); } } }); } } } { pnlHops = new JPanel(); BorderLayout pnlHopsLayout = new BorderLayout(); pnlHops.setBorder(BorderFactory.createTitledBorder(new LineBorder( new java.awt.Color(0, 0, 0), 1, false), "Hops", TitledBorder.LEADING, TitledBorder.TOP, new java.awt.Font("Dialog", 1, 12), new java.awt.Color(51, 51, 51))); pnlHops.setLayout(pnlHopsLayout); pnlTables.add(pnlHops); { tblHopsTotalsModel = new DefaultTableModel(new String[][]{{""}}, new String[]{"1", "2", "3", "4", "5", "6", "7", "8", "9"}); tblHopsTotals = new JTable(); pnlHops.add(tblHopsTotals, BorderLayout.SOUTH); tblHopsTotals.setModel(tblHopsTotalsModel); tblHopsTotals.setAutoCreateColumnsFromModel(false); // set up the units combobox hopsTotalUnitsComboBox = new JComboBox(); hopsTotalUnitsComboModel = new ComboModel(); hopsTotalUnitsComboModel.setList(new Quantity().getListofUnits("weight")); hopsTotalUnitsComboBox.setModel(hopsTotalUnitsComboModel); TableColumn t = tblHopsTotals.getColumnModel().getColumn(4); t.setCellEditor(new DefaultCellEditor(hopsTotalUnitsComboBox)); hopsTotalUnitsComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { String u = (String) hopsTotalUnitsComboModel.getSelectedItem(); if (myRecipe != null) { myRecipe.setHopsUnits(u); displayRecipe(); } } }); } { jScrollPane2 = new JScrollPane(); pnlHops.add(jScrollPane2, BorderLayout.CENTER); { hopsTableModel = new HopsTableModel(this); hopsTable = new JTable() { public String getToolTipText(MouseEvent e) { java.awt.Point p = e.getPoint(); int rowIndex = rowAtPoint(p); return SBStringUtils.multiLineToolTip(40, hopsTableModel .getDescriptionAt(rowIndex)); } }; jScrollPane2.setViewportView(hopsTable); hopsTable.setModel(hopsTableModel); hopsTable.getTableHeader().setReorderingAllowed(false); TableColumn hopColumn = hopsTable.getColumnModel().getColumn(0); hopComboBox = new JComboBox(); cmbHopsModel = new ComboModel(); hopComboBox.setModel(cmbHopsModel); hopColumn.setCellEditor(new DefaultCellEditor(hopComboBox)); // set up hop units combo hopsUnitsComboBox = new JComboBox(); cmbHopsUnitsModel = new ComboModel(); hopsUnitsComboBox.setModel(cmbHopsUnitsModel); hopColumn = hopsTable.getColumnModel().getColumn(4); hopColumn.setCellEditor(new DefaultCellEditor(hopsUnitsComboBox)); // set up hop type combo String[] forms = {"Leaf", "Pellet", "Plug"}; JComboBox hopsFormComboBox = new JComboBox(forms); hopColumn = hopsTable.getColumnModel().getColumn(1); hopColumn.setCellEditor(new DefaultCellEditor(hopsFormComboBox)); // set up hop add combo String[] add = {"Boil", "FWH", "Dry", "Mash"}; JComboBox hopsAddComboBox = new JComboBox(add); hopColumn = hopsTable.getColumnModel().getColumn(5); hopColumn.setCellEditor(new DefaultCellEditor(hopsAddComboBox)); } } } { pnlHopsButtons = new JPanel(); FlowLayout pnlHopsButtonsLayout = new FlowLayout(); pnlHopsButtonsLayout.setAlignment(FlowLayout.LEFT); pnlHopsButtonsLayout.setVgap(0); pnlHopsButtons.setLayout(pnlHopsButtonsLayout); pnlTables.add(pnlHopsButtons); pnlHopsButtons.setPreferredSize(new java.awt.Dimension(512, 16)); { tlbHops = new JToolBar(); pnlHopsButtons.add(tlbHops); tlbHops.setPreferredSize(new java.awt.Dimension(413, 19)); tlbHops.setFloatable(false); { btnAddHop = new JButton(); tlbHops.add(btnAddHop); btnAddHop.setText("+"); btnAddHop.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { Hop h = new Hop(myRecipe.getHopUnits()); myRecipe.addHop(h); hopsTable.updateUI(); displayRecipe(); } } }); } { btnDelHop = new JButton(); tlbHops.add(btnDelHop); btnDelHop.setText("-"); btnDelHop.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { int i = hopsTable.getSelectedRow(); myRecipe.delHop(i); hopsTable.updateUI(); displayRecipe(); } } }); } } } } { statusPanel = new JPanel(); FlowLayout statusPanelLayout = new FlowLayout(); statusPanelLayout.setAlignment(FlowLayout.LEFT); statusPanelLayout.setHgap(2); statusPanelLayout.setVgap(2); statusPanel.setLayout(statusPanelLayout); pnlMain.add(statusPanel, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); { fileNamePanel = new JPanel(); statusPanel.add(fileNamePanel); fileNamePanel.setBorder(BorderFactory .createBevelBorder(BevelBorder.LOWERED)); { fileNameLabel = new JLabel(); fileNamePanel.add(fileNameLabel); fileNameLabel.setText("File Name"); fileNameLabel.setFont(new java.awt.Font("Dialog", 1, 10)); } } { ibuMethodPanel = new JPanel(); statusPanel.add(ibuMethodPanel); ibuMethodPanel.setBorder(BorderFactory .createBevelBorder(BevelBorder.LOWERED)); { ibuMethodLabel = new JLabel(); ibuMethodPanel.add(ibuMethodLabel); ibuMethodLabel.setText("IBU Method:"); ibuMethodLabel.setFont(new java.awt.Font("Dialog", 1, 10)); } } { alcMethodPanel = new JPanel(); statusPanel.add(alcMethodPanel); alcMethodPanel.setBorder(BorderFactory .createBevelBorder(BevelBorder.LOWERED)); { alcMethodLabel = new JLabel(); alcMethodPanel.add(alcMethodLabel); alcMethodLabel.setText("Alc Method:"); alcMethodLabel.setFont(new java.awt.Font("Dialog", 1, 10)); } } } } { jMenuBar1 = new JMenuBar(); setJMenuBar(jMenuBar1); { fileMenu = new JMenu(); jMenuBar1.add(fileMenu); fileMenu.setText("File"); { newFileMenuItem = new JMenuItem(); fileMenu.add(newFileMenuItem); newFileMenuItem.setText("New"); newFileMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // This is just a test right now to see that // stuff is changed. myRecipe = new Recipe(); myRecipe.setVersion(version); currentFile = null; attachRecipeData(); displayRecipe(); } }); } { openFileMenuItem = new JMenuItem(); fileMenu.add(openFileMenuItem); openFileMenuItem.setText("Open"); openFileMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_O, ActionEvent.CTRL_MASK)); openFileMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Show open dialog; this method does // not return until the dialog is closed String[] ext = {"xml", "qbrew", "rec"}; String desc = "StrangBrew and importable formats"; sbFileFilter openFileFilter = new sbFileFilter(ext, desc); // fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); fileChooser.setFileFilter(openFileFilter); int returnVal = fileChooser.showOpenDialog(jMenuBar1); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); Debug.print("Opening: " + file.getName() + ".\n"); OpenImport oi = new OpenImport(); myRecipe = oi.openFile(file); if (oi.getFileType().equals("")){ JOptionPane.showMessageDialog( null, "The file you've tried to open isn't a recognized format. \n" + "You can open: \n" + "StrangeBrew 1.x and Java files (.xml)\n" + "QBrew files (.qbrew)\n" + "BeerXML files (.xml)\n" + "Promash files (.rec)", "Unrecognized Format!", JOptionPane.INFORMATION_MESSAGE); } if (oi.getFileType().equals("beerxml")){ JOptionPane.showMessageDialog( null, "The file you've opened is in BeerXML format. It may contain \n" + "several recipes. Only the first recipe is opened. Use the Find \n" + "dialog to open other recipes in a BeerXML file.", "BeerXML!", JOptionPane.INFORMATION_MESSAGE); } myRecipe.setVersion(version); myRecipe.calcMaltTotals(); myRecipe.calcHopsTotals(); myRecipe.mash.calcMashSchedule(); checkIngredientsInDB(); attachRecipeData(); currentFile = file; displayRecipe(); } else { Debug.print("Open command cancelled by user.\n"); } } }); } { imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/find.gif"); icon = new ImageIcon(imgURL); findFileMenuItem = new JMenuItem("Find", icon); findFileMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_F, ActionEvent.CTRL_MASK)); fileMenu.add(findFileMenuItem); final JFrame owner = this; findFileMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // open the find dialog FindDialog fd = new FindDialog(owner); fd.setVisible(true); } }); } { imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/save.gif"); icon = new ImageIcon(imgURL); saveMenuItem = new JMenuItem("Save", icon); fileMenu.add(saveMenuItem); saveMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_S, ActionEvent.CTRL_MASK)); saveMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { int choice = 1; if (currentFile != null) { File file = currentFile; //This is where a real application would save the file. try { FileWriter out = new FileWriter(file); out.write(myRecipe.toXML()); out.close(); Debug.print("Saved: " + file.getAbsoluteFile()); currentFile = file; } catch (Exception e) { showError(e); } } // prompt to save if not already saved else { choice = JOptionPane.showConfirmDialog(null, "File not saved. Do you wish to save it?", "File note saved", JOptionPane.YES_NO_OPTION); } if (choice == 0) { // same as save as: saveAs(); } } }); } { imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/saveas.gif"); icon = new ImageIcon(imgURL); saveAsMenuItem = new JMenuItem("Save As ...", icon); fileMenu.add(saveAsMenuItem); saveAsMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // This is just a test right now to see that // stuff is changed. Debug.print(myRecipe.toXML()); saveAs(); } }); } { exportMenu = new JMenu(); fileMenu.add(exportMenu); exportMenu.setText("Export"); { exportHTMLmenu = new JMenuItem(); exportMenu.add(exportHTMLmenu); exportHTMLmenu.setText("HTML"); exportHTMLmenu.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Show save dialog; this method does // not return until the dialog is closed String[] ext = {"html", "htm"}; sbFileFilter saveFileFilter = new sbFileFilter(ext, "HTML"); fileChooser.setFileFilter(saveFileFilter); fileChooser.setSelectedFile(new File(myRecipe.getName() + ".html")); int returnVal = fileChooser.showSaveDialog(jMenuBar1); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); //This is where a real application would save the file. try { saveAsHTML(file, "ca/strangebrew/data/recipeToHtml.xslt"); } catch (Exception e) { showError(e); } } else { Debug.print("Save command cancelled by user.\n"); } } }); exportTextMenuItem = new JMenuItem(); exportMenu.add(exportTextMenuItem); exportTextMenuItem.setText("Text"); exportTextMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Show save dialog; this method does // not return until the dialog is closed String[] ext = {"txt"}; sbFileFilter saveFileFilter = new sbFileFilter(ext, "Text"); fileChooser.setFileFilter(saveFileFilter); fileChooser.setSelectedFile(new File(myRecipe.getName() + ".txt")); int returnVal = fileChooser.showSaveDialog(jMenuBar1); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); //This is where a real application would save the file. try { FileWriter out = new FileWriter(file); out.write(myRecipe.toText()); out.close(); } catch (Exception e) { showError(e); } } else { Debug.print("Export text command cancelled by user.\n"); } } }); } } { JMenuItem clipboardMenuItem = new JMenuItem("Copy to Clipboard"); fileMenu.add(clipboardMenuItem); clipboardMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Copy current recipe to clipboard Clipboard clipboard = getToolkit ().getSystemClipboard (); StringSelection s = new StringSelection(myRecipe.toText()); clipboard.setContents(s, s); } }); JMenuItem printMenuItem = new JMenuItem("Print..."); fileMenu.add(printMenuItem); final JFrame owner = this; printMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Copy current recipe to clipboard// save file as xml, then transform it to html File tmp = new File("tmp.html"); try { saveAsHTML(tmp, "ca/strangebrew/data/recipeToSimpleHtml.xslt"); HTMLViewer view = new HTMLViewer(owner, tmp.toURL()); view.setModal(true); view.setVisible(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } tmp.delete(); } }); } { jSeparator2 = new JSeparator(); fileMenu.add(jSeparator2); } { exitMenuItem = new JMenuItem(); fileMenu.add(exitMenuItem); exitMenuItem.setText("Exit"); exitMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_Q, ActionEvent.CTRL_MASK)); final JFrame owner = this; exitMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // exit program processWindowEvent(new WindowEvent(owner,WindowEvent.WINDOW_CLOSING)); System.exit(0); } }); } } { jMenu4 = new JMenu(); jMenuBar1.add(jMenu4); jMenu4.setText("Edit"); { final JFrame owner = this; editPrefsMenuItem = new JMenuItem(); jMenu4.add(editPrefsMenuItem); editPrefsMenuItem.setText("Preferences..."); editPrefsMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { PreferencesDialog d = new PreferencesDialog(owner, preferences); d.setVisible(true); } }); } { jSeparator1 = new JSeparator(); jMenu4.add(jSeparator1); } { deleteMenuItem = new JMenuItem(); jMenu4.add(deleteMenuItem); deleteMenuItem.setText("Delete"); deleteMenuItem.setEnabled(false); } } { mnuTools = new JMenu(); jMenuBar1.add(mnuTools); mnuTools.setText("Tools"); { final JFrame owner = this; JMenuItem scalRecipeMenuItem = new JMenuItem(); mnuTools.add(scalRecipeMenuItem); scalRecipeMenuItem.setText("Scale Recipe..."); scalRecipeMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_R, ActionEvent.CTRL_MASK)); scalRecipeMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { ScaleRecipeDialog scaleRecipe = new ScaleRecipeDialog(owner); scaleRecipe.setModal(true); scaleRecipe.setVisible(true); } }); JMenuItem maltPercentMenuItem = new JMenuItem(); mnuTools.add(maltPercentMenuItem); maltPercentMenuItem.setText("Malt Percent..."); maltPercentMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_M, ActionEvent.CTRL_MASK)); maltPercentMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { MaltPercentDialog maltPercent = new MaltPercentDialog(owner); maltPercent.setModal(true); maltPercent.setVisible(true); } }); } } { jMenu5 = new JMenu(); jMenuBar1.add(jMenu5); jMenu5.setText("Help"); { helpMenuItem = new JMenuItem(); jMenu5.add(helpMenuItem); helpMenuItem.setText("Help"); final JFrame owner = this; helpMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { URL help; try { help = new File(appRoot + "/help/index.html").toURL(); HTMLViewer view = new HTMLViewer(owner, help); view.setModal(true); view.setVisible(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); } { aboutMenuItem = new JMenuItem(); jMenu5.add(aboutMenuItem); aboutMenuItem.setText("About..."); final JFrame owner = this; aboutMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { aboutDlg = new AboutDialog(owner, version); aboutDlg.setVisible(true); } }); } } } } catch (Exception e) { e.printStackTrace(); } }
private void initGUI() { try { // restore the saved size and location: this.setSize(preferences.getIProperty("winWidth"), preferences.getIProperty("winHeight")); this.setLocation(preferences.getIProperty("winX"), preferences.getIProperty("winY")); imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/sb2.gif"); icon = new ImageIcon(imgURL); this.setIconImage(icon.getImage()); this.setTitle("StrangeBrew " + version); this.addWindowListener(new WindowAdapter() { public void windowClosed(WindowEvent evt) { System.exit(1); } }); { pnlMain = new JPanel(); GridBagLayout jPanel2Layout = new GridBagLayout(); jPanel2Layout.columnWeights = new double[]{0.1}; jPanel2Layout.columnWidths = new int[]{7}; jPanel2Layout.rowWeights = new double[]{0.1, 0.1, 0.9, 0.1}; jPanel2Layout.rowHeights = new int[]{7, 7, 7, 7}; pnlMain.setLayout(jPanel2Layout); this.getContentPane().add(pnlMain, BorderLayout.CENTER); { jTabbedPane1 = new JTabbedPane(); pnlMain.add(jTabbedPane1, new GridBagConstraints(0, 1, 1, 1, 0.1, 0.1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); { pnlDetails = new JPanel(); GridBagLayout pnlDetailsLayout = new GridBagLayout(); pnlDetailsLayout.columnWeights = new double[]{0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1}; pnlDetailsLayout.columnWidths = new int[]{7, 7, 7, 7, 7, 7, 7, 7, 7, 7}; pnlDetailsLayout.rowWeights = new double[]{0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1}; pnlDetailsLayout.rowHeights = new int[]{7, 7, 7, 7, 7, 7, 7}; pnlDetails.setLayout(pnlDetailsLayout); jTabbedPane1.addTab("Details", null, pnlDetails, null); pnlDetails.setPreferredSize(new java.awt.Dimension(20, 16)); { lblBrewer = new JLabel(); pnlDetails.add(lblBrewer, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblBrewer.setText("Brewer:"); } { brewerNameText = new JTextField(); pnlDetails.add(brewerNameText, new GridBagConstraints(1, 0, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); brewerNameText.setPreferredSize(new java.awt.Dimension(69, 20)); brewerNameText.setText("Brewer"); } { lblDate = new JLabel(); pnlDetails.add(lblDate, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblDate.setText("Date:"); } { lblStyle = new JLabel(); pnlDetails.add(lblStyle, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblStyle.setText("Style:"); } { lblYeast = new JLabel(); pnlDetails.add(lblYeast, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblYeast.setText("Yeast:"); } { lblPreBoil = new JLabel(); pnlDetails.add(lblPreBoil, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblPreBoil.setText("Pre boil:"); } { lblPostBoil = new JLabel(); pnlDetails.add(lblPostBoil, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblPostBoil.setText("Post boil:"); } { lblEffic = new JLabel(); pnlDetails.add(lblEffic, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblEffic.setText("Effic:"); lblEffic.setPreferredSize(new java.awt.Dimension(31, 14)); } { lblAtten = new JLabel(); pnlDetails.add(lblAtten, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblAtten.setText("Atten:"); lblAtten.setPreferredSize(new java.awt.Dimension(34, 14)); } { lblOG = new JLabel(); pnlDetails.add(lblOG, new GridBagConstraints(5, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblOG.setText("OG:"); } { lblFG = new JLabel(); pnlDetails.add(lblFG, new GridBagConstraints(5, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblFG.setText("FG:"); } { lblIBU = new JLabel(); pnlDetails.add(lblIBU, new GridBagConstraints(7, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblIBU.setText("IBU:"); } { lblAlc = new JLabel(); pnlDetails.add(lblAlc, new GridBagConstraints(7, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblAlc.setText("%Alc:"); } { lblColour = new JLabel(); pnlDetails.add(lblColour, new GridBagConstraints(7, 2, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblColour.setText("Colour:"); } { //txtDate = new JFormattedTextField(); txtDate = new DatePicker(); pnlDetails.add(txtDate, new GridBagConstraints(1, 1, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); // txtDate.setText("Date"); txtDate.setPreferredSize(new java.awt.Dimension(73, 20)); txtDate.setDateStyle(DateFormat.SHORT); } { cmbStyleModel = new ComboModel(); cmbStyle = new JComboBox(); pnlDetails.add(cmbStyle, new GridBagConstraints(1, 2, 5, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cmbStyle.setModel(cmbStyleModel); cmbStyle.setMaximumSize(new java.awt.Dimension(100, 32767)); cmbStyle.setPreferredSize(new java.awt.Dimension(190, 20)); } { txtPreBoil = new JFormattedTextField(); pnlDetails.add(txtPreBoil, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); txtPreBoil.setText("Pre Boil"); txtPreBoil.setPreferredSize(new java.awt.Dimension(37, 20)); } { postBoilText = new JFormattedTextField(); pnlDetails.add(postBoilText, new GridBagConstraints(1, 5, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); postBoilText.setText("Post Boil"); postBoilText.setPreferredSize(new java.awt.Dimension(46, 20)); } { lblComments = new JLabel(); pnlDetails.add(lblComments, new GridBagConstraints(6, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblComments.setText("Comments:"); } { SpinnerNumberModel spnEfficModel = new SpinnerNumberModel(75.0, 0.0, 100.0, 1.0); spnEffic = new JSpinner(); pnlDetails.add(spnEffic, new GridBagConstraints(4, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnEffic.setModel(spnEfficModel); spnEffic.setMaximumSize(new java.awt.Dimension(70, 32767)); spnEffic.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { myRecipe.setEfficiency(Double.parseDouble(spnEffic.getValue() .toString())); displayRecipe(); } }); spnEffic.setEditor(new JSpinner.NumberEditor(spnEffic, "00.#")); spnEffic.getEditor().setPreferredSize(new java.awt.Dimension(28, 16)); spnEffic.setPreferredSize(new java.awt.Dimension(53, 18)); } { SpinnerNumberModel spnAttenModel = new SpinnerNumberModel(75.0, 0.0, 100.0, 1.0); spnAtten = new JSpinner(); pnlDetails.add(spnAtten, new GridBagConstraints(4, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnAtten.setModel(spnAttenModel); spnAtten.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { myRecipe.setAttenuation(Double.parseDouble(spnAtten.getValue() .toString())); displayRecipe(); } }); spnAtten.setEditor(new JSpinner.NumberEditor(spnAtten, "00.#")); spnAtten.setPreferredSize(new java.awt.Dimension(49, 20)); } { SpinnerNumberModel spnOgModel = new SpinnerNumberModel(1.000, 0.900, 2.000, 0.001); spnOG = new JSpinner(); pnlDetails.add(spnOG, new GridBagConstraints(6, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnOG.setModel(spnOgModel); spnOG.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { myRecipe.setEstOg(Double.parseDouble(spnOG.getValue() .toString())); displayRecipe(); } }); spnOG.setEditor(new JSpinner.NumberEditor(spnOG, "0.000")); spnOG.getEditor().setPreferredSize(new java.awt.Dimension(20, 16)); spnOG.setPreferredSize(new java.awt.Dimension(67, 18)); } { SpinnerNumberModel spnFgModel = new SpinnerNumberModel(1.000, 0.900, 2.000, 0.001); spnFG = new JSpinner(); pnlDetails.add(spnFG, new GridBagConstraints(6, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnFG.setModel(spnFgModel); spnFG.setEditor(new JSpinner.NumberEditor(spnFG, "0.000")); spnFG.setPreferredSize(new java.awt.Dimension(69, 20)); spnFG.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { // set the new FG, and update alc: myRecipe.setEstFg(Double.parseDouble(spnFG.getValue() .toString())); displayRecipe(); } }); } { lblIBUvalue = new JLabel(); pnlDetails.add(lblIBUvalue, new GridBagConstraints(8, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblIBUvalue.setText("IBUs"); } { lblColourValue = new JLabel(); pnlDetails.add(lblColourValue, new GridBagConstraints(8, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblColourValue.setText("Colour"); } { lblAlcValue = new JLabel(); pnlDetails.add(lblAlcValue, new GridBagConstraints(8, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblAlcValue.setText("Alc"); } { scpComments = new JScrollPane(); pnlDetails.add(scpComments, new GridBagConstraints(7, 4, 3, 2, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); { txtComments = new JTextArea(); scpComments.setViewportView(txtComments); txtComments.setText("Comments"); txtComments.setWrapStyleWord(true); // txtComments.setPreferredSize(new java.awt.Dimension(117, 42)); txtComments.setLineWrap(true); txtComments.setPreferredSize(new java.awt.Dimension(263, 40)); txtComments.addFocusListener(new FocusAdapter() { public void focusLost(FocusEvent evt) { if (!txtComments.getText().equals(myRecipe.getComments())) { myRecipe.setComments(txtComments.getText()); } } }); } } { cmbYeastModel = new ComboModel(); cmbYeast = new JComboBox(); pnlDetails.add(cmbYeast, new GridBagConstraints(1, 3, 5, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cmbYeast.setModel(cmbYeastModel); cmbYeast.setPreferredSize(new java.awt.Dimension(193, 20)); } { cmbSizeUnitsModel = new ComboModel(); cmbSizeUnits = new JComboBox(); pnlDetails.add(cmbSizeUnits, new GridBagConstraints(2, 4, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cmbSizeUnits.setModel(cmbSizeUnitsModel); } { lblSizeUnits = new JLabel(); pnlDetails.add(lblSizeUnits, new GridBagConstraints(2, 5, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); lblSizeUnits.setText("Size Units"); } { boilTimeLable = new JLabel(); pnlDetails.add(boilTimeLable, new GridBagConstraints(4, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); boilTimeLable.setText("Boil Min:"); } { evapLabel = new JLabel(); pnlDetails.add(evapLabel, new GridBagConstraints(4, 5, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); evapLabel.setText("Evap/hr:"); } { boilMinText = new JTextField(); pnlDetails.add(boilMinText, new GridBagConstraints(5, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); boilMinText.setText("60"); boilMinText.setPreferredSize(new java.awt.Dimension(22, 20)); } { evapText = new JTextField(); pnlDetails.add(evapText, new GridBagConstraints(5, 5, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); evapText.setText("4"); evapText.setPreferredSize(new java.awt.Dimension(23, 20)); } { alcMethodComboModel = new DefaultComboBoxModel(new String[]{"Volume", "Weight"}); alcMethodCombo = new JComboBox(alcMethodComboModel); pnlDetails.add(alcMethodCombo, new GridBagConstraints(9, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); alcMethodCombo.setPreferredSize(new java.awt.Dimension(58, 20)); } { ibuMethodComboModel = new DefaultComboBoxModel(new String[]{"Tinseth", "Garetz", "Rager"}); ibuMethodCombo = new JComboBox(ibuMethodComboModel); pnlDetails.add(ibuMethodCombo, new GridBagConstraints(9, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); ibuMethodCombo.setPreferredSize(new java.awt.Dimension(59, 20)); } { colourMethodComboModel = new DefaultComboBoxModel(new String[]{"SRM", "EBC"}); colourMethodCombo = new JComboBox(colourMethodComboModel); pnlDetails.add(colourMethodCombo, new GridBagConstraints(9, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); colourMethodCombo.setPreferredSize(new java.awt.Dimension(44, 20)); } ComboBoxModel evapMethodComboModel = new DefaultComboBoxModel(new String[] { "Constant", "Percent" }); { jPanel1 = new JPanel(); pnlMain.add(jPanel1, new GridBagConstraints( 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); FlowLayout jPanel1Layout = new FlowLayout(); jPanel1Layout.setAlignment(FlowLayout.LEFT); jPanel1.setLayout(jPanel1Layout); jToolBar1 = new JToolBar(); getContentPane().add(jToolBar1, BorderLayout.NORTH); jToolBar1.setFloatable(false); jToolBar1.setRollover(true); jButton1 = new JButton(); jToolBar1.add(jButton1); jButton1.setMnemonic(java.awt.event.KeyEvent.VK_S); jButton1.setIcon(new ImageIcon(getClass().getClassLoader().getResource( "ca/strangebrew/icons/save.gif"))); jButton1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { System.out.println("jButton1.actionPerformed, event=" + evt); //TODO add your code for jButton1.actionPerformed } }); jButton2 = new JButton(); jToolBar1.add(jButton2); jButton2.setIcon(new ImageIcon(getClass().getClassLoader().getResource( "ca/strangebrew/icons/find.gif"))); jButton2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { System.out.println("jButton2.actionPerformed, event=" + evt); //TODO add your code for jButton2.actionPerformed } }); { lblName = new JLabel(); jPanel1.add(lblName); lblName.setText("Name:"); } { txtName = new JTextField(); jPanel1.add(txtName); txtName.setText("Name"); txtName.setPreferredSize(new java.awt.Dimension(297, 20)); } } evapMethodCombo = new JComboBox(); pnlDetails.add(evapMethodCombo, new GridBagConstraints(6, 5, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); evapMethodCombo.setModel(evapMethodComboModel); evapMethodCombo.setPreferredSize(new java.awt.Dimension(64, 20)); colourPanel = new JPanel(); pnlDetails.add(colourPanel, new GridBagConstraints(9, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); colourPanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); } { SBNotifier sbn = new SBNotifier(); stylePanel = new StylePanel(sbn); jTabbedPane1.addTab("Style", null, stylePanel, null); miscPanel = new MiscPanel(myRecipe); jTabbedPane1.addTab("Misc", null, miscPanel, null); notesPanel = new NotesPanel(); jTabbedPane1.addTab("Notes", null, notesPanel, null); dilutionPanel = new DilutionPanel(); jTabbedPane1.addTab("Dilution", null, dilutionPanel, null); mashPanel = new MashPanel(myRecipe); jTabbedPane1.addTab("Mash", null, mashPanel, null); waterPanel = new WaterPanel(); jTabbedPane1.addTab("Water", null, waterPanel, null); costPanel = new CostPanel(); jTabbedPane1.addTab("Cost", null, costPanel, null); // SBNotifier sbn = new SBNotifier(); settingsPanel = new SettingsPanel(sbn); jTabbedPane1.addTab("Settings", null, settingsPanel, null); } } { pnlTables = new JPanel(); BoxLayout pnlMaltsLayout = new BoxLayout(pnlTables, javax.swing.BoxLayout.Y_AXIS); pnlMain.add(pnlTables, new GridBagConstraints(0, 2, 1, 1, 0.5, 0.5, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); pnlTables.setLayout(pnlMaltsLayout); { pnlMalt = new JPanel(); pnlTables.add(pnlMalt); BorderLayout pnlMaltLayout1 = new BorderLayout(); pnlMalt.setBorder(BorderFactory.createTitledBorder(new LineBorder( new java.awt.Color(0, 0, 0), 1, false), "Fermentables", TitledBorder.LEADING, TitledBorder.TOP, new java.awt.Font("Dialog", 1, 12), new java.awt.Color(51, 51, 51))); pnlMalt.setLayout(pnlMaltLayout1); { jScrollPane1 = new JScrollPane(); pnlMalt.add(jScrollPane1, BorderLayout.CENTER); { maltTableModel = new MaltTableModel(this); maltTable = new JTable() { public String getToolTipText(MouseEvent e) { java.awt.Point p = e.getPoint(); int rowIndex = rowAtPoint(p); return SBStringUtils.multiLineToolTip(40, maltTableModel .getDescriptionAt(rowIndex)); } }; jScrollPane1.setViewportView(maltTable); maltTable.setModel(maltTableModel); // maltTable.setAutoCreateColumnsFromModel(false); maltTable.getTableHeader().setReorderingAllowed(false); TableColumn maltColumn = maltTable.getColumnModel().getColumn(0); // set up malt list combo maltComboBox = new JComboBox(); cmbMaltModel = new ComboModel(); maltComboBox.setModel(cmbMaltModel); maltColumn.setCellEditor(new DefaultCellEditor(maltComboBox)); // set up malt amount editor amountEditor = new SBCellEditor(new JTextField()); maltColumn = maltTable.getColumnModel().getColumn(1); maltColumn.setCellEditor(amountEditor); // set up malt units combo maltUnitsComboBox = new JComboBox(); cmbMaltUnitsModel = new ComboModel(); maltUnitsComboBox.setModel(cmbMaltUnitsModel); maltColumn = maltTable.getColumnModel().getColumn(2); maltColumn.setCellEditor(new DefaultCellEditor(maltUnitsComboBox)); } } { tblMaltTotalsModel = new DefaultTableModel(new String[][]{{""}}, new String[]{"S", "M", "Malt", "Amount", "Units", "Points", "Lov", "Cost/U", "%"}); tblMaltTotals = new JTable(); pnlMalt.add(tblMaltTotals, BorderLayout.SOUTH); tblMaltTotals.setModel(tblMaltTotalsModel); tblMaltTotals.getTableHeader().setEnabled(false); tblMaltTotals.setAutoCreateColumnsFromModel(false); // set up the units combobox maltTotalUnitsComboBox = new JComboBox(); maltTotalUnitsComboModel = new ComboModel(); maltTotalUnitsComboModel.setList(new Quantity().getListofUnits("weight")); maltTotalUnitsComboBox.setModel(maltTotalUnitsComboModel); TableColumn t = tblMaltTotals.getColumnModel().getColumn(2); t.setCellEditor(new DefaultCellEditor(maltTotalUnitsComboBox)); maltTotalUnitsComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { String u = (String) maltTotalUnitsComboModel.getSelectedItem(); if (myRecipe != null) { myRecipe.setMaltUnits(u); displayRecipe(); } } }); } } { pnlMaltButtons = new JPanel(); pnlTables.add(pnlMaltButtons); FlowLayout pnlMaltButtonsLayout = new FlowLayout(); pnlMaltButtonsLayout.setAlignment(FlowLayout.LEFT); pnlMaltButtonsLayout.setVgap(0); pnlMaltButtons.setLayout(pnlMaltButtonsLayout); pnlMaltButtons.setPreferredSize(new java.awt.Dimension(592, 27)); { tlbMalt = new JToolBar(); pnlMaltButtons.add(tlbMalt); tlbMalt.setPreferredSize(new java.awt.Dimension(386, 20)); tlbMalt.setFloatable(false); { btnAddMalt = new JButton(); tlbMalt.add(btnAddMalt); btnAddMalt.setText("+"); btnAddMalt.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { Fermentable f = new Fermentable(myRecipe.getMaltUnits()); myRecipe.addMalt(f); maltTable.updateUI(); displayRecipe(); } } }); } { btnDelMalt = new JButton(); tlbMalt.add(btnDelMalt); btnDelMalt.setText("-"); btnDelMalt.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { int i = maltTable.getSelectedRow(); myRecipe.delMalt(i); maltTable.updateUI(); displayRecipe(); } } }); } } } { pnlHops = new JPanel(); BorderLayout pnlHopsLayout = new BorderLayout(); pnlHops.setBorder(BorderFactory.createTitledBorder(new LineBorder( new java.awt.Color(0, 0, 0), 1, false), "Hops", TitledBorder.LEADING, TitledBorder.TOP, new java.awt.Font("Dialog", 1, 12), new java.awt.Color(51, 51, 51))); pnlHops.setLayout(pnlHopsLayout); pnlTables.add(pnlHops); { tblHopsTotalsModel = new DefaultTableModel(new String[][]{{""}}, new String[]{"1", "2", "3", "4", "5", "6", "7", "8", "9"}); tblHopsTotals = new JTable(); pnlHops.add(tblHopsTotals, BorderLayout.SOUTH); tblHopsTotals.setModel(tblHopsTotalsModel); tblHopsTotals.setAutoCreateColumnsFromModel(false); // set up the units combobox hopsTotalUnitsComboBox = new JComboBox(); hopsTotalUnitsComboModel = new ComboModel(); hopsTotalUnitsComboModel.setList(new Quantity().getListofUnits("weight")); hopsTotalUnitsComboBox.setModel(hopsTotalUnitsComboModel); TableColumn t = tblHopsTotals.getColumnModel().getColumn(4); t.setCellEditor(new DefaultCellEditor(hopsTotalUnitsComboBox)); hopsTotalUnitsComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { String u = (String) hopsTotalUnitsComboModel.getSelectedItem(); if (myRecipe != null) { myRecipe.setHopsUnits(u); displayRecipe(); } } }); } { jScrollPane2 = new JScrollPane(); pnlHops.add(jScrollPane2, BorderLayout.CENTER); { hopsTableModel = new HopsTableModel(this); hopsTable = new JTable() { public String getToolTipText(MouseEvent e) { java.awt.Point p = e.getPoint(); int rowIndex = rowAtPoint(p); return SBStringUtils.multiLineToolTip(40, hopsTableModel .getDescriptionAt(rowIndex)); } }; jScrollPane2.setViewportView(hopsTable); hopsTable.setModel(hopsTableModel); hopsTable.getTableHeader().setReorderingAllowed(false); TableColumn hopColumn = hopsTable.getColumnModel().getColumn(0); hopComboBox = new JComboBox(); cmbHopsModel = new ComboModel(); hopComboBox.setModel(cmbHopsModel); hopColumn.setCellEditor(new DefaultCellEditor(hopComboBox)); // set up hop units combo hopsUnitsComboBox = new JComboBox(); cmbHopsUnitsModel = new ComboModel(); hopsUnitsComboBox.setModel(cmbHopsUnitsModel); hopColumn = hopsTable.getColumnModel().getColumn(4); hopColumn.setCellEditor(new DefaultCellEditor(hopsUnitsComboBox)); // set up hop type combo String[] forms = {"Leaf", "Pellet", "Plug"}; JComboBox hopsFormComboBox = new JComboBox(forms); hopColumn = hopsTable.getColumnModel().getColumn(1); hopColumn.setCellEditor(new DefaultCellEditor(hopsFormComboBox)); // set up hop add combo String[] add = {"Boil", "FWH", "Dry", "Mash"}; JComboBox hopsAddComboBox = new JComboBox(add); hopColumn = hopsTable.getColumnModel().getColumn(5); hopColumn.setCellEditor(new DefaultCellEditor(hopsAddComboBox)); } } } { pnlHopsButtons = new JPanel(); FlowLayout pnlHopsButtonsLayout = new FlowLayout(); pnlHopsButtonsLayout.setAlignment(FlowLayout.LEFT); pnlHopsButtonsLayout.setVgap(0); pnlHopsButtons.setLayout(pnlHopsButtonsLayout); pnlTables.add(pnlHopsButtons); pnlHopsButtons.setPreferredSize(new java.awt.Dimension(512, 16)); { tlbHops = new JToolBar(); pnlHopsButtons.add(tlbHops); tlbHops.setPreferredSize(new java.awt.Dimension(413, 19)); tlbHops.setFloatable(false); { btnAddHop = new JButton(); tlbHops.add(btnAddHop); btnAddHop.setText("+"); btnAddHop.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { Hop h = new Hop(myRecipe.getHopUnits()); myRecipe.addHop(h); hopsTable.updateUI(); displayRecipe(); } } }); } { btnDelHop = new JButton(); tlbHops.add(btnDelHop); btnDelHop.setText("-"); btnDelHop.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { int i = hopsTable.getSelectedRow(); myRecipe.delHop(i); hopsTable.updateUI(); displayRecipe(); } } }); } } } } { statusPanel = new JPanel(); FlowLayout statusPanelLayout = new FlowLayout(); statusPanelLayout.setAlignment(FlowLayout.LEFT); statusPanelLayout.setHgap(2); statusPanelLayout.setVgap(2); statusPanel.setLayout(statusPanelLayout); pnlMain.add(statusPanel, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); { fileNamePanel = new JPanel(); statusPanel.add(fileNamePanel); fileNamePanel.setBorder(BorderFactory .createBevelBorder(BevelBorder.LOWERED)); { fileNameLabel = new JLabel(); fileNamePanel.add(fileNameLabel); fileNameLabel.setText("File Name"); fileNameLabel.setFont(new java.awt.Font("Dialog", 1, 10)); } } { ibuMethodPanel = new JPanel(); statusPanel.add(ibuMethodPanel); ibuMethodPanel.setBorder(BorderFactory .createBevelBorder(BevelBorder.LOWERED)); { ibuMethodLabel = new JLabel(); ibuMethodPanel.add(ibuMethodLabel); ibuMethodLabel.setText("IBU Method:"); ibuMethodLabel.setFont(new java.awt.Font("Dialog", 1, 10)); } } { alcMethodPanel = new JPanel(); statusPanel.add(alcMethodPanel); alcMethodPanel.setBorder(BorderFactory .createBevelBorder(BevelBorder.LOWERED)); { alcMethodLabel = new JLabel(); alcMethodPanel.add(alcMethodLabel); alcMethodLabel.setText("Alc Method:"); alcMethodLabel.setFont(new java.awt.Font("Dialog", 1, 10)); } } } } { jMenuBar1 = new JMenuBar(); setJMenuBar(jMenuBar1); { fileMenu = new JMenu(); jMenuBar1.add(fileMenu); fileMenu.setText("File"); { newFileMenuItem = new JMenuItem(); fileMenu.add(newFileMenuItem); newFileMenuItem.setText("New"); newFileMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // This is just a test right now to see that // stuff is changed. myRecipe = new Recipe(); myRecipe.setVersion(version); currentFile = null; attachRecipeData(); displayRecipe(); } }); } { openFileMenuItem = new JMenuItem(); fileMenu.add(openFileMenuItem); openFileMenuItem.setText("Open"); openFileMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_O, ActionEvent.CTRL_MASK)); openFileMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Show open dialog; this method does // not return until the dialog is closed String[] ext = {"xml", "qbrew", "rec"}; String desc = "StrangBrew and importable formats"; sbFileFilter openFileFilter = new sbFileFilter(ext, desc); // fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); fileChooser.setFileFilter(openFileFilter); int returnVal = fileChooser.showOpenDialog(jMenuBar1); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); Debug.print("Opening: " + file.getName() + ".\n"); OpenImport oi = new OpenImport(); myRecipe = oi.openFile(file); if (oi.getFileType().equals("")){ JOptionPane.showMessageDialog( null, "The file you've tried to open isn't a recognized format. \n" + "You can open: \n" + "StrangeBrew 1.x and Java files (.xml)\n" + "QBrew files (.qbrew)\n" + "BeerXML files (.xml)\n" + "Promash files (.rec)", "Unrecognized Format!", JOptionPane.INFORMATION_MESSAGE); } if (oi.getFileType().equals("beerxml")){ JOptionPane.showMessageDialog( null, "The file you've opened is in BeerXML format. It may contain \n" + "several recipes. Only the first recipe is opened. Use the Find \n" + "dialog to open other recipes in a BeerXML file.", "BeerXML!", JOptionPane.INFORMATION_MESSAGE); } myRecipe.setVersion(version); myRecipe.calcMaltTotals(); myRecipe.calcHopsTotals(); myRecipe.mash.calcMashSchedule(); checkIngredientsInDB(); attachRecipeData(); currentFile = file; displayRecipe(); } else { Debug.print("Open command cancelled by user.\n"); } } }); } { imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/find.gif"); icon = new ImageIcon(imgURL); findFileMenuItem = new JMenuItem("Find", icon); findFileMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_F, ActionEvent.CTRL_MASK)); fileMenu.add(findFileMenuItem); final JFrame owner = this; findFileMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // open the find dialog FindDialog fd = new FindDialog(owner); fd.setVisible(true); } }); } { imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/save.gif"); icon = new ImageIcon(imgURL); saveMenuItem = new JMenuItem("Save", icon); fileMenu.add(saveMenuItem); saveMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_S, ActionEvent.CTRL_MASK)); saveMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { int choice = 1; if (currentFile != null) { File file = currentFile; //This is where a real application would save the file. try { FileWriter out = new FileWriter(file); out.write(myRecipe.toXML()); out.close(); Debug.print("Saved: " + file.getAbsoluteFile()); currentFile = file; } catch (Exception e) { showError(e); } } // prompt to save if not already saved else { choice = JOptionPane.showConfirmDialog(null, "File not saved. Do you wish to save it?", "File note saved", JOptionPane.YES_NO_OPTION); } if (choice == 0) { // same as save as: saveAs(); } } }); } { imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/saveas.gif"); icon = new ImageIcon(imgURL); saveAsMenuItem = new JMenuItem("Save As ...", icon); fileMenu.add(saveAsMenuItem); saveAsMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // This is just a test right now to see that // stuff is changed. Debug.print(myRecipe.toXML()); saveAs(); } }); } { exportMenu = new JMenu(); fileMenu.add(exportMenu); exportMenu.setText("Export"); { exportHTMLmenu = new JMenuItem(); exportMenu.add(exportHTMLmenu); exportHTMLmenu.setText("HTML"); exportHTMLmenu.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Show save dialog; this method does // not return until the dialog is closed String[] ext = {"html", "htm"}; sbFileFilter saveFileFilter = new sbFileFilter(ext, "HTML"); fileChooser.setFileFilter(saveFileFilter); fileChooser.setSelectedFile(new File(myRecipe.getName() + ".html")); int returnVal = fileChooser.showSaveDialog(jMenuBar1); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); //This is where a real application would save the file. try { saveAsHTML(file, "ca/strangebrew/data/recipeToHtml.xslt"); } catch (Exception e) { showError(e); } } else { Debug.print("Save command cancelled by user.\n"); } } }); exportTextMenuItem = new JMenuItem(); exportMenu.add(exportTextMenuItem); exportTextMenuItem.setText("Text"); exportTextMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Show save dialog; this method does // not return until the dialog is closed String[] ext = {"txt"}; sbFileFilter saveFileFilter = new sbFileFilter(ext, "Text"); fileChooser.setFileFilter(saveFileFilter); fileChooser.setSelectedFile(new File(myRecipe.getName() + ".txt")); int returnVal = fileChooser.showSaveDialog(jMenuBar1); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); //This is where a real application would save the file. try { FileWriter out = new FileWriter(file); out.write(myRecipe.toText()); out.close(); } catch (Exception e) { showError(e); } } else { Debug.print("Export text command cancelled by user.\n"); } } }); } } { JMenuItem clipboardMenuItem = new JMenuItem("Copy to Clipboard"); fileMenu.add(clipboardMenuItem); clipboardMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Copy current recipe to clipboard Clipboard clipboard = getToolkit ().getSystemClipboard (); StringSelection s = new StringSelection(myRecipe.toText()); clipboard.setContents(s, s); } }); JMenuItem printMenuItem = new JMenuItem("Print..."); fileMenu.add(printMenuItem); final JFrame owner = this; printMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Copy current recipe to clipboard// save file as xml, then transform it to html File tmp = new File("tmp.html"); try { saveAsHTML(tmp, "ca/strangebrew/data/recipeToSimpleHtml.xslt"); HTMLViewer view = new HTMLViewer(owner, tmp.toURL()); view.setModal(true); view.setVisible(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } tmp.delete(); } }); } { jSeparator2 = new JSeparator(); fileMenu.add(jSeparator2); } { exitMenuItem = new JMenuItem(); fileMenu.add(exitMenuItem); exitMenuItem.setText("Exit"); exitMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_Q, ActionEvent.CTRL_MASK)); final JFrame owner = this; exitMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // exit program processWindowEvent(new WindowEvent(owner,WindowEvent.WINDOW_CLOSING)); System.exit(0); } }); } } { jMenu4 = new JMenu(); jMenuBar1.add(jMenu4); jMenu4.setText("Edit"); { final JFrame owner = this; editPrefsMenuItem = new JMenuItem(); jMenu4.add(editPrefsMenuItem); editPrefsMenuItem.setText("Preferences..."); editPrefsMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { PreferencesDialog d = new PreferencesDialog(owner, preferences); d.setVisible(true); } }); } { jSeparator1 = new JSeparator(); jMenu4.add(jSeparator1); } { deleteMenuItem = new JMenuItem(); jMenu4.add(deleteMenuItem); deleteMenuItem.setText("Delete"); deleteMenuItem.setEnabled(false); } } { mnuTools = new JMenu(); jMenuBar1.add(mnuTools); mnuTools.setText("Tools"); { final JFrame owner = this; JMenuItem scalRecipeMenuItem = new JMenuItem(); mnuTools.add(scalRecipeMenuItem); scalRecipeMenuItem.setText("Scale Recipe..."); scalRecipeMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_R, ActionEvent.CTRL_MASK)); scalRecipeMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { ScaleRecipeDialog scaleRecipe = new ScaleRecipeDialog(owner); scaleRecipe.setModal(true); scaleRecipe.setVisible(true); } }); JMenuItem maltPercentMenuItem = new JMenuItem(); mnuTools.add(maltPercentMenuItem); maltPercentMenuItem.setText("Malt Percent..."); maltPercentMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_M, ActionEvent.CTRL_MASK)); maltPercentMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { MaltPercentDialog maltPercent = new MaltPercentDialog(owner); maltPercent.setModal(true); maltPercent.setVisible(true); } }); } } { jMenu5 = new JMenu(); jMenuBar1.add(jMenu5); jMenu5.setText("Help"); { helpMenuItem = new JMenuItem(); jMenu5.add(helpMenuItem); helpMenuItem.setText("Help"); final JFrame owner = this; helpMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { URL help; try { help = new File(appRoot + "/help/index.html").toURL(); HTMLViewer view = new HTMLViewer(owner, help); view.setModal(true); view.setVisible(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); } { aboutMenuItem = new JMenuItem(); jMenu5.add(aboutMenuItem); aboutMenuItem.setText("About..."); final JFrame owner = this; aboutMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { aboutDlg = new AboutDialog(owner, version); aboutDlg.setVisible(true); } }); } } } } catch (Exception e) { e.printStackTrace(); } }
1,115,278
public void addOrInsert(Object o) { int i = 0; boolean found = false; while (i < list.size() && !found) { if (DEBUG) System.out.println(o.getClass().getName().toString()); if (o.getClass().getName().toString().equals( "strangebrew.Yeast")) { Yeast y = (Yeast) list.get(i); Yeast y2 = (Yeast) o; found = y.getName().equalsIgnoreCase(y2.getName()); } else if (o.getClass().getName().toString().equals("strangebrew.Fermentable")) { Fermentable f = (Fermentable) list.get(i); Fermentable f2 = (Fermentable) o; found = f.getName().equalsIgnoreCase(f2.getName()); } else if (o.getClass().getName().toString().equals("strangebrew.Hop")) { Hop h = (Hop) list.get(i); Hop h2 = (Hop) o; found = h.getName().equalsIgnoreCase(h2.getName()); } else if (o.getClass().getName().toString().equals("strangebrew.Style")) { Style s = (Style) list.get(i); Style s2 = (Style) o; found = s.getName().equalsIgnoreCase(s2.getName()); } else if (o.getClass().getName().toString().equals("java.lang.String")) { String q = (String) list.get(i); String q2 = (String) o; found = q.equalsIgnoreCase(q2); } i++; } // if it's not found, add it to the list & select it, // otherwise, set the found index to the selected index if (!found) { list.add(o); selected = o; } else selected = list.get(i-1); }
public void addOrInsert(Object o) { int i = 0; boolean found = false; while (i < list.size() && !found) { if (DEBUG) System.out.println(o.getClass().getName().toString()); if (o.getClass().getName().toString().equals( "strangebrew.Yeast")) { Yeast y = (Yeast) list.get(i); Yeast y2 = (Yeast) o; found = y.getName().equalsIgnoreCase(y2.getName()); } else if (o.getClass().getName().toString().equals("strangebrew.Fermentable")) { Fermentable f = (Fermentable) list.get(i); Fermentable f2 = (Fermentable) o; found = f.getName().equalsIgnoreCase(f2.getName()); } else if (o.getClass().getName().toString().equals("strangebrew.Hop")) { Hop h = (Hop) list.get(i); Hop h2 = (Hop) o; found = h.getName().equalsIgnoreCase(h2.getName()); } else if (o.getClass().getName().toString().equals("strangebrew.Style")) { Style s = (Style) list.get(i); Style s2 = (Style) o; found = s.getName().equalsIgnoreCase(s2.getName()); } else if (o.getClass().getName().toString().equals("java.lang.String")) { String q = (String) list.get(i); String q2 = (String) o; found = q.equalsIgnoreCase(q2); } i++; } // if it's not found, add it to the list & select it, // otherwise, set the found index to the selected index if (!found) { list.add(o); selected = o; } else selected = list.get(i-1); }
1,115,279
public void addOrInsert(Object o) { int i = 0; boolean found = false; while (i < list.size() && !found) { if (DEBUG) System.out.println(o.getClass().getName().toString()); if (o.getClass().getName().toString().equals( "strangebrew.Yeast")) { Yeast y = (Yeast) list.get(i); Yeast y2 = (Yeast) o; found = y.getName().equalsIgnoreCase(y2.getName()); } else if (o.getClass().getName().toString().equals("strangebrew.Fermentable")) { Fermentable f = (Fermentable) list.get(i); Fermentable f2 = (Fermentable) o; found = f.getName().equalsIgnoreCase(f2.getName()); } else if (o.getClass().getName().toString().equals("strangebrew.Hop")) { Hop h = (Hop) list.get(i); Hop h2 = (Hop) o; found = h.getName().equalsIgnoreCase(h2.getName()); } else if (o.getClass().getName().toString().equals("strangebrew.Style")) { Style s = (Style) list.get(i); Style s2 = (Style) o; found = s.getName().equalsIgnoreCase(s2.getName()); } else if (o.getClass().getName().toString().equals("java.lang.String")) { String q = (String) list.get(i); String q2 = (String) o; found = q.equalsIgnoreCase(q2); } i++; } // if it's not found, add it to the list & select it, // otherwise, set the found index to the selected index if (!found) { list.add(o); selected = o; } else selected = list.get(i-1); }
public void addOrInsert(Object o) { int i = 0; boolean found = false; while (i < list.size() && !found) { if (DEBUG) System.out.println(o.getClass().getName().toString()); if (o.getClass().getName().toString().equals( "strangebrew.Yeast")) { Yeast y = (Yeast) list.get(i); Yeast y2 = (Yeast) o; found = y.getName().equalsIgnoreCase(y2.getName()); } else if (o.getClass().getName().toString().equals("ca.strangebrew.Fermentable")) { Fermentable f = (Fermentable) list.get(i); Fermentable f2 = (Fermentable) o; found = f.getName().equalsIgnoreCase(f2.getName()); } else if (o.getClass().getName().toString().equals("strangebrew.Hop")) { Hop h = (Hop) list.get(i); Hop h2 = (Hop) o; found = h.getName().equalsIgnoreCase(h2.getName()); } else if (o.getClass().getName().toString().equals("strangebrew.Style")) { Style s = (Style) list.get(i); Style s2 = (Style) o; found = s.getName().equalsIgnoreCase(s2.getName()); } else if (o.getClass().getName().toString().equals("java.lang.String")) { String q = (String) list.get(i); String q2 = (String) o; found = q.equalsIgnoreCase(q2); } i++; } // if it's not found, add it to the list & select it, // otherwise, set the found index to the selected index if (!found) { list.add(o); selected = o; } else selected = list.get(i-1); }
1,115,280
public void addOrInsert(Object o) { int i = 0; boolean found = false; while (i < list.size() && !found) { if (DEBUG) System.out.println(o.getClass().getName().toString()); if (o.getClass().getName().toString().equals( "strangebrew.Yeast")) { Yeast y = (Yeast) list.get(i); Yeast y2 = (Yeast) o; found = y.getName().equalsIgnoreCase(y2.getName()); } else if (o.getClass().getName().toString().equals("strangebrew.Fermentable")) { Fermentable f = (Fermentable) list.get(i); Fermentable f2 = (Fermentable) o; found = f.getName().equalsIgnoreCase(f2.getName()); } else if (o.getClass().getName().toString().equals("strangebrew.Hop")) { Hop h = (Hop) list.get(i); Hop h2 = (Hop) o; found = h.getName().equalsIgnoreCase(h2.getName()); } else if (o.getClass().getName().toString().equals("strangebrew.Style")) { Style s = (Style) list.get(i); Style s2 = (Style) o; found = s.getName().equalsIgnoreCase(s2.getName()); } else if (o.getClass().getName().toString().equals("java.lang.String")) { String q = (String) list.get(i); String q2 = (String) o; found = q.equalsIgnoreCase(q2); } i++; } // if it's not found, add it to the list & select it, // otherwise, set the found index to the selected index if (!found) { list.add(o); selected = o; } else selected = list.get(i-1); }
public void addOrInsert(Object o) { int i = 0; boolean found = false; while (i < list.size() && !found) { if (DEBUG) System.out.println(o.getClass().getName().toString()); if (o.getClass().getName().toString().equals( "strangebrew.Yeast")) { Yeast y = (Yeast) list.get(i); Yeast y2 = (Yeast) o; found = y.getName().equalsIgnoreCase(y2.getName()); } else if (o.getClass().getName().toString().equals("strangebrew.Fermentable")) { Fermentable f = (Fermentable) list.get(i); Fermentable f2 = (Fermentable) o; found = f.getName().equalsIgnoreCase(f2.getName()); } else if (o.getClass().getName().toString().equals("ca.strangebrew.Hop")) { Hop h = (Hop) list.get(i); Hop h2 = (Hop) o; found = h.getName().equalsIgnoreCase(h2.getName()); } else if (o.getClass().getName().toString().equals("strangebrew.Style")) { Style s = (Style) list.get(i); Style s2 = (Style) o; found = s.getName().equalsIgnoreCase(s2.getName()); } else if (o.getClass().getName().toString().equals("java.lang.String")) { String q = (String) list.get(i); String q2 = (String) o; found = q.equalsIgnoreCase(q2); } i++; } // if it's not found, add it to the list & select it, // otherwise, set the found index to the selected index if (!found) { list.add(o); selected = o; } else selected = list.get(i-1); }
1,115,281
public void addOrInsert(Object o) { int i = 0; boolean found = false; while (i < list.size() && !found) { if (DEBUG) System.out.println(o.getClass().getName().toString()); if (o.getClass().getName().toString().equals( "strangebrew.Yeast")) { Yeast y = (Yeast) list.get(i); Yeast y2 = (Yeast) o; found = y.getName().equalsIgnoreCase(y2.getName()); } else if (o.getClass().getName().toString().equals("strangebrew.Fermentable")) { Fermentable f = (Fermentable) list.get(i); Fermentable f2 = (Fermentable) o; found = f.getName().equalsIgnoreCase(f2.getName()); } else if (o.getClass().getName().toString().equals("strangebrew.Hop")) { Hop h = (Hop) list.get(i); Hop h2 = (Hop) o; found = h.getName().equalsIgnoreCase(h2.getName()); } else if (o.getClass().getName().toString().equals("strangebrew.Style")) { Style s = (Style) list.get(i); Style s2 = (Style) o; found = s.getName().equalsIgnoreCase(s2.getName()); } else if (o.getClass().getName().toString().equals("java.lang.String")) { String q = (String) list.get(i); String q2 = (String) o; found = q.equalsIgnoreCase(q2); } i++; } // if it's not found, add it to the list & select it, // otherwise, set the found index to the selected index if (!found) { list.add(o); selected = o; } else selected = list.get(i-1); }
public void addOrInsert(Object o) { int i = 0; boolean found = false; while (i < list.size() && !found) { if (DEBUG) System.out.println(o.getClass().getName().toString()); if (o.getClass().getName().toString().equals( "strangebrew.Yeast")) { Yeast y = (Yeast) list.get(i); Yeast y2 = (Yeast) o; found = y.getName().equalsIgnoreCase(y2.getName()); } else if (o.getClass().getName().toString().equals("strangebrew.Fermentable")) { Fermentable f = (Fermentable) list.get(i); Fermentable f2 = (Fermentable) o; found = f.getName().equalsIgnoreCase(f2.getName()); } else if (o.getClass().getName().toString().equals("strangebrew.Hop")) { Hop h = (Hop) list.get(i); Hop h2 = (Hop) o; found = h.getName().equalsIgnoreCase(h2.getName()); } else if (o.getClass().getName().toString().equals("ca.strangebrew.Style")) { Style s = (Style) list.get(i); Style s2 = (Style) o; found = s.getName().equalsIgnoreCase(s2.getName()); } else if (o.getClass().getName().toString().equals("java.lang.String")) { String q = (String) list.get(i); String q2 = (String) o; found = q.equalsIgnoreCase(q2); } i++; } // if it's not found, add it to the list & select it, // otherwise, set the found index to the selected index if (!found) { list.add(o); selected = o; } else selected = list.get(i-1); }
1,115,282
public void addOrInsert(Object o) { int i = 0; boolean found = false; while (i < list.size() && !found) { if (DEBUG) System.out.println(o.getClass().getName().toString()); if (o.getClass().getName().toString().equals( "strangebrew.Yeast")) { Yeast y = (Yeast) list.get(i); Yeast y2 = (Yeast) o; found = y.getName().equalsIgnoreCase(y2.getName()); } else if (o.getClass().getName().toString().equals("strangebrew.Fermentable")) { Fermentable f = (Fermentable) list.get(i); Fermentable f2 = (Fermentable) o; found = f.getName().equalsIgnoreCase(f2.getName()); } else if (o.getClass().getName().toString().equals("strangebrew.Hop")) { Hop h = (Hop) list.get(i); Hop h2 = (Hop) o; found = h.getName().equalsIgnoreCase(h2.getName()); } else if (o.getClass().getName().toString().equals("strangebrew.Style")) { Style s = (Style) list.get(i); Style s2 = (Style) o; found = s.getName().equalsIgnoreCase(s2.getName()); } else if (o.getClass().getName().toString().equals("java.lang.String")) { String q = (String) list.get(i); String q2 = (String) o; found = q.equalsIgnoreCase(q2); } i++; } // if it's not found, add it to the list & select it, // otherwise, set the found index to the selected index if (!found) { list.add(o); selected = o; } else selected = list.get(i-1); }
public void addOrInsert(Object o) { int i = 0; boolean found = false; while (i < list.size() && !found) { if (DEBUG) System.out.println(o.getClass().getName().toString()); if (o.getClass().getName().toString().equals( "strangebrew.Yeast")) { Yeast y = (Yeast) list.get(i); Yeast y2 = (Yeast) o; found = y.getName().equalsIgnoreCase(y2.getName()); } else if (o.getClass().getName().toString().equals("strangebrew.Fermentable")) { Fermentable f = (Fermentable) list.get(i); Fermentable f2 = (Fermentable) o; found = f.getName().equalsIgnoreCase(f2.getName()); } else if (o.getClass().getName().toString().equals("strangebrew.Hop")) { Hop h = (Hop) list.get(i); Hop h2 = (Hop) o; found = h.getName().equalsIgnoreCase(h2.getName()); } else if (o.getClass().getName().toString().equals("strangebrew.Style")) { Style s = (Style) list.get(i); Style s2 = (Style) o; found = s.getName().equalsIgnoreCase(s2.getName()); } else if (o.getClass().getName().toString().equals("java.lang.String")) { String q = (String) list.get(i); String q2 = (String) o; found = q.equalsIgnoreCase(q2); } i++; } // if it's not found, add it to the list & select it, // otherwise, set the found index to the selected index if (!found) { list.add(o); selected = o; } else { selected = list.get(i-1); } }
1,115,283
public void calcMaltTotals() { double maltPoints = 0; double mcu = 0; totalMaltLbs = 0; totalMaltCost = 0; totalMashLbs = 0; // first figure out the total we're dealing with for (int i = 0; i < fermentables.size(); i++) { Fermentable m = ((Fermentable) fermentables.get(i)); totalMaltLbs += (m.getAmountAs("lb")); if (m.getMashed()) { // apply efficiency and add to mash weight maltPoints += (m.getPppg() - 1) * m.getAmountAs("lb") * efficiency / postBoilVol.getValueAs("gal"); totalMashLbs += (m.getAmountAs("lb")); } else maltPoints += (m.getPppg() - 1) * m.getAmountAs("lb") * 100 / postBoilVol.getValueAs("gal"); mcu += m.getLov() * m.getAmountAs("lb") / postBoilVol.getValueAs("gal"); totalMaltCost += m.getCostPerU() * m.getAmountAs("lb"); } // now set the malt % by weight: for (int i = 0; i < fermentables.size(); i++) { Fermentable m = ((Fermentable) fermentables.get(i)); m.setPercent((m.getAmountAs("lb") / totalMaltLbs * 100)); } // set the fields in the object estOg = (maltPoints / 100) + 1; estFg = 1 + ((estOg - 1) * ((100 - attenuation) / 100)); srm = calcColour(mcu); mash.setMaltWeight(totalMashLbs); calcAlcohol(getAlcMethod()); // do the water calcs w/ the updated mash: chillShrinkQTS = getPostBoilVol("qt") * 0.03; spargeQTS = getPreBoilVol("qt") - (mash.getTotalWaterQts() - mash.getAbsorbedQts()); totalWaterQTS = mash.getTotalWaterQts() + spargeQTS; finalWortVolQTS = postBoilVol.getValueAs("qt") - (chillShrinkQTS + Quantity.convertUnit(getVolUnits(), "qt", kettleLoss) + Quantity.convertUnit(getVolUnits(), "qt", trubLoss) + Quantity .convertUnit(getVolUnits(), "qt", miscLoss)); }
public void calcMaltTotals() { double maltPoints = 0; double mcu = 0; totalMaltLbs = 0; totalMaltCost = 0; totalMashLbs = 0; // first figure out the total we're dealing with for (int i = 0; i < fermentables.size(); i++) { Fermentable m = ((Fermentable) fermentables.get(i)); totalMaltLbs += (m.getAmountAs("lb")); if (m.getMashed()) { // apply efficiency and add to mash weight maltPoints += (m.getPppg() - 1) * m.getAmountAs("lb") * efficiency / postBoilVol.getValueAs("gal"); totalMashLbs += (m.getAmountAs("lb")); } else maltPoints += (m.getPppg() - 1) * m.getAmountAs("lb") * 100 / postBoilVol.getValueAs("gal"); mcu += m.getLov() * m.getAmountAs("lb") / postBoilVol.getValueAs("gal"); totalMaltCost += m.getCostPerU() * m.getAmountAs(m.getUnits()); } // now set the malt % by weight: for (int i = 0; i < fermentables.size(); i++) { Fermentable m = ((Fermentable) fermentables.get(i)); m.setPercent((m.getAmountAs("lb") / totalMaltLbs * 100)); } // set the fields in the object estOg = (maltPoints / 100) + 1; estFg = 1 + ((estOg - 1) * ((100 - attenuation) / 100)); srm = calcColour(mcu); mash.setMaltWeight(totalMashLbs); calcAlcohol(getAlcMethod()); // do the water calcs w/ the updated mash: chillShrinkQTS = getPostBoilVol("qt") * 0.03; spargeQTS = getPreBoilVol("qt") - (mash.getTotalWaterQts() - mash.getAbsorbedQts()); totalWaterQTS = mash.getTotalWaterQts() + spargeQTS; finalWortVolQTS = postBoilVol.getValueAs("qt") - (chillShrinkQTS + Quantity.convertUnit(getVolUnits(), "qt", kettleLoss) + Quantity.convertUnit(getVolUnits(), "qt", trubLoss) + Quantity .convertUnit(getVolUnits(), "qt", miscLoss)); }
1,115,284
public void calcHopsTotals() { double ibuTotal = 0; totalHopsCost = 0; totalHopsOz = 0; for (int i = 0; i < hops.size(); i++) { // calculate the average OG of the boil // first, the OG at the time of addition: double adjPreSize, aveOg = 0; Hop h = ((Hop) hops.get(i)); if (h.getAdd().equalsIgnoreCase("boil") || h.getAdd().equalsIgnoreCase("fwh")) { if (h.getMinutes() > 0) adjPreSize = postBoilVol.getValueAs("gal") + (preBoilVol.getValueAs("gal") - postBoilVol.getValueAs("gal")) / (boilMinutes / h.getMinutes()); else adjPreSize = postBoilVol.getValueAs("gal"); aveOg = 1 + (((estOg - 1) + ((estOg - 1) / (adjPreSize / postBoilVol .getValueAs("gal")))) / 2); if (ibuCalcMethod.equals("Tinseth")) h.setIBU(calcTinseth(h.getAmountAs("oz"), postBoilVol.getValueAs("gal"), aveOg, h.getMinutes(), h.getAlpha(), ibuHopUtil)); else if (ibuCalcMethod.equals("Rager")) h.setIBU(CalcRager(h.getAmountAs("oz"), postBoilVol.getValueAs("gal"), aveOg, h .getMinutes(), h.getAlpha())); else h.setIBU(CalcGaretz(h.getAmountAs("oz"), postBoilVol.getValueAs("gal"), aveOg, h.getMinutes(), preBoilVol.getValueAs("gal"), 1, h.getAlpha())); if (h.getType().equalsIgnoreCase("Pellet")) { h.setIBU(h.getIBU() * (1.0 + (pelletHopPct / 100))); } ibuTotal += h.getIBU(); } totalHopsCost += h.getCostPerU() * h.getAmountAs("oz"); totalHopsOz += h.getAmountAs("oz"); } ibu = ibuTotal; }
public void calcHopsTotals() { double ibuTotal = 0; totalHopsCost = 0; totalHopsOz = 0; for (int i = 0; i < hops.size(); i++) { // calculate the average OG of the boil // first, the OG at the time of addition: double adjPreSize, aveOg = 0; Hop h = ((Hop) hops.get(i)); if (h.getAdd().equalsIgnoreCase("boil") || h.getAdd().equalsIgnoreCase("fwh")) { if (h.getMinutes() > 0) adjPreSize = postBoilVol.getValueAs("gal") + (preBoilVol.getValueAs("gal") - postBoilVol.getValueAs("gal")) / (boilMinutes / h.getMinutes()); else adjPreSize = postBoilVol.getValueAs("gal"); aveOg = 1 + (((estOg - 1) + ((estOg - 1) / (adjPreSize / postBoilVol .getValueAs("gal")))) / 2); if (ibuCalcMethod.equals("Tinseth")) h.setIBU(calcTinseth(h.getAmountAs("oz"), postBoilVol.getValueAs("gal"), aveOg, h.getMinutes(), h.getAlpha(), ibuHopUtil)); else if (ibuCalcMethod.equals("Rager")) h.setIBU(CalcRager(h.getAmountAs("oz"), postBoilVol.getValueAs("gal"), aveOg, h .getMinutes(), h.getAlpha())); else h.setIBU(CalcGaretz(h.getAmountAs("oz"), postBoilVol.getValueAs("gal"), aveOg, h.getMinutes(), preBoilVol.getValueAs("gal"), 1, h.getAlpha())); if (h.getType().equalsIgnoreCase("Pellet")) { h.setIBU(h.getIBU() * (1.0 + (pelletHopPct / 100))); } ibuTotal += h.getIBU(); } totalHopsCost += h.getCostPerU() * h.getAmountAs(h.getUnits()); totalHopsOz += h.getAmountAs("oz"); } ibu = ibuTotal; }
1,115,285
public void setStyle(Style s) { style = s; }
public void setStyle(Style s) { style = s; }
1,115,286
public String getColourMethod() { return ""; }
public String getColourMethod() { return colourMethod; }
1,115,287
public void displayMash() { if (myRecipe != null) { recipeNameLabel.setText(myRecipe.getName()); volUnitsComboModel.addOrInsert(myRecipe.mash.getMashVolUnits()); // temp units: if (myRecipe.mash.getMashTempUnits().equals("F")) tempFrb.setSelected(true); else tempCrb.setSelected(true); grainTempULabel.setText(myRecipe.mash.getMashTempUnits()); tempLostULabel.setText(myRecipe.mash.getMashTempUnits()); boilTempULbl.setText(myRecipe.mash.getMashTempUnits()); // set totals: String mashWeightTotal = SBStringUtils.format(myRecipe.getTotalMash(), 1) + " " + myRecipe.getMaltUnits(); totalMashLabel.setText(mashWeightTotal); totalTimeLabel.setText(new Integer(myRecipe.mash.getMashTotalTime()).toString()); volLabel.setText(myRecipe.mash.getMashTotalVol()); grainTempText.setText(new Double(myRecipe.mash.getGrainTemp()).toString()); boilTempTxt.setText(new Double(myRecipe.mash.getBoilTemp()).toString()); tunLossTxt.setText(new Double(myRecipe.mash.getTunLoss()).toString()); tempFrb.setSelected(myRecipe.mash.getMashTempUnits().equalsIgnoreCase("F")); } }
public void displayMash() { if (myRecipe != null) { recipeNameLabel.setText(myRecipe.getName()); volUnitsComboModel.addOrInsert(myRecipe.mash.getMashVolUnits()); // temp units: if (myRecipe.mash.getMashTempUnits().equals("F")) tempFrb.setSelected(true); else tempCrb.setSelected(true); grainTempULabel.setText(myRecipe.mash.getMashTempUnits()); tempLostULabel.setText(myRecipe.mash.getMashTempUnits()); boilTempULbl.setText(myRecipe.mash.getMashTempUnits()); // set totals: String mashWeightTotal = SBStringUtils.format(myRecipe.getTotalMash(), 1) + " " + myRecipe.getMaltUnits(); totalMashLabel.setText(mashWeightTotal); totalTimeLabel.setText(new Integer(myRecipe.mash.getMashTotalTime()).toString()); volLabel.setText(myRecipe.mash.getMashTotalVol()); grainTempText.setText(new Double(myRecipe.mash.getGrainTemp()).toString()); boilTempTxt.setText(new Double(myRecipe.mash.getBoilTemp()).toString()); tunLossTxt.setText(SBStringUtils.format(myRecipe.mash.getTunLoss(), 1)); tempFrb.setSelected(myRecipe.mash.getMashTempUnits().equalsIgnoreCase("F")); } }
1,115,288
public StylePanel(StrangeSwing.SBNotifier sb) { super(); sbn = sb; initGUI(); }
public StylePanel() { super(); sbn = sb; initGUI(); }
1,115,289
public StylePanel(StrangeSwing.SBNotifier sb) { super(); sbn = sb; initGUI(); }
public StylePanel(StrangeSwing.SBNotifier sb) { super(); initGUI(); }
1,115,290
protected static int[][] compressYvalues(LocalSeismogram seismogram, MicroSecondTimeRange tr, UnitRangeImpl ampRange, Dimension size)throws UnsupportedDataEncoding { LocalSeismogramImpl seis = (LocalSeismogramImpl)seismogram; /*double pointsPerPixel = tr.getInterval().divideBy(seis.getSampling().getPeriod()).getValue() / size.width; if(pointsPerPixel < 3 ){ return getPlottableSimple(seis, ampRange, tr, size); }else{*/ int[][] uncomp = scaleXvalues(seismogram, tr, ampRange, size); // enough points to take the extra time to compress the line int[][] comp = new int[2][2 * size.width]; int j = 0, startIndex = 0, xvalue = 0, endIndex = 0; if(uncomp[0].length != 0) xvalue = uncomp[0][0]; for(int i = 0; i < uncomp[0].length; i++) { if(uncomp[0][i] != xvalue) { endIndex = i - 1; comp[1][j] = getMinValue(uncomp[1], startIndex, endIndex); comp[1][j+1] = (int)getMaxValue(uncomp[1], startIndex, endIndex); comp[0][j] = uncomp[0][i]; comp[0][j+1] = uncomp[0][i]; j = j + 2; startIndex = endIndex + 1; xvalue = uncomp[0][i]; } } if(xvalue != 0) { startIndex = uncomp[0].length - 1; endIndex = uncomp[0].length - 1; comp[1][j] = getMinValue(uncomp[1], startIndex, endIndex); comp[1][j+1] = (int)getMaxValue(uncomp[1], startIndex, endIndex); comp[0][j] = uncomp[0][endIndex]; comp[0][j+1] = uncomp[0][endIndex]; j = j + 2; } int temp[][] = new int[2][j]; System.arraycopy(comp[0], 0, temp[0], 0, j); System.arraycopy(comp[1], 0, temp[1], 0, j); return temp; }
protected static int[][] compressYvalues(LocalSeismogram seismogram, MicroSecondTimeRange tr, UnitRangeImpl ampRange, Dimension size)throws UnsupportedDataEncoding { LocalSeismogramImpl seis = (LocalSeismogramImpl)seismogram; /*double pointsPerPixel = tr.getInterval().divideBy(seis.getSampling().getPeriod()).getValue() / size.width; if(pointsPerPixel < 3 ){ return getPlottableSimpl(seis, ampRange, tr, size); }else{*/ int[][] uncomp = scaleXvalues(seismogram, tr, ampRange, size); // enough points to take the extra time to compress the line int[][] comp = new int[2][2 * size.width]; int j = 0, startIndex = 0, xvalue = 0, endIndex = 0; if(uncomp[0].length != 0) xvalue = uncomp[0][0]; for(int i = 0; i < uncomp[0].length; i++) { if(uncomp[0][i] != xvalue) { endIndex = i - 1; comp[1][j] = getMinValue(uncomp[1], startIndex, endIndex); comp[1][j+1] = (int)getMaxValue(uncomp[1], startIndex, endIndex); comp[0][j] = uncomp[0][i]; comp[0][j+1] = uncomp[0][i]; j = j + 2; startIndex = endIndex + 1; xvalue = uncomp[0][i]; } } if(xvalue != 0) { startIndex = uncomp[0].length - 1; endIndex = uncomp[0].length - 1; comp[1][j] = getMinValue(uncomp[1], startIndex, endIndex); comp[1][j+1] = (int)getMaxValue(uncomp[1], startIndex, endIndex); comp[0][j] = uncomp[0][endIndex]; comp[0][j+1] = uncomp[0][endIndex]; j = j + 2; } int temp[][] = new int[2][j]; System.arraycopy(comp[0], 0, temp[0], 0, j); System.arraycopy(comp[1], 0, temp[1], 0, j); return temp; }
1,115,292
public Object umin(Object param1) throws ParseException { if(param1 instanceof MVector) return umin((MVector) param1); if(param1 instanceof Matrix) return umin((Matrix) param1); else return super.umin(param1); }
public Object umin(Object param1) throws ParseException { if(param1 instanceof MVector) return umin((MVector) param1); if(param1 instanceof Matrix) return umin((Matrix) param1); else return super.umin(param1); }
1,115,293
public MVector(int size) { data = new Object[size]; dim = Dimensions.valueOf(size); }
public MVector(int size) { data = new Object[size]; dim = Dimensions.valueOf(size); }
1,115,294
public Tensor(Tensor t) { values = new Object[t.getDim().numEles()]; this.dims = t.getDim(); }
public Tensor(Tensor t) { values = new Object[t.getDim().numEles()]; this.dims = t.getDim(); }
1,115,295
final public void Function() throws ParseException { int reqArguments = 0; String identString = ""; ASTFunNode jjtn001 = new ASTFunNode(JJTFUNNODE); boolean jjtc001 = true; jjtree.openNodeScope(jjtn001); try { identString = Identifier(); if (jep.funTab.containsKey(identString)) { //Set number of required arguments reqArguments = ((PostfixMathCommand)jep.funTab.get(identString)).getNumberOfParameters(); jjtn001.setFunction(identString, (PostfixMathCommandI)jep.funTab.get(identString)); } else { addToErrorList("!!! Unrecognized function \"" + identString +"\""); } jj_consume_token(28); ArgumentList(reqArguments, identString); jj_consume_token(29); } catch (Throwable jjte001) { if (jjtc001) { jjtree.clearNodeScope(jjtn001); jjtc001 = false; } else { jjtree.popNode(); } if (jjte001 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte001;} } if (jjte001 instanceof ParseException) { {if (true) throw (ParseException)jjte001;} } {if (true) throw (Error)jjte001;} } finally { if (jjtc001) { jjtree.closeNodeScope(jjtn001, true); } } }
final public void Function() throws ParseException { int reqArguments = 0; String identString = ""; ASTFunNode jjtn001 = new ASTFunNode(JJTFUNNODE); boolean jjtc001 = true; jjtree.openNodeScope(jjtn001); try { identString = Identifier(); if (jep.funTab.containsKey(identString)) { //Set number of required arguments reqArguments = ((PostfixMathCommandI)jep.funTab.get(identString)).getNumberOfParameters(); jjtn001.setFunction(identString, (PostfixMathCommandI)jep.funTab.get(identString)); } else { addToErrorList("!!! Unrecognized function \"" + identString +"\""); } jj_consume_token(28); ArgumentList(reqArguments, identString); jj_consume_token(29); } catch (Throwable jjte001) { if (jjtc001) { jjtree.clearNodeScope(jjtn001); jjtc001 = false; } else { jjtree.popNode(); } if (jjte001 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte001;} } if (jjte001 instanceof ParseException) { {if (true) throw (ParseException)jjte001;} } {if (true) throw (Error)jjte001;} } finally { if (jjtc001) { jjtree.closeNodeScope(jjtn001, true); } } }
1,115,296
public FissuresNamingServiceImpl (java.util.Properties props) throws org.omg.CORBA.ORBPackage.InvalidName{ this.props = props; String[] args = new String[0]; try { orb = (org.omg.CORBA_2_3.ORB)org.omg.CORBA.ORB.init(args, props); // register valuetype factories AllVTFactory vt = new AllVTFactory(); vt.register(orb); // get a reference to the Naming Service root_context org.omg.CORBA.Object rootObj = orb.resolve_initial_references("NameService"); if (rootObj == null) { //logger.error logger.info("Name service object is null!"); return; } namingContext = NamingContextExtHelper.narrow(rootObj); //logger.info logger.info("got Name context"); } catch(org.omg.CORBA.ORBPackage.InvalidName ine) { throw new org.omg.CORBA.ORBPackage.InvalidName(); } }
public FissuresNamingServiceImpl (java.util.Properties props) throws InvalidName { this.props = props; String[] args = new String[0]; try { orb = (org.omg.CORBA_2_3.ORB)org.omg.CORBA.ORB.init(args, props); // register valuetype factories AllVTFactory vt = new AllVTFactory(); vt.register(orb); // get a reference to the Naming Service root_context org.omg.CORBA.Object rootObj = orb.resolve_initial_references("NameService"); if (rootObj == null) { //logger.error logger.info("Name service object is null!"); return; } namingContext = NamingContextExtHelper.narrow(rootObj); //logger.info logger.info("got Name context"); } catch(org.omg.CORBA.ORBPackage.InvalidName ine) { throw new org.omg.CORBA.ORBPackage.InvalidName(); } }
1,115,297
public FissuresNamingServiceImpl (java.util.Properties props) throws org.omg.CORBA.ORBPackage.InvalidName{ this.props = props; String[] args = new String[0]; try { orb = (org.omg.CORBA_2_3.ORB)org.omg.CORBA.ORB.init(args, props); // register valuetype factories AllVTFactory vt = new AllVTFactory(); vt.register(orb); // get a reference to the Naming Service root_context org.omg.CORBA.Object rootObj = orb.resolve_initial_references("NameService"); if (rootObj == null) { //logger.error logger.info("Name service object is null!"); return; } namingContext = NamingContextExtHelper.narrow(rootObj); //logger.info logger.info("got Name context"); } catch(org.omg.CORBA.ORBPackage.InvalidName ine) { throw new org.omg.CORBA.ORBPackage.InvalidName(); } }
public FissuresNamingServiceImpl (java.util.Properties props) throws org.omg.CORBA.ORBPackage.InvalidName{ this.props = props; String[] args = new String[0]; try { orb = (org.omg.CORBA_2_3.ORB)org.omg.CORBA.ORB.init(args, props); // register valuetype factories AllVTFactory vt = new AllVTFactory(); vt.register(orb); // get a reference to the Naming Service root_context org.omg.CORBA.Object rootObj = orb.resolve_initial_references("NameService"); if (rootObj == null) { //logger.error logger.info("Name service object is null!"); return; } namingContext = NamingContextExtHelper.narrow(rootObj); //logger.info logger.info("got Name context"); } catch(org.omg.CORBA.ORBPackage.InvalidName ine) { throw new org.omg.CORBA.ORBPackage.InvalidName(); } }
1,115,298
public FissuresNamingServiceImpl (java.util.Properties props) throws org.omg.CORBA.ORBPackage.InvalidName{ this.props = props; String[] args = new String[0]; try { orb = (org.omg.CORBA_2_3.ORB)org.omg.CORBA.ORB.init(args, props); // register valuetype factories AllVTFactory vt = new AllVTFactory(); vt.register(orb); // get a reference to the Naming Service root_context org.omg.CORBA.Object rootObj = orb.resolve_initial_references("NameService"); if (rootObj == null) { //logger.error logger.info("Name service object is null!"); return; } namingContext = NamingContextExtHelper.narrow(rootObj); //logger.info logger.info("got Name context"); } catch(org.omg.CORBA.ORBPackage.InvalidName ine) { throw new org.omg.CORBA.ORBPackage.InvalidName(); } }
public FissuresNamingServiceImpl (java.util.Properties props) throws org.omg.CORBA.ORBPackage.InvalidName{ this.props = props; String[] args = new String[0]; try { orb = (org.omg.CORBA_2_3.ORB)org.omg.CORBA.ORB.init(args, props); // register valuetype factories AllVTFactory vt = new AllVTFactory(); vt.register(orb); // get a reference to the Naming Service root_context org.omg.CORBA.Object rootObj = orb.resolve_initial_references("NameService"); if (rootObj == null) { //logger.error logger.info("Name service object is null!"); return; } namingContext = NamingContextExtHelper.narrow(rootObj); //logger.info logger.info("got Name context"); } catch(org.omg.CORBA.ORBPackage.InvalidName ine) { throw new org.omg.CORBA.ORBPackage.InvalidName(); } }
1,115,299
public FissuresNamingServiceImpl (java.util.Properties props) throws org.omg.CORBA.ORBPackage.InvalidName{ this.props = props; String[] args = new String[0]; try { orb = (org.omg.CORBA_2_3.ORB)org.omg.CORBA.ORB.init(args, props); // register valuetype factories AllVTFactory vt = new AllVTFactory(); vt.register(orb); // get a reference to the Naming Service root_context org.omg.CORBA.Object rootObj = orb.resolve_initial_references("NameService"); if (rootObj == null) { //logger.error logger.info("Name service object is null!"); return; } namingContext = NamingContextExtHelper.narrow(rootObj); //logger.info logger.info("got Name context"); } catch(org.omg.CORBA.ORBPackage.InvalidName ine) { throw new org.omg.CORBA.ORBPackage.InvalidName(); } }
public FissuresNamingServiceImpl (java.util.Properties props) throws org.omg.CORBA.ORBPackage.InvalidName{ this.props = props; String[] args = new String[0]; try { orb = (org.omg.CORBA_2_3.ORB)org.omg.CORBA.ORB.init(args, props); // register valuetype factories AllVTFactory vt = new AllVTFactory(); vt.register(orb); // get a reference to the Naming Service root_context org.omg.CORBA.Object rootObj = orb.resolve_initial_references("NameService"); if (rootObj == null) { //logger.error logger.info("Name service object is null!"); return; } namingContext = NamingContextExtHelper.narrow(rootObj); //logger.info logger.info("got Name context"); } catch(org.omg.CORBA.ORBPackage.InvalidName ine) { throw new org.omg.CORBA.ORBPackage.InvalidName(); } }
1,115,300
public void rebind(String dns, String objectname, org.omg.CORBA.Object obj) throws org.omg.CosNaming.NamingContextPackage.NotFound, org.omg.CosNaming.NamingContextPackage.CannotProceed, org.omg.CosNaming.NamingContextPackage.InvalidName, Exception { logger.info("The CLASS Name is "+obj.getClass().getName()); String interfacename = getInterfaceName(obj); dns = appendKindNames(dns); if(interfacename != null && interfacename.length() != 0) dns = dns + "/" + interfacename + ".interface"; if(objectname != null && objectname.length() != 0) { objectname = objectname + getVersion(); dns = dns + "/" + objectname + ".object"; } logger.info("the dns to be bind is "+dns); NameComponent[] ncName; try { ncName = namingContext.to_name(dns); } catch(org.omg.CosNaming.NamingContextPackage.InvalidName ine) { logger.info("INVALID NAME EXCEPTION IS CAUGHT"); throw new org.omg.CosNaming.NamingContextPackage.InvalidName();//"The DNS name "+dns+" that is passed is InValid "); //return false; } NameComponent[] ncName1 = new NameComponent[1]; NamingContext namingContextTemp = (NamingContext)namingContext; int counter; for(counter = 0; counter < ncName.length; counter++) { //NameComponent temp[] = new NameComponent[counter]; int subcounter; try { namingContext.rebind(namingContext.to_name(dns), obj); //namingContext.reslove(namingContext.to_name(dns)); } catch(org.omg.CosNaming.NamingContextPackage.NotFound nfe) { switch(nfe.why.value()) { case NotFoundReason._missing_node: ncName1[0] = nfe.rest_of_name[0]; logger.info("The id of the context is "+ncName1[0].id) ; subcounter = 0; for(int i = 0 ; i < ncName.length && !ncName[i].id.equals(ncName1[0].id); i++) { subcounter++; } NameComponent temp[] = new NameComponent[subcounter]; for(int i = 0 ; i < ncName.length && !ncName[i].id.equals(ncName1[0].id); i++) { temp[i] = ncName[i]; } try { if(subcounter != 0){ logger.info("resolving new naming context"); namingContextTemp = NamingContextExtHelper.narrow(namingContext.resolve(temp)); } if(ncName1[0].id.equals(interfacename)) ncName1[0].kind = "interface"; else if(ncName1[0].id.equals(objectname)) ncName1[0].kind = "object"; else ncName1[0].kind = "dns"; namingContextTemp.bind_new_context(ncName1); } catch(Exception ex) { logger.info("This Exception must not occur"); ex.printStackTrace(); throw new Exception(); } break; case NotFoundReason._not_context: logger.info("Not a Context"); logger.info(nfe.rest_of_name[0].id+" IS PASSED AS A CONTEXT. ACTUALLY IT IS ALREADY BOUND AS AN OBJECT"); throw new org.omg.CosNaming.NamingContextPackage.NotFound(nfe.why, nfe.rest_of_name); //break; case NotFoundReason._not_object: logger.info("Not an Object"); logger.info(nfe.rest_of_name[0].id+" IS PASSED AS AN OBJECT. ACTUALLY IT IS ALREADY BOUND AS A CONTEXT"); throw new org.omg.CosNaming.NamingContextPackage.NotFound(nfe.why, nfe.rest_of_name); } } catch(org.omg.CosNaming.NamingContextPackage.CannotProceed cpe) { logger.info("Caught Exception cannot proceed"); throw new org.omg.CosNaming.NamingContextPackage.CannotProceed(); } } }
public void rebind(String dns, String objectname, org.omg.CORBA.Object obj) throws org.omg.CosNaming.NamingContextPackage.NotFound, org.omg.CosNaming.NamingContextPackage.CannotProceed, org.omg.CosNaming.NamingContextPackage.InvalidName { logger.info("The CLASS Name is "+obj.getClass().getName()); String interfacename = getInterfaceName(obj); dns = appendKindNames(dns); if(interfacename != null && interfacename.length() != 0) dns = dns + "/" + interfacename + ".interface"; if(objectname != null && objectname.length() != 0) { objectname = objectname + getVersion(); dns = dns + "/" + objectname + ".object"; } logger.info("the dns to be bind is "+dns); NameComponent[] ncName; try { ncName = namingContext.to_name(dns); } catch(org.omg.CosNaming.NamingContextPackage.InvalidName ine) { logger.info("INVALID NAME EXCEPTION IS CAUGHT"); throw new org.omg.CosNaming.NamingContextPackage.InvalidName();//"The DNS name "+dns+" that is passed is InValid "); //return false; } NameComponent[] ncName1 = new NameComponent[1]; NamingContext namingContextTemp = (NamingContext)namingContext; int counter; for(counter = 0; counter < ncName.length; counter++) { //NameComponent temp[] = new NameComponent[counter]; int subcounter; try { namingContext.rebind(namingContext.to_name(dns), obj); //namingContext.reslove(namingContext.to_name(dns)); } catch(org.omg.CosNaming.NamingContextPackage.NotFound nfe) { switch(nfe.why.value()) { case NotFoundReason._missing_node: ncName1[0] = nfe.rest_of_name[0]; logger.info("The id of the context is "+ncName1[0].id) ; subcounter = 0; for(int i = 0 ; i < ncName.length && !ncName[i].id.equals(ncName1[0].id); i++) { subcounter++; } NameComponent temp[] = new NameComponent[subcounter]; for(int i = 0 ; i < ncName.length && !ncName[i].id.equals(ncName1[0].id); i++) { temp[i] = ncName[i]; } try { if(subcounter != 0){ logger.info("resolving new naming context"); namingContextTemp = NamingContextExtHelper.narrow(namingContext.resolve(temp)); } if(ncName1[0].id.equals(interfacename)) ncName1[0].kind = "interface"; else if(ncName1[0].id.equals(objectname)) ncName1[0].kind = "object"; else ncName1[0].kind = "dns"; namingContextTemp.bind_new_context(ncName1); } catch(Exception ex) { logger.info("This Exception must not occur"); ex.printStackTrace(); throw new Exception(); } break; case NotFoundReason._not_context: logger.info("Not a Context"); logger.info(nfe.rest_of_name[0].id+" IS PASSED AS A CONTEXT. ACTUALLY IT IS ALREADY BOUND AS AN OBJECT"); throw new org.omg.CosNaming.NamingContextPackage.NotFound(nfe.why, nfe.rest_of_name); //break; case NotFoundReason._not_object: logger.info("Not an Object"); logger.info(nfe.rest_of_name[0].id+" IS PASSED AS AN OBJECT. ACTUALLY IT IS ALREADY BOUND AS A CONTEXT"); throw new org.omg.CosNaming.NamingContextPackage.NotFound(nfe.why, nfe.rest_of_name); } } catch(org.omg.CosNaming.NamingContextPackage.CannotProceed cpe) { logger.info("Caught Exception cannot proceed"); throw new org.omg.CosNaming.NamingContextPackage.CannotProceed(); } } }
1,115,302
public void rebind(String dns, String objectname, org.omg.CORBA.Object obj) throws org.omg.CosNaming.NamingContextPackage.NotFound, org.omg.CosNaming.NamingContextPackage.CannotProceed, org.omg.CosNaming.NamingContextPackage.InvalidName, Exception { logger.info("The CLASS Name is "+obj.getClass().getName()); String interfacename = getInterfaceName(obj); dns = appendKindNames(dns); if(interfacename != null && interfacename.length() != 0) dns = dns + "/" + interfacename + ".interface"; if(objectname != null && objectname.length() != 0) { objectname = objectname + getVersion(); dns = dns + "/" + objectname + ".object"; } logger.info("the dns to be bind is "+dns); NameComponent[] ncName; try { ncName = namingContext.to_name(dns); } catch(org.omg.CosNaming.NamingContextPackage.InvalidName ine) { logger.info("INVALID NAME EXCEPTION IS CAUGHT"); throw new org.omg.CosNaming.NamingContextPackage.InvalidName();//"The DNS name "+dns+" that is passed is InValid "); //return false; } NameComponent[] ncName1 = new NameComponent[1]; NamingContext namingContextTemp = (NamingContext)namingContext; int counter; for(counter = 0; counter < ncName.length; counter++) { //NameComponent temp[] = new NameComponent[counter]; int subcounter; try { namingContext.rebind(namingContext.to_name(dns), obj); //namingContext.reslove(namingContext.to_name(dns)); } catch(org.omg.CosNaming.NamingContextPackage.NotFound nfe) { switch(nfe.why.value()) { case NotFoundReason._missing_node: ncName1[0] = nfe.rest_of_name[0]; logger.info("The id of the context is "+ncName1[0].id) ; subcounter = 0; for(int i = 0 ; i < ncName.length && !ncName[i].id.equals(ncName1[0].id); i++) { subcounter++; } NameComponent temp[] = new NameComponent[subcounter]; for(int i = 0 ; i < ncName.length && !ncName[i].id.equals(ncName1[0].id); i++) { temp[i] = ncName[i]; } try { if(subcounter != 0){ logger.info("resolving new naming context"); namingContextTemp = NamingContextExtHelper.narrow(namingContext.resolve(temp)); } if(ncName1[0].id.equals(interfacename)) ncName1[0].kind = "interface"; else if(ncName1[0].id.equals(objectname)) ncName1[0].kind = "object"; else ncName1[0].kind = "dns"; namingContextTemp.bind_new_context(ncName1); } catch(Exception ex) { logger.info("This Exception must not occur"); ex.printStackTrace(); throw new Exception(); } break; case NotFoundReason._not_context: logger.info("Not a Context"); logger.info(nfe.rest_of_name[0].id+" IS PASSED AS A CONTEXT. ACTUALLY IT IS ALREADY BOUND AS AN OBJECT"); throw new org.omg.CosNaming.NamingContextPackage.NotFound(nfe.why, nfe.rest_of_name); //break; case NotFoundReason._not_object: logger.info("Not an Object"); logger.info(nfe.rest_of_name[0].id+" IS PASSED AS AN OBJECT. ACTUALLY IT IS ALREADY BOUND AS A CONTEXT"); throw new org.omg.CosNaming.NamingContextPackage.NotFound(nfe.why, nfe.rest_of_name); } } catch(org.omg.CosNaming.NamingContextPackage.CannotProceed cpe) { logger.info("Caught Exception cannot proceed"); throw new org.omg.CosNaming.NamingContextPackage.CannotProceed(); } } }
public void rebind(String dns, String objectname, org.omg.CORBA.Object obj) throws org.omg.CosNaming.NamingContextPackage.NotFound, org.omg.CosNaming.NamingContextPackage.CannotProceed, org.omg.CosNaming.NamingContextPackage.InvalidName, Exception { logger.info("The CLASS Name is "+obj.getClass().getName()); String interfacename = getInterfaceName(obj); dns = appendKindNames(dns); if(interfacename != null && interfacename.length() != 0) dns = dns + "/" + interfacename + ".interface"; if(objectname != null && objectname.length() != 0) { objectname = objectname + getVersion(); dns = dns + "/" + objectname + ".object"; } logger.info("the dns to be bind is "+dns); NameComponent[] ncName; try { ncName = namingContext.to_name(dns); } catch(org.omg.CosNaming.NamingContextPackage.InvalidName ine) { logger.info("INVALID NAME EXCEPTION IS CAUGHT"); throw new org.omg.CosNaming.NamingContextPackage.InvalidName();//"The DNS name "+dns+" that is passed is InValid "); //return false; } NameComponent[] ncName1 = new NameComponent[1]; NamingContext namingContextTemp = (NamingContext)namingContext; int counter; for(counter = 0; counter < ncName.length; counter++) { //NameComponent temp[] = new NameComponent[counter]; int subcounter; try { namingContext.rebind(namingContext.to_name(dns), obj); //namingContext.reslove(namingContext.to_name(dns)); } catch(org.omg.CosNaming.NamingContextPackage.NotFound nfe) { switch(nfe.why.value()) { case NotFoundReason._missing_node: ncName1[0] = nfe.rest_of_name[0]; logger.info("The id of the context is "+ncName1[0].id) ; subcounter = 0; for(int i = 0 ; i < ncName.length && !ncName[i].id.equals(ncName1[0].id); i++) { subcounter++; } NameComponent temp[] = new NameComponent[subcounter]; for(int i = 0 ; i < ncName.length && !ncName[i].id.equals(ncName1[0].id); i++) { temp[i] = ncName[i]; } try { if(subcounter != 0){ logger.info("resolving new naming context"); namingContextTemp = NamingContextExtHelper.narrow(namingContext.resolve(temp)); } if(ncName1[0].id.equals(interfacename)) ncName1[0].kind = "interface"; else if(ncName1[0].id.equals(objectname)) ncName1[0].kind = "object"; else ncName1[0].kind = "dns"; namingContextTemp.bind_new_context(ncName1); } catch(Exception ex) { logger.info("This Exception must not occur"); ex.printStackTrace(); throw new Exception(); } break; case NotFoundReason._not_context: logger.info("Not a Context"); logger.info(nfe.rest_of_name[0].id+" IS PASSED AS A CONTEXT. ACTUALLY IT IS ALREADY BOUND AS AN OBJECT"); throw new org.omg.CosNaming.NamingContextPackage.NotFound(nfe.why, nfe.rest_of_name); //break; case NotFoundReason._not_object: logger.info("Not an Object"); logger.info(nfe.rest_of_name[0].id+" IS PASSED AS AN OBJECT. ACTUALLY IT IS ALREADY BOUND AS A CONTEXT"); throw new org.omg.CosNaming.NamingContextPackage.NotFound(nfe.why, nfe.rest_of_name); } } catch(org.omg.CosNaming.NamingContextPackage.CannotProceed cpe) { logger.info("Caught Exception cannot proceed"); throw new org.omg.CosNaming.NamingContextPackage.CannotProceed(); } } }
1,115,303
public void rebind(String dns, String objectname, org.omg.CORBA.Object obj) throws org.omg.CosNaming.NamingContextPackage.NotFound, org.omg.CosNaming.NamingContextPackage.CannotProceed, org.omg.CosNaming.NamingContextPackage.InvalidName, Exception { logger.info("The CLASS Name is "+obj.getClass().getName()); String interfacename = getInterfaceName(obj); dns = appendKindNames(dns); if(interfacename != null && interfacename.length() != 0) dns = dns + "/" + interfacename + ".interface"; if(objectname != null && objectname.length() != 0) { objectname = objectname + getVersion(); dns = dns + "/" + objectname + ".object"; } logger.info("the dns to be bind is "+dns); NameComponent[] ncName; try { ncName = namingContext.to_name(dns); } catch(org.omg.CosNaming.NamingContextPackage.InvalidName ine) { logger.info("INVALID NAME EXCEPTION IS CAUGHT"); throw new org.omg.CosNaming.NamingContextPackage.InvalidName();//"The DNS name "+dns+" that is passed is InValid "); //return false; } NameComponent[] ncName1 = new NameComponent[1]; NamingContext namingContextTemp = (NamingContext)namingContext; int counter; for(counter = 0; counter < ncName.length; counter++) { //NameComponent temp[] = new NameComponent[counter]; int subcounter; try { namingContext.rebind(namingContext.to_name(dns), obj); //namingContext.reslove(namingContext.to_name(dns)); } catch(org.omg.CosNaming.NamingContextPackage.NotFound nfe) { switch(nfe.why.value()) { case NotFoundReason._missing_node: ncName1[0] = nfe.rest_of_name[0]; logger.info("The id of the context is "+ncName1[0].id) ; subcounter = 0; for(int i = 0 ; i < ncName.length && !ncName[i].id.equals(ncName1[0].id); i++) { subcounter++; } NameComponent temp[] = new NameComponent[subcounter]; for(int i = 0 ; i < ncName.length && !ncName[i].id.equals(ncName1[0].id); i++) { temp[i] = ncName[i]; } try { if(subcounter != 0){ logger.info("resolving new naming context"); namingContextTemp = NamingContextExtHelper.narrow(namingContext.resolve(temp)); } if(ncName1[0].id.equals(interfacename)) ncName1[0].kind = "interface"; else if(ncName1[0].id.equals(objectname)) ncName1[0].kind = "object"; else ncName1[0].kind = "dns"; namingContextTemp.bind_new_context(ncName1); } catch(Exception ex) { logger.info("This Exception must not occur"); ex.printStackTrace(); throw new Exception(); } break; case NotFoundReason._not_context: logger.info("Not a Context"); logger.info(nfe.rest_of_name[0].id+" IS PASSED AS A CONTEXT. ACTUALLY IT IS ALREADY BOUND AS AN OBJECT"); throw new org.omg.CosNaming.NamingContextPackage.NotFound(nfe.why, nfe.rest_of_name); //break; case NotFoundReason._not_object: logger.info("Not an Object"); logger.info(nfe.rest_of_name[0].id+" IS PASSED AS AN OBJECT. ACTUALLY IT IS ALREADY BOUND AS A CONTEXT"); throw new org.omg.CosNaming.NamingContextPackage.NotFound(nfe.why, nfe.rest_of_name); } } catch(org.omg.CosNaming.NamingContextPackage.CannotProceed cpe) { logger.info("Caught Exception cannot proceed"); throw new org.omg.CosNaming.NamingContextPackage.CannotProceed(); } } }
public void rebind(String dns, String objectname, org.omg.CORBA.Object obj) throws org.omg.CosNaming.NamingContextPackage.NotFound, org.omg.CosNaming.NamingContextPackage.CannotProceed, org.omg.CosNaming.NamingContextPackage.InvalidName, Exception { logger.info("The CLASS Name is "+obj.getClass().getName()); String interfacename = getInterfaceName(obj); dns = appendKindNames(dns); if(interfacename != null && interfacename.length() != 0) dns = dns + "/" + interfacename + ".interface"; if(objectname != null && objectname.length() != 0) { objectname = objectname + getVersion(); dns = dns + "/" + objectname + ".object"; } logger.info("the dns to be bind is "+dns); NameComponent[] ncName; try { ncName = namingContext.to_name(dns); } catch(org.omg.CosNaming.NamingContextPackage.InvalidName ine) { logger.info("INVALID NAME EXCEPTION IS CAUGHT"); throw new org.omg.CosNaming.NamingContextPackage.InvalidName();//"The DNS name "+dns+" that is passed is InValid "); //return false; } NameComponent[] ncName1 = new NameComponent[1]; NamingContext namingContextTemp = (NamingContext)namingContext; int counter; for(counter = 0; counter < ncName.length; counter++) { //NameComponent temp[] = new NameComponent[counter]; int subcounter; try { namingContext.rebind(namingContext.to_name(dns), obj); //namingContext.reslove(namingContext.to_name(dns)); } catch(org.omg.CosNaming.NamingContextPackage.NotFound nfe) { switch(nfe.why.value()) { case NotFoundReason._missing_node: ncName1[0] = nfe.rest_of_name[0]; logger.info("The id of the context is "+ncName1[0].id) ; subcounter = 0; for(int i = 0 ; i < ncName.length && !ncName[i].id.equals(ncName1[0].id); i++) { subcounter++; } NameComponent temp[] = new NameComponent[subcounter]; for(int i = 0 ; i < ncName.length && !ncName[i].id.equals(ncName1[0].id); i++) { temp[i] = ncName[i]; } try { if(subcounter != 0){ logger.info("resolving new naming context"); namingContextTemp = NamingContextExtHelper.narrow(namingContext.resolve(temp)); } if(ncName1[0].id.equals(interfacename)) ncName1[0].kind = "interface"; else if(ncName1[0].id.equals(objectname)) ncName1[0].kind = "object"; else ncName1[0].kind = "dns"; namingContextTemp.bind_new_context(ncName1); } catch(Exception ex) { logger.info("This Exception must not occur"); ex.printStackTrace(); throw new Exception(); } break; case NotFoundReason._not_context: logger.info("Not a Context"); logger.info(nfe.rest_of_name[0].id+" IS PASSED AS A CONTEXT. ACTUALLY IT IS ALREADY BOUND AS AN OBJECT"); throw new org.omg.CosNaming.NamingContextPackage.NotFound(nfe.why, nfe.rest_of_name); //break; case NotFoundReason._not_object: logger.info("Not an Object"); logger.info(nfe.rest_of_name[0].id+" IS PASSED AS AN OBJECT. ACTUALLY IT IS ALREADY BOUND AS A CONTEXT"); throw new org.omg.CosNaming.NamingContextPackage.NotFound(nfe.why, nfe.rest_of_name); } } catch(org.omg.CosNaming.NamingContextPackage.CannotProceed cpe) { logger.info("Caught Exception cannot proceed"); throw new org.omg.CosNaming.NamingContextPackage.CannotProceed(); } } }
1,115,304
public void exchangeHTTPHandshake( SWDownloadSegment aSegment ) throws IOException, UnusableHostException, HTTPMessageException { NetworkManager networkMgr = NetworkManager.getInstance(); isDownloadSuccessful = false; segment = aSegment; long downloadOffset = segment.getTransferStartPosition(); OutputStreamWriter writer = new OutputStreamWriter( connection.getOutputStream() ); // reset to default input stream inStream = connection.getInputStream(); String requestUrl = candidate.getDownloadRequestUrl(); HTTPRequest request = new HTTPRequest( "GET", requestUrl, true ); request.addHeader( new HTTPHeader( HTTPHeaderNames.HOST, candidate.getHostAddress().getFullHostName() ) ); request.addHeader( new HTTPHeader( GnutellaHeaderNames.LISTEN_IP, networkMgr.getLocalAddress().getFullHostName() ) ); long segmentEndOffset = segment.getEnd(); if ( segmentEndOffset == -1 ) {// create header with open end request.addHeader( new HTTPHeader( HTTPHeaderNames.RANGE, "bytes=" + downloadOffset + "-" ) ); } else { request.addHeader( new HTTPHeader( HTTPHeaderNames.RANGE, "bytes=" + downloadOffset + "-" + segmentEndOffset ) ); } request.addHeader( new HTTPHeader( GnutellaHeaderNames.X_QUEUE, "0.1" ) ); // request a HTTP keep alive connection, needed for queuing to work. request.addHeader( new HTTPHeader( HTTPHeaderNames.CONNECTION, "Keep-Alive" ) ); if ( candidate.isG2FeatureAdded() ) { request.addHeader( new HTTPHeader( "X-Features", "g2/1.0" ) ); } buildAltLocRequestHeader(request); if ( ServiceManager.sCfg.isChatEnabled ) { DestAddress ha = networkMgr.getLocalAddress(); IpAddress myIp = ha.getIpAddress(); if ( myIp == null || !myIp.isSiteLocalIP() ) { request.addHeader( new HTTPHeader( "Chat", ha.getFullHostName() ) ); } } String httpRequestStr = request.buildHTTPRequestString(); NLogger.debug(NLoggerNames.Download_Engine, "HTTP Request to: " + candidate.getHostAddress() + "\n" + httpRequestStr ); candidate.addToCandidateLog( "HTTP Request:\n" + httpRequestStr ); // write request... writer.write( httpRequestStr ); writer.flush(); HTTPResponse response = HTTPProcessor.parseHTTPResponse( connection ); if ( NLogger.isDebugEnabled( NLoggerNames.Download_Engine ) ) { NLogger.debug(NLoggerNames.Download_Engine, "HTTP Response from: " + candidate.getHostAddress() + "\n" + response.buildHTTPResponseString() ); } if ( ServiceManager.sCfg.downloadCandidateLogBufferSize > 0 ) { candidate.addToCandidateLog( "HTTP Response:\n" + response.buildHTTPResponseString() ); } HTTPHeader header = response.getHeader( HTTPHeaderNames.SERVER ); if ( header != null ) { candidate.setVendor( header.getValue() ); } header = response.getHeader( HTTPHeaderNames.TRANSFER_ENCODING ); if ( header != null ) { if ( header.getValue().equals("chunked") ) { inStream = new ChunkedInputStream( connection.getInputStream() ); } } replyContentRange = null; header = response.getHeader( HTTPHeaderNames.CONTENT_RANGE ); if ( header != null ) { replyContentRange = parseContentRange( header.getValue() ); // startPos of -1 indicates '*' (free to choose) if ( replyContentRange.startPos != -1 && replyContentRange.startPos != downloadOffset ) { throw new IOException( "Invalid 'CONTENT-RANGE' start offset." ); } } replyContentLength = -1; header = response.getHeader( HTTPHeaderNames.CONTENT_LENGTH ); if ( header != null ) { try { replyContentLength = header.longValue(); } catch ( NumberFormatException exp ) { //unknown } } URN downloadFileURN = downloadFile.getFileURN(); List<HTTPHeader> contentURNHeaders = new ArrayList<HTTPHeader>(); header = response.getHeader( GnutellaHeaderNames.X_GNUTELLA_CONTENT_URN ); if ( header != null ) { contentURNHeaders.add( header ); } // Shareaza 1.8.10.4 send also a bitprint urn in multiple X-Content-URN headers! HTTPHeader[] headers = response.getHeaders( GnutellaHeaderNames.X_CONTENT_URN ); CollectionUtils.addAll( contentURNHeaders, headers ); if ( downloadFileURN != null ) { Iterator<HTTPHeader> contentURNIterator = contentURNHeaders.iterator(); while ( contentURNIterator.hasNext() ) { header = contentURNIterator.next(); String contentURNStr = header.getValue(); // check if I can understand urn. if ( URN.isValidURN( contentURNStr ) ) { URN contentURN = new URN( contentURNStr ); if ( !downloadFileURN.equals( contentURN ) ) { throw new IOException( "Required URN and content URN do not match." ); } } } } // check Limewire chat support header. header = response.getHeader( GnutellaHeaderNames.CHAT ); if ( header != null ) { candidate.setChatSupported( true ); } // read out REMOTE-IP header... to update my IP header = response.getHeader( GnutellaHeaderNames.REMOTE_IP ); if ( header != null ) { byte[] remoteIP = AddressUtils.parseIP( header.getValue() ); if ( remoteIP != null ) { IpAddress ip = new IpAddress( remoteIP ); DestAddress address = PresentationManager.getInstance().createHostAddress(ip, -1); networkMgr.updateLocalAddress( address ); } } int httpCode = response.getStatusCode(); // read available ranges header = response.getHeader( GnutellaHeaderNames.X_AVAILABLE_RANGES ); if ( header != null ) { HTTPRangeSet availableRanges = HTTPRangeSet.parseHTTPRangeSet( header.getValue(), false ); if ( availableRanges == null ) {// failed to parse... give more detailed error report NLogger.error(NLoggerNames.Download_Engine, "Failed to parse X-Available-Ranges in " + candidate.getVendor() + " request: " + response.buildHTTPResponseString() ); } candidate.setAvailableRangeSet( availableRanges ); } else if ( httpCode >= 200 && httpCode < 300 && downloadFile.getTotalDataSize() != SWDownloadConstants.UNKNOWN_FILE_SIZE) {// OK header and no available range header.. we assume candidate // shares the whole file candidate.setAvailableRangeSet( new HTTPRangeSet( 0, downloadFile.getTotalDataSize() - 1) ); } // collect alternate locations... List<AlternateLocation> altLocList = new ArrayList<AlternateLocation>(); headers = response.getHeaders( GnutellaHeaderNames.ALT_LOC ); List<AlternateLocation> altLocTmpList = AltLocContainer.parseUriResAltLocFromHeaders( headers ); altLocList.addAll( altLocTmpList ); headers = response.getHeaders( GnutellaHeaderNames.X_ALT_LOC ); altLocTmpList = AltLocContainer.parseUriResAltLocFromHeaders( headers ); altLocList.addAll( altLocTmpList ); headers = response.getHeaders( GnutellaHeaderNames.X_ALT ); altLocTmpList = AltLocContainer.parseCompactIpAltLocFromHeaders( headers, downloadFileURN ); altLocList.addAll( altLocTmpList ); // TODO1 huh?? dont we pare X-NALT???? Iterator<AlternateLocation> iterator = altLocList.iterator(); while( iterator.hasNext() ) { downloadFile.addDownloadCandidate( iterator.next() ); } // collect push proxies. // first the old headers.. headers = response.getHeaders( "X-Pushproxies" ); handlePushProxyHeaders( headers ); headers = response.getHeaders( "X-Push-Proxies" ); handlePushProxyHeaders( headers ); // now the standard header headers = response.getHeaders( GnutellaHeaderNames.X_PUSH_PROXY ); handlePushProxyHeaders( headers ); updateKeepAliveSupport( response ); if ( httpCode >= 200 && httpCode < 300 ) {// code accepted // check if we can accept the urn... if ( contentURNHeaders.size() == 0 && requestUrl.startsWith(GnutellaRequest.GNUTELLA_URI_RES_PREFIX) ) {// we requested a download via /uri-res resource urn. // we expect that the result contains a x-gnutella-content-urn // or Shareaza X-Content-URN header. throw new IOException( "Response to uri-res request without valid Content-URN header." ); } // check if we need and can update our file and segment size. if ( downloadFile.getTotalDataSize() == SWDownloadConstants.UNKNOWN_FILE_SIZE ) { // we have a file with an unknown data size. For aditional check assert // certain parameters assert( segment.getTotalDataSize() == -1 ); // Now verify if we have the great chance to update our file data! if ( replyContentRange != null && replyContentRange.totalLength != SWDownloadConstants.UNKNOWN_FILE_SIZE ) { downloadFile.setFileSize( replyContentRange.totalLength ); // we learned the file size. To allow normal segment use // interrupt the download! stopDownload(); throw new ReconnectException(); } } // connection successfully finished NLogger.debug(NLoggerNames.Download_Engine, "HTTP Handshake successfull."); return; } // check error type else if ( httpCode == 503 ) {// 503 -> host is busy (this can also be returned when remotly queued) header = response.getHeader( GnutellaHeaderNames.X_QUEUE ); XQueueParameters xQueueParameters = null; if ( header != null ) { xQueueParameters = XQueueParameters.parseHTTPRangeSet( header.getValue() ); } // check for persistent connection (gtk-gnutella uses queuing with 'Connection: close') if ( xQueueParameters != null && isKeepAliveSupported ) { throw new RemotelyQueuedException( xQueueParameters ); } else { header = response.getHeader( HTTPHeaderNames.RETRY_AFTER ); if ( header != null ) { int delta = HTTPRetryAfter.parseDeltaInSeconds( header ); if ( delta > 0 ) { throw new HostBusyException( delta ); } } throw new HostBusyException(); } } else if ( httpCode == HTTPCodes.HTTP_401_UNAUTHORIZED || httpCode == HTTPCodes.HTTP_403_FORBIDDEN ) { if ( "Network Disabled".equals( response.getStatusReason() ) ) { if ( candidate.isG2FeatureAdded() ) { // already tried G2 but no success.. better give up and dont hammer.. throw new UnusableHostException( "Request Forbidden" ); } else { // we have not tried G2 but we could.. candidate.setG2FeatureAdded( true ); throw new HostBusyException( 60 * 5 ); } } else { throw new UnusableHostException( "Request Forbidden" ); } } else if ( httpCode == 408 ) { // 408 -> Time out. Try later? throw new HostBusyException(); } else if ( httpCode == 404 || httpCode == 410 ) {// 404: File not found / 410: Host not sharing throw new FileNotAvailableException(); } else if ( httpCode == 416 ) {// 416: Requested Range Unavailable header = response.getHeader( HTTPHeaderNames.RETRY_AFTER ); if ( header != null ) { int delta = HTTPRetryAfter.parseDeltaInSeconds( header ); if ( delta > 0 ) { throw new RangeUnavailableException( delta ); } } throw new RangeUnavailableException(); } else if ( httpCode == 500 ) { throw new UnusableHostException( "Internal Server Error" ); } else { throw new IOException( "Unknown HTTP code: " + httpCode ); } }
public void exchangeHTTPHandshake( SWDownloadSegment aSegment ) throws IOException, UnusableHostException, HTTPMessageException { NetworkManager networkMgr = NetworkManager.getInstance(); isDownloadSuccessful = false; segment = aSegment; long downloadOffset = segment.getTransferStartPosition(); OutputStreamWriter writer = new OutputStreamWriter( connection.getOutputStream() ); // reset to default input stream inStream = connection.getInputStream(); String requestUrl = candidate.getDownloadRequestUrl(); HTTPRequest request = new HTTPRequest( "GET", requestUrl, true ); request.addHeader( new HTTPHeader( HTTPHeaderNames.HOST, candidate.getHostAddress().getFullHostName() ) ); request.addHeader( new HTTPHeader( GnutellaHeaderNames.LISTEN_IP, networkMgr.getLocalAddress().getFullHostName() ) ); long segmentEndOffset = segment.getEnd(); if ( segmentEndOffset == -1 ) {// create header with open end request.addHeader( new HTTPHeader( HTTPHeaderNames.RANGE, "bytes=" + downloadOffset + "-" ) ); } else { request.addHeader( new HTTPHeader( HTTPHeaderNames.RANGE, "bytes=" + downloadOffset + "-" + segmentEndOffset ) ); } request.addHeader( new HTTPHeader( GnutellaHeaderNames.X_QUEUE, "0.1" ) ); // request a HTTP keep alive connection, needed for queuing to work. request.addHeader( new HTTPHeader( HTTPHeaderNames.CONNECTION, "Keep-Alive" ) ); if ( candidate.isG2FeatureAdded() ) { request.addHeader( new HTTPHeader( "X-Features", "g2/1.0" ) ); } buildAltLocRequestHeader(request); if ( ServiceManager.sCfg.isChatEnabled ) { DestAddress ha = networkMgr.getLocalAddress(); IpAddress myIp = ha.getIpAddress(); if ( myIp == null || !myIp.isSiteLocalIP() ) { request.addHeader( new HTTPHeader( "Chat", ha.getFullHostName() ) ); } } String httpRequestStr = request.buildHTTPRequestString(); NLogger.debug(NLoggerNames.Download_Engine, "HTTP Request to: " + candidate.getHostAddress() + "\n" + httpRequestStr ); candidate.addToCandidateLog( "HTTP Request:\n" + httpRequestStr ); // write request... writer.write( httpRequestStr ); writer.flush(); HTTPResponse response = HTTPProcessor.parseHTTPResponse( connection ); if ( NLogger.isDebugEnabled( NLoggerNames.Download_Engine ) ) { NLogger.debug(NLoggerNames.Download_Engine, "HTTP Response from: " + candidate.getHostAddress() + "\n" + response.buildHTTPResponseString() ); } if ( ServiceManager.sCfg.downloadCandidateLogBufferSize > 0 ) { candidate.addToCandidateLog( "HTTP Response:\n" + response.buildHTTPResponseString() ); } HTTPHeader header = response.getHeader( HTTPHeaderNames.SERVER ); if ( header != null ) { candidate.setVendor( header.getValue() ); } header = response.getHeader( HTTPHeaderNames.TRANSFER_ENCODING ); if ( header != null ) { if ( header.getValue().equals("chunked") ) { inStream = new ChunkedInputStream( connection.getInputStream() ); } } replyContentRange = null; header = response.getHeader( HTTPHeaderNames.CONTENT_RANGE ); if ( header != null ) { replyContentRange = parseContentRange( header.getValue() ); // startPos of -1 indicates '*' (free to choose) if ( replyContentRange.startPos != -1 && replyContentRange.startPos != downloadOffset ) { throw new IOException( "Invalid 'CONTENT-RANGE' start offset." ); } } replyContentLength = -1; header = response.getHeader( HTTPHeaderNames.CONTENT_LENGTH ); if ( header != null ) { try { replyContentLength = header.longValue(); } catch ( NumberFormatException exp ) { //unknown } } URN downloadFileURN = downloadFile.getFileURN(); List<HTTPHeader> contentURNHeaders = new ArrayList<HTTPHeader>(); header = response.getHeader( GnutellaHeaderNames.X_GNUTELLA_CONTENT_URN ); if ( header != null ) { contentURNHeaders.add( header ); } // Shareaza 1.8.10.4 send also a bitprint urn in multiple X-Content-URN headers! HTTPHeader[] headers = response.getHeaders( GnutellaHeaderNames.X_CONTENT_URN ); CollectionUtils.addAll( contentURNHeaders, headers ); if ( downloadFileURN != null ) { Iterator<HTTPHeader> contentURNIterator = contentURNHeaders.iterator(); while ( contentURNIterator.hasNext() ) { header = contentURNIterator.next(); String contentURNStr = header.getValue(); // check if I can understand urn. if ( URN.isValidURN( contentURNStr ) ) { URN contentURN = new URN( contentURNStr ); if ( !downloadFileURN.equals( contentURN ) ) { throw new IOException( "Required URN and content URN do not match." ); } } } } // check Limewire chat support header. header = response.getHeader( GnutellaHeaderNames.CHAT ); if ( header != null ) { candidate.setChatSupported( true ); } // read out REMOTE-IP header... to update my IP header = response.getHeader( GnutellaHeaderNames.REMOTE_IP ); if ( header != null ) { byte[] remoteIP = AddressUtils.parseIP( header.getValue() ); if ( remoteIP != null ) { IpAddress ip = new IpAddress( remoteIP ); DestAddress address = PresentationManager.getInstance().createHostAddress(ip, -1); networkMgr.updateLocalAddress( address ); } } int httpCode = response.getStatusCode(); // read available ranges header = response.getHeader( GnutellaHeaderNames.X_AVAILABLE_RANGES ); if ( header != null ) { HTTPRangeSet availableRanges = HTTPRangeSet.parseHTTPRangeSet( header.getValue(), false ); if ( availableRanges == null ) {// failed to parse... give more detailed error report NLogger.error(NLoggerNames.Download_Engine, "Failed to parse X-Available-Ranges in " + candidate.getVendor() + " request: " + response.buildHTTPResponseString() ); } try { candidate.setAvailableRangeSet( availableRanges ); } catch ( IllegalArgumentException exp ) { NLogger.error(NLoggerNames.Download_Engine, "Failed to parse X-Available-Ranges in " + candidate.getVendor() + " request: " + response.buildHTTPResponseString(), exp ); } } else if ( httpCode >= 200 && httpCode < 300 && downloadFile.getTotalDataSize() != SWDownloadConstants.UNKNOWN_FILE_SIZE) {// OK header and no available range header.. we assume candidate // shares the whole file candidate.setAvailableRangeSet( new HTTPRangeSet( 0, downloadFile.getTotalDataSize() - 1) ); } // collect alternate locations... List<AlternateLocation> altLocList = new ArrayList<AlternateLocation>(); headers = response.getHeaders( GnutellaHeaderNames.ALT_LOC ); List<AlternateLocation> altLocTmpList = AltLocContainer.parseUriResAltLocFromHeaders( headers ); altLocList.addAll( altLocTmpList ); headers = response.getHeaders( GnutellaHeaderNames.X_ALT_LOC ); altLocTmpList = AltLocContainer.parseUriResAltLocFromHeaders( headers ); altLocList.addAll( altLocTmpList ); headers = response.getHeaders( GnutellaHeaderNames.X_ALT ); altLocTmpList = AltLocContainer.parseCompactIpAltLocFromHeaders( headers, downloadFileURN ); altLocList.addAll( altLocTmpList ); // TODO1 huh?? dont we pare X-NALT???? Iterator<AlternateLocation> iterator = altLocList.iterator(); while( iterator.hasNext() ) { downloadFile.addDownloadCandidate( iterator.next() ); } // collect push proxies. // first the old headers.. headers = response.getHeaders( "X-Pushproxies" ); handlePushProxyHeaders( headers ); headers = response.getHeaders( "X-Push-Proxies" ); handlePushProxyHeaders( headers ); // now the standard header headers = response.getHeaders( GnutellaHeaderNames.X_PUSH_PROXY ); handlePushProxyHeaders( headers ); updateKeepAliveSupport( response ); if ( httpCode >= 200 && httpCode < 300 ) {// code accepted // check if we can accept the urn... if ( contentURNHeaders.size() == 0 && requestUrl.startsWith(GnutellaRequest.GNUTELLA_URI_RES_PREFIX) ) {// we requested a download via /uri-res resource urn. // we expect that the result contains a x-gnutella-content-urn // or Shareaza X-Content-URN header. throw new IOException( "Response to uri-res request without valid Content-URN header." ); } // check if we need and can update our file and segment size. if ( downloadFile.getTotalDataSize() == SWDownloadConstants.UNKNOWN_FILE_SIZE ) { // we have a file with an unknown data size. For aditional check assert // certain parameters assert( segment.getTotalDataSize() == -1 ); // Now verify if we have the great chance to update our file data! if ( replyContentRange != null && replyContentRange.totalLength != SWDownloadConstants.UNKNOWN_FILE_SIZE ) { downloadFile.setFileSize( replyContentRange.totalLength ); // we learned the file size. To allow normal segment use // interrupt the download! stopDownload(); throw new ReconnectException(); } } // connection successfully finished NLogger.debug(NLoggerNames.Download_Engine, "HTTP Handshake successfull."); return; } // check error type else if ( httpCode == 503 ) {// 503 -> host is busy (this can also be returned when remotly queued) header = response.getHeader( GnutellaHeaderNames.X_QUEUE ); XQueueParameters xQueueParameters = null; if ( header != null ) { xQueueParameters = XQueueParameters.parseHTTPRangeSet( header.getValue() ); } // check for persistent connection (gtk-gnutella uses queuing with 'Connection: close') if ( xQueueParameters != null && isKeepAliveSupported ) { throw new RemotelyQueuedException( xQueueParameters ); } else { header = response.getHeader( HTTPHeaderNames.RETRY_AFTER ); if ( header != null ) { int delta = HTTPRetryAfter.parseDeltaInSeconds( header ); if ( delta > 0 ) { throw new HostBusyException( delta ); } } throw new HostBusyException(); } } else if ( httpCode == HTTPCodes.HTTP_401_UNAUTHORIZED || httpCode == HTTPCodes.HTTP_403_FORBIDDEN ) { if ( "Network Disabled".equals( response.getStatusReason() ) ) { if ( candidate.isG2FeatureAdded() ) { // already tried G2 but no success.. better give up and dont hammer.. throw new UnusableHostException( "Request Forbidden" ); } else { // we have not tried G2 but we could.. candidate.setG2FeatureAdded( true ); throw new HostBusyException( 60 * 5 ); } } else { throw new UnusableHostException( "Request Forbidden" ); } } else if ( httpCode == 408 ) { // 408 -> Time out. Try later? throw new HostBusyException(); } else if ( httpCode == 404 || httpCode == 410 ) {// 404: File not found / 410: Host not sharing throw new FileNotAvailableException(); } else if ( httpCode == 416 ) {// 416: Requested Range Unavailable header = response.getHeader( HTTPHeaderNames.RETRY_AFTER ); if ( header != null ) { int delta = HTTPRetryAfter.parseDeltaInSeconds( header ); if ( delta > 0 ) { throw new RangeUnavailableException( delta ); } } throw new RangeUnavailableException(); } else if ( httpCode == 500 ) { throw new UnusableHostException( "Internal Server Error" ); } else { throw new IOException( "Unknown HTTP code: " + httpCode ); } }
1,115,305
public void exchangeHTTPHandshake( SWDownloadSegment aSegment ) throws IOException, UnusableHostException, HTTPMessageException { NetworkManager networkMgr = NetworkManager.getInstance(); isDownloadSuccessful = false; segment = aSegment; long downloadOffset = segment.getTransferStartPosition(); OutputStreamWriter writer = new OutputStreamWriter( connection.getOutputStream() ); // reset to default input stream inStream = connection.getInputStream(); String requestUrl = candidate.getDownloadRequestUrl(); HTTPRequest request = new HTTPRequest( "GET", requestUrl, true ); request.addHeader( new HTTPHeader( HTTPHeaderNames.HOST, candidate.getHostAddress().getFullHostName() ) ); request.addHeader( new HTTPHeader( GnutellaHeaderNames.LISTEN_IP, networkMgr.getLocalAddress().getFullHostName() ) ); long segmentEndOffset = segment.getEnd(); if ( segmentEndOffset == -1 ) {// create header with open end request.addHeader( new HTTPHeader( HTTPHeaderNames.RANGE, "bytes=" + downloadOffset + "-" ) ); } else { request.addHeader( new HTTPHeader( HTTPHeaderNames.RANGE, "bytes=" + downloadOffset + "-" + segmentEndOffset ) ); } request.addHeader( new HTTPHeader( GnutellaHeaderNames.X_QUEUE, "0.1" ) ); // request a HTTP keep alive connection, needed for queuing to work. request.addHeader( new HTTPHeader( HTTPHeaderNames.CONNECTION, "Keep-Alive" ) ); if ( candidate.isG2FeatureAdded() ) { request.addHeader( new HTTPHeader( "X-Features", "g2/1.0" ) ); } buildAltLocRequestHeader(request); if ( ServiceManager.sCfg.isChatEnabled ) { DestAddress ha = networkMgr.getLocalAddress(); IpAddress myIp = ha.getIpAddress(); if ( myIp == null || !myIp.isSiteLocalIP() ) { request.addHeader( new HTTPHeader( "Chat", ha.getFullHostName() ) ); } } String httpRequestStr = request.buildHTTPRequestString(); NLogger.debug(NLoggerNames.Download_Engine, "HTTP Request to: " + candidate.getHostAddress() + "\n" + httpRequestStr ); candidate.addToCandidateLog( "HTTP Request:\n" + httpRequestStr ); // write request... writer.write( httpRequestStr ); writer.flush(); HTTPResponse response = HTTPProcessor.parseHTTPResponse( connection ); if ( NLogger.isDebugEnabled( NLoggerNames.Download_Engine ) ) { NLogger.debug(NLoggerNames.Download_Engine, "HTTP Response from: " + candidate.getHostAddress() + "\n" + response.buildHTTPResponseString() ); } if ( ServiceManager.sCfg.downloadCandidateLogBufferSize > 0 ) { candidate.addToCandidateLog( "HTTP Response:\n" + response.buildHTTPResponseString() ); } HTTPHeader header = response.getHeader( HTTPHeaderNames.SERVER ); if ( header != null ) { candidate.setVendor( header.getValue() ); } header = response.getHeader( HTTPHeaderNames.TRANSFER_ENCODING ); if ( header != null ) { if ( header.getValue().equals("chunked") ) { inStream = new ChunkedInputStream( connection.getInputStream() ); } } replyContentRange = null; header = response.getHeader( HTTPHeaderNames.CONTENT_RANGE ); if ( header != null ) { replyContentRange = parseContentRange( header.getValue() ); // startPos of -1 indicates '*' (free to choose) if ( replyContentRange.startPos != -1 && replyContentRange.startPos != downloadOffset ) { throw new IOException( "Invalid 'CONTENT-RANGE' start offset." ); } } replyContentLength = -1; header = response.getHeader( HTTPHeaderNames.CONTENT_LENGTH ); if ( header != null ) { try { replyContentLength = header.longValue(); } catch ( NumberFormatException exp ) { //unknown } } URN downloadFileURN = downloadFile.getFileURN(); List<HTTPHeader> contentURNHeaders = new ArrayList<HTTPHeader>(); header = response.getHeader( GnutellaHeaderNames.X_GNUTELLA_CONTENT_URN ); if ( header != null ) { contentURNHeaders.add( header ); } // Shareaza 1.8.10.4 send also a bitprint urn in multiple X-Content-URN headers! HTTPHeader[] headers = response.getHeaders( GnutellaHeaderNames.X_CONTENT_URN ); CollectionUtils.addAll( contentURNHeaders, headers ); if ( downloadFileURN != null ) { Iterator<HTTPHeader> contentURNIterator = contentURNHeaders.iterator(); while ( contentURNIterator.hasNext() ) { header = contentURNIterator.next(); String contentURNStr = header.getValue(); // check if I can understand urn. if ( URN.isValidURN( contentURNStr ) ) { URN contentURN = new URN( contentURNStr ); if ( !downloadFileURN.equals( contentURN ) ) { throw new IOException( "Required URN and content URN do not match." ); } } } } // check Limewire chat support header. header = response.getHeader( GnutellaHeaderNames.CHAT ); if ( header != null ) { candidate.setChatSupported( true ); } // read out REMOTE-IP header... to update my IP header = response.getHeader( GnutellaHeaderNames.REMOTE_IP ); if ( header != null ) { byte[] remoteIP = AddressUtils.parseIP( header.getValue() ); if ( remoteIP != null ) { IpAddress ip = new IpAddress( remoteIP ); DestAddress address = PresentationManager.getInstance().createHostAddress(ip, -1); networkMgr.updateLocalAddress( address ); } } int httpCode = response.getStatusCode(); // read available ranges header = response.getHeader( GnutellaHeaderNames.X_AVAILABLE_RANGES ); if ( header != null ) { HTTPRangeSet availableRanges = HTTPRangeSet.parseHTTPRangeSet( header.getValue(), false ); if ( availableRanges == null ) {// failed to parse... give more detailed error report NLogger.error(NLoggerNames.Download_Engine, "Failed to parse X-Available-Ranges in " + candidate.getVendor() + " request: " + response.buildHTTPResponseString() ); } candidate.setAvailableRangeSet( availableRanges ); } else if ( httpCode >= 200 && httpCode < 300 && downloadFile.getTotalDataSize() != SWDownloadConstants.UNKNOWN_FILE_SIZE) {// OK header and no available range header.. we assume candidate // shares the whole file candidate.setAvailableRangeSet( new HTTPRangeSet( 0, downloadFile.getTotalDataSize() - 1) ); } // collect alternate locations... List<AlternateLocation> altLocList = new ArrayList<AlternateLocation>(); headers = response.getHeaders( GnutellaHeaderNames.ALT_LOC ); List<AlternateLocation> altLocTmpList = AltLocContainer.parseUriResAltLocFromHeaders( headers ); altLocList.addAll( altLocTmpList ); headers = response.getHeaders( GnutellaHeaderNames.X_ALT_LOC ); altLocTmpList = AltLocContainer.parseUriResAltLocFromHeaders( headers ); altLocList.addAll( altLocTmpList ); headers = response.getHeaders( GnutellaHeaderNames.X_ALT ); altLocTmpList = AltLocContainer.parseCompactIpAltLocFromHeaders( headers, downloadFileURN ); altLocList.addAll( altLocTmpList ); // TODO1 huh?? dont we pare X-NALT???? Iterator<AlternateLocation> iterator = altLocList.iterator(); while( iterator.hasNext() ) { downloadFile.addDownloadCandidate( iterator.next() ); } // collect push proxies. // first the old headers.. headers = response.getHeaders( "X-Pushproxies" ); handlePushProxyHeaders( headers ); headers = response.getHeaders( "X-Push-Proxies" ); handlePushProxyHeaders( headers ); // now the standard header headers = response.getHeaders( GnutellaHeaderNames.X_PUSH_PROXY ); handlePushProxyHeaders( headers ); updateKeepAliveSupport( response ); if ( httpCode >= 200 && httpCode < 300 ) {// code accepted // check if we can accept the urn... if ( contentURNHeaders.size() == 0 && requestUrl.startsWith(GnutellaRequest.GNUTELLA_URI_RES_PREFIX) ) {// we requested a download via /uri-res resource urn. // we expect that the result contains a x-gnutella-content-urn // or Shareaza X-Content-URN header. throw new IOException( "Response to uri-res request without valid Content-URN header." ); } // check if we need and can update our file and segment size. if ( downloadFile.getTotalDataSize() == SWDownloadConstants.UNKNOWN_FILE_SIZE ) { // we have a file with an unknown data size. For aditional check assert // certain parameters assert( segment.getTotalDataSize() == -1 ); // Now verify if we have the great chance to update our file data! if ( replyContentRange != null && replyContentRange.totalLength != SWDownloadConstants.UNKNOWN_FILE_SIZE ) { downloadFile.setFileSize( replyContentRange.totalLength ); // we learned the file size. To allow normal segment use // interrupt the download! stopDownload(); throw new ReconnectException(); } } // connection successfully finished NLogger.debug(NLoggerNames.Download_Engine, "HTTP Handshake successfull."); return; } // check error type else if ( httpCode == 503 ) {// 503 -> host is busy (this can also be returned when remotly queued) header = response.getHeader( GnutellaHeaderNames.X_QUEUE ); XQueueParameters xQueueParameters = null; if ( header != null ) { xQueueParameters = XQueueParameters.parseHTTPRangeSet( header.getValue() ); } // check for persistent connection (gtk-gnutella uses queuing with 'Connection: close') if ( xQueueParameters != null && isKeepAliveSupported ) { throw new RemotelyQueuedException( xQueueParameters ); } else { header = response.getHeader( HTTPHeaderNames.RETRY_AFTER ); if ( header != null ) { int delta = HTTPRetryAfter.parseDeltaInSeconds( header ); if ( delta > 0 ) { throw new HostBusyException( delta ); } } throw new HostBusyException(); } } else if ( httpCode == HTTPCodes.HTTP_401_UNAUTHORIZED || httpCode == HTTPCodes.HTTP_403_FORBIDDEN ) { if ( "Network Disabled".equals( response.getStatusReason() ) ) { if ( candidate.isG2FeatureAdded() ) { // already tried G2 but no success.. better give up and dont hammer.. throw new UnusableHostException( "Request Forbidden" ); } else { // we have not tried G2 but we could.. candidate.setG2FeatureAdded( true ); throw new HostBusyException( 60 * 5 ); } } else { throw new UnusableHostException( "Request Forbidden" ); } } else if ( httpCode == 408 ) { // 408 -> Time out. Try later? throw new HostBusyException(); } else if ( httpCode == 404 || httpCode == 410 ) {// 404: File not found / 410: Host not sharing throw new FileNotAvailableException(); } else if ( httpCode == 416 ) {// 416: Requested Range Unavailable header = response.getHeader( HTTPHeaderNames.RETRY_AFTER ); if ( header != null ) { int delta = HTTPRetryAfter.parseDeltaInSeconds( header ); if ( delta > 0 ) { throw new RangeUnavailableException( delta ); } } throw new RangeUnavailableException(); } else if ( httpCode == 500 ) { throw new UnusableHostException( "Internal Server Error" ); } else { throw new IOException( "Unknown HTTP code: " + httpCode ); } }
public void exchangeHTTPHandshake( SWDownloadSegment aSegment ) throws IOException, UnusableHostException, HTTPMessageException { NetworkManager networkMgr = NetworkManager.getInstance(); isDownloadSuccessful = false; segment = aSegment; long downloadOffset = segment.getTransferStartPosition(); OutputStreamWriter writer = new OutputStreamWriter( connection.getOutputStream() ); // reset to default input stream inStream = connection.getInputStream(); String requestUrl = candidate.getDownloadRequestUrl(); HTTPRequest request = new HTTPRequest( "GET", requestUrl, true ); request.addHeader( new HTTPHeader( HTTPHeaderNames.HOST, candidate.getHostAddress().getFullHostName() ) ); request.addHeader( new HTTPHeader( GnutellaHeaderNames.LISTEN_IP, networkMgr.getLocalAddress().getFullHostName() ) ); long segmentEndOffset = segment.getEnd(); if ( segmentEndOffset == -1 ) {// create header with open end request.addHeader( new HTTPHeader( HTTPHeaderNames.RANGE, "bytes=" + downloadOffset + "-" ) ); } else { request.addHeader( new HTTPHeader( HTTPHeaderNames.RANGE, "bytes=" + downloadOffset + "-" + segmentEndOffset ) ); } request.addHeader( new HTTPHeader( GnutellaHeaderNames.X_QUEUE, "0.1" ) ); // request a HTTP keep alive connection, needed for queuing to work. request.addHeader( new HTTPHeader( HTTPHeaderNames.CONNECTION, "Keep-Alive" ) ); if ( candidate.isG2FeatureAdded() ) { request.addHeader( new HTTPHeader( "X-Features", "g2/1.0" ) ); } buildAltLocRequestHeader(request); if ( ServiceManager.sCfg.isChatEnabled ) { DestAddress ha = networkMgr.getLocalAddress(); IpAddress myIp = ha.getIpAddress(); if ( myIp == null || !myIp.isSiteLocalIP() ) { request.addHeader( new HTTPHeader( "Chat", ha.getFullHostName() ) ); } } String httpRequestStr = request.buildHTTPRequestString(); NLogger.debug(NLoggerNames.Download_Engine, "HTTP Request to: " + candidate.getHostAddress() + "\n" + httpRequestStr ); candidate.addToCandidateLog( "HTTP Request:\n" + httpRequestStr ); // write request... writer.write( httpRequestStr ); writer.flush(); HTTPResponse response = HTTPProcessor.parseHTTPResponse( connection ); if ( NLogger.isDebugEnabled( NLoggerNames.Download_Engine ) ) { NLogger.debug(NLoggerNames.Download_Engine, "HTTP Response from: " + candidate.getHostAddress() + "\n" + response.buildHTTPResponseString() ); } if ( ServiceManager.sCfg.downloadCandidateLogBufferSize > 0 ) { candidate.addToCandidateLog( "HTTP Response:\n" + response.buildHTTPResponseString() ); } HTTPHeader header = response.getHeader( HTTPHeaderNames.SERVER ); if ( header != null ) { candidate.setVendor( header.getValue() ); } header = response.getHeader( HTTPHeaderNames.TRANSFER_ENCODING ); if ( header != null ) { if ( header.getValue().equals("chunked") ) { inStream = new ChunkedInputStream( connection.getInputStream() ); } } replyContentRange = null; header = response.getHeader( HTTPHeaderNames.CONTENT_RANGE ); if ( header != null ) { replyContentRange = parseContentRange( header.getValue() ); // startPos of -1 indicates '*' (free to choose) if ( replyContentRange.startPos != -1 && replyContentRange.startPos != downloadOffset ) { throw new IOException( "Invalid 'CONTENT-RANGE' start offset." ); } } replyContentLength = -1; header = response.getHeader( HTTPHeaderNames.CONTENT_LENGTH ); if ( header != null ) { try { replyContentLength = header.longValue(); } catch ( NumberFormatException exp ) { //unknown } } URN downloadFileURN = downloadFile.getFileURN(); List<HTTPHeader> contentURNHeaders = new ArrayList<HTTPHeader>(); header = response.getHeader( GnutellaHeaderNames.X_GNUTELLA_CONTENT_URN ); if ( header != null ) { contentURNHeaders.add( header ); } // Shareaza 1.8.10.4 send also a bitprint urn in multiple X-Content-URN headers! HTTPHeader[] headers = response.getHeaders( GnutellaHeaderNames.X_CONTENT_URN ); CollectionUtils.addAll( contentURNHeaders, headers ); if ( downloadFileURN != null ) { Iterator<HTTPHeader> contentURNIterator = contentURNHeaders.iterator(); while ( contentURNIterator.hasNext() ) { header = contentURNIterator.next(); String contentURNStr = header.getValue(); // check if I can understand urn. if ( URN.isValidURN( contentURNStr ) ) { URN contentURN = new URN( contentURNStr ); if ( !downloadFileURN.equals( contentURN ) ) { throw new IOException( "Required URN and content URN do not match." ); } } } } // check Limewire chat support header. header = response.getHeader( GnutellaHeaderNames.CHAT ); if ( header != null ) { candidate.setChatSupported( true ); } // read out REMOTE-IP header... to update my IP header = response.getHeader( GnutellaHeaderNames.REMOTE_IP ); if ( header != null ) { byte[] remoteIP = AddressUtils.parseIP( header.getValue() ); if ( remoteIP != null ) { IpAddress ip = new IpAddress( remoteIP ); DestAddress address = PresentationManager.getInstance().createHostAddress(ip, -1); networkMgr.updateLocalAddress( address ); } } int httpCode = response.getStatusCode(); // read available ranges header = response.getHeader( GnutellaHeaderNames.X_AVAILABLE_RANGES ); if ( header != null ) { HTTPRangeSet availableRanges = HTTPRangeSet.parseHTTPRangeSet( header.getValue(), false ); if ( availableRanges == null ) {// failed to parse... give more detailed error report NLogger.error(NLoggerNames.Download_Engine, "Failed to parse X-Available-Ranges in " + candidate.getVendor() + " request: " + response.buildHTTPResponseString() ); } candidate.setAvailableRangeSet( availableRanges ); } else if ( httpCode >= 200 && httpCode < 300 && downloadFile.getTotalDataSize() != SWDownloadConstants.UNKNOWN_FILE_SIZE) {// OK header and no available range header.. we assume candidate // shares the whole file candidate.setAvailableRangeSet( new HTTPRangeSet( 0, downloadFile.getTotalDataSize() - 1) ); } // collect alternate locations... List<AlternateLocation> altLocList = new ArrayList<AlternateLocation>(); headers = response.getHeaders( GnutellaHeaderNames.ALT_LOC ); List<AlternateLocation> altLocTmpList = AltLocContainer.parseUriResAltLocFromHeaders( headers ); altLocList.addAll( altLocTmpList ); headers = response.getHeaders( GnutellaHeaderNames.X_ALT_LOC ); altLocTmpList = AltLocContainer.parseUriResAltLocFromHeaders( headers ); altLocList.addAll( altLocTmpList ); headers = response.getHeaders( GnutellaHeaderNames.X_ALT ); altLocTmpList = AltLocContainer.parseCompactIpAltLocFromHeaders( headers, downloadFileURN ); altLocList.addAll( altLocTmpList ); // TODO1 huh?? dont we pare X-NALT???? Iterator<AlternateLocation> iterator = altLocList.iterator(); while( iterator.hasNext() ) { downloadFile.addDownloadCandidate( iterator.next() ); } // collect push proxies. // first the old headers.. headers = response.getHeaders( "X-Pushproxies" ); handlePushProxyHeaders( headers ); headers = response.getHeaders( "X-Push-Proxies" ); handlePushProxyHeaders( headers ); // now the standard header headers = response.getHeaders( GnutellaHeaderNames.X_PUSH_PROXY ); handlePushProxyHeaders( headers ); updateKeepAliveSupport( response ); if ( httpCode >= 200 && httpCode < 300 ) {// code accepted // check if we can accept the urn... if ( contentURNHeaders.size() == 0 && requestUrl.startsWith(GnutellaRequest.GNUTELLA_URI_RES_PREFIX) ) {// we requested a download via /uri-res resource urn. // we expect that the result contains a x-gnutella-content-urn // or Shareaza X-Content-URN header. throw new IOException( "Response to uri-res request without valid Content-URN header." ); } // check if we need and can update our file and segment size. if ( downloadFile.getTotalDataSize() == SWDownloadConstants.UNKNOWN_FILE_SIZE ) { // we have a file with an unknown data size. For aditional check assert // certain parameters assert( segment.getTotalDataSize() == -1 ); // Now verify if we have the great chance to update our file data! if ( replyContentRange != null && replyContentRange.totalLength != SWDownloadConstants.UNKNOWN_FILE_SIZE ) { downloadFile.setFileSize( replyContentRange.totalLength ); // we learned the file size. To allow normal segment use // interrupt the download! stopDownload(); throw new ReconnectException(); } } // connection successfully finished NLogger.debug(NLoggerNames.Download_Engine, "HTTP Handshake successfull."); return; } // check error type else if ( httpCode == 503 ) {// 503 -> host is busy (this can also be returned when remotly queued) header = response.getHeader( GnutellaHeaderNames.X_QUEUE ); XQueueParameters xQueueParameters = null; if ( header != null ) { xQueueParameters = XQueueParameters.parseHTTPRangeSet( header.getValue() ); } // check for persistent connection (gtk-gnutella uses queuing with 'Connection: close') if ( xQueueParameters != null && isKeepAliveSupported ) { throw new RemotelyQueuedException( xQueueParameters ); } else { header = response.getHeader( HTTPHeaderNames.RETRY_AFTER ); if ( header != null ) { int delta = HTTPRetryAfter.parseDeltaInSeconds( header ); if ( delta > 0 ) { throw new HostBusyException( delta ); } } throw new HostBusyException(); } } else if ( httpCode == HTTPCodes.HTTP_401_UNAUTHORIZED || httpCode == HTTPCodes.HTTP_403_FORBIDDEN ) { if ( "Network Disabled".equals( response.getStatusReason() ) ) { if ( candidate.isG2FeatureAdded() ) { // already tried G2 but no success.. better give up and dont hammer.. throw new UnusableHostException( "Request Forbidden" ); } else { // we have not tried G2 but we could.. candidate.setG2FeatureAdded( true ); throw new HostBusyException( 60 * 5 ); } } else { throw new UnusableHostException( "Request Forbidden" ); } } else if ( httpCode == 408 ) { // 408 -> Time out. Try later? throw new HostBusyException(); } else if ( httpCode == 404 || httpCode == 410 ) {// 404: File not found / 410: Host not sharing throw new FileNotAvailableException(); } else if ( httpCode == 416 ) {// 416: Requested Range Unavailable header = response.getHeader( HTTPHeaderNames.RETRY_AFTER ); if ( header != null ) { int delta = HTTPRetryAfter.parseDeltaInSeconds( header ); if ( delta > 0 ) { throw new RangeUnavailableException( delta ); } } throw new RangeUnavailableException(); } else if ( httpCode == 500 ) { throw new UnusableHostException( "Internal Server Error" ); } else { throw new IOException( "Unknown HTTP code: " + httpCode ); } }
1,115,306
public void setValidValue(boolean val) { validValue = val; }
public void setValidValue(boolean val) { if(isConstant()) return; validValue = val; }
1,115,307
public Variable createVariable(String name, Object value) { return new Variable(name,value); }
public Variable createVariable(String name, Object value) { Variable var = new Variable(name,value); return var; }
1,115,308
public synchronized void save() throws IOException { Writer w = new OutputStreamWriter(new FileOutputStream(new File(getRootDir(),"build.xml")),"UTF-8"); w.write("<?xml version='1.0' encoding='UTF-8'?>\n"); createConfiguredStream().toXML(this,w); w.close(); }
public synchronized void save() throws IOException { Writer w = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(getRootDir(),"build.xml")),"UTF-8")); w.write("<?xml version='1.0' encoding='UTF-8'?>\n"); createConfiguredStream().toXML(this,w); w.close(); }
1,115,309
public void execute() throws BuildException { File savedDir = m_dir; // may be altered in validate try { validate(); final Properties userList = new Properties(); loadUserlist(userList); for (Enumeration e = m_cvsUsers.elements(); e.hasMoreElements();) { final CvsUser user = (CvsUser) e.nextElement(); user.validate(); userList.put(user.getUserID(), user.getDisplayname()); } setCommand("log"); if (getTag() != null) { CvsVersion myCvsVersion = new CvsVersion(); myCvsVersion.setProject(getProject()); myCvsVersion.setTaskName("cvsversion"); myCvsVersion.setCvsRoot(getCvsRoot()); myCvsVersion.setCvsRsh(getCvsRsh()); myCvsVersion.setPassfile(getPassFile()); myCvsVersion.setDest(m_dir); myCvsVersion.execute(); if (myCvsVersion.supportsCvsLogWithSOption()) { addCommandArgument("-S"); } } if (null != m_start) { final SimpleDateFormat outputDate = new SimpleDateFormat("yyyy-MM-dd"); // We want something of the form: -d ">=YYYY-MM-dd" final String dateRange = ">=" + outputDate.format(m_start); // Supply '-d' as a separate argument - Bug# 14397 addCommandArgument("-d"); addCommandArgument(dateRange); } // Check if list of files to check has been specified if (!m_filesets.isEmpty()) { for (String file : m_filesets) { addCommandArgument(file); } } final ChangeLogParser parser = new ChangeLogParser(this); final RedirectingStreamHandler handler = new RedirectingStreamHandler(parser); log(getCommand(), Project.MSG_VERBOSE); setDest(m_dir); setExecuteStreamHandler(handler); try { super.execute(); } finally { final String errors = handler.getErrors(); if (null != errors && errors.length()!=0) { log(errors, Project.MSG_ERR); } } final CVSEntry[] entrySet = parser.getEntrySetAsArray(); final CVSEntry[] filteredEntrySet = filterEntrySet(entrySet); replaceAuthorIdWithName(userList, filteredEntrySet); writeChangeLog(filteredEntrySet); } finally { m_dir = savedDir; } }
public void execute() throws BuildException { File savedDir = m_dir; // may be altered in validate try { validate(); final Properties userList = new Properties(); loadUserlist(userList); for (Enumeration e = m_cvsUsers.elements(); e.hasMoreElements();) { final CvsUser user = (CvsUser) e.nextElement(); user.validate(); userList.put(user.getUserID(), user.getDisplayname()); } setCommand("log"); if (getTag() != null) { CvsVersion myCvsVersion = new CvsVersion(); myCvsVersion.setProject(getProject()); myCvsVersion.setTaskName("cvsversion"); myCvsVersion.setCvsRoot(getCvsRoot()); myCvsVersion.setCvsRsh(getCvsRsh()); myCvsVersion.setPassfile(getPassFile()); myCvsVersion.setDest(m_dir); myCvsVersion.execute(); if (myCvsVersion.supportsCvsLogWithSOption()) { addCommandArgument("-S"); } } if (null != m_start) { final SimpleDateFormat outputDate = new SimpleDateFormat("yyyy-MM-dd"); // We want something of the form: -d ">=YYYY-MM-dd" final String dateRange = ">=" + outputDate.format(safeStart); // Supply '-d' as a separate argument - Bug# 14397 addCommandArgument("-d"); addCommandArgument(dateRange); } // Check if list of files to check has been specified if (!m_filesets.isEmpty()) { for (String file : m_filesets) { addCommandArgument(file); } } final ChangeLogParser parser = new ChangeLogParser(this); final RedirectingStreamHandler handler = new RedirectingStreamHandler(parser); log(getCommand(), Project.MSG_VERBOSE); setDest(m_dir); setExecuteStreamHandler(handler); try { super.execute(); } finally { final String errors = handler.getErrors(); if (null != errors && errors.length()!=0) { log(errors, Project.MSG_ERR); } } final CVSEntry[] entrySet = parser.getEntrySetAsArray(); final CVSEntry[] filteredEntrySet = filterEntrySet(entrySet); replaceAuthorIdWithName(userList, filteredEntrySet); writeChangeLog(filteredEntrySet); } finally { m_dir = savedDir; } }
1,115,310
public boolean isBuildable() { return true; }
public boolean isBuildable() { return !isDisabled(); }
1,115,312
public void scheduleBuild() { getParent().getQueue().add(this); }
public void scheduleBuild() { if(!disabled) getParent().getQueue().add(this); }
1,115,313
public void mkdirs() throws IOException { if(!local.mkdirs()) throw new IOException("Failed to mkdirs: "+local); }
public void mkdirs() throws IOException { if(!local.mkdirs() && !local.exists()) throw new IOException("Failed to mkdirs: "+local); }
1,115,314
public ByteCopier(InputStream in, OutputStream out) { this.in = in; this.out = out; }
public ByteCopier(String threadName, InputStream in, OutputStream out) { super(threadName); this.in = in; this.out = out; }
1,115,316
public Copier(InputStream in, OutputStream out) { this.in = in; this.out = out; }
public Copier(String threadName, InputStream in, OutputStream out) { super(threadName); this.in = in; this.out = out; }
1,115,317
boolean check(Calendar cal) { if(!checkBits(bits[0],cal.get(Calendar.MINUTE))) return false; if(!checkBits(bits[1],cal.get(Calendar.HOUR))) return false; if(!checkBits(bits[2],cal.get(Calendar.DAY_OF_MONTH))) return false; if(!checkBits(bits[3],cal.get(Calendar.MONTH)+1)) return false; if(!checkBits(dayOfWeek,cal.get(Calendar.DAY_OF_WEEK)-1)) return false; return true; }
boolean check(Calendar cal) { if(!checkBits(bits[0],cal.get(Calendar.MINUTE))) return false; if(!checkBits(bits[1],cal.get(Calendar.HOUR_OF_DAY))) return false; if(!checkBits(bits[2],cal.get(Calendar.DAY_OF_MONTH))) return false; if(!checkBits(bits[3],cal.get(Calendar.MONTH)+1)) return false; if(!checkBits(dayOfWeek,cal.get(Calendar.DAY_OF_WEEK)-1)) return false; return true; }
1,115,318
public void addStyle(String name, Color foreground, Color background, boolean bold) { if (m_textPane == null) return; StyledDocument doc = m_textPane.getStyledDocument(); StyleContext context = StyleContext.getDefaultStyleContext(); Style def = context.getStyle(StyleContext.DEFAULT_STYLE); Style style = doc.addStyle(name, def); if (foreground != null) StyleConstants.setForeground(style, foreground); if (background != null) StyleConstants.setForeground(style, background); StyleConstants.setBold(style, bold); if (m_noLineSpacing) StyleConstants.setLineSpacing(style, 0f); }
public void addStyle(String name, Color foreground, Color background, boolean bold) { if (m_textPane == null) return; StyledDocument doc = m_textPane.getStyledDocument(); StyleContext context = StyleContext.getDefaultStyleContext(); Style def = context.getStyle(StyleContext.DEFAULT_STYLE); Style style = doc.addStyle(name, def); if (foreground != null) StyleConstants.setForeground(style, foreground); if (background != null) StyleConstants.setForeground(style, background); StyleConstants.setBold(style, bold); if (m_noLineSpacing) StyleConstants.setLineSpacing(style, 0f); }
1,115,319
public void addStyle(String name, Color foreground, Color background, boolean bold) { if (m_textPane == null) return; StyledDocument doc = m_textPane.getStyledDocument(); StyleContext context = StyleContext.getDefaultStyleContext(); Style def = context.getStyle(StyleContext.DEFAULT_STYLE); Style style = doc.addStyle(name, def); if (foreground != null) StyleConstants.setForeground(style, foreground); if (background != null) StyleConstants.setForeground(style, background); StyleConstants.setBold(style, bold); if (m_noLineSpacing) StyleConstants.setLineSpacing(style, 0f); }
public void addStyle(String name, Color foreground, Color background, boolean bold) { if (m_textPane == null) return; StyledDocument doc = m_textPane.getStyledDocument(); StyleContext context = StyleContext.getDefaultStyleContext(); Style def = context.getStyle(StyleContext.DEFAULT_STYLE); Style style = doc.addStyle(name, def); if (foreground != null) StyleConstants.setForeground(style, foreground); if (background != null) StyleConstants.setForeground(style, background); StyleConstants.setBold(style, bold); if (m_noLineSpacing) StyleConstants.setLineSpacing(style, 0f); }
1,115,320
public Object visit(ASTVarNode node, Object data) throws ParseException { Variable var = node.getVar(); if(var instanceof PartialDerivative) { PartialDerivative deriv = (PartialDerivative) var; if(printPartialEquations && deriv.hasEquation()) deriv.getEquation().jjtAccept(this,null); else sb.append(node.getName()); } else if(var instanceof DVariable) { DVariable dvar = (DVariable) var; if(printVariableEquations && dvar.hasEquation()) dvar.getEquation().jjtAccept(this,null); else sb.append(node.getName()); } else sb.append(node.getName()); return data; }
public Object visit(ASTVarNode node, Object data) throws ParseException { Variable var = node.getVar(); if(var instanceof PartialDerivative) { PartialDerivative deriv = (PartialDerivative) var; if(((mode & PRINT_PARTIAL_EQNS)!=0) && deriv.hasEquation()) deriv.getEquation().jjtAccept(this,null); else sb.append(node.getName()); } else if(var instanceof DVariable) { DVariable dvar = (DVariable) var; if(printVariableEquations && dvar.hasEquation()) dvar.getEquation().jjtAccept(this,null); else sb.append(node.getName()); } else sb.append(node.getName()); return data; }
1,115,321
public Object visit(ASTVarNode node, Object data) throws ParseException { Variable var = node.getVar(); if(var instanceof PartialDerivative) { PartialDerivative deriv = (PartialDerivative) var; if(printPartialEquations && deriv.hasEquation()) deriv.getEquation().jjtAccept(this,null); else sb.append(node.getName()); } else if(var instanceof DVariable) { DVariable dvar = (DVariable) var; if(printVariableEquations && dvar.hasEquation()) dvar.getEquation().jjtAccept(this,null); else sb.append(node.getName()); } else sb.append(node.getName()); return data; }
public Object visit(ASTVarNode node, Object data) throws ParseException { Variable var = node.getVar(); if(var instanceof PartialDerivative) { PartialDerivative deriv = (PartialDerivative) var; if(printPartialEquations && deriv.hasEquation()) deriv.getEquation().jjtAccept(this,null); else sb.append(node.getName()); } else if(var instanceof DVariable) { DVariable dvar = (DVariable) var; if(((mode & PRINT_VARIABLE_EQNS)!=0) && dvar.hasEquation()) dvar.getEquation().jjtAccept(this,null); else sb.append(node.getName()); } else sb.append(node.getName()); return data; }
1,115,322
public Object visit(ASTVarNode node, Object data) throws ParseException { sb.append(node.getName()); return data; }
public Object visit(ASTVarNode node, Object data) throws ParseException { sb.append(node.getName()); return data; }
1,115,323
public void fireUploadFileChanged(UploadState file) { synchronized (uploadStateList) { int position = uploadStateList.indexOf( file ); if ( position >= 0 ) { fireUploadFileChanged( position ); } } }
private void fireUploadFileChanged(final int position) { synchronized (uploadStateList) { int position = uploadStateList.indexOf( file ); if ( position >= 0 ) { fireUploadFileChanged( position ); } } }
1,115,324
public void fireUploadFileChanged(UploadState file) { synchronized (uploadStateList) { int position = uploadStateList.indexOf( file ); if ( position >= 0 ) { fireUploadFileChanged( position ); } } }
public void fireUploadFileChanged(UploadState file) { AsynchronousDispatcher.invokeLater( new Runnable() { int position = uploadStateList.indexOf( file ); if ( position >= 0 ) { fireUploadFileChanged( position ); } } }
1,115,325
public void fireUploadFileChanged(UploadState file) { synchronized (uploadStateList) { int position = uploadStateList.indexOf( file ); if ( position >= 0 ) { fireUploadFileChanged( position ); } } }
public void fireUploadFileChanged(UploadState file) { synchronized (uploadStateList) { int position = uploadStateList.indexOf( file ); if ( position >= 0 ) { fireUploadFileChanged( position ); } } }
1,115,326
public void fireUploadFileChanged(UploadState file) { synchronized (uploadStateList) { int position = uploadStateList.indexOf( file ); if ( position >= 0 ) { fireUploadFileChanged( position ); } } }
public void fireUploadFileChanged(UploadState file) { synchronized (uploadStateList) { int position = uploadStateList.indexOf( file ); if ( position >= 0 ) { Object[] listeners = listenerList.toArray(); UploadFilesChangeListener listener; for (int i = listeners.length - 1; i >= 0; i--) { listener = (UploadFilesChangeListener) listeners[i]; listener.uploadFileChanged( position ); } } } }
1,115,327
public void fireUploadFileChanged(UploadState file) { synchronized (uploadStateList) { int position = uploadStateList.indexOf( file ); if ( position >= 0 ) { fireUploadFileChanged( position ); } } }
public void fireUploadFileChanged(UploadState file) { synchronized (uploadStateList) { int position = uploadStateList.indexOf( file ); if ( position >= 0 ) { fireUploadFileChanged( position ); } ); } ); } );
1,115,328
public void run() { run(new Runner() { public Result run(BuildListener listener) throws IOException { if(!project.checkout(Build.this,listener)) return Result.FAILURE; if(!project.getScm().calcChangeLog(Build.this,new File(getRootDir(),"changelog.xml"),listener)) return Result.FAILURE; if(!preBuild(listener,project.getBuilders())) return Result.FAILURE; if(!preBuild(listener,project.getPublishers())) return Result.FAILURE; if(!build(listener,project.getBuilders())) return Result.FAILURE; if(!isWindows()) { try { // ignore a failure. new Proc(new String[]{"rm","../latest"},new String[0],listener.getLogger(),getProject().getBuildDir()).join(); int r = new Proc(new String[]{"ln","-s",getRootDir().getPath(),"../lastSuccessful"}, new String[0],listener.getLogger(),getProject().getBuildDir()).join(); if(r!=0) listener.getLogger().println("ln failed: "+r); } catch (IOException e) { PrintStream log = listener.getLogger(); log.println("ln failed"); e.printStackTrace( log ); } } return Result.SUCCESS; } public void post(BuildListener listener) { build(listener,project.getPublishers()); } }); }
public void run() { run(new Runner() { public Result run(BuildListener listener) throws IOException { if(!project.checkout(Build.this,listener)) return Result.FAILURE; if(!project.getScm().calcChangeLog(Build.this,new File(getRootDir(),"changelog.xml"),listener)) return Result.FAILURE; if(!preBuild(listener,project.getBuilders())) return Result.FAILURE; if(!preBuild(listener,project.getPublishers())) return Result.FAILURE; if(!build(listener,project.getBuilders())) return Result.FAILURE; if(!isWindows()) { try { // ignore a failure. new Proc(new String[]{"rm","../latest"},new String[0],listener.getLogger(),getProject().getBuildDir()).join(); int r = new Proc(new String[]{ "ln","-s","builds/"+getId(),"../lastSuccessful"}, new String[0],listener.getLogger(),getProject().getBuildDir()).join(); if(r!=0) listener.getLogger().println("ln failed: "+r); } catch (IOException e) { PrintStream log = listener.getLogger(); log.println("ln failed"); e.printStackTrace( log ); } } return Result.SUCCESS; } public void post(BuildListener listener) { build(listener,project.getPublishers()); } }); }
1,115,329
public Result run(BuildListener listener) throws IOException { if(!project.checkout(Build.this,listener)) return Result.FAILURE; if(!project.getScm().calcChangeLog(Build.this,new File(getRootDir(),"changelog.xml"),listener)) return Result.FAILURE; if(!preBuild(listener,project.getBuilders())) return Result.FAILURE; if(!preBuild(listener,project.getPublishers())) return Result.FAILURE; if(!build(listener,project.getBuilders())) return Result.FAILURE; if(!isWindows()) { try { // ignore a failure. new Proc(new String[]{"rm","../latest"},new String[0],listener.getLogger(),getProject().getBuildDir()).join(); int r = new Proc(new String[]{"ln","-s",getRootDir().getPath(),"../lastSuccessful"}, new String[0],listener.getLogger(),getProject().getBuildDir()).join(); if(r!=0) listener.getLogger().println("ln failed: "+r); } catch (IOException e) { PrintStream log = listener.getLogger(); log.println("ln failed"); e.printStackTrace( log ); } } return Result.SUCCESS; }
public Result run(BuildListener listener) throws IOException { if(!project.checkout(Build.this,listener)) return Result.FAILURE; if(!project.getScm().calcChangeLog(Build.this,new File(getRootDir(),"changelog.xml"),listener)) return Result.FAILURE; if(!preBuild(listener,project.getBuilders())) return Result.FAILURE; if(!preBuild(listener,project.getPublishers())) return Result.FAILURE; if(!build(listener,project.getBuilders())) return Result.FAILURE; if(!isWindows()) { try { // ignore a failure. new Proc(new String[]{"rm","../latest"},new String[0],listener.getLogger(),getProject().getBuildDir()).join(); int r = new Proc(new String[]{ "ln","-s","builds/"+getId(),"../lastSuccessful"}, new String[0],listener.getLogger(),getProject().getBuildDir()).join(); if(r!=0) listener.getLogger().println("ln failed: "+r); } catch (IOException e) { PrintStream log = listener.getLogger(); log.println("ln failed"); e.printStackTrace( log ); } } return Result.SUCCESS; }
1,115,330
public XJep newInstance(SymbolTable st) { XJep newJep = new XJep(this); newJep.symTab = st; return newJep; }
public XJep newInstance() { XJep newJep = new XJep(this); newJep.symTab = st; return newJep; }
1,115,332
public XJep newInstance(SymbolTable st) { XJep newJep = new XJep(this); newJep.symTab = st; return newJep; }
public XJep newInstance(SymbolTable st) { XJep newJep = new XJep(this); return newJep; }
1,115,333
public ASTVarNode buildVariableNode(Variable var) throws ParseException { ASTVarNode node = new ASTVarNode(ParserTreeConstants.JJTVARNODE); node.setVar(var); return node; }
public ASTVarNode buildVariableNode(ASTVarNode node) throws ParseException { ASTVarNode node = new ASTVarNode(ParserTreeConstants.JJTVARNODE); node.setVar(var); return node; }
1,115,334
public ASTVarNode buildVariableNode(Variable var) throws ParseException { ASTVarNode node = new ASTVarNode(ParserTreeConstants.JJTVARNODE); node.setVar(var); return node; }
public ASTVarNode buildVariableNode(Variable var) throws ParseException { ASTVarNode node = new ASTVarNode(ParserTreeConstants.JJTVARNODE); node.setVar(var); return node; }
1,115,335
public Node rewrite(Node node,XJep xjep,RewriteRuleI rules[],boolean simplify) throws ParseException,IllegalArgumentException { xj = xjep; nf = xjep.getNodeFactory(); opSet = xjep.getOperatorSet(); tu = xjep.getTreeUtils(); this.rules = rules; this.simp = simplify; if(this.rules.length==0) return node; if (node == null) throw new IllegalArgumentException( "topNode parameter is null"); Node res = (Node) node.jjtAccept(this,null); return res; }
public Node rewrite(Node node,XJep xjep,RewriteRuleI inrules[],boolean simplify) throws ParseException,IllegalArgumentException { xj = xjep; nf = xjep.getNodeFactory(); opSet = xjep.getOperatorSet(); tu = xjep.getTreeUtils(); this.rules = rules; this.simp = simplify; if(this.rules.length==0) return node; if (node == null) throw new IllegalArgumentException( "topNode parameter is null"); Node res = (Node) node.jjtAccept(this,null); return res; }
1,115,336
public Node rewrite(Node node,XJep xjep,RewriteRuleI rules[],boolean simplify) throws ParseException,IllegalArgumentException { xj = xjep; nf = xjep.getNodeFactory(); opSet = xjep.getOperatorSet(); tu = xjep.getTreeUtils(); this.rules = rules; this.simp = simplify; if(this.rules.length==0) return node; if (node == null) throw new IllegalArgumentException( "topNode parameter is null"); Node res = (Node) node.jjtAccept(this,null); return res; }
public Node rewrite(Node node,XJep xjep,RewriteRuleI rules[],boolean simplify) throws ParseException,IllegalArgumentException { xj = xjep; nf = xjep.getNodeFactory(); opSet = xjep.getOperatorSet(); tu = xjep.getTreeUtils(); this.rules = rules; this.simp = simplify; if(this.rules.length==0) return node; if (node == null) throw new IllegalArgumentException( "topNode parameter is null"); Node res = (Node) node.jjtAccept(this,null); return res; }
1,115,337
public void calcMashSchedule() { // Method to run through the mash table and calculate values double strikeTemp = 0; double targetTemp = 0; double endTemp = 0; double waterAddedQTS = 0; double waterEquiv = 0; double mr = mashRatio; double currentTemp = grainTempF; double displTemp = 0; double tunLoss = tunLossF; // figure out a better way to do this, eg: themal mass double decoct = 0; int totalMashTime = 0; double totalSpargeTime = 0; double mashWaterQTS = 0; double mashVolQTS = 0; String stepType; int numSparge = 0; // convert mash ratio to qts/lb if in l/kg if (mashRatioU.equalsIgnoreCase("l/kg")) { mr *= 0.479325; } // convert CurrentTemp to F if (mashTempU == "C") { currentTemp = cToF(currentTemp); tunLoss = cToF(tunLossF); } // perform calcs on first record if (steps.isEmpty()) return; // sort the list Collections.sort(steps, new stepComparator()); MashStep stp = ((MashStep) steps.get(0)); targetTemp = stp.startTemp; endTemp = stp.endTemp; strikeTemp = calcStrikeTemp(targetTemp, currentTemp, mr, tunLoss); waterAddedQTS = mr * maltWeightLbs; waterEquiv = maltWeightLbs * (0.192 + mr); mashVolQTS = calcMashVol(maltWeightLbs, mr); totalMashTime += stp.minutes; mashWaterQTS += waterAddedQTS; stp.infuseVol.setUnits("qt"); stp.infuseVol.setAmount(waterAddedQTS); stp.method = "infusion"; // subtract the water added from the Water Equiv so that they are correct when added in the next part of the loop waterEquiv -= waterAddedQTS; // Updated the water added if (tempUnits == "C") strikeTemp = fToC(strikeTemp); stp.directions = "Mash in with " + df1.format(stp.infuseVol.getValueAs(volUnits)) + " " + volUnits + " of water at " + df1.format(strikeTemp) + " " + tempUnits; // set TargetTemp to the end temp targetTemp = stp.endTemp; for (int i = 1; i < steps.size(); i++) { stp = ((MashStep) steps.get(i)); currentTemp = targetTemp; // switch targetTemp = stp.startTemp; // do calcs if (stp.method.equals("infusion")) { // calculate an infusion step decoct = 0; waterEquiv += waterAddedQTS; // add previous addition to get WE strikeTemp = boilTempF; // boiling water // Updated the water added waterAddedQTS = calcWaterAddition(targetTemp, currentTemp, waterEquiv, boilTempF); stp.infuseVol.setUnits("qt"); stp.infuseVol.setAmount(waterAddedQTS); if (tempUnits == "C") strikeTemp = 100; stp.directions = "Add " + df1.format(stp.infuseVol.getValueAs(volUnits)) + " " + volUnits + " of water at " + df1.format(strikeTemp) + " " + tempUnits; mashWaterQTS += waterAddedQTS; mashVolQTS += waterAddedQTS; } else if (stp.method.indexOf("decoction") > 0) { // calculate a decoction step waterEquiv += waterAddedQTS; // add previous addition to get WE waterAddedQTS = 0; strikeTemp = boilTempF; // boiling water double ratio=0.75; if (stp.method.indexOf("thick") > 0) ratio = 0.6; else if (stp.method.indexOf("thin") > 0) ratio = 0.9; // Calculate volume (qts) of mash to remove decoct = calcDecoction2(targetTemp, currentTemp, mashWaterQTS, ratio); stp.decoctVol.setUnits("qt"); stp.decoctVol.setAmount(decoct); // Updated the decoction, convert to right units & make directions stp.directions = "Remove " + df1.format(stp.decoctVol.getValueAs(volUnits)) + " " + volUnits + " of mash, boil, and return to mash."; } else if (stp.method.equals("direct")) { // calculate a direct heat step decoct = 0; waterEquiv += waterAddedQTS; // add previous addition to get WE waterAddedQTS = 0; stp.directions = "Add direct heat until mash reaches " + displTemp + " " + tempUnits + "."; } if (stp.method.equals("sparge")) { // Count it numSparge++; } else totalMashTime += stp.minutes; stp.infuseVol.setUnits("qt"); stp.infuseVol.setAmount(waterAddedQTS); stp.decoctVol.setUnits("qt"); stp.decoctVol.setAmount(decoct); // set target temp to end temp for next step targetTemp = stp.endTemp; } // while not eof waterEquiv += waterAddedQTS; // add previous addition to get WE totalTime = totalMashTime; volQts = mashVolQTS; // water use stats: absorbedQTS = maltWeightLbs * 0.55; // figure from HBD // spargeTotalQTS = (myRecipe.getPreBoilVol("qt")) - (mashWaterQTS - absorbedQTS); totalWaterQTS = mashWaterQTS; // TODO: sparge stuff should get figured here: }
public void calcMashSchedule() { // Method to run through the mash table and calculate values double strikeTemp = 0; double targetTemp = 0; double endTemp = 0; double waterAddedQTS = 0; double waterEquiv = 0; double mr = mashRatio; double currentTemp = grainTempF; double displTemp = 0; double tunLoss = tunLossF; // figure out a better way to do this, eg: themal mass double decoct = 0; int totalMashTime = 0; double totalSpargeTime = 0; double mashWaterQTS = 0; double mashVolQTS = 0; String stepType; int numSparge = 0; // convert mash ratio to qts/lb if in l/kg if (mashRatioU.equalsIgnoreCase("l/kg")) { mr *= 0.479325; } // convert CurrentTemp to F if (mashTempU == "C") { currentTemp = cToF(currentTemp); tunLoss = tunLossF * 1.8; } // perform calcs on first record if (steps.isEmpty()) return; // sort the list Collections.sort(steps, new stepComparator()); MashStep stp = ((MashStep) steps.get(0)); targetTemp = stp.startTemp; endTemp = stp.endTemp; strikeTemp = calcStrikeTemp(targetTemp, currentTemp, mr, tunLoss); waterAddedQTS = mr * maltWeightLbs; waterEquiv = maltWeightLbs * (0.192 + mr); mashVolQTS = calcMashVol(maltWeightLbs, mr); totalMashTime += stp.minutes; mashWaterQTS += waterAddedQTS; stp.infuseVol.setUnits("qt"); stp.infuseVol.setAmount(waterAddedQTS); stp.method = "infusion"; // subtract the water added from the Water Equiv so that they are correct when added in the next part of the loop waterEquiv -= waterAddedQTS; // Updated the water added if (tempUnits == "C") strikeTemp = fToC(strikeTemp); stp.directions = "Mash in with " + df1.format(stp.infuseVol.getValueAs(volUnits)) + " " + volUnits + " of water at " + df1.format(strikeTemp) + " " + tempUnits; // set TargetTemp to the end temp targetTemp = stp.endTemp; for (int i = 1; i < steps.size(); i++) { stp = ((MashStep) steps.get(i)); currentTemp = targetTemp; // switch targetTemp = stp.startTemp; // do calcs if (stp.method.equals("infusion")) { // calculate an infusion step decoct = 0; waterEquiv += waterAddedQTS; // add previous addition to get WE strikeTemp = boilTempF; // boiling water // Updated the water added waterAddedQTS = calcWaterAddition(targetTemp, currentTemp, waterEquiv, boilTempF); stp.infuseVol.setUnits("qt"); stp.infuseVol.setAmount(waterAddedQTS); if (tempUnits == "C") strikeTemp = 100; stp.directions = "Add " + df1.format(stp.infuseVol.getValueAs(volUnits)) + " " + volUnits + " of water at " + df1.format(strikeTemp) + " " + tempUnits; mashWaterQTS += waterAddedQTS; mashVolQTS += waterAddedQTS; } else if (stp.method.indexOf("decoction") > 0) { // calculate a decoction step waterEquiv += waterAddedQTS; // add previous addition to get WE waterAddedQTS = 0; strikeTemp = boilTempF; // boiling water double ratio=0.75; if (stp.method.indexOf("thick") > 0) ratio = 0.6; else if (stp.method.indexOf("thin") > 0) ratio = 0.9; // Calculate volume (qts) of mash to remove decoct = calcDecoction2(targetTemp, currentTemp, mashWaterQTS, ratio); stp.decoctVol.setUnits("qt"); stp.decoctVol.setAmount(decoct); // Updated the decoction, convert to right units & make directions stp.directions = "Remove " + df1.format(stp.decoctVol.getValueAs(volUnits)) + " " + volUnits + " of mash, boil, and return to mash."; } else if (stp.method.equals("direct")) { // calculate a direct heat step decoct = 0; waterEquiv += waterAddedQTS; // add previous addition to get WE waterAddedQTS = 0; stp.directions = "Add direct heat until mash reaches " + displTemp + " " + tempUnits + "."; } if (stp.method.equals("sparge")) { // Count it numSparge++; } else totalMashTime += stp.minutes; stp.infuseVol.setUnits("qt"); stp.infuseVol.setAmount(waterAddedQTS); stp.decoctVol.setUnits("qt"); stp.decoctVol.setAmount(decoct); // set target temp to end temp for next step targetTemp = stp.endTemp; } // while not eof waterEquiv += waterAddedQTS; // add previous addition to get WE totalTime = totalMashTime; volQts = mashVolQTS; // water use stats: absorbedQTS = maltWeightLbs * 0.55; // figure from HBD // spargeTotalQTS = (myRecipe.getPreBoilVol("qt")) - (mashWaterQTS - absorbedQTS); totalWaterQTS = mashWaterQTS; // TODO: sparge stuff should get figured here: }
1,115,338
public double getTunLoss() { if (tempUnits.equals("F")) return tunLossF; else return fToC(tunLossF); }
public double getTunLoss() { if (tempUnits.equals("F")) return tunLossF; else return ( tunLossF / 1.8 ); }
1,115,339
public void setTunLoss(double t){ if (tempUnits.equals("F")) tunLossF = t; else tunLossF = cToF(t); calcMashSchedule(); }
public void setTunLoss(double t){ if (tempUnits.equals("F")) tunLossF = t; else tunLossF = t * 1.8; calcMashSchedule(); }
1,115,340
public void displayMash() { if (myRecipe != null) { recipeNameLabel.setText(myRecipe.getName()); mashModel.setData(myRecipe.getMash()); tblMash.updateUI(); volUnitsComboModel.addOrInsert(myRecipe.mash.getMashVolUnits()); // temp units: if (myRecipe.mash.getMashTempUnits().equals("F")) tempFrb.setSelected(true); else tempCrb.setSelected(true); grainTempULabel.setText(myRecipe.mash.getMashTempUnits()); tempLostULabel.setText(myRecipe.mash.getMashTempUnits()); // set totals: String mashWeightTotal = SBStringUtils.df1.format(myRecipe.getTotalMash()) + " " + myRecipe.getMaltUnits(); totalMashLabel.setText(mashWeightTotal); totalTimeLabel.setText(new Integer(myRecipe.mash.getMashTotalTime()).toString()); volLabel.setText(myRecipe.mash.getMashTotalVol()); grainTempText.setText(new Double(myRecipe.mash.getGrainTemp()).toString()); int i = tblMash.getSelectedRow(); if (i>-1){ directionsTextArea.setText(myRecipe.mash.getStepDirections(i)); } displayWater(); } }
public void displayMash() { if (myRecipe != null) { recipeNameLabel.setText(myRecipe.getName()); mashModel.setData(myRecipe.getMash()); tblMash.updateUI(); volUnitsComboModel.addOrInsert(myRecipe.mash.getMashVolUnits()); // temp units: if (myRecipe.mash.getMashTempUnits().equals("F")) tempFrb.setSelected(true); else tempCrb.setSelected(true); grainTempULabel.setText(myRecipe.mash.getMashTempUnits()); tempLostULabel.setText(myRecipe.mash.getMashTempUnits()); // set totals: String mashWeightTotal = SBStringUtils.df1.format(myRecipe.getTotalMash()) + " " + myRecipe.getMaltUnits(); totalMashLabel.setText(mashWeightTotal); totalTimeLabel.setText(new Integer(myRecipe.mash.getMashTotalTime()).toString()); volLabel.setText(myRecipe.mash.getMashTotalVol()); grainTempText.setText(new Double(myRecipe.mash.getGrainTemp()).toString()); int i = tblMash.getSelectedRow(); if (i>-1){ directionsTextArea.setText(myRecipe.mash.getStepDirections(i)); } displayWater(); } }
1,115,342
public void setGrainTemp(double t){ if (tempUnits.equals("F")) grainTempF = t; else grainTempF = cToF(t); calcMashSchedule(); }
public void setGrainTemp(double t){ if (tempUnits.equals("F")) grainTempF = t; else grainTempF = BrewCalcs.cToF(t); calcMashSchedule(); }
1,115,344
public double getGrainTemp() { if (tempUnits.equals("F")) return grainTempF; else return fToC(grainTempF); }
public double getGrainTemp() { if (tempUnits.equals("F")) return grainTempF; else return BrewCalcs.fToC(grainTempF); }
1,115,345
public String getVolAbrv(String unit) { return getAbrvFromUnit(getTypeFromUnit(unit), unit); }
public String getVolAbrv(String unit) { return getAbrvFromUnit(getTypeFromUnit(unit), unit); }
1,115,346
public Dimensions calcDim(Dimensions l,Dimensions r) { if(l.equals(Dimensions.ONE) && r.equals(Dimensions.ONE)) return Dimensions.ONE; if(l.is0D() ) return r; // scalar mult on left if(r.is0D() ) return l; // scalar mult on right if(l.is1D() && r.is1D() ) return null; // error for vector * vector if(l.is2D() && r.is1D() ) // matrix times vector { if(l.getLastDim() == r.getFirstDim()) return Dimensions.valueOf(l.getFirstDim()); else return null; } if(l.is1D() && r.is2D() ) // vector times matrix { if(l.getLastDim() == r.getFirstDim()) return Dimensions.valueOf(r.getLastDim()); else return null; } if(l.is2D() && r.is2D() ) // matrix times matrix { if(l.getLastDim() == r.getFirstDim()) return Dimensions.valueOf(l.getFirstDim(),r.getLastDim()); else return null; } if(l.getLastDim() == r.getFirstDim()) // Something else { int dims[] = new int[l.rank()+r.rank()-2]; int j = 0; for(int i=0;i<l.rank()-1;++i) dims[j++]=l.getIthDim(i); for(int i=1;i<r.rank();++i) dims[j++]=r.getIthDim(i); return Dimensions.valueOf(dims); } else return null; }
public Dimensions calcDim(Dimensions l,Dimensions r) { if(l.equals(Dimensions.ONE) && r.equals(Dimensions.ONE)) return Dimensions.ONE; if(l.is0D() ) return r; // scalar mult on left if(r.is0D() ) return l; // scalar mult on right if(l.is1D() && r.is1D() ) return null; // error for vector * vector if(l.is2D() && r.is1D() ) // matrix times vector { if(l.getLastDim() == r.getFirstDim()) return Dimensions.valueOf(l.getFirstDim()); else return null; } if(l.is1D() && r.is2D() ) // vector times matrix { if(l.getLastDim() == r.getFirstDim()) return Dimensions.valueOf(r.getLastDim()); else return null; } if(l.is2D() && r.is2D() ) // matrix times matrix { if(l.getLastDim() == r.getFirstDim()) return Dimensions.valueOf(l.getFirstDim(),r.getLastDim()); else return null; } if(l.getLastDim() == r.getFirstDim()) // Something else { int dims[] = new int[l.rank()+r.rank()-2]; int j = 0; for(int i=0;i<l.rank()-1;++i) dims[j++]=l.getIthDim(i); for(int i=1;i<r.rank();++i) dims[j++]=r.getIthDim(i); return Dimensions.valueOf(dims); } else return null; }
1,115,347
public Dimensions calcDim(Dimensions l,Dimensions r) { if(l.equals(Dimensions.ONE) && r.equals(Dimensions.ONE)) return Dimensions.ONE; if(l.is0D() ) return r; // scalar mult on left if(r.is0D() ) return l; // scalar mult on right if(l.is1D() && r.is1D() ) return null; // error for vector * vector if(l.is2D() && r.is1D() ) // matrix times vector { if(l.getLastDim() == r.getFirstDim()) return Dimensions.valueOf(l.getFirstDim()); else return null; } if(l.is1D() && r.is2D() ) // vector times matrix { if(l.getLastDim() == r.getFirstDim()) return Dimensions.valueOf(r.getLastDim()); else return null; } if(l.is2D() && r.is2D() ) // matrix times matrix { if(l.getLastDim() == r.getFirstDim()) return Dimensions.valueOf(l.getFirstDim(),r.getLastDim()); else return null; } if(l.getLastDim() == r.getFirstDim()) // Something else { int dims[] = new int[l.rank()+r.rank()-2]; int j = 0; for(int i=0;i<l.rank()-1;++i) dims[j++]=l.getIthDim(i); for(int i=1;i<r.rank();++i) dims[j++]=r.getIthDim(i); return Dimensions.valueOf(dims); } else return null; }
public Dimensions calcDim(Dimensions l,Dimensions r) { if(l.equals(Dimensions.ONE) && r.equals(Dimensions.ONE)) return Dimensions.ONE; if(l.is0D() ) return r; // scalar mult on left if(r.is0D() ) return l; // scalar mult on right if(l.is1D() && r.is1D() ) return null; // error for vector * vector if(l.is2D() && r.is1D() ) // matrix times vector { if(l.getLastDim() == r.getFirstDim()) return Dimensions.valueOf(l.getFirstDim()); else return null; } if(l.is1D() && r.is2D() ) // vector times matrix { if(l.getLastDim() == r.getFirstDim()) return Dimensions.valueOf(r.getLastDim()); else return null; } if(l.is2D() && r.is2D() ) // matrix times matrix { if(l.getLastDim() == r.getFirstDim()) return Dimensions.valueOf(l.getFirstDim(),r.getLastDim()); else return null; } if(l.getLastDim() == r.getFirstDim()) // Something else { int dims[] = new int[l.rank()+r.rank()-2]; int j = 0; for(int i=0;i<l.rank()-1;++i) dims[j++]=l.getIthDim(i); for(int i=1;i<r.rank();++i) dims[j++]=r.getIthDim(i); return Dimensions.valueOf(dims); } else return null; }
1,115,348
public Dimensions calcDim(Dimensions l,Dimensions r) { if(l.equals(Dimensions.ONE) && r.equals(Dimensions.ONE)) return Dimensions.ONE; if(l.is0D() ) return r; // scalar mult on left if(r.is0D() ) return l; // scalar mult on right if(l.is1D() && r.is1D() ) return null; // error for vector * vector if(l.is2D() && r.is1D() ) // matrix times vector { if(l.getLastDim() == r.getFirstDim()) return Dimensions.valueOf(l.getFirstDim()); else return null; } if(l.is1D() && r.is2D() ) // vector times matrix { if(l.getLastDim() == r.getFirstDim()) return Dimensions.valueOf(r.getLastDim()); else return null; } if(l.is2D() && r.is2D() ) // matrix times matrix { if(l.getLastDim() == r.getFirstDim()) return Dimensions.valueOf(l.getFirstDim(),r.getLastDim()); else return null; } if(l.getLastDim() == r.getFirstDim()) // Something else { int dims[] = new int[l.rank()+r.rank()-2]; int j = 0; for(int i=0;i<l.rank()-1;++i) dims[j++]=l.getIthDim(i); for(int i=1;i<r.rank();++i) dims[j++]=r.getIthDim(i); return Dimensions.valueOf(dims); } else return null; }
public Dimensions calcDim(Dimensions l,Dimensions r) { if(l.equals(Dimensions.ONE) && r.equals(Dimensions.ONE)) return Dimensions.ONE; if(l.is0D() ) return r; // scalar mult on left if(r.is0D() ) return l; // scalar mult on right if(l.is1D() && r.is1D() ) return null; // error for vector * vector if(l.is2D() && r.is1D() ) // matrix times vector { if(l.getLastDim() == r.getFirstDim()) return Dimensions.valueOf(l.getFirstDim()); else return null; } if(l.is1D() && r.is2D() ) // vector times matrix { if(l.getLastDim() == r.getFirstDim()) return Dimensions.valueOf(r.getLastDim()); else return null; } if(l.is2D() && r.is2D() ) // matrix times matrix { if(l.getLastDim() == r.getFirstDim()) return Dimensions.valueOf(l.getFirstDim(),r.getLastDim()); else return null; } if(l.getLastDim() == r.getFirstDim()) // Something else { int dims[] = new int[l.rank()+r.rank()-2]; int j = 0; for(int i=0;i<l.rank()-1;++i) dims[j++]=l.getIthDim(i); for(int i=1;i<r.rank();++i) dims[j++]=r.getIthDim(i); return Dimensions.valueOf(dims); } else return null; }
1,115,349
public MatrixValueI calcValue(MatrixValueI res,MatrixValueI param1,MatrixValueI param2) throws ParseException { if(res instanceof MVector && param1 instanceof Matrix && param2 instanceof MVector) return calcValue((MVector) res,(Matrix) param1,(MVector) param2); else if(res instanceof MVector && param1 instanceof MVector && param2 instanceof Matrix) return calcValue((MVector) res,(MVector) param1,(Matrix) param2); else if(res instanceof MVector && param1 instanceof MVector && param2 instanceof MVector) return calcValue((MVector) res,(MVector) param1,(MVector) param2); else if(res instanceof Matrix && param1 instanceof Matrix && param2 instanceof Matrix) return calcValue((Matrix) res,(Matrix) param1,(Matrix) param2); else if(res instanceof Scaler && param1 instanceof Scaler && param2 instanceof Scaler) return calcValue((Scaler) res,(Scaler) param1,(Scaler) param2); else if(res instanceof MVector && param1 instanceof MVector && param2 instanceof Scaler) return calcValue((MVector) res,(MVector) param1,((Scaler) param2).getEle(0)); else if(res instanceof MVector && param1 instanceof Scaler && param2 instanceof MVector) return calcValue((MVector) res,((Scaler) param1).getEle(0),(MVector) param2); else if(res instanceof Matrix && param1 instanceof Matrix && param2 instanceof Scaler) return calcValue((Matrix) res,(Matrix) param1,((Scaler) param2).getEle(0)); else if(res instanceof Matrix && param1 instanceof Scaler && param2 instanceof Matrix) return calcValue((Matrix) res,((Scaler) param1).getEle(0),(Matrix) param2); else { Object val = super.mul(param1,param2); res.setEle(0,val); return res; } }
public MatrixValueI calcValue(MatrixValueI res,MatrixValueI param1,MatrixValueI param2) throws ParseException { if(res instanceof MVector && param1 instanceof Matrix && param2 instanceof MVector) return calcValue((MVector) res,(Matrix) param1,(MVector) param2); else if(res instanceof MVector && param1 instanceof MVector && param2 instanceof Matrix) return calcValue((MVector) res,(MVector) param1,(Matrix) param2); else if(res instanceof MVector && param1 instanceof MVector && param2 instanceof MVector) return calcValue((MVector) res,(MVector) param1,(MVector) param2); else if(res instanceof Matrix && param1 instanceof Matrix && param2 instanceof Matrix) return calcValue((Matrix) res,(Matrix) param1,(Matrix) param2); else if(res instanceof Scaler && param1 instanceof Scaler && param2 instanceof Scaler) return calcValue((Scaler) res,(Scaler) param1,(Scaler) param2); else if(res instanceof MVector && param1 instanceof MVector && param2 instanceof Scaler) return calcValue((MVector) res,(MVector) param1,((Scaler) param2).getEle(0)); else if(res instanceof MVector && param1 instanceof Scaler && param2 instanceof MVector) return calcValue((MVector) res,((Scaler) param1).getEle(0),(MVector) param2); else if(res instanceof Matrix && param1 instanceof Matrix && param2 instanceof Scaler) return calcValue((Matrix) res,(Matrix) param1,((Scaler) param2).getEle(0)); else if(res instanceof Matrix && param1 instanceof Scaler && param2 instanceof Matrix) return calcValue((Matrix) res,((Scaler) param1).getEle(0),(Matrix) param2); else { Object val = super.mul(param1,param2); res.setEle(0,val); return res; } }
1,115,350
public MatrixValueI calcValue(MatrixValueI res,MatrixValueI param1,MatrixValueI param2) throws ParseException { if(res instanceof MVector && param1 instanceof Matrix && param2 instanceof MVector) return calcValue((MVector) res,(Matrix) param1,(MVector) param2); else if(res instanceof MVector && param1 instanceof MVector && param2 instanceof Matrix) return calcValue((MVector) res,(MVector) param1,(Matrix) param2); else if(res instanceof MVector && param1 instanceof MVector && param2 instanceof MVector) return calcValue((MVector) res,(MVector) param1,(MVector) param2); else if(res instanceof Matrix && param1 instanceof Matrix && param2 instanceof Matrix) return calcValue((Matrix) res,(Matrix) param1,(Matrix) param2); else if(res instanceof Scaler && param1 instanceof Scaler && param2 instanceof Scaler) return calcValue((Scaler) res,(Scaler) param1,(Scaler) param2); else if(res instanceof MVector && param1 instanceof MVector && param2 instanceof Scaler) return calcValue((MVector) res,(MVector) param1,((Scaler) param2).getEle(0)); else if(res instanceof MVector && param1 instanceof Scaler && param2 instanceof MVector) return calcValue((MVector) res,((Scaler) param1).getEle(0),(MVector) param2); else if(res instanceof Matrix && param1 instanceof Matrix && param2 instanceof Scaler) return calcValue((Matrix) res,(Matrix) param1,((Scaler) param2).getEle(0)); else if(res instanceof Matrix && param1 instanceof Scaler && param2 instanceof Matrix) return calcValue((Matrix) res,((Scaler) param1).getEle(0),(Matrix) param2); else { Object val = super.mul(param1,param2); res.setEle(0,val); return res; } }
public MatrixValueI calcValue(MatrixValueI res,MatrixValueI param1,MatrixValueI param2) throws ParseException { if(res instanceof MVector && param1 instanceof Matrix && param2 instanceof MVector) return calcValue((MVector) res,(Matrix) param1,(MVector) param2); else if(res instanceof MVector && param1 instanceof MVector && param2 instanceof Matrix) return calcValue((MVector) res,(MVector) param1,(Matrix) param2); else if(res instanceof MVector && param1 instanceof MVector && param2 instanceof MVector) return calcValue((MVector) res,(MVector) param1,(MVector) param2); else if(res instanceof Matrix && param1 instanceof Matrix && param2 instanceof Matrix) return calcValue((Matrix) res,(Matrix) param1,(Matrix) param2); else if(res instanceof Scaler && param1 instanceof Scaler && param2 instanceof Scaler) return calcValue((Scaler) res,(Scaler) param1,(Scaler) param2); else if(res instanceof MVector && param1 instanceof MVector && param2 instanceof Scaler) return calcValue((MVector) res,(MVector) param1,((Scaler) param2).getEle(0)); else if(res instanceof MVector && param1 instanceof Scaler && param2 instanceof MVector) return calcValue((MVector) res,((Scaler) param1).getEle(0),(MVector) param2); else if(res instanceof Matrix && param1 instanceof Matrix && param2 instanceof Scaler) return calcValue((Matrix) res,(Matrix) param1,((Scaler) param2).getEle(0)); else if(res instanceof Matrix && param1 instanceof Scaler && param2 instanceof Matrix) return calcValue((Matrix) res,((Scaler) param1).getEle(0),(Matrix) param2); else { Object val = super.mul(param1,param2); res.setEle(0,val); return res; } }
1,115,351
public Object mul(Object param1, Object param2) throws ParseException { // TODO tensor mult? if(param1 instanceof Matrix && param2 instanceof MVector) return mul((Matrix) param1,(MVector) param2); else if(param1 instanceof MVector && param2 instanceof Matrix) return mul((MVector) param1,(Matrix) param2); else if(param1 instanceof Matrix && param2 instanceof Matrix) return mul((Matrix) param1,(Matrix) param2); else if(param1 instanceof MVector && param2 instanceof MVector) return mul((MVector) param1,(MVector) param2); else if(param1 instanceof MVector) return mul((MVector) param1,param2); else if(param2 instanceof MVector) return mul(param1,(MVector) param2); else if(param1 instanceof Matrix) return mul((Matrix) param1,param2); else if(param2 instanceof Matrix) return mul(param1,(Matrix) param2); else return super.mul(param1,param2); }
public Object mul(Object param1, Object param2) throws ParseException { // TODO tensor mult? if(param1 instanceof Matrix && param2 instanceof MVector) return mul((Matrix) param1,(MVector) param2); else if(param1 instanceof MVector && param2 instanceof Matrix) return mul((MVector) param1,(Matrix) param2); else if(param1 instanceof Matrix && param2 instanceof Matrix) return mul((Matrix) param1,(Matrix) param2); else if(param1 instanceof MVector && param2 instanceof MVector) return mul((MVector) param1,(MVector) param2); else if(param1 instanceof MVector) return mul((MVector) param1,param2); else if(param2 instanceof MVector) return mul(param1,(MVector) param2); else if(param1 instanceof Matrix) return mul((Matrix) param1,param2); else if(param2 instanceof Matrix) return mul(param1,(Matrix) param2); else return super.mul(param1,param2); }
1,115,353
public void setEle(int i,int j,Object value) { data[i][j] = value; }
public void setEle(int n,Object value) { data[i][j] = value; }
1,115,354
public Matrix(int rows,int cols) { this.rows = rows; this.cols = cols; data = new Object[rows][cols]; dims = Dimensions.valueOf(rows,cols); }
public Matrix(int rows,int cols) { this.rows = rows; this.cols = cols; data = new Object[rows][cols]; dims = Dimensions.valueOf(rows,cols); }
1,115,356