Example usage for javax.swing JTable setDefaultRenderer

List of usage examples for javax.swing JTable setDefaultRenderer

Introduction

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

Prototype

public void setDefaultRenderer(Class<?> columnClass, TableCellRenderer renderer) 

Source Link

Document

Sets a default cell renderer to be used if no renderer has been set in a TableColumn.

Usage

From source file:TableDialogEditDemo.java

public TableDialogEditDemo() {
    super(new GridLayout(1, 0));

    JTable table = new JTable(new MyTableModel());
    table.setPreferredScrollableViewportSize(new Dimension(500, 70));

    //Create the scroll pane and add the table to it.
    JScrollPane scrollPane = new JScrollPane(table);

    //Set up renderer and editor for the Favorite Color column.
    table.setDefaultRenderer(Color.class, new ColorRenderer(true));
    table.setDefaultEditor(Color.class, new ColorEditor());

    //Add the scroll pane to this panel.
    add(scrollPane);/*from   w  ww  . j av a  2 s .com*/
}

From source file:org.drugis.addis.gui.builder.NetworkMetaAnalysisView.java

/**
 * Make table of results (Cipriani et al., Lancet(2009), fig. 3, pp752).
 * @param mtc Model for which to display results.
 * @return A TablePanel//from   www.jav  a 2  s .  co  m
 */
private TablePanel createNetworkTablePanel(final MTCModelWrapper<TreatmentDefinition> mtc) {
    NetworkRelativeEffectTableModel tableModel = NetworkRelativeEffectTableModel.build(d_pm.getAlternatives(),
            mtc);
    final JTable table = new JTable(tableModel);
    final NetworkRelativeEffectTableCellRenderer renderer = new NetworkRelativeEffectTableCellRenderer(
            !d_pm.isContinuous());
    table.setDefaultRenderer(Object.class, renderer);
    table.setTableHeader(null);

    table.addMouseListener(treatmentCategorizationListener(renderer));

    setColumnWidths(table);
    TableCopyHandler.registerCopyAction(table);
    return new TablePanel(table);
}

From source file:org.esa.snap.rcp.statistics.StatisticsPanel.java

private JPanel createStatPanel(Stx stx, final Mask mask) {
    final Histogram histogram = stx.getHistogram();

    XIntervalSeries histogramSeries = new XIntervalSeries("Histogram");
    int[] bins = histogram.getBins(0);
    for (int j = 0; j < bins.length; j++) {
        histogramSeries.add(histogram.getBinLowValue(0, j), histogram.getBinLowValue(0, j),
                j < bins.length - 1 ? histogram.getBinLowValue(0, j + 1) : histogram.getHighValue(0), bins[j]);
    }//from   www.j a v a2 s . com
    ChartPanel histogramPanel = createChartPanel(histogramSeries, "Value", "#Pixels", new Color(0, 0, 127));

    XIntervalSeries percentileSeries = new XIntervalSeries("Percentile");
    percentileSeries.add(0, 0, 1, histogram.getLowValue(0));
    for (int j = 1; j < 99; j++) {
        percentileSeries.add(j, j, j + 1, histogram.getPTileThreshold(j / 100.0)[0]);
    }
    percentileSeries.add(99, 99, 100, histogram.getHighValue(0));

    ChartPanel percentilePanel = createChartPanel(percentileSeries, "Percentile (%)", "Value Threshold",
            new Color(127, 0, 0));

    Object[][] tableData = new Object[][] { new Object[] { "#Pixels total:", histogram.getTotals()[0] },
            new Object[] { "Minimum:", stx.getMinimum() }, new Object[] { "Maximum:", stx.getMaximum() },
            new Object[] { "Mean:", stx.getMean() }, new Object[] { "Sigma:", stx.getStandardDeviation() },
            new Object[] { "Median:", stx.getMedian() },
            new Object[] { "Coef Variation:", stx.getCoefficientOfVariation() },
            new Object[] { "ENL:", stx.getEquivalentNumberOfLooks() },
            new Object[] { "P75 threshold:", histogram.getPTileThreshold(0.75)[0] },
            new Object[] { "P80 threshold:", histogram.getPTileThreshold(0.80)[0] },
            new Object[] { "P85 threshold:", histogram.getPTileThreshold(0.85)[0] },
            new Object[] { "P90 threshold:", histogram.getPTileThreshold(0.90)[0] },
            new Object[] { "Max error:", getBinSize(histogram) }, };

    JPanel plotContainerPanel = new JPanel(new GridLayout(1, 2));
    plotContainerPanel.add(histogramPanel);
    plotContainerPanel.add(percentilePanel);

    TableModel tableModel = new DefaultTableModel(tableData, new String[] { "Name", "Value" }) {
        @Override
        public Class<?> getColumnClass(int columnIndex) {
            return columnIndex == 0 ? String.class : Number.class;
        }

        @Override
        public boolean isCellEditable(int row, int column) {
            return false;
        }
    };

    final JTable table = new JTable(tableModel);
    table.setDefaultRenderer(Number.class, new DefaultTableCellRenderer() {
        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                boolean hasFocus, int row, int column) {
            final Component label = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row,
                    column);
            if (value instanceof Float || value instanceof Double) {
                setHorizontalTextPosition(RIGHT);
                setText(getFormattedValue((Number) value));
            }
            return label;
        }

        private String getFormattedValue(Number value) {
            if (value.doubleValue() < 0.001 && value.doubleValue() > -0.001 && value.doubleValue() != 0.0) {
                return new DecimalFormat("0.####E0").format(value.doubleValue());
            }
            return String.format("%.4f", value.doubleValue());
        }
    });
    table.addMouseListener(popupHandler);

    JPanel textContainerPanel = new JPanel(new BorderLayout(2, 2));
    textContainerPanel.setBackground(Color.WHITE);
    textContainerPanel.add(table, BorderLayout.CENTER);

    JPanel statPanel = new JPanel(new BorderLayout(4, 4));
    statPanel.setBorder(new EmptyBorder(10, 2, 10, 2));
    statPanel.setBackground(Color.WHITE);
    statPanel.add(new JLabel(getSubPanelTitle(mask)), BorderLayout.NORTH);
    statPanel.add(textContainerPanel, BorderLayout.WEST);
    statPanel.add(plotContainerPanel, BorderLayout.CENTER);

    return statPanel;
}

From source file:fll.subjective.SubjectiveFrame.java

private void createSubjectiveTable(final JTabbedPane tabbedPane, final ScoreCategory subjectiveCategory) {
    final SubjectiveTableModel tableModel = new SubjectiveTableModel(_scoreDocument, subjectiveCategory,
            _schedule, _scheduleColumnMappings);
    final JTable table = new JTable(tableModel);
    table.setDefaultRenderer(Date.class, DateRenderer.INSTANCE);

    // Make grid lines black (needed for Mac)
    table.setGridColor(Color.BLACK);

    // auto table sorter
    table.setAutoCreateRowSorter(true);/*from  w w  w .j ava  2s .co  m*/

    final String title = subjectiveCategory.getTitle();
    _tables.put(title, table);
    final JScrollPane tableScroller = new JScrollPane(table);
    tableScroller.setPreferredSize(new Dimension(640, 480));
    tabbedPane.addTab(title, tableScroller);

    table.setSelectionBackground(Color.YELLOW);

    setupTabReturnBehavior(table);

    int goalIndex = 0;
    for (final AbstractGoal goal : subjectiveCategory.getGoals()) {
        final TableColumn column = table.getColumnModel()
                .getColumn(goalIndex + tableModel.getNumColumnsLeftOfScores());
        if (goal.isEnumerated()) {
            final Vector<String> posValues = new Vector<String>();
            posValues.add("");
            for (final EnumeratedValue posValue : goal.getSortedValues()) {
                posValues.add(posValue.getTitle());
            }

            column.setCellEditor(new DefaultCellEditor(new JComboBox<String>(posValues)));
        } else {
            final JTextField editor = new SelectTextField();
            column.setCellEditor(new DefaultCellEditor(editor));
        }
        ++goalIndex;
    }
}

From source file:coolmap.application.widget.impl.WidgetUserGroup.java

private void init() {

    table.getTableHeader().setReorderingAllowed(false);
    table.setAutoCreateRowSorter(true);/*from   w  w w  .  j a va2  s  . com*/
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

    table.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() {

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                boolean hasFocus, int row, int column) {
            JLabel label = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row,
                    column);
            if (isSelected) {
                return label;
            }

            if (column == 1) {
                try {
                    label.setBackground(
                            nodeColor.get(table.getModel().getValueAt(table.convertRowIndexToModel(row), 0)));
                } catch (Exception e) {

                }
            } else {
                label.setBackground(UI.colorWhite);
            }

            return label;
        }

    });
    //Need a search box as well.

    //
    getContentPane().setLayout(new BorderLayout());

    //
    getContentPane().add(new JScrollPane(table), BorderLayout.CENTER);
    JToolBar t = new JToolBar();
    getContentPane().add(t, BorderLayout.NORTH);
    t.setFloatable(false);

    try {
        //also add an action to add group nodes
        JMenuItem item = new JMenuItem("selected row nodes");
        item.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {

                CoolMapObject o = CoolMapMaster.getActiveCoolMapObject();
                if (o == null) {
                    return;
                }

                ArrayList<Range<Integer>> selected = o.getCoolMapView().getSelectedRows();
                ArrayList<VNode> selectedNodes = new ArrayList<>();

                for (Range<Integer> r : selected) {
                    for (int i = r.lowerEndpoint(); i < r.upperEndpoint(); i++) {
                        selectedNodes.add(o.getViewNodeRow(i));
                    }
                }

                createNewGroup(selectedNodes);

                //create a group
            }
        });
        WidgetMaster.getViewport().addPopupMenuItem("Create group", item, false);

        item = new JMenuItem("selected column nodes");
        item.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {

                CoolMapObject o = CoolMapMaster.getActiveCoolMapObject();
                if (o == null) {
                    return;
                }

                ArrayList<Range<Integer>> selected = o.getCoolMapView().getSelectedColumns();
                ArrayList<VNode> selectedNodes = new ArrayList<>();

                for (Range<Integer> r : selected) {
                    for (int i = r.lowerEndpoint(); i < r.upperEndpoint(); i++) {
                        selectedNodes.add(o.getViewNodeColumn(i));
                    }
                }

                createNewGroup(selectedNodes);

            }
        });
        WidgetMaster.getViewport().addPopupMenuItem("Create group", item, false);
    } catch (Exception e) {
        //
        //Error handling.
    }

}

From source file:com.diversityarrays.kdxplore.trials.SampleGroupViewer.java

private SampleGroupViewer(String title, KdxploreDatabase kdxdb, Trial trial, SampleGroup sampleGroup) {
    super(new BorderLayout());

    this.title = title;
    //        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    this.kdxdb = kdxdb;
    this.trial = trial;
    this.sampleGroup = sampleGroup;

    initialise();/*from  w  w  w  . ja v  a 2 s .  co  m*/
    if (plotInfoByPlotId.isEmpty()) {
        add(new JLabel("No Plots available"), BorderLayout.CENTER);
    } else {
        tiChoiceTableModel = new TraitInstanceChoiceTableModel();
        JTable tiTable = new JTable(tiChoiceTableModel);
        tiTable.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                if (SwingUtilities.isRightMouseButton(e)) {
                    List<Integer> modelRows = GuiUtil.getSelectedModelRows(tiTable);
                    if (modelRows.isEmpty()) {
                        Point pt = e.getPoint();
                        int vrow = tiTable.rowAtPoint(pt);
                        if (vrow >= 0) {
                            int mrow = tiTable.convertRowIndexToModel(vrow);
                            if (mrow >= 0) {
                                showPopupMenu(tiTable, pt, Arrays.asList(Integer.valueOf(mrow)));
                            }
                        }
                    } else {
                        showPopupMenu(tiTable, e.getPoint(), modelRows);
                    }
                }
            }
        });

        tableModel = new DataTableModel(plotInfoByPlotId);
        JTable table = new JTable(tableModel);
        DefaultTableCellRenderer r = new DefaultTableCellRenderer();
        r.setHorizontalAlignment(SwingConstants.CENTER);
        table.setDefaultRenderer(String.class, r);

        splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(tiTable),
                new JScrollPane(table));
        splitPane.setResizeWeight(0.2);
        add(splitPane, BorderLayout.CENTER);
        table.setTransferHandler(TableTransferHandler.initialiseForCopySelectAll(table, true));
    }
}

From source file:edu.ku.brc.specify.plugins.sgr.SGRResultsDisplay.java

private JTable createTable(DefaultTableModel resultsTableModel, final List<List<Color>> rowColors) {
    JTable table = new JTable(resultsTableModel) {
        public Component prepareRenderer(TableCellRenderer renderer, int rowIndex, int colIndex) {
            Component c = super.prepareRenderer(renderer, rowIndex, colIndex);

            final Color bgColor = isCellSelected(rowIndex, colIndex) ? getSelectionBackground()
                    : rowColors.get(rowIndex).get(colIndex);

            c.setBackground(bgColor);//  ww w .  ja  v  a 2 s .  c o m
            return c;
        }
    };

    DefaultTableCellRenderer tcr = getTableCellRenderer();//model.getRowInfoList());
    for (int i = 0; i < resultsTableModel.getColumnCount(); i++) {
        if (resultsTableModel.getColumnClass(i) != Boolean.class) {
            table.setDefaultRenderer(resultsTableModel.getColumnClass(i), tcr);
        }
    }

    table.setCellSelectionEnabled(true);

    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

    UIHelper.makeTableHeadersCentered(table, false);
    table.setDefaultRenderer(String.class, new BiColorTableCellRenderer(false));
    table.setRowHeight(ROW_HEIGHT);

    autoResizeColWidth(table, resultsTableModel);
    return table;
}

From source file:MainClass.java

public MainClass() {
    super("Table With DefaultCellEditor Example");
    setSize(500, 300);/*from   w  ww.  j a v a 2  s.  co  m*/
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    JTable table = new JTable(new AbstractTableModel() {
        ColorName data[] = { colors[0], colors[1], colors[2], colors[3], colors[4], colors[0], colors[1],
                colors[2], colors[3], colors[4] };

        public int getColumnCount() {
            return 3;
        }

        public int getRowCount() {
            return 10;
        }

        public Object getValueAt(int r, int c) {
            switch (c) {
            case 0:
                return (r + 1) + ".";
            case 1:
                return "Some pithy quote #" + r;
            case 2:
                return data[r];
            }
            return "Bad Column";
        }

        public Class getColumnClass(int c) {
            if (c == 2)
                return ColorName.class;
            return String.class;
        }

        public boolean isCellEditable(int r, int c) {
            return c == 2;
        }

        public void setValueAt(Object value, int r, int c) {
            data[r] = (ColorName) value;
        }
    });

    table.setDefaultEditor(ColorName.class, new DefaultCellEditor(new JComboBox(colors)));
    table.setDefaultRenderer(ColorName.class, new DefaultTableCellRenderer());
    table.setRowHeight(20);
    getContentPane().add(new JScrollPane(table));
}

From source file:org.zaproxy.zap.extension.multiFuzz.impl.http.HttpFuzzResultDialog.java

@Override
public JXTreeTable getTable() {
    if (table == null) {
        if (model == null) {
            model = new HttpFuzzTableModel();
        }/*  ww w .jav a  2  s  .  com*/
        table = new JXTreeTable(model);
        table.setDoubleBuffered(true);
        table.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);
        table.setName("HttpFuzzResultTable");
        table.setFont(new java.awt.Font("Default", java.awt.Font.PLAIN, 12));
        table.setDefaultRenderer(Pair.class, new IconTableCellRenderer());

        int[] widths = { 10, 25, 550, 30, 85, 55, 40, 70 };
        for (int i = 0, count = widths.length; i < count; i++) {
            TableColumn column = table.getColumnModel().getColumn(i);
            column.setPreferredWidth(widths[i]);
        }
        table.addMouseListener(new java.awt.event.MouseAdapter() {
            @Override
            public void mousePressed(java.awt.event.MouseEvent e) {
                showPopupMenuIfTriggered(e);
            }

            @Override
            public void mouseReleased(java.awt.event.MouseEvent e) {
                showPopupMenuIfTriggered(e);
            }

            private void showPopupMenuIfTriggered(java.awt.event.MouseEvent e) {
                if (e.isPopupTrigger()) {
                    if (e.isPopupTrigger()) {
                        // Select list item on right click
                        JTable table = (JTable) e.getSource();
                        int row = table.rowAtPoint(e.getPoint());

                        if (!table.isRowSelected(row)) {
                            table.changeSelection(row, 0, false, false);
                        }
                        View.getSingleton().getPopupMenu().show(e.getComponent(), e.getX(), e.getY());
                    }
                }
            }

        });
        table.getSelectionModel().addListSelectionListener(new javax.swing.event.ListSelectionListener() {

            @Override
            public void valueChanged(javax.swing.event.ListSelectionEvent e) {
                if (!e.getValueIsAdjusting()) {
                    if (table.getSelectedRowCount() == 0) {
                        return;
                    }
                    final int row = table.getSelectedRow();
                    if (getEntry(row) instanceof HttpFuzzRequestRecord) {
                        final HistoryReference historyReference = ((HttpFuzzRequestRecord) getEntry(row))
                                .getHistory();
                        try {
                            getMessageInspection().setMessage(historyReference.getHttpMessage());
                        } catch (HttpMalformedHeaderException | SQLException ex) {
                            logger.error(ex.getMessage(), ex);
                        }
                    }
                    updateValues();
                    redrawDiagrams();
                }
            }
        });
    }
    table.getTableHeader().addMouseListener(new MouseListener() {
        int sortedOn = -1;

        @Override
        public void mouseReleased(MouseEvent arg0) {
        }

        @Override
        public void mousePressed(MouseEvent arg0) {
        }

        @Override
        public void mouseExited(MouseEvent arg0) {
        }

        @Override
        public void mouseEntered(MouseEvent arg0) {
        }

        @Override
        public void mouseClicked(MouseEvent e) {
            int index = table.columnAtPoint(e.getPoint());
            List<HttpFuzzRecord> list = model.getEntries();
            if (list.size() == 0) {
                return;
            }
            HttpFuzzRecordComparator comp = new HttpFuzzRecordComparator();
            comp.setFeature(index);
            if (index == sortedOn) {
                Collections.sort(list, comp);
                Collections.reverse(list);
                sortedOn = -1;
            } else {
                Collections.sort(list, comp);
                sortedOn = index;
            }
            table.updateUI();
        }
    });
    table.setRootVisible(false);
    table.setVisible(true);
    return table;
}

From source file:mt.listeners.InteractiveRANSAC.java

public void updateRANSAC() {

    negcount = 0;/*from w w  w .  j  a va 2 s .  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;

}