1
Fork 0
mirror of https://github.com/Steffo99/unimore-oop-2020-cleaver.git synced 2024-11-22 16:14:18 +00:00

UI is feature complete!

This commit is contained in:
Steffo 2019-12-16 02:01:24 +01:00
parent bc2591b7a2
commit fbe9dbbd0f
8 changed files with 29 additions and 39 deletions

View file

@ -35,16 +35,14 @@ public class CleaverFrame extends JFrame {
ActionListener chopListener = new ActionListener() { ActionListener chopListener = new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
chopStitchPanel.createAndAddChopJobs(jobs); chopStitchPanel.createAndAddChopJobs(jobs, jobsTablePanel::updateTableChanged);
jobsTablePanel.updateTableChanged();
} }
}; };
ActionListener stitchListener = new ActionListener() { ActionListener stitchListener = new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
chopStitchPanel.createAndAddStitchJobs(jobs); chopStitchPanel.createAndAddStitchJobs(jobs, jobsTablePanel::updateTableChanged);
jobsTablePanel.updateTableChanged();
} }
}; };
@ -74,12 +72,10 @@ public class CleaverFrame extends JFrame {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
for(Job job : jobs) { for(Job job : jobs) {
if(job.getProgress().getClass() == NotStartedProgress.class) if(job.getProgress() instanceof NotStartedProgress)
{ {
job.start(); job.start();
} }
// TODO: refresh the jobs table every once in a while
// TODO: catch exceptions from the jobs
} }
} }
}; };

View file

@ -28,11 +28,11 @@ public class ChopAndStitchPanel extends JPanel {
this.add(Box.createHorizontalStrut(4)); this.add(Box.createHorizontalStrut(4));
} }
public void createAndAddChopJobs(ArrayList<Job> jobs) { public void createAndAddChopJobs(ArrayList<Job> jobs, Runnable updateTable) {
chopPanel.createAndAddJobs(jobs); chopPanel.createAndAddJobs(jobs, updateTable);
} }
public void createAndAddStitchJobs(ArrayList<Job> jobs) { public void createAndAddStitchJobs(ArrayList<Job> jobs, Runnable updateTable) {
stitchPanel.createAndAddJobs(jobs); stitchPanel.createAndAddJobs(jobs, updateTable);
} }
} }

View file

@ -27,11 +27,6 @@ public class ChopPanel extends CreateJobPanel {
return "Chop"; return "Chop";
} }
@Override
protected Class<? extends Job> getJobClass() {
return ChopJob.class;
}
public ChopPanel(ActionListener onCreateJobClick) { public ChopPanel(ActionListener onCreateJobClick) {
super(onCreateJobClick); super(onCreateJobClick);
@ -58,7 +53,7 @@ public class ChopPanel extends CreateJobPanel {
this.add(Box.createVerticalStrut(8)); this.add(Box.createVerticalStrut(8));
} }
public void createAndAddJobs(ArrayList<Job> jobs) { public void createAndAddJobs(ArrayList<Job> jobs, Runnable updateTable) {
if(fileSelectPanel.getSelectedFiles().length == 0) { if(fileSelectPanel.getSelectedFiles().length == 0) {
JOptionPane.showMessageDialog(null, "No files selected.", "Error", JOptionPane.ERROR_MESSAGE); JOptionPane.showMessageDialog(null, "No files selected.", "Error", JOptionPane.ERROR_MESSAGE);
} }
@ -76,12 +71,9 @@ public class ChopPanel extends CreateJobPanel {
CompressConfig zc = compressOptionPanel.getCompressConfig(); CompressConfig zc = compressOptionPanel.getCompressConfig();
try { Job job = new ChopJob(file, updateTable, sc, cc, zc);
Job job = getJobClass().getConstructor(File.class, SplitConfig.class, CryptConfig.class, CompressConfig.class).newInstance(file, sc, cc, zc);
jobs.add(job); jobs.add(job);
} catch (InstantiationException | NoSuchMethodException | InvocationTargetException | IllegalAccessException ex) {
JOptionPane.showMessageDialog(null, ex.toString(), "Error", JOptionPane.ERROR_MESSAGE);
}
} }
fileSelectPanel.clearSelectedFiles(); fileSelectPanel.clearSelectedFiles();
} }

View file

@ -13,8 +13,6 @@ public abstract class CreateJobPanel extends JPanel {
protected abstract String getPanelText(); protected abstract String getPanelText();
protected abstract Class<? extends Job> getJobClass();
public CreateJobPanel(ActionListener onCreateJobClick) { public CreateJobPanel(ActionListener onCreateJobClick) {
super(); super();

View file

@ -22,11 +22,6 @@ public class StitchPanel extends CreateJobPanel {
return "Stitch"; return "Stitch";
} }
@Override
protected Class<? extends Job> getJobClass() {
return StitchJob.class;
}
public StitchPanel(ActionListener onCreateJobClick) { public StitchPanel(ActionListener onCreateJobClick) {
super(onCreateJobClick); super(onCreateJobClick);
@ -49,11 +44,11 @@ public class StitchPanel extends CreateJobPanel {
fileSelectPanel.setFileFilter(new FileNameExtensionFilter("Cleaver Metadata (*.chp)", "chp")); fileSelectPanel.setFileFilter(new FileNameExtensionFilter("Cleaver Metadata (*.chp)", "chp"));
} }
public void createAndAddJobs(ArrayList<Job> jobs) { public void createAndAddJobs(ArrayList<Job> jobs, Runnable updateTable) {
File[] files = fileSelectPanel.getSelectedFiles(); File[] files = fileSelectPanel.getSelectedFiles();
for(File file : files) { for(File file : files) {
try { try {
Job job = new StitchJob(file, keyOptionRow.getKey()); Job job = new StitchJob(file, updateTable, keyOptionRow.getKey());
jobs.add(job); jobs.add(job);
} catch (ChpFileError ex) { } catch (ChpFileError ex) {
JOptionPane.showMessageDialog(null, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); JOptionPane.showMessageDialog(null, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);

View file

@ -2,6 +2,7 @@ package eu.steffo.cleaver.logic;
import eu.steffo.cleaver.logic.compress.CompressConfig; import eu.steffo.cleaver.logic.compress.CompressConfig;
import eu.steffo.cleaver.logic.crypt.CryptConfig; import eu.steffo.cleaver.logic.crypt.CryptConfig;
import eu.steffo.cleaver.logic.progress.FinishedProgress;
import eu.steffo.cleaver.logic.split.SplitConfig; import eu.steffo.cleaver.logic.split.SplitConfig;
import java.io.File; import java.io.File;
@ -9,10 +10,7 @@ import java.io.File;
public class ChopJob extends Job { public class ChopJob extends Job {
public ChopJob(File file, SplitConfig splitConfig, CryptConfig cryptConfig, CompressConfig compressConfig) { public ChopJob(File file, SplitConfig splitConfig, CryptConfig cryptConfig, CompressConfig compressConfig) {
super(file); this(file, null, splitConfig, cryptConfig, compressConfig);
this.splitConfig = splitConfig;
this.cryptConfig = cryptConfig;
this.compressConfig = compressConfig;
} }
public ChopJob(File file, Runnable swingCallLaterOnProgressChanges, SplitConfig splitConfig, CryptConfig cryptConfig, CompressConfig compressConfig) { public ChopJob(File file, Runnable swingCallLaterOnProgressChanges, SplitConfig splitConfig, CryptConfig cryptConfig, CompressConfig compressConfig) {
@ -29,6 +27,7 @@ public class ChopJob extends Job {
@Override @Override
public void run() { public void run() {
this.setProgress(new FinishedProgress());
} }
public SplitConfig getSplitConfig() { public SplitConfig getSplitConfig() {

View file

@ -27,6 +27,9 @@ public abstract class Job extends Thread {
public Job(File file, Runnable swingCallLaterOnProgressChanges) { public Job(File file, Runnable swingCallLaterOnProgressChanges) {
this(file); this(file);
this.swingCallLaterOnProgressChanges = swingCallLaterOnProgressChanges; this.swingCallLaterOnProgressChanges = swingCallLaterOnProgressChanges;
if(swingCallLaterOnProgressChanges != null) {
SwingUtilities.invokeLater(swingCallLaterOnProgressChanges);
}
} }
public abstract String getType(); public abstract String getType();
@ -41,8 +44,10 @@ public abstract class Job extends Thread {
protected void setProgress(Progress progress) { protected void setProgress(Progress progress) {
this.progress = progress; this.progress = progress;
if(swingCallLaterOnProgressChanges != null) {
SwingUtilities.invokeLater(swingCallLaterOnProgressChanges); SwingUtilities.invokeLater(swingCallLaterOnProgressChanges);
} }
}
public SplitConfig getSplitConfig() { public SplitConfig getSplitConfig() {
return splitConfig; return splitConfig;

View file

@ -4,6 +4,7 @@ import eu.steffo.cleaver.errors.ChpFileError;
import eu.steffo.cleaver.errors.ProgrammingError; import eu.steffo.cleaver.errors.ProgrammingError;
import eu.steffo.cleaver.logic.compress.CompressConfig; import eu.steffo.cleaver.logic.compress.CompressConfig;
import eu.steffo.cleaver.logic.crypt.CryptConfig; import eu.steffo.cleaver.logic.crypt.CryptConfig;
import eu.steffo.cleaver.logic.progress.FinishedProgress;
import eu.steffo.cleaver.logic.split.SplitByPartsConfig; import eu.steffo.cleaver.logic.split.SplitByPartsConfig;
import eu.steffo.cleaver.logic.split.SplitBySizeConfig; import eu.steffo.cleaver.logic.split.SplitBySizeConfig;
import eu.steffo.cleaver.logic.split.SplitConfig; import eu.steffo.cleaver.logic.split.SplitConfig;
@ -25,7 +26,11 @@ import java.io.IOException;
public class StitchJob extends Job { public class StitchJob extends Job {
public StitchJob(File file, String cryptKey) throws ChpFileError, ProgrammingError { public StitchJob(File file, String cryptKey) throws ChpFileError, ProgrammingError {
super(file); this(file, null, cryptKey);
}
public StitchJob(File file, Runnable updateTable, String cryptKey) throws ChpFileError, ProgrammingError {
super(file, updateTable);
parseChp(openChp(file), cryptKey); parseChp(openChp(file), cryptKey);
} }
@ -84,6 +89,6 @@ public class StitchJob extends Job {
@Override @Override
public void run() { public void run() {
this.setProgress(new FinishedProgress());
} }
} }