Personalized File Manager (in development)

Summary - This application shows us recommendations of files by analyzing the previous search keywords and name of files opened.

Development Language - This application is developed using java swing.

Classes -
FileInfo.java
This class contains filename and number of times the file is opened by user. This data will be saved in database.

OpenFile.java
This class has methods to open selected file and also provide array of files in folder to display it.

StoreData.java
This class is used to store data into database.

MainMethod.java
Contains main method

UserInterface.java
Contains only UI methods and variables.

Data saved in database -
1. File name
2. Number of times file opened

Real time working of project -
While StartUp -
At the launch of this application the recommendations window will be filled with the filename suggestions according to the file open history.

User Interface -
There will be two windows. one to display list of files available in the targeted folder and another to display the recommended files for the user from the same folder. Also a button which will launch the selected file.

Behind the action listener of button -
The button not only opens the selected file but also records the files name and the numbers of clicks to that particular file. This data will be sent to database.

When we launch this application then the data from database including filename and number of times file opened will be fetched.

Classes - 

1. UserInterface

import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.border.Border;

public class UserInterface {
OpenFile of = new OpenFile();
FileInfo fileinfo;

JFrame jf = new JFrame("File Manager");
JButton jb1 = new JButton("Open File");
JLabel jl1 = new JLabel("Recommendations appear here");
JLabel jl2 = new JLabel();
JList<String> list;

public void build() {
DefaultListModel<String> str = new DefaultListModel<String>();

// loop to add file names into str array
for (int i = 0; i < of.f.length; i++) {
str.addElement(of.f[i].getAbsolutePath());
}

list = new JList<String>(str);

Border b = BorderFactory.createLineBorder(Color.black, 2);
Font f = new Font("Arial", Font.BOLD, 20);

jl1.setFont(f);
jl1.setBorder(b);
list.setFont(f);
jf.add(jl1).setBounds(30, 100, 300, 200);
jf.add(list).setBounds(400, 100, 300, 300);
jf.add(jb1).setBounds(250, 300, 100, 50);
jf.setLayout(null);
jf.setSize(800, 800);
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

jb1.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
// s has absolute file path
String s = list.getSelectedValue();
int i = s.lastIndexOf('\\');
// s has only name of file
s = s.substring(i + 1, s.length());

of.OpenFileMethod(list.getSelectedValue());
// returns the FileInfo object
// fileinfo = fileinfo.callObject();
// fileinfo.setFilename(s);
}
});
}
}


StoreData - 

import java.util.Iterator;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

public class StoreData {
FileInfo fileinfo;

public void StoreDataMethod() {
Configuration con = new Configuration();
con.configure("hibernate.cfg.xml");
SessionFactory sf = con.buildSessionFactory();
Session session = sf.openSession();
Transaction t = session.beginTransaction();

// Query query = session.createQuery("select filename from fileinfo where times_opened=1");
// System.out.println("query status " + query.getResultList());
// List<FileInfo> fileinfo = query.getResultList();
// for (FileInfo fileInfo2 : fileinfo) {
// System.out.println(fileInfo2.filename);
// }

Criteria c = session.createCriteria(FileInfo.class);

List<FileInfo> list = c.list();
Iterator<FileInfo> i = list.iterator();
while (i.hasNext()) {
fileinfo = new FileInfo();
fileinfo = i.next();
System.out.println(fileinfo.filename);
System.out.println(fileinfo.times_opened);
// fileinfo = i.next();
// System.out.println(fileinfo.filename);
// System.out.println(fileinfo.times_opened);
}

t.commit();
}
}


Comments

Popular posts from this blog

How to check if two Strings are anagrams of each other?

Multimedia search engine using python

How to sort String array by length of each string present in an array