package org.drugis.addis.gui.renderer;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import org.drugis.addis.entities.ContinuousVariableType;
import org.drugis.addis.forestplot.ForestPlot;
import org.drugis.addis.forestplot.LogScale;
import org.drugis.addis.forestplot.RelativeEffectBar;
import org.drugis.addis.presentation.BRATTableModel.BRATForest;
import org.drugis.addis.presentation.REMAForestPlotPresentation;
import org.drugis.common.gui.table.RenderAsImage;
public class BRATForestCellRenderer<PresentationType>
extends DefaultTableCellRenderer
implements RenderAsImage {
private final Color d_fg;
private final BRATForest d_forest;
private final Color d_bg;
private static final long serialVersionUID = 1L;
d_forest = forest;
d_bg = bg;
d_fg = fg;
}
@Override
g.setColor(d_bg);
Rectangle bounds = g.getClipBounds();
g.fillRect(bounds.x, bounds.y, bounds.width, bounds.height);
if (d_forest == null || d_forest.scale == null) {
return;
}
g.translate(PADDING, 0);
g.setColor(d_fg);
if (d_forest.ci != null) {
final RelativeEffectBar bar = new RelativeEffectBar(d_forest.scale, ForestPlot.ROWVCENTER, d_forest.ci, ForestPlot.ROWHEIGHT / 3, d_forest.vt instanceof ContinuousVariableType);
bar.paint((Graphics2D) g);
int originX = d_forest.scale.getBin(d_forest.scale.getScale() instanceof LogScale ? 1D : 0D).bin;
g.drawLine(originX, 1 - ForestPlot.ROWPAD, originX, ForestPlot.FULLROW);
} else if (d_forest.axis != null) {
g.drawLine(d_forest.scale.getBin(d_forest.axis.getMin()).bin, 1, d_forest.scale.getBin(d_forest.axis.getMax()).bin, 1);
ForestPlot.drawAxisTicks(g, 1, REMAForestPlotPresentation.getTicks(d_forest.scale, d_forest.axis), REMAForestPlotPresentation.getTickVals(d_forest.scale, d_forest.axis));
}
g.translate(-PADDING, 0);
}
@Override
return new Dimension(ForestPlot.BARWIDTH, ForestPlot.ROWHEIGHT);
}
@Override
return getSize();
}
@Override
return getSize();
}
}
private static final long serialVersionUID = -6339099621262904161L;
public static final int PADDING = 20;
@Override
Component superRenderer = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
final Color bg = superRenderer.getBackground();
final Color fg = superRenderer.getForeground();
final BRATForest forest = (BRATForest) value;
JPanel panel = new ForestPlotTableCell(forest, bg, fg);
return panel;
}
}