use of org.scijava.swing.checkboxtree.CheckBoxNodeData in project mafscaling by vimsh.
the class VVTCalc method plotVEData.
private boolean plotVEData() {
int i = 0;
int j = 0;
int k = 0;
double rpm;
String name;
try {
boolean isVvt2Specified = !Config.getVvt2ColumnName().equals(Config.NO_NAME);
clearChartData();
DefaultMutableTreeNode treeNode;
TreePath path;
XYSeriesCollection[] datasets = new XYSeriesCollection[ChartPanelCount];
XYLineAndShapeRenderer[] lineRenderers = new XYLineAndShapeRenderer[ChartPanelCount];
DefaultMutableTreeNode root = (DefaultMutableTreeNode) pullTree.getModel().getRoot();
((DefaultTreeModel) pullTree.getModel()).reload(root);
for (k = 0; k < ChartPanelCount; ++k) {
datasets[k] = (XYSeriesCollection) chartPanels[k].getChart().getXYPlot().getDataset(0);
lineRenderers[k] = (XYLineAndShapeRenderer) chartPanels[k].getChart().getXYPlot().getRenderer(0);
}
Stroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, null, 0.0f);
for (i = 0; i < runTables.size(); ++i) {
try {
JTable table = runTables.get(i);
XYSeries vvt1Series = new XYSeries(i);
XYSeries vvt2Series = new XYSeries(i);
XYSeries veSeries = new XYSeries(i);
for (j = 0; j < table.getRowCount(); ++j) {
if (table.getValueAt(j, 0).equals("") || table.getValueAt(j, 3).equals(""))
break;
rpm = Double.valueOf(table.getValueAt(j, 0).toString());
vvt1Series.add(rpm, Double.valueOf(table.getValueAt(j, 1).toString()));
if (isVvt2Specified)
vvt2Series.add(rpm, Double.valueOf(table.getValueAt(j, 2).toString()));
veSeries.add(rpm, Double.valueOf(table.getValueAt(j, 3).toString()));
}
if (vvt1Series.getItemCount() > 0) {
name = pullIndexReplaceString + (i + 1);
vvt1Series.setDescription(name);
vvt2Series.setDescription(name);
veSeries.setDescription(name);
pullsComboBox.addItem(name);
vvt1RunSeries.add(vvt1Series);
datasets[0].addSeries(vvt1Series);
lineRenderers[0].setSeriesShapesVisible(datasets[0].getSeriesCount() - 1, false);
lineRenderers[0].setSeriesStroke(datasets[0].getSeriesCount() - 1, stroke);
if (isVvt2Specified && vvt2Series.getItemCount() > 0) {
vvt2RunSeries.add(vvt2Series);
datasets[1].addSeries(vvt2Series);
lineRenderers[1].setSeriesShapesVisible(datasets[1].getSeriesCount() - 1, false);
lineRenderers[1].setSeriesStroke(datasets[1].getSeriesCount() - 1, stroke);
}
veRunSeries.add(veSeries);
datasets[2].addSeries(veSeries);
lineRenderers[2].setSeriesShapesVisible(datasets[2].getSeriesCount() - 1, false);
lineRenderers[2].setSeriesStroke(datasets[2].getSeriesCount() - 1, stroke);
treeNode = new DefaultMutableTreeNode(new CheckBoxNodeData(name, true));
root.add(treeNode);
path = new TreePath(root);
pullTree.expandPath(path.pathByAddingChild(treeNode));
}
} catch (NumberFormatException e) {
logger.error(e);
JOptionPane.showMessageDialog(null, "Error parsing number from Pull " + (i + 1) + " table, row " + (j + 1) + ": " + e, "Error", JOptionPane.ERROR_MESSAGE);
return false;
}
}
((DefaultTreeModel) pullTree.getModel()).reload(root);
} catch (Exception e) {
logger.error(e);
JOptionPane.showMessageDialog(null, "Failed to plot VE data: " + e, "Error", JOptionPane.ERROR_MESSAGE);
}
return true;
}
use of org.scijava.swing.checkboxtree.CheckBoxNodeData in project mafscaling by vimsh.
the class VVTCalc method createTreePanel.
protected void createTreePanel() {
DefaultMutableTreeNode wotTreeRoot = new DefaultMutableTreeNode("Root");
DefaultTreeModel treeModel = new DefaultTreeModel(wotTreeRoot);
pullTree = new JTree(treeModel);
pullTree.setCellRenderer(new PullNodeRenderer());
pullTree.setCellEditor(new CheckBoxNodeEditor(pullTree));
pullTree.setEditable(true);
pullTree.setRootVisible(false);
pullTree.setOpaque(false);
pullTree.setBackground(null);
pullTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
pullTree.addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
Object obj = ((DefaultMutableTreeNode) e.getPath().getLastPathComponent()).getUserObject();
if (obj instanceof CheckBoxNodeData) {
CheckBoxNodeData checkBoxNode = (CheckBoxNodeData) obj;
XYSeriesCollection dataset;
XYSeries series;
for (int i = 0; i < hiddenSeries.size(); ++i) {
dataset = (XYSeriesCollection) chartPanels[i].getChart().getXYPlot().getDataset(0);
if (checkBoxNode.isChecked()) {
series = hiddenSeries.get(i).get(checkBoxNode.getText());
if (series != null) {
dataset.addSeries(series);
hiddenSeries.get(i).remove(checkBoxNode.getText());
}
} else {
for (int j = 0; j < dataset.getSeriesCount(); ++j) {
series = dataset.getSeries(j);
if (series.getDescription().equals(checkBoxNode.getText())) {
hiddenSeries.get(i).put(checkBoxNode.getText(), series);
dataset.removeSeries(j);
}
}
}
}
}
}
});
}
use of org.scijava.swing.checkboxtree.CheckBoxNodeData in project mafscaling by vimsh.
the class LogView method viewWotPlotsByRpm.
private void viewWotPlotsByRpm(boolean skipDrops) {
getWotYAxisGroups();
if (wotYAxisGroups.size() == 0) {
JOptionPane.showMessageDialog(null, "Please select columns to plot", "Invalid parameters", JOptionPane.ERROR_MESSAGE);
return;
}
clearWotPlots();
ArrayList<HashMap<String, ArrayList<Double>>> filePulls;
HashMap<String, ArrayList<Double>> pullData;
ArrayList<Double> rpmData;
ArrayList<Double> colData;
DefaultMutableTreeNode fileNode;
CheckBoxNodeData pullNode;
String fileName;
String pullName;
int pullIdx;
setCursor(new Cursor(Cursor.WAIT_CURSOR));
try {
for (int i = 0; i < wotYAxisGroups.size(); ++i) {
TreeSet<String> group = wotYAxisGroups.get(i);
XYSeriesCollection dataset = new XYSeriesCollection();
String yAxisName = "";
for (String yAxisColName : group) {
yAxisName += (yAxisName.isEmpty() ? yAxisColName : ", " + yAxisColName);
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 (int j = 0; j < fileNode.getChildCount(); ++j) {
pullNode = (CheckBoxNodeData) ((DefaultMutableTreeNode) fileNode.getChildAt(j)).getUserObject();
if (!pullNode.isChecked())
continue;
pullName = pullNode.getText();
filePulls = filesData.get(fileName);
pullIdx = Integer.parseInt(pullName.replaceAll(pullIndexReplaceString, "")) - 1;
pullData = filePulls.get(pullIdx);
rpmData = pullData.get(logRpmColName);
colData = pullData.get(yAxisColName);
if (colData != null) {
pullName = yAxisColName + " [" + pullName + ": " + fileName + "]";
XYSeries series = new XYSeries(pullName);
series.setDescription(pullName);
for (int k = 0; k < rpmData.size(); ++k) {
if (skipDrops) {
if (k > 0 && rpmData.get(k) > rpmData.get(k - 1))
series.add(Double.valueOf(rpmData.get(k)), Double.valueOf(colData.get(k)));
} else
series.add(Double.valueOf(rpmData.get(k)), Double.valueOf(colData.get(k)));
}
dataset.addSeries(series);
}
}
}
}
NumberAxis yAxis = new NumberAxis(yAxisName);
yAxis.setAutoRangeIncludesZero(false);
yAxis.setTickLabelPaint(Color.WHITE);
yAxis.setLabelPaint(Color.LIGHT_GRAY);
XYLineAndShapeRenderer lineRenderer = new XYLineAndShapeRenderer();
lineRenderer.setBaseShapesVisible(showWotCurvePoints);
wotPlot.setRenderer(i, lineRenderer);
wotPlot.setRangeAxis(i, yAxis, false);
wotPlot.setDataset(i, dataset);
wotPlot.mapDatasetToRangeAxis(i, i);
wotPlot.mapDatasetToDomainAxis(i, 0);
wotPlot.setRangeAxisLocation(i, (i % 2 == 0 ? AxisLocation.BOTTOM_OR_LEFT : AxisLocation.BOTTOM_OR_RIGHT));
}
} finally {
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
}
use of org.scijava.swing.checkboxtree.CheckBoxNodeData in project mafscaling by vimsh.
the class LogView method viewWotPlotsByTime.
private void viewWotPlotsByTime() {
getWotYAxisGroups();
if (wotYAxisGroups.size() == 0) {
JOptionPane.showMessageDialog(null, "Please select columns to plot", "Invalid parameters", JOptionPane.ERROR_MESSAGE);
return;
}
clearWotPlots();
ArrayList<HashMap<String, ArrayList<Double>>> filePulls;
HashMap<String, ArrayList<Double>> pullData;
ArrayList<Double> rpmData;
ArrayList<Double> timeData;
ArrayList<Double> colData = null;
DefaultMutableTreeNode fileNode;
CheckBoxNodeData pullNode;
String fileName;
String pullName;
int pullIdx;
int idx;
int rpm;
int maxrpm = 0;
double time = 0;
double newtime = 0;
double maxtime = 0;
double timeOffset = 0;
setCursor(new Cursor(Cursor.WAIT_CURSOR));
try {
// sort all pulls by RPM
TreeMap<Integer, ArrayList<HashMap<String, HashMap<String, ArrayList<Double>>>>> pullsByRpm = new TreeMap<Integer, ArrayList<HashMap<String, HashMap<String, ArrayList<Double>>>>>();
ArrayList<HashMap<String, HashMap<String, ArrayList<Double>>>> pulls;
DefaultMutableTreeNode root = (DefaultMutableTreeNode) wotTree.getModel().getRoot();
for (idx = 0; idx < root.getChildCount(); ++idx) {
fileNode = (DefaultMutableTreeNode) root.getChildAt(idx);
fileName = fileNode.getUserObject().toString().replaceAll(fileNameReplaceString, "");
for (int j = 0; j < fileNode.getChildCount(); ++j) {
pullNode = (CheckBoxNodeData) ((DefaultMutableTreeNode) fileNode.getChildAt(j)).getUserObject();
if (!pullNode.isChecked())
continue;
pullName = pullNode.getText();
filePulls = filesData.get(fileName);
pullIdx = Integer.parseInt(pullName.replaceAll(pullIndexReplaceString, "")) - 1;
pullData = filePulls.get(pullIdx);
pullName = " [" + pullName + ": " + fileName + "]";
HashMap<String, HashMap<String, ArrayList<Double>>> pullDataByName = new HashMap<String, HashMap<String, ArrayList<Double>>>();
pullDataByName.put(pullName, pullData);
rpmData = pullData.get(logRpmColName);
rpm = rpmData.get(0).intValue();
pulls = pullsByRpm.get(rpm);
if (pulls == null) {
pulls = new ArrayList<HashMap<String, HashMap<String, ArrayList<Double>>>>();
pullsByRpm.put(rpm, pulls);
}
pulls.add(pullDataByName);
}
}
// Reset pulls time by aligning RPM
ArrayList<HashMap<String, HashMap<String, ArrayList<Double>>>> allpulls = new ArrayList<HashMap<String, HashMap<String, ArrayList<Double>>>>();
while (pullsByRpm.size() > 0) {
time = newtime;
newtime = 0;
rpm = pullsByRpm.firstKey();
maxrpm = rpm;
pulls = pullsByRpm.remove(rpm);
for (idx = 0; idx < pulls.size(); ++idx) {
pullData = (pulls.get(idx)).entrySet().iterator().next().getValue();
rpmData = pullData.get(logRpmColName);
timeData = pullData.get(logTimeColName);
colData = new ArrayList<Double>();
for (int j = 0; j < rpmData.size(); ++j) {
double tm = timeData.get(j);
if (j == 0)
timeOffset = tm - time;
tm = tm - timeOffset;
colData.add(tm);
rpm = rpmData.get(j).intValue();
if (pullsByRpm.size() > 0 && newtime == 0 && rpm >= pullsByRpm.firstKey())
newtime = tm;
}
maxrpm = Math.max(maxrpm, rpmData.get(rpmData.size() - 1).intValue());
maxtime = Math.max(maxtime, colData.get(colData.size() - 1));
pullData.put("xaxis", colData);
}
if (pullsByRpm.size() > 0 && newtime == 0)
newtime = (maxtime * pullsByRpm.firstKey()) / maxrpm;
allpulls.addAll(pulls);
}
// Plot data
for (int i = 0; i < wotYAxisGroups.size(); ++i) {
TreeSet<String> group = wotYAxisGroups.get(i);
XYSeriesCollection dataset = new XYSeriesCollection();
String yAxisName = "";
for (String yAxisColName : group) {
yAxisName += (yAxisName.isEmpty() ? yAxisColName : ", " + yAxisColName);
for (idx = 0; idx < allpulls.size(); ++idx) {
Map.Entry<String, HashMap<String, ArrayList<Double>>> keyval = allpulls.get(idx).entrySet().iterator().next();
pullName = yAxisColName + keyval.getKey();
pullData = keyval.getValue();
timeData = pullData.get("xaxis");
colData = pullData.get(yAxisColName);
if (colData != null) {
XYSeries series = new XYSeries(pullName);
series.setDescription(pullName);
for (int k = 0; k < timeData.size(); ++k) series.add(Double.valueOf(timeData.get(k)), Double.valueOf(colData.get(k)));
dataset.addSeries(series);
}
}
}
NumberAxis yAxis = new NumberAxis(yAxisName);
yAxis.setAutoRangeIncludesZero(false);
yAxis.setTickLabelPaint(Color.WHITE);
yAxis.setLabelPaint(Color.LIGHT_GRAY);
XYLineAndShapeRenderer lineRenderer = new XYLineAndShapeRenderer();
lineRenderer.setBaseShapesVisible(showWotCurvePoints);
wotPlot.setRenderer(i, lineRenderer);
wotPlot.setRangeAxis(i, yAxis, false);
wotPlot.setDataset(i, dataset);
wotPlot.mapDatasetToRangeAxis(i, i);
wotPlot.mapDatasetToDomainAxis(i, 0);
wotPlot.setRangeAxisLocation(i, (i % 2 == 0 ? AxisLocation.BOTTOM_OR_LEFT : AxisLocation.BOTTOM_OR_RIGHT));
}
} 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