defaultowy obrazek
ładowanie obrazka początek obsługi interfejsu
This commit is contained in:
BIN
no_img_recipe.jpg
Normal file
BIN
no_img_recipe.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.7 KiB |
@@ -3,16 +3,24 @@ package ksiazka.kucharska;
|
|||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
|
|
||||||
|
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.border.EmptyBorder;
|
import javax.swing.border.EmptyBorder;
|
||||||
|
import javax.swing.ImageIcon;
|
||||||
|
import javax.swing.JFileChooser;
|
||||||
import javax.swing.JSplitPane;
|
import javax.swing.JSplitPane;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JTextField;
|
import javax.swing.JTextField;
|
||||||
|
|
||||||
|
import java.awt.Graphics2D;
|
||||||
import java.awt.GridLayout;
|
import java.awt.GridLayout;
|
||||||
import java.awt.GridBagLayout;
|
import java.awt.GridBagLayout;
|
||||||
import java.awt.GridBagConstraints;
|
import java.awt.GridBagConstraints;
|
||||||
|
import java.awt.Image;
|
||||||
import java.awt.Insets;
|
import java.awt.Insets;
|
||||||
|
import java.awt.RenderingHints;
|
||||||
|
|
||||||
import javax.swing.JList;
|
import javax.swing.JList;
|
||||||
import javax.swing.JTextPane;
|
import javax.swing.JTextPane;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
@@ -21,6 +29,10 @@ import javax.swing.border.LineBorder;
|
|||||||
import java.awt.SystemColor;
|
import java.awt.SystemColor;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import javax.swing.SwingConstants;
|
||||||
|
|
||||||
public class FrmMain extends JFrame {
|
public class FrmMain extends JFrame {
|
||||||
|
|
||||||
@@ -41,6 +53,9 @@ public class FrmMain extends JFrame {
|
|||||||
private JButton btnDelRecipe;
|
private JButton btnDelRecipe;
|
||||||
private JButton btnLoadImg;
|
private JButton btnLoadImg;
|
||||||
private JLabel lblRecipeTitle;
|
private JLabel lblRecipeTitle;
|
||||||
|
private JLabel imgRecipe;
|
||||||
|
private JFileChooser fcImg;
|
||||||
|
private ImageIcon imgDefaultRecipe;
|
||||||
|
|
||||||
void DeactivateAddMenu() {
|
void DeactivateAddMenu() {
|
||||||
btnCancel.setVisible(false);
|
btnCancel.setVisible(false);
|
||||||
@@ -66,6 +81,12 @@ public class FrmMain extends JFrame {
|
|||||||
txtIngredients.setEditable(true);
|
txtIngredients.setEditable(true);
|
||||||
txtTags.setEditable(true);
|
txtTags.setEditable(true);
|
||||||
lblRecipeTitle.setVisible(false);
|
lblRecipeTitle.setVisible(false);
|
||||||
|
|
||||||
|
//czyszczenie pól formularza
|
||||||
|
txtDescription.setText("");
|
||||||
|
txtEdTitle.setText("");
|
||||||
|
txtIngredients.setText("");
|
||||||
|
txtTags.setText("");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -84,7 +105,7 @@ public class FrmMain extends JFrame {
|
|||||||
JSplitPane splitPane = new JSplitPane();
|
JSplitPane splitPane = new JSplitPane();
|
||||||
splitPane.setDividerSize(5);
|
splitPane.setDividerSize(5);
|
||||||
splitPane.setEnabled(false);
|
splitPane.setEnabled(false);
|
||||||
splitPane.setResizeWeight(0.2);
|
splitPane.setResizeWeight(0.1);
|
||||||
contentPane.add(splitPane, BorderLayout.CENTER);
|
contentPane.add(splitPane, BorderLayout.CENTER);
|
||||||
|
|
||||||
JPanel panel = new JPanel();
|
JPanel panel = new JPanel();
|
||||||
@@ -139,6 +160,7 @@ public class FrmMain extends JFrame {
|
|||||||
btnAddRecipe.addActionListener(new ActionListener() {
|
btnAddRecipe.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
ActivateAddMenu();
|
ActivateAddMenu();
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
panel_1.add(btnAddRecipe);
|
panel_1.add(btnAddRecipe);
|
||||||
@@ -153,6 +175,9 @@ public class FrmMain extends JFrame {
|
|||||||
btnSave = new JButton("Zapisz");
|
btnSave = new JButton("Zapisz");
|
||||||
btnSave.addActionListener(new ActionListener() {
|
btnSave.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
System.out.println("sprawdzam ikonę...");
|
||||||
|
if (imgRecipe.getIcon() == imgDefaultRecipe.getImage())
|
||||||
|
System.out.println("Ta sama ikona");
|
||||||
DeactivateAddMenu();
|
DeactivateAddMenu();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -189,12 +214,49 @@ public class FrmMain extends JFrame {
|
|||||||
lblDescription.setBounds(26, 227, 152, 15);
|
lblDescription.setBounds(26, 227, 152, 15);
|
||||||
panel_2.add(lblDescription);
|
panel_2.add(lblDescription);
|
||||||
|
|
||||||
JLabel imgRecipe = new JLabel("");
|
imgRecipe = new JLabel("");
|
||||||
|
imgRecipe.setHorizontalAlignment(SwingConstants.CENTER);
|
||||||
imgRecipe.setBorder(new LineBorder(SystemColor.textHighlightText));
|
imgRecipe.setBorder(new LineBorder(SystemColor.textHighlightText));
|
||||||
imgRecipe.setBounds(272, 88, 164, 126);
|
imgRecipe.setBounds(272, 88, 164, 126);
|
||||||
panel_2.add(imgRecipe);
|
panel_2.add(imgRecipe);
|
||||||
|
|
||||||
btnLoadImg = new JButton("Wczytaj");
|
btnLoadImg = new JButton("Wczytaj");
|
||||||
|
|
||||||
|
fcImg = new JFileChooser();
|
||||||
|
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());
|
||||||
|
|
||||||
|
System.out.println(w);
|
||||||
|
|
||||||
|
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) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
btnLoadImg.setVisible(false);
|
btnLoadImg.setVisible(false);
|
||||||
btnLoadImg.setBounds(304, 217, 102, 25);
|
btnLoadImg.setBounds(304, 217, 102, 25);
|
||||||
panel_2.add(btnLoadImg);
|
panel_2.add(btnLoadImg);
|
||||||
|
|||||||
Reference in New Issue
Block a user