Package giris.gui

Source Code of giris.gui.PSAGirisSayfasi

package giris.gui;

import hibernateSwingApi.component.CPasswordField;
import hibernateSwingApi.component.CTextField;
import hibernateSwingApi.hibernate.HibernateManager;
import hibernateSwingApi.utils.BackupManager;
import hibernateSwingApi.utils.Utils;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.SystemColor;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.SocketException;
import java.util.Timer;
import java.util.TimerTask;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRootPane;
import javax.swing.border.EmptyBorder;

import kullanici.pojos.Kullanici;

import org.hibernate.cfg.Configuration;

import service.AutoClosingMessageDialog;
import service.PSAUtil;
import database.DatabaseConnection;

public class PSAGirisSayfasi extends JFrame {

  private static final long serialVersionUID = 1L;

  private static PSAGirisSayfasi instance;
  private JPanel contentPane;
  private JLabel jLabelKullaniciAd;
  private CTextField cTextFieldKullaniciAd;
  private JLabel jLabelSifre;
  private CPasswordField cPasswordFieldSifre;
  private JButton JButtonGiris;
  private Kullanici kullanici;
  private static ServerSocket ss;
  private JRootPane rootPane;
  private String passText;

  public static PSAGirisSayfasi getInstance() {
    if (instance == null) {
      instance = new PSAGirisSayfasi();
    }
    return instance;
  }

  public static void main(String[] args) {
    applicationStartControl();
    DatabaseConnection.databaseConnect();

    TimerTask tt = new TimerTask() {

      @Override
      public void run() {
        Configuration configuration = HibernateManager.getInstance()
            .getConfiguration();
        String file_path = configuration.getProperty("mysqldump_file");
        File f = new File(file_path);
        BackupManager.backupMysqlSchema(f, configuration);
      }
    };

    Timer t = new Timer();
    long delay = 1000 * 60 * 1;
    long period = 1000 * 60 * 60;
    t.schedule(tt, delay, period);

    EventQueue.invokeLater(new Runnable() {
      @Override
      public void run() {
        try {
          PSAGirisSayfasi.getInstance().setVisible(true);
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    });
  }

  public PSAGirisSayfasi() {
    initialize();
  }

  public void initialize() {
    setTitle("PSA GİRİŞ EKRANI");
    setResizable(false);
    setIconImage(PSAUtil.getImageIconViaRelativePath("picture/psaIcon.png")
        .getImage());
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(558, 581);
    locateFrameToMiddle();
    contentPane = new JPanel();
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    contentPane.setLayout(new BorderLayout(0, 0));
    setContentPane(contentPane);

    GirisSayfasiPanel gsp = new GirisSayfasiPanel();
    contentPane.add(gsp, BorderLayout.CENTER);
    gsp.setLayout(null);

    jLabelKullaniciAd = new JLabel();
    jLabelKullaniciAd.setText("Kullanıcı Adı");
    jLabelKullaniciAd.setFont(new Font("Tahoma", Font.BOLD, 15));
    jLabelKullaniciAd.setBounds(141, 198, 115, 19);
    gsp.add(jLabelKullaniciAd);

    cTextFieldKullaniciAd = new CTextField(20);
    cTextFieldKullaniciAd.setBounds(261, 195, 140, 22);
    gsp.add(cTextFieldKullaniciAd);

    jLabelSifre = new JLabel();
    jLabelSifre.setText("Şifre");
    jLabelSifre.setFont(new Font("Tahoma", Font.BOLD, 15));
    jLabelSifre.setBounds(141, 226, 115, 19);
    gsp.add(jLabelSifre);

    cPasswordFieldSifre = new CPasswordField();
    cPasswordFieldSifre.setBounds(261, 223, 140, 25);
    gsp.add(cPasswordFieldSifre);

    JButtonGiris = new JButton();
    JButtonGiris.setText("GİRİŞ");
    JButtonGiris.setFont(new Font("Tahoma", Font.BOLD, 14));
    JButtonGiris.setBackground(SystemColor.controlShadow);
    JButtonGiris.setBounds(141, 259, 260, 41);
    gsp.add(JButtonGiris);

    initListener();
  }

  private void initListener() {

    rootPane = getRootPane();
    rootPane.setDefaultButton(JButtonGiris);

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

  protected void girisButtonClicked() {
    kullanici = (Kullanici) HibernateManager.getInstance()
        .getObjectWithUniqueColumn(Kullanici.class, "kullaniciAdi",
            cTextFieldKullaniciAd.getText(), false);
    passText = new String(cPasswordFieldSifre.getPassword());
    if (kullanici != null && kullanici.getSifre().equals(passText)) {
      PSAAnaEkran.getInstance(kullanici).setVisible(true);
      clearComponent();
      instance.dispose();
    } else {
      Utils.showMessage("Kullanıcı adınızı ve şifrenizi kontrol ediniz...");
      cPasswordFieldSifre.setText("");
    }
  }

  private void clearComponent() {
    cTextFieldKullaniciAd.setText("");
    cPasswordFieldSifre.setText("");
  }

  private void locateFrameToMiddle() {
    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    int w = this.getSize().width;
    int h = this.getSize().height;
    int x = (dim.width - w) / 2;
    int y = (dim.height - h) / 2;
    setLocation(x, y);
  }

  private static void applicationStartControl() {
    try {
      ss = new ServerSocket();
      ss.bind(new InetSocketAddress(2500));
      System.out.println("Application started");
    } catch (SocketException e) {
      AutoClosingMessageDialog.showAutoClosingMessageDialog(
          "Uygulama çalışır durumda bulunmaktadır.", 2);
      System.exit(1);
    } catch (Exception e) {
      AutoClosingMessageDialog
          .showAutoClosingMessageDialog(
              "Uygulamada problem ile karşılaşılmıştır. Teknik servisi bilgilendiriniz.",
              2);
      System.exit(1);
    }
  }
}
TOP

Related Classes of giris.gui.PSAGirisSayfasi

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.