/** * @param points * @param color * @param g */ private void paintSequence( Slot type, List<List<ValuePointColored>> points, Color color, Graphics2D g) { int i = 0; int size = points.size(); if (size > 0) { double increment = 200 / size; for (List<ValuePointColored> valuePoints : points) { int alpha = (int) (i * increment) + 55; Color c = new Color(color.getRed(), color.getGreen(), color.getBlue(), alpha); for (ValuePointColored valuePoint : valuePoints) { double[] coordinates = valuePoint.getPoint().toArray(); int x = xToPix(coordinates[0]); int y = yToPix(coordinates[1]); // if minimum then red, else black if (valuePoint.getBest() == true) { g.setColor(Color.red); } else { g.setColor(c); } g.setStroke(LINE); switch (type) { case CIRCLE: g.drawOval(x - RADIUS / 2 - 3, y - RADIUS / 2 - 3, RADIUS * 2, RADIUS * 2); break; case SQUARE: g.drawRect(x - RADIUS / 2 - 2, y - RADIUS / 2 - 2, RADIUS * 2 - 2, RADIUS * 2 - 2); break; case TRIANGLE: GeneralPath polyline = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 3); polyline.moveTo(x, y - RADIUS / 2 - 4); polyline.lineTo(x + RADIUS / 2 + 3, y + RADIUS / 2 + 1); polyline.lineTo(x - RADIUS / 2 - 3, y + RADIUS / 2 + 1); polyline.closePath(); g.draw(polyline); break; case CROSS: int xLow = x - RADIUS / 2 - 1; int xHigh = x + RADIUS / 2 + 1; int yLow = y - RADIUS / 2 - 1; int yHigh = y + RADIUS / 2 + 1; g.drawLine(xLow, yLow, xHigh, yHigh); g.drawLine(xHigh, yLow, xLow, yHigh); break; } } i++; } } }
public int compare(ValuePointColored o1, ValuePointColored o2) { double yCoordinate1 = o1.getPoint().toArray()[1]; double yCoordinate2 = o2.getPoint().toArray()[1]; if (yCoordinate1 == yCoordinate2) { return 0; } else { if (yCoordinate1 < yCoordinate2) { return -1; } else { return 1; } } }
@Test public void testPoint() { ValuePointColored p1 = ValuePointColored.at(Point.at(10.0), 1.0, true); ValuePointColored p2 = ValuePointColored.at(Point.at(10.0), 1.0, true); ValuePointColored p3 = ValuePointColored.at(Point.at(13.0), 1.0, true); ValuePointColored p4 = ValuePointColored.at(Point.at(10.0), 2.0, false); assertTrue(p1.equals(p2)); assertEquals(p1.hashCode(), p2.hashCode()); assertFalse(p1.equals(p3)); assertNotEquals(p3.hashCode(), p2.hashCode()); assertFalse(p1.equals(p4)); assertNotEquals(p4.hashCode(), p2.hashCode()); assertTrue(p1.toString().contains("1.0@")); assertEquals(1, p1.getValue(), 0.000001); assertEquals(Point.at(10.0), p1.getPoint()); assertTrue(p1.getBest()); assertFalse(p4.getBest()); assertTrue(p4.compareTo(ValuePoint.at(Point.at(13.0), 1.0)) > 0); assertTrue(p3.compareTo(ValuePoint.at(Point.at(10.0), 2.0)) < 0); assertTrue( ValuePointColored.at(Point.at(19.0), 2.0, true) .compareTo(ValuePoint.at(Point.at(10.0), 2.0)) == 0); }