recipeList.setSelectedIndex(lastClicked);
}
if (DatabaseHandler.isConnected()) {
int index = recipeList.locationToIndex(evt.getPoint());
if (index >= 0) {
RecipeType recipe = DatabaseHandler.recipeByNum(DatabaseHandler.getRecipeByName((String) recipeListModel.get(index)));
while (ingredientModel.getRowCount() > 0) {
ingredientModel.removeRow(0);
}
List<IngredientType> ingredients = recipe.getIngredients();
for (IngredientType i : ingredients) {
String[] temp = new String[2];
temp[0] = i.getName();
if (i.getNumerator() == 0) {
temp[1] = "";
} else if (i.getDenominator() == 0) {
temp[1] = "" + i.getNumerator();
} else {
temp[1] = i.getNumerator() + "/" + i.getDenominator();
}
temp[1] += " " + i.getUnit();
ingredientModel.addRow(temp);
}
int counter = 1;
String instructions = "";
for (String s : recipe.getSteps()) {
instructions += counter + ": " + s + "\n\n";
counter++;
}
instructionTextField.setText(instructions);
}