@ -7,6 +7,7 @@ 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.JSplitPane ;
@ -33,6 +34,9 @@ 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.ListSelectionListener ;
import javax.swing.event.ListSelectionEvent ;
public class FrmMain extends JFrame {
@ -42,20 +46,19 @@ public class FrmMain extends JFrame {
private static final long serialVersionUID = 2634383304749703669L ;
private JPanel contentPane ;
private JTextField txtSearch ;
private JTextField txtEdTitle ;
private JTextField txtTags ;
public static JTextField txtEdTitle ;
public static JTextField txtTags ;
private JButton btnSave ;
private JButton btnCancel ;
private JTextPane txtIngredients ;
private JTextPane txtDescription ;
public static JTextPane txtIngredients ;
public static JTextPane txtDescription ;
private JButton btnAddRecipe ;
private JButton btnSearch ;
private JButton btnDelRecipe ;
private JButton btnLoadImg ;
private JLabel lblRecipeTitle ;
private JLabel imgRecipe ;
private JFileChooser fcImg ;
private ImageIcon imgDefaultRecipe ;
public static JLabel lblRecipeTitle ;
private static DefaultListModel recipesListModel ;
void DeactivateAddMenu ( ) {
btnCancel . setVisible ( false ) ;
@ -89,6 +92,11 @@ public class FrmMain extends JFrame {
txtTags . setText ( "" ) ;
}
public static DefaultListModel getRecipesList ( )
{
return recipesListModel ;
}
/ * *
* Create the frame .
* /
@ -136,7 +144,14 @@ public class FrmMain extends JFrame {
gbc_btnSearch . gridy = 0 ;
panel . add ( btnSearch , gbc_btnSearch ) ;
JList recipesList = new JList ( ) ;
recipesListModel = new DefaultListModel ( ) ;
final JList recipesList = new JList ( recipesListModel ) ;
recipesList . addListSelectionListener ( new ListSelectionListener ( ) {
public void valueChanged ( ListSelectionEvent e ) {
if ( recipesList . getSelectedIndex ( ) ! = - 1 )
RetrieveData . fillComponents ( recipesList . getSelectedValue ( ) . toString ( ) ) ;
}
} ) ;
GridBagConstraints gbc_recipesList = new GridBagConstraints ( ) ;
gbc_recipesList . insets = new Insets ( 0 , 0 , 5 , 0 ) ;
gbc_recipesList . gridwidth = 2 ;
@ -156,29 +171,38 @@ public class FrmMain extends JFrame {
panel . add ( panel_1 , gbc_panel_1 ) ;
panel_1 . setLayout ( new GridLayout ( 0 , 2 , 0 , 0 ) ) ;
btnAddRecipe = new JButton ( "Dodaj " ) ;
btnAddRecipe = new JButton ( "Nowy " ) ;
btnAddRecipe . addActionListener ( new ActionListener ( ) {
public void actionPerformed ( ActionEvent e ) {
ActivateAddMenu ( ) ;
}
} ) ;
panel_1 . add ( btnAddRecipe ) ;
btnDelRecipe = new JButton ( "Usuń" ) ;
btnDelRecipe . addActionListener ( new ActionListener ( ) {
public void actionPerformed ( ActionEvent e ) {
DefaultListModel model = ( DefaultListModel ) recipesList . getModel ( ) ;
if ( recipesList . getSelectedIndex ( ) ! = - 1 )
{
RetrieveData . removeRecipe ( recipesList . getSelectedValue ( ) . toString ( ) ) ;
model . remove ( recipesList . getSelectedIndex ( ) ) ;
}
}
} ) ;
panel_1 . add ( btnDelRecipe ) ;
JPanel panel_2 = new JPanel ( ) ;
splitPane . setRightComponent ( panel_2 ) ;
panel_2 . setLayout ( null ) ;
btnSave = new JButton ( "Zapisz" ) ;
btnSave = new JButton ( "Dodaj " ) ;
btnSave . addActionListener ( new ActionListener ( ) {
public void actionPerformed ( ActionEvent e ) {
System . out . println ( "sprawdzam ikonę..." ) ;
if ( imgRecipe . getIcon ( ) = = imgDefaultRecipe . getImage ( ) )
System . out . println ( "Ta sama ikona" ) ;
RetrieveData . addNewRecipe ( ) ;
DeactivateAddMenu ( ) ;
DefaultListModel model = ( DefaultListModel ) recipesList . getModel ( ) ;
model . addElement ( txtEdTitle . getText ( ) ) ;
}
} ) ;
btnSave . setVisible ( false ) ;
@ -281,5 +305,7 @@ public class FrmMain extends JFrame {
btnCancel . setBounds ( 319 , 46 , 117 , 25 ) ;
panel_2 . add ( btnCancel ) ;
/ / RetrieveData . insertSampleData ( ) ;
RetrieveData . fillList ( ) ;
}
}