rem
stringlengths 0
477k
| add
stringlengths 0
313k
| context
stringlengths 6
599k
|
---|---|---|
return fToC(boilTempF); | return BrewCalcs.fToC(boilTempF); | public double getBoilTemp() { if (tempUnits.equals("F")) return boilTempF; else return fToC(boilTempF); } |
return fToC(((MashStep)steps.get(i)).getTemp()); | return BrewCalcs.fToC(((MashStep)steps.get(i)).getTemp()); | public double getStepTemp(int i) { if (((MashStep)steps.get(i)).getTemp() == 0) return 0; if (tempUnits.equals("F")) return ((MashStep)steps.get(i)).getTemp(); else return fToC(((MashStep)steps.get(i)).getTemp()); } |
boilTempF = cToF(t); | boilTempF = BrewCalcs.cToF(t); | public void setBoilTemp(double t){ if (tempUnits.equals("F")) boilTempF = t; else boilTempF = cToF(t); calcMashSchedule(); } |
sb.append(SBStringUtils.xmlElement("GRAIN_TEMP", "" + fToC(grainTempF), 4)); sb.append(SBStringUtils.xmlElement("BOIL_TEMP", "" + fToC(boilTempF), 4)); | sb.append(SBStringUtils.xmlElement("GRAIN_TEMP", "" + BrewCalcs.fToC(grainTempF), 4)); sb.append(SBStringUtils.xmlElement("BOIL_TEMP", "" + BrewCalcs.fToC(boilTempF), 4)); | public String toXml() { StringBuffer sb = new StringBuffer(); sb.append(" <MASH>\n"); sb.append(SBStringUtils.xmlElement("MASH_VOLUME", SBStringUtils.format(Quantity.convertUnit("qt", volUnits, volQts), 2) , 4)); sb.append(SBStringUtils.xmlElement("MASH_VOL_U", "" + volUnits, 4)); sb.append(SBStringUtils.xmlElement("MASH_RATIO", "" + mashRatio, 4)); sb.append(SBStringUtils.xmlElement("MASH_RATIO_U", "" + mashRatioU, 4)); sb.append(SBStringUtils.xmlElement("MASH_TIME", "" + totalTime, 4)); sb.append(SBStringUtils.xmlElement("MASH_TMP_U", "" + tempUnits, 4)); sb.append(SBStringUtils.xmlElement("THICK_DECOCT_RATIO", "" + thickDecoctRatio, 4)); sb.append(SBStringUtils.xmlElement("THIN_DECOCT_RATIO", "" + thinDecoctRatio, 4)); if (tempUnits.equals("C")){ sb.append(SBStringUtils.xmlElement("MASH_TUNLOSS_TEMP", "" + (tunLossF/1.8), 4)); sb.append(SBStringUtils.xmlElement("GRAIN_TEMP", "" + fToC(grainTempF), 4)); sb.append(SBStringUtils.xmlElement("BOIL_TEMP", "" + fToC(boilTempF), 4)); } else { sb.append(SBStringUtils.xmlElement("MASH_TUNLOSS_TEMP", "" + tunLossF, 4)); sb.append(SBStringUtils.xmlElement("GRAIN_TEMP", "" + grainTempF, 4)); sb.append(SBStringUtils.xmlElement("BOIL_TEMP", "" + boilTempF, 4)); } for (int i = 0; i < steps.size(); i++) { MashStep st = (MashStep) steps.get(i); sb.append(" <ITEM>\n"); sb.append(" <TYPE>" + st.type + "</TYPE>\n"); sb.append(" <TEMP>" + st.startTemp + "</TEMP>\n"); if (tempUnits.equals("C")) sb.append(" <DISPL_TEMP>" + SBStringUtils.format(fToC(st.startTemp), 1) + "</DISPL_TEMP>\n"); else sb.append(" <DISPL_TEMP>" + st.startTemp + "</DISPL_TEMP>\n"); sb.append(" <END_TEMP>" + st.endTemp + "</END_TEMP>\n"); if (tempUnits.equals("C")) sb.append(" <DISPL_END_TEMP>" + SBStringUtils.format(fToC(st.endTemp), 1) + "</DISPL_END_TEMP>\n"); else sb.append(" <DISPL_END_TEMP>" + st.endTemp + "</DISPL_END_TEMP>\n"); sb.append(" <MIN>" + st.minutes + "</MIN>\n"); sb.append(" <RAMP_MIN>" + st.rampMin + "</RAMP_MIN>\n"); sb.append(" <METHOD>" + st.method + "</METHOD>\n"); sb.append(" <WEIGHT_LBS>" + st.weightLbs + "</WEIGHT_LBS>\n"); sb.append(" <DIRECTIONS>" + st.directions + "</DIRECTIONS>\n"); sb.append(" </ITEM>\n"); } sb.append(" </MASH>\n"); return sb.toString(); } |
sb.append(" <DISPL_TEMP>" + SBStringUtils.format(fToC(st.startTemp), 1) + "</DISPL_TEMP>\n"); | sb.append(" <DISPL_TEMP>" + SBStringUtils.format(BrewCalcs.fToC(st.startTemp), 1) + "</DISPL_TEMP>\n"); | public String toXml() { StringBuffer sb = new StringBuffer(); sb.append(" <MASH>\n"); sb.append(SBStringUtils.xmlElement("MASH_VOLUME", SBStringUtils.format(Quantity.convertUnit("qt", volUnits, volQts), 2) , 4)); sb.append(SBStringUtils.xmlElement("MASH_VOL_U", "" + volUnits, 4)); sb.append(SBStringUtils.xmlElement("MASH_RATIO", "" + mashRatio, 4)); sb.append(SBStringUtils.xmlElement("MASH_RATIO_U", "" + mashRatioU, 4)); sb.append(SBStringUtils.xmlElement("MASH_TIME", "" + totalTime, 4)); sb.append(SBStringUtils.xmlElement("MASH_TMP_U", "" + tempUnits, 4)); sb.append(SBStringUtils.xmlElement("THICK_DECOCT_RATIO", "" + thickDecoctRatio, 4)); sb.append(SBStringUtils.xmlElement("THIN_DECOCT_RATIO", "" + thinDecoctRatio, 4)); if (tempUnits.equals("C")){ sb.append(SBStringUtils.xmlElement("MASH_TUNLOSS_TEMP", "" + (tunLossF/1.8), 4)); sb.append(SBStringUtils.xmlElement("GRAIN_TEMP", "" + fToC(grainTempF), 4)); sb.append(SBStringUtils.xmlElement("BOIL_TEMP", "" + fToC(boilTempF), 4)); } else { sb.append(SBStringUtils.xmlElement("MASH_TUNLOSS_TEMP", "" + tunLossF, 4)); sb.append(SBStringUtils.xmlElement("GRAIN_TEMP", "" + grainTempF, 4)); sb.append(SBStringUtils.xmlElement("BOIL_TEMP", "" + boilTempF, 4)); } for (int i = 0; i < steps.size(); i++) { MashStep st = (MashStep) steps.get(i); sb.append(" <ITEM>\n"); sb.append(" <TYPE>" + st.type + "</TYPE>\n"); sb.append(" <TEMP>" + st.startTemp + "</TEMP>\n"); if (tempUnits.equals("C")) sb.append(" <DISPL_TEMP>" + SBStringUtils.format(fToC(st.startTemp), 1) + "</DISPL_TEMP>\n"); else sb.append(" <DISPL_TEMP>" + st.startTemp + "</DISPL_TEMP>\n"); sb.append(" <END_TEMP>" + st.endTemp + "</END_TEMP>\n"); if (tempUnits.equals("C")) sb.append(" <DISPL_END_TEMP>" + SBStringUtils.format(fToC(st.endTemp), 1) + "</DISPL_END_TEMP>\n"); else sb.append(" <DISPL_END_TEMP>" + st.endTemp + "</DISPL_END_TEMP>\n"); sb.append(" <MIN>" + st.minutes + "</MIN>\n"); sb.append(" <RAMP_MIN>" + st.rampMin + "</RAMP_MIN>\n"); sb.append(" <METHOD>" + st.method + "</METHOD>\n"); sb.append(" <WEIGHT_LBS>" + st.weightLbs + "</WEIGHT_LBS>\n"); sb.append(" <DIRECTIONS>" + st.directions + "</DIRECTIONS>\n"); sb.append(" </ITEM>\n"); } sb.append(" </MASH>\n"); return sb.toString(); } |
sb.append(" <DISPL_END_TEMP>" + SBStringUtils.format(fToC(st.endTemp), 1) + "</DISPL_END_TEMP>\n"); | sb.append(" <DISPL_END_TEMP>" + SBStringUtils.format(BrewCalcs.fToC(st.endTemp), 1) + "</DISPL_END_TEMP>\n"); | public String toXml() { StringBuffer sb = new StringBuffer(); sb.append(" <MASH>\n"); sb.append(SBStringUtils.xmlElement("MASH_VOLUME", SBStringUtils.format(Quantity.convertUnit("qt", volUnits, volQts), 2) , 4)); sb.append(SBStringUtils.xmlElement("MASH_VOL_U", "" + volUnits, 4)); sb.append(SBStringUtils.xmlElement("MASH_RATIO", "" + mashRatio, 4)); sb.append(SBStringUtils.xmlElement("MASH_RATIO_U", "" + mashRatioU, 4)); sb.append(SBStringUtils.xmlElement("MASH_TIME", "" + totalTime, 4)); sb.append(SBStringUtils.xmlElement("MASH_TMP_U", "" + tempUnits, 4)); sb.append(SBStringUtils.xmlElement("THICK_DECOCT_RATIO", "" + thickDecoctRatio, 4)); sb.append(SBStringUtils.xmlElement("THIN_DECOCT_RATIO", "" + thinDecoctRatio, 4)); if (tempUnits.equals("C")){ sb.append(SBStringUtils.xmlElement("MASH_TUNLOSS_TEMP", "" + (tunLossF/1.8), 4)); sb.append(SBStringUtils.xmlElement("GRAIN_TEMP", "" + fToC(grainTempF), 4)); sb.append(SBStringUtils.xmlElement("BOIL_TEMP", "" + fToC(boilTempF), 4)); } else { sb.append(SBStringUtils.xmlElement("MASH_TUNLOSS_TEMP", "" + tunLossF, 4)); sb.append(SBStringUtils.xmlElement("GRAIN_TEMP", "" + grainTempF, 4)); sb.append(SBStringUtils.xmlElement("BOIL_TEMP", "" + boilTempF, 4)); } for (int i = 0; i < steps.size(); i++) { MashStep st = (MashStep) steps.get(i); sb.append(" <ITEM>\n"); sb.append(" <TYPE>" + st.type + "</TYPE>\n"); sb.append(" <TEMP>" + st.startTemp + "</TEMP>\n"); if (tempUnits.equals("C")) sb.append(" <DISPL_TEMP>" + SBStringUtils.format(fToC(st.startTemp), 1) + "</DISPL_TEMP>\n"); else sb.append(" <DISPL_TEMP>" + st.startTemp + "</DISPL_TEMP>\n"); sb.append(" <END_TEMP>" + st.endTemp + "</END_TEMP>\n"); if (tempUnits.equals("C")) sb.append(" <DISPL_END_TEMP>" + SBStringUtils.format(fToC(st.endTemp), 1) + "</DISPL_END_TEMP>\n"); else sb.append(" <DISPL_END_TEMP>" + st.endTemp + "</DISPL_END_TEMP>\n"); sb.append(" <MIN>" + st.minutes + "</MIN>\n"); sb.append(" <RAMP_MIN>" + st.rampMin + "</RAMP_MIN>\n"); sb.append(" <METHOD>" + st.method + "</METHOD>\n"); sb.append(" <WEIGHT_LBS>" + st.weightLbs + "</WEIGHT_LBS>\n"); sb.append(" <DIRECTIONS>" + st.directions + "</DIRECTIONS>\n"); sb.append(" </ITEM>\n"); } sb.append(" </MASH>\n"); return sb.toString(); } |
sortedGWebCaches = new TreeSet( new GWebCacheComparator() ); | sortedGWebCaches = new TreeSet<GWebCache>( new GWebCacheComparator() ); | public GWebCacheContainer() { NLogger.debug( NLoggerNames.GWEBCACHE, "Initializing GWebCacheContainer" ); allGWebCaches = new ArrayList(); phexGWebCaches = new ArrayList(); functionalGWebCaches = new ArrayList(); uniqueGWebCacheURLs = new HashSet( ); sortedGWebCaches = new TreeSet( new GWebCacheComparator() ); random = new Random(); NLogger.debug( NLoggerNames.GWEBCACHE, "Initialized GWebCacheContainer" ); } |
*/ | private GWebCache getGWebCacheForUpdate( GWebCache ignore ) { GWebCache gWebCache = null; int count = functionalGWebCaches.size(); if ( count == 0 ) { return null; } else if ( count == 1 ) { gWebCache = (GWebCache)functionalGWebCaches.get( 0 ); if ( gWebCache.equals( ignore ) ) { return null; } else { assert( !gWebCache.isPhexCache() ); return gWebCache; } } int tries = 0; do { int randomIndex = random.nextInt( count - 1 ); gWebCache = (GWebCache)functionalGWebCaches.get( randomIndex ); if ( !gWebCache.equals( ignore ) ) { assert ( !gWebCache.isPhexCache() ); return gWebCache; } tries ++; } while ( tries < 10 ); // no valid cache found... return null; } |
|
assert !gWebCache.isPhexCache() && !gWebCache.equals( connection.getGWebCache() ) | assert gWebCache == null || (!gWebCache.isPhexCache() && !gWebCache.equals( connection.getGWebCache() )) | public boolean updateRemoteGWebCache( DestAddress myHostAddress, boolean preferPhex ) { String fullHostName = null; if ( myHostAddress != null ) { fullHostName = myHostAddress.getFullHostName(); } int retrys = 0; boolean succ = false; do { retrys ++; GWebCacheConnection connection = getRandomGWebCacheConnection( preferPhex ); // continue if no connection... if ( connection == null ) { continue; } GWebCache gWebCache = getGWebCacheForUpdate( connection.getGWebCache() ); assert !gWebCache.isPhexCache() && !gWebCache.equals( connection.getGWebCache() ) : "isPhexCache: " + gWebCache.isPhexCache() + ",equals " + gWebCache.getUrl() + " - " + connection.getGWebCache().getUrl(); String urlString = null; if ( gWebCache != null ) { urlString = gWebCache.getUrl().toExternalForm(); } if ( fullHostName == null && urlString == null ) { // no data to update... try again to determine random GWebCache in loop continue; } succ = connection.updateRequest( fullHostName, urlString ); // continue if cache is bad or not successful... if ( !verifyGWebCache( connection ) || !succ ) { continue; } } // do this max 5 times or until we where successful while ( !succ && retrys < 5 ); return succ; } |
public void addCaughtHost( DestAddress address, short priority ) | public boolean addCaughtHost( PongMsg pongMsg ) | public void addCaughtHost( DestAddress address, short priority ) { boolean valid = isValidCaughtHostAddress( address ); if ( !valid ) { return; } CaughtHost caughtHost = new CaughtHost( address ); addPersistentCaughtHost( caughtHost ); addToCaughtHostFetcher( caughtHost, priority ); } |
return; } | return false; } | public void addCaughtHost( DestAddress address, short priority ) { boolean valid = isValidCaughtHostAddress( address ); if ( !valid ) { return; } CaughtHost caughtHost = new CaughtHost( address ); addPersistentCaughtHost( caughtHost ); addToCaughtHostFetcher( caughtHost, priority ); } |
addToCaughtHostFetcher( caughtHost, priority ); | boolean isNew = addToCaughtHostFetcher( caughtHost, priority ); return isNew; | public void addCaughtHost( DestAddress address, short priority ) { boolean valid = isValidCaughtHostAddress( address ); if ( !valid ) { return; } CaughtHost caughtHost = new CaughtHost( address ); addPersistentCaughtHost( caughtHost ); addToCaughtHostFetcher( caughtHost, priority ); } |
else { return ((Integer) index).intValue(); } | return ((Integer) index).intValue(); | final int addVar(Variable var){ Object index = varRefs.get(var); if(index==null) { int size = varRefs.size(); expandVarArray(size+1); varRefs.put(var,new Integer(size)); copyFromVar(var,size); var.addObserver(this); return size; } else { return ((Integer) index).intValue(); } } |
this.jep = jep; | public RpEval(JEP jep) { this.jep = jep; this.opSet = jep.getOperatorSet(); } |
|
; | private File getHomeDir(ServletContextEvent event) { // check JNDI for the home directory first try { Context env = (Context) new InitialContext().lookup("java:comp/env"); String value = (String) env.lookup("HUDSON_HOME"); if(value!=null && value.trim().length()>0) return new File(value); } catch (NamingException e) { ; // ignore } // look at the env var next String env = EnvVars.masterEnvVars.get("HUDSON_HOME"); if(env!=null) return new File(env); // otherwise pick a place by ourselves String root = event.getServletContext().getRealPath("/WEB-INF/workspace"); if(root!=null) return new File(root); // if for some reason we can't put it within the webapp, use home directory. return new File(new File(System.getProperty("user.home")),".hudson"); } |
|
String sysProp = System.getProperty("HUDSON_HOME"); if(sysProp!=null) return new File(sysProp); | private File getHomeDir(ServletContextEvent event) { // check JNDI for the home directory first try { Context env = (Context) new InitialContext().lookup("java:comp/env"); String value = (String) env.lookup("HUDSON_HOME"); if(value!=null && value.trim().length()>0) return new File(value); } catch (NamingException e) { ; // ignore } // look at the env var next String env = EnvVars.masterEnvVars.get("HUDSON_HOME"); if(env!=null) return new File(env); // otherwise pick a place by ourselves String root = event.getServletContext().getRealPath("/WEB-INF/workspace"); if(root!=null) return new File(root); // if for some reason we can't put it within the webapp, use home directory. return new File(new File(System.getProperty("user.home")),".hudson"); } |
|
public String getString(String option, String defaultValue) | public String getString(String option) | public String getString(String option, String defaultValue) { assert(isValidOption(option)); String value = getValue(option); if (value == null) return defaultValue; return value; } |
assert(isValidOption(option)); String value = getValue(option); if (value == null) return defaultValue; return value; | return getString(option, ""); | public String getString(String option, String defaultValue) { assert(isValidOption(option)); String value = getValue(option); if (value == null) return defaultValue; return value; } |
if (!o.getClass().getName().endsWith("JTextField")) return; | public void actionPerformed(ActionEvent e) { Object o = e.getSource(); String s = ""; // String t = ""; s = ((JTextField) o).getText(); // t = s.replace(',','.'); // accept also european decimal komma if (o == txtName) myRecipe.setName(s); else if (o == brewerNameText) myRecipe.setBrewer(s); else if (o == txtPreBoil) { myRecipe.setPreBoil(Double.parseDouble(s)); displayRecipe(); } else if (o == postBoilText) { myRecipe.setPostBoil(Double.parseDouble(s)); displayRecipe(); } else if (o == evapText) { myRecipe.setEvap(Double.parseDouble(s)); displayRecipe(); } else if (o == boilMinText) { if( s.indexOf('.') > 0) { // parseInt doesn't like '.' or ',', so trim the string s = s.substring(0,s.indexOf('.')); } myRecipe.setBoilMinutes(Integer.parseInt(s)); displayRecipe(); } } |
|
txtDate.setText(SBStringUtils.dateFormat1.format(myRecipe.getCreated().getTime())); | try { txtDate.setDate(myRecipe.getCreated().getTime()); } catch (PropertyVetoException e) { e.printStackTrace(); } | public void displayRecipe() { if (myRecipe == null) return; txtName.setText(myRecipe.getName()); brewerNameText.setText(myRecipe.getBrewer()); txtPreBoil.setValue(new Double(myRecipe.getPreBoilVol(myRecipe.getVolUnits()))); lblSizeUnits.setText(myRecipe.getVolUnits()); postBoilText.setValue(new Double(myRecipe.getPostBoilVol(myRecipe.getVolUnits()))); boilMinText.setText(SBStringUtils.format(myRecipe.getBoilMinutes(), 0)); evapText.setText(SBStringUtils.format(myRecipe.getEvap(), 1)); spnEffic.setValue(new Double(myRecipe.getEfficiency())); spnAtten.setValue(new Double(myRecipe.getAttenuation())); spnOG.setValue(new Double(myRecipe.getEstOg())); spnFG.setValue(new Double(myRecipe.getEstFg())); txtComments.setText(myRecipe.getComments()); lblIBUvalue.setText(SBStringUtils.format(myRecipe.getIbu(), 1)); lblColourValue.setText(SBStringUtils.format(myRecipe.getSrm(), 1)); lblAlcValue.setText(SBStringUtils.format(myRecipe.getAlcohol(), 1)); txtDate.setText(SBStringUtils.dateFormat1.format(myRecipe.getCreated().getTime())); Costs = SBStringUtils.myNF.format(myRecipe.getTotalMaltCost()); tblMaltTotalsModel.setDataVector(new String[][]{{"Totals:", "" + SBStringUtils.format(myRecipe.getTotalMalt(), 1), myRecipe.getMaltUnits(), "" + SBStringUtils.format(myRecipe.getEstOg(), 3), "" + SBStringUtils.format(myRecipe.getSrm(), 1), Costs, "100"}}, new String[]{"", "", "", "", "", "", ""}); Costs = SBStringUtils.myNF.format(myRecipe.getTotalHopsCost()); tblHopsTotalsModel.setDataVector(new String[][]{{"Totals:", "", "", "" + SBStringUtils.format(myRecipe.getTotalHops(), 1), myRecipe.getHopUnits(), "", "", "" + SBStringUtils.format(myRecipe.getIbu(), 1), Costs}}, new String[]{"", "", "", "", "", "", "", "", ""}); String fileName = "not saved"; if (currentFile != null) { fileName = currentFile.getName(); } fileNameLabel.setText("File: " + fileName); ibuMethodLabel.setText("IBU method: " + myRecipe.getIBUMethod()); alcMethodLabel.setText("Alc method: " + myRecipe.getAlcMethod()); double colour = myRecipe.getSrm(); // convert from ebc if that's our mode: if (myRecipe.getColourMethod().equals("EBC")) { // From Greg Noonan's article at // http://brewingtechniques.com/bmg/noonan.html colour = (colour + 1.2) / 2.65; } if (preferences.getProperty("optRGBMethod").equals("1")) colourPanel.setBackground(Recipe.calcRGB(1, colour, preferences.getIProperty("optRed"), preferences.getIProperty("optGreen"), preferences.getIProperty("optBlue"), preferences.getIProperty("optAlpha"))); else colourPanel.setBackground(Recipe.calcRGB(2, colour, preferences.getIProperty("optRed"), preferences.getIProperty("optGreen"), preferences.getIProperty("optBlue"), preferences.getIProperty("optAlpha"))); // update the panels stylePanel.setStyleData(); costPanel.displayCost(); waterPanel.displayWater(); mashPanel.displayMash(); } |
imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/brew.gif"); | imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/sb2.gif"); | private void initGUI() { try { // restore the saved size and location: this.setSize(preferences.getIProperty("winWidth"), preferences.getIProperty("winHeight")); this.setLocation(preferences.getIProperty("winX"), preferences.getIProperty("winY")); imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/brew.gif"); icon = new ImageIcon(imgURL); this.setIconImage(icon.getImage()); this.setTitle("StrangeBrew " + version); this.addWindowListener(new WindowAdapter() { public void windowClosed(WindowEvent evt) { System.exit(1); } }); { pnlMain = new JPanel(); GridBagLayout jPanel2Layout = new GridBagLayout(); jPanel2Layout.columnWeights = new double[]{0.1}; jPanel2Layout.columnWidths = new int[]{7}; jPanel2Layout.rowWeights = new double[]{0.1, 0.1, 0.9, 0.1}; jPanel2Layout.rowHeights = new int[]{7, 7, 7, 7}; pnlMain.setLayout(jPanel2Layout); this.getContentPane().add(pnlMain, BorderLayout.CENTER); { jTabbedPane1 = new JTabbedPane(); pnlMain.add(jTabbedPane1, new GridBagConstraints(0, 1, 1, 1, 0.1, 0.1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); { pnlDetails = new JPanel(); GridBagLayout pnlDetailsLayout = new GridBagLayout(); pnlDetailsLayout.columnWeights = new double[]{0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1}; pnlDetailsLayout.columnWidths = new int[]{7, 7, 7, 7, 7, 7, 7, 7, 7, 7}; pnlDetailsLayout.rowWeights = new double[]{0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1}; pnlDetailsLayout.rowHeights = new int[]{7, 7, 7, 7, 7, 7, 7}; pnlDetails.setLayout(pnlDetailsLayout); jTabbedPane1.addTab("Details", null, pnlDetails, null); pnlDetails.setPreferredSize(new java.awt.Dimension(20, 16)); { lblBrewer = new JLabel(); pnlDetails.add(lblBrewer, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblBrewer.setText("Brewer:"); } { brewerNameText = new JTextField(); pnlDetails.add(brewerNameText, new GridBagConstraints(1, 0, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); brewerNameText.setPreferredSize(new java.awt.Dimension(69, 20)); brewerNameText.setText("Brewer"); } { lblDate = new JLabel(); pnlDetails.add(lblDate, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblDate.setText("Date:"); } { lblStyle = new JLabel(); pnlDetails.add(lblStyle, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblStyle.setText("Style:"); } { lblYeast = new JLabel(); pnlDetails.add(lblYeast, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblYeast.setText("Yeast:"); } { lblPreBoil = new JLabel(); pnlDetails.add(lblPreBoil, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblPreBoil.setText("Pre boil:"); } { lblPostBoil = new JLabel(); pnlDetails.add(lblPostBoil, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblPostBoil.setText("Post boil:"); } { lblEffic = new JLabel(); pnlDetails.add(lblEffic, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblEffic.setText("Effic:"); lblEffic.setPreferredSize(new java.awt.Dimension(31, 14)); } { lblAtten = new JLabel(); pnlDetails.add(lblAtten, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblAtten.setText("Atten:"); lblAtten.setPreferredSize(new java.awt.Dimension(34, 14)); } { lblOG = new JLabel(); pnlDetails.add(lblOG, new GridBagConstraints(5, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblOG.setText("OG:"); } { lblFG = new JLabel(); pnlDetails.add(lblFG, new GridBagConstraints(5, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblFG.setText("FG:"); } { lblIBU = new JLabel(); pnlDetails.add(lblIBU, new GridBagConstraints(7, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblIBU.setText("IBU:"); } { lblAlc = new JLabel(); pnlDetails.add(lblAlc, new GridBagConstraints(7, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblAlc.setText("%Alc:"); } { lblColour = new JLabel(); pnlDetails.add(lblColour, new GridBagConstraints(7, 2, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblColour.setText("Colour:"); } { txtDate = new JFormattedTextField(); pnlDetails.add(txtDate, new GridBagConstraints(1, 1, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); txtDate.setText("Date"); txtDate.setPreferredSize(new java.awt.Dimension(73, 20)); } { cmbStyleModel = new ComboModel(); cmbStyle = new JComboBox(); pnlDetails.add(cmbStyle, new GridBagConstraints(1, 2, 5, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cmbStyle.setModel(cmbStyleModel); cmbStyle.setMaximumSize(new java.awt.Dimension(100, 32767)); cmbStyle.setPreferredSize(new java.awt.Dimension(190, 20)); } { txtPreBoil = new JFormattedTextField(); pnlDetails.add(txtPreBoil, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); txtPreBoil.setText("Pre Boil"); txtPreBoil.setPreferredSize(new java.awt.Dimension(37, 20)); } { postBoilText = new JFormattedTextField(); pnlDetails.add(postBoilText, new GridBagConstraints(1, 5, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); postBoilText.setText("Post Boil"); postBoilText.setPreferredSize(new java.awt.Dimension(46, 20)); } { lblComments = new JLabel(); pnlDetails.add(lblComments, new GridBagConstraints(6, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblComments.setText("Comments:"); } { SpinnerNumberModel spnEfficModel = new SpinnerNumberModel(75.0, 0.0, 100.0, 1.0); spnEffic = new JSpinner(); pnlDetails.add(spnEffic, new GridBagConstraints(4, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnEffic.setModel(spnEfficModel); spnEffic.setMaximumSize(new java.awt.Dimension(70, 32767)); spnEffic.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { myRecipe.setEfficiency(Double.parseDouble(spnEffic.getValue() .toString())); displayRecipe(); } }); spnEffic.setEditor(new JSpinner.NumberEditor(spnEffic, "00.#")); spnEffic.getEditor().setPreferredSize(new java.awt.Dimension(28, 16)); spnEffic.setPreferredSize(new java.awt.Dimension(53, 18)); } { SpinnerNumberModel spnAttenModel = new SpinnerNumberModel(75.0, 0.0, 100.0, 1.0); spnAtten = new JSpinner(); pnlDetails.add(spnAtten, new GridBagConstraints(4, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnAtten.setModel(spnAttenModel); spnAtten.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { myRecipe.setAttenuation(Double.parseDouble(spnAtten.getValue() .toString())); displayRecipe(); } }); spnAtten.setEditor(new JSpinner.NumberEditor(spnAtten, "00.#")); spnAtten.setPreferredSize(new java.awt.Dimension(49, 20)); } { SpinnerNumberModel spnOgModel = new SpinnerNumberModel(1.000, 0.900, 2.000, 0.001); spnOG = new JSpinner(); pnlDetails.add(spnOG, new GridBagConstraints(6, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnOG.setModel(spnOgModel); spnOG.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { myRecipe.setEstOg(Double.parseDouble(spnOG.getValue() .toString())); displayRecipe(); } }); spnOG.setEditor(new JSpinner.NumberEditor(spnOG, "0.000")); spnOG.getEditor().setPreferredSize(new java.awt.Dimension(20, 16)); spnOG.setPreferredSize(new java.awt.Dimension(67, 18)); } { SpinnerNumberModel spnFgModel = new SpinnerNumberModel(1.000, 0.900, 2.000, 0.001); spnFG = new JSpinner(); pnlDetails.add(spnFG, new GridBagConstraints(6, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnFG.setModel(spnFgModel); spnFG.setEditor(new JSpinner.NumberEditor(spnFG, "0.000")); spnFG.setPreferredSize(new java.awt.Dimension(69, 20)); spnFG.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { // set the new FG, and update alc: myRecipe.setEstFg(Double.parseDouble(spnFG.getValue() .toString())); displayRecipe(); } }); } { lblIBUvalue = new JLabel(); pnlDetails.add(lblIBUvalue, new GridBagConstraints(8, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblIBUvalue.setText("IBUs"); } { lblColourValue = new JLabel(); pnlDetails.add(lblColourValue, new GridBagConstraints(8, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblColourValue.setText("Colour"); } { lblAlcValue = new JLabel(); pnlDetails.add(lblAlcValue, new GridBagConstraints(8, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblAlcValue.setText("Alc"); } { scpComments = new JScrollPane(); pnlDetails.add(scpComments, new GridBagConstraints(7, 4, 3, 2, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); { txtComments = new JTextArea(); scpComments.setViewportView(txtComments); txtComments.setText("Comments"); txtComments.setWrapStyleWord(true); // txtComments.setPreferredSize(new java.awt.Dimension(117, 42)); txtComments.setLineWrap(true); txtComments.setPreferredSize(new java.awt.Dimension(263, 40)); txtComments.addFocusListener(new FocusAdapter() { public void focusLost(FocusEvent evt) { if (!txtComments.getText().equals(myRecipe.getComments())) { myRecipe.setComments(txtComments.getText()); } } }); } } { cmbYeastModel = new ComboModel(); cmbYeast = new JComboBox(); pnlDetails.add(cmbYeast, new GridBagConstraints(1, 3, 5, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cmbYeast.setModel(cmbYeastModel); cmbYeast.setPreferredSize(new java.awt.Dimension(193, 20)); } { cmbSizeUnitsModel = new ComboModel(); cmbSizeUnits = new JComboBox(); pnlDetails.add(cmbSizeUnits, new GridBagConstraints(2, 4, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cmbSizeUnits.setModel(cmbSizeUnitsModel); } { lblSizeUnits = new JLabel(); pnlDetails.add(lblSizeUnits, new GridBagConstraints(2, 5, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); lblSizeUnits.setText("Size Units"); } { boilTimeLable = new JLabel(); pnlDetails.add(boilTimeLable, new GridBagConstraints(4, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); boilTimeLable.setText("Boil Min:"); } { evapLabel = new JLabel(); pnlDetails.add(evapLabel, new GridBagConstraints(4, 5, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); evapLabel.setText("Evap/hr:"); } { boilMinText = new JTextField(); pnlDetails.add(boilMinText, new GridBagConstraints(5, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); boilMinText.setText("60"); boilMinText.setPreferredSize(new java.awt.Dimension(22, 20)); } { evapText = new JTextField(); pnlDetails.add(evapText, new GridBagConstraints(5, 5, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); evapText.setText("4"); evapText.setPreferredSize(new java.awt.Dimension(23, 20)); } { alcMethodComboModel = new DefaultComboBoxModel(new String[]{"Volume", "Weight"}); alcMethodCombo = new JComboBox(alcMethodComboModel); pnlDetails.add(alcMethodCombo, new GridBagConstraints(9, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); alcMethodCombo.setPreferredSize(new java.awt.Dimension(58, 20)); } { ibuMethodComboModel = new DefaultComboBoxModel(new String[]{"Tinseth", "Garetz", "Rager"}); ibuMethodCombo = new JComboBox(ibuMethodComboModel); pnlDetails.add(ibuMethodCombo, new GridBagConstraints(9, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); ibuMethodCombo.setPreferredSize(new java.awt.Dimension(59, 20)); } { colourMethodComboModel = new DefaultComboBoxModel(new String[]{"SRM", "EBC"}); colourMethodCombo = new JComboBox(colourMethodComboModel); pnlDetails.add(colourMethodCombo, new GridBagConstraints(9, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); colourMethodCombo.setPreferredSize(new java.awt.Dimension(44, 20)); } ComboBoxModel evapMethodComboModel = new DefaultComboBoxModel(new String[] { "Constant", "Percent" }); { jPanel1 = new JPanel(); pnlMain.add(jPanel1, new GridBagConstraints( 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); FlowLayout jPanel1Layout = new FlowLayout(); jPanel1Layout.setAlignment(FlowLayout.LEFT); jPanel1.setLayout(jPanel1Layout); jToolBar1 = new JToolBar(); getContentPane().add(jToolBar1, BorderLayout.NORTH); jToolBar1.setFloatable(false); jToolBar1.setRollover(true); jButton1 = new JButton(); jToolBar1.add(jButton1); jButton1.setMnemonic(java.awt.event.KeyEvent.VK_S); jButton1.setIcon(new ImageIcon(getClass().getClassLoader().getResource( "ca/strangebrew/icons/save.gif"))); jButton1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { System.out.println("jButton1.actionPerformed, event=" + evt); //TODO add your code for jButton1.actionPerformed } }); jButton2 = new JButton(); jToolBar1.add(jButton2); jButton2.setIcon(new ImageIcon(getClass().getClassLoader().getResource( "ca/strangebrew/icons/find.gif"))); jButton2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { System.out.println("jButton2.actionPerformed, event=" + evt); //TODO add your code for jButton2.actionPerformed } }); { lblName = new JLabel(); jPanel1.add(lblName); lblName.setText("Name:"); } { txtName = new JTextField(); jPanel1.add(txtName); txtName.setText("Name"); txtName.setPreferredSize(new java.awt.Dimension(297, 20)); } } evapMethodCombo = new JComboBox(); pnlDetails.add(evapMethodCombo, new GridBagConstraints(6, 5, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); evapMethodCombo.setModel(evapMethodComboModel); evapMethodCombo.setPreferredSize(new java.awt.Dimension(64, 20)); colourPanel = new JPanel(); pnlDetails.add(colourPanel, new GridBagConstraints(9, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); colourPanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); } { SBNotifier sbn = new SBNotifier(); stylePanel = new StylePanel(sbn); jTabbedPane1.addTab("Style", null, stylePanel, null); miscPanel = new MiscPanel(myRecipe); jTabbedPane1.addTab("Misc", null, miscPanel, null); notesPanel = new NotesPanel(); jTabbedPane1.addTab("Notes", null, notesPanel, null); dilutionPanel = new DilutionPanel(); jTabbedPane1.addTab("Dilution", null, dilutionPanel, null); mashPanel = new MashPanel(myRecipe); jTabbedPane1.addTab("Mash", null, mashPanel, null); waterPanel = new WaterPanel(); jTabbedPane1.addTab("Water", null, waterPanel, null); costPanel = new CostPanel(); jTabbedPane1.addTab("Cost", null, costPanel, null); // SBNotifier sbn = new SBNotifier(); settingsPanel = new SettingsPanel(sbn); jTabbedPane1.addTab("Settings", null, settingsPanel, null); } } { pnlTables = new JPanel(); BoxLayout pnlMaltsLayout = new BoxLayout(pnlTables, javax.swing.BoxLayout.Y_AXIS); pnlMain.add(pnlTables, new GridBagConstraints(0, 2, 1, 1, 0.5, 0.5, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); pnlTables.setLayout(pnlMaltsLayout); { pnlMalt = new JPanel(); pnlTables.add(pnlMalt); BorderLayout pnlMaltLayout1 = new BorderLayout(); pnlMalt.setBorder(BorderFactory.createTitledBorder(new LineBorder( new java.awt.Color(0, 0, 0), 1, false), "Fermentables", TitledBorder.LEADING, TitledBorder.TOP, new java.awt.Font("Dialog", 1, 12), new java.awt.Color(51, 51, 51))); pnlMalt.setLayout(pnlMaltLayout1); { jScrollPane1 = new JScrollPane(); pnlMalt.add(jScrollPane1, BorderLayout.CENTER); { maltTableModel = new MaltTableModel(this); maltTable = new JTable() { public String getToolTipText(MouseEvent e) { java.awt.Point p = e.getPoint(); int rowIndex = rowAtPoint(p); return SBStringUtils.multiLineToolTip(40, maltTableModel .getDescriptionAt(rowIndex)); } }; jScrollPane1.setViewportView(maltTable); maltTable.setModel(maltTableModel); // maltTable.setAutoCreateColumnsFromModel(false); maltTable.getTableHeader().setReorderingAllowed(false); TableColumn maltColumn = maltTable.getColumnModel().getColumn(0); // set up malt list combo maltComboBox = new JComboBox(); cmbMaltModel = new ComboModel(); maltComboBox.setModel(cmbMaltModel); maltColumn.setCellEditor(new DefaultCellEditor(maltComboBox)); // set up malt units combo maltUnitsComboBox = new JComboBox(); cmbMaltUnitsModel = new ComboModel(); maltUnitsComboBox.setModel(cmbMaltUnitsModel); maltColumn = maltTable.getColumnModel().getColumn(2); maltColumn.setCellEditor(new DefaultCellEditor(maltUnitsComboBox)); } } { tblMaltTotalsModel = new DefaultTableModel(new String[][]{{""}}, new String[]{"Malt", "Amount", "Units", "Points", "Lov", "Cost/U", "%"}); tblMaltTotals = new JTable(); pnlMalt.add(tblMaltTotals, BorderLayout.SOUTH); tblMaltTotals.setModel(tblMaltTotalsModel); tblMaltTotals.getTableHeader().setEnabled(false); tblMaltTotals.setAutoCreateColumnsFromModel(false); // set up the units combobox maltTotalUnitsComboBox = new JComboBox(); maltTotalUnitsComboModel = new ComboModel(); maltTotalUnitsComboModel.setList(new Quantity().getListofUnits("weight")); maltTotalUnitsComboBox.setModel(maltTotalUnitsComboModel); TableColumn t = tblMaltTotals.getColumnModel().getColumn(2); t.setCellEditor(new DefaultCellEditor(maltTotalUnitsComboBox)); maltTotalUnitsComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { String u = (String) maltTotalUnitsComboModel.getSelectedItem(); if (myRecipe != null) { myRecipe.setMaltUnits(u); displayRecipe(); } } }); } } { pnlMaltButtons = new JPanel(); pnlTables.add(pnlMaltButtons); FlowLayout pnlMaltButtonsLayout = new FlowLayout(); pnlMaltButtonsLayout.setAlignment(FlowLayout.LEFT); pnlMaltButtonsLayout.setVgap(0); pnlMaltButtons.setLayout(pnlMaltButtonsLayout); pnlMaltButtons.setPreferredSize(new java.awt.Dimension(592, 27)); { tlbMalt = new JToolBar(); pnlMaltButtons.add(tlbMalt); tlbMalt.setPreferredSize(new java.awt.Dimension(55, 20)); tlbMalt.setFloatable(false); { btnAddMalt = new JButton(); tlbMalt.add(btnAddMalt); btnAddMalt.setText("+"); btnAddMalt.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { Fermentable f = new Fermentable(myRecipe.getMaltUnits()); myRecipe.addMalt(f); maltTable.updateUI(); displayRecipe(); } } }); } { btnDelMalt = new JButton(); tlbMalt.add(btnDelMalt); btnDelMalt.setText("-"); btnDelMalt.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { int i = maltTable.getSelectedRow(); myRecipe.delMalt(i); maltTable.updateUI(); displayRecipe(); } } }); } } } { pnlHops = new JPanel(); BorderLayout pnlHopsLayout = new BorderLayout(); pnlHops.setBorder(BorderFactory.createTitledBorder(new LineBorder( new java.awt.Color(0, 0, 0), 1, false), "Hops", TitledBorder.LEADING, TitledBorder.TOP, new java.awt.Font("Dialog", 1, 12), new java.awt.Color(51, 51, 51))); pnlHops.setLayout(pnlHopsLayout); pnlTables.add(pnlHops); { tblHopsTotalsModel = new DefaultTableModel(new String[][]{{""}}, new String[]{"1", "2", "3", "4", "5", "6", "7", "8", "9"}); tblHopsTotals = new JTable(); pnlHops.add(tblHopsTotals, BorderLayout.SOUTH); tblHopsTotals.setModel(tblHopsTotalsModel); tblHopsTotals.setAutoCreateColumnsFromModel(false); // set up the units combobox hopsTotalUnitsComboBox = new JComboBox(); hopsTotalUnitsComboModel = new ComboModel(); hopsTotalUnitsComboModel.setList(new Quantity().getListofUnits("weight")); hopsTotalUnitsComboBox.setModel(hopsTotalUnitsComboModel); TableColumn t = tblHopsTotals.getColumnModel().getColumn(4); t.setCellEditor(new DefaultCellEditor(hopsTotalUnitsComboBox)); hopsTotalUnitsComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { String u = (String) hopsTotalUnitsComboModel.getSelectedItem(); if (myRecipe != null) { myRecipe.setHopsUnits(u); displayRecipe(); } } }); } { jScrollPane2 = new JScrollPane(); pnlHops.add(jScrollPane2, BorderLayout.CENTER); { hopsTableModel = new HopsTableModel(this); hopsTable = new JTable() { public String getToolTipText(MouseEvent e) { java.awt.Point p = e.getPoint(); int rowIndex = rowAtPoint(p); return SBStringUtils.multiLineToolTip(40, hopsTableModel .getDescriptionAt(rowIndex)); } }; jScrollPane2.setViewportView(hopsTable); hopsTable.setModel(hopsTableModel); hopsTable.getTableHeader().setReorderingAllowed(false); TableColumn hopColumn = hopsTable.getColumnModel().getColumn(0); hopComboBox = new JComboBox(); cmbHopsModel = new ComboModel(); hopComboBox.setModel(cmbHopsModel); hopColumn.setCellEditor(new DefaultCellEditor(hopComboBox)); // set up hop units combo hopsUnitsComboBox = new JComboBox(); cmbHopsUnitsModel = new ComboModel(); hopsUnitsComboBox.setModel(cmbHopsUnitsModel); hopColumn = hopsTable.getColumnModel().getColumn(4); hopColumn.setCellEditor(new DefaultCellEditor(hopsUnitsComboBox)); // set up hop type combo String[] forms = {"Leaf", "Pellet", "Plug"}; JComboBox hopsFormComboBox = new JComboBox(forms); hopColumn = hopsTable.getColumnModel().getColumn(1); hopColumn.setCellEditor(new DefaultCellEditor(hopsFormComboBox)); // set up hop add combo String[] add = {"Boil", "FWH", "Dry", "Mash"}; JComboBox hopsAddComboBox = new JComboBox(add); hopColumn = hopsTable.getColumnModel().getColumn(5); hopColumn.setCellEditor(new DefaultCellEditor(hopsAddComboBox)); } } } { pnlHopsButtons = new JPanel(); FlowLayout pnlHopsButtonsLayout = new FlowLayout(); pnlHopsButtonsLayout.setAlignment(FlowLayout.LEFT); pnlHopsButtonsLayout.setVgap(0); pnlHopsButtons.setLayout(pnlHopsButtonsLayout); pnlTables.add(pnlHopsButtons); pnlHopsButtons.setPreferredSize(new java.awt.Dimension(512, 16)); { tlbHops = new JToolBar(); pnlHopsButtons.add(tlbHops); tlbHops.setPreferredSize(new java.awt.Dimension(58, 19)); tlbHops.setFloatable(false); { btnAddHop = new JButton(); tlbHops.add(btnAddHop); btnAddHop.setText("+"); btnAddHop.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { Hop h = new Hop(myRecipe.getHopUnits()); myRecipe.addHop(h); hopsTable.updateUI(); displayRecipe(); } } }); } { btnDelHop = new JButton(); tlbHops.add(btnDelHop); btnDelHop.setText("-"); btnDelHop.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { int i = hopsTable.getSelectedRow(); myRecipe.delHop(i); hopsTable.updateUI(); displayRecipe(); } } }); } } } } { statusPanel = new JPanel(); FlowLayout statusPanelLayout = new FlowLayout(); statusPanelLayout.setAlignment(FlowLayout.LEFT); statusPanelLayout.setHgap(2); statusPanelLayout.setVgap(2); statusPanel.setLayout(statusPanelLayout); pnlMain.add(statusPanel, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); { fileNamePanel = new JPanel(); statusPanel.add(fileNamePanel); fileNamePanel.setBorder(BorderFactory .createBevelBorder(BevelBorder.LOWERED)); { fileNameLabel = new JLabel(); fileNamePanel.add(fileNameLabel); fileNameLabel.setText("File Name"); fileNameLabel.setFont(new java.awt.Font("Dialog", 1, 10)); } } { ibuMethodPanel = new JPanel(); statusPanel.add(ibuMethodPanel); ibuMethodPanel.setBorder(BorderFactory .createBevelBorder(BevelBorder.LOWERED)); { ibuMethodLabel = new JLabel(); ibuMethodPanel.add(ibuMethodLabel); ibuMethodLabel.setText("IBU Method:"); ibuMethodLabel.setFont(new java.awt.Font("Dialog", 1, 10)); } } { alcMethodPanel = new JPanel(); statusPanel.add(alcMethodPanel); alcMethodPanel.setBorder(BorderFactory .createBevelBorder(BevelBorder.LOWERED)); { alcMethodLabel = new JLabel(); alcMethodPanel.add(alcMethodLabel); alcMethodLabel.setText("Alc Method:"); alcMethodLabel.setFont(new java.awt.Font("Dialog", 1, 10)); } } } } { jMenuBar1 = new JMenuBar(); setJMenuBar(jMenuBar1); { fileMenu = new JMenu(); jMenuBar1.add(fileMenu); fileMenu.setText("File"); { newFileMenuItem = new JMenuItem(); fileMenu.add(newFileMenuItem); newFileMenuItem.setText("New"); newFileMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // This is just a test right now to see that // stuff is changed. myRecipe = new Recipe(); myRecipe.setVersion(version); currentFile = null; attachRecipeData(); displayRecipe(); } }); } { openFileMenuItem = new JMenuItem(); fileMenu.add(openFileMenuItem); openFileMenuItem.setText("Open"); openFileMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_O, ActionEvent.CTRL_MASK)); openFileMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Show open dialog; this method does // not return until the dialog is closed String[] ext = {"xml", "qbrew", "rec"}; String desc = "StrangBrew and importable formats"; sbFileFilter openFileFilter = new sbFileFilter(ext, desc); // fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); fileChooser.setFileFilter(openFileFilter); int returnVal = fileChooser.showOpenDialog(jMenuBar1); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); Debug.print("Opening: " + file.getName() + ".\n"); OpenImport oi = new OpenImport(); myRecipe = oi.openFile(file); if (oi.getFileType().equals("")){ JOptionPane.showMessageDialog( null, "The file you've tried to open isn't a recognized format. \n" + "You can open: \n" + "StrangeBrew 1.x and Java files (.xml)\n" + "QBrew files (.qbrew)\n" + "BeerXML files (.xml)\n" + "Promash files (.rec)", "Unrecognized Format!", JOptionPane.INFORMATION_MESSAGE); } if (oi.getFileType().equals("beerxml")){ JOptionPane.showMessageDialog( null, "The file you've opened is in BeerXML format. It may contain \n" + "several recipes. Only the first recipe is opened. Use the Find \n" + "dialog to open other recipes in a BeerXML file.", "BeerXML!", JOptionPane.INFORMATION_MESSAGE); } myRecipe.setVersion(version); myRecipe.calcMaltTotals(); myRecipe.calcHopsTotals(); myRecipe.mash.calcMashSchedule(); checkIngredientsInDB(); attachRecipeData(); currentFile = file; displayRecipe(); } else { Debug.print("Open command cancelled by user.\n"); } } }); } { imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/find.gif"); icon = new ImageIcon(imgURL); findFileMenuItem = new JMenuItem("Find", icon); findFileMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_F, ActionEvent.CTRL_MASK)); fileMenu.add(findFileMenuItem); final JFrame owner = this; findFileMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // open the find dialog FindDialog fd = new FindDialog(owner); fd.setVisible(true); } }); } { imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/save.gif"); icon = new ImageIcon(imgURL); saveMenuItem = new JMenuItem("Save", icon); fileMenu.add(saveMenuItem); saveMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_S, ActionEvent.CTRL_MASK)); saveMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { int choice = 1; if (currentFile != null) { File file = currentFile; //This is where a real application would save the file. try { FileWriter out = new FileWriter(file); out.write(myRecipe.toXML()); out.close(); Debug.print("Saved: " + file.getAbsoluteFile()); currentFile = file; } catch (Exception e) { showError(e); } } // prompt to save if not already saved else { choice = JOptionPane.showConfirmDialog(null, "File not saved. Do you wish to save it?", "File note saved", JOptionPane.YES_NO_OPTION); } if (choice == 0) { // same as save as: saveAs(); } } }); } { imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/saveas.gif"); icon = new ImageIcon(imgURL); saveAsMenuItem = new JMenuItem("Save As ...", icon); fileMenu.add(saveAsMenuItem); saveAsMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // This is just a test right now to see that // stuff is changed. Debug.print(myRecipe.toXML()); saveAs(); } }); } { exportMenu = new JMenu(); fileMenu.add(exportMenu); exportMenu.setText("Export"); { exportHTMLmenu = new JMenuItem(); exportMenu.add(exportHTMLmenu); exportHTMLmenu.setText("HTML"); exportHTMLmenu.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Show save dialog; this method does // not return until the dialog is closed String[] ext = {"html", "htm"}; sbFileFilter saveFileFilter = new sbFileFilter(ext, "HTML"); fileChooser.setFileFilter(saveFileFilter); fileChooser.setSelectedFile(new File(myRecipe.getName() + ".html")); int returnVal = fileChooser.showSaveDialog(jMenuBar1); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); //This is where a real application would save the file. try { saveAsHTML(file, "ca/strangebrew/data/recipeToHtml.xslt"); } catch (Exception e) { showError(e); } } else { Debug.print("Save command cancelled by user.\n"); } } }); exportTextMenuItem = new JMenuItem(); exportMenu.add(exportTextMenuItem); exportTextMenuItem.setText("Text"); exportTextMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Show save dialog; this method does // not return until the dialog is closed String[] ext = {"txt"}; sbFileFilter saveFileFilter = new sbFileFilter(ext, "Text"); fileChooser.setFileFilter(saveFileFilter); fileChooser.setSelectedFile(new File(myRecipe.getName() + ".txt")); int returnVal = fileChooser.showSaveDialog(jMenuBar1); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); //This is where a real application would save the file. try { FileWriter out = new FileWriter(file); out.write(myRecipe.toText()); out.close(); } catch (Exception e) { showError(e); } } else { Debug.print("Export text command cancelled by user.\n"); } } }); } } { JMenuItem clipboardMenuItem = new JMenuItem("Copy to Clipboard"); fileMenu.add(clipboardMenuItem); clipboardMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Copy current recipe to clipboard Clipboard clipboard = getToolkit ().getSystemClipboard (); StringSelection s = new StringSelection(myRecipe.toText()); clipboard.setContents(s, s); } }); JMenuItem printMenuItem = new JMenuItem("Print..."); fileMenu.add(printMenuItem); final JFrame owner = this; printMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Copy current recipe to clipboard// save file as xml, then transform it to html File tmp = new File("tmp.html"); try { saveAsHTML(tmp, "ca/strangebrew/data/recipeToSimpleHtml.xslt"); HTMLViewer view = new HTMLViewer(owner, tmp.toURL()); view.setModal(true); view.setVisible(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } tmp.delete(); } }); } { jSeparator2 = new JSeparator(); fileMenu.add(jSeparator2); } { exitMenuItem = new JMenuItem(); fileMenu.add(exitMenuItem); exitMenuItem.setText("Exit"); exitMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_Q, ActionEvent.CTRL_MASK)); final JFrame owner = this; exitMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // exit program processWindowEvent(new WindowEvent(owner,WindowEvent.WINDOW_CLOSING)); System.exit(0); } }); } } { jMenu4 = new JMenu(); jMenuBar1.add(jMenu4); jMenu4.setText("Edit"); { final JFrame owner = this; editPrefsMenuItem = new JMenuItem(); jMenu4.add(editPrefsMenuItem); editPrefsMenuItem.setText("Preferences..."); editPrefsMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { PreferencesDialog d = new PreferencesDialog(owner, preferences); d.setVisible(true); } }); } { jSeparator1 = new JSeparator(); jMenu4.add(jSeparator1); } { deleteMenuItem = new JMenuItem(); jMenu4.add(deleteMenuItem); deleteMenuItem.setText("Delete"); deleteMenuItem.setEnabled(false); } } { mnuTools = new JMenu(); jMenuBar1.add(mnuTools); mnuTools.setText("Tools"); { final JFrame owner = this; JMenuItem scalRecipeMenuItem = new JMenuItem(); mnuTools.add(scalRecipeMenuItem); scalRecipeMenuItem.setText("Scale Recipe..."); scalRecipeMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_R, ActionEvent.CTRL_MASK)); scalRecipeMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { ScaleRecipeDialog scaleRecipe = new ScaleRecipeDialog(owner); scaleRecipe.setModal(true); scaleRecipe.setVisible(true); } }); JMenuItem maltPercentMenuItem = new JMenuItem(); mnuTools.add(maltPercentMenuItem); maltPercentMenuItem.setText("Malt Percent..."); maltPercentMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_M, ActionEvent.CTRL_MASK)); maltPercentMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { MaltPercentDialog maltPercent = new MaltPercentDialog(owner); maltPercent.setModal(true); maltPercent.setVisible(true); } }); } } { jMenu5 = new JMenu(); jMenuBar1.add(jMenu5); jMenu5.setText("Help"); { helpMenuItem = new JMenuItem(); jMenu5.add(helpMenuItem); helpMenuItem.setText("Help"); final JFrame owner = this; helpMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { URL help; try { help = new File(appRoot + "/help/index.html").toURL(); HTMLViewer view = new HTMLViewer(owner, help); view.setModal(true); view.setVisible(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); } { aboutMenuItem = new JMenuItem(); jMenu5.add(aboutMenuItem); aboutMenuItem.setText("About..."); final JFrame owner = this; aboutMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { aboutDlg = new AboutDialog(owner, version); aboutDlg.setVisible(true); } }); } } } } catch (Exception e) { e.printStackTrace(); } } |
txtDate = new JFormattedTextField(); | txtDate = new DatePicker(); | private void initGUI() { try { // restore the saved size and location: this.setSize(preferences.getIProperty("winWidth"), preferences.getIProperty("winHeight")); this.setLocation(preferences.getIProperty("winX"), preferences.getIProperty("winY")); imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/brew.gif"); icon = new ImageIcon(imgURL); this.setIconImage(icon.getImage()); this.setTitle("StrangeBrew " + version); this.addWindowListener(new WindowAdapter() { public void windowClosed(WindowEvent evt) { System.exit(1); } }); { pnlMain = new JPanel(); GridBagLayout jPanel2Layout = new GridBagLayout(); jPanel2Layout.columnWeights = new double[]{0.1}; jPanel2Layout.columnWidths = new int[]{7}; jPanel2Layout.rowWeights = new double[]{0.1, 0.1, 0.9, 0.1}; jPanel2Layout.rowHeights = new int[]{7, 7, 7, 7}; pnlMain.setLayout(jPanel2Layout); this.getContentPane().add(pnlMain, BorderLayout.CENTER); { jTabbedPane1 = new JTabbedPane(); pnlMain.add(jTabbedPane1, new GridBagConstraints(0, 1, 1, 1, 0.1, 0.1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); { pnlDetails = new JPanel(); GridBagLayout pnlDetailsLayout = new GridBagLayout(); pnlDetailsLayout.columnWeights = new double[]{0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1}; pnlDetailsLayout.columnWidths = new int[]{7, 7, 7, 7, 7, 7, 7, 7, 7, 7}; pnlDetailsLayout.rowWeights = new double[]{0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1}; pnlDetailsLayout.rowHeights = new int[]{7, 7, 7, 7, 7, 7, 7}; pnlDetails.setLayout(pnlDetailsLayout); jTabbedPane1.addTab("Details", null, pnlDetails, null); pnlDetails.setPreferredSize(new java.awt.Dimension(20, 16)); { lblBrewer = new JLabel(); pnlDetails.add(lblBrewer, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblBrewer.setText("Brewer:"); } { brewerNameText = new JTextField(); pnlDetails.add(brewerNameText, new GridBagConstraints(1, 0, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); brewerNameText.setPreferredSize(new java.awt.Dimension(69, 20)); brewerNameText.setText("Brewer"); } { lblDate = new JLabel(); pnlDetails.add(lblDate, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblDate.setText("Date:"); } { lblStyle = new JLabel(); pnlDetails.add(lblStyle, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblStyle.setText("Style:"); } { lblYeast = new JLabel(); pnlDetails.add(lblYeast, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblYeast.setText("Yeast:"); } { lblPreBoil = new JLabel(); pnlDetails.add(lblPreBoil, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblPreBoil.setText("Pre boil:"); } { lblPostBoil = new JLabel(); pnlDetails.add(lblPostBoil, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblPostBoil.setText("Post boil:"); } { lblEffic = new JLabel(); pnlDetails.add(lblEffic, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblEffic.setText("Effic:"); lblEffic.setPreferredSize(new java.awt.Dimension(31, 14)); } { lblAtten = new JLabel(); pnlDetails.add(lblAtten, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblAtten.setText("Atten:"); lblAtten.setPreferredSize(new java.awt.Dimension(34, 14)); } { lblOG = new JLabel(); pnlDetails.add(lblOG, new GridBagConstraints(5, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblOG.setText("OG:"); } { lblFG = new JLabel(); pnlDetails.add(lblFG, new GridBagConstraints(5, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblFG.setText("FG:"); } { lblIBU = new JLabel(); pnlDetails.add(lblIBU, new GridBagConstraints(7, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblIBU.setText("IBU:"); } { lblAlc = new JLabel(); pnlDetails.add(lblAlc, new GridBagConstraints(7, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblAlc.setText("%Alc:"); } { lblColour = new JLabel(); pnlDetails.add(lblColour, new GridBagConstraints(7, 2, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblColour.setText("Colour:"); } { txtDate = new JFormattedTextField(); pnlDetails.add(txtDate, new GridBagConstraints(1, 1, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); txtDate.setText("Date"); txtDate.setPreferredSize(new java.awt.Dimension(73, 20)); } { cmbStyleModel = new ComboModel(); cmbStyle = new JComboBox(); pnlDetails.add(cmbStyle, new GridBagConstraints(1, 2, 5, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cmbStyle.setModel(cmbStyleModel); cmbStyle.setMaximumSize(new java.awt.Dimension(100, 32767)); cmbStyle.setPreferredSize(new java.awt.Dimension(190, 20)); } { txtPreBoil = new JFormattedTextField(); pnlDetails.add(txtPreBoil, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); txtPreBoil.setText("Pre Boil"); txtPreBoil.setPreferredSize(new java.awt.Dimension(37, 20)); } { postBoilText = new JFormattedTextField(); pnlDetails.add(postBoilText, new GridBagConstraints(1, 5, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); postBoilText.setText("Post Boil"); postBoilText.setPreferredSize(new java.awt.Dimension(46, 20)); } { lblComments = new JLabel(); pnlDetails.add(lblComments, new GridBagConstraints(6, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblComments.setText("Comments:"); } { SpinnerNumberModel spnEfficModel = new SpinnerNumberModel(75.0, 0.0, 100.0, 1.0); spnEffic = new JSpinner(); pnlDetails.add(spnEffic, new GridBagConstraints(4, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnEffic.setModel(spnEfficModel); spnEffic.setMaximumSize(new java.awt.Dimension(70, 32767)); spnEffic.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { myRecipe.setEfficiency(Double.parseDouble(spnEffic.getValue() .toString())); displayRecipe(); } }); spnEffic.setEditor(new JSpinner.NumberEditor(spnEffic, "00.#")); spnEffic.getEditor().setPreferredSize(new java.awt.Dimension(28, 16)); spnEffic.setPreferredSize(new java.awt.Dimension(53, 18)); } { SpinnerNumberModel spnAttenModel = new SpinnerNumberModel(75.0, 0.0, 100.0, 1.0); spnAtten = new JSpinner(); pnlDetails.add(spnAtten, new GridBagConstraints(4, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnAtten.setModel(spnAttenModel); spnAtten.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { myRecipe.setAttenuation(Double.parseDouble(spnAtten.getValue() .toString())); displayRecipe(); } }); spnAtten.setEditor(new JSpinner.NumberEditor(spnAtten, "00.#")); spnAtten.setPreferredSize(new java.awt.Dimension(49, 20)); } { SpinnerNumberModel spnOgModel = new SpinnerNumberModel(1.000, 0.900, 2.000, 0.001); spnOG = new JSpinner(); pnlDetails.add(spnOG, new GridBagConstraints(6, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnOG.setModel(spnOgModel); spnOG.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { myRecipe.setEstOg(Double.parseDouble(spnOG.getValue() .toString())); displayRecipe(); } }); spnOG.setEditor(new JSpinner.NumberEditor(spnOG, "0.000")); spnOG.getEditor().setPreferredSize(new java.awt.Dimension(20, 16)); spnOG.setPreferredSize(new java.awt.Dimension(67, 18)); } { SpinnerNumberModel spnFgModel = new SpinnerNumberModel(1.000, 0.900, 2.000, 0.001); spnFG = new JSpinner(); pnlDetails.add(spnFG, new GridBagConstraints(6, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnFG.setModel(spnFgModel); spnFG.setEditor(new JSpinner.NumberEditor(spnFG, "0.000")); spnFG.setPreferredSize(new java.awt.Dimension(69, 20)); spnFG.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { // set the new FG, and update alc: myRecipe.setEstFg(Double.parseDouble(spnFG.getValue() .toString())); displayRecipe(); } }); } { lblIBUvalue = new JLabel(); pnlDetails.add(lblIBUvalue, new GridBagConstraints(8, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblIBUvalue.setText("IBUs"); } { lblColourValue = new JLabel(); pnlDetails.add(lblColourValue, new GridBagConstraints(8, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblColourValue.setText("Colour"); } { lblAlcValue = new JLabel(); pnlDetails.add(lblAlcValue, new GridBagConstraints(8, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblAlcValue.setText("Alc"); } { scpComments = new JScrollPane(); pnlDetails.add(scpComments, new GridBagConstraints(7, 4, 3, 2, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); { txtComments = new JTextArea(); scpComments.setViewportView(txtComments); txtComments.setText("Comments"); txtComments.setWrapStyleWord(true); // txtComments.setPreferredSize(new java.awt.Dimension(117, 42)); txtComments.setLineWrap(true); txtComments.setPreferredSize(new java.awt.Dimension(263, 40)); txtComments.addFocusListener(new FocusAdapter() { public void focusLost(FocusEvent evt) { if (!txtComments.getText().equals(myRecipe.getComments())) { myRecipe.setComments(txtComments.getText()); } } }); } } { cmbYeastModel = new ComboModel(); cmbYeast = new JComboBox(); pnlDetails.add(cmbYeast, new GridBagConstraints(1, 3, 5, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cmbYeast.setModel(cmbYeastModel); cmbYeast.setPreferredSize(new java.awt.Dimension(193, 20)); } { cmbSizeUnitsModel = new ComboModel(); cmbSizeUnits = new JComboBox(); pnlDetails.add(cmbSizeUnits, new GridBagConstraints(2, 4, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cmbSizeUnits.setModel(cmbSizeUnitsModel); } { lblSizeUnits = new JLabel(); pnlDetails.add(lblSizeUnits, new GridBagConstraints(2, 5, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); lblSizeUnits.setText("Size Units"); } { boilTimeLable = new JLabel(); pnlDetails.add(boilTimeLable, new GridBagConstraints(4, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); boilTimeLable.setText("Boil Min:"); } { evapLabel = new JLabel(); pnlDetails.add(evapLabel, new GridBagConstraints(4, 5, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); evapLabel.setText("Evap/hr:"); } { boilMinText = new JTextField(); pnlDetails.add(boilMinText, new GridBagConstraints(5, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); boilMinText.setText("60"); boilMinText.setPreferredSize(new java.awt.Dimension(22, 20)); } { evapText = new JTextField(); pnlDetails.add(evapText, new GridBagConstraints(5, 5, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); evapText.setText("4"); evapText.setPreferredSize(new java.awt.Dimension(23, 20)); } { alcMethodComboModel = new DefaultComboBoxModel(new String[]{"Volume", "Weight"}); alcMethodCombo = new JComboBox(alcMethodComboModel); pnlDetails.add(alcMethodCombo, new GridBagConstraints(9, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); alcMethodCombo.setPreferredSize(new java.awt.Dimension(58, 20)); } { ibuMethodComboModel = new DefaultComboBoxModel(new String[]{"Tinseth", "Garetz", "Rager"}); ibuMethodCombo = new JComboBox(ibuMethodComboModel); pnlDetails.add(ibuMethodCombo, new GridBagConstraints(9, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); ibuMethodCombo.setPreferredSize(new java.awt.Dimension(59, 20)); } { colourMethodComboModel = new DefaultComboBoxModel(new String[]{"SRM", "EBC"}); colourMethodCombo = new JComboBox(colourMethodComboModel); pnlDetails.add(colourMethodCombo, new GridBagConstraints(9, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); colourMethodCombo.setPreferredSize(new java.awt.Dimension(44, 20)); } ComboBoxModel evapMethodComboModel = new DefaultComboBoxModel(new String[] { "Constant", "Percent" }); { jPanel1 = new JPanel(); pnlMain.add(jPanel1, new GridBagConstraints( 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); FlowLayout jPanel1Layout = new FlowLayout(); jPanel1Layout.setAlignment(FlowLayout.LEFT); jPanel1.setLayout(jPanel1Layout); jToolBar1 = new JToolBar(); getContentPane().add(jToolBar1, BorderLayout.NORTH); jToolBar1.setFloatable(false); jToolBar1.setRollover(true); jButton1 = new JButton(); jToolBar1.add(jButton1); jButton1.setMnemonic(java.awt.event.KeyEvent.VK_S); jButton1.setIcon(new ImageIcon(getClass().getClassLoader().getResource( "ca/strangebrew/icons/save.gif"))); jButton1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { System.out.println("jButton1.actionPerformed, event=" + evt); //TODO add your code for jButton1.actionPerformed } }); jButton2 = new JButton(); jToolBar1.add(jButton2); jButton2.setIcon(new ImageIcon(getClass().getClassLoader().getResource( "ca/strangebrew/icons/find.gif"))); jButton2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { System.out.println("jButton2.actionPerformed, event=" + evt); //TODO add your code for jButton2.actionPerformed } }); { lblName = new JLabel(); jPanel1.add(lblName); lblName.setText("Name:"); } { txtName = new JTextField(); jPanel1.add(txtName); txtName.setText("Name"); txtName.setPreferredSize(new java.awt.Dimension(297, 20)); } } evapMethodCombo = new JComboBox(); pnlDetails.add(evapMethodCombo, new GridBagConstraints(6, 5, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); evapMethodCombo.setModel(evapMethodComboModel); evapMethodCombo.setPreferredSize(new java.awt.Dimension(64, 20)); colourPanel = new JPanel(); pnlDetails.add(colourPanel, new GridBagConstraints(9, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); colourPanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); } { SBNotifier sbn = new SBNotifier(); stylePanel = new StylePanel(sbn); jTabbedPane1.addTab("Style", null, stylePanel, null); miscPanel = new MiscPanel(myRecipe); jTabbedPane1.addTab("Misc", null, miscPanel, null); notesPanel = new NotesPanel(); jTabbedPane1.addTab("Notes", null, notesPanel, null); dilutionPanel = new DilutionPanel(); jTabbedPane1.addTab("Dilution", null, dilutionPanel, null); mashPanel = new MashPanel(myRecipe); jTabbedPane1.addTab("Mash", null, mashPanel, null); waterPanel = new WaterPanel(); jTabbedPane1.addTab("Water", null, waterPanel, null); costPanel = new CostPanel(); jTabbedPane1.addTab("Cost", null, costPanel, null); // SBNotifier sbn = new SBNotifier(); settingsPanel = new SettingsPanel(sbn); jTabbedPane1.addTab("Settings", null, settingsPanel, null); } } { pnlTables = new JPanel(); BoxLayout pnlMaltsLayout = new BoxLayout(pnlTables, javax.swing.BoxLayout.Y_AXIS); pnlMain.add(pnlTables, new GridBagConstraints(0, 2, 1, 1, 0.5, 0.5, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); pnlTables.setLayout(pnlMaltsLayout); { pnlMalt = new JPanel(); pnlTables.add(pnlMalt); BorderLayout pnlMaltLayout1 = new BorderLayout(); pnlMalt.setBorder(BorderFactory.createTitledBorder(new LineBorder( new java.awt.Color(0, 0, 0), 1, false), "Fermentables", TitledBorder.LEADING, TitledBorder.TOP, new java.awt.Font("Dialog", 1, 12), new java.awt.Color(51, 51, 51))); pnlMalt.setLayout(pnlMaltLayout1); { jScrollPane1 = new JScrollPane(); pnlMalt.add(jScrollPane1, BorderLayout.CENTER); { maltTableModel = new MaltTableModel(this); maltTable = new JTable() { public String getToolTipText(MouseEvent e) { java.awt.Point p = e.getPoint(); int rowIndex = rowAtPoint(p); return SBStringUtils.multiLineToolTip(40, maltTableModel .getDescriptionAt(rowIndex)); } }; jScrollPane1.setViewportView(maltTable); maltTable.setModel(maltTableModel); // maltTable.setAutoCreateColumnsFromModel(false); maltTable.getTableHeader().setReorderingAllowed(false); TableColumn maltColumn = maltTable.getColumnModel().getColumn(0); // set up malt list combo maltComboBox = new JComboBox(); cmbMaltModel = new ComboModel(); maltComboBox.setModel(cmbMaltModel); maltColumn.setCellEditor(new DefaultCellEditor(maltComboBox)); // set up malt units combo maltUnitsComboBox = new JComboBox(); cmbMaltUnitsModel = new ComboModel(); maltUnitsComboBox.setModel(cmbMaltUnitsModel); maltColumn = maltTable.getColumnModel().getColumn(2); maltColumn.setCellEditor(new DefaultCellEditor(maltUnitsComboBox)); } } { tblMaltTotalsModel = new DefaultTableModel(new String[][]{{""}}, new String[]{"Malt", "Amount", "Units", "Points", "Lov", "Cost/U", "%"}); tblMaltTotals = new JTable(); pnlMalt.add(tblMaltTotals, BorderLayout.SOUTH); tblMaltTotals.setModel(tblMaltTotalsModel); tblMaltTotals.getTableHeader().setEnabled(false); tblMaltTotals.setAutoCreateColumnsFromModel(false); // set up the units combobox maltTotalUnitsComboBox = new JComboBox(); maltTotalUnitsComboModel = new ComboModel(); maltTotalUnitsComboModel.setList(new Quantity().getListofUnits("weight")); maltTotalUnitsComboBox.setModel(maltTotalUnitsComboModel); TableColumn t = tblMaltTotals.getColumnModel().getColumn(2); t.setCellEditor(new DefaultCellEditor(maltTotalUnitsComboBox)); maltTotalUnitsComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { String u = (String) maltTotalUnitsComboModel.getSelectedItem(); if (myRecipe != null) { myRecipe.setMaltUnits(u); displayRecipe(); } } }); } } { pnlMaltButtons = new JPanel(); pnlTables.add(pnlMaltButtons); FlowLayout pnlMaltButtonsLayout = new FlowLayout(); pnlMaltButtonsLayout.setAlignment(FlowLayout.LEFT); pnlMaltButtonsLayout.setVgap(0); pnlMaltButtons.setLayout(pnlMaltButtonsLayout); pnlMaltButtons.setPreferredSize(new java.awt.Dimension(592, 27)); { tlbMalt = new JToolBar(); pnlMaltButtons.add(tlbMalt); tlbMalt.setPreferredSize(new java.awt.Dimension(55, 20)); tlbMalt.setFloatable(false); { btnAddMalt = new JButton(); tlbMalt.add(btnAddMalt); btnAddMalt.setText("+"); btnAddMalt.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { Fermentable f = new Fermentable(myRecipe.getMaltUnits()); myRecipe.addMalt(f); maltTable.updateUI(); displayRecipe(); } } }); } { btnDelMalt = new JButton(); tlbMalt.add(btnDelMalt); btnDelMalt.setText("-"); btnDelMalt.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { int i = maltTable.getSelectedRow(); myRecipe.delMalt(i); maltTable.updateUI(); displayRecipe(); } } }); } } } { pnlHops = new JPanel(); BorderLayout pnlHopsLayout = new BorderLayout(); pnlHops.setBorder(BorderFactory.createTitledBorder(new LineBorder( new java.awt.Color(0, 0, 0), 1, false), "Hops", TitledBorder.LEADING, TitledBorder.TOP, new java.awt.Font("Dialog", 1, 12), new java.awt.Color(51, 51, 51))); pnlHops.setLayout(pnlHopsLayout); pnlTables.add(pnlHops); { tblHopsTotalsModel = new DefaultTableModel(new String[][]{{""}}, new String[]{"1", "2", "3", "4", "5", "6", "7", "8", "9"}); tblHopsTotals = new JTable(); pnlHops.add(tblHopsTotals, BorderLayout.SOUTH); tblHopsTotals.setModel(tblHopsTotalsModel); tblHopsTotals.setAutoCreateColumnsFromModel(false); // set up the units combobox hopsTotalUnitsComboBox = new JComboBox(); hopsTotalUnitsComboModel = new ComboModel(); hopsTotalUnitsComboModel.setList(new Quantity().getListofUnits("weight")); hopsTotalUnitsComboBox.setModel(hopsTotalUnitsComboModel); TableColumn t = tblHopsTotals.getColumnModel().getColumn(4); t.setCellEditor(new DefaultCellEditor(hopsTotalUnitsComboBox)); hopsTotalUnitsComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { String u = (String) hopsTotalUnitsComboModel.getSelectedItem(); if (myRecipe != null) { myRecipe.setHopsUnits(u); displayRecipe(); } } }); } { jScrollPane2 = new JScrollPane(); pnlHops.add(jScrollPane2, BorderLayout.CENTER); { hopsTableModel = new HopsTableModel(this); hopsTable = new JTable() { public String getToolTipText(MouseEvent e) { java.awt.Point p = e.getPoint(); int rowIndex = rowAtPoint(p); return SBStringUtils.multiLineToolTip(40, hopsTableModel .getDescriptionAt(rowIndex)); } }; jScrollPane2.setViewportView(hopsTable); hopsTable.setModel(hopsTableModel); hopsTable.getTableHeader().setReorderingAllowed(false); TableColumn hopColumn = hopsTable.getColumnModel().getColumn(0); hopComboBox = new JComboBox(); cmbHopsModel = new ComboModel(); hopComboBox.setModel(cmbHopsModel); hopColumn.setCellEditor(new DefaultCellEditor(hopComboBox)); // set up hop units combo hopsUnitsComboBox = new JComboBox(); cmbHopsUnitsModel = new ComboModel(); hopsUnitsComboBox.setModel(cmbHopsUnitsModel); hopColumn = hopsTable.getColumnModel().getColumn(4); hopColumn.setCellEditor(new DefaultCellEditor(hopsUnitsComboBox)); // set up hop type combo String[] forms = {"Leaf", "Pellet", "Plug"}; JComboBox hopsFormComboBox = new JComboBox(forms); hopColumn = hopsTable.getColumnModel().getColumn(1); hopColumn.setCellEditor(new DefaultCellEditor(hopsFormComboBox)); // set up hop add combo String[] add = {"Boil", "FWH", "Dry", "Mash"}; JComboBox hopsAddComboBox = new JComboBox(add); hopColumn = hopsTable.getColumnModel().getColumn(5); hopColumn.setCellEditor(new DefaultCellEditor(hopsAddComboBox)); } } } { pnlHopsButtons = new JPanel(); FlowLayout pnlHopsButtonsLayout = new FlowLayout(); pnlHopsButtonsLayout.setAlignment(FlowLayout.LEFT); pnlHopsButtonsLayout.setVgap(0); pnlHopsButtons.setLayout(pnlHopsButtonsLayout); pnlTables.add(pnlHopsButtons); pnlHopsButtons.setPreferredSize(new java.awt.Dimension(512, 16)); { tlbHops = new JToolBar(); pnlHopsButtons.add(tlbHops); tlbHops.setPreferredSize(new java.awt.Dimension(58, 19)); tlbHops.setFloatable(false); { btnAddHop = new JButton(); tlbHops.add(btnAddHop); btnAddHop.setText("+"); btnAddHop.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { Hop h = new Hop(myRecipe.getHopUnits()); myRecipe.addHop(h); hopsTable.updateUI(); displayRecipe(); } } }); } { btnDelHop = new JButton(); tlbHops.add(btnDelHop); btnDelHop.setText("-"); btnDelHop.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { int i = hopsTable.getSelectedRow(); myRecipe.delHop(i); hopsTable.updateUI(); displayRecipe(); } } }); } } } } { statusPanel = new JPanel(); FlowLayout statusPanelLayout = new FlowLayout(); statusPanelLayout.setAlignment(FlowLayout.LEFT); statusPanelLayout.setHgap(2); statusPanelLayout.setVgap(2); statusPanel.setLayout(statusPanelLayout); pnlMain.add(statusPanel, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); { fileNamePanel = new JPanel(); statusPanel.add(fileNamePanel); fileNamePanel.setBorder(BorderFactory .createBevelBorder(BevelBorder.LOWERED)); { fileNameLabel = new JLabel(); fileNamePanel.add(fileNameLabel); fileNameLabel.setText("File Name"); fileNameLabel.setFont(new java.awt.Font("Dialog", 1, 10)); } } { ibuMethodPanel = new JPanel(); statusPanel.add(ibuMethodPanel); ibuMethodPanel.setBorder(BorderFactory .createBevelBorder(BevelBorder.LOWERED)); { ibuMethodLabel = new JLabel(); ibuMethodPanel.add(ibuMethodLabel); ibuMethodLabel.setText("IBU Method:"); ibuMethodLabel.setFont(new java.awt.Font("Dialog", 1, 10)); } } { alcMethodPanel = new JPanel(); statusPanel.add(alcMethodPanel); alcMethodPanel.setBorder(BorderFactory .createBevelBorder(BevelBorder.LOWERED)); { alcMethodLabel = new JLabel(); alcMethodPanel.add(alcMethodLabel); alcMethodLabel.setText("Alc Method:"); alcMethodLabel.setFont(new java.awt.Font("Dialog", 1, 10)); } } } } { jMenuBar1 = new JMenuBar(); setJMenuBar(jMenuBar1); { fileMenu = new JMenu(); jMenuBar1.add(fileMenu); fileMenu.setText("File"); { newFileMenuItem = new JMenuItem(); fileMenu.add(newFileMenuItem); newFileMenuItem.setText("New"); newFileMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // This is just a test right now to see that // stuff is changed. myRecipe = new Recipe(); myRecipe.setVersion(version); currentFile = null; attachRecipeData(); displayRecipe(); } }); } { openFileMenuItem = new JMenuItem(); fileMenu.add(openFileMenuItem); openFileMenuItem.setText("Open"); openFileMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_O, ActionEvent.CTRL_MASK)); openFileMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Show open dialog; this method does // not return until the dialog is closed String[] ext = {"xml", "qbrew", "rec"}; String desc = "StrangBrew and importable formats"; sbFileFilter openFileFilter = new sbFileFilter(ext, desc); // fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); fileChooser.setFileFilter(openFileFilter); int returnVal = fileChooser.showOpenDialog(jMenuBar1); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); Debug.print("Opening: " + file.getName() + ".\n"); OpenImport oi = new OpenImport(); myRecipe = oi.openFile(file); if (oi.getFileType().equals("")){ JOptionPane.showMessageDialog( null, "The file you've tried to open isn't a recognized format. \n" + "You can open: \n" + "StrangeBrew 1.x and Java files (.xml)\n" + "QBrew files (.qbrew)\n" + "BeerXML files (.xml)\n" + "Promash files (.rec)", "Unrecognized Format!", JOptionPane.INFORMATION_MESSAGE); } if (oi.getFileType().equals("beerxml")){ JOptionPane.showMessageDialog( null, "The file you've opened is in BeerXML format. It may contain \n" + "several recipes. Only the first recipe is opened. Use the Find \n" + "dialog to open other recipes in a BeerXML file.", "BeerXML!", JOptionPane.INFORMATION_MESSAGE); } myRecipe.setVersion(version); myRecipe.calcMaltTotals(); myRecipe.calcHopsTotals(); myRecipe.mash.calcMashSchedule(); checkIngredientsInDB(); attachRecipeData(); currentFile = file; displayRecipe(); } else { Debug.print("Open command cancelled by user.\n"); } } }); } { imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/find.gif"); icon = new ImageIcon(imgURL); findFileMenuItem = new JMenuItem("Find", icon); findFileMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_F, ActionEvent.CTRL_MASK)); fileMenu.add(findFileMenuItem); final JFrame owner = this; findFileMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // open the find dialog FindDialog fd = new FindDialog(owner); fd.setVisible(true); } }); } { imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/save.gif"); icon = new ImageIcon(imgURL); saveMenuItem = new JMenuItem("Save", icon); fileMenu.add(saveMenuItem); saveMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_S, ActionEvent.CTRL_MASK)); saveMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { int choice = 1; if (currentFile != null) { File file = currentFile; //This is where a real application would save the file. try { FileWriter out = new FileWriter(file); out.write(myRecipe.toXML()); out.close(); Debug.print("Saved: " + file.getAbsoluteFile()); currentFile = file; } catch (Exception e) { showError(e); } } // prompt to save if not already saved else { choice = JOptionPane.showConfirmDialog(null, "File not saved. Do you wish to save it?", "File note saved", JOptionPane.YES_NO_OPTION); } if (choice == 0) { // same as save as: saveAs(); } } }); } { imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/saveas.gif"); icon = new ImageIcon(imgURL); saveAsMenuItem = new JMenuItem("Save As ...", icon); fileMenu.add(saveAsMenuItem); saveAsMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // This is just a test right now to see that // stuff is changed. Debug.print(myRecipe.toXML()); saveAs(); } }); } { exportMenu = new JMenu(); fileMenu.add(exportMenu); exportMenu.setText("Export"); { exportHTMLmenu = new JMenuItem(); exportMenu.add(exportHTMLmenu); exportHTMLmenu.setText("HTML"); exportHTMLmenu.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Show save dialog; this method does // not return until the dialog is closed String[] ext = {"html", "htm"}; sbFileFilter saveFileFilter = new sbFileFilter(ext, "HTML"); fileChooser.setFileFilter(saveFileFilter); fileChooser.setSelectedFile(new File(myRecipe.getName() + ".html")); int returnVal = fileChooser.showSaveDialog(jMenuBar1); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); //This is where a real application would save the file. try { saveAsHTML(file, "ca/strangebrew/data/recipeToHtml.xslt"); } catch (Exception e) { showError(e); } } else { Debug.print("Save command cancelled by user.\n"); } } }); exportTextMenuItem = new JMenuItem(); exportMenu.add(exportTextMenuItem); exportTextMenuItem.setText("Text"); exportTextMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Show save dialog; this method does // not return until the dialog is closed String[] ext = {"txt"}; sbFileFilter saveFileFilter = new sbFileFilter(ext, "Text"); fileChooser.setFileFilter(saveFileFilter); fileChooser.setSelectedFile(new File(myRecipe.getName() + ".txt")); int returnVal = fileChooser.showSaveDialog(jMenuBar1); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); //This is where a real application would save the file. try { FileWriter out = new FileWriter(file); out.write(myRecipe.toText()); out.close(); } catch (Exception e) { showError(e); } } else { Debug.print("Export text command cancelled by user.\n"); } } }); } } { JMenuItem clipboardMenuItem = new JMenuItem("Copy to Clipboard"); fileMenu.add(clipboardMenuItem); clipboardMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Copy current recipe to clipboard Clipboard clipboard = getToolkit ().getSystemClipboard (); StringSelection s = new StringSelection(myRecipe.toText()); clipboard.setContents(s, s); } }); JMenuItem printMenuItem = new JMenuItem("Print..."); fileMenu.add(printMenuItem); final JFrame owner = this; printMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Copy current recipe to clipboard// save file as xml, then transform it to html File tmp = new File("tmp.html"); try { saveAsHTML(tmp, "ca/strangebrew/data/recipeToSimpleHtml.xslt"); HTMLViewer view = new HTMLViewer(owner, tmp.toURL()); view.setModal(true); view.setVisible(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } tmp.delete(); } }); } { jSeparator2 = new JSeparator(); fileMenu.add(jSeparator2); } { exitMenuItem = new JMenuItem(); fileMenu.add(exitMenuItem); exitMenuItem.setText("Exit"); exitMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_Q, ActionEvent.CTRL_MASK)); final JFrame owner = this; exitMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // exit program processWindowEvent(new WindowEvent(owner,WindowEvent.WINDOW_CLOSING)); System.exit(0); } }); } } { jMenu4 = new JMenu(); jMenuBar1.add(jMenu4); jMenu4.setText("Edit"); { final JFrame owner = this; editPrefsMenuItem = new JMenuItem(); jMenu4.add(editPrefsMenuItem); editPrefsMenuItem.setText("Preferences..."); editPrefsMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { PreferencesDialog d = new PreferencesDialog(owner, preferences); d.setVisible(true); } }); } { jSeparator1 = new JSeparator(); jMenu4.add(jSeparator1); } { deleteMenuItem = new JMenuItem(); jMenu4.add(deleteMenuItem); deleteMenuItem.setText("Delete"); deleteMenuItem.setEnabled(false); } } { mnuTools = new JMenu(); jMenuBar1.add(mnuTools); mnuTools.setText("Tools"); { final JFrame owner = this; JMenuItem scalRecipeMenuItem = new JMenuItem(); mnuTools.add(scalRecipeMenuItem); scalRecipeMenuItem.setText("Scale Recipe..."); scalRecipeMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_R, ActionEvent.CTRL_MASK)); scalRecipeMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { ScaleRecipeDialog scaleRecipe = new ScaleRecipeDialog(owner); scaleRecipe.setModal(true); scaleRecipe.setVisible(true); } }); JMenuItem maltPercentMenuItem = new JMenuItem(); mnuTools.add(maltPercentMenuItem); maltPercentMenuItem.setText("Malt Percent..."); maltPercentMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_M, ActionEvent.CTRL_MASK)); maltPercentMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { MaltPercentDialog maltPercent = new MaltPercentDialog(owner); maltPercent.setModal(true); maltPercent.setVisible(true); } }); } } { jMenu5 = new JMenu(); jMenuBar1.add(jMenu5); jMenu5.setText("Help"); { helpMenuItem = new JMenuItem(); jMenu5.add(helpMenuItem); helpMenuItem.setText("Help"); final JFrame owner = this; helpMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { URL help; try { help = new File(appRoot + "/help/index.html").toURL(); HTMLViewer view = new HTMLViewer(owner, help); view.setModal(true); view.setVisible(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); } { aboutMenuItem = new JMenuItem(); jMenu5.add(aboutMenuItem); aboutMenuItem.setText("About..."); final JFrame owner = this; aboutMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { aboutDlg = new AboutDialog(owner, version); aboutDlg.setVisible(true); } }); } } } } catch (Exception e) { e.printStackTrace(); } } |
txtDate.setText("Date"); | private void initGUI() { try { // restore the saved size and location: this.setSize(preferences.getIProperty("winWidth"), preferences.getIProperty("winHeight")); this.setLocation(preferences.getIProperty("winX"), preferences.getIProperty("winY")); imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/brew.gif"); icon = new ImageIcon(imgURL); this.setIconImage(icon.getImage()); this.setTitle("StrangeBrew " + version); this.addWindowListener(new WindowAdapter() { public void windowClosed(WindowEvent evt) { System.exit(1); } }); { pnlMain = new JPanel(); GridBagLayout jPanel2Layout = new GridBagLayout(); jPanel2Layout.columnWeights = new double[]{0.1}; jPanel2Layout.columnWidths = new int[]{7}; jPanel2Layout.rowWeights = new double[]{0.1, 0.1, 0.9, 0.1}; jPanel2Layout.rowHeights = new int[]{7, 7, 7, 7}; pnlMain.setLayout(jPanel2Layout); this.getContentPane().add(pnlMain, BorderLayout.CENTER); { jTabbedPane1 = new JTabbedPane(); pnlMain.add(jTabbedPane1, new GridBagConstraints(0, 1, 1, 1, 0.1, 0.1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); { pnlDetails = new JPanel(); GridBagLayout pnlDetailsLayout = new GridBagLayout(); pnlDetailsLayout.columnWeights = new double[]{0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1}; pnlDetailsLayout.columnWidths = new int[]{7, 7, 7, 7, 7, 7, 7, 7, 7, 7}; pnlDetailsLayout.rowWeights = new double[]{0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1}; pnlDetailsLayout.rowHeights = new int[]{7, 7, 7, 7, 7, 7, 7}; pnlDetails.setLayout(pnlDetailsLayout); jTabbedPane1.addTab("Details", null, pnlDetails, null); pnlDetails.setPreferredSize(new java.awt.Dimension(20, 16)); { lblBrewer = new JLabel(); pnlDetails.add(lblBrewer, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblBrewer.setText("Brewer:"); } { brewerNameText = new JTextField(); pnlDetails.add(brewerNameText, new GridBagConstraints(1, 0, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); brewerNameText.setPreferredSize(new java.awt.Dimension(69, 20)); brewerNameText.setText("Brewer"); } { lblDate = new JLabel(); pnlDetails.add(lblDate, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblDate.setText("Date:"); } { lblStyle = new JLabel(); pnlDetails.add(lblStyle, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblStyle.setText("Style:"); } { lblYeast = new JLabel(); pnlDetails.add(lblYeast, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblYeast.setText("Yeast:"); } { lblPreBoil = new JLabel(); pnlDetails.add(lblPreBoil, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblPreBoil.setText("Pre boil:"); } { lblPostBoil = new JLabel(); pnlDetails.add(lblPostBoil, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblPostBoil.setText("Post boil:"); } { lblEffic = new JLabel(); pnlDetails.add(lblEffic, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblEffic.setText("Effic:"); lblEffic.setPreferredSize(new java.awt.Dimension(31, 14)); } { lblAtten = new JLabel(); pnlDetails.add(lblAtten, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblAtten.setText("Atten:"); lblAtten.setPreferredSize(new java.awt.Dimension(34, 14)); } { lblOG = new JLabel(); pnlDetails.add(lblOG, new GridBagConstraints(5, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblOG.setText("OG:"); } { lblFG = new JLabel(); pnlDetails.add(lblFG, new GridBagConstraints(5, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblFG.setText("FG:"); } { lblIBU = new JLabel(); pnlDetails.add(lblIBU, new GridBagConstraints(7, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblIBU.setText("IBU:"); } { lblAlc = new JLabel(); pnlDetails.add(lblAlc, new GridBagConstraints(7, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblAlc.setText("%Alc:"); } { lblColour = new JLabel(); pnlDetails.add(lblColour, new GridBagConstraints(7, 2, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblColour.setText("Colour:"); } { txtDate = new JFormattedTextField(); pnlDetails.add(txtDate, new GridBagConstraints(1, 1, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); txtDate.setText("Date"); txtDate.setPreferredSize(new java.awt.Dimension(73, 20)); } { cmbStyleModel = new ComboModel(); cmbStyle = new JComboBox(); pnlDetails.add(cmbStyle, new GridBagConstraints(1, 2, 5, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cmbStyle.setModel(cmbStyleModel); cmbStyle.setMaximumSize(new java.awt.Dimension(100, 32767)); cmbStyle.setPreferredSize(new java.awt.Dimension(190, 20)); } { txtPreBoil = new JFormattedTextField(); pnlDetails.add(txtPreBoil, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); txtPreBoil.setText("Pre Boil"); txtPreBoil.setPreferredSize(new java.awt.Dimension(37, 20)); } { postBoilText = new JFormattedTextField(); pnlDetails.add(postBoilText, new GridBagConstraints(1, 5, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); postBoilText.setText("Post Boil"); postBoilText.setPreferredSize(new java.awt.Dimension(46, 20)); } { lblComments = new JLabel(); pnlDetails.add(lblComments, new GridBagConstraints(6, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblComments.setText("Comments:"); } { SpinnerNumberModel spnEfficModel = new SpinnerNumberModel(75.0, 0.0, 100.0, 1.0); spnEffic = new JSpinner(); pnlDetails.add(spnEffic, new GridBagConstraints(4, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnEffic.setModel(spnEfficModel); spnEffic.setMaximumSize(new java.awt.Dimension(70, 32767)); spnEffic.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { myRecipe.setEfficiency(Double.parseDouble(spnEffic.getValue() .toString())); displayRecipe(); } }); spnEffic.setEditor(new JSpinner.NumberEditor(spnEffic, "00.#")); spnEffic.getEditor().setPreferredSize(new java.awt.Dimension(28, 16)); spnEffic.setPreferredSize(new java.awt.Dimension(53, 18)); } { SpinnerNumberModel spnAttenModel = new SpinnerNumberModel(75.0, 0.0, 100.0, 1.0); spnAtten = new JSpinner(); pnlDetails.add(spnAtten, new GridBagConstraints(4, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnAtten.setModel(spnAttenModel); spnAtten.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { myRecipe.setAttenuation(Double.parseDouble(spnAtten.getValue() .toString())); displayRecipe(); } }); spnAtten.setEditor(new JSpinner.NumberEditor(spnAtten, "00.#")); spnAtten.setPreferredSize(new java.awt.Dimension(49, 20)); } { SpinnerNumberModel spnOgModel = new SpinnerNumberModel(1.000, 0.900, 2.000, 0.001); spnOG = new JSpinner(); pnlDetails.add(spnOG, new GridBagConstraints(6, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnOG.setModel(spnOgModel); spnOG.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { myRecipe.setEstOg(Double.parseDouble(spnOG.getValue() .toString())); displayRecipe(); } }); spnOG.setEditor(new JSpinner.NumberEditor(spnOG, "0.000")); spnOG.getEditor().setPreferredSize(new java.awt.Dimension(20, 16)); spnOG.setPreferredSize(new java.awt.Dimension(67, 18)); } { SpinnerNumberModel spnFgModel = new SpinnerNumberModel(1.000, 0.900, 2.000, 0.001); spnFG = new JSpinner(); pnlDetails.add(spnFG, new GridBagConstraints(6, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnFG.setModel(spnFgModel); spnFG.setEditor(new JSpinner.NumberEditor(spnFG, "0.000")); spnFG.setPreferredSize(new java.awt.Dimension(69, 20)); spnFG.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { // set the new FG, and update alc: myRecipe.setEstFg(Double.parseDouble(spnFG.getValue() .toString())); displayRecipe(); } }); } { lblIBUvalue = new JLabel(); pnlDetails.add(lblIBUvalue, new GridBagConstraints(8, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblIBUvalue.setText("IBUs"); } { lblColourValue = new JLabel(); pnlDetails.add(lblColourValue, new GridBagConstraints(8, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblColourValue.setText("Colour"); } { lblAlcValue = new JLabel(); pnlDetails.add(lblAlcValue, new GridBagConstraints(8, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblAlcValue.setText("Alc"); } { scpComments = new JScrollPane(); pnlDetails.add(scpComments, new GridBagConstraints(7, 4, 3, 2, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); { txtComments = new JTextArea(); scpComments.setViewportView(txtComments); txtComments.setText("Comments"); txtComments.setWrapStyleWord(true); // txtComments.setPreferredSize(new java.awt.Dimension(117, 42)); txtComments.setLineWrap(true); txtComments.setPreferredSize(new java.awt.Dimension(263, 40)); txtComments.addFocusListener(new FocusAdapter() { public void focusLost(FocusEvent evt) { if (!txtComments.getText().equals(myRecipe.getComments())) { myRecipe.setComments(txtComments.getText()); } } }); } } { cmbYeastModel = new ComboModel(); cmbYeast = new JComboBox(); pnlDetails.add(cmbYeast, new GridBagConstraints(1, 3, 5, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cmbYeast.setModel(cmbYeastModel); cmbYeast.setPreferredSize(new java.awt.Dimension(193, 20)); } { cmbSizeUnitsModel = new ComboModel(); cmbSizeUnits = new JComboBox(); pnlDetails.add(cmbSizeUnits, new GridBagConstraints(2, 4, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cmbSizeUnits.setModel(cmbSizeUnitsModel); } { lblSizeUnits = new JLabel(); pnlDetails.add(lblSizeUnits, new GridBagConstraints(2, 5, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); lblSizeUnits.setText("Size Units"); } { boilTimeLable = new JLabel(); pnlDetails.add(boilTimeLable, new GridBagConstraints(4, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); boilTimeLable.setText("Boil Min:"); } { evapLabel = new JLabel(); pnlDetails.add(evapLabel, new GridBagConstraints(4, 5, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); evapLabel.setText("Evap/hr:"); } { boilMinText = new JTextField(); pnlDetails.add(boilMinText, new GridBagConstraints(5, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); boilMinText.setText("60"); boilMinText.setPreferredSize(new java.awt.Dimension(22, 20)); } { evapText = new JTextField(); pnlDetails.add(evapText, new GridBagConstraints(5, 5, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); evapText.setText("4"); evapText.setPreferredSize(new java.awt.Dimension(23, 20)); } { alcMethodComboModel = new DefaultComboBoxModel(new String[]{"Volume", "Weight"}); alcMethodCombo = new JComboBox(alcMethodComboModel); pnlDetails.add(alcMethodCombo, new GridBagConstraints(9, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); alcMethodCombo.setPreferredSize(new java.awt.Dimension(58, 20)); } { ibuMethodComboModel = new DefaultComboBoxModel(new String[]{"Tinseth", "Garetz", "Rager"}); ibuMethodCombo = new JComboBox(ibuMethodComboModel); pnlDetails.add(ibuMethodCombo, new GridBagConstraints(9, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); ibuMethodCombo.setPreferredSize(new java.awt.Dimension(59, 20)); } { colourMethodComboModel = new DefaultComboBoxModel(new String[]{"SRM", "EBC"}); colourMethodCombo = new JComboBox(colourMethodComboModel); pnlDetails.add(colourMethodCombo, new GridBagConstraints(9, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); colourMethodCombo.setPreferredSize(new java.awt.Dimension(44, 20)); } ComboBoxModel evapMethodComboModel = new DefaultComboBoxModel(new String[] { "Constant", "Percent" }); { jPanel1 = new JPanel(); pnlMain.add(jPanel1, new GridBagConstraints( 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); FlowLayout jPanel1Layout = new FlowLayout(); jPanel1Layout.setAlignment(FlowLayout.LEFT); jPanel1.setLayout(jPanel1Layout); jToolBar1 = new JToolBar(); getContentPane().add(jToolBar1, BorderLayout.NORTH); jToolBar1.setFloatable(false); jToolBar1.setRollover(true); jButton1 = new JButton(); jToolBar1.add(jButton1); jButton1.setMnemonic(java.awt.event.KeyEvent.VK_S); jButton1.setIcon(new ImageIcon(getClass().getClassLoader().getResource( "ca/strangebrew/icons/save.gif"))); jButton1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { System.out.println("jButton1.actionPerformed, event=" + evt); //TODO add your code for jButton1.actionPerformed } }); jButton2 = new JButton(); jToolBar1.add(jButton2); jButton2.setIcon(new ImageIcon(getClass().getClassLoader().getResource( "ca/strangebrew/icons/find.gif"))); jButton2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { System.out.println("jButton2.actionPerformed, event=" + evt); //TODO add your code for jButton2.actionPerformed } }); { lblName = new JLabel(); jPanel1.add(lblName); lblName.setText("Name:"); } { txtName = new JTextField(); jPanel1.add(txtName); txtName.setText("Name"); txtName.setPreferredSize(new java.awt.Dimension(297, 20)); } } evapMethodCombo = new JComboBox(); pnlDetails.add(evapMethodCombo, new GridBagConstraints(6, 5, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); evapMethodCombo.setModel(evapMethodComboModel); evapMethodCombo.setPreferredSize(new java.awt.Dimension(64, 20)); colourPanel = new JPanel(); pnlDetails.add(colourPanel, new GridBagConstraints(9, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); colourPanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); } { SBNotifier sbn = new SBNotifier(); stylePanel = new StylePanel(sbn); jTabbedPane1.addTab("Style", null, stylePanel, null); miscPanel = new MiscPanel(myRecipe); jTabbedPane1.addTab("Misc", null, miscPanel, null); notesPanel = new NotesPanel(); jTabbedPane1.addTab("Notes", null, notesPanel, null); dilutionPanel = new DilutionPanel(); jTabbedPane1.addTab("Dilution", null, dilutionPanel, null); mashPanel = new MashPanel(myRecipe); jTabbedPane1.addTab("Mash", null, mashPanel, null); waterPanel = new WaterPanel(); jTabbedPane1.addTab("Water", null, waterPanel, null); costPanel = new CostPanel(); jTabbedPane1.addTab("Cost", null, costPanel, null); // SBNotifier sbn = new SBNotifier(); settingsPanel = new SettingsPanel(sbn); jTabbedPane1.addTab("Settings", null, settingsPanel, null); } } { pnlTables = new JPanel(); BoxLayout pnlMaltsLayout = new BoxLayout(pnlTables, javax.swing.BoxLayout.Y_AXIS); pnlMain.add(pnlTables, new GridBagConstraints(0, 2, 1, 1, 0.5, 0.5, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); pnlTables.setLayout(pnlMaltsLayout); { pnlMalt = new JPanel(); pnlTables.add(pnlMalt); BorderLayout pnlMaltLayout1 = new BorderLayout(); pnlMalt.setBorder(BorderFactory.createTitledBorder(new LineBorder( new java.awt.Color(0, 0, 0), 1, false), "Fermentables", TitledBorder.LEADING, TitledBorder.TOP, new java.awt.Font("Dialog", 1, 12), new java.awt.Color(51, 51, 51))); pnlMalt.setLayout(pnlMaltLayout1); { jScrollPane1 = new JScrollPane(); pnlMalt.add(jScrollPane1, BorderLayout.CENTER); { maltTableModel = new MaltTableModel(this); maltTable = new JTable() { public String getToolTipText(MouseEvent e) { java.awt.Point p = e.getPoint(); int rowIndex = rowAtPoint(p); return SBStringUtils.multiLineToolTip(40, maltTableModel .getDescriptionAt(rowIndex)); } }; jScrollPane1.setViewportView(maltTable); maltTable.setModel(maltTableModel); // maltTable.setAutoCreateColumnsFromModel(false); maltTable.getTableHeader().setReorderingAllowed(false); TableColumn maltColumn = maltTable.getColumnModel().getColumn(0); // set up malt list combo maltComboBox = new JComboBox(); cmbMaltModel = new ComboModel(); maltComboBox.setModel(cmbMaltModel); maltColumn.setCellEditor(new DefaultCellEditor(maltComboBox)); // set up malt units combo maltUnitsComboBox = new JComboBox(); cmbMaltUnitsModel = new ComboModel(); maltUnitsComboBox.setModel(cmbMaltUnitsModel); maltColumn = maltTable.getColumnModel().getColumn(2); maltColumn.setCellEditor(new DefaultCellEditor(maltUnitsComboBox)); } } { tblMaltTotalsModel = new DefaultTableModel(new String[][]{{""}}, new String[]{"Malt", "Amount", "Units", "Points", "Lov", "Cost/U", "%"}); tblMaltTotals = new JTable(); pnlMalt.add(tblMaltTotals, BorderLayout.SOUTH); tblMaltTotals.setModel(tblMaltTotalsModel); tblMaltTotals.getTableHeader().setEnabled(false); tblMaltTotals.setAutoCreateColumnsFromModel(false); // set up the units combobox maltTotalUnitsComboBox = new JComboBox(); maltTotalUnitsComboModel = new ComboModel(); maltTotalUnitsComboModel.setList(new Quantity().getListofUnits("weight")); maltTotalUnitsComboBox.setModel(maltTotalUnitsComboModel); TableColumn t = tblMaltTotals.getColumnModel().getColumn(2); t.setCellEditor(new DefaultCellEditor(maltTotalUnitsComboBox)); maltTotalUnitsComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { String u = (String) maltTotalUnitsComboModel.getSelectedItem(); if (myRecipe != null) { myRecipe.setMaltUnits(u); displayRecipe(); } } }); } } { pnlMaltButtons = new JPanel(); pnlTables.add(pnlMaltButtons); FlowLayout pnlMaltButtonsLayout = new FlowLayout(); pnlMaltButtonsLayout.setAlignment(FlowLayout.LEFT); pnlMaltButtonsLayout.setVgap(0); pnlMaltButtons.setLayout(pnlMaltButtonsLayout); pnlMaltButtons.setPreferredSize(new java.awt.Dimension(592, 27)); { tlbMalt = new JToolBar(); pnlMaltButtons.add(tlbMalt); tlbMalt.setPreferredSize(new java.awt.Dimension(55, 20)); tlbMalt.setFloatable(false); { btnAddMalt = new JButton(); tlbMalt.add(btnAddMalt); btnAddMalt.setText("+"); btnAddMalt.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { Fermentable f = new Fermentable(myRecipe.getMaltUnits()); myRecipe.addMalt(f); maltTable.updateUI(); displayRecipe(); } } }); } { btnDelMalt = new JButton(); tlbMalt.add(btnDelMalt); btnDelMalt.setText("-"); btnDelMalt.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { int i = maltTable.getSelectedRow(); myRecipe.delMalt(i); maltTable.updateUI(); displayRecipe(); } } }); } } } { pnlHops = new JPanel(); BorderLayout pnlHopsLayout = new BorderLayout(); pnlHops.setBorder(BorderFactory.createTitledBorder(new LineBorder( new java.awt.Color(0, 0, 0), 1, false), "Hops", TitledBorder.LEADING, TitledBorder.TOP, new java.awt.Font("Dialog", 1, 12), new java.awt.Color(51, 51, 51))); pnlHops.setLayout(pnlHopsLayout); pnlTables.add(pnlHops); { tblHopsTotalsModel = new DefaultTableModel(new String[][]{{""}}, new String[]{"1", "2", "3", "4", "5", "6", "7", "8", "9"}); tblHopsTotals = new JTable(); pnlHops.add(tblHopsTotals, BorderLayout.SOUTH); tblHopsTotals.setModel(tblHopsTotalsModel); tblHopsTotals.setAutoCreateColumnsFromModel(false); // set up the units combobox hopsTotalUnitsComboBox = new JComboBox(); hopsTotalUnitsComboModel = new ComboModel(); hopsTotalUnitsComboModel.setList(new Quantity().getListofUnits("weight")); hopsTotalUnitsComboBox.setModel(hopsTotalUnitsComboModel); TableColumn t = tblHopsTotals.getColumnModel().getColumn(4); t.setCellEditor(new DefaultCellEditor(hopsTotalUnitsComboBox)); hopsTotalUnitsComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { String u = (String) hopsTotalUnitsComboModel.getSelectedItem(); if (myRecipe != null) { myRecipe.setHopsUnits(u); displayRecipe(); } } }); } { jScrollPane2 = new JScrollPane(); pnlHops.add(jScrollPane2, BorderLayout.CENTER); { hopsTableModel = new HopsTableModel(this); hopsTable = new JTable() { public String getToolTipText(MouseEvent e) { java.awt.Point p = e.getPoint(); int rowIndex = rowAtPoint(p); return SBStringUtils.multiLineToolTip(40, hopsTableModel .getDescriptionAt(rowIndex)); } }; jScrollPane2.setViewportView(hopsTable); hopsTable.setModel(hopsTableModel); hopsTable.getTableHeader().setReorderingAllowed(false); TableColumn hopColumn = hopsTable.getColumnModel().getColumn(0); hopComboBox = new JComboBox(); cmbHopsModel = new ComboModel(); hopComboBox.setModel(cmbHopsModel); hopColumn.setCellEditor(new DefaultCellEditor(hopComboBox)); // set up hop units combo hopsUnitsComboBox = new JComboBox(); cmbHopsUnitsModel = new ComboModel(); hopsUnitsComboBox.setModel(cmbHopsUnitsModel); hopColumn = hopsTable.getColumnModel().getColumn(4); hopColumn.setCellEditor(new DefaultCellEditor(hopsUnitsComboBox)); // set up hop type combo String[] forms = {"Leaf", "Pellet", "Plug"}; JComboBox hopsFormComboBox = new JComboBox(forms); hopColumn = hopsTable.getColumnModel().getColumn(1); hopColumn.setCellEditor(new DefaultCellEditor(hopsFormComboBox)); // set up hop add combo String[] add = {"Boil", "FWH", "Dry", "Mash"}; JComboBox hopsAddComboBox = new JComboBox(add); hopColumn = hopsTable.getColumnModel().getColumn(5); hopColumn.setCellEditor(new DefaultCellEditor(hopsAddComboBox)); } } } { pnlHopsButtons = new JPanel(); FlowLayout pnlHopsButtonsLayout = new FlowLayout(); pnlHopsButtonsLayout.setAlignment(FlowLayout.LEFT); pnlHopsButtonsLayout.setVgap(0); pnlHopsButtons.setLayout(pnlHopsButtonsLayout); pnlTables.add(pnlHopsButtons); pnlHopsButtons.setPreferredSize(new java.awt.Dimension(512, 16)); { tlbHops = new JToolBar(); pnlHopsButtons.add(tlbHops); tlbHops.setPreferredSize(new java.awt.Dimension(58, 19)); tlbHops.setFloatable(false); { btnAddHop = new JButton(); tlbHops.add(btnAddHop); btnAddHop.setText("+"); btnAddHop.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { Hop h = new Hop(myRecipe.getHopUnits()); myRecipe.addHop(h); hopsTable.updateUI(); displayRecipe(); } } }); } { btnDelHop = new JButton(); tlbHops.add(btnDelHop); btnDelHop.setText("-"); btnDelHop.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { int i = hopsTable.getSelectedRow(); myRecipe.delHop(i); hopsTable.updateUI(); displayRecipe(); } } }); } } } } { statusPanel = new JPanel(); FlowLayout statusPanelLayout = new FlowLayout(); statusPanelLayout.setAlignment(FlowLayout.LEFT); statusPanelLayout.setHgap(2); statusPanelLayout.setVgap(2); statusPanel.setLayout(statusPanelLayout); pnlMain.add(statusPanel, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); { fileNamePanel = new JPanel(); statusPanel.add(fileNamePanel); fileNamePanel.setBorder(BorderFactory .createBevelBorder(BevelBorder.LOWERED)); { fileNameLabel = new JLabel(); fileNamePanel.add(fileNameLabel); fileNameLabel.setText("File Name"); fileNameLabel.setFont(new java.awt.Font("Dialog", 1, 10)); } } { ibuMethodPanel = new JPanel(); statusPanel.add(ibuMethodPanel); ibuMethodPanel.setBorder(BorderFactory .createBevelBorder(BevelBorder.LOWERED)); { ibuMethodLabel = new JLabel(); ibuMethodPanel.add(ibuMethodLabel); ibuMethodLabel.setText("IBU Method:"); ibuMethodLabel.setFont(new java.awt.Font("Dialog", 1, 10)); } } { alcMethodPanel = new JPanel(); statusPanel.add(alcMethodPanel); alcMethodPanel.setBorder(BorderFactory .createBevelBorder(BevelBorder.LOWERED)); { alcMethodLabel = new JLabel(); alcMethodPanel.add(alcMethodLabel); alcMethodLabel.setText("Alc Method:"); alcMethodLabel.setFont(new java.awt.Font("Dialog", 1, 10)); } } } } { jMenuBar1 = new JMenuBar(); setJMenuBar(jMenuBar1); { fileMenu = new JMenu(); jMenuBar1.add(fileMenu); fileMenu.setText("File"); { newFileMenuItem = new JMenuItem(); fileMenu.add(newFileMenuItem); newFileMenuItem.setText("New"); newFileMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // This is just a test right now to see that // stuff is changed. myRecipe = new Recipe(); myRecipe.setVersion(version); currentFile = null; attachRecipeData(); displayRecipe(); } }); } { openFileMenuItem = new JMenuItem(); fileMenu.add(openFileMenuItem); openFileMenuItem.setText("Open"); openFileMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_O, ActionEvent.CTRL_MASK)); openFileMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Show open dialog; this method does // not return until the dialog is closed String[] ext = {"xml", "qbrew", "rec"}; String desc = "StrangBrew and importable formats"; sbFileFilter openFileFilter = new sbFileFilter(ext, desc); // fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); fileChooser.setFileFilter(openFileFilter); int returnVal = fileChooser.showOpenDialog(jMenuBar1); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); Debug.print("Opening: " + file.getName() + ".\n"); OpenImport oi = new OpenImport(); myRecipe = oi.openFile(file); if (oi.getFileType().equals("")){ JOptionPane.showMessageDialog( null, "The file you've tried to open isn't a recognized format. \n" + "You can open: \n" + "StrangeBrew 1.x and Java files (.xml)\n" + "QBrew files (.qbrew)\n" + "BeerXML files (.xml)\n" + "Promash files (.rec)", "Unrecognized Format!", JOptionPane.INFORMATION_MESSAGE); } if (oi.getFileType().equals("beerxml")){ JOptionPane.showMessageDialog( null, "The file you've opened is in BeerXML format. It may contain \n" + "several recipes. Only the first recipe is opened. Use the Find \n" + "dialog to open other recipes in a BeerXML file.", "BeerXML!", JOptionPane.INFORMATION_MESSAGE); } myRecipe.setVersion(version); myRecipe.calcMaltTotals(); myRecipe.calcHopsTotals(); myRecipe.mash.calcMashSchedule(); checkIngredientsInDB(); attachRecipeData(); currentFile = file; displayRecipe(); } else { Debug.print("Open command cancelled by user.\n"); } } }); } { imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/find.gif"); icon = new ImageIcon(imgURL); findFileMenuItem = new JMenuItem("Find", icon); findFileMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_F, ActionEvent.CTRL_MASK)); fileMenu.add(findFileMenuItem); final JFrame owner = this; findFileMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // open the find dialog FindDialog fd = new FindDialog(owner); fd.setVisible(true); } }); } { imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/save.gif"); icon = new ImageIcon(imgURL); saveMenuItem = new JMenuItem("Save", icon); fileMenu.add(saveMenuItem); saveMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_S, ActionEvent.CTRL_MASK)); saveMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { int choice = 1; if (currentFile != null) { File file = currentFile; //This is where a real application would save the file. try { FileWriter out = new FileWriter(file); out.write(myRecipe.toXML()); out.close(); Debug.print("Saved: " + file.getAbsoluteFile()); currentFile = file; } catch (Exception e) { showError(e); } } // prompt to save if not already saved else { choice = JOptionPane.showConfirmDialog(null, "File not saved. Do you wish to save it?", "File note saved", JOptionPane.YES_NO_OPTION); } if (choice == 0) { // same as save as: saveAs(); } } }); } { imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/saveas.gif"); icon = new ImageIcon(imgURL); saveAsMenuItem = new JMenuItem("Save As ...", icon); fileMenu.add(saveAsMenuItem); saveAsMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // This is just a test right now to see that // stuff is changed. Debug.print(myRecipe.toXML()); saveAs(); } }); } { exportMenu = new JMenu(); fileMenu.add(exportMenu); exportMenu.setText("Export"); { exportHTMLmenu = new JMenuItem(); exportMenu.add(exportHTMLmenu); exportHTMLmenu.setText("HTML"); exportHTMLmenu.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Show save dialog; this method does // not return until the dialog is closed String[] ext = {"html", "htm"}; sbFileFilter saveFileFilter = new sbFileFilter(ext, "HTML"); fileChooser.setFileFilter(saveFileFilter); fileChooser.setSelectedFile(new File(myRecipe.getName() + ".html")); int returnVal = fileChooser.showSaveDialog(jMenuBar1); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); //This is where a real application would save the file. try { saveAsHTML(file, "ca/strangebrew/data/recipeToHtml.xslt"); } catch (Exception e) { showError(e); } } else { Debug.print("Save command cancelled by user.\n"); } } }); exportTextMenuItem = new JMenuItem(); exportMenu.add(exportTextMenuItem); exportTextMenuItem.setText("Text"); exportTextMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Show save dialog; this method does // not return until the dialog is closed String[] ext = {"txt"}; sbFileFilter saveFileFilter = new sbFileFilter(ext, "Text"); fileChooser.setFileFilter(saveFileFilter); fileChooser.setSelectedFile(new File(myRecipe.getName() + ".txt")); int returnVal = fileChooser.showSaveDialog(jMenuBar1); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); //This is where a real application would save the file. try { FileWriter out = new FileWriter(file); out.write(myRecipe.toText()); out.close(); } catch (Exception e) { showError(e); } } else { Debug.print("Export text command cancelled by user.\n"); } } }); } } { JMenuItem clipboardMenuItem = new JMenuItem("Copy to Clipboard"); fileMenu.add(clipboardMenuItem); clipboardMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Copy current recipe to clipboard Clipboard clipboard = getToolkit ().getSystemClipboard (); StringSelection s = new StringSelection(myRecipe.toText()); clipboard.setContents(s, s); } }); JMenuItem printMenuItem = new JMenuItem("Print..."); fileMenu.add(printMenuItem); final JFrame owner = this; printMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Copy current recipe to clipboard// save file as xml, then transform it to html File tmp = new File("tmp.html"); try { saveAsHTML(tmp, "ca/strangebrew/data/recipeToSimpleHtml.xslt"); HTMLViewer view = new HTMLViewer(owner, tmp.toURL()); view.setModal(true); view.setVisible(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } tmp.delete(); } }); } { jSeparator2 = new JSeparator(); fileMenu.add(jSeparator2); } { exitMenuItem = new JMenuItem(); fileMenu.add(exitMenuItem); exitMenuItem.setText("Exit"); exitMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_Q, ActionEvent.CTRL_MASK)); final JFrame owner = this; exitMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // exit program processWindowEvent(new WindowEvent(owner,WindowEvent.WINDOW_CLOSING)); System.exit(0); } }); } } { jMenu4 = new JMenu(); jMenuBar1.add(jMenu4); jMenu4.setText("Edit"); { final JFrame owner = this; editPrefsMenuItem = new JMenuItem(); jMenu4.add(editPrefsMenuItem); editPrefsMenuItem.setText("Preferences..."); editPrefsMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { PreferencesDialog d = new PreferencesDialog(owner, preferences); d.setVisible(true); } }); } { jSeparator1 = new JSeparator(); jMenu4.add(jSeparator1); } { deleteMenuItem = new JMenuItem(); jMenu4.add(deleteMenuItem); deleteMenuItem.setText("Delete"); deleteMenuItem.setEnabled(false); } } { mnuTools = new JMenu(); jMenuBar1.add(mnuTools); mnuTools.setText("Tools"); { final JFrame owner = this; JMenuItem scalRecipeMenuItem = new JMenuItem(); mnuTools.add(scalRecipeMenuItem); scalRecipeMenuItem.setText("Scale Recipe..."); scalRecipeMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_R, ActionEvent.CTRL_MASK)); scalRecipeMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { ScaleRecipeDialog scaleRecipe = new ScaleRecipeDialog(owner); scaleRecipe.setModal(true); scaleRecipe.setVisible(true); } }); JMenuItem maltPercentMenuItem = new JMenuItem(); mnuTools.add(maltPercentMenuItem); maltPercentMenuItem.setText("Malt Percent..."); maltPercentMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_M, ActionEvent.CTRL_MASK)); maltPercentMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { MaltPercentDialog maltPercent = new MaltPercentDialog(owner); maltPercent.setModal(true); maltPercent.setVisible(true); } }); } } { jMenu5 = new JMenu(); jMenuBar1.add(jMenu5); jMenu5.setText("Help"); { helpMenuItem = new JMenuItem(); jMenu5.add(helpMenuItem); helpMenuItem.setText("Help"); final JFrame owner = this; helpMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { URL help; try { help = new File(appRoot + "/help/index.html").toURL(); HTMLViewer view = new HTMLViewer(owner, help); view.setModal(true); view.setVisible(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); } { aboutMenuItem = new JMenuItem(); jMenu5.add(aboutMenuItem); aboutMenuItem.setText("About..."); final JFrame owner = this; aboutMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { aboutDlg = new AboutDialog(owner, version); aboutDlg.setVisible(true); } }); } } } } catch (Exception e) { e.printStackTrace(); } } |
|
amountEditor = new SBCellEditor(new JTextField()); maltColumn = maltTable.getColumnModel().getColumn(1); maltColumn.setCellEditor(amountEditor); | private void initGUI() { try { // restore the saved size and location: this.setSize(preferences.getIProperty("winWidth"), preferences.getIProperty("winHeight")); this.setLocation(preferences.getIProperty("winX"), preferences.getIProperty("winY")); imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/brew.gif"); icon = new ImageIcon(imgURL); this.setIconImage(icon.getImage()); this.setTitle("StrangeBrew " + version); this.addWindowListener(new WindowAdapter() { public void windowClosed(WindowEvent evt) { System.exit(1); } }); { pnlMain = new JPanel(); GridBagLayout jPanel2Layout = new GridBagLayout(); jPanel2Layout.columnWeights = new double[]{0.1}; jPanel2Layout.columnWidths = new int[]{7}; jPanel2Layout.rowWeights = new double[]{0.1, 0.1, 0.9, 0.1}; jPanel2Layout.rowHeights = new int[]{7, 7, 7, 7}; pnlMain.setLayout(jPanel2Layout); this.getContentPane().add(pnlMain, BorderLayout.CENTER); { jTabbedPane1 = new JTabbedPane(); pnlMain.add(jTabbedPane1, new GridBagConstraints(0, 1, 1, 1, 0.1, 0.1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); { pnlDetails = new JPanel(); GridBagLayout pnlDetailsLayout = new GridBagLayout(); pnlDetailsLayout.columnWeights = new double[]{0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1}; pnlDetailsLayout.columnWidths = new int[]{7, 7, 7, 7, 7, 7, 7, 7, 7, 7}; pnlDetailsLayout.rowWeights = new double[]{0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1}; pnlDetailsLayout.rowHeights = new int[]{7, 7, 7, 7, 7, 7, 7}; pnlDetails.setLayout(pnlDetailsLayout); jTabbedPane1.addTab("Details", null, pnlDetails, null); pnlDetails.setPreferredSize(new java.awt.Dimension(20, 16)); { lblBrewer = new JLabel(); pnlDetails.add(lblBrewer, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblBrewer.setText("Brewer:"); } { brewerNameText = new JTextField(); pnlDetails.add(brewerNameText, new GridBagConstraints(1, 0, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); brewerNameText.setPreferredSize(new java.awt.Dimension(69, 20)); brewerNameText.setText("Brewer"); } { lblDate = new JLabel(); pnlDetails.add(lblDate, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblDate.setText("Date:"); } { lblStyle = new JLabel(); pnlDetails.add(lblStyle, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblStyle.setText("Style:"); } { lblYeast = new JLabel(); pnlDetails.add(lblYeast, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblYeast.setText("Yeast:"); } { lblPreBoil = new JLabel(); pnlDetails.add(lblPreBoil, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblPreBoil.setText("Pre boil:"); } { lblPostBoil = new JLabel(); pnlDetails.add(lblPostBoil, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblPostBoil.setText("Post boil:"); } { lblEffic = new JLabel(); pnlDetails.add(lblEffic, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblEffic.setText("Effic:"); lblEffic.setPreferredSize(new java.awt.Dimension(31, 14)); } { lblAtten = new JLabel(); pnlDetails.add(lblAtten, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblAtten.setText("Atten:"); lblAtten.setPreferredSize(new java.awt.Dimension(34, 14)); } { lblOG = new JLabel(); pnlDetails.add(lblOG, new GridBagConstraints(5, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblOG.setText("OG:"); } { lblFG = new JLabel(); pnlDetails.add(lblFG, new GridBagConstraints(5, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblFG.setText("FG:"); } { lblIBU = new JLabel(); pnlDetails.add(lblIBU, new GridBagConstraints(7, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblIBU.setText("IBU:"); } { lblAlc = new JLabel(); pnlDetails.add(lblAlc, new GridBagConstraints(7, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblAlc.setText("%Alc:"); } { lblColour = new JLabel(); pnlDetails.add(lblColour, new GridBagConstraints(7, 2, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblColour.setText("Colour:"); } { txtDate = new JFormattedTextField(); pnlDetails.add(txtDate, new GridBagConstraints(1, 1, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); txtDate.setText("Date"); txtDate.setPreferredSize(new java.awt.Dimension(73, 20)); } { cmbStyleModel = new ComboModel(); cmbStyle = new JComboBox(); pnlDetails.add(cmbStyle, new GridBagConstraints(1, 2, 5, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cmbStyle.setModel(cmbStyleModel); cmbStyle.setMaximumSize(new java.awt.Dimension(100, 32767)); cmbStyle.setPreferredSize(new java.awt.Dimension(190, 20)); } { txtPreBoil = new JFormattedTextField(); pnlDetails.add(txtPreBoil, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); txtPreBoil.setText("Pre Boil"); txtPreBoil.setPreferredSize(new java.awt.Dimension(37, 20)); } { postBoilText = new JFormattedTextField(); pnlDetails.add(postBoilText, new GridBagConstraints(1, 5, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); postBoilText.setText("Post Boil"); postBoilText.setPreferredSize(new java.awt.Dimension(46, 20)); } { lblComments = new JLabel(); pnlDetails.add(lblComments, new GridBagConstraints(6, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblComments.setText("Comments:"); } { SpinnerNumberModel spnEfficModel = new SpinnerNumberModel(75.0, 0.0, 100.0, 1.0); spnEffic = new JSpinner(); pnlDetails.add(spnEffic, new GridBagConstraints(4, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnEffic.setModel(spnEfficModel); spnEffic.setMaximumSize(new java.awt.Dimension(70, 32767)); spnEffic.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { myRecipe.setEfficiency(Double.parseDouble(spnEffic.getValue() .toString())); displayRecipe(); } }); spnEffic.setEditor(new JSpinner.NumberEditor(spnEffic, "00.#")); spnEffic.getEditor().setPreferredSize(new java.awt.Dimension(28, 16)); spnEffic.setPreferredSize(new java.awt.Dimension(53, 18)); } { SpinnerNumberModel spnAttenModel = new SpinnerNumberModel(75.0, 0.0, 100.0, 1.0); spnAtten = new JSpinner(); pnlDetails.add(spnAtten, new GridBagConstraints(4, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnAtten.setModel(spnAttenModel); spnAtten.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { myRecipe.setAttenuation(Double.parseDouble(spnAtten.getValue() .toString())); displayRecipe(); } }); spnAtten.setEditor(new JSpinner.NumberEditor(spnAtten, "00.#")); spnAtten.setPreferredSize(new java.awt.Dimension(49, 20)); } { SpinnerNumberModel spnOgModel = new SpinnerNumberModel(1.000, 0.900, 2.000, 0.001); spnOG = new JSpinner(); pnlDetails.add(spnOG, new GridBagConstraints(6, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnOG.setModel(spnOgModel); spnOG.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { myRecipe.setEstOg(Double.parseDouble(spnOG.getValue() .toString())); displayRecipe(); } }); spnOG.setEditor(new JSpinner.NumberEditor(spnOG, "0.000")); spnOG.getEditor().setPreferredSize(new java.awt.Dimension(20, 16)); spnOG.setPreferredSize(new java.awt.Dimension(67, 18)); } { SpinnerNumberModel spnFgModel = new SpinnerNumberModel(1.000, 0.900, 2.000, 0.001); spnFG = new JSpinner(); pnlDetails.add(spnFG, new GridBagConstraints(6, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnFG.setModel(spnFgModel); spnFG.setEditor(new JSpinner.NumberEditor(spnFG, "0.000")); spnFG.setPreferredSize(new java.awt.Dimension(69, 20)); spnFG.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { // set the new FG, and update alc: myRecipe.setEstFg(Double.parseDouble(spnFG.getValue() .toString())); displayRecipe(); } }); } { lblIBUvalue = new JLabel(); pnlDetails.add(lblIBUvalue, new GridBagConstraints(8, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblIBUvalue.setText("IBUs"); } { lblColourValue = new JLabel(); pnlDetails.add(lblColourValue, new GridBagConstraints(8, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblColourValue.setText("Colour"); } { lblAlcValue = new JLabel(); pnlDetails.add(lblAlcValue, new GridBagConstraints(8, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblAlcValue.setText("Alc"); } { scpComments = new JScrollPane(); pnlDetails.add(scpComments, new GridBagConstraints(7, 4, 3, 2, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); { txtComments = new JTextArea(); scpComments.setViewportView(txtComments); txtComments.setText("Comments"); txtComments.setWrapStyleWord(true); // txtComments.setPreferredSize(new java.awt.Dimension(117, 42)); txtComments.setLineWrap(true); txtComments.setPreferredSize(new java.awt.Dimension(263, 40)); txtComments.addFocusListener(new FocusAdapter() { public void focusLost(FocusEvent evt) { if (!txtComments.getText().equals(myRecipe.getComments())) { myRecipe.setComments(txtComments.getText()); } } }); } } { cmbYeastModel = new ComboModel(); cmbYeast = new JComboBox(); pnlDetails.add(cmbYeast, new GridBagConstraints(1, 3, 5, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cmbYeast.setModel(cmbYeastModel); cmbYeast.setPreferredSize(new java.awt.Dimension(193, 20)); } { cmbSizeUnitsModel = new ComboModel(); cmbSizeUnits = new JComboBox(); pnlDetails.add(cmbSizeUnits, new GridBagConstraints(2, 4, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cmbSizeUnits.setModel(cmbSizeUnitsModel); } { lblSizeUnits = new JLabel(); pnlDetails.add(lblSizeUnits, new GridBagConstraints(2, 5, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); lblSizeUnits.setText("Size Units"); } { boilTimeLable = new JLabel(); pnlDetails.add(boilTimeLable, new GridBagConstraints(4, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); boilTimeLable.setText("Boil Min:"); } { evapLabel = new JLabel(); pnlDetails.add(evapLabel, new GridBagConstraints(4, 5, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); evapLabel.setText("Evap/hr:"); } { boilMinText = new JTextField(); pnlDetails.add(boilMinText, new GridBagConstraints(5, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); boilMinText.setText("60"); boilMinText.setPreferredSize(new java.awt.Dimension(22, 20)); } { evapText = new JTextField(); pnlDetails.add(evapText, new GridBagConstraints(5, 5, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); evapText.setText("4"); evapText.setPreferredSize(new java.awt.Dimension(23, 20)); } { alcMethodComboModel = new DefaultComboBoxModel(new String[]{"Volume", "Weight"}); alcMethodCombo = new JComboBox(alcMethodComboModel); pnlDetails.add(alcMethodCombo, new GridBagConstraints(9, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); alcMethodCombo.setPreferredSize(new java.awt.Dimension(58, 20)); } { ibuMethodComboModel = new DefaultComboBoxModel(new String[]{"Tinseth", "Garetz", "Rager"}); ibuMethodCombo = new JComboBox(ibuMethodComboModel); pnlDetails.add(ibuMethodCombo, new GridBagConstraints(9, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); ibuMethodCombo.setPreferredSize(new java.awt.Dimension(59, 20)); } { colourMethodComboModel = new DefaultComboBoxModel(new String[]{"SRM", "EBC"}); colourMethodCombo = new JComboBox(colourMethodComboModel); pnlDetails.add(colourMethodCombo, new GridBagConstraints(9, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); colourMethodCombo.setPreferredSize(new java.awt.Dimension(44, 20)); } ComboBoxModel evapMethodComboModel = new DefaultComboBoxModel(new String[] { "Constant", "Percent" }); { jPanel1 = new JPanel(); pnlMain.add(jPanel1, new GridBagConstraints( 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); FlowLayout jPanel1Layout = new FlowLayout(); jPanel1Layout.setAlignment(FlowLayout.LEFT); jPanel1.setLayout(jPanel1Layout); jToolBar1 = new JToolBar(); getContentPane().add(jToolBar1, BorderLayout.NORTH); jToolBar1.setFloatable(false); jToolBar1.setRollover(true); jButton1 = new JButton(); jToolBar1.add(jButton1); jButton1.setMnemonic(java.awt.event.KeyEvent.VK_S); jButton1.setIcon(new ImageIcon(getClass().getClassLoader().getResource( "ca/strangebrew/icons/save.gif"))); jButton1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { System.out.println("jButton1.actionPerformed, event=" + evt); //TODO add your code for jButton1.actionPerformed } }); jButton2 = new JButton(); jToolBar1.add(jButton2); jButton2.setIcon(new ImageIcon(getClass().getClassLoader().getResource( "ca/strangebrew/icons/find.gif"))); jButton2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { System.out.println("jButton2.actionPerformed, event=" + evt); //TODO add your code for jButton2.actionPerformed } }); { lblName = new JLabel(); jPanel1.add(lblName); lblName.setText("Name:"); } { txtName = new JTextField(); jPanel1.add(txtName); txtName.setText("Name"); txtName.setPreferredSize(new java.awt.Dimension(297, 20)); } } evapMethodCombo = new JComboBox(); pnlDetails.add(evapMethodCombo, new GridBagConstraints(6, 5, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); evapMethodCombo.setModel(evapMethodComboModel); evapMethodCombo.setPreferredSize(new java.awt.Dimension(64, 20)); colourPanel = new JPanel(); pnlDetails.add(colourPanel, new GridBagConstraints(9, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); colourPanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); } { SBNotifier sbn = new SBNotifier(); stylePanel = new StylePanel(sbn); jTabbedPane1.addTab("Style", null, stylePanel, null); miscPanel = new MiscPanel(myRecipe); jTabbedPane1.addTab("Misc", null, miscPanel, null); notesPanel = new NotesPanel(); jTabbedPane1.addTab("Notes", null, notesPanel, null); dilutionPanel = new DilutionPanel(); jTabbedPane1.addTab("Dilution", null, dilutionPanel, null); mashPanel = new MashPanel(myRecipe); jTabbedPane1.addTab("Mash", null, mashPanel, null); waterPanel = new WaterPanel(); jTabbedPane1.addTab("Water", null, waterPanel, null); costPanel = new CostPanel(); jTabbedPane1.addTab("Cost", null, costPanel, null); // SBNotifier sbn = new SBNotifier(); settingsPanel = new SettingsPanel(sbn); jTabbedPane1.addTab("Settings", null, settingsPanel, null); } } { pnlTables = new JPanel(); BoxLayout pnlMaltsLayout = new BoxLayout(pnlTables, javax.swing.BoxLayout.Y_AXIS); pnlMain.add(pnlTables, new GridBagConstraints(0, 2, 1, 1, 0.5, 0.5, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); pnlTables.setLayout(pnlMaltsLayout); { pnlMalt = new JPanel(); pnlTables.add(pnlMalt); BorderLayout pnlMaltLayout1 = new BorderLayout(); pnlMalt.setBorder(BorderFactory.createTitledBorder(new LineBorder( new java.awt.Color(0, 0, 0), 1, false), "Fermentables", TitledBorder.LEADING, TitledBorder.TOP, new java.awt.Font("Dialog", 1, 12), new java.awt.Color(51, 51, 51))); pnlMalt.setLayout(pnlMaltLayout1); { jScrollPane1 = new JScrollPane(); pnlMalt.add(jScrollPane1, BorderLayout.CENTER); { maltTableModel = new MaltTableModel(this); maltTable = new JTable() { public String getToolTipText(MouseEvent e) { java.awt.Point p = e.getPoint(); int rowIndex = rowAtPoint(p); return SBStringUtils.multiLineToolTip(40, maltTableModel .getDescriptionAt(rowIndex)); } }; jScrollPane1.setViewportView(maltTable); maltTable.setModel(maltTableModel); // maltTable.setAutoCreateColumnsFromModel(false); maltTable.getTableHeader().setReorderingAllowed(false); TableColumn maltColumn = maltTable.getColumnModel().getColumn(0); // set up malt list combo maltComboBox = new JComboBox(); cmbMaltModel = new ComboModel(); maltComboBox.setModel(cmbMaltModel); maltColumn.setCellEditor(new DefaultCellEditor(maltComboBox)); // set up malt units combo maltUnitsComboBox = new JComboBox(); cmbMaltUnitsModel = new ComboModel(); maltUnitsComboBox.setModel(cmbMaltUnitsModel); maltColumn = maltTable.getColumnModel().getColumn(2); maltColumn.setCellEditor(new DefaultCellEditor(maltUnitsComboBox)); } } { tblMaltTotalsModel = new DefaultTableModel(new String[][]{{""}}, new String[]{"Malt", "Amount", "Units", "Points", "Lov", "Cost/U", "%"}); tblMaltTotals = new JTable(); pnlMalt.add(tblMaltTotals, BorderLayout.SOUTH); tblMaltTotals.setModel(tblMaltTotalsModel); tblMaltTotals.getTableHeader().setEnabled(false); tblMaltTotals.setAutoCreateColumnsFromModel(false); // set up the units combobox maltTotalUnitsComboBox = new JComboBox(); maltTotalUnitsComboModel = new ComboModel(); maltTotalUnitsComboModel.setList(new Quantity().getListofUnits("weight")); maltTotalUnitsComboBox.setModel(maltTotalUnitsComboModel); TableColumn t = tblMaltTotals.getColumnModel().getColumn(2); t.setCellEditor(new DefaultCellEditor(maltTotalUnitsComboBox)); maltTotalUnitsComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { String u = (String) maltTotalUnitsComboModel.getSelectedItem(); if (myRecipe != null) { myRecipe.setMaltUnits(u); displayRecipe(); } } }); } } { pnlMaltButtons = new JPanel(); pnlTables.add(pnlMaltButtons); FlowLayout pnlMaltButtonsLayout = new FlowLayout(); pnlMaltButtonsLayout.setAlignment(FlowLayout.LEFT); pnlMaltButtonsLayout.setVgap(0); pnlMaltButtons.setLayout(pnlMaltButtonsLayout); pnlMaltButtons.setPreferredSize(new java.awt.Dimension(592, 27)); { tlbMalt = new JToolBar(); pnlMaltButtons.add(tlbMalt); tlbMalt.setPreferredSize(new java.awt.Dimension(55, 20)); tlbMalt.setFloatable(false); { btnAddMalt = new JButton(); tlbMalt.add(btnAddMalt); btnAddMalt.setText("+"); btnAddMalt.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { Fermentable f = new Fermentable(myRecipe.getMaltUnits()); myRecipe.addMalt(f); maltTable.updateUI(); displayRecipe(); } } }); } { btnDelMalt = new JButton(); tlbMalt.add(btnDelMalt); btnDelMalt.setText("-"); btnDelMalt.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { int i = maltTable.getSelectedRow(); myRecipe.delMalt(i); maltTable.updateUI(); displayRecipe(); } } }); } } } { pnlHops = new JPanel(); BorderLayout pnlHopsLayout = new BorderLayout(); pnlHops.setBorder(BorderFactory.createTitledBorder(new LineBorder( new java.awt.Color(0, 0, 0), 1, false), "Hops", TitledBorder.LEADING, TitledBorder.TOP, new java.awt.Font("Dialog", 1, 12), new java.awt.Color(51, 51, 51))); pnlHops.setLayout(pnlHopsLayout); pnlTables.add(pnlHops); { tblHopsTotalsModel = new DefaultTableModel(new String[][]{{""}}, new String[]{"1", "2", "3", "4", "5", "6", "7", "8", "9"}); tblHopsTotals = new JTable(); pnlHops.add(tblHopsTotals, BorderLayout.SOUTH); tblHopsTotals.setModel(tblHopsTotalsModel); tblHopsTotals.setAutoCreateColumnsFromModel(false); // set up the units combobox hopsTotalUnitsComboBox = new JComboBox(); hopsTotalUnitsComboModel = new ComboModel(); hopsTotalUnitsComboModel.setList(new Quantity().getListofUnits("weight")); hopsTotalUnitsComboBox.setModel(hopsTotalUnitsComboModel); TableColumn t = tblHopsTotals.getColumnModel().getColumn(4); t.setCellEditor(new DefaultCellEditor(hopsTotalUnitsComboBox)); hopsTotalUnitsComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { String u = (String) hopsTotalUnitsComboModel.getSelectedItem(); if (myRecipe != null) { myRecipe.setHopsUnits(u); displayRecipe(); } } }); } { jScrollPane2 = new JScrollPane(); pnlHops.add(jScrollPane2, BorderLayout.CENTER); { hopsTableModel = new HopsTableModel(this); hopsTable = new JTable() { public String getToolTipText(MouseEvent e) { java.awt.Point p = e.getPoint(); int rowIndex = rowAtPoint(p); return SBStringUtils.multiLineToolTip(40, hopsTableModel .getDescriptionAt(rowIndex)); } }; jScrollPane2.setViewportView(hopsTable); hopsTable.setModel(hopsTableModel); hopsTable.getTableHeader().setReorderingAllowed(false); TableColumn hopColumn = hopsTable.getColumnModel().getColumn(0); hopComboBox = new JComboBox(); cmbHopsModel = new ComboModel(); hopComboBox.setModel(cmbHopsModel); hopColumn.setCellEditor(new DefaultCellEditor(hopComboBox)); // set up hop units combo hopsUnitsComboBox = new JComboBox(); cmbHopsUnitsModel = new ComboModel(); hopsUnitsComboBox.setModel(cmbHopsUnitsModel); hopColumn = hopsTable.getColumnModel().getColumn(4); hopColumn.setCellEditor(new DefaultCellEditor(hopsUnitsComboBox)); // set up hop type combo String[] forms = {"Leaf", "Pellet", "Plug"}; JComboBox hopsFormComboBox = new JComboBox(forms); hopColumn = hopsTable.getColumnModel().getColumn(1); hopColumn.setCellEditor(new DefaultCellEditor(hopsFormComboBox)); // set up hop add combo String[] add = {"Boil", "FWH", "Dry", "Mash"}; JComboBox hopsAddComboBox = new JComboBox(add); hopColumn = hopsTable.getColumnModel().getColumn(5); hopColumn.setCellEditor(new DefaultCellEditor(hopsAddComboBox)); } } } { pnlHopsButtons = new JPanel(); FlowLayout pnlHopsButtonsLayout = new FlowLayout(); pnlHopsButtonsLayout.setAlignment(FlowLayout.LEFT); pnlHopsButtonsLayout.setVgap(0); pnlHopsButtons.setLayout(pnlHopsButtonsLayout); pnlTables.add(pnlHopsButtons); pnlHopsButtons.setPreferredSize(new java.awt.Dimension(512, 16)); { tlbHops = new JToolBar(); pnlHopsButtons.add(tlbHops); tlbHops.setPreferredSize(new java.awt.Dimension(58, 19)); tlbHops.setFloatable(false); { btnAddHop = new JButton(); tlbHops.add(btnAddHop); btnAddHop.setText("+"); btnAddHop.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { Hop h = new Hop(myRecipe.getHopUnits()); myRecipe.addHop(h); hopsTable.updateUI(); displayRecipe(); } } }); } { btnDelHop = new JButton(); tlbHops.add(btnDelHop); btnDelHop.setText("-"); btnDelHop.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { int i = hopsTable.getSelectedRow(); myRecipe.delHop(i); hopsTable.updateUI(); displayRecipe(); } } }); } } } } { statusPanel = new JPanel(); FlowLayout statusPanelLayout = new FlowLayout(); statusPanelLayout.setAlignment(FlowLayout.LEFT); statusPanelLayout.setHgap(2); statusPanelLayout.setVgap(2); statusPanel.setLayout(statusPanelLayout); pnlMain.add(statusPanel, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); { fileNamePanel = new JPanel(); statusPanel.add(fileNamePanel); fileNamePanel.setBorder(BorderFactory .createBevelBorder(BevelBorder.LOWERED)); { fileNameLabel = new JLabel(); fileNamePanel.add(fileNameLabel); fileNameLabel.setText("File Name"); fileNameLabel.setFont(new java.awt.Font("Dialog", 1, 10)); } } { ibuMethodPanel = new JPanel(); statusPanel.add(ibuMethodPanel); ibuMethodPanel.setBorder(BorderFactory .createBevelBorder(BevelBorder.LOWERED)); { ibuMethodLabel = new JLabel(); ibuMethodPanel.add(ibuMethodLabel); ibuMethodLabel.setText("IBU Method:"); ibuMethodLabel.setFont(new java.awt.Font("Dialog", 1, 10)); } } { alcMethodPanel = new JPanel(); statusPanel.add(alcMethodPanel); alcMethodPanel.setBorder(BorderFactory .createBevelBorder(BevelBorder.LOWERED)); { alcMethodLabel = new JLabel(); alcMethodPanel.add(alcMethodLabel); alcMethodLabel.setText("Alc Method:"); alcMethodLabel.setFont(new java.awt.Font("Dialog", 1, 10)); } } } } { jMenuBar1 = new JMenuBar(); setJMenuBar(jMenuBar1); { fileMenu = new JMenu(); jMenuBar1.add(fileMenu); fileMenu.setText("File"); { newFileMenuItem = new JMenuItem(); fileMenu.add(newFileMenuItem); newFileMenuItem.setText("New"); newFileMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // This is just a test right now to see that // stuff is changed. myRecipe = new Recipe(); myRecipe.setVersion(version); currentFile = null; attachRecipeData(); displayRecipe(); } }); } { openFileMenuItem = new JMenuItem(); fileMenu.add(openFileMenuItem); openFileMenuItem.setText("Open"); openFileMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_O, ActionEvent.CTRL_MASK)); openFileMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Show open dialog; this method does // not return until the dialog is closed String[] ext = {"xml", "qbrew", "rec"}; String desc = "StrangBrew and importable formats"; sbFileFilter openFileFilter = new sbFileFilter(ext, desc); // fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); fileChooser.setFileFilter(openFileFilter); int returnVal = fileChooser.showOpenDialog(jMenuBar1); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); Debug.print("Opening: " + file.getName() + ".\n"); OpenImport oi = new OpenImport(); myRecipe = oi.openFile(file); if (oi.getFileType().equals("")){ JOptionPane.showMessageDialog( null, "The file you've tried to open isn't a recognized format. \n" + "You can open: \n" + "StrangeBrew 1.x and Java files (.xml)\n" + "QBrew files (.qbrew)\n" + "BeerXML files (.xml)\n" + "Promash files (.rec)", "Unrecognized Format!", JOptionPane.INFORMATION_MESSAGE); } if (oi.getFileType().equals("beerxml")){ JOptionPane.showMessageDialog( null, "The file you've opened is in BeerXML format. It may contain \n" + "several recipes. Only the first recipe is opened. Use the Find \n" + "dialog to open other recipes in a BeerXML file.", "BeerXML!", JOptionPane.INFORMATION_MESSAGE); } myRecipe.setVersion(version); myRecipe.calcMaltTotals(); myRecipe.calcHopsTotals(); myRecipe.mash.calcMashSchedule(); checkIngredientsInDB(); attachRecipeData(); currentFile = file; displayRecipe(); } else { Debug.print("Open command cancelled by user.\n"); } } }); } { imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/find.gif"); icon = new ImageIcon(imgURL); findFileMenuItem = new JMenuItem("Find", icon); findFileMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_F, ActionEvent.CTRL_MASK)); fileMenu.add(findFileMenuItem); final JFrame owner = this; findFileMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // open the find dialog FindDialog fd = new FindDialog(owner); fd.setVisible(true); } }); } { imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/save.gif"); icon = new ImageIcon(imgURL); saveMenuItem = new JMenuItem("Save", icon); fileMenu.add(saveMenuItem); saveMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_S, ActionEvent.CTRL_MASK)); saveMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { int choice = 1; if (currentFile != null) { File file = currentFile; //This is where a real application would save the file. try { FileWriter out = new FileWriter(file); out.write(myRecipe.toXML()); out.close(); Debug.print("Saved: " + file.getAbsoluteFile()); currentFile = file; } catch (Exception e) { showError(e); } } // prompt to save if not already saved else { choice = JOptionPane.showConfirmDialog(null, "File not saved. Do you wish to save it?", "File note saved", JOptionPane.YES_NO_OPTION); } if (choice == 0) { // same as save as: saveAs(); } } }); } { imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/saveas.gif"); icon = new ImageIcon(imgURL); saveAsMenuItem = new JMenuItem("Save As ...", icon); fileMenu.add(saveAsMenuItem); saveAsMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // This is just a test right now to see that // stuff is changed. Debug.print(myRecipe.toXML()); saveAs(); } }); } { exportMenu = new JMenu(); fileMenu.add(exportMenu); exportMenu.setText("Export"); { exportHTMLmenu = new JMenuItem(); exportMenu.add(exportHTMLmenu); exportHTMLmenu.setText("HTML"); exportHTMLmenu.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Show save dialog; this method does // not return until the dialog is closed String[] ext = {"html", "htm"}; sbFileFilter saveFileFilter = new sbFileFilter(ext, "HTML"); fileChooser.setFileFilter(saveFileFilter); fileChooser.setSelectedFile(new File(myRecipe.getName() + ".html")); int returnVal = fileChooser.showSaveDialog(jMenuBar1); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); //This is where a real application would save the file. try { saveAsHTML(file, "ca/strangebrew/data/recipeToHtml.xslt"); } catch (Exception e) { showError(e); } } else { Debug.print("Save command cancelled by user.\n"); } } }); exportTextMenuItem = new JMenuItem(); exportMenu.add(exportTextMenuItem); exportTextMenuItem.setText("Text"); exportTextMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Show save dialog; this method does // not return until the dialog is closed String[] ext = {"txt"}; sbFileFilter saveFileFilter = new sbFileFilter(ext, "Text"); fileChooser.setFileFilter(saveFileFilter); fileChooser.setSelectedFile(new File(myRecipe.getName() + ".txt")); int returnVal = fileChooser.showSaveDialog(jMenuBar1); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); //This is where a real application would save the file. try { FileWriter out = new FileWriter(file); out.write(myRecipe.toText()); out.close(); } catch (Exception e) { showError(e); } } else { Debug.print("Export text command cancelled by user.\n"); } } }); } } { JMenuItem clipboardMenuItem = new JMenuItem("Copy to Clipboard"); fileMenu.add(clipboardMenuItem); clipboardMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Copy current recipe to clipboard Clipboard clipboard = getToolkit ().getSystemClipboard (); StringSelection s = new StringSelection(myRecipe.toText()); clipboard.setContents(s, s); } }); JMenuItem printMenuItem = new JMenuItem("Print..."); fileMenu.add(printMenuItem); final JFrame owner = this; printMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Copy current recipe to clipboard// save file as xml, then transform it to html File tmp = new File("tmp.html"); try { saveAsHTML(tmp, "ca/strangebrew/data/recipeToSimpleHtml.xslt"); HTMLViewer view = new HTMLViewer(owner, tmp.toURL()); view.setModal(true); view.setVisible(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } tmp.delete(); } }); } { jSeparator2 = new JSeparator(); fileMenu.add(jSeparator2); } { exitMenuItem = new JMenuItem(); fileMenu.add(exitMenuItem); exitMenuItem.setText("Exit"); exitMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_Q, ActionEvent.CTRL_MASK)); final JFrame owner = this; exitMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // exit program processWindowEvent(new WindowEvent(owner,WindowEvent.WINDOW_CLOSING)); System.exit(0); } }); } } { jMenu4 = new JMenu(); jMenuBar1.add(jMenu4); jMenu4.setText("Edit"); { final JFrame owner = this; editPrefsMenuItem = new JMenuItem(); jMenu4.add(editPrefsMenuItem); editPrefsMenuItem.setText("Preferences..."); editPrefsMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { PreferencesDialog d = new PreferencesDialog(owner, preferences); d.setVisible(true); } }); } { jSeparator1 = new JSeparator(); jMenu4.add(jSeparator1); } { deleteMenuItem = new JMenuItem(); jMenu4.add(deleteMenuItem); deleteMenuItem.setText("Delete"); deleteMenuItem.setEnabled(false); } } { mnuTools = new JMenu(); jMenuBar1.add(mnuTools); mnuTools.setText("Tools"); { final JFrame owner = this; JMenuItem scalRecipeMenuItem = new JMenuItem(); mnuTools.add(scalRecipeMenuItem); scalRecipeMenuItem.setText("Scale Recipe..."); scalRecipeMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_R, ActionEvent.CTRL_MASK)); scalRecipeMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { ScaleRecipeDialog scaleRecipe = new ScaleRecipeDialog(owner); scaleRecipe.setModal(true); scaleRecipe.setVisible(true); } }); JMenuItem maltPercentMenuItem = new JMenuItem(); mnuTools.add(maltPercentMenuItem); maltPercentMenuItem.setText("Malt Percent..."); maltPercentMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_M, ActionEvent.CTRL_MASK)); maltPercentMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { MaltPercentDialog maltPercent = new MaltPercentDialog(owner); maltPercent.setModal(true); maltPercent.setVisible(true); } }); } } { jMenu5 = new JMenu(); jMenuBar1.add(jMenu5); jMenu5.setText("Help"); { helpMenuItem = new JMenuItem(); jMenu5.add(helpMenuItem); helpMenuItem.setText("Help"); final JFrame owner = this; helpMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { URL help; try { help = new File(appRoot + "/help/index.html").toURL(); HTMLViewer view = new HTMLViewer(owner, help); view.setModal(true); view.setVisible(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); } { aboutMenuItem = new JMenuItem(); jMenu5.add(aboutMenuItem); aboutMenuItem.setText("About..."); final JFrame owner = this; aboutMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { aboutDlg = new AboutDialog(owner, version); aboutDlg.setVisible(true); } }); } } } } catch (Exception e) { e.printStackTrace(); } } |
|
tlbMalt.setPreferredSize(new java.awt.Dimension(55, 20)); | tlbMalt.setPreferredSize(new java.awt.Dimension(386, 20)); | private void initGUI() { try { // restore the saved size and location: this.setSize(preferences.getIProperty("winWidth"), preferences.getIProperty("winHeight")); this.setLocation(preferences.getIProperty("winX"), preferences.getIProperty("winY")); imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/brew.gif"); icon = new ImageIcon(imgURL); this.setIconImage(icon.getImage()); this.setTitle("StrangeBrew " + version); this.addWindowListener(new WindowAdapter() { public void windowClosed(WindowEvent evt) { System.exit(1); } }); { pnlMain = new JPanel(); GridBagLayout jPanel2Layout = new GridBagLayout(); jPanel2Layout.columnWeights = new double[]{0.1}; jPanel2Layout.columnWidths = new int[]{7}; jPanel2Layout.rowWeights = new double[]{0.1, 0.1, 0.9, 0.1}; jPanel2Layout.rowHeights = new int[]{7, 7, 7, 7}; pnlMain.setLayout(jPanel2Layout); this.getContentPane().add(pnlMain, BorderLayout.CENTER); { jTabbedPane1 = new JTabbedPane(); pnlMain.add(jTabbedPane1, new GridBagConstraints(0, 1, 1, 1, 0.1, 0.1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); { pnlDetails = new JPanel(); GridBagLayout pnlDetailsLayout = new GridBagLayout(); pnlDetailsLayout.columnWeights = new double[]{0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1}; pnlDetailsLayout.columnWidths = new int[]{7, 7, 7, 7, 7, 7, 7, 7, 7, 7}; pnlDetailsLayout.rowWeights = new double[]{0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1}; pnlDetailsLayout.rowHeights = new int[]{7, 7, 7, 7, 7, 7, 7}; pnlDetails.setLayout(pnlDetailsLayout); jTabbedPane1.addTab("Details", null, pnlDetails, null); pnlDetails.setPreferredSize(new java.awt.Dimension(20, 16)); { lblBrewer = new JLabel(); pnlDetails.add(lblBrewer, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblBrewer.setText("Brewer:"); } { brewerNameText = new JTextField(); pnlDetails.add(brewerNameText, new GridBagConstraints(1, 0, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); brewerNameText.setPreferredSize(new java.awt.Dimension(69, 20)); brewerNameText.setText("Brewer"); } { lblDate = new JLabel(); pnlDetails.add(lblDate, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblDate.setText("Date:"); } { lblStyle = new JLabel(); pnlDetails.add(lblStyle, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblStyle.setText("Style:"); } { lblYeast = new JLabel(); pnlDetails.add(lblYeast, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblYeast.setText("Yeast:"); } { lblPreBoil = new JLabel(); pnlDetails.add(lblPreBoil, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblPreBoil.setText("Pre boil:"); } { lblPostBoil = new JLabel(); pnlDetails.add(lblPostBoil, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblPostBoil.setText("Post boil:"); } { lblEffic = new JLabel(); pnlDetails.add(lblEffic, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblEffic.setText("Effic:"); lblEffic.setPreferredSize(new java.awt.Dimension(31, 14)); } { lblAtten = new JLabel(); pnlDetails.add(lblAtten, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblAtten.setText("Atten:"); lblAtten.setPreferredSize(new java.awt.Dimension(34, 14)); } { lblOG = new JLabel(); pnlDetails.add(lblOG, new GridBagConstraints(5, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblOG.setText("OG:"); } { lblFG = new JLabel(); pnlDetails.add(lblFG, new GridBagConstraints(5, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblFG.setText("FG:"); } { lblIBU = new JLabel(); pnlDetails.add(lblIBU, new GridBagConstraints(7, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblIBU.setText("IBU:"); } { lblAlc = new JLabel(); pnlDetails.add(lblAlc, new GridBagConstraints(7, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblAlc.setText("%Alc:"); } { lblColour = new JLabel(); pnlDetails.add(lblColour, new GridBagConstraints(7, 2, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblColour.setText("Colour:"); } { txtDate = new JFormattedTextField(); pnlDetails.add(txtDate, new GridBagConstraints(1, 1, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); txtDate.setText("Date"); txtDate.setPreferredSize(new java.awt.Dimension(73, 20)); } { cmbStyleModel = new ComboModel(); cmbStyle = new JComboBox(); pnlDetails.add(cmbStyle, new GridBagConstraints(1, 2, 5, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cmbStyle.setModel(cmbStyleModel); cmbStyle.setMaximumSize(new java.awt.Dimension(100, 32767)); cmbStyle.setPreferredSize(new java.awt.Dimension(190, 20)); } { txtPreBoil = new JFormattedTextField(); pnlDetails.add(txtPreBoil, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); txtPreBoil.setText("Pre Boil"); txtPreBoil.setPreferredSize(new java.awt.Dimension(37, 20)); } { postBoilText = new JFormattedTextField(); pnlDetails.add(postBoilText, new GridBagConstraints(1, 5, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); postBoilText.setText("Post Boil"); postBoilText.setPreferredSize(new java.awt.Dimension(46, 20)); } { lblComments = new JLabel(); pnlDetails.add(lblComments, new GridBagConstraints(6, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblComments.setText("Comments:"); } { SpinnerNumberModel spnEfficModel = new SpinnerNumberModel(75.0, 0.0, 100.0, 1.0); spnEffic = new JSpinner(); pnlDetails.add(spnEffic, new GridBagConstraints(4, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnEffic.setModel(spnEfficModel); spnEffic.setMaximumSize(new java.awt.Dimension(70, 32767)); spnEffic.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { myRecipe.setEfficiency(Double.parseDouble(spnEffic.getValue() .toString())); displayRecipe(); } }); spnEffic.setEditor(new JSpinner.NumberEditor(spnEffic, "00.#")); spnEffic.getEditor().setPreferredSize(new java.awt.Dimension(28, 16)); spnEffic.setPreferredSize(new java.awt.Dimension(53, 18)); } { SpinnerNumberModel spnAttenModel = new SpinnerNumberModel(75.0, 0.0, 100.0, 1.0); spnAtten = new JSpinner(); pnlDetails.add(spnAtten, new GridBagConstraints(4, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnAtten.setModel(spnAttenModel); spnAtten.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { myRecipe.setAttenuation(Double.parseDouble(spnAtten.getValue() .toString())); displayRecipe(); } }); spnAtten.setEditor(new JSpinner.NumberEditor(spnAtten, "00.#")); spnAtten.setPreferredSize(new java.awt.Dimension(49, 20)); } { SpinnerNumberModel spnOgModel = new SpinnerNumberModel(1.000, 0.900, 2.000, 0.001); spnOG = new JSpinner(); pnlDetails.add(spnOG, new GridBagConstraints(6, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnOG.setModel(spnOgModel); spnOG.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { myRecipe.setEstOg(Double.parseDouble(spnOG.getValue() .toString())); displayRecipe(); } }); spnOG.setEditor(new JSpinner.NumberEditor(spnOG, "0.000")); spnOG.getEditor().setPreferredSize(new java.awt.Dimension(20, 16)); spnOG.setPreferredSize(new java.awt.Dimension(67, 18)); } { SpinnerNumberModel spnFgModel = new SpinnerNumberModel(1.000, 0.900, 2.000, 0.001); spnFG = new JSpinner(); pnlDetails.add(spnFG, new GridBagConstraints(6, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnFG.setModel(spnFgModel); spnFG.setEditor(new JSpinner.NumberEditor(spnFG, "0.000")); spnFG.setPreferredSize(new java.awt.Dimension(69, 20)); spnFG.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { // set the new FG, and update alc: myRecipe.setEstFg(Double.parseDouble(spnFG.getValue() .toString())); displayRecipe(); } }); } { lblIBUvalue = new JLabel(); pnlDetails.add(lblIBUvalue, new GridBagConstraints(8, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblIBUvalue.setText("IBUs"); } { lblColourValue = new JLabel(); pnlDetails.add(lblColourValue, new GridBagConstraints(8, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblColourValue.setText("Colour"); } { lblAlcValue = new JLabel(); pnlDetails.add(lblAlcValue, new GridBagConstraints(8, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblAlcValue.setText("Alc"); } { scpComments = new JScrollPane(); pnlDetails.add(scpComments, new GridBagConstraints(7, 4, 3, 2, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); { txtComments = new JTextArea(); scpComments.setViewportView(txtComments); txtComments.setText("Comments"); txtComments.setWrapStyleWord(true); // txtComments.setPreferredSize(new java.awt.Dimension(117, 42)); txtComments.setLineWrap(true); txtComments.setPreferredSize(new java.awt.Dimension(263, 40)); txtComments.addFocusListener(new FocusAdapter() { public void focusLost(FocusEvent evt) { if (!txtComments.getText().equals(myRecipe.getComments())) { myRecipe.setComments(txtComments.getText()); } } }); } } { cmbYeastModel = new ComboModel(); cmbYeast = new JComboBox(); pnlDetails.add(cmbYeast, new GridBagConstraints(1, 3, 5, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cmbYeast.setModel(cmbYeastModel); cmbYeast.setPreferredSize(new java.awt.Dimension(193, 20)); } { cmbSizeUnitsModel = new ComboModel(); cmbSizeUnits = new JComboBox(); pnlDetails.add(cmbSizeUnits, new GridBagConstraints(2, 4, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cmbSizeUnits.setModel(cmbSizeUnitsModel); } { lblSizeUnits = new JLabel(); pnlDetails.add(lblSizeUnits, new GridBagConstraints(2, 5, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); lblSizeUnits.setText("Size Units"); } { boilTimeLable = new JLabel(); pnlDetails.add(boilTimeLable, new GridBagConstraints(4, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); boilTimeLable.setText("Boil Min:"); } { evapLabel = new JLabel(); pnlDetails.add(evapLabel, new GridBagConstraints(4, 5, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); evapLabel.setText("Evap/hr:"); } { boilMinText = new JTextField(); pnlDetails.add(boilMinText, new GridBagConstraints(5, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); boilMinText.setText("60"); boilMinText.setPreferredSize(new java.awt.Dimension(22, 20)); } { evapText = new JTextField(); pnlDetails.add(evapText, new GridBagConstraints(5, 5, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); evapText.setText("4"); evapText.setPreferredSize(new java.awt.Dimension(23, 20)); } { alcMethodComboModel = new DefaultComboBoxModel(new String[]{"Volume", "Weight"}); alcMethodCombo = new JComboBox(alcMethodComboModel); pnlDetails.add(alcMethodCombo, new GridBagConstraints(9, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); alcMethodCombo.setPreferredSize(new java.awt.Dimension(58, 20)); } { ibuMethodComboModel = new DefaultComboBoxModel(new String[]{"Tinseth", "Garetz", "Rager"}); ibuMethodCombo = new JComboBox(ibuMethodComboModel); pnlDetails.add(ibuMethodCombo, new GridBagConstraints(9, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); ibuMethodCombo.setPreferredSize(new java.awt.Dimension(59, 20)); } { colourMethodComboModel = new DefaultComboBoxModel(new String[]{"SRM", "EBC"}); colourMethodCombo = new JComboBox(colourMethodComboModel); pnlDetails.add(colourMethodCombo, new GridBagConstraints(9, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); colourMethodCombo.setPreferredSize(new java.awt.Dimension(44, 20)); } ComboBoxModel evapMethodComboModel = new DefaultComboBoxModel(new String[] { "Constant", "Percent" }); { jPanel1 = new JPanel(); pnlMain.add(jPanel1, new GridBagConstraints( 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); FlowLayout jPanel1Layout = new FlowLayout(); jPanel1Layout.setAlignment(FlowLayout.LEFT); jPanel1.setLayout(jPanel1Layout); jToolBar1 = new JToolBar(); getContentPane().add(jToolBar1, BorderLayout.NORTH); jToolBar1.setFloatable(false); jToolBar1.setRollover(true); jButton1 = new JButton(); jToolBar1.add(jButton1); jButton1.setMnemonic(java.awt.event.KeyEvent.VK_S); jButton1.setIcon(new ImageIcon(getClass().getClassLoader().getResource( "ca/strangebrew/icons/save.gif"))); jButton1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { System.out.println("jButton1.actionPerformed, event=" + evt); //TODO add your code for jButton1.actionPerformed } }); jButton2 = new JButton(); jToolBar1.add(jButton2); jButton2.setIcon(new ImageIcon(getClass().getClassLoader().getResource( "ca/strangebrew/icons/find.gif"))); jButton2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { System.out.println("jButton2.actionPerformed, event=" + evt); //TODO add your code for jButton2.actionPerformed } }); { lblName = new JLabel(); jPanel1.add(lblName); lblName.setText("Name:"); } { txtName = new JTextField(); jPanel1.add(txtName); txtName.setText("Name"); txtName.setPreferredSize(new java.awt.Dimension(297, 20)); } } evapMethodCombo = new JComboBox(); pnlDetails.add(evapMethodCombo, new GridBagConstraints(6, 5, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); evapMethodCombo.setModel(evapMethodComboModel); evapMethodCombo.setPreferredSize(new java.awt.Dimension(64, 20)); colourPanel = new JPanel(); pnlDetails.add(colourPanel, new GridBagConstraints(9, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); colourPanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); } { SBNotifier sbn = new SBNotifier(); stylePanel = new StylePanel(sbn); jTabbedPane1.addTab("Style", null, stylePanel, null); miscPanel = new MiscPanel(myRecipe); jTabbedPane1.addTab("Misc", null, miscPanel, null); notesPanel = new NotesPanel(); jTabbedPane1.addTab("Notes", null, notesPanel, null); dilutionPanel = new DilutionPanel(); jTabbedPane1.addTab("Dilution", null, dilutionPanel, null); mashPanel = new MashPanel(myRecipe); jTabbedPane1.addTab("Mash", null, mashPanel, null); waterPanel = new WaterPanel(); jTabbedPane1.addTab("Water", null, waterPanel, null); costPanel = new CostPanel(); jTabbedPane1.addTab("Cost", null, costPanel, null); // SBNotifier sbn = new SBNotifier(); settingsPanel = new SettingsPanel(sbn); jTabbedPane1.addTab("Settings", null, settingsPanel, null); } } { pnlTables = new JPanel(); BoxLayout pnlMaltsLayout = new BoxLayout(pnlTables, javax.swing.BoxLayout.Y_AXIS); pnlMain.add(pnlTables, new GridBagConstraints(0, 2, 1, 1, 0.5, 0.5, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); pnlTables.setLayout(pnlMaltsLayout); { pnlMalt = new JPanel(); pnlTables.add(pnlMalt); BorderLayout pnlMaltLayout1 = new BorderLayout(); pnlMalt.setBorder(BorderFactory.createTitledBorder(new LineBorder( new java.awt.Color(0, 0, 0), 1, false), "Fermentables", TitledBorder.LEADING, TitledBorder.TOP, new java.awt.Font("Dialog", 1, 12), new java.awt.Color(51, 51, 51))); pnlMalt.setLayout(pnlMaltLayout1); { jScrollPane1 = new JScrollPane(); pnlMalt.add(jScrollPane1, BorderLayout.CENTER); { maltTableModel = new MaltTableModel(this); maltTable = new JTable() { public String getToolTipText(MouseEvent e) { java.awt.Point p = e.getPoint(); int rowIndex = rowAtPoint(p); return SBStringUtils.multiLineToolTip(40, maltTableModel .getDescriptionAt(rowIndex)); } }; jScrollPane1.setViewportView(maltTable); maltTable.setModel(maltTableModel); // maltTable.setAutoCreateColumnsFromModel(false); maltTable.getTableHeader().setReorderingAllowed(false); TableColumn maltColumn = maltTable.getColumnModel().getColumn(0); // set up malt list combo maltComboBox = new JComboBox(); cmbMaltModel = new ComboModel(); maltComboBox.setModel(cmbMaltModel); maltColumn.setCellEditor(new DefaultCellEditor(maltComboBox)); // set up malt units combo maltUnitsComboBox = new JComboBox(); cmbMaltUnitsModel = new ComboModel(); maltUnitsComboBox.setModel(cmbMaltUnitsModel); maltColumn = maltTable.getColumnModel().getColumn(2); maltColumn.setCellEditor(new DefaultCellEditor(maltUnitsComboBox)); } } { tblMaltTotalsModel = new DefaultTableModel(new String[][]{{""}}, new String[]{"Malt", "Amount", "Units", "Points", "Lov", "Cost/U", "%"}); tblMaltTotals = new JTable(); pnlMalt.add(tblMaltTotals, BorderLayout.SOUTH); tblMaltTotals.setModel(tblMaltTotalsModel); tblMaltTotals.getTableHeader().setEnabled(false); tblMaltTotals.setAutoCreateColumnsFromModel(false); // set up the units combobox maltTotalUnitsComboBox = new JComboBox(); maltTotalUnitsComboModel = new ComboModel(); maltTotalUnitsComboModel.setList(new Quantity().getListofUnits("weight")); maltTotalUnitsComboBox.setModel(maltTotalUnitsComboModel); TableColumn t = tblMaltTotals.getColumnModel().getColumn(2); t.setCellEditor(new DefaultCellEditor(maltTotalUnitsComboBox)); maltTotalUnitsComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { String u = (String) maltTotalUnitsComboModel.getSelectedItem(); if (myRecipe != null) { myRecipe.setMaltUnits(u); displayRecipe(); } } }); } } { pnlMaltButtons = new JPanel(); pnlTables.add(pnlMaltButtons); FlowLayout pnlMaltButtonsLayout = new FlowLayout(); pnlMaltButtonsLayout.setAlignment(FlowLayout.LEFT); pnlMaltButtonsLayout.setVgap(0); pnlMaltButtons.setLayout(pnlMaltButtonsLayout); pnlMaltButtons.setPreferredSize(new java.awt.Dimension(592, 27)); { tlbMalt = new JToolBar(); pnlMaltButtons.add(tlbMalt); tlbMalt.setPreferredSize(new java.awt.Dimension(55, 20)); tlbMalt.setFloatable(false); { btnAddMalt = new JButton(); tlbMalt.add(btnAddMalt); btnAddMalt.setText("+"); btnAddMalt.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { Fermentable f = new Fermentable(myRecipe.getMaltUnits()); myRecipe.addMalt(f); maltTable.updateUI(); displayRecipe(); } } }); } { btnDelMalt = new JButton(); tlbMalt.add(btnDelMalt); btnDelMalt.setText("-"); btnDelMalt.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { int i = maltTable.getSelectedRow(); myRecipe.delMalt(i); maltTable.updateUI(); displayRecipe(); } } }); } } } { pnlHops = new JPanel(); BorderLayout pnlHopsLayout = new BorderLayout(); pnlHops.setBorder(BorderFactory.createTitledBorder(new LineBorder( new java.awt.Color(0, 0, 0), 1, false), "Hops", TitledBorder.LEADING, TitledBorder.TOP, new java.awt.Font("Dialog", 1, 12), new java.awt.Color(51, 51, 51))); pnlHops.setLayout(pnlHopsLayout); pnlTables.add(pnlHops); { tblHopsTotalsModel = new DefaultTableModel(new String[][]{{""}}, new String[]{"1", "2", "3", "4", "5", "6", "7", "8", "9"}); tblHopsTotals = new JTable(); pnlHops.add(tblHopsTotals, BorderLayout.SOUTH); tblHopsTotals.setModel(tblHopsTotalsModel); tblHopsTotals.setAutoCreateColumnsFromModel(false); // set up the units combobox hopsTotalUnitsComboBox = new JComboBox(); hopsTotalUnitsComboModel = new ComboModel(); hopsTotalUnitsComboModel.setList(new Quantity().getListofUnits("weight")); hopsTotalUnitsComboBox.setModel(hopsTotalUnitsComboModel); TableColumn t = tblHopsTotals.getColumnModel().getColumn(4); t.setCellEditor(new DefaultCellEditor(hopsTotalUnitsComboBox)); hopsTotalUnitsComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { String u = (String) hopsTotalUnitsComboModel.getSelectedItem(); if (myRecipe != null) { myRecipe.setHopsUnits(u); displayRecipe(); } } }); } { jScrollPane2 = new JScrollPane(); pnlHops.add(jScrollPane2, BorderLayout.CENTER); { hopsTableModel = new HopsTableModel(this); hopsTable = new JTable() { public String getToolTipText(MouseEvent e) { java.awt.Point p = e.getPoint(); int rowIndex = rowAtPoint(p); return SBStringUtils.multiLineToolTip(40, hopsTableModel .getDescriptionAt(rowIndex)); } }; jScrollPane2.setViewportView(hopsTable); hopsTable.setModel(hopsTableModel); hopsTable.getTableHeader().setReorderingAllowed(false); TableColumn hopColumn = hopsTable.getColumnModel().getColumn(0); hopComboBox = new JComboBox(); cmbHopsModel = new ComboModel(); hopComboBox.setModel(cmbHopsModel); hopColumn.setCellEditor(new DefaultCellEditor(hopComboBox)); // set up hop units combo hopsUnitsComboBox = new JComboBox(); cmbHopsUnitsModel = new ComboModel(); hopsUnitsComboBox.setModel(cmbHopsUnitsModel); hopColumn = hopsTable.getColumnModel().getColumn(4); hopColumn.setCellEditor(new DefaultCellEditor(hopsUnitsComboBox)); // set up hop type combo String[] forms = {"Leaf", "Pellet", "Plug"}; JComboBox hopsFormComboBox = new JComboBox(forms); hopColumn = hopsTable.getColumnModel().getColumn(1); hopColumn.setCellEditor(new DefaultCellEditor(hopsFormComboBox)); // set up hop add combo String[] add = {"Boil", "FWH", "Dry", "Mash"}; JComboBox hopsAddComboBox = new JComboBox(add); hopColumn = hopsTable.getColumnModel().getColumn(5); hopColumn.setCellEditor(new DefaultCellEditor(hopsAddComboBox)); } } } { pnlHopsButtons = new JPanel(); FlowLayout pnlHopsButtonsLayout = new FlowLayout(); pnlHopsButtonsLayout.setAlignment(FlowLayout.LEFT); pnlHopsButtonsLayout.setVgap(0); pnlHopsButtons.setLayout(pnlHopsButtonsLayout); pnlTables.add(pnlHopsButtons); pnlHopsButtons.setPreferredSize(new java.awt.Dimension(512, 16)); { tlbHops = new JToolBar(); pnlHopsButtons.add(tlbHops); tlbHops.setPreferredSize(new java.awt.Dimension(58, 19)); tlbHops.setFloatable(false); { btnAddHop = new JButton(); tlbHops.add(btnAddHop); btnAddHop.setText("+"); btnAddHop.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { Hop h = new Hop(myRecipe.getHopUnits()); myRecipe.addHop(h); hopsTable.updateUI(); displayRecipe(); } } }); } { btnDelHop = new JButton(); tlbHops.add(btnDelHop); btnDelHop.setText("-"); btnDelHop.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { int i = hopsTable.getSelectedRow(); myRecipe.delHop(i); hopsTable.updateUI(); displayRecipe(); } } }); } } } } { statusPanel = new JPanel(); FlowLayout statusPanelLayout = new FlowLayout(); statusPanelLayout.setAlignment(FlowLayout.LEFT); statusPanelLayout.setHgap(2); statusPanelLayout.setVgap(2); statusPanel.setLayout(statusPanelLayout); pnlMain.add(statusPanel, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); { fileNamePanel = new JPanel(); statusPanel.add(fileNamePanel); fileNamePanel.setBorder(BorderFactory .createBevelBorder(BevelBorder.LOWERED)); { fileNameLabel = new JLabel(); fileNamePanel.add(fileNameLabel); fileNameLabel.setText("File Name"); fileNameLabel.setFont(new java.awt.Font("Dialog", 1, 10)); } } { ibuMethodPanel = new JPanel(); statusPanel.add(ibuMethodPanel); ibuMethodPanel.setBorder(BorderFactory .createBevelBorder(BevelBorder.LOWERED)); { ibuMethodLabel = new JLabel(); ibuMethodPanel.add(ibuMethodLabel); ibuMethodLabel.setText("IBU Method:"); ibuMethodLabel.setFont(new java.awt.Font("Dialog", 1, 10)); } } { alcMethodPanel = new JPanel(); statusPanel.add(alcMethodPanel); alcMethodPanel.setBorder(BorderFactory .createBevelBorder(BevelBorder.LOWERED)); { alcMethodLabel = new JLabel(); alcMethodPanel.add(alcMethodLabel); alcMethodLabel.setText("Alc Method:"); alcMethodLabel.setFont(new java.awt.Font("Dialog", 1, 10)); } } } } { jMenuBar1 = new JMenuBar(); setJMenuBar(jMenuBar1); { fileMenu = new JMenu(); jMenuBar1.add(fileMenu); fileMenu.setText("File"); { newFileMenuItem = new JMenuItem(); fileMenu.add(newFileMenuItem); newFileMenuItem.setText("New"); newFileMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // This is just a test right now to see that // stuff is changed. myRecipe = new Recipe(); myRecipe.setVersion(version); currentFile = null; attachRecipeData(); displayRecipe(); } }); } { openFileMenuItem = new JMenuItem(); fileMenu.add(openFileMenuItem); openFileMenuItem.setText("Open"); openFileMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_O, ActionEvent.CTRL_MASK)); openFileMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Show open dialog; this method does // not return until the dialog is closed String[] ext = {"xml", "qbrew", "rec"}; String desc = "StrangBrew and importable formats"; sbFileFilter openFileFilter = new sbFileFilter(ext, desc); // fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); fileChooser.setFileFilter(openFileFilter); int returnVal = fileChooser.showOpenDialog(jMenuBar1); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); Debug.print("Opening: " + file.getName() + ".\n"); OpenImport oi = new OpenImport(); myRecipe = oi.openFile(file); if (oi.getFileType().equals("")){ JOptionPane.showMessageDialog( null, "The file you've tried to open isn't a recognized format. \n" + "You can open: \n" + "StrangeBrew 1.x and Java files (.xml)\n" + "QBrew files (.qbrew)\n" + "BeerXML files (.xml)\n" + "Promash files (.rec)", "Unrecognized Format!", JOptionPane.INFORMATION_MESSAGE); } if (oi.getFileType().equals("beerxml")){ JOptionPane.showMessageDialog( null, "The file you've opened is in BeerXML format. It may contain \n" + "several recipes. Only the first recipe is opened. Use the Find \n" + "dialog to open other recipes in a BeerXML file.", "BeerXML!", JOptionPane.INFORMATION_MESSAGE); } myRecipe.setVersion(version); myRecipe.calcMaltTotals(); myRecipe.calcHopsTotals(); myRecipe.mash.calcMashSchedule(); checkIngredientsInDB(); attachRecipeData(); currentFile = file; displayRecipe(); } else { Debug.print("Open command cancelled by user.\n"); } } }); } { imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/find.gif"); icon = new ImageIcon(imgURL); findFileMenuItem = new JMenuItem("Find", icon); findFileMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_F, ActionEvent.CTRL_MASK)); fileMenu.add(findFileMenuItem); final JFrame owner = this; findFileMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // open the find dialog FindDialog fd = new FindDialog(owner); fd.setVisible(true); } }); } { imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/save.gif"); icon = new ImageIcon(imgURL); saveMenuItem = new JMenuItem("Save", icon); fileMenu.add(saveMenuItem); saveMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_S, ActionEvent.CTRL_MASK)); saveMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { int choice = 1; if (currentFile != null) { File file = currentFile; //This is where a real application would save the file. try { FileWriter out = new FileWriter(file); out.write(myRecipe.toXML()); out.close(); Debug.print("Saved: " + file.getAbsoluteFile()); currentFile = file; } catch (Exception e) { showError(e); } } // prompt to save if not already saved else { choice = JOptionPane.showConfirmDialog(null, "File not saved. Do you wish to save it?", "File note saved", JOptionPane.YES_NO_OPTION); } if (choice == 0) { // same as save as: saveAs(); } } }); } { imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/saveas.gif"); icon = new ImageIcon(imgURL); saveAsMenuItem = new JMenuItem("Save As ...", icon); fileMenu.add(saveAsMenuItem); saveAsMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // This is just a test right now to see that // stuff is changed. Debug.print(myRecipe.toXML()); saveAs(); } }); } { exportMenu = new JMenu(); fileMenu.add(exportMenu); exportMenu.setText("Export"); { exportHTMLmenu = new JMenuItem(); exportMenu.add(exportHTMLmenu); exportHTMLmenu.setText("HTML"); exportHTMLmenu.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Show save dialog; this method does // not return until the dialog is closed String[] ext = {"html", "htm"}; sbFileFilter saveFileFilter = new sbFileFilter(ext, "HTML"); fileChooser.setFileFilter(saveFileFilter); fileChooser.setSelectedFile(new File(myRecipe.getName() + ".html")); int returnVal = fileChooser.showSaveDialog(jMenuBar1); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); //This is where a real application would save the file. try { saveAsHTML(file, "ca/strangebrew/data/recipeToHtml.xslt"); } catch (Exception e) { showError(e); } } else { Debug.print("Save command cancelled by user.\n"); } } }); exportTextMenuItem = new JMenuItem(); exportMenu.add(exportTextMenuItem); exportTextMenuItem.setText("Text"); exportTextMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Show save dialog; this method does // not return until the dialog is closed String[] ext = {"txt"}; sbFileFilter saveFileFilter = new sbFileFilter(ext, "Text"); fileChooser.setFileFilter(saveFileFilter); fileChooser.setSelectedFile(new File(myRecipe.getName() + ".txt")); int returnVal = fileChooser.showSaveDialog(jMenuBar1); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); //This is where a real application would save the file. try { FileWriter out = new FileWriter(file); out.write(myRecipe.toText()); out.close(); } catch (Exception e) { showError(e); } } else { Debug.print("Export text command cancelled by user.\n"); } } }); } } { JMenuItem clipboardMenuItem = new JMenuItem("Copy to Clipboard"); fileMenu.add(clipboardMenuItem); clipboardMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Copy current recipe to clipboard Clipboard clipboard = getToolkit ().getSystemClipboard (); StringSelection s = new StringSelection(myRecipe.toText()); clipboard.setContents(s, s); } }); JMenuItem printMenuItem = new JMenuItem("Print..."); fileMenu.add(printMenuItem); final JFrame owner = this; printMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Copy current recipe to clipboard// save file as xml, then transform it to html File tmp = new File("tmp.html"); try { saveAsHTML(tmp, "ca/strangebrew/data/recipeToSimpleHtml.xslt"); HTMLViewer view = new HTMLViewer(owner, tmp.toURL()); view.setModal(true); view.setVisible(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } tmp.delete(); } }); } { jSeparator2 = new JSeparator(); fileMenu.add(jSeparator2); } { exitMenuItem = new JMenuItem(); fileMenu.add(exitMenuItem); exitMenuItem.setText("Exit"); exitMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_Q, ActionEvent.CTRL_MASK)); final JFrame owner = this; exitMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // exit program processWindowEvent(new WindowEvent(owner,WindowEvent.WINDOW_CLOSING)); System.exit(0); } }); } } { jMenu4 = new JMenu(); jMenuBar1.add(jMenu4); jMenu4.setText("Edit"); { final JFrame owner = this; editPrefsMenuItem = new JMenuItem(); jMenu4.add(editPrefsMenuItem); editPrefsMenuItem.setText("Preferences..."); editPrefsMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { PreferencesDialog d = new PreferencesDialog(owner, preferences); d.setVisible(true); } }); } { jSeparator1 = new JSeparator(); jMenu4.add(jSeparator1); } { deleteMenuItem = new JMenuItem(); jMenu4.add(deleteMenuItem); deleteMenuItem.setText("Delete"); deleteMenuItem.setEnabled(false); } } { mnuTools = new JMenu(); jMenuBar1.add(mnuTools); mnuTools.setText("Tools"); { final JFrame owner = this; JMenuItem scalRecipeMenuItem = new JMenuItem(); mnuTools.add(scalRecipeMenuItem); scalRecipeMenuItem.setText("Scale Recipe..."); scalRecipeMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_R, ActionEvent.CTRL_MASK)); scalRecipeMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { ScaleRecipeDialog scaleRecipe = new ScaleRecipeDialog(owner); scaleRecipe.setModal(true); scaleRecipe.setVisible(true); } }); JMenuItem maltPercentMenuItem = new JMenuItem(); mnuTools.add(maltPercentMenuItem); maltPercentMenuItem.setText("Malt Percent..."); maltPercentMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_M, ActionEvent.CTRL_MASK)); maltPercentMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { MaltPercentDialog maltPercent = new MaltPercentDialog(owner); maltPercent.setModal(true); maltPercent.setVisible(true); } }); } } { jMenu5 = new JMenu(); jMenuBar1.add(jMenu5); jMenu5.setText("Help"); { helpMenuItem = new JMenuItem(); jMenu5.add(helpMenuItem); helpMenuItem.setText("Help"); final JFrame owner = this; helpMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { URL help; try { help = new File(appRoot + "/help/index.html").toURL(); HTMLViewer view = new HTMLViewer(owner, help); view.setModal(true); view.setVisible(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); } { aboutMenuItem = new JMenuItem(); jMenu5.add(aboutMenuItem); aboutMenuItem.setText("About..."); final JFrame owner = this; aboutMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { aboutDlg = new AboutDialog(owner, version); aboutDlg.setVisible(true); } }); } } } } catch (Exception e) { e.printStackTrace(); } } |
tlbHops.setPreferredSize(new java.awt.Dimension(58, 19)); | tlbHops.setPreferredSize(new java.awt.Dimension(413, 19)); | private void initGUI() { try { // restore the saved size and location: this.setSize(preferences.getIProperty("winWidth"), preferences.getIProperty("winHeight")); this.setLocation(preferences.getIProperty("winX"), preferences.getIProperty("winY")); imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/brew.gif"); icon = new ImageIcon(imgURL); this.setIconImage(icon.getImage()); this.setTitle("StrangeBrew " + version); this.addWindowListener(new WindowAdapter() { public void windowClosed(WindowEvent evt) { System.exit(1); } }); { pnlMain = new JPanel(); GridBagLayout jPanel2Layout = new GridBagLayout(); jPanel2Layout.columnWeights = new double[]{0.1}; jPanel2Layout.columnWidths = new int[]{7}; jPanel2Layout.rowWeights = new double[]{0.1, 0.1, 0.9, 0.1}; jPanel2Layout.rowHeights = new int[]{7, 7, 7, 7}; pnlMain.setLayout(jPanel2Layout); this.getContentPane().add(pnlMain, BorderLayout.CENTER); { jTabbedPane1 = new JTabbedPane(); pnlMain.add(jTabbedPane1, new GridBagConstraints(0, 1, 1, 1, 0.1, 0.1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); { pnlDetails = new JPanel(); GridBagLayout pnlDetailsLayout = new GridBagLayout(); pnlDetailsLayout.columnWeights = new double[]{0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1}; pnlDetailsLayout.columnWidths = new int[]{7, 7, 7, 7, 7, 7, 7, 7, 7, 7}; pnlDetailsLayout.rowWeights = new double[]{0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1}; pnlDetailsLayout.rowHeights = new int[]{7, 7, 7, 7, 7, 7, 7}; pnlDetails.setLayout(pnlDetailsLayout); jTabbedPane1.addTab("Details", null, pnlDetails, null); pnlDetails.setPreferredSize(new java.awt.Dimension(20, 16)); { lblBrewer = new JLabel(); pnlDetails.add(lblBrewer, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblBrewer.setText("Brewer:"); } { brewerNameText = new JTextField(); pnlDetails.add(brewerNameText, new GridBagConstraints(1, 0, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); brewerNameText.setPreferredSize(new java.awt.Dimension(69, 20)); brewerNameText.setText("Brewer"); } { lblDate = new JLabel(); pnlDetails.add(lblDate, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblDate.setText("Date:"); } { lblStyle = new JLabel(); pnlDetails.add(lblStyle, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblStyle.setText("Style:"); } { lblYeast = new JLabel(); pnlDetails.add(lblYeast, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblYeast.setText("Yeast:"); } { lblPreBoil = new JLabel(); pnlDetails.add(lblPreBoil, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblPreBoil.setText("Pre boil:"); } { lblPostBoil = new JLabel(); pnlDetails.add(lblPostBoil, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblPostBoil.setText("Post boil:"); } { lblEffic = new JLabel(); pnlDetails.add(lblEffic, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblEffic.setText("Effic:"); lblEffic.setPreferredSize(new java.awt.Dimension(31, 14)); } { lblAtten = new JLabel(); pnlDetails.add(lblAtten, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblAtten.setText("Atten:"); lblAtten.setPreferredSize(new java.awt.Dimension(34, 14)); } { lblOG = new JLabel(); pnlDetails.add(lblOG, new GridBagConstraints(5, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblOG.setText("OG:"); } { lblFG = new JLabel(); pnlDetails.add(lblFG, new GridBagConstraints(5, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblFG.setText("FG:"); } { lblIBU = new JLabel(); pnlDetails.add(lblIBU, new GridBagConstraints(7, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblIBU.setText("IBU:"); } { lblAlc = new JLabel(); pnlDetails.add(lblAlc, new GridBagConstraints(7, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblAlc.setText("%Alc:"); } { lblColour = new JLabel(); pnlDetails.add(lblColour, new GridBagConstraints(7, 2, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblColour.setText("Colour:"); } { txtDate = new JFormattedTextField(); pnlDetails.add(txtDate, new GridBagConstraints(1, 1, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); txtDate.setText("Date"); txtDate.setPreferredSize(new java.awt.Dimension(73, 20)); } { cmbStyleModel = new ComboModel(); cmbStyle = new JComboBox(); pnlDetails.add(cmbStyle, new GridBagConstraints(1, 2, 5, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cmbStyle.setModel(cmbStyleModel); cmbStyle.setMaximumSize(new java.awt.Dimension(100, 32767)); cmbStyle.setPreferredSize(new java.awt.Dimension(190, 20)); } { txtPreBoil = new JFormattedTextField(); pnlDetails.add(txtPreBoil, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); txtPreBoil.setText("Pre Boil"); txtPreBoil.setPreferredSize(new java.awt.Dimension(37, 20)); } { postBoilText = new JFormattedTextField(); pnlDetails.add(postBoilText, new GridBagConstraints(1, 5, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); postBoilText.setText("Post Boil"); postBoilText.setPreferredSize(new java.awt.Dimension(46, 20)); } { lblComments = new JLabel(); pnlDetails.add(lblComments, new GridBagConstraints(6, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblComments.setText("Comments:"); } { SpinnerNumberModel spnEfficModel = new SpinnerNumberModel(75.0, 0.0, 100.0, 1.0); spnEffic = new JSpinner(); pnlDetails.add(spnEffic, new GridBagConstraints(4, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnEffic.setModel(spnEfficModel); spnEffic.setMaximumSize(new java.awt.Dimension(70, 32767)); spnEffic.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { myRecipe.setEfficiency(Double.parseDouble(spnEffic.getValue() .toString())); displayRecipe(); } }); spnEffic.setEditor(new JSpinner.NumberEditor(spnEffic, "00.#")); spnEffic.getEditor().setPreferredSize(new java.awt.Dimension(28, 16)); spnEffic.setPreferredSize(new java.awt.Dimension(53, 18)); } { SpinnerNumberModel spnAttenModel = new SpinnerNumberModel(75.0, 0.0, 100.0, 1.0); spnAtten = new JSpinner(); pnlDetails.add(spnAtten, new GridBagConstraints(4, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnAtten.setModel(spnAttenModel); spnAtten.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { myRecipe.setAttenuation(Double.parseDouble(spnAtten.getValue() .toString())); displayRecipe(); } }); spnAtten.setEditor(new JSpinner.NumberEditor(spnAtten, "00.#")); spnAtten.setPreferredSize(new java.awt.Dimension(49, 20)); } { SpinnerNumberModel spnOgModel = new SpinnerNumberModel(1.000, 0.900, 2.000, 0.001); spnOG = new JSpinner(); pnlDetails.add(spnOG, new GridBagConstraints(6, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnOG.setModel(spnOgModel); spnOG.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { myRecipe.setEstOg(Double.parseDouble(spnOG.getValue() .toString())); displayRecipe(); } }); spnOG.setEditor(new JSpinner.NumberEditor(spnOG, "0.000")); spnOG.getEditor().setPreferredSize(new java.awt.Dimension(20, 16)); spnOG.setPreferredSize(new java.awt.Dimension(67, 18)); } { SpinnerNumberModel spnFgModel = new SpinnerNumberModel(1.000, 0.900, 2.000, 0.001); spnFG = new JSpinner(); pnlDetails.add(spnFG, new GridBagConstraints(6, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); spnFG.setModel(spnFgModel); spnFG.setEditor(new JSpinner.NumberEditor(spnFG, "0.000")); spnFG.setPreferredSize(new java.awt.Dimension(69, 20)); spnFG.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { // set the new FG, and update alc: myRecipe.setEstFg(Double.parseDouble(spnFG.getValue() .toString())); displayRecipe(); } }); } { lblIBUvalue = new JLabel(); pnlDetails.add(lblIBUvalue, new GridBagConstraints(8, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblIBUvalue.setText("IBUs"); } { lblColourValue = new JLabel(); pnlDetails.add(lblColourValue, new GridBagConstraints(8, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblColourValue.setText("Colour"); } { lblAlcValue = new JLabel(); pnlDetails.add(lblAlcValue, new GridBagConstraints(8, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); lblAlcValue.setText("Alc"); } { scpComments = new JScrollPane(); pnlDetails.add(scpComments, new GridBagConstraints(7, 4, 3, 2, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); { txtComments = new JTextArea(); scpComments.setViewportView(txtComments); txtComments.setText("Comments"); txtComments.setWrapStyleWord(true); // txtComments.setPreferredSize(new java.awt.Dimension(117, 42)); txtComments.setLineWrap(true); txtComments.setPreferredSize(new java.awt.Dimension(263, 40)); txtComments.addFocusListener(new FocusAdapter() { public void focusLost(FocusEvent evt) { if (!txtComments.getText().equals(myRecipe.getComments())) { myRecipe.setComments(txtComments.getText()); } } }); } } { cmbYeastModel = new ComboModel(); cmbYeast = new JComboBox(); pnlDetails.add(cmbYeast, new GridBagConstraints(1, 3, 5, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cmbYeast.setModel(cmbYeastModel); cmbYeast.setPreferredSize(new java.awt.Dimension(193, 20)); } { cmbSizeUnitsModel = new ComboModel(); cmbSizeUnits = new JComboBox(); pnlDetails.add(cmbSizeUnits, new GridBagConstraints(2, 4, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cmbSizeUnits.setModel(cmbSizeUnitsModel); } { lblSizeUnits = new JLabel(); pnlDetails.add(lblSizeUnits, new GridBagConstraints(2, 5, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); lblSizeUnits.setText("Size Units"); } { boilTimeLable = new JLabel(); pnlDetails.add(boilTimeLable, new GridBagConstraints(4, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); boilTimeLable.setText("Boil Min:"); } { evapLabel = new JLabel(); pnlDetails.add(evapLabel, new GridBagConstraints(4, 5, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); evapLabel.setText("Evap/hr:"); } { boilMinText = new JTextField(); pnlDetails.add(boilMinText, new GridBagConstraints(5, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); boilMinText.setText("60"); boilMinText.setPreferredSize(new java.awt.Dimension(22, 20)); } { evapText = new JTextField(); pnlDetails.add(evapText, new GridBagConstraints(5, 5, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); evapText.setText("4"); evapText.setPreferredSize(new java.awt.Dimension(23, 20)); } { alcMethodComboModel = new DefaultComboBoxModel(new String[]{"Volume", "Weight"}); alcMethodCombo = new JComboBox(alcMethodComboModel); pnlDetails.add(alcMethodCombo, new GridBagConstraints(9, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); alcMethodCombo.setPreferredSize(new java.awt.Dimension(58, 20)); } { ibuMethodComboModel = new DefaultComboBoxModel(new String[]{"Tinseth", "Garetz", "Rager"}); ibuMethodCombo = new JComboBox(ibuMethodComboModel); pnlDetails.add(ibuMethodCombo, new GridBagConstraints(9, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); ibuMethodCombo.setPreferredSize(new java.awt.Dimension(59, 20)); } { colourMethodComboModel = new DefaultComboBoxModel(new String[]{"SRM", "EBC"}); colourMethodCombo = new JComboBox(colourMethodComboModel); pnlDetails.add(colourMethodCombo, new GridBagConstraints(9, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); colourMethodCombo.setPreferredSize(new java.awt.Dimension(44, 20)); } ComboBoxModel evapMethodComboModel = new DefaultComboBoxModel(new String[] { "Constant", "Percent" }); { jPanel1 = new JPanel(); pnlMain.add(jPanel1, new GridBagConstraints( 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); FlowLayout jPanel1Layout = new FlowLayout(); jPanel1Layout.setAlignment(FlowLayout.LEFT); jPanel1.setLayout(jPanel1Layout); jToolBar1 = new JToolBar(); getContentPane().add(jToolBar1, BorderLayout.NORTH); jToolBar1.setFloatable(false); jToolBar1.setRollover(true); jButton1 = new JButton(); jToolBar1.add(jButton1); jButton1.setMnemonic(java.awt.event.KeyEvent.VK_S); jButton1.setIcon(new ImageIcon(getClass().getClassLoader().getResource( "ca/strangebrew/icons/save.gif"))); jButton1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { System.out.println("jButton1.actionPerformed, event=" + evt); //TODO add your code for jButton1.actionPerformed } }); jButton2 = new JButton(); jToolBar1.add(jButton2); jButton2.setIcon(new ImageIcon(getClass().getClassLoader().getResource( "ca/strangebrew/icons/find.gif"))); jButton2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { System.out.println("jButton2.actionPerformed, event=" + evt); //TODO add your code for jButton2.actionPerformed } }); { lblName = new JLabel(); jPanel1.add(lblName); lblName.setText("Name:"); } { txtName = new JTextField(); jPanel1.add(txtName); txtName.setText("Name"); txtName.setPreferredSize(new java.awt.Dimension(297, 20)); } } evapMethodCombo = new JComboBox(); pnlDetails.add(evapMethodCombo, new GridBagConstraints(6, 5, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); evapMethodCombo.setModel(evapMethodComboModel); evapMethodCombo.setPreferredSize(new java.awt.Dimension(64, 20)); colourPanel = new JPanel(); pnlDetails.add(colourPanel, new GridBagConstraints(9, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); colourPanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); } { SBNotifier sbn = new SBNotifier(); stylePanel = new StylePanel(sbn); jTabbedPane1.addTab("Style", null, stylePanel, null); miscPanel = new MiscPanel(myRecipe); jTabbedPane1.addTab("Misc", null, miscPanel, null); notesPanel = new NotesPanel(); jTabbedPane1.addTab("Notes", null, notesPanel, null); dilutionPanel = new DilutionPanel(); jTabbedPane1.addTab("Dilution", null, dilutionPanel, null); mashPanel = new MashPanel(myRecipe); jTabbedPane1.addTab("Mash", null, mashPanel, null); waterPanel = new WaterPanel(); jTabbedPane1.addTab("Water", null, waterPanel, null); costPanel = new CostPanel(); jTabbedPane1.addTab("Cost", null, costPanel, null); // SBNotifier sbn = new SBNotifier(); settingsPanel = new SettingsPanel(sbn); jTabbedPane1.addTab("Settings", null, settingsPanel, null); } } { pnlTables = new JPanel(); BoxLayout pnlMaltsLayout = new BoxLayout(pnlTables, javax.swing.BoxLayout.Y_AXIS); pnlMain.add(pnlTables, new GridBagConstraints(0, 2, 1, 1, 0.5, 0.5, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); pnlTables.setLayout(pnlMaltsLayout); { pnlMalt = new JPanel(); pnlTables.add(pnlMalt); BorderLayout pnlMaltLayout1 = new BorderLayout(); pnlMalt.setBorder(BorderFactory.createTitledBorder(new LineBorder( new java.awt.Color(0, 0, 0), 1, false), "Fermentables", TitledBorder.LEADING, TitledBorder.TOP, new java.awt.Font("Dialog", 1, 12), new java.awt.Color(51, 51, 51))); pnlMalt.setLayout(pnlMaltLayout1); { jScrollPane1 = new JScrollPane(); pnlMalt.add(jScrollPane1, BorderLayout.CENTER); { maltTableModel = new MaltTableModel(this); maltTable = new JTable() { public String getToolTipText(MouseEvent e) { java.awt.Point p = e.getPoint(); int rowIndex = rowAtPoint(p); return SBStringUtils.multiLineToolTip(40, maltTableModel .getDescriptionAt(rowIndex)); } }; jScrollPane1.setViewportView(maltTable); maltTable.setModel(maltTableModel); // maltTable.setAutoCreateColumnsFromModel(false); maltTable.getTableHeader().setReorderingAllowed(false); TableColumn maltColumn = maltTable.getColumnModel().getColumn(0); // set up malt list combo maltComboBox = new JComboBox(); cmbMaltModel = new ComboModel(); maltComboBox.setModel(cmbMaltModel); maltColumn.setCellEditor(new DefaultCellEditor(maltComboBox)); // set up malt units combo maltUnitsComboBox = new JComboBox(); cmbMaltUnitsModel = new ComboModel(); maltUnitsComboBox.setModel(cmbMaltUnitsModel); maltColumn = maltTable.getColumnModel().getColumn(2); maltColumn.setCellEditor(new DefaultCellEditor(maltUnitsComboBox)); } } { tblMaltTotalsModel = new DefaultTableModel(new String[][]{{""}}, new String[]{"Malt", "Amount", "Units", "Points", "Lov", "Cost/U", "%"}); tblMaltTotals = new JTable(); pnlMalt.add(tblMaltTotals, BorderLayout.SOUTH); tblMaltTotals.setModel(tblMaltTotalsModel); tblMaltTotals.getTableHeader().setEnabled(false); tblMaltTotals.setAutoCreateColumnsFromModel(false); // set up the units combobox maltTotalUnitsComboBox = new JComboBox(); maltTotalUnitsComboModel = new ComboModel(); maltTotalUnitsComboModel.setList(new Quantity().getListofUnits("weight")); maltTotalUnitsComboBox.setModel(maltTotalUnitsComboModel); TableColumn t = tblMaltTotals.getColumnModel().getColumn(2); t.setCellEditor(new DefaultCellEditor(maltTotalUnitsComboBox)); maltTotalUnitsComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { String u = (String) maltTotalUnitsComboModel.getSelectedItem(); if (myRecipe != null) { myRecipe.setMaltUnits(u); displayRecipe(); } } }); } } { pnlMaltButtons = new JPanel(); pnlTables.add(pnlMaltButtons); FlowLayout pnlMaltButtonsLayout = new FlowLayout(); pnlMaltButtonsLayout.setAlignment(FlowLayout.LEFT); pnlMaltButtonsLayout.setVgap(0); pnlMaltButtons.setLayout(pnlMaltButtonsLayout); pnlMaltButtons.setPreferredSize(new java.awt.Dimension(592, 27)); { tlbMalt = new JToolBar(); pnlMaltButtons.add(tlbMalt); tlbMalt.setPreferredSize(new java.awt.Dimension(55, 20)); tlbMalt.setFloatable(false); { btnAddMalt = new JButton(); tlbMalt.add(btnAddMalt); btnAddMalt.setText("+"); btnAddMalt.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { Fermentable f = new Fermentable(myRecipe.getMaltUnits()); myRecipe.addMalt(f); maltTable.updateUI(); displayRecipe(); } } }); } { btnDelMalt = new JButton(); tlbMalt.add(btnDelMalt); btnDelMalt.setText("-"); btnDelMalt.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { int i = maltTable.getSelectedRow(); myRecipe.delMalt(i); maltTable.updateUI(); displayRecipe(); } } }); } } } { pnlHops = new JPanel(); BorderLayout pnlHopsLayout = new BorderLayout(); pnlHops.setBorder(BorderFactory.createTitledBorder(new LineBorder( new java.awt.Color(0, 0, 0), 1, false), "Hops", TitledBorder.LEADING, TitledBorder.TOP, new java.awt.Font("Dialog", 1, 12), new java.awt.Color(51, 51, 51))); pnlHops.setLayout(pnlHopsLayout); pnlTables.add(pnlHops); { tblHopsTotalsModel = new DefaultTableModel(new String[][]{{""}}, new String[]{"1", "2", "3", "4", "5", "6", "7", "8", "9"}); tblHopsTotals = new JTable(); pnlHops.add(tblHopsTotals, BorderLayout.SOUTH); tblHopsTotals.setModel(tblHopsTotalsModel); tblHopsTotals.setAutoCreateColumnsFromModel(false); // set up the units combobox hopsTotalUnitsComboBox = new JComboBox(); hopsTotalUnitsComboModel = new ComboModel(); hopsTotalUnitsComboModel.setList(new Quantity().getListofUnits("weight")); hopsTotalUnitsComboBox.setModel(hopsTotalUnitsComboModel); TableColumn t = tblHopsTotals.getColumnModel().getColumn(4); t.setCellEditor(new DefaultCellEditor(hopsTotalUnitsComboBox)); hopsTotalUnitsComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { String u = (String) hopsTotalUnitsComboModel.getSelectedItem(); if (myRecipe != null) { myRecipe.setHopsUnits(u); displayRecipe(); } } }); } { jScrollPane2 = new JScrollPane(); pnlHops.add(jScrollPane2, BorderLayout.CENTER); { hopsTableModel = new HopsTableModel(this); hopsTable = new JTable() { public String getToolTipText(MouseEvent e) { java.awt.Point p = e.getPoint(); int rowIndex = rowAtPoint(p); return SBStringUtils.multiLineToolTip(40, hopsTableModel .getDescriptionAt(rowIndex)); } }; jScrollPane2.setViewportView(hopsTable); hopsTable.setModel(hopsTableModel); hopsTable.getTableHeader().setReorderingAllowed(false); TableColumn hopColumn = hopsTable.getColumnModel().getColumn(0); hopComboBox = new JComboBox(); cmbHopsModel = new ComboModel(); hopComboBox.setModel(cmbHopsModel); hopColumn.setCellEditor(new DefaultCellEditor(hopComboBox)); // set up hop units combo hopsUnitsComboBox = new JComboBox(); cmbHopsUnitsModel = new ComboModel(); hopsUnitsComboBox.setModel(cmbHopsUnitsModel); hopColumn = hopsTable.getColumnModel().getColumn(4); hopColumn.setCellEditor(new DefaultCellEditor(hopsUnitsComboBox)); // set up hop type combo String[] forms = {"Leaf", "Pellet", "Plug"}; JComboBox hopsFormComboBox = new JComboBox(forms); hopColumn = hopsTable.getColumnModel().getColumn(1); hopColumn.setCellEditor(new DefaultCellEditor(hopsFormComboBox)); // set up hop add combo String[] add = {"Boil", "FWH", "Dry", "Mash"}; JComboBox hopsAddComboBox = new JComboBox(add); hopColumn = hopsTable.getColumnModel().getColumn(5); hopColumn.setCellEditor(new DefaultCellEditor(hopsAddComboBox)); } } } { pnlHopsButtons = new JPanel(); FlowLayout pnlHopsButtonsLayout = new FlowLayout(); pnlHopsButtonsLayout.setAlignment(FlowLayout.LEFT); pnlHopsButtonsLayout.setVgap(0); pnlHopsButtons.setLayout(pnlHopsButtonsLayout); pnlTables.add(pnlHopsButtons); pnlHopsButtons.setPreferredSize(new java.awt.Dimension(512, 16)); { tlbHops = new JToolBar(); pnlHopsButtons.add(tlbHops); tlbHops.setPreferredSize(new java.awt.Dimension(58, 19)); tlbHops.setFloatable(false); { btnAddHop = new JButton(); tlbHops.add(btnAddHop); btnAddHop.setText("+"); btnAddHop.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { Hop h = new Hop(myRecipe.getHopUnits()); myRecipe.addHop(h); hopsTable.updateUI(); displayRecipe(); } } }); } { btnDelHop = new JButton(); tlbHops.add(btnDelHop); btnDelHop.setText("-"); btnDelHop.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (myRecipe != null) { int i = hopsTable.getSelectedRow(); myRecipe.delHop(i); hopsTable.updateUI(); displayRecipe(); } } }); } } } } { statusPanel = new JPanel(); FlowLayout statusPanelLayout = new FlowLayout(); statusPanelLayout.setAlignment(FlowLayout.LEFT); statusPanelLayout.setHgap(2); statusPanelLayout.setVgap(2); statusPanel.setLayout(statusPanelLayout); pnlMain.add(statusPanel, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); { fileNamePanel = new JPanel(); statusPanel.add(fileNamePanel); fileNamePanel.setBorder(BorderFactory .createBevelBorder(BevelBorder.LOWERED)); { fileNameLabel = new JLabel(); fileNamePanel.add(fileNameLabel); fileNameLabel.setText("File Name"); fileNameLabel.setFont(new java.awt.Font("Dialog", 1, 10)); } } { ibuMethodPanel = new JPanel(); statusPanel.add(ibuMethodPanel); ibuMethodPanel.setBorder(BorderFactory .createBevelBorder(BevelBorder.LOWERED)); { ibuMethodLabel = new JLabel(); ibuMethodPanel.add(ibuMethodLabel); ibuMethodLabel.setText("IBU Method:"); ibuMethodLabel.setFont(new java.awt.Font("Dialog", 1, 10)); } } { alcMethodPanel = new JPanel(); statusPanel.add(alcMethodPanel); alcMethodPanel.setBorder(BorderFactory .createBevelBorder(BevelBorder.LOWERED)); { alcMethodLabel = new JLabel(); alcMethodPanel.add(alcMethodLabel); alcMethodLabel.setText("Alc Method:"); alcMethodLabel.setFont(new java.awt.Font("Dialog", 1, 10)); } } } } { jMenuBar1 = new JMenuBar(); setJMenuBar(jMenuBar1); { fileMenu = new JMenu(); jMenuBar1.add(fileMenu); fileMenu.setText("File"); { newFileMenuItem = new JMenuItem(); fileMenu.add(newFileMenuItem); newFileMenuItem.setText("New"); newFileMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // This is just a test right now to see that // stuff is changed. myRecipe = new Recipe(); myRecipe.setVersion(version); currentFile = null; attachRecipeData(); displayRecipe(); } }); } { openFileMenuItem = new JMenuItem(); fileMenu.add(openFileMenuItem); openFileMenuItem.setText("Open"); openFileMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_O, ActionEvent.CTRL_MASK)); openFileMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Show open dialog; this method does // not return until the dialog is closed String[] ext = {"xml", "qbrew", "rec"}; String desc = "StrangBrew and importable formats"; sbFileFilter openFileFilter = new sbFileFilter(ext, desc); // fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); fileChooser.setFileFilter(openFileFilter); int returnVal = fileChooser.showOpenDialog(jMenuBar1); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); Debug.print("Opening: " + file.getName() + ".\n"); OpenImport oi = new OpenImport(); myRecipe = oi.openFile(file); if (oi.getFileType().equals("")){ JOptionPane.showMessageDialog( null, "The file you've tried to open isn't a recognized format. \n" + "You can open: \n" + "StrangeBrew 1.x and Java files (.xml)\n" + "QBrew files (.qbrew)\n" + "BeerXML files (.xml)\n" + "Promash files (.rec)", "Unrecognized Format!", JOptionPane.INFORMATION_MESSAGE); } if (oi.getFileType().equals("beerxml")){ JOptionPane.showMessageDialog( null, "The file you've opened is in BeerXML format. It may contain \n" + "several recipes. Only the first recipe is opened. Use the Find \n" + "dialog to open other recipes in a BeerXML file.", "BeerXML!", JOptionPane.INFORMATION_MESSAGE); } myRecipe.setVersion(version); myRecipe.calcMaltTotals(); myRecipe.calcHopsTotals(); myRecipe.mash.calcMashSchedule(); checkIngredientsInDB(); attachRecipeData(); currentFile = file; displayRecipe(); } else { Debug.print("Open command cancelled by user.\n"); } } }); } { imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/find.gif"); icon = new ImageIcon(imgURL); findFileMenuItem = new JMenuItem("Find", icon); findFileMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_F, ActionEvent.CTRL_MASK)); fileMenu.add(findFileMenuItem); final JFrame owner = this; findFileMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // open the find dialog FindDialog fd = new FindDialog(owner); fd.setVisible(true); } }); } { imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/save.gif"); icon = new ImageIcon(imgURL); saveMenuItem = new JMenuItem("Save", icon); fileMenu.add(saveMenuItem); saveMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_S, ActionEvent.CTRL_MASK)); saveMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { int choice = 1; if (currentFile != null) { File file = currentFile; //This is where a real application would save the file. try { FileWriter out = new FileWriter(file); out.write(myRecipe.toXML()); out.close(); Debug.print("Saved: " + file.getAbsoluteFile()); currentFile = file; } catch (Exception e) { showError(e); } } // prompt to save if not already saved else { choice = JOptionPane.showConfirmDialog(null, "File not saved. Do you wish to save it?", "File note saved", JOptionPane.YES_NO_OPTION); } if (choice == 0) { // same as save as: saveAs(); } } }); } { imgURL = getClass().getClassLoader().getResource("ca/strangebrew/icons/saveas.gif"); icon = new ImageIcon(imgURL); saveAsMenuItem = new JMenuItem("Save As ...", icon); fileMenu.add(saveAsMenuItem); saveAsMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // This is just a test right now to see that // stuff is changed. Debug.print(myRecipe.toXML()); saveAs(); } }); } { exportMenu = new JMenu(); fileMenu.add(exportMenu); exportMenu.setText("Export"); { exportHTMLmenu = new JMenuItem(); exportMenu.add(exportHTMLmenu); exportHTMLmenu.setText("HTML"); exportHTMLmenu.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Show save dialog; this method does // not return until the dialog is closed String[] ext = {"html", "htm"}; sbFileFilter saveFileFilter = new sbFileFilter(ext, "HTML"); fileChooser.setFileFilter(saveFileFilter); fileChooser.setSelectedFile(new File(myRecipe.getName() + ".html")); int returnVal = fileChooser.showSaveDialog(jMenuBar1); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); //This is where a real application would save the file. try { saveAsHTML(file, "ca/strangebrew/data/recipeToHtml.xslt"); } catch (Exception e) { showError(e); } } else { Debug.print("Save command cancelled by user.\n"); } } }); exportTextMenuItem = new JMenuItem(); exportMenu.add(exportTextMenuItem); exportTextMenuItem.setText("Text"); exportTextMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Show save dialog; this method does // not return until the dialog is closed String[] ext = {"txt"}; sbFileFilter saveFileFilter = new sbFileFilter(ext, "Text"); fileChooser.setFileFilter(saveFileFilter); fileChooser.setSelectedFile(new File(myRecipe.getName() + ".txt")); int returnVal = fileChooser.showSaveDialog(jMenuBar1); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); //This is where a real application would save the file. try { FileWriter out = new FileWriter(file); out.write(myRecipe.toText()); out.close(); } catch (Exception e) { showError(e); } } else { Debug.print("Export text command cancelled by user.\n"); } } }); } } { JMenuItem clipboardMenuItem = new JMenuItem("Copy to Clipboard"); fileMenu.add(clipboardMenuItem); clipboardMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Copy current recipe to clipboard Clipboard clipboard = getToolkit ().getSystemClipboard (); StringSelection s = new StringSelection(myRecipe.toText()); clipboard.setContents(s, s); } }); JMenuItem printMenuItem = new JMenuItem("Print..."); fileMenu.add(printMenuItem); final JFrame owner = this; printMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Copy current recipe to clipboard// save file as xml, then transform it to html File tmp = new File("tmp.html"); try { saveAsHTML(tmp, "ca/strangebrew/data/recipeToSimpleHtml.xslt"); HTMLViewer view = new HTMLViewer(owner, tmp.toURL()); view.setModal(true); view.setVisible(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } tmp.delete(); } }); } { jSeparator2 = new JSeparator(); fileMenu.add(jSeparator2); } { exitMenuItem = new JMenuItem(); fileMenu.add(exitMenuItem); exitMenuItem.setText("Exit"); exitMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_Q, ActionEvent.CTRL_MASK)); final JFrame owner = this; exitMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // exit program processWindowEvent(new WindowEvent(owner,WindowEvent.WINDOW_CLOSING)); System.exit(0); } }); } } { jMenu4 = new JMenu(); jMenuBar1.add(jMenu4); jMenu4.setText("Edit"); { final JFrame owner = this; editPrefsMenuItem = new JMenuItem(); jMenu4.add(editPrefsMenuItem); editPrefsMenuItem.setText("Preferences..."); editPrefsMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { PreferencesDialog d = new PreferencesDialog(owner, preferences); d.setVisible(true); } }); } { jSeparator1 = new JSeparator(); jMenu4.add(jSeparator1); } { deleteMenuItem = new JMenuItem(); jMenu4.add(deleteMenuItem); deleteMenuItem.setText("Delete"); deleteMenuItem.setEnabled(false); } } { mnuTools = new JMenu(); jMenuBar1.add(mnuTools); mnuTools.setText("Tools"); { final JFrame owner = this; JMenuItem scalRecipeMenuItem = new JMenuItem(); mnuTools.add(scalRecipeMenuItem); scalRecipeMenuItem.setText("Scale Recipe..."); scalRecipeMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_R, ActionEvent.CTRL_MASK)); scalRecipeMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { ScaleRecipeDialog scaleRecipe = new ScaleRecipeDialog(owner); scaleRecipe.setModal(true); scaleRecipe.setVisible(true); } }); JMenuItem maltPercentMenuItem = new JMenuItem(); mnuTools.add(maltPercentMenuItem); maltPercentMenuItem.setText("Malt Percent..."); maltPercentMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_M, ActionEvent.CTRL_MASK)); maltPercentMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { MaltPercentDialog maltPercent = new MaltPercentDialog(owner); maltPercent.setModal(true); maltPercent.setVisible(true); } }); } } { jMenu5 = new JMenu(); jMenuBar1.add(jMenu5); jMenu5.setText("Help"); { helpMenuItem = new JMenuItem(); jMenu5.add(helpMenuItem); helpMenuItem.setText("Help"); final JFrame owner = this; helpMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { URL help; try { help = new File(appRoot + "/help/index.html").toURL(); HTMLViewer view = new HTMLViewer(owner, help); view.setModal(true); view.setVisible(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); } { aboutMenuItem = new JMenuItem(); jMenu5.add(aboutMenuItem); aboutMenuItem.setText("About..."); final JFrame owner = this; aboutMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { aboutDlg = new AboutDialog(owner, version); aboutDlg.setVisible(true); } }); } } } } catch (Exception e) { e.printStackTrace(); } } |
for( AbstractTestResultAction a=this; a!=null; a=a.getPreviousResult() ) { | for( AbstractTestResultAction<?> a=this; a!=null; a=a.getPreviousResult(AbstractTestResultAction.class) ) { | public void doGraph( StaplerRequest req, StaplerResponse rsp) throws IOException { if(awtProblem) { // not available. send out error message rsp.sendRedirect2(req.getContextPath()+"/images/headless.png"); return; } try { if(req.checkIfModified(owner.getTimestamp(),rsp)) return; class BuildLabel implements Comparable<BuildLabel> { private final Build build; public BuildLabel(Build build) { this.build = build; } public int compareTo(BuildLabel that) { return this.build.number-that.build.number; } public boolean equals(Object o) { BuildLabel that = (BuildLabel) o; return build==that.build; } public int hashCode() { return build.hashCode(); } public String toString() { return build.getDisplayName(); } } boolean failureOnly = Boolean.valueOf(req.getParameter("failureOnly")); DataSetBuilder<String,BuildLabel> dsb = new DataSetBuilder<String,BuildLabel>(); for( AbstractTestResultAction a=this; a!=null; a=a.getPreviousResult() ) { dsb.add( a.getFailCount(), "failed", new BuildLabel(a.owner)); if(!failureOnly) dsb.add( a.getTotalCount()-a.getFailCount(),"total", new BuildLabel(a.owner)); } String w = req.getParameter("width"); if(w==null) w="500"; String h = req.getParameter("height"); if(h==null) h="200"; BufferedImage image = createChart(dsb.build()).createBufferedImage(Integer.parseInt(w),Integer.parseInt(h)); rsp.setContentType("image/png"); ServletOutputStream os = rsp.getOutputStream(); ImageIO.write(image, "PNG", os); os.close(); } catch(HeadlessException e) { // not available. send out error message rsp.sendRedirect2(req.getContextPath()+"/images/headless.png"); } } |
Build b = owner; while(true) { b = b.getPreviousBuild(); if(b==null) return null; if(b.getResult()== Result.FAILURE) continue; T r = (T)b.getAction(getClass()); if(r!=null) return r; } | return (T)getPreviousResult(getClass()); | public T getPreviousResult() { Build b = owner; while(true) { b = b.getPreviousBuild(); if(b==null) return null; if(b.getResult()== Result.FAILURE) continue; T r = (T)b.getAction(getClass()); if(r!=null) return r; } } |
public <T extends Action> T getAction(Class<T> type) { for (Action a : getActions()) { if(type.isInstance(a)) return (T)a; } return null; | public Action getAction(int index) { if(actions==null) return null; return actions.get(index); | public <T extends Action> T getAction(Class<T> type) { for (Action a : getActions()) { if(type.isInstance(a)) return (T)a; // type.cast() not available in JDK 1.4 } return null; } |
QueryResponseRecord rec; | public void processResponse( QueryResponseMsg msg ) { //we like to receive results even if the query was stopped already. // check if it is a response for this query? if (!msg.getHeader().getMsgID().equals( queryMsg.getHeader().getMsgID())) { return; } // remoteHost.log("Got response to my query. " + msg); long speed = msg.getRemoteHostSpeed(); GUID rcID = msg.getRemoteClientID(); DestAddress address = msg.getDestAddress(); QueryHitHost qhHost = new QueryHitHost( rcID, address, speed ); qhHost.setQHDFlags( msg.getPushNeededFlag(), msg.getServerBusyFlag(), msg.getHasUploadedFlag(), msg.getUploadSpeedFlag() ); qhHost.setQueryResponseFields( msg ); QueryResponseRecord rec; RemoteFile rfile; int recordCount = msg.getRecordCount(); ArrayList newHitList = new ArrayList( recordCount ); for (int i = 0; i < recordCount; i++) { rec = msg.getMsgRecord(i); // verify record when using a urn query // this acts like a filter but there seem to be no need to make this // not permanet... if ( searchURN != null && rec.getURN() != null ) { if ( !searchURN.equals( rec.getURN() ) ) { continue; } } synchronized( this ) { long fileSize = rec.getFileSize(); String filename = rec.getFilename(); URN urn = rec.getURN(); int fileIndex = rec.getFileIndex(); String metaData = rec.getMetaData(); // search string might be null in case whats new search is used short score = searchString == null ? 100 : KeywordSearch.calculateSearchScore( searchString, filename ); // find duplicate from same host... RemoteFile availableHit = searchResultHolder.findQueryHit( qhHost, urn, filename, fileSize, fileIndex ); if ( availableHit != null ) { // update availableHit availableHit.updateQueryHitHost( qhHost ); availableHit.setMetaData( metaData ); } else { String pathInfo = rec.getPathInfo(); rfile = new RemoteFile( qhHost, fileIndex, filename, pathInfo, fileSize, urn, metaData, score ); searchResultHolder.addQueryHit( rfile ); newHitList.add( rfile ); } // handle possible AlternateLocations DestAddress[] alternateLocations = rec.getAlternateLocations(); if ( urn != null && alternateLocations != null) { for ( int j = 0; j < alternateLocations.length; j++ ) { // find duplicate from same host... QueryHitHost qhh = new QueryHitHost( null, alternateLocations[j], -1 ); availableHit = searchResultHolder.findQueryHit( qhHost, urn, filename, fileSize, fileIndex ); if ( availableHit != null ) { // update availableHit availableHit.updateQueryHitHost( qhHost ); availableHit.setMetaData( metaData ); } else { rfile = new RemoteFile( qhh, -1, filename, "", fileSize, urn, metaData, score ); searchResultHolder.addQueryHit( rfile ); newHitList.add( rfile ); } } } } } // if something was added... if ( newHitList.size() > 0 ) { if ( queryEngine != null ) { queryEngine.incrementResultCount( msg.getUniqueResultCount() ); } RemoteFile[] newHits = new RemoteFile[ newHitList.size() ]; newHitList.toArray( newHits ); fireSearchHitsAdded( newHits ); } } |
|
int recordCount = msg.getRecordCount(); ArrayList newHitList = new ArrayList( recordCount ); for (int i = 0; i < recordCount; i++) | QueryResponseRecord[] records = msg.getMsgRecords(); ArrayList<RemoteFile> newHitList = new ArrayList<RemoteFile>( records.length ); for (int i = 0; i < records.length; i++) | public void processResponse( QueryResponseMsg msg ) { //we like to receive results even if the query was stopped already. // check if it is a response for this query? if (!msg.getHeader().getMsgID().equals( queryMsg.getHeader().getMsgID())) { return; } // remoteHost.log("Got response to my query. " + msg); long speed = msg.getRemoteHostSpeed(); GUID rcID = msg.getRemoteClientID(); DestAddress address = msg.getDestAddress(); QueryHitHost qhHost = new QueryHitHost( rcID, address, speed ); qhHost.setQHDFlags( msg.getPushNeededFlag(), msg.getServerBusyFlag(), msg.getHasUploadedFlag(), msg.getUploadSpeedFlag() ); qhHost.setQueryResponseFields( msg ); QueryResponseRecord rec; RemoteFile rfile; int recordCount = msg.getRecordCount(); ArrayList newHitList = new ArrayList( recordCount ); for (int i = 0; i < recordCount; i++) { rec = msg.getMsgRecord(i); // verify record when using a urn query // this acts like a filter but there seem to be no need to make this // not permanet... if ( searchURN != null && rec.getURN() != null ) { if ( !searchURN.equals( rec.getURN() ) ) { continue; } } synchronized( this ) { long fileSize = rec.getFileSize(); String filename = rec.getFilename(); URN urn = rec.getURN(); int fileIndex = rec.getFileIndex(); String metaData = rec.getMetaData(); // search string might be null in case whats new search is used short score = searchString == null ? 100 : KeywordSearch.calculateSearchScore( searchString, filename ); // find duplicate from same host... RemoteFile availableHit = searchResultHolder.findQueryHit( qhHost, urn, filename, fileSize, fileIndex ); if ( availableHit != null ) { // update availableHit availableHit.updateQueryHitHost( qhHost ); availableHit.setMetaData( metaData ); } else { String pathInfo = rec.getPathInfo(); rfile = new RemoteFile( qhHost, fileIndex, filename, pathInfo, fileSize, urn, metaData, score ); searchResultHolder.addQueryHit( rfile ); newHitList.add( rfile ); } // handle possible AlternateLocations DestAddress[] alternateLocations = rec.getAlternateLocations(); if ( urn != null && alternateLocations != null) { for ( int j = 0; j < alternateLocations.length; j++ ) { // find duplicate from same host... QueryHitHost qhh = new QueryHitHost( null, alternateLocations[j], -1 ); availableHit = searchResultHolder.findQueryHit( qhHost, urn, filename, fileSize, fileIndex ); if ( availableHit != null ) { // update availableHit availableHit.updateQueryHitHost( qhHost ); availableHit.setMetaData( metaData ); } else { rfile = new RemoteFile( qhh, -1, filename, "", fileSize, urn, metaData, score ); searchResultHolder.addQueryHit( rfile ); newHitList.add( rfile ); } } } } } // if something was added... if ( newHitList.size() > 0 ) { if ( queryEngine != null ) { queryEngine.incrementResultCount( msg.getUniqueResultCount() ); } RemoteFile[] newHits = new RemoteFile[ newHitList.size() ]; newHitList.toArray( newHits ); fireSearchHitsAdded( newHits ); } } |
rec = msg.getMsgRecord(i); | public void processResponse( QueryResponseMsg msg ) { //we like to receive results even if the query was stopped already. // check if it is a response for this query? if (!msg.getHeader().getMsgID().equals( queryMsg.getHeader().getMsgID())) { return; } // remoteHost.log("Got response to my query. " + msg); long speed = msg.getRemoteHostSpeed(); GUID rcID = msg.getRemoteClientID(); DestAddress address = msg.getDestAddress(); QueryHitHost qhHost = new QueryHitHost( rcID, address, speed ); qhHost.setQHDFlags( msg.getPushNeededFlag(), msg.getServerBusyFlag(), msg.getHasUploadedFlag(), msg.getUploadSpeedFlag() ); qhHost.setQueryResponseFields( msg ); QueryResponseRecord rec; RemoteFile rfile; int recordCount = msg.getRecordCount(); ArrayList newHitList = new ArrayList( recordCount ); for (int i = 0; i < recordCount; i++) { rec = msg.getMsgRecord(i); // verify record when using a urn query // this acts like a filter but there seem to be no need to make this // not permanet... if ( searchURN != null && rec.getURN() != null ) { if ( !searchURN.equals( rec.getURN() ) ) { continue; } } synchronized( this ) { long fileSize = rec.getFileSize(); String filename = rec.getFilename(); URN urn = rec.getURN(); int fileIndex = rec.getFileIndex(); String metaData = rec.getMetaData(); // search string might be null in case whats new search is used short score = searchString == null ? 100 : KeywordSearch.calculateSearchScore( searchString, filename ); // find duplicate from same host... RemoteFile availableHit = searchResultHolder.findQueryHit( qhHost, urn, filename, fileSize, fileIndex ); if ( availableHit != null ) { // update availableHit availableHit.updateQueryHitHost( qhHost ); availableHit.setMetaData( metaData ); } else { String pathInfo = rec.getPathInfo(); rfile = new RemoteFile( qhHost, fileIndex, filename, pathInfo, fileSize, urn, metaData, score ); searchResultHolder.addQueryHit( rfile ); newHitList.add( rfile ); } // handle possible AlternateLocations DestAddress[] alternateLocations = rec.getAlternateLocations(); if ( urn != null && alternateLocations != null) { for ( int j = 0; j < alternateLocations.length; j++ ) { // find duplicate from same host... QueryHitHost qhh = new QueryHitHost( null, alternateLocations[j], -1 ); availableHit = searchResultHolder.findQueryHit( qhHost, urn, filename, fileSize, fileIndex ); if ( availableHit != null ) { // update availableHit availableHit.updateQueryHitHost( qhHost ); availableHit.setMetaData( metaData ); } else { rfile = new RemoteFile( qhh, -1, filename, "", fileSize, urn, metaData, score ); searchResultHolder.addQueryHit( rfile ); newHitList.add( rfile ); } } } } } // if something was added... if ( newHitList.size() > 0 ) { if ( queryEngine != null ) { queryEngine.incrementResultCount( msg.getUniqueResultCount() ); } RemoteFile[] newHits = new RemoteFile[ newHitList.size() ]; newHitList.toArray( newHits ); fireSearchHitsAdded( newHits ); } } |
|
if ( searchURN != null && rec.getURN() != null ) | if ( searchURN != null && records[i].getURN() != null ) | public void processResponse( QueryResponseMsg msg ) { //we like to receive results even if the query was stopped already. // check if it is a response for this query? if (!msg.getHeader().getMsgID().equals( queryMsg.getHeader().getMsgID())) { return; } // remoteHost.log("Got response to my query. " + msg); long speed = msg.getRemoteHostSpeed(); GUID rcID = msg.getRemoteClientID(); DestAddress address = msg.getDestAddress(); QueryHitHost qhHost = new QueryHitHost( rcID, address, speed ); qhHost.setQHDFlags( msg.getPushNeededFlag(), msg.getServerBusyFlag(), msg.getHasUploadedFlag(), msg.getUploadSpeedFlag() ); qhHost.setQueryResponseFields( msg ); QueryResponseRecord rec; RemoteFile rfile; int recordCount = msg.getRecordCount(); ArrayList newHitList = new ArrayList( recordCount ); for (int i = 0; i < recordCount; i++) { rec = msg.getMsgRecord(i); // verify record when using a urn query // this acts like a filter but there seem to be no need to make this // not permanet... if ( searchURN != null && rec.getURN() != null ) { if ( !searchURN.equals( rec.getURN() ) ) { continue; } } synchronized( this ) { long fileSize = rec.getFileSize(); String filename = rec.getFilename(); URN urn = rec.getURN(); int fileIndex = rec.getFileIndex(); String metaData = rec.getMetaData(); // search string might be null in case whats new search is used short score = searchString == null ? 100 : KeywordSearch.calculateSearchScore( searchString, filename ); // find duplicate from same host... RemoteFile availableHit = searchResultHolder.findQueryHit( qhHost, urn, filename, fileSize, fileIndex ); if ( availableHit != null ) { // update availableHit availableHit.updateQueryHitHost( qhHost ); availableHit.setMetaData( metaData ); } else { String pathInfo = rec.getPathInfo(); rfile = new RemoteFile( qhHost, fileIndex, filename, pathInfo, fileSize, urn, metaData, score ); searchResultHolder.addQueryHit( rfile ); newHitList.add( rfile ); } // handle possible AlternateLocations DestAddress[] alternateLocations = rec.getAlternateLocations(); if ( urn != null && alternateLocations != null) { for ( int j = 0; j < alternateLocations.length; j++ ) { // find duplicate from same host... QueryHitHost qhh = new QueryHitHost( null, alternateLocations[j], -1 ); availableHit = searchResultHolder.findQueryHit( qhHost, urn, filename, fileSize, fileIndex ); if ( availableHit != null ) { // update availableHit availableHit.updateQueryHitHost( qhHost ); availableHit.setMetaData( metaData ); } else { rfile = new RemoteFile( qhh, -1, filename, "", fileSize, urn, metaData, score ); searchResultHolder.addQueryHit( rfile ); newHitList.add( rfile ); } } } } } // if something was added... if ( newHitList.size() > 0 ) { if ( queryEngine != null ) { queryEngine.incrementResultCount( msg.getUniqueResultCount() ); } RemoteFile[] newHits = new RemoteFile[ newHitList.size() ]; newHitList.toArray( newHits ); fireSearchHitsAdded( newHits ); } } |
if ( !searchURN.equals( rec.getURN() ) ) | if ( !searchURN.equals( records[i].getURN() ) ) | public void processResponse( QueryResponseMsg msg ) { //we like to receive results even if the query was stopped already. // check if it is a response for this query? if (!msg.getHeader().getMsgID().equals( queryMsg.getHeader().getMsgID())) { return; } // remoteHost.log("Got response to my query. " + msg); long speed = msg.getRemoteHostSpeed(); GUID rcID = msg.getRemoteClientID(); DestAddress address = msg.getDestAddress(); QueryHitHost qhHost = new QueryHitHost( rcID, address, speed ); qhHost.setQHDFlags( msg.getPushNeededFlag(), msg.getServerBusyFlag(), msg.getHasUploadedFlag(), msg.getUploadSpeedFlag() ); qhHost.setQueryResponseFields( msg ); QueryResponseRecord rec; RemoteFile rfile; int recordCount = msg.getRecordCount(); ArrayList newHitList = new ArrayList( recordCount ); for (int i = 0; i < recordCount; i++) { rec = msg.getMsgRecord(i); // verify record when using a urn query // this acts like a filter but there seem to be no need to make this // not permanet... if ( searchURN != null && rec.getURN() != null ) { if ( !searchURN.equals( rec.getURN() ) ) { continue; } } synchronized( this ) { long fileSize = rec.getFileSize(); String filename = rec.getFilename(); URN urn = rec.getURN(); int fileIndex = rec.getFileIndex(); String metaData = rec.getMetaData(); // search string might be null in case whats new search is used short score = searchString == null ? 100 : KeywordSearch.calculateSearchScore( searchString, filename ); // find duplicate from same host... RemoteFile availableHit = searchResultHolder.findQueryHit( qhHost, urn, filename, fileSize, fileIndex ); if ( availableHit != null ) { // update availableHit availableHit.updateQueryHitHost( qhHost ); availableHit.setMetaData( metaData ); } else { String pathInfo = rec.getPathInfo(); rfile = new RemoteFile( qhHost, fileIndex, filename, pathInfo, fileSize, urn, metaData, score ); searchResultHolder.addQueryHit( rfile ); newHitList.add( rfile ); } // handle possible AlternateLocations DestAddress[] alternateLocations = rec.getAlternateLocations(); if ( urn != null && alternateLocations != null) { for ( int j = 0; j < alternateLocations.length; j++ ) { // find duplicate from same host... QueryHitHost qhh = new QueryHitHost( null, alternateLocations[j], -1 ); availableHit = searchResultHolder.findQueryHit( qhHost, urn, filename, fileSize, fileIndex ); if ( availableHit != null ) { // update availableHit availableHit.updateQueryHitHost( qhHost ); availableHit.setMetaData( metaData ); } else { rfile = new RemoteFile( qhh, -1, filename, "", fileSize, urn, metaData, score ); searchResultHolder.addQueryHit( rfile ); newHitList.add( rfile ); } } } } } // if something was added... if ( newHitList.size() > 0 ) { if ( queryEngine != null ) { queryEngine.incrementResultCount( msg.getUniqueResultCount() ); } RemoteFile[] newHits = new RemoteFile[ newHitList.size() ]; newHitList.toArray( newHits ); fireSearchHitsAdded( newHits ); } } |
long fileSize = rec.getFileSize(); String filename = rec.getFilename(); URN urn = rec.getURN(); int fileIndex = rec.getFileIndex(); String metaData = rec.getMetaData(); | long fileSize = records[i].getFileSize(); String filename = records[i].getFilename(); URN urn = records[i].getURN(); int fileIndex = records[i].getFileIndex(); String metaData = records[i].getMetaData(); | public void processResponse( QueryResponseMsg msg ) { //we like to receive results even if the query was stopped already. // check if it is a response for this query? if (!msg.getHeader().getMsgID().equals( queryMsg.getHeader().getMsgID())) { return; } // remoteHost.log("Got response to my query. " + msg); long speed = msg.getRemoteHostSpeed(); GUID rcID = msg.getRemoteClientID(); DestAddress address = msg.getDestAddress(); QueryHitHost qhHost = new QueryHitHost( rcID, address, speed ); qhHost.setQHDFlags( msg.getPushNeededFlag(), msg.getServerBusyFlag(), msg.getHasUploadedFlag(), msg.getUploadSpeedFlag() ); qhHost.setQueryResponseFields( msg ); QueryResponseRecord rec; RemoteFile rfile; int recordCount = msg.getRecordCount(); ArrayList newHitList = new ArrayList( recordCount ); for (int i = 0; i < recordCount; i++) { rec = msg.getMsgRecord(i); // verify record when using a urn query // this acts like a filter but there seem to be no need to make this // not permanet... if ( searchURN != null && rec.getURN() != null ) { if ( !searchURN.equals( rec.getURN() ) ) { continue; } } synchronized( this ) { long fileSize = rec.getFileSize(); String filename = rec.getFilename(); URN urn = rec.getURN(); int fileIndex = rec.getFileIndex(); String metaData = rec.getMetaData(); // search string might be null in case whats new search is used short score = searchString == null ? 100 : KeywordSearch.calculateSearchScore( searchString, filename ); // find duplicate from same host... RemoteFile availableHit = searchResultHolder.findQueryHit( qhHost, urn, filename, fileSize, fileIndex ); if ( availableHit != null ) { // update availableHit availableHit.updateQueryHitHost( qhHost ); availableHit.setMetaData( metaData ); } else { String pathInfo = rec.getPathInfo(); rfile = new RemoteFile( qhHost, fileIndex, filename, pathInfo, fileSize, urn, metaData, score ); searchResultHolder.addQueryHit( rfile ); newHitList.add( rfile ); } // handle possible AlternateLocations DestAddress[] alternateLocations = rec.getAlternateLocations(); if ( urn != null && alternateLocations != null) { for ( int j = 0; j < alternateLocations.length; j++ ) { // find duplicate from same host... QueryHitHost qhh = new QueryHitHost( null, alternateLocations[j], -1 ); availableHit = searchResultHolder.findQueryHit( qhHost, urn, filename, fileSize, fileIndex ); if ( availableHit != null ) { // update availableHit availableHit.updateQueryHitHost( qhHost ); availableHit.setMetaData( metaData ); } else { rfile = new RemoteFile( qhh, -1, filename, "", fileSize, urn, metaData, score ); searchResultHolder.addQueryHit( rfile ); newHitList.add( rfile ); } } } } } // if something was added... if ( newHitList.size() > 0 ) { if ( queryEngine != null ) { queryEngine.incrementResultCount( msg.getUniqueResultCount() ); } RemoteFile[] newHits = new RemoteFile[ newHitList.size() ]; newHitList.toArray( newHits ); fireSearchHitsAdded( newHits ); } } |
String pathInfo = rec.getPathInfo(); | String pathInfo = records[i].getPathInfo(); | public void processResponse( QueryResponseMsg msg ) { //we like to receive results even if the query was stopped already. // check if it is a response for this query? if (!msg.getHeader().getMsgID().equals( queryMsg.getHeader().getMsgID())) { return; } // remoteHost.log("Got response to my query. " + msg); long speed = msg.getRemoteHostSpeed(); GUID rcID = msg.getRemoteClientID(); DestAddress address = msg.getDestAddress(); QueryHitHost qhHost = new QueryHitHost( rcID, address, speed ); qhHost.setQHDFlags( msg.getPushNeededFlag(), msg.getServerBusyFlag(), msg.getHasUploadedFlag(), msg.getUploadSpeedFlag() ); qhHost.setQueryResponseFields( msg ); QueryResponseRecord rec; RemoteFile rfile; int recordCount = msg.getRecordCount(); ArrayList newHitList = new ArrayList( recordCount ); for (int i = 0; i < recordCount; i++) { rec = msg.getMsgRecord(i); // verify record when using a urn query // this acts like a filter but there seem to be no need to make this // not permanet... if ( searchURN != null && rec.getURN() != null ) { if ( !searchURN.equals( rec.getURN() ) ) { continue; } } synchronized( this ) { long fileSize = rec.getFileSize(); String filename = rec.getFilename(); URN urn = rec.getURN(); int fileIndex = rec.getFileIndex(); String metaData = rec.getMetaData(); // search string might be null in case whats new search is used short score = searchString == null ? 100 : KeywordSearch.calculateSearchScore( searchString, filename ); // find duplicate from same host... RemoteFile availableHit = searchResultHolder.findQueryHit( qhHost, urn, filename, fileSize, fileIndex ); if ( availableHit != null ) { // update availableHit availableHit.updateQueryHitHost( qhHost ); availableHit.setMetaData( metaData ); } else { String pathInfo = rec.getPathInfo(); rfile = new RemoteFile( qhHost, fileIndex, filename, pathInfo, fileSize, urn, metaData, score ); searchResultHolder.addQueryHit( rfile ); newHitList.add( rfile ); } // handle possible AlternateLocations DestAddress[] alternateLocations = rec.getAlternateLocations(); if ( urn != null && alternateLocations != null) { for ( int j = 0; j < alternateLocations.length; j++ ) { // find duplicate from same host... QueryHitHost qhh = new QueryHitHost( null, alternateLocations[j], -1 ); availableHit = searchResultHolder.findQueryHit( qhHost, urn, filename, fileSize, fileIndex ); if ( availableHit != null ) { // update availableHit availableHit.updateQueryHitHost( qhHost ); availableHit.setMetaData( metaData ); } else { rfile = new RemoteFile( qhh, -1, filename, "", fileSize, urn, metaData, score ); searchResultHolder.addQueryHit( rfile ); newHitList.add( rfile ); } } } } } // if something was added... if ( newHitList.size() > 0 ) { if ( queryEngine != null ) { queryEngine.incrementResultCount( msg.getUniqueResultCount() ); } RemoteFile[] newHits = new RemoteFile[ newHitList.size() ]; newHitList.toArray( newHits ); fireSearchHitsAdded( newHits ); } } |
DestAddress[] alternateLocations = rec.getAlternateLocations(); | DestAddress[] alternateLocations = records[i].getAlternateLocations(); | public void processResponse( QueryResponseMsg msg ) { //we like to receive results even if the query was stopped already. // check if it is a response for this query? if (!msg.getHeader().getMsgID().equals( queryMsg.getHeader().getMsgID())) { return; } // remoteHost.log("Got response to my query. " + msg); long speed = msg.getRemoteHostSpeed(); GUID rcID = msg.getRemoteClientID(); DestAddress address = msg.getDestAddress(); QueryHitHost qhHost = new QueryHitHost( rcID, address, speed ); qhHost.setQHDFlags( msg.getPushNeededFlag(), msg.getServerBusyFlag(), msg.getHasUploadedFlag(), msg.getUploadSpeedFlag() ); qhHost.setQueryResponseFields( msg ); QueryResponseRecord rec; RemoteFile rfile; int recordCount = msg.getRecordCount(); ArrayList newHitList = new ArrayList( recordCount ); for (int i = 0; i < recordCount; i++) { rec = msg.getMsgRecord(i); // verify record when using a urn query // this acts like a filter but there seem to be no need to make this // not permanet... if ( searchURN != null && rec.getURN() != null ) { if ( !searchURN.equals( rec.getURN() ) ) { continue; } } synchronized( this ) { long fileSize = rec.getFileSize(); String filename = rec.getFilename(); URN urn = rec.getURN(); int fileIndex = rec.getFileIndex(); String metaData = rec.getMetaData(); // search string might be null in case whats new search is used short score = searchString == null ? 100 : KeywordSearch.calculateSearchScore( searchString, filename ); // find duplicate from same host... RemoteFile availableHit = searchResultHolder.findQueryHit( qhHost, urn, filename, fileSize, fileIndex ); if ( availableHit != null ) { // update availableHit availableHit.updateQueryHitHost( qhHost ); availableHit.setMetaData( metaData ); } else { String pathInfo = rec.getPathInfo(); rfile = new RemoteFile( qhHost, fileIndex, filename, pathInfo, fileSize, urn, metaData, score ); searchResultHolder.addQueryHit( rfile ); newHitList.add( rfile ); } // handle possible AlternateLocations DestAddress[] alternateLocations = rec.getAlternateLocations(); if ( urn != null && alternateLocations != null) { for ( int j = 0; j < alternateLocations.length; j++ ) { // find duplicate from same host... QueryHitHost qhh = new QueryHitHost( null, alternateLocations[j], -1 ); availableHit = searchResultHolder.findQueryHit( qhHost, urn, filename, fileSize, fileIndex ); if ( availableHit != null ) { // update availableHit availableHit.updateQueryHitHost( qhHost ); availableHit.setMetaData( metaData ); } else { rfile = new RemoteFile( qhh, -1, filename, "", fileSize, urn, metaData, score ); searchResultHolder.addQueryHit( rfile ); newHitList.add( rfile ); } } } } } // if something was added... if ( newHitList.size() > 0 ) { if ( queryEngine != null ) { queryEngine.incrementResultCount( msg.getUniqueResultCount() ); } RemoteFile[] newHits = new RemoteFile[ newHitList.size() ]; newHitList.toArray( newHits ); fireSearchHitsAdded( newHits ); } } |
public abstract void processResponse( QueryResponseMsg msg ); | public abstract void processResponse( QueryResponseMsg msg ) throws InvalidMessageException; | public abstract void processResponse( QueryResponseMsg msg ); |
throws InvalidMessageException | public void setQueryResponseFields( QueryResponseMsg msg ) { setVendorCode( msg.getVendorCode() ); setChatSupported( msg.isChatSupported() ); setBrowseHostSupported( msg.isBrowseHostSupported() ); setPushProxyAddresses( msg.getPushProxyAddresses() ); } |
|
else { | public Node differentiate(ASTFunNode node,String var,Node [] children,Node [] dchildren,DJep djep) throws ParseException { OperatorSet op = djep.getOperatorSet(); NodeFactory nf = djep.getNodeFactory(); TreeUtils tu = djep.getTreeUtils(); FunctionTable funTab = djep.getFunctionTable(); int nchild = node.jjtGetNumChildren(); if(nchild!=2) throw new ParseException("Too many children "+nchild+" for "+node+"\n"); // x^y -> n*(pow(x,y-1)) x' + ln(y) pow(x,y) y' if(tu.isConstant(children[1])) { ASTConstant c = (ASTConstant) children[1]; Object value = c.getValue(); if(value instanceof Double) { // x^m -> m * x^(m-1) * x'// Node a = TreeUtils.deepCopy(children[1]);// Node b = TreeUtils.deepCopy(children[0]);// Node cc = TreeUtils.createConstant( ((Double) value).doubleValue()-1.0);// Node d = opSet.buildPowerNode(b,cc);// Node e = opSet.buildMultiplyNode(a,d); return nf.buildOperatorNode(op.getMultiply(), djep.deepCopy(children[1]), nf.buildOperatorNode(op.getMultiply(), nf.buildOperatorNode(op.getPower(), djep.deepCopy(children[0]), nf.buildConstantNode( tu.getNumber(((Double) value).doubleValue()-1.0))), dchildren[0])); } else { return nf.buildOperatorNode(op.getMultiply(), djep.deepCopy(children[1]), nf.buildOperatorNode(op.getMultiply(), nf.buildOperatorNode(op.getPower(), djep.deepCopy(children[0]), nf.buildOperatorNode(op.getSubtract(), djep.deepCopy(children[1]), nf.buildConstantNode(tu.getONE()))), dchildren[0])); } } else // z * y^(z-1) * diff(y,x) + y^z * ln(z) * diff(z,x) { return nf.buildOperatorNode(op.getAdd(), nf.buildOperatorNode(op.getMultiply(), // z * y^(z-1) * diff(y,x) nf.buildOperatorNode(op.getMultiply(), // z * y^(z-1) djep.deepCopy(children[1]), // z nf.buildOperatorNode(op.getPower(), // y^(z-1) djep.deepCopy(children[0]), // y nf.buildOperatorNode(op.getSubtract(), // z-1 djep.deepCopy(children[1]), // z djep.getNodeFactory().buildConstantNode(tu.getONE()) ))), dchildren[0]), // diff(y,x) nf.buildOperatorNode(op.getMultiply(), // + y^z * ln(z) * diff(z,x) nf.buildOperatorNode(op.getMultiply(), nf.buildOperatorNode(op.getPower(), // y^z djep.deepCopy(children[0]), djep.deepCopy(children[1])), djep.getNodeFactory().buildFunctionNode("ln",funTab.get("ln"), // ln(z) new Node[]{djep.deepCopy(children[0])})), dchildren[1])); // TODO will NaturalLog always have the name "ln" } } |
|
} | public Node differentiate(ASTFunNode node,String var,Node [] children,Node [] dchildren,DJep djep) throws ParseException { OperatorSet op = djep.getOperatorSet(); NodeFactory nf = djep.getNodeFactory(); TreeUtils tu = djep.getTreeUtils(); FunctionTable funTab = djep.getFunctionTable(); int nchild = node.jjtGetNumChildren(); if(nchild!=2) throw new ParseException("Too many children "+nchild+" for "+node+"\n"); // x^y -> n*(pow(x,y-1)) x' + ln(y) pow(x,y) y' if(tu.isConstant(children[1])) { ASTConstant c = (ASTConstant) children[1]; Object value = c.getValue(); if(value instanceof Double) { // x^m -> m * x^(m-1) * x'// Node a = TreeUtils.deepCopy(children[1]);// Node b = TreeUtils.deepCopy(children[0]);// Node cc = TreeUtils.createConstant( ((Double) value).doubleValue()-1.0);// Node d = opSet.buildPowerNode(b,cc);// Node e = opSet.buildMultiplyNode(a,d); return nf.buildOperatorNode(op.getMultiply(), djep.deepCopy(children[1]), nf.buildOperatorNode(op.getMultiply(), nf.buildOperatorNode(op.getPower(), djep.deepCopy(children[0]), nf.buildConstantNode( tu.getNumber(((Double) value).doubleValue()-1.0))), dchildren[0])); } else { return nf.buildOperatorNode(op.getMultiply(), djep.deepCopy(children[1]), nf.buildOperatorNode(op.getMultiply(), nf.buildOperatorNode(op.getPower(), djep.deepCopy(children[0]), nf.buildOperatorNode(op.getSubtract(), djep.deepCopy(children[1]), nf.buildConstantNode(tu.getONE()))), dchildren[0])); } } else // z * y^(z-1) * diff(y,x) + y^z * ln(z) * diff(z,x) { return nf.buildOperatorNode(op.getAdd(), nf.buildOperatorNode(op.getMultiply(), // z * y^(z-1) * diff(y,x) nf.buildOperatorNode(op.getMultiply(), // z * y^(z-1) djep.deepCopy(children[1]), // z nf.buildOperatorNode(op.getPower(), // y^(z-1) djep.deepCopy(children[0]), // y nf.buildOperatorNode(op.getSubtract(), // z-1 djep.deepCopy(children[1]), // z djep.getNodeFactory().buildConstantNode(tu.getONE()) ))), dchildren[0]), // diff(y,x) nf.buildOperatorNode(op.getMultiply(), // + y^z * ln(z) * diff(z,x) nf.buildOperatorNode(op.getMultiply(), nf.buildOperatorNode(op.getPower(), // y^z djep.deepCopy(children[0]), djep.deepCopy(children[1])), djep.getNodeFactory().buildFunctionNode("ln",funTab.get("ln"), // ln(z) new Node[]{djep.deepCopy(children[0])})), dchildren[1])); // TODO will NaturalLog always have the name "ln" } } |
|
else | public Node differentiate(ASTFunNode node,String var,Node [] children,Node [] dchildren,DJep djep) throws ParseException { OperatorSet op = djep.getOperatorSet(); NodeFactory nf = djep.getNodeFactory(); TreeUtils tu = djep.getTreeUtils(); FunctionTable funTab = djep.getFunctionTable(); int nchild = node.jjtGetNumChildren(); if(nchild!=2) throw new ParseException("Too many children "+nchild+" for "+node+"\n"); // x^y -> n*(pow(x,y-1)) x' + ln(y) pow(x,y) y' if(tu.isConstant(children[1])) { ASTConstant c = (ASTConstant) children[1]; Object value = c.getValue(); if(value instanceof Double) { // x^m -> m * x^(m-1) * x'// Node a = TreeUtils.deepCopy(children[1]);// Node b = TreeUtils.deepCopy(children[0]);// Node cc = TreeUtils.createConstant( ((Double) value).doubleValue()-1.0);// Node d = opSet.buildPowerNode(b,cc);// Node e = opSet.buildMultiplyNode(a,d); return nf.buildOperatorNode(op.getMultiply(), djep.deepCopy(children[1]), nf.buildOperatorNode(op.getMultiply(), nf.buildOperatorNode(op.getPower(), djep.deepCopy(children[0]), nf.buildConstantNode( tu.getNumber(((Double) value).doubleValue()-1.0))), dchildren[0])); } else { return nf.buildOperatorNode(op.getMultiply(), djep.deepCopy(children[1]), nf.buildOperatorNode(op.getMultiply(), nf.buildOperatorNode(op.getPower(), djep.deepCopy(children[0]), nf.buildOperatorNode(op.getSubtract(), djep.deepCopy(children[1]), nf.buildConstantNode(tu.getONE()))), dchildren[0])); } } else // z * y^(z-1) * diff(y,x) + y^z * ln(z) * diff(z,x) { return nf.buildOperatorNode(op.getAdd(), nf.buildOperatorNode(op.getMultiply(), // z * y^(z-1) * diff(y,x) nf.buildOperatorNode(op.getMultiply(), // z * y^(z-1) djep.deepCopy(children[1]), // z nf.buildOperatorNode(op.getPower(), // y^(z-1) djep.deepCopy(children[0]), // y nf.buildOperatorNode(op.getSubtract(), // z-1 djep.deepCopy(children[1]), // z djep.getNodeFactory().buildConstantNode(tu.getONE()) ))), dchildren[0]), // diff(y,x) nf.buildOperatorNode(op.getMultiply(), // + y^z * ln(z) * diff(z,x) nf.buildOperatorNode(op.getMultiply(), nf.buildOperatorNode(op.getPower(), // y^z djep.deepCopy(children[0]), djep.deepCopy(children[1])), djep.getNodeFactory().buildFunctionNode("ln",funTab.get("ln"), // ln(z) new Node[]{djep.deepCopy(children[0])})), dchildren[1])); // TODO will NaturalLog always have the name "ln" } } |
|
try { MagnetData magnetData = MagnetData.parseFromURI(uri); URN urn = MagnetData.lookupSHA1URN(magnetData); SwarmingManager swarmingMgr = SwarmingManager.getInstance(); if ( !swarmingMgr.isURNDownloaded( urn ) ) { swarmingMgr.addFileToDownload( uri ); } } catch (IOException exp) { NLogger.warn(NLoggerNames.MAGMA, exp.getMessage(), exp); } | downloadUri( uri ); | public static void sheduledReadout( URI uri, long time ) { try { // dont add already downloading urns. MagnetData magnetData = MagnetData.parseFromURI(uri); URN urn = MagnetData.lookupSHA1URN(magnetData); SwarmingManager swarmingMgr = SwarmingManager.getInstance(); if ( !swarmingMgr.isURNDownloaded( urn ) ) { swarmingMgr.addFileToDownload( uri ); } } catch (IOException exp) { NLogger.warn(NLoggerNames.MAGMA, exp.getMessage(), exp); } } |
File file = new File(archive.getParentFile(), s); | File file = resolve(archive.getParentFile(), s); | public PluginWrapper(PluginManager owner, File archive) throws IOException { LOGGER.info("Loading plugin: "+archive); this.shortName = getShortName(archive); boolean isLinked = archive.getName().endsWith(".hpl"); File expandDir = null; // if .hpi, this is the directory where war is expanded if(isLinked) { FileInputStream in = new FileInputStream(archive); try { manifest = new Manifest(in); } finally { in.close(); } } else { expandDir = new File(archive.getParentFile(), shortName); explode(archive,expandDir); File manifestFile = new File(expandDir,"META-INF/MANIFEST.MF"); if(!manifestFile.exists()) { throw new IOException("Plugin installation failed. No manifest at "+manifestFile); } FileInputStream fin = new FileInputStream(manifestFile); try { manifest = new Manifest(fin); } finally { fin.close(); } } // TODO: define a mechanism to hide classes // String export = manifest.getMainAttributes().getValue("Export"); List<URL> paths = new ArrayList<URL>(); if(isLinked) { String classPath = manifest.getMainAttributes().getValue("Class-Path"); for (String s : classPath.split(" +")) { File file = new File(archive.getParentFile(), s); if(file.getName().contains("*")) { // handle wildcard FileSet fs = new FileSet(); File dir = file.getParentFile(); fs.setDir(dir); fs.setIncludes(file.getName()); for( String included : fs.getDirectoryScanner(new Project()).getIncludedFiles() ) { paths.add(new File(dir,included).toURL()); } } else { if(!file.exists()) throw new IOException("No such file: "+file); paths.add(file.toURL()); } } this.baseResourceURL = new File(archive.getParentFile(), manifest.getMainAttributes().getValue("Resource-Path")).toURL(); } else { File classes = new File(expandDir,"WEB-INF/classes"); if(classes.exists()) paths.add(classes.toURL()); File lib = new File(expandDir,"WEB-INF/lib"); File[] libs = lib.listFiles(JAR_FILTER); if(libs!=null) { for (File jar : libs) paths.add(jar.toURL()); } this.baseResourceURL = expandDir.toURL(); } this.classLoader = new URLClassLoader(paths.toArray(new URL[0]), getClass().getClassLoader()); disableFile = new File(archive.getPath()+".disabled"); if(disableFile.exists()) { LOGGER.info("Plugin is disabled"); this.plugin = null; return; } String className = manifest.getMainAttributes().getValue("Plugin-Class"); if(className ==null) { throw new IOException("Plugin installation failed. No 'Plugin-Class' entry in the manifest of "+archive); } try { Class clazz = classLoader.loadClass(className); Object plugin = clazz.newInstance(); if(!(plugin instanceof Plugin)) { throw new IOException(className+" doesn't extend from hudson.Plugin"); } this.plugin = (Plugin)plugin; this.plugin.wrapper = this; } catch (ClassNotFoundException e) { IOException ioe = new IOException("Unable to load " + className + " from " + archive); ioe.initCause(e); throw ioe; } catch (IllegalAccessException e) { IOException ioe = new IOException("Unable to create instance of " + className + " from " + archive); ioe.initCause(e); throw ioe; } catch (InstantiationException e) { IOException ioe = new IOException("Unable to create instance of " + className + " from " + archive); ioe.initCause(e); throw ioe; } // initialize plugin try { plugin.setServletContext(owner.context); plugin.start(); } catch(Throwable t) { // gracefully handle any error in plugin. IOException ioe = new IOException("Failed to initialize"); ioe.initCause(t); throw ioe; } } |
this.baseResourceURL = new File(archive.getParentFile(), | this.baseResourceURL = resolve(archive.getParentFile(), | public PluginWrapper(PluginManager owner, File archive) throws IOException { LOGGER.info("Loading plugin: "+archive); this.shortName = getShortName(archive); boolean isLinked = archive.getName().endsWith(".hpl"); File expandDir = null; // if .hpi, this is the directory where war is expanded if(isLinked) { FileInputStream in = new FileInputStream(archive); try { manifest = new Manifest(in); } finally { in.close(); } } else { expandDir = new File(archive.getParentFile(), shortName); explode(archive,expandDir); File manifestFile = new File(expandDir,"META-INF/MANIFEST.MF"); if(!manifestFile.exists()) { throw new IOException("Plugin installation failed. No manifest at "+manifestFile); } FileInputStream fin = new FileInputStream(manifestFile); try { manifest = new Manifest(fin); } finally { fin.close(); } } // TODO: define a mechanism to hide classes // String export = manifest.getMainAttributes().getValue("Export"); List<URL> paths = new ArrayList<URL>(); if(isLinked) { String classPath = manifest.getMainAttributes().getValue("Class-Path"); for (String s : classPath.split(" +")) { File file = new File(archive.getParentFile(), s); if(file.getName().contains("*")) { // handle wildcard FileSet fs = new FileSet(); File dir = file.getParentFile(); fs.setDir(dir); fs.setIncludes(file.getName()); for( String included : fs.getDirectoryScanner(new Project()).getIncludedFiles() ) { paths.add(new File(dir,included).toURL()); } } else { if(!file.exists()) throw new IOException("No such file: "+file); paths.add(file.toURL()); } } this.baseResourceURL = new File(archive.getParentFile(), manifest.getMainAttributes().getValue("Resource-Path")).toURL(); } else { File classes = new File(expandDir,"WEB-INF/classes"); if(classes.exists()) paths.add(classes.toURL()); File lib = new File(expandDir,"WEB-INF/lib"); File[] libs = lib.listFiles(JAR_FILTER); if(libs!=null) { for (File jar : libs) paths.add(jar.toURL()); } this.baseResourceURL = expandDir.toURL(); } this.classLoader = new URLClassLoader(paths.toArray(new URL[0]), getClass().getClassLoader()); disableFile = new File(archive.getPath()+".disabled"); if(disableFile.exists()) { LOGGER.info("Plugin is disabled"); this.plugin = null; return; } String className = manifest.getMainAttributes().getValue("Plugin-Class"); if(className ==null) { throw new IOException("Plugin installation failed. No 'Plugin-Class' entry in the manifest of "+archive); } try { Class clazz = classLoader.loadClass(className); Object plugin = clazz.newInstance(); if(!(plugin instanceof Plugin)) { throw new IOException(className+" doesn't extend from hudson.Plugin"); } this.plugin = (Plugin)plugin; this.plugin.wrapper = this; } catch (ClassNotFoundException e) { IOException ioe = new IOException("Unable to load " + className + " from " + archive); ioe.initCause(e); throw ioe; } catch (IllegalAccessException e) { IOException ioe = new IOException("Unable to create instance of " + className + " from " + archive); ioe.initCause(e); throw ioe; } catch (InstantiationException e) { IOException ioe = new IOException("Unable to create instance of " + className + " from " + archive); ioe.initCause(e); throw ioe; } // initialize plugin try { plugin.setServletContext(owner.context); plugin.start(); } catch(Throwable t) { // gracefully handle any error in plugin. IOException ioe = new IOException("Failed to initialize"); ioe.initCause(t); throw ioe; } } |
System.out.println("drawing a seismogram"); | logger.debug("drawing a seismogram"); GeneralPath currentShape = new GeneralPath(); | public Shape draw(Dimension size){ System.out.println("drawing a seismogram"); int scale = 5; int w = size.width, h = size.height; Dimension mySize = new Dimension(w, h); int[] xPixels = null; int[] yPixels = null; int[][] pixels; MicroSecondTimeRange overTimeRange = timeConfig.getTimeRange(seismogram).getOversizedTimeRange((scale -1)/2); try{ pixels = SeisPlotUtil.calculatePlottable(seismogram, ampConfig.getAmpRange(seismogram), overTimeRange, mySize); xPixels = pixels[0]; yPixels = pixels[1]; SeisPlotUtil.flipArray(yPixels, mySize.height); // create cache SoftReference xPixelRef = new SoftReference(xPixels); SoftReference yPixelRef = new SoftReference(yPixels); currentShape = new GeneralPath(); currentShape.moveTo(xPixels[0], yPixels[0]); for(int i = 1; i < xPixels.length; i++) currentShape.lineTo(xPixels[i], yPixels[i]); } catch(Exception e){ e.printStackTrace(); } return currentShape; } |
SoftReference xPixelRef = new SoftReference(xPixels); SoftReference yPixelRef = new SoftReference(yPixels); currentShape = new GeneralPath(); currentShape.moveTo(xPixels[0], yPixels[0]); | if(xPixels.length >= 1) currentShape.moveTo(xPixels[0], yPixels[0]); | public Shape draw(Dimension size){ System.out.println("drawing a seismogram"); int scale = 5; int w = size.width, h = size.height; Dimension mySize = new Dimension(w, h); int[] xPixels = null; int[] yPixels = null; int[][] pixels; MicroSecondTimeRange overTimeRange = timeConfig.getTimeRange(seismogram).getOversizedTimeRange((scale -1)/2); try{ pixels = SeisPlotUtil.calculatePlottable(seismogram, ampConfig.getAmpRange(seismogram), overTimeRange, mySize); xPixels = pixels[0]; yPixels = pixels[1]; SeisPlotUtil.flipArray(yPixels, mySize.height); // create cache SoftReference xPixelRef = new SoftReference(xPixels); SoftReference yPixelRef = new SoftReference(yPixels); currentShape = new GeneralPath(); currentShape.moveTo(xPixels[0], yPixels[0]); for(int i = 1; i < xPixels.length; i++) currentShape.lineTo(xPixels[i], yPixels[i]); } catch(Exception e){ e.printStackTrace(); } return currentShape; } |
if(!hasValidValue()) sb.append("(invalid)"); sb.append(" "); if(getEquation()!=null) sb.append(pv.toString(getEquation())); | if(!hasValidValue()) sb.append("NA"); sb.append("\t"); if(this.isConstant()) sb.append("constant"); else if(getEquation()!=null) sb.append(pv.toString(getEquation())); | public String toString(PrintVisitor pv) { StringBuffer sb = new StringBuffer(name); sb.append(": val "+getValue() ); if(!hasValidValue()) sb.append("(invalid)"); sb.append(" "); if(getEquation()!=null) sb.append(pv.toString(getEquation())); else sb.append("no equation"); return sb.toString(); } |
this.addMouseListener(new PlottableMouseListener(this)); | PlottableMouseListener plottableMouseListener = new PlottableMouseListener(this); this.addMouseListener(plottableMouseListener); this.addMouseMotionListener(plottableMouseListener); | public PlottableDisplay() { super(); removeAll(); final Color bg = Color.white; final Color fg = Color.yellow; //Initialize drawing colors, border, opacity. setBackground(bg); setForeground(fg); setBorder(BorderFactory.createCompoundBorder( BorderFactory.createRaisedBevelBorder(), BorderFactory.createLoweredBevelBorder())); setLayout(new BorderLayout()); // add(imagePanel, BorderLayout.CENTER); this.addMouseListener(new PlottableMouseListener(this)); configChanged(); } |
int[] minmax = findMinMax(arrayplottable); | private void drawHighlightRegion(Graphics g) { // get new graphics to avoid messing up original Graphics2D newG = (Graphics2D)g.create(); if(g != currentImageGraphics) { newG.translate(labelXShift, titleYShift); newG.clipRect(0, 0, plot_x/plotrows, plot_y +(plotoffset * (plotrows-1))); } int xShift = plot_x/plotrows; int[] selectedRows = getSelectedRows(beginy, endy); for (int currRow = 0; currRow < plotrows; currRow++) { // 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); java.awt.geom.AffineTransform original = newG.getTransform(); java.awt.geom.AffineTransform affine = newG.getTransform(); affine.concatenate(affine.getTranslateInstance(-1*xShift*currRow, plot_y/2+plotoffset*currRow)); // account for graphics y positive down affine.concatenate(affine.getScaleInstance(1, -1)); newG.setTransform(affine); newG.setPaint(Color.red); AlphaComposite originalComposite = (AlphaComposite)newG.getComposite(); AlphaComposite newComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .4f); Point2D.Float beginPoint = new Point2D.Float(beginx, endx); newG.setPaint(Color.green); newG.setComposite(newComposite); if(isRowSelected(selectedRows, currRow)) { int bx = 0; int by = 0; int ex = 0; int ey = 0; if(currRow == selectedRows[0] ) { System.out.println("Calculating values for start row"); bx = beginx + xShift*currRow ;//-labelXShift + beginx; if(selectedRows.length != 1) { ex = 6000; } else { ex = endx - beginx; } by = -10; ey = 20; } else if(currRow == selectedRows[selectedRows.length -1 ]) { System.out.println("Caculating values for end row "+currRow); bx = xShift*currRow; ex = (endx); by = -10; ey = 20; } else { bx = 0; ex = 6000; by = -10; ey = 20; } System.out.println("NOW DRAW THE rectangle for row "+currRow); newG.drawRect(bx, by, ex, ey); newG.fillRect(bx, by, ex, ey); }//end of if newG.setTransform(original); }//end of for newG.dispose(); } |
|
int mean = getMean(); | private void drawHighlightRegion(Graphics g) { // get new graphics to avoid messing up original Graphics2D newG = (Graphics2D)g.create(); if(g != currentImageGraphics) { newG.translate(labelXShift, titleYShift); newG.clipRect(0, 0, plot_x/plotrows, plot_y +(plotoffset * (plotrows-1))); } int xShift = plot_x/plotrows; int[] selectedRows = getSelectedRows(beginy, endy); for (int currRow = 0; currRow < plotrows; currRow++) { // 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); java.awt.geom.AffineTransform original = newG.getTransform(); java.awt.geom.AffineTransform affine = newG.getTransform(); affine.concatenate(affine.getTranslateInstance(-1*xShift*currRow, plot_y/2+plotoffset*currRow)); // account for graphics y positive down affine.concatenate(affine.getScaleInstance(1, -1)); newG.setTransform(affine); newG.setPaint(Color.red); AlphaComposite originalComposite = (AlphaComposite)newG.getComposite(); AlphaComposite newComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .4f); Point2D.Float beginPoint = new Point2D.Float(beginx, endx); newG.setPaint(Color.green); newG.setComposite(newComposite); if(isRowSelected(selectedRows, currRow)) { int bx = 0; int by = 0; int ex = 0; int ey = 0; if(currRow == selectedRows[0] ) { System.out.println("Calculating values for start row"); bx = beginx + xShift*currRow ;//-labelXShift + beginx; if(selectedRows.length != 1) { ex = 6000; } else { ex = endx - beginx; } by = -10; ey = 20; } else if(currRow == selectedRows[selectedRows.length -1 ]) { System.out.println("Caculating values for end row "+currRow); bx = xShift*currRow; ex = (endx); by = -10; ey = 20; } else { bx = 0; ex = 6000; by = -10; ey = 20; } System.out.println("NOW DRAW THE rectangle for row "+currRow); newG.drawRect(bx, by, ex, ey); newG.fillRect(bx, by, ex, ey); }//end of if newG.setTransform(original); }//end of for newG.dispose(); } |
|
int by = 0; | private void drawHighlightRegion(Graphics g) { // get new graphics to avoid messing up original Graphics2D newG = (Graphics2D)g.create(); if(g != currentImageGraphics) { newG.translate(labelXShift, titleYShift); newG.clipRect(0, 0, plot_x/plotrows, plot_y +(plotoffset * (plotrows-1))); } int xShift = plot_x/plotrows; int[] selectedRows = getSelectedRows(beginy, endy); for (int currRow = 0; currRow < plotrows; currRow++) { // 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); java.awt.geom.AffineTransform original = newG.getTransform(); java.awt.geom.AffineTransform affine = newG.getTransform(); affine.concatenate(affine.getTranslateInstance(-1*xShift*currRow, plot_y/2+plotoffset*currRow)); // account for graphics y positive down affine.concatenate(affine.getScaleInstance(1, -1)); newG.setTransform(affine); newG.setPaint(Color.red); AlphaComposite originalComposite = (AlphaComposite)newG.getComposite(); AlphaComposite newComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .4f); Point2D.Float beginPoint = new Point2D.Float(beginx, endx); newG.setPaint(Color.green); newG.setComposite(newComposite); if(isRowSelected(selectedRows, currRow)) { int bx = 0; int by = 0; int ex = 0; int ey = 0; if(currRow == selectedRows[0] ) { System.out.println("Calculating values for start row"); bx = beginx + xShift*currRow ;//-labelXShift + beginx; if(selectedRows.length != 1) { ex = 6000; } else { ex = endx - beginx; } by = -10; ey = 20; } else if(currRow == selectedRows[selectedRows.length -1 ]) { System.out.println("Caculating values for end row "+currRow); bx = xShift*currRow; ex = (endx); by = -10; ey = 20; } else { bx = 0; ex = 6000; by = -10; ey = 20; } System.out.println("NOW DRAW THE rectangle for row "+currRow); newG.drawRect(bx, by, ex, ey); newG.fillRect(bx, by, ex, ey); }//end of if newG.setTransform(original); }//end of for newG.dispose(); } |
|
int ey = 0; | int by = -plotoffset/2 + 10; int ey = plotoffset - 10; | private void drawHighlightRegion(Graphics g) { // get new graphics to avoid messing up original Graphics2D newG = (Graphics2D)g.create(); if(g != currentImageGraphics) { newG.translate(labelXShift, titleYShift); newG.clipRect(0, 0, plot_x/plotrows, plot_y +(plotoffset * (plotrows-1))); } int xShift = plot_x/plotrows; int[] selectedRows = getSelectedRows(beginy, endy); for (int currRow = 0; currRow < plotrows; currRow++) { // 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); java.awt.geom.AffineTransform original = newG.getTransform(); java.awt.geom.AffineTransform affine = newG.getTransform(); affine.concatenate(affine.getTranslateInstance(-1*xShift*currRow, plot_y/2+plotoffset*currRow)); // account for graphics y positive down affine.concatenate(affine.getScaleInstance(1, -1)); newG.setTransform(affine); newG.setPaint(Color.red); AlphaComposite originalComposite = (AlphaComposite)newG.getComposite(); AlphaComposite newComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .4f); Point2D.Float beginPoint = new Point2D.Float(beginx, endx); newG.setPaint(Color.green); newG.setComposite(newComposite); if(isRowSelected(selectedRows, currRow)) { int bx = 0; int by = 0; int ex = 0; int ey = 0; if(currRow == selectedRows[0] ) { System.out.println("Calculating values for start row"); bx = beginx + xShift*currRow ;//-labelXShift + beginx; if(selectedRows.length != 1) { ex = 6000; } else { ex = endx - beginx; } by = -10; ey = 20; } else if(currRow == selectedRows[selectedRows.length -1 ]) { System.out.println("Caculating values for end row "+currRow); bx = xShift*currRow; ex = (endx); by = -10; ey = 20; } else { bx = 0; ex = 6000; by = -10; ey = 20; } System.out.println("NOW DRAW THE rectangle for row "+currRow); newG.drawRect(bx, by, ex, ey); newG.fillRect(bx, by, ex, ey); }//end of if newG.setTransform(original); }//end of for newG.dispose(); } |
by = -10; ey = 20; | private void drawHighlightRegion(Graphics g) { // get new graphics to avoid messing up original Graphics2D newG = (Graphics2D)g.create(); if(g != currentImageGraphics) { newG.translate(labelXShift, titleYShift); newG.clipRect(0, 0, plot_x/plotrows, plot_y +(plotoffset * (plotrows-1))); } int xShift = plot_x/plotrows; int[] selectedRows = getSelectedRows(beginy, endy); for (int currRow = 0; currRow < plotrows; currRow++) { // 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); java.awt.geom.AffineTransform original = newG.getTransform(); java.awt.geom.AffineTransform affine = newG.getTransform(); affine.concatenate(affine.getTranslateInstance(-1*xShift*currRow, plot_y/2+plotoffset*currRow)); // account for graphics y positive down affine.concatenate(affine.getScaleInstance(1, -1)); newG.setTransform(affine); newG.setPaint(Color.red); AlphaComposite originalComposite = (AlphaComposite)newG.getComposite(); AlphaComposite newComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .4f); Point2D.Float beginPoint = new Point2D.Float(beginx, endx); newG.setPaint(Color.green); newG.setComposite(newComposite); if(isRowSelected(selectedRows, currRow)) { int bx = 0; int by = 0; int ex = 0; int ey = 0; if(currRow == selectedRows[0] ) { System.out.println("Calculating values for start row"); bx = beginx + xShift*currRow ;//-labelXShift + beginx; if(selectedRows.length != 1) { ex = 6000; } else { ex = endx - beginx; } by = -10; ey = 20; } else if(currRow == selectedRows[selectedRows.length -1 ]) { System.out.println("Caculating values for end row "+currRow); bx = xShift*currRow; ex = (endx); by = -10; ey = 20; } else { bx = 0; ex = 6000; by = -10; ey = 20; } System.out.println("NOW DRAW THE rectangle for row "+currRow); newG.drawRect(bx, by, ex, ey); newG.fillRect(bx, by, ex, ey); }//end of if newG.setTransform(original); }//end of for newG.dispose(); } |
|
if (propValue != null && propValue.length > 1) { | if (propValue != null && propValue.length() > 1) { | public String getGeographicRegionName(int geoNum) { String propValue = feProps.getProperty("GeogRegion"+geoNum); if (propValue != null && propValue.length > 1) { return propValue; } return "GeoRegion"+geoNum; } |
if (propValue != null && propValue.length > 1) { | if (propValue != null && propValue.length() > 1) { | public String getSeismicRegionName(int seisNum) { String propValue = feProps.getProperty("SeismicRegion"+seisNum); if (propValue != null && propValue.length > 1) { return propValue; } return "SeisRegion"+seisNum; } |
else if (type.equals("mash")){ | /*else if (type.equals("mash")){ | private void setDefaults(Properties d) { if (type.equals("strangebrew")) { for (int i = 0; i<optionString.length; i++) { d.put(optionString[i][0], optionString[i][1]); } } else if (type.equals("mash")){ d.put("optMashVolU", "gallons US"); d.put("optMashTempU", "F"); d.put("optMashRatioU", "qt/lb"); d.put("optMashRatio", "1.25"); d.put("optGrainTemp", "68"); d.put("optTunLossF", "3"); d.put("optBoilTempF", "212"); d.put("optThickDecoctRatio", "0.6"); d.put("optThinDecoctRatio", "0.9"); // default ranges for mash steps - indicates the bottom of the range d.put("optAcidTmpF", "85"); d.put("optGlucanTmpF", "95"); d.put("optProteinTmpF", "113"); d.put("optBetaTmpF", "131"); d.put("optAlphaTmpF", "151"); d.put("optMashoutTmpF", "161"); d.put("optSpargeTmpF", "170"); d.put("optCerealMashTmpF", "155"); } } |
} | }*/ | private void setDefaults(Properties d) { if (type.equals("strangebrew")) { for (int i = 0; i<optionString.length; i++) { d.put(optionString[i][0], optionString[i][1]); } } else if (type.equals("mash")){ d.put("optMashVolU", "gallons US"); d.put("optMashTempU", "F"); d.put("optMashRatioU", "qt/lb"); d.put("optMashRatio", "1.25"); d.put("optGrainTemp", "68"); d.put("optTunLossF", "3"); d.put("optBoilTempF", "212"); d.put("optThickDecoctRatio", "0.6"); d.put("optThinDecoctRatio", "0.9"); // default ranges for mash steps - indicates the bottom of the range d.put("optAcidTmpF", "85"); d.put("optGlucanTmpF", "95"); d.put("optProteinTmpF", "113"); d.put("optBetaTmpF", "131"); d.put("optAlphaTmpF", "151"); d.put("optMashoutTmpF", "161"); d.put("optSpargeTmpF", "170"); d.put("optCerealMashTmpF", "155"); } } |
public DataSetSeismogram (LocalSeismogramImpl seismo, DataSet ds){ this(seismo, ds, seismo.getName()); | public DataSetSeismogram(DataSetSeismogram dss, String name){ this(dss.getSeismogram(), dss.getDataSet(), name); | public DataSetSeismogram (LocalSeismogramImpl seismo, DataSet ds){ this(seismo, ds, seismo.getName()); } |
Reader r = new InputStreamReader(new FileInputStream(new File(buildDir,"build.xml")),"UTF-8"); createConfiguredStream().unmarshal(new XppReader(r),this); r.close(); | Reader r = new BufferedReader(new InputStreamReader(new FileInputStream(new File(buildDir,"build.xml")),"UTF-8")); try { createConfiguredStream().unmarshal(new XppReader(r),this); } catch (StreamException e) { throw new IOException(e.getMessage()); } finally { r.close(); } | private void load(File buildDir) throws IOException { Reader r = new InputStreamReader(new FileInputStream(new File(buildDir,"build.xml")),"UTF-8"); createConfiguredStream().unmarshal(new XppReader(r),this); r.close(); } |
public static UserRole userRoleFactory(User requiredUser, Service requiredService, String serviceExtension) { | public static UserRole userRoleFactory(UserGroup requiredUser, Service requiredService, String serviceExtension) { | public static UserRole userRoleFactory(User requiredUser, Service requiredService, String serviceExtension) { assertNotNull(requiredUser); assertNotNull(requiredService); UserRole userRole = new UserRole(); userRole.setUser(requiredUser); userRole.setService(requiredService); userRole.setServiceExtension(serviceExtension); requiredUser.getRoles().add(userRole); return userRole; } |
userRole.setUser(requiredUser); | userRole.setUserGroup(requiredUser); | public static UserRole userRoleFactory(User requiredUser, Service requiredService, String serviceExtension) { assertNotNull(requiredUser); assertNotNull(requiredService); UserRole userRole = new UserRole(); userRole.setUser(requiredUser); userRole.setService(requiredService); userRole.setServiceExtension(serviceExtension); requiredUser.getRoles().add(userRole); return userRole; } |
if(verbose) | if(verbose) { | public void processEquation(Node node) throws ParseException { MatrixJep mj = (MatrixJep) j; if(verbose) { print("Parsed:\t\t"); println(mj.toString(node)); } Node processed = mj.preprocess(node); if(verbose) { print("Processed:\t"); println(mj.toString(processed)); } Node simp = mj.simplify(processed); if(verbose) print("Simplified:\t"); println(mj.toString(simp)); Object val = mj.evaluate(simp); String s = mj.getPrintVisitor().formatValue(val); println("Value:\t\t"+s); } |
println(mj.toString(simp)); | println(mj.toString(simp)); } | public void processEquation(Node node) throws ParseException { MatrixJep mj = (MatrixJep) j; if(verbose) { print("Parsed:\t\t"); println(mj.toString(node)); } Node processed = mj.preprocess(node); if(verbose) { print("Processed:\t"); println(mj.toString(processed)); } Node simp = mj.simplify(processed); if(verbose) print("Simplified:\t"); println(mj.toString(simp)); Object val = mj.evaluate(simp); String s = mj.getPrintVisitor().formatValue(val); println("Value:\t\t"+s); } |
println("DJep: differentation in JEP. eg. diff(x^2,x)"); | println("DJep: differentiation in JEP. e.g. diff(x^2,x)"); | public void printIntroText() { println("DJep: differentation in JEP. eg. diff(x^2,x)"); printStdHelp(); } |
rsp.sendRedirect(req.getContextPath()); | rsp.sendRedirect(req.getContextPath()+"/"); | public synchronized void doDoDelete( StaplerRequest req, StaplerResponse rsp ) throws IOException { if(!Hudson.adminCheck(req,rsp)) return; Util.deleteRecursive(root); getParent().deleteJob(this); rsp.sendRedirect(req.getContextPath()); } |
MagnetData magnetData = MagnetData.parseFromURI(uri); URN urn = MagnetData.lookupSHA1URN(magnetData); if ( !isURNDownloaded( urn ) ) { SwarmingManager.getInstance().addFileToDownload( uri ); } | InternalFileHandler.downloadUri( uri ); | public synchronized void addMagmaToDownload( File magmaFile ) //Is this still used anywhere? throws URIException, IOException { BufferedInputStream inStream = new BufferedInputStream( new FileInputStream( magmaFile ) ); MagmaParser parser = new MagmaParser( inStream ); parser.start(); List magnetList = parser.getMagnets(); Iterator iter = magnetList.iterator(); while (iter.hasNext()) { String magnet = (String) iter.next(); URI uri = new URI( magnet, true ); MagnetData magnetData = MagnetData.parseFromURI(uri); URN urn = MagnetData.lookupSHA1URN(magnetData); // dont add already downloading urns. if ( !isURNDownloaded( urn ) ) { SwarmingManager.getInstance().addFileToDownload( uri ); } } } |
public SWDownloadFile( DDownloadFile dFile ) | private SWDownloadFile() | public SWDownloadFile( DDownloadFile dFile ) { this(); URN fileUrn = null; if ( dFile.getFileURN() != null ) { fileUrn = new URN( dFile.getFileURN() ); } String destDir = dFile.getDestinationDirectory(); if ( !StringUtils.isEmpty( destDir ) ) { destinationDirectory = new File( destDir ); } initialize( dFile.getLocalFileName(), fileUrn, dFile.getFileSize(), dFile.getSearchTerm(), false ); String incompleteFileName = dFile.getIncompleteFileName(); if ( !StringUtils.isEmpty( incompleteFileName ) ) { try { incompleteManagedFile = FileManager.getInstance().getReadWriteManagedFile( new File( incompleteFileName ) ); } catch ( ManagedFileException exp ) { NLogger.error( NLoggerNames.Download, exp, exp ); incompleteManagedFile = null; } } setCreatedDate( new Date( dFile.getCreationTime() ) ); setDownloadedDate( new Date( dFile.getModificationTime() ) ); status = dFile.getStatus(); memoryFile.createDownloadScopes( dFile ); createDownloadCandidates( dFile ); forceCollectionOfTransferData(); verifyStatus(); if ( isFileCompletedOrMoved() ) { // set transferred data... this is lazy collected from // segments when the download is not completed transferredDataSize = fileSize; // in case some interrupted move occured... or some old downloads // are still sitting there if ( isFileCompleted() ) { if ( memoryFile.getFinishedLength() == 0 ) { setStatus(STATUS_FILE_COMPLETED_MOVED); } } } } |
this(); URN fileUrn = null; if ( dFile.getFileURN() != null ) { fileUrn = new URN( dFile.getFileURN() ); } | allCandidatesList = new ArrayList<SWDownloadCandidate>(); goodCandidatesList = new ArrayList<SWDownloadCandidate>(); mediumCandidatesList = new ArrayList<SWDownloadCandidate>(); badCandidatesList = new ArrayList<SWDownloadCandidate>(); transferCandidatesList = new ArrayList<SWDownloadCandidate>(); queuedCandidatesSet = new HashSet<SWDownloadCandidate>(); allocatedCandidateWorkerMap = new LinkedMap(); candidateCountObj = new IntObj( 0 ); downloadingCandidateCount = 0; queuedCandidateCount = 0; connectingCandidateCount = 0; lastCandidateWorkerCountUpdate = 0; currentProgress = Integer.valueOf( 0 ); createdDate = modifiedDate = new Date( System.currentTimeMillis() ); | public SWDownloadFile( DDownloadFile dFile ) { this(); URN fileUrn = null; if ( dFile.getFileURN() != null ) { fileUrn = new URN( dFile.getFileURN() ); } String destDir = dFile.getDestinationDirectory(); if ( !StringUtils.isEmpty( destDir ) ) { destinationDirectory = new File( destDir ); } initialize( dFile.getLocalFileName(), fileUrn, dFile.getFileSize(), dFile.getSearchTerm(), false ); String incompleteFileName = dFile.getIncompleteFileName(); if ( !StringUtils.isEmpty( incompleteFileName ) ) { try { incompleteManagedFile = FileManager.getInstance().getReadWriteManagedFile( new File( incompleteFileName ) ); } catch ( ManagedFileException exp ) { NLogger.error( NLoggerNames.Download, exp, exp ); incompleteManagedFile = null; } } setCreatedDate( new Date( dFile.getCreationTime() ) ); setDownloadedDate( new Date( dFile.getModificationTime() ) ); status = dFile.getStatus(); memoryFile.createDownloadScopes( dFile ); createDownloadCandidates( dFile ); forceCollectionOfTransferData(); verifyStatus(); if ( isFileCompletedOrMoved() ) { // set transferred data... this is lazy collected from // segments when the download is not completed transferredDataSize = fileSize; // in case some interrupted move occured... or some old downloads // are still sitting there if ( isFileCompleted() ) { if ( memoryFile.getFinishedLength() == 0 ) { setStatus(STATUS_FILE_COMPLETED_MOVED); } } } } |
String destDir = dFile.getDestinationDirectory(); if ( !StringUtils.isEmpty( destDir ) ) { destinationDirectory = new File( destDir ); } initialize( dFile.getLocalFileName(), fileUrn, dFile.getFileSize(), dFile.getSearchTerm(), false ); String incompleteFileName = dFile.getIncompleteFileName(); if ( !StringUtils.isEmpty( incompleteFileName ) ) { try { incompleteManagedFile = FileManager.getInstance().getReadWriteManagedFile( new File( incompleteFileName ) ); } catch ( ManagedFileException exp ) { NLogger.error( NLoggerNames.Download, exp, exp ); incompleteManagedFile = null; } } setCreatedDate( new Date( dFile.getCreationTime() ) ); setDownloadedDate( new Date( dFile.getModificationTime() ) ); status = dFile.getStatus(); memoryFile.createDownloadScopes( dFile ); createDownloadCandidates( dFile ); forceCollectionOfTransferData(); verifyStatus(); if ( isFileCompletedOrMoved() ) { transferredDataSize = fileSize; if ( isFileCompleted() ) { if ( memoryFile.getFinishedLength() == 0 ) { setStatus(STATUS_FILE_COMPLETED_MOVED); } } } | status = STATUS_FILE_WAITING; bandwidthController = BandwidthController.acquireBandwidthController( "DownloadFile-"+toString(), Long.MAX_VALUE ); bandwidthController.activateShortTransferAvg( 1000, 15 ); bandwidthController.linkControllerIntoChain( BandwidthManager.getInstance().getDownloadBandwidthController() ); | public SWDownloadFile( DDownloadFile dFile ) { this(); URN fileUrn = null; if ( dFile.getFileURN() != null ) { fileUrn = new URN( dFile.getFileURN() ); } String destDir = dFile.getDestinationDirectory(); if ( !StringUtils.isEmpty( destDir ) ) { destinationDirectory = new File( destDir ); } initialize( dFile.getLocalFileName(), fileUrn, dFile.getFileSize(), dFile.getSearchTerm(), false ); String incompleteFileName = dFile.getIncompleteFileName(); if ( !StringUtils.isEmpty( incompleteFileName ) ) { try { incompleteManagedFile = FileManager.getInstance().getReadWriteManagedFile( new File( incompleteFileName ) ); } catch ( ManagedFileException exp ) { NLogger.error( NLoggerNames.Download, exp, exp ); incompleteManagedFile = null; } } setCreatedDate( new Date( dFile.getCreationTime() ) ); setDownloadedDate( new Date( dFile.getModificationTime() ) ); status = dFile.getStatus(); memoryFile.createDownloadScopes( dFile ); createDownloadCandidates( dFile ); forceCollectionOfTransferData(); verifyStatus(); if ( isFileCompletedOrMoved() ) { // set transferred data... this is lazy collected from // segments when the download is not completed transferredDataSize = fileSize; // in case some interrupted move occured... or some old downloads // are still sitting there if ( isFileCompleted() ) { if ( memoryFile.getFinishedLength() == 0 ) { setStatus(STATUS_FILE_COMPLETED_MOVED); } } } } |
if ( !managedFile.getFile().exists() ) | if ( !managedFile.exists() ) | public static DPhex loadDPhexFromFile( ManagedFile managedFile ) throws IOException, ManagedFileException { if ( !managedFile.getFile().exists() ) { return null; } NLogger.debug( XMLBuilder.class, "Loading DPhex from: " + managedFile ); InputStream inStream = null; try { managedFile.acquireFileLock(); inStream = new ManagedFileInputStream( managedFile, 0 ); return readDPhexFromStream(inStream); } finally { IOUtil.closeQuietly( inStream ); IOUtil.closeQuietly( managedFile ); managedFile.releaseFileLock(); } } |
public void fireDisplayUserMessage( String userMessageId, String[] args ) | public void fireDisplayUserMessage( String userMessageId ) | public void fireDisplayUserMessage( String userMessageId, String[] args ) { // if initialized if ( userMessageListener != null ) { userMessageListener.displayUserMessage( userMessageId, args ); } } |
userMessageListener.displayUserMessage( userMessageId, args ); | userMessageListener.displayUserMessage( userMessageId, null ); | public void fireDisplayUserMessage( String userMessageId, String[] args ) { // if initialized if ( userMessageListener != null ) { userMessageListener.displayUserMessage( userMessageId, args ); } } |
public void stopDownload() | public void stopDownload( SWDownloadCandidate candidate ) | public void stopDownload() { setStatus( STATUS_FILE_STOPPED ); stopAllWorkers( true ); } |
setStatus( STATUS_FILE_STOPPED ); stopAllWorkers( true ); | SWDownloadWorker worker; synchronized ( candidatesLock ) { worker = (SWDownloadWorker)allocatedCandidateWorkerMap.get( candidate ); } if ( worker != null ) { worker.stopWorker(); worker.waitTillFinished(); } | public void stopDownload() { setStatus( STATUS_FILE_STOPPED ); stopAllWorkers( true ); } |
r.nextBuild = prev.nextBuild; r.previousBuild = prev; if(r.nextBuild!=null) r.nextBuild.previousBuild = r; prev.nextBuild=r; | value.nextBuild = prev.nextBuild; value.previousBuild = prev; if(value.nextBuild!=null) value.nextBuild.previousBuild = value; prev.nextBuild=value; | private R update(TreeMap<Integer, R> m, Integer key, R value) { R r = m.put(key, value); SortedMap<Integer,R> head = m.headMap(key); if(!head.isEmpty()) { R prev = m.get(head.lastKey()); r.nextBuild = prev.nextBuild; r.previousBuild = prev; if(r.nextBuild!=null) r.nextBuild.previousBuild = r; prev.nextBuild=r; } else { if(!m.isEmpty()) { R first = m.get(m.firstKey()); r.nextBuild = first; r.previousBuild = null; first.previousBuild = r; } } return r; } |
r.nextBuild = first; r.previousBuild = null; first.previousBuild = r; | value.nextBuild = first; value.previousBuild = null; first.previousBuild = value; | private R update(TreeMap<Integer, R> m, Integer key, R value) { R r = m.put(key, value); SortedMap<Integer,R> head = m.headMap(key); if(!head.isEmpty()) { R prev = m.get(head.lastKey()); r.nextBuild = prev.nextBuild; r.previousBuild = prev; if(r.nextBuild!=null) r.nextBuild.previousBuild = r; prev.nextBuild=r; } else { if(!m.isEmpty()) { R first = m.get(m.firstKey()); r.nextBuild = first; r.previousBuild = null; first.previousBuild = r; } } return r; } |
if(owner.considerTestAsTestObject()) digester.addCallMethod("*/test", "setconsiderTestAsTestObject"); | public void add( File reportXml ) throws IOException, SAXException { Digester digester = new Digester(); digester.setClassLoader(getClass().getClassLoader()); digester.push(this); digester.addObjectCreate("*/testsuite",Suite.class); digester.addObjectCreate("*/test",Test.class); digester.addObjectCreate("*/testcase",TestCase.class); digester.addSetNext("*/testsuite","add"); digester.addSetNext("*/test","add"); digester.addSetNext("*/testcase","add"); // common properties applicable to more than one TestObjects. digester.addBeanPropertySetter("*/id"); digester.addBeanPropertySetter("*/name"); digester.addBeanPropertySetter("*/description"); digester.addSetProperties("*/status","value","statusString"); // set attributes. in particular @revision digester.addBeanPropertySetter("*/status","statusMessage"); digester.parse(reportXml); } |
|
rsp.sendRedirect(req.getContextPath()); | rsp.sendRedirect(req.getContextPath()+"/"); | public synchronized void doDoDelete( StaplerRequest req, StaplerResponse rsp ) throws IOException { if(!Hudson.adminCheck(req,rsp)) return; owner.deleteView(this); rsp.sendRedirect(req.getContextPath()); } |
lastStackTraceElem = Thread.currentThread().getStackTrace(); | private void checkOpenFile( ) throws ManagedFileException { try { lock.acquire(); } catch ( InterruptedException exp ) { Thread.currentThread().interrupt(); throw new ManagedFileException( "open failes: interrupted", exp ); } try { // check if already open. if ( raFile != null ) { FileManager.getInstance().trackFileInUse(this); return; } FileManager.getInstance().trackFileOpen(this); try { raFile = new RandomAccessFile( fsFile, accessMode.fileMode ); } catch( Exception exp ) { throw new ManagedFileException( "failed to open", exp ); } } finally { lock.release(); } } |
|
private void printCommandLine(String[] cmd) { | private void printCommandLine(String[] cmd, FilePath workDir) { | private void printCommandLine(String[] cmd) { StringBuffer buf = new StringBuffer(); buf.append('$'); for (String c : cmd) { buf.append(' ').append(c); } listener.getLogger().println(buf.toString()); } |
if (workDir != null) { buf.append('['); buf.append(workDir.getRemote().replace("^.+[/\\]", "")); buf.append("] "); } | private void printCommandLine(String[] cmd) { StringBuffer buf = new StringBuffer(); buf.append('$'); for (String c : cmd) { buf.append(' ').append(c); } listener.getLogger().println(buf.toString()); } |
|
public Proc(String[] cmd,String[] env,OutputStream out, File workDir) throws IOException { this( Runtime.getRuntime().exec(cmd,env,workDir), null, out ); | public Proc(String cmd,Map env, OutputStream out, File workDir) throws IOException { this(cmd,mapToEnv(env),out,workDir); | public Proc(String[] cmd,String[] env,OutputStream out, File workDir) throws IOException { this( Runtime.getRuntime().exec(cmd,env,workDir), null, out ); } |
String u = a.substring(i); | String u = a.substring(i); preBoilVol.setQuantity( null, u.trim(), Double.parseDouble(d.trim())); | public void setAmountAndUnits(String a){ int i = a.indexOf(" "); String d = a.substring(0,i); String u = a.substring(i); postBoilVol.setQuantity( null, u.trim(), Double.parseDouble(d.trim())); } |
setPostBoil(Double.parseDouble(d.trim())); | public void setAmountAndUnits(String a){ int i = a.indexOf(" "); String d = a.substring(0,i); String u = a.substring(i); postBoilVol.setQuantity( null, u.trim(), Double.parseDouble(d.trim())); } |
|
public void setCost(String c){ if (c.substring(0,1).equals("$")) { c = c.substring(1, c.length()); } costPerU = Double.parseDouble(c); } | public void setCost(double c){ costPerU = c; } | public void setCost(String c){ if (c.substring(0,1).equals("$")) { c = c.substring(1, c.length()); // trim leading "$" } costPerU = Double.parseDouble(c); } |
dilution = new DilutedRecipe(); | public Recipe() { Options opts = new Options(); name = "My Recipe"; created = new GregorianCalendar(); efficiency = opts.getDProperty("optEfficiency"); preBoilVol.setQuantity(opts.getProperty("optSizeU"), null, opts.getDProperty("optPreBoilVol")); postBoilVol.setQuantity(opts.getProperty("optSizeU"), null, opts.getDProperty("optPostBoilVol")); attenuation = opts.getDProperty("optAttenuation"); boilMinutes = opts.getIProperty("optBoilTime"); ibuCalcMethod = opts.getProperty("optIBUCalcMethod"); ibuHopUtil = opts.getDProperty("optHopsUtil"); hopUnits = opts.getProperty("optHopsU"); maltUnits = opts.getProperty("optMaltU"); brewer = opts.getProperty("optBrewer"); evapMethod = opts.getProperty("optEvapCalcMethod"); evap = opts.getDProperty("optEvaporation"); alcMethod = opts.getProperty("optAlcCalcMethod"); colourMethod = opts.getProperty("optColourMethod"); } |
|
return node; | if(nodeName==null) return Hudson.getInstance(); return Hudson.getInstance().getSlave(nodeName); | public Node getNode() { return node; } |
j.dv.addStandardDiffRules(); | j.addStandardDiffRules(); | public static void main(String args[]) { /* initilisation */ DJep j = new DJep(); j.addStandardConstants(); j.addStandardFunctions(); j.addComplex(); j.setAllowUndeclared(true); j.setAllowAssignment(true); j.setImplicitMul(true); j.dv.addStandardDiffRules(); try { // parse the string Node node = j.parse("sin(x^2)"); // differentiate wrt x Node diff = j.differentiate(node,"x"); // print j.println(diff); // simplify Node simp = j.simplify(diff); // print j.println(simp); // This time the differentation is specified by // the diff(eqn,var) function Node node2 = j.parse("diff(cos(x^3),x)"); // To actually make diff do its work the // equation needs to be preprocessed Node processed = j.preprocess(node2); j.println(processed); // finally simplify Node simp2 = j.simplify(processed); j.println(simp2); // Now combine assignment and differentation Node node3 = j.parse("y=x^5"); j.preprocess(node3); Node node4 = j.parse("diff(y^2+x,x)"); Node simp3 = j.simplify(j.preprocess(node4)); j.dpv.setPrintVariableEquations(true); j.println(simp3); j.dpv.setPrintPartialEquations(false); j.dpv.setPrintVariableEquations(false); j.println(simp3); Node node5 = j.parse("y"); j.println(node5); j.dpv.setPrintVariableEquations(true); j.println(node5); j.getSymbolTable().setVarValue("x",new Double(5)); System.out.println(j.evaluate(simp3)); j.evaluate(node3); System.out.println(j.getSymbolTable().getVar("y").getValue()); j.getSymbolTable().setVarValue("x",new Double(0)); System.out.println(j.evaluate(simp)); Node node10 = j.parse("x=3"); Node node11 = j.preprocess(node10); System.out.println(j.evaluate(node11)); Node node12 = j.parse("y=x^2"); Node node13 = j.preprocess(node12); System.out.println(j.evaluate(node13)); Node node14 = j.parse("z=diff(y,x)"); Node node15 = j.simplify(j.preprocess(node14)); System.out.println(j.evaluate(node15)); // If a variable is changed then any expresion tree // it depends on needs to be re-evaluated to bring // values of other variables upto date j.setVarValue("x",new Double(4)); System.out.println(j.evaluate(node13)); System.out.println(j.evaluate(node15)); System.out.println("z: "+j.getVarValue("z").toString()); // the findVarValue method will automatically // re-calculate the value of variables specified by // equations if needed. However a lazy j.setVarValue("x",new Double(5)); System.out.println("j.setVarValue(\"x\",new Double(5));"); System.out.println("j.findVarValue(y): "+j.findVarValue("y").toString()); System.out.println("j.findVarValue(z): "+j.findVarValue("z").toString()); // if j.getSymbolTable().clearValues(); // is called before values of equations are set // then the values of intermediate equations // are automatically calculated, so you can jump // straight to the chase: no need to calculate // y explititly to find the value of z. j.getSymbolTable().clearValues(); j.setVarValue("x",new Double(6)); System.out.println("j.setVarValue(\"x\",new Double(6));"); System.out.println("j.findVarValue(z): "+j.findVarValue("z").toString()); j.getSymbolTable().clearValues(); j.setVarValue("x",new Double(7)); System.out.println(j.evaluate(node15)); System.out.println("z: "+j.getVarValue("z").toString()); } catch(ParseException e) { System.out.println("Error with parsing"); } catch(Exception e) { System.out.println("Error with evaluation"); } } |
j.dpv.setPrintVariableEquations(true); | j.getDPrintVisitor().setPrintVariableEquations(true); | public static void main(String args[]) { /* initilisation */ DJep j = new DJep(); j.addStandardConstants(); j.addStandardFunctions(); j.addComplex(); j.setAllowUndeclared(true); j.setAllowAssignment(true); j.setImplicitMul(true); j.dv.addStandardDiffRules(); try { // parse the string Node node = j.parse("sin(x^2)"); // differentiate wrt x Node diff = j.differentiate(node,"x"); // print j.println(diff); // simplify Node simp = j.simplify(diff); // print j.println(simp); // This time the differentation is specified by // the diff(eqn,var) function Node node2 = j.parse("diff(cos(x^3),x)"); // To actually make diff do its work the // equation needs to be preprocessed Node processed = j.preprocess(node2); j.println(processed); // finally simplify Node simp2 = j.simplify(processed); j.println(simp2); // Now combine assignment and differentation Node node3 = j.parse("y=x^5"); j.preprocess(node3); Node node4 = j.parse("diff(y^2+x,x)"); Node simp3 = j.simplify(j.preprocess(node4)); j.dpv.setPrintVariableEquations(true); j.println(simp3); j.dpv.setPrintPartialEquations(false); j.dpv.setPrintVariableEquations(false); j.println(simp3); Node node5 = j.parse("y"); j.println(node5); j.dpv.setPrintVariableEquations(true); j.println(node5); j.getSymbolTable().setVarValue("x",new Double(5)); System.out.println(j.evaluate(simp3)); j.evaluate(node3); System.out.println(j.getSymbolTable().getVar("y").getValue()); j.getSymbolTable().setVarValue("x",new Double(0)); System.out.println(j.evaluate(simp)); Node node10 = j.parse("x=3"); Node node11 = j.preprocess(node10); System.out.println(j.evaluate(node11)); Node node12 = j.parse("y=x^2"); Node node13 = j.preprocess(node12); System.out.println(j.evaluate(node13)); Node node14 = j.parse("z=diff(y,x)"); Node node15 = j.simplify(j.preprocess(node14)); System.out.println(j.evaluate(node15)); // If a variable is changed then any expresion tree // it depends on needs to be re-evaluated to bring // values of other variables upto date j.setVarValue("x",new Double(4)); System.out.println(j.evaluate(node13)); System.out.println(j.evaluate(node15)); System.out.println("z: "+j.getVarValue("z").toString()); // the findVarValue method will automatically // re-calculate the value of variables specified by // equations if needed. However a lazy j.setVarValue("x",new Double(5)); System.out.println("j.setVarValue(\"x\",new Double(5));"); System.out.println("j.findVarValue(y): "+j.findVarValue("y").toString()); System.out.println("j.findVarValue(z): "+j.findVarValue("z").toString()); // if j.getSymbolTable().clearValues(); // is called before values of equations are set // then the values of intermediate equations // are automatically calculated, so you can jump // straight to the chase: no need to calculate // y explititly to find the value of z. j.getSymbolTable().clearValues(); j.setVarValue("x",new Double(6)); System.out.println("j.setVarValue(\"x\",new Double(6));"); System.out.println("j.findVarValue(z): "+j.findVarValue("z").toString()); j.getSymbolTable().clearValues(); j.setVarValue("x",new Double(7)); System.out.println(j.evaluate(node15)); System.out.println("z: "+j.getVarValue("z").toString()); } catch(ParseException e) { System.out.println("Error with parsing"); } catch(Exception e) { System.out.println("Error with evaluation"); } } |
j.dpv.setPrintPartialEquations(false); j.dpv.setPrintVariableEquations(false); | j.getDPrintVisitor().setPrintPartialEquations(false); j.getDPrintVisitor().setPrintVariableEquations(false); | public static void main(String args[]) { /* initilisation */ DJep j = new DJep(); j.addStandardConstants(); j.addStandardFunctions(); j.addComplex(); j.setAllowUndeclared(true); j.setAllowAssignment(true); j.setImplicitMul(true); j.dv.addStandardDiffRules(); try { // parse the string Node node = j.parse("sin(x^2)"); // differentiate wrt x Node diff = j.differentiate(node,"x"); // print j.println(diff); // simplify Node simp = j.simplify(diff); // print j.println(simp); // This time the differentation is specified by // the diff(eqn,var) function Node node2 = j.parse("diff(cos(x^3),x)"); // To actually make diff do its work the // equation needs to be preprocessed Node processed = j.preprocess(node2); j.println(processed); // finally simplify Node simp2 = j.simplify(processed); j.println(simp2); // Now combine assignment and differentation Node node3 = j.parse("y=x^5"); j.preprocess(node3); Node node4 = j.parse("diff(y^2+x,x)"); Node simp3 = j.simplify(j.preprocess(node4)); j.dpv.setPrintVariableEquations(true); j.println(simp3); j.dpv.setPrintPartialEquations(false); j.dpv.setPrintVariableEquations(false); j.println(simp3); Node node5 = j.parse("y"); j.println(node5); j.dpv.setPrintVariableEquations(true); j.println(node5); j.getSymbolTable().setVarValue("x",new Double(5)); System.out.println(j.evaluate(simp3)); j.evaluate(node3); System.out.println(j.getSymbolTable().getVar("y").getValue()); j.getSymbolTable().setVarValue("x",new Double(0)); System.out.println(j.evaluate(simp)); Node node10 = j.parse("x=3"); Node node11 = j.preprocess(node10); System.out.println(j.evaluate(node11)); Node node12 = j.parse("y=x^2"); Node node13 = j.preprocess(node12); System.out.println(j.evaluate(node13)); Node node14 = j.parse("z=diff(y,x)"); Node node15 = j.simplify(j.preprocess(node14)); System.out.println(j.evaluate(node15)); // If a variable is changed then any expresion tree // it depends on needs to be re-evaluated to bring // values of other variables upto date j.setVarValue("x",new Double(4)); System.out.println(j.evaluate(node13)); System.out.println(j.evaluate(node15)); System.out.println("z: "+j.getVarValue("z").toString()); // the findVarValue method will automatically // re-calculate the value of variables specified by // equations if needed. However a lazy j.setVarValue("x",new Double(5)); System.out.println("j.setVarValue(\"x\",new Double(5));"); System.out.println("j.findVarValue(y): "+j.findVarValue("y").toString()); System.out.println("j.findVarValue(z): "+j.findVarValue("z").toString()); // if j.getSymbolTable().clearValues(); // is called before values of equations are set // then the values of intermediate equations // are automatically calculated, so you can jump // straight to the chase: no need to calculate // y explititly to find the value of z. j.getSymbolTable().clearValues(); j.setVarValue("x",new Double(6)); System.out.println("j.setVarValue(\"x\",new Double(6));"); System.out.println("j.findVarValue(z): "+j.findVarValue("z").toString()); j.getSymbolTable().clearValues(); j.setVarValue("x",new Double(7)); System.out.println(j.evaluate(node15)); System.out.println("z: "+j.getVarValue("z").toString()); } catch(ParseException e) { System.out.println("Error with parsing"); } catch(Exception e) { System.out.println("Error with evaluation"); } } |
nl(); | public void ignorableWhitespace(char buf[], int offset, int len) throws SAXException { nl(); // emit("IGNORABLE"); } |
|
nl(); | public void processingInstruction(String target, String data) throws SAXException { nl(); emit("PROCESS: "); emit("<?" + target + " " + data + "?>"); } |
|
else if (currentElement.equalsIgnoreCase("YEAST_COST")) { r.getYeastObj().setCost((Double.parseDouble(s))); } else if (currentElement.equalsIgnoreCase("OTHER_COST")) { r.setOtherCost(Double.parseDouble(s)); } | void sbCharacters(String s){ if (currentList.equals("FERMENTABLES")) { if (currentElement.equalsIgnoreCase("MALT")) { m.setName(s); } else if (currentElement.equalsIgnoreCase("AMOUNT")) { m.setAmount(Double.parseDouble(s)); } else if (currentElement.equalsIgnoreCase("POINTS")) { m.setPppg(Double.parseDouble(s)); } else if (currentElement.equalsIgnoreCase("COSTLB")) { m.setCost( s ); } else if (currentElement.equalsIgnoreCase("UNITS")) { m.setUnits(s); } else if (currentElement.equalsIgnoreCase("LOV")) { m.setLov(Double.parseDouble(s)); } else if (currentElement.equalsIgnoreCase("DescrLookup")) { m.setDescription(s); } } else if (currentList.equalsIgnoreCase("HOPS")) { if (currentElement.equalsIgnoreCase("HOP")) { h.setName(s); } else if (currentElement.equalsIgnoreCase("AMOUNT")) { h.setAmount(Double.parseDouble(s)); } else if (currentElement.equalsIgnoreCase("ALPHA")) { h.setAlpha(Double.parseDouble(s)); } else if (currentElement.equalsIgnoreCase("UNITS")) { h.setUnits(s); } else if (currentElement.equalsIgnoreCase("FORM")) { h.setType(s); } else if (currentElement.equalsIgnoreCase("COSTOZ")) { h.setCost( s ); } else if (currentElement.equalsIgnoreCase("ADD")) { h.setAdd(s); } else if (currentElement.equalsIgnoreCase("DescrLookup")) { descrBuf = descrBuf + s; } else if (currentElement.equalsIgnoreCase("TIME")) { h.setMinutes(Integer.parseInt(s)); } } else if (currentList.equalsIgnoreCase("MISC")) { if (currentElement.equalsIgnoreCase("NAME")) { misc.setName(s); } else if (currentElement.equalsIgnoreCase("AMOUNT")) { misc.setAmount(Double.parseDouble(s)); } else if (currentElement.equalsIgnoreCase("UNITS")) { misc.setUnits(s); } else if (currentElement.equalsIgnoreCase("COMMENTS")) { misc.setComments(s); } else if (currentElement.equalsIgnoreCase("COST_PER_U")) { // misc.setCost( Double.parseDouble(s) ); } else if (currentElement.equalsIgnoreCase("ADD")) { h.setAdd(s); } else if (currentElement.equalsIgnoreCase("DescrLookup")) { descrBuf = descrBuf + s; } else if (currentElement.equalsIgnoreCase("TIME")) { misc.setTime(Integer.parseInt(s)); } else if (currentElement.equalsIgnoreCase("STAGE")) { misc.setStage(s); } } else if (currentList.equalsIgnoreCase("NOTES")) { if (currentElement.equalsIgnoreCase("DATE")) { DateFormat df = new SimpleDateFormat("MM/dd/yyyy"); try { Date d = df.parse(s); note.setDate(d); } catch(ParseException e) { System.out.println("Unable to parse " + s); } } else if (currentElement.equalsIgnoreCase("TYPE")) { note.setType(s); } else if (currentElement.equalsIgnoreCase("NOTE")) { note.setNote(s); } } else if (currentList.equalsIgnoreCase("MASH")) { if (currentElement.equalsIgnoreCase("TYPE")) { type = s; } else if (currentElement.equalsIgnoreCase("TEMP")) { startTemp = Double.parseDouble(s); } else if (currentElement.equalsIgnoreCase("METHOD")) { method = s; } else if (currentElement.equalsIgnoreCase("MIN")) { minutes = Integer.parseInt(s); } else if (currentElement.equalsIgnoreCase("END_TEMP")) { endTemp = Double.parseDouble(s); } else if (currentElement.equalsIgnoreCase("RAMP_MIN")) { rampMin = Integer.parseInt(s); } } else if (currentList.equalsIgnoreCase("DETAILS")) { if (currentElement.equalsIgnoreCase("NAME")) { // r.setName(s); buffer = buffer + s; } else if (currentElement.equalsIgnoreCase("EFFICIENCY")) { r.setEfficiency(Double.parseDouble(s)); } else if (currentElement.equalsIgnoreCase("ATTENUATION")) { r.setAttenuation(Double.parseDouble(s)); } else if (currentElement.equalsIgnoreCase("PRESIZE")) { r.setPreBoil(Double.parseDouble(s)); } else if (currentElement.equalsIgnoreCase("SIZE")) { r.setPostBoil(Double.parseDouble(s)); } else if (currentElement.equalsIgnoreCase("SIZE_UNITS")) { // also sets postboil: r.setVolUnits(s); } else if (currentElement.equalsIgnoreCase("STYLE")) { r.setStyle(s); } else if (currentElement.equalsIgnoreCase("BOIL_TIME")) { r.setBoilMinutes(Integer.parseInt(s)); } else if (currentElement.equalsIgnoreCase("HOPS_UNITS")) { r.setHopsUnits(s); } else if (currentElement.equalsIgnoreCase("MALT_UNITS")) { r.setMaltUnits(s); } else if (currentElement.equalsIgnoreCase("MASH_RATIO")) { r.setMashRatio(Double.parseDouble(s)); } else if (currentElement.equalsIgnoreCase("MASH_RATIO_U")) { r.setMashRatioU(s); } else if (currentElement.equalsIgnoreCase("BREWER")) { r.setBrewer(s); } else if (currentElement.equalsIgnoreCase("MASH")) { r.setMashed(Boolean.valueOf(s).booleanValue()); } else if (currentElement.equalsIgnoreCase("YEAST")) { r.setYeastName(s); } else if (currentElement.equalsIgnoreCase("RECIPE_DATE")) { DateFormat df = new SimpleDateFormat("MM/dd/yyyy"); try { Date d = df.parse(s); r.setCreated(d); } catch(ParseException e) { System.out.println("Unable to parse " + s); } // These are SBJ1.0 Extensions: } else if (currentElement.equalsIgnoreCase("ALC_METHOD")) { r.setAlcMethod(s); } else if (currentElement.equalsIgnoreCase("IBU_METHOD")) { r.setIBUMethod(s); } else if (currentElement.equalsIgnoreCase("COLOUR_METHOD")) { r.setColourMethod(s); } else if (currentElement.equalsIgnoreCase("EVAP")) { r.setEvap(Double.parseDouble(s)); } else if (currentElement.equalsIgnoreCase("EVAP_METHOD")) { r.setEvapMethod(s); } else if (currentElement.equalsIgnoreCase("KETTLE_LOSS")) { r.setKettleLoss(Double.parseDouble(s)); } else if (currentElement.equalsIgnoreCase("MISC_LOSS")) { r.setMiscLoss(Double.parseDouble(s)); } else if (currentElement.equalsIgnoreCase("TRUB_LOSS")) { r.setTrubLoss(Double.parseDouble(s)); } else if (currentElement.equalsIgnoreCase("PELLET_HOP_PCT")) { r.setPelletHopPct(Double.parseDouble(s)); } } else s = ""; } |
|
public XMLDataSet(DocumentBuilder docBuilder, URL base, Element config) { this(docBuilder, base); this.config = config; | public XMLDataSet(DocumentBuilder docBuilder, URL datasetURL) { this.base = datasetURL; this.docBuilder = docBuilder; Document doc = docBuilder.newDocument(); config = doc.createElement("dataset"); config.setAttribute("xmlns:xlink", "http: | public XMLDataSet(DocumentBuilder docBuilder, URL base, Element config) { this(docBuilder, base); this.config = config; } |
name = getUniqueName(name); | name = getUniqueName(getSeismogramNames(), name); | public void addSeismogram(LocalSeismogramImpl seis, AuditInfo[] audit) { seismogramNameCache = null; // Note this does not set the xlink, as the seis has not been saved anywhere yet. Document doc = config.getOwnerDocument(); Element localSeismogram = doc.createElement("localSeismogram");//doc.createElement("SacSeismogram"); String name =seis.getProperty(seisNameKey); if (name == null || name.length() == 0) { name = seis.channel_id.network_id.network_code+"."+ seis.channel_id.station_code+"."+ seis.channel_id.channel_code; //edu.iris.Fissures.network.ChannelIdUtil.toStringNoDates(seis.channel_id); } name = getUniqueName(name); seis.setName(name); Element seismogramAttr = doc.createElement("seismogramAttr"); XMLSeismogramAttr.insert(seismogramAttr, (LocalSeismogram)seis); //localSeismogram.appendChild(seismogramAttr); Element propertyElement = doc.createElement("property"); propertyElement.appendChild(XMLUtil.createTextElement(doc, "name", "Name")); propertyElement.appendChild(XMLUtil.createTextElement(doc, "value", name)); ///seismogramAttr.appendChild(propertyElement); localSeismogram.appendChild(seismogramAttr); Property[] props = seis.getProperties(); //System.out.println("the length of the Properties of the seismogram are "+props.length); Element propE, propNameE, propValueE; for (int i=0; i<props.length; i++) { if (props[i].name != seisNameKey) { propE = doc.createElement("property"); propNameE = doc.createElement("name"); propNameE.setNodeValue(props[i].name); propValueE = doc.createElement("value"); propValueE.setNodeValue(props[i].value); propE.appendChild(propNameE); propE.appendChild(propValueE); localSeismogram.appendChild(propE); } } config.appendChild(localSeismogram); seismogramCache.put(name, seis); logger.debug("added seis now "+getSeismogramNames().length+" seisnogram names."); seismogramNameCache = null; //xpath = new XPathAPI(); //xpath = new CachedXPathAPI(xpath); logger.debug("2 added seis now "+getSeismogramNames().length+" seisnogram names."); } |
if (props[i].name != seisNameKey) { | if (props[i] != null && props[i].name != seisNameKey) { | public void addSeismogram(LocalSeismogramImpl seis, AuditInfo[] audit) { seismogramNameCache = null; // Note this does not set the xlink, as the seis has not been saved anywhere yet. Document doc = config.getOwnerDocument(); Element localSeismogram = doc.createElement("localSeismogram");//doc.createElement("SacSeismogram"); String name =seis.getProperty(seisNameKey); if (name == null || name.length() == 0) { name = seis.channel_id.network_id.network_code+"."+ seis.channel_id.station_code+"."+ seis.channel_id.channel_code; //edu.iris.Fissures.network.ChannelIdUtil.toStringNoDates(seis.channel_id); } name = getUniqueName(name); seis.setName(name); Element seismogramAttr = doc.createElement("seismogramAttr"); XMLSeismogramAttr.insert(seismogramAttr, (LocalSeismogram)seis); //localSeismogram.appendChild(seismogramAttr); Element propertyElement = doc.createElement("property"); propertyElement.appendChild(XMLUtil.createTextElement(doc, "name", "Name")); propertyElement.appendChild(XMLUtil.createTextElement(doc, "value", name)); ///seismogramAttr.appendChild(propertyElement); localSeismogram.appendChild(seismogramAttr); Property[] props = seis.getProperties(); //System.out.println("the length of the Properties of the seismogram are "+props.length); Element propE, propNameE, propValueE; for (int i=0; i<props.length; i++) { if (props[i].name != seisNameKey) { propE = doc.createElement("property"); propNameE = doc.createElement("name"); propNameE.setNodeValue(props[i].name); propValueE = doc.createElement("value"); propValueE.setNodeValue(props[i].value); propE.appendChild(propNameE); propE.appendChild(propValueE); localSeismogram.appendChild(propE); } } config.appendChild(localSeismogram); seismogramCache.put(name, seis); logger.debug("added seis now "+getSeismogramNames().length+" seisnogram names."); seismogramNameCache = null; //xpath = new XPathAPI(); //xpath = new CachedXPathAPI(xpath); logger.debug("2 added seis now "+getSeismogramNames().length+" seisnogram names."); } |
name = getUniqueName(name); | name = getUniqueName(getSeismogramNames(), name); | public void addSeismogramRef(LocalSeismogramImpl seis, URL seisURL, String name, Property[] props, ParameterRef[] parm_ids, AuditInfo[] audit) { seismogramNameCache = null; String baseStr = base.toString(); String seisStr = seisURL.toString(); if (seisStr.startsWith(baseStr)) { // use relative URL seisStr = seisStr.substring(baseStr.length()); } // end of if (seisStr.startsWith(baseStr)) Document doc = config.getOwnerDocument(); Element localSeismogram = doc.createElement("localSeismogram"); if(name == null || name.length() == 0) { name =seis.getProperty(seisNameKey); } if (name == null || name.length() == 0) { name = edu.iris.Fissures.network.ChannelIdUtil.toStringNoDates(seis.channel_id); } name = getUniqueName(name); seis.setName(name); Element seismogramAttr = doc.createElement("seismogramAttr"); XMLSeismogramAttr.insert(seismogramAttr, (LocalSeismogram)seis); //localSeismogram.appendChild(seismogramAttr); Element propertyElement = doc.createElement("property"); propertyElement.appendChild(XMLUtil.createTextElement(doc, "name", "Name")); propertyElement.appendChild(XMLUtil.createTextElement(doc, "value", name)); //seismogramAttr.appendChild(propertyElement); localSeismogram.appendChild(seismogramAttr); Element data = doc.createElement("data"); data.setAttributeNS(xlinkNS, "xlink:type", "simple"); data.setAttributeNS(xlinkNS, "xlink:href", seisStr); data.setAttribute("seisType", "sac"); //Element nameE = doc.createElement("name"); // Text text = doc.createTextNode(name); //nameE.appendChild(text); //localSeismogram.appendChild(nameE); localSeismogram.appendChild(data); /* Element propE, propNameE, propValueE; for (int i=0; i<props.length; i++) { if (props[i].name != seisNameKey) { propE = doc.createElement("property"); propNameE = doc.createElement("name"); text = doc.createTextNode(props[i].name); propNameE.appendChild(text); propValueE = doc.createElement("value"); text = doc.createTextNode(props[i].value); propValueE.appendChild(text); propE.appendChild(propNameE); propE.appendChild(propValueE); sac.appendChild(propE); } }*/ config.appendChild(localSeismogram); } |
addDataSet(dataset, audit); | public DataSet createChildDataSet(String id, String name, String owner, AuditInfo[] audit) { dataSetIdCache = null; XMLDataSet dataset = new XMLDataSet(docBuilder, base, id, name, owner); addDataSet(dataset, audit); return dataset; } |
|
if (name == ds.getName()) { | logger.debug("++++++++ name is "+name +" the datasetID name is "+ds.getName()); if (name.equals(ds.getName())) { | public DataSet getDataSet(String name) { String[] ids = getDataSetIds(); for (int i=0; i<ids.length; i++) { DataSet ds = getDataSetById(ids[i]); if (name == ds.getName()) { return ds; } } // end of for (int i=0; i<ids.length; i++) return null; } |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.