Example usage for org.apache.commons.collections15.bag TreeBag TreeBag

List of usage examples for org.apache.commons.collections15.bag TreeBag TreeBag

Introduction

In this page you can find the example usage for org.apache.commons.collections15.bag TreeBag TreeBag.

Prototype

public TreeBag() 

Source Link

Document

Constructs an empty TreeBag.

Usage

From source file:com.diversityarrays.kdxplore.scatterplot.ScatterPlotPanel.java

public ScatterPlotPanel(PlotInfoProvider infoProvider, VisualisationToolId<?> vtoolId, SelectedValueStore svs,
        String title, VisToolData data, Supplier<TraitColorProvider> colorProviderFactory,
        SuppressionHandler sh) {/*  w  ww  .  java 2  s . co m*/
    super(title, vtoolId, svs, nextId++, data.traitInstances, data.context.getTrial(), sh);

    this.plotInfoProvider = infoProvider;

    if (data.plotSpecimensToGraph == null) {
        plotSpecimens = new ArrayList<>();
        VisToolUtil.collectPlotSpecimens(plotInfoProvider.getPlots(), new Consumer<PlotOrSpecimen>() {
            @Override
            public void accept(PlotOrSpecimen pos) {
                plotSpecimens.add(pos);
            }
        });
    } else {
        plotSpecimens = data.plotSpecimensToGraph;
    }

    List<List<Comparable<?>>> instanceValuesList = new ArrayList<>();

    this.colorProviderFactory = colorProviderFactory;

    Function<TraitInstance, List<KdxSample>> sampleProvider = new Function<TraitInstance, List<KdxSample>>() {
        @Override
        public List<KdxSample> apply(TraitInstance ti) {
            return infoProvider.getSampleMeasurements(ti);
        }
    };
    tivrByTi = VisToolUtil.buildTraitInstanceValueRetrieverMap(trial, traitInstances, sampleProvider);

    int plotLength = instanceValuesList.size();
    if (plotLength < 3) {
        plotLength = 3;
    }

    xInstance = traitInstances.get(0);
    TraitInstance firstValueInstance = null;

    for (int i = 1; i < traitInstances.size(); i++) {
        TraitInstance ti = traitInstances.get(i);
        if (firstValueInstance == null) {
            firstValueInstance = ti;
        }
        valueInstances.add(ti);
        valueInstanceByTraitIdAndNumber.put(InstanceIdentifierUtil.getInstanceIdentifier(ti), ti);
    }

    xAxisName = traitNameStyle.makeTraitInstanceName(xInstance);

    if (traitInstances.size() == 2) {
        yAxisName = traitNameStyle.makeTraitInstanceName(firstValueInstance);
    } else {
        yAxisName = "Sample Measurement Value";
    }

    chartPanel.addChartMouseListener(chartMouseListener);

    Bag<String> missingOrBad = new TreeBag<String>();
    Bag<String> suppressed = new TreeBag<String>();

    generateChart(true, missingOrBad, suppressed);

    ChangeListener listener = new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            if (!stillChanging) {
                clearExternallySelectedPlots();

                setXYValues();
                drawRectangle();
                if (mouseDownPoint != null && mouseUpPoint != null) {
                    buildMinMaxPoints();
                    setSelectedTraitAndMeasurements();
                }
            }
        }
    };

    minxSpinner.addChangeListener(listener);
    minySpinner.addChangeListener(listener);
    maxxSpinner.addChangeListener(listener);
    maxySpinner.addChangeListener(listener);

    stillChanging = true;
    minxModel.setValue(dataxMin);
    maxxModel.setValue(dataxMax);

    minyModel.setValue(datayMin);
    maxyModel.setValue(datayMax);

    minxModel.setMinimum(dataxMin);
    minxModel.setMaximum(dataxMax);
    minyModel.setMinimum(datayMin);
    minyModel.setMaximum(datayMax);

    maxxModel.setMinimum(dataxMin);
    maxxModel.setMaximum(dataxMax);
    maxyModel.setMinimum(datayMin);
    maxyModel.setMaximum(datayMax);
    stillChanging = false;

    Box hbox = Box.createHorizontalBox();
    hbox.add(syncedOption);

    addSpinners(hbox, minxSpinner, minySpinner);
    hbox.add(new JLabel(" " + Msg.LABEL_MIN_TO_MAX_SEPARATOR() + " ")); //$NON-NLS-1$ //$NON-NLS-2$
    addSpinners(hbox, maxxSpinner, maxySpinner);

    List<TraitInstance> curationControlInstances = traitInstances;
    curationControlInstances.remove(xInstance);

    curationControls = new CurationControls(true, // askAboutValueForUnscored
            suppressionHandler, selectedValueStore,
            //              plotInfoProvider, 
            toolPanelId, null, traitNameStyle, curationControlInstances);

    reportTextArea = new JTextArea();
    reportTextArea.setEditable(false);

    tabMessages = Msg.TAB_MESSAGES();
    tabCuration = Msg.TAB_CURATION();
    tabbedPane.addTab(tabMessages, new JScrollPane(reportTextArea));
    tabbedPane.addTab(tabCuration, curationControls);

    splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, tabbedPane, chartPanel);

    splitPane.setOneTouchExpandable(true);
    splitPane.setResizeWeight(0.0);
    add(splitPane, BorderLayout.CENTER);
    add(hbox, BorderLayout.SOUTH);

    splitPane.repaint(); // TODO why is this here?

    String msg = VisToolData.createReportText(missingOrBad, suppressed);
    if (Check.isEmpty(msg)) {
        tabbedPane.setSelectedIndex(tabbedPane.indexOfTab(tabCuration));
    } else {
        reportTextArea.setText(msg);
        tabbedPane.setSelectedIndex(tabbedPane.indexOfTab(tabMessages));
    }

    setPreferredSize(new Dimension(600, 500));
}

From source file:com.diversityarrays.kdxplore.boxplot.BoxPlotPanel.java

private void generateGraph(Why why) {

    overallMinMax[0] = null;/*w  ww .  ja  va 2s  . co m*/
    overallMinMax[1] = null;

    if (chartPanel != null) {
        for (EventListener cml : chartPanel.getListeners(ChartMouseListener.class)) {
            chartPanel.removeChartMouseListener((ChartMouseListener) cml);
        }
    }

    Bag<String> missingOrBad = new TreeBag<>();
    Bag<String> suppressed = new TreeBag<>();

    final BoxAndWhiskerCategoryDataset dataset = createSampleDataSet(missingOrBad, suppressed, overallMinMax);

    final CategoryAxis xAxis = new CategoryAxis(Msg.AXIS_LABEL_TRAIT_INSTANCE());
    final NumberAxis yAxis = new NumberAxis(Msg.AXIS_LABEL_SAMPLE_VALUE());
    yAxis.setAutoRangeIncludesZero(false);
    final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setMaximumBarWidth(.35);
    //        renderer.setItemMargin(.1);
    renderer.setFillBox(true);
    renderer.setUseOutlinePaintForWhiskers(true);
    renderer.setOutliersVisible(showOutliers.isSelected());
    renderer.setMeanVisible(showMean.isSelected());
    renderer.setMedianVisible(showMedian.isSelected());
    //        renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
    CategoryPlot boxplot = new CategoryPlot(dataset, xAxis, yAxis, renderer);

    chart = new JFreeChart(getTitle(), new Font(FONT_NAME_SANS_SERIF, Font.BOLD, 14), boxplot, true);
    //        dataMin = ((CategoryPlot) chart.getPlot()).getRangeAxis().getLowerBound();
    //        dataMax = ((CategoryPlot) chart.getPlot()).getRangeAxis().getUpperBound();

    CategoryItemRenderer catr = ((CategoryPlot) chart.getPlot()).getRendererForDataset(dataset);
    TraitColorProvider traitColorProvider = colorProviderFactory.get();
    for (TraitInstance ti : traitInstances) {
        ColorPair colorPair = traitColorProvider.getTraitInstanceColor(ti);
        if (colorPair != null) {

            String validName = traitNameStyle.makeTraitInstanceName(ti);

            if (seriesCountByTraitName.get(validName) != null) {
                catr.setSeriesPaint(seriesCountByTraitName.get(validName), colorPair.getBackground());
            }
        }
    }
    //      ((CategoryPlot) chart.getPlot()).setRenderer(catr);

    chartPanel = new KDXploreChartPanel(chart);

    chartPanel.addChartMouseListener(chartMouseListener);

    // TODO check if we should be checking syncedOption
    if (marker != null && syncedOption.getSyncWhat().isSync()) {
        ((CategoryPlot) getChart().getPlot()).addRangeMarker(marker);
        //         curationControls.setSyncedState(true);
    }

    if (why.needsReport()) {
        String msg = VisToolData.createReportText(missingOrBad, suppressed);
        if (!Check.isEmpty(msg)) {
            if (why.needsLeadingNewline()) {
                reportTextArea.append("\n");
            }
            reportTextArea.append("==== ");
            reportTextArea.append(why.displayValue);
            reportTextArea.append("\n");
            reportTextArea.append(msg);
        }
    }

    splitPane.setRightComponent(chartPanel);

    this.updateUI();
    this.repaint();
}

From source file:com.diversityarrays.kdxplore.scatterplot.ScatterPlotPanel.java

protected void redoGenerateChart(String why, boolean recreateDataSet) {
    Bag<String> missingOrBad = new TreeBag<String>();
    Bag<String> suppressed = new TreeBag<String>();

    generateChart(recreateDataSet, missingOrBad, suppressed);

    String msg = VisToolData.createReportText(missingOrBad, suppressed);
    if (!Check.isEmpty(msg)) {
        if (!Check.isEmpty(why)) {
            reportTextArea.append("\n===== " + why);
            reportTextArea.append("\n");
        }//from www  .  j a  v  a  2  s  .  c o m
        reportTextArea.append(msg);
        tabbedPane.setSelectedIndex(tabbedPane.indexOfTab(tabMessages));
    }
}