package barcode.gui;
import gui.PSAAnaEkran;
import hibernateSwingApi.component.CComboBox;
import hibernateSwingApi.hibernate.HibernateManager;
import hibernateSwingApi.utils.Utils;
import java.awt.Color;
import java.awt.Font;
import java.awt.SystemColor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.List;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.border.LineBorder;
import service.PSAUtil;
import barcode.pojos.Etiket;
import barcode.pojos.PrintProperty;
public class PSAEtiketSecimEkrani {
private JFrame frame;
private JPanel panel;
private CComboBox<Etiket> cComboBoxVarolanEtiketler;
private JButton JButtonEtiketGuncelle;
private JLabel JLabelVeya;
private JButton JButtonYeniEtiket;
private JLabel JLabelVarolanEtiketSeiniz;
private JLabel JLabelEtiketTasarla;
private JButton JButtonYaziciSecenek;
private JButton JButtonEtiketYazdir;
private PrintProperty pProperty;
private List<PrintProperty> propertyList;
public JFrame getFrame() {
return frame;
}
public void setFrame(JFrame frame) {
this.frame = frame;
}
public PSAEtiketSecimEkrani() {
initialize();
}
private void initialize() {
frame = new JFrame();
frame.setBounds(0, 0, 580, 294);
frame.setResizable(false);
frame.setTitle("ETİKET SEÇENEKLERİ");
frame.setIconImage(PSAUtil.getImageIconViaRelativePath(
"picture/psaIcon.png").getImage());
panel = new JPanel();
panel.setBackground(SystemColor.info);
panel.setBorder(new LineBorder(new Color(0, 0, 0), 2));
cComboBoxVarolanEtiketler = new CComboBox<Etiket>(Etiket.class);
JButtonEtiketGuncelle = new JButton();
JButtonEtiketGuncelle.setIcon(PSAUtil
.getImageIconViaRelativePath("picture/personelGuncelle.png"));
JButtonEtiketGuncelle.setFont(new Font("Tahoma", Font.BOLD, 12));
JButtonEtiketGuncelle.setText("GÜNCELLE");
JButtonEtiketGuncelle.setEnabled(false);
JLabelVeya = new JLabel();
JLabelVeya.setText("veya");
JButtonYeniEtiket = new JButton();
JButtonYeniEtiket.setIcon(PSAUtil
.getImageIconViaRelativePath("picture/ekle.png"));
JButtonYeniEtiket.setFont(new Font("Tahoma", Font.BOLD, 12));
JButtonYeniEtiket.setText("YENİ ETİKET");
JLabelVarolanEtiketSeiniz = new JLabel();
JLabelVarolanEtiketSeiniz.setFont(new Font("Tahoma", Font.BOLD, 12));
JLabelVarolanEtiketSeiniz.setText("Varolan Etiket Seçiniz");
JLabelEtiketTasarla = new JLabel();
JLabelEtiketTasarla.setFont(new Font("Tahoma", Font.BOLD, 14));
JLabelEtiketTasarla.setHorizontalAlignment(SwingConstants.CENTER);
JLabelEtiketTasarla.setText("ETİKET TASARLA");
JButtonYaziciSecenek = new JButton();
JButtonYaziciSecenek.setIcon(PSAUtil
.getImageIconViaRelativePath("picture/printIcon.png"));
JButtonYaziciSecenek.setFont(new Font("Tahoma", Font.BOLD, 14));
JButtonYaziciSecenek.setText("YAZICI SEÇENEKLERİ");
JButtonEtiketYazdir = new JButton();
JButtonEtiketYazdir.setIcon(PSAUtil
.getImageIconViaRelativePath("picture/yazdir.png"));
JButtonEtiketYazdir.setText("ETİKET YAZDIR");
JButtonEtiketYazdir.setFont(new Font("Tahoma", Font.BOLD, 14));
GroupLayout groupLayout = new GroupLayout(frame.getContentPane());
groupLayout.setHorizontalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addGap(28)
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addComponent(JLabelEtiketTasarla, GroupLayout.DEFAULT_SIZE, 440, Short.MAX_VALUE)
.addComponent(panel, GroupLayout.DEFAULT_SIZE, 440, Short.MAX_VALUE)
.addGroup(groupLayout.createSequentialGroup()
.addComponent(JButtonYaziciSecenek, GroupLayout.PREFERRED_SIZE, 238, GroupLayout.PREFERRED_SIZE)
.addGap(18)
.addComponent(JButtonEtiketYazdir, GroupLayout.DEFAULT_SIZE, 184, Short.MAX_VALUE)))
.addGap(21))
);
groupLayout.setVerticalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addGap(24)
.addComponent(JLabelEtiketTasarla, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE)
.addGap(3)
.addComponent(panel, GroupLayout.PREFERRED_SIZE, 121, GroupLayout.PREFERRED_SIZE)
.addGap(24)
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addComponent(JButtonYaziciSecenek, GroupLayout.PREFERRED_SIZE, 43, GroupLayout.PREFERRED_SIZE)
.addComponent(JButtonEtiketYazdir, GroupLayout.PREFERRED_SIZE, 43, GroupLayout.PREFERRED_SIZE)))
);
GroupLayout gl_panel = new GroupLayout(panel);
gl_panel.setHorizontalGroup(gl_panel
.createParallelGroup(Alignment.LEADING)
.addGroup(
gl_panel.createSequentialGroup()
.addGap(21)
.addGroup(
gl_panel.createParallelGroup(
Alignment.LEADING)
.addComponent(
JLabelVarolanEtiketSeiniz,
GroupLayout.PREFERRED_SIZE,
148,
GroupLayout.PREFERRED_SIZE)
.addGroup(
gl_panel.createSequentialGroup()
.addGroup(
gl_panel.createParallelGroup(
Alignment.LEADING)
.addComponent(
cComboBoxVarolanEtiketler,
GroupLayout.DEFAULT_SIZE,
148,
Short.MAX_VALUE)
.addComponent(
JButtonEtiketGuncelle,
GroupLayout.DEFAULT_SIZE,
148,
Short.MAX_VALUE))
.addGap(11)
.addGroup(
gl_panel.createParallelGroup(
Alignment.LEADING)
.addGroup(
gl_panel.createSequentialGroup()
.addGap(39)
.addComponent(
JButtonYeniEtiket,
GroupLayout.DEFAULT_SIZE,
155,
Short.MAX_VALUE))
.addGroup(
gl_panel.createSequentialGroup()
.addComponent(
JLabelVeya,
GroupLayout.DEFAULT_SIZE,
47,
Short.MAX_VALUE)
.addGap(147)))))
.addGap(24)));
gl_panel.setVerticalGroup(gl_panel
.createParallelGroup(Alignment.LEADING)
.addGroup(
gl_panel.createSequentialGroup()
.addGap(9)
.addComponent(JLabelVarolanEtiketSeiniz,
GroupLayout.PREFERRED_SIZE, 14,
GroupLayout.PREFERRED_SIZE)
.addGap(3)
.addGroup(
gl_panel.createParallelGroup(
Alignment.LEADING)
.addGroup(
gl_panel.createSequentialGroup()
.addComponent(
cComboBoxVarolanEtiketler,
GroupLayout.PREFERRED_SIZE,
GroupLayout.DEFAULT_SIZE,
GroupLayout.PREFERRED_SIZE)
.addGap(20)
.addComponent(
JButtonEtiketGuncelle,
GroupLayout.PREFERRED_SIZE,
34,
GroupLayout.PREFERRED_SIZE))
.addComponent(
JButtonYeniEtiket,
GroupLayout.DEFAULT_SIZE,
74, Short.MAX_VALUE)
.addGroup(
gl_panel.createSequentialGroup()
.addGap(31)
.addComponent(
JLabelVeya,
GroupLayout.PREFERRED_SIZE,
GroupLayout.DEFAULT_SIZE,
GroupLayout.PREFERRED_SIZE)))
.addGap(17)));
panel.setLayout(gl_panel);
frame.getContentPane().setLayout(groupLayout);
cComboBoxVarolanEtiketler.refresh();
initListeners();
}
@SuppressWarnings("unchecked")
private void getPrintProperty() {
propertyList = (List<PrintProperty>) HibernateManager.getInstance()
.get(PrintProperty.class);
}
private void initListeners() {
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
PSAAnaEkran.getInstance(null).setEnabled(true);
frame.dispose();
}
});
JButtonYeniEtiket.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
yeniEtiketClicked();
}
});
JButtonEtiketGuncelle.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
etiketGuncelleClicked();
}
});
cComboBoxVarolanEtiketler.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent arg0) {
JButtonEtiketGuncelle.setEnabled(true);
}
});
JButtonYaziciSecenek.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
PSAYaziciSecenekleriEkrani yazici = new PSAYaziciSecenekleriEkrani();
yazici.getFrame().setVisible(true);
}
});
JButtonEtiketYazdir.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
etiketYazdirClicked();
}
});
}
protected void etiketYazdirClicked() {
getPrintProperty();
if (propertyList != null && propertyList.size() > 0) {
pProperty = propertyList.get(0);
PSAEtiketBasimEkrani basim = new PSAEtiketBasimEkrani(pProperty);
basim.getFrame().setVisible(true);
} else {
Utils.showMessage("Kayıtlı Yazıcı Seçeneği Bulunmamaktadır!");
return;
}
}
protected void etiketGuncelleClicked() {
Etiket etiket = (Etiket) cComboBoxVarolanEtiketler.getSelectedItem();
getPrintProperty();
if (propertyList != null && propertyList.size() > 0) {
pProperty = propertyList.get(0);
PSAEtiketTasarimEkrani tasarimEkrani = new PSAEtiketTasarimEkrani(
etiket, pProperty, true);
tasarimEkrani.getFrame().setVisible(true);
} else {
Utils.showMessage("Kayıtlı Yazıcı Seçeneği Bulunmamaktadır!");
return;
}
}
protected void yeniEtiketClicked() {
getPrintProperty();
if (propertyList != null && propertyList.size() > 0) {
pProperty = propertyList.get(0);
PSAEtiketTasarimEkrani tasarimEkrani = new PSAEtiketTasarimEkrani(
null, pProperty, false);
if (!tasarimEkrani.getFrame().isVisible()) {
tasarimEkrani.getFrame().setVisible(true);
}
} else {
Utils.showMessage("Kayıtlı Yazıcı Seçeneği Bulunmamaktadır!");
return;
}
}
}