Search in sources :

Example 51 with Cursor

use of java.awt.Cursor in project mafscaling by vimsh.

the class AMafScaling method smoothReset.

protected void smoothReset() {
    if (gsCorrected.size() == 0)
        return;
    setCursor(new Cursor(Cursor.WAIT_CURSOR));
    try {
        smoothGsArray.clear();
        smoothGsArray.addAll(gsCorrected);
        setXYTable(mafSmoothingTable, voltArray, smoothGsArray);
        corrMafData.clear();
        onSmoothReset();
    } finally {
        setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    }
}
Also used : Cursor(java.awt.Cursor)

Example 52 with Cursor

use of java.awt.Cursor in project mafscaling by vimsh.

the class AMafScaling method smoothCurve.

protected void smoothCurve() {
    if (!checkBoxSmoothing.isSelected() || voltArray.size() == 0 || smoothGsArray.size() == 0)
        return;
    int degree = Integer.parseInt(smoothComboBox.getSelectedItem().toString().trim());
    int[] rows = mafSmoothingTable.getSelectedRows();
    int[] cols = mafSmoothingTable.getSelectedColumns();
    if (rows == null || cols == null || cols.length < degree) {
        JOptionPane.showMessageDialog(null, "Please select MAF Scaling table cells range to apply smoothing. Number of selected columns must be greater than the smoothing degree value.", "Invalid selection", JOptionPane.ERROR_MESSAGE);
        return;
    }
    setCursor(new Cursor(Cursor.WAIT_CURSOR));
    int start = cols[0];
    int end = cols[cols.length - 1];
    try {
        double[] input = new double[end - start + 1];
        for (int i = 0; i < input.length; ++i) input[i] = smoothGsArray.get(i + start);
        double[] output = Utils.getWeightedMovingAverageSmoothing(input, degree);
        for (int i = 0; i < output.length; ++i) smoothGsArray.set(i + start, output[i]);
        plotSmoothingLineSlopes();
    } finally {
        setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    }
}
Also used : Cursor(java.awt.Cursor)

Example 53 with Cursor

use of java.awt.Cursor 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));
    }
}
Also used : XYSeries(org.jfree.data.xy.XYSeries) NumberAxis(org.jfree.chart.axis.NumberAxis) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) HashMap(java.util.HashMap) XYLineAndShapeRenderer(org.jfree.chart.renderer.xy.XYLineAndShapeRenderer) ArrayList(java.util.ArrayList) Cursor(java.awt.Cursor) TreeMap(java.util.TreeMap) CheckBoxNodeData(org.scijava.swing.checkboxtree.CheckBoxNodeData) Paint(java.awt.Paint) XYSeriesCollection(org.jfree.data.xy.XYSeriesCollection) Map(java.util.Map) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap)

Example 54 with Cursor

use of java.awt.Cursor 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));
    }
}
Also used : XYSeries(org.jfree.data.xy.XYSeries) NumberAxis(org.jfree.chart.axis.NumberAxis) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) HashMap(java.util.HashMap) XYLineAndShapeRenderer(org.jfree.chart.renderer.xy.XYLineAndShapeRenderer) ArrayList(java.util.ArrayList) Cursor(java.awt.Cursor) CheckBoxNodeData(org.scijava.swing.checkboxtree.CheckBoxNodeData) Paint(java.awt.Paint) XYSeriesCollection(org.jfree.data.xy.XYSeriesCollection)

Example 55 with Cursor

use of java.awt.Cursor in project mafscaling by vimsh.

the class LogView method loadLogFile.

private void loadLogFile() {
    // close log player
    if (logPlayWindow != null)
        disposeLogView();
    // process log file
    File file = fileChooser.getSelectedFile();
    Properties prop = new Properties();
    prop.put("delimiter", ",");
    prop.put("firstRowHasColumnNames", "true");
    setCursor(new Cursor(Cursor.WAIT_CURSOR));
    logDataTable.filter(null);
    filterText.setText("");
    Column col;
    String colName;
    String lcColName;
    String val;
    try {
        for (int i = 0; i < logDataTable.getColumnCount(); ++i) {
            try {
                CheckboxHeaderRenderer cbr = (CheckboxHeaderRenderer) logDataTable.getColumn(i).getHeaderRenderer();
                logDataTable.getTableHeader().removeMouseListener(cbr.getMouseListener());
            } catch (Exception e) {
            }
        }
        BufferedReader br = null;
        try {
            br = new BufferedReader(new InputStreamReader(new FileInputStream(file.getAbsoluteFile()), Config.getEncoding()));
            String line = null;
            br.mark(1024);
            while ((line = br.readLine()) != null && !line.contains(",")) {
                br.mark(1024);
                continue;
            }
            br.reset();
            logDataTable.refresh(br, prop);
            // Below is a hack code to check and convert time column hh:mm:ss.sss to msec number
            convertTimeToMsec();
            // Below is a hack code to check and convert column(s) with on/off values to number
            convertOnOffToNumMsec();
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
            return;
        } finally {
            if (br != null) {
                try {
                    br.close();
                } catch (IOException e) {
                    logger.error(e);
                }
            }
        }
        CheckboxHeaderRenderer renderer;
        Component comp;
        XYSeries series;
        selectionCombo.removeAllItems();
        listModel.removeAllElements();
        xAxisColumn.removeAllItems();
        yAxisColumn.removeAllItems();
        plotsColumn.removeAllItems();
        xAxisColumn.addItem("");
        yAxisColumn.addItem("");
        plotsColumn.setText("");
        plot3d.removeAllPlots();
        rpmDataset.removeAllSeries();
        dataset.removeAllSeries();
        xMarker.clearLabels(true);
        rpmCol = -1;
        displCount = 0;
        JTableHeader tableHeader = logDataTable.getTableHeader();
        TreeSet<String> sortedColumns = new TreeSet<String>();
        for (int i = 0; i < logDataTable.getColumnCount(); ++i) {
            col = logDataTable.getColumn(i);
            renderer = new CheckboxHeaderRenderer(i + 1, tableHeader);
            col.setHeaderRenderer(renderer);
            colName = col.getHeaderValue().toString();
            sortedColumns.add(colName);
            comp = renderer.getTableCellRendererComponent(logDataTable.getTable(), colName, false, false, 0, 0);
            col.setPreferredWidth(comp.getPreferredSize().width + 4);
            series = new XYSeries(colName);
            series.setDescription(colName);
            lcColName = colName.toLowerCase();
            dataset.addSeries(series);
            plotRenderer.setSeriesShapesVisible(i, false);
            plotRenderer.setSeriesVisible(i, false);
            if (rpmDataset.getSeriesCount() == 0 && (lcColName.matches(rpmMatchString) || lcColName.matches(engineSpeedMatchString))) {
                rpmDataset.addSeries(series);
                rpmPlotRenderer.setSeriesShapesVisible(0, false);
                rpmPlotRenderer.setSeriesVisible(0, false);
                rpmCol = i;
            }
            for (int j = 0; j < logDataTable.getRowCount(); ++j) {
                try {
                    val = (String) logDataTable.getValueAt(j, i);
                    series.add(j, Double.valueOf(val), false);
                } catch (Exception e) {
                    JOptionPane.showMessageDialog(null, "Invalid numeric value in column " + colName + ", row " + (j + 1), "Invalid value", JOptionPane.ERROR_MESSAGE);
                    if (br != null)
                        br.close();
                    return;
                }
            }
            series.fireSeriesChanged();
        }
        for (String s : sortedColumns) {
            xAxisColumn.addItem(s);
            yAxisColumn.addItem(s);
            plotsColumn.addItem(s);
            selectionCombo.addItem(s);
            renderer = (CheckboxHeaderRenderer) logDataTable.getColumnByHeaderName(s).getHeaderRenderer();
            listModel.addElement(new JLabel(s, renderer.getCheckIcon(), JLabel.LEFT));
        }
        if (logDataTable.getControlPanel().getComponentCount() > tableControlPanelNumComponents)
            logDataTable.getControlPanel().remove(tableControlPanelNumComponents);
        logDataTable.getControlPanel().add(new JLabel("     [" + file.getName() + "]"));
        initColors();
    } catch (Exception ex) {
        ex.printStackTrace();
        logger.error(ex);
    } finally {
        setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    }
}
Also used : XYSeries(org.jfree.data.xy.XYSeries) InputStreamReader(java.io.InputStreamReader) JTableHeader(javax.swing.table.JTableHeader) JLabel(javax.swing.JLabel) IOException(java.io.IOException) Properties(java.util.Properties) PrintProperties(quick.dbtable.PrintProperties) Cursor(java.awt.Cursor) Paint(java.awt.Paint) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Column(quick.dbtable.Column) TreeSet(java.util.TreeSet) BufferedReader(java.io.BufferedReader) Component(java.awt.Component) File(java.io.File)

Aggregations

Cursor (java.awt.Cursor)136 IOException (java.io.IOException)34 File (java.io.File)27 Point (java.awt.Point)19 MouseEvent (java.awt.event.MouseEvent)16 MouseAdapter (java.awt.event.MouseAdapter)13 Component (java.awt.Component)12 BufferedReader (java.io.BufferedReader)10 FileInputStream (java.io.FileInputStream)10 InputStreamReader (java.io.InputStreamReader)10 JLabel (javax.swing.JLabel)10 ArrayList (java.util.ArrayList)8 URISyntaxException (java.net.URISyntaxException)7 Color (java.awt.Color)6 Insets (java.awt.Insets)6 WalletCallException (com.vaklinov.zcashui.ZCashClientCaller.WalletCallException)5 Dimension (java.awt.Dimension)5 GridBagConstraints (java.awt.GridBagConstraints)5 Rectangle (java.awt.Rectangle)5 JPanel (javax.swing.JPanel)5