rem
stringlengths
0
477k
add
stringlengths
0
313k
context
stringlengths
6
599k
public synchronized void next() throws IOException { if (!enabled) { if (isLoggedOn()) { if (!state.isLogoutSent()) { state.logEvent("Initiated logout request"); generateLogout(logoutReason); } } else { return; } }
public synchronized void next(Message message) throws FieldNotFound, RejectLogon, IncorrectDataFormat, IncorrectTagValue, UnsupportedMessageType, IOException, InvalidMessage { state.setConnected(true);
public synchronized void next() throws IOException { if (!enabled) { if (isLoggedOn()) { if (!state.isLogoutSent()) { state.logEvent("Initiated logout request"); generateLogout(logoutReason); } } else { return; } } if (!checkSessionTime()) { reset(); return; } if (!state.isLogonReceived()) { if (state.isLogonSendNeeded()) { if (generateLogon()) { state.logEvent("Initiated logon request"); } else { state.logEvent("Error during logon request initiation"); } } else if (state.isLogonAlreadySent() && state.isLogonTimedOut()) { state.logEvent("Timed out waiting for logon response"); disconnect(); } return; } if (state.getHeartBeatInterval() == 0) { return; } if (state.isLogoutTimedOut()) { state.logEvent("Timed out waiting for logout response"); disconnect(); } if (state.isWithinHeartBeat()) { return; } if (state.isTimedOut()) { state.logEvent("Timed out waiting for heartbeat"); disconnect(); } else { if (state.isTestRequestNeeded()) { generateTestRequest("TEST"); state.incrementTestRequestCounter(); state.logEvent("Sent test request TEST"); } else if (state.isHeartBeatNeeded()) { generateHeartbeat(); } } }
if (!state.isLogonReceived()) { if (state.isLogonSendNeeded()) { if (generateLogon()) { state.logEvent("Initiated logon request");
String msgType = message.getHeader().getString(MsgType.FIELD); try { if (isStateRefreshNeeded(msgType)) { if (getStore() instanceof RefreshableMessageStore) { getLog().onEvent("Refreshing message/state store at logon"); ((RefreshableMessageStore) getStore()).refresh();
public synchronized void next() throws IOException { if (!enabled) { if (isLoggedOn()) { if (!state.isLogoutSent()) { state.logEvent("Initiated logout request"); generateLogout(logoutReason); } } else { return; } } if (!checkSessionTime()) { reset(); return; } if (!state.isLogonReceived()) { if (state.isLogonSendNeeded()) { if (generateLogon()) { state.logEvent("Initiated logon request"); } else { state.logEvent("Error during logon request initiation"); } } else if (state.isLogonAlreadySent() && state.isLogonTimedOut()) { state.logEvent("Timed out waiting for logon response"); disconnect(); } return; } if (state.getHeartBeatInterval() == 0) { return; } if (state.isLogoutTimedOut()) { state.logEvent("Timed out waiting for logout response"); disconnect(); } if (state.isWithinHeartBeat()) { return; } if (state.isTimedOut()) { state.logEvent("Timed out waiting for heartbeat"); disconnect(); } else { if (state.isTestRequestNeeded()) { generateTestRequest("TEST"); state.incrementTestRequestCounter(); state.logEvent("Sent test request TEST"); } else if (state.isHeartBeatNeeded()) { generateHeartbeat(); } } }
state.logEvent("Error during logon request initiation");
getLog().onEvent( "Refresh at logon requested, but message store not capable: " + getStore().getClass().getName());
public synchronized void next() throws IOException { if (!enabled) { if (isLoggedOn()) { if (!state.isLogoutSent()) { state.logEvent("Initiated logout request"); generateLogout(logoutReason); } } else { return; } } if (!checkSessionTime()) { reset(); return; } if (!state.isLogonReceived()) { if (state.isLogonSendNeeded()) { if (generateLogon()) { state.logEvent("Initiated logon request"); } else { state.logEvent("Error during logon request initiation"); } } else if (state.isLogonAlreadySent() && state.isLogonTimedOut()) { state.logEvent("Timed out waiting for logon response"); disconnect(); } return; } if (state.getHeartBeatInterval() == 0) { return; } if (state.isLogoutTimedOut()) { state.logEvent("Timed out waiting for logout response"); disconnect(); } if (state.isWithinHeartBeat()) { return; } if (state.isTimedOut()) { state.logEvent("Timed out waiting for heartbeat"); disconnect(); } else { if (state.isTestRequestNeeded()) { generateTestRequest("TEST"); state.incrementTestRequestCounter(); state.logEvent("Sent test request TEST"); } else if (state.isHeartBeatNeeded()) { generateHeartbeat(); } } }
} else if (state.isLogonAlreadySent() && state.isLogonTimedOut()) { state.logEvent("Timed out waiting for logon response");
} String beginString = message.getHeader().getString(BeginString.FIELD); if (!beginString.equals(sessionID.getBeginString())) { throw new UnsupportedVersion(); } if (dataDictionary != null) { dataDictionary.validate(message); } if (msgType.equals(MsgType.LOGON)) { nextLogon(message); } else if (msgType.equals(MsgType.HEARTBEAT)) { nextHeartBeat(message); } else if (msgType.equals(MsgType.TEST_REQUEST)) { nextTestRequest(message); } else if (msgType.equals(MsgType.SEQUENCE_RESET)) { nextSequenceReset(message); } else if (msgType.equals(MsgType.LOGOUT)) { nextLogout(message); } else if (msgType.equals(MsgType.RESEND_REQUEST)) { nextResendRequest(message); } else if (msgType.equals(MsgType.REJECT)) { nextReject(message); } else { if (!verify(message)) { return; } state.incrNextTargetMsgSeqNum(); } } catch (FieldException e) { generateReject(message, e.getSessionRejectReason(), e.getField()); } catch (FieldNotFound e) { if (sessionID.getBeginString().compareTo(FixVersions.BEGINSTRING_FIX42) >= 0 && message.isApp()) { generateBusinessReject(message, BusinessRejectReason.CONDITIONALLY_REQUIRED_FIELD_MISSING); } else { generateReject(message, SessionRejectReason.REQUIRED_TAG_MISSING, e.field); if (msgType.equals(MsgType.LOGON)) { state.logEvent("Required field missing from logon"); disconnect(); } } } catch (IncorrectTagValue e) { generateReject(message, SessionRejectReason.VALUE_IS_INCORRECT, e.field); } catch (InvalidMessage e) { state.logEvent("Skipping invalid message: " + e.getMessage()); } catch (RejectLogon e) { String rejectMessage = e.getMessage() != null ? (": " + e.getMessage()) : ""; state.getLog().onEvent("Logon rejected" + rejectMessage); generateLogout(e.getMessage()); disconnect(); } catch (UnsupportedMessageType e) { if (sessionID.getBeginString().compareTo(FixVersions.BEGINSTRING_FIX42) >= 0) { generateBusinessReject(message, BusinessRejectReason.UNSUPPORTED_MESSAGE_TYPE); } else { generateReject(message, "Unsupported message type"); } } catch (UnsupportedVersion e) { if (msgType.equals(MsgType.LOGOUT)) { nextLogout(message); } else { generateLogout("Incorrect BeginString"); state.incrNextTargetMsgSeqNum();
public synchronized void next() throws IOException { if (!enabled) { if (isLoggedOn()) { if (!state.isLogoutSent()) { state.logEvent("Initiated logout request"); generateLogout(logoutReason); } } else { return; } } if (!checkSessionTime()) { reset(); return; } if (!state.isLogonReceived()) { if (state.isLogonSendNeeded()) { if (generateLogon()) { state.logEvent("Initiated logon request"); } else { state.logEvent("Error during logon request initiation"); } } else if (state.isLogonAlreadySent() && state.isLogonTimedOut()) { state.logEvent("Timed out waiting for logon response"); disconnect(); } return; } if (state.getHeartBeatInterval() == 0) { return; } if (state.isLogoutTimedOut()) { state.logEvent("Timed out waiting for logout response"); disconnect(); } if (state.isWithinHeartBeat()) { return; } if (state.isTimedOut()) { state.logEvent("Timed out waiting for heartbeat"); disconnect(); } else { if (state.isTestRequestNeeded()) { generateTestRequest("TEST"); state.incrementTestRequestCounter(); state.logEvent("Sent test request TEST"); } else if (state.isHeartBeatNeeded()) { generateHeartbeat(); } } }
return;
} catch (IOException e) { LogUtil.logThrowable(sessionID, "error processing message", e);
public synchronized void next() throws IOException { if (!enabled) { if (isLoggedOn()) { if (!state.isLogoutSent()) { state.logEvent("Initiated logout request"); generateLogout(logoutReason); } } else { return; } } if (!checkSessionTime()) { reset(); return; } if (!state.isLogonReceived()) { if (state.isLogonSendNeeded()) { if (generateLogon()) { state.logEvent("Initiated logon request"); } else { state.logEvent("Error during logon request initiation"); } } else if (state.isLogonAlreadySent() && state.isLogonTimedOut()) { state.logEvent("Timed out waiting for logon response"); disconnect(); } return; } if (state.getHeartBeatInterval() == 0) { return; } if (state.isLogoutTimedOut()) { state.logEvent("Timed out waiting for logout response"); disconnect(); } if (state.isWithinHeartBeat()) { return; } if (state.isTimedOut()) { state.logEvent("Timed out waiting for heartbeat"); disconnect(); } else { if (state.isTestRequestNeeded()) { generateTestRequest("TEST"); state.incrementTestRequestCounter(); state.logEvent("Sent test request TEST"); } else if (state.isHeartBeatNeeded()) { generateHeartbeat(); } } }
if (state.getHeartBeatInterval() == 0) { return; } if (state.isLogoutTimedOut()) { state.logEvent("Timed out waiting for logout response"); disconnect(); } if (state.isWithinHeartBeat()) { return; } if (state.isTimedOut()) { state.logEvent("Timed out waiting for heartbeat"); disconnect(); } else { if (state.isTestRequestNeeded()) { generateTestRequest("TEST"); state.incrementTestRequestCounter(); state.logEvent("Sent test request TEST"); } else if (state.isHeartBeatNeeded()) { generateHeartbeat(); }
nextQueued(); if (isLoggedOn()) { next();
public synchronized void next() throws IOException { if (!enabled) { if (isLoggedOn()) { if (!state.isLogoutSent()) { state.logEvent("Initiated logout request"); generateLogout(logoutReason); } } else { return; } } if (!checkSessionTime()) { reset(); return; } if (!state.isLogonReceived()) { if (state.isLogonSendNeeded()) { if (generateLogon()) { state.logEvent("Initiated logon request"); } else { state.logEvent("Error during logon request initiation"); } } else if (state.isLogonAlreadySent() && state.isLogonTimedOut()) { state.logEvent("Timed out waiting for logon response"); disconnect(); } return; } if (state.getHeartBeatInterval() == 0) { return; } if (state.isLogoutTimedOut()) { state.logEvent("Timed out waiting for logout response"); disconnect(); } if (state.isWithinHeartBeat()) { return; } if (state.isTimedOut()) { state.logEvent("Timed out waiting for heartbeat"); disconnect(); } else { if (state.isTestRequestNeeded()) { generateTestRequest("TEST"); state.incrementTestRequestCounter(); state.logEvent("Sent test request TEST"); } else if (state.isHeartBeatNeeded()) { generateHeartbeat(); } } }
public String getString(String name, String defaultValue) { String result = getString(name); return (result == null) ? defaultValue : result;
public String getString(String name) { String result = (String) getProperty(name, XMLConstants.XS_STRING_QNAME); if (result == null) return null; result = result.trim(); return (result.length() == 0) ? null : result;
public String getString(String name, String defaultValue) { String result = getString(name); return (result == null) ? defaultValue : result; }
public MatrixValueI evaluate(MatrixNodeI node,MatrixJep mjep) throws ParseException
public MatrixValueI evaluate(MatrixNodeI node,MatrixJep mj) throws ParseException
public MatrixValueI evaluate(MatrixNodeI node,MatrixJep mjep) throws ParseException { this.mjep=mjep; return (MatrixValueI) node.jjtAccept(this,null); }
this.mjep=mjep;
this.mjep=mj;
public MatrixValueI evaluate(MatrixNodeI node,MatrixJep mjep) throws ParseException { this.mjep=mjep; return (MatrixValueI) node.jjtAccept(this,null); }
public void formatValue(Object val,StringBuffer sb)
public void formatValue(Object val,StringBuffer sb1)
public void formatValue(Object val,StringBuffer sb) { if(format != null) { if(val instanceof Number) format.format(val,sb,fp); else if(val instanceof Complex) { if((mode | COMPLEX_I) == COMPLEX_I) sb.append(((Complex) val).toString(format,true)); else sb.append(((Complex) val).toString(format)); } else sb.append(val); } else sb.append(val); }
format.format(val,sb,fp);
format.format(val,sb1,fp);
public void formatValue(Object val,StringBuffer sb) { if(format != null) { if(val instanceof Number) format.format(val,sb,fp); else if(val instanceof Complex) { if((mode | COMPLEX_I) == COMPLEX_I) sb.append(((Complex) val).toString(format,true)); else sb.append(((Complex) val).toString(format)); } else sb.append(val); } else sb.append(val); }
sb.append(((Complex) val).toString(format,true));
sb1.append(((Complex) val).toString(format,true));
public void formatValue(Object val,StringBuffer sb) { if(format != null) { if(val instanceof Number) format.format(val,sb,fp); else if(val instanceof Complex) { if((mode | COMPLEX_I) == COMPLEX_I) sb.append(((Complex) val).toString(format,true)); else sb.append(((Complex) val).toString(format)); } else sb.append(val); } else sb.append(val); }
sb.append(((Complex) val).toString(format));
sb1.append(((Complex) val).toString(format));
public void formatValue(Object val,StringBuffer sb) { if(format != null) { if(val instanceof Number) format.format(val,sb,fp); else if(val instanceof Complex) { if((mode | COMPLEX_I) == COMPLEX_I) sb.append(((Complex) val).toString(format,true)); else sb.append(((Complex) val).toString(format)); } else sb.append(val); } else sb.append(val); }
sb.append(val);
sb1.append(val);
public void formatValue(Object val,StringBuffer sb) { if(format != null) { if(val instanceof Number) format.format(val,sb,fp); else if(val instanceof Complex) { if((mode | COMPLEX_I) == COMPLEX_I) sb.append(((Complex) val).toString(format,true)); else sb.append(((Complex) val).toString(format)); } else sb.append(val); } else sb.append(val); }
else return true;
return true;
private boolean testRight(XOperator top,Node rhs){ if((mode & FULL_BRACKET)!= 0) { return true; } else if(rhs instanceof ASTFunNode && ((ASTFunNode) rhs).isOperator()) { XOperator rhsop = (XOperator) ((ASTFunNode) rhs).getOperator(); if(top == rhsop) { if(top.getBinding() == XOperator.RIGHT // 1=(2=3) -> 1=2=3 || top.isAssociative() ) // 1+(2-3) -> 1+2-3 return false; else return true; // 1-(2+3) -> 1-(2-3) } else if(top.getPrecedence() == rhsop.getPrecedence()) { if(top.getBinding() == XOperator.LEFT && top.isAssociative() ) // 1+(2-3) -> 1+2-3) return false; // a+(b-c) -> a+b-c else return true; // a-(b+c) -> a-(b+c) } else if(top.getPrecedence() > rhsop.getPrecedence()) // 1+(2*3) -> 1+2*3 return false; else return true; } else return false;}
else throw new ParseException("Bad second argument to ele, expecting a double "+param2.toString());
throw new ParseException("Bad second argument to ele, expecting a double "+param2.toString());
public void run(Stack stack) throws ParseException { checkStack(stack); // check the stack Object param1,param2; // get the parameter from the stack param2 = stack.pop(); param1 = stack.pop(); if(param1 instanceof MVector) { if(param2 instanceof Double) { Object val = ((MVector) param1).getEle(((Double) param2).intValue()-1); stack.push(val); return; } else throw new ParseException("Bad second argument to ele, expecting a double "+param2.toString()); } else if(param1 instanceof Matrix) { if(param2 instanceof MVector) { MVector vec = (MVector) param2; if(vec.getDim().equals(Dimensions.TWO)) { Double d1 = (Double) vec.getEle(0); Double d2 = (Double) vec.getEle(1); Object val = ((Matrix) param1).getEle(d1.intValue()-1,d2.intValue()-1); stack.push(val); return; } } else throw new ParseException("Bad second argument to ele, expecting [i,j] "+param2.toString()); } else if(param1 instanceof Tensor) { throw new ParseException("Sorry don't know how to find elements for a tensor"); } throw new ParseException("ele requires a vector matrix or tensor for first argument it has "+param1.toString()); }
public Object getEle(int i,int j)
public Object getEle(int n)
public Object getEle(int i,int j) { return data[i][j]; }
int i = n / cols; int j = n % cols;
public Object getEle(int i,int j) { return data[i][j]; }
rsp.sendRedirect(req.getContextPath()+"/nocacheImages/48x48/"+getBuildStatusUrl());
rsp.sendRedirect2(req.getContextPath()+"/nocacheImages/48x48/"+getBuildStatusUrl());
public void doBuildStatus( StaplerRequest req, StaplerResponse rsp ) throws IOException { // see Hudson.doNocacheImages. this is a work around for a bug in Firefox rsp.sendRedirect(req.getContextPath()+"/nocacheImages/48x48/"+getBuildStatusUrl()); }
req.getView(this,"dir.jsp").forward(req,rsp);
req.getView(this,"dir.jelly").forward(req,rsp);
protected final void serveFile(StaplerRequest req, StaplerResponse rsp, File root, String icon, boolean serveDirIndex) throws IOException, ServletException { if(req.getQueryString()!=null) { req.setCharacterEncoding("UTF-8"); String path = req.getParameter("path"); if(path!=null) { rsp.sendRedirect(URLEncoder.encode(path,"UTF-8")); return; } } String path = req.getRestOfPath(); if(path.length()==0) path = "/"; if(path.indexOf("..")!=-1 || path.length()<1) { // don't serve anything other than files in the artifacts dir rsp.sendError(HttpServletResponse.SC_BAD_REQUEST); return; } File f = new File(root,path.substring(1)); boolean isFingerprint=false; if(f.getName().equals("*fingerprint*")) { f = f.getParentFile(); isFingerprint = true; } if(!f.exists()) { rsp.sendError(HttpServletResponse.SC_NOT_FOUND); return; } if(f.isDirectory()) { if(!req.getRequestURL().toString().endsWith("/")) { rsp.sendRedirect2(req.getRequestURL().append('/').toString()); return; } if(serveDirIndex) { req.setAttribute("it",this); List<Path> parentPaths = buildParentPath(path); req.setAttribute("parentPath",parentPaths); req.setAttribute("topPath", parentPaths.isEmpty() ? "." : repeat("../",parentPaths.size())); req.setAttribute("files",buildChildPathList(f)); req.setAttribute("icon",icon); req.getView(this,"dir.jsp").forward(req,rsp); return; } else { f = new File(f,"index.html"); } } FileInputStream in = new FileInputStream(f); try { if(isFingerprint) { Hudson hudson = Hudson.getInstance(); rsp.forward(hudson.getFingerprint(hudson.getDigestOf(in)),"/",req); } else { // serve the file String contentType = req.getServletContext().getMimeType(f.getPath()); rsp.setContentType(contentType); rsp.setContentLength((int)f.length()); byte[] buf = new byte[1024]; int len; while((len=in.read(buf))>0) rsp.getOutputStream().write(buf,0,len); } } finally { in.close(); } }
Node node = j.parse(str); Node proc = j.preprocess(node); Node simp = j.simplify(proc);
Node node = mj.parse(str); Node proc = mj.preprocess(node); Node simp = mj.simplify(proc);
public static void doStuff(String str) { try { Node node = j.parse(str); Node proc = j.preprocess(node); Node simp = j.simplify(proc); MRpEval rpe = new MRpEval(j); MRpCommandList list = rpe.compile(simp); MRpRes res = rpe.evaluate(list); j.print(node); // conversion to String System.out.println("\nres " + res.toString()); // conversion to MatrixValueI MatrixValueI mat = res.toVecMat(); System.out.println("matrix " + mat.toString()); // conversion to array if(res.getDims().is1D()) { double vecArray[] = (double []) res.toArray(); System.out.print("["); for(int i=0;i<vecArray.length;++i) System.out.print(""+vecArray[i]+" "); System.out.println("]"); } else if(res.getDims().is2D()) { double matArray[][] = (double [][]) res.toArray(); System.out.print("["); for(int i=0;i<matArray.length;++i) { System.out.print("["); for(int j=0;j<matArray[i].length;++j) System.out.print(""+matArray[i][j]+" "); System.out.print("]"); } System.out.println("]"); } // List of commands System.out.println("Commands"); System.out.println(list.toString()); } catch(ParseException e) { System.out.println("Parse error "+e.getMessage()); } catch(Exception e) { System.out.println("evaluation error "+e.getMessage()); e.printStackTrace(); } }
MRpEval rpe = new MRpEval(j);
public static void doStuff(String str) { try { Node node = j.parse(str); Node proc = j.preprocess(node); Node simp = j.simplify(proc); MRpEval rpe = new MRpEval(j); MRpCommandList list = rpe.compile(simp); MRpRes res = rpe.evaluate(list); j.print(node); // conversion to String System.out.println("\nres " + res.toString()); // conversion to MatrixValueI MatrixValueI mat = res.toVecMat(); System.out.println("matrix " + mat.toString()); // conversion to array if(res.getDims().is1D()) { double vecArray[] = (double []) res.toArray(); System.out.print("["); for(int i=0;i<vecArray.length;++i) System.out.print(""+vecArray[i]+" "); System.out.println("]"); } else if(res.getDims().is2D()) { double matArray[][] = (double [][]) res.toArray(); System.out.print("["); for(int i=0;i<matArray.length;++i) { System.out.print("["); for(int j=0;j<matArray[i].length;++j) System.out.print(""+matArray[i][j]+" "); System.out.print("]"); } System.out.println("]"); } // List of commands System.out.println("Commands"); System.out.println(list.toString()); } catch(ParseException e) { System.out.println("Parse error "+e.getMessage()); } catch(Exception e) { System.out.println("evaluation error "+e.getMessage()); e.printStackTrace(); } }
j.print(node);
mj.print(node);
public static void doStuff(String str) { try { Node node = j.parse(str); Node proc = j.preprocess(node); Node simp = j.simplify(proc); MRpEval rpe = new MRpEval(j); MRpCommandList list = rpe.compile(simp); MRpRes res = rpe.evaluate(list); j.print(node); // conversion to String System.out.println("\nres " + res.toString()); // conversion to MatrixValueI MatrixValueI mat = res.toVecMat(); System.out.println("matrix " + mat.toString()); // conversion to array if(res.getDims().is1D()) { double vecArray[] = (double []) res.toArray(); System.out.print("["); for(int i=0;i<vecArray.length;++i) System.out.print(""+vecArray[i]+" "); System.out.println("]"); } else if(res.getDims().is2D()) { double matArray[][] = (double [][]) res.toArray(); System.out.print("["); for(int i=0;i<matArray.length;++i) { System.out.print("["); for(int j=0;j<matArray[i].length;++j) System.out.print(""+matArray[i][j]+" "); System.out.print("]"); } System.out.println("]"); } // List of commands System.out.println("Commands"); System.out.println(list.toString()); } catch(ParseException e) { System.out.println("Parse error "+e.getMessage()); } catch(Exception e) { System.out.println("evaluation error "+e.getMessage()); e.printStackTrace(); } }
j = new MatrixJep(); j.addStandardConstants(); j.addStandardFunctions(); j.addComplex(); j.setAllowUndeclared(true); j.setImplicitMul(true); j.setAllowAssignment(true);
mj = new MatrixJep(); mj.addStandardConstants(); mj.addStandardFunctions(); mj.addComplex(); mj.setAllowUndeclared(true); mj.setImplicitMul(true); mj.setAllowAssignment(true); rpe = new MRpEval(mj);
public static void main(String args[]) { j = new MatrixJep(); j.addStandardConstants(); j.addStandardFunctions(); j.addComplex(); j.setAllowUndeclared(true); j.setImplicitMul(true); j.setAllowAssignment(true); // parse and evaluate each equation in turn doStuff("[1,2,3]"); // Value: [1.0,2.0,3.0] doStuff("[1,2,3].[4,5,6]"); // Value: 32.0 doStuff("[1,2,3]^[4,5,6]"); // Value: [-3.0,6.0,-3.0] doStuff("[1,2,3]+[4,5,6]"); // Value: [5.0,7.0,9.0] doStuff("[[1,2],[3,4]]"); // Value: [[1.0,2.0],[3.0,4.0]] doStuff("[[1,2],[3,4]]*[1,0]"); // Value: [1.0,3.0] doStuff("[1,0]*[[1,2],[3,4]]"); // Value: [1.0,2.0] doStuff("[[1,2],[3,4]]*[[1,2],[3,4]]"); // Value: [[7.0,10.0],[15.0,22.0]] // vectors and matricies can be used with assignment// doStuff("x=[1,2,3]"); // Value: [1.0,2.0,3.0]// doStuff("x+x"); // Value: [2.0,4.0,6.0]// doStuff("x . x"); // Value: 14.0// doStuff("x^x"); // Value: [0.0,0.0,0.0]// doStuff("y=[[1,2],[3,4]]"); // Value: [[1.0,2.0],[3.0,4.0]]// doStuff("y * y"); // Value: [[7.0,10.0],[15.0,22.0]] // accessing the elements on an array or vector// doStuff("ele(x,2)"); // Value: 2.0// doStuff("ele(y,[1,2])"); // Value: 2.0 // using differentation// doStuff("x=2"); // 2.0// doStuff("y=[x^3,x^2,x]"); // [8.0,4.0,2.0]// doStuff("z=diff(y,x)"); // [12.0,4.0,1.0]// doStuff("diff([x^3,x^2,x],x)");// System.out.println("dim(z) "+((MatrixVariableI) j.getVar("z")).getDimensions()); }
doStuff("x=[1,2,3]"); doStuff("x+x"); doStuff("x . x"); doStuff("x^x"); doStuff("y=[[1,2],[3,4]]"); doStuff("y * y");
public static void main(String args[]) { j = new MatrixJep(); j.addStandardConstants(); j.addStandardFunctions(); j.addComplex(); j.setAllowUndeclared(true); j.setImplicitMul(true); j.setAllowAssignment(true); // parse and evaluate each equation in turn doStuff("[1,2,3]"); // Value: [1.0,2.0,3.0] doStuff("[1,2,3].[4,5,6]"); // Value: 32.0 doStuff("[1,2,3]^[4,5,6]"); // Value: [-3.0,6.0,-3.0] doStuff("[1,2,3]+[4,5,6]"); // Value: [5.0,7.0,9.0] doStuff("[[1,2],[3,4]]"); // Value: [[1.0,2.0],[3.0,4.0]] doStuff("[[1,2],[3,4]]*[1,0]"); // Value: [1.0,3.0] doStuff("[1,0]*[[1,2],[3,4]]"); // Value: [1.0,2.0] doStuff("[[1,2],[3,4]]*[[1,2],[3,4]]"); // Value: [[7.0,10.0],[15.0,22.0]] // vectors and matricies can be used with assignment// doStuff("x=[1,2,3]"); // Value: [1.0,2.0,3.0]// doStuff("x+x"); // Value: [2.0,4.0,6.0]// doStuff("x . x"); // Value: 14.0// doStuff("x^x"); // Value: [0.0,0.0,0.0]// doStuff("y=[[1,2],[3,4]]"); // Value: [[1.0,2.0],[3.0,4.0]]// doStuff("y * y"); // Value: [[7.0,10.0],[15.0,22.0]] // accessing the elements on an array or vector// doStuff("ele(x,2)"); // Value: 2.0// doStuff("ele(y,[1,2])"); // Value: 2.0 // using differentation// doStuff("x=2"); // 2.0// doStuff("y=[x^3,x^2,x]"); // [8.0,4.0,2.0]// doStuff("z=diff(y,x)"); // [12.0,4.0,1.0]// doStuff("diff([x^3,x^2,x],x)");// System.out.println("dim(z) "+((MatrixVariableI) j.getVar("z")).getDimensions()); }
public final MRpCommandList compile(Node node) throws ParseException
public final MRpCommandList compile(MatrixVariableI var,Node node) throws ParseException
public final MRpCommandList compile(Node node) throws ParseException { curCommandList = new MRpCommandList(); node.jjtAccept(this,null); scalerStore.alloc(); v2Store.alloc(); v3Store.alloc(); v4Store.alloc(); vnStore.alloc(); m22Store.alloc(); m23Store.alloc(); m24Store.alloc(); m32Store.alloc(); m33Store.alloc(); m34Store.alloc(); m42Store.alloc(); m43Store.alloc(); m44Store.alloc(); mnnStore.alloc(); Dimensions dims = ((MatrixNodeI) node).getDim(); curCommandList.setFinalType(getDimType(dims));// returnObj = Tensor.getInstance(dims);// if(dims.is2D())// returnMat = (Matrix) returnObj; return curCommandList; }
curCommandList = new MRpCommandList(); node.jjtAccept(this,null); scalerStore.alloc(); v2Store.alloc(); v3Store.alloc(); v4Store.alloc(); vnStore.alloc(); m22Store.alloc(); m23Store.alloc(); m24Store.alloc(); m32Store.alloc(); m33Store.alloc(); m34Store.alloc(); m42Store.alloc(); m43Store.alloc(); m44Store.alloc(); mnnStore.alloc(); Dimensions dims = ((MatrixNodeI) node).getDim(); curCommandList.setFinalType(getDimType(dims)); return curCommandList;
MRpCommandList list = compile(node); ObjStore store = getStoreByDim(var.getDimensions()); short vRef = (short) store.addVar(var); store.decStack(); list.addCommand(ASSIGN,getDimType(var.getDimensions()),vRef); return list;
public final MRpCommandList compile(Node node) throws ParseException { curCommandList = new MRpCommandList(); node.jjtAccept(this,null); scalerStore.alloc(); v2Store.alloc(); v3Store.alloc(); v4Store.alloc(); vnStore.alloc(); m22Store.alloc(); m23Store.alloc(); m24Store.alloc(); m32Store.alloc(); m33Store.alloc(); m34Store.alloc(); m42Store.alloc(); m43Store.alloc(); m44Store.alloc(); mnnStore.alloc(); Dimensions dims = ((MatrixNodeI) node).getDim(); curCommandList.setFinalType(getDimType(dims));// returnObj = Tensor.getInstance(dims);// if(dims.is2D())// returnMat = (Matrix) returnObj; return curCommandList; }
Operator tens = ((MatrixOperatorSet) opSet).getMTensorFun();
this.parser.setInitialTokenManagerState(Parser.NO_DOT_IN_IDENTIFIERS); Operator tens = ((MatrixOperatorSet) opSet).getMList();
public MatrixJep() { super(); nf = new MatrixNodeFactory(); symTab = new DSymbolTable(mvf); opSet = new MatrixOperatorSet(); /* Operator.OP_ADD.setPFMC(new MAdd()); Operator.OP_SUBTRACT.setPFMC(new MSubtract()); Operator.OP_MULTIPLY.setPFMC(new MMultiply()); Operator.OP_POWER.setPFMC(new MPower()); Operator.OP_UMINUS.setPFMC(new MUMinus()); Operator.OP_DOT.setPFMC(new MDot()); Operator.OP_CROSS.setPFMC(new ExteriorProduct()); Operator.OP_ASSIGN.setPFMC(new Assignment());*/ Operator tens = ((MatrixOperatorSet) opSet).getMTensorFun(); pv.addSpecialRule(tens,(PrintVisitor.PrintRulesI) tens.getPFMC()); dv.addDiffRule(new PassThroughDiffRule(tens.getName(),tens.getPFMC())); }
dv.addDiffRule(new PassThroughDiffRule(tens.getName(),tens.getPFMC()));
addDiffRule(new PassThroughDiffRule(tens.getName(),tens.getPFMC())); Operator cross = ((MatrixOperatorSet) opSet).getCross(); addDiffRule(new MultiplyDiffRule(cross.getName(),cross)); Operator dot = ((MatrixOperatorSet) opSet).getDot(); addDiffRule(new MultiplyDiffRule(dot.getName(),dot));
public MatrixJep() { super(); nf = new MatrixNodeFactory(); symTab = new DSymbolTable(mvf); opSet = new MatrixOperatorSet(); /* Operator.OP_ADD.setPFMC(new MAdd()); Operator.OP_SUBTRACT.setPFMC(new MSubtract()); Operator.OP_MULTIPLY.setPFMC(new MMultiply()); Operator.OP_POWER.setPFMC(new MPower()); Operator.OP_UMINUS.setPFMC(new MUMinus()); Operator.OP_DOT.setPFMC(new MDot()); Operator.OP_CROSS.setPFMC(new ExteriorProduct()); Operator.OP_ASSIGN.setPFMC(new Assignment());*/ Operator tens = ((MatrixOperatorSet) opSet).getMTensorFun(); pv.addSpecialRule(tens,(PrintVisitor.PrintRulesI) tens.getPFMC()); dv.addDiffRule(new PassThroughDiffRule(tens.getName(),tens.getPFMC())); }
super.addFunction("ele",new Ele());
public void addStandardFunctions() { super.addStandardFunctions(); this.getFunctionTable().remove("if"); this.getFunctionTable().put("if",new MIf()); }
backupFile(maltsFile);
public void writeFermentables(ArrayList newIngr, boolean[] add) { File maltsFile = new File(dbPath, "malts.csv"); try { CSVWriter writer = new CSVWriter(new FileWriter(maltsFile)); writer.put("Item"); writer.put("Name"); writer.put("Yield"); writer.put("Lov"); writer.put("Cost"); writer.put("Stock"); writer.put("Units"); writer.put("Mash"); writer.put("Descr"); writer.put("Steep"); writer.put("Modified"); writer.nl(); int i = 0, j = 0, k = 0; while (i < fermDB.size() || j < newIngr.size()) { Fermentable f = null; if (i < fermDB.size()) { f = (Fermentable) fermDB.get(i); i++; } else if (j < newIngr.size()) { if (newIngr.get(j).getClass().getName().equals("ca.strangebrew.Fermentable") && add[j]){ f = (Fermentable) newIngr.get(j); } j++; } if (f != null) { k++; writer.put("" + (k)); writer.put(f.getName()); writer.put("" + f.getPppg()); writer.put("" + f.getLov()); writer.put("" + f.getCostPerU()); writer.put("" + f.getStock()); writer.put(f.getUnitsAbrv()); writer.put("" + f.getMashed()); writer.put(f.getDescription()); writer.put("" + f.getSteep()); writer.put("" + f.getModified()); writer.nl(); } } writer.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
backupFile(hopsFile);
public void writeHops(ArrayList newIngr, boolean[] add) { if (!(newIngr.size() > 0)) return; File hopsFile = new File(dbPath, "hops.csv"); try { CSVWriter writer = new CSVWriter(new FileWriter(hopsFile)); writer.put("Item"); writer.put("Name"); writer.put("Alpha"); writer.put("Cost"); writer.put("Stock"); writer.put("Units"); writer.put("Descr"); writer.put("Storage"); writer.put("Date"); writer.put("Modified"); writer.nl(); int i = 0, j = 0, k = 0; while (i < hopsDB.size() || j < newIngr.size()) { Hop h = null; if (i < hopsDB.size()) { h = (Hop) hopsDB.get(i); i++; } else if (j < newIngr.size()) { if (newIngr.get(j).getClass().getName().equals("ca.strangebrew.Hop") && add[j]){ h = (Hop) newIngr.get(j); } j++; } if (h != null) { k++; writer.put("" + (k)); writer.put(h.getName()); writer.put("" + h.getAlpha()); writer.put("" + h.getCostPerU()); writer.put("" + h.getStock()); writer.put(h.getUnitsAbrv()); writer.put(h.getDescription()); writer.put("" + h.getStorage()); writer.put("" + h.getDate()); writer.put("" + h.getModified()); writer.nl(); } } writer.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
backupFile(miscFile);
public void writeMisc(ArrayList newIngr, boolean[] add) { if (!(newIngr.size() > 0)) return; File miscFile = new File(dbPath, "misc_ingr.csv"); try { CSVWriter writer = new CSVWriter(new FileWriter(miscFile)); writer.put("ITEM"); writer.put("NAME"); writer.put("COST"); writer.put("DESCR"); writer.put("UNITS"); writer.put("STAGE"); writer.put("Modified"); writer.nl(); int i = 0, j = 0, k = 0; while (i < miscDB.size() || j < newIngr.size()) { Misc m = null; if (i < miscDB.size()) { m = (Misc) miscDB.get(i); i++; } else if (j < newIngr.size()) { if (newIngr.get(j).getClass().getName().equals("ca.strangebrew.Misc") && add[j]){ m = (Misc) newIngr.get(j); } j++; } if (m != null) { k++; writer.put("" + (k)); writer.put(m.getName()); writer.put("" + m.getCostPerU()); writer.put(m.getDescription()); writer.put(m.getUnitsAbrv()); writer.put(m.getStage()); writer.put("" + m.getModified()); writer.nl(); } } writer.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
backupFile(yeastFile);
public void writeYeast(ArrayList newIngr, boolean[] add) { if (!(newIngr.size() > 0)) return; File yeastFile = new File(dbPath, "yeast.csv"); try { CSVWriter writer = new CSVWriter(new FileWriter(yeastFile)); writer.put("Item"); writer.put("Name"); writer.put("Cost"); writer.put("Descr"); writer.put("Modified"); writer.nl(); int i = 0, j = 0, k = 0; while (i < yeastDB.size() || j < newIngr.size()) { Yeast y = null; if (i < yeastDB.size()) { y = (Yeast) yeastDB.get(i); i++; } else if (j < newIngr.size()) { if (newIngr.get(j).getClass().getName().equals("ca.strangebrew.Yeast") && add[j]){ y = (Yeast) newIngr.get(j); } j++; } if (y != null) { k++; writer.put("" + (k)); writer.put(y.getName()); writer.put("" + y.getCostPerU()); writer.put(y.getDescription()); writer.put("" + y.getModified()); writer.nl(); } } writer.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
public Fermentable(){ setName(""); pppg = 0; lov = 0; setAmount(1.0); setUnits("pounds");
public Fermentable(String n, double p, double l, double a, String u) { setName(n); pppg = p; lov = l; setAmount(a); setUnits(u);
public Fermentable(){ // default constructor setName(""); pppg = 0; lov = 0; setAmount(1.0); setUnits("pounds"); mashed = true; // I want to get options working sometime, // but can't figure out how: // myOptions.getProperty("optMaltUnits"); }
public Partner(Entity entity, String alias, char state, boolean strong) { this.entity = entity; this.alias = alias; this.state = state; this.strong = strong;
public Partner() {
public Partner(Entity entity, String alias, char state, boolean strong) { this.entity = entity; this.alias = alias; this.state = state; this.strong = strong; }
seismograms.put(seis, ampConfig.getAmpRange(seis));
public void addSeismogram(DataSetSeismogram seis){ ampConfig.addSeismogram(seis); seismograms.put(seis, ampConfig.getAmpRange(seis)); }
seismograms.remove(seis);
public void removeSeismogram(DataSetSeismogram seis){ ampConfig.removeSeismogram(seis); seismograms.remove(seis); }
seismograms = ampConfig.getSeismograms();
public void setAmpConfig(AmpRangeConfig ampConfig){ ampConfig.removeAmpSyncListener(this); Iterator e = seismograms.keySet().iterator(); while(e.hasNext()){ DataSetSeismogram current = (DataSetSeismogram)e.next(); ampConfig.addSeismogram(current); seismograms.put(current, ampConfig.getAmpRange(current)); } ampConfig.addAmpSyncListener(this); this.ampConfig = ampConfig; updateAmpSyncListeners(); }
userRole.setUser(new User());
userRole.setUserGroup(new UserGroup()); userRole.setUserGroup(new User());
public void testUserRole() { UserRole userRole = new UserRole(); userRole.setId(Long.MAX_VALUE); userRole.setId(Long.MIN_VALUE); userRole.setUser(new User()); userRole.setService(new Service()); userRole.setServiceExtension(""); }
userRole.setUser(new User());
userRole.setUserGroup(new UserGroup());
public void testUserRoleEquals() { UserRole copy, userRole = new UserRole(); userRole.setUser(new User()); userRole.setService(new Service()); copy = (UserRole) DomainTestSupport.minimalEqualsTest(userRole); copy.setUser(userRole.getUser()); assertFalse(userRole.equals(copy)); copy.setUser(null); copy.setService(userRole.getService()); assertFalse(userRole.equals(copy)); copy.setUser(userRole.getUser()); copy.setService(userRole.getService()); assertTrue(userRole.equals(copy)); }
copy.setUser(userRole.getUser());
copy.setUserGroup(userRole.getUserGroup());
public void testUserRoleEquals() { UserRole copy, userRole = new UserRole(); userRole.setUser(new User()); userRole.setService(new Service()); copy = (UserRole) DomainTestSupport.minimalEqualsTest(userRole); copy.setUser(userRole.getUser()); assertFalse(userRole.equals(copy)); copy.setUser(null); copy.setService(userRole.getService()); assertFalse(userRole.equals(copy)); copy.setUser(userRole.getUser()); copy.setService(userRole.getService()); assertTrue(userRole.equals(copy)); }
copy.setUser(null);
copy.setUserGroup(null);
public void testUserRoleEquals() { UserRole copy, userRole = new UserRole(); userRole.setUser(new User()); userRole.setService(new Service()); copy = (UserRole) DomainTestSupport.minimalEqualsTest(userRole); copy.setUser(userRole.getUser()); assertFalse(userRole.equals(copy)); copy.setUser(null); copy.setService(userRole.getService()); assertFalse(userRole.equals(copy)); copy.setUser(userRole.getUser()); copy.setService(userRole.getService()); assertTrue(userRole.equals(copy)); }
public Contact(Partner partner, Credential credential, int internalNumber, int priority) { this.partner = partner; this.credential = credential; this.internalNumber = internalNumber; this.priority = priority;
public Contact() {
public Contact(Partner partner, Credential credential, int internalNumber, int priority) { this.partner = partner; this.credential = credential; this.internalNumber = internalNumber; this.priority = priority; }
public Controller(View aView) {
public Controller(View aView, Recipe aRecipe) {
public Controller(View aView) { myView = aView; aView.setController(this); }
myRecipe = aRecipe;
public Controller(View aView) { myView = aView; aView.setController(this); }
public void addStep(){ MashStep step = new MashStep(); steps.add(step);
public void addStep(String type, double st, double et, String m, int min, int rmin, double weight) { MashStep step = new MashStep(type, st, et, m, min, rmin); if (m.equals("cereal mash")) step.weightLbs = weight; steps.add(step);
public void addStep(){ MashStep step = new MashStep(); steps.add(step); calcMashSchedule(); }
return fToC(((MashStep)steps.get(i)).getStartTemp());
return BrewCalcs.fToC(((MashStep)steps.get(i)).getStartTemp());
public double getStepStartTemp(int i) { if (tempUnits.equals("C")) return fToC(((MashStep)steps.get(i)).getStartTemp()); else return ((MashStep)steps.get(i)).getStartTemp(); }
return fToC(((MashStep)steps.get(i)).getEndTemp());
return BrewCalcs.fToC(((MashStep)steps.get(i)).getEndTemp());
public double getStepEndTemp(int i) { if (tempUnits.equals("C")) return fToC(((MashStep)steps.get(i)).getEndTemp()); else return ((MashStep)steps.get(i)).getEndTemp(); }
t = cToF(t);
t = BrewCalcs.cToF(t);
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(); }
((MashStep)steps.get(i)).setEndTemp(cToF(t));
((MashStep)steps.get(i)).setEndTemp(BrewCalcs.cToF(t));
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(); }
currentTemp = cToF(currentTemp);
currentTemp = BrewCalcs.cToF(currentTemp);
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++; } } }
strikeTemp = fToC(strikeTemp);
strikeTemp = BrewCalcs.fToC(strikeTemp);
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++; } } }
displTemp = fToC(displTemp);
displTemp = BrewCalcs.fToC(displTemp);
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++; } } }
strikeTemp = fToC(strikeTemp); cerealTemp = fToC(cerealTemp); targetTemp = fToC(targetTemp); cerealTargTemp = fToC(cerealTargTemp);
strikeTemp = BrewCalcs.fToC(strikeTemp); cerealTemp = BrewCalcs.fToC(cerealTemp); targetTemp = BrewCalcs.fToC(targetTemp); cerealTargTemp = BrewCalcs.fToC(cerealTargTemp);
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++; } } }
tempStr = SBStringUtils.format(fToC(SPARGETMPF), 1) + "C";
tempStr = SBStringUtils.format(BrewCalcs.fToC(SPARGETMPF), 1) + "C";
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 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 { stack.push(symTab.get(node.getName())); }
public Object visit(SimpleNode node, Object 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; }
Map<String,String> previousRevisions = parseRevisionFile(build.getPreviousBuild());
Map<String,Integer> previousRevisions = parseRevisionFile(build.getPreviousBuild());
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; }
String prevRev = previousRevisions.get(module);
Integer prevRev = previousRevisions.get(module);
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; }
String cmd = DESCRIPTOR.getSvnExe()+" log -v --xml --non-interactive -r "+prevRev+":BASE "+module;
String cmd = DESCRIPTOR.getSvnExe()+" log -v --xml --non-interactive -r "+(prevRev+1)+":BASE "+module;
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; }
static Map<String,String> parseRevisionFile(Build build) throws IOException { Map<String,String> revisions = new HashMap<String,String>();
static Map<String,Integer> parseRevisionFile(Build build) throws IOException { Map<String,Integer> revisions = new HashMap<String,Integer>();
/*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; }
revisions.put(line.substring(0,index), line.substring(index+1));
try { revisions.put(line.substring(0,index), Integer.parseInt(line.substring(index+1))); } catch (NumberFormatException e) { }
/*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; }
public Node getChild(int i)
public Node getChild()
public Node getChild(int i) { return (Node)m_children.get(i); }
return (Node)m_children.get(i);
if (getNumberChildren() == 0) return null; return getChild(0);
public Node getChild(int i) { return (Node)m_children.get(i); }
assertEquals(stat.executeUpdate("create temp table in1000 (a);"), 0);
assertEquals(stat.executeUpdate("create table in1000 (a);"), 0);
@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); }
return scm.parse(changelogFile);
return scm.parse(this,changelogFile);
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; }
else if(num != num) return new Double(Double.NaN);
public Object ln(Object param) throws ParseException { if (param instanceof Complex) { return ((Complex)param).log(); } else if (param instanceof Number) { // Now returns Complex if param is <0 double num = ((Number) param).doubleValue(); if( num > 0) return new Double(Math.log(num)); else { Complex temp = new Complex(num); return temp.log(); } } throw new ParseException("Invalid parameter type"); }
public Complex(double re_in) { re = re_in;
public Complex() { re = 0;
public Complex(double re_in) { re = re_in; im = 0; }
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; }
return mychannelchooser.getChannelId(keyStr);
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; } }
debug = false;
public EvaluatorVisitor() { errorList = null; stack = new Stack(); }
log.debug("removing gateway attribute from session");
protected void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response, final FilterChain filterChain) throws IOException, ServletException { final HttpSession session = request.getSession(isUseSession()); final String ticket = request.getParameter(PARAM_TICKET); final Assertion assertion = session != null ? (Assertion) session .getAttribute(CONST_ASSERTION) : null; final boolean wasGatewayed = session != null && session.getAttribute(CONST_GATEWAY) != null; if (CommonUtils.isBlank(ticket) && assertion == null && !wasGatewayed) { if (this.gateway && session != null) { session.setAttribute(CONST_GATEWAY, "yes"); } final String serviceUrl = constructServiceUrl(request, response); final String urlToRedirectTo = this.casServerLoginUrl + "?service=" + URLEncoder.encode(serviceUrl, "UTF-8") + (this.renew ? "&renew=true" : "") + (this.gateway ? "&gateway=true" : ""); response.sendRedirect(urlToRedirectTo); return; } if (session != null) { session.setAttribute(CONST_GATEWAY, null); } filterChain.doFilter(request, response); }
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) { this(serverName, serviceUrl, true);
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; }
maltTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); TableColumn col = mtcm.getColumn(0); col.setPreferredWidth(10); col = mtcm.getColumn(1); col.setPreferredWidth(10); col = mtcm.getColumn(2); col.setPreferredWidth(200); maltTable.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
private void addColumnWidthListeners() { TableColumnModel mtcm = maltTable.getColumnModel(); TableColumnModel htcm = hopsTable.getColumnModel(); //: listener that watches the width of a column PropertyChangeListener mpcl = new PropertyChangeListener() { private int columnCount = maltTable.getColumnCount(); private int[] width = new int[columnCount]; public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("preferredWidth")) { TableColumnModel tcm = maltTable.getColumnModel(); TableColumnModel tcmt = tblMaltTotals.getColumnModel(); int colCount = tcm.getColumnCount(); // for each column, get its width for (int i = 0; i < colCount; i++) { tcmt.getColumn(i).setPreferredWidth(tcm.getColumn(i).getPreferredWidth()); } } } }; //: listener that watches the width of a column PropertyChangeListener hpcl = new PropertyChangeListener() { private int columnCount = hopsTable.getColumnCount(); private int[] width = new int[columnCount]; public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("preferredWidth")) { TableColumnModel tcm = hopsTable.getColumnModel(); TableColumnModel tcmt = tblHopsTotals.getColumnModel(); int colCount = tcm.getColumnCount(); // for each column, get its width for (int i = 0; i < colCount; i++) { tcmt.getColumn(i).setPreferredWidth(tcm.getColumn(i).getPreferredWidth()); } } } }; //: add the column width lister to each column for (Enumeration e = mtcm.getColumns(); e.hasMoreElements();) { TableColumn tc = (TableColumn) e.nextElement(); tc.addPropertyChangeListener(mpcl); } //: add the column width lister to each column for (Enumeration e = htcm.getColumns(); e.hasMoreElements();) { TableColumn tc = (TableColumn) e.nextElement(); tc.addPropertyChangeListener(hpcl); } }
tblMaltTotalsModel.setDataVector(new String[][]{{"Totals:",
tblMaltTotalsModel.setDataVector(new String[][]{{"", "", "Totals:",
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(); }
Costs, "100"}}, new String[]{"",
Costs, "100"}}, new String[]{"", "", "",
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(); }
TableColumn maltColumn = maltTable.getColumnModel().getColumn(0);
TableColumn maltColumn = maltTable.getColumnModel().getColumn(2);
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(); } }
maltColumn = maltTable.getColumnModel().getColumn(1);
maltColumn = maltTable.getColumnModel().getColumn(3);
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(); } }
maltColumn = maltTable.getColumnModel().getColumn(2);
maltColumn = maltTable.getColumnModel().getColumn(4);
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(); } }
new String[]{"Malt", "Amount", "Units", "Points", "Lov",
new String[]{"S", "M", "Malt", "Amount", "Units", "Points", "Lov",
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(); } }
while (i < list.size() && !found) { if (DEBUG) System.out.println(o.getClass().getName().toString()); if (o.getClass().getName().toString().equals( "strangebrew.Yeast")) {
while (i < list.size() && !found) { if (o.getClass().getName().toString().equals("ca.strangebrew.Yeast")) {
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); }
} else if (o.getClass().getName().toString().equals("strangebrew.Fermentable")) {
} else if (o.getClass().getName().toString().equals("ca.strangebrew.Fermentable")) {
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); }
} else if (o.getClass().getName().toString().equals("strangebrew.Hop")) {
} else if (o.getClass().getName().toString().equals("ca.strangebrew.Hop")) {
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); }
} else if (o.getClass().getName().toString().equals("strangebrew.Style")) {
} else if (o.getClass().getName().toString().equals("ca.strangebrew.Style")) {
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); }
else selected = list.get(i-1);
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); }
totalMaltCost += m.getCostPerU() * m.getAmountAs("lb");
totalMaltCost += m.getCostPerU() * m.getAmountAs(m.getUnits());
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)); }
totalHopsCost += h.getCostPerU() * h.getAmountAs("oz");
totalHopsCost += h.getCostPerU() * h.getAmountAs(h.getUnits());
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 setStyle(Style s) { style = s;
public void setStyle(String s) { style.setName(s);
public void setStyle(Style s) { style = s; }
return "";
return colourMethod;
public String getColourMethod() { return ""; }
tunLossTxt.setText(new Double(myRecipe.mash.getTunLoss()).toString());
tunLossTxt.setText(SBStringUtils.format(myRecipe.mash.getTunLoss(), 1));
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 StylePanel(StrangeSwing.SBNotifier sb) {
public StylePanel() {
public StylePanel(StrangeSwing.SBNotifier sb) { super(); sbn = sb; initGUI(); }
sbn = sb;
public StylePanel(StrangeSwing.SBNotifier sb) { super(); sbn = sb; initGUI(); }
loadRecipes(currentDir);
public FindDialog(JFrame frame) { super(frame); recipes = new ArrayList(); files = new ArrayList(); inst = (StrangeSwing) frame; currentDir = new java.io.File("."); initGUI(); dirLocationText.setText(currentDir.getAbsolutePath()); // loadRecipes(currentDir); }
return getPlottableSimple(seis, ampRange, tr, size);
return getPlottableSimpl(seis, ampRange, tr, size);
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; }
else return super.umin(param1);
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); }
public MVector(int size) { data = new Object[size]; dim = Dimensions.valueOf(size); }
private MVector() {}
public MVector(int size) { data = new Object[size]; dim = Dimensions.valueOf(size); }
public Tensor(Tensor t) { values = new Object[t.getDim().numEles()]; this.dims = t.getDim(); }
private Tensor() {}
public Tensor(Tensor t) { values = new Object[t.getDim().numEles()]; this.dims = t.getDim(); }
((PostfixMathCommand)jep.funTab.get(identString)).getNumberOfParameters();
((PostfixMathCommandI)jep.funTab.get(identString)).getNumberOfParameters();
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); } } }
public FissuresNamingServiceImpl (java.util.Properties props) throws org.omg.CORBA.ORBPackage.InvalidName{
public FissuresNamingServiceImpl (java.util.Properties props) throws 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(); } }
try { orb = (org.omg.CORBA_2_3.ORB)org.omg.CORBA.ORB.init(args, props); AllVTFactory vt = new AllVTFactory(); vt.register(orb);
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(); } }
org.omg.CORBA.Object rootObj = orb.resolve_initial_references("NameService"); if (rootObj == null) { logger.info("Name service object is null!"); return; } namingContext = NamingContextExtHelper.narrow(rootObj); logger.info("got Name context");
orb = (org.omg.CORBA_2_3.ORB)org.omg.CORBA.ORB.init(args, props);
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(); } }