Merge branch 'master' of ssh://git.pioder.pl:24/ksiazka-kucharska
Conflicts: .classpath cookbook.db
This commit is contained in:
@@ -53,6 +53,7 @@ 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, ImageIcon img) {
|
public boolean insertRecipe(String name, String ingredients, String description, String tags, ImageIcon img) {
|
||||||
try {
|
try {
|
||||||
BufferedImage bImg = new BufferedImage(img.getIconWidth(), img.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
|
BufferedImage bImg = new BufferedImage(img.getIconWidth(), img.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
|
||||||
@@ -86,6 +87,27 @@ public class Cookbook {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean insertRecipe(Recipe ob) {
|
||||||
|
try {
|
||||||
|
PreparedStatement prepStmt = conn.prepareStatement(
|
||||||
|
"INSERT INTO recipes VALUES (NULL, ?, ?, ?, ?, ?);");
|
||||||
|
prepStmt.setString(1, ob.getName());
|
||||||
|
prepStmt.setString(2, ob.getIngredients());
|
||||||
|
prepStmt.setString(3, ob.getDescription());
|
||||||
|
prepStmt.setString(4, ob.getTags());
|
||||||
|
prepStmt.setBytes(5, ob.getImageArr());
|
||||||
|
prepStmt.execute();
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (SQLException e) {
|
||||||
|
System.err.println("Blad przy wstawianiu przepisu");
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public Recipe selectRecipe(String name) {
|
public Recipe selectRecipe(String name) {
|
||||||
Recipe selectedRecipe;
|
Recipe selectedRecipe;
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
package db;
|
package db;
|
||||||
|
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
import javax.swing.ImageIcon;
|
import javax.swing.ImageIcon;
|
||||||
|
|
||||||
public class Recipe {
|
public class Recipe {
|
||||||
@@ -43,6 +48,28 @@ public class Recipe {
|
|||||||
public void setImage(ImageIcon img) {
|
public void setImage(ImageIcon img) {
|
||||||
this.img = img;
|
this.img = img;
|
||||||
}
|
}
|
||||||
|
public byte[] getImageArr() {
|
||||||
|
try {
|
||||||
|
//przekształcam ImageIcon -> BufferedImage
|
||||||
|
BufferedImage bImg = new BufferedImage(img.getIconWidth(), img.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
|
||||||
|
|
||||||
|
bImg.getGraphics().drawImage(img.getImage(), 0,0, null);
|
||||||
|
ByteArrayOutputStream bStream = new ByteArrayOutputStream();
|
||||||
|
//Buffered Image -> Byte Stream
|
||||||
|
ImageIO.write( bImg, "png", bStream );
|
||||||
|
bStream.flush();
|
||||||
|
//Byte Stream -> Byte Array
|
||||||
|
byte [] arr = bStream.toByteArray();
|
||||||
|
bStream.close();
|
||||||
|
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
System.err.println("Blad przy wstawianiu przepisu");
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Recipe() {}
|
public Recipe() {}
|
||||||
public Recipe(int id, String name, String ingredients, String description, String tags, ImageIcon img) {
|
public Recipe(int id, String name, String ingredients, String description, String tags, ImageIcon img) {
|
||||||
|
|||||||
@@ -17,14 +17,13 @@ import javax.swing.JButton;
|
|||||||
import javax.swing.JTextField;
|
import javax.swing.JTextField;
|
||||||
|
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.GridLayout;
|
|
||||||
import java.awt.GridBagLayout;
|
import java.awt.GridBagLayout;
|
||||||
import java.awt.GridBagConstraints;
|
import java.awt.GridBagConstraints;
|
||||||
import java.awt.Insets;
|
import java.awt.Insets;
|
||||||
import java.awt.RenderingHints;
|
import java.awt.RenderingHints;
|
||||||
|
|
||||||
import javax.swing.JList;
|
import javax.swing.JList;
|
||||||
import javax.swing.JTextPane;
|
import javax.swing.JTextArea;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
import javax.swing.border.LineBorder;
|
import javax.swing.border.LineBorder;
|
||||||
@@ -39,6 +38,8 @@ import ksiazka.kucharska.RetrieveData;
|
|||||||
import javax.swing.event.ListSelectionListener;
|
import javax.swing.event.ListSelectionListener;
|
||||||
import javax.swing.event.ListSelectionEvent;
|
import javax.swing.event.ListSelectionEvent;
|
||||||
import javax.swing.filechooser.FileNameExtensionFilter;
|
import javax.swing.filechooser.FileNameExtensionFilter;
|
||||||
|
import javax.swing.ScrollPaneConstants;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
|
||||||
public class FrmMain extends JFrame {
|
public class FrmMain extends JFrame {
|
||||||
|
|
||||||
@@ -52,10 +53,8 @@ public class FrmMain extends JFrame {
|
|||||||
public static JTextField txtTags;
|
public static JTextField txtTags;
|
||||||
private JButton btnSave;
|
private JButton btnSave;
|
||||||
private JButton btnCancel;
|
private JButton btnCancel;
|
||||||
public static JTextPane txtIngredients;
|
public static JTextArea txtDescription;
|
||||||
public static JTextPane txtDescription;
|
|
||||||
private JButton btnAddRecipe;
|
private JButton btnAddRecipe;
|
||||||
private JButton btnSearch;
|
|
||||||
private JButton btnDelRecipe;
|
private JButton btnDelRecipe;
|
||||||
private JButton btnLoadImg;
|
private JButton btnLoadImg;
|
||||||
public static JLabel lblRecipeTitle;
|
public static JLabel lblRecipeTitle;
|
||||||
@@ -64,13 +63,16 @@ public class FrmMain extends JFrame {
|
|||||||
private JFileChooser fcImg;
|
private JFileChooser fcImg;
|
||||||
public static ImageIcon imgDefaultRecipe;
|
public static ImageIcon imgDefaultRecipe;
|
||||||
private JList recipesList;
|
private JList recipesList;
|
||||||
|
private JScrollPane scrollPane_1;
|
||||||
|
public static JTextArea txtIngredients;
|
||||||
|
private JScrollPane scrollPane_2;
|
||||||
|
|
||||||
void DeactivateAddMenu() {
|
void DeactivateAddMenu() {
|
||||||
btnAddRecipe.setEnabled(true);
|
btnAddRecipe.setEnabled(true);
|
||||||
btnCancel.setVisible(false);
|
btnCancel.setVisible(false);
|
||||||
btnDelRecipe.setEnabled(true);
|
btnDelRecipe.setEnabled(true);
|
||||||
btnLoadImg.setVisible(false);
|
btnLoadImg.setVisible(false);
|
||||||
btnSearch.setEnabled(true);
|
txtSearch.setEnabled(true);
|
||||||
btnSave.setVisible(false);
|
btnSave.setVisible(false);
|
||||||
txtDescription.setEditable(false);
|
txtDescription.setEditable(false);
|
||||||
txtEdTitle.setVisible(false);
|
txtEdTitle.setVisible(false);
|
||||||
@@ -85,7 +87,7 @@ public class FrmMain extends JFrame {
|
|||||||
btnCancel.setVisible(true);
|
btnCancel.setVisible(true);
|
||||||
btnDelRecipe.setEnabled(false);
|
btnDelRecipe.setEnabled(false);
|
||||||
btnLoadImg.setVisible(true);
|
btnLoadImg.setVisible(true);
|
||||||
btnSearch.setEnabled(false);
|
txtSearch.setEnabled(false);
|
||||||
btnSave.setVisible(true);
|
btnSave.setVisible(true);
|
||||||
txtDescription.setEditable(true);
|
txtDescription.setEditable(true);
|
||||||
txtEdTitle.setVisible(true);
|
txtEdTitle.setVisible(true);
|
||||||
@@ -120,39 +122,34 @@ public class FrmMain extends JFrame {
|
|||||||
setContentPane(contentPane);
|
setContentPane(contentPane);
|
||||||
|
|
||||||
JSplitPane splitPane = new JSplitPane();
|
JSplitPane splitPane = new JSplitPane();
|
||||||
|
splitPane.setResizeWeight(0.18);
|
||||||
|
splitPane.setRequestFocusEnabled(false);
|
||||||
|
splitPane.setPreferredSize(new Dimension(200, 27));
|
||||||
splitPane.setDividerSize(5);
|
splitPane.setDividerSize(5);
|
||||||
splitPane.setEnabled(false);
|
splitPane.setEnabled(false);
|
||||||
splitPane.setResizeWeight(0.1);
|
|
||||||
contentPane.add(splitPane, BorderLayout.CENTER);
|
contentPane.add(splitPane, BorderLayout.CENTER);
|
||||||
|
|
||||||
JPanel panel = new JPanel();
|
JPanel panel = new JPanel();
|
||||||
|
panel.setMaximumSize(new Dimension(100, 32767));
|
||||||
splitPane.setLeftComponent(panel);
|
splitPane.setLeftComponent(panel);
|
||||||
GridBagLayout gbl_panel = new GridBagLayout();
|
GridBagLayout gbl_panel = new GridBagLayout();
|
||||||
gbl_panel.columnWidths = new int[] {0, 30};
|
gbl_panel.columnWidths = new int[] {0, 0};
|
||||||
gbl_panel.rowHeights = new int[] {0, 0, 0};
|
gbl_panel.rowHeights = new int[] {0, 0, 0};
|
||||||
gbl_panel.columnWeights = new double[]{1.0, 0.0};
|
gbl_panel.columnWeights = new double[]{1.0, 1.0};
|
||||||
gbl_panel.rowWeights = new double[]{0.0, 1.0, 0.0};
|
gbl_panel.rowWeights = new double[]{0.0, 1.0, 0.0};
|
||||||
panel.setLayout(gbl_panel);
|
panel.setLayout(gbl_panel);
|
||||||
|
|
||||||
txtSearch = new JTextField();
|
txtSearch = new JTextField();
|
||||||
txtSearch.setText("wpisz tytuł/tagi...");
|
txtSearch.setText("wpisz tytuł/tagi...");
|
||||||
GridBagConstraints gbc_txtSearch = new GridBagConstraints();
|
GridBagConstraints gbc_txtSearch = new GridBagConstraints();
|
||||||
gbc_txtSearch.insets = new Insets(0, 0, 5, 5);
|
gbc_txtSearch.gridwidth = 2;
|
||||||
|
gbc_txtSearch.insets = new Insets(5, 5, 5, 0);
|
||||||
gbc_txtSearch.fill = GridBagConstraints.HORIZONTAL;
|
gbc_txtSearch.fill = GridBagConstraints.HORIZONTAL;
|
||||||
gbc_txtSearch.gridx = 0;
|
gbc_txtSearch.gridx = 0;
|
||||||
gbc_txtSearch.gridy = 0;
|
gbc_txtSearch.gridy = 0;
|
||||||
panel.add(txtSearch, gbc_txtSearch);
|
panel.add(txtSearch, gbc_txtSearch);
|
||||||
txtSearch.setColumns(10);
|
txtSearch.setColumns(10);
|
||||||
|
|
||||||
btnSearch = new JButton("Szukaj");
|
|
||||||
GridBagConstraints gbc_btnSearch = new GridBagConstraints();
|
|
||||||
gbc_btnSearch.anchor = GridBagConstraints.NORTH;
|
|
||||||
gbc_btnSearch.fill = GridBagConstraints.HORIZONTAL;
|
|
||||||
gbc_btnSearch.insets = new Insets(0, 0, 5, 0);
|
|
||||||
gbc_btnSearch.gridx = 1;
|
|
||||||
gbc_btnSearch.gridy = 0;
|
|
||||||
panel.add(btnSearch, gbc_btnSearch);
|
|
||||||
|
|
||||||
recipesListModel = new DefaultListModel();
|
recipesListModel = new DefaultListModel();
|
||||||
recipesList = new JList(recipesListModel);
|
recipesList = new JList(recipesListModel);
|
||||||
recipesList.addListSelectionListener(new ListSelectionListener() {
|
recipesList.addListSelectionListener(new ListSelectionListener() {
|
||||||
@@ -161,34 +158,39 @@ public class FrmMain extends JFrame {
|
|||||||
RetrieveData.fillComponents(recipesList.getSelectedValue().toString());
|
RetrieveData.fillComponents(recipesList.getSelectedValue().toString());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
GridBagConstraints gbc_recipesList = new GridBagConstraints();
|
|
||||||
gbc_recipesList.insets = new Insets(0, 0, 5, 0);
|
scrollPane_2 = new JScrollPane();
|
||||||
gbc_recipesList.gridwidth = 2;
|
scrollPane_2.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
|
||||||
gbc_recipesList.fill = GridBagConstraints.BOTH;
|
scrollPane_2.setMaximumSize(new Dimension(100, 100));
|
||||||
gbc_recipesList.gridx = 0;
|
scrollPane_2.setViewportView(recipesList);
|
||||||
gbc_recipesList.gridy = 1;
|
GridBagConstraints gbc_scrollPane_2 = new GridBagConstraints();
|
||||||
panel.add(recipesList, gbc_recipesList);
|
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);
|
||||||
|
|
||||||
JPanel panel_1 = new JPanel();
|
|
||||||
GridBagConstraints gbc_panel_1 = new GridBagConstraints();
|
|
||||||
gbc_panel_1.gridwidth = 2;
|
|
||||||
gbc_panel_1.gridheight = 0;
|
|
||||||
gbc_panel_1.insets = new Insets(0, 0, 0, 5);
|
|
||||||
gbc_panel_1.fill = GridBagConstraints.BOTH;
|
|
||||||
gbc_panel_1.gridx = 0;
|
|
||||||
gbc_panel_1.gridy = 2;
|
|
||||||
panel.add(panel_1, gbc_panel_1);
|
|
||||||
panel_1.setLayout(new GridLayout(0, 2, 0, 0));
|
|
||||||
|
|
||||||
btnAddRecipe = new JButton("Nowy");
|
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() {
|
btnAddRecipe.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
ActivateAddMenu();
|
ActivateAddMenu();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
panel_1.add(btnAddRecipe);
|
|
||||||
|
|
||||||
btnDelRecipe = new JButton("Usuń");
|
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() {
|
btnDelRecipe.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
DefaultListModel model = (DefaultListModel) recipesList.getModel();
|
DefaultListModel model = (DefaultListModel) recipesList.getModel();
|
||||||
@@ -214,7 +216,6 @@ public class FrmMain extends JFrame {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
panel_1.add(btnDelRecipe);
|
|
||||||
|
|
||||||
JPanel panel_2 = new JPanel();
|
JPanel panel_2 = new JPanel();
|
||||||
splitPane.setRightComponent(panel_2);
|
splitPane.setRightComponent(panel_2);
|
||||||
@@ -241,15 +242,6 @@ public class FrmMain extends JFrame {
|
|||||||
panel_2.add(txtEdTitle);
|
panel_2.add(txtEdTitle);
|
||||||
txtEdTitle.setColumns(10);
|
txtEdTitle.setColumns(10);
|
||||||
|
|
||||||
txtIngredients = new JTextPane();
|
|
||||||
txtIngredients.setEditable(false);
|
|
||||||
txtIngredients.setBounds(26, 88, 228, 126);
|
|
||||||
panel_2.add(txtIngredients);
|
|
||||||
|
|
||||||
txtDescription = new JTextPane();
|
|
||||||
txtDescription.setEditable(false);
|
|
||||||
txtDescription.setBounds(26, 254, 410, 196);
|
|
||||||
panel_2.add(txtDescription);
|
|
||||||
|
|
||||||
lblRecipeTitle = new JLabel("Nazwa przepisu");
|
lblRecipeTitle = new JLabel("Nazwa przepisu");
|
||||||
lblRecipeTitle.setFont(new Font("Dialog", Font.BOLD, 18));
|
lblRecipeTitle.setFont(new Font("Dialog", Font.BOLD, 18));
|
||||||
@@ -260,10 +252,6 @@ public class FrmMain extends JFrame {
|
|||||||
lblIngredients.setBounds(26, 61, 70, 15);
|
lblIngredients.setBounds(26, 61, 70, 15);
|
||||||
panel_2.add(lblIngredients);
|
panel_2.add(lblIngredients);
|
||||||
|
|
||||||
JLabel lblDescription = new JLabel("Opis wykonania:");
|
|
||||||
lblDescription.setBounds(26, 227, 152, 15);
|
|
||||||
panel_2.add(lblDescription);
|
|
||||||
|
|
||||||
imgRecipe = new JLabel("");
|
imgRecipe = new JLabel("");
|
||||||
imgRecipe.setHorizontalAlignment(SwingConstants.CENTER);
|
imgRecipe.setHorizontalAlignment(SwingConstants.CENTER);
|
||||||
imgRecipe.setBorder(new LineBorder(SystemColor.textHighlightText));
|
imgRecipe.setBorder(new LineBorder(SystemColor.textHighlightText));
|
||||||
@@ -309,6 +297,16 @@ public class FrmMain extends JFrame {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
btnLoadImg.setVisible(false);
|
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);
|
btnLoadImg.setBounds(304, 217, 102, 25);
|
||||||
panel_2.add(btnLoadImg);
|
panel_2.add(btnLoadImg);
|
||||||
|
|
||||||
@@ -334,6 +332,20 @@ public class FrmMain extends JFrame {
|
|||||||
btnCancel.setBounds(319, 46, 117, 25);
|
btnCancel.setBounds(319, 46, 117, 25);
|
||||||
panel_2.add(btnCancel);
|
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.insertSampleData();
|
||||||
RetrieveData.fillList();
|
RetrieveData.fillList();
|
||||||
}
|
}
|
||||||
|
|||||||
82
src/main/java/ksiazka/kucharska/RecipeBuilder.java
Normal file
82
src/main/java/ksiazka/kucharska/RecipeBuilder.java
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
package ksiazka.kucharska;
|
||||||
|
import javax.swing.ImageIcon;
|
||||||
|
|
||||||
|
import db.Recipe;
|
||||||
|
|
||||||
|
|
||||||
|
abstract class RecipeBuilder {
|
||||||
|
protected Recipe rOb;
|
||||||
|
|
||||||
|
public Recipe build() {
|
||||||
|
return rOb;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void newRecipe() {
|
||||||
|
rOb = new Recipe();
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void buildTitle();
|
||||||
|
public abstract void buildIngred();
|
||||||
|
public abstract void buildDesc();
|
||||||
|
public abstract void buildTags();
|
||||||
|
public abstract void buildImg();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class NewRecipeBuilder extends RecipeBuilder {
|
||||||
|
|
||||||
|
public void buildTitle() {
|
||||||
|
rOb.setName(FrmMain.txtEdTitle.getText());
|
||||||
|
}
|
||||||
|
public void buildIngred() {
|
||||||
|
rOb.setIngredients(FrmMain.txtIngredients.getText());
|
||||||
|
}
|
||||||
|
public void buildDesc() {
|
||||||
|
rOb.setDescription(FrmMain.txtDescription.getText());
|
||||||
|
}
|
||||||
|
public void buildTags() {
|
||||||
|
rOb.setTags(FrmMain.txtTags.getText());
|
||||||
|
}
|
||||||
|
public void buildImg() {
|
||||||
|
rOb.setImage((ImageIcon)FrmMain.imgRecipe.getIcon());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ExampleRecipeBuilder extends RecipeBuilder {
|
||||||
|
|
||||||
|
public void buildTitle() {
|
||||||
|
rOb.setName("Kanapka");
|
||||||
|
}
|
||||||
|
public void buildIngred() {
|
||||||
|
rOb.setIngredients("Chleb, margaryna, szynka");
|
||||||
|
}
|
||||||
|
public void buildDesc() {
|
||||||
|
rOb.setDescription("Posmarować kanapke margaryną i położyć na niej plaster szynki");
|
||||||
|
}
|
||||||
|
public void buildTags() {
|
||||||
|
rOb.setTags("kanapka, szynka, chleb");
|
||||||
|
}
|
||||||
|
public void buildImg() {
|
||||||
|
rOb.setImage(FrmMain.imgDefaultRecipe);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class RecipeManager {
|
||||||
|
|
||||||
|
private RecipeBuilder recipeBuilder;
|
||||||
|
|
||||||
|
public void setRecipeBuilder(RecipeBuilder rb) {
|
||||||
|
recipeBuilder = rb;
|
||||||
|
}
|
||||||
|
public Recipe getRecipe() {
|
||||||
|
return recipeBuilder.build();
|
||||||
|
}
|
||||||
|
public void constructRecipe() {
|
||||||
|
recipeBuilder.newRecipe();
|
||||||
|
recipeBuilder.buildTitle();
|
||||||
|
recipeBuilder.buildIngred();
|
||||||
|
recipeBuilder.buildDesc();
|
||||||
|
recipeBuilder.buildTags();
|
||||||
|
recipeBuilder.buildImg();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -51,7 +51,14 @@ public class RetrieveData extends FrmMain{
|
|||||||
}
|
}
|
||||||
public static void addNewRecipe(){
|
public static void addNewRecipe(){
|
||||||
Cookbook myCb = new Cookbook();
|
Cookbook myCb = new Cookbook();
|
||||||
myCb.insertRecipe(txtEdTitle.getText(), txtIngredients.getText(), txtDescription.getText(), txtTags.getText(), (ImageIcon)imgRecipe.getIcon());
|
|
||||||
|
RecipeManager rm = new RecipeManager();
|
||||||
|
rm.setRecipeBuilder(new NewRecipeBuilder());
|
||||||
|
rm.constructRecipe();
|
||||||
|
|
||||||
|
Recipe obj = rm.getRecipe();
|
||||||
|
myCb.insertRecipe(obj);
|
||||||
|
//myCb.insertRecipe(txtEdTitle.getText(), txtIngredients.getText(), txtDescription.getText(), txtTags.getText(), (ImageIcon)imgRecipe.getIcon());
|
||||||
|
|
||||||
myCb.closeConnection();
|
myCb.closeConnection();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user