Unnamed: 0
int64 0
2.05k
| func
stringlengths 27
124k
| target
bool 2
classes | project
stringlengths 39
117
|
---|---|---|---|
2,000 | public class JUnitScatterXYPlotLine extends TestCase {
private ScatterXYPlotLine line;
private XYPlot plot;
private List<Rectangle> repaints = new ArrayList<Rectangle>();
private int linesPerBox = 3;
@Override
protected void setUp() throws Exception {
XYAxis xAxis = new LinearXYAxis(XYDimension.X);
XYAxis yAxis = new LinearXYAxis(XYDimension.Y);
xAxis.setStart(0);
xAxis.setEnd(1);
yAxis.setStart(0);
yAxis.setEnd(1);
line = new ScatterXYPlotLine(xAxis, yAxis, linesPerBox) {
private static final long serialVersionUID = 1L;
@Override
public void repaint(int x, int y, int width, int height) {
repaints.add(new Rectangle(x, y, width, height));
super.repaint(x, y, width, height);
}
};
XYPlotContents contents = new XYPlotContents();
contents.add(line);
plot = new XYPlot();
plot.add(contents);
plot.add(xAxis);
plot.add(yAxis);
plot.setXAxis(xAxis);
plot.setYAxis(yAxis);
new DefaultXYLayoutGenerator().generateLayout(plot);
}
private void add(double x, double y) {
line.add(x, y);
}
private void prepend(double x, double y) {
line.prepend(new double[] { x }, 0, new double[] { y }, 0, 1);
}
private void prependDD(double x, double y) {
DoubleData xData = new DoubleData();
DoubleData yData = new DoubleData();
xData.add(x);
yData.add(y);
line.prepend(xData, yData);
}
public void testPaintSimple() throws InterruptedException, InvocationTargetException {
add(.1, .1);
add(.9, .9);
CountingGraphics g = paint();
LineChecker c = new LineChecker();
c.require(19, 180, 179, 20);
c.check(g.getLines());
assertEquals(2, g.getPointCount());
}
public void testPaintInverted() throws InterruptedException, InvocationTargetException {
plot.getXAxis().setStart(1);
plot.getXAxis().setEnd(0);
add(.1, .1);
add(.9, .9);
CountingGraphics g = paint();
LineChecker c = new LineChecker();
c.require(179, 180, 19, 20);
c.check(g.getLines());
assertEquals(2, g.getPointCount());
}
public void testPaintLeadingNaN() throws InterruptedException, InvocationTargetException {
add(.05, Double.NaN);
add(.1, .1);
add(.9, .9);
CountingGraphics g = paint();
LineChecker c = new LineChecker();
c.require(19, 180, 179, 20);
c.check(g.getLines());
assertEquals(2, g.getPointCount());
}
public void testPaintTrailingNaN() throws InterruptedException, InvocationTargetException {
add(.1, .1);
add(.9, .9);
add(.95, Double.NaN);
CountingGraphics g = paint();
LineChecker c = new LineChecker();
c.require(19, 180, 179, 20);
c.check(g.getLines());
assertEquals(2, g.getPointCount());
}
public void testPaintMiddleNaN() throws InterruptedException, InvocationTargetException {
add(.1, .1);
add(.2, .2);
add(.5, Double.NaN);
add(.8, .8);
add(.9, .9);
CountingGraphics g = paint();
LineChecker c = new LineChecker();
c.require(19, 180, 39, 160);
c.require(159, 40, 179, 20);
c.check(g.getLines());
assertEquals(4, g.getPointCount());
}
public void testPaintTrailingTripleNaN() throws InterruptedException, InvocationTargetException {
add(.1, .1);
add(.9, .9);
add(.95, Double.NaN);
add(.96, Double.NaN);
add(.97, Double.NaN);
CountingGraphics g = paint();
LineChecker c = new LineChecker();
c.require(19, 180, 179, 20);
c.check(g.getLines());
assertEquals(2, g.getPointCount());
}
public void testAddToEmptyBox() throws InterruptedException, InvocationTargetException {
add(.1, Double.NaN);
add(.2, Double.NaN);
add(.3, Double.NaN);
add(.4, .4);
add(.5, .5);
CountingGraphics g = paint(new Rectangle(84, 116, 10, 10));
LineChecker c = new LineChecker();
c.allow(39, 160, 59, 140);
c.allow(59, 140, 79, 120);
c.require(79, 120, 99, 100);
c.check(g.getLines());
assertEquals(g.getLines().size() + 1, g.getPointCount());
}
public void testPrependToEmptyBox() throws InterruptedException, InvocationTargetException {
prepend(.1, .1);
prepend(.2, .2);
prepend(.3, .3);
prepend(.4, Double.NaN);
prepend(.5, Double.NaN);
CountingGraphics g = paint(new Rectangle(24, 176, 10, 10));
LineChecker c = new LineChecker();
c.require(19, 180, 39, 160);
c.allow(39, 160, 59, 140);
c.check(g.getLines());
assertEquals(g.getLines().size() + 1, g.getPointCount());
}
public void testPrependDDToEmptyBox() throws InterruptedException, InvocationTargetException {
prependDD(.1, .1);
prependDD(.2, .2);
prependDD(.3, .3);
prependDD(.4, Double.NaN);
prependDD(.5, Double.NaN);
CountingGraphics g = paint(new Rectangle(24, 176, 10, 10));
LineChecker c = new LineChecker();
c.require(19, 180, 39, 160);
c.allow(39, 160, 59, 140);
c.check(g.getLines());
assertEquals(g.getLines().size() + 1, g.getPointCount());
}
public void testRemoveAllPoints() throws InterruptedException, InvocationTargetException {
add(.1, .1);
add(.2, .2);
add(.3, .3);
add(.4, .4);
add(.5, .5);
assertEquals(5, line.getPointCount());
line.removeAllPoints();
assertEquals(0, line.getPointCount());
assertEquals(0, line.getXData().getLength());
assertEquals(0, line.getYData().getLength());
CountingGraphics g = paint();
assertEquals(0, g.getPointCount());
add(.1, .1);
add(.2, .2);
CountingGraphics g2 = paint(new Rectangle(24, 176, 10, 10));
LineChecker c = new LineChecker();
c.require(19, 180, 39, 160);
c.allow(39, 160, 59, 140);
c.allow(59, 140, 79, 120);
c.check(g2.getLines());
assertEquals(g2.getLines().size() + 1, g2.getPointCount());
}
public void testPaintClip() throws InterruptedException, InvocationTargetException {
add(.1, .1);
add(.2, .2);
add(.3, .3);
add(.4, .4);
add(.5, .5);
CountingGraphics g = paint(new Rectangle(24, 176, 10, 10));
LineChecker c = new LineChecker();
c.require(19, 180, 39, 160);
c.allow(39, 160, 59, 140);
c.allow(59, 140, 79, 120);
c.check(g.getLines());
assertEquals(g.getLines().size() + 1, g.getPointCount());
}
public void testPaintClip2() throws InterruptedException, InvocationTargetException {
add(.1, .1);
add(.2, .2);
add(.3, .3);
add(.4, .4);
add(.5, .5);
CountingGraphics g = paint(new Rectangle(44, 136, 10, 10));
LineChecker c = new LineChecker();
c.allow(19, 180, 39, 160);
c.require(39, 160, 59, 140);
c.allow(59, 140, 79, 120);
c.check(g.getLines());
assertEquals(g.getLines().size() + 1, g.getPointCount());
}
public void testPaintClip3() throws InterruptedException, InvocationTargetException {
add(.1, .1);
add(.2, .2);
add(.3, .3);
add(.4, .4);
add(.5, .5);
CountingGraphics g = paint(new Rectangle(64, 116, 10, 10));
LineChecker c = new LineChecker();
c.allow(19, 180, 39, 160);
c.allow(39, 160, 59, 140);
c.require(59, 140, 79, 120);
c.check(g.getLines());
assertEquals(g.getLines().size() + 1, g.getPointCount());
}
public void testPaintClip4() throws InterruptedException, InvocationTargetException {
add(.1, .1);
add(.2, .2);
add(.3, .3);
add(.4, .4);
add(.5, .5);
CountingGraphics g = paint(new Rectangle(84, 96, 10, 10));
LineChecker c = new LineChecker();
c.require(79, 120, 99, 100);
c.check(g.getLines());
assertEquals(g.getLines().size() + 1, g.getPointCount());
}
public void testPaintClipInverted() throws InterruptedException, InvocationTargetException {
plot.getXAxis().setStart(1);
plot.getXAxis().setEnd(0);
add(.9, .1);
add(.8, .2);
add(.7, .3);
add(.6, .4);
add(.5, .5);
CountingGraphics g = paint(new Rectangle(24, 176, 10, 10));
LineChecker c = new LineChecker();
c.require(19, 180, 39, 160);
c.allow(39, 160, 59, 140);
c.allow(59, 140, 79, 120);
c.check(g.getLines());
assertEquals(g.getLines().size() + 1, g.getPointCount());
}
public void testPaintClipPrepend() throws InterruptedException, InvocationTargetException {
prepend(.1, .1);
prepend(.2, .2);
prepend(.3, .3);
prepend(.4, .4);
prepend(.5, .5);
CountingGraphics g = paint(new Rectangle(24, 176, 10, 10));
LineChecker c = new LineChecker();
c.require(19, 180, 39, 160);
c.allow(39, 160, 59, 140);
c.check(g.getLines());
assertEquals(g.getLines().size() + 1, g.getPointCount());
}
public void testPaintClipPrepend2() throws InterruptedException, InvocationTargetException {
prepend(.1, .1);
prepend(.2, .2);
prepend(.3, .3);
prepend(.4, .4);
prepend(.5, .5);
CountingGraphics g = paint(new Rectangle(44, 156, 10, 10));
LineChecker c = new LineChecker();
c.allow(19, 180, 39, 160);
c.require(39, 160, 59, 140);
c.check(g.getLines());
assertEquals(g.getLines().size() + 1, g.getPointCount());
}
public void testPaintClipPrepend3() throws InterruptedException, InvocationTargetException {
prepend(.1, .1);
prepend(.2, .2);
prepend(.3, .3);
prepend(.4, .4);
prepend(.5, .5);
prepend(.6, .6);
CountingGraphics g = paint(new Rectangle(24, 176, 10, 10));
LineChecker c = new LineChecker();
c.require(19, 180, 39, 160);
c.allow(39, 160, 59, 140);
c.check(g.getLines());
assertEquals(g.getLines().size() + 1, g.getPointCount());
}
public void testPaintClipPrepend4() throws InterruptedException, InvocationTargetException {
prepend(.1, .1);
prepend(.2, .2);
prepend(.3, .3);
prepend(.4, .4);
prepend(.5, .5);
prepend(.6, .6);
CountingGraphics g = paint(new Rectangle(44, 156, 10, 10));
LineChecker c = new LineChecker();
c.allow(19, 180, 39, 160);
c.require(39, 160, 59, 140);
c.check(g.getLines());
assertEquals(g.getLines().size() + 1, g.getPointCount());
}
public void testPaintClipPrependDD() throws InterruptedException, InvocationTargetException {
prependDD(.1, .1);
prependDD(.2, .2);
prependDD(.3, .3);
prependDD(.4, .4);
prependDD(.5, .5);
CountingGraphics g = paint(new Rectangle(24, 176, 10, 10));
LineChecker c = new LineChecker();
c.require(19, 180, 39, 160);
c.allow(39, 160, 59, 140);
c.check(g.getLines());
assertEquals(g.getLines().size() + 1, g.getPointCount());
}
public void testRemoveFirst() throws InterruptedException, InvocationTargetException {
prepend(.1, .1);
prepend(.2, .2);
prepend(.3, .3);
prepend(.4, .4);
prepend(.5, .5);
prepend(.6, .6);
line.removeFirst(1);
CountingGraphics g = paint(new Rectangle(24, 176, 10, 10));
LineChecker c = new LineChecker();
c.require(19, 180, 39, 160);
c.allow(39, 160, 59, 140);
c.check(g.getLines());
assertEquals(g.getLines().size() + 1, g.getPointCount());
}
public void testRemoveFirst2() throws InterruptedException, InvocationTargetException {
prepend(.1, .1);
prepend(.2, .2);
prepend(.3, .3);
prepend(.4, .4);
prepend(.5, .5);
prepend(.6, .6);
line.removeFirst(1);
CountingGraphics g = paint(new Rectangle(44, 156, 10, 10));
LineChecker c = new LineChecker();
c.allow(19, 180, 39, 160);
c.require(39, 160, 59, 140);
c.check(g.getLines());
assertEquals(g.getLines().size() + 1, g.getPointCount());
}
public void testRemoveFirst3() throws InterruptedException, InvocationTargetException {
prepend(.1, .1);
prepend(.2, .2);
prepend(.3, .3);
prepend(.4, .4);
prepend(.5, .5);
prepend(.6, .6);
prepend(.7, .7);
line.removeFirst(1);
CountingGraphics g = paint(new Rectangle(24, 176, 10, 10));
LineChecker c = new LineChecker();
c.require(19, 180, 39, 160);
c.allow(39, 160, 59, 140);
c.check(g.getLines());
assertEquals(g.getLines().size() + 1, g.getPointCount());
}
public void testRemoveFirst4() throws InterruptedException, InvocationTargetException {
prepend(.1, .1);
prepend(.2, .2);
prepend(.3, .3);
prepend(.4, .4);
prepend(.5, .5);
prepend(.6, .6);
prepend(.7, .7);
line.removeFirst(1);
CountingGraphics g = paint(new Rectangle(44, 156, 10, 10));
LineChecker c = new LineChecker();
c.allow(19, 180, 39, 160);
c.require(39, 160, 59, 140);
c.check(g.getLines());
assertEquals(g.getLines().size() + 1, g.getPointCount());
}
public void testRemoveLast() throws InterruptedException, InvocationTargetException {
prepend(.6, .6);
prepend(.1, .1);
prepend(.2, .2);
prepend(.3, .3);
prepend(.4, .4);
prepend(.5, .5);
line.removeLast(1);
CountingGraphics g = paint(new Rectangle(24, 176, 10, 10));
LineChecker c = new LineChecker();
c.require(19, 180, 39, 160);
c.allow(39, 160, 59, 140);
c.check(g.getLines());
assertEquals(g.getLines().size() + 1, g.getPointCount());
}
public void testRemoveLast2() throws InterruptedException, InvocationTargetException {
prepend(.0, .0);
prepend(.1, .1);
prepend(.2, .2);
prepend(.3, .3);
prepend(.4, .4);
prepend(.5, .5);
line.removeLast(1);
CountingGraphics g = paint(new Rectangle(44, 156, 10, 10));
LineChecker c = new LineChecker();
c.allow(19, 180, 39, 160);
c.require(39, 160, 59, 140);
c.allow(59, 140, 79, 120);
c.allow(79, 120, 99, 100);
c.check(g.getLines());
int lineCount = g.getLines().size();
assertTrue(lineCount <= linesPerBox);
assertEquals(lineCount + 1, g.getPointCount());
}
public void testRemoveLast3() throws InterruptedException, InvocationTargetException {
prepend(.0, .0);
prepend(.1, .1);
prepend(.2, .2);
prepend(.3, .3);
prepend(.4, .4);
prepend(.5, .5);
prepend(.6, .6);
line.removeLast(1);
CountingGraphics g = paint(new Rectangle(24, 176, 10, 10));
LineChecker c = new LineChecker();
c.require(19, 180, 39, 160);
c.allow(39, 160, 59, 140);
c.check(g.getLines());
assertEquals(g.getLines().size() + 1, g.getPointCount());
}
public void testRemoveLast4() throws InterruptedException, InvocationTargetException {
prepend(-.3, -.3);
prepend(-.2, -.2);
prepend(-.1, -.1);
prepend(.0, .0);
prepend(.1, .1);
prepend(.2, .2);
prepend(.3, .3);
prepend(.4, .4);
prepend(.5, .5);
prepend(.6, .6);
line.removeLast(4);
CountingGraphics g = paint(new Rectangle(44, 156, 10, 10));
LineChecker c = new LineChecker();
c.allow(19, 180, 39, 160);
c.require(39, 160, 59, 140);
c.allow(59, 140, 79, 120);
c.allow(79, 120, 99, 100);
c.check(g.getLines());
int lineCount = g.getLines().size();
assertTrue(lineCount <= linesPerBox);
assertEquals(lineCount + 1, g.getPointCount());
}
public void testComplex() throws InterruptedException, InvocationTargetException {
prepend(.2, .2);
prepend(.3, .3);
prepend(.4, .4);
prepend(.5, .5);
prepend(.6, .6);
line.removeFirst(1);
line.add(.1, .1);
CountingGraphics g = paint(new Rectangle(24, 176, 10, 10));
LineChecker c = new LineChecker();
c.require(19, 180, 39, 160);
c.allow(39, 160, 59, 140);
c.allow(59, 140, 79, 120);
c.check(g.getLines());
assertEquals(g.getLines().size() + 1, g.getPointCount());
}
public void testComplex2() throws InterruptedException, InvocationTargetException {
prepend(.2, .2);
prepend(.3, .3);
prepend(.4, .4);
prepend(.5, .5);
prepend(.6, .6);
line.removeFirst(1);
line.add(.1, .1);
CountingGraphics g = paint(new Rectangle(44, 156, 10, 10));
LineChecker c = new LineChecker();
c.allow(19, 180, 39, 160);
c.require(39, 160, 59, 140);
c.allow(59, 140, 79, 120);
c.check(g.getLines());
assertEquals(g.getLines().size() + 1, g.getPointCount());
}
public void testComplex3() throws InterruptedException, InvocationTargetException {
prepend(.2, .2);
prepend(.3, .3);
prepend(.4, .4);
prepend(.5, .5);
prepend(.6, .6);
prepend(.7, .7);
line.removeFirst(1);
line.add(.1, .1);
CountingGraphics g = paint(new Rectangle(24, 176, 10, 10));
LineChecker c = new LineChecker();
c.require(19, 180, 39, 160);
c.allow(39, 160, 59, 140);
c.allow(59, 140, 79, 120);
c.check(g.getLines());
assertEquals(g.getLines().size() + 1, g.getPointCount());
}
public void testComplex4() throws InterruptedException, InvocationTargetException {
prepend(.2, .2);
prepend(.3, .3);
prepend(.4, .4);
prepend(.5, .5);
prepend(.6, .6);
prepend(.7, .7);
line.removeFirst(1);
line.add(.1, .1);
CountingGraphics g = paint(new Rectangle(44, 156, 10, 10));
LineChecker c = new LineChecker();
c.allow(19, 180, 39, 160);
c.require(39, 160, 59, 140);
c.allow(59, 140, 79, 120);
c.check(g.getLines());
assertEquals(g.getLines().size() + 1, g.getPointCount());
}
public void testRepaint() {
add(.1, .2);
add(.2, .3);
add(.3, .4);
line.setSize(200, 200);
plot.getXAxis().setSize(200, 1);
plot.getYAxis().setSize(1, 200);
repaints.clear();
line.repaintData(1);
assertEquals(1, repaints.size());
assertEquals(new Rectangle(18, 119, 42, 42), repaints.get(0));
}
public void testRepaint2() {
add(.1, .2);
add(.2, .3);
add(.3, .4);
add(.4, .5);
add(.5, .6);
add(.6, .7);
line.setSize(200, 200);
plot.getXAxis().setSize(200, 1);
plot.getYAxis().setSize(1, 200);
repaints.clear();
line.repaintData(2, 2);
assertEquals(1, repaints.size());
assertEquals(new Rectangle(38, 79, 62, 62), repaints.get(0));
}
public void testRepaint3() {
add(.1, .4);
add(.2, .3);
add(.3, .2);
line.setSize(200, 200);
plot.getXAxis().setSize(200, 1);
plot.getYAxis().setSize(1, 200);
repaints.clear();
line.repaintData(1);
assertEquals(1, repaints.size());
assertEquals(new Rectangle(18, 119, 42, 42), repaints.get(0));
}
public void testRepaint4() {
add(.6, .7);
add(.5, .6);
add(.4, .5);
add(.3, .4);
add(.2, .3);
add(.1, .2);
line.setSize(200, 200);
plot.getXAxis().setSize(200, 1);
plot.getYAxis().setSize(1, 200);
repaints.clear();
line.repaintData(2, 2);
assertEquals(1, repaints.size());
assertEquals(new Rectangle(38, 79, 62, 62), repaints.get(0));
}
public void testRepaint5() {
add(.1, .2);
add(.2, .3);
add(.3, .4);
add(.4, .5);
add(.5, .6);
add(.6, .7);
line.setSize(200, 200);
XYAxis xAxis = plot.getXAxis();
xAxis.setStart(1);
xAxis.setEnd(0);
xAxis.setSize(200, 1);
plot.getYAxis().setSize(1, 200);
repaints.clear();
line.repaintData(2, 2);
assertEquals(1, repaints.size());
assertEquals(new Rectangle(98, 79, 62, 62), repaints.get(0));
}
public void testRepaintNone() {
add(.1, .4);
add(.2, .3);
add(.3, .2);
line.setSize(200, 200);
plot.getXAxis().setSize(200, 1);
plot.getYAxis().setSize(1, 200);
repaints.clear();
line.repaintData(0, 0);
assertEquals(0, repaints.size());
}
public void testRepaintInverted() {
add(.1, .2);
add(.2, .3);
add(.3, .4);
line.setSize(200, 200);
plot.getXAxis().setStart(1);
plot.getXAxis().setEnd(0);
plot.getXAxis().setSize(200, 1);
plot.getYAxis().setSize(1, 200);
repaints.clear();
line.repaintData(1);
assertEquals(1, repaints.size());
assertEquals(new Rectangle(138, 119, 42, 42), repaints.get(0));
}
public void testPointOutline() throws InterruptedException, InvocationTargetException {
line.setPointOutline(createSquare());
add(.1, .1);
add(.9, .9);
CountingGraphics g = paint();
assertEquals(12, g.getPointCount());
assertEquals(2, g.getShapeCount());
LineChecker c = new LineChecker();
c.require(19, 180, 179, 20);
// Point 1
c.require(14, 175, 14, 185);
c.require(14, 185, 24, 185);
c.require(24, 185, 24, 175);
c.require(24, 175, 14, 175);
// Point 2
c.require(174, 15, 174, 25);
c.require(174, 25, 184, 25);
c.require(184, 25, 184, 15);
c.require(184, 15, 174, 15);
c.check(g.getLines());
}
public void testPointOutlineNaN() throws InterruptedException, InvocationTargetException {
line.setPointOutline(createSquare());
add(.1, .1);
add(.5, Double.NaN);
add(.9, .9);
CountingGraphics g = paint();
assertEquals(10, g.getPointCount());
assertEquals(2, g.getShapeCount());
LineChecker c = new LineChecker();
// Point 1
c.require(14, 175, 14, 185);
c.require(14, 185, 24, 185);
c.require(24, 185, 24, 175);
c.require(24, 175, 14, 175);
// Point 3
c.require(174, 15, 174, 25);
c.require(174, 25, 184, 25);
c.require(184, 25, 184, 15);
c.require(184, 15, 174, 15);
c.check(g.getLines());
}
private GeneralPath createSquare() {
GeneralPath pointShape = new GeneralPath();
pointShape.moveTo(-5, -5);
pointShape.lineTo(-5, 5);
pointShape.lineTo(5, 5);
pointShape.lineTo(5, -5);
pointShape.lineTo(-5, -5);
return pointShape;
}
public void testIndependentDimension() {
assertNull(line.getIndependentDimension());
}
public void testProperties() throws InvocationTargetException, IllegalAccessException, IntrospectionException {
PropertyTester t = new PropertyTester(line);
t.test("stroke", null, new BasicStroke(1));
}
private CountingGraphics paint() throws InterruptedException, InvocationTargetException {
return paint(null);
}
// Ensures that the line is 200x200, paints it, and returns the stats.
// We can't use 100x100 because on Mac OSX, the minimum frame width is 128.
private CountingGraphics paint(Shape clip) throws InterruptedException, InvocationTargetException {
final JFrame frame = new JFrame();
frame.getContentPane().add(plot);
BufferedImage image = new BufferedImage(200, 200, BufferedImage.TYPE_3BYTE_BGR);
final Graphics2D imageG = image.createGraphics();
final CountingGraphics g = new CountingGraphics(imageG);
try {
if(clip != null) {
g.setClip(clip);
}
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
try {
frame.pack();
int xo = 200 - line.getWidth();
int yo = 200 - line.getHeight();
frame.setSize(frame.getWidth() + xo, frame.getHeight() + yo);
frame.validate();
// These are sanity checks to make sure our setup is correct, not actual functionality tests.
assertEquals(200, line.getWidth());
assertEquals(200, line.getHeight());
line.paint(g);
} finally {
frame.dispose();
}
}
});
} finally {
imageG.dispose();
}
return g;
}
} | false | Plotter_src_test_java_plotter_xy_JUnitScatterXYPlotLine.java |
2,001 | line = new ScatterXYPlotLine(xAxis, yAxis, linesPerBox) {
private static final long serialVersionUID = 1L;
@Override
public void repaint(int x, int y, int width, int height) {
repaints.add(new Rectangle(x, y, width, height));
super.repaint(x, y, width, height);
}
}; | false | Plotter_src_test_java_plotter_xy_JUnitScatterXYPlotLine.java |
2,002 | SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
try {
frame.pack();
int xo = 200 - line.getWidth();
int yo = 200 - line.getHeight();
frame.setSize(frame.getWidth() + xo, frame.getHeight() + yo);
frame.validate();
// These are sanity checks to make sure our setup is correct, not actual functionality tests.
assertEquals(200, line.getWidth());
assertEquals(200, line.getHeight());
line.paint(g);
} finally {
frame.dispose();
}
}
}); | false | Plotter_src_test_java_plotter_xy_JUnitScatterXYPlotLine.java |
2,003 | public class JUnitSimpleXYDataset extends TestCase {
private static class MinMaxTracker implements MinMaxChangeListener {
private int count;
@Override
public void minMaxChanged(SimpleXYDataset dataset, XYDimension dimension) {
count++;
}
}
private SimpleXYDataset createDataset(XYDimension independentDimension) {
LinearXYAxis xAxis = new LinearXYAxis(XYDimension.X);
LinearXYAxis yAxis = new LinearXYAxis(XYDimension.Y);
LinearXYPlotLine line = new LinearXYPlotLine(xAxis, yAxis, independentDimension);
SimpleXYDataset dataset = new SimpleXYDataset(line);
XYPlot plot = new XYPlot();
XYPlotContents contents = new XYPlotContents();
plot.add(contents);
contents.add(line);
plot.add(xAxis);
plot.add(yAxis);
return dataset;
}
public void testMinMax() {
SimpleXYDataset dataset = createDataset(null);
MinMaxTracker xTracker = new MinMaxTracker();
MinMaxTracker yTracker = new MinMaxTracker();
dataset.addXMinMaxChangeListener(xTracker);
dataset.addYMinMaxChangeListener(yTracker);
dataset.add(0, 0);
assertEquals(1, xTracker.count);
assertEquals(1, yTracker.count);
assertEquals(0.0, dataset.getMinX());
assertEquals(0.0, dataset.getMaxX());
assertEquals(0.0, dataset.getMinY());
assertEquals(0.0, dataset.getMaxY());
dataset.add(1, 2);
assertEquals(2, xTracker.count);
assertEquals(2, yTracker.count);
assertEquals(0.0, dataset.getMinX());
assertEquals(1.0, dataset.getMaxX());
assertEquals(0.0, dataset.getMinY());
assertEquals(2.0, dataset.getMaxY());
dataset.add(2, 1);
assertEquals(3, xTracker.count);
assertEquals(2, yTracker.count);
assertEquals(0.0, dataset.getMinX());
assertEquals(2.0, dataset.getMaxX());
assertEquals(0.0, dataset.getMinY());
assertEquals(2.0, dataset.getMaxY());
dataset.removeAllXMinMaxChangeListeners();
dataset.removeAllYMinMaxChangeListeners();
dataset.add(100, 100);
assertEquals(3, xTracker.count);
assertEquals(2, yTracker.count);
}
public void testPrepend() {
SimpleXYDataset dataset = createDataset(null);
dataset.add(0, 0);
dataset.add(1, 1);
dataset.add(2, 2);
dataset.add(3, 3);
dataset.add(4, 4);
assertEquals(5, dataset.getPointCount());
double[] newx = { 10, 11, 12, 13, 14 };
double[] newy = { 10, 11, 12, 13, 14 };
dataset.prepend(newx, 0, newy, 0, 5);
assertEquals(10, dataset.getPointCount());
DoubleData x = dataset.getXData();
DoubleData y = dataset.getYData();
assertEquals(10, x.getLength());
assertEquals(10, y.getLength());
assertEquals(10.0, x.get(0));
assertEquals(10.0, y.get(0));
assertEquals(4.0, x.get(9));
assertEquals(4.0, y.get(9));
assertEquals(0.0, dataset.getMinX());
assertEquals(14.0, dataset.getMaxX());
assertEquals(0.0, dataset.getMinY());
assertEquals(14.0, dataset.getMaxY());
}
public void testTruncate() {
SimpleXYDataset dataset = createDataset(null);
dataset.setMaxCapacity(5);
dataset.add(10, 10);
dataset.add(1, 1);
dataset.add(0, 0);
dataset.add(2, 2);
dataset.add(3, 3);
assertEquals(5, dataset.getPointCount());
dataset.add(5, 5);
assertEquals(5, dataset.getPointCount());
DoubleData x = dataset.getXData();
DoubleData y = dataset.getYData();
assertEquals(5, x.getLength());
assertEquals(5, y.getLength());
assertEquals(1.0, x.get(0));
assertEquals(1.0, y.get(0));
assertEquals(5.0, x.get(4));
assertEquals(5.0, y.get(4));
assertEquals(0.0, dataset.getMinX());
assertEquals(5.0, dataset.getMaxX());
assertEquals(0.0, dataset.getMinY());
assertEquals(5.0, dataset.getMaxY());
}
public void testTruncateSorted() {
SimpleXYDataset dataset = createDataset(XYDimension.X);
dataset.setMaxCapacity(5);
dataset.add(0, 0);
dataset.add(1, 1);
dataset.add(2, 2);
dataset.add(3, 3);
dataset.add(4, 4);
assertEquals(5, dataset.getPointCount());
dataset.add(5, 5);
assertEquals(5, dataset.getPointCount());
DoubleData x = dataset.getXData();
DoubleData y = dataset.getYData();
assertEquals(5, x.getLength());
assertEquals(5, y.getLength());
assertEquals(1.0, x.get(0));
assertEquals(1.0, y.get(0));
assertEquals(5.0, x.get(4));
assertEquals(5.0, y.get(4));
assertEquals(1.0, dataset.getMinX());
assertEquals(5.0, dataset.getMaxX());
assertEquals(1.0, dataset.getMinY());
assertEquals(5.0, dataset.getMaxY());
}
public void testRemoveFirst() {
SimpleXYDataset dataset = createDataset(XYDimension.X);
dataset.add(0, 0);
dataset.add(1, 1);
dataset.add(2, 2);
dataset.add(3, 3);
dataset.add(4, 4);
dataset.removeFirst(2);
assertEquals(3, dataset.getPointCount());
assertEquals(2.0, dataset.getMinX());
assertEquals(4.0, dataset.getMaxX());
assertEquals(2.0, dataset.getMinY());
assertEquals(4.0, dataset.getMaxY());
dataset.removeFirst(3);
assertEquals(0, dataset.getPointCount());
assertEquals(Double.POSITIVE_INFINITY, dataset.getMinX());
assertEquals(Double.NEGATIVE_INFINITY, dataset.getMaxX());
assertEquals(Double.POSITIVE_INFINITY, dataset.getMinY());
assertEquals(Double.NEGATIVE_INFINITY, dataset.getMaxY());
}
public void testRemoveAll() {
SimpleXYDataset dataset = createDataset(null);
dataset.add(0, 0);
dataset.add(1, 1);
dataset.add(2, 2);
dataset.add(3, 3);
dataset.add(4, 4);
dataset.removeAllPoints();
assertEquals(0, dataset.getPointCount());
assertEquals(Double.POSITIVE_INFINITY, dataset.getMinX());
assertEquals(Double.NEGATIVE_INFINITY, dataset.getMaxX());
assertEquals(Double.POSITIVE_INFINITY, dataset.getMinY());
assertEquals(Double.NEGATIVE_INFINITY, dataset.getMaxY());
}
public void testProperties() throws InvocationTargetException, IllegalAccessException, IntrospectionException {
SimpleXYDataset dataset = createDataset(null);
PropertyTester t = new PropertyTester(dataset);
t.test("maxCapacity", 1, Integer.MAX_VALUE);
t.test("XData", new DoubleData(), null);
t.test("YData", new DoubleData(), null);
}
} | false | Plotter_src_test_java_plotter_xy_JUnitSimpleXYDataset.java |
2,004 | private static class MinMaxTracker implements MinMaxChangeListener {
private int count;
@Override
public void minMaxChanged(SimpleXYDataset dataset, XYDimension dimension) {
count++;
}
} | false | Plotter_src_test_java_plotter_xy_JUnitSimpleXYDataset.java |
2,005 | public class JUnitSlopeLine extends TestCase {
private final class MockListener implements Listener {
SlopeLine line;
XYPlot plot;
int addCount;
int updateCount;
int removeCount;
double startX;
double startY;
double endX;
double endY;
public MockListener(SlopeLine line, XYPlot plot) {
this.line = line;
this.plot = plot;
}
@Override
public void slopeLineUpdated(SlopeLine line, XYPlot plot, double startX, double startY, double endX, double endY) {
assertEquals(this.line, line);
assertEquals(this.plot, plot);
updateCount++;
this.startX = startX;
this.startY = startY;
this.endX = endX;
this.endY = endY;
}
@Override
public void slopeLineRemoved(SlopeLine line, XYPlot plot) {
assertEquals(this.line, line);
assertEquals(this.plot, plot);
removeCount++;
}
@Override
public void slopeLineAdded(SlopeLine line, XYPlot plot, double startX, double startY) {
assertEquals(this.line, line);
assertEquals(this.plot, plot);
addCount++;
this.startX = startX;
this.startY = startY;
}
}
public void testSlopeLine() {
XYPlot plot = new XYPlot();
XYAxis xAxis = new LinearXYAxis(XYDimension.X);
XYAxis yAxis = new LinearXYAxis(XYDimension.Y);
plot.add(xAxis);
plot.add(yAxis);
plot.setXAxis(xAxis);
plot.setYAxis(yAxis);
xAxis.setStart(0);
xAxis.setEnd(1);
yAxis.setStart(0);
yAxis.setEnd(1);
xAxis.setSize(1000, 1);
yAxis.setSize(1, 1000);
XYPlotContents contents = new XYPlotContents();
plot.add(contents);
SlopeLine slopeLine = new SlopeLine();
slopeLine.attach(plot);
slopeLine.setSize(1000, 1000);
MockListener listener = new MockListener(slopeLine, plot);
slopeLine.addListenerForPlot(null, listener);
int x = 100;
int y = 100;
int xAbs = x + 10;
int yAbs = y + 10;
MouseEvent press = new MouseEvent(contents, MouseEvent.MOUSE_PRESSED, System.currentTimeMillis(), InputEvent.BUTTON1_DOWN_MASK, x, y,
xAbs, yAbs, 1, false, MouseEvent.BUTTON1);
slopeLine.mousePressed(press);
assertEquals(1, listener.addCount);
assertEquals(0, listener.updateCount);
assertEquals(0, listener.removeCount);
assertEquals(.1, listener.startX, .01);
assertEquals(.9, listener.startY, .01);
int x2 = 200;
int y2 = 300;
int xAbs2 = x2 + 10;
int yAbs2 = y2 + 10;
MouseEvent drag = new MouseEvent(contents, MouseEvent.MOUSE_DRAGGED, System.currentTimeMillis(), 0, x2, y2,
xAbs2, yAbs2, 1, false, MouseEvent.BUTTON1);
slopeLine.mouseDragged(drag);
assertEquals(1, listener.addCount);
assertEquals(1, listener.updateCount);
assertEquals(0, listener.removeCount);
assertEquals(.1, listener.startX, .01);
assertEquals(.9, listener.startY, .01);
assertEquals(.2, listener.endX, .01);
assertEquals(.7, listener.endY, .01);
int x3 = 300;
int y3 = 200;
int xAbs3 = x3 + 10;
int yAbs3 = y3 + 10;
MouseEvent drag2 = new MouseEvent(contents, MouseEvent.MOUSE_DRAGGED, System.currentTimeMillis(), 0, x3, y3,
xAbs3, yAbs3, 1, false, MouseEvent.BUTTON1);
slopeLine.mouseDragged(drag2);
assertEquals(1, listener.addCount);
assertEquals(2, listener.updateCount);
assertEquals(0, listener.removeCount);
assertEquals(.1, listener.startX, .01);
assertEquals(.9, listener.startY, .01);
assertEquals(.3, listener.endX, .01);
assertEquals(.8, listener.endY, .01);
CountingGraphics g = new CountingGraphics(new BufferedImage(1000, 1000, BufferedImage.TYPE_3BYTE_BGR)
.createGraphics());
slopeLine.paintComponent(g);
LineChecker lines = new LineChecker();
lines.require(0, 50, 1000, 550);
lines.check(g.getLines());
MouseEvent release = new MouseEvent(contents, MouseEvent.MOUSE_RELEASED, System.currentTimeMillis(), 0, x3, y3,
xAbs3, yAbs3, 1, false, MouseEvent.BUTTON1);
slopeLine.mouseReleased(release);
assertEquals(1, listener.addCount);
assertEquals(2, listener.updateCount);
assertEquals(1, listener.removeCount);
}
} | false | Plotter_src_test_java_plotter_xy_JUnitSlopeLine.java |
2,006 | private final class MockListener implements Listener {
SlopeLine line;
XYPlot plot;
int addCount;
int updateCount;
int removeCount;
double startX;
double startY;
double endX;
double endY;
public MockListener(SlopeLine line, XYPlot plot) {
this.line = line;
this.plot = plot;
}
@Override
public void slopeLineUpdated(SlopeLine line, XYPlot plot, double startX, double startY, double endX, double endY) {
assertEquals(this.line, line);
assertEquals(this.plot, plot);
updateCount++;
this.startX = startX;
this.startY = startY;
this.endX = endX;
this.endY = endY;
}
@Override
public void slopeLineRemoved(SlopeLine line, XYPlot plot) {
assertEquals(this.line, line);
assertEquals(this.plot, plot);
removeCount++;
}
@Override
public void slopeLineAdded(SlopeLine line, XYPlot plot, double startX, double startY) {
assertEquals(this.line, line);
assertEquals(this.plot, plot);
addCount++;
this.startX = startX;
this.startY = startY;
}
} | false | Plotter_src_test_java_plotter_xy_JUnitSlopeLine.java |
2,007 | public class JUnitSlopeLineDisplay extends TestCase {
private SlopeLineDisplay display;
private SlopeLine line;
@Override
protected void setUp() throws Exception {
line = new SlopeLine();
display = new SlopeLineDisplay();
}
public void testAdd() {
display.setText("");
display.slopeLineAdded(line, null, 0, 0);
assertEquals("", display.getText());
}
public void testRemove() {
display.setText("test");
display.slopeLineRemoved(line, null);
assertEquals("", display.getText());
}
public void testUpdate() {
MessageFormat format = new MessageFormat("{0} {1} {2}");
display.setFormat(format);
assertEquals(format, display.getFormat());
display.slopeLineUpdated(line, null, 1, 2, 3, 10);
assertEquals("2 8 4", display.getText());
}
public void testUpdateSame() {
MessageFormat format = new MessageFormat("{0} {1} {2}");
display.setFormat(format);
assertEquals(format, display.getFormat());
display.slopeLineUpdated(line, null, 1, 2, 1, 2);
assertEquals("", display.getText());
}
} | false | Plotter_src_test_java_plotter_xy_JUnitSlopeLineDisplay.java |
2,008 | public class JUnitXY extends TestSuite {
public static TestSuite suite() {
TestSuite suite = new TestSuite("Plotter XY");
suite.addTestSuite(JUnitCompressingXYDataset.class);
suite.addTestSuite(JUnitDefaultCompressor.class);
suite.addTestSuite(JUnitDefaultXYLayoutGenerator.class);
suite.addTestSuite(JUnitLinearXYAxis.class);
suite.addTestSuite(JUnitLinearXYPlotLine.class);
suite.addTestSuite(JUnitLinearXYPlotLineYIndependent.class);
suite.addTestSuite(JUnitScatterXYPlotLine.class);
suite.addTestSuite(JUnitSimpleXYDataset.class);
suite.addTestSuite(JUnitSlopeLine.class);
suite.addTestSuite(JUnitSlopeLineDisplay.class);
suite.addTestSuite(JUnitXYAxis.class);
suite.addTestSuite(JUnitXYGrid.class);
suite.addTestSuite(JUnitXYLocationDisplay.class);
suite.addTestSuite(JUnitXYMarkerLine.class);
suite.addTestSuite(JUnitXYPlot.class);
suite.addTestSuite(JUnitXYPlotLine.class);
suite.addTestSuite(JUnitXYReversingDataset.class);
return suite;
}
} | false | Plotter_src_test_java_plotter_xy_JUnitXY.java |
2,009 | public class JUnitXYAxis extends TestCase {
private static class TestAxis extends XYAxis {
private static final long serialVersionUID = 1L;
private TestAxis(XYDimension d) {
super(d);
}
@Override
public double toLogical(int n) {
return n;
}
@Override
public int toPhysical(double d) {
return (int) d;
}
}
public void testPaintX() throws InterruptedException, InvocationTargetException {
XYAxis axis = createAxis(XYDimension.X);
axis.setStartMargin(10);
CountingGraphics g = paint(axis);
assertEquals(12, g.getPointCount());
LineChecker c = new LineChecker();
// main line
c.require(10, 0, 199, 0);
// major tick marks
c.require(10, 0, 10, 5);
c.require(110, 0, 110, 5);
c.require(210, 0, 210, 5);
// minor tick marks
c.require(20, 0, 20, 3);
c.require(30, 0, 30, 3);
c.check(g.getLines());
}
public void testPaintXNoStartMargin() throws InterruptedException, InvocationTargetException {
XYAxis axis = createAxis(XYDimension.X);
axis.setStartMargin(0);
CountingGraphics g = paint(axis);
assertEquals(12, g.getPointCount());
LineChecker c = new LineChecker();
// main line
c.require(0, 0, 199, 0);
// major tick marks
c.require(0, 0, 0, 5);
c.require(100, 0, 100, 5);
c.require(200, 0, 200, 5);
// minor tick marks
c.require(10, 0, 10, 3);
c.require(20, 0, 20, 3);
c.check(g.getLines());
}
public void testPaintY() throws InterruptedException, InvocationTargetException {
XYAxis axis = createAxis(XYDimension.Y);
axis.setStartMargin(10);
CountingGraphics g = paint(axis);
assertEquals(12, g.getPointCount());
LineChecker c = new LineChecker();
// main line
c.require(199, 189, 199, 0);
// major tick marks
c.require(194, 189, 199, 189);
c.require(194, 89, 199, 89);
c.require(194, -11, 199, -11);
// minor tick marks
c.require(196, 179, 199, 179);
c.require(196, 169, 199, 169);
c.check(g.getLines());
}
public void testPaintYNoStartMargin() throws InterruptedException, InvocationTargetException {
XYAxis axis = createAxis(XYDimension.Y);
axis.setStartMargin(0);
CountingGraphics g = paint(axis);
assertEquals(12, g.getPointCount());
LineChecker c = new LineChecker();
// main line
c.require(199, 199, 199, 0);
// major tick marks
c.require(194, 199, 199, 199);
c.require(194, 99, 199, 99);
c.require(194, -1, 199, -1);
// minor tick marks
c.require(196, 189, 199, 189);
c.require(196, 179, 199, 179);
c.check(g.getLines());
}
private XYAxis createAxis(XYDimension dimension) {
XYAxis axis = new TestAxis(dimension);
axis.setStart(0);
axis.setEnd(200);
axis.setMajorTickLength(5);
axis.setMinorTickLength(3);
axis.setMajorTicks(new int[] {0, 100, 200});
axis.setMinorTicks(new int[] {10, 20});
return axis;
}
private CountingGraphics paint(XYAxis axis) throws InterruptedException, InvocationTargetException {
return paint(axis, null);
}
// Ensures that the line is 200x200, paints it, and returns the stats.
// We can't use 100x100 because on Mac OSX, the minimum frame width is 128.
private CountingGraphics paint(final XYAxis axis, Shape clip) throws InterruptedException, InvocationTargetException {
final JFrame frame = new JFrame();
frame.getContentPane().add(axis);
BufferedImage image = new BufferedImage(200, 200, BufferedImage.TYPE_3BYTE_BGR);
final Graphics2D imageG = image.createGraphics();
final CountingGraphics g = new CountingGraphics(imageG);
try {
if(clip != null) {
g.setClip(clip);
}
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
try {
frame.pack();
int xo = 200 - axis.getWidth();
int yo = 200 - axis.getHeight();
frame.setSize(frame.getWidth() + xo, frame.getHeight() + yo);
frame.validate();
// These are sanity checks to make sure our setup is correct, not actual functionality tests.
assertEquals(200, axis.getWidth());
assertEquals(200, axis.getHeight());
axis.paint(g);
} finally {
frame.dispose();
}
}
});
} finally {
imageG.dispose();
}
return g;
}
} | false | Plotter_src_test_java_plotter_xy_JUnitXYAxis.java |
2,010 | SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
try {
frame.pack();
int xo = 200 - axis.getWidth();
int yo = 200 - axis.getHeight();
frame.setSize(frame.getWidth() + xo, frame.getHeight() + yo);
frame.validate();
// These are sanity checks to make sure our setup is correct, not actual functionality tests.
assertEquals(200, axis.getWidth());
assertEquals(200, axis.getHeight());
axis.paint(g);
} finally {
frame.dispose();
}
}
}); | false | Plotter_src_test_java_plotter_xy_JUnitXYAxis.java |
2,011 | private static class TestAxis extends XYAxis {
private static final long serialVersionUID = 1L;
private TestAxis(XYDimension d) {
super(d);
}
@Override
public double toLogical(int n) {
return n;
}
@Override
public int toPhysical(double d) {
return (int) d;
}
} | false | Plotter_src_test_java_plotter_xy_JUnitXYAxis.java |
2,012 | public class JUnitXYGrid extends TestCase {
private XYGrid grid;
private XYPlot plot;
@Override
protected void setUp() throws Exception {
LinearXYAxis xAxis = new LinearXYAxis(XYDimension.X);
LinearXYAxis yAxis = new LinearXYAxis(XYDimension.Y);
xAxis.setStart(0);
xAxis.setEnd(1);
yAxis.setStart(0);
yAxis.setEnd(1);
xAxis.setPreferredSize(new Dimension(1, 10));
yAxis.setPreferredSize(new Dimension(10, 1));
xAxis.setTickMarkCalculator(new TickMarkCalculator() {
@Override
public double[][] calculateTickMarks(Axis axis) {
return new double[][] { { 0, .25, .5, .75, 1 }, {} };
}
});
yAxis.setTickMarkCalculator(new TickMarkCalculator() {
@Override
public double[][] calculateTickMarks(Axis axis) {
return new double[][] { { 0, .25, .5, .75, 1 }, {} };
}
});
grid = new XYGrid(xAxis, yAxis);
XYPlotContents contents = new XYPlotContents();
contents.add(grid);
plot = new XYPlot();
plot.add(contents);
plot.add(xAxis);
plot.add(yAxis);
plot.setXAxis(xAxis);
plot.setYAxis(yAxis);
new DefaultXYLayoutGenerator().generateLayout(plot);
}
public void testPaintSimple() throws InterruptedException, InvocationTargetException {
CountingGraphics g = paint();
LineChecker c = new LineChecker();
c.require(199, 0, 199, 200);
c.require(149, 0, 149, 200);
c.require(99, 0, 99, 200);
c.require(49, 0, 49, 200);
c.require(0, 150, 200, 150);
c.require(0, 100, 200, 100);
c.require(0, 50, 200, 50);
c.require(0, 0, 200, 0);
c.check(g.getLines());
}
public void testPaintClip() throws InterruptedException, InvocationTargetException {
CountingGraphics g = paint(new Rectangle(25, 25, 50, 2));
LineChecker c = new LineChecker();
c.require(49, 24, 49, 27);
c.check(g.getLines());
}
public void testPaintClipCustomStroke() throws InterruptedException, InvocationTargetException {
grid.setStroke(new BasicStroke(1, 0, 0, 1, new float[] { 5, 5 }, 0));
CountingGraphics g = paint(new Rectangle(25, 25, 50, 2));
LineChecker c = new LineChecker();
c.require(49, 20, 49, 27);
c.check(g.getLines());
}
public void testPaintClipNonBasicStroke() throws InterruptedException, InvocationTargetException {
grid.setStroke(new Stroke() {
Stroke s = new BasicStroke(1, 0, 0, 1, new float[] { 4, 4 }, 0);
@Override
public Shape createStrokedShape(Shape p) {
return s.createStrokedShape(p);
}
});
CountingGraphics g = paint(new Rectangle(25, 25, 50, 2));
LineChecker c = new LineChecker();
c.require(49, 0, 49, 199);
c.check(g.getLines());
}
private CountingGraphics paint() throws InterruptedException, InvocationTargetException {
return paint(null);
}
// Ensures that the line is 200x200, paints it, and returns the stats.
// We can't use 100x100 because on Mac OSX, the minimum frame width is 128.
private CountingGraphics paint(Shape clip) throws InterruptedException, InvocationTargetException {
final JFrame frame = new JFrame();
frame.getContentPane().add(plot);
BufferedImage image = new BufferedImage(200, 200, BufferedImage.TYPE_3BYTE_BGR);
final Graphics2D imageG = image.createGraphics();
final CountingGraphics g = new CountingGraphics(imageG);
try {
if(clip != null) {
g.setClip(clip);
}
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
try {
frame.pack();
int xo = 200 - grid.getWidth();
int yo = 200 - grid.getHeight();
frame.setSize(frame.getWidth() + xo, frame.getHeight() + yo);
frame.validate();
// These are sanity checks to make sure our setup is correct, not actual functionality tests.
assertEquals(200, grid.getWidth());
assertEquals(200, grid.getHeight());
grid.paint(g);
} finally {
frame.dispose();
}
}
});
} finally {
imageG.dispose();
}
return g;
}
} | false | Plotter_src_test_java_plotter_xy_JUnitXYGrid.java |
2,013 | xAxis.setTickMarkCalculator(new TickMarkCalculator() {
@Override
public double[][] calculateTickMarks(Axis axis) {
return new double[][] { { 0, .25, .5, .75, 1 }, {} };
}
}); | false | Plotter_src_test_java_plotter_xy_JUnitXYGrid.java |
2,014 | yAxis.setTickMarkCalculator(new TickMarkCalculator() {
@Override
public double[][] calculateTickMarks(Axis axis) {
return new double[][] { { 0, .25, .5, .75, 1 }, {} };
}
}); | false | Plotter_src_test_java_plotter_xy_JUnitXYGrid.java |
2,015 | grid.setStroke(new Stroke() {
Stroke s = new BasicStroke(1, 0, 0, 1, new float[] { 4, 4 }, 0);
@Override
public Shape createStrokedShape(Shape p) {
return s.createStrokedShape(p);
}
}); | false | Plotter_src_test_java_plotter_xy_JUnitXYGrid.java |
2,016 | SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
try {
frame.pack();
int xo = 200 - grid.getWidth();
int yo = 200 - grid.getHeight();
frame.setSize(frame.getWidth() + xo, frame.getHeight() + yo);
frame.validate();
// These are sanity checks to make sure our setup is correct, not actual functionality tests.
assertEquals(200, grid.getWidth());
assertEquals(200, grid.getHeight());
grid.paint(g);
} finally {
frame.dispose();
}
}
}); | false | Plotter_src_test_java_plotter_xy_JUnitXYGrid.java |
2,017 | public class JUnitXYLocationDisplay extends TestCase {
public void testFailIfNoContents() {
XYLocationDisplay display = new XYLocationDisplay();
XYPlot plot = new XYPlot();
try {
display.attach(plot);
fail("Should throw an exception");
} catch(IllegalArgumentException e) {
// should happen
}
}
public void testGeneral() {
XYLocationDisplay display = new XYLocationDisplay();
MessageFormat format = new MessageFormat("{0} {1}");
display.setFormat(format);
assertSame(format, display.getFormat());
XYPlot plot = new XYPlot();
XYPlotContents contents = new XYPlotContents();
plot.add(contents);
LinearXYAxis xAxis = new LinearXYAxis(XYDimension.X);
LinearXYAxis yAxis = new LinearXYAxis(XYDimension.Y);
plot.add(xAxis);
plot.add(yAxis);
plot.setXAxis(xAxis);
plot.setYAxis(yAxis);
contents.setSize(100, 100);
xAxis.setSize(100, 1);
yAxis.setSize(1, 100);
xAxis.setStartMargin(0);
yAxis.setStartMargin(0);
xAxis.setStart(0);
xAxis.setEnd(100);
yAxis.setStart(0);
yAxis.setEnd(100);
display.attach(plot);
// The mouse should not affect the display until it enters
display.mouseMoved(new MouseEvent(contents, MouseEvent.MOUSE_MOVED, System.currentTimeMillis(), 0, 0, 0, 0, false));
assertEquals("", display.getText());
display.mouseEntered(new MouseEvent(contents, MouseEvent.MOUSE_ENTERED, System.currentTimeMillis(), 0, 0, 0, 0, false));
display.mouseMoved(new MouseEvent(contents, MouseEvent.MOUSE_MOVED, System.currentTimeMillis(), 0, 25, 25, 0, false));
assertEquals("26 75", display.getText());
display.mouseDragged(new MouseEvent(contents, MouseEvent.MOUSE_DRAGGED, System.currentTimeMillis(), 0, 75, 75, 0, false));
assertEquals("76 25", display.getText());
// These aren't used, but make sure they don't affect anything or throw exceptions
display.mousePressed(new MouseEvent(contents, MouseEvent.MOUSE_PRESSED, System.currentTimeMillis(), 0, 0, 0, 0, false));
display.mouseReleased(new MouseEvent(contents, MouseEvent.MOUSE_RELEASED, System.currentTimeMillis(), 0, 0, 0, 0, false));
display.mouseClicked(new MouseEvent(contents, MouseEvent.MOUSE_CLICKED, System.currentTimeMillis(), 0, 0, 0, 0, false));
// Exiting should always clear the display
display.mouseExited(new MouseEvent(contents, MouseEvent.MOUSE_EXITED, System.currentTimeMillis(), 0, 0, 0, 0, false));
assertEquals("", display.getText());
}
} | false | Plotter_src_test_java_plotter_xy_JUnitXYLocationDisplay.java |
2,018 | public class JUnitXYMarkerLine extends TestCase {
private TestXYMarkerLine line;
private XYPlot plot;
private void setupX() {
XYAxis xAxis = new LinearXYAxis(XYDimension.X);
XYAxis yAxis = new LinearXYAxis(XYDimension.Y);
xAxis.setStart(0);
xAxis.setEnd(1);
yAxis.setStart(0);
yAxis.setEnd(1);
line = new TestXYMarkerLine(xAxis, .5);
XYPlotContents contents = new XYPlotContents();
contents.add(line);
plot = new XYPlot();
plot.add(contents);
plot.add(xAxis);
plot.add(yAxis);
plot.setXAxis(xAxis);
plot.setYAxis(yAxis);
new DefaultXYLayoutGenerator().generateLayout(plot);
}
private void setupY() {
XYAxis xAxis = new LinearXYAxis(XYDimension.X);
XYAxis yAxis = new LinearXYAxis(XYDimension.Y);
xAxis.setStart(0);
xAxis.setEnd(1);
yAxis.setStart(0);
yAxis.setEnd(1);
line = new TestXYMarkerLine(yAxis, .5);
XYPlotContents contents = new XYPlotContents();
contents.add(line);
plot = new XYPlot();
plot.add(contents);
plot.add(xAxis);
plot.add(yAxis);
plot.setXAxis(xAxis);
plot.setYAxis(yAxis);
new DefaultXYLayoutGenerator().generateLayout(plot);
}
public void testPaintSimple() throws InterruptedException, InvocationTargetException {
setupX();
line.setValue(.5);
CountingGraphics g = paint();
assertEquals(2, g.getPointCount());
LineChecker c = new LineChecker();
c.require(99, 0, 99, 200);
c.check(g.getLines());
}
public void testPaintSimpleY() throws InterruptedException, InvocationTargetException {
setupY();
line.setValue(.5);
CountingGraphics g = paint();
assertEquals(2, g.getPointCount());
LineChecker c = new LineChecker();
c.require(0, 100, 200, 100);
c.check(g.getLines());
}
public void testPaintClip() throws InterruptedException, InvocationTargetException {
setupX();
line.setValue(.5);
CountingGraphics g = paint(new Rectangle(150, 0, 50, 200));
assertEquals(0, g.getPointCount());
}
public void testPaintClipY() throws InterruptedException, InvocationTargetException {
setupY();
line.setValue(.5);
CountingGraphics g = paint(new Rectangle(0, 200, 150, 50));
assertEquals(0, g.getPointCount());
}
public void testPaintClipPartial() throws InterruptedException, InvocationTargetException {
setupX();
line.setValue(.5);
CountingGraphics g = paint(new Rectangle(0, 49, 200, 100));
LineChecker c = new LineChecker();
c.require(99, 48, 99, 149);
c.check(g.getLines());
}
public void testPaintClipPartialY() throws InterruptedException, InvocationTargetException {
setupY();
line.setValue(.5);
CountingGraphics g = paint(new Rectangle(49, 0, 100, 200));
LineChecker c = new LineChecker();
c.require(48, 100, 149, 100);
c.check(g.getLines());
}
public void testPaintClipPartialCustomStroke() throws InterruptedException, InvocationTargetException {
setupX();
line.setStroke(new BasicStroke(1, 0, 0, 1, new float[] { 5, 5 }, 0));
line.setValue(.5);
CountingGraphics g = paint(new Rectangle(0, 49, 200, 100));
LineChecker c = new LineChecker();
c.require(99, 40, 99, 149);
c.check(g.getLines());
}
public void testPaintClipPartialCustomStrokeY() throws InterruptedException, InvocationTargetException {
setupY();
line.setStroke(new BasicStroke(1, 0, 0, 1, new float[] { 5, 5 }, 0));
line.setValue(.5);
CountingGraphics g = paint(new Rectangle(49, 0, 100, 200));
LineChecker c = new LineChecker();
c.require(40, 100, 149, 100);
c.check(g.getLines());
}
public void testPaintClipPartialNonBasicStroke() throws InterruptedException, InvocationTargetException {
setupX();
line.setStroke(new Stroke() {
Stroke s = new BasicStroke(1, 0, 0, 1, new float[] { 4, 4 }, 0);
@Override
public Shape createStrokedShape(Shape p) {
return s.createStrokedShape(p);
}
});
line.setValue(.5);
CountingGraphics g = paint(new Rectangle(0, 49, 200, 100));
LineChecker c = new LineChecker();
c.require(99, 0, 99, 200);
c.check(g.getLines());
}
public void testPaintClipPartialNonBasicStrokeY() throws InterruptedException, InvocationTargetException {
setupY();
line.setStroke(new Stroke() {
Stroke s = new BasicStroke(1, 0, 0, 1, new float[] { 4, 4 }, 0);
@Override
public Shape createStrokedShape(Shape p) {
return s.createStrokedShape(p);
}
});
line.setValue(.5);
CountingGraphics g = paint(new Rectangle(49, 0, 100, 200));
LineChecker c = new LineChecker();
c.require(0, 100, 200, 100);
c.check(g.getLines());
}
public void testRepaintTinyChange() {
// Same pixel, should not repaint
setupX();
line.setSize(100, 100);
plot.getXAxis().setStartMargin(0);
plot.getXAxis().setSize(100, 1);
line.setValue(.5);
line.repaints.clear();
line.setValue(.501);
assertTrue(line.repaints.isEmpty());
}
public void testRepaintTinyChangeY() {
// Same pixel, should not repaint
setupY();
line.setSize(100, 100);
plot.getYAxis().setStartMargin(0);
plot.getYAxis().setSize(1, 100);
line.setValue(.5);
line.repaints.clear();
line.setValue(.501);
assertTrue(line.repaints.isEmpty());
}
public void testRepaintSmallChange() {
// Adjacent pixel, should combine into one repaint
setupX();
line.setSize(100, 100);
plot.getXAxis().setStartMargin(0);
plot.getXAxis().setSize(100, 1);
line.setValue(.5);
line.repaints.clear();
line.setValue(.51);
assertEquals(1, line.repaints.size());
assertTrue(line.repaints.contains(new Rectangle(49, 0, 2, 100)));
}
public void testRepaintSmallChangeY() {
// Adjacent pixel, should combine into one repaint
setupY();
line.setSize(100, 100);
plot.getYAxis().setStartMargin(0);
plot.getYAxis().setSize(1, 100);
line.setValue(.5);
line.repaints.clear();
line.setValue(.51);
assertEquals(1, line.repaints.size());
assertTrue(line.repaints.contains(new Rectangle(0, 49, 100, 2)));
}
public void testRepaintBigChange() {
// Far apart pixels, should issue separate repaints
setupX();
line.setSize(100, 100);
plot.getXAxis().setStartMargin(0);
plot.getXAxis().setSize(100, 1);
line.setValue(.5);
line.repaints.clear();
line.setValue(.9);
assertEquals(2, line.repaints.size());
assertTrue(line.repaints.contains(new Rectangle(49, 0, 1, 100)));
assertTrue(line.repaints.contains(new Rectangle(89, 0, 1, 100)));
}
public void testRepaintBigChangeY() {
// Far apart pixels, should issue separate repaints
setupY();
line.setSize(100, 100);
plot.getYAxis().setStartMargin(0);
plot.getYAxis().setSize(1, 100);
line.setValue(.5);
line.repaints.clear();
line.setValue(.9);
assertEquals(2, line.repaints.size());
assertTrue(line.repaints.contains(new Rectangle(0, 50, 100, 1)));
assertTrue(line.repaints.contains(new Rectangle(0, 10, 100, 1)));
}
private CountingGraphics paint() throws InterruptedException, InvocationTargetException {
return paint(null);
}
// Ensures that the line is 200x200, paints it, and returns the stats.
// We can't use 100x100 because on Mac OSX, the minimum frame width is 128.
private CountingGraphics paint(Shape clip) throws InterruptedException, InvocationTargetException {
final JFrame frame = new JFrame();
frame.getContentPane().add(plot);
BufferedImage image = new BufferedImage(200, 200, BufferedImage.TYPE_3BYTE_BGR);
final Graphics2D imageG = image.createGraphics();
final CountingGraphics g = new CountingGraphics(imageG);
try {
if(clip != null) {
g.setClip(clip);
}
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
try {
frame.pack();
int xo = 200 - line.getWidth();
int yo = 200 - line.getHeight();
frame.setSize(frame.getWidth() + xo, frame.getHeight() + yo);
frame.validate();
// These are sanity checks to make sure our setup is correct, not actual functionality tests.
assertEquals(200, line.getWidth());
assertEquals(200, line.getHeight());
line.paint(g);
} finally {
frame.dispose();
}
}
});
} finally {
imageG.dispose();
}
return g;
}
private static class TestXYMarkerLine extends XYMarkerLine {
private static final long serialVersionUID = 1L;
List<Rectangle> repaints = new ArrayList<Rectangle>();
private TestXYMarkerLine(XYAxis axis, double value) {
super(axis, value);
}
public void repaint(int x, int y, int width, int height) {
repaints.add(new Rectangle(x, y, width, height));
super.repaint(x, y, width, height);
}
}
} | false | Plotter_src_test_java_plotter_xy_JUnitXYMarkerLine.java |
2,019 | line.setStroke(new Stroke() {
Stroke s = new BasicStroke(1, 0, 0, 1, new float[] { 4, 4 }, 0);
@Override
public Shape createStrokedShape(Shape p) {
return s.createStrokedShape(p);
}
}); | false | Plotter_src_test_java_plotter_xy_JUnitXYMarkerLine.java |
2,020 | line.setStroke(new Stroke() {
Stroke s = new BasicStroke(1, 0, 0, 1, new float[] { 4, 4 }, 0);
@Override
public Shape createStrokedShape(Shape p) {
return s.createStrokedShape(p);
}
}); | false | Plotter_src_test_java_plotter_xy_JUnitXYMarkerLine.java |
2,021 | SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
try {
frame.pack();
int xo = 200 - line.getWidth();
int yo = 200 - line.getHeight();
frame.setSize(frame.getWidth() + xo, frame.getHeight() + yo);
frame.validate();
// These are sanity checks to make sure our setup is correct, not actual functionality tests.
assertEquals(200, line.getWidth());
assertEquals(200, line.getHeight());
line.paint(g);
} finally {
frame.dispose();
}
}
}); | false | Plotter_src_test_java_plotter_xy_JUnitXYMarkerLine.java |
2,022 | private static class TestXYMarkerLine extends XYMarkerLine {
private static final long serialVersionUID = 1L;
List<Rectangle> repaints = new ArrayList<Rectangle>();
private TestXYMarkerLine(XYAxis axis, double value) {
super(axis, value);
}
public void repaint(int x, int y, int width, int height) {
repaints.add(new Rectangle(x, y, width, height));
super.repaint(x, y, width, height);
}
} | false | Plotter_src_test_java_plotter_xy_JUnitXYMarkerLine.java |
2,023 | public class JUnitXYPlot extends TestCase {
public void testToPhysical() {
XYPlot plot = new XYPlot();
LinearXYAxis xAxis = new LinearXYAxis(XYDimension.X);
LinearXYAxis yAxis = new LinearXYAxis(XYDimension.Y);
plot.setXAxis(xAxis);
plot.setYAxis(yAxis);
xAxis.setStart(1);
xAxis.setEnd(2);
yAxis.setStart(2);
yAxis.setEnd(3);
xAxis.setSize(200, 1);
yAxis.setSize(1, 200);
Point2D src = new Point2D.Double(1.1, 2.2);
plot.toPhysical(src, src);
assertEquals(new Point2D.Double(19, 160), src);
}
public void testPaintComponent() {
XYPlot plot = new XYPlot();
plot.setBackground(new Color(1, 2, 3));
plot.setSize(100, 100);
BufferedImage image = new BufferedImage(plot.getWidth(), plot.getHeight(), BufferedImage.TYPE_3BYTE_BGR);
Graphics g = image.getGraphics();
plot.paintComponent(g);
g.dispose();
WritableRaster raster = image.getRaster();
int[] data = new int[3];
for(int x = 0; x < 100; x++) {
for(int y = 0; y < 100; y++) {
raster.getPixel(x, y, data);
assertEquals(1, data[0]);
assertEquals(2, data[1]);
assertEquals(3, data[2]);
}
}
}
} | false | Plotter_src_test_java_plotter_xy_JUnitXYPlot.java |
2,024 | public class JUnitXYPlotLine extends TestCase {
private XYPlotLine line;
protected void setUp() {
line = new XYPlotLine() {
@Override
public void repaintData(int index, int count) {
}
@Override
public void repaintData(int index) {
}
@Override
public void removeLast(int removeCount) {
}
@Override
public void removeFirst(int removeCount) {
}
@Override
public void removeAllPoints() {
}
@Override
public void prepend(double[] x, int xoff, double[] y, int yoff, int len) {
}
@Override
public void prepend(DoubleData x, DoubleData y) {
}
@Override
public DoubleData getYData() {
return null;
}
@Override
public DoubleData getXData() {
return null;
}
@Override
public XYDimension getIndependentDimension() {
return null;
}
@Override
public void add(double x, double y) {
}
};
}
public void testProperties() throws InvocationTargetException, IllegalAccessException, IntrospectionException {
PropertyTester t = new PropertyTester(line);
t.test("pointFill", null, new GeneralPath());
t.test("pointOutline", null, new GeneralPath());
}
} | false | Plotter_src_test_java_plotter_xy_JUnitXYPlotLine.java |
2,025 | line = new XYPlotLine() {
@Override
public void repaintData(int index, int count) {
}
@Override
public void repaintData(int index) {
}
@Override
public void removeLast(int removeCount) {
}
@Override
public void removeFirst(int removeCount) {
}
@Override
public void removeAllPoints() {
}
@Override
public void prepend(double[] x, int xoff, double[] y, int yoff, int len) {
}
@Override
public void prepend(DoubleData x, DoubleData y) {
}
@Override
public DoubleData getYData() {
return null;
}
@Override
public DoubleData getXData() {
return null;
}
@Override
public XYDimension getIndependentDimension() {
return null;
}
@Override
public void add(double x, double y) {
}
}; | false | Plotter_src_test_java_plotter_xy_JUnitXYPlotLine.java |
2,026 | public class JUnitXYReversingDataset extends TestCase {
final List<Point2D> points = new ArrayList<Point2D>();
public void testAll() {
DummyXYDataset base = new DummyXYDataset();
XYReversingDataset d = new XYReversingDataset(base);
d.add(1, 2);
assertEquals(1, d.getPointCount());
assertEquals(1, points.size());
assertEquals(new Point2D.Double(2, 1), points.get(0));
DoubleData xData = new DoubleData();
DoubleData yData = new DoubleData();
xData.add(2);
yData.add(3);
xData.add(3);
yData.add(4);
d.prepend(xData, yData);
assertEquals(3, d.getPointCount());
assertEquals(3, points.size());
assertEquals(new Point2D.Double(4, 3), points.get(0));
assertEquals(new Point2D.Double(3, 2), points.get(1));
d.prepend(new double[] { 4, 5 }, 0, new double[] { 5, 6 }, 0, 2);
assertEquals(5, d.getPointCount());
assertEquals(5, points.size());
assertEquals(new Point2D.Double(6, 5), points.get(0));
assertEquals(new Point2D.Double(5, 4), points.get(1));
d.removeLast(1);
assertEquals(4, d.getPointCount());
assertEquals(4, points.size());
d.removeAllPoints();
assertEquals(0, d.getPointCount());
assertEquals(0, points.size());
}
private class DummyXYDataset implements XYDataset {
@Override
public int getPointCount() {
return points.size();
}
@Override
public void removeAllPoints() {
points.clear();
}
@Override
public void add(double x, double y) {
points.add(new Point2D.Double(x, y));
}
@Override
public void removeLast(int count) {
points.subList(points.size() - count, points.size()).clear();
}
@Override
public void prepend(double[] x, int xoff, double[] y, int yoff, int len) {
for(int i = 0; i < len; i++) {
points.add(0, new Point2D.Double(x[xoff + i], y[yoff + i]));
}
}
@Override
public void prepend(DoubleData x, DoubleData y) {
int n = x.getLength();
for(int i = 0; i < n; i++) {
points.add(0, new Point2D.Double(x.get(i), y.get(i)));
}
}
}
} | false | Plotter_src_test_java_plotter_xy_JUnitXYReversingDataset.java |
2,027 | private class DummyXYDataset implements XYDataset {
@Override
public int getPointCount() {
return points.size();
}
@Override
public void removeAllPoints() {
points.clear();
}
@Override
public void add(double x, double y) {
points.add(new Point2D.Double(x, y));
}
@Override
public void removeLast(int count) {
points.subList(points.size() - count, points.size()).clear();
}
@Override
public void prepend(double[] x, int xoff, double[] y, int yoff, int len) {
for(int i = 0; i < len; i++) {
points.add(0, new Point2D.Double(x[xoff + i], y[yoff + i]));
}
}
@Override
public void prepend(DoubleData x, DoubleData y) {
int n = x.getLength();
for(int i = 0; i < n; i++) {
points.add(0, new Point2D.Double(x.get(i), y.get(i)));
}
}
} | false | Plotter_src_test_java_plotter_xy_JUnitXYReversingDataset.java |
2,028 | public class LinearXYAxis extends XYAxis {
private static final long serialVersionUID = 1L;
/** Start value of the axis at the time the labels were cached. */
private double labelCacheStart = Double.NaN;
/** End value of the axis at the time the labels were cached. */
private double labelCacheEnd = Double.NaN;
/** Values of the major tick marks. */
private double[] majorVals;
/** Values of the minor tick marks. */
private double[] minorVals;
/** Calculates tick marks and labels for the axis. */
private TickMarkCalculator tickMarkCalculator = new LinearTickMarkCalculator();
/** Format used to display values in labels. */
private NumberFormat format = NumberFormat.getInstance();
/**
* Creates an axis.
* @param d dimension the axis represents
*/
public LinearXYAxis(XYDimension d) {
super(d);
}
@Override
public void doLayout() {
super.doLayout();
double start = getStart();
double end = getEnd();
double diff = end - start;
XYDimension plotDimension = getPlotDimension();
int startMargin = getStartMargin();
int width = getWidth();
int height = getHeight();
int size = (plotDimension == XYDimension.X ? width : height) - startMargin - getEndMargin();
// Labels only need to be recreated if the min or max changes.
// Otherwise, they simply need to be repositioned.
if(start != labelCacheStart || end != labelCacheEnd) {
double[][] ticks = tickMarkCalculator.calculateTickMarks(this);
majorVals = ticks[0];
minorVals = ticks[1];
labelCacheStart = start;
labelCacheEnd = end;
}
// Calculate the physical locations of the tick marks from the logical locations.
int[] major = new int[majorVals.length];
int[] minor = new int[minorVals.length];
for(int i = 0; i < major.length; i++) {
major[i] = (int) ((majorVals[i] - start) / diff * size + .5) - 1;
}
for(int i = 0; i < minor.length; i++) {
minor[i] = (int) ((minorVals[i] - start) / diff * size + .5) - 1;
}
setMajorTicks(major);
setMinorTicks(minor);
if(isShowLabels()) {
updateLabels();
} else {
removeAll();
}
}
/**
* Updates labels to match the tick marks.
* Labels may be added, removed, or repositioned.
*/
private void updateLabels() {
int[] major = getMajorTicks();
int width = getWidth();
int height = getHeight();
int startMargin = getStartMargin();
XYDimension plotDimension = getPlotDimension();
double diff = getEnd() - getStart();
Component[] components = getComponents();
// oldLabels contains the original labels that have not been reused.
Set<AxisLabel> oldLabels = new HashSet<AxisLabel>(components.length);
for(Component c : components) {
oldLabels.add((AxisLabel) c);
}
// maxLabelError defines the largest absolute difference between a label's value and the needed value.
// If the error is greater than this, the label is not reused.
double maxLabelError = .01 * Math.abs(diff);
AxisLabel[] labels = new AxisLabel[majorVals.length];
for(int i = 0; i < labels.length; i++) {
labels[i] = createLabel(majorVals[i], oldLabels, maxLabelError);
}
// Remove labels that have not been reused.
for(AxisLabel oldLabel : oldLabels) {
remove(oldLabel);
}
// Position the labels to line up with the corresponding tick marks.
int textMargin = getTextMargin();
boolean inverted = getEnd() < getStart();
if(plotDimension == XYDimension.X) {
for(int i = 0; i < major.length; i++) {
Component label = labels[i];
double preferredSize = label.getPreferredSize().getWidth();
double end = preferredSize / 2;
double start = -end;
if(inverted) {
if(i < major.length - 1) {
start = Math.max(start, (major[i + 1] - major[i]) / 2);
}
if(i > 0) {
end = Math.min(end, (major[i - 1] - major[i]) / 2);
}
} else {
if(i > 0) {
start = Math.max(start, (major[i - 1] - major[i]) / 2);
}
if(i < major.length - 1) {
end = Math.min(end, (major[i + 1] - major[i]) / 2);
}
}
double labelWidth = end - start;
label.setSize((int) labelWidth, label.getHeight());
label.setLocation((int) (start + startMargin + major[i]), textMargin);
}
} else {
int height2 = height - startMargin;
int width2 = width - textMargin;
for(int i = 0; i < major.length; i++) {
Component label = labels[i];
double preferredSize = label.getPreferredSize().getHeight();
double end = preferredSize / 2;
double start = -end;
if(inverted) {
if(i < major.length - 1) {
start = Math.max(start, (major[i + 1] - major[i]) / 2);
}
if(i > 0) {
end = Math.min(end, (major[i - 1] - major[i]) / 2);
}
} else {
if(i > 0) {
start = Math.max(start, (major[i - 1] - major[i]) / 2);
}
if(i < major.length - 1) {
end = Math.min(end, (major[i + 1] - major[i]) / 2);
}
}
double labelHeight = end - start;
int labelWidth = label.getWidth();
label.setSize(labelWidth, (int) labelHeight);
label.setLocation(width2 - labelWidth, (int) (height2 - major[i] - end));
}
}
}
/**
* Creates a label for the given value.
* A label may instead be reused (and removed) from the <code>oldLabels</code> set.
* @param value value the label displays
* @param oldLabels labels that may be reused
* @param maxLabelError largest absolute difference between a label's value and <code>value</code> that allows a label to be reused
* @return the label, which may be new or reused
*/
private AxisLabel createLabel(double value, Set<AxisLabel> oldLabels, double maxLabelError) {
for(AxisLabel oldLabel : oldLabels) {
// Value is the same, reuse the label.
// It is currently assumed that if the value is close enough, the text doesn't change.
// For well-behaved tick mark calculators and label formats, this should be true. (Use rounding!)
// The new text could be calculated, but that is expensive.
if(Math.abs(value - oldLabel.getValue()) < maxLabelError) {
oldLabels.remove(oldLabel);
return oldLabel;
}
}
AxisLabel label = new AxisLabel(value, format.format(value));
Rotation labelRotation = getLabelRotation();
if(labelRotation != null) {
label.putClientProperty(Rotation.class.getName(), labelRotation);
}
label.setUI(MultiLineLabelUI.labelUI);
label.setForeground(getForeground());
label.setFont(getFont());
add(label);
label.setSize(label.getPreferredSize());
return label;
}
@Override
public int toPhysical(double d) {
double min = getStart();
double max = getEnd();
int endMargin = getEndMargin();
if(getPlotDimension() == XYDimension.X) {
int width = getWidth();
int startMargin = getStartMargin();
return (int) ((d - min) / (max - min) * (width - startMargin - endMargin) + .5) + getStartMargin() - 1;
} else {
int height = getHeight() - getStartMargin();
return height - (int) ((d - min) / (max - min) * (height - endMargin) + .5);
}
}
@Override
public double toLogical(int n) {
double min = getStart();
double max = getEnd();
int endMargin = getEndMargin();
if(getPlotDimension() == XYDimension.X) {
int width = getWidth();
int startMargin = getStartMargin();
return (n - startMargin + 1) * 1.0 / (width - startMargin - endMargin) * (max - min) + min;
} else {
int height = getHeight() - getStartMargin() - endMargin;
return (height - n + endMargin) * 1.0 / height * (max - min) + min;
}
}
/**
* Sets the foreground color.
* Overridden to update the color of the labels.
* @param color the foreground color
*/
@Override
public void setForeground(Color color) {
super.setForeground(color);
for(Component c : getComponents()) {
c.setForeground(color);
}
}
/**
* Sets the font.
* Overridden to update the font of the labels.
* @param font the font
*/
@Override
public void setFont(Font font) {
super.setFont(font);
for(Component c : getComponents()) {
c.setFont(font);
}
}
/**
* Returns the tick mark calculator.
* @return the tick mark calculator
*/
public TickMarkCalculator getTickMarkCalculator() {
return tickMarkCalculator;
}
/**
* Sets the tick mark calculator.
* @param tickMarkCalculator the tick mark calculator
*/
public void setTickMarkCalculator(TickMarkCalculator tickMarkCalculator) {
this.tickMarkCalculator = tickMarkCalculator;
}
/**
* Returns the format for the labels.
* @return the format for the labels
*/
public NumberFormat getFormat() {
return format;
}
/**
* Sets the format for the labels.
* @param format the format for the labels
*/
public void setFormat(NumberFormat format) {
this.format = format;
}
} | false | Plotter_src_main_java_plotter_xy_LinearXYAxis.java |
2,029 | public class LinearXYPlotLine extends XYPlotLine implements XYDataset {
private static final long serialVersionUID = 1L;
/** The X data. */
private DoubleData xData = new DoubleData();
/** The Y data. */
private DoubleData yData = new DoubleData();
/** The X axis, used to retrieve the min and max. */
private XYAxis xAxis;
/** The Y axis, used to retrieve the min and max. */
private XYAxis yAxis;
/** The algorithm used to draw the line. */
private LineMode lineMode = LineMode.STRAIGHT;
/** The stroke used to draw the line, or null to use the default. */
private Stroke stroke;
/** Specifies which lines to draw around a missing/invalid point. */
private MissingPointMode missingPointMode = MissingPointMode.NONE;
/** The independent dimension stores data in increasing or decreasing order. May be null for a scatter plot or parametric plot, although this is not supported yet. */
private XYDimension independentDimension;
/**
* Creates a plot line.
* The independent dimension stores data in increasing or decreasing order. May be null for a scatter plot or parametric plot, although this is not supported yet.
* @param xAxis the X axis
* @param yAxis the Y axis
* @param independentDimension the independent dimension
*/
public LinearXYPlotLine(XYAxis xAxis, XYAxis yAxis, XYDimension independentDimension) {
this.xAxis = xAxis;
this.yAxis = yAxis;
this.independentDimension = independentDimension;
}
@Override
protected void paintComponent(Graphics g) {
int n = xData.getLength();
Graphics2D g2 = (Graphics2D) g;
final double xstart = xAxis.getStart();
final double xend = xAxis.getEnd();
final double ystart = yAxis.getStart();
final double yend = yAxis.getEnd();
final int width = getWidth();
final int height = getHeight();
g2.setColor(getForeground());
if(stroke != null) {
g2.setStroke(stroke);
}
// Skip the points that are outside our clipping area
// TODO: Support a stop index, not just a start index
int index;
if(independentDimension == XYDimension.X) {
int clipx;
if(xstart < xend) {
clipx = g.getClipBounds().x;
} else {
clipx = (int) g.getClipBounds().getMaxX();
}
clipx = toAxisX(clipx) - 1;
double min = xAxis.toLogical(clipx);
index = xData.binarySearch(min);
if(index < 0) {
index = -index - 1;
}
index--;
} else {
int clipy;
if(ystart < yend) {
clipy = (int) g.getClipBounds().getMaxY();
} else {
clipy = (int) g.getClipBounds().getMinY();
}
clipy = toAxisY(clipy) - 1;
double min = yAxis.toLogical(clipy);
index = yData.binarySearch(min);
if(index < 0) {
index = -index - 1;
}
index--;
}
int i = Math.max(0, index);
double xscale = width / (xend - xstart);
double yscale = height / (yend - ystart);
int[] pointsx = new int[(n - i) * 2];
int[] pointsy = new int[pointsx.length];
DoubleData dependentData = independentDimension == XYDimension.Y ? xData : yData;
// Loop through all the points to draw.
outer: while(i < n - 1) {
// Find the first non-NaN point.
while(Double.isNaN(dependentData.get(i))) {
i++;
if(i == n) {
break outer;
}
}
int x = (int) ((xData.get(i) - xstart) * xscale + .5) - 1;
int y = height - (int) ((yData.get(i) - ystart) * yscale + .5);
int points = 0;
if(missingPointMode == MissingPointMode.RIGHT || missingPointMode == MissingPointMode.BOTH) {
if(i > 0 && i > index) {
if(independentDimension == XYDimension.X) {
pointsx[points] = (int) ((xData.get(i - 1) - xstart) * xscale + .5) - 1;
pointsy[points] = y;
points++;
} else if(independentDimension == XYDimension.Y) {
pointsy[points] = height - (int) ((yData.get(i - 1) - ystart) * yscale + .5);
pointsx[points] = x;
points++;
}
}
}
pointsx[points]=x;
pointsy[points]=y;
points++;
i++;
// Add points until we come to the end or a NaN point.
while(i < n) {
if(Double.isNaN(dependentData.get(i))) {
if(missingPointMode == MissingPointMode.BOTH || missingPointMode == MissingPointMode.LEFT) {
if(independentDimension == XYDimension.X) {
double xd = xData.get(i);
int x2 = (int) ((xd - xstart) * xscale + .5) - 1;
pointsx[points] = x2;
pointsy[points] = y;
points++;
} else if(independentDimension == XYDimension.Y) {
double yd = yData.get(i);
int y2 = height - (int) ((yd - ystart) * yscale + .5);
pointsx[points] = x;
pointsy[points] = y2;
points++;
}
}
i++;
break;
}
double xd = xData.get(i);
double yd = yData.get(i);
int x2 = (int) ((xd - xstart) * xscale + .5) - 1;
int y2 = height - (int) ((yd - ystart) * yscale + .5);
if(lineMode == LineMode.STRAIGHT) {
pointsx[points]=x2;
pointsy[points]=y2;
points++;
} else if(lineMode == LineMode.STEP_XY) {
pointsx[points]=x2;
pointsy[points]=y;
points++;
pointsx[points]=x2;
pointsy[points]=y2;
points++;
} else {
pointsx[points]=x;
pointsy[points]=y2;
points++;
pointsx[points]=x2;
pointsy[points]=y2;
points++;
}
x = x2;
y = y2;
i++;
}
if(points > 1) {
g2.drawPolyline(pointsx, pointsy, points);
}
}
if(pointFill != null || pointOutline != null || pointIcon != null) {
int oldx = 0;
int oldy = 0;
for(i = Math.max(0, index); i < n; i++) {
double xx = xData.get(i);
double yy = yData.get(i);
if(!Double.isNaN(xx) && !Double.isNaN(yy)) {
int x = (int) ((xx - xstart) * xscale + .5) - 1;
int y = height - (int) ((yy - ystart) * yscale + .5);
g2.translate(x - oldx, y - oldy);
if(pointFill != null) {
g2.fill(pointFill);
}
if(pointOutline != null) {
g2.draw(pointOutline);
}
if(pointIcon != null) {
pointIcon.paintIcon(this, g2, 0, 0);
}
oldx = x;
oldy = y;
}
}
}
}
private int toAxisX(int x) {
// Assumption: plot line is contained in an XYPlotContents, which is contained in an XYPlot. xAxis is contained in the XYPlot.
return x + getParent().getX() - xAxis.getX();
}
private int toAxisY(int y) {
// Assumption: plot line is contained in an XYPlotContents, which is contained in an XYPlot. yAxis is contained in the XYPlot.
return y + getParent().getY() - yAxis.getY();
}
/**
* Repaints a data point and adjoining line segments.
* @param index index of the data point
*/
@Override
public void repaintData(int index) {
// Implementation note:
// We don't call repaintData(int,int) with a count of 1
// because this method gets called a lot (from SimpleXYDataset.add, for example)
// so we want it to be fast.
// Calculate the bounding box of the line segment(s) that need to be repainted
double x = xData.get(index);
double y = yData.get(index);
XYAxis xAxis = getXAxis();
XYAxis yAxis = getYAxis();
int xmin = xAxis.toPhysical(x);
int xmax = xmin;
int ymin = yAxis.toPhysical(y);
int ymax = ymin;
// Take care of the previous point
if(index > 0) {
int x2p = xAxis.toPhysical(xData.get(index - 1));
if(x2p > xmax) {
xmax = x2p;
} else if(x2p < xmin) {
xmin = x2p;
}
int y2p = yAxis.toPhysical(yData.get(index - 1));
if(y2p > ymax) {
ymax = y2p;
} else if(y2p < ymin) {
ymin = y2p;
}
}
// Take care of the next point
if(index < xData.getLength() - 1) {
int x2p = xAxis.toPhysical(xData.get(index + 1));
if(x2p > xmax) {
xmax = x2p;
} else if(x2p < xmin) {
xmin = x2p;
}
int y2p = yAxis.toPhysical(yData.get(index + 1));
if(y2p > ymax) {
ymax = y2p;
} else if(y2p < ymin) {
ymin = y2p;
}
}
// Adjust for offsets.
int xo = toAxisX(0);
int yo = toAxisY(0);
xmin -= xo;
xmax -= xo;
ymin -= yo;
ymax -= yo;
// Add a fudge factor, just to be sure.
int fudge = 1;
xmin -= fudge;
xmax += fudge;
ymin -= fudge;
ymax += fudge;
repaint(xmin, ymin, xmax - xmin, ymax - ymin);
}
/**
* Repaints data points and adjoining line segments.
* @param index index of the first data point
* @param count number of data points
*/
@Override
public void repaintData(int index, int count) {
if(count == 0) {
return;
}
// Calculate the bounding box of the line segment(s) that need to be repainted
XYAxis xAxis = getXAxis();
XYAxis yAxis = getYAxis();
double xmin = Double.POSITIVE_INFINITY;
double xmax = Double.NEGATIVE_INFINITY;
double ymin = Double.POSITIVE_INFINITY;
double ymax = Double.NEGATIVE_INFINITY;
// Take care of the interior points
for(int i = 0; i < count; i++) {
double x = xData.get(index + i);
double y = yData.get(index + i);
if(x > xmax) {
xmax = x;
}
if(x < xmin) {
xmin = x;
}
if(y > ymax) {
ymax = y;
}
if(y < ymin) {
ymin = y;
}
}
// Take care of the previous point
if(index > 0) {
double x = xData.get(index - 1);
if(x > xmax) {
xmax = x;
}
if(x < xmin) {
xmin = x;
}
double y = yData.get(index - 1);
if(y > ymax) {
ymax = y;
}
if(y < ymin) {
ymin = y;
}
}
// Take care of the next point
if(index + count < xData.getLength()) {
double x = xData.get(index + count);
if(x > xmax) {
xmax = x;
}
if(x < xmin) {
xmin = x;
}
double y = yData.get(index + count);
if(y > ymax) {
ymax = y;
}
if(y < ymin) {
ymin = y;
}
}
int xmin2 = xAxis.toPhysical(xmin);
int xmax2 = xAxis.toPhysical(xmax);
int ymin2 = yAxis.toPhysical(ymin);
int ymax2 = yAxis.toPhysical(ymax);
if(xmin2 > xmax2) {
int tmp = xmin2;
xmin2 = xmax2;
xmax2 = tmp;
}
if(ymin2 > ymax2) {
int tmp = ymin2;
ymin2 = ymax2;
ymax2 = tmp;
}
// Adjust for offsets.
int xo = toAxisX(0);
int yo = toAxisY(0);
xmin2 -= xo;
xmax2 -= xo;
ymin2 -= yo;
ymax2 -= yo;
// Add a fudge factor, just to be sure.
int fudge = 1;
xmin2 -= fudge;
xmax2 += fudge;
ymin2 -= fudge;
ymax2 += fudge;
repaint(xmin2, ymin2, xmax2 - xmin2, ymax2 - ymin2);
}
/**
* Returns the X data.
* @return the X data
*/
@Override
public DoubleData getXData() {
return xData;
}
/**
* Sets the X data.
* @param xData the X data
*/
public void setXData(DoubleData xData) {
this.xData = xData;
}
/**
* Returns the Y data.
* @return the Y data
*/
@Override
public DoubleData getYData() {
return yData;
}
/**
* Sets the Y data.
* @param yData the Y data
*/
public void setYData(DoubleData yData) {
this.yData = yData;
}
/**
* Returns the X axis.
* @return the X axis
*/
public XYAxis getXAxis() {
return xAxis;
}
/**
* Returns the Y axis.
* @return the Y axis
*/
public XYAxis getYAxis() {
return yAxis;
}
/**
* Returns the line mode used for connecting points.
* @return the line mode used for connecting points
*/
public LineMode getLineMode() {
return lineMode;
}
/**
* Sets the line mode used for connecting points.
* @param lineMode the line mode used for connecting points
*/
public void setLineMode(LineMode lineMode) {
this.lineMode = lineMode;
}
/**
* Returns the stroke used to draw the line.
* @return the stroke used to draw the line
*/
public Stroke getStroke() {
return stroke;
}
/**
* Sets the stroke used to draw the line.
* @param stroke the stroke used to draw the line
*/
public void setStroke(Stroke stroke) {
this.stroke = stroke;
}
/**
* Returns the missing point mode.
* @return the missing point mode
*/
public MissingPointMode getMissingPointMode() {
return missingPointMode;
}
/**
* Sets the missing point mode.
* @param missingPointMode the missing point mode
*/
public void setMissingPointMode(MissingPointMode missingPointMode) {
this.missingPointMode = missingPointMode;
}
/**
* Returns the independent dimension. May be null.
* @return the independent dimension
*/
@Override
public XYDimension getIndependentDimension() {
return independentDimension;
}
@Override
public void prepend(double[] x, int xoff, double[] y, int yoff, int len) {
xData.prepend(x, xoff, len);
yData.prepend(y, yoff, len);
repaintData(0, len);
}
@Override
public void prepend(DoubleData x, DoubleData y) {
int len = x.getLength();
if(len != y.getLength()) {
throw new IllegalArgumentException("x and y must be the same length. x.length = " + x.getLength() + ", y.length = " + y.getLength());
}
xData.prepend(x, 0, len);
yData.prepend(y, 0, len);
repaintData(0, len);
}
@Override
public int getPointCount() {
return xData.getLength();
}
@Override
public void removeAllPoints() {
xData.removeAll();
yData.removeAll();
repaint();
}
@Override
public void add(double x, double y) {
xData.add(x);
yData.add(y);
repaintData(xData.getLength() - 1);
}
@Override
public void removeFirst(int removeCount) {
repaintData(0, removeCount);
xData.removeFirst(removeCount);
yData.removeFirst(removeCount);
}
@Override
public void removeLast(int count) {
repaintData(xData.getLength() - count, count);
xData.removeLast(count);
yData.removeLast(count);
}
/**
* A line mode specifies how lines are drawn connecting points.
*/
public enum LineMode {
/**
* Straight lines are drawn between points.
*/
STRAIGHT,
/**
* A horizontal line is drawn to the new point's X coordinate, then a vertical line is drawn.
*/
STEP_XY,
/**
* A vertical line is drawn the the new point's Y coordinate, then a horizontal line is drawn.
*/
STEP_YX
}
} | false | Plotter_src_main_java_plotter_xy_LinearXYPlotLine.java |
2,030 | public enum LineMode {
/**
* Straight lines are drawn between points.
*/
STRAIGHT,
/**
* A horizontal line is drawn to the new point's X coordinate, then a vertical line is drawn.
*/
STEP_XY,
/**
* A vertical line is drawn the the new point's Y coordinate, then a horizontal line is drawn.
*/
STEP_YX
} | false | Plotter_src_main_java_plotter_xy_LinearXYPlotLine.java |
2,031 | public enum MissingPointMode {
/**
* Don't draw either line.
*/
NONE,
/**
* Draw the line from the previous point.
*/
LEFT,
/**
* Draw the line to the next point.
*/
RIGHT,
/**
* Draw the lines on either side.
*/
BOTH
} | false | Plotter_src_main_java_plotter_xy_MissingPointMode.java |
2,032 | public class PointData implements CompressionOutput {
private DoubleData x;
private DoubleData y;
/**
* Creates point data with new default {@link DoubleData} objects for X and Y.
*/
public PointData() {
this(new DoubleData(), new DoubleData());
}
/**
* Creates point data using the given X and Y data.
* @param x X data
* @param y Y data
*/
public PointData(DoubleData x, DoubleData y) {
this.x = x;
this.y = y;
}
/**
* Returns the X data.
* @return the X data
*/
public DoubleData getX() {
return x;
}
/**
* Sets the X data.
* @param x the X data
*/
public void setX(DoubleData x) {
this.x = x;
}
/**
* Returns the Y data.
* @return the Y data
*/
public DoubleData getY() {
return y;
}
/**
* Sets the Y data.
* @param y the Y data
*/
public void setY(DoubleData y) {
this.y = y;
}
/**
* Convenience method for adding a point.
* Equivalent to:
* <pre>
* PointData d = ...;
* d.getX().add(x);
* d.getY().add(y);
* </pre>
* @param x X coordinate of the point to add
* @param y Y coordinate of the point to add
*/
@Override
public void add(double x, double y) {
this.x.add(x);
this.y.add(y);
}
/**
* Removes all points.
*/
public void removeAll() {
x.removeAll();
y.removeAll();
}
/**
* Removes <code>count</code> points from the end.
* @param count number of points to remove
*/
@Override
public void removeLast(int count) {
x.removeLast(count);
y.removeLast(count);
}
@Override
public int getPointCount() {
return x.getLength();
}
} | false | Plotter_src_main_java_plotter_xy_PointData.java |
2,033 | public class ScatterXYPlotLine extends XYPlotLine implements XYDataset {
private static final long serialVersionUID = 1L;
private static final int DEFAULT_LINES_PER_BOUNDING_BOX = 25;
/** The X data. */
private DoubleData xData = new DoubleData();
/** The Y data. */
private DoubleData yData = new DoubleData();
/** The X axis, used to retrieve the min and max. */
private XYAxis xAxis;
/** The Y axis, used to retrieve the min and max. */
private XYAxis yAxis;
/** The stroke used to draw the line, or null to use the default. */
private Stroke stroke;
/** Number of line segments per bounding box. */
private int linesPerBoundingBox;
/** Number of line segments missing from the beginning of the first bounding box. */
private int boundingBoxOffset;
/** Bounding boxes for consecutive groups of line segments. */
private List<Rectangle2D> boundingBoxes = new ArrayList<Rectangle2D>();
/**
* Creates a plot line.
* @param xAxis the X axis
* @param yAxis the Y axis
*/
public ScatterXYPlotLine(XYAxis xAxis, XYAxis yAxis) {
this(xAxis, yAxis, DEFAULT_LINES_PER_BOUNDING_BOX);
}
/**
* Creates a plot line.
* @param xAxis the X axis
* @param yAxis the Y axis
* @param linesPerBoundingBox lines per bounding box, a tuning parameter for clipping
*/
public ScatterXYPlotLine(XYAxis xAxis, XYAxis yAxis, int linesPerBoundingBox) {
this.xAxis = xAxis;
this.yAxis = yAxis;
this.linesPerBoundingBox = linesPerBoundingBox;
}
private boolean invariants() {
assert 0 <= boundingBoxOffset && boundingBoxOffset < linesPerBoundingBox : "boundingBoxOffset = " + boundingBoxOffset
+ ", linesPerBoundingBox = " + linesPerBoundingBox;
int expectedSize = (xData.getLength() + boundingBoxOffset + linesPerBoundingBox - 1) / linesPerBoundingBox;
assert boundingBoxes.size() == expectedSize : "Expected boundingBoxes to be of size " + expectedSize + ", but was " + boundingBoxes.size();
if(!boundingBoxes.isEmpty()) {
assert firstIndex(0) == 0 : "firstIndex(0) = " + firstIndex(0);
}
if(boundingBoxes.size() > 0) {
assert firstIndex(1) == linesPerBoundingBox - boundingBoxOffset : "firstIndex(1) = " + firstIndex(1) + ", linesPerBoundingBox = "
+ linesPerBoundingBox;
}
return true;
}
@Override
protected void paintComponent(Graphics g) {
assert invariants();
int n = xData.getLength();
Graphics2D g2 = (Graphics2D) g;
final double xstart = xAxis.getStart();
final double xend = xAxis.getEnd();
final double ystart = yAxis.getStart();
final double yend = yAxis.getEnd();
final int width = getWidth();
final int height = getHeight();
g2.setColor(getForeground());
if(stroke != null) {
g2.setStroke(stroke);
}
// Convert the clipping rectangle to logical coordinates
Rectangle clipBounds = g2.getClipBounds();
double xscale = width / (xend - xstart);
double yscale = height / (yend - ystart);
double xmin = xstart + (clipBounds.getMinX() - 1) / xscale;
double xmax = xstart + (clipBounds.getMaxX() + 1) / xscale;
double ymin = ystart + (height - clipBounds.getMinY() + 1) / yscale;
double ymax = ystart + (height - clipBounds.getMaxY() - 1) / yscale;
if(xmin > xmax) {
double tmp = xmin;
xmin = xmax;
xmax = tmp;
}
if(ymin > ymax) {
double tmp = ymin;
ymin = ymax;
ymax = tmp;
}
Rectangle2D clipLogical = new Rectangle2D.Double(xmin, ymin, xmax - xmin, ymax - ymin);
// Only paint lines in bounding boxes that intersect the logical clipping rectangle
int boxCount = boundingBoxes.size();
for(int k = 0; k < boxCount; k++) {
Rectangle2D box = boundingBoxes.get(k);
if(box != null && box.intersects(clipLogical)) {
int index = firstIndex(k);
int endIndex = Math.min(n, index + linesPerBoundingBox + 1);
int i = index;
int[] pointsx = new int[(n - i) * 2];
int[] pointsy = new int[pointsx.length];
// Loop through all the points to draw.
outer: while(i < endIndex - 1) {
// Find the first non-NaN point.
while(Double.isNaN(xData.get(i)) || Double.isNaN(yData.get(i))) {
i++;
if(i == n) {
break outer;
}
}
int x = (int) ((xData.get(i) - xstart) * xscale + .5) - 1;
int y = height - (int) ((yData.get(i) - ystart) * yscale + .5);
int points = 0;
pointsx[points] = x;
pointsy[points] = y;
points++;
i++;
// Add points until we come to the end or a NaN point.
while(i < endIndex) {
double xd = xData.get(i);
double yd = yData.get(i);
if(Double.isNaN(xd) || Double.isNaN(yd)) {
i++;
break;
}
int x2 = (int) ((xd - xstart) * xscale + .5) - 1;
int y2 = height - (int) ((yd - ystart) * yscale + .5);
pointsx[points] = x2;
pointsy[points] = y2;
points++;
x = x2;
y = y2;
i++;
}
if(points > 1) {
g2.drawPolyline(pointsx, pointsy, points);
}
}
}
}
if(pointFill != null || pointOutline != null) {
for(int k = 0; k < boxCount; k++) {
Rectangle2D box = boundingBoxes.get(k);
if(box == null || !box.intersects(clipLogical)) {
continue;
}
int index = firstIndex(k);
int endIndex = Math.min(n, index + linesPerBoundingBox + 1);
int oldx = 0;
int oldy = 0;
for(int i = index; i < endIndex; i++) {
double xx = xData.get(i);
double yy = yData.get(i);
if(Double.isNaN(xx) || Double.isNaN(yy)) {
continue;
}
int x = (int) ((xx - xstart) * xscale + .5) - 1;
int y = height - (int) ((yy - ystart) * yscale + .5);
g2.translate(x - oldx, y - oldy);
if(pointFill != null) {
g2.fill(pointFill);
}
if(pointOutline != null) {
g2.draw(pointOutline);
}
oldx = x;
oldy = y;
}
}
}
assert invariants();
}
/**
* Returns the index of the first point in this bounding box.
* @param boundingBoxIndex bounding box index
* @return index of the first point in this bounding box
*/
private int firstIndex(int boundingBoxIndex) {
return Math.max(0, boundingBoxIndex * linesPerBoundingBox - boundingBoxOffset);
}
private int toAxisX(int x) {
// Assumption: plot line is contained in an XYPlotContents, which is contained in an XYPlot. xAxis is contained in the XYPlot.
return x + getParent().getX() - xAxis.getX();
}
private int toAxisY(int y) {
// Assumption: plot line is contained in an XYPlotContents, which is contained in an XYPlot. yAxis is contained in the XYPlot.
return y + getParent().getY() - yAxis.getY();
}
/**
* Repaints a data point and adjoining line segments.
* @param index index of the data point
*/
@Override
public void repaintData(int index) {
// Implementation note:
// We don't call repaintData(int,int) with a count of 1
// because this method gets called a lot (from SimpleXYDataset.add, for example)
// so we want it to be fast.
// Calculate the bounding box of the line segment(s) that need to be repainted
double x = xData.get(index);
double y = yData.get(index);
XYAxis xAxis = getXAxis();
XYAxis yAxis = getYAxis();
int xmin = xAxis.toPhysical(x);
int xmax = xmin;
int ymin = yAxis.toPhysical(y);
int ymax = ymin;
// Take care of the previous point
if(index > 0) {
int x2p = xAxis.toPhysical(xData.get(index - 1));
if(x2p > xmax) {
xmax = x2p;
} else if(x2p < xmin) {
xmin = x2p;
}
int y2p = yAxis.toPhysical(yData.get(index - 1));
if(y2p > ymax) {
ymax = y2p;
} else if(y2p < ymin) {
ymin = y2p;
}
}
// Take care of the next point
if(index < xData.getLength() - 1) {
int x2p = xAxis.toPhysical(xData.get(index + 1));
if(x2p > xmax) {
xmax = x2p;
} else if(x2p < xmin) {
xmin = x2p;
}
int y2p = yAxis.toPhysical(yData.get(index + 1));
if(y2p > ymax) {
ymax = y2p;
} else if(y2p < ymin) {
ymin = y2p;
}
}
// Adjust for offsets.
int xo = toAxisX(0);
int yo = toAxisY(0);
xmin -= xo;
xmax -= xo;
ymin -= yo;
ymax -= yo;
// Add a fudge factor, just to be sure.
int fudge = 1;
xmin -= fudge;
xmax += fudge;
ymin -= fudge;
ymax += fudge;
repaint(xmin, ymin, xmax - xmin, ymax - ymin);
}
/**
* Repaints data points and adjoining line segments.
* @param index index of the first data point
* @param count number of data points
*/
@Override
public void repaintData(int index, int count) {
if(count == 0) {
return;
}
// Calculate the bounding box of the line segment(s) that need to be repainted
XYAxis xAxis = getXAxis();
XYAxis yAxis = getYAxis();
double xmin = Double.POSITIVE_INFINITY;
double xmax = Double.NEGATIVE_INFINITY;
double ymin = Double.POSITIVE_INFINITY;
double ymax = Double.NEGATIVE_INFINITY;
// Take care of the interior points
for(int i = 0; i < count; i++) {
double x = xData.get(index + i);
double y = yData.get(index + i);
if(x > xmax) {
xmax = x;
}
if(x < xmin) {
xmin = x;
}
if(y > ymax) {
ymax = y;
}
if(y < ymin) {
ymin = y;
}
}
// Take care of the previous point
if(index > 0) {
double x = xData.get(index - 1);
if(x > xmax) {
xmax = x;
}
if(x < xmin) {
xmin = x;
}
double y = yData.get(index - 1);
if(y > ymax) {
ymax = y;
}
if(y < ymin) {
ymin = y;
}
}
// Take care of the next point
if(index + count < xData.getLength()) {
double x = xData.get(index + count);
if(x > xmax) {
xmax = x;
}
if(x < xmin) {
xmin = x;
}
double y = yData.get(index + count);
if(y > ymax) {
ymax = y;
}
if(y < ymin) {
ymin = y;
}
}
int xmin2 = xAxis.toPhysical(xmin);
int xmax2 = xAxis.toPhysical(xmax);
int ymin2 = yAxis.toPhysical(ymin);
int ymax2 = yAxis.toPhysical(ymax);
if(xmin2 > xmax2) {
int tmp = xmin2;
xmin2 = xmax2;
xmax2 = tmp;
}
if(ymin2 > ymax2) {
int tmp = ymin2;
ymin2 = ymax2;
ymax2 = tmp;
}
// Adjust for offsets.
int xo = toAxisX(0);
int yo = toAxisY(0);
xmin2 -= xo;
xmax2 -= xo;
ymin2 -= yo;
ymax2 -= yo;
// Add a fudge factor, just to be sure.
int fudge = 1;
xmin2 -= fudge;
xmax2 += fudge;
ymin2 -= fudge;
ymax2 += fudge;
repaint(xmin2, ymin2, xmax2 - xmin2, ymax2 - ymin2);
}
/**
* Returns the X data.
* @return the X data
*/
@Override
public DoubleData getXData() {
return xData;
}
/**
* Sets the X data.
* @param xData the X data
*/
public void setXData(DoubleData xData) {
this.xData = xData;
}
/**
* Returns the Y data.
* @return the Y data
*/
@Override
public DoubleData getYData() {
return yData;
}
/**
* Sets the Y data.
* @param yData the Y data
*/
public void setYData(DoubleData yData) {
this.yData = yData;
}
/**
* Returns the X axis.
* @return the X axis
*/
public XYAxis getXAxis() {
return xAxis;
}
/**
* Returns the Y axis.
* @return the Y axis
*/
public XYAxis getYAxis() {
return yAxis;
}
/**
* Returns the stroke used to draw the line.
* @return the stroke used to draw the line
*/
public Stroke getStroke() {
return stroke;
}
/**
* Sets the stroke used to draw the line.
* @param stroke the stroke used to draw the line
*/
public void setStroke(Stroke stroke) {
this.stroke = stroke;
}
/**
* Returns null.
* @return null
*/
@Override
public XYDimension getIndependentDimension() {
return null;
}
@Override
public void prepend(double[] x, int xoff, double[] y, int yoff, int len) {
assert invariants();
for(int i = len - 1; i >= 0; i--) {
double xx = x[xoff + i];
double yy = y[yoff + i];
boundingBoxOffset--;
if(boundingBoxOffset == -1) {
boundingBoxOffset = linesPerBoundingBox - 1;
boundingBoxes.add(0, null);
}
if(!Double.isNaN(xx) && !Double.isNaN(yy)) {
Rectangle2D box = boundingBoxes.get(0);
if(box == null) {
box = new Rectangle2D.Double(xx, yy, 0, 0);
boundingBoxes.set(0, box);
} else {
box.add(xx, yy);
}
}
if(xData.getLength() > 0) {
double xxx = xData.get(0);
double yyy = yData.get(0);
if(!Double.isNaN(xxx) && !Double.isNaN(yyy)) {
Rectangle2D box = boundingBoxes.get(0);
if(box == null) {
box = new Rectangle2D.Double(xxx, yyy, 0, 0);
boundingBoxes.set(0, box);
} else {
box.add(xxx, yyy);
}
}
}
}
xData.prepend(x, xoff, len);
yData.prepend(y, yoff, len);
repaintData(0, len);
assert invariants();
}
@Override
public void prepend(DoubleData x, DoubleData y) {
assert invariants();
double firstx = Double.NaN;
double firsty = Double.NaN;
if(xData.getLength() > 0) {
firstx = xData.get(0);
firsty = yData.get(0);
}
int len = x.getLength();
for(int i = len - 1; i >= 0; i--) {
double xx = x.get(i);
double yy = y.get(i);
boundingBoxOffset--;
if(boundingBoxOffset == -1) {
boundingBoxOffset = linesPerBoundingBox - 1;
boundingBoxes.add(0, null);
}
if(!Double.isNaN(xx) && !Double.isNaN(yy)) {
Rectangle2D box = boundingBoxes.get(0);
if(box == null) {
box = new Rectangle2D.Double(xx, yy, 0, 0);
boundingBoxes.set(0, box);
} else {
box.add(xx, yy);
}
}
if(!Double.isNaN(firstx) && !Double.isNaN(firsty)) {
Rectangle2D box = boundingBoxes.get(0);
if(box == null) {
box = new Rectangle2D.Double(firstx, firsty, 0, 0);
boundingBoxes.set(0, box);
} else {
box.add(firstx, firsty);
}
}
firstx = xx;
firsty = yy;
}
xData.prepend(x, 0, len);
yData.prepend(y, 0, len);
repaintData(0, len);
assert invariants();
}
@Override
public int getPointCount() {
return xData.getLength();
}
@Override
public void removeAllPoints() {
assert invariants();
xData.removeAll();
yData.removeAll();
boundingBoxes.clear();
boundingBoxOffset = 0;
repaint();
assert invariants();
}
@Override
public void add(double x, double y) {
assert invariants();
int nPoints = xData.getLength();
int lastBoxSize = (nPoints + boundingBoxOffset + linesPerBoundingBox) % linesPerBoundingBox;
int n = boundingBoxes.size();
if(lastBoxSize == 0) {
if(n > 0 && !Double.isNaN(x) && !Double.isNaN(y)) {
Rectangle2D box = boundingBoxes.get(n - 1);
if(box == null) {
box = new Rectangle2D.Double(x, y, 0, 0);
boundingBoxes.set(n - 1, box);
} else {
box.add(x, y);
}
}
boundingBoxes.add(null);
n++;
}
if(!Double.isNaN(x) && !Double.isNaN(y)) {
Rectangle2D box = boundingBoxes.get(n - 1);
if(box == null) {
box = new Rectangle2D.Double(x, y, 0, 0);
boundingBoxes.set(n - 1, box);
} else {
box.add(x, y);
}
}
xData.add(x);
yData.add(y);
repaintData(nPoints);
assert invariants();
}
@Override
public void removeFirst(int removeCount) {
assert invariants();
repaintData(0, removeCount);
boundingBoxOffset += removeCount;
while(boundingBoxOffset >= linesPerBoundingBox) {
boundingBoxes.remove(0);
boundingBoxOffset -= linesPerBoundingBox;
}
xData.removeFirst(removeCount);
yData.removeFirst(removeCount);
assert invariants();
}
@Override
public void removeLast(int count) {
assert invariants();
int length = xData.getLength();
repaintData(length - count, count);
int boxCount = (length - count + boundingBoxOffset + linesPerBoundingBox - 1) / linesPerBoundingBox;
while(boxCount < boundingBoxes.size()) {
boundingBoxes.remove(boundingBoxes.size() - 1);
}
xData.removeLast(count);
yData.removeLast(count);
assert invariants();
}
} | false | Plotter_src_main_java_plotter_xy_ScatterXYPlotLine.java |
2,034 | public class SimpleXYDataset implements XYDataset {
/** Plot line that displays the data. */
private XYPlotLine line;
/** Holds the X data. */
private DoubleData xData;
/** Holds the Y data. */
private DoubleData yData;
/** Maximum size (inclusive) before truncating. */
private int maxCapacity = Integer.MAX_VALUE;
/** Cached minimum X value of all points in the dataset. */
private double minX = Double.POSITIVE_INFINITY;
/** Cached maximum X value of all points in the dataset. */
private double maxX = Double.NEGATIVE_INFINITY;
/** Cached minimum Y value of all points in the dataset. */
private double minY = Double.POSITIVE_INFINITY;
/** Cached maximum Y value of all points in the dataset. */
private double maxY = Double.NEGATIVE_INFINITY;
/** Listeners that get notified if the X min or max changes. May be null. */
private Set<MinMaxChangeListener> xMinMaxListeners;
/** Listeners that get notified if the Y min or max chagnes. May be null. */
private Set<MinMaxChangeListener> yMinMaxListeners;
/** Value of {@link #minX} before a modification. */
private double oldMinX;
/** Value of {@link #maxX} before a modification. */
private double oldMaxX;
/** Value of {@link #minY} before a modification. */
private double oldMinY;
/** Value of {@link #maxY} before a modification. */
private double oldMaxY;
/**
* Creates a dataset.
* @param line line to plot the data
*/
public SimpleXYDataset(XYPlotLine line) {
this.line = line;
xData = line.getXData();
yData = line.getYData();
}
/**
* Adds a point, truncating the buffer if necessary.
* The X value must be greater than or equal to all other X values in the dataset.
* @param x the X coordinate
* @param y the Y coordinate
*/
@Override
public void add(double x, double y) {
preMod();
int length = xData.getLength() + 1; // length after add
if(length > maxCapacity) {
_removeFirst(length - maxCapacity);
length = maxCapacity;
}
line.add(x, y);
updateMinMax(x, y);
postMod();
}
/**
* Called after a modification.
* Notifies any relevant listeners of changes.
*/
protected void postMod() {
if(xMinMaxListeners != null) {
if(minX != oldMinX || maxX != oldMaxX) {
for(MinMaxChangeListener listener : xMinMaxListeners) {
listener.minMaxChanged(this, XYDimension.X);
}
}
}
if(yMinMaxListeners != null) {
if(minY != oldMinY || maxY != oldMaxY) {
for(MinMaxChangeListener listener : yMinMaxListeners) {
listener.minMaxChanged(this, XYDimension.Y);
}
}
}
}
/**
* Called before a modification.
* Stores any state needed for {@link #postMod()}.
*/
protected void preMod() {
oldMinX = minX;
oldMaxX = maxX;
oldMinY = minY;
oldMaxY = maxY;
}
/**
* Removes the first <code>removeCount</code> points from the dataset.
* @param removeCount number of points to remove
*/
public void removeFirst(int removeCount) {
preMod();
_removeFirst(removeCount);
postMod();
}
/**
* Removes the first <code>removeCount</code> points from the dataset.
* Does not call {@link #preMod()} or {@link #postMod()}.
* @param removeCount number of points to remove
*/
private void _removeFirst(int removeCount) {
// TODO: Use a more efficient method than rescanning the entire arrays. For example, cache min/max values for subranges.
int length = xData.getLength();
boolean rescanX = false;
boolean rescanY = false;
for(int i = 0; i < removeCount; i++) {
double xd = xData.get(i);
double yd = yData.get(i);
if(xd == minX || xd == maxX) {
rescanX = true;
}
if(yd == minY || yd == maxY) {
rescanY = true;
}
}
if(rescanX) {
if(line.getIndependentDimension() == XYDimension.X) {
if(removeCount < length) {
minX = xData.get(removeCount);
maxX = xData.get(length - 1);
} else {
minX = Double.POSITIVE_INFINITY;
maxX = Double.NEGATIVE_INFINITY;
}
} else {
minX = Double.POSITIVE_INFINITY;
maxX = Double.NEGATIVE_INFINITY;
for(int i = removeCount; i < length; i++) {
double xd = xData.get(i);
if(xd > maxX) {
maxX = xd;
}
if(xd < minX) {
minX = xd;
}
}
}
}
if(rescanY) {
if(line.getIndependentDimension() == XYDimension.Y) {
if(removeCount < length) {
minY = yData.get(removeCount);
maxY = yData.get(length - 1);
} else {
minY = Double.POSITIVE_INFINITY;
maxY = Double.NEGATIVE_INFINITY;
}
} else {
minY = Double.POSITIVE_INFINITY;
maxY = Double.NEGATIVE_INFINITY;
for(int i = removeCount; i < length; i++) {
double yd = yData.get(i);
if(yd > maxY) {
maxY = yd;
}
if(yd < minY) {
minY = yd;
}
}
}
}
line.removeFirst(removeCount);
}
@Override
public void prepend(double[] x, int xoff, double[] y, int yoff, int len) {
preMod();
for(int i = 0; i < len; i++) {
updateMinMax(x[xoff + i], y[yoff + i]);
}
// TODO: Only add data that wouldn't be truncated
line.prepend(x, xoff, y, yoff, len);
postMod();
}
@Override
public void prepend(DoubleData x, DoubleData y) {
preMod();
int len = x.getLength();
for(int i = 0; i < len; i++) {
updateMinMax(x.get(i), y.get(i));
}
// TODO: Only add data that wouldn't be truncated
line.prepend(x, y);
postMod();
}
/**
* Updates the min/max cache to include this point.
* @param x X coordinate
* @param y Y coordinate
*/
private void updateMinMax(double x, double y) {
if(x > maxX) {
maxX = x;
}
if(x < minX) {
minX = x;
}
if(y > maxY) {
maxY = y;
}
if(y < minY) {
minY = y;
}
}
@Override
public void removeAllPoints() {
preMod();
line.removeAllPoints();
minX = Double.POSITIVE_INFINITY;
maxX = Double.NEGATIVE_INFINITY;
minY = Double.POSITIVE_INFINITY;
maxY = Double.NEGATIVE_INFINITY;
postMod();
}
@Override
public int getPointCount() {
return xData.getLength();
}
/**
* Returns the X data.
* @return the X data
*/
public DoubleData getXData() {
return xData;
}
/**
* Sets the X data.
* @param xData the X data
*/
public void setXData(DoubleData xData) {
this.xData = xData;
}
/**
* Returns the Y data.
* @return the Y data
*/
public DoubleData getYData() {
return yData;
}
/**
* Sets the Y data.
* @param yData the Y data
*/
public void setYData(DoubleData yData) {
this.yData = yData;
}
/**
* Returns the maximum size this dataset will hold.
* @return the maximum size this dataset will hold
*/
public int getMaxCapacity() {
return maxCapacity;
}
/**
* Sets the maximum size this dataset will hold.
* @param maxCapacity the maximum size this dataset will hold
*/
public void setMaxCapacity(int maxCapacity) {
this.maxCapacity = maxCapacity;
}
/**
* Returns the minimum X value.
* @return the minimum X value
*/
public double getMinX() {
return minX;
}
/**
* Returns the maximum X value.
* @return the maximum X value
*/
public double getMaxX() {
return maxX;
}
/**
* Returns the minimum Y value.
* @return the minimum Y value
*/
public double getMinY() {
return minY;
}
/**
* Returns the maximum Y value.
* @return the maximum Y value
*/
public double getMaxY() {
return maxY;
}
/**
* Adds a listener for min/max changes to the X data.
* @param listener listener to add
*/
public void addXMinMaxChangeListener(MinMaxChangeListener listener) {
if(xMinMaxListeners == null) {
xMinMaxListeners = new HashSet<MinMaxChangeListener>();
}
xMinMaxListeners.add(listener);
}
/**
* Adds a listener for min/max changes to the Y data.
* @param listener listener to add
*/
public void addYMinMaxChangeListener(MinMaxChangeListener listener) {
if(yMinMaxListeners == null) {
yMinMaxListeners = new HashSet<MinMaxChangeListener>();
}
yMinMaxListeners.add(listener);
}
/**
* Removes all {@link MinMaxChangeListener}s for the Y data.
*/
public void removeAllYMinMaxChangeListeners() {
yMinMaxListeners = null;
}
/**
* Removes all {@link MinMaxChangeListener}s for the X data.
*/
public void removeAllXMinMaxChangeListeners() {
xMinMaxListeners = null;
}
@Override
public void removeLast(int count) {
line.removeLast(count);
}
/**
* Listens to min/max changes.
* @author Adam Crume
*/
public interface MinMaxChangeListener {
/**
* Notifies the listener that the min or max changed.
* @param dataset dataset containing the data
* @param dimension specifies whether this notification is for the X or Y data
*/
public void minMaxChanged(SimpleXYDataset dataset, XYDimension dimension);
}
} | false | Plotter_src_main_java_plotter_xy_SimpleXYDataset.java |
2,035 | public interface MinMaxChangeListener {
/**
* Notifies the listener that the min or max changed.
* @param dataset dataset containing the data
* @param dimension specifies whether this notification is for the X or Y data
*/
public void minMaxChanged(SimpleXYDataset dataset, XYDimension dimension);
} | false | Plotter_src_main_java_plotter_xy_SimpleXYDataset.java |
2,036 | public class SlopeLine extends JComponent implements MouseListener, MouseMotionListener {
private static final long serialVersionUID = 1L;
private static final int CURSOR_BOX_SIZE = 4;
/** X coordinate of the point where the user started drawing a slope line. */
private int startX;
/** Y coordinate of the point where the user started drawing a slope line. */
private int startY;
/** Plot contents displaying the slope line, or null if the slope line is not displayed. */
private XYPlotContents contents;
// Note that the end points of the slope line are not guaranteed to be in any particular order.
/** X coordinate of end 1 of the slope line, or -1 to flag that the line is not yet visible. */
private int x1;
/** Y coordinate of end 1 of the slope line. */
private int y1;
/** X coordinate of end 2 of the slope line. */
private int x2;
/** Y coordinate of end 2 of the slope line. */
private int y2;
/** Maps plots to listeners for that plot. The key null is used for listeners that listen to all plots. May be null. */
private Map<XYPlot, Set<Listener>> listeners;
private boolean showSlopeLine = false;
@Override
protected void paintComponent(Graphics g) {
if(contents != null && x1 != -1) {
Color savedColor = g.getColor();
try {
g.setColor(getForeground());
int b = CURSOR_BOX_SIZE;
// Draw a small rectangle where the user originally pressed the mouse button.
g.drawRect(startX - b / 2, startY - b / 2, b, b);
// Draw the slope line itself.
g.drawLine(x1, y1, x2, y2);
} finally {
g.setColor(savedColor);
}
}
}
@Override
public void mouseClicked(MouseEvent e) {
// ignore
}
@Override
public void mouseEntered(MouseEvent e) {
// ignore
}
@Override
public void mouseExited(MouseEvent e) {
// ignore
}
@Override
public void mousePressed(MouseEvent e) {
showSlopeLine = false;
if ((e.getModifiersEx() & Integer.MAX_VALUE) == InputEvent.BUTTON1_DOWN_MASK)
showSlopeLine = true;
else
return;
startX = e.getX();
startY = e.getY();
x1 = -1;
contents = (XYPlotContents) e.getSource();
contents.add(this);
contents.revalidate();
XYPlot plot = (XYPlot) contents.getParent();
Set<Listener> set = getListenersForPlot(plot);
if(set != null) {
Point2D p = new Point2D.Double(startX, startY);
plot.toLogical(p, p);
double startLogicalX = p.getX();
double startLogicalY = p.getY();
for(Listener listener : set) {
listener.slopeLineAdded(this, plot, startLogicalX, startLogicalY);
}
}
}
@Override
public void mouseReleased(MouseEvent e) {
if (!showSlopeLine)
return;
if(contents == null) {
return;
}
contents.remove(this);
int minX = Math.min(x1, x2);
int maxX = Math.max(x1, x2);
int minY = Math.min(y1, y2);
int maxY = Math.max(y1, y2);
repaintLine(contents, minX, minY, maxX, maxY);
XYPlot plot = (XYPlot) contents.getParent();
Set<Listener> set = getListenersForPlot(plot);
if(set != null) {
for(Listener listener : set) {
listener.slopeLineRemoved(this, plot);
}
}
contents = null;
}
@Override
public void mouseDragged(MouseEvent e) {
if (!showSlopeLine)
return;
// Old bounding box
int minX = Math.min(x1, x2);
int maxX = Math.max(x1, x2);
int minY = Math.min(y1, y2);
int maxY = Math.max(y1, y2);
// Extend the line to the edges of the contents
int dx = e.getX() - startX;
int dy = e.getY() - startY;
if(dx == 0 && dy == 0) {
x1 = -1;
} else if(Math.abs(dx) > Math.abs(dy)) {
double m = dy / (double) dx;
double b = startY - m * startX;
x1 = 0;
y1 = (int) (b + .5);
x2 = getWidth();
y2 = (int) (m * x2 + b + .5);
} else {
double m = dx / (double) dy;
double b = startX - m * startY;
y1 = 0;
x1 = (int) (b + .5);
y2 = getHeight();
x2 = (int) (m * y2 + b + .5);
}
// Union the old bounding box with the new one
minX = Math.min(minX, Math.min(x1, x2));
maxX = Math.max(maxX, Math.max(x1, x2));
minY = Math.min(minY, Math.min(y1, y2));
maxY = Math.max(maxY, Math.max(y1, y2));
// Repaint the union of the old and new bounding boxes
repaintLine(this, minX, minY, maxX, maxY);
XYPlot plot = (XYPlot) contents.getParent();
Set<Listener> set = getListenersForPlot(plot);
if(set != null) {
Point2D p = new Point2D.Double(startX, startY);
plot.toLogical(p, p);
double startLogicalX = p.getX();
double startLogicalY = p.getY();
p.setLocation(e.getX(), e.getY());
plot.toLogical(p, p);
double endLogicalX = p.getX();
double endLogicalY = p.getY();
for(Listener listener : set) {
listener.slopeLineUpdated(this, plot, startLogicalX, startLogicalY, endLogicalX, endLogicalY);
}
}
}
/**
* Returns all listeners that should receive events for the plot.
* A return value of null is equivalent to the empty set.
* @param plot plot with changes
* @return relevant listeners, may be null
*/
private Set<Listener> getListenersForPlot(XYPlot plot) {
if(listeners != null) {
Set<Listener> wildcardListeners = listeners.get(null);
Set<Listener> specificListeners = listeners.get(plot);
if(wildcardListeners == null) {
return specificListeners;
} else if(specificListeners == null) {
return wildcardListeners;
} else {
Set<Listener> s = new HashSet<Listener>(wildcardListeners);
s.addAll(specificListeners);
return s;
}
}
return null;
}
/**
* Given the slope line's bounding box, repaints an area large enough to contain the bounding box and the cursor rectangle.
* @param c component to repaint
* @param minX minimum X coordinate of the bounding box
* @param minY minimum Y coordinate of the bounding box
* @param maxX maximum X coordinate of the bounding box
* @param maxY maximum Y coordinate of the bounding box
*/
private void repaintLine(Component c, int minX, int minY, int maxX, int maxY) {
int width = maxX - minX + 1;
int height = maxY - minY + 1;
if(width < CURSOR_BOX_SIZE) {
minX = (minX + maxX) / 2 - CURSOR_BOX_SIZE / 2 - 1;
width = CURSOR_BOX_SIZE + 2;
}
if(height < CURSOR_BOX_SIZE) {
minY = (minY + maxY) / 2 - CURSOR_BOX_SIZE / 2 - 1;
height = CURSOR_BOX_SIZE + 2;
}
c.repaint(minX, minY, width, height);
}
@Override
public void mouseMoved(MouseEvent e) {
// ignore
}
/**
* Attaches this slope line to a plot.
* @param plot plot to attach to
*/
public void attach(XYPlot plot) {
XYPlotContents contents = plot.getContents();
if(contents == null) {
throw new IllegalArgumentException("Plot does not contain an XYPlotContents component");
}
contents.addMouseListener(this);
contents.addMouseMotionListener(this);
}
/**
* Adds a listener for slope changes.
* @param plot plot to listen to, or null for all plots this line is attached to
* @param listener listener to add
*/
public void addListenerForPlot(XYPlot plot, Listener listener) {
if(listeners == null) {
listeners = new HashMap<XYPlot, Set<Listener>>();
}
Set<Listener> set = listeners.get(plot);
if(set == null) {
set = new HashSet<Listener>();
listeners.put(plot, set);
}
set.add(listener);
}
/**
* Listens for slope changes.
* @author Adam Crume
*/
public interface Listener {
/**
* Notifies that a slope line has been started.
* @param line line that was added
* @param plot plot the line is displayed on
* @param startX X coordinate of the start point
* @param startY Y coordinate of the start point
*/
void slopeLineAdded(SlopeLine line, XYPlot plot, double startX, double startY);
/**
* Notifies that a slope line has been updated.
* @param line line that was updated
* @param plot plot the line is displayed on
* @param startX X coordinate of the start point
* @param startY Y coordinate of the start point
* @param endX X coordinate of the end point
* @param endY Y coordinate of the end point
*/
void slopeLineUpdated(SlopeLine line, XYPlot plot, double startX, double startY, double endX, double endY);
/**
* Notifies that a slope line has been hidden.
* @param line line that was hidden
* @param plot plot that the line was displayed on
*/
void slopeLineRemoved(SlopeLine line, XYPlot plot);
}
} | false | Plotter_src_main_java_plotter_xy_SlopeLine.java |
2,037 | public interface Listener {
/**
* Notifies that a slope line has been started.
* @param line line that was added
* @param plot plot the line is displayed on
* @param startX X coordinate of the start point
* @param startY Y coordinate of the start point
*/
void slopeLineAdded(SlopeLine line, XYPlot plot, double startX, double startY);
/**
* Notifies that a slope line has been updated.
* @param line line that was updated
* @param plot plot the line is displayed on
* @param startX X coordinate of the start point
* @param startY Y coordinate of the start point
* @param endX X coordinate of the end point
* @param endY Y coordinate of the end point
*/
void slopeLineUpdated(SlopeLine line, XYPlot plot, double startX, double startY, double endX, double endY);
/**
* Notifies that a slope line has been hidden.
* @param line line that was hidden
* @param plot plot that the line was displayed on
*/
void slopeLineRemoved(SlopeLine line, XYPlot plot);
} | false | Plotter_src_main_java_plotter_xy_SlopeLine.java |
2,038 | public class SlopeLineDisplay extends JLabel implements SlopeLine.Listener {
private static final long serialVersionUID = 1L;
/** Formats the slope information. The format is given three arguments: the X difference, the Y difference, and the slope. */
private MessageFormat format = new MessageFormat("dx: {0} dy: {1}");
@Override
public void slopeLineAdded(SlopeLine slopeLine, XYPlot plot, double startX, double startY) {
// ignore
}
@Override
public void slopeLineRemoved(SlopeLine line, XYPlot plot) {
setText("");
}
@Override
public void slopeLineUpdated(SlopeLine line, XYPlot plot, double startX, double startY, double endX, double endY) {
if(startX == endX && startY == endY) {
setText("");
} else {
double dx = endX - startX;
double dy = endY - startY;
setText(format.format(new Object[] { dx, dy, dy / dx }));
}
}
/**
* Returns the format used to display the data.
* @return the format used to display the data
*/
public MessageFormat getFormat() {
return format;
}
/**
* Sets the format used to display the data.
* The format is given three arguments: the X difference, the Y difference, and the slope.
* @param format the format used to display the data
*/
public void setFormat(MessageFormat format) {
this.format = format;
}
} | false | Plotter_src_main_java_plotter_xy_SlopeLineDisplay.java |
2,039 | public abstract class XYAxis extends Axis {
private static final long serialVersionUID = 1L;
private static final int[] EMPTY = new int[0];
/** Specifies which dimension this axis controls. */
private final XYDimension plotDimension;
/** Distance in pixels of the major ticks from the min location. */
private int[] majorTicks = EMPTY;
/** Distance in pixels of the minor ticks from the min location. */
private int[] minorTicks = EMPTY;
/** Number of pixels this axis overlaps the other axis. */
private int startMargin;
/** Number of pixels at the end that serve as margin. */
private int endMargin;
/** Listeners that get notified when the tick marks change. */
private Set<TicksChangedListener> tickListeners = new HashSet<TicksChangedListener>();
/** Specifies how the labels are oriented. */
private Rotation labelRotation;
/**
* Creates an axis.
* @param d dimension controlled by this axis
*/
public XYAxis(XYDimension d) {
assert d != null;
this.plotDimension = d;
setOpaque(false);
}
@Override
protected void paintComponent(Graphics g) {
int width = getWidth();
int height = getHeight();
g = g.create();
if(plotDimension == XYDimension.X) {
width -= startMargin + endMargin;
g.translate(startMargin, 0);
} else {
height -= startMargin + endMargin;
g.translate(0, endMargin);
}
g.setColor(getForeground());
int majorTickLength = getMajorTickLength();
int minorTickLength = getMinorTickLength();
if(plotDimension == XYDimension.X) {
g.drawLine(0, 0, width - 1, 0);
for(int x : getMajorTicks()) {
g.drawLine(x, 0, x, majorTickLength);
}
for(int x : getMinorTicks()) {
g.drawLine(x, 0, x, minorTickLength);
}
} else {
g.drawLine(width - 1, height - 1, width - 1, 0);
for(int y : getMajorTicks()) {
g.drawLine(width - 1 - majorTickLength, height - 1 - y, width - 1, height - 1 - y);
}
for(int y : getMinorTicks()) {
g.drawLine(width - 1 - minorTickLength, height - 1 - y, width - 1, height - 1 - y);
}
}
}
/**
* Converts a logical coordinate to a physical one.
* @param d logical coordinate
* @return physical coordinate
*/
public abstract int toPhysical(double d);
/**
* Converts a physical coordinate to a logical one.
* @param n physical coordinate
* @return logical coordinate
*/
public abstract double toLogical(int n);
/**
* Returns the dimension this axis controls.
* @return the dimension this axis controls
*/
public XYDimension getPlotDimension() {
return plotDimension;
}
/**
* Returns the number of pixels at the start that serve as margin.
* @return margin, in pixels
*/
public int getStartMargin() {
return startMargin;
}
/**
* Sets the number of pixels at the start that serve as margin.
* @param startMargin margin, in pixels
*/
public void setStartMargin(int startMargin) {
this.startMargin = startMargin;
}
/**
* Returns the number of pixels at the end that serve as margin.
* @return margin, in pixels
*/
public int getEndMargin() {
return endMargin;
}
/**
* Sets the number of pixels at the end that serve as margin.
* @param endMargin margin, in pixels
*/
public void setEndMargin(int endMargin) {
this.endMargin = endMargin;
}
/**
* Do not modify the returned array.
* @return distance of the major tick marks from the beginning of the axis, in pixels
*/
public int[] getMajorTicks() {
return majorTicks;
}
/**
* Sets the major tick marks.
* All {@link TicksChangedListener}s are notified.
* @param majorTicks physical locations of the major tick marks
*/
protected void setMajorTicks(int[] majorTicks) {
assert majorTicks != null;
this.majorTicks = majorTicks;
for(TicksChangedListener listener : tickListeners) {
listener.ticksChanged(this);
}
}
/**
* Do not modify the returned array.
* @return distance of the minor ticks from the beginning of the axis, in pixels
*/
public int[] getMinorTicks() {
return minorTicks;
}
/**
* Sets the locations of the minor ticks.
* @param minorTicks physical locations of the minor tick marks
*/
protected void setMinorTicks(int[] minorTicks) {
assert minorTicks != null;
this.minorTicks = minorTicks;
}
/**
* Adds a tick listener.
* @param listener listener to add
*/
public void addTickListener(TicksChangedListener listener) {
tickListeners.add(listener);
}
/**
* Returns the label rotation.
* @return the label rotation
*/
public Rotation getLabelRotation() {
return labelRotation;
}
/**
* Sets the label rotation.
* @param labelRotation the label rotation
*/
public void setLabelRotation(Rotation labelRotation) {
this.labelRotation = labelRotation;
}
/**
* A TicksChangedListener gets notified when tick marks change.
* @author Adam Crume
*/
public static interface TicksChangedListener {
/**
* Notifies this listener that an axis's tick marks changed.
* @param a axis whose tick marks changed
*/
public void ticksChanged(XYAxis a);
}
} | false | Plotter_src_main_java_plotter_xy_XYAxis.java |
2,040 | public static interface TicksChangedListener {
/**
* Notifies this listener that an axis's tick marks changed.
* @param a axis whose tick marks changed
*/
public void ticksChanged(XYAxis a);
} | false | Plotter_src_main_java_plotter_xy_XYAxis.java |
2,041 | public interface XYDataset extends Dataset, CompressionOutput {
/**
* Adds points to the beginning of the plot.
* @param x the X coordinates of the points
* @param xoff offset within the x array to copy data from
* @param y the Y coordinates of the points
* @param yoff offset within the y array to copy data from
* @param len number of points
*/
public void prepend(double[] x, int xoff, double[] y, int yoff, int len);
/**
* Adds points to the beginning of the plot.
* @param x the X coordinates of the points
* @param y the Y coordinates of the points
*/
public void prepend(DoubleData x, DoubleData y);
} | false | Plotter_src_main_java_plotter_xy_XYDataset.java |
2,042 | public enum XYDimension {
/**
* The X (horizontal) axis.
*/
X,
/**
* The Y (vertical) axis.
*/
Y
} | false | Plotter_src_main_java_plotter_xy_XYDimension.java |
2,043 | public class XYGrid extends JComponent implements TicksChangedListener {
private static final long serialVersionUID = 1L;
/** Used to draw the grid lines. */
private Stroke stroke = new BasicStroke(1, 0, 0, 1, new float[] { 4, 4 }, 0);
/** X axis this grid takes its values from. */
private XYAxis xAxis;
/** Y axis this grid takes its value from. */
private XYAxis yAxis;
/** Period length of the stroke, used to optimize drawing. */
private double strokeLength = 8;
/**
* Creates a grid.
* @param xAxis X axis this grid takes tick marks from
* @param yAxis Y axis this grid takes tick marks from
*/
public XYGrid(XYAxis xAxis, XYAxis yAxis) {
assert xAxis != null;
assert yAxis != null;
this.xAxis = xAxis;
this.yAxis = yAxis;
xAxis.addTickListener(this);
yAxis.addTickListener(this);
}
@Override
protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
Color origColor = g2.getColor();
Stroke origStroke = g2.getStroke();
g2.setColor(getForeground());
g2.setStroke(stroke);
int height = getHeight();
int width = getWidth();
Rectangle clip = g2.getClipBounds();
int xmin = clip.x;
int xmax = clip.x + clip.width - 1;
int ymin = clip.y;
int ymax = clip.y + clip.height - 1;
// Draw shorter lines when possible.
// This makes drawing dashed lines faster.
int linexmin = 0;
int linexmax = width - 1;
int lineymin = 0;
int lineymax = height - 1;
if(strokeLength != 0) {
// We have to adjust the starting points so that the dashes are in phase
// with what they would have been if we drew the whole line.
linexmin = (int) (strokeLength * (int) (xmin / strokeLength));
lineymin = (int) (strokeLength * (int) (ymin / strokeLength));
linexmax = xmax + 1;
lineymax = ymax + 1;
}
for(int x : xAxis.getMajorTicks()) {
if(x >= xmin && x <= xmax) {
g2.drawLine(x, lineymin, x, lineymax);
}
}
for(int y : yAxis.getMajorTicks()) {
y = height - 1 - y;
if(y >= ymin && y <= ymax) {
g2.drawLine(linexmin, y, linexmax, y);
}
}
g2.setColor(origColor);
g2.setStroke(origStroke);
}
@Override
public void ticksChanged(XYAxis a) {
repaint();
}
/**
* Returns the stroke used to draw the lines.
* @return the stroke used to draw the lines
*/
public Stroke getStroke() {
return stroke;
}
/**
* Sets the stroke used to draw the lines.
* @param stroke the stroke used to draw the lines
*/
public void setStroke(Stroke stroke) {
this.stroke = stroke;
if(stroke instanceof BasicStroke) {
float[] dashes = ((BasicStroke) stroke).getDashArray();
float strokeLength = 0;
for(float f : dashes) {
strokeLength += f;
}
this.strokeLength = strokeLength;
} else {
this.strokeLength = 0;
}
}
} | false | Plotter_src_main_java_plotter_xy_XYGrid.java |
2,044 | public class XYLocationDisplay extends JLabel implements MouseMotionListener, MouseListener {
private static final long serialVersionUID = 1L;
/** Formats the point for display. The format is given two arguments, the X and Y coordinates. */
private MessageFormat format = new MessageFormat("X: {0} Y: {1}");
/** True if the mouse cursor is within the plot contents area. */
private boolean haveMouse;
@Override
public void mouseDragged(MouseEvent e) {
if(haveMouse) {
XYPlotContents contents = (XYPlotContents) e.getSource();
Point2D p = new Point2D.Double();
contents.toLogical(p, e.getPoint());
setText(format.format(new Object[] {p.getX(), p.getY()}));
}
}
@Override
public void mouseMoved(MouseEvent e) {
if(haveMouse) {
XYPlotContents contents = (XYPlotContents) e.getSource();
Point2D p = new Point2D.Double();
contents.toLogical(p, e.getPoint());
setText(format.format(new Object[] {p.getX(), p.getY()}));
}
}
@Override
public void mouseClicked(MouseEvent e) {
// ignore
}
@Override
public void mouseEntered(MouseEvent e) {
haveMouse = true;
}
@Override
public void mouseExited(MouseEvent e) {
haveMouse = false;
setText("");
}
@Override
public void mousePressed(MouseEvent e) {
// ignore
}
@Override
public void mouseReleased(MouseEvent e) {
// ignore
}
/**
* Attaches the display to a plot.
* @param plot plot to display the coordinates of
*/
public void attach(XYPlot plot) {
XYPlotContents contents = plot.getContents();
if(contents == null) {
throw new IllegalArgumentException("Plot does not contain an XYPlotContents component");
}
contents.addMouseListener(this);
contents.addMouseMotionListener(this);
}
/**
* Returns the format used to display the point.
* @return the format used to display the point
*/
public MessageFormat getFormat() {
return format;
}
/**
* Sets the format used to display the point.
* @param format the format used to display the point
*/
public void setFormat(MessageFormat format) {
this.format = format;
}
} | false | Plotter_src_main_java_plotter_xy_XYLocationDisplay.java |
2,045 | public class XYMarkerLine extends JComponent {
private static final long serialVersionUID = 1L;
/** If the line moves by fewer than this many pixels, only one repaint is issued.
* Otherwise, two separate repaints (to erase the old and draw the new) are issued. */
private static final int REPAINT_COMBINE_THRESHOLD = 5;
/** Default stroke used to draw lines. */
private static final Stroke DEFAULT_STROKE = new BasicStroke(1, 0, 0, 1, new float[] { 4, 4 }, 0);
/** Used to draw the line. */
private Stroke stroke = DEFAULT_STROKE;
/** Axis this line corresponds to. */
private XYAxis axis;
/** Value this line is drawn at. */
private double value;
/** Period length of the stroke, used to optimize drawing. */
private double strokeLength = 8;
/**
* Creates a marker line.
* @param axis axis the value lies on
* @param value value to draw the line at
*/
public XYMarkerLine(XYAxis axis, double value) {
this.axis = axis;
this.value = value;
}
@Override
protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g.create();
g2.setColor(getForeground());
g2.setStroke(stroke);
int height = getHeight();
Rectangle clip = g2.getClipBounds();
int loc = axis.toPhysical(value);
if(axis.getPlotDimension() == XYDimension.X) {
Point p = SwingUtilities.convertPoint(axis, loc, 0, this);
loc = p.x;
int xmin = clip.x;
int xmax = clip.x + clip.width;
if(loc >= xmin && loc <= xmax) {
// Draw shorter lines when possible.
// This makes drawing dashed lines faster.
int lineymin = 0;
int lineymax = height;
if(strokeLength != 0) {
// We have to adjust the starting points so that the dashes are in phase
// with what they would have been if we drew the whole line.
lineymin = (int) (strokeLength * (int) (clip.y / strokeLength));
lineymax = clip.y + clip.height;
}
g2.drawLine(loc, lineymin, loc, lineymax);
}
} else {
Point p = SwingUtilities.convertPoint(axis, 0, loc, this);
loc = p.y;
int width = getWidth();
int ymin = clip.y;
int ymax = clip.y + clip.height;
if(loc >= ymin && loc <= ymax) {
// Draw shorter lines when possible.
// This makes drawing dashed lines faster.
int linexmin = 0;
int linexmax = width;
if(strokeLength != 0) {
// We have to adjust the starting points so that the dashes are in phase
// with what they would have been if we drew the whole line.
linexmin = (int) (strokeLength * (int) (clip.x / strokeLength));
linexmax = clip.x + clip.width;
}
g2.drawLine(linexmin, loc, linexmax, loc);
}
}
}
/**
* Returns the stroke used to draw the lines.
* @return the stroke used to draw the lines
*/
public Stroke getStroke() {
return stroke;
}
/**
* Sets the stroke used to draw the lines.
* @param stroke the stroke used to draw the lines
*/
public void setStroke(Stroke stroke) {
this.stroke = stroke;
if(stroke instanceof BasicStroke) {
float[] dashes = ((BasicStroke) stroke).getDashArray();
float strokeLength = 0;
for(float f : dashes) {
strokeLength += f;
}
this.strokeLength = strokeLength;
} else {
this.strokeLength = 0;
}
}
/**
* Returns the value this line is drawn at.
* @return the value this line is drawn at
*/
public double getValue() {
return value;
}
/**
* Sets the value this line is drawn at.
* @param value the value this line is drawn at
*/
public void setValue(double value) {
double oldValue = this.value;
if(value != oldValue) {
this.value = value;
int loc = axis.toPhysical(oldValue);
int loc2 = axis.toPhysical(value);
if(loc == loc2) {
// Old and new values do not match exactly, but they paint the same.
return;
}
int minLoc = Math.min(loc, loc2);
int maxLoc = Math.max(loc, loc2);
int span = maxLoc - minLoc + 1;
// If the old and new values are close together, just issue one paint request.
// Otherwise, issue two smaller paint requests.
if(span < REPAINT_COMBINE_THRESHOLD) {
if(axis.getPlotDimension() == XYDimension.X) {
Point p = SwingUtilities.convertPoint(axis, minLoc, 0, this);
repaint(p.x, 0, span, getHeight());
} else {
Point p = SwingUtilities.convertPoint(axis, 0, minLoc, this);
repaint(0, p.y, getWidth(), span);
}
} else {
if(axis.getPlotDimension() == XYDimension.X) {
int xo = SwingUtilities.convertPoint(axis, 0, 0, this).x;
int height = getHeight();
repaint(loc + xo, 0, 1, height);
repaint(loc2 + xo, 0, 1, height);
} else {
int yo = SwingUtilities.convertPoint(axis, 0, 0, this).y;
int width = getWidth();
repaint(0, loc + yo, width, 1);
repaint(0, loc2 + yo, width, 1);
}
}
}
}
} | false | Plotter_src_main_java_plotter_xy_XYMarkerLine.java |
2,046 | public class XYPlot extends Plot {
private static final long serialVersionUID = 1L;
/** The X axis. */
private XYAxis xAxis;
/** The Y axis. */
private XYAxis yAxis;
@Override
protected void paintComponent(Graphics g) {
int width = getWidth();
int height = getHeight();
Color background = getBackground();
if(background != null) {
g.setColor(background);
g.fillRect(0, 0, width, height);
}
}
@Override
public void toLogical(Point2D dest, Point2D src) {
double x = xAxis.toLogical((int) (src.getX() + .5) - xAxis.getX());
double y = yAxis.toLogical((int) (src.getY() + .5) - yAxis.getY());
dest.setLocation(x, y);
}
@Override
public void toPhysical(Point2D dest, Point2D src) {
int x = xAxis.toPhysical(src.getX()) + xAxis.getX();
int y = yAxis.toPhysical(src.getY()) + yAxis.getY();
dest.setLocation(x, y);
}
/**
* Overridden to return false since subcomponents are transparent.
*/
@Override
public boolean isOptimizedDrawingEnabled() {
return false;
}
/**
* Returns the X axis.
* @return the X axis
*/
public XYAxis getXAxis() {
return xAxis;
}
/**
* Sets the X axis.
* @param xAxis the X axis
*/
public void setXAxis(XYAxis xAxis) {
this.xAxis = xAxis;
}
/**
* Returns the Y axis.
* @return the Y axis
*/
public XYAxis getYAxis() {
return yAxis;
}
/**
* Sets the Y axis.
* @param yAxis the Y axis
*/
public void setYAxis(XYAxis yAxis) {
this.yAxis = yAxis;
}
/**
* Returns the content area of the plot.
* @return the content area of the plot
*/
public XYPlotContents getContents() {
XYPlotContents contents = null;
for(Component c : getComponents()) {
if(c instanceof XYPlotContents) {
contents = (XYPlotContents) c;
}
}
return contents;
}
} | false | Plotter_src_main_java_plotter_xy_XYPlot.java |
2,047 | public class XYPlotContents extends JComponent {
private static final long serialVersionUID = 1L;
@Override
public void doLayout() {
int width = getWidth();
int height = getHeight();
for(Component c : getComponents()) {
c.setBounds(0, 0, width, height);
}
}
/**
* Converts from physical to logical coordinates.
* @param dest modified to contain the logical coordinates
* @param src contains the physical coordinates
*/
public void toLogical(Point2D dest, Point src) {
XYPlot plot = (XYPlot) getParent();
Point loc = SwingUtilities.convertPoint(this, src, plot);
plot.toLogical(dest, loc);
}
@Override
public boolean isValidateRoot() {
return true;
}
@Override
protected void paintComponent(Graphics g) {
g.setColor(getBackground());
g.fillRect(0, 0, getWidth(), getHeight());
}
} | false | Plotter_src_main_java_plotter_xy_XYPlotContents.java |
2,048 | public abstract class XYPlotLine extends JComponent {
private static final long serialVersionUID = 1L;
/** Shape used to draw the outline of each data point. May be null. */
protected Shape pointOutline;
/** Shape used to fill each data point. May be null. */
protected Shape pointFill;
/** Icon to draw at each data point. May be null */
protected Icon pointIcon;
/**
* Returns the X data.
* This should not be modified directly.
* @return X data
*/
public abstract DoubleData getXData();
/**
* Returns the Y data.
* This should not be modified directly.
* @return Y data
*/
public abstract DoubleData getYData();
/**
* Adds a data point.
* @param x X-coordinate of the data point
* @param y Y-coordinate of the data point
*/
public abstract void add(double x, double y);
/**
* Repaints a data point and adjoining line segments.
* @param index index of the data point
*/
public abstract void repaintData(int index);
/**
* Repaints data points and adjoining line segments.
* @param index index of the first data point
* @param count number of data points
*/
public abstract void repaintData(int index, int count);
/**
* Returns the independent dimension. May be null.
* @return the independent dimension
*/
public abstract XYDimension getIndependentDimension();
/**
* Adds data to the beginning.
* @param x X data to add
* @param y Y data to add
*/
public abstract void prepend(DoubleData x, DoubleData y);
/**
* Adds data to the beginning.
* @param x X data to add
* @param xoff index within <code>x</code> to start copying from
* @param y Y data to add
* @param yoff index within <code>y</code> to start copying from
* @param len number of points to add
*/
public abstract void prepend(double[] x, int xoff, double[] y, int yoff, int len);
/**
* Removes points from the beginning.
* @param removeCount number of points to remove
*/
public abstract void removeFirst(int removeCount);
/**
* Removes points from the end.
* @param removeCount number of points to remove
*/
public abstract void removeLast(int removeCount);
/**
* Removes all points.
*/
public abstract void removeAllPoints();
/**
* Returns the point outline.
* @return the point outline
*/
public Shape getPointOutline() {
return pointOutline;
}
/**
* Sets the point outline
* @param pointOutline the point outline
*/
public void setPointOutline(Shape pointOutline) {
this.pointOutline = pointOutline;
}
/**
* Returns the point fill.
* @return the point fill
*/
public Shape getPointFill() {
return pointFill;
}
/**
* Sets the point fill.
* @param pointFill the point fill
*/
public void setPointFill(Shape pointFill) {
this.pointFill = pointFill;
}
/**
* @return the icon used to draw each data point
*/
public Icon getPointIcon() {
return pointIcon;
}
/**
* @param pointIcon the icon to draw at each data point
*/
public void setPointIcon(Icon pointIcon) {
this.pointIcon = pointIcon;
}
} | false | Plotter_src_main_java_plotter_xy_XYPlotLine.java |
2,049 | public class XYReversingDataset implements XYDataset {
private final XYDataset base;
/**
* Creates the dataset.
* @param base dataset to forward data to
*/
public XYReversingDataset(XYDataset base) {
this.base = base;
}
@Override
public int getPointCount() {
return base.getPointCount();
}
@Override
public void add(double x, double y) {
base.add(y, x);
}
@Override
public void removeAllPoints() {
base.removeAllPoints();
}
@Override
public void prepend(double[] x, int xoff, double[] y, int yoff, int len) {
base.prepend(y, yoff, x, xoff, len);
}
@Override
public void prepend(DoubleData x, DoubleData y) {
base.prepend(y, x);
}
@Override
public void removeLast(int count) {
base.removeLast(count);
}
} | false | Plotter_src_main_java_plotter_xy_XYReversingDataset.java |