Skip to content

Commit

Permalink
More updates for Pantry mode, #150, you can now enable a tickbox in
Browse files Browse the repository at this point in the history
brewer preferences to hide Non Stock items.
  • Loading branch information
dougedey committed Sep 15, 2012
1 parent 22b4492 commit dcf3f05
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 8 deletions.
Binary file modified StrangeBrew-2.0.3-ALPHA.zip
Binary file not shown.
29 changes: 24 additions & 5 deletions src/ca/strangebrew/Database.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ public class Database {
// read from the csv files.

private static Database instance = null;

private Options preferences = Options.getInstance();
public List<Fermentable> fermDB = new ArrayList<Fermentable>();
public List<Fermentable> stockFermDB = new ArrayList<Fermentable>();
public List<Hop> hopsDB = new ArrayList<Hop>();
public List<Hop> stockHopsDB = new ArrayList<Hop>();
final public List<Yeast> yeastDB = new ArrayList<Yeast>();
public List<Style> styleDB = new ArrayList<Style>();
final public List<Misc> miscDB = new ArrayList<Misc>();
Expand Down Expand Up @@ -368,6 +370,13 @@ public void readFermentables(String path) {
f.setDescription(res.getString("Descr"));
f.setModified(Boolean.valueOf(res.getString("Modified")).booleanValue());
fermDB.add(f);

// check to see if we have nonStock set

if(f.getStock() > 0.00 ) {
Debug.print("Adding to Stock DB");
stockFermDB.add(f);
}
}
Collections.sort(fermDB);

Expand Down Expand Up @@ -498,6 +507,7 @@ public void writeFermentables() {
}
//clear the list
fermDB = new ArrayList<Fermentable>();
stockFermDB = new ArrayList<Fermentable>();

Debug.print("Trying to update DB at: "+dbPath);
readFermentables(dbPath);
Expand Down Expand Up @@ -637,6 +647,10 @@ public void readHops(String path) {
h.setModified(Boolean.valueOf(res.getString("Modified")).booleanValue());
hopsDB.add(h);

if(h.getStock() > 0 && preferences.getProperty("optHideNonStock") != null && preferences.getProperty("optHideNonStock") == "true") {
stockHopsDB.add(h);
}

//Item,Name,Yield,Lov,Cost,Stock,Units,Mash,Descr,Steep,Modified
Debug.print("Loading from database: "+ res.getString("Name"));

Expand Down Expand Up @@ -693,7 +707,7 @@ public void writeHops() {
insertMisc.setString(7, Double.toString(h.getStorage()));
insertMisc.setString(8, h.getDate().toString());
insertMisc.executeUpdate();
} else { // do update
} else { // check to see if we need to update

rStatement.setString(1, h.getName());
rStatement.setString(2, Double.toString(h.getAlpha()));
Expand Down Expand Up @@ -725,7 +739,11 @@ public void writeHops() {
}
}


//clear the list
hopsDB = new ArrayList<Hop>();
stockHopsDB = new ArrayList<Hop>();

readHops(dbPath);

} catch (SQLException e) {
// TODO Auto-generated catch block
Expand Down Expand Up @@ -847,6 +865,7 @@ public void readYeast(String path) {
e.printStackTrace();
}
Collections.sort(hopsDB);
Collections.sort(stockHopsDB);



Expand Down Expand Up @@ -934,7 +953,7 @@ public void readStyles(String path){
fields = reader.getAllFieldsInLine();

//Item,Name, Category,OG_Low,OG_High,Alc_Low,Alc_High,IBU_Low,IBU_High,Lov_Low,Lov_High,Comm_examples,Descr
Debug.print("SELECT COUNT(*) FROM styleguide WHERE name='"+fields[nameIdx]+"';");
//Debug.print("SELECT COUNT(*) FROM styleguide WHERE name='"+fields[nameIdx]+"';");
pStatement = conn.prepareStatement("SELECT COUNT(*) FROM styleguide WHERE name=?;");

pStatement.setString(1, fields[nameIdx]);
Expand Down Expand Up @@ -1141,7 +1160,7 @@ public void importStyles(String path, String year){
s.comments = res.getString("Comments");
if(res.getString("Ingredients") != null)
s.ingredients = res.getString("Ingredients");
Debug.print("Adding style " + s.getName() + s.toText());
// Debug.print("Adding style " + s.getName() + s.toText());
styleDB.add(s);
}

Expand Down
2 changes: 1 addition & 1 deletion src/ca/strangebrew/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ public int getIProperty(String key){

public boolean getBProperty(String key) {
String s = props.getProperty(key);
if (s.equalsIgnoreCase("true")) {
if (s != null && s.equalsIgnoreCase("true")) {
return true;
}
return false;
Expand Down
2 changes: 2 additions & 0 deletions src/ca/strangebrew/ui/swing/MaltTableModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import ca.strangebrew.Debug;
import ca.strangebrew.Fermentable;
import ca.strangebrew.Options;
import ca.strangebrew.Recipe;
import ca.strangebrew.SBStringUtils;

Expand Down Expand Up @@ -128,6 +129,7 @@ public void setValueAt(Object value, int row, int col) {

data.setMaltName(row, value.toString());


// Shouldn't this re-set most of the data fields with base info
if (value instanceof Fermentable) {
Fermentable m = (Fermentable)value;
Expand Down
32 changes: 30 additions & 2 deletions src/ca/strangebrew/ui/swing/StrangeSwing.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@

import com.michaelbaranov.microba.calendar.DatePicker;


import edu.stanford.ejalbert.BrowserLauncher;
import edu.stanford.ejalbert.BrowserLauncherRunner;
import edu.stanford.ejalbert.exception.BrowserLaunchingInitializingException;
Expand Down Expand Up @@ -472,10 +473,18 @@ public StrangeSwing() throws UnsupportedEncodingException {
cmbStyleModel.setList(DB.styleDB);
cmbYeastModel.setList(DB.yeastDB);

cmbMaltModel.setList(DB.fermDB);
// check to see if we are hiding non stock ingredients
Debug.print("OptHideNonStock: "+preferences.getProperty("optHideNonStock"));
if(preferences.getProperty("optHideNonStock") != null && preferences.getBProperty("optHideNonStock") ) {
Debug.print("Hiding Stock");
cmbMaltModel.setList(DB.stockFermDB);
cmbHopsModel.setList(DB.stockHopsDB);
} else {
cmbMaltModel.setList(DB.fermDB);
cmbHopsModel.setList(DB.hopsDB);
}


cmbHopsModel.setList(DB.hopsDB);
carbPanel.setList(DB.primeSugarDB);
// waterTreatmentPanel.setList(DB.waterDB);

Expand Down Expand Up @@ -2090,6 +2099,25 @@ else if (o == saveButton) {
PreferencesDialog d = new PreferencesDialog(this);
d.setVisible(true);
preferences = d.getOpts();
String path;
try {
path = SBStringUtils.getAppPath("data");
DB.readDB(path, preferences.getProperty("optStyleYear"));
Debug.print("OptHideNonStock: "+preferences.getProperty("optHideNonStock"));
if(preferences.getProperty("optHideNonStock") != null && preferences.getBProperty("optHideNonStock") ) {
Debug.print("Hiding Stock");
cmbMaltModel.setList(DB.stockFermDB);
cmbHopsModel.setList(DB.stockHopsDB);
} else {
cmbMaltModel.setList(DB.fermDB);
cmbHopsModel.setList(DB.hopsDB);
}
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}


} else if (o == exitMenuItem) {
// exit program
processWindowEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
Expand Down
11 changes: 11 additions & 0 deletions src/ca/strangebrew/ui/swing/dialogs/PreferencesDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ public class PreferencesDialog extends javax.swing.JDialog implements ActionList
final private JLabel swingTheme = new JLabel();
private JComboBox swingComboBox = new JComboBox();
final private JLabel currentTheme = new JLabel();
final private JCheckBox checkStock = new JCheckBox("Show Stock");

// Carb
final private GridBagLayout layoutCarbPanel = new GridBagLayout();
Expand Down Expand Up @@ -309,6 +310,7 @@ private void setOptions() {
txtServTemp.setText(opts.getProperty("optServTemp"));
txtVol.setText(opts.getProperty("optVolsCO2"));
checkKegged.setSelected(opts.getBProperty("optKegged"));
checkStock.setSelected(opts.getBProperty("optHideNonStock"));
comboTubingID.setSelectedItem(opts.getProperty("optTubingID"));
textHeight.setText(opts.getProperty("optHeightAboveKeg"));

Expand Down Expand Up @@ -392,6 +394,7 @@ private void saveOptions() {
opts.setProperty("optKegged", "false");
}


// Brewer tab:
opts.setProperty("optBrewer", txtBrewerName.getText());
opts.setProperty("optPhone", txtPhone.getText());
Expand All @@ -400,6 +403,13 @@ private void saveOptions() {
opts.setProperty("optRecipe", txtRecipe.getText());
opts.setProperty("optAppearance", ((Looks)swingComboBox.getSelectedItem()).value);

if (checkStock.isSelected()) {
opts.setProperty("optHideNonStock", "true");

} else {
opts.setProperty("optHideNonStock", "false");
}

// TODO
opts.setLocale((Locale)localeComboBox.getSelectedItem());

Expand Down Expand Up @@ -842,6 +852,7 @@ GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(0, 0,
localeLabel.setText("Set Locale:");
}
{
pnlBrewer.add(checkStock, constraints);
pnlBrewer.add(localeComboBox, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0,
GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(0,
0, 0, 0), 0, 0));
Expand Down

0 comments on commit dcf3f05

Please sign in to comment.