use of org.scijava.swing.checkboxtree.CheckBoxNodeData in project mafscaling by vimsh.
the class LogView method exportSelectedWotPulls.
private void exportSelectedWotPulls() {
ArrayList<HashMap<String, ArrayList<Double>>> filePulls;
HashMap<String, ArrayList<Double>> pullData;
DefaultMutableTreeNode fileNode;
CheckBoxNodeData pullNode;
String fileName = null;
String nodeName = null;
String dirName = null;
int pullIdx;
int cnt;
int i, j;
setCursor(new Cursor(Cursor.WAIT_CURSOR));
try {
DefaultMutableTreeNode root = (DefaultMutableTreeNode) wotTree.getModel().getRoot();
for (int idx = 0; idx < root.getChildCount(); ++idx) {
fileNode = (DefaultMutableTreeNode) root.getChildAt(idx);
fileName = fileNode.getUserObject().toString().replaceAll(fileNameReplaceString, "");
for (cnt = 0; cnt < fileNode.getChildCount(); ++cnt) {
pullNode = (CheckBoxNodeData) ((DefaultMutableTreeNode) fileNode.getChildAt(cnt)).getUserObject();
if (!pullNode.isChecked())
continue;
filePulls = filesData.get(fileName);
nodeName = pullNode.getText();
pullIdx = Integer.parseInt(nodeName.replaceAll(pullIndexReplaceString, "")) - 1;
pullData = filePulls.get(pullIdx);
if (pullData.size() == 0)
continue;
if (dirName == null) {
JFileChooser fc = new JFileChooser();
fc.setCurrentDirectory((lastPullExportDir == null ? fileChooser.getCurrentDirectory() : lastPullExportDir));
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
fc.setAcceptAllFileFilterUsed(false);
if (JFileChooser.APPROVE_OPTION != fc.showSaveDialog(null))
return;
File dir = fc.getSelectedFile();
if (!dir.exists() || !dir.isDirectory()) {
JOptionPane.showMessageDialog(null, "Directory doesn't exist: " + dir.getAbsolutePath(), "Invalid directory", JOptionPane.ERROR_MESSAGE);
return;
}
lastPullExportDir = dir;
dirName = dir.getAbsolutePath();
}
ArrayList<String> columns = new ArrayList<String>();
ArrayList<ArrayList<Double>> data = new ArrayList<ArrayList<Double>>();
for (Map.Entry<String, ArrayList<Double>> entry : pullData.entrySet()) {
columns.add(entry.getKey());
data.add(entry.getValue());
}
Writer out = null;
try {
File file = new File(dirName + File.separator + fileName + "_" + nodeName + ".csv");
out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file, false), Config.getEncoding()));
int lidx = columns.size() - 1;
int rows = data.get(0).size();
for (i = 0; i <= lidx; ++i) out.write(columns.get(i) + (i < lidx ? "," : ""));
out.write("\n");
for (j = 0; j < rows; ++j) {
for (i = 0; i <= lidx; ++i) out.write(data.get(i).get(j) + (i < lidx ? "," : ""));
out.write("\n");
}
} catch (Exception e) {
logger.error(e);
} finally {
if (out != null) {
try {
out.close();
} catch (IOException e) {
logger.error(e);
}
}
}
}
}
} catch (Exception e) {
logger.error(e);
} finally {
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
}
use of org.scijava.swing.checkboxtree.CheckBoxNodeData in project mafscaling by vimsh.
the class LogView method loadWotLogFiles.
private void loadWotLogFiles() {
File[] files = fileChooser.getSelectedFiles();
if (files.length < 1)
return;
filesData = new HashMap<String, ArrayList<HashMap<String, ArrayList<Double>>>>();
wotYAxisGroups = new ArrayList<TreeSet<String>>();
TreeSet<String> columns = new TreeSet<String>();
ArrayList<String> colNames = null;
DefaultMutableTreeNode root = (DefaultMutableTreeNode) wotTree.getModel().getRoot();
root.removeAllChildren();
((DefaultTreeModel) wotTree.getModel()).reload(root);
wotPlotsColumn.removeAllItems();
wotPlotsColumn.setText("");
clearWotPlots();
double val;
int i = 0;
int row = 0;
for (File file : files) {
BufferedReader br = null;
try {
br = new BufferedReader(new InputStreamReader(new FileInputStream(file.getAbsoluteFile()), Config.getEncoding()));
String line = null;
String[] elements = null;
while ((line = br.readLine()) != null && (elements = line.split(Utils.fileFieldSplitter, -1)) != null && elements.length < 2) continue;
if (line.charAt(line.length() - 1) == ',')
Arrays.copyOf(elements, elements.length - 1);
colNames = new ArrayList<String>(Arrays.asList(elements));
if (false == getColumnsFilters(colNames))
continue;
DefaultMutableTreeNode fileNode = new DefaultMutableTreeNode("<html><u>" + file.getName() + "</u></html>");
ArrayList<HashMap<String, ArrayList<Double>>> pulls = new ArrayList<HashMap<String, ArrayList<Double>>>();
HashMap<String, ArrayList<Double>> pullData = new HashMap<String, ArrayList<Double>>();
ArrayList<Double> columnData;
String[] flds;
row = 0;
int pullRows = 0;
boolean wotFlag = true;
while ((line = br.readLine()) != null) {
if (line.length() > 0 && line.charAt(line.length() - 1) == ',')
line = line.substring(0, line.length() - 1);
flds = line.split(Utils.fileFieldSplitter, -1);
val = Double.valueOf(flds[logThtlAngleColIdx]);
if (row == 0 && val < 99)
wotFlag = false;
if (val < wotPoint) {
if (wotFlag == true) {
wotFlag = false;
if (pullRows >= 10) {
pulls.add(pullData);
pullData = new HashMap<String, ArrayList<Double>>();
fileNode.add(new DefaultMutableTreeNode(new CheckBoxNodeData(pullIndexReplaceString + pulls.size(), true)));
}
}
} else {
boolean newPullData = false;
if (wotFlag == false || row == 0) {
wotFlag = true;
newPullData = true;
pullRows = 0;
}
pullRows += 1;
for (i = 0; i < colNames.size(); ++i) {
if (newPullData) {
columnData = new ArrayList<Double>();
pullData.put(colNames.get(i), columnData);
} else
columnData = pullData.get(colNames.get(i));
if (flds[i].matches(Utils.tmRegex)) {
if (row == 0)
Utils.resetBaseTime(flds[i]);
columnData.add((double) Utils.parseTime(flds[i]));
} else
columnData.add(Utils.parseValue(flds[i]));
}
}
row += 1;
}
if (wotFlag == true) {
if (pullRows >= 10) {
pulls.add(pullData);
pullData = new HashMap<String, ArrayList<Double>>();
fileNode.add(new DefaultMutableTreeNode(new CheckBoxNodeData(pullIndexReplaceString + pulls.size(), true)));
}
}
if (pulls.size() > 0) {
root.add(fileNode);
TreePath path = new TreePath(root);
wotTree.expandPath(path.pathByAddingChild(fileNode));
filesData.put(file.getName(), pulls);
columns.addAll(colNames);
}
} catch (NumberFormatException ne) {
logger.error(ne);
JOptionPane.showMessageDialog(null, "Error parsing number at " + file.getName() + ", column " + colNames.get(i) + " line " + row + ": " + ne, "Error processing file", JOptionPane.ERROR_MESSAGE);
return;
} catch (Exception e) {
logger.error(e);
JOptionPane.showMessageDialog(null, e.getMessage(), "Error processing file " + file.getName(), JOptionPane.ERROR_MESSAGE);
return;
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
logger.error(e);
}
}
}
}
if (columns.size() > 0) {
for (String col : columns) wotPlotsColumn.addItem(col);
((DefaultTreeModel) wotTree.getModel()).reload(root);
for (row = 0; row < wotTree.getRowCount(); ++row) wotTree.expandRow(row);
linkYAxis.setEnabled(true);
} else {
JOptionPane.showMessageDialog(null, "No WOT pulls were found in the log file(s)", "Oops", JOptionPane.INFORMATION_MESSAGE);
}
}
Aggregations