Example usage for java.awt List size

List of usage examples for java.awt List size

Introduction

In this page you can find the example usage for java.awt List size.

Prototype

@Deprecated
public Dimension size() 

Source Link

Document

Returns the size of this component in the form of a Dimension object.

Usage

From source file:org.fhcrc.cpl.viewer.gui.SpectrumChartFactory.java

public static ChartPanel CreateChartPanel(java.util.List datasets, Color[] colors) {
    if (datasets.size() == 1)
        return CreateChartPanel((XYSeriesCollection) datasets.get(0), colors);

    CombinedDomainXYPlot combined = new CombinedDomainXYPlot();
    for (Iterator it = datasets.iterator(); it.hasNext();) {
        XYSeriesCollection series = (XYSeriesCollection) it.next();
        XYPlot xy = createXYPlot(series, colors);
        combined.add(xy);/*from   w  w w  .  ja va 2  s .  c  o  m*/
    }
    NumberAxis axisDomain = new NumberAxis();
    axisDomain.setAutoRangeIncludesZero(false);
    //      axisDomain.setRange(400.0, 1600.0);
    combined.setDomainAxis(axisDomain);

    JFreeChart chart = new JFreeChart(combined);
    ChartPanel chartPanel = new SpectrumChartPanel(chart);
    chartPanel.setDisplayToolTips(true);
    chartPanel.setMouseZoomable(true);
    // Remove the autogenerated subtitle
    if (chart.getSubtitleCount() == 1)
        chart.removeSubtitle(chart.getSubtitle(chart.getSubtitleCount() - 1));
    return chartPanel;
}

From source file:org.fhcrc.cpl.viewer.gui.SpectrumChartFactory.java

public static void setColors(ChartPanel panel, Color[] colors) {
    Plot plot = panel.getChart().getPlot();
    if (plot instanceof XYPlot) {
        setColors((XYPlot) plot, colors);
        return;/*from w  ww.jav  a  2s  . co  m*/
    }

    CombinedDomainXYPlot plotCombined = (CombinedDomainXYPlot) plot;
    java.util.List list = (plotCombined).getSubplots();
    for (int i = 0; i < list.size(); i++)
        setColors((XYPlot) list.get(i), colors);
}

From source file:org.fhcrc.cpl.toolbox.gui.chart.PanelWithScatterPlot.java

/**
 * Create a scatterplot with the logs of the values passed in
 * @param xValues//ww w . java 2 s .  com
 * @param yValues
 * @param dataSetName
 * @return
 */
public static PanelWithScatterPlot createPlotForLogValues(java.util.List<? extends Number> xValues,
        java.util.List<? extends Number> yValues, String dataSetName) {
    java.util.List<Double> xValuesLog = new ArrayList<Double>();
    java.util.List<Double> yValuesLog = new ArrayList<Double>();

    for (int i = 0; i < xValues.size(); i++) {
        xValuesLog.add(Math.log(xValues.get(i).doubleValue()));
        yValuesLog.add(Math.log(yValues.get(i).doubleValue()));
    }
    return new PanelWithScatterPlot(xValuesLog, yValuesLog, dataSetName);
}

From source file:net.semanticmetadata.lire.utils.FileUtils.java

public static ArrayList<String> readFileLines(File directory, boolean descendIntoSubDirectories)
        throws IOException {
    ArrayList<String> resultList = new ArrayList<String>(256);
    String[] extensions = new String[] { "jpg", "JPG", "jpeg", "png", "gif", "tif", "tiff" };

    System.out.print("Getting all images in " + directory.getCanonicalPath() + " "
            + ((descendIntoSubDirectories) ? "including" : "not including") + " those in subdirectories");
    java.util.List<File> files = (LinkedList<File>) org.apache.commons.io.FileUtils.listFiles(directory,
            extensions, descendIntoSubDirectories);
    System.out.println(" ~ Found " + files.size() + " images");
    for (File file : files) {
        resultList.add(file.getCanonicalPath());
    }// w  w  w . j  av  a2s  .c  o  m

    return resultList;
}

From source file:dbseer.gui.chart.DBSeerChartFactory.java

public static XYSeriesCollection getXYSeriesCollection(String chartName, DBSeerDataSet dataset)
        throws Exception {
    StatisticalPackageRunner runner = DBSeerGUI.runner;

    runner.eval("[title legends Xdata Ydata Xlabel Ylabel timestamp] = plotter.plot" + chartName + ";");

    String title = runner.getVariableString("title");
    Object[] legends = (Object[]) runner.getVariableCell("legends");
    Object[] xCellArray = (Object[]) runner.getVariableCell("Xdata");
    Object[] yCellArray = (Object[]) runner.getVariableCell("Ydata");
    String xLabel = runner.getVariableString("Xlabel");
    String yLabel = runner.getVariableString("Ylabel");

    timestamp = runner.getVariableDouble("timestamp");

    XYSeriesCollection XYdataSet = new XYSeriesCollection();

    int numLegends = legends.length;
    int numXCellArray = xCellArray.length;
    int numYCellArray = yCellArray.length;
    int dataCount = 0;

    if (numXCellArray != numYCellArray) {
        JOptionPane.showMessageDialog(null, "The number of X dataset and Y dataset does not match.",
                "The number of X dataset and Y dataset does not match.", JOptionPane.ERROR_MESSAGE);
        System.out.println(numXCellArray + " : " + numYCellArray);
        return null;
    }/*from w ww  .  ja v a2 s.  c o m*/

    java.util.List<String> transactionNames = dataset.getTransactionTypeNames();

    for (int i = 0; i < numLegends; ++i) {
        String legend = (String) legends[i];
        for (int j = 0; j < transactionNames.size(); ++j) {
            if (legend.contains("Type " + (j + 1))) {
                legends[i] = legend.replace("Type " + (j + 1), transactionNames.get(j));
                break;
            }
        }
    }

    for (int i = 0; i < numYCellArray; ++i) {
        double[] xArray = (double[]) xCellArray[i];
        int row = 0, col = 0;
        int xLength = 0;

        runner.eval("yArraySize = size(Ydata{" + (i + 1) + "});");
        runner.eval("yArray = Ydata{" + (i + 1) + "};");
        double[] yArraySize = runner.getVariableDouble("yArraySize");
        double[] yArray = runner.getVariableDouble("yArray");

        xLength = xArray.length;
        row = (int) yArraySize[0];
        col = (int) yArraySize[1];

        for (int c = 0; c < col; ++c) {
            XYSeries series;
            String legend = "";
            int legendIdx = (dataCount >= numLegends) ? numLegends - 1 : dataCount;
            if (legendIdx >= 0) {
                legend = (String) legends[legendIdx];
            }
            if (numLegends == 0) {
                series = new XYSeries("Data " + dataCount + 1);
            } else if (dataCount >= numLegends) {
                series = new XYSeries(legend + (dataCount + 1));
            } else {
                series = new XYSeries(legend);
            }

            for (int r = 0; r < row; ++r) {
                int xRow = (r >= xLength) ? xLength - 1 : r;
                double yValue = yArray[r + c * row];
                // remove negatives
                if (yValue < 0) {
                    yValue = 0;
                }
                series.add(xArray[xRow], yValue);
            }
            XYdataSet.addSeries(series);
            ++dataCount;
        }
    }

    return XYdataSet;
}

From source file:dbseer.gui.chart.DBSeerChartFactory.java

public static JFreeChart createXYLineChart(String chartName, DBSeerDataSet dataset) throws Exception {
    StatisticalPackageRunner runner = DBSeerGUI.runner;

    runner.eval("[title legends Xdata Ydata Xlabel Ylabel timestamp] = plotter.plot" + chartName + ";");

    String title = runner.getVariableString("title");
    Object[] legends = (Object[]) runner.getVariableCell("legends");
    Object[] xCellArray = (Object[]) runner.getVariableCell("Xdata");
    Object[] yCellArray = (Object[]) runner.getVariableCell("Ydata");
    String xLabel = runner.getVariableString("Xlabel");
    String yLabel = runner.getVariableString("Ylabel");

    timestamp = runner.getVariableDouble("timestamp");

    XYSeriesCollection XYdataSet = new XYSeriesCollection();

    int numLegends = legends.length;
    int numXCellArray = xCellArray.length;
    int numYCellArray = yCellArray.length;
    int dataCount = 0;

    if (numXCellArray != numYCellArray) {
        JOptionPane.showMessageDialog(null, "The number of X dataset and Y dataset does not match.",
                "The number of X dataset and Y dataset does not match.", JOptionPane.ERROR_MESSAGE);
        System.out.println(numXCellArray + " : " + numYCellArray);
        return null;
    }// w  ww .ja  va  2  s .  c o  m

    java.util.List<String> transactionNames = dataset.getTransactionTypeNames();

    for (int i = 0; i < numLegends; ++i) {
        String legend = (String) legends[i];
        for (int j = 0; j < transactionNames.size(); ++j) {
            if (legend.contains("Type " + (j + 1))) {
                legends[i] = legend.replace("Type " + (j + 1), transactionNames.get(j));
                break;
            }
        }
    }

    for (int i = 0; i < numYCellArray; ++i) {
        double[] xArray = (double[]) xCellArray[i];
        int row = 0, col = 0;
        int xLength = 0;

        runner.eval("yArraySize = size(Ydata{" + (i + 1) + "});");
        runner.eval("yArray = Ydata{" + (i + 1) + "};");
        double[] yArraySize = runner.getVariableDouble("yArraySize");
        double[] yArray = runner.getVariableDouble("yArray");

        xLength = xArray.length;
        row = (int) yArraySize[0];
        col = (int) yArraySize[1];

        for (int c = 0; c < col; ++c) {
            XYSeries series;
            String legend = "";
            int legendIdx = (dataCount >= numLegends) ? numLegends - 1 : dataCount;
            if (legendIdx >= 0) {
                legend = (String) legends[legendIdx];
            }
            if (numLegends == 0) {
                series = new XYSeries("Data " + dataCount + 1);
            } else if (dataCount >= numLegends) {
                series = new XYSeries(legend + (dataCount + 1));
            } else {
                series = new XYSeries(legend);
            }

            for (int r = 0; r < row; ++r) {
                int xRow = (r >= xLength) ? xLength - 1 : r;
                double yValue = yArray[r + c * row];
                // remove negatives
                if (yValue < 0) {
                    yValue = 0;
                }
                series.add(xArray[xRow], yValue);
            }
            XYdataSet.addSeries(series);
            ++dataCount;
        }
    }

    JFreeChart chart = ChartFactory.createXYLineChart(title, xLabel, yLabel, XYdataSet);
    boolean isTransactionSampleChart = false;
    for (String name : DBSeerGUI.transactionSampleCharts) {
        if (name.equals(chartName)) {
            isTransactionSampleChart = true;
            break;
        }
    }

    // Renderer to highlight selected normal or outlier points.
    if (isTransactionSampleChart) {
        chart.getXYPlot().setRenderer(new DBSeerXYLineAndShapeRenderer(timestamp, dataset));
    } else {
        chart.getXYPlot().setRenderer(new DBSeerXYLineAndShapeRenderer());

    }

    chart.getXYPlot().getDomainAxis().setUpperMargin(0);

    return chart;
}

From source file:dbseer.gui.chart.DBSeerChartFactory.java

public static JFreeChart createPredictionBarChart(PredictionCenter center) throws Exception {
    StatisticalPackageRunner runner = DBSeerGUI.runner;

    String title = runner.getVariableString("title");
    Object[] legends = (Object[]) runner.getVariableCell("legends");
    Object[] xCellArray = (Object[]) runner.getVariableCell("Xdata");
    Object[] yCellArray = (Object[]) runner.getVariableCell("Ydata");
    String xLabel = runner.getVariableString("Xlabel");
    String yLabel = runner.getVariableString("Ylabel");

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    int numLegends = legends.length;
    int numXCellArray = xCellArray.length;
    int numYCellArray = yCellArray.length;
    int dataCount = 0;

    final java.util.List<String> transactionNames = center.getTrainConfig().getDataset(0)
            .getTransactionTypeNames();// w w  w .j  a v a2s  .com
    for (int i = 0; i < numLegends; ++i) {
        String legend = (String) legends[i];
        for (int j = 0; j < transactionNames.size(); ++j) {
            if (legend.contains("Type " + (j + 1))) {
                legends[i] = legend.replace("Type " + (j + 1), transactionNames.get(j));
                break;
            }
        }
    }
    for (int j = 0; j < transactionNames.size(); ++j) {
        if (xLabel.contains("Type " + (j + 1))) {
            xLabel = xLabel.replace("Type " + (j + 1), transactionNames.get(j));
            break;
        }
    }
    for (int j = 0; j < transactionNames.size(); ++j) {
        if (yLabel.contains("Type " + (j + 1))) {
            yLabel = yLabel.replace("Type " + (j + 1), transactionNames.get(j));
            break;
        }
    }

    for (int i = 0; i < numYCellArray; ++i) {
        runner.eval("yArraySize = size(Ydata{" + (i + 1) + "});");
        runner.eval("yArray = Ydata{" + (i + 1) + "};");
        double[] yArraySize = runner.getVariableDouble("yArraySize");
        double[] yArray = runner.getVariableDouble("yArray");

        int row = (int) yArraySize[0];
        int col = (int) yArraySize[1];

        for (int c = 0; c < col; ++c) {
            String category = "";
            int legendIdx = (dataCount >= numLegends) ? numLegends - 1 : dataCount;
            String legend = (String) legends[legendIdx];
            if (numLegends == 0) {
                category = "Data " + dataCount + 1;
            } else if (dataCount >= numLegends) {
                category = legend + (dataCount + 1);
            } else {
                category = legend;
            }

            for (int r = 0; r < row; ++r) {
                double yValue = yArray[r + c * row];
                // remove negatives.
                if (yValue < 0 || yValue == Double.NaN || yValue == Double.POSITIVE_INFINITY
                        || yValue == Double.NEGATIVE_INFINITY) {
                    yValue = 0.0;
                }

                dataset.addValue(yValue, category, "");
            }
            ++dataCount;
        }
    }

    JFreeChart chart = ChartFactory.createBarChart(title, xLabel, yLabel, dataset);

    return chart;
}

From source file:dbseer.gui.chart.DBSeerChartFactory.java

public static JFreeChart createXYLinePredictionChart(PredictionCenter center) throws Exception {
    StatisticalPackageRunner runner = DBSeerGUI.runner;

    String title = runner.getVariableString("title");
    Object[] legends = (Object[]) runner.getVariableCell("legends");
    Object[] xCellArray = (Object[]) runner.getVariableCell("Xdata");
    Object[] yCellArray = (Object[]) runner.getVariableCell("Ydata");
    String xLabel = runner.getVariableString("Xlabel");
    String yLabel = runner.getVariableString("Ylabel");

    XYSeriesCollection dataSet = new XYSeriesCollection();

    int numLegends = legends.length;
    int numXCellArray = xCellArray.length;
    int numYCellArray = yCellArray.length;
    int dataCount = 0;

    if (numXCellArray != numYCellArray) {
        JOptionPane.showMessageDialog(null, "The number of X dataset and Y dataset does not match.",
                "The number of X dataset and Y dataset does not match.", JOptionPane.ERROR_MESSAGE);
        System.out.println(numXCellArray + " : " + numYCellArray);
        return null;
    }/*from  w w  w. j  ava 2  s  .com*/

    final java.util.List<String> transactionNames = center.getTrainConfig().getDataset(0)
            .getTransactionTypeNames();
    for (int i = 0; i < numLegends; ++i) {
        String legend = (String) legends[i];
        for (int j = 0; j < transactionNames.size(); ++j) {
            if (legend.contains("Type " + (j + 1))) {
                legends[i] = legend.replace("Type " + (j + 1), transactionNames.get(j));
                break;
            }
        }
    }
    for (int j = 0; j < transactionNames.size(); ++j) {
        if (xLabel.contains("Type " + (j + 1))) {
            xLabel = xLabel.replace("Type " + (j + 1), transactionNames.get(j));
            break;
        }
    }
    for (int j = 0; j < transactionNames.size(); ++j) {
        if (yLabel.contains("Type " + (j + 1))) {
            yLabel = yLabel.replace("Type " + (j + 1), transactionNames.get(j));
            break;
        }
    }

    for (int i = 0; i < numYCellArray; ++i) {
        double[] xArray = (double[]) xCellArray[i];
        runner.eval("yArraySize = size(Ydata{" + (i + 1) + "});");
        runner.eval("yArray = Ydata{" + (i + 1) + "};");
        double[] yArraySize = runner.getVariableDouble("yArraySize");
        double[] yArray = runner.getVariableDouble("yArray");

        int xLength = xArray.length;
        int row = (int) yArraySize[0];
        int col = (int) yArraySize[1];

        for (int c = 0; c < col; ++c) {
            XYSeries series;
            int legendIdx = (dataCount >= numLegends) ? numLegends - 1 : dataCount;
            String legend = (String) legends[legendIdx];
            if (numLegends == 0) {
                series = new XYSeries("Data " + dataCount + 1);
            } else if (dataCount >= numLegends) {
                series = new XYSeries(legend + (dataCount + 1));
            } else {
                series = new XYSeries(legend);
            }

            for (int r = 0; r < row; ++r) {
                int xRow = (r >= xLength) ? xLength - 1 : r;
                double yValue = yArray[r + c * row];
                // remove negatives & NaN & infs.
                if (yValue < 0 || yValue == Double.NaN || yValue == Double.POSITIVE_INFINITY
                        || yValue == Double.NEGATIVE_INFINITY) {
                    yValue = 0.0;
                }
                series.add(xArray[xRow], yValue);
            }
            dataSet.addSeries(series);
            ++dataCount;
        }
    }

    JFreeChart chart = ChartFactory.createXYLineChart(title, xLabel, yLabel, dataSet);

    // change 'predicted' data to have dotted lines.
    BasicStroke dashStroke = toStroke(STYLE_DASH);
    BasicStroke dotStroke = toStroke(STYLE_DOT);
    BasicStroke lineStroke = toStroke(STYLE_LINE);
    for (int i = 0; i < dataSet.getSeriesCount(); ++i) {
        String legend = (String) dataSet.getSeriesKey(i);
        XYPlot plot = chart.getXYPlot();
        XYItemRenderer renderer = plot.getRenderer();
        if (legend.contains("predicted") || legend.contains("Predicted")) {
            renderer.setSeriesStroke(i, dotStroke);
        } else {
            renderer.setSeriesStroke(i, lineStroke);
        }
    }

    return chart;
}

From source file:dbseer.gui.chart.DBSeerChartFactory.java

public static JTable createErrorTable(PredictionCenter center) throws Exception {
    JTable errorTable = null;//from w  ww .  ja va 2s.c o  m
    DefaultTableModel errorTableModel = null;
    StatisticalPackageRunner runner = DBSeerGUI.runner;

    Object[] maeList = (Object[]) runner.getVariableCell("meanAbsError");
    Object[] mreList = (Object[]) runner.getVariableCell("meanRelError");
    Object[] headers = (Object[]) runner.getVariableCell("errorHeader");

    if (maeList.length > 0 || mreList.length > 0) {
        errorTableModel = new DefaultTableModel() {
            @Override
            public boolean isCellEditable(int row, int column) {
                return false;
            }
        };
        //errorTable = new JTable();
        errorTableModel.addColumn(null, new String[] { "", "MAE", "MRE" }); // first empty column

        final java.util.List<String> transactionNames = center.getTrainConfig().getDataset(0)
                .getTransactionTypeNames();
        for (int i = 0; i < maeList.length; ++i) {
            Object maeObj = maeList[i];
            Object mreObj = mreList[i];

            double[] mae = (double[]) maeObj;
            double[] mre = (double[]) mreObj;

            String header = (String) headers[i];
            for (int j = 0; j < transactionNames.size(); ++j) {
                if (header.contains("Type " + (j + 1))) {
                    headers[i] = header.replace("Type " + (j + 1), transactionNames.get(j));
                    break;
                }
            }

            errorTableModel.addColumn(null,
                    new Object[] { headers[i], String.format("%.3f", mae[0]), String.format("%.3f", mre[0]) });
        }
        errorTable = new JTable(errorTableModel);
    }

    return errorTable;
}

From source file:org.fhcrc.cpl.toolbox.gui.chart.PanelWithLineChart.java

public void addData(java.util.List<? extends Number> xValuesList, java.util.List<? extends Number> yValuesList,
        String dataSetName) {/*from   w w  w. j a v a2  s. c  o  m*/
    double[] xValues = new double[xValuesList.size()];
    double[] yValues = new double[yValuesList.size()];
    for (int i = 0; i < xValues.length; i++) {
        xValues[i] = xValuesList.get(i).doubleValue();
        yValues[i] = yValuesList.get(i).doubleValue();
    }

    addData(xValues, yValues, dataSetName);

}