rem
stringlengths
0
477k
add
stringlengths
0
313k
context
stringlengths
6
599k
if(result!=null) {
if(!isBuilding()) {
public String getIconColor() { if(result!=null) { // already built if(result==Result.SUCCESS) return "blue"; if(result== Result.UNSTABLE) return "yellow"; else return "red"; } // a new build is in progress String baseColor; if(previousBuild==null) baseColor = "grey"; else baseColor = previousBuild.getIconColor(); return baseColor +"_anime"; }
if(useUpdate && isUpdatable(workspace.getLocal(),listener)) {
if(useUpdate && isUpdatable(workspace,listener)) {
public boolean checkout(Build build, Launcher launcher, FilePath workspace, BuildListener listener, File changelogFile) throws IOException { boolean result; if(useUpdate && isUpdatable(workspace.getLocal(),listener)) { result = update(launcher,workspace,listener); if(!result) return false; } else { workspace.deleteContents(); StringTokenizer tokens = new StringTokenizer(modules); while(tokens.hasMoreTokens()) { ArgumentListBuilder cmd = new ArgumentListBuilder(); cmd.add(DESCRIPTOR.getSvnExe(),"co","-q","--non-interactive"); if(username!=null) cmd.add("--username",username); if(otherOptions!=null) cmd.add(Util.tokenize(otherOptions)); cmd.add(tokens.nextToken()); result = run(launcher,cmd,listener,workspace); if(!result) return false; } } // write out the revision file PrintWriter w = new PrintWriter(new FileOutputStream(getRevisionFile(build))); try { Map<String,SvnInfo> revMap = buildRevisionMap(workspace,listener); for (Entry<String,SvnInfo> e : revMap.entrySet()) { w.println( e.getKey() +'/'+ e.getValue().revision ); } } finally { w.close(); } return calcChangeLog(build, changelogFile, launcher, listener); }
private boolean isUpdatable(File dir,BuildListener listener) {
private boolean isUpdatable(FilePath workspace,BuildListener listener) {
private boolean isUpdatable(File dir,BuildListener listener) { StringTokenizer tokens = new StringTokenizer(modules); while(tokens.hasMoreTokens()) { String url = tokens.nextToken(); File module = new File(dir,getLastPathComponent(url)); File svn = new File(module,".svn/entries"); if(!svn.exists()) { listener.getLogger().println("Checking out a fresh workspace because "+svn+" doesn't exist."); return false; } // check wc-entries/entry/@url synchronized(spf) { try { SAXParser parser = spf.newSAXParser(); Checker checker = new Checker(url); parser.parse(svn,checker); if(!checker.found()) { listener.getLogger().println("Checking out a fresh workspace because the workspace is not "+url); return false; } } catch (ParserConfigurationException e) { // impossible throw new Error(e); } catch (SAXException e) { // corrupt file? don't use update to be safe failedToParse(listener, svn, e); return false; } catch (IOException e) { // corrupt file? don't use update to be safe failedToParse(listener, svn, e); return false; } } } return true; }
File module = new File(dir,getLastPathComponent(url)); File svn = new File(module,".svn/entries"); if(!svn.exists()) { listener.getLogger().println("Checking out a fresh workspace because "+svn+" doesn't exist."); return false; }
String moduleName = getLastPathComponent(url); File module = workspace.child(url).getLocal();
private boolean isUpdatable(File dir,BuildListener listener) { StringTokenizer tokens = new StringTokenizer(modules); while(tokens.hasMoreTokens()) { String url = tokens.nextToken(); File module = new File(dir,getLastPathComponent(url)); File svn = new File(module,".svn/entries"); if(!svn.exists()) { listener.getLogger().println("Checking out a fresh workspace because "+svn+" doesn't exist."); return false; } // check wc-entries/entry/@url synchronized(spf) { try { SAXParser parser = spf.newSAXParser(); Checker checker = new Checker(url); parser.parse(svn,checker); if(!checker.found()) { listener.getLogger().println("Checking out a fresh workspace because the workspace is not "+url); return false; } } catch (ParserConfigurationException e) { // impossible throw new Error(e); } catch (SAXException e) { // corrupt file? don't use update to be safe failedToParse(listener, svn, e); return false; } catch (IOException e) { // corrupt file? don't use update to be safe failedToParse(listener, svn, e); return false; } } } return true; }
synchronized(spf) { try { SAXParser parser = spf.newSAXParser(); Checker checker = new Checker(url); parser.parse(svn,checker); if(!checker.found()) { listener.getLogger().println("Checking out a fresh workspace because the workspace is not "+url); return false; } } catch (ParserConfigurationException e) { throw new Error(e); } catch (SAXException e) { failedToParse(listener, svn, e); return false; } catch (IOException e) { failedToParse(listener, svn, e);
try { SvnInfo svnInfo = SvnInfo.parse(moduleName, createEnvVarMap(false), workspace, listener); if(!svnInfo.url.equals(url)) { listener.getLogger().println("Checking out a fresh workspace because the workspace is not "+url);
private boolean isUpdatable(File dir,BuildListener listener) { StringTokenizer tokens = new StringTokenizer(modules); while(tokens.hasMoreTokens()) { String url = tokens.nextToken(); File module = new File(dir,getLastPathComponent(url)); File svn = new File(module,".svn/entries"); if(!svn.exists()) { listener.getLogger().println("Checking out a fresh workspace because "+svn+" doesn't exist."); return false; } // check wc-entries/entry/@url synchronized(spf) { try { SAXParser parser = spf.newSAXParser(); Checker checker = new Checker(url); parser.parse(svn,checker); if(!checker.found()) { listener.getLogger().println("Checking out a fresh workspace because the workspace is not "+url); return false; } } catch (ParserConfigurationException e) { // impossible throw new Error(e); } catch (SAXException e) { // corrupt file? don't use update to be safe failedToParse(listener, svn, e); return false; } catch (IOException e) { // corrupt file? don't use update to be safe failedToParse(listener, svn, e); return false; } } } return true; }
} catch (IOException e) { listener.getLogger().println("Checking out a fresh workspace because Hudson failed to detect the current workspace "+module); e.printStackTrace(listener.error(e.getMessage()));
private boolean isUpdatable(File dir,BuildListener listener) { StringTokenizer tokens = new StringTokenizer(modules); while(tokens.hasMoreTokens()) { String url = tokens.nextToken(); File module = new File(dir,getLastPathComponent(url)); File svn = new File(module,".svn/entries"); if(!svn.exists()) { listener.getLogger().println("Checking out a fresh workspace because "+svn+" doesn't exist."); return false; } // check wc-entries/entry/@url synchronized(spf) { try { SAXParser parser = spf.newSAXParser(); Checker checker = new Checker(url); parser.parse(svn,checker); if(!checker.found()) { listener.getLogger().println("Checking out a fresh workspace because the workspace is not "+url); return false; } } catch (ParserConfigurationException e) { // impossible throw new Error(e); } catch (SAXException e) { // corrupt file? don't use update to be safe failedToParse(listener, svn, e); return false; } catch (IOException e) { // corrupt file? don't use update to be safe failedToParse(listener, svn, e); return false; } } } return true; }
className = cn; testName = testCase.attributeValue("name");
className = cn.replace('/','_'); testName = testCase.attributeValue("name").replace('/','_');
CaseResult(SuiteResult parent, Element testCase) { String cn = testCase.attributeValue("classname"); if(cn==null) // Maven seems to skip classname, and that shows up in testSuite/@name cn = parent.getName(); className = cn; testName = testCase.attributeValue("name"); errorStackTrace = getError(testCase); }
myOpenFileDialog.open(); return myOpenFileDialog.getFilterPath().concat("/").concat( myOpenFileDialog.getFileName());
return myOpenFileDialog.open();
public String getOpenFilename() { myOpenFileDialog.open(); return myOpenFileDialog.getFilterPath().concat("/").concat( myOpenFileDialog.getFileName()); }
else if(num != num) return new Double(Double.NaN);
public Object log(Object param) throws ParseException { if (param instanceof Complex) { return ((Complex)param).log().div(CLOG10); } else if (param instanceof Number) { double num = ((Number) param).doubleValue(); if( num > 0) return new Double(Math.log(num)/LOG10); else { Complex temp = new Complex(num); return temp.log().div(CLOG10); } } throw new ParseException("Invalid parameter type"); }
if(req.getQueryString()!=null) { String path = req.getParameter("path"); if(path!=null) { rsp.sendRedirect(path); return; } }
public synchronized void doWs( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException { serveFile(req, rsp, getWorkspace(), true); }
File[] files = f.listFiles(); Arrays.sort(files,FILE_SORTER); req.setAttribute("files",files);
req.setAttribute("parentPath",buildParentPath(path)); req.setAttribute("files",buildChildPathList(f));
private void serveFile(StaplerRequest req, StaplerResponse rsp, File root, boolean serveDirIndex) throws IOException, ServletException { 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)); if(!f.exists()) { rsp.sendError(HttpServletResponse.SC_NOT_FOUND); return; } if(f.isDirectory()) { if(!req.getRequestURL().toString().endsWith("/")) { rsp.sendRedirect(req.getRequestURL().append('/').toString()); return; } if(serveDirIndex) { req.setAttribute("it",this); File[] files = f.listFiles(); Arrays.sort(files,FILE_SORTER); req.setAttribute("files",files); req.getView(this,"workspaceDir.jsp").forward(req,rsp); return; } else { f = new File(f,"index.html"); } } FileInputStream in = new FileInputStream(f); // serve the file rsp.setContentType(req.getServletContext().getMimeType(req.getServletPath())); rsp.setContentLength((int)f.length()); byte[] buf = new byte[1024]; int len; while((len=in.read(buf))>0) rsp.getOutputStream().write(buf,0,len); in.close(); }
public void persistPersonalData(PersonalData personalData);
public void persistPersonalData(SecureUserDetails secureUserDetails);
public void persistPersonalData(PersonalData personalData);
plottableDisplay.setSelectedRectangle(prevx, prevy, me.getX(), me.getY());
public void mouseReleased(MouseEvent me) { plottableDisplay.setSelectedRectangle(prevx, prevy, me.getX(), me.getY()); }
setName( job.getJobName() );
setName( job.getJobName() + "-W" + Integer.toHexString( hashCode() ) );
public void run() { Job job = null; activeThreads ++; while(true) { synchronized( ThreadPool.this ) { long startedWaiting = System.currentTimeMillis(); // As long as no jobs are waiting, check to see if it's time to end this thread. while( jobs.isEmpty() ) { // if inactive for too long then give up long timePassed = System.currentTimeMillis() - startedWaiting; long timeLeft = suicideTime - timePassed; if( timeLeft < 0 ) { activeThreads --; return; } try { // wait for a job until we should really be dying ThreadPool.this.wait(timeLeft); } catch (InterruptedException ie) { // don't care why - lets loop till we have something to do } } if( askedToStop ) { activeThreads --; return; } job = jobs.removeFirst(); } try { job.associateThread( this ); setName( job.getJobName() ); job.getRunnable().run(); } catch (Throwable t) { NLogger.error( NLoggerNames.GLOBAL, t, t); } finally { job.releaseAssociateThread(); } setName( "ThreadPool.Worker-" + Integer.toHexString( hashCode() ) ); } }
public short getHasUploadedFlag()
public short getHasUploadedFlag() throws InvalidMessageException
public short getHasUploadedFlag() { parseBody(); return hasUploadedFlag; }
public short getPushNeededFlag()
public short getPushNeededFlag() throws InvalidMessageException
public short getPushNeededFlag() { parseBody(); return pushNeededFlag; }
public DestAddress[] getPushProxyAddresses()
public DestAddress[] getPushProxyAddresses() throws InvalidMessageException
public DestAddress[] getPushProxyAddresses() { parseBody(); return pushProxyAddresses; }
public long getRemoteHostSpeed()
public long getRemoteHostSpeed() throws InvalidMessageException
public long getRemoteHostSpeed() { parseBody(); return remoteHostSpeed; }
public short getServerBusyFlag()
public short getServerBusyFlag() throws InvalidMessageException
public short getServerBusyFlag() { parseBody(); return serverBusyFlag; }
public short getUniqueResultCount()
public short getUniqueResultCount() throws InvalidMessageException
public short getUniqueResultCount() { parseBody(); return uniqueResultCount; }
public short getUploadSpeedFlag()
public short getUploadSpeedFlag() throws InvalidMessageException
public short getUploadSpeedFlag() { parseBody(); return uploadSpeedFlag; }
public String getVendorCode()
public String getVendorCode() throws InvalidMessageException
public String getVendorCode() { parseBody(); return vendorCode; }
public boolean isBrowseHostSupported()
public boolean isBrowseHostSupported() throws InvalidMessageException
public boolean isBrowseHostSupported() { parseBody(); return isBrowseHostSupported; }
public boolean isChatSupported()
public boolean isChatSupported() throws InvalidMessageException
public boolean isChatSupported() { parseBody(); return isChatSupported; }
private boolean isVendorCodeValid( String vendorCode )
private static boolean isVendorCodeValid( String vendorCode )
private boolean isVendorCodeValid( String vendorCode ) { // verify length if ( vendorCode.length() != 4 ) { return false; } // verify characters for ( int i = 0; i < 4; i++ ) { if ( !XMLUtils.isXmlChar( vendorCode.charAt( i ) ) ) { return false; } } return true; }
try
long speed = IOUtil.unsignedInt2Long( IOUtil.deserializeIntLE(body, offset) ); remoteHostSpeed = speed; offset += 4; uniqueResultCount = 0; Set<URN> uniqueURNs = new HashSet<URN>(); records = new QueryResponseRecord[ recordCount ]; int highestAltLocCount = 0; for (int i = 0; i < recordCount; i++)
private void parseBody() { if ( isParsed ) { return; } // Already read the header. int offset = 0; byte n = body[offset++]; short recordCount = (short)(n < 0 ? 256 + n : n); // parsing of port and ip is done on demand in getHostAddress() and // getHostIP() offset += 2; // skip port offset += 4; // skip ip try { long speed = IOUtil.unsignedInt2Long( IOUtil.deserializeIntLE(body, offset) ); remoteHostSpeed = speed; offset += 4; uniqueResultCount = 0; Set<URN> uniqueURNs = new HashSet<URN>(); records = new QueryResponseRecord[ recordCount ]; for (int i = 0; i < recordCount; i++) { QueryResponseRecord rec = new QueryResponseRecord(); offset = rec.deserialize(body, offset); if ( NLogger.isWarnEnabled( QueryResponseMsg.class ) && rec.getAlternateLocations() != null && rec.getAlternateLocations().length > 15 ) { NLogger.warn( QueryResponseMsg.class, "QueryRespRecord with " + rec.getAlternateLocations().length + " alt locs..." ); } records[ i ] = rec; URN urn = rec.getURN(); if ( urn != null ) { uniqueURNs.add( urn ); } else { uniqueResultCount ++; } } uniqueResultCount += uniqueURNs.size(); // Handle Bearshare meta informations. The format is documented in // the GnutellaProtocol04.pdf document pushNeededFlag = QHD_UNKNOWN_FLAG; serverBusyFlag = QHD_UNKNOWN_FLAG; hasUploadedFlag = QHD_UNKNOWN_FLAG; uploadSpeedFlag = QHD_UNKNOWN_FLAG; // GGEP extensions isBrowseHostSupported = false; if ( offset <= (getHeader().getDataLength() - 16 - 4 - 2) ) { // parse meta data // Use ISO encoding for two bytes characters on some platforms. vendorCode = new String( body, offset, 4, "ISO-8859-1"); if ( !isVendorCodeValid( vendorCode ) ) { String hexVendorCode = HexConverter.toHexString( body, offset, 4 ); NLogger.warn(QueryResponseMsg.class, getHeader().getFromHost() + ": Illegal QHD vendor code found: " + vendorCode + " (" + hexVendorCode + "). Body: " + HexConverter.toHexString( body ) ); vendorCode = hexVendorCode; } offset += 4; int openDataLength = IOUtil.unsignedByte2int( body[ offset ] ); offset += 1; // parse upload speed, have uploaded, busy and push if ( openDataLength > 1) { // if we have a flag byte byte flag1 = body[ offset ]; byte flag2 = body[ offset + 1]; // check if push flag is meaningfull do it reversed from other checks if ( ( flag2 & PUSH_NEEDED_MASK ) != 0 ) { if ( ( flag1 & PUSH_NEEDED_MASK ) != 0 ) { pushNeededFlag = QHD_TRUE_FLAG; } else { pushNeededFlag = QHD_FALSE_FLAG; } } // check if server busy flag meaningfull if ((flag1 & SERVER_BUSY_MASK) != 0) { if ( (flag2 & SERVER_BUSY_MASK) != 0 ) { serverBusyFlag = QHD_TRUE_FLAG; } else { serverBusyFlag = QHD_FALSE_FLAG; } } // check if the uploaded flag is meaningfull if ((flag1 & HAS_UPLOADED_MASK) != 0) { if ( (flag2 & HAS_UPLOADED_MASK) != 0 ) { hasUploadedFlag = QHD_TRUE_FLAG; } else { hasUploadedFlag = QHD_FALSE_FLAG; } } if ((flag1 & UPLOAD_SPEED_MASK) != 0 ) { if ( (flag2 & UPLOAD_SPEED_MASK) != 0 ) { uploadSpeedFlag = QHD_TRUE_FLAG; } else { uploadSpeedFlag = QHD_FALSE_FLAG; } } if ((flag1 & GGEP_MASK) != 0 && (flag2 & GGEP_MASK) !=0 ) {// parse GGEP area should follow after open data area but // we can't be sure... int ggepMagicIndex = offset + 2; // search for real magic index while ( ggepMagicIndex < body.length ) { if ( body[ ggepMagicIndex ] == GGEPBlock.MAGIC_NUMBER ) { // found index! break; } ggepMagicIndex ++; } GGEPBlock[] ggepBlocks = null; try { // if there are GGEPs, see if Browse Host supported... ggepBlocks = GGEPBlock.parseGGEPBlocks( body, ggepMagicIndex ); isBrowseHostSupported = GGEPBlock.isExtensionHeaderInBlocks( ggepBlocks, GGEPBlock.BROWSE_HOST_HEADER_ID ); pushProxyAddresses = GGEPExtension.parsePushProxyExtensionData( ggepBlocks ); } catch ( InvalidGGEPBlockException exp ) {// ignore and continue parsing... NLogger.debug(QueryResponseMsg.class, exp, exp ); } } } // skip unknown open data length offset += openDataLength; //Parse private area of Limewire and Shareaza to read out chat //flag. If chatflag is 0x1 chat is supported, if 0x0 its not. int privateDataLength = body.length - offset - 16; if ( privateDataLength > 0 && ( vendorCode.equals("LIME") || vendorCode.equals("RAZA") || vendorCode.equals("PHEX") ) ) { byte flag = body[ offset ]; isChatSupported = ( flag & CHAT_SUPPORTED_MASK ) != 0; } //System.out.println( (mHeader.getDataLen() -16 - 4 -2) + " " + offset + " " + // /*new String( body, offset, mHeader.getDataLen() - offset) + " " +*/ // openDataLength + " " + pushNeededFlag + " " + serverBusyFlag + " " + // uploadSpeedFlag + " " + hasUploadedFlag + " " + vendorCode ); } parseRemoteClientID(); isParsed = true; } catch ( java.io.UnsupportedEncodingException exp ) { return; } }
long speed = IOUtil.unsignedInt2Long( IOUtil.deserializeIntLE(body, offset) ); remoteHostSpeed = speed;
QueryResponseRecord rec = new QueryResponseRecord(); offset = rec.deserialize(body, offset); if ( rec.getAlternateLocations() != null ) { highestAltLocCount = Math.max(highestAltLocCount, rec.getAlternateLocations().length); if ( NLogger.isWarnEnabled( QueryResponseMsg.class ) && rec.getAlternateLocations().length > 15 ) { NLogger.warn( QueryResponseMsg.class, "QueryRespRecord with " + rec.getAlternateLocations().length + " alt locs" + " - file: " + rec.getFilename() ); } } records[ i ] = rec; URN urn = rec.getURN(); if ( urn != null ) { uniqueURNs.add( urn ); } else { uniqueResultCount ++; } } uniqueResultCount += uniqueURNs.size(); pushNeededFlag = QHD_UNKNOWN_FLAG; serverBusyFlag = QHD_UNKNOWN_FLAG; hasUploadedFlag = QHD_UNKNOWN_FLAG; uploadSpeedFlag = QHD_UNKNOWN_FLAG; isBrowseHostSupported = false; if ( offset <= (getHeader().getDataLength() - 16 - 4 - 2) ) { try { vendorCode = new String( body, offset, 4, "ISO-8859-1"); } catch ( UnsupportedEncodingException exp ) { NLogger.error(NLoggerNames.GLOBAL, exp ); throw new RuntimeException( exp ); } if ( NLogger.isWarnEnabled( QueryResponseMsg.class ) && highestAltLocCount > 15 ) { NLogger.warn( QueryResponseMsg.class, "QueryRespRecord with " + highestAltLocCount + " alt locs" + " - vendor: " +vendorCode ); } if ( !isVendorCodeValid( vendorCode ) ) { String hexVendorCode = HexConverter.toHexString( body, offset, 4 ); NLogger.warn(QueryResponseMsg.class, getHeader().getFromHost() + ": Illegal QHD vendor code found: " + vendorCode + " (" + hexVendorCode + "). Body: " + HexConverter.toHexString( body ) ); vendorCode = hexVendorCode; }
private void parseBody() { if ( isParsed ) { return; } // Already read the header. int offset = 0; byte n = body[offset++]; short recordCount = (short)(n < 0 ? 256 + n : n); // parsing of port and ip is done on demand in getHostAddress() and // getHostIP() offset += 2; // skip port offset += 4; // skip ip try { long speed = IOUtil.unsignedInt2Long( IOUtil.deserializeIntLE(body, offset) ); remoteHostSpeed = speed; offset += 4; uniqueResultCount = 0; Set<URN> uniqueURNs = new HashSet<URN>(); records = new QueryResponseRecord[ recordCount ]; for (int i = 0; i < recordCount; i++) { QueryResponseRecord rec = new QueryResponseRecord(); offset = rec.deserialize(body, offset); if ( NLogger.isWarnEnabled( QueryResponseMsg.class ) && rec.getAlternateLocations() != null && rec.getAlternateLocations().length > 15 ) { NLogger.warn( QueryResponseMsg.class, "QueryRespRecord with " + rec.getAlternateLocations().length + " alt locs..." ); } records[ i ] = rec; URN urn = rec.getURN(); if ( urn != null ) { uniqueURNs.add( urn ); } else { uniqueResultCount ++; } } uniqueResultCount += uniqueURNs.size(); // Handle Bearshare meta informations. The format is documented in // the GnutellaProtocol04.pdf document pushNeededFlag = QHD_UNKNOWN_FLAG; serverBusyFlag = QHD_UNKNOWN_FLAG; hasUploadedFlag = QHD_UNKNOWN_FLAG; uploadSpeedFlag = QHD_UNKNOWN_FLAG; // GGEP extensions isBrowseHostSupported = false; if ( offset <= (getHeader().getDataLength() - 16 - 4 - 2) ) { // parse meta data // Use ISO encoding for two bytes characters on some platforms. vendorCode = new String( body, offset, 4, "ISO-8859-1"); if ( !isVendorCodeValid( vendorCode ) ) { String hexVendorCode = HexConverter.toHexString( body, offset, 4 ); NLogger.warn(QueryResponseMsg.class, getHeader().getFromHost() + ": Illegal QHD vendor code found: " + vendorCode + " (" + hexVendorCode + "). Body: " + HexConverter.toHexString( body ) ); vendorCode = hexVendorCode; } offset += 4; int openDataLength = IOUtil.unsignedByte2int( body[ offset ] ); offset += 1; // parse upload speed, have uploaded, busy and push if ( openDataLength > 1) { // if we have a flag byte byte flag1 = body[ offset ]; byte flag2 = body[ offset + 1]; // check if push flag is meaningfull do it reversed from other checks if ( ( flag2 & PUSH_NEEDED_MASK ) != 0 ) { if ( ( flag1 & PUSH_NEEDED_MASK ) != 0 ) { pushNeededFlag = QHD_TRUE_FLAG; } else { pushNeededFlag = QHD_FALSE_FLAG; } } // check if server busy flag meaningfull if ((flag1 & SERVER_BUSY_MASK) != 0) { if ( (flag2 & SERVER_BUSY_MASK) != 0 ) { serverBusyFlag = QHD_TRUE_FLAG; } else { serverBusyFlag = QHD_FALSE_FLAG; } } // check if the uploaded flag is meaningfull if ((flag1 & HAS_UPLOADED_MASK) != 0) { if ( (flag2 & HAS_UPLOADED_MASK) != 0 ) { hasUploadedFlag = QHD_TRUE_FLAG; } else { hasUploadedFlag = QHD_FALSE_FLAG; } } if ((flag1 & UPLOAD_SPEED_MASK) != 0 ) { if ( (flag2 & UPLOAD_SPEED_MASK) != 0 ) { uploadSpeedFlag = QHD_TRUE_FLAG; } else { uploadSpeedFlag = QHD_FALSE_FLAG; } } if ((flag1 & GGEP_MASK) != 0 && (flag2 & GGEP_MASK) !=0 ) {// parse GGEP area should follow after open data area but // we can't be sure... int ggepMagicIndex = offset + 2; // search for real magic index while ( ggepMagicIndex < body.length ) { if ( body[ ggepMagicIndex ] == GGEPBlock.MAGIC_NUMBER ) { // found index! break; } ggepMagicIndex ++; } GGEPBlock[] ggepBlocks = null; try { // if there are GGEPs, see if Browse Host supported... ggepBlocks = GGEPBlock.parseGGEPBlocks( body, ggepMagicIndex ); isBrowseHostSupported = GGEPBlock.isExtensionHeaderInBlocks( ggepBlocks, GGEPBlock.BROWSE_HOST_HEADER_ID ); pushProxyAddresses = GGEPExtension.parsePushProxyExtensionData( ggepBlocks ); } catch ( InvalidGGEPBlockException exp ) {// ignore and continue parsing... NLogger.debug(QueryResponseMsg.class, exp, exp ); } } } // skip unknown open data length offset += openDataLength; //Parse private area of Limewire and Shareaza to read out chat //flag. If chatflag is 0x1 chat is supported, if 0x0 its not. int privateDataLength = body.length - offset - 16; if ( privateDataLength > 0 && ( vendorCode.equals("LIME") || vendorCode.equals("RAZA") || vendorCode.equals("PHEX") ) ) { byte flag = body[ offset ]; isChatSupported = ( flag & CHAT_SUPPORTED_MASK ) != 0; } //System.out.println( (mHeader.getDataLen() -16 - 4 -2) + " " + offset + " " + // /*new String( body, offset, mHeader.getDataLen() - offset) + " " +*/ // openDataLength + " " + pushNeededFlag + " " + serverBusyFlag + " " + // uploadSpeedFlag + " " + hasUploadedFlag + " " + vendorCode ); } parseRemoteClientID(); isParsed = true; } catch ( java.io.UnsupportedEncodingException exp ) { return; } }
uniqueResultCount = 0; Set<URN> uniqueURNs = new HashSet<URN>(); records = new QueryResponseRecord[ recordCount ]; for (int i = 0; i < recordCount; i++) { QueryResponseRecord rec = new QueryResponseRecord(); offset = rec.deserialize(body, offset); if ( NLogger.isWarnEnabled( QueryResponseMsg.class ) && rec.getAlternateLocations() != null && rec.getAlternateLocations().length > 15 ) { NLogger.warn( QueryResponseMsg.class, "QueryRespRecord with " + rec.getAlternateLocations().length + " alt locs..." ); } records[ i ] = rec; URN urn = rec.getURN(); if ( urn != null ) { uniqueURNs.add( urn ); } else { uniqueResultCount ++; } } uniqueResultCount += uniqueURNs.size(); pushNeededFlag = QHD_UNKNOWN_FLAG; serverBusyFlag = QHD_UNKNOWN_FLAG; hasUploadedFlag = QHD_UNKNOWN_FLAG; uploadSpeedFlag = QHD_UNKNOWN_FLAG; isBrowseHostSupported = false; if ( offset <= (getHeader().getDataLength() - 16 - 4 - 2) ) { vendorCode = new String( body, offset, 4, "ISO-8859-1"); if ( !isVendorCodeValid( vendorCode ) ) { String hexVendorCode = HexConverter.toHexString( body, offset, 4 ); NLogger.warn(QueryResponseMsg.class, getHeader().getFromHost() + ": Illegal QHD vendor code found: " + vendorCode + " (" + hexVendorCode + "). Body: " + HexConverter.toHexString( body ) ); vendorCode = hexVendorCode; } offset += 4; int openDataLength = IOUtil.unsignedByte2int( body[ offset ] ); offset += 1; if ( openDataLength > 1) { byte flag1 = body[ offset ]; byte flag2 = body[ offset + 1]; if ( ( flag2 & PUSH_NEEDED_MASK ) != 0 ) { if ( ( flag1 & PUSH_NEEDED_MASK ) != 0 )
int openDataLength = IOUtil.unsignedByte2int( body[ offset ] ); offset += 1; if ( openDataLength > 1) { byte flag1 = body[ offset ]; byte flag2 = body[ offset + 1]; if ( ( flag2 & PUSH_NEEDED_MASK ) != 0 ) { if ( ( flag1 & PUSH_NEEDED_MASK ) != 0 ) { pushNeededFlag = QHD_TRUE_FLAG; } else { pushNeededFlag = QHD_FALSE_FLAG; } } if ((flag1 & SERVER_BUSY_MASK) != 0) { if ( (flag2 & SERVER_BUSY_MASK) != 0 ) { serverBusyFlag = QHD_TRUE_FLAG; } else { serverBusyFlag = QHD_FALSE_FLAG; } } if ((flag1 & HAS_UPLOADED_MASK) != 0) { if ( (flag2 & HAS_UPLOADED_MASK) != 0 ) { hasUploadedFlag = QHD_TRUE_FLAG; } else { hasUploadedFlag = QHD_FALSE_FLAG; } } if ((flag1 & UPLOAD_SPEED_MASK) != 0 ) { if ( (flag2 & UPLOAD_SPEED_MASK) != 0 ) { uploadSpeedFlag = QHD_TRUE_FLAG; } else { uploadSpeedFlag = QHD_FALSE_FLAG; } } if ((flag1 & GGEP_MASK) != 0 && (flag2 & GGEP_MASK) !=0 ) { int ggepMagicIndex = offset + 2; while ( ggepMagicIndex < body.length ) { if ( body[ ggepMagicIndex ] == GGEPBlock.MAGIC_NUMBER )
private void parseBody() { if ( isParsed ) { return; } // Already read the header. int offset = 0; byte n = body[offset++]; short recordCount = (short)(n < 0 ? 256 + n : n); // parsing of port and ip is done on demand in getHostAddress() and // getHostIP() offset += 2; // skip port offset += 4; // skip ip try { long speed = IOUtil.unsignedInt2Long( IOUtil.deserializeIntLE(body, offset) ); remoteHostSpeed = speed; offset += 4; uniqueResultCount = 0; Set<URN> uniqueURNs = new HashSet<URN>(); records = new QueryResponseRecord[ recordCount ]; for (int i = 0; i < recordCount; i++) { QueryResponseRecord rec = new QueryResponseRecord(); offset = rec.deserialize(body, offset); if ( NLogger.isWarnEnabled( QueryResponseMsg.class ) && rec.getAlternateLocations() != null && rec.getAlternateLocations().length > 15 ) { NLogger.warn( QueryResponseMsg.class, "QueryRespRecord with " + rec.getAlternateLocations().length + " alt locs..." ); } records[ i ] = rec; URN urn = rec.getURN(); if ( urn != null ) { uniqueURNs.add( urn ); } else { uniqueResultCount ++; } } uniqueResultCount += uniqueURNs.size(); // Handle Bearshare meta informations. The format is documented in // the GnutellaProtocol04.pdf document pushNeededFlag = QHD_UNKNOWN_FLAG; serverBusyFlag = QHD_UNKNOWN_FLAG; hasUploadedFlag = QHD_UNKNOWN_FLAG; uploadSpeedFlag = QHD_UNKNOWN_FLAG; // GGEP extensions isBrowseHostSupported = false; if ( offset <= (getHeader().getDataLength() - 16 - 4 - 2) ) { // parse meta data // Use ISO encoding for two bytes characters on some platforms. vendorCode = new String( body, offset, 4, "ISO-8859-1"); if ( !isVendorCodeValid( vendorCode ) ) { String hexVendorCode = HexConverter.toHexString( body, offset, 4 ); NLogger.warn(QueryResponseMsg.class, getHeader().getFromHost() + ": Illegal QHD vendor code found: " + vendorCode + " (" + hexVendorCode + "). Body: " + HexConverter.toHexString( body ) ); vendorCode = hexVendorCode; } offset += 4; int openDataLength = IOUtil.unsignedByte2int( body[ offset ] ); offset += 1; // parse upload speed, have uploaded, busy and push if ( openDataLength > 1) { // if we have a flag byte byte flag1 = body[ offset ]; byte flag2 = body[ offset + 1]; // check if push flag is meaningfull do it reversed from other checks if ( ( flag2 & PUSH_NEEDED_MASK ) != 0 ) { if ( ( flag1 & PUSH_NEEDED_MASK ) != 0 ) { pushNeededFlag = QHD_TRUE_FLAG; } else { pushNeededFlag = QHD_FALSE_FLAG; } } // check if server busy flag meaningfull if ((flag1 & SERVER_BUSY_MASK) != 0) { if ( (flag2 & SERVER_BUSY_MASK) != 0 ) { serverBusyFlag = QHD_TRUE_FLAG; } else { serverBusyFlag = QHD_FALSE_FLAG; } } // check if the uploaded flag is meaningfull if ((flag1 & HAS_UPLOADED_MASK) != 0) { if ( (flag2 & HAS_UPLOADED_MASK) != 0 ) { hasUploadedFlag = QHD_TRUE_FLAG; } else { hasUploadedFlag = QHD_FALSE_FLAG; } } if ((flag1 & UPLOAD_SPEED_MASK) != 0 ) { if ( (flag2 & UPLOAD_SPEED_MASK) != 0 ) { uploadSpeedFlag = QHD_TRUE_FLAG; } else { uploadSpeedFlag = QHD_FALSE_FLAG; } } if ((flag1 & GGEP_MASK) != 0 && (flag2 & GGEP_MASK) !=0 ) {// parse GGEP area should follow after open data area but // we can't be sure... int ggepMagicIndex = offset + 2; // search for real magic index while ( ggepMagicIndex < body.length ) { if ( body[ ggepMagicIndex ] == GGEPBlock.MAGIC_NUMBER ) { // found index! break; } ggepMagicIndex ++; } GGEPBlock[] ggepBlocks = null; try { // if there are GGEPs, see if Browse Host supported... ggepBlocks = GGEPBlock.parseGGEPBlocks( body, ggepMagicIndex ); isBrowseHostSupported = GGEPBlock.isExtensionHeaderInBlocks( ggepBlocks, GGEPBlock.BROWSE_HOST_HEADER_ID ); pushProxyAddresses = GGEPExtension.parsePushProxyExtensionData( ggepBlocks ); } catch ( InvalidGGEPBlockException exp ) {// ignore and continue parsing... NLogger.debug(QueryResponseMsg.class, exp, exp ); } } } // skip unknown open data length offset += openDataLength; //Parse private area of Limewire and Shareaza to read out chat //flag. If chatflag is 0x1 chat is supported, if 0x0 its not. int privateDataLength = body.length - offset - 16; if ( privateDataLength > 0 && ( vendorCode.equals("LIME") || vendorCode.equals("RAZA") || vendorCode.equals("PHEX") ) ) { byte flag = body[ offset ]; isChatSupported = ( flag & CHAT_SUPPORTED_MASK ) != 0; } //System.out.println( (mHeader.getDataLen() -16 - 4 -2) + " " + offset + " " + // /*new String( body, offset, mHeader.getDataLen() - offset) + " " +*/ // openDataLength + " " + pushNeededFlag + " " + serverBusyFlag + " " + // uploadSpeedFlag + " " + hasUploadedFlag + " " + vendorCode ); } parseRemoteClientID(); isParsed = true; } catch ( java.io.UnsupportedEncodingException exp ) { return; } }
pushNeededFlag = QHD_TRUE_FLAG;
break;
private void parseBody() { if ( isParsed ) { return; } // Already read the header. int offset = 0; byte n = body[offset++]; short recordCount = (short)(n < 0 ? 256 + n : n); // parsing of port and ip is done on demand in getHostAddress() and // getHostIP() offset += 2; // skip port offset += 4; // skip ip try { long speed = IOUtil.unsignedInt2Long( IOUtil.deserializeIntLE(body, offset) ); remoteHostSpeed = speed; offset += 4; uniqueResultCount = 0; Set<URN> uniqueURNs = new HashSet<URN>(); records = new QueryResponseRecord[ recordCount ]; for (int i = 0; i < recordCount; i++) { QueryResponseRecord rec = new QueryResponseRecord(); offset = rec.deserialize(body, offset); if ( NLogger.isWarnEnabled( QueryResponseMsg.class ) && rec.getAlternateLocations() != null && rec.getAlternateLocations().length > 15 ) { NLogger.warn( QueryResponseMsg.class, "QueryRespRecord with " + rec.getAlternateLocations().length + " alt locs..." ); } records[ i ] = rec; URN urn = rec.getURN(); if ( urn != null ) { uniqueURNs.add( urn ); } else { uniqueResultCount ++; } } uniqueResultCount += uniqueURNs.size(); // Handle Bearshare meta informations. The format is documented in // the GnutellaProtocol04.pdf document pushNeededFlag = QHD_UNKNOWN_FLAG; serverBusyFlag = QHD_UNKNOWN_FLAG; hasUploadedFlag = QHD_UNKNOWN_FLAG; uploadSpeedFlag = QHD_UNKNOWN_FLAG; // GGEP extensions isBrowseHostSupported = false; if ( offset <= (getHeader().getDataLength() - 16 - 4 - 2) ) { // parse meta data // Use ISO encoding for two bytes characters on some platforms. vendorCode = new String( body, offset, 4, "ISO-8859-1"); if ( !isVendorCodeValid( vendorCode ) ) { String hexVendorCode = HexConverter.toHexString( body, offset, 4 ); NLogger.warn(QueryResponseMsg.class, getHeader().getFromHost() + ": Illegal QHD vendor code found: " + vendorCode + " (" + hexVendorCode + "). Body: " + HexConverter.toHexString( body ) ); vendorCode = hexVendorCode; } offset += 4; int openDataLength = IOUtil.unsignedByte2int( body[ offset ] ); offset += 1; // parse upload speed, have uploaded, busy and push if ( openDataLength > 1) { // if we have a flag byte byte flag1 = body[ offset ]; byte flag2 = body[ offset + 1]; // check if push flag is meaningfull do it reversed from other checks if ( ( flag2 & PUSH_NEEDED_MASK ) != 0 ) { if ( ( flag1 & PUSH_NEEDED_MASK ) != 0 ) { pushNeededFlag = QHD_TRUE_FLAG; } else { pushNeededFlag = QHD_FALSE_FLAG; } } // check if server busy flag meaningfull if ((flag1 & SERVER_BUSY_MASK) != 0) { if ( (flag2 & SERVER_BUSY_MASK) != 0 ) { serverBusyFlag = QHD_TRUE_FLAG; } else { serverBusyFlag = QHD_FALSE_FLAG; } } // check if the uploaded flag is meaningfull if ((flag1 & HAS_UPLOADED_MASK) != 0) { if ( (flag2 & HAS_UPLOADED_MASK) != 0 ) { hasUploadedFlag = QHD_TRUE_FLAG; } else { hasUploadedFlag = QHD_FALSE_FLAG; } } if ((flag1 & UPLOAD_SPEED_MASK) != 0 ) { if ( (flag2 & UPLOAD_SPEED_MASK) != 0 ) { uploadSpeedFlag = QHD_TRUE_FLAG; } else { uploadSpeedFlag = QHD_FALSE_FLAG; } } if ((flag1 & GGEP_MASK) != 0 && (flag2 & GGEP_MASK) !=0 ) {// parse GGEP area should follow after open data area but // we can't be sure... int ggepMagicIndex = offset + 2; // search for real magic index while ( ggepMagicIndex < body.length ) { if ( body[ ggepMagicIndex ] == GGEPBlock.MAGIC_NUMBER ) { // found index! break; } ggepMagicIndex ++; } GGEPBlock[] ggepBlocks = null; try { // if there are GGEPs, see if Browse Host supported... ggepBlocks = GGEPBlock.parseGGEPBlocks( body, ggepMagicIndex ); isBrowseHostSupported = GGEPBlock.isExtensionHeaderInBlocks( ggepBlocks, GGEPBlock.BROWSE_HOST_HEADER_ID ); pushProxyAddresses = GGEPExtension.parsePushProxyExtensionData( ggepBlocks ); } catch ( InvalidGGEPBlockException exp ) {// ignore and continue parsing... NLogger.debug(QueryResponseMsg.class, exp, exp ); } } } // skip unknown open data length offset += openDataLength; //Parse private area of Limewire and Shareaza to read out chat //flag. If chatflag is 0x1 chat is supported, if 0x0 its not. int privateDataLength = body.length - offset - 16; if ( privateDataLength > 0 && ( vendorCode.equals("LIME") || vendorCode.equals("RAZA") || vendorCode.equals("PHEX") ) ) { byte flag = body[ offset ]; isChatSupported = ( flag & CHAT_SUPPORTED_MASK ) != 0; } //System.out.println( (mHeader.getDataLen() -16 - 4 -2) + " " + offset + " " + // /*new String( body, offset, mHeader.getDataLen() - offset) + " " +*/ // openDataLength + " " + pushNeededFlag + " " + serverBusyFlag + " " + // uploadSpeedFlag + " " + hasUploadedFlag + " " + vendorCode ); } parseRemoteClientID(); isParsed = true; } catch ( java.io.UnsupportedEncodingException exp ) { return; } }
else { pushNeededFlag = QHD_FALSE_FLAG; } } if ((flag1 & SERVER_BUSY_MASK) != 0) { if ( (flag2 & SERVER_BUSY_MASK) != 0 ) { serverBusyFlag = QHD_TRUE_FLAG; } else { serverBusyFlag = QHD_FALSE_FLAG; } } if ((flag1 & HAS_UPLOADED_MASK) != 0) { if ( (flag2 & HAS_UPLOADED_MASK) != 0 ) { hasUploadedFlag = QHD_TRUE_FLAG; } else { hasUploadedFlag = QHD_FALSE_FLAG; } } if ((flag1 & UPLOAD_SPEED_MASK) != 0 ) { if ( (flag2 & UPLOAD_SPEED_MASK) != 0 ) { uploadSpeedFlag = QHD_TRUE_FLAG; } else { uploadSpeedFlag = QHD_FALSE_FLAG; } } if ((flag1 & GGEP_MASK) != 0 && (flag2 & GGEP_MASK) !=0 ) { int ggepMagicIndex = offset + 2; while ( ggepMagicIndex < body.length ) { if ( body[ ggepMagicIndex ] == GGEPBlock.MAGIC_NUMBER ) { break; } ggepMagicIndex ++; } GGEPBlock[] ggepBlocks = null; try { ggepBlocks = GGEPBlock.parseGGEPBlocks( body, ggepMagicIndex ); isBrowseHostSupported = GGEPBlock.isExtensionHeaderInBlocks( ggepBlocks, GGEPBlock.BROWSE_HOST_HEADER_ID ); pushProxyAddresses = GGEPExtension.parsePushProxyExtensionData( ggepBlocks ); } catch ( InvalidGGEPBlockException exp ) { NLogger.debug(QueryResponseMsg.class, exp, exp ); } } } offset += openDataLength; int privateDataLength = body.length - offset - 16; if ( privateDataLength > 0 && ( vendorCode.equals("LIME") || vendorCode.equals("RAZA") || vendorCode.equals("PHEX") ) ) { byte flag = body[ offset ]; isChatSupported = ( flag & CHAT_SUPPORTED_MASK ) != 0; } } parseRemoteClientID(); isParsed = true;
ggepMagicIndex ++; } GGEPBlock[] ggepBlocks = null; try { ggepBlocks = GGEPBlock.parseGGEPBlocks( body, ggepMagicIndex ); isBrowseHostSupported = GGEPBlock.isExtensionHeaderInBlocks( ggepBlocks, GGEPBlock.BROWSE_HOST_HEADER_ID ); pushProxyAddresses = GGEPExtension.parsePushProxyExtensionData( ggepBlocks ); } catch ( InvalidGGEPBlockException exp ) { NLogger.debug(QueryResponseMsg.class, exp, exp ); } } } offset += openDataLength; int privateDataLength = body.length - offset - 16; if ( privateDataLength > 0 && ( vendorCode.equals("LIME") || vendorCode.equals("RAZA") || vendorCode.equals("PHEX") ) ) { byte flag = body[ offset ]; isChatSupported = ( flag & CHAT_SUPPORTED_MASK ) != 0; }
private void parseBody() { if ( isParsed ) { return; } // Already read the header. int offset = 0; byte n = body[offset++]; short recordCount = (short)(n < 0 ? 256 + n : n); // parsing of port and ip is done on demand in getHostAddress() and // getHostIP() offset += 2; // skip port offset += 4; // skip ip try { long speed = IOUtil.unsignedInt2Long( IOUtil.deserializeIntLE(body, offset) ); remoteHostSpeed = speed; offset += 4; uniqueResultCount = 0; Set<URN> uniqueURNs = new HashSet<URN>(); records = new QueryResponseRecord[ recordCount ]; for (int i = 0; i < recordCount; i++) { QueryResponseRecord rec = new QueryResponseRecord(); offset = rec.deserialize(body, offset); if ( NLogger.isWarnEnabled( QueryResponseMsg.class ) && rec.getAlternateLocations() != null && rec.getAlternateLocations().length > 15 ) { NLogger.warn( QueryResponseMsg.class, "QueryRespRecord with " + rec.getAlternateLocations().length + " alt locs..." ); } records[ i ] = rec; URN urn = rec.getURN(); if ( urn != null ) { uniqueURNs.add( urn ); } else { uniqueResultCount ++; } } uniqueResultCount += uniqueURNs.size(); // Handle Bearshare meta informations. The format is documented in // the GnutellaProtocol04.pdf document pushNeededFlag = QHD_UNKNOWN_FLAG; serverBusyFlag = QHD_UNKNOWN_FLAG; hasUploadedFlag = QHD_UNKNOWN_FLAG; uploadSpeedFlag = QHD_UNKNOWN_FLAG; // GGEP extensions isBrowseHostSupported = false; if ( offset <= (getHeader().getDataLength() - 16 - 4 - 2) ) { // parse meta data // Use ISO encoding for two bytes characters on some platforms. vendorCode = new String( body, offset, 4, "ISO-8859-1"); if ( !isVendorCodeValid( vendorCode ) ) { String hexVendorCode = HexConverter.toHexString( body, offset, 4 ); NLogger.warn(QueryResponseMsg.class, getHeader().getFromHost() + ": Illegal QHD vendor code found: " + vendorCode + " (" + hexVendorCode + "). Body: " + HexConverter.toHexString( body ) ); vendorCode = hexVendorCode; } offset += 4; int openDataLength = IOUtil.unsignedByte2int( body[ offset ] ); offset += 1; // parse upload speed, have uploaded, busy and push if ( openDataLength > 1) { // if we have a flag byte byte flag1 = body[ offset ]; byte flag2 = body[ offset + 1]; // check if push flag is meaningfull do it reversed from other checks if ( ( flag2 & PUSH_NEEDED_MASK ) != 0 ) { if ( ( flag1 & PUSH_NEEDED_MASK ) != 0 ) { pushNeededFlag = QHD_TRUE_FLAG; } else { pushNeededFlag = QHD_FALSE_FLAG; } } // check if server busy flag meaningfull if ((flag1 & SERVER_BUSY_MASK) != 0) { if ( (flag2 & SERVER_BUSY_MASK) != 0 ) { serverBusyFlag = QHD_TRUE_FLAG; } else { serverBusyFlag = QHD_FALSE_FLAG; } } // check if the uploaded flag is meaningfull if ((flag1 & HAS_UPLOADED_MASK) != 0) { if ( (flag2 & HAS_UPLOADED_MASK) != 0 ) { hasUploadedFlag = QHD_TRUE_FLAG; } else { hasUploadedFlag = QHD_FALSE_FLAG; } } if ((flag1 & UPLOAD_SPEED_MASK) != 0 ) { if ( (flag2 & UPLOAD_SPEED_MASK) != 0 ) { uploadSpeedFlag = QHD_TRUE_FLAG; } else { uploadSpeedFlag = QHD_FALSE_FLAG; } } if ((flag1 & GGEP_MASK) != 0 && (flag2 & GGEP_MASK) !=0 ) {// parse GGEP area should follow after open data area but // we can't be sure... int ggepMagicIndex = offset + 2; // search for real magic index while ( ggepMagicIndex < body.length ) { if ( body[ ggepMagicIndex ] == GGEPBlock.MAGIC_NUMBER ) { // found index! break; } ggepMagicIndex ++; } GGEPBlock[] ggepBlocks = null; try { // if there are GGEPs, see if Browse Host supported... ggepBlocks = GGEPBlock.parseGGEPBlocks( body, ggepMagicIndex ); isBrowseHostSupported = GGEPBlock.isExtensionHeaderInBlocks( ggepBlocks, GGEPBlock.BROWSE_HOST_HEADER_ID ); pushProxyAddresses = GGEPExtension.parsePushProxyExtensionData( ggepBlocks ); } catch ( InvalidGGEPBlockException exp ) {// ignore and continue parsing... NLogger.debug(QueryResponseMsg.class, exp, exp ); } } } // skip unknown open data length offset += openDataLength; //Parse private area of Limewire and Shareaza to read out chat //flag. If chatflag is 0x1 chat is supported, if 0x0 its not. int privateDataLength = body.length - offset - 16; if ( privateDataLength > 0 && ( vendorCode.equals("LIME") || vendorCode.equals("RAZA") || vendorCode.equals("PHEX") ) ) { byte flag = body[ offset ]; isChatSupported = ( flag & CHAT_SUPPORTED_MASK ) != 0; } //System.out.println( (mHeader.getDataLen() -16 - 4 -2) + " " + offset + " " + // /*new String( body, offset, mHeader.getDataLen() - offset) + " " +*/ // openDataLength + " " + pushNeededFlag + " " + serverBusyFlag + " " + // uploadSpeedFlag + " " + hasUploadedFlag + " " + vendorCode ); } parseRemoteClientID(); isParsed = true; } catch ( java.io.UnsupportedEncodingException exp ) { return; } }
catch ( java.io.UnsupportedEncodingException exp ) { return; }
parseRemoteClientID(); isParsed = true;
private void parseBody() { if ( isParsed ) { return; } // Already read the header. int offset = 0; byte n = body[offset++]; short recordCount = (short)(n < 0 ? 256 + n : n); // parsing of port and ip is done on demand in getHostAddress() and // getHostIP() offset += 2; // skip port offset += 4; // skip ip try { long speed = IOUtil.unsignedInt2Long( IOUtil.deserializeIntLE(body, offset) ); remoteHostSpeed = speed; offset += 4; uniqueResultCount = 0; Set<URN> uniqueURNs = new HashSet<URN>(); records = new QueryResponseRecord[ recordCount ]; for (int i = 0; i < recordCount; i++) { QueryResponseRecord rec = new QueryResponseRecord(); offset = rec.deserialize(body, offset); if ( NLogger.isWarnEnabled( QueryResponseMsg.class ) && rec.getAlternateLocations() != null && rec.getAlternateLocations().length > 15 ) { NLogger.warn( QueryResponseMsg.class, "QueryRespRecord with " + rec.getAlternateLocations().length + " alt locs..." ); } records[ i ] = rec; URN urn = rec.getURN(); if ( urn != null ) { uniqueURNs.add( urn ); } else { uniqueResultCount ++; } } uniqueResultCount += uniqueURNs.size(); // Handle Bearshare meta informations. The format is documented in // the GnutellaProtocol04.pdf document pushNeededFlag = QHD_UNKNOWN_FLAG; serverBusyFlag = QHD_UNKNOWN_FLAG; hasUploadedFlag = QHD_UNKNOWN_FLAG; uploadSpeedFlag = QHD_UNKNOWN_FLAG; // GGEP extensions isBrowseHostSupported = false; if ( offset <= (getHeader().getDataLength() - 16 - 4 - 2) ) { // parse meta data // Use ISO encoding for two bytes characters on some platforms. vendorCode = new String( body, offset, 4, "ISO-8859-1"); if ( !isVendorCodeValid( vendorCode ) ) { String hexVendorCode = HexConverter.toHexString( body, offset, 4 ); NLogger.warn(QueryResponseMsg.class, getHeader().getFromHost() + ": Illegal QHD vendor code found: " + vendorCode + " (" + hexVendorCode + "). Body: " + HexConverter.toHexString( body ) ); vendorCode = hexVendorCode; } offset += 4; int openDataLength = IOUtil.unsignedByte2int( body[ offset ] ); offset += 1; // parse upload speed, have uploaded, busy and push if ( openDataLength > 1) { // if we have a flag byte byte flag1 = body[ offset ]; byte flag2 = body[ offset + 1]; // check if push flag is meaningfull do it reversed from other checks if ( ( flag2 & PUSH_NEEDED_MASK ) != 0 ) { if ( ( flag1 & PUSH_NEEDED_MASK ) != 0 ) { pushNeededFlag = QHD_TRUE_FLAG; } else { pushNeededFlag = QHD_FALSE_FLAG; } } // check if server busy flag meaningfull if ((flag1 & SERVER_BUSY_MASK) != 0) { if ( (flag2 & SERVER_BUSY_MASK) != 0 ) { serverBusyFlag = QHD_TRUE_FLAG; } else { serverBusyFlag = QHD_FALSE_FLAG; } } // check if the uploaded flag is meaningfull if ((flag1 & HAS_UPLOADED_MASK) != 0) { if ( (flag2 & HAS_UPLOADED_MASK) != 0 ) { hasUploadedFlag = QHD_TRUE_FLAG; } else { hasUploadedFlag = QHD_FALSE_FLAG; } } if ((flag1 & UPLOAD_SPEED_MASK) != 0 ) { if ( (flag2 & UPLOAD_SPEED_MASK) != 0 ) { uploadSpeedFlag = QHD_TRUE_FLAG; } else { uploadSpeedFlag = QHD_FALSE_FLAG; } } if ((flag1 & GGEP_MASK) != 0 && (flag2 & GGEP_MASK) !=0 ) {// parse GGEP area should follow after open data area but // we can't be sure... int ggepMagicIndex = offset + 2; // search for real magic index while ( ggepMagicIndex < body.length ) { if ( body[ ggepMagicIndex ] == GGEPBlock.MAGIC_NUMBER ) { // found index! break; } ggepMagicIndex ++; } GGEPBlock[] ggepBlocks = null; try { // if there are GGEPs, see if Browse Host supported... ggepBlocks = GGEPBlock.parseGGEPBlocks( body, ggepMagicIndex ); isBrowseHostSupported = GGEPBlock.isExtensionHeaderInBlocks( ggepBlocks, GGEPBlock.BROWSE_HOST_HEADER_ID ); pushProxyAddresses = GGEPExtension.parsePushProxyExtensionData( ggepBlocks ); } catch ( InvalidGGEPBlockException exp ) {// ignore and continue parsing... NLogger.debug(QueryResponseMsg.class, exp, exp ); } } } // skip unknown open data length offset += openDataLength; //Parse private area of Limewire and Shareaza to read out chat //flag. If chatflag is 0x1 chat is supported, if 0x0 its not. int privateDataLength = body.length - offset - 16; if ( privateDataLength > 0 && ( vendorCode.equals("LIME") || vendorCode.equals("RAZA") || vendorCode.equals("PHEX") ) ) { byte flag = body[ offset ]; isChatSupported = ( flag & CHAT_SUPPORTED_MASK ) != 0; } //System.out.println( (mHeader.getDataLen() -16 - 4 -2) + " " + offset + " " + // /*new String( body, offset, mHeader.getDataLen() - offset) + " " +*/ // openDataLength + " " + pushNeededFlag + " " + serverBusyFlag + " " + // uploadSpeedFlag + " " + hasUploadedFlag + " " + vendorCode ); } parseRemoteClientID(); isParsed = true; } catch ( java.io.UnsupportedEncodingException exp ) { return; } }
else return null;
return null;
public Dimensions calcDim(Dimensions l,Dimensions r) { if(l.equals(r) && l.is1D()) return Dimensions.ONE; else return null; }
else return super.mul(param1,param2);
return super.mul(param1,param2);
public Object dot(Object param1, Object param2) throws ParseException { if(param1 instanceof MVector && param2 instanceof MVector) return dot((MVector) param1,(MVector) param2); else return super.mul(param1,param2); }
System.out.println("currRow xShift min max ampScale ampScale*min ampScale*max plotofset plot_y"); System.out.println(" plot_x");
void drawPlottableNew(Graphics g, Plottable[] plot) { int xShift = plot_x/plotrows; mean = getMean(); for (int currRow = 0; currRow < plotrows; currRow++) { System.out.println(currRow+" "+xShift+" "+min+" "+max+" "+ampScale+" "+(ampScale*min)+" "+(ampScale*max)+" "+plotoffset+" "+plot_y+" "+plot_x); // get new graphics to avoid messing up original Graphics2D newG = (Graphics2D)g.create(); // shift for row (left so time is in window, //down to correct row on screen, plus // newG.translate(xShift*currRow, plot_y/2 + plotoffset*currRow); newG.translate(-1*xShift*currRow, plot_y/2+plotoffset*currRow); // account for graphics y positive down newG.scale(1, -1); newG.scale(1, ampScale); // translate max so mean is in middle newG.translate(0, -1*mean); newG.setPaint(Color.red); newG.drawLine(0, 0, 6000, 0); System.out.println(currRow+": "+(-1*currRow*xShift)+", "+currRow*plotoffset+" "+getMean()); if (currRow % 2 == 0) { newG.setPaint(Color.black); } else { newG.setPaint(Color.blue); } for (int i=0; i<arrayplottable.length; i++) { int lastXValue = arrayplottable[i].x_coor[arrayplottable[i].x_coor.length-1]; // only draw plottable if it overlaps displayed part of row if (( (xShift*currRow) <= arrayplottable[i].x_coor[0] && (xShift*(currRow+1)) <= arrayplottable[i].x_coor[0]) || (xShift*(currRow) >= lastXValue && (xShift*(currRow+1)) >= lastXValue)) { // no overlap } else { newG.drawPolyline(arrayplottable[i].x_coor, arrayplottable[i].y_coor, arrayplottable[i].x_coor.length); } // end of else } newG.dispose(); //break; // only do first row } }
int[] minmax = findMinMax(arrayplottable); min = minmax[0]; max = minmax[1];
public void setAmpScale(float ampScalePercent) { this.ampScalePercent = ampScalePercent; this.ampScale = ampScalePercent*plot_y/(max-min); System.out.println("AmpScale "+ampScalePercent+" "+ampScale); configChanged(); }
return ((Rational) a).compareTo((Rational) b);
return ((Rational) a).compareTo(b);
public int compare(Number a,Number b) { return ((Rational) a).compareTo((Rational) b); }
return ((Rational) a).compareTo((Rational) b) == 0;
return ((Rational) a).compareTo(b) == 0;
public boolean equals(Number a,Number b) { return ((Rational) a).compareTo((Rational) b) == 0; }
this.setValidValue(true);
protected boolean setValueRaw(Object val) { if(val instanceof MatrixValueI) { mvalue = (MatrixValueI) val; this.dims = mvalue.getDim(); } else mvalue.setEle(0,val); return true; }
if(isConstant()) return;
public void invalidateAll() { setValidValue(false); for(Enumeration e = derivatives.elements(); e.hasMoreElements(); ) { PartialDerivative deriv = (PartialDerivative) e.nextElement(); deriv.setValidValue(false); } }
public void setStepEndTemp(int i, int t){
public void setStepEndTemp(int i, double t){
public void setStepEndTemp(int i, int t){ if (tempUnits.equals("C")) ((MashStep)steps.get(i)).setEndTemp(cToF(t)); else ((MashStep)steps.get(i)).setEndTemp(t); calcMashSchedule(); }
this.parser.setInitialTokenManagerState(Parser.NO_DOT_IN_IDENTIFIERS);
public VectorJep() { super(); /* 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_LIST.setPFMC(new VList());*/ opSet = new VOperatorSet(); }
int currentTryCount = Math.max( 0, allHostCount - hostCount - errorHostCount );
int totalCount = networkHostsContainer.getTotalConnectionCount(); int currentTryCount = Math.max( 0, allHostCount - totalCount - errorHostCount);
public void doAutoConnectCheck() { if ( !networkMgr.isNetworkJoined() || !networkMgr.isConnected() ) { return; } int hostCount; int requiredHostCount; if ( isAbleToBecomeUltrapeer() ) { // as a ultrapeer I'm primary searching for Ultrapeers only... // to make sure I'm well connected... hostCount = networkHostsContainer.getUltrapeerConnectionCount(); requiredHostCount = ServiceManager.sCfg.up2upConnections; } else if ( isShieldedLeafNode() || ServiceManager.sCfg.allowToBecomeLeaf ) { // as a leaf I'm primary searching for Ultrapeers only... hostCount = networkHostsContainer.getUltrapeerConnectionCount(); requiredHostCount = ServiceManager.sCfg.leaf2upConnections; } else { hostCount = networkHostsContainer.getTotalConnectionCount(); requiredHostCount = ServiceManager.sCfg.peerConnections; } // count the number of missing connection tryes this is the required count // minus the available count. The result is multiplied by four to raise the // connection try count. int missingCount = ( requiredHostCount - hostCount ) * 4; // find out the number of hosts where a connection is currently tried... int allHostCount = networkHostsContainer.getNetworkHostCount( ); int errorHostCount = networkHostsContainer.getNetworkHostCount( HostStatus.ERROR); // make sure the value is not negative. int currentTryCount = Math.max( 0, allHostCount - hostCount - errorHostCount ); // we will never try more then a reasonable parallel tries.. int upperLimit = Math.min( MAX_PARALLEL_CONNECTION_TRIES, ServiceManager.sCfg.maxConcurrentConnectAttempts ) - currentTryCount; int outConnectCount = Math.min( missingCount-currentTryCount, upperLimit ); if ( outConnectCount > 0 ) { NLogger.debug( HostManager.class, "Auto-connect to " + outConnectCount + " new hosts."); networkHostsContainer.createOutConnectionToNextHosts( outConnectCount ); } }
System.out.println("SeisPoint[0] forehand: " + seisPoints[0] + "dragged points: " + (pointsPerPixel * dragAmount));
private void drag(int dragAmount, int dragFrom, SeismogramShapeIterator iterator){ double pointsPerPixel = iterator.getPointsPerPixel(); int[] seisPoints = currentIterator.getSeisPoints(); System.out.println("SeisPoint[0] forehand: " + seisPoints[0] + "dragged points: " + (pointsPerPixel * dragAmount)); seisPoints[0] =(int)-(iterator.getTotalShift() * pointsPerPixel) + iterator.getBaseSeisPoint(); //Math.ceil(pointsPerPixel * dragAmount); System.out.println("SeisPoint[0] afterhand: " + seisPoints[0]); seisPoints[1] = seisPoints[0] + (int)-(iterator.getSize().width * pointsPerPixel); //Math.ceil(pointsPerPixel * dragAmount); iterator.setSeisPoints(seisPoints); int[][] points = currentIterator.getPoints(); int length = points[0].length - Math.abs(dragAmount); System.arraycopy(points[0], dragFrom, points[0], dragFrom + dragAmount, length); System.arraycopy(points[1], dragFrom, points[1], dragFrom + dragAmount, length); int[] drawnPixels = getPixels(iterator); iterator.setDrawnPixels(drawnPixels); int drawStart, drawEnd; if(dragAmount < 0){ drawStart = drawnPixels[1] + dragAmount; drawEnd = drawnPixels[1] - 1; }else{ drawStart = drawnPixels[0]; drawEnd = dragAmount--; } plotPixels(drawStart, drawEnd, iterator); currentIterator = iterator; }
System.out.println("SeisPoint[0] afterhand: " + seisPoints[0]);
private void drag(int dragAmount, int dragFrom, SeismogramShapeIterator iterator){ double pointsPerPixel = iterator.getPointsPerPixel(); int[] seisPoints = currentIterator.getSeisPoints(); System.out.println("SeisPoint[0] forehand: " + seisPoints[0] + "dragged points: " + (pointsPerPixel * dragAmount)); seisPoints[0] =(int)-(iterator.getTotalShift() * pointsPerPixel) + iterator.getBaseSeisPoint(); //Math.ceil(pointsPerPixel * dragAmount); System.out.println("SeisPoint[0] afterhand: " + seisPoints[0]); seisPoints[1] = seisPoints[0] + (int)-(iterator.getSize().width * pointsPerPixel); //Math.ceil(pointsPerPixel * dragAmount); iterator.setSeisPoints(seisPoints); int[][] points = currentIterator.getPoints(); int length = points[0].length - Math.abs(dragAmount); System.arraycopy(points[0], dragFrom, points[0], dragFrom + dragAmount, length); System.arraycopy(points[1], dragFrom, points[1], dragFrom + dragAmount, length); int[] drawnPixels = getPixels(iterator); iterator.setDrawnPixels(drawnPixels); int drawStart, drawEnd; if(dragAmount < 0){ drawStart = drawnPixels[1] + dragAmount; drawEnd = drawnPixels[1] - 1; }else{ drawStart = drawnPixels[0]; drawEnd = dragAmount--; } plotPixels(drawStart, drawEnd, iterator); currentIterator = iterator; }
System.out.println("Draggin left");
public void dragLeft(int dragAmount, SeismogramShapeIterator iterator){ System.out.println("Draggin left"); drag(dragAmount, -dragAmount, iterator); }
System.out.println("Draggin right"); drag(dragAmount, 0, iterator);
drag(dragAmount, 0, iterator);
public void dragRight(int dragAmount, SeismogramShapeIterator iterator){ System.out.println("Draggin right"); drag(dragAmount, 0, iterator); }
System.out.println("Plotting all points");
public void plot(SeismogramShapeIterator iterator){ System.out.println("Plotting all points"); iterator.setSeisPoints(DisplayUtils.getSeisPoints(dss.getSeismogram(), iterator.getTime())); iterator.setBaseSeisPoint(); iterator.setPointsPerPixel(); iterator.setPoints(new int[2][iterator.getSize().width]); plotPixels(iterator); currentIterator = iterator; }
if (param instanceof Number)
if (param instanceof Complex) { return ((Complex)param).atanh(); } else if (param instanceof Number)
public Object atanh(Object param) throws ParseException { if (param instanceof Number) { Complex temp = new Complex(((Number)param).doubleValue(),0.0); return temp.atanh(); } else if (param instanceof Complex) { return ((Complex)param).atanh(); } throw new ParseException("Invalid parameter type"); }
else if (param instanceof Complex) { return ((Complex)param).atanh(); }
public Object atanh(Object param) throws ParseException { if (param instanceof Number) { Complex temp = new Complex(((Number)param).doubleValue(),0.0); return temp.atanh(); } else if (param instanceof Complex) { return ((Complex)param).atanh(); } throw new ParseException("Invalid parameter type"); }
queuePosition = uploadMgr.getQueuedPosition(uploadState) + 1;
queuePosition = uploadMgr.getQueuedPosition(uploadState);
private boolean evaluateHTTPRequest() throws IOException { String logMsg = "HTTP Request: " + httpRequest.buildHTTPRequestString(); NLogger.debug( UploadEngine.class, logMsg); uploadState.addToUploadLog( logMsg ); GnutellaRequest gRequest = httpRequest.getGnutellaRequest(); if ( gRequest == null ) { throw new IOException("Not a Gnutella file request."); } HTTPHeader header; if (gRequest.getURN() == null) { header = httpRequest .getHeader(GnutellaHeaderNames.X_GNUTELLA_CONTENT_URN); if (header != null) { if (URN.isValidURN(header.getValue())) { URN urn = new URN(header.getValue()); gRequest.setContentURN(urn); } } } SocketFacade socket = connection.getSocket(); int port = -1; header = httpRequest.getHeader(GnutellaHeaderNames.LISTEN_IP); if (header == null) { header = httpRequest.getHeader(GnutellaHeaderNames.X_MY_ADDRESS); } if (header != null) { // parse port port = AddressUtils.parsePort(header.getValue()); } if (port <= 0) { port = socket.getRemoteAddress().getPort(); } hostAddress = new DefaultDestAddress(socket.getRemoteAddress().getHostName(), port); UploadManager uploadMgr = UploadManager.getInstance(); HTTPResponse httpResponse; if (!isIPCounted) { boolean succ = uploadMgr.validateAndCountIP(hostAddress); if (!succ) { httpResponse = new HTTPResponse((short) 503, "Upload Limit Reached for IP", true); sendHTTPResponse(httpResponse); return false; } isIPCounted = true; } ShareFile requestedShareFile = findShareFile(gRequest); if (requestedShareFile == null) { httpResponse = new HTTPResponse((short) 404, "File not found", true); sendHTTPResponse(httpResponse); return false; } isUploadQueued = false; if (uploadMgr.isHostBusy()) { header = httpRequest.getHeader(GnutellaHeaderNames.X_QUEUE); if (header == null || !ServiceManager.sCfg.allowUploadQueuing || uploadMgr.isQueueLimitReached()) {// queueing is not supported httpResponse = new HTTPResponse((short) 503, "Upload Limit Reached", true); addAltLocResponseHeader(httpResponse, requestedShareFile); sendHTTPResponse(httpResponse); return false; } isUploadQueued = true; } HTTPHeader rangeHeader = null; HTTPRangeSet uploadRange = null; Range uploadRangeEntry = null; if ( !gRequest.isTigerTreeRequest() ) { rangeHeader = httpRequest.getHeader(HTTPHeaderNames.RANGE); if (rangeHeader != null) { uploadRange = HTTPRangeSet.parseHTTPRangeSet( rangeHeader.getValue(), true); if (uploadRange == null) { // this is not 416 Requested Range Not Satisfiable since // we have a parsing error on the requested range. httpResponse = new HTTPResponse((short) 500, "Requested Range Not Parseable", true); addAltLocResponseHeader(httpResponse, requestedShareFile); sendHTTPResponse(httpResponse); return false; } } else { uploadRange = new HTTPRangeSet(0, HTTPRangeSet.NOT_SET); } uploadRangeEntry = uploadRange.getFirstRange(); short rangeStatus = requestedShareFile .getRangeAvailableStatus(uploadRangeEntry); if (rangeStatus != UploadConstants.RANGE_AVAILABLE) { if (rangeStatus == UploadConstants.RANGE_NOT_AVAILABLE) { httpResponse = new HTTPResponse((short) 503, "Requested Range Not Available", true); } else //case: if ( rangeStatus == // UploadConstants.RANGE_NOT_SATISFIABLE ) { httpResponse = new HTTPResponse((short) 416, "Requested Range Not Satisfiable", true); } if (requestedShareFile instanceof PartialShareFile) { // TODO we could check if the partial file is progressing // and // return a 416 when the range will not come available soon. PartialShareFile pShareFile = (PartialShareFile) requestedShareFile; httpResponse.addHeader(new HTTPHeader( GnutellaHeaderNames.X_AVAILABLE_RANGES, pShareFile .buildXAvailableRangesString())); } addAltLocResponseHeader(httpResponse, requestedShareFile); sendHTTPResponse(httpResponse); return false; } } // everything is right... collect upload infos String vendor = null; header = httpRequest.getHeader(HTTPHeaderNames.USER_AGENT); if (header != null) { vendor = header.getValue(); } else { vendor = ""; } // check for persistent connection... // a connection is assumed to be persistent if its a HTTP 1.1 connection // with no 'Connection: close' header. Or a HTTP connection with // Connection: Keep-Alive header. header = httpRequest.getHeader(HTTPHeaderNames.CONNECTION); if (HTTPRequest.HTTP_11.equals(httpRequest.getHTTPVersion())) { if (header != null && header.getValue().equalsIgnoreCase("CLOSE")) { isPersistentConnection = false; } else { isPersistentConnection = true; } } else { if (header != null && header.getValue().equalsIgnoreCase("KEEP-ALIVE")) { isPersistentConnection = true; } else { isPersistentConnection = false; } } if (isUploadQueued) { // queueing is supported int queuePosition; uploadState.update(hostAddress, vendor); queuePosition = uploadMgr.getQueuedPosition(uploadState) + 1; if ( queuePosition < 0 ) {// missing in queue list queuePosition = uploadMgr.addQueuedUpload(uploadState) + 1; } uploadState.setStatus(UploadConstants.STATUS_QUEUED); int queueLength = uploadMgr.getUploadQueueSize(); int uploadLimit = ServiceManager.sCfg.mMaxUpload; int pollMin = ServiceManager.sCfg.minUploadQueuePollTime; int pollMax = ServiceManager.sCfg.maxUploadQueuePollTime; httpResponse = new HTTPResponse((short) 503, "Remotely Queued", true); addAltLocResponseHeader(httpResponse, requestedShareFile); XQueueParameters xQueueParas = new XQueueParameters(queuePosition, queueLength, uploadLimit, pollMin, pollMax); httpResponse.addHeader(new HTTPHeader(GnutellaHeaderNames.X_QUEUE, xQueueParas.buildHTTPString())); sendHTTPResponse(httpResponse); socket.setSoTimeout(pollMax * 1000); minNextPollTime = System.currentTimeMillis() + pollMin * 1000; return true; } // standard upload... HTTPHeader additionalResponseHeader = null; long contentLength = 0; if ( !gRequest.isTigerTreeRequest() ) { if (requestedShareFile instanceof PartialShareFile) { PartialShareFile pShareFile = (PartialShareFile) requestedShareFile; // call adjusts uploadRangeEntry to fit... pShareFile.findFittingPartForRange(uploadRangeEntry); fileStartOffset = pShareFile.getFileStartOffset(); additionalResponseHeader = new HTTPHeader( GnutellaHeaderNames.X_AVAILABLE_RANGES, pShareFile .buildXAvailableRangesString()); } else { fileStartOffset = uploadRangeEntry .getStartOffset(requestedShareFile.getFileSize()); } startOffset = uploadRangeEntry.getStartOffset(requestedShareFile .getFileSize()); endOffset = uploadRangeEntry.getEndOffset(requestedShareFile .getFileSize()); contentLength = endOffset - startOffset + 1; } URN sharedFileURN = requestedShareFile.getURN(); if ( gRequest.isTigerTreeRequest() ) { uploadState.update(hostAddress, vendor, requestedShareFile.getFileName()); } else { uploadState.update(hostAddress, vendor, requestedShareFile .getFileName(), sharedFileURN, requestedShareFile.getSystemFile(), contentLength); } if ( !uploadMgr.containsUploadState(uploadState) ) { uploadMgr.addUploadState(uploadState); } uploadState.setUploadEngine(this); // form ok response... if ( !gRequest.isTigerTreeRequest() ) { if (startOffset == 0 && endOffset == requestedShareFile.getFileSize() - 1) { httpResponse = new HTTPResponse((short) 200, "OK", true); } else { httpResponse = new HTTPResponse((short) 206, "Partial Content", true); } if (additionalResponseHeader != null) { httpResponse.addHeader(additionalResponseHeader); } } else { httpResponse = new HTTPResponse((short) 200, "OK", true); } // TODO for browser request we might like to return explicite content // types: // contentType = MimeTypeMapping.getMimeTypeForExtension( ext ); httpResponse.addHeader(new HTTPHeader(HTTPHeaderNames.CONTENT_TYPE, "application/binary")); if ( !gRequest.isTigerTreeRequest() ) { httpResponse.addHeader(new HTTPHeader( HTTPHeaderNames.CONTENT_LENGTH, String.valueOf(contentLength))); httpResponse.addHeader(new HTTPHeader( HTTPHeaderNames.CONTENT_RANGE, "bytes " + startOffset + "-" + endOffset + "/" + requestedShareFile.getFileSize())); } // in case of tiger tree request we need to close the connection since // we dont know the content length of the dime here already... // TODO: we could pre calculate the dime length in this case! if ( isPersistentConnection && !gRequest.isTigerTreeRequest() ) { httpResponse.addHeader( new HTTPHeader( HTTPHeaderNames.CONNECTION, "Keep-Alive" ) ); } else { httpResponse.addHeader(new HTTPHeader(HTTPHeaderNames.CONNECTION, "close")); isPersistentConnection = false; } if ( sharedFileURN != null ) { httpResponse.addHeader(new HTTPHeader( GnutellaHeaderNames.X_GNUTELLA_CONTENT_URN, sharedFileURN .getAsString())); } if ( !gRequest.isTigerTreeRequest() ) { addAltLocResponseHeader(httpResponse, requestedShareFile); addPushProxyResponseHeader( httpResponse ); } if ( sharedFileURN != null && !gRequest.isTigerTreeRequest() ) { parseAltLocRequestHeader( requestedShareFile, sharedFileURN ); // add thex download url ShareFileThexData thexData = requestedShareFile.getThexData( true ); if ( thexData != null ) { String thexRootHash = thexData.getRootHash(); HTTPHeader thexHeader = new HTTPHeader( GnutellaHeaderNames.X_THEX_URI, URLUtil.buildName2ResThexURL( sharedFileURN, thexRootHash ) ); httpResponse.addHeader( thexHeader ); } } sendHTTPResponse(httpResponse); socket.setSoTimeout(ServiceManager.sCfg.socketConnectTimeout); // check if we need to count again.. // this is the case if we have no PartialShareFile (same // PartialShareFile is never equal again, since its always a new instance) // and the ShareFile is not equal to the requested file. if ( uploadShareFile != null && !(requestedShareFile instanceof PartialShareFile) && uploadShareFile != requestedShareFile) { isUploadCounted = false; } uploadShareFile = requestedShareFile; minNextPollTime = -1; return true; }
queuePosition = uploadMgr.addQueuedUpload(uploadState) + 1;
queuePosition = uploadMgr.addQueuedUpload(uploadState);
private boolean evaluateHTTPRequest() throws IOException { String logMsg = "HTTP Request: " + httpRequest.buildHTTPRequestString(); NLogger.debug( UploadEngine.class, logMsg); uploadState.addToUploadLog( logMsg ); GnutellaRequest gRequest = httpRequest.getGnutellaRequest(); if ( gRequest == null ) { throw new IOException("Not a Gnutella file request."); } HTTPHeader header; if (gRequest.getURN() == null) { header = httpRequest .getHeader(GnutellaHeaderNames.X_GNUTELLA_CONTENT_URN); if (header != null) { if (URN.isValidURN(header.getValue())) { URN urn = new URN(header.getValue()); gRequest.setContentURN(urn); } } } SocketFacade socket = connection.getSocket(); int port = -1; header = httpRequest.getHeader(GnutellaHeaderNames.LISTEN_IP); if (header == null) { header = httpRequest.getHeader(GnutellaHeaderNames.X_MY_ADDRESS); } if (header != null) { // parse port port = AddressUtils.parsePort(header.getValue()); } if (port <= 0) { port = socket.getRemoteAddress().getPort(); } hostAddress = new DefaultDestAddress(socket.getRemoteAddress().getHostName(), port); UploadManager uploadMgr = UploadManager.getInstance(); HTTPResponse httpResponse; if (!isIPCounted) { boolean succ = uploadMgr.validateAndCountIP(hostAddress); if (!succ) { httpResponse = new HTTPResponse((short) 503, "Upload Limit Reached for IP", true); sendHTTPResponse(httpResponse); return false; } isIPCounted = true; } ShareFile requestedShareFile = findShareFile(gRequest); if (requestedShareFile == null) { httpResponse = new HTTPResponse((short) 404, "File not found", true); sendHTTPResponse(httpResponse); return false; } isUploadQueued = false; if (uploadMgr.isHostBusy()) { header = httpRequest.getHeader(GnutellaHeaderNames.X_QUEUE); if (header == null || !ServiceManager.sCfg.allowUploadQueuing || uploadMgr.isQueueLimitReached()) {// queueing is not supported httpResponse = new HTTPResponse((short) 503, "Upload Limit Reached", true); addAltLocResponseHeader(httpResponse, requestedShareFile); sendHTTPResponse(httpResponse); return false; } isUploadQueued = true; } HTTPHeader rangeHeader = null; HTTPRangeSet uploadRange = null; Range uploadRangeEntry = null; if ( !gRequest.isTigerTreeRequest() ) { rangeHeader = httpRequest.getHeader(HTTPHeaderNames.RANGE); if (rangeHeader != null) { uploadRange = HTTPRangeSet.parseHTTPRangeSet( rangeHeader.getValue(), true); if (uploadRange == null) { // this is not 416 Requested Range Not Satisfiable since // we have a parsing error on the requested range. httpResponse = new HTTPResponse((short) 500, "Requested Range Not Parseable", true); addAltLocResponseHeader(httpResponse, requestedShareFile); sendHTTPResponse(httpResponse); return false; } } else { uploadRange = new HTTPRangeSet(0, HTTPRangeSet.NOT_SET); } uploadRangeEntry = uploadRange.getFirstRange(); short rangeStatus = requestedShareFile .getRangeAvailableStatus(uploadRangeEntry); if (rangeStatus != UploadConstants.RANGE_AVAILABLE) { if (rangeStatus == UploadConstants.RANGE_NOT_AVAILABLE) { httpResponse = new HTTPResponse((short) 503, "Requested Range Not Available", true); } else //case: if ( rangeStatus == // UploadConstants.RANGE_NOT_SATISFIABLE ) { httpResponse = new HTTPResponse((short) 416, "Requested Range Not Satisfiable", true); } if (requestedShareFile instanceof PartialShareFile) { // TODO we could check if the partial file is progressing // and // return a 416 when the range will not come available soon. PartialShareFile pShareFile = (PartialShareFile) requestedShareFile; httpResponse.addHeader(new HTTPHeader( GnutellaHeaderNames.X_AVAILABLE_RANGES, pShareFile .buildXAvailableRangesString())); } addAltLocResponseHeader(httpResponse, requestedShareFile); sendHTTPResponse(httpResponse); return false; } } // everything is right... collect upload infos String vendor = null; header = httpRequest.getHeader(HTTPHeaderNames.USER_AGENT); if (header != null) { vendor = header.getValue(); } else { vendor = ""; } // check for persistent connection... // a connection is assumed to be persistent if its a HTTP 1.1 connection // with no 'Connection: close' header. Or a HTTP connection with // Connection: Keep-Alive header. header = httpRequest.getHeader(HTTPHeaderNames.CONNECTION); if (HTTPRequest.HTTP_11.equals(httpRequest.getHTTPVersion())) { if (header != null && header.getValue().equalsIgnoreCase("CLOSE")) { isPersistentConnection = false; } else { isPersistentConnection = true; } } else { if (header != null && header.getValue().equalsIgnoreCase("KEEP-ALIVE")) { isPersistentConnection = true; } else { isPersistentConnection = false; } } if (isUploadQueued) { // queueing is supported int queuePosition; uploadState.update(hostAddress, vendor); queuePosition = uploadMgr.getQueuedPosition(uploadState) + 1; if ( queuePosition < 0 ) {// missing in queue list queuePosition = uploadMgr.addQueuedUpload(uploadState) + 1; } uploadState.setStatus(UploadConstants.STATUS_QUEUED); int queueLength = uploadMgr.getUploadQueueSize(); int uploadLimit = ServiceManager.sCfg.mMaxUpload; int pollMin = ServiceManager.sCfg.minUploadQueuePollTime; int pollMax = ServiceManager.sCfg.maxUploadQueuePollTime; httpResponse = new HTTPResponse((short) 503, "Remotely Queued", true); addAltLocResponseHeader(httpResponse, requestedShareFile); XQueueParameters xQueueParas = new XQueueParameters(queuePosition, queueLength, uploadLimit, pollMin, pollMax); httpResponse.addHeader(new HTTPHeader(GnutellaHeaderNames.X_QUEUE, xQueueParas.buildHTTPString())); sendHTTPResponse(httpResponse); socket.setSoTimeout(pollMax * 1000); minNextPollTime = System.currentTimeMillis() + pollMin * 1000; return true; } // standard upload... HTTPHeader additionalResponseHeader = null; long contentLength = 0; if ( !gRequest.isTigerTreeRequest() ) { if (requestedShareFile instanceof PartialShareFile) { PartialShareFile pShareFile = (PartialShareFile) requestedShareFile; // call adjusts uploadRangeEntry to fit... pShareFile.findFittingPartForRange(uploadRangeEntry); fileStartOffset = pShareFile.getFileStartOffset(); additionalResponseHeader = new HTTPHeader( GnutellaHeaderNames.X_AVAILABLE_RANGES, pShareFile .buildXAvailableRangesString()); } else { fileStartOffset = uploadRangeEntry .getStartOffset(requestedShareFile.getFileSize()); } startOffset = uploadRangeEntry.getStartOffset(requestedShareFile .getFileSize()); endOffset = uploadRangeEntry.getEndOffset(requestedShareFile .getFileSize()); contentLength = endOffset - startOffset + 1; } URN sharedFileURN = requestedShareFile.getURN(); if ( gRequest.isTigerTreeRequest() ) { uploadState.update(hostAddress, vendor, requestedShareFile.getFileName()); } else { uploadState.update(hostAddress, vendor, requestedShareFile .getFileName(), sharedFileURN, requestedShareFile.getSystemFile(), contentLength); } if ( !uploadMgr.containsUploadState(uploadState) ) { uploadMgr.addUploadState(uploadState); } uploadState.setUploadEngine(this); // form ok response... if ( !gRequest.isTigerTreeRequest() ) { if (startOffset == 0 && endOffset == requestedShareFile.getFileSize() - 1) { httpResponse = new HTTPResponse((short) 200, "OK", true); } else { httpResponse = new HTTPResponse((short) 206, "Partial Content", true); } if (additionalResponseHeader != null) { httpResponse.addHeader(additionalResponseHeader); } } else { httpResponse = new HTTPResponse((short) 200, "OK", true); } // TODO for browser request we might like to return explicite content // types: // contentType = MimeTypeMapping.getMimeTypeForExtension( ext ); httpResponse.addHeader(new HTTPHeader(HTTPHeaderNames.CONTENT_TYPE, "application/binary")); if ( !gRequest.isTigerTreeRequest() ) { httpResponse.addHeader(new HTTPHeader( HTTPHeaderNames.CONTENT_LENGTH, String.valueOf(contentLength))); httpResponse.addHeader(new HTTPHeader( HTTPHeaderNames.CONTENT_RANGE, "bytes " + startOffset + "-" + endOffset + "/" + requestedShareFile.getFileSize())); } // in case of tiger tree request we need to close the connection since // we dont know the content length of the dime here already... // TODO: we could pre calculate the dime length in this case! if ( isPersistentConnection && !gRequest.isTigerTreeRequest() ) { httpResponse.addHeader( new HTTPHeader( HTTPHeaderNames.CONNECTION, "Keep-Alive" ) ); } else { httpResponse.addHeader(new HTTPHeader(HTTPHeaderNames.CONNECTION, "close")); isPersistentConnection = false; } if ( sharedFileURN != null ) { httpResponse.addHeader(new HTTPHeader( GnutellaHeaderNames.X_GNUTELLA_CONTENT_URN, sharedFileURN .getAsString())); } if ( !gRequest.isTigerTreeRequest() ) { addAltLocResponseHeader(httpResponse, requestedShareFile); addPushProxyResponseHeader( httpResponse ); } if ( sharedFileURN != null && !gRequest.isTigerTreeRequest() ) { parseAltLocRequestHeader( requestedShareFile, sharedFileURN ); // add thex download url ShareFileThexData thexData = requestedShareFile.getThexData( true ); if ( thexData != null ) { String thexRootHash = thexData.getRootHash(); HTTPHeader thexHeader = new HTTPHeader( GnutellaHeaderNames.X_THEX_URI, URLUtil.buildName2ResThexURL( sharedFileURN, thexRootHash ) ); httpResponse.addHeader( thexHeader ); } } sendHTTPResponse(httpResponse); socket.setSoTimeout(ServiceManager.sCfg.socketConnectTimeout); // check if we need to count again.. // this is the case if we have no PartialShareFile (same // PartialShareFile is never equal again, since its always a new instance) // and the ShareFile is not equal to the requested file. if ( uploadShareFile != null && !(requestedShareFile instanceof PartialShareFile) && uploadShareFile != requestedShareFile) { isUploadCounted = false; } uploadShareFile = requestedShareFile; minNextPollTime = -1; return true; }
queuePosition ++;
private boolean evaluateHTTPRequest() throws IOException { String logMsg = "HTTP Request: " + httpRequest.buildHTTPRequestString(); NLogger.debug( UploadEngine.class, logMsg); uploadState.addToUploadLog( logMsg ); GnutellaRequest gRequest = httpRequest.getGnutellaRequest(); if ( gRequest == null ) { throw new IOException("Not a Gnutella file request."); } HTTPHeader header; if (gRequest.getURN() == null) { header = httpRequest .getHeader(GnutellaHeaderNames.X_GNUTELLA_CONTENT_URN); if (header != null) { if (URN.isValidURN(header.getValue())) { URN urn = new URN(header.getValue()); gRequest.setContentURN(urn); } } } SocketFacade socket = connection.getSocket(); int port = -1; header = httpRequest.getHeader(GnutellaHeaderNames.LISTEN_IP); if (header == null) { header = httpRequest.getHeader(GnutellaHeaderNames.X_MY_ADDRESS); } if (header != null) { // parse port port = AddressUtils.parsePort(header.getValue()); } if (port <= 0) { port = socket.getRemoteAddress().getPort(); } hostAddress = new DefaultDestAddress(socket.getRemoteAddress().getHostName(), port); UploadManager uploadMgr = UploadManager.getInstance(); HTTPResponse httpResponse; if (!isIPCounted) { boolean succ = uploadMgr.validateAndCountIP(hostAddress); if (!succ) { httpResponse = new HTTPResponse((short) 503, "Upload Limit Reached for IP", true); sendHTTPResponse(httpResponse); return false; } isIPCounted = true; } ShareFile requestedShareFile = findShareFile(gRequest); if (requestedShareFile == null) { httpResponse = new HTTPResponse((short) 404, "File not found", true); sendHTTPResponse(httpResponse); return false; } isUploadQueued = false; if (uploadMgr.isHostBusy()) { header = httpRequest.getHeader(GnutellaHeaderNames.X_QUEUE); if (header == null || !ServiceManager.sCfg.allowUploadQueuing || uploadMgr.isQueueLimitReached()) {// queueing is not supported httpResponse = new HTTPResponse((short) 503, "Upload Limit Reached", true); addAltLocResponseHeader(httpResponse, requestedShareFile); sendHTTPResponse(httpResponse); return false; } isUploadQueued = true; } HTTPHeader rangeHeader = null; HTTPRangeSet uploadRange = null; Range uploadRangeEntry = null; if ( !gRequest.isTigerTreeRequest() ) { rangeHeader = httpRequest.getHeader(HTTPHeaderNames.RANGE); if (rangeHeader != null) { uploadRange = HTTPRangeSet.parseHTTPRangeSet( rangeHeader.getValue(), true); if (uploadRange == null) { // this is not 416 Requested Range Not Satisfiable since // we have a parsing error on the requested range. httpResponse = new HTTPResponse((short) 500, "Requested Range Not Parseable", true); addAltLocResponseHeader(httpResponse, requestedShareFile); sendHTTPResponse(httpResponse); return false; } } else { uploadRange = new HTTPRangeSet(0, HTTPRangeSet.NOT_SET); } uploadRangeEntry = uploadRange.getFirstRange(); short rangeStatus = requestedShareFile .getRangeAvailableStatus(uploadRangeEntry); if (rangeStatus != UploadConstants.RANGE_AVAILABLE) { if (rangeStatus == UploadConstants.RANGE_NOT_AVAILABLE) { httpResponse = new HTTPResponse((short) 503, "Requested Range Not Available", true); } else //case: if ( rangeStatus == // UploadConstants.RANGE_NOT_SATISFIABLE ) { httpResponse = new HTTPResponse((short) 416, "Requested Range Not Satisfiable", true); } if (requestedShareFile instanceof PartialShareFile) { // TODO we could check if the partial file is progressing // and // return a 416 when the range will not come available soon. PartialShareFile pShareFile = (PartialShareFile) requestedShareFile; httpResponse.addHeader(new HTTPHeader( GnutellaHeaderNames.X_AVAILABLE_RANGES, pShareFile .buildXAvailableRangesString())); } addAltLocResponseHeader(httpResponse, requestedShareFile); sendHTTPResponse(httpResponse); return false; } } // everything is right... collect upload infos String vendor = null; header = httpRequest.getHeader(HTTPHeaderNames.USER_AGENT); if (header != null) { vendor = header.getValue(); } else { vendor = ""; } // check for persistent connection... // a connection is assumed to be persistent if its a HTTP 1.1 connection // with no 'Connection: close' header. Or a HTTP connection with // Connection: Keep-Alive header. header = httpRequest.getHeader(HTTPHeaderNames.CONNECTION); if (HTTPRequest.HTTP_11.equals(httpRequest.getHTTPVersion())) { if (header != null && header.getValue().equalsIgnoreCase("CLOSE")) { isPersistentConnection = false; } else { isPersistentConnection = true; } } else { if (header != null && header.getValue().equalsIgnoreCase("KEEP-ALIVE")) { isPersistentConnection = true; } else { isPersistentConnection = false; } } if (isUploadQueued) { // queueing is supported int queuePosition; uploadState.update(hostAddress, vendor); queuePosition = uploadMgr.getQueuedPosition(uploadState) + 1; if ( queuePosition < 0 ) {// missing in queue list queuePosition = uploadMgr.addQueuedUpload(uploadState) + 1; } uploadState.setStatus(UploadConstants.STATUS_QUEUED); int queueLength = uploadMgr.getUploadQueueSize(); int uploadLimit = ServiceManager.sCfg.mMaxUpload; int pollMin = ServiceManager.sCfg.minUploadQueuePollTime; int pollMax = ServiceManager.sCfg.maxUploadQueuePollTime; httpResponse = new HTTPResponse((short) 503, "Remotely Queued", true); addAltLocResponseHeader(httpResponse, requestedShareFile); XQueueParameters xQueueParas = new XQueueParameters(queuePosition, queueLength, uploadLimit, pollMin, pollMax); httpResponse.addHeader(new HTTPHeader(GnutellaHeaderNames.X_QUEUE, xQueueParas.buildHTTPString())); sendHTTPResponse(httpResponse); socket.setSoTimeout(pollMax * 1000); minNextPollTime = System.currentTimeMillis() + pollMin * 1000; return true; } // standard upload... HTTPHeader additionalResponseHeader = null; long contentLength = 0; if ( !gRequest.isTigerTreeRequest() ) { if (requestedShareFile instanceof PartialShareFile) { PartialShareFile pShareFile = (PartialShareFile) requestedShareFile; // call adjusts uploadRangeEntry to fit... pShareFile.findFittingPartForRange(uploadRangeEntry); fileStartOffset = pShareFile.getFileStartOffset(); additionalResponseHeader = new HTTPHeader( GnutellaHeaderNames.X_AVAILABLE_RANGES, pShareFile .buildXAvailableRangesString()); } else { fileStartOffset = uploadRangeEntry .getStartOffset(requestedShareFile.getFileSize()); } startOffset = uploadRangeEntry.getStartOffset(requestedShareFile .getFileSize()); endOffset = uploadRangeEntry.getEndOffset(requestedShareFile .getFileSize()); contentLength = endOffset - startOffset + 1; } URN sharedFileURN = requestedShareFile.getURN(); if ( gRequest.isTigerTreeRequest() ) { uploadState.update(hostAddress, vendor, requestedShareFile.getFileName()); } else { uploadState.update(hostAddress, vendor, requestedShareFile .getFileName(), sharedFileURN, requestedShareFile.getSystemFile(), contentLength); } if ( !uploadMgr.containsUploadState(uploadState) ) { uploadMgr.addUploadState(uploadState); } uploadState.setUploadEngine(this); // form ok response... if ( !gRequest.isTigerTreeRequest() ) { if (startOffset == 0 && endOffset == requestedShareFile.getFileSize() - 1) { httpResponse = new HTTPResponse((short) 200, "OK", true); } else { httpResponse = new HTTPResponse((short) 206, "Partial Content", true); } if (additionalResponseHeader != null) { httpResponse.addHeader(additionalResponseHeader); } } else { httpResponse = new HTTPResponse((short) 200, "OK", true); } // TODO for browser request we might like to return explicite content // types: // contentType = MimeTypeMapping.getMimeTypeForExtension( ext ); httpResponse.addHeader(new HTTPHeader(HTTPHeaderNames.CONTENT_TYPE, "application/binary")); if ( !gRequest.isTigerTreeRequest() ) { httpResponse.addHeader(new HTTPHeader( HTTPHeaderNames.CONTENT_LENGTH, String.valueOf(contentLength))); httpResponse.addHeader(new HTTPHeader( HTTPHeaderNames.CONTENT_RANGE, "bytes " + startOffset + "-" + endOffset + "/" + requestedShareFile.getFileSize())); } // in case of tiger tree request we need to close the connection since // we dont know the content length of the dime here already... // TODO: we could pre calculate the dime length in this case! if ( isPersistentConnection && !gRequest.isTigerTreeRequest() ) { httpResponse.addHeader( new HTTPHeader( HTTPHeaderNames.CONNECTION, "Keep-Alive" ) ); } else { httpResponse.addHeader(new HTTPHeader(HTTPHeaderNames.CONNECTION, "close")); isPersistentConnection = false; } if ( sharedFileURN != null ) { httpResponse.addHeader(new HTTPHeader( GnutellaHeaderNames.X_GNUTELLA_CONTENT_URN, sharedFileURN .getAsString())); } if ( !gRequest.isTigerTreeRequest() ) { addAltLocResponseHeader(httpResponse, requestedShareFile); addPushProxyResponseHeader( httpResponse ); } if ( sharedFileURN != null && !gRequest.isTigerTreeRequest() ) { parseAltLocRequestHeader( requestedShareFile, sharedFileURN ); // add thex download url ShareFileThexData thexData = requestedShareFile.getThexData( true ); if ( thexData != null ) { String thexRootHash = thexData.getRootHash(); HTTPHeader thexHeader = new HTTPHeader( GnutellaHeaderNames.X_THEX_URI, URLUtil.buildName2ResThexURL( sharedFileURN, thexRootHash ) ); httpResponse.addHeader( thexHeader ); } } sendHTTPResponse(httpResponse); socket.setSoTimeout(ServiceManager.sCfg.socketConnectTimeout); // check if we need to count again.. // this is the case if we have no PartialShareFile (same // PartialShareFile is never equal again, since its always a new instance) // and the ShareFile is not equal to the requested file. if ( uploadShareFile != null && !(requestedShareFile instanceof PartialShareFile) && uploadShareFile != requestedShareFile) { isUploadCounted = false; } uploadShareFile = requestedShareFile; minNextPollTime = -1; return true; }
int available = throttleController.getAvailableByteCount( true ); int ableToSend = Math.min( likeToSend, available );
int ableToSend = throttleController.getAvailableByteCount( likeToSend, true, false );
private void sendBinaryData() throws IOException { NLogger.debug(UploadEngine.class, "About to send binary range: " + startOffset + " to " + endOffset); uploadState.addToUploadLog( "About to send binary range: " + startOffset + " to " + endOffset ); // the upload is actually starting now.. // if not yet done we are counting this upload. if (!isUploadCounted) { // count upload even if upload is just starting and not finished // yet. // swarming uploads fail often anyway. uploadShareFile.incUploadCount(); // Increment the completed uploads count StatisticsManager statMgr = StatisticsManager.getInstance(); SimpleStatisticProvider provider = (SimpleStatisticProvider) statMgr .getStatisticProvider(StatisticProviderConstants.SESSION_UPLOAD_COUNT_PROVIDER); provider.increment(1); isUploadCounted = true; } uploadState.setStatus(UploadConstants.STATUS_UPLOADING); // open file File sourceFile = uploadState.getUploadFile(); raFile = new RandomAccessFile(sourceFile, "r"); raFile.seek(fileStartOffset); BandwidthController throttleController = BandwidthManager.getInstance() .getUploadBandwidthController(); long lengthToUpload = endOffset - startOffset + 1; long lengthUploaded = 0; int lengthRead = -1; int likeToSend; OutputStream outStream = connection.getOutputStream(); byte[] buffer = new byte[BUFFER_LENGTH]; while (lengthToUpload > 0) { // make sure we dont send more then requested likeToSend = (int) Math.min(lengthToUpload, (long) BUFFER_LENGTH); // we may be throttled to less than this amount int available = throttleController.getAvailableByteCount( true ); int ableToSend = Math.min( likeToSend, available ); if ( NLogger.isDebugEnabled( UploadEngine.class ) ) { NLogger.debug( UploadEngine.class, "Reading in " + ableToSend + " bytes at " + raFile.getFilePointer() + " from " + sourceFile.getName()); } lengthRead = raFile.read(buffer, 0, ableToSend); // lengthRead should equal ableToSend. I can't see a reason // why it wouldn't.... if (lengthRead == -1) { break; } outStream.write(buffer, 0, lengthRead); lengthToUpload -= lengthRead; lengthUploaded += lengthRead; uploadState.setTransferredDataSize(lengthUploaded); } uploadState.setStatus(UploadConstants.STATUS_COMPLETED); }
public synchronized int getAvailableByteCount( boolean blockTillAvailable )
public synchronized int getAvailableByteCount( int maxToRequest, boolean blockTillAvailable, boolean markBytesUsed ) throws IOException
public synchronized int getAvailableByteCount( boolean blockTillAvailable ) { updateWindow( blockTillAvailable ); int bytesAllowed = bytesRemaining; // If there is another controller we are chained to, call it. if( nextContollerInChain != null ) { bytesAllowed = Math.min( bytesAllowed, nextContollerInChain.getAvailableByteCount( blockTillAvailable ) ); } short logLevel = NLogger.LOG_LEVEL_DEBUG; if ( bytesRemaining < 0 ) { logLevel = NLogger.LOG_LEVEL_ERROR; } if ( NLogger.isEnabled( logLevel, NLoggerNames.BANDWIDTH ) ) { NLogger.log( logLevel, NLoggerNames.BANDWIDTH, "["+controllerName + "] Available byte count " + bytesAllowed + "bps - Remaining: " + bytesRemaining + "."); } return bytesAllowed; }
int bytesAllowed = bytesRemaining;
int bytesAllowed = Math.max( 0, Math.min( maxToRequest, bytesRemaining ) );
public synchronized int getAvailableByteCount( boolean blockTillAvailable ) { updateWindow( blockTillAvailable ); int bytesAllowed = bytesRemaining; // If there is another controller we are chained to, call it. if( nextContollerInChain != null ) { bytesAllowed = Math.min( bytesAllowed, nextContollerInChain.getAvailableByteCount( blockTillAvailable ) ); } short logLevel = NLogger.LOG_LEVEL_DEBUG; if ( bytesRemaining < 0 ) { logLevel = NLogger.LOG_LEVEL_ERROR; } if ( NLogger.isEnabled( logLevel, NLoggerNames.BANDWIDTH ) ) { NLogger.log( logLevel, NLoggerNames.BANDWIDTH, "["+controllerName + "] Available byte count " + bytesAllowed + "bps - Remaining: " + bytesRemaining + "."); } return bytesAllowed; }
bytesAllowed = Math.min( bytesAllowed, nextContollerInChain.getAvailableByteCount( blockTillAvailable ) );
bytesAllowed = nextContollerInChain.getAvailableByteCount( bytesAllowed, blockTillAvailable, markBytesUsed ); } if ( markBytesUsed ) { markBytesUsed( bytesAllowed );
public synchronized int getAvailableByteCount( boolean blockTillAvailable ) { updateWindow( blockTillAvailable ); int bytesAllowed = bytesRemaining; // If there is another controller we are chained to, call it. if( nextContollerInChain != null ) { bytesAllowed = Math.min( bytesAllowed, nextContollerInChain.getAvailableByteCount( blockTillAvailable ) ); } short logLevel = NLogger.LOG_LEVEL_DEBUG; if ( bytesRemaining < 0 ) { logLevel = NLogger.LOG_LEVEL_ERROR; } if ( NLogger.isEnabled( logLevel, NLoggerNames.BANDWIDTH ) ) { NLogger.log( logLevel, NLoggerNames.BANDWIDTH, "["+controllerName + "] Available byte count " + bytesAllowed + "bps - Remaining: " + bytesRemaining + "."); } return bytesAllowed; }
sb.append(" <YEAST_COST>" + yeast.getCostPerU() + "</YEAST_COST>\n"); sb.append(" <OTHER_COST>" + otherCost + "</OTHER_COST>\n");
public String toXML() { StringBuffer sb = new StringBuffer(); sb.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"); sb.append("<STRANGEBREWRECIPE version = \"" + version + "\">\n"); sb.append("<!-- This is a SBJava export. StrangeBrew 1.8 will not import it. -->\n"); sb.append(" <DETAILS>\n"); sb.append(" <NAME>" + SBStringUtils.subEntities(name) + "</NAME>\n"); sb.append(" <BREWER>" + SBStringUtils.subEntities(brewer) + "</BREWER>\n"); sb.append(" <NOTES>" + SBStringUtils.subEntities(comments) + "</NOTES>\n"); sb.append(" <EFFICIENCY>" + efficiency + "</EFFICIENCY>\n"); sb.append(" <OG>" + SBStringUtils.df3.format(estOg) + "</OG>\n"); sb.append(" <FG>" + SBStringUtils.df3.format(estFg) + "</FG>\n"); sb.append(" <STYLE>" + style.getName() + "</STYLE>\n"); sb.append(" <MASH>" + mashed + "</MASH>\n"); sb.append(" <LOV>" + SBStringUtils.df1.format(srm) + "</LOV>\n"); sb.append(" <IBU>" + SBStringUtils.df1.format(ibu) + "</IBU>\n"); sb.append(" <ALC>" + SBStringUtils.df1.format(alcohol) + "</ALC>\n"); sb.append(" <BOIL_TIME>" + boilMinutes + "</BOIL_TIME>\n"); sb.append(" <PRESIZE>" + preBoilVol.getValue() + "</PRESIZE>\n"); sb.append(" <SIZE>" + postBoilVol.getValue() + "</SIZE>\n"); sb.append(" <SIZE_UNITS>" + postBoilVol.getUnits() + "</SIZE_UNITS>\n"); sb.append(" <MALT_UNITS>" + maltUnits + "</MALT_UNITS>\n"); sb.append(" <HOPS_UNITS>" + hopUnits + "</HOPS_UNITS>\n"); sb.append(" <YEAST>" + yeast.getName() + "</YEAST>\n"); SimpleDateFormat df = new SimpleDateFormat("MM/dd/yyyy"); sb.append(" <RECIPE_DATE>" + df.format(created.getTime()) + "</RECIPE_DATE>\n"); sb.append(" <ATTENUATION>" + attenuation + "</ATTENUATION>\n"); sb.append(" <!-- SBJ1.0 Extensions: -->\n"); sb.append(" <ALC_METHOD>" + alcMethod + "</ALC_METHOD>\n"); sb.append(" <IBU_METHOD>" + ibuCalcMethod + "</IBU_METHOD>\n"); sb.append(" <COLOUR_METHOD>" + colourMethod + "</COLOUR_METHOD>\n"); sb.append(" <EVAP>" + evap + "</EVAP>\n"); sb.append(" <EVAP_METHOD>" + evapMethod + "</EVAP_METHOD>\n"); sb.append(" <KETTLE_LOSS>" + kettleLoss + "</KETTLE_LOSS>\n"); sb.append(" <TRUB_LOSS>" + trubLoss + "</TRUB_LOSS>\n"); sb.append(" <MISC_LOSS>" + miscLoss + "</MISC_LOSS>\n"); sb.append(" <PELLET_HOP_PCT>" + pelletHopPct + "</PELLET_HOP_PCT>\n"); sb.append(" <!-- END SBJ1.0 Extensions -->\n"); sb.append(" </DETAILS>\n"); // fermentables list: sb.append(" <FERMENTABLES>\n"); for (int i = 0; i < fermentables.size(); i++) { Fermentable m = (Fermentable) fermentables.get(i); sb.append(m.toXML()); } sb.append(" </FERMENTABLES>\n"); // hops list: sb.append(" <HOPS>\n"); for (int i = 0; i < hops.size(); i++) { Hop h = (Hop) hops.get(i); sb.append(h.toXML()); } sb.append(" </HOPS>\n"); // misc ingredients list: sb.append(" <MISC>\n"); for (int i = 0; i < misc.size(); i++) { Misc mi = (Misc) misc.get(i); sb.append(mi.toXML()); } sb.append(" </MISC>\n"); sb.append(mash.toXml()); // notes list: sb.append(" <NOTES>\n"); for (int i = 0; i < notes.size(); i++) { sb.append(((Note) notes.get(i)).toXML()); } sb.append(" </NOTES>\n"); sb.append("</STRANGEBREWRECIPE>"); return sb.toString(); }
app.saveAsHTML(file, "ca/strangebrew/data/recipeToHtml.xslt", printOptions);
app.saveAsHTML(file, "recipeToHtml.xslt", printOptions);
public void actionPerformed(ActionEvent ev) { Object o = ev.getSource(); String font = fontComboModel.getSelectedItem().toString(); String fontSize = sizeSpin.getValue().toString(); String printOptions = " <PRINT FONTSIZE=\"" + fontSize + "pt\" FONTFACE=\"" + font + "\"/>\n"; if (o == prevButton) { File file = new File("print.html"); try { app.saveAsHTML(file, "ca/strangebrew/data/recipeToHtml.xslt", printOptions); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } String urlString; try { urlString = "file://" + file.getCanonicalPath(); Debug.print(urlString); AbstractLogger logger = new SystemLogger(); BrowserLauncher launcher; launcher = new BrowserLauncher(logger); BrowserLauncherRunner runner = new BrowserLauncherRunner(launcher, urlString, null); Thread launcherThread = new Thread(runner); launcherThread.start(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (BrowserLaunchingInitializingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (UnsupportedOperatingSystemException e) { // TODO Auto-generated catch block e.printStackTrace(); } } setVisible(false); dispose(); }
return calculateComplexValue((Complex) group.getRootVal());
return calculateComplexValue(group.getRootVal());
public Complex getComplexValue() { return calculateComplexValue((Complex) group.getRootVal()); }
AmpConfigData dssData = (AmpConfigData)ampData.get(sdce.getSource()); dssData.addSeismograms(sdce.getSeismos()); this.seismos = null; calculateAmp(); recalculateAmp(); fireAmpEvent();
AmpConfigData dssData = (AmpConfigData)ampData.get(sdce.getSource()); if ( dssData == null) { return; } dssData.addSeismograms(sdce.getSeismos()); this.seismos = null; calculateAmp(); recalculateAmp(); fireAmpEvent();
public synchronized void pushData(SeisDataChangeEvent sdce) { AmpConfigData dssData = (AmpConfigData)ampData.get(sdce.getSource()); dssData.addSeismograms(sdce.getSeismos()); this.seismos = null; calculateAmp(); recalculateAmp(); fireAmpEvent(); }
Object val = Scaler.getInstance(mat.getEle(0,0));
Object val = mat.getEle(0,0);
public MatrixValueI calcValue(MatrixValueI res, MatrixValueI lhs) throws ParseException { if(!(res instanceof Scaler)) throw new ParseException("trace: result must be a scaler"); if(!(lhs instanceof Matrix)) throw new ParseException("trace: argument must be a matrix"); Matrix mat = (Matrix) lhs; if( mat.getNumRows()!= mat.getNumCols()) throw new ParseException("trace: argument must be a square matrix "+mat); if(mat.getNumRows() == 2) { res.setEle(0,add.add(mat.getEle(0,0),mat.getEle(1,1))); } else if(mat.getNumRows() == 3) { res.setEle(0,add.add(mat.getEle(0,0),add.add(mat.getEle(1,1),mat.getEle(2,2)))); } else { Object val = Scaler.getInstance(mat.getEle(0,0)); for(int i=1;i<mat.getNumRows();++i) val = add.add(val,mat.getEle(i,i)); res.setEle(0,val); } return res; }
assertEquals(userRole, authorizationDao.findUserRoleByNaturalId(userRole.getUser(), userRole.getService(), userRole.getServiceExtension()));
assertEquals(userRole, authorizationDao.findUserRoleByNaturalId(userRole.getUserGroup(), userRole.getService(), userRole.getServiceExtension()));
public void testFindUserRole() { // write list List<UserRole> userRoleList = writeUserRole(); // read UserRole userRole = userRoleList.get((int) Math.random()*userRoleList.size()); assertEquals(userRole, authorizationDao.findUserRoleByNaturalId(userRole.getUser(), userRole.getService(), userRole.getServiceExtension())); }
assertEquals(userRole, authorizationDao.findUserRoleByNaturalId(userRole.getUser(), userRole.getService(), userRole.getServiceExtension()));
assertEquals(userRole, authorizationDao.findUserRoleByNaturalId(userRole.getUserGroup(), userRole.getService(), userRole.getServiceExtension()));
public void testPersistUserRole() { //write UserRole userRole = createAndPersistUserRole(authorizationDao); hibernateTemplate.flush(); //read assertEquals(userRole, authorizationDao.findUserRoleByNaturalId(userRole.getUser(), userRole.getService(), userRole.getServiceExtension())); }
this.parser.setInitialTokenManagerState(Parser.NO_DOT_IN_IDENTIFIERS);
this.parser.setInitialTokenManagerState(ParserConstants.NO_DOT_IN_IDENTIFIERS);
public MatrixJep() { super(); nf = new MatrixNodeFactory(); symTab = new DSymbolTable(mvf); opSet = new MatrixOperatorSet(); this.parser.setInitialTokenManagerState(Parser.NO_DOT_IN_IDENTIFIERS); Operator tens = ((MatrixOperatorSet) opSet).getMList(); pv.addSpecialRule(tens,(PrintVisitor.PrintRulesI) 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)); }
else return res;
return res;
public Object evaluate(Node node) throws ParseException { Object res = mev.evaluate((MatrixNodeI) node,this); if(res instanceof Scaler) return ((Scaler) res).getEle(0); else return res; }
else return res;
return res;
public Object getValueAsObject() { try { Object res = mev.evaluate((MatrixNodeI) getTopNode(),this); if(res instanceof Scaler) return ((Scaler) res).getEle(0); else return res; } catch(Exception e) { this.errorList.addElement("Error during evaluation:"); this.errorList.addElement(e.getMessage()); return null; } }
public synchronized void doWs( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException {
public void doWs( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException {
public synchronized void doWs( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException { File dir = getWorkspace().getLocal(); if(!dir.exists()) { // if there's no workspace, report a nice error message rsp.forward(this,"noWorkspace",req); } else { serveFile(req, rsp, dir, "folder.gif", true); } }
File xsltFile = new File(path + xslt);
File xsltFile = new File(path, xslt);
public void saveAsHTML(File f, String xslt, String options) throws Exception { // save file as xml, then transform it to html File tmp = new File("tmp.xml"); FileWriter out = new FileWriter(tmp); out.write(myRecipe.toXML(options)); out.close(); // find the xslt stylesheet in the classpath // URL xsltUrl = getClass().getClassLoader().getResource(xslt); String path = SBStringUtils.getAppPath("data"); File xsltFile = new File(path + xslt); FileOutputStream output = new FileOutputStream(f); XmlTransformer.writeStream(tmp, xsltFile, output); // tmp.delete(); }
println("DJep: differention in JEP. eg. diff(x^2,x)");
println("DJep: differentation in JEP. eg. diff(x^2,x)");
public void printIntroText() { println("DJep: differention in JEP. eg. diff(x^2,x)"); printStdHelp(); }
DJep j = (DJep) this.j;
DJep dj = (DJep) this.j;
public void processEquation(Node node) throws ParseException { DJep j = (DJep) this.j; if(verbose) { print("Parsed:\t\t"); println(j.toString(node)); } Node processed = j.preprocess(node); if(verbose) { print("Processed:\t"); println(j.toString(processed)); } Node simp = j.simplify(processed); if(verbose) print("Simplified:\t"); println(j.toString(simp)); if(verbose) { print("Full Brackets, no variable expansion:\n\t\t"); j.getPrintVisitor().setMode(PrintVisitor.FULL_BRACKET,true); j.getPrintVisitor().setMode(DPrintVisitor.PRINT_PARTIAL_EQNS,false); println(j.toString(simp)); j.getPrintVisitor().setMode(DPrintVisitor.PRINT_PARTIAL_EQNS,true); j.getPrintVisitor().setMode(PrintVisitor.FULL_BRACKET,false); } Object val = j.evaluate(simp); String s = j.getPrintVisitor().formatValue(val); println("Value:\t\t"+s); }
println(j.toString(node));
println(dj.toString(node));
public void processEquation(Node node) throws ParseException { DJep j = (DJep) this.j; if(verbose) { print("Parsed:\t\t"); println(j.toString(node)); } Node processed = j.preprocess(node); if(verbose) { print("Processed:\t"); println(j.toString(processed)); } Node simp = j.simplify(processed); if(verbose) print("Simplified:\t"); println(j.toString(simp)); if(verbose) { print("Full Brackets, no variable expansion:\n\t\t"); j.getPrintVisitor().setMode(PrintVisitor.FULL_BRACKET,true); j.getPrintVisitor().setMode(DPrintVisitor.PRINT_PARTIAL_EQNS,false); println(j.toString(simp)); j.getPrintVisitor().setMode(DPrintVisitor.PRINT_PARTIAL_EQNS,true); j.getPrintVisitor().setMode(PrintVisitor.FULL_BRACKET,false); } Object val = j.evaluate(simp); String s = j.getPrintVisitor().formatValue(val); println("Value:\t\t"+s); }
Node processed = j.preprocess(node);
Node processed = dj.preprocess(node);
public void processEquation(Node node) throws ParseException { DJep j = (DJep) this.j; if(verbose) { print("Parsed:\t\t"); println(j.toString(node)); } Node processed = j.preprocess(node); if(verbose) { print("Processed:\t"); println(j.toString(processed)); } Node simp = j.simplify(processed); if(verbose) print("Simplified:\t"); println(j.toString(simp)); if(verbose) { print("Full Brackets, no variable expansion:\n\t\t"); j.getPrintVisitor().setMode(PrintVisitor.FULL_BRACKET,true); j.getPrintVisitor().setMode(DPrintVisitor.PRINT_PARTIAL_EQNS,false); println(j.toString(simp)); j.getPrintVisitor().setMode(DPrintVisitor.PRINT_PARTIAL_EQNS,true); j.getPrintVisitor().setMode(PrintVisitor.FULL_BRACKET,false); } Object val = j.evaluate(simp); String s = j.getPrintVisitor().formatValue(val); println("Value:\t\t"+s); }
println(j.toString(processed));
println(dj.toString(processed));
public void processEquation(Node node) throws ParseException { DJep j = (DJep) this.j; if(verbose) { print("Parsed:\t\t"); println(j.toString(node)); } Node processed = j.preprocess(node); if(verbose) { print("Processed:\t"); println(j.toString(processed)); } Node simp = j.simplify(processed); if(verbose) print("Simplified:\t"); println(j.toString(simp)); if(verbose) { print("Full Brackets, no variable expansion:\n\t\t"); j.getPrintVisitor().setMode(PrintVisitor.FULL_BRACKET,true); j.getPrintVisitor().setMode(DPrintVisitor.PRINT_PARTIAL_EQNS,false); println(j.toString(simp)); j.getPrintVisitor().setMode(DPrintVisitor.PRINT_PARTIAL_EQNS,true); j.getPrintVisitor().setMode(PrintVisitor.FULL_BRACKET,false); } Object val = j.evaluate(simp); String s = j.getPrintVisitor().formatValue(val); println("Value:\t\t"+s); }
Node simp = j.simplify(processed);
Node simp = dj.simplify(processed);
public void processEquation(Node node) throws ParseException { DJep j = (DJep) this.j; if(verbose) { print("Parsed:\t\t"); println(j.toString(node)); } Node processed = j.preprocess(node); if(verbose) { print("Processed:\t"); println(j.toString(processed)); } Node simp = j.simplify(processed); if(verbose) print("Simplified:\t"); println(j.toString(simp)); if(verbose) { print("Full Brackets, no variable expansion:\n\t\t"); j.getPrintVisitor().setMode(PrintVisitor.FULL_BRACKET,true); j.getPrintVisitor().setMode(DPrintVisitor.PRINT_PARTIAL_EQNS,false); println(j.toString(simp)); j.getPrintVisitor().setMode(DPrintVisitor.PRINT_PARTIAL_EQNS,true); j.getPrintVisitor().setMode(PrintVisitor.FULL_BRACKET,false); } Object val = j.evaluate(simp); String s = j.getPrintVisitor().formatValue(val); println("Value:\t\t"+s); }
println(j.toString(simp));
println(dj.toString(simp));
public void processEquation(Node node) throws ParseException { DJep j = (DJep) this.j; if(verbose) { print("Parsed:\t\t"); println(j.toString(node)); } Node processed = j.preprocess(node); if(verbose) { print("Processed:\t"); println(j.toString(processed)); } Node simp = j.simplify(processed); if(verbose) print("Simplified:\t"); println(j.toString(simp)); if(verbose) { print("Full Brackets, no variable expansion:\n\t\t"); j.getPrintVisitor().setMode(PrintVisitor.FULL_BRACKET,true); j.getPrintVisitor().setMode(DPrintVisitor.PRINT_PARTIAL_EQNS,false); println(j.toString(simp)); j.getPrintVisitor().setMode(DPrintVisitor.PRINT_PARTIAL_EQNS,true); j.getPrintVisitor().setMode(PrintVisitor.FULL_BRACKET,false); } Object val = j.evaluate(simp); String s = j.getPrintVisitor().formatValue(val); println("Value:\t\t"+s); }
j.getPrintVisitor().setMode(PrintVisitor.FULL_BRACKET,true); j.getPrintVisitor().setMode(DPrintVisitor.PRINT_PARTIAL_EQNS,false); println(j.toString(simp)); j.getPrintVisitor().setMode(DPrintVisitor.PRINT_PARTIAL_EQNS,true); j.getPrintVisitor().setMode(PrintVisitor.FULL_BRACKET,false);
dj.getPrintVisitor().setMode(PrintVisitor.FULL_BRACKET,true); dj.getPrintVisitor().setMode(DPrintVisitor.PRINT_PARTIAL_EQNS,false); println(dj.toString(simp)); dj.getPrintVisitor().setMode(DPrintVisitor.PRINT_PARTIAL_EQNS,true); dj.getPrintVisitor().setMode(PrintVisitor.FULL_BRACKET,false);
public void processEquation(Node node) throws ParseException { DJep j = (DJep) this.j; if(verbose) { print("Parsed:\t\t"); println(j.toString(node)); } Node processed = j.preprocess(node); if(verbose) { print("Processed:\t"); println(j.toString(processed)); } Node simp = j.simplify(processed); if(verbose) print("Simplified:\t"); println(j.toString(simp)); if(verbose) { print("Full Brackets, no variable expansion:\n\t\t"); j.getPrintVisitor().setMode(PrintVisitor.FULL_BRACKET,true); j.getPrintVisitor().setMode(DPrintVisitor.PRINT_PARTIAL_EQNS,false); println(j.toString(simp)); j.getPrintVisitor().setMode(DPrintVisitor.PRINT_PARTIAL_EQNS,true); j.getPrintVisitor().setMode(PrintVisitor.FULL_BRACKET,false); } Object val = j.evaluate(simp); String s = j.getPrintVisitor().formatValue(val); println("Value:\t\t"+s); }
Object val = j.evaluate(simp); String s = j.getPrintVisitor().formatValue(val);
Object val = dj.evaluate(simp); String s = dj.getPrintVisitor().formatValue(val);
public void processEquation(Node node) throws ParseException { DJep j = (DJep) this.j; if(verbose) { print("Parsed:\t\t"); println(j.toString(node)); } Node processed = j.preprocess(node); if(verbose) { print("Processed:\t"); println(j.toString(processed)); } Node simp = j.simplify(processed); if(verbose) print("Simplified:\t"); println(j.toString(simp)); if(verbose) { print("Full Brackets, no variable expansion:\n\t\t"); j.getPrintVisitor().setMode(PrintVisitor.FULL_BRACKET,true); j.getPrintVisitor().setMode(DPrintVisitor.PRINT_PARTIAL_EQNS,false); println(j.toString(simp)); j.getPrintVisitor().setMode(DPrintVisitor.PRINT_PARTIAL_EQNS,true); j.getPrintVisitor().setMode(PrintVisitor.FULL_BRACKET,false); } Object val = j.evaluate(simp); String s = j.getPrintVisitor().formatValue(val); println("Value:\t\t"+s); }
else if (o == crb || o == frb){ if (crb.isSelected()) boilTempULbl.setText("C"); else boilTempULbl.setText("F"); }
public void actionPerformed(ActionEvent e) { Object o = e.getSource(); if (o == okButton) { saveOptions(); opts.saveProperties(); ((StrangeSwing)sb).displayRecipe(); setVisible(false); dispose(); } else if (o == cancelButton){ setVisible(false); dispose(); } else if (o == colMethod1rb || o == colMethod2rb){ redSpn.setEnabled(o == colMethod1rb); greenSpn.setEnabled(o == colMethod1rb); blueSpn.setEnabled(o == colMethod1rb); displayColour(); } else if (o == rbPercent){ evapAmountLbl.setText("%"); } else if (o == rbConstant){ evapAmountLbl.setText(Quantity.getVolAbrv(volUnitsComboModel.getSelectedItem().toString()) + "/hr"); } }
mashPanel.add(jLabel12); jLabel12.setText("Boil Temp (F):");
mashPanel.add(jLabel12, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel12.setText("Boil Temp:");
private void layoutUi() { JPanel buttons = new JPanel(); okButton = new JButton("OK"); okButton.addActionListener(this); cancelButton = new JButton("Cancel"); cancelButton.addActionListener(this); buttons.setLayout(new FlowLayout(FlowLayout.RIGHT)); buttons.add(cancelButton); buttons.add(okButton); getContentPane().setLayout(new BorderLayout()); this.setFocusTraversalKeysEnabled(false); { jTabbedPane1 = new JTabbedPane(); getContentPane().add(jTabbedPane1, BorderLayout.CENTER); { pnlCalculations = new JPanel(); jTabbedPane1.addTab("Calculations", null, pnlCalculations, null); { try { { GridBagLayout thisLayout = new GridBagLayout(); thisLayout.rowWeights = new double[]{0.1, 0.1, 0.1, 0.1}; thisLayout.rowHeights = new int[]{7, 7, 7, 7}; thisLayout.columnWeights = new double[]{0.1, 0.2}; thisLayout.columnWidths = new int[]{7, 7}; pnlCalculations.setLayout(thisLayout); pnlCalculations.setPreferredSize(new java.awt.Dimension(524, 372)); { { bgHopsCalc = new ButtonGroup(); { pnlHops = new JPanel(); GridLayout pnlHopsLayout = new GridLayout(2, 2); pnlHopsLayout.setColumns(2); pnlHopsLayout.setHgap(5); pnlHopsLayout.setVgap(5); pnlHopsLayout.setRows(2); pnlHops.setLayout(pnlHopsLayout); pnlCalculations.add(pnlHops, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); pnlHops .setBorder(BorderFactory .createTitledBorder("Hops:")); { jLabelc1 = new JLabel(); pnlHops.add(jLabelc1); jLabelc1.setText("Pellet Hops +%"); } { txtPellet = new JTextField(); pnlHops.add(txtPellet); txtPellet.setPreferredSize(new java.awt.Dimension(20, 20)); } { jLabelc2 = new JLabel(); pnlHops.add(jLabelc2); jLabelc2.setText("Tinseth Utilization Factor"); } { txtTinsethUtil = new JTextField(); pnlHops.add(txtTinsethUtil); txtTinsethUtil.setText("4.15"); } } { pnlAlc = new JPanel(); BoxLayout pnlAlcLayout = new BoxLayout(pnlAlc, javax.swing.BoxLayout.Y_AXIS); pnlAlc.setLayout(pnlAlcLayout); pnlCalculations.add(pnlAlc, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); pnlAlc.setBorder(BorderFactory .createTitledBorder("Alcohol By:")); { rbABV = new JRadioButton(); pnlAlc.add(rbABV); bgAlc.add(rbABV); rbABV.setText("Volume"); } { rbABW = new JRadioButton(); pnlAlc.add(rbABW); bgAlc.add(rbABW); rbABW.setText("Weight"); } } { pnlHopTimes = new JPanel(); GridLayout pnlHopTimesLayout = new GridLayout(3, 2); pnlHopTimesLayout.setColumns(2); pnlHopTimesLayout.setHgap(5); pnlHopTimesLayout.setVgap(5); pnlHopTimesLayout.setRows(3); pnlHopTimes.setLayout(pnlHopTimesLayout); pnlCalculations.add(pnlHopTimes, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); pnlHopTimes.setBorder(BorderFactory .createTitledBorder("Hop Times:")); { jLabelc3 = new JLabel(); pnlHopTimes.add(jLabelc3); jLabelc3.setText("Dry (min):"); } { txtDryHopTime = new JTextField(); pnlHopTimes.add(txtDryHopTime); txtDryHopTime.setText("0.0"); } { jLabelc4 = new JLabel(); pnlHopTimes.add(jLabelc4); jLabelc4.setText("FWH, boil minus (min):"); } { txtFWHTime = new JTextField(); pnlHopTimes.add(txtFWHTime); txtFWHTime.setText("20.0"); } { jLabelc5 = new JLabel(); pnlHopTimes.add(jLabelc5); jLabelc5.setText("Mash Hop (min):"); } { txtMashHopTime = new JTextField(); pnlHopTimes.add(txtMashHopTime); txtMashHopTime.setText("2.0"); } } } pnlHopsCalc = new JPanel(); BoxLayout pnlHopsCalcLayout = new BoxLayout(pnlHopsCalc, javax.swing.BoxLayout.Y_AXIS); pnlHopsCalc.setLayout(pnlHopsCalcLayout); pnlCalculations.add(pnlHopsCalc, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); pnlCalculations.add(getPnlWaterUsage(), new GridBagConstraints(1, 2, 1, 2, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); pnlCalculations.add(getPnlColourOptions(), new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); pnlCalculations.add(getPnlEvaporation(), new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); pnlHopsCalc.setPreferredSize(new java.awt.Dimension(117, 107)); pnlHopsCalc.setBorder(BorderFactory .createTitledBorder("IBU Calc Method:")); { rbTinseth = new JRadioButton(); pnlHopsCalc.add(rbTinseth); rbTinseth.setText("Tinseth"); bgHopsCalc.add(rbTinseth); } { rbRager = new JRadioButton(); pnlHopsCalc.add(rbRager); rbRager.setText("Rager"); bgHopsCalc.add(rbRager); } { rbGaretz = new JRadioButton(); pnlHopsCalc.add(rbGaretz); rbGaretz.setText("Garetz"); bgHopsCalc.add(rbGaretz); } } } } catch (Exception e) { e.printStackTrace(); } } } { costCarbPanel = new JPanel(); BorderLayout costCarbPanelLayout = new BorderLayout(); costCarbPanel.setLayout(costCarbPanelLayout); jTabbedPane1.addTab("Cost & Carb", null, costCarbPanel, null); { carbPanel = new JPanel(); costCarbPanel.add(carbPanel, BorderLayout.CENTER); carbPanel.setBorder(BorderFactory.createTitledBorder(null, "Carbonation", TitledBorder.LEADING, TitledBorder.TOP)); { jLabel3 = new JLabel(); carbPanel.add(jLabel3); jLabel3.setText("Not implemented"); } } { jPanel2 = new JPanel(); costCarbPanel.add(jPanel2, BorderLayout.NORTH); GridBagLayout jPanel2Layout = new GridBagLayout(); jPanel2Layout.rowWeights = new double[]{0.1, 0.1, 0.4}; jPanel2Layout.rowHeights = new int[]{7, 7, 7}; jPanel2Layout.columnWeights = new double[]{0.1, 0.1, 0.1}; jPanel2Layout.columnWidths = new int[]{7, 7, 7}; jPanel2.setPreferredSize(new java.awt.Dimension(232, 176)); jPanel2.setBorder(BorderFactory.createTitledBorder("Cost")); jPanel2.setLayout(jPanel2Layout); { jLabel1 = new JLabel(); jPanel2.add(jLabel1, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel1.setText("Other Cost:"); } { txtOtherCost = new JTextField(); jPanel2.add(txtOtherCost, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); txtOtherCost.setText("$0.00"); txtOtherCost.setPreferredSize(new java.awt.Dimension(62, 20)); } { jLabel2 = new JLabel(); jPanel2.add(jLabel2, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel2.setText("Bottle Size:"); } { cmbBottleSize = new JComboBox(); cmbBottleSizeModel = new ComboModel(); cmbBottleSizeModel.setList(new Quantity().getListofUnits("vol")); cmbBottleSize.setModel(cmbBottleSizeModel); jPanel2.add(cmbBottleSize, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); cmbBottleSize.setPreferredSize(new java.awt.Dimension(89, 20)); jPanel2.add(getTxtBottleSize(), new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); } } { } } { pnlBrewer = new JPanel(); GridBagLayout pnlBrewerLayout = new GridBagLayout(); pnlBrewerLayout.rowWeights = new double[]{0.1, 0.1, 0.3, 0.3}; pnlBrewerLayout.rowHeights = new int[]{2, 2, 7, 7}; pnlBrewerLayout.columnWeights = new double[]{0.1, 0.1, 0.1, 0.1}; pnlBrewerLayout.columnWidths = new int[]{7, 7, 7, 7}; pnlBrewer.setLayout(pnlBrewerLayout); jTabbedPane1.addTab("Brewer", null, pnlBrewer, null); { jLabel4 = new JLabel(); pnlBrewer.add(jLabel4, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel4.setText("Name:"); } { txtBrewerName = new JTextField(); pnlBrewer.add(txtBrewerName, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); txtBrewerName.setText("Your Name"); } { jLabel5 = new JLabel(); pnlBrewer.add(jLabel5, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel5.setText("Phone:"); } { txtPhone = new JTextField(); pnlBrewer.add(txtPhone, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); txtPhone.setText("Your Phone"); } { jLabel6 = new JLabel(); pnlBrewer.add(jLabel6, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel6.setText("Club Name:"); } { txtClubName = new JTextField(); pnlBrewer.add(txtClubName, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); txtClubName.setText("Club Name"); } { jLabel7 = new JLabel(); pnlBrewer.add(jLabel7, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel7.setText("Email:"); } { txtEmail = new JTextField(); pnlBrewer.add(txtEmail, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); txtEmail.setText("Email"); } } { pnlDatabase = new JPanel(); BorderLayout pnlDatabaseLayout = new BorderLayout(); pnlDatabase.setLayout(pnlDatabaseLayout); pnlDatabase.add(getPnlDefaultDB(), BorderLayout.NORTH); pnlDatabase.add(getPnlSortOrder(), BorderLayout.WEST); jTabbedPane1.addTab("Database", null, pnlDatabase, null); pnlDatabase.setVisible(false); } newRecipePanel = new JPanel(); GridBagLayout newRecipePanelLayout = new GridBagLayout(); newRecipePanelLayout.rowWeights = new double[]{0.1, 0.1, 0.1, 0.1}; newRecipePanelLayout.rowHeights = new int[]{7, 7, 7, 7}; newRecipePanelLayout.columnWeights = new double[]{0.1, 0.1, 0.1, 0.1}; newRecipePanelLayout.columnWidths = new int[]{7, 7, 7, 7}; newRecipePanel.setLayout(newRecipePanelLayout); jTabbedPane1.addTab("New Recipe Defaults", null, newRecipePanel, null); appearancePanel = new JPanel(); BorderLayout appearancePanelLayout = new BorderLayout(); appearancePanel.setLayout(appearancePanelLayout); jTabbedPane1.addTab("Appearance", null, appearancePanel, null);/* landfPanel = new JPanel(); appearancePanel.add(landfPanel, BorderLayout.NORTH); jLabel19 = new JLabel(); landfPanel.add(jLabel19); jLabel19.setText("Look and Feel:"); landfCombo = new JComboBox(looks.toArray()); landfPanel.add(landfCombo);*/ colourPanel = new JPanel(); appearancePanel.add(colourPanel, BorderLayout.CENTER); GridBagLayout colourPanelLayout = new GridBagLayout(); colourPanelLayout.rowWeights = new double[] {0.1, 0.1, 0.1, 0.1, 0.1, 0.1}; colourPanelLayout.rowHeights = new int[] {7, 7, 7, 7, 7, 7}; colourPanelLayout.columnWeights = new double[] {0.1, 0.1, 0.1, 0.1, 0.1, 0.1}; colourPanelLayout.columnWidths = new int[] {7, 7, 7, 7, 7, 7}; colourPanel.setLayout(colourPanelLayout); colourPanel.setPreferredSize(new java.awt.Dimension(340, 223)); colourPanel.setBorder(BorderFactory.createTitledBorder("Colour Swatch")); colMethod1rb = new JRadioButton(); colMethod1rb.addActionListener(this); colourGroup.add(colMethod1rb); colourPanel.add(colMethod1rb, new GridBagConstraints(0, 0, 3, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); colMethod1rb.setText("Colour Method 1"); colMethod2rb = new JRadioButton(); colMethod2rb.addActionListener(this); colourGroup.add(colMethod2rb); colourPanel.add(colMethod2rb, new GridBagConstraints(3, 0, 3, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); colMethod2rb.setText("Colour Method 2"); jLabel13 = new JLabel(); colourPanel.add(jLabel13, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); jLabel13.setText("Straw \n(2)"); jLabel14 = new JLabel(); colourPanel.add(jLabel14, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); jLabel14.setText("Pale\n(4)"); jLabel15 = new JLabel(); colourPanel.add(jLabel15, new GridBagConstraints(2, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); jLabel15.setText("Amber\n(8)"); jLabel16 = new JLabel(); colourPanel.add(jLabel16, new GridBagConstraints(3, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); jLabel16.setText("Copper (15)"); jLabel17 = new JLabel(); colourPanel.add(jLabel17, new GridBagConstraints(4, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); jLabel17.setText("Brown (20)"); jLabel18 = new JLabel(); colourPanel.add(jLabel18, new GridBagConstraints(5, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); jLabel18.setText("Black (30)"); stawPanel = new JPanel(); colourPanel.add(stawPanel, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); stawPanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); palePanel = new JPanel(); colourPanel.add(palePanel, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); palePanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); amberPanel = new JPanel(); colourPanel.add(amberPanel, new GridBagConstraints(2, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); amberPanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); copperPanel = new JPanel(); colourPanel.add(copperPanel, new GridBagConstraints(3, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); copperPanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); brownPanel = new JPanel(); colourPanel.add(brownPanel, new GridBagConstraints(4, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); brownPanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); blackPanel = new JPanel(); colourPanel.add(blackPanel, new GridBagConstraints(5, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); blackPanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); SpinnerNumberModel redSpnModel = new SpinnerNumberModel(8,0,255,1); redSpn = new JSpinner(); colourPanel.add(redSpn, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); redSpn.setModel(redSpnModel); redSpn.addChangeListener(this); SpinnerNumberModel greenSpnModel = new SpinnerNumberModel(30,0,255,1); greenSpn = new JSpinner(); colourPanel.add(greenSpn, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); greenSpn.setModel(greenSpnModel); greenSpn.addChangeListener(this); SpinnerNumberModel blueSpnModel = new SpinnerNumberModel(20,0,255,1); blueSpn = new JSpinner(); colourPanel.add(blueSpn, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); blueSpn.setModel(blueSpnModel); blueSpn.addChangeListener(this); SpinnerNumberModel alphaSpnModel = new SpinnerNumberModel(255,0,255,1); alphaSpn = new JSpinner(); colourPanel.add(alphaSpn, new GridBagConstraints(3, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); alphaSpn.setModel(alphaSpnModel); alphaSpn.addChangeListener(this); jLabel20 = new JLabel(); colourPanel.add(jLabel20, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel20.setText("Red:"); jLabel21 = new JLabel(); colourPanel.add(jLabel21, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel21.setText("Blue:"); jLabel22 = new JLabel(); colourPanel.add(jLabel22, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel22.setText("Green:"); jLabel23 = new JLabel(); colourPanel.add(jLabel23, new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel23.setText("Alpha:"); mashPanel = new JPanel(); newRecipePanel.add(mashPanel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); mashPanel.setBorder(BorderFactory.createTitledBorder("Mash")); jPanel1 = new JPanel(); GridBagLayout jPanel1Layout = new GridBagLayout(); jPanel1Layout.rowWeights = new double[] {0.1, 0.1, 0.1, 0.1}; jPanel1Layout.rowHeights = new int[] {7, 7, 7, 7}; jPanel1Layout.columnWeights = new double[] {0.1, 0.1}; jPanel1Layout.columnWidths = new int[] {7, 7}; jPanel1.setLayout(jPanel1Layout); newRecipePanel.add(jPanel1, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); jPanel1.setBorder(BorderFactory.createTitledBorder("Units")); jLabel19 = new JLabel(); jPanel1.add(jLabel19, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel19.setText("Malt Units:"); maltUnitsCombo = new JComboBox(); jPanel1.add(maltUnitsCombo, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); maltUnitsComboModel = new ComboModel(); maltUnitsComboModel.setList(new Quantity().getListofUnits("weight")); maltUnitsCombo.setModel(maltUnitsComboModel); jLabel24 = new JLabel(); jPanel1.add(jLabel24, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel24.setText("Hops Units:"); hopsUnitsCombo = new JComboBox(); jPanel1.add(hopsUnitsCombo, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); hopsUnitsComboModel = new ComboModel(); hopsUnitsComboModel.setList(new Quantity().getListofUnits("weight")); hopsUnitsCombo.setModel(hopsUnitsComboModel); jLabel25 = new JLabel(); jPanel1.add(jLabel25, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel25.setText("Vol Units:"); volUnitsCombo = new JComboBox(); volUnitsCombo.addActionListener(new ActionListener() { public void actionPerformed (ActionEvent e){ setEvapLable(); } }); jPanel1.add(volUnitsCombo, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); volUnitsComboModel = new ComboModel(); volUnitsComboModel.setList(new Quantity().getListofUnits("vol")); volUnitsCombo.setModel(volUnitsComboModel); jLabel26 = new JLabel(); jPanel1.add(jLabel26, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel26.setText("Batch Size:"); batchSizeTxt = new JTextField(); jPanel1.add(batchSizeTxt, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); batchSizeTxt.setText("jTextField1"); jLabel12 = new JLabel(); mashPanel.add(jLabel12); jLabel12.setText("Boil Temp (F):"); boilTempTxt = new JTextField(); mashPanel.add(boilTempTxt); boilTempTxt.setText("212"); boilTempTxt.setPreferredSize(new java.awt.Dimension(43, 20)); } getContentPane().add(BorderLayout.CENTER, jTabbedPane1); getContentPane().add(BorderLayout.SOUTH, buttons); setSize(500, 500); }
mashPanel.add(boilTempTxt);
mashPanel.add(boilTempTxt, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
private void layoutUi() { JPanel buttons = new JPanel(); okButton = new JButton("OK"); okButton.addActionListener(this); cancelButton = new JButton("Cancel"); cancelButton.addActionListener(this); buttons.setLayout(new FlowLayout(FlowLayout.RIGHT)); buttons.add(cancelButton); buttons.add(okButton); getContentPane().setLayout(new BorderLayout()); this.setFocusTraversalKeysEnabled(false); { jTabbedPane1 = new JTabbedPane(); getContentPane().add(jTabbedPane1, BorderLayout.CENTER); { pnlCalculations = new JPanel(); jTabbedPane1.addTab("Calculations", null, pnlCalculations, null); { try { { GridBagLayout thisLayout = new GridBagLayout(); thisLayout.rowWeights = new double[]{0.1, 0.1, 0.1, 0.1}; thisLayout.rowHeights = new int[]{7, 7, 7, 7}; thisLayout.columnWeights = new double[]{0.1, 0.2}; thisLayout.columnWidths = new int[]{7, 7}; pnlCalculations.setLayout(thisLayout); pnlCalculations.setPreferredSize(new java.awt.Dimension(524, 372)); { { bgHopsCalc = new ButtonGroup(); { pnlHops = new JPanel(); GridLayout pnlHopsLayout = new GridLayout(2, 2); pnlHopsLayout.setColumns(2); pnlHopsLayout.setHgap(5); pnlHopsLayout.setVgap(5); pnlHopsLayout.setRows(2); pnlHops.setLayout(pnlHopsLayout); pnlCalculations.add(pnlHops, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); pnlHops .setBorder(BorderFactory .createTitledBorder("Hops:")); { jLabelc1 = new JLabel(); pnlHops.add(jLabelc1); jLabelc1.setText("Pellet Hops +%"); } { txtPellet = new JTextField(); pnlHops.add(txtPellet); txtPellet.setPreferredSize(new java.awt.Dimension(20, 20)); } { jLabelc2 = new JLabel(); pnlHops.add(jLabelc2); jLabelc2.setText("Tinseth Utilization Factor"); } { txtTinsethUtil = new JTextField(); pnlHops.add(txtTinsethUtil); txtTinsethUtil.setText("4.15"); } } { pnlAlc = new JPanel(); BoxLayout pnlAlcLayout = new BoxLayout(pnlAlc, javax.swing.BoxLayout.Y_AXIS); pnlAlc.setLayout(pnlAlcLayout); pnlCalculations.add(pnlAlc, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); pnlAlc.setBorder(BorderFactory .createTitledBorder("Alcohol By:")); { rbABV = new JRadioButton(); pnlAlc.add(rbABV); bgAlc.add(rbABV); rbABV.setText("Volume"); } { rbABW = new JRadioButton(); pnlAlc.add(rbABW); bgAlc.add(rbABW); rbABW.setText("Weight"); } } { pnlHopTimes = new JPanel(); GridLayout pnlHopTimesLayout = new GridLayout(3, 2); pnlHopTimesLayout.setColumns(2); pnlHopTimesLayout.setHgap(5); pnlHopTimesLayout.setVgap(5); pnlHopTimesLayout.setRows(3); pnlHopTimes.setLayout(pnlHopTimesLayout); pnlCalculations.add(pnlHopTimes, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); pnlHopTimes.setBorder(BorderFactory .createTitledBorder("Hop Times:")); { jLabelc3 = new JLabel(); pnlHopTimes.add(jLabelc3); jLabelc3.setText("Dry (min):"); } { txtDryHopTime = new JTextField(); pnlHopTimes.add(txtDryHopTime); txtDryHopTime.setText("0.0"); } { jLabelc4 = new JLabel(); pnlHopTimes.add(jLabelc4); jLabelc4.setText("FWH, boil minus (min):"); } { txtFWHTime = new JTextField(); pnlHopTimes.add(txtFWHTime); txtFWHTime.setText("20.0"); } { jLabelc5 = new JLabel(); pnlHopTimes.add(jLabelc5); jLabelc5.setText("Mash Hop (min):"); } { txtMashHopTime = new JTextField(); pnlHopTimes.add(txtMashHopTime); txtMashHopTime.setText("2.0"); } } } pnlHopsCalc = new JPanel(); BoxLayout pnlHopsCalcLayout = new BoxLayout(pnlHopsCalc, javax.swing.BoxLayout.Y_AXIS); pnlHopsCalc.setLayout(pnlHopsCalcLayout); pnlCalculations.add(pnlHopsCalc, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); pnlCalculations.add(getPnlWaterUsage(), new GridBagConstraints(1, 2, 1, 2, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); pnlCalculations.add(getPnlColourOptions(), new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); pnlCalculations.add(getPnlEvaporation(), new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); pnlHopsCalc.setPreferredSize(new java.awt.Dimension(117, 107)); pnlHopsCalc.setBorder(BorderFactory .createTitledBorder("IBU Calc Method:")); { rbTinseth = new JRadioButton(); pnlHopsCalc.add(rbTinseth); rbTinseth.setText("Tinseth"); bgHopsCalc.add(rbTinseth); } { rbRager = new JRadioButton(); pnlHopsCalc.add(rbRager); rbRager.setText("Rager"); bgHopsCalc.add(rbRager); } { rbGaretz = new JRadioButton(); pnlHopsCalc.add(rbGaretz); rbGaretz.setText("Garetz"); bgHopsCalc.add(rbGaretz); } } } } catch (Exception e) { e.printStackTrace(); } } } { costCarbPanel = new JPanel(); BorderLayout costCarbPanelLayout = new BorderLayout(); costCarbPanel.setLayout(costCarbPanelLayout); jTabbedPane1.addTab("Cost & Carb", null, costCarbPanel, null); { carbPanel = new JPanel(); costCarbPanel.add(carbPanel, BorderLayout.CENTER); carbPanel.setBorder(BorderFactory.createTitledBorder(null, "Carbonation", TitledBorder.LEADING, TitledBorder.TOP)); { jLabel3 = new JLabel(); carbPanel.add(jLabel3); jLabel3.setText("Not implemented"); } } { jPanel2 = new JPanel(); costCarbPanel.add(jPanel2, BorderLayout.NORTH); GridBagLayout jPanel2Layout = new GridBagLayout(); jPanel2Layout.rowWeights = new double[]{0.1, 0.1, 0.4}; jPanel2Layout.rowHeights = new int[]{7, 7, 7}; jPanel2Layout.columnWeights = new double[]{0.1, 0.1, 0.1}; jPanel2Layout.columnWidths = new int[]{7, 7, 7}; jPanel2.setPreferredSize(new java.awt.Dimension(232, 176)); jPanel2.setBorder(BorderFactory.createTitledBorder("Cost")); jPanel2.setLayout(jPanel2Layout); { jLabel1 = new JLabel(); jPanel2.add(jLabel1, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel1.setText("Other Cost:"); } { txtOtherCost = new JTextField(); jPanel2.add(txtOtherCost, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); txtOtherCost.setText("$0.00"); txtOtherCost.setPreferredSize(new java.awt.Dimension(62, 20)); } { jLabel2 = new JLabel(); jPanel2.add(jLabel2, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel2.setText("Bottle Size:"); } { cmbBottleSize = new JComboBox(); cmbBottleSizeModel = new ComboModel(); cmbBottleSizeModel.setList(new Quantity().getListofUnits("vol")); cmbBottleSize.setModel(cmbBottleSizeModel); jPanel2.add(cmbBottleSize, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); cmbBottleSize.setPreferredSize(new java.awt.Dimension(89, 20)); jPanel2.add(getTxtBottleSize(), new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); } } { } } { pnlBrewer = new JPanel(); GridBagLayout pnlBrewerLayout = new GridBagLayout(); pnlBrewerLayout.rowWeights = new double[]{0.1, 0.1, 0.3, 0.3}; pnlBrewerLayout.rowHeights = new int[]{2, 2, 7, 7}; pnlBrewerLayout.columnWeights = new double[]{0.1, 0.1, 0.1, 0.1}; pnlBrewerLayout.columnWidths = new int[]{7, 7, 7, 7}; pnlBrewer.setLayout(pnlBrewerLayout); jTabbedPane1.addTab("Brewer", null, pnlBrewer, null); { jLabel4 = new JLabel(); pnlBrewer.add(jLabel4, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel4.setText("Name:"); } { txtBrewerName = new JTextField(); pnlBrewer.add(txtBrewerName, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); txtBrewerName.setText("Your Name"); } { jLabel5 = new JLabel(); pnlBrewer.add(jLabel5, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel5.setText("Phone:"); } { txtPhone = new JTextField(); pnlBrewer.add(txtPhone, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); txtPhone.setText("Your Phone"); } { jLabel6 = new JLabel(); pnlBrewer.add(jLabel6, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel6.setText("Club Name:"); } { txtClubName = new JTextField(); pnlBrewer.add(txtClubName, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); txtClubName.setText("Club Name"); } { jLabel7 = new JLabel(); pnlBrewer.add(jLabel7, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel7.setText("Email:"); } { txtEmail = new JTextField(); pnlBrewer.add(txtEmail, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); txtEmail.setText("Email"); } } { pnlDatabase = new JPanel(); BorderLayout pnlDatabaseLayout = new BorderLayout(); pnlDatabase.setLayout(pnlDatabaseLayout); pnlDatabase.add(getPnlDefaultDB(), BorderLayout.NORTH); pnlDatabase.add(getPnlSortOrder(), BorderLayout.WEST); jTabbedPane1.addTab("Database", null, pnlDatabase, null); pnlDatabase.setVisible(false); } newRecipePanel = new JPanel(); GridBagLayout newRecipePanelLayout = new GridBagLayout(); newRecipePanelLayout.rowWeights = new double[]{0.1, 0.1, 0.1, 0.1}; newRecipePanelLayout.rowHeights = new int[]{7, 7, 7, 7}; newRecipePanelLayout.columnWeights = new double[]{0.1, 0.1, 0.1, 0.1}; newRecipePanelLayout.columnWidths = new int[]{7, 7, 7, 7}; newRecipePanel.setLayout(newRecipePanelLayout); jTabbedPane1.addTab("New Recipe Defaults", null, newRecipePanel, null); appearancePanel = new JPanel(); BorderLayout appearancePanelLayout = new BorderLayout(); appearancePanel.setLayout(appearancePanelLayout); jTabbedPane1.addTab("Appearance", null, appearancePanel, null);/* landfPanel = new JPanel(); appearancePanel.add(landfPanel, BorderLayout.NORTH); jLabel19 = new JLabel(); landfPanel.add(jLabel19); jLabel19.setText("Look and Feel:"); landfCombo = new JComboBox(looks.toArray()); landfPanel.add(landfCombo);*/ colourPanel = new JPanel(); appearancePanel.add(colourPanel, BorderLayout.CENTER); GridBagLayout colourPanelLayout = new GridBagLayout(); colourPanelLayout.rowWeights = new double[] {0.1, 0.1, 0.1, 0.1, 0.1, 0.1}; colourPanelLayout.rowHeights = new int[] {7, 7, 7, 7, 7, 7}; colourPanelLayout.columnWeights = new double[] {0.1, 0.1, 0.1, 0.1, 0.1, 0.1}; colourPanelLayout.columnWidths = new int[] {7, 7, 7, 7, 7, 7}; colourPanel.setLayout(colourPanelLayout); colourPanel.setPreferredSize(new java.awt.Dimension(340, 223)); colourPanel.setBorder(BorderFactory.createTitledBorder("Colour Swatch")); colMethod1rb = new JRadioButton(); colMethod1rb.addActionListener(this); colourGroup.add(colMethod1rb); colourPanel.add(colMethod1rb, new GridBagConstraints(0, 0, 3, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); colMethod1rb.setText("Colour Method 1"); colMethod2rb = new JRadioButton(); colMethod2rb.addActionListener(this); colourGroup.add(colMethod2rb); colourPanel.add(colMethod2rb, new GridBagConstraints(3, 0, 3, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); colMethod2rb.setText("Colour Method 2"); jLabel13 = new JLabel(); colourPanel.add(jLabel13, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); jLabel13.setText("Straw \n(2)"); jLabel14 = new JLabel(); colourPanel.add(jLabel14, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); jLabel14.setText("Pale\n(4)"); jLabel15 = new JLabel(); colourPanel.add(jLabel15, new GridBagConstraints(2, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); jLabel15.setText("Amber\n(8)"); jLabel16 = new JLabel(); colourPanel.add(jLabel16, new GridBagConstraints(3, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); jLabel16.setText("Copper (15)"); jLabel17 = new JLabel(); colourPanel.add(jLabel17, new GridBagConstraints(4, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); jLabel17.setText("Brown (20)"); jLabel18 = new JLabel(); colourPanel.add(jLabel18, new GridBagConstraints(5, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); jLabel18.setText("Black (30)"); stawPanel = new JPanel(); colourPanel.add(stawPanel, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); stawPanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); palePanel = new JPanel(); colourPanel.add(palePanel, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); palePanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); amberPanel = new JPanel(); colourPanel.add(amberPanel, new GridBagConstraints(2, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); amberPanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); copperPanel = new JPanel(); colourPanel.add(copperPanel, new GridBagConstraints(3, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); copperPanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); brownPanel = new JPanel(); colourPanel.add(brownPanel, new GridBagConstraints(4, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); brownPanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); blackPanel = new JPanel(); colourPanel.add(blackPanel, new GridBagConstraints(5, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); blackPanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); SpinnerNumberModel redSpnModel = new SpinnerNumberModel(8,0,255,1); redSpn = new JSpinner(); colourPanel.add(redSpn, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); redSpn.setModel(redSpnModel); redSpn.addChangeListener(this); SpinnerNumberModel greenSpnModel = new SpinnerNumberModel(30,0,255,1); greenSpn = new JSpinner(); colourPanel.add(greenSpn, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); greenSpn.setModel(greenSpnModel); greenSpn.addChangeListener(this); SpinnerNumberModel blueSpnModel = new SpinnerNumberModel(20,0,255,1); blueSpn = new JSpinner(); colourPanel.add(blueSpn, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); blueSpn.setModel(blueSpnModel); blueSpn.addChangeListener(this); SpinnerNumberModel alphaSpnModel = new SpinnerNumberModel(255,0,255,1); alphaSpn = new JSpinner(); colourPanel.add(alphaSpn, new GridBagConstraints(3, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); alphaSpn.setModel(alphaSpnModel); alphaSpn.addChangeListener(this); jLabel20 = new JLabel(); colourPanel.add(jLabel20, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel20.setText("Red:"); jLabel21 = new JLabel(); colourPanel.add(jLabel21, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel21.setText("Blue:"); jLabel22 = new JLabel(); colourPanel.add(jLabel22, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel22.setText("Green:"); jLabel23 = new JLabel(); colourPanel.add(jLabel23, new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel23.setText("Alpha:"); mashPanel = new JPanel(); newRecipePanel.add(mashPanel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); mashPanel.setBorder(BorderFactory.createTitledBorder("Mash")); jPanel1 = new JPanel(); GridBagLayout jPanel1Layout = new GridBagLayout(); jPanel1Layout.rowWeights = new double[] {0.1, 0.1, 0.1, 0.1}; jPanel1Layout.rowHeights = new int[] {7, 7, 7, 7}; jPanel1Layout.columnWeights = new double[] {0.1, 0.1}; jPanel1Layout.columnWidths = new int[] {7, 7}; jPanel1.setLayout(jPanel1Layout); newRecipePanel.add(jPanel1, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); jPanel1.setBorder(BorderFactory.createTitledBorder("Units")); jLabel19 = new JLabel(); jPanel1.add(jLabel19, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel19.setText("Malt Units:"); maltUnitsCombo = new JComboBox(); jPanel1.add(maltUnitsCombo, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); maltUnitsComboModel = new ComboModel(); maltUnitsComboModel.setList(new Quantity().getListofUnits("weight")); maltUnitsCombo.setModel(maltUnitsComboModel); jLabel24 = new JLabel(); jPanel1.add(jLabel24, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel24.setText("Hops Units:"); hopsUnitsCombo = new JComboBox(); jPanel1.add(hopsUnitsCombo, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); hopsUnitsComboModel = new ComboModel(); hopsUnitsComboModel.setList(new Quantity().getListofUnits("weight")); hopsUnitsCombo.setModel(hopsUnitsComboModel); jLabel25 = new JLabel(); jPanel1.add(jLabel25, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel25.setText("Vol Units:"); volUnitsCombo = new JComboBox(); volUnitsCombo.addActionListener(new ActionListener() { public void actionPerformed (ActionEvent e){ setEvapLable(); } }); jPanel1.add(volUnitsCombo, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); volUnitsComboModel = new ComboModel(); volUnitsComboModel.setList(new Quantity().getListofUnits("vol")); volUnitsCombo.setModel(volUnitsComboModel); jLabel26 = new JLabel(); jPanel1.add(jLabel26, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel26.setText("Batch Size:"); batchSizeTxt = new JTextField(); jPanel1.add(batchSizeTxt, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); batchSizeTxt.setText("jTextField1"); jLabel12 = new JLabel(); mashPanel.add(jLabel12); jLabel12.setText("Boil Temp (F):"); boilTempTxt = new JTextField(); mashPanel.add(boilTempTxt); boilTempTxt.setText("212"); boilTempTxt.setPreferredSize(new java.awt.Dimension(43, 20)); } getContentPane().add(BorderLayout.CENTER, jTabbedPane1); getContentPane().add(BorderLayout.SOUTH, buttons); setSize(500, 500); }
boilTempTxt.setPreferredSize(new java.awt.Dimension(43, 20));
boilTempTxt.setPreferredSize(new java.awt.Dimension(45, 20)); boilTempULbl = new JLabel(); mashPanel.add(boilTempULbl, new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); boilTempULbl.setText("F"); boilTempULbl.setPreferredSize(new java.awt.Dimension(21, 14)); jLabel27 = new JLabel(); mashPanel.add(jLabel27, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel27.setText("Temp Units:"); frb = new JRadioButton(); mashPanel.add(frb, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); frb.setText("F"); tempUBG.add(frb); frb.setSelected(true); frb.addActionListener(this); crb = new JRadioButton(); mashPanel.add(crb, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); crb.setText("C"); tempUBG.add(crb); crb.addActionListener(this); jLabel28 = new JLabel(); mashPanel.add(jLabel28, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel28.setText("Vol Units:"); mashVolComboModel = new ComboModel(); mashVolComboModel.setList(new Quantity().getListofUnits("vol")); mashVolCombo = new JComboBox(); mashPanel.add(mashVolCombo, new GridBagConstraints(1, 0, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); mashVolCombo.setModel(mashVolComboModel); mashVolCombo.setPreferredSize(new java.awt.Dimension(137, 20)); jLabel29 = new JLabel(); mashPanel.add(jLabel29, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel29.setText("Ratio:"); mashRatioTxt = new JTextField(); mashPanel.add(mashRatioTxt, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); mashRatioTxt.setText("1.25"); mashRatioTxt.setPreferredSize(new java.awt.Dimension(45, 20)); ComboBoxModel mashRatioUComboModel = new DefaultComboBoxModel(new String[] { "qt/l", "l/kg" }); mashRatioUCombo = new JComboBox(); mashPanel.add(mashRatioUCombo, new GridBagConstraints(2, 3, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); mashRatioUCombo.setModel(mashRatioUComboModel); mashRatioUCombo.setPreferredSize(new java.awt.Dimension(71, 20));
private void layoutUi() { JPanel buttons = new JPanel(); okButton = new JButton("OK"); okButton.addActionListener(this); cancelButton = new JButton("Cancel"); cancelButton.addActionListener(this); buttons.setLayout(new FlowLayout(FlowLayout.RIGHT)); buttons.add(cancelButton); buttons.add(okButton); getContentPane().setLayout(new BorderLayout()); this.setFocusTraversalKeysEnabled(false); { jTabbedPane1 = new JTabbedPane(); getContentPane().add(jTabbedPane1, BorderLayout.CENTER); { pnlCalculations = new JPanel(); jTabbedPane1.addTab("Calculations", null, pnlCalculations, null); { try { { GridBagLayout thisLayout = new GridBagLayout(); thisLayout.rowWeights = new double[]{0.1, 0.1, 0.1, 0.1}; thisLayout.rowHeights = new int[]{7, 7, 7, 7}; thisLayout.columnWeights = new double[]{0.1, 0.2}; thisLayout.columnWidths = new int[]{7, 7}; pnlCalculations.setLayout(thisLayout); pnlCalculations.setPreferredSize(new java.awt.Dimension(524, 372)); { { bgHopsCalc = new ButtonGroup(); { pnlHops = new JPanel(); GridLayout pnlHopsLayout = new GridLayout(2, 2); pnlHopsLayout.setColumns(2); pnlHopsLayout.setHgap(5); pnlHopsLayout.setVgap(5); pnlHopsLayout.setRows(2); pnlHops.setLayout(pnlHopsLayout); pnlCalculations.add(pnlHops, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); pnlHops .setBorder(BorderFactory .createTitledBorder("Hops:")); { jLabelc1 = new JLabel(); pnlHops.add(jLabelc1); jLabelc1.setText("Pellet Hops +%"); } { txtPellet = new JTextField(); pnlHops.add(txtPellet); txtPellet.setPreferredSize(new java.awt.Dimension(20, 20)); } { jLabelc2 = new JLabel(); pnlHops.add(jLabelc2); jLabelc2.setText("Tinseth Utilization Factor"); } { txtTinsethUtil = new JTextField(); pnlHops.add(txtTinsethUtil); txtTinsethUtil.setText("4.15"); } } { pnlAlc = new JPanel(); BoxLayout pnlAlcLayout = new BoxLayout(pnlAlc, javax.swing.BoxLayout.Y_AXIS); pnlAlc.setLayout(pnlAlcLayout); pnlCalculations.add(pnlAlc, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); pnlAlc.setBorder(BorderFactory .createTitledBorder("Alcohol By:")); { rbABV = new JRadioButton(); pnlAlc.add(rbABV); bgAlc.add(rbABV); rbABV.setText("Volume"); } { rbABW = new JRadioButton(); pnlAlc.add(rbABW); bgAlc.add(rbABW); rbABW.setText("Weight"); } } { pnlHopTimes = new JPanel(); GridLayout pnlHopTimesLayout = new GridLayout(3, 2); pnlHopTimesLayout.setColumns(2); pnlHopTimesLayout.setHgap(5); pnlHopTimesLayout.setVgap(5); pnlHopTimesLayout.setRows(3); pnlHopTimes.setLayout(pnlHopTimesLayout); pnlCalculations.add(pnlHopTimes, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); pnlHopTimes.setBorder(BorderFactory .createTitledBorder("Hop Times:")); { jLabelc3 = new JLabel(); pnlHopTimes.add(jLabelc3); jLabelc3.setText("Dry (min):"); } { txtDryHopTime = new JTextField(); pnlHopTimes.add(txtDryHopTime); txtDryHopTime.setText("0.0"); } { jLabelc4 = new JLabel(); pnlHopTimes.add(jLabelc4); jLabelc4.setText("FWH, boil minus (min):"); } { txtFWHTime = new JTextField(); pnlHopTimes.add(txtFWHTime); txtFWHTime.setText("20.0"); } { jLabelc5 = new JLabel(); pnlHopTimes.add(jLabelc5); jLabelc5.setText("Mash Hop (min):"); } { txtMashHopTime = new JTextField(); pnlHopTimes.add(txtMashHopTime); txtMashHopTime.setText("2.0"); } } } pnlHopsCalc = new JPanel(); BoxLayout pnlHopsCalcLayout = new BoxLayout(pnlHopsCalc, javax.swing.BoxLayout.Y_AXIS); pnlHopsCalc.setLayout(pnlHopsCalcLayout); pnlCalculations.add(pnlHopsCalc, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); pnlCalculations.add(getPnlWaterUsage(), new GridBagConstraints(1, 2, 1, 2, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); pnlCalculations.add(getPnlColourOptions(), new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); pnlCalculations.add(getPnlEvaporation(), new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); pnlHopsCalc.setPreferredSize(new java.awt.Dimension(117, 107)); pnlHopsCalc.setBorder(BorderFactory .createTitledBorder("IBU Calc Method:")); { rbTinseth = new JRadioButton(); pnlHopsCalc.add(rbTinseth); rbTinseth.setText("Tinseth"); bgHopsCalc.add(rbTinseth); } { rbRager = new JRadioButton(); pnlHopsCalc.add(rbRager); rbRager.setText("Rager"); bgHopsCalc.add(rbRager); } { rbGaretz = new JRadioButton(); pnlHopsCalc.add(rbGaretz); rbGaretz.setText("Garetz"); bgHopsCalc.add(rbGaretz); } } } } catch (Exception e) { e.printStackTrace(); } } } { costCarbPanel = new JPanel(); BorderLayout costCarbPanelLayout = new BorderLayout(); costCarbPanel.setLayout(costCarbPanelLayout); jTabbedPane1.addTab("Cost & Carb", null, costCarbPanel, null); { carbPanel = new JPanel(); costCarbPanel.add(carbPanel, BorderLayout.CENTER); carbPanel.setBorder(BorderFactory.createTitledBorder(null, "Carbonation", TitledBorder.LEADING, TitledBorder.TOP)); { jLabel3 = new JLabel(); carbPanel.add(jLabel3); jLabel3.setText("Not implemented"); } } { jPanel2 = new JPanel(); costCarbPanel.add(jPanel2, BorderLayout.NORTH); GridBagLayout jPanel2Layout = new GridBagLayout(); jPanel2Layout.rowWeights = new double[]{0.1, 0.1, 0.4}; jPanel2Layout.rowHeights = new int[]{7, 7, 7}; jPanel2Layout.columnWeights = new double[]{0.1, 0.1, 0.1}; jPanel2Layout.columnWidths = new int[]{7, 7, 7}; jPanel2.setPreferredSize(new java.awt.Dimension(232, 176)); jPanel2.setBorder(BorderFactory.createTitledBorder("Cost")); jPanel2.setLayout(jPanel2Layout); { jLabel1 = new JLabel(); jPanel2.add(jLabel1, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel1.setText("Other Cost:"); } { txtOtherCost = new JTextField(); jPanel2.add(txtOtherCost, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); txtOtherCost.setText("$0.00"); txtOtherCost.setPreferredSize(new java.awt.Dimension(62, 20)); } { jLabel2 = new JLabel(); jPanel2.add(jLabel2, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel2.setText("Bottle Size:"); } { cmbBottleSize = new JComboBox(); cmbBottleSizeModel = new ComboModel(); cmbBottleSizeModel.setList(new Quantity().getListofUnits("vol")); cmbBottleSize.setModel(cmbBottleSizeModel); jPanel2.add(cmbBottleSize, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); cmbBottleSize.setPreferredSize(new java.awt.Dimension(89, 20)); jPanel2.add(getTxtBottleSize(), new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); } } { } } { pnlBrewer = new JPanel(); GridBagLayout pnlBrewerLayout = new GridBagLayout(); pnlBrewerLayout.rowWeights = new double[]{0.1, 0.1, 0.3, 0.3}; pnlBrewerLayout.rowHeights = new int[]{2, 2, 7, 7}; pnlBrewerLayout.columnWeights = new double[]{0.1, 0.1, 0.1, 0.1}; pnlBrewerLayout.columnWidths = new int[]{7, 7, 7, 7}; pnlBrewer.setLayout(pnlBrewerLayout); jTabbedPane1.addTab("Brewer", null, pnlBrewer, null); { jLabel4 = new JLabel(); pnlBrewer.add(jLabel4, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel4.setText("Name:"); } { txtBrewerName = new JTextField(); pnlBrewer.add(txtBrewerName, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); txtBrewerName.setText("Your Name"); } { jLabel5 = new JLabel(); pnlBrewer.add(jLabel5, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel5.setText("Phone:"); } { txtPhone = new JTextField(); pnlBrewer.add(txtPhone, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); txtPhone.setText("Your Phone"); } { jLabel6 = new JLabel(); pnlBrewer.add(jLabel6, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel6.setText("Club Name:"); } { txtClubName = new JTextField(); pnlBrewer.add(txtClubName, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); txtClubName.setText("Club Name"); } { jLabel7 = new JLabel(); pnlBrewer.add(jLabel7, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel7.setText("Email:"); } { txtEmail = new JTextField(); pnlBrewer.add(txtEmail, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); txtEmail.setText("Email"); } } { pnlDatabase = new JPanel(); BorderLayout pnlDatabaseLayout = new BorderLayout(); pnlDatabase.setLayout(pnlDatabaseLayout); pnlDatabase.add(getPnlDefaultDB(), BorderLayout.NORTH); pnlDatabase.add(getPnlSortOrder(), BorderLayout.WEST); jTabbedPane1.addTab("Database", null, pnlDatabase, null); pnlDatabase.setVisible(false); } newRecipePanel = new JPanel(); GridBagLayout newRecipePanelLayout = new GridBagLayout(); newRecipePanelLayout.rowWeights = new double[]{0.1, 0.1, 0.1, 0.1}; newRecipePanelLayout.rowHeights = new int[]{7, 7, 7, 7}; newRecipePanelLayout.columnWeights = new double[]{0.1, 0.1, 0.1, 0.1}; newRecipePanelLayout.columnWidths = new int[]{7, 7, 7, 7}; newRecipePanel.setLayout(newRecipePanelLayout); jTabbedPane1.addTab("New Recipe Defaults", null, newRecipePanel, null); appearancePanel = new JPanel(); BorderLayout appearancePanelLayout = new BorderLayout(); appearancePanel.setLayout(appearancePanelLayout); jTabbedPane1.addTab("Appearance", null, appearancePanel, null);/* landfPanel = new JPanel(); appearancePanel.add(landfPanel, BorderLayout.NORTH); jLabel19 = new JLabel(); landfPanel.add(jLabel19); jLabel19.setText("Look and Feel:"); landfCombo = new JComboBox(looks.toArray()); landfPanel.add(landfCombo);*/ colourPanel = new JPanel(); appearancePanel.add(colourPanel, BorderLayout.CENTER); GridBagLayout colourPanelLayout = new GridBagLayout(); colourPanelLayout.rowWeights = new double[] {0.1, 0.1, 0.1, 0.1, 0.1, 0.1}; colourPanelLayout.rowHeights = new int[] {7, 7, 7, 7, 7, 7}; colourPanelLayout.columnWeights = new double[] {0.1, 0.1, 0.1, 0.1, 0.1, 0.1}; colourPanelLayout.columnWidths = new int[] {7, 7, 7, 7, 7, 7}; colourPanel.setLayout(colourPanelLayout); colourPanel.setPreferredSize(new java.awt.Dimension(340, 223)); colourPanel.setBorder(BorderFactory.createTitledBorder("Colour Swatch")); colMethod1rb = new JRadioButton(); colMethod1rb.addActionListener(this); colourGroup.add(colMethod1rb); colourPanel.add(colMethod1rb, new GridBagConstraints(0, 0, 3, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); colMethod1rb.setText("Colour Method 1"); colMethod2rb = new JRadioButton(); colMethod2rb.addActionListener(this); colourGroup.add(colMethod2rb); colourPanel.add(colMethod2rb, new GridBagConstraints(3, 0, 3, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); colMethod2rb.setText("Colour Method 2"); jLabel13 = new JLabel(); colourPanel.add(jLabel13, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); jLabel13.setText("Straw \n(2)"); jLabel14 = new JLabel(); colourPanel.add(jLabel14, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); jLabel14.setText("Pale\n(4)"); jLabel15 = new JLabel(); colourPanel.add(jLabel15, new GridBagConstraints(2, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); jLabel15.setText("Amber\n(8)"); jLabel16 = new JLabel(); colourPanel.add(jLabel16, new GridBagConstraints(3, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); jLabel16.setText("Copper (15)"); jLabel17 = new JLabel(); colourPanel.add(jLabel17, new GridBagConstraints(4, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); jLabel17.setText("Brown (20)"); jLabel18 = new JLabel(); colourPanel.add(jLabel18, new GridBagConstraints(5, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); jLabel18.setText("Black (30)"); stawPanel = new JPanel(); colourPanel.add(stawPanel, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); stawPanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); palePanel = new JPanel(); colourPanel.add(palePanel, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); palePanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); amberPanel = new JPanel(); colourPanel.add(amberPanel, new GridBagConstraints(2, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); amberPanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); copperPanel = new JPanel(); colourPanel.add(copperPanel, new GridBagConstraints(3, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); copperPanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); brownPanel = new JPanel(); colourPanel.add(brownPanel, new GridBagConstraints(4, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); brownPanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); blackPanel = new JPanel(); colourPanel.add(blackPanel, new GridBagConstraints(5, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); blackPanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); SpinnerNumberModel redSpnModel = new SpinnerNumberModel(8,0,255,1); redSpn = new JSpinner(); colourPanel.add(redSpn, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); redSpn.setModel(redSpnModel); redSpn.addChangeListener(this); SpinnerNumberModel greenSpnModel = new SpinnerNumberModel(30,0,255,1); greenSpn = new JSpinner(); colourPanel.add(greenSpn, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); greenSpn.setModel(greenSpnModel); greenSpn.addChangeListener(this); SpinnerNumberModel blueSpnModel = new SpinnerNumberModel(20,0,255,1); blueSpn = new JSpinner(); colourPanel.add(blueSpn, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); blueSpn.setModel(blueSpnModel); blueSpn.addChangeListener(this); SpinnerNumberModel alphaSpnModel = new SpinnerNumberModel(255,0,255,1); alphaSpn = new JSpinner(); colourPanel.add(alphaSpn, new GridBagConstraints(3, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); alphaSpn.setModel(alphaSpnModel); alphaSpn.addChangeListener(this); jLabel20 = new JLabel(); colourPanel.add(jLabel20, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel20.setText("Red:"); jLabel21 = new JLabel(); colourPanel.add(jLabel21, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel21.setText("Blue:"); jLabel22 = new JLabel(); colourPanel.add(jLabel22, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel22.setText("Green:"); jLabel23 = new JLabel(); colourPanel.add(jLabel23, new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel23.setText("Alpha:"); mashPanel = new JPanel(); newRecipePanel.add(mashPanel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); mashPanel.setBorder(BorderFactory.createTitledBorder("Mash")); jPanel1 = new JPanel(); GridBagLayout jPanel1Layout = new GridBagLayout(); jPanel1Layout.rowWeights = new double[] {0.1, 0.1, 0.1, 0.1}; jPanel1Layout.rowHeights = new int[] {7, 7, 7, 7}; jPanel1Layout.columnWeights = new double[] {0.1, 0.1}; jPanel1Layout.columnWidths = new int[] {7, 7}; jPanel1.setLayout(jPanel1Layout); newRecipePanel.add(jPanel1, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); jPanel1.setBorder(BorderFactory.createTitledBorder("Units")); jLabel19 = new JLabel(); jPanel1.add(jLabel19, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel19.setText("Malt Units:"); maltUnitsCombo = new JComboBox(); jPanel1.add(maltUnitsCombo, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); maltUnitsComboModel = new ComboModel(); maltUnitsComboModel.setList(new Quantity().getListofUnits("weight")); maltUnitsCombo.setModel(maltUnitsComboModel); jLabel24 = new JLabel(); jPanel1.add(jLabel24, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel24.setText("Hops Units:"); hopsUnitsCombo = new JComboBox(); jPanel1.add(hopsUnitsCombo, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); hopsUnitsComboModel = new ComboModel(); hopsUnitsComboModel.setList(new Quantity().getListofUnits("weight")); hopsUnitsCombo.setModel(hopsUnitsComboModel); jLabel25 = new JLabel(); jPanel1.add(jLabel25, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel25.setText("Vol Units:"); volUnitsCombo = new JComboBox(); volUnitsCombo.addActionListener(new ActionListener() { public void actionPerformed (ActionEvent e){ setEvapLable(); } }); jPanel1.add(volUnitsCombo, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); volUnitsComboModel = new ComboModel(); volUnitsComboModel.setList(new Quantity().getListofUnits("vol")); volUnitsCombo.setModel(volUnitsComboModel); jLabel26 = new JLabel(); jPanel1.add(jLabel26, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel26.setText("Batch Size:"); batchSizeTxt = new JTextField(); jPanel1.add(batchSizeTxt, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); batchSizeTxt.setText("jTextField1"); jLabel12 = new JLabel(); mashPanel.add(jLabel12); jLabel12.setText("Boil Temp (F):"); boilTempTxt = new JTextField(); mashPanel.add(boilTempTxt); boilTempTxt.setText("212"); boilTempTxt.setPreferredSize(new java.awt.Dimension(43, 20)); } getContentPane().add(BorderLayout.CENTER, jTabbedPane1); getContentPane().add(BorderLayout.SOUTH, buttons); setSize(500, 500); }
opts.setProperty("optBoilTempF", boilTempTxt.getText());
private void saveOptions() { // cost tab: opts.setProperty("optMiscCost", txtOtherCost.getText()); opts.setProperty("optBottleSize", txtBottleSize.getText()); opts.setProperty("optBottleU", (String) cmbBottleSize.getSelectedItem()); // Brewer tab: opts.setProperty("optBrewer", txtBrewerName.getText()); opts.setProperty("optPhone", txtPhone.getText()); opts.setProperty("optClub", txtClubName.getText()); opts.setProperty("optEmail", txtEmail.getText()); // calculations tab: if (rbTinseth.isSelected()) opts.setProperty("optIBUCalcMethod", "Tinseth"); if (rbRager.isSelected()) opts.setProperty("optIBUCalcMethod", "Rager"); if (rbGaretz.isSelected()) opts.setProperty("optIBUCalcMethod", "Garetz"); if (rbABV.isSelected()) opts.setProperty("optAlcCalcMethod", "Volume"); if (rbABW.isSelected()) opts.setProperty("optAlcCalcMethod", "Weight"); if (rbSRM.isSelected()) opts.setProperty("optColourMethod", "SRM"); if (rbEBC.isSelected()) opts.setProperty("optColourMethod", "EBC"); if (rbPercent.isSelected()) opts.setProperty("optEvapCalcMethod", "Percent"); if (rbConstant.isSelected()) opts.setProperty("optEvapCalcMethod", "Constant"); opts.setProperty("optEvaporation", evapAmountTxt.getText()); opts.setProperty("optPelletHopsPct", txtPellet.getText()); opts.setProperty("optHopsUtil", txtTinsethUtil.getText()); opts.setProperty("optDryHopTime", txtDryHopTime.getText()); opts.setProperty("optFWHTime", txtFWHTime.getText()); opts.setProperty("optMashHopTime", txtMashHopTime.getText()); opts.setProperty("optKettleLoss", txtLeftInKettle.getText()); opts.setProperty("optMiscLoss", txtMiscLosses.getText()); opts.setProperty("optTrubLoss", txtLostInTrub.getText()); // new recipe tab: opts.setProperty("optBoilTempF", boilTempTxt.getText()); opts.setProperty("optPostBoilVol", batchSizeTxt.getText()); opts.setProperty("optMaltU", maltUnitsComboModel.getSelectedItem().toString()); opts.setProperty("optHopsU", hopsUnitsComboModel.getSelectedItem().toString()); opts.setProperty("optSizeU", volUnitsComboModel.getSelectedItem().toString()); // appearances: opts.setProperty("optRed", redSpn.getValue().toString()); opts.setProperty("optGreen", greenSpn.getValue().toString()); opts.setProperty("optBlue", blueSpn.getValue().toString()); opts.setProperty("optAlpha", alphaSpn.getValue().toString()); if (colMethod1rb.isSelected()) opts.setProperty("optRGBMethod", "1"); else opts.setProperty("optRGBMethod", "2"); }
opts.setProperty("optMashVolU", mashVolComboModel.getSelectedItem().toString()); if (frb.isSelected()){ opts.setProperty("optMashTempU", "F"); opts.setProperty("optBoilTempF", boilTempTxt.getText()); } else { opts.setProperty("optMashTempU", "C"); double t = Double.parseDouble(boilTempTxt.getText()); opts.setDProperty("optBoilTempF", BrewCalcs.cToF(t)); } opts.setProperty("optMashRatioU", mashRatioUCombo.getSelectedItem().toString()); opts.setProperty("optMashRatio", mashRatioTxt.getText());
private void saveOptions() { // cost tab: opts.setProperty("optMiscCost", txtOtherCost.getText()); opts.setProperty("optBottleSize", txtBottleSize.getText()); opts.setProperty("optBottleU", (String) cmbBottleSize.getSelectedItem()); // Brewer tab: opts.setProperty("optBrewer", txtBrewerName.getText()); opts.setProperty("optPhone", txtPhone.getText()); opts.setProperty("optClub", txtClubName.getText()); opts.setProperty("optEmail", txtEmail.getText()); // calculations tab: if (rbTinseth.isSelected()) opts.setProperty("optIBUCalcMethod", "Tinseth"); if (rbRager.isSelected()) opts.setProperty("optIBUCalcMethod", "Rager"); if (rbGaretz.isSelected()) opts.setProperty("optIBUCalcMethod", "Garetz"); if (rbABV.isSelected()) opts.setProperty("optAlcCalcMethod", "Volume"); if (rbABW.isSelected()) opts.setProperty("optAlcCalcMethod", "Weight"); if (rbSRM.isSelected()) opts.setProperty("optColourMethod", "SRM"); if (rbEBC.isSelected()) opts.setProperty("optColourMethod", "EBC"); if (rbPercent.isSelected()) opts.setProperty("optEvapCalcMethod", "Percent"); if (rbConstant.isSelected()) opts.setProperty("optEvapCalcMethod", "Constant"); opts.setProperty("optEvaporation", evapAmountTxt.getText()); opts.setProperty("optPelletHopsPct", txtPellet.getText()); opts.setProperty("optHopsUtil", txtTinsethUtil.getText()); opts.setProperty("optDryHopTime", txtDryHopTime.getText()); opts.setProperty("optFWHTime", txtFWHTime.getText()); opts.setProperty("optMashHopTime", txtMashHopTime.getText()); opts.setProperty("optKettleLoss", txtLeftInKettle.getText()); opts.setProperty("optMiscLoss", txtMiscLosses.getText()); opts.setProperty("optTrubLoss", txtLostInTrub.getText()); // new recipe tab: opts.setProperty("optBoilTempF", boilTempTxt.getText()); opts.setProperty("optPostBoilVol", batchSizeTxt.getText()); opts.setProperty("optMaltU", maltUnitsComboModel.getSelectedItem().toString()); opts.setProperty("optHopsU", hopsUnitsComboModel.getSelectedItem().toString()); opts.setProperty("optSizeU", volUnitsComboModel.getSelectedItem().toString()); // appearances: opts.setProperty("optRed", redSpn.getValue().toString()); opts.setProperty("optGreen", greenSpn.getValue().toString()); opts.setProperty("optBlue", blueSpn.getValue().toString()); opts.setProperty("optAlpha", alphaSpn.getValue().toString()); if (colMethod1rb.isSelected()) opts.setProperty("optRGBMethod", "1"); else opts.setProperty("optRGBMethod", "2"); }
boilTempTxt.setText(opts.getProperty("optBoilTempF"));
private void setOptions() { // new recipe tab: boilTempTxt.setText(opts.getProperty("optBoilTempF")); batchSizeTxt.setText(opts.getProperty("optPostBoilVol")); maltUnitsComboModel.addOrInsert(opts.getProperty("optMaltU")); hopsUnitsComboModel.addOrInsert(opts.getProperty("optHopsU")); volUnitsComboModel.addOrInsert(opts.getProperty("optSizeU")); // cost tab: txtOtherCost.setText(opts.getProperty("optMiscCost")); txtBottleSize.setText(opts.getProperty("optBottleSize")); cmbBottleSizeModel.addOrInsert(opts.getProperty("optBottleU")); // brewer tab: txtBrewerName.setText(opts.getProperty("optBrewer")); txtPhone.setText(opts.getProperty("optPhone")); txtClubName.setText(opts.getProperty("optClub")); txtEmail.setText(opts.getProperty("optEmail")); // calculations tab: rbTinseth.setSelected(opts.getProperty("optIBUCalcMethod").equalsIgnoreCase("Tinseth")); rbRager.setSelected(opts.getProperty("optIBUCalcMethod").equalsIgnoreCase("Rager")); rbGaretz.setSelected(opts.getProperty("optIBUCalcMethod").equalsIgnoreCase("Garetz")); rbABV.setSelected((opts.getProperty("optAlcCalcMethod").equalsIgnoreCase("Volume"))); rbABW.setSelected((opts.getProperty("optAlcCalcMethod").equalsIgnoreCase("Weight"))); rbSRM.setSelected((opts.getProperty("optColourMethod").equalsIgnoreCase("SRM"))); rbEBC.setSelected((opts.getProperty("optColourMethod").equalsIgnoreCase("EBC"))); rbPercent.setSelected((opts.getProperty("optEvapCalcMethod").equalsIgnoreCase("Percent"))); rbConstant.setSelected((opts.getProperty("optEvapCalcMethod").equalsIgnoreCase("Constant"))); evapAmountTxt.setText(opts.getProperty("optEvaporation")); setEvapLable(); txtPellet.setText(opts.getProperty("optPelletHopsPct")); txtTinsethUtil.setText(opts.getProperty("optHopsUtil")); txtDryHopTime.setText(opts.getProperty("optDryHopTime")); txtFWHTime.setText(opts.getProperty("optFWHTime")); txtMashHopTime.setText(opts.getProperty("optMashHopTime")); txtLeftInKettle.setText(opts.getProperty("optKettleLoss")); txtMiscLosses.setText(opts.getProperty("optMiscLoss")); txtLostInTrub.setText(opts.getProperty("optTrubLoss")); // appearances tab: redSpn.setValue(new Integer(opts.getIProperty("optRed"))); greenSpn.setValue(new Integer(opts.getIProperty("optGreen"))); blueSpn.setValue(new Integer(opts.getIProperty("optBlue"))); alphaSpn.setValue(new Integer(opts.getIProperty("optAlpha"))); colMethod1rb.setSelected(opts.getProperty("optRGBMethod").equals("1")); colMethod2rb.setSelected(opts.getProperty("optRGBMethod").equals("2")); displayColour(); }
boilTempTxt.setText(opts.getProperty("optBoilTempF")); mashVolComboModel.addOrInsert(opts.getProperty("optMashVolU")); frb.setSelected(opts.getProperty("optMashTempU").equalsIgnoreCase("F")); crb.setSelected(opts.getProperty("optMashTempU").equalsIgnoreCase("C")); mashRatioUCombo.setSelectedItem(opts.getProperty("optMashRatioU")); mashRatioTxt.setText(opts.getProperty("optMashRatio"));
private void setOptions() { // new recipe tab: boilTempTxt.setText(opts.getProperty("optBoilTempF")); batchSizeTxt.setText(opts.getProperty("optPostBoilVol")); maltUnitsComboModel.addOrInsert(opts.getProperty("optMaltU")); hopsUnitsComboModel.addOrInsert(opts.getProperty("optHopsU")); volUnitsComboModel.addOrInsert(opts.getProperty("optSizeU")); // cost tab: txtOtherCost.setText(opts.getProperty("optMiscCost")); txtBottleSize.setText(opts.getProperty("optBottleSize")); cmbBottleSizeModel.addOrInsert(opts.getProperty("optBottleU")); // brewer tab: txtBrewerName.setText(opts.getProperty("optBrewer")); txtPhone.setText(opts.getProperty("optPhone")); txtClubName.setText(opts.getProperty("optClub")); txtEmail.setText(opts.getProperty("optEmail")); // calculations tab: rbTinseth.setSelected(opts.getProperty("optIBUCalcMethod").equalsIgnoreCase("Tinseth")); rbRager.setSelected(opts.getProperty("optIBUCalcMethod").equalsIgnoreCase("Rager")); rbGaretz.setSelected(opts.getProperty("optIBUCalcMethod").equalsIgnoreCase("Garetz")); rbABV.setSelected((opts.getProperty("optAlcCalcMethod").equalsIgnoreCase("Volume"))); rbABW.setSelected((opts.getProperty("optAlcCalcMethod").equalsIgnoreCase("Weight"))); rbSRM.setSelected((opts.getProperty("optColourMethod").equalsIgnoreCase("SRM"))); rbEBC.setSelected((opts.getProperty("optColourMethod").equalsIgnoreCase("EBC"))); rbPercent.setSelected((opts.getProperty("optEvapCalcMethod").equalsIgnoreCase("Percent"))); rbConstant.setSelected((opts.getProperty("optEvapCalcMethod").equalsIgnoreCase("Constant"))); evapAmountTxt.setText(opts.getProperty("optEvaporation")); setEvapLable(); txtPellet.setText(opts.getProperty("optPelletHopsPct")); txtTinsethUtil.setText(opts.getProperty("optHopsUtil")); txtDryHopTime.setText(opts.getProperty("optDryHopTime")); txtFWHTime.setText(opts.getProperty("optFWHTime")); txtMashHopTime.setText(opts.getProperty("optMashHopTime")); txtLeftInKettle.setText(opts.getProperty("optKettleLoss")); txtMiscLosses.setText(opts.getProperty("optMiscLoss")); txtLostInTrub.setText(opts.getProperty("optTrubLoss")); // appearances tab: redSpn.setValue(new Integer(opts.getIProperty("optRed"))); greenSpn.setValue(new Integer(opts.getIProperty("optGreen"))); blueSpn.setValue(new Integer(opts.getIProperty("optBlue"))); alphaSpn.setValue(new Integer(opts.getIProperty("optAlpha"))); colMethod1rb.setSelected(opts.getProperty("optRGBMethod").equals("1")); colMethod2rb.setSelected(opts.getProperty("optRGBMethod").equals("2")); displayColour(); }
public static void main(String args[]) throws IOException {
public static void main(String args[]) {
public static void main(String args[]) throws IOException { DJepApplet app = new DJepApplet(); app.init(); Frame mainFrame = new Frame("Wallpaper patterns"); mainFrame.setBounds(0,0,200,200); mainFrame.add(app); mainFrame.show(); }
if(build.getPreviousBuild()==null || changedFiles.isEmpty()) {
if(build.getPreviousBuild()==null || (changedFiles!=null && changedFiles.isEmpty())) {
private boolean calcChangeLog(Build build, List<String> changedFiles, File changelogFile, BuildListener listener) { if(build.getPreviousBuild()==null || changedFiles.isEmpty()) { // nothing to compare against, or no changes listener.getLogger().println("$ no changes detected"); return createEmptyChangeLog(changelogFile,listener, "changelog"); } listener.getLogger().println("$ computing changelog"); ChangeLogTask task = new ChangeLogTask() { { setOutputStream(System.out); setErrorStream(System.err); } }; task.setProject(new org.apache.tools.ant.Project()); task.setDir(build.getProject().getWorkspace().getLocal()); if(DESCRIPTOR.getCvspassFile().length()!=0) task.setPassfile(new File(DESCRIPTOR.getCvspassFile())); task.setCvsRoot(cvsroot); task.setCvsRsh(cvsRsh); task.setFailOnError(true); task.setDestfile(changelogFile); task.setStart(build.getPreviousBuild().getTimestamp().getTime()); task.setEnd(build.getTimestamp().getTime()); task.setFile(changedFiles); try { task.execute(); return true; } catch( BuildException e ) { e.printStackTrace(listener.error(e.getMessage())); return false; } catch( RuntimeException e ) { // an user reported a NPE inside the changeLog task. // we don't want a bug in Ant to prevent a build. e.printStackTrace(listener.error(e.getMessage())); return true; // so record the message but continue } }
task.setFile(changedFiles);
if(changedFiles!=null) task.setFile(changedFiles); else { if(!flatten) task.setPackage(module); }
private boolean calcChangeLog(Build build, List<String> changedFiles, File changelogFile, BuildListener listener) { if(build.getPreviousBuild()==null || changedFiles.isEmpty()) { // nothing to compare against, or no changes listener.getLogger().println("$ no changes detected"); return createEmptyChangeLog(changelogFile,listener, "changelog"); } listener.getLogger().println("$ computing changelog"); ChangeLogTask task = new ChangeLogTask() { { setOutputStream(System.out); setErrorStream(System.err); } }; task.setProject(new org.apache.tools.ant.Project()); task.setDir(build.getProject().getWorkspace().getLocal()); if(DESCRIPTOR.getCvspassFile().length()!=0) task.setPassfile(new File(DESCRIPTOR.getCvspassFile())); task.setCvsRoot(cvsroot); task.setCvsRsh(cvsRsh); task.setFailOnError(true); task.setDestfile(changelogFile); task.setStart(build.getPreviousBuild().getTimestamp().getTime()); task.setEnd(build.getTimestamp().getTime()); task.setFile(changedFiles); try { task.execute(); return true; } catch( BuildException e ) { e.printStackTrace(listener.error(e.getMessage())); return false; } catch( RuntimeException e ) { // an user reported a NPE inside the changeLog task. // we don't want a bug in Ant to prevent a build. e.printStackTrace(listener.error(e.getMessage())); return true; // so record the message but continue } }
if(changedFiles==null) return createEmptyChangeLog(changelogFile,listener, "changelog"); else return calcChangeLog(build, changedFiles, changelogFile, listener);
return calcChangeLog(build, changedFiles, changelogFile, listener);
public boolean checkout(Build build, Launcher launcher, FilePath dir, BuildListener listener, File changelogFile) throws IOException { List<String> changedFiles = null; // files that were affected by update. null this is a check out if(canUseUpdate && isUpdatable(dir.getLocal())) { changedFiles = update(false,launcher,dir,listener); if(changedFiles==null) return false; // failed } else { dir.deleteContents(); String cmd = MessageFormat.format("cvs -Q -z9 -d {0} co {1} {2} {3}", cvsroot, branch!=null?"-r "+branch:"", flatten?"-d "+dir.getName():"", module ); if(!run(launcher,cmd,listener, flatten ? dir.getParent() : dir)) return false; } // archive the workspace to support later tagging // TODO: doing this partially remotely would be faster File archiveFile = getArchiveFile(build); ZipOutputStream zos = new ZipOutputStream(archiveFile); if(flatten) { archive(build.getProject().getWorkspace().getLocal(), module, zos); } else { StringTokenizer tokens = new StringTokenizer(module); while(tokens.hasMoreTokens()) { String m = tokens.nextToken(); archive(new File(build.getProject().getWorkspace().getLocal(),m),m,zos); } } zos.close(); // contribute the tag action build.getActions().add(new TagAction(build)); if(changedFiles==null) // nothing to compare against return createEmptyChangeLog(changelogFile,listener, "changelog"); else return calcChangeLog(build, changedFiles, changelogFile, listener); }
SimpleDateFormat df = new SimpleDateFormat();
SimpleDateFormat df = new SimpleDateFormat("MM/dd/yyyy");
public String toXML() { StringBuffer sb = new StringBuffer(); sb.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"); sb.append("<STRANGEBREWRECIPE version = \"2.0A\">\n"); sb.append(" <DETAILS>\n"); sb.append(" <NAME>" + name + "</NAME>\n"); sb.append(" <NOTES>" + comments + "</NOTES>\n"); sb.append(" <EFFICIENCY>" + efficiency + "</EFFICIENCY>\n"); sb.append(" <OG>" + df3.format(estOg) + "</OG>\n"); sb.append(" <FG>" + df3.format(estFg) + "</FG>\n"); sb.append(" <STYLE>" + style.getName() + "</STYLE>\n"); sb.append(" <MASH>" + mashed + "</MASH>\n"); sb.append(" <LOV>" + df1.format(srm) + "</LOV>\n"); sb.append(" <IBU>" + df1.format(ibu) + "</IBU>\n"); sb.append(" <ALC>" + df1.format(alcohol) + "</ALC>\n"); sb.append(" <BOIL_TIME>" + boilMinutes + "</BOIL_TIME>\n"); sb.append(" <PRESIZE>" + preBoilVol.getValue() + "</PRESIZE>\n"); sb.append(" <SIZE>" + postBoilVol.getValue() + "</SIZE>\n"); sb.append(" <SIZE_UNITS>" + postBoilVol.getUnits() + "</SIZE_UNITS>\n"); sb.append(" <MALT_UNITS>" + maltUnits + "</MALT_UNITS>\n"); sb.append(" <HOPS_UNITS>" + hopUnits + "</HOPS_UNITS>\n"); sb.append(" <YEAST>" + yeast.getName() + "</YEAST>\n"); SimpleDateFormat df = new SimpleDateFormat(); sb.append(" <RECIPE_DATE>" + df.format(created.getTime()) + "</RECIPE_DATE>\n"); sb.append(" <ATTENUATION>" + attenuation + "</ATTENUATION>\n"); sb.append(" </DETAILS>\n"); // fermentables list: sb.append(" <FERMENTABLES>\n"); for (int i = 0; i < fermentables.size(); i++) { Fermentable m = (Fermentable) fermentables.get(i); sb.append(m.toXML()); } sb.append(" </FERMENTABLES>\n"); // hops list: sb.append(" <HOPS>\n"); for (int i = 0; i < hops.size(); i++) { Hop h = (Hop) hops.get(i); sb.append(h.toXML()); } sb.append(" </HOPS>\n"); // misc ingredients list: sb.append(" <MISC>\n"); for (int i = 0; i < misc.size(); i++) { Misc mi = (Misc) misc.get(i); sb.append(mi.toXML()); } sb.append(" </MISC>\n"); sb.append(mash.toXml()); sb.append("</STRANGEBREWRECIPE>"); return sb.toString(); }
canvas.drawString(name, xPosition, yPosition);
canvas.drawString(getName(), xPosition, yPosition);
public boolean drawName(Graphics2D canvas, int xPosition, int yPosition){ if(visible){ canvas.setPaint(color); canvas.drawString(name, xPosition, yPosition); return true; } return false; }
public String getName(){ return name; }
public String getName(){ return getSeismogram().getName(); }
public String getName(){ return name; }
public String toString(){ return name; }
public String toString(){ return getName(); }
public String toString(){ return name; }
return ( (Integer) iterate(CREDENTIAL_QRY_CNT, principal).next() ).intValue();
return find(CREDENTIAL_QRY, principal).size();
public int countCredentialByPrincipal(String principal) { return ( (Integer) iterate(CREDENTIAL_QRY_CNT, principal).next() ).intValue(); }
tblMalt.updateUI(); tblHops.updateUI();
public void displayRecipe() { if (myRecipe == null) return; txtName.setText(myRecipe.getName()); txtBrewer.setText(myRecipe.getBrewer()); cmbStyleModel.addOrInsert(myRecipe.getStyleObj()); cmbYeastModel.addOrInsert(myRecipe.getYeastObj()); txtPreBoil.setValue(new Double(myRecipe.getPreBoilVol(myRecipe .getVolUnits()))); txtPostBoil.setValue(new Double(myRecipe.getPostBoilVol(myRecipe .getVolUnits()))); 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(df1.format(myRecipe.getIbu())); lblColourValue.setText(df1.format(myRecipe.getSrm())); lblAlcValue.setText(df1.format(myRecipe.getAlcohol())); tblMaltModel.setData(myRecipe.getFermentablesList()); tblHopsModel.setData(myRecipe.getHopsList()); tblMaltTotalsModel.setDataVector(new String[][]{{"Totals:", "" + df1.format(myRecipe.getTotalMaltLbs()), myRecipe.getMaltUnits(), "" + df3.format(myRecipe.getEstOg()), "" + df1.format(myRecipe.getSrm()), "$" + df2.format(myRecipe.getTotalMaltCost()), "100"}}, new String[]{"", "", "", "", "", "", ""}); tblHopsTotalsModel.setDataVector(new String[][]{{"Totals:", "", "", "" + df1.format(myRecipe.getTotalHopsOz()), myRecipe.getHopUnits(), "", "", "" + df1.format(myRecipe.getIbu()), "$" + df2.format(myRecipe.getTotalHopsCost())}}, new String[]{ "", "", "", "", "", "", "", "", ""}); }
BorderLayout tblMaltLayout = new BorderLayout(); tblMalt.setLayout(tblMaltLayout);
private void initGUI() { try { this.setSize(520, 532); 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.1}; jPanel2Layout.rowHeights = new int[]{7, 7, 7}; pnlMain.setLayout(jPanel2Layout); this.getContentPane().add(pnlMain, BorderLayout.CENTER); { 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); { lblName = new JLabel(); jPanel1.add(lblName); lblName.setText("Name:"); } { txtName = new JTextField(); jPanel1.add(txtName); txtName.setText("Name"); txtName .setPreferredSize(new java.awt.Dimension(179, 20)); txtName.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { myRecipe.setName(txtName.getText()); } }); } } { 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}; pnlDetailsLayout.columnWidths = new int[]{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); { 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:"); } { txtBrewer = new JTextField(); pnlDetails.add(txtBrewer, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets( 0, 0, 0, 0), 0, 0)); txtBrewer.setText("Brewer"); txtBrewer.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { myRecipe.setBrewer(txtBrewer.getText()); } }); } { 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:"); } { lblMash = new JLabel(); pnlDetails.add(lblMash, new GridBagConstraints(0, 6, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblMash.setText("Mash:"); } { 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:"); } { 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:"); } { lblOG = new JLabel(); pnlDetails.add(lblOG, new GridBagConstraints(3, 2, 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(3, 3, 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(5, 0, 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(5, 2, 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(5, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblColour.setText("Colour:"); } { txtDate = new JTextField(); pnlDetails.add(txtDate, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets( 0, 0, 0, 0), 0, 0)); txtDate.setText("Date"); } { cmbStyleModel = new ComboModel(); cmbStyle = new JComboBox(); pnlDetails.add(cmbStyle, new GridBagConstraints(1, 2, 2, 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.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { Style s = (Style) cmbStyleModel .getSelectedItem(); if (myRecipe != null && s != myRecipe.getStyleObj()) { myRecipe.setStyle(s); } } }); } { 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.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { myRecipe.setPreBoil(Double .parseDouble(txtPreBoil.getText() .toString())); displayRecipe(); } }); } { txtPostBoil = new JFormattedTextField(); pnlDetails.add(txtPostBoil, new GridBagConstraints( 1, 5, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets( 0, 0, 0, 0), 0, 0)); txtPostBoil.setText("Post Boil"); txtPostBoil.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { System.out .println("txtPostBoil.actionPerformed, event=" + evt); myRecipe.setPostBoil(Double .parseDouble(txtPostBoil.getText() .toString())); displayRecipe(); } }); } { lblComments = new JLabel(); pnlDetails.add(lblComments, new GridBagConstraints( 3, 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.#")); } { 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.#")); } { SpinnerNumberModel spnOgModel = new SpinnerNumberModel( 1.000, 0.900, 2.000, 0.001); spnOG = new JSpinner(); pnlDetails.add(spnOG, new GridBagConstraints(4, 2, 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")); } { SpinnerNumberModel spnFgModel = new SpinnerNumberModel( 1.000, 0.900, 2.000, 0.001); spnFG = new JSpinner(); pnlDetails.add(spnFG, new GridBagConstraints(4, 3, 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.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( 6, 0, 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(6, 1, 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( 6, 2, 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( 3, 5, 4, 2, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); { txtComments = new JTextArea(); scpComments.setViewportView(txtComments); txtComments.setText("Comments"); txtComments.setWrapStyleWord(true); 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, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets( 0, 0, 0, 0), 0, 0)); cmbYeast.setModel(cmbYeastModel); cmbYeast.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { Yeast y = (Yeast) cmbYeastModel .getSelectedItem(); if (myRecipe!= null && y != myRecipe.getYeastObj()) { myRecipe.setYeast(y); } } }); } { ComboBoxModel cmbSizeUnitsModel = new DefaultComboBoxModel( new String[]{"Item One", "Item Two"}); cmbSizeUnits = new JComboBox(); pnlDetails.add(cmbSizeUnits, new GridBagConstraints(2, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); cmbSizeUnits.setModel(cmbSizeUnitsModel); } { lblSizeUnits = new JLabel(); pnlDetails.add(lblSizeUnits, new GridBagConstraints(2, 5, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblSizeUnits.setText("Size Units"); } } { pnlStyle = new JPanel(); FlowLayout pnlStyleLayout = new FlowLayout(); pnlStyle.setLayout(pnlStyleLayout); jTabbedPane1.addTab("Style", null, pnlStyle, null); { lblStyle2 = new JLabel(); pnlStyle.add(lblStyle2); lblStyle2.setText("Style:"); } { ComboBoxModel cmbStyle2Model = new DefaultComboBoxModel( new String[] { "Item One", "Item Two" }); cmbStyle2 = new JComboBox(); pnlStyle.add(cmbStyle2); cmbStyle2.setModel(cmbStyle2Model); } { jPanel2 = new JPanel(); GridBagLayout jPanel2Layout1 = new GridBagLayout(); jPanel2Layout1.columnWeights = new double[] {0.1,0.1,0.1,0.1}; jPanel2Layout1.columnWidths = new int[] {7,7,7,7}; jPanel2Layout1.rowWeights = new double[] {0.1,0.1,0.1,0.1,0.1,0.1}; jPanel2Layout1.rowHeights = new int[] {7,7,7,7,7,7}; jPanel2.setPreferredSize(new java.awt.Dimension(179, 120)); jPanel2.setLayout(jPanel2Layout1); pnlStyle.add(jPanel2); jPanel2.setBorder(BorderFactory.createTitledBorder(new LineBorder(new java.awt.Color(0,0,0), 1, false), "Recipe Conformance:", TitledBorder.LEADING, TitledBorder.TOP, new java.awt.Font("Dialog",0,12), new java.awt.Color(0,0,0))); { jLabel5 = new JLabel(); jPanel2.add(jLabel5, new GridBagConstraints( 0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel5.setText("OG:"); jLabel5.setBounds(74, 3, 60, 30); } { jLabel1 = new JLabel(); jPanel2.add(jLabel1, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); GridLayout jLabel1Layout = new GridLayout(1, 1); jLabel1.setLayout(jLabel1Layout); jLabel1.setText("Low:"); } { jLabel2 = new JLabel(); jPanel2.add(jLabel2, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel2.setText("Recipe:"); } { jLabel3 = new JLabel(); jPanel2.add(jLabel3, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel3.setText("High:"); } { jLabel4 = new JLabel(); jPanel2.add(jLabel4, new GridBagConstraints( 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel4.setText("IBU:"); } { jLabel6 = new JLabel(); jPanel2.add(jLabel6, new GridBagConstraints( 0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel6.setText("Colour:"); } { jLabel7 = new JLabel(); jPanel2.add(jLabel7, new GridBagConstraints( 0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel7.setText("ABV:"); } } { jScrollPane3 = new JScrollPane(); pnlStyle.add(jScrollPane3); { txaStyles = new JTextArea(); jScrollPane3.setViewportView(txaStyles); txaStyles.setText("Matched Styles"); } } { sldMatch = new JSlider(); pnlStyle.add(sldMatch); } } } { 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(); FlowLayout pnlMaltLayout = new FlowLayout(); 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); { tblMaltModel = new MaltTableModel(this); tblMalt = new JTable(); jScrollPane1.setViewportView(tblMalt); BorderLayout tblMaltLayout = new BorderLayout(); tblMalt.setLayout(tblMaltLayout); tblMalt.setModel(tblMaltModel); // TableColumn column = null; TableColumn maltColumn = tblMalt.getColumnModel().getColumn(0); JComboBox maltComboBox = new JComboBox(); cmbMaltModel = new ComboModel(); maltComboBox.setModel(cmbMaltModel); maltColumn.setCellEditor(new DefaultCellEditor(maltComboBox)); /* for (int i = 0; i < tblMalt.getColumnCount(); i++) { column = tblMalt.getColumnModel() .getColumn(i); if (i == 0) { column.setPreferredWidth(100); } else { column.setPreferredWidth(50); } }*/ maltComboBox .addActionListener(new ActionListener() { public void actionPerformed( ActionEvent evt) { Fermentable f = (Fermentable) cmbMaltModel .getSelectedItem(); int i = tblMalt .getSelectedRow(); if (myRecipe != null) { Fermentable f2 = (Fermentable) myRecipe .getFermentablesList() .get(i); f2.setLov(f.getLov()); f2.setPppg(f.getPppg()); } } }); } } { 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); } } { 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[]{ "Column 1", "Column 2"}); tblHopsTotals = new JTable(); pnlHops.add(tblHopsTotals, BorderLayout.SOUTH); tblHopsTotals.setModel(tblHopsTotalsModel); } { jScrollPane2 = new JScrollPane(); pnlHops.add(jScrollPane2, BorderLayout.CENTER); { tblHopsModel = new HopsTableModel(this); tblHops = new JTable(); jScrollPane2.setViewportView(tblHops); BorderLayout tblHopsLayout = new BorderLayout(); tblHops.setLayout(tblHopsLayout); tblHops.setModel(tblHopsModel); TableColumn hopColumn = tblHops.getColumnModel().getColumn(0); JComboBox hopComboBox = new JComboBox(); cmbHopsModel = new ComboModel(); hopComboBox.setModel(cmbHopsModel); hopColumn.setCellEditor(new DefaultCellEditor(hopComboBox)); } } } } } { jMenuBar1 = new JMenuBar(); setJMenuBar(jMenuBar1); { jMenu3 = new JMenu(); jMenuBar1.add(jMenu3); jMenu3.setText("File"); { newFileMenuItem = new JMenuItem(); jMenu3.add(newFileMenuItem); newFileMenuItem.setText("New"); } { openFileMenuItem = new JMenuItem(); jMenu3.add(openFileMenuItem); openFileMenuItem.setText("Open"); openFileMenuItem .addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { String path = getClass() .getProtectionDomain() .getCodeSource().getLocation() .toString().substring(6) + "\\"; JFileChooser fc = new JFileChooser(path); // Show open dialog; this method does // not return until the dialog is closed int returnVal = fc .showOpenDialog(jMenuBar1); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); System.out.print("Opening: " + file.getName() + ".\n"); ImportXml imp = new ImportXml(file .toString()); myRecipe = imp.handler.getRecipe(); myRecipe.calcMaltTotals(); myRecipe.calcHopsTotals(); myRecipe.mash .setMaltWeight(myRecipe .getTotalMashLbs()); myRecipe.mash.calcMashSchedule(); displayRecipe(); } else { System.out .print("Open command cancelled by user.\n"); } } }); } { saveMenuItem = new JMenuItem(); jMenu3.add(saveMenuItem); saveMenuItem.setText("Save"); } { saveAsMenuItem = new JMenuItem(); jMenu3.add(saveAsMenuItem); saveAsMenuItem.setText("Save As ..."); saveAsMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // This is just a test right now to see that // stuff is changed. System.out.print(myRecipe.toText()); } }); } { exportMenu = new JMenu(); jMenu3.add(exportMenu); exportMenu.setText("Export"); { exportHTMLmenu = new JMenuItem(); exportMenu.add(exportHTMLmenu); exportHTMLmenu.setText("HTML"); exportHTMLmenu .addActionListener(new ActionListener() { public void actionPerformed ( ActionEvent evt) { try{ saveAsHTML(); } catch (Exception e){ } } }); } } { closeFileMenuItem = new JMenuItem(); jMenu3.add(closeFileMenuItem); closeFileMenuItem.setText("Close"); } { jSeparator2 = new JSeparator(); jMenu3.add(jSeparator2); } { exitMenuItem = new JMenuItem(); jMenu3.add(exitMenuItem); exitMenuItem.setText("Exit"); exitMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // exit program System.exit(0); } }); } } { jMenu4 = new JMenu(); jMenuBar1.add(jMenu4); jMenu4.setText("Edit"); { cutMenuItem = new JMenuItem(); jMenu4.add(cutMenuItem); cutMenuItem.setText("Cut"); } { copyMenuItem = new JMenuItem(); jMenu4.add(copyMenuItem); copyMenuItem.setText("Copy"); } { pasteMenuItem = new JMenuItem(); jMenu4.add(pasteMenuItem); pasteMenuItem.setText("Paste"); } { jSeparator1 = new JSeparator(); jMenu4.add(jSeparator1); } { deleteMenuItem = new JMenuItem(); jMenu4.add(deleteMenuItem); deleteMenuItem.setText("Delete"); } } { jMenu5 = new JMenu(); jMenuBar1.add(jMenu5); jMenu5.setText("Help"); { helpMenuItem = new JMenuItem(); jMenu5.add(helpMenuItem); helpMenuItem.setText("Help"); } } } } catch (Exception e) { e.printStackTrace(); } }
/*
private void initGUI() { try { this.setSize(520, 532); 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.1}; jPanel2Layout.rowHeights = new int[]{7, 7, 7}; pnlMain.setLayout(jPanel2Layout); this.getContentPane().add(pnlMain, BorderLayout.CENTER); { 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); { lblName = new JLabel(); jPanel1.add(lblName); lblName.setText("Name:"); } { txtName = new JTextField(); jPanel1.add(txtName); txtName.setText("Name"); txtName .setPreferredSize(new java.awt.Dimension(179, 20)); txtName.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { myRecipe.setName(txtName.getText()); } }); } } { 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}; pnlDetailsLayout.columnWidths = new int[]{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); { 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:"); } { txtBrewer = new JTextField(); pnlDetails.add(txtBrewer, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets( 0, 0, 0, 0), 0, 0)); txtBrewer.setText("Brewer"); txtBrewer.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { myRecipe.setBrewer(txtBrewer.getText()); } }); } { 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:"); } { lblMash = new JLabel(); pnlDetails.add(lblMash, new GridBagConstraints(0, 6, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblMash.setText("Mash:"); } { 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:"); } { 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:"); } { lblOG = new JLabel(); pnlDetails.add(lblOG, new GridBagConstraints(3, 2, 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(3, 3, 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(5, 0, 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(5, 2, 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(5, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblColour.setText("Colour:"); } { txtDate = new JTextField(); pnlDetails.add(txtDate, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets( 0, 0, 0, 0), 0, 0)); txtDate.setText("Date"); } { cmbStyleModel = new ComboModel(); cmbStyle = new JComboBox(); pnlDetails.add(cmbStyle, new GridBagConstraints(1, 2, 2, 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.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { Style s = (Style) cmbStyleModel .getSelectedItem(); if (myRecipe != null && s != myRecipe.getStyleObj()) { myRecipe.setStyle(s); } } }); } { 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.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { myRecipe.setPreBoil(Double .parseDouble(txtPreBoil.getText() .toString())); displayRecipe(); } }); } { txtPostBoil = new JFormattedTextField(); pnlDetails.add(txtPostBoil, new GridBagConstraints( 1, 5, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets( 0, 0, 0, 0), 0, 0)); txtPostBoil.setText("Post Boil"); txtPostBoil.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { System.out .println("txtPostBoil.actionPerformed, event=" + evt); myRecipe.setPostBoil(Double .parseDouble(txtPostBoil.getText() .toString())); displayRecipe(); } }); } { lblComments = new JLabel(); pnlDetails.add(lblComments, new GridBagConstraints( 3, 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.#")); } { 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.#")); } { SpinnerNumberModel spnOgModel = new SpinnerNumberModel( 1.000, 0.900, 2.000, 0.001); spnOG = new JSpinner(); pnlDetails.add(spnOG, new GridBagConstraints(4, 2, 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")); } { SpinnerNumberModel spnFgModel = new SpinnerNumberModel( 1.000, 0.900, 2.000, 0.001); spnFG = new JSpinner(); pnlDetails.add(spnFG, new GridBagConstraints(4, 3, 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.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( 6, 0, 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(6, 1, 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( 6, 2, 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( 3, 5, 4, 2, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); { txtComments = new JTextArea(); scpComments.setViewportView(txtComments); txtComments.setText("Comments"); txtComments.setWrapStyleWord(true); 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, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets( 0, 0, 0, 0), 0, 0)); cmbYeast.setModel(cmbYeastModel); cmbYeast.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { Yeast y = (Yeast) cmbYeastModel .getSelectedItem(); if (myRecipe!= null && y != myRecipe.getYeastObj()) { myRecipe.setYeast(y); } } }); } { ComboBoxModel cmbSizeUnitsModel = new DefaultComboBoxModel( new String[]{"Item One", "Item Two"}); cmbSizeUnits = new JComboBox(); pnlDetails.add(cmbSizeUnits, new GridBagConstraints(2, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); cmbSizeUnits.setModel(cmbSizeUnitsModel); } { lblSizeUnits = new JLabel(); pnlDetails.add(lblSizeUnits, new GridBagConstraints(2, 5, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblSizeUnits.setText("Size Units"); } } { pnlStyle = new JPanel(); FlowLayout pnlStyleLayout = new FlowLayout(); pnlStyle.setLayout(pnlStyleLayout); jTabbedPane1.addTab("Style", null, pnlStyle, null); { lblStyle2 = new JLabel(); pnlStyle.add(lblStyle2); lblStyle2.setText("Style:"); } { ComboBoxModel cmbStyle2Model = new DefaultComboBoxModel( new String[] { "Item One", "Item Two" }); cmbStyle2 = new JComboBox(); pnlStyle.add(cmbStyle2); cmbStyle2.setModel(cmbStyle2Model); } { jPanel2 = new JPanel(); GridBagLayout jPanel2Layout1 = new GridBagLayout(); jPanel2Layout1.columnWeights = new double[] {0.1,0.1,0.1,0.1}; jPanel2Layout1.columnWidths = new int[] {7,7,7,7}; jPanel2Layout1.rowWeights = new double[] {0.1,0.1,0.1,0.1,0.1,0.1}; jPanel2Layout1.rowHeights = new int[] {7,7,7,7,7,7}; jPanel2.setPreferredSize(new java.awt.Dimension(179, 120)); jPanel2.setLayout(jPanel2Layout1); pnlStyle.add(jPanel2); jPanel2.setBorder(BorderFactory.createTitledBorder(new LineBorder(new java.awt.Color(0,0,0), 1, false), "Recipe Conformance:", TitledBorder.LEADING, TitledBorder.TOP, new java.awt.Font("Dialog",0,12), new java.awt.Color(0,0,0))); { jLabel5 = new JLabel(); jPanel2.add(jLabel5, new GridBagConstraints( 0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel5.setText("OG:"); jLabel5.setBounds(74, 3, 60, 30); } { jLabel1 = new JLabel(); jPanel2.add(jLabel1, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); GridLayout jLabel1Layout = new GridLayout(1, 1); jLabel1.setLayout(jLabel1Layout); jLabel1.setText("Low:"); } { jLabel2 = new JLabel(); jPanel2.add(jLabel2, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel2.setText("Recipe:"); } { jLabel3 = new JLabel(); jPanel2.add(jLabel3, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel3.setText("High:"); } { jLabel4 = new JLabel(); jPanel2.add(jLabel4, new GridBagConstraints( 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel4.setText("IBU:"); } { jLabel6 = new JLabel(); jPanel2.add(jLabel6, new GridBagConstraints( 0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel6.setText("Colour:"); } { jLabel7 = new JLabel(); jPanel2.add(jLabel7, new GridBagConstraints( 0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel7.setText("ABV:"); } } { jScrollPane3 = new JScrollPane(); pnlStyle.add(jScrollPane3); { txaStyles = new JTextArea(); jScrollPane3.setViewportView(txaStyles); txaStyles.setText("Matched Styles"); } } { sldMatch = new JSlider(); pnlStyle.add(sldMatch); } } } { 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(); FlowLayout pnlMaltLayout = new FlowLayout(); 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); { tblMaltModel = new MaltTableModel(this); tblMalt = new JTable(); jScrollPane1.setViewportView(tblMalt); BorderLayout tblMaltLayout = new BorderLayout(); tblMalt.setLayout(tblMaltLayout); tblMalt.setModel(tblMaltModel); // TableColumn column = null; TableColumn maltColumn = tblMalt.getColumnModel().getColumn(0); JComboBox maltComboBox = new JComboBox(); cmbMaltModel = new ComboModel(); maltComboBox.setModel(cmbMaltModel); maltColumn.setCellEditor(new DefaultCellEditor(maltComboBox)); /* for (int i = 0; i < tblMalt.getColumnCount(); i++) { column = tblMalt.getColumnModel() .getColumn(i); if (i == 0) { column.setPreferredWidth(100); } else { column.setPreferredWidth(50); } }*/ maltComboBox .addActionListener(new ActionListener() { public void actionPerformed( ActionEvent evt) { Fermentable f = (Fermentable) cmbMaltModel .getSelectedItem(); int i = tblMalt .getSelectedRow(); if (myRecipe != null) { Fermentable f2 = (Fermentable) myRecipe .getFermentablesList() .get(i); f2.setLov(f.getLov()); f2.setPppg(f.getPppg()); } } }); } } { 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); } } { 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[]{ "Column 1", "Column 2"}); tblHopsTotals = new JTable(); pnlHops.add(tblHopsTotals, BorderLayout.SOUTH); tblHopsTotals.setModel(tblHopsTotalsModel); } { jScrollPane2 = new JScrollPane(); pnlHops.add(jScrollPane2, BorderLayout.CENTER); { tblHopsModel = new HopsTableModel(this); tblHops = new JTable(); jScrollPane2.setViewportView(tblHops); BorderLayout tblHopsLayout = new BorderLayout(); tblHops.setLayout(tblHopsLayout); tblHops.setModel(tblHopsModel); TableColumn hopColumn = tblHops.getColumnModel().getColumn(0); JComboBox hopComboBox = new JComboBox(); cmbHopsModel = new ComboModel(); hopComboBox.setModel(cmbHopsModel); hopColumn.setCellEditor(new DefaultCellEditor(hopComboBox)); } } } } } { jMenuBar1 = new JMenuBar(); setJMenuBar(jMenuBar1); { jMenu3 = new JMenu(); jMenuBar1.add(jMenu3); jMenu3.setText("File"); { newFileMenuItem = new JMenuItem(); jMenu3.add(newFileMenuItem); newFileMenuItem.setText("New"); } { openFileMenuItem = new JMenuItem(); jMenu3.add(openFileMenuItem); openFileMenuItem.setText("Open"); openFileMenuItem .addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { String path = getClass() .getProtectionDomain() .getCodeSource().getLocation() .toString().substring(6) + "\\"; JFileChooser fc = new JFileChooser(path); // Show open dialog; this method does // not return until the dialog is closed int returnVal = fc .showOpenDialog(jMenuBar1); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); System.out.print("Opening: " + file.getName() + ".\n"); ImportXml imp = new ImportXml(file .toString()); myRecipe = imp.handler.getRecipe(); myRecipe.calcMaltTotals(); myRecipe.calcHopsTotals(); myRecipe.mash .setMaltWeight(myRecipe .getTotalMashLbs()); myRecipe.mash.calcMashSchedule(); displayRecipe(); } else { System.out .print("Open command cancelled by user.\n"); } } }); } { saveMenuItem = new JMenuItem(); jMenu3.add(saveMenuItem); saveMenuItem.setText("Save"); } { saveAsMenuItem = new JMenuItem(); jMenu3.add(saveAsMenuItem); saveAsMenuItem.setText("Save As ..."); saveAsMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // This is just a test right now to see that // stuff is changed. System.out.print(myRecipe.toText()); } }); } { exportMenu = new JMenu(); jMenu3.add(exportMenu); exportMenu.setText("Export"); { exportHTMLmenu = new JMenuItem(); exportMenu.add(exportHTMLmenu); exportHTMLmenu.setText("HTML"); exportHTMLmenu .addActionListener(new ActionListener() { public void actionPerformed ( ActionEvent evt) { try{ saveAsHTML(); } catch (Exception e){ } } }); } } { closeFileMenuItem = new JMenuItem(); jMenu3.add(closeFileMenuItem); closeFileMenuItem.setText("Close"); } { jSeparator2 = new JSeparator(); jMenu3.add(jSeparator2); } { exitMenuItem = new JMenuItem(); jMenu3.add(exitMenuItem); exitMenuItem.setText("Exit"); exitMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // exit program System.exit(0); } }); } } { jMenu4 = new JMenu(); jMenuBar1.add(jMenu4); jMenu4.setText("Edit"); { cutMenuItem = new JMenuItem(); jMenu4.add(cutMenuItem); cutMenuItem.setText("Cut"); } { copyMenuItem = new JMenuItem(); jMenu4.add(copyMenuItem); copyMenuItem.setText("Copy"); } { pasteMenuItem = new JMenuItem(); jMenu4.add(pasteMenuItem); pasteMenuItem.setText("Paste"); } { jSeparator1 = new JSeparator(); jMenu4.add(jSeparator1); } { deleteMenuItem = new JMenuItem(); jMenu4.add(deleteMenuItem); deleteMenuItem.setText("Delete"); } } { jMenu5 = new JMenu(); jMenuBar1.add(jMenu5); jMenu5.setText("Help"); { helpMenuItem = new JMenuItem(); jMenu5.add(helpMenuItem); helpMenuItem.setText("Help"); } } } } catch (Exception e) { e.printStackTrace(); } }
}*/
}
private void initGUI() { try { this.setSize(520, 532); 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.1}; jPanel2Layout.rowHeights = new int[]{7, 7, 7}; pnlMain.setLayout(jPanel2Layout); this.getContentPane().add(pnlMain, BorderLayout.CENTER); { 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); { lblName = new JLabel(); jPanel1.add(lblName); lblName.setText("Name:"); } { txtName = new JTextField(); jPanel1.add(txtName); txtName.setText("Name"); txtName .setPreferredSize(new java.awt.Dimension(179, 20)); txtName.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { myRecipe.setName(txtName.getText()); } }); } } { 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}; pnlDetailsLayout.columnWidths = new int[]{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); { 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:"); } { txtBrewer = new JTextField(); pnlDetails.add(txtBrewer, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets( 0, 0, 0, 0), 0, 0)); txtBrewer.setText("Brewer"); txtBrewer.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { myRecipe.setBrewer(txtBrewer.getText()); } }); } { 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:"); } { lblMash = new JLabel(); pnlDetails.add(lblMash, new GridBagConstraints(0, 6, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblMash.setText("Mash:"); } { 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:"); } { 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:"); } { lblOG = new JLabel(); pnlDetails.add(lblOG, new GridBagConstraints(3, 2, 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(3, 3, 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(5, 0, 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(5, 2, 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(5, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblColour.setText("Colour:"); } { txtDate = new JTextField(); pnlDetails.add(txtDate, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets( 0, 0, 0, 0), 0, 0)); txtDate.setText("Date"); } { cmbStyleModel = new ComboModel(); cmbStyle = new JComboBox(); pnlDetails.add(cmbStyle, new GridBagConstraints(1, 2, 2, 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.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { Style s = (Style) cmbStyleModel .getSelectedItem(); if (myRecipe != null && s != myRecipe.getStyleObj()) { myRecipe.setStyle(s); } } }); } { 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.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { myRecipe.setPreBoil(Double .parseDouble(txtPreBoil.getText() .toString())); displayRecipe(); } }); } { txtPostBoil = new JFormattedTextField(); pnlDetails.add(txtPostBoil, new GridBagConstraints( 1, 5, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets( 0, 0, 0, 0), 0, 0)); txtPostBoil.setText("Post Boil"); txtPostBoil.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { System.out .println("txtPostBoil.actionPerformed, event=" + evt); myRecipe.setPostBoil(Double .parseDouble(txtPostBoil.getText() .toString())); displayRecipe(); } }); } { lblComments = new JLabel(); pnlDetails.add(lblComments, new GridBagConstraints( 3, 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.#")); } { 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.#")); } { SpinnerNumberModel spnOgModel = new SpinnerNumberModel( 1.000, 0.900, 2.000, 0.001); spnOG = new JSpinner(); pnlDetails.add(spnOG, new GridBagConstraints(4, 2, 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")); } { SpinnerNumberModel spnFgModel = new SpinnerNumberModel( 1.000, 0.900, 2.000, 0.001); spnFG = new JSpinner(); pnlDetails.add(spnFG, new GridBagConstraints(4, 3, 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.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( 6, 0, 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(6, 1, 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( 6, 2, 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( 3, 5, 4, 2, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); { txtComments = new JTextArea(); scpComments.setViewportView(txtComments); txtComments.setText("Comments"); txtComments.setWrapStyleWord(true); 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, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets( 0, 0, 0, 0), 0, 0)); cmbYeast.setModel(cmbYeastModel); cmbYeast.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { Yeast y = (Yeast) cmbYeastModel .getSelectedItem(); if (myRecipe!= null && y != myRecipe.getYeastObj()) { myRecipe.setYeast(y); } } }); } { ComboBoxModel cmbSizeUnitsModel = new DefaultComboBoxModel( new String[]{"Item One", "Item Two"}); cmbSizeUnits = new JComboBox(); pnlDetails.add(cmbSizeUnits, new GridBagConstraints(2, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); cmbSizeUnits.setModel(cmbSizeUnitsModel); } { lblSizeUnits = new JLabel(); pnlDetails.add(lblSizeUnits, new GridBagConstraints(2, 5, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblSizeUnits.setText("Size Units"); } } { pnlStyle = new JPanel(); FlowLayout pnlStyleLayout = new FlowLayout(); pnlStyle.setLayout(pnlStyleLayout); jTabbedPane1.addTab("Style", null, pnlStyle, null); { lblStyle2 = new JLabel(); pnlStyle.add(lblStyle2); lblStyle2.setText("Style:"); } { ComboBoxModel cmbStyle2Model = new DefaultComboBoxModel( new String[] { "Item One", "Item Two" }); cmbStyle2 = new JComboBox(); pnlStyle.add(cmbStyle2); cmbStyle2.setModel(cmbStyle2Model); } { jPanel2 = new JPanel(); GridBagLayout jPanel2Layout1 = new GridBagLayout(); jPanel2Layout1.columnWeights = new double[] {0.1,0.1,0.1,0.1}; jPanel2Layout1.columnWidths = new int[] {7,7,7,7}; jPanel2Layout1.rowWeights = new double[] {0.1,0.1,0.1,0.1,0.1,0.1}; jPanel2Layout1.rowHeights = new int[] {7,7,7,7,7,7}; jPanel2.setPreferredSize(new java.awt.Dimension(179, 120)); jPanel2.setLayout(jPanel2Layout1); pnlStyle.add(jPanel2); jPanel2.setBorder(BorderFactory.createTitledBorder(new LineBorder(new java.awt.Color(0,0,0), 1, false), "Recipe Conformance:", TitledBorder.LEADING, TitledBorder.TOP, new java.awt.Font("Dialog",0,12), new java.awt.Color(0,0,0))); { jLabel5 = new JLabel(); jPanel2.add(jLabel5, new GridBagConstraints( 0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel5.setText("OG:"); jLabel5.setBounds(74, 3, 60, 30); } { jLabel1 = new JLabel(); jPanel2.add(jLabel1, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); GridLayout jLabel1Layout = new GridLayout(1, 1); jLabel1.setLayout(jLabel1Layout); jLabel1.setText("Low:"); } { jLabel2 = new JLabel(); jPanel2.add(jLabel2, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel2.setText("Recipe:"); } { jLabel3 = new JLabel(); jPanel2.add(jLabel3, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel3.setText("High:"); } { jLabel4 = new JLabel(); jPanel2.add(jLabel4, new GridBagConstraints( 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel4.setText("IBU:"); } { jLabel6 = new JLabel(); jPanel2.add(jLabel6, new GridBagConstraints( 0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel6.setText("Colour:"); } { jLabel7 = new JLabel(); jPanel2.add(jLabel7, new GridBagConstraints( 0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel7.setText("ABV:"); } } { jScrollPane3 = new JScrollPane(); pnlStyle.add(jScrollPane3); { txaStyles = new JTextArea(); jScrollPane3.setViewportView(txaStyles); txaStyles.setText("Matched Styles"); } } { sldMatch = new JSlider(); pnlStyle.add(sldMatch); } } } { 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(); FlowLayout pnlMaltLayout = new FlowLayout(); 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); { tblMaltModel = new MaltTableModel(this); tblMalt = new JTable(); jScrollPane1.setViewportView(tblMalt); BorderLayout tblMaltLayout = new BorderLayout(); tblMalt.setLayout(tblMaltLayout); tblMalt.setModel(tblMaltModel); // TableColumn column = null; TableColumn maltColumn = tblMalt.getColumnModel().getColumn(0); JComboBox maltComboBox = new JComboBox(); cmbMaltModel = new ComboModel(); maltComboBox.setModel(cmbMaltModel); maltColumn.setCellEditor(new DefaultCellEditor(maltComboBox)); /* for (int i = 0; i < tblMalt.getColumnCount(); i++) { column = tblMalt.getColumnModel() .getColumn(i); if (i == 0) { column.setPreferredWidth(100); } else { column.setPreferredWidth(50); } }*/ maltComboBox .addActionListener(new ActionListener() { public void actionPerformed( ActionEvent evt) { Fermentable f = (Fermentable) cmbMaltModel .getSelectedItem(); int i = tblMalt .getSelectedRow(); if (myRecipe != null) { Fermentable f2 = (Fermentable) myRecipe .getFermentablesList() .get(i); f2.setLov(f.getLov()); f2.setPppg(f.getPppg()); } } }); } } { 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); } } { 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[]{ "Column 1", "Column 2"}); tblHopsTotals = new JTable(); pnlHops.add(tblHopsTotals, BorderLayout.SOUTH); tblHopsTotals.setModel(tblHopsTotalsModel); } { jScrollPane2 = new JScrollPane(); pnlHops.add(jScrollPane2, BorderLayout.CENTER); { tblHopsModel = new HopsTableModel(this); tblHops = new JTable(); jScrollPane2.setViewportView(tblHops); BorderLayout tblHopsLayout = new BorderLayout(); tblHops.setLayout(tblHopsLayout); tblHops.setModel(tblHopsModel); TableColumn hopColumn = tblHops.getColumnModel().getColumn(0); JComboBox hopComboBox = new JComboBox(); cmbHopsModel = new ComboModel(); hopComboBox.setModel(cmbHopsModel); hopColumn.setCellEditor(new DefaultCellEditor(hopComboBox)); } } } } } { jMenuBar1 = new JMenuBar(); setJMenuBar(jMenuBar1); { jMenu3 = new JMenu(); jMenuBar1.add(jMenu3); jMenu3.setText("File"); { newFileMenuItem = new JMenuItem(); jMenu3.add(newFileMenuItem); newFileMenuItem.setText("New"); } { openFileMenuItem = new JMenuItem(); jMenu3.add(openFileMenuItem); openFileMenuItem.setText("Open"); openFileMenuItem .addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { String path = getClass() .getProtectionDomain() .getCodeSource().getLocation() .toString().substring(6) + "\\"; JFileChooser fc = new JFileChooser(path); // Show open dialog; this method does // not return until the dialog is closed int returnVal = fc .showOpenDialog(jMenuBar1); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); System.out.print("Opening: " + file.getName() + ".\n"); ImportXml imp = new ImportXml(file .toString()); myRecipe = imp.handler.getRecipe(); myRecipe.calcMaltTotals(); myRecipe.calcHopsTotals(); myRecipe.mash .setMaltWeight(myRecipe .getTotalMashLbs()); myRecipe.mash.calcMashSchedule(); displayRecipe(); } else { System.out .print("Open command cancelled by user.\n"); } } }); } { saveMenuItem = new JMenuItem(); jMenu3.add(saveMenuItem); saveMenuItem.setText("Save"); } { saveAsMenuItem = new JMenuItem(); jMenu3.add(saveAsMenuItem); saveAsMenuItem.setText("Save As ..."); saveAsMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // This is just a test right now to see that // stuff is changed. System.out.print(myRecipe.toText()); } }); } { exportMenu = new JMenu(); jMenu3.add(exportMenu); exportMenu.setText("Export"); { exportHTMLmenu = new JMenuItem(); exportMenu.add(exportHTMLmenu); exportHTMLmenu.setText("HTML"); exportHTMLmenu .addActionListener(new ActionListener() { public void actionPerformed ( ActionEvent evt) { try{ saveAsHTML(); } catch (Exception e){ } } }); } } { closeFileMenuItem = new JMenuItem(); jMenu3.add(closeFileMenuItem); closeFileMenuItem.setText("Close"); } { jSeparator2 = new JSeparator(); jMenu3.add(jSeparator2); } { exitMenuItem = new JMenuItem(); jMenu3.add(exitMenuItem); exitMenuItem.setText("Exit"); exitMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // exit program System.exit(0); } }); } } { jMenu4 = new JMenu(); jMenuBar1.add(jMenu4); jMenu4.setText("Edit"); { cutMenuItem = new JMenuItem(); jMenu4.add(cutMenuItem); cutMenuItem.setText("Cut"); } { copyMenuItem = new JMenuItem(); jMenu4.add(copyMenuItem); copyMenuItem.setText("Copy"); } { pasteMenuItem = new JMenuItem(); jMenu4.add(pasteMenuItem); pasteMenuItem.setText("Paste"); } { jSeparator1 = new JSeparator(); jMenu4.add(jSeparator1); } { deleteMenuItem = new JMenuItem(); jMenu4.add(deleteMenuItem); deleteMenuItem.setText("Delete"); } } { jMenu5 = new JMenu(); jMenuBar1.add(jMenu5); jMenu5.setText("Help"); { helpMenuItem = new JMenuItem(); jMenu5.add(helpMenuItem); helpMenuItem.setText("Help"); } } } } catch (Exception e) { e.printStackTrace(); } }
float[] fdata = seis.get_as_floats();
float[] fdata; if(seis.can_convert_to_float()) fdata = seis.get_as_floats(); else{ int[] idata = seis.get_as_longs(); fdata = new float[idata.length]; for(int i = 0; i < idata.length; i++) fdata[i] = idata[i]; idata = null; }
public void filterData(){ float[] fdata = seis.get_as_floats(); // remove the mean before filtering double mean = 0; for (int i=0; i<fdata.length; i++) { mean += fdata[i]; } // end of for (int i=0; i<fdata.length; i++) mean /= fdata.length; float fmean = (float)mean; for (int i=0; i<fdata.length; i++) { fdata[i] -= fmean; } // end of for (int i=0; i<fdata.length; i++) Cmplx[] fftdata = Cmplx.fft(fdata); //save memory fdata = null; double dt = seis.getSampling().getPeriod().convertTo(UnitImpl.SECOND).getValue(); Cmplx[] filtered = filter.apply(dt, fftdata); // save memory fftdata = null; float[] outData = Cmplx.fftInverse(filtered, seis.getNumPoints()); TimeSeriesDataSel sel = new TimeSeriesDataSel(); sel.flt_values(outData); filteredSeis = new LocalSeismogramImpl(seis, sel); }
ObjComparator sc = new ObjComparator(); Collections.sort(styleDB, sc); Collections.sort(fermDB, sc); Collections.sort(hopsDB, sc); Collections.sort(yeastDB, sc);
public void readDB(String path){ dbPath = path; fermDB = new ArrayList(); readFermentables(dbPath); hopsDB = new ArrayList(); readHops(dbPath); yeastDB = new ArrayList(); readYeast(dbPath); // readStyles(dbPath); miscDB = new ArrayList(); readMisc(dbPath); styleDB = new ArrayList(); importStyles(dbPath); }