|
@ -0,0 +1,285 @@ |
|
|
|
|
|
package ksiazka.kucharska; |
|
|
|
|
|
|
|
|
|
|
|
import java.awt.*; |
|
|
|
|
|
import java.awt.event.ActionListener; |
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
import javax.swing.*; |
|
|
|
|
|
import javax.swing.border.EmptyBorder; |
|
|
|
|
|
import javax.swing.border.LineBorder; |
|
|
|
|
|
import javax.swing.event.ListSelectionListener; |
|
|
|
|
|
import javax.swing.filechooser.FileNameExtensionFilter; |
|
|
|
|
|
|
|
|
|
|
|
public class CB_View extends JFrame{ |
|
|
|
|
|
private static final long serialVersionUID = 2634383304749703669L; |
|
|
|
|
|
private JTextField txtSearch = new JTextField(); |
|
|
|
|
|
private JTextField txtEdTitle = new JTextField(); |
|
|
|
|
|
private JTextField txtTags = new JTextField(); |
|
|
|
|
|
private JTextArea txtDescription = new JTextArea(); |
|
|
|
|
|
private JTextArea txtIngredients = new JTextArea(); |
|
|
|
|
|
private JButton btnAddRecipe = new JButton("Nowy"); |
|
|
|
|
|
private JButton btnDelRecipe = new JButton("Usuń"); |
|
|
|
|
|
private JButton btnLoadImg = new JButton("Wczytaj"); |
|
|
|
|
|
private JButton btnCancel = new JButton("Anuluj"); |
|
|
|
|
|
private JButton btnSave = new JButton("Dodaj"); |
|
|
|
|
|
private ImageIcon imgDefaultRecipe = new ImageIcon(); |
|
|
|
|
|
private JScrollPane scrollPane_1 = new JScrollPane(); |
|
|
|
|
|
private JScrollPane scrollPane_2 = new JScrollPane(); |
|
|
|
|
|
private JSplitPane splitPane = new JSplitPane(); |
|
|
|
|
|
private DefaultListModel recipesListModel = new DefaultListModel(); |
|
|
|
|
|
private JList recipesList = new JList(recipesListModel); |
|
|
|
|
|
private JLabel lblIngredients = new JLabel("Składniki:"); |
|
|
|
|
|
private JLabel lblDescription = new JLabel("Opis wykonania:"); |
|
|
|
|
|
private JLabel imgRecipe = new JLabel(""); |
|
|
|
|
|
private JLabel lblRecipeTitle = new JLabel("Nazwa przepisu"); |
|
|
|
|
|
private JLabel lblTags = new JLabel("Tagi:"); |
|
|
|
|
|
private JFileChooser fcImg = new JFileChooser(); |
|
|
|
|
|
private JScrollPane scrollPane = new JScrollPane(); |
|
|
|
|
|
|
|
|
|
|
|
CB_View(){ |
|
|
|
|
|
this.setResizable(false); |
|
|
|
|
|
this.setTitle("Książka Kucharska v1.0"); |
|
|
|
|
|
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
|
|
|
|
|
this.setBounds(100, 100, 723, 549); |
|
|
|
|
|
|
|
|
|
|
|
JPanel contentPane = new JPanel(); |
|
|
|
|
|
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); |
|
|
|
|
|
contentPane.setLayout(new BorderLayout(0, 0)); |
|
|
|
|
|
this.setContentPane(contentPane); |
|
|
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
|
|
|
|
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; |
|
|
|
|
|
|
|
|
|
|
|
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(); |
|
|
|
|
|
splitPane.setRightComponent(panel_2); |
|
|
|
|
|
panel_2.setLayout(null); |
|
|
|
|
|
|
|
|
|
|
|
btnSave.setVisible(false); |
|
|
|
|
|
btnSave.setBounds(319, 12, 117, 25); |
|
|
|
|
|
|
|
|
|
|
|
txtEdTitle.setVisible(false); |
|
|
|
|
|
txtEdTitle.setBounds(26, 15, 281, 19); |
|
|
|
|
|
txtEdTitle.setColumns(10); |
|
|
|
|
|
|
|
|
|
|
|
lblRecipeTitle.setFont(new Font("Dialog", Font.BOLD, 18)); |
|
|
|
|
|
lblRecipeTitle.setBounds(12, 12, 442, 22); |
|
|
|
|
|
|
|
|
|
|
|
lblIngredients.setBounds(26, 61, 70, 15); |
|
|
|
|
|
|
|
|
|
|
|
imgRecipe.setHorizontalAlignment(SwingConstants.CENTER); |
|
|
|
|
|
imgRecipe.setBorder(new LineBorder(SystemColor.textHighlightText)); |
|
|
|
|
|
imgRecipe.setBounds(272, 88, 164, 126); |
|
|
|
|
|
|
|
|
|
|
|
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.setVisible(false); |
|
|
|
|
|
|
|
|
|
|
|
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); |
|
|
|
|
|
scrollPane.setBounds(26, 254, 410, 196); |
|
|
|
|
|
|
|
|
|
|
|
txtDescription = new JTextArea(); |
|
|
|
|
|
txtDescription.setEditable(false); |
|
|
|
|
|
txtDescription.setLineWrap(true); |
|
|
|
|
|
scrollPane.setViewportView(txtDescription); |
|
|
|
|
|
btnLoadImg.setBounds(304, 217, 102, 25); |
|
|
|
|
|
|
|
|
|
|
|
txtTags.setEditable(false); |
|
|
|
|
|
txtTags.setBounds(26, 480, 410, 19); |
|
|
|
|
|
txtTags.setColumns(10); |
|
|
|
|
|
|
|
|
|
|
|
lblTags.setBounds(26, 462, 70, 15); |
|
|
|
|
|
|
|
|
|
|
|
btnCancel.setVisible(false); |
|
|
|
|
|
btnCancel.setBounds(319, 46, 117, 25); |
|
|
|
|
|
|
|
|
|
|
|
lblDescription.setBounds(26, 227, 152, 15); |
|
|
|
|
|
|
|
|
|
|
|
scrollPane_1.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); |
|
|
|
|
|
scrollPane_1.setBounds(26, 88, 228, 126); |
|
|
|
|
|
|
|
|
|
|
|
txtIngredients.setEditable(false); |
|
|
|
|
|
txtIngredients.setLineWrap(true); |
|
|
|
|
|
scrollPane_1.setViewportView(txtIngredients); |
|
|
|
|
|
|
|
|
|
|
|
scrollPane_2.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); |
|
|
|
|
|
scrollPane_2.setMaximumSize(new Dimension(100, 100)); |
|
|
|
|
|
scrollPane_2.setViewportView(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(txtSearch, gbc_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(txtEdTitle); |
|
|
|
|
|
panel_2.add(lblRecipeTitle); |
|
|
|
|
|
panel_2.add(lblIngredients); |
|
|
|
|
|
panel_2.add(lblTags); |
|
|
|
|
|
panel_2.add(imgRecipe); |
|
|
|
|
|
panel_2.add(scrollPane); |
|
|
|
|
|
panel_2.add(btnLoadImg); |
|
|
|
|
|
panel_2.add(txtTags); |
|
|
|
|
|
panel_2.add(btnCancel); |
|
|
|
|
|
panel_2.add(lblDescription); |
|
|
|
|
|
panel_2.add(scrollPane_1); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public String getRecipeTitle(){ |
|
|
|
|
|
return lblRecipeTitle.getText().toString(); |
|
|
|
|
|
} |
|
|
|
|
|
public String getRecipeIngredients(){ |
|
|
|
|
|
return txtIngredients.getText().toString(); |
|
|
|
|
|
} |
|
|
|
|
|
public String getRecipeDescription(){ |
|
|
|
|
|
return txtDescription.getText().toString(); |
|
|
|
|
|
} |
|
|
|
|
|
public String getRecipeTags(){ |
|
|
|
|
|
return txtTags.getText().toString(); |
|
|
|
|
|
} |
|
|
|
|
|
public JFileChooser getFileChooser(){ |
|
|
|
|
|
return fcImg; |
|
|
|
|
|
} |
|
|
|
|
|
public JList getRecipesList(){ |
|
|
|
|
|
return recipesList; |
|
|
|
|
|
} |
|
|
|
|
|
public JLabel getImgRecipe(){ |
|
|
|
|
|
return imgRecipe; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void setRecipeTitle(String name){ |
|
|
|
|
|
lblRecipeTitle.setText(name); |
|
|
|
|
|
} |
|
|
|
|
|
public void setRecipeIngredients(String ingredients){ |
|
|
|
|
|
txtIngredients.setText(ingredients); |
|
|
|
|
|
} |
|
|
|
|
|
public void setRecipeDescription(String description){ |
|
|
|
|
|
txtDescription.setText(description); |
|
|
|
|
|
} |
|
|
|
|
|
public void setRecipeTags(String tags){ |
|
|
|
|
|
txtTags.setText(tags); |
|
|
|
|
|
} |
|
|
|
|
|
public void setRecipesList(List<String> names){ |
|
|
|
|
|
for (String r : names) |
|
|
|
|
|
{ |
|
|
|
|
|
recipesListModel.addElement(r); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
public void setRecipeIcon(Icon icon){ |
|
|
|
|
|
imgRecipe.setIcon(icon); |
|
|
|
|
|
} |
|
|
|
|
|
public void resetCaretPositions(){ |
|
|
|
|
|
txtDescription.setCaretPosition(0); |
|
|
|
|
|
txtIngredients.setCaretPosition(0); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void addListener(ActionListener listenForAddButton){ |
|
|
|
|
|
btnAddRecipe.addActionListener(listenForAddButton); |
|
|
|
|
|
} |
|
|
|
|
|
void delListener(ActionListener listenForDelButton){ |
|
|
|
|
|
btnDelRecipe.addActionListener(listenForDelButton); |
|
|
|
|
|
} |
|
|
|
|
|
void loadListener(ActionListener listenForLoadButton){ |
|
|
|
|
|
btnLoadImg.addActionListener(listenForLoadButton); |
|
|
|
|
|
} |
|
|
|
|
|
void cancelListener(ActionListener listenForAddButton){ |
|
|
|
|
|
btnCancel.addActionListener(listenForAddButton); |
|
|
|
|
|
} |
|
|
|
|
|
void saveListener(ActionListener listenForAddButton){ |
|
|
|
|
|
btnSave.addActionListener(listenForAddButton); |
|
|
|
|
|
} |
|
|
|
|
|
void listSelectListener(ListSelectionListener listenForSelectionChagnge){ |
|
|
|
|
|
recipesList.addListSelectionListener(listenForSelectionChagnge); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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(""); |
|
|
|
|
|
} |
|
|
|
|
|
} |