poprawki wzorców projektowych pod MVC
poprawki interfejsu usunięcie przestarzałych plików
This commit is contained in:
BIN
cookbook.db
BIN
cookbook.db
Binary file not shown.
@@ -54,7 +54,6 @@ public class Cookbook {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* funkcja przestarzała (deprecated) - do usunięcia w bliskiej przyszłości - PioDer */
|
|
||||||
public boolean insertRecipe(String name, String ingredients, String description, String tags, byte[] imgArr) {
|
public boolean insertRecipe(String name, String ingredients, String description, String tags, byte[] imgArr) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,12 @@ package db;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import ksiazka.kucharska.CB_View;
|
||||||
|
|
||||||
public abstract class SearchRecipe {
|
public abstract class SearchRecipe {
|
||||||
|
protected CB_View tV;
|
||||||
public abstract List<String> obtainRecipeNames();
|
public abstract List<String> obtainRecipeNames();
|
||||||
|
public SearchRecipe(CB_View v) {
|
||||||
|
tV = v;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -2,13 +2,17 @@ package db;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import ksiazka.kucharska.FrmMain;
|
import ksiazka.kucharska.CB_View;
|
||||||
|
|
||||||
public class SearchRecipeNameTag extends SearchRecipe {
|
public class SearchRecipeNameTag extends SearchRecipe {
|
||||||
|
|
||||||
|
public SearchRecipeNameTag(CB_View v) {
|
||||||
|
super(v);
|
||||||
|
}
|
||||||
|
|
||||||
public List<String> obtainRecipeNames() {
|
public List<String> obtainRecipeNames() {
|
||||||
Cookbook myCb = new Cookbook();
|
Cookbook myCb = new Cookbook();
|
||||||
List<String> names = myCb.obtainSearchedNames(FrmMain.txtSearch.getText(), FrmMain.txtSearch.getText());
|
List<String> names = myCb.obtainSearchedNames(tV.getSearchValue(), tV.getSearchValue());
|
||||||
myCb.closeConnection();
|
myCb.closeConnection();
|
||||||
|
|
||||||
return names;
|
return names;
|
||||||
|
|||||||
@@ -16,10 +16,15 @@ import javax.swing.JFileChooser;
|
|||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JList;
|
import javax.swing.JList;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
|
import javax.swing.event.DocumentEvent;
|
||||||
|
import javax.swing.event.DocumentListener;
|
||||||
import javax.swing.event.ListSelectionEvent;
|
import javax.swing.event.ListSelectionEvent;
|
||||||
import javax.swing.event.ListSelectionListener;
|
import javax.swing.event.ListSelectionListener;
|
||||||
|
|
||||||
|
import db.SearchRecipeAll;
|
||||||
import db.Cookbook;
|
import db.Cookbook;
|
||||||
|
import db.SearchRecipe;
|
||||||
|
import db.SearchRecipeNameTag;
|
||||||
|
|
||||||
public class CB_Controller {
|
public class CB_Controller {
|
||||||
private static CB_View theView;
|
private static CB_View theView;
|
||||||
@@ -34,11 +39,21 @@ public class CB_Controller {
|
|||||||
CB_Controller.theView.cancelListener(new CancelListener());
|
CB_Controller.theView.cancelListener(new CancelListener());
|
||||||
CB_Controller.theView.saveListener(new SaveListener());
|
CB_Controller.theView.saveListener(new SaveListener());
|
||||||
CB_Controller.theView.listSelectListener(new SelectionListener());
|
CB_Controller.theView.listSelectListener(new SelectionListener());
|
||||||
|
CB_Controller.theView.searchTypeListener(new SearchListener());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fillList(){
|
public void fillList(){
|
||||||
Cookbook myCb = new Cookbook();
|
Cookbook myCb = new Cookbook();
|
||||||
List<String> names = myCb.selectNames();
|
SearchRecipe sr;
|
||||||
|
if (theView.getSearchValue() != "") {
|
||||||
|
sr = new SearchRecipeNameTag(theView);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sr = new SearchRecipeAll(theView);
|
||||||
|
}
|
||||||
|
List<String> names = sr.obtainRecipeNames();
|
||||||
|
|
||||||
theView.setRecipesList(names);
|
theView.setRecipesList(names);
|
||||||
myCb.closeConnection();
|
myCb.closeConnection();
|
||||||
}
|
}
|
||||||
@@ -57,7 +72,7 @@ public class CB_Controller {
|
|||||||
Cookbook myCb = new Cookbook();
|
Cookbook myCb = new Cookbook();
|
||||||
|
|
||||||
RecipeManager rm = new RecipeManager();
|
RecipeManager rm = new RecipeManager();
|
||||||
rm.setRecipeBuilder(new NewRecipeBuilder());
|
rm.setRecipeBuilder(new NewRecipeBuilder(theView));
|
||||||
rm.constructRecipe();
|
rm.constructRecipe();
|
||||||
|
|
||||||
CB_Model obj = rm.getRecipe();
|
CB_Model obj = rm.getRecipe();
|
||||||
@@ -96,12 +111,12 @@ public class CB_Controller {
|
|||||||
{
|
{
|
||||||
int dialogResult = JOptionPane.showConfirmDialog (null, "Czy na pewno chcesz usunąć przepis?", "Pytanie", JOptionPane.YES_NO_OPTION);
|
int dialogResult = JOptionPane.showConfirmDialog (null, "Czy na pewno chcesz usunąć przepis?", "Pytanie", JOptionPane.YES_NO_OPTION);
|
||||||
if(dialogResult == JOptionPane.YES_OPTION){
|
if(dialogResult == JOptionPane.YES_OPTION){
|
||||||
RetrieveData.removeRecipe(recipesList.getSelectedValue().toString());
|
removeRecipe(recipesList.getSelectedValue().toString());
|
||||||
model.remove(recipesList.getSelectedIndex());
|
model.remove(recipesList.getSelectedIndex());
|
||||||
if (recipesList.getModel().getSize()>0)
|
if (recipesList.getModel().getSize()>0)
|
||||||
{
|
{
|
||||||
recipesList.setSelectedIndex(0);
|
recipesList.setSelectedIndex(0);
|
||||||
RetrieveData.fillComponents(recipesList.getSelectedValue().toString());
|
fillComponents(recipesList.getSelectedValue().toString());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -147,7 +162,6 @@ public class CB_Controller {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
catch(NumberFormatException ex){
|
catch(NumberFormatException ex){
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -177,12 +191,10 @@ public class CB_Controller {
|
|||||||
|
|
||||||
try{
|
try{
|
||||||
addNewRecipe();
|
addNewRecipe();
|
||||||
/*JList recipesList = theView.getRecipesList();
|
theView.setRecipesListItem(theView.getRecipeEdTitle());
|
||||||
DefaultListModel model = (DefaultListModel) recipesList.getModel();
|
|
||||||
model.addElement(theView.getRecipeTitle());*/
|
|
||||||
theView.DeactivateAddMenu();
|
theView.DeactivateAddMenu();
|
||||||
/*recipesList.setSelectedIndex(recipesList.getModel().getSize()-1);
|
theView.getRecipesList().setSelectedIndex(theView.getRecipesList().getModel().getSize()-1);
|
||||||
fillComponents(recipesList.getSelectedValue().toString());*/
|
fillComponents(theView.getRecipesList().getSelectedValue().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
catch(NumberFormatException ex){
|
catch(NumberFormatException ex){
|
||||||
@@ -207,5 +219,18 @@ public class CB_Controller {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class SearchListener implements DocumentListener{
|
||||||
|
|
||||||
|
public void changedUpdate(DocumentEvent e) {
|
||||||
|
fillList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void insertUpdate(DocumentEvent e) {
|
||||||
|
fillList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeUpdate(DocumentEvent e) {
|
||||||
|
fillList();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,13 @@ package ksiazka.kucharska;
|
|||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.image.ImageObserver;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import javax.swing.border.EmptyBorder;
|
import javax.swing.border.EmptyBorder;
|
||||||
import javax.swing.border.LineBorder;
|
import javax.swing.border.LineBorder;
|
||||||
|
import javax.swing.event.DocumentListener;
|
||||||
import javax.swing.event.ListSelectionListener;
|
import javax.swing.event.ListSelectionListener;
|
||||||
import javax.swing.filechooser.FileNameExtensionFilter;
|
import javax.swing.filechooser.FileNameExtensionFilter;
|
||||||
|
|
||||||
@@ -40,14 +42,14 @@ public class CB_View extends JFrame{
|
|||||||
this.setResizable(false);
|
this.setResizable(false);
|
||||||
this.setTitle("Książka Kucharska v1.0");
|
this.setTitle("Książka Kucharska v1.0");
|
||||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
this.setBounds(100, 100, 723, 549);
|
this.setBounds(100, 100, 720, 551);
|
||||||
|
|
||||||
JPanel contentPane = new JPanel();
|
JPanel contentPane = new JPanel();
|
||||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||||
contentPane.setLayout(new BorderLayout(0, 0));
|
contentPane.setLayout(new BorderLayout(0, 0));
|
||||||
this.setContentPane(contentPane);
|
this.setContentPane(contentPane);
|
||||||
|
|
||||||
splitPane.setResizeWeight(0.1);
|
splitPane.setResizeWeight(0.35);
|
||||||
splitPane.setRequestFocusEnabled(false);
|
splitPane.setRequestFocusEnabled(false);
|
||||||
splitPane.setPreferredSize(new Dimension(200, 27));
|
splitPane.setPreferredSize(new Dimension(200, 27));
|
||||||
splitPane.setDividerSize(5);
|
splitPane.setDividerSize(5);
|
||||||
@@ -57,41 +59,16 @@ public class CB_View extends JFrame{
|
|||||||
JPanel panel = new JPanel();
|
JPanel panel = new JPanel();
|
||||||
panel.setMaximumSize(new Dimension(100, 32767));
|
panel.setMaximumSize(new Dimension(100, 32767));
|
||||||
splitPane.setLeftComponent(panel);
|
splitPane.setLeftComponent(panel);
|
||||||
GridBagLayout gbl_panel = new GridBagLayout();
|
txtSearch.setBounds(5, 5, 237, 20);
|
||||||
gbl_panel.columnWidths = new int[] {0, 0};
|
|
||||||
gbl_panel.rowHeights = new int[] {0, 0, 0};
|
|
||||||
gbl_panel.columnWeights = new double[]{1.0, 1.0};
|
|
||||||
gbl_panel.rowWeights = new double[]{0.0, 1.0, 0.0};
|
|
||||||
panel.setLayout(gbl_panel);
|
|
||||||
|
|
||||||
GridBagConstraints gbc_txtSearch = new GridBagConstraints();
|
|
||||||
gbc_txtSearch.gridwidth = 2;
|
|
||||||
gbc_txtSearch.insets = new Insets(5, 5, 5, 0);
|
|
||||||
gbc_txtSearch.fill = GridBagConstraints.HORIZONTAL;
|
|
||||||
gbc_txtSearch.gridx = 0;
|
|
||||||
gbc_txtSearch.gridy = 0;
|
|
||||||
txtSearch.setColumns(10);
|
txtSearch.setColumns(10);
|
||||||
|
scrollPane_2.setBounds(5, 30, 237, 453);
|
||||||
|
|
||||||
scrollPane_2.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
|
scrollPane_2.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
|
||||||
scrollPane_2.setMaximumSize(new Dimension(100, 100));
|
scrollPane_2.setMaximumSize(new Dimension(100, 100));
|
||||||
|
recipesList.setSize(new Dimension(100, 0));
|
||||||
|
recipesList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||||
|
recipesList.setMaximumSize(new Dimension(40, 0));
|
||||||
scrollPane_2.setViewportView(recipesList);
|
scrollPane_2.setViewportView(recipesList);
|
||||||
GridBagConstraints gbc_scrollPane_2 = new GridBagConstraints();
|
|
||||||
gbc_scrollPane_2.gridwidth = 2;
|
|
||||||
gbc_scrollPane_2.insets = new Insets(0, 0, 5, 0);
|
|
||||||
gbc_scrollPane_2.fill = GridBagConstraints.BOTH;
|
|
||||||
gbc_scrollPane_2.gridx = 0;
|
|
||||||
gbc_scrollPane_2.gridy = 1;
|
|
||||||
|
|
||||||
GridBagConstraints gbc_btnAddRecipe = new GridBagConstraints();
|
|
||||||
gbc_btnAddRecipe.fill = GridBagConstraints.HORIZONTAL;
|
|
||||||
gbc_btnAddRecipe.insets = new Insets(0, 5, 0, 5);
|
|
||||||
gbc_btnAddRecipe.gridx = 0;
|
|
||||||
gbc_btnAddRecipe.gridy = 2;
|
|
||||||
|
|
||||||
GridBagConstraints gbc_btnDelRecipe = new GridBagConstraints();
|
|
||||||
gbc_btnDelRecipe.fill = GridBagConstraints.HORIZONTAL;
|
|
||||||
gbc_btnDelRecipe.gridx = 1;
|
|
||||||
gbc_btnDelRecipe.gridy = 2;
|
|
||||||
|
|
||||||
JPanel panel_2 = new JPanel();
|
JPanel panel_2 = new JPanel();
|
||||||
splitPane.setRightComponent(panel_2);
|
splitPane.setRightComponent(panel_2);
|
||||||
@@ -155,18 +132,15 @@ public class CB_View extends JFrame{
|
|||||||
scrollPane_2.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
|
scrollPane_2.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
|
||||||
scrollPane_2.setMaximumSize(new Dimension(100, 100));
|
scrollPane_2.setMaximumSize(new Dimension(100, 100));
|
||||||
scrollPane_2.setViewportView(recipesList);
|
scrollPane_2.setViewportView(recipesList);
|
||||||
|
panel.setLayout(null);
|
||||||
|
|
||||||
gbc_scrollPane_2.gridwidth = 2;
|
panel.add(txtSearch);
|
||||||
gbc_scrollPane_2.insets = new Insets(0, 0, 5, 0);
|
panel.add(scrollPane_2);
|
||||||
gbc_scrollPane_2.fill = GridBagConstraints.BOTH;
|
btnAddRecipe.setBounds(5, 486, 116, 25);
|
||||||
gbc_scrollPane_2.gridx = 0;
|
panel.add(btnAddRecipe);
|
||||||
gbc_scrollPane_2.gridy = 1;
|
btnDelRecipe.setBounds(125, 486, 116, 25);
|
||||||
|
panel.add(btnDelRecipe);
|
||||||
panel.add(txtSearch, gbc_txtSearch);
|
panel.add(txtSearch);
|
||||||
panel.add(scrollPane_2, gbc_scrollPane_2);
|
|
||||||
panel.add(btnAddRecipe, gbc_btnAddRecipe);
|
|
||||||
panel.add(btnDelRecipe, gbc_btnDelRecipe);
|
|
||||||
panel.add(txtSearch, gbc_txtSearch);
|
|
||||||
panel_2.add(btnSave);
|
panel_2.add(btnSave);
|
||||||
panel_2.add(txtEdTitle);
|
panel_2.add(txtEdTitle);
|
||||||
panel_2.add(lblRecipeTitle);
|
panel_2.add(lblRecipeTitle);
|
||||||
@@ -182,13 +156,16 @@ public class CB_View extends JFrame{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getRecipeTitle(){
|
public String getRecipeTitle(){
|
||||||
return lblRecipeTitle.getText().toString();
|
return lblRecipeTitle.getText();
|
||||||
|
}
|
||||||
|
public String getRecipeEdTitle(){
|
||||||
|
return txtEdTitle.getText();
|
||||||
}
|
}
|
||||||
public String getRecipeIngredients(){
|
public String getRecipeIngredients(){
|
||||||
return txtIngredients.getText().toString();
|
return txtIngredients.getText();
|
||||||
}
|
}
|
||||||
public String getRecipeDescription(){
|
public String getRecipeDescription(){
|
||||||
return txtDescription.getText().toString();
|
return txtDescription.getText();
|
||||||
}
|
}
|
||||||
public String getRecipeTags(){
|
public String getRecipeTags(){
|
||||||
return txtTags.getText().toString();
|
return txtTags.getText().toString();
|
||||||
@@ -202,7 +179,12 @@ public class CB_View extends JFrame{
|
|||||||
public JLabel getImgRecipe(){
|
public JLabel getImgRecipe(){
|
||||||
return imgRecipe;
|
return imgRecipe;
|
||||||
}
|
}
|
||||||
|
public ImageIcon getDefaultImgRecipe(){
|
||||||
|
return imgDefaultRecipe;
|
||||||
|
}
|
||||||
|
public String getSearchValue(){
|
||||||
|
return txtSearch.getText();
|
||||||
|
}
|
||||||
public void setRecipeTitle(String name){
|
public void setRecipeTitle(String name){
|
||||||
lblRecipeTitle.setText(name);
|
lblRecipeTitle.setText(name);
|
||||||
}
|
}
|
||||||
@@ -216,11 +198,15 @@ public class CB_View extends JFrame{
|
|||||||
txtTags.setText(tags);
|
txtTags.setText(tags);
|
||||||
}
|
}
|
||||||
public void setRecipesList(List<String> names){
|
public void setRecipesList(List<String> names){
|
||||||
|
recipesListModel.clear();
|
||||||
for (String r : names)
|
for (String r : names)
|
||||||
{
|
{
|
||||||
recipesListModel.addElement(r);
|
recipesListModel.addElement(r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public void setRecipesListItem(String item){
|
||||||
|
recipesListModel.addElement(item);
|
||||||
|
}
|
||||||
public void setRecipeIcon(Icon icon){
|
public void setRecipeIcon(Icon icon){
|
||||||
imgRecipe.setIcon(icon);
|
imgRecipe.setIcon(icon);
|
||||||
}
|
}
|
||||||
@@ -244,8 +230,11 @@ public class CB_View extends JFrame{
|
|||||||
void saveListener(ActionListener listenForAddButton){
|
void saveListener(ActionListener listenForAddButton){
|
||||||
btnSave.addActionListener(listenForAddButton);
|
btnSave.addActionListener(listenForAddButton);
|
||||||
}
|
}
|
||||||
void listSelectListener(ListSelectionListener listenForSelectionChagnge){
|
void listSelectListener(ListSelectionListener listenForSelectionChange){
|
||||||
recipesList.addListSelectionListener(listenForSelectionChagnge);
|
recipesList.addListSelectionListener(listenForSelectionChange);
|
||||||
|
}
|
||||||
|
void searchTypeListener(DocumentListener listenForSearchTyping){
|
||||||
|
txtSearch.getDocument().addDocumentListener(listenForSearchTyping);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeactivateAddMenu() {
|
void DeactivateAddMenu() {
|
||||||
|
|||||||
@@ -1,381 +0,0 @@
|
|||||||
package ksiazka.kucharska;
|
|
||||||
|
|
||||||
import java.awt.BorderLayout;
|
|
||||||
|
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
|
||||||
import javax.swing.JFrame;
|
|
||||||
import javax.swing.JPanel;
|
|
||||||
import javax.swing.border.EmptyBorder;
|
|
||||||
import javax.swing.DefaultListModel;
|
|
||||||
import javax.swing.ImageIcon;
|
|
||||||
import javax.swing.JFileChooser;
|
|
||||||
import javax.swing.JOptionPane;
|
|
||||||
import javax.swing.JScrollPane;
|
|
||||||
import javax.swing.JSplitPane;
|
|
||||||
import javax.swing.JButton;
|
|
||||||
import javax.swing.JTextField;
|
|
||||||
|
|
||||||
import java.awt.Graphics2D;
|
|
||||||
import java.awt.GridBagLayout;
|
|
||||||
import java.awt.GridBagConstraints;
|
|
||||||
import java.awt.Insets;
|
|
||||||
import java.awt.RenderingHints;
|
|
||||||
|
|
||||||
import javax.swing.JList;
|
|
||||||
import javax.swing.JTextArea;
|
|
||||||
import javax.swing.JLabel;
|
|
||||||
import java.awt.Font;
|
|
||||||
import javax.swing.border.LineBorder;
|
|
||||||
import java.awt.SystemColor;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import javax.swing.SwingConstants;
|
|
||||||
import ksiazka.kucharska.RetrieveData;
|
|
||||||
|
|
||||||
import javax.swing.event.DocumentEvent;
|
|
||||||
import javax.swing.event.DocumentListener;
|
|
||||||
import javax.swing.event.ListSelectionListener;
|
|
||||||
import javax.swing.event.ListSelectionEvent;
|
|
||||||
import javax.swing.filechooser.FileNameExtensionFilter;
|
|
||||||
import javax.swing.ScrollPaneConstants;
|
|
||||||
import java.awt.Dimension;
|
|
||||||
import java.awt.event.InputMethodListener;
|
|
||||||
import java.awt.event.InputMethodEvent;
|
|
||||||
|
|
||||||
public class FrmMain extends JFrame {
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private static final long serialVersionUID = 2634383304749703669L;
|
|
||||||
private JPanel contentPane;
|
|
||||||
<<<<<<< HEAD
|
|
||||||
public static JTextField txtSearch;
|
|
||||||
public static JTextField txtEdTitle;
|
|
||||||
=======
|
|
||||||
private JTextField txtSearch;
|
|
||||||
public static JTextField txtEdTitle;
|
|
||||||
>>>>>>> 17d917cc3f055645be7f87095a3ba404b9b885e9
|
|
||||||
public static JTextField txtTags;
|
|
||||||
private JButton btnSave;
|
|
||||||
private JButton btnCancel;
|
|
||||||
public static JTextArea txtDescription;
|
|
||||||
private JButton btnAddRecipe;
|
|
||||||
private JButton btnDelRecipe;
|
|
||||||
private JButton btnLoadImg;
|
|
||||||
public static JLabel lblRecipeTitle;
|
|
||||||
private static DefaultListModel recipesListModel;
|
|
||||||
public static JLabel imgRecipe;
|
|
||||||
private JFileChooser fcImg;
|
|
||||||
public static ImageIcon imgDefaultRecipe;
|
|
||||||
private JList recipesList;
|
|
||||||
private JScrollPane scrollPane_1;
|
|
||||||
public static JTextArea txtIngredients;
|
|
||||||
private JScrollPane scrollPane_2;
|
|
||||||
|
|
||||||
void DeactivateAddMenu() {
|
|
||||||
btnAddRecipe.setEnabled(true);
|
|
||||||
btnCancel.setVisible(false);
|
|
||||||
btnDelRecipe.setEnabled(true);
|
|
||||||
btnLoadImg.setVisible(false);
|
|
||||||
txtSearch.setEnabled(true);
|
|
||||||
btnSave.setVisible(false);
|
|
||||||
txtDescription.setEditable(false);
|
|
||||||
txtEdTitle.setVisible(false);
|
|
||||||
txtIngredients.setEditable(false);
|
|
||||||
txtTags.setEditable(false);
|
|
||||||
lblRecipeTitle.setVisible(true);
|
|
||||||
recipesList.setEnabled(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ActivateAddMenu() {
|
|
||||||
btnAddRecipe.setEnabled(false);
|
|
||||||
btnCancel.setVisible(true);
|
|
||||||
btnDelRecipe.setEnabled(false);
|
|
||||||
btnLoadImg.setVisible(true);
|
|
||||||
txtSearch.setEnabled(false);
|
|
||||||
btnSave.setVisible(true);
|
|
||||||
txtDescription.setEditable(true);
|
|
||||||
txtEdTitle.setVisible(true);
|
|
||||||
txtIngredients.setEditable(true);
|
|
||||||
txtTags.setEditable(true);
|
|
||||||
lblRecipeTitle.setVisible(false);
|
|
||||||
recipesList.setEnabled(false);
|
|
||||||
imgRecipe.setIcon(imgDefaultRecipe);
|
|
||||||
txtDescription.setText("");
|
|
||||||
txtEdTitle.setText("");
|
|
||||||
txtIngredients.setText("");
|
|
||||||
txtTags.setText("");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static DefaultListModel getRecipesList()
|
|
||||||
{
|
|
||||||
return recipesListModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create the frame.
|
|
||||||
*/
|
|
||||||
public FrmMain() {
|
|
||||||
setResizable(false);
|
|
||||||
setTitle("Książka Kucharska v1.0");
|
|
||||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
||||||
setBounds(100, 100, 723, 549);
|
|
||||||
contentPane = new JPanel();
|
|
||||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
|
||||||
contentPane.setLayout(new BorderLayout(0, 0));
|
|
||||||
setContentPane(contentPane);
|
|
||||||
|
|
||||||
JSplitPane splitPane = new JSplitPane();
|
|
||||||
splitPane.setResizeWeight(0.1);
|
|
||||||
splitPane.setRequestFocusEnabled(false);
|
|
||||||
splitPane.setPreferredSize(new Dimension(200, 27));
|
|
||||||
splitPane.setDividerSize(5);
|
|
||||||
splitPane.setEnabled(false);
|
|
||||||
contentPane.add(splitPane, BorderLayout.CENTER);
|
|
||||||
|
|
||||||
JPanel panel = new JPanel();
|
|
||||||
panel.setMaximumSize(new Dimension(100, 32767));
|
|
||||||
splitPane.setLeftComponent(panel);
|
|
||||||
GridBagLayout gbl_panel = new GridBagLayout();
|
|
||||||
gbl_panel.columnWidths = new int[] {0, 0};
|
|
||||||
gbl_panel.rowHeights = new int[] {0, 0, 0};
|
|
||||||
gbl_panel.columnWeights = new double[]{1.0, 1.0};
|
|
||||||
gbl_panel.rowWeights = new double[]{0.0, 1.0, 0.0};
|
|
||||||
panel.setLayout(gbl_panel);
|
|
||||||
|
|
||||||
txtSearch = new JTextField();
|
|
||||||
<<<<<<< HEAD
|
|
||||||
txtSearch.setText("");
|
|
||||||
|
|
||||||
=======
|
|
||||||
>>>>>>> 17d917cc3f055645be7f87095a3ba404b9b885e9
|
|
||||||
GridBagConstraints gbc_txtSearch = new GridBagConstraints();
|
|
||||||
gbc_txtSearch.gridwidth = 2;
|
|
||||||
gbc_txtSearch.insets = new Insets(5, 5, 5, 0);
|
|
||||||
gbc_txtSearch.fill = GridBagConstraints.HORIZONTAL;
|
|
||||||
gbc_txtSearch.gridx = 0;
|
|
||||||
gbc_txtSearch.gridy = 0;
|
|
||||||
panel.add(txtSearch, gbc_txtSearch);
|
|
||||||
txtSearch.setColumns(10);
|
|
||||||
|
|
||||||
recipesListModel = new DefaultListModel();
|
|
||||||
recipesList = new JList(recipesListModel);
|
|
||||||
recipesList.addListSelectionListener(new ListSelectionListener() {
|
|
||||||
public void valueChanged(ListSelectionEvent e){
|
|
||||||
if(recipesList.getSelectedIndex() != -1)
|
|
||||||
RetrieveData.fillComponents(recipesList.getSelectedValue().toString());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
scrollPane_2 = new JScrollPane();
|
|
||||||
scrollPane_2.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
|
|
||||||
scrollPane_2.setMaximumSize(new Dimension(100, 100));
|
|
||||||
scrollPane_2.setViewportView(recipesList);
|
|
||||||
GridBagConstraints gbc_scrollPane_2 = new GridBagConstraints();
|
|
||||||
gbc_scrollPane_2.gridwidth = 2;
|
|
||||||
gbc_scrollPane_2.insets = new Insets(0, 0, 5, 0);
|
|
||||||
gbc_scrollPane_2.fill = GridBagConstraints.BOTH;
|
|
||||||
gbc_scrollPane_2.gridx = 0;
|
|
||||||
gbc_scrollPane_2.gridy = 1;
|
|
||||||
panel.add(scrollPane_2, gbc_scrollPane_2);
|
|
||||||
|
|
||||||
|
|
||||||
btnAddRecipe = new JButton("Nowy");
|
|
||||||
GridBagConstraints gbc_btnAddRecipe = new GridBagConstraints();
|
|
||||||
gbc_btnAddRecipe.fill = GridBagConstraints.HORIZONTAL;
|
|
||||||
gbc_btnAddRecipe.insets = new Insets(0, 5, 0, 5);
|
|
||||||
gbc_btnAddRecipe.gridx = 0;
|
|
||||||
gbc_btnAddRecipe.gridy = 2;
|
|
||||||
panel.add(btnAddRecipe, gbc_btnAddRecipe);
|
|
||||||
btnAddRecipe.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
ActivateAddMenu();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
btnDelRecipe = new JButton("Usuń");
|
|
||||||
GridBagConstraints gbc_btnDelRecipe = new GridBagConstraints();
|
|
||||||
gbc_btnDelRecipe.fill = GridBagConstraints.HORIZONTAL;
|
|
||||||
gbc_btnDelRecipe.gridx = 1;
|
|
||||||
gbc_btnDelRecipe.gridy = 2;
|
|
||||||
panel.add(btnDelRecipe, gbc_btnDelRecipe);
|
|
||||||
btnDelRecipe.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
DefaultListModel model = (DefaultListModel) recipesList.getModel();
|
|
||||||
if (recipesList.getSelectedIndex() != -1)
|
|
||||||
{
|
|
||||||
int dialogResult = JOptionPane.showConfirmDialog (null, "Czy na pewno chcesz usunąć przepis?", "Pytanie", JOptionPane.YES_NO_OPTION);
|
|
||||||
if(dialogResult == JOptionPane.YES_OPTION){
|
|
||||||
RetrieveData.removeRecipe(recipesList.getSelectedValue().toString());
|
|
||||||
model.remove(recipesList.getSelectedIndex());
|
|
||||||
if (recipesList.getModel().getSize()>0)
|
|
||||||
{
|
|
||||||
recipesList.setSelectedIndex(0);
|
|
||||||
RetrieveData.fillComponents(recipesList.getSelectedValue().toString());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
txtDescription.setText("");
|
|
||||||
lblRecipeTitle.setText("Nazwa przepisu");
|
|
||||||
txtIngredients.setText("");
|
|
||||||
txtTags.setText("");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
JPanel panel_2 = new JPanel();
|
|
||||||
splitPane.setRightComponent(panel_2);
|
|
||||||
panel_2.setLayout(null);
|
|
||||||
|
|
||||||
btnSave = new JButton("Dodaj");
|
|
||||||
btnSave.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
RetrieveData.addNewRecipe();
|
|
||||||
DefaultListModel model = (DefaultListModel) recipesList.getModel();
|
|
||||||
model.addElement(txtEdTitle.getText());
|
|
||||||
DeactivateAddMenu();
|
|
||||||
recipesList.setSelectedIndex(recipesList.getModel().getSize()-1);
|
|
||||||
RetrieveData.fillComponents(recipesList.getSelectedValue().toString());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
btnSave.setVisible(false);
|
|
||||||
btnSave.setBounds(319, 12, 117, 25);
|
|
||||||
panel_2.add(btnSave);
|
|
||||||
|
|
||||||
txtEdTitle = new JTextField();
|
|
||||||
txtEdTitle.setVisible(false);
|
|
||||||
txtEdTitle.setBounds(26, 15, 281, 19);
|
|
||||||
panel_2.add(txtEdTitle);
|
|
||||||
txtEdTitle.setColumns(10);
|
|
||||||
|
|
||||||
|
|
||||||
lblRecipeTitle = new JLabel("Nazwa przepisu");
|
|
||||||
lblRecipeTitle.setFont(new Font("Dialog", Font.BOLD, 18));
|
|
||||||
lblRecipeTitle.setBounds(12, 12, 442, 22);
|
|
||||||
panel_2.add(lblRecipeTitle);
|
|
||||||
|
|
||||||
JLabel lblIngredients = new JLabel("Składniki:");
|
|
||||||
lblIngredients.setBounds(26, 61, 70, 15);
|
|
||||||
panel_2.add(lblIngredients);
|
|
||||||
|
|
||||||
imgRecipe = new JLabel("");
|
|
||||||
imgRecipe.setHorizontalAlignment(SwingConstants.CENTER);
|
|
||||||
imgRecipe.setBorder(new LineBorder(SystemColor.textHighlightText));
|
|
||||||
imgRecipe.setBounds(272, 88, 164, 126);
|
|
||||||
panel_2.add(imgRecipe);
|
|
||||||
|
|
||||||
btnLoadImg = new JButton("Wczytaj");
|
|
||||||
|
|
||||||
fcImg = new JFileChooser();
|
|
||||||
FileNameExtensionFilter ffAll = new FileNameExtensionFilter("Wszystkie grafiki", "jpg", "jpeg", "gif", "png");
|
|
||||||
fcImg.addChoosableFileFilter(ffAll);
|
|
||||||
fcImg.addChoosableFileFilter(new FileNameExtensionFilter("Pliki JPEG", "jpg", "jpeg"));
|
|
||||||
fcImg.addChoosableFileFilter(new FileNameExtensionFilter("Pliki GIF", "gif"));
|
|
||||||
fcImg.addChoosableFileFilter(new FileNameExtensionFilter("Pliki PNG", "png"));
|
|
||||||
fcImg.setAcceptAllFileFilterUsed(false);
|
|
||||||
fcImg.setFileFilter(ffAll);
|
|
||||||
imgDefaultRecipe = new ImageIcon("no_img_recipe.jpg");
|
|
||||||
imgRecipe.setIcon(imgDefaultRecipe);
|
|
||||||
|
|
||||||
|
|
||||||
btnLoadImg.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent arg0) {
|
|
||||||
int returnVal = fcImg.showOpenDialog(FrmMain.this);
|
|
||||||
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
|
||||||
File file = fcImg.getSelectedFile();
|
|
||||||
try {
|
|
||||||
BufferedImage srcImg = ImageIO.read(file);
|
|
||||||
|
|
||||||
int w = (int)Math.ceil(srcImg.getWidth()/(double)srcImg.getHeight()*imgRecipe.getHeight());
|
|
||||||
|
|
||||||
BufferedImage resizedImg = new BufferedImage(w, imgRecipe.getHeight(), BufferedImage.TYPE_INT_ARGB);
|
|
||||||
Graphics2D g2 = resizedImg.createGraphics();
|
|
||||||
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
|
|
||||||
g2.drawImage(srcImg, 0, 0, w, imgRecipe.getHeight(), null);
|
|
||||||
g2.dispose();
|
|
||||||
ImageIcon iconLogo = new ImageIcon(resizedImg);
|
|
||||||
imgRecipe.setIcon(iconLogo);
|
|
||||||
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
btnLoadImg.setVisible(false);
|
|
||||||
|
|
||||||
JScrollPane scrollPane = new JScrollPane();
|
|
||||||
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
|
|
||||||
scrollPane.setBounds(26, 254, 410, 196);
|
|
||||||
panel_2.add(scrollPane);
|
|
||||||
|
|
||||||
txtDescription = new JTextArea();
|
|
||||||
txtDescription.setEditable(false);
|
|
||||||
txtDescription.setLineWrap(true);
|
|
||||||
scrollPane.setViewportView(txtDescription);
|
|
||||||
btnLoadImg.setBounds(304, 217, 102, 25);
|
|
||||||
panel_2.add(btnLoadImg);
|
|
||||||
|
|
||||||
txtTags = new JTextField();
|
|
||||||
txtTags.setEditable(false);
|
|
||||||
txtTags.setBounds(26, 480, 410, 19);
|
|
||||||
panel_2.add(txtTags);
|
|
||||||
txtTags.setColumns(10);
|
|
||||||
|
|
||||||
JLabel lblTags = new JLabel("Tagi:");
|
|
||||||
lblTags.setBounds(26, 462, 70, 15);
|
|
||||||
panel_2.add(lblTags);
|
|
||||||
|
|
||||||
btnCancel = new JButton("Anuluj");
|
|
||||||
btnCancel.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
DeactivateAddMenu();
|
|
||||||
if(recipesList.getSelectedIndex() != -1)
|
|
||||||
RetrieveData.fillComponents(recipesList.getSelectedValue().toString());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
btnCancel.setVisible(false);
|
|
||||||
btnCancel.setBounds(319, 46, 117, 25);
|
|
||||||
panel_2.add(btnCancel);
|
|
||||||
|
|
||||||
JLabel lblDescription = new JLabel("Opis wykonania:");
|
|
||||||
lblDescription.setBounds(26, 227, 152, 15);
|
|
||||||
panel_2.add(lblDescription);
|
|
||||||
|
|
||||||
scrollPane_1 = new JScrollPane();
|
|
||||||
scrollPane_1.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
|
|
||||||
scrollPane_1.setBounds(26, 88, 228, 126);
|
|
||||||
panel_2.add(scrollPane_1);
|
|
||||||
|
|
||||||
txtIngredients = new JTextArea();
|
|
||||||
txtIngredients.setEditable(false);
|
|
||||||
txtIngredients.setLineWrap(true);
|
|
||||||
scrollPane_1.setViewportView(txtIngredients);
|
|
||||||
|
|
||||||
//RetrieveData.insertSampleData();
|
|
||||||
RetrieveData.fillList();
|
|
||||||
txtSearch.setText("wpisz tytuł/tagi...");
|
|
||||||
txtSearch.getDocument().addDocumentListener(new DocumentListener() {
|
|
||||||
|
|
||||||
public void changedUpdate(DocumentEvent e) {
|
|
||||||
RetrieveData.fillList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void insertUpdate(DocumentEvent e) {
|
|
||||||
RetrieveData.fillList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeUpdate(DocumentEvent e) {
|
|
||||||
RetrieveData.fillList();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -5,6 +5,7 @@ import javax.swing.ImageIcon;
|
|||||||
|
|
||||||
abstract class RecipeBuilder {
|
abstract class RecipeBuilder {
|
||||||
protected CB_Model rOb;
|
protected CB_Model rOb;
|
||||||
|
protected CB_View tV;
|
||||||
|
|
||||||
public CB_Model build() {
|
public CB_Model build() {
|
||||||
return rOb;
|
return rOb;
|
||||||
@@ -14,6 +15,10 @@ abstract class RecipeBuilder {
|
|||||||
rOb = new CB_Model();
|
rOb = new CB_Model();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RecipeBuilder(CB_View v) {
|
||||||
|
tV = v;
|
||||||
|
}
|
||||||
|
|
||||||
public abstract void buildTitle();
|
public abstract void buildTitle();
|
||||||
public abstract void buildIngred();
|
public abstract void buildIngred();
|
||||||
public abstract void buildDesc();
|
public abstract void buildDesc();
|
||||||
@@ -24,25 +29,31 @@ abstract class RecipeBuilder {
|
|||||||
|
|
||||||
class NewRecipeBuilder extends RecipeBuilder {
|
class NewRecipeBuilder extends RecipeBuilder {
|
||||||
|
|
||||||
|
public NewRecipeBuilder(CB_View v) {
|
||||||
|
super(v);
|
||||||
|
}
|
||||||
public void buildTitle() {
|
public void buildTitle() {
|
||||||
rOb.setName(FrmMain.txtEdTitle.getText());
|
rOb.setName(tV.getRecipeEdTitle());
|
||||||
}
|
}
|
||||||
public void buildIngred() {
|
public void buildIngred() {
|
||||||
rOb.setIngredients(FrmMain.txtIngredients.getText());
|
rOb.setIngredients(tV.getRecipeIngredients());
|
||||||
}
|
}
|
||||||
public void buildDesc() {
|
public void buildDesc() {
|
||||||
rOb.setDescription(FrmMain.txtDescription.getText());
|
rOb.setDescription(tV.getRecipeDescription());
|
||||||
}
|
}
|
||||||
public void buildTags() {
|
public void buildTags() {
|
||||||
rOb.setTags(FrmMain.txtTags.getText());
|
rOb.setTags(tV.getRecipeTags());
|
||||||
}
|
}
|
||||||
public void buildImg() {
|
public void buildImg() {
|
||||||
rOb.setImage((ImageIcon)FrmMain.imgRecipe.getIcon());
|
rOb.setImage((ImageIcon)tV.getImgRecipe().getIcon());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ExampleRecipeBuilder extends RecipeBuilder {
|
class ExampleRecipeBuilder extends RecipeBuilder {
|
||||||
|
|
||||||
|
public ExampleRecipeBuilder(CB_View v) {
|
||||||
|
super(v);
|
||||||
|
}
|
||||||
public void buildTitle() {
|
public void buildTitle() {
|
||||||
rOb.setName("Kanapka");
|
rOb.setName("Kanapka");
|
||||||
}
|
}
|
||||||
@@ -56,13 +67,14 @@ class ExampleRecipeBuilder extends RecipeBuilder {
|
|||||||
rOb.setTags("kanapka, szynka, chleb");
|
rOb.setTags("kanapka, szynka, chleb");
|
||||||
}
|
}
|
||||||
public void buildImg() {
|
public void buildImg() {
|
||||||
rOb.setImage(FrmMain.imgDefaultRecipe);
|
rOb.setImage(tV.getDefaultImgRecipe());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class RecipeManager {
|
class RecipeManager {
|
||||||
|
|
||||||
private RecipeBuilder recipeBuilder;
|
private RecipeBuilder recipeBuilder;
|
||||||
|
protected CB_View tV;
|
||||||
|
|
||||||
public void setRecipeBuilder(RecipeBuilder rb) {
|
public void setRecipeBuilder(RecipeBuilder rb) {
|
||||||
recipeBuilder = rb;
|
recipeBuilder = rb;
|
||||||
|
|||||||
@@ -1,82 +0,0 @@
|
|||||||
package ksiazka.kucharska;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.swing.DefaultListModel;
|
|
||||||
import javax.swing.ImageIcon;
|
|
||||||
|
|
||||||
import db.AllRecipes;
|
|
||||||
import db.Cookbook;
|
|
||||||
import db.Recipe;
|
|
||||||
import db.SearchRecipe;
|
|
||||||
import db.SearchRecipeNameTag;
|
|
||||||
|
|
||||||
public class RetrieveData extends FrmMain{
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
public static void insertSampleData(){
|
|
||||||
Cookbook myCb = new Cookbook();
|
|
||||||
|
|
||||||
RecipeManager rm = new RecipeManager();
|
|
||||||
rm.setRecipeBuilder(new ExampleRecipeBuilder());
|
|
||||||
rm.constructRecipe();
|
|
||||||
Recipe rc = rm.getRecipe();
|
|
||||||
myCb.insertRecipe(rc);
|
|
||||||
|
|
||||||
myCb.closeConnection();
|
|
||||||
}
|
|
||||||
public static void fillList(){
|
|
||||||
Cookbook myCb = new Cookbook();
|
|
||||||
SearchRecipe sr;
|
|
||||||
if (txtSearch.getText() != "") {
|
|
||||||
sr = new SearchRecipeNameTag();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sr = new AllRecipes();
|
|
||||||
}
|
|
||||||
List<String> names = sr.obtainRecipeNames();
|
|
||||||
|
|
||||||
DefaultListModel recipesList;
|
|
||||||
recipesList = getRecipesList();
|
|
||||||
recipesList.clear();
|
|
||||||
|
|
||||||
for (String r : names)
|
|
||||||
{
|
|
||||||
recipesList.addElement(r);
|
|
||||||
}
|
|
||||||
myCb.closeConnection();
|
|
||||||
}
|
|
||||||
public static void fillComponents(String name){
|
|
||||||
Cookbook myCb = new Cookbook();
|
|
||||||
CB_Model myRecipe = myCb.selectRecipe(name);
|
|
||||||
lblRecipeTitle.setText(name);
|
|
||||||
txtIngredients.setText(myRecipe.getIngredients());
|
|
||||||
txtDescription.setText(myRecipe.getDescription());
|
|
||||||
txtTags.setText(myRecipe.getTags());
|
|
||||||
imgRecipe.setIcon(myRecipe.getImage());
|
|
||||||
txtDescription.setCaretPosition(0);
|
|
||||||
txtIngredients.setCaretPosition(0);
|
|
||||||
myCb.closeConnection();
|
|
||||||
}
|
|
||||||
public static void addNewRecipe(){
|
|
||||||
Cookbook myCb = new Cookbook();
|
|
||||||
|
|
||||||
RecipeManager rm = new RecipeManager();
|
|
||||||
rm.setRecipeBuilder(new NewRecipeBuilder());
|
|
||||||
rm.constructRecipe();
|
|
||||||
|
|
||||||
CB_Model obj = rm.getRecipe();
|
|
||||||
myCb.insertRecipe(obj);
|
|
||||||
//myCb.insertRecipe(txtEdTitle.getText(), txtIngredients.getText(), txtDescription.getText(), txtTags.getText(), (ImageIcon)imgRecipe.getIcon());
|
|
||||||
|
|
||||||
myCb.closeConnection();
|
|
||||||
}
|
|
||||||
public static void removeRecipe(String name){
|
|
||||||
Cookbook myCb = new Cookbook();
|
|
||||||
myCb.deleteRecipe(name);
|
|
||||||
myCb.closeConnection();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user