package view; import java.awt.BorderLayout; import java.awt.Graphics; import java.awt.Image; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Observable; import java.util.Observer; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.WindowConstants; import Controler.ControlerCreate_User; import Controler.ControlerCreate_Database; import Controler.ControlerDelete_Database; import Controler.ControlerRemove_User; import Controler.Controler_Connect_Local_User; import Controler.Controler_General_Display; import model.ShanghaiMetro_Database; /** * This code was edited or generated using CloudGarden's Jigloo * SWT/Swing GUI Builder, which is free for non-commercial * use. If Jigloo is being used commercially (ie, by a corporation, * company or business for any purpose whatever) then you * should purchase a license for each developer using Jigloo. * Please visit www.cloudgarden.com for details. * Use of Jigloo implies acceptance of these licensing terms. * A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR * THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED * LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE. */ public class DatabaseView extends javax.swing.JFrame implements Observer{ private static final long serialVersionUID = 3477287769198950032L; private JButton Create_Database; private JButton Delete_Database; private JButton Show_Users; private JButton ShowAll_Database; private JButton Disconnect_to_local_User; private JButton ModifyDatabase; private JButton Connect_to_local_user; private JButton Remove_User; private JButton Create_User; private JPanel pan; ShanghaiMetro_Database ShanghaiM; // Controler for PAnelNorth ControlerCreate_Database controlerCreate_Data; ControlerDelete_Database controlDelete_data; ControlerCreate_User controlCreate_User; ControlerRemove_User controlRemove_User; Controler_Connect_Local_User controlLocalServer_connection; Controler_General_Display controlGeneralDisplay; Image image; public DatabaseView(ShanghaiMetro_Database SM) { super(); image = Toolkit.getDefaultToolkit().createImage("images/Wallpaper.jpg"); initGUI(); (SM.getCdata()).addObserver(this); (SM.getcUser()).addObserver(this); (SM.getdData()).addObserver(this); (SM.getrUser()).addObserver(this); (SM.getcLocalServer()).addObserver(this); (SM.getDisp()).addObserver(this); this.ShanghaiM = SM; this.controlCreate_User = new ControlerCreate_User(SM.getcUser()); this.controlRemove_User = new ControlerRemove_User(SM.getrUser()); this.controlDelete_data = new ControlerDelete_Database(SM.getdData()); this.controlerCreate_Data = new ControlerCreate_Database(SM.getCdata()); this.controlGeneralDisplay = new Controler_General_Display(SM.getDisp()); this.controlLocalServer_connection = new Controler_Connect_Local_User(SM.getcLocalServer()); } private void initGUI() { try { this.setTitle("Shanghai Subway System Database "); this.setIconImage(new ImageIcon("images/Logo.jpg").getImage()); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); { pan = new JPanel(); this.getContentPane().add(pan); pan.setLayout(null); pan.setBackground(new java.awt.Color(255,255,255)); pan.setFocusable(false); pan.setPreferredSize(new java.awt.Dimension(582, 372)); { Create_Database = new JButton(); pan.add(Create_Database); Create_Database.setText("Create DATABASE"); Create_Database.setBounds(77, 7, 154, 42); Create_Database.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { Create_DatabaseActionPerformed(evt); } }); } { Delete_Database = new JButton(); pan.add(Delete_Database); Delete_Database.setText("Delete DATABASE"); Delete_Database.setBounds(370, 7, 154, 42); Delete_Database.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { Delete_DatabaseActionPerformed(evt); } }); } { Remove_User = new JButton(); pan.add(Remove_User); Remove_User.setText("Remove USER"); Remove_User.setBounds(370, 60, 154, 42); Remove_User.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { Remove_UserActionPerformed(evt); } }); } { Create_User = new JButton(); pan.add(Create_User); Create_User.setText("Create USER"); Create_User.setBounds(77, 60, 154, 42); Create_User.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { Create_UserActionPerformed(evt); } }); } { Connect_to_local_user = new JButton(); pan.add(Connect_to_local_user); Connect_to_local_user.setText("Connect to the local USER"); Connect_to_local_user.setBounds(65, 112, 181, 42); Connect_to_local_user.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { Connect_to_local_userActionPerformed(evt); } }); } { ModifyDatabase = new JButton(); pan.add(ModifyDatabase); ModifyDatabase.setText("Modify DATABASE"); ModifyDatabase.setBounds(439, 360, 150, 23); ModifyDatabase.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { ModifyDatabaseActionPerformed(evt); } }); } { Disconnect_to_local_User = new JButton(); pan.add(Disconnect_to_local_User); Disconnect_to_local_User.setText("Disconnect to the local User"); Disconnect_to_local_User.setBounds(358, 113, 181, 40); Disconnect_to_local_User.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { Disconnect_to_local_UserActionPerformed(evt); } }); } { ShowAll_Database = new JButton(); pan.add(ShowAll_Database); ShowAll_Database.setText("Show All DAtabase on this server"); ShowAll_Database.setBounds(181, 360, 239, 23); ShowAll_Database.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { ShowAll_DatabaseActionPerformed(evt); } }); ShowAll_Database.setVisible(true); } { Show_Users = new JButton(); pan.add(Show_Users, BorderLayout.CENTER); Show_Users.setText("Show all USERS"); Show_Users.setBounds(12,360, 150, 23); Show_Users.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { Show_UsersActionPerformed(evt); } }); } pan.validate(); pan.setVisible(true); } pack(); setSize(600, 410); this.setResizable(false); this.validate(); this.setVisible(true); this.setLocationRelativeTo(null); } catch (Exception e) { e.printStackTrace(); } } public void paint(Graphics g){ super.paint(g); g.drawImage(image,0, 0,this.getWidth(), this.getHeight(), null); } private void Create_DatabaseActionPerformed(ActionEvent evt) { controlerCreate_Data.control(JOptionPane.showInputDialog (this, "Enter the name of the database you want to create")); JOptionPane.showMessageDialog(this, (this.ShanghaiM.getCdata()).getStr_cretaDabase() , "Result of Creation", JOptionPane.PLAIN_MESSAGE); } private void Create_UserActionPerformed(ActionEvent evt) { this.controlCreate_User.control(JOptionPane.showInputDialog (this, "Enter the name of the database that you want to add an user"), JOptionPane.showInputDialog (this, "Enter the name of the user you want to create"), JOptionPane.showInputDialog (this, "Enter the password of the user you want to create")); JOptionPane.showMessageDialog(this, (this.ShanghaiM.getcUser()).getStr_createUser() , "Result of Creation", JOptionPane.PLAIN_MESSAGE); } private void Delete_DatabaseActionPerformed(ActionEvent evt) { JOptionPane.showMessageDialog(this, "DON'T DELETE THE DATABASES NAMES: \n" + " information_schema\n" + " mysql\n" + " performance_schema\n" + " sakila\n" + " test\n" + " world\n" , "BE CAREFUL", JOptionPane.PLAIN_MESSAGE); this.controlDelete_data.control(JOptionPane.showInputDialog (this, "Enter the name of the database you want to delete.\n" + "It should be different from the database name: \n" + " information_schema\n" + " mysql\n" + " performance_schema\n" + " sakila\n" + " test\n" + " world\n" )); JOptionPane.showMessageDialog(this, (this.ShanghaiM.getdData()).getStr_deleteDatabase() , "Result of Deletion", JOptionPane.PLAIN_MESSAGE); } private void Remove_UserActionPerformed(ActionEvent evt) { this.controlRemove_User.control(JOptionPane.showInputDialog (this, "Enter the name of the user you want to remove")); JOptionPane.showMessageDialog(this, (this.ShanghaiM.getrUser()).getStr_removeUser() , "Result of Deletion", JOptionPane.PLAIN_MESSAGE); } private void Connect_to_local_userActionPerformed(ActionEvent evt) { this.controlLocalServer_connection.control( JOptionPane.showInputDialog (this, "Enter the name of the database that you want to be connected"), JOptionPane.showInputDialog (this, "Enter the name of the local user who have all privilege \n" + "to the database you want to be connected"), JOptionPane.showInputDialog (this, "Enter the password of the user this user")); JOptionPane.showMessageDialog(this, (this.ShanghaiM.getcLocalServer()).getLocal_Server_str_Error() , "Result of connection", JOptionPane.PLAIN_MESSAGE); } private void ModifyDatabaseActionPerformed(ActionEvent evt) { if ( (this.ShanghaiM.getcLocalServer()).getConnect() == null ) JOptionPane.showMessageDialog(this, " Make sure that you have being connected first.\n" + " To do that, click to the button \"Connect to the local USER\"" , "BE CAREFUL", JOptionPane.PLAIN_MESSAGE); else new Modify_Database(ShanghaiM); } private void Disconnect_to_local_UserActionPerformed(ActionEvent evt) { this.controlLocalServer_connection.deconnection(); JOptionPane.showMessageDialog(this, (this.ShanghaiM.getcLocalServer()).getDeconnection() , "Result of deconnection", JOptionPane.PLAIN_MESSAGE); } private void ShowAll_DatabaseActionPerformed(ActionEvent evt) { this.controlGeneralDisplay.control(); JOptionPane.showMessageDialog(this, (this.ShanghaiM.getDisp()).getDisplayDatabases() , "This is all existing databases on this server", JOptionPane.PLAIN_MESSAGE); } private void Show_UsersActionPerformed(ActionEvent evt) { this.controlGeneralDisplay.display(); JOptionPane.showMessageDialog(this, (this.ShanghaiM.getDisp()).getShowUsers() , "This is all existing users on this server", JOptionPane.PLAIN_MESSAGE); } @Override public void update(Observable arg0, Object arg) {} }