package viewer; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Stroke; public class Point implements Drawable{ public double x; public double y; public boolean last; public boolean mapped = false; public Color color; public int radius = 0; public double mappedX; public double mappedY; public Point(double x, double y) { this.x = x; this.y = y; } public void drawYourself(Graphics g, int[] areaSize, double[] limits, int[] nextCoords, boolean lineMode) { if(color != null) { g.setColor(color); } int[] drawcoords = getDrawCoords(areaSize, limits); if(last || nextCoords == null || color != null) { if(lineMode && color != null && nextCoords != null && !last) { if(radius > 1) { Graphics2D g2 = (Graphics2D)g; Stroke cur = g2.getStroke(); g2.setStroke(new BasicStroke(radius*2, BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND)); g.drawLine(drawcoords[0],drawcoords[1],nextCoords[0],nextCoords[1]); g2.setStroke(cur); } else { g.drawLine(drawcoords[0],drawcoords[1],nextCoords[0],nextCoords[1]); } } else { if(radius > 1) { g.fillOval(drawcoords[0]-radius/2,drawcoords[1]-radius/2,radius,radius); } else { if(color == null) g.drawLine(drawcoords[0],drawcoords[1],drawcoords[0],drawcoords[1]); else g.drawOval(drawcoords[0]-radius/2,drawcoords[1]-radius/2,2,0); } } } else { if(lineMode) { g.drawLine(drawcoords[0],drawcoords[1],nextCoords[0],nextCoords[1]); } else { if(color == null) g.drawLine(drawcoords[0],drawcoords[1],drawcoords[0],drawcoords[1]); else g.drawOval(drawcoords[0]-radius/2,drawcoords[1]-radius/2,2,0); } } } public int[] getDrawCoords(int[] areaSize, double[] limits) { int[] coords = new int[2]; double width = limits[1] - limits[0]; double height = limits[2] - limits[3]; coords[0] = (int)Math.round(((x - limits[0]) / width) * areaSize[0]); coords[1] = (int)Math.round(((1-(y - limits[3]) / height)) * areaSize[1]); return coords; } public void setLast(boolean value) { this.last = value; } public Color getColor() { return color; } }