Example usage for org.apache.commons.collections.primitives FloatIterator hasNext

List of usage examples for org.apache.commons.collections.primitives FloatIterator hasNext

Introduction

In this page you can find the example usage for org.apache.commons.collections.primitives FloatIterator hasNext.

Prototype

boolean hasNext();

Source Link

Document

Returns true iff I have more elements.

Usage

From source file:pipeline.GUI_utils.ListOfPointsView.java

@Override
@SuppressWarnings({ "rawtypes" })
public void actionPerformed(ActionEvent event) {
    if (event.getActionCommand().equals("Update display in real time")) {
        realTimeUpdates = realTimeUpdateCheckbox.isSelected();
    } else if (event.getActionCommand().equals("Force display update")) {
        updateImage();/*from w  w  w.j a  v  a2s .  c  o m*/
    } else if (event.getActionCommand().equals("Save table to file")) {
        saveToFile();
    } else if (event.getActionCommand().equals("Scatter plot from selected columns")) {
        int[] selectedColumns = table.getSelectedColumns();
        String name1 = table.getColumnName(selectedColumns[0]);
        XYScatterPlotView scv = null;
        if (selectedColumns.length == 1) {
            // display a histogram rather than a scatter plot
            scv = new XYScatterPlotView(1);
            scv.setWindowTitle("Histogram of " + name1);

            final int columnModelIndex = table.convertColumnIndexToModel(selectedColumns[0]);

            int nFilteredRows = table.getNumberFilteredRows();
            if (nFilteredRows == 0) {
                // No row filtered, so create a plot that should be dynamically updated as
                // the underlying PluginIO is updated by the pipeline plugins
                ColumnInformation columnInfo = tableModel.columns.get(columnModelIndex);
                if (columnInfo.getReturnType().equals(ArrayFloatList.class)) {
                    // Display histogram of values for the selected cell, NOT a histogram for
                    // a single value for all cells in table
                    ArrayFloatList values = (ArrayFloatList) table.getValueAt(table.getSelectedRow(),
                            selectedColumns[0]);
                    XYSeriesE series = new XYSeriesE(columnInfo.fieldName);
                    FloatIterator it = values.iterator();
                    while (it.hasNext()) {
                        series.add(it.next(), 0);
                    }
                    scv.addSeries(name1, series);

                } else {
                    if (columnInfo.indexInList > -1) {
                        scv.addSeries(name1,
                                points.getJFreeChartXYSeries(columnInfo.fieldName, null, columnInfo.indexInList,
                                        -1, tableModel.columns.get(columnModelIndex).getName(), null));
                    } else
                        scv.addSeries(name1, points.getJFreeChartXYSeries(name1, null, -1, -1,
                                tableModel.columns.get(columnModelIndex).getName(), null));
                }
            } else {
                // Some rows are filtered, so we do not want to display everything
                // TODO Ideally we would want to dynamically refilter when master list is changed by pipeline plugin
                List<@Nullable T> filteredPoints = new ArrayList<>(table.getRowCount());// -nFilteredRows
                for (int i = 0; i < tableModel.getRowCount(); i++) {
                    int rowIndex = table.convertRowIndexToView(i);
                    if (rowIndex > -1) {
                        filteredPoints.add(tableModel.getRow(i));
                    }
                }
                ColumnInformation columnInfo = tableModel.columns.get(columnModelIndex);
                @SuppressWarnings("unchecked")
                IPluginIOList<T> subList = (IPluginIOList<T>) points.duplicateStructure();
                subList.addAll(filteredPoints);
                if (columnInfo.indexInList > -1) {
                    scv.addSeries(name1,
                            subList.getJFreeChartXYSeries(columnInfo.fieldName, null, columnInfo.indexInList,
                                    -1, tableModel.columns.get(columnModelIndex).getName(), null));
                } else
                    scv.addSeries(name1, subList.getJFreeChartXYSeries(name1, null, -1, -1,
                            tableModel.columns.get(columnModelIndex).getName(), null));
            }
        } else { // display a scatter plot
            final int xColumnModelIndex = table.convertColumnIndexToModel(selectedColumns[0]);
            final int yColumnModelIndex = table.convertColumnIndexToModel(selectedColumns[1]);
            String name2 = table.getColumnName(selectedColumns[1]);
            // Utils.log("Creating pairwise plot for columns "+name1+" and "+name2,LogLevel.DEBUG);
            // For now just deal with the first two columns
            scv = new XYScatterPlotView(0);
            scv.setWindowTitle("Scatterplot: " + name2 + " vs " + name1);
            int nFilteredRows = table.getNumberFilteredRows();
            ColumnInformation xColumnInfo = tableModel.columns.get(xColumnModelIndex);
            ColumnInformation yColumnInfo = tableModel.columns.get(yColumnModelIndex);
            int xListIndex = xColumnInfo.indexInList;
            int yListIndex = yColumnInfo.indexInList;
            String xName = xListIndex > -1 ? xColumnInfo.fieldName : name1;
            String yName = yListIndex > -1 ? yColumnInfo.fieldName : name2;
            if (nFilteredRows == 0) {
                // No row filtered, so create a plot that should be dynamically updated as
                // the underlying PluginIO is updated by the pipeline plugins
                scv.addSeries(name1 + " and " + name2,
                        points.getJFreeChartXYSeries(xName, yName, xListIndex, yListIndex,
                                tableModel.columns.get(xColumnModelIndex).getName(),
                                tableModel.columns.get(yColumnModelIndex).getName()));
            } else {
                // Some rows are filtered, so we do not want to display everything
                // TODO Ideally we would want to dynamically refilter when master list is changed by pipeline plugin
                List<@Nullable T> filteredPoints = new ArrayList<>(table.getRowCount());
                for (int i = 0; i < tableModel.getRowCount(); i++) {
                    int rowIndex = table.convertRowIndexToView(i);
                    if (rowIndex > -1) {
                        filteredPoints.add(tableModel.getRow(i));
                    }
                }
                @SuppressWarnings("unchecked")
                IPluginIOList<T> subList = (IPluginIOList<T>) points.duplicateStructure();
                subList.addAll(filteredPoints);
                scv.addSeries(name1 + " and " + name2,
                        subList.getJFreeChartXYSeries(xName, yName, xListIndex, yListIndex,
                                tableModel.columns.get(xColumnModelIndex).getName(),
                                tableModel.columns.get(yColumnModelIndex).getName()));
            }
        }
        scv.show();

    } else if (event.getActionCommand().equals("Extend formula to column")) {
        int[] selectedColumns = table.getSelectedColumns();
        if ((selectedColumns.length < 1) || (!table.getColumnName(selectedColumns[0]).contains("userCell"))) {
            Utils.displayMessage("No user column selected; length is " + selectedColumns.length, true,
                    LogLevel.ERROR);
            return;
        }
        int[] selectedRows = table.getSelectedRows();
        Utils.log("Extending formula in cell " + selectedRows[0] + ", " + selectedColumns[0], LogLevel.DEBUG);
        // String formula=((SpreadsheetCell) table.getValueAt(selectedRows[0], selectedColumns[0])).getFormula();
        silenceUpdates.incrementAndGet();// for performance reasons

        try {

            for (int i = 0; i < tableModel.getRowCount(); i++) {
                Expr4jAdditions.extendFormula(spreadsheetEngine, selectedRows[0] + 1, selectedColumns[0] + 1,
                        i + 1, selectedColumns[0] + 1);
                String formula = spreadsheetEngine
                        .getInput(new Range(null, new GridReference(selectedColumns[0] + 1, i + 1)));
                if (tableModel.getValueAt(i, selectedColumns[0]) == null) {
                    SpreadsheetCell cell = new SpreadsheetCell("", "", new Object[] { 0.0, formula }, true,
                            null, null);
                    tableModel.setValueAt(cell, i, selectedColumns[0]);
                } else {

                    SpreadsheetCell cell = (SpreadsheetCell) table.getValueAt(i, selectedColumns[0]);
                    cell.setFormula(formula);
                }
            }
        } catch (Exception excp) {
            Utils.printStack(excp);
        } finally {
            silenceUpdates.decrementAndGet();
        }
        // the following is to get a histogram displayed for the column we've computed
        table.needToInitializeFilterModel = true;
        table.initializeFilterModel();
        table.updateRangeOfColumn(selectedColumns[0], true, 0, false);
        tableModel.fireTableDataChanged();
    } else if ("Save user formulas".equals(event.getActionCommand())) {
        List<Integer> userColumns = getUserColumnList();
        table.saveFilteredRowsToFile(userColumns, true, null);
    } else if ("Reload user formulas".equals(event.getActionCommand())) {
        reloadUserFormulasFromFile();
    } else if ("comboBoxEdited".equals(event.getActionCommand())
            || ("comboBoxChanged".equals(event.getActionCommand()))) {
        Object colorSelection = coloringComboBox.getModel().getSelectedItem();
        if (colorSelection != null)
            points.firePluginIOViewEvent(this, false);
    }
}