Package gui

Source Code of gui.PSAFirmaEklemeEkrani

package gui;

import hibernateSwingApi.component.CTextArea;
import hibernateSwingApi.component.CTextField;
import hibernateSwingApi.hibernate.HibernateManager;
import hibernateSwingApi.utils.Utils;

import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.text.ParseException;

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.JScrollPane;
import javax.swing.UIManager;
import javax.swing.WindowConstants;
import javax.swing.text.MaskFormatter;

import pojos.Firma;
import service.AutoClosingMessageDialog;
import service.PSAUtil;
import control.MailRegex;

public class PSAFirmaEklemeEkrani extends JFrame {

  private static final long serialVersionUID = 1L;
  private static PSAFirmaEklemeEkrani instance;
  private JPanel cPanelFirma;
  private JLabel cLabelFirmaEkleme;
  private JPanel cPanelFirmaEkleme;
  private JLabel cLabelFirmaAd;
  private JLabel cLabelFirmaTelNo;
  private JLabel cLabelFaksNo;
  private JLabel cLabelFirmaIcon;
  private JLabel cLabelFirmaAdres;
  private JLabel cLabelFirmaMail;
  private CTextField cTextFieldFirmaAd;
  private CTextField cTextFieldFirmaTelNo;
  private CTextField cTextFieldFaksNo;
  private CTextField cTextFieldFirmaMail;
  private JButton JButtonFirmaEkle;
  private JButton JButtonFirmaGeri;
  private JScrollPane cScrollPaneFirmaAdres;
  private CTextArea cTextAreaFirmaAdres;
  private JButton JButtonTemizle;

  private static final String E_MAIL = "info@altisoft.com.tr";
  private static int frameState;

  public static PSAFirmaEklemeEkrani getInstance(int state) {
    frameState = state;
    instance = new PSAFirmaEklemeEkrani();
    return instance;
  }

  public PSAFirmaEklemeEkrani() {
    initialize();
  }

  private void initialize() {
    setTitle("PSA MERKEZ FİRMA EKLEME EKRANI");
    setBounds(0, 0, 510, 567);
    setResizable(false);
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    setIconImage(PSAUtil.getImageIconViaRelativePath("picture/psaIcon.png")
        .getImage());

    cPanelFirma = new JPanel();

    cLabelFirmaEkleme = new JLabel();
    cLabelFirmaEkleme.setText("F\u0130RMA EKLEME");
    cLabelFirmaEkleme.setFont(new Font("Tahoma", Font.BOLD, 16));

    cPanelFirmaEkleme = new JPanel();
    cPanelFirmaEkleme.setBackground(UIManager.getColor("Button.shadow"));

    cLabelFirmaAd = new JLabel();
    cLabelFirmaAd.setBounds(89, 132, 127, 20);
    cLabelFirmaAd.setText("*Firma Ad\u0131");
    cLabelFirmaAd.setFont(new Font("Tahoma", Font.BOLD, 14));

    cTextFieldFirmaAd = new CTextField(30);
    cTextFieldFirmaAd.setBounds(226, 132, 186, 21);

    cLabelFirmaTelNo = new JLabel();
    cLabelFirmaTelNo.setBounds(89, 160, 127, 21);
    cLabelFirmaTelNo.setText("Tel No");
    cLabelFirmaTelNo.setFont(new Font("Tahoma", Font.BOLD, 14));

    MaskFormatter mf = null;
    try {
      mf = new MaskFormatter("(###) ### ## ##");
      mf.setPlaceholderCharacter('_');
    } catch (ParseException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    cTextFieldFirmaTelNo = new CTextField(mf);
    cTextFieldFirmaTelNo.setBounds(226, 160, 186, 20);

    cLabelFaksNo = new JLabel();
    cLabelFaksNo.setBounds(89, 188, 127, 20);
    cLabelFaksNo.setText("Faks No");
    cLabelFaksNo.setFont(new Font("Tahoma", Font.BOLD, 14));

    cTextFieldFaksNo = new CTextField(mf);
    cTextFieldFaksNo.setBounds(226, 188, 186, 21);

    cLabelFirmaAdres = new JLabel();
    cLabelFirmaAdres.setBounds(89, 247, 127, 20);
    cLabelFirmaAdres.setText("Adresi");
    cLabelFirmaAdres.setFont(new Font("Tahoma", Font.BOLD, 14));

    JButtonFirmaEkle = new JButton();
    JButtonFirmaEkle.setBounds(89, 379, 323, 40);
    JButtonFirmaEkle.setIcon(PSAUtil
        .getImageIconViaRelativePath("picture/ekle.png"));
    JButtonFirmaEkle.setText("F\u0130RMA EKLE");
    JButtonFirmaEkle.setFont(new Font("Tahoma", Font.BOLD, 15));

    cLabelFirmaIcon = new JLabel();
    cLabelFirmaIcon.setBounds(194, 11, 96, 116);
    cLabelFirmaIcon.setIcon(PSAUtil
        .getImageIconViaRelativePath("picture/firmaBilgileri.png"));

    cLabelFirmaMail = new JLabel();
    cLabelFirmaMail.setBounds(89, 219, 127, 20);
    cLabelFirmaMail.setText("E-posta");
    cLabelFirmaMail.setFont(new Font("Tahoma", Font.BOLD, 14));

    cTextFieldFirmaMail = new CTextField(40);
    cTextFieldFirmaMail.setBounds(226, 219, 186, 20);
    cTextFieldFirmaMail.setHint(E_MAIL);

    cScrollPaneFirmaAdres = new JScrollPane();
    cScrollPaneFirmaAdres.setBounds(226, 247, 186, 81);

    cTextAreaFirmaAdres = new CTextArea(100);
    cTextAreaFirmaAdres.setLineWrap(true);
    cScrollPaneFirmaAdres.setViewportView(cTextAreaFirmaAdres);

    JButtonFirmaGeri = new JButton();
    JButtonFirmaGeri.setBounds(89, 432, 323, 40);
    JButtonFirmaGeri.setIcon(PSAUtil
        .getImageIconViaRelativePath("picture/geriButonu.png"));
    JButtonFirmaGeri.setText("\u0130PTAL");
    JButtonFirmaGeri.setFont(new Font("Tahoma", Font.BOLD, 15));
    GroupLayout gl_cPanelFirma = new GroupLayout(cPanelFirma);
    gl_cPanelFirma.setHorizontalGroup(gl_cPanelFirma
        .createParallelGroup(Alignment.LEADING)
        .addGroup(
            gl_cPanelFirma
                .createSequentialGroup()
                .addComponent(cLabelFirmaEkleme,
                    GroupLayout.DEFAULT_SIZE,
                    GroupLayout.DEFAULT_SIZE,
                    Short.MAX_VALUE).addGap(362))
        .addComponent(cPanelFirmaEkleme, GroupLayout.DEFAULT_SIZE, 485,
            Short.MAX_VALUE));
    gl_cPanelFirma.setVerticalGroup(gl_cPanelFirma.createParallelGroup(
        Alignment.LEADING)
        .addGroup(
            gl_cPanelFirma
                .createSequentialGroup()
                .addComponent(cLabelFirmaEkleme,
                    GroupLayout.DEFAULT_SIZE, 20,
                    Short.MAX_VALUE)
                .addGap(6)
                .addComponent(cPanelFirmaEkleme,
                    GroupLayout.DEFAULT_SIZE, 491,
                    Short.MAX_VALUE)));
    cPanelFirmaEkleme.setLayout(null);
    cPanelFirmaEkleme.add(cLabelFirmaIcon);
    cPanelFirmaEkleme.add(cLabelFirmaAd);
    cPanelFirmaEkleme.add(cTextFieldFirmaAd);
    cPanelFirmaEkleme.add(cLabelFirmaTelNo);
    cPanelFirmaEkleme.add(cTextFieldFirmaTelNo);
    cPanelFirmaEkleme.add(cLabelFaksNo);
    cPanelFirmaEkleme.add(cTextFieldFaksNo);
    cPanelFirmaEkleme.add(JButtonFirmaEkle);
    cPanelFirmaEkleme.add(JButtonFirmaGeri);
    cPanelFirmaEkleme.add(cLabelFirmaAdres);
    cPanelFirmaEkleme.add(cScrollPaneFirmaAdres);
    cPanelFirmaEkleme.add(cLabelFirmaMail);
    cPanelFirmaEkleme.add(cTextFieldFirmaMail);

    JButtonTemizle = new JButton();
    JButtonTemizle.setText("TEM\u0130ZLE");
    JButtonTemizle.setIcon(PSAUtil
        .getImageIconViaRelativePath("picture/temizle.png"));
    JButtonTemizle.setFont(new Font("Tahoma", Font.BOLD, 9));
    JButtonTemizle.setBounds(363, 11, 108, 27);
    cPanelFirmaEkleme.add(JButtonTemizle);
    cPanelFirma.setLayout(gl_cPanelFirma);
    GroupLayout groupLayout = new GroupLayout(getContentPane());
    groupLayout.setHorizontalGroup(groupLayout.createParallelGroup(
        Alignment.LEADING).addGroup(
        groupLayout
            .createSequentialGroup()
            .addGap(10)
            .addComponent(cPanelFirma, GroupLayout.DEFAULT_SIZE,
                GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGap(9)));
    groupLayout.setVerticalGroup(groupLayout.createParallelGroup(
        Alignment.LEADING).addGroup(
        groupLayout
            .createSequentialGroup()
            .addGap(11)
            .addComponent(cPanelFirma, GroupLayout.DEFAULT_SIZE,
                GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGap(11)));
    getContentPane().setLayout(groupLayout);

    initListeners();
  }

  private void initListeners() {

    addWindowListener(new WindowAdapter() {
      @Override
      public void windowClosing(WindowEvent e) {
        firmaEkraniSetEnable();
      }
    });

    JButtonFirmaEkle.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        firmaEkleClicked();
      }
    });

    JButtonFirmaGeri.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        firmaEkraniSetEnable();
      }
    });

    JButtonTemizle.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent arg0) {
        temizleClicked();
      }
    });
  }

  protected void temizleClicked() {
    cTextFieldFirmaAd.setText("");
    cTextFieldFirmaTelNo.setValue(null);
    cTextFieldFaksNo.setValue(null);
    cTextFieldFirmaMail.setText("");
    cTextAreaFirmaAdres.setText("");
  }

  protected void firmaEkraniSetEnable() {
    if (frameState != 0) {
      PSAFirmaEkrani.getInstance(1).setEnabled(true);
    } else {
      PSAUrunEklemeEkrani.getInstance(1, 1).setEnabled(true);
    }
    instance.dispose();
  }

  protected void firmaEkleClicked() {
    String firmaAd = cTextFieldFirmaAd.getText().trim();
    if (firmaAd.trim().equals("")) {
      Utils.showMessage("Lütfen zorunlu(*) alanları doldurunuz.");
      return;
    }
    String firmaMail = cTextFieldFirmaMail.getText().trim();
    if (firmaMail.length() > 0 && !MailRegex.validate(firmaMail)) {
      Utils.showMessage("E-posta adresinin doğruluğunu kontrol ediniz.");
      return;
    }

    Firma firma = new Firma();
    String firmaAdres = cTextAreaFirmaAdres.getText().trim();
    firma.setFirmaAd(firmaAd.toUpperCase());
    Object firmaTelNo = cTextFieldFirmaTelNo.getValue();
    Object firmaFaksNo = cTextFieldFaksNo.getValue();

    if (firmaTelNo != null) {
      firma.setFirmaTelNo(String.valueOf(firmaTelNo));
    } else {
      firma.setFirmaTelNo("-");
    }
    if (firmaFaksNo != null) {
      firma.setFirmaFaksNo(String.valueOf(firmaFaksNo));
    } else {
      firma.setFirmaFaksNo("-");
    }
    if (firmaMail.length() > 0) {
      firma.setFirmaMail(firmaMail);
    }
    if (firmaAdres.length() > 0) {
      firma.setFirmaAdres(firmaAdres);
    }

    boolean control = HibernateManager.getInstance().save(firma);
    if (control == true) {
      AutoClosingMessageDialog.showAutoClosingMessageDialog(
          "Sisteme firma kaydınız başarı ile tamamlanmıştır.", 2);
      firmaEkraniSetEnable();
    }
  }
}
TOP

Related Classes of gui.PSAFirmaEklemeEkrani

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.