Example usage for javax.swing JTable validate

List of usage examples for javax.swing JTable validate

Introduction

In this page you can find the example usage for javax.swing JTable validate.

Prototype

public void validate() 

Source Link

Document

Validates this container and all of its subcomponents.

Usage

From source file:mt.listeners.InteractiveRANSAC.java

public void updateRANSAC() {

    negcount = 0;// ww  w .  j  a v  a  2s  . c  o  m
    negtimediff = 0;
    averageshrink = 0;
    catindex = 0;
    negsegments = new ArrayList<Pair<LinearFunction, ArrayList<PointFunctionMatch>>>();
    ArrayList<Rateobject> allrates = new ArrayList<Rateobject>();
    ArrayList<Averagerate> averagerates = new ArrayList<Averagerate>();

    ++updateCount;

    dataset.removeAllSeries();
    this.dataset.addSeries(Tracking.drawPoints(mts, calibrations));

    @SuppressWarnings("unchecked")
    ArrayList<Pair<AbstractFunction2D, ArrayList<PointFunctionMatch>>> segments = Tracking
            .findAllFunctions(points, function, maxError, minInliers, maxDist);

    if (segments == null || segments.size() == 0) {
        --updateCount;
        return;
    }

    // sort the segments according to time HORIZONTAL to each other and the
    // PointFunctionMatches internally
    sort(segments);

    final LinearFunction linear = new LinearFunction();
    int linearcount = 1;
    i = 1;
    segment = 1;
    int count = 0;

    int rescount = 0;
    int catcount = 0;
    double timediff = 0;
    double restimediff = 0;

    double averagegrowth = 0;

    double growthrate = 0;
    double shrinkrate = 0;

    double minstartY = leastStart(segments);

    double minstartX = Double.MAX_VALUE;
    double minendX = Double.MAX_VALUE;
    double catfrequ = 0;
    double resfrequ = 0;
    double lifetime = 0;

    ArrayList<Double> previousendX = new ArrayList<Double>();
    ResultsTable rt = new ResultsTable();
    ResultsTable rtAll = new ResultsTable();

    List<Pair<Float, Float>> starttimerates = new ArrayList<Pair<Float, Float>>();
    List<Pair<Float, Float>> catstarttimerates = new ArrayList<Pair<Float, Float>>();
    for (final Pair<AbstractFunction2D, ArrayList<PointFunctionMatch>> result : segments) {
        if (LinearFunction.slopeFits(result.getB(), linear, minSlope, maxSlope)) {

            final Pair<Double, Double> minMax = Tracking.fromTo(result.getB());

            double startX = minMax.getA();
            double endX = minMax.getB();

            if (startX < minstartX) {

                minstartX = startX;
            }
            if (endX < minendX) {

                minendX = endX;
            }

            Polynomial<?, Point> polynomial = (Polynomial) result.getA();

            dataset.addSeries(
                    Tracking.drawFunction(polynomial, minMax.getA(), minMax.getB(), 0.5, "Segment " + segment));

            if (functionChoice > 0) {
                Tracking.setColor(chart, i, new Color(255, 0, 0));
                Tracking.setDisplayType(chart, i, true, false);
                Tracking.setStroke(chart, i, 0.5f);
                chart.setTitle("Length plot for" + " " + this.inputfiles[row].getName());
            } else {
                Tracking.setColor(chart, i, new Color(0, 128, 0));
                Tracking.setDisplayType(chart, i, true, false);
                Tracking.setStroke(chart, i, 2f);
                chart.setTitle("Length plot for" + " " + this.inputfiles[row].getName());
            }

            ++i;

            if (functionChoice > 0) {

                dataset.addSeries(Tracking.drawFunction(linear, minMax.getA(), minMax.getB(), 0.5,
                        "Linear Segment " + segment));

                Tracking.setColor(chart, i, new Color(0, 128, 0));
                Tracking.setDisplayType(chart, i, true, false);
                Tracking.setStroke(chart, i, 2f);

                ++i;

            }

            double startY = polynomial.predict(startX);
            double linearrate = linear.getCoefficient(1);
            if (linearrate > 0 && startY - minstartY > restolerance && previousendX.size() > 0) {
                rescount++;
                restimediff += -previousendX.get(previousendX.size() - 1) + startX;

            }

            if (linearrate > 0) {

                count++;
                growthrate = linearrate;
                // Ignore last growth event for getting fcat
                if (points.get(points.size() - 1).getW()[0] - endX >= tptolerance)
                    catcount++;
                timediff += endX - startX;
                lifetime = endX - startX;
                averagegrowth += linearrate;
                lifecount.add(new ValuePair<Integer, Double>(count, lifetime));

                Rateobject velocity = new Rateobject(linearrate * calibrations[0] / calibrations[2],
                        (int) (startX * calibrations[2]), (int) (endX * calibrations[2]));
                allrates.add(velocity);
                rt.incrementCounter();
                rt.addValue("Start time", startX * calibrations[2]);
                rt.addValue("End time", endX * calibrations[2]);
                rt.addValue("Growth velocity", linearrate * calibrations[0] / calibrations[2]);

                Pair<Float, Float> startrate = new ValuePair<Float, Float>((float) startX, (float) linearrate);

                starttimerates.add(startrate);
            }
            if (linearrate < 0) {

                negcount++;
                negtimediff += endX - startX;

                shrinkrate = linearrate;
                averageshrink += linearrate;

                rt.incrementCounter();
                rt.addValue("Start time", startX * calibrations[2]);
                rt.addValue("End time", endX * calibrations[2]);
                rt.addValue("Growth velocity", linearrate * calibrations[0] / calibrations[2]);

                Pair<Float, Float> startrate = new ValuePair<Float, Float>((float) startX, (float) linearrate);

                starttimerates.add(startrate);

            }
            if (linearrate > 0) {
                previousendX.add(endX);

            }
            dataset.addSeries(Tracking.drawPoints(Tracking.toPairList(result.getB()), calibrations,
                    "Inliers " + segment));

            Tracking.setColor(chart, i, new Color(255, 0, 0));
            Tracking.setDisplayType(chart, i, false, true);
            Tracking.setSmallUpTriangleShape(chart, i);

            ++i;
            ++segment;

        } else {
            System.out.println("Removed segment because slope is wrong.");

        }

    }

    if (this.detectCatastrophe) {

        if (segments.size() < 2) {

            System.out.println("Only two points found");

        } else {
            for (int catastrophy = 0; catastrophy < segments.size() - 1; ++catastrophy) {
                final Pair<AbstractFunction2D, ArrayList<PointFunctionMatch>> start = segments.get(catastrophy);
                final Pair<AbstractFunction2D, ArrayList<PointFunctionMatch>> end = segments
                        .get(catastrophy + 1);

                double tStart = start.getB().get(start.getB().size() - 1).getP1().getL()[0];
                double tEnd = end.getB().get(0).getP1().getL()[0];

                final double lStart = start.getB().get(start.getB().size() - 1).getP1().getL()[1];
                final double lEnd = end.getB().get(0).getP1().getL()[1];

                final ArrayList<Point> catastropyPoints = new ArrayList<Point>();

                for (final Point p : points)
                    if (p.getL()[0] >= tStart && p.getL()[0] <= tEnd)
                        catastropyPoints.add(p);

                if (catastropyPoints.size() > 2) {
                    if (Math.abs(lStart - lEnd) >= this.minDistanceCatastrophe) {
                        // maximally 1.1 timepoints between points on a line
                        final Pair<LinearFunction, ArrayList<PointFunctionMatch>> fit = Tracking
                                .findFunction(catastropyPoints, new LinearFunction(), 0.75, 3, 1.1);

                        if (fit != null) {
                            if (fit.getA().getM() < 0) {
                                sort(fit);
                                negsegments.add(fit);
                                double minY = Math.min(fit.getB().get(0).getP1().getL()[1],
                                        fit.getB().get(fit.getB().size() - 1).getP1().getL()[1]);
                                double maxY = Math.max(fit.getB().get(0).getP1().getL()[1],
                                        fit.getB().get(fit.getB().size() - 1).getP1().getL()[1]);

                                final Pair<Double, Double> minMax = Tracking.fromTo(fit.getB());

                                double startX = minMax.getA();
                                double endX = minMax.getB();

                                double linearrate = fit.getA().getCoefficient(1);

                                if (linearrate < 0) {
                                    dataset.addSeries(Tracking.drawFunction((Polynomial) fit.getA(),
                                            minMax.getA() - 1, minMax.getB() + 1, 0.1, minY - 2.5, maxY + 2.5,
                                            "CRansac " + catastrophy));
                                    negcount++;
                                    negtimediff += endX - startX;

                                    shrinkrate = linearrate;
                                    averageshrink += linearrate;

                                    rt.incrementCounter();
                                    rt.addValue("Start time", startX * calibrations[2]);
                                    rt.addValue("End time", endX * calibrations[2]);
                                    rt.addValue("Growth velocity",
                                            linearrate * calibrations[0] / calibrations[2]);

                                    Pair<Float, Float> startrate = new ValuePair<Float, Float>((float) startX,
                                            (float) linearrate);

                                    starttimerates.add(startrate);

                                    Rateobject velocity = new Rateobject(
                                            linearrate * calibrations[0] / calibrations[2],
                                            (int) (startX * calibrations[2]), (int) (endX * calibrations[2]));
                                    allrates.add(velocity);
                                    Tracking.setColor(chart, i, new Color(0, 0, 255));
                                    Tracking.setDisplayType(chart, i, true, false);
                                    Tracking.setStroke(chart, i, 2f);

                                    ++i;
                                    dataset.addSeries(Tracking.drawPoints(Tracking.toPairList(fit.getB()),
                                            calibrations, "C(inl) " + catastrophy));

                                    Tracking.setColor(chart, i, new Color(0, 0, 255));
                                    Tracking.setDisplayType(chart, i, false, true);
                                    Tracking.setShape(chart, i, ShapeUtils.createDownTriangle(4f));

                                    ++i;
                                }
                            }
                        }

                    }

                    else {
                        System.out.println("Catastrophy height not sufficient " + Math.abs(lStart - lEnd)
                                + " < " + this.minDistanceCatastrophe);

                    }
                }

            }

        }
    }

    if (this.detectmanualCatastrophe) {

        catindex++;
        catstarttimerates = ManualCat(segments, allrates, shrinkrate, rt);

    }

    if (count > 0)
        averagegrowth /= count;

    if (catcount > 0)

        catfrequ = catcount / (timediff * calibrations[2]);

    if (rescount > 0)

        resfrequ = rescount / (restimediff * calibrations[2]);

    if (negcount > 0)
        averageshrink /= negcount;

    if (resfrequ < 0)
        resfrequ = 0;

    rt.show("Rates(real units) for" + " " + this.inputfile.getName());
    averageshrink *= calibrations[0] / calibrations[2];
    averagegrowth *= calibrations[0] / calibrations[2];
    rtAll.incrementCounter();
    rtAll.addValue("Average Growth", averagegrowth);
    rtAll.addValue("Growth events", count);
    rtAll.addValue("Average Shrink", averageshrink);
    rtAll.addValue("Shrink events", negcount);
    rtAll.addValue("Catastrophe Frequency", catfrequ);
    rtAll.addValue("Catastrophe events", catcount);
    rtAll.addValue("Rescue Frequency", resfrequ);
    rtAll.addValue("Rescue events", rescount);
    // rtAll.show("Average Rates and Frequencies (real units)");

    starttimerates.addAll(catstarttimerates);
    sortTime(starttimerates);

    for (int index = 0; index < starttimerates.size() - 1; ++index) {

        int prevsign = (int) Math.signum(starttimerates.get(index).getB());
        int nextsign = (int) Math.signum(starttimerates.get(index + 1).getB());

        if (nextsign == prevsign)
            wrongfile = true;
        else
            wrongfile = false;

        wrongfileindex = new ValuePair<Boolean, Integer>(wrongfile, row);
        wrongfileindexlist.put(row, wrongfile);
    }
    table.getModel().setValueAt(new DecimalFormat("#.###").format(averagegrowth), row, 1);
    table.getModel().setValueAt(new DecimalFormat("#.###").format(averageshrink), row, 2);
    table.getModel().setValueAt(new DecimalFormat("#").format(count), row, 3);
    table.getModel().setValueAt(new DecimalFormat("#").format(negcount), row, 4);
    table.getModel().setValueAt(new DecimalFormat("#.###").format(catfrequ), row, 5);
    table.getModel().setValueAt(new DecimalFormat("#.###").format(resfrequ), row, 6);
    if (wrongfileindexlist.get(row) != null) {
        table.getModel().setValueAt(wrongfileindexlist.get(row).toString(), row, 7);
    }
    int size = 100;
    table.getColumnModel().getColumn(0).setPreferredWidth(size);
    table.getColumnModel().getColumn(1).setPreferredWidth(size);
    table.getColumnModel().getColumn(2).setPreferredWidth(size);
    table.getColumnModel().getColumn(3).setPreferredWidth(size);
    table.getColumnModel().getColumn(4).setPreferredWidth(size);
    table.getColumnModel().getColumn(5).setPreferredWidth(size);
    table.getColumnModel().getColumn(6).setPreferredWidth(size);
    table.getColumnModel().getColumn(7).setPreferredWidth(size);
    table.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() {
        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                boolean hasFocus, int rowA, int col) {

            super.getTableCellRendererComponent(table, value, isSelected, hasFocus, rowA, col);

            String status = (String) table.getModel().getValueAt(row, 7);
            if ("true".equals(status)) {
                setBackground(Color.GRAY);

            } else {
                setBackground(Color.GRAY);
            }
            return this;
        }
    });
    table.validate();

    scrollPane.validate();

    Averagerate avrate = new Averagerate(averagegrowth, averageshrink, catfrequ, resfrequ, count, negcount,
            catcount, rescount, this.inputfile);
    averagerates.add(avrate);
    Compilepositiverates.put(row, allrates);

    Compileaverage.put(row, avrate);

    --updateCount;

}