/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package ui;
import design_patterns.bridge.JsonServerData;
import design_patterns.bridge.XmlServerData;
import java.util.ArrayList;
import java.util.Map;
import javax.swing.JOptionPane;
/**
*
* @author root
*/
public class Login extends javax.swing.JFrame {
private ArrayList authors, books, videos, reservations , products;
private Map users_map,authors_map, books_map, videos_map, reservations_map , products_map;
public static String url="http://";
/**
* Creates new form Login
*/
public Login() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
username = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
password = new javax.swing.JPasswordField();
jLabel3 = new javax.swing.JLabel();
loginbtn = new javax.swing.JButton();
jCheckBoxXml = new javax.swing.JCheckBox();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
jMenu2 = new javax.swing.JMenu();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
jLabel1.setText("Username");
username.setText("admin");
username.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
usernameActionPerformed(evt);
}
});
jLabel2.setText("Password");
jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/booksintomovies_SCALED.jpg"))); // NOI18N
loginbtn.setText("Login");
loginbtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
loginbtnActionPerformed(evt);
}
});
jCheckBoxXml.setText("Use Xml (Default is set to Json)");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(loginbtn)
.addGap(114, 114, 114))
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel3)
.addGap(0, 77, Short.MAX_VALUE))
.addComponent(username)))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel2)
.addGap(14, 14, 14)
.addComponent(password))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jCheckBoxXml)
.addGap(0, 0, Short.MAX_VALUE)))
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, 159, Short.MAX_VALUE)
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(username, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(password, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(10, 10, 10)
.addComponent(jCheckBoxXml)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(loginbtn)
.addGap(27, 27, 27))
);
jMenu1.setText("File");
jMenuBar1.add(jMenu1);
jMenu2.setText("Edit");
jMenuBar1.add(jMenu2);
setJMenuBar(jMenuBar1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void loginbtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loginbtnActionPerformed
// TODO add your handling code here:
if(this.jCheckBoxXml.isSelected()){
System.out.println("xml chosen");
if(new XmlServerData(this,this.username,this.password).fetchdata()){
this.dispose();
}
else{
JOptionPane.showMessageDialog(null, "Unauthorized access");
}
}
else { //Default is Json
if(new JsonServerData(this,this.username,this.password).fetchdata()){
this.dispose();
}
else{
JOptionPane.showMessageDialog(null, "Unauthorized access");
}
}
}//GEN-LAST:event_loginbtnActionPerformed
private void usernameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_usernameActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_usernameActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
try {
Login.url += args[0]+"/";
} catch (Exception e) {
System.err.println("Default url");
Login.url += "localhost:8000/";
}
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Login().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JCheckBox jCheckBoxXml;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JPanel jPanel1;
private javax.swing.JButton loginbtn;
private javax.swing.JPasswordField password;
private javax.swing.JTextField username;
// End of variables declaration//GEN-END:variables
/**
* @return the authors
*/
public ArrayList getAuthors() {
return authors;
}
/**
* @param authors the authors to set
*/
public void setAuthors(ArrayList authors) {
this.authors = authors;
}
/**
* @return the books
*/
public ArrayList getBooks() {
return books;
}
/**
* @param books the books to set
*/
public void setBooks(ArrayList books) {
this.books = books;
}
/**
* @return the videos
*/
public ArrayList getVideos() {
return videos;
}
/**
* @param videos the videos to set
*/
public void setVideos(ArrayList videos) {
this.videos = videos;
}
/**
* @return the reservations
*/
public ArrayList getReservations() {
return reservations;
}
/**
* @param reservations the reservations to set
*/
public void setReservations(ArrayList reservations) {
this.reservations = reservations;
}
/**
* @return the products
*/
public ArrayList getProducts() {
return products;
}
/**
* @param products the products to set
*/
public void setProducts(ArrayList products) {
this.products = products;
}
/**
* @return the authors_map
*/
public Map getAuthors_map() {
return authors_map;
}
/**
* @param authors_map the authors_map to set
*/
public void setAuthors_map(Map authors_map) {
this.authors_map = authors_map;
}
/**
* @return the books_map
*/
public Map getBooks_map() {
return books_map;
}
/**
* @param books_map the books_map to set
*/
public void setBooks_map(Map books_map) {
this.books_map = books_map;
}
/**
* @return the videos_map
*/
public Map getVideos_map() {
return videos_map;
}
/**
* @param videos_map the videos_map to set
*/
public void setVideos_map(Map videos_map) {
this.videos_map = videos_map;
}
/**
* @return the reservations_map
*/
public Map getReservations_map() {
return reservations_map;
}
/**
* @param reservations_map the reservations_map to set
*/
public void setReservations_map(Map reservations_map) {
this.reservations_map = reservations_map;
}
/**
* @return the products_map
*/
public Map getProducts_map() {
return products_map;
}
/**
* @param products_map the products_map to set
*/
public void setProducts_map(Map products_map) {
this.products_map = products_map;
}
/**
* @return the users_map
*/
public Map getUsers_map() {
return users_map;
}
/**
* @param users_map the users_map to set
*/
public void setUsers_map(Map users_map) {
this.users_map = users_map;
}
}