1
Fork 0
mirror of https://github.com/Steffo99/unimore-oop-2020-cleaver.git synced 2024-11-21 23:54:20 +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() {
@Override
public void actionPerformed(ActionEvent e) {
chopStitchPanel.createAndAddChopJobs(jobs);
jobsTablePanel.updateTableChanged();
chopStitchPanel.createAndAddChopJobs(jobs, jobsTablePanel::updateTableChanged);
}
};
ActionListener stitchListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
chopStitchPanel.createAndAddStitchJobs(jobs);
jobsTablePanel.updateTableChanged();
chopStitchPanel.createAndAddStitchJobs(jobs, jobsTablePanel::updateTableChanged);
}
};
@ -74,12 +72,10 @@ public class CleaverFrame extends JFrame {
@Override
public void actionPerformed(ActionEvent e) {
for(Job job : jobs) {
if(job.getProgress().getClass() == NotStartedProgress.class)
if(job.getProgress() instanceof NotStartedProgress)
{
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));
}
public void createAndAddChopJobs(ArrayList<Job> jobs) {
chopPanel.createAndAddJobs(jobs);
public void createAndAddChopJobs(ArrayList<Job> jobs, Runnable updateTable) {
chopPanel.createAndAddJobs(jobs, updateTable);
}
public void createAndAddStitchJobs(ArrayList<Job> jobs) {
stitchPanel.createAndAddJobs(jobs);
public void createAndAddStitchJobs(ArrayList<Job> jobs, Runnable updateTable) {
stitchPanel.createAndAddJobs(jobs, updateTable);
}
}

View file

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

View file

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

View file

@ -22,11 +22,6 @@ public class StitchPanel extends CreateJobPanel {
return "Stitch";
}
@Override
protected Class<? extends Job> getJobClass() {
return StitchJob.class;
}
public StitchPanel(ActionListener onCreateJobClick) {
super(onCreateJobClick);
@ -49,11 +44,11 @@ public class StitchPanel extends CreateJobPanel {
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();
for(File file : files) {
try {
Job job = new StitchJob(file, keyOptionRow.getKey());
Job job = new StitchJob(file, updateTable, keyOptionRow.getKey());
jobs.add(job);
} catch (ChpFileError ex) {
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.crypt.CryptConfig;
import eu.steffo.cleaver.logic.progress.FinishedProgress;
import eu.steffo.cleaver.logic.split.SplitConfig;
import java.io.File;
@ -9,10 +10,7 @@ import java.io.File;
public class ChopJob extends Job {
public ChopJob(File file, SplitConfig splitConfig, CryptConfig cryptConfig, CompressConfig compressConfig) {
super(file);
this.splitConfig = splitConfig;
this.cryptConfig = cryptConfig;
this.compressConfig = compressConfig;
this(file, null, splitConfig, cryptConfig, compressConfig);
}
public ChopJob(File file, Runnable swingCallLaterOnProgressChanges, SplitConfig splitConfig, CryptConfig cryptConfig, CompressConfig compressConfig) {
@ -29,6 +27,7 @@ public class ChopJob extends Job {
@Override
public void run() {
this.setProgress(new FinishedProgress());
}
public SplitConfig getSplitConfig() {

View file

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

View file

@ -4,6 +4,7 @@ import eu.steffo.cleaver.errors.ChpFileError;
import eu.steffo.cleaver.errors.ProgrammingError;
import eu.steffo.cleaver.logic.compress.CompressConfig;
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.SplitBySizeConfig;
import eu.steffo.cleaver.logic.split.SplitConfig;
@ -25,7 +26,11 @@ import java.io.IOException;
public class StitchJob extends Job {
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);
}
@ -84,6 +89,6 @@ public class StitchJob extends Job {
@Override
public void run() {
this.setProgress(new FinishedProgress());
}
}