/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* MainWin.java
*
* Created on 29.10.2010, 14:47:41
*/
package at.redeye.FindDup;
import at.redeye.FindDup.SearchThread.STATE;
import at.redeye.FrameWork.Plugin.AboutPlugins;
import at.redeye.FrameWork.base.AutoLogger;
import at.redeye.FrameWork.base.BaseDialog;
import at.redeye.FrameWork.base.Root;
import at.redeye.FrameWork.base.Setup;
import at.redeye.FrameWork.base.desktoplauncher.DesktopLauncher;
import at.redeye.FrameWork.base.desktoplauncher.DesktopLauncher2;
import at.redeye.FrameWork.base.prm.impl.gui.LocalConfig;
import at.redeye.FrameWork.utilities.StringUtils;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Vector;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
/**
*
* @author moberza
*/
public class MainWin extends BaseDialog {
private static final String SELECTED_VIDEO = "SelectedVideos";
private static final String SELECTED_AUDIO = "SelectedAudio";
private static final String SELECTED_IMAGES = "SelectedImages";
private static final String SELECTED_OFFICE = "SelectedOffice";
private static final String SELECTED_ALL = "SelectedAll";
private static final String SELECTED_MASK = "SelectedMask";
private static final String SELECTED_SYSPATHS = "SelectedSysPaths";
private static final String SELECTED_ROOTS = "SelectedRoots";
private String MESSAGE_NO_DESKTOP_ICON;
private String MESSAGE_PROGRESS;
SearchThread search_thread = null;
ImageLoaderThread image_loader;
boolean clean_up_started = false;
public MainWin(Root root)
{
super(root, root.getAppTitle());
initComponents();
helper.autoRefreshTimer.schedule(helper.autoRefreshTask, 500, 500);
jLProgress.setText("");
jListErg.setCellRenderer(new ImageCellRenderer());
image_loader = new ImageLoaderThread(root,jListErg);
jCall.setSelected( StringUtils.isYes(root.getSetup().getLocalConfig(SELECTED_ALL, "false")) );
jCimages.setSelected( StringUtils.isYes(root.getSetup().getLocalConfig(SELECTED_IMAGES, "true")) );
jCvideo.setSelected( StringUtils.isYes(root.getSetup().getLocalConfig(SELECTED_VIDEO, "true")) );
jCMusic.setSelected( StringUtils.isYes(root.getSetup().getLocalConfig(SELECTED_AUDIO, "true")) );
jCoffice.setSelected( StringUtils.isYes(root.getSetup().getLocalConfig(SELECTED_OFFICE, "true")) );
jCsystemPaths.setSelected( StringUtils.isYes(root.getSetup().getLocalConfig(SELECTED_SYSPATHS, "true")) );
jTFileendings.setText(root.getSetup().getLocalConfig(SELECTED_MASK, ""));
drivePanel.showSystemDrives(!jCsystemPaths.isSelected());
drivePanel.setSelectedDirs(root.getSetup().getLocalConfig(SELECTED_ROOTS, drivePanel.getDirsAsString()));
if( jTFileendings.getText().trim().isEmpty() )
updateFileendings();
new AutoLogger(MainWin.class.getName()) {
@Override
public void do_stuff() throws Exception {
updateErgList(readLastResult());
}
};
initMessages();
if (!DesktopLauncher.canCreateDesktopIcon())
{
jMCreateDesktopIcon.setVisible(false);
}
else
{
jMCreateDesktopIcon.setEnabled(false);
}
}
private void initMessages() {
if (MESSAGE_NO_DESKTOP_ICON != null) {
return;
}
MESSAGE_NO_DESKTOP_ICON = MlM("Das Desktopicon konnte leider nicht erzeugt werden.");
MESSAGE_PROGRESS = MlM("Fortschritt:");
}
@Override
public void doAutoRefresh()
{
if( search_thread == null )
{
jBSearch.setText(MlM("Suche Starten"));
}
else if( search_thread.isAlive() )
{
STATE thread_state = search_thread.getCurrentState();
switch( thread_state )
{
case IDLE:
case SEARCHING_FOR_FILES:
jLProgress.setText(String.format(MlM("%d Dateien gefunden"), search_thread.getNumOfFiles() ) );
break;
case DONE:
setWaitCursor(false);
case ANALYSING_FILES:
jLProgress.setText(String.format(MlM("%d Dateien gleichen sich"), search_thread.getNumOfEqualFiles() ) );
break;
}
jBSearch.setText(MlM("Suche Abbrechen"));
}
else
{
final Map<String, List<FileEntry>> equalFilesByMD5 = search_thread.getEqualFilesByMD5();
updateErgList(equalFilesByMD5);
jLProgress.setText(String.format(MlM("%d gleiche Dateien gefunden"), search_thread.getNumOfEqualFiles() ) );
search_thread = null;
new AutoLogger(MainWin.class.getName()) {
@Override
public void do_stuff() throws Exception {
saveResult(equalFilesByMD5);
if( !clean_up_started )
{
CleanUpThread clean_up = new CleanUpThread(root);
clean_up.start();
clean_up_started = true;
}
}
};
setWaitCursor(false);
}
if( search_thread != null )
jLInfo.setText( MESSAGE_PROGRESS + " " + search_thread.getProgressInfo() );
else
jLInfo.setText(MESSAGE_PROGRESS);
}
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jBSearch = new javax.swing.JButton();
jLProgress = new javax.swing.JLabel();
drivePanel = new at.redeye.FindDup.DrivePanel(root);
jPanel1 = new javax.swing.JPanel();
jTFileendings = new javax.swing.JTextField();
jCimages = new javax.swing.JCheckBox();
jCvideo = new javax.swing.JCheckBox();
jCMusic = new javax.swing.JCheckBox();
jCoffice = new javax.swing.JCheckBox();
jCall = new javax.swing.JCheckBox();
jCsystemPaths = new javax.swing.JCheckBox();
jPanel2 = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
jListErg = new javax.swing.JList();
jScrollPane2 = new javax.swing.JScrollPane();
jLInfo = new javax.swing.JLabel();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
jMSettings = new javax.swing.JMenuItem();
jMCreateDesktopIcon = new javax.swing.JMenuItem();
jMQuit = new javax.swing.JMenuItem();
jMenu2 = new javax.swing.JMenu();
jMAbout = new javax.swing.JMenuItem();
jMChangeLog = new javax.swing.JMenuItem();
jMPlugin = new javax.swing.JMenuItem();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
jBSearch.setText("Suche Starten");
jBSearch.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jBSearchActionPerformed(evt);
}
});
jLProgress.setText("XXX");
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Dateiendungen"));
jTFileendings.setText("*.mp3 *.jpg *.jpeg");
jTFileendings.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTFileendingsActionPerformed(evt);
}
});
jCi