Skip to content

Commit

Permalink
Merge pull request mzmine#12 from TDI-tenderholt/display_log_fix
Browse files Browse the repository at this point in the history
Some various fixes & clean-up for displaying the job log
  • Loading branch information
DavidARivkin committed Jan 27, 2016
2 parents f5b87e1 + 909609c commit f278358
Showing 1 changed file with 94 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@

package net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.PeakInvestigator;

import java.awt.Container;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
Expand All @@ -34,6 +40,11 @@
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;

import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.ProgressMonitor;

import java.io.BufferedReader;
Expand All @@ -47,6 +58,7 @@
import net.sf.mzmine.main.MZmineCore;
import net.sf.mzmine.parameters.ParameterSet;
import net.sf.mzmine.util.ExitCode;
import net.sf.mzmine.util.GUIUtils;

import org.xeustechnologies.jtar.TarEntry;
import org.xeustechnologies.jtar.TarInputStream;
Expand Down Expand Up @@ -469,35 +481,41 @@ private void startRetrieve()
}
vtmx.getFile(inputLogFilename);
progressMonitor.setProgress(6);
if(showLog) {
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader(inputLogFilename));
} catch (FileNotFoundException e2) {
MZmineCore.getDesktop().displayErrorMessage(MZmineCore.getDesktop().getMainWindow(), "Error", "Log file not found", logger);
}
if(br != null) {
try {
StringBuilder sb = new StringBuilder();
String line = br.readLine();

while (line != null) {
sb.append(line);
sb.append(System.lineSeparator());
line = br.readLine();
}
logInfo = sb.toString();
} catch (Exception e1) {
logger.finest(e1.getMessage());
MZmineCore.getDesktop().displayErrorMessage(MZmineCore.getDesktop().getMainWindow(), "Error", "Cannot parse log file", logger);
errors++;
e1.printStackTrace();
} finally {
try { br.close(); } catch (Exception e) {}
MZmineCore.getDesktop().displayMessage(MZmineCore.getDesktop().getMainWindow(), "Peak Investigator Job Log", logInfo);
if (showLog) {
File fileWithFullPath = new File(inputLogFilename);
try (BufferedReader br = new BufferedReader(new FileReader(
fileWithFullPath.getName()))) {
StringBuilder sb = new StringBuilder();
String line = br.readLine();

while (line != null) {
sb.append(line);
sb.append(System.lineSeparator());
line = br.readLine();
}

logInfo = sb.toString();
PeakInvestigatorLogDialog logDialog = new PeakInvestigatorLogDialog(logInfo);
logDialog.setVisible(true);

// MZmineCore.getDesktop().displayMessage(
// MZmineCore.getDesktop().getMainWindow(),
// "Peak Investigator Job Log", logInfo);

} catch (FileNotFoundException e2) {
MZmineCore.getDesktop().displayErrorMessage(
MZmineCore.getDesktop().getMainWindow(), "Error",
"Log file not found", logger);
} catch (Exception e1) {
logger.finest(e1.getMessage());
MZmineCore.getDesktop().displayErrorMessage(
MZmineCore.getDesktop().getMainWindow(), "Error",
"Cannot parse log file", logger);
errors++;
e1.printStackTrace();
}
}

progressMonitor.setNote("Finished");
progressMonitor.setProgress(7);
}
Expand Down Expand Up @@ -569,6 +587,13 @@ private void finishRetrieve()

desc = "finishing retrieve";
logger.info("Finishing retrieval of job " + jobID);

if (System.getProperty("PeakInvestigatorTask.deleteJob")
.equals("false")) {
logger.info("Job " + jobID + " not being deleted as requested.");
return;
}

vtmx.getPageDone();
rawDataFile.removeJob(jobID);
desc = "retrieve finished";
Expand All @@ -577,4 +602,47 @@ private void finishRetrieve()
"Remember to save your project before closing MZminePI.", logger);
}

class PeakInvestigatorLogDialog extends JDialog implements ActionListener {

private static final long serialVersionUID = 1L;

PeakInvestigatorLogDialog(String contents) {
super(MZmineCore.getDesktop().getMainWindow(),
"PeakInvestigator Job Log",
Dialog.ModalityType.DOCUMENT_MODAL);

Container verticalBox = Box.createVerticalBox();

JTextArea textArea = new JTextArea(contents);
textArea.setEditable(false);

JScrollPane scrollPane = new JScrollPane(textArea);
verticalBox.add(scrollPane);

Container buttonBox = Box.createHorizontalBox();

@SuppressWarnings("unused")
JButton closeButton = GUIUtils.addButton(buttonBox, "Close", null,
this);

verticalBox.add(buttonBox);

add(verticalBox);

setLocationRelativeTo(getParent());
setMinimumSize(new Dimension(400, 300));

}

@Override
public void actionPerformed(ActionEvent e) {
Object object = e.getSource();

if (object instanceof JButton
&& ((JButton) object).getText() == "Close") {
dispose();
}
}
}

}

0 comments on commit f278358

Please sign in to comment.