public void paintComponent(Graphics g) { super.paintComponent(g); paintComponentForChessBoard(g); paintComponentForBoardEdge(g); paintComponentForEdgeTriangles(g); paintComponentForAllPoints(g); paintComponentForEdgeTriangleInfo(g); g.setColor(Color.green); for (Point p : selectedPointList) { Point.InfoPack info = p.getPixelInformation(); double pStartX = info.posX - info.width / 2, pEndX = info.posX + info.width / 2, pStartY = info.posY - info.height / 2, pEndY = info.posY + info.height / 2; for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) g.fillRect( (int) Math.round(info.posX - 2.5 - info.width / 2 + (info.width * 0.75 + 2.5) * i), (int) Math.round(info.posY - 2.5 - info.height / 2 + info.height * j), (int) Math.round(info.width * 0.25 + 2.5), 5); for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) g.fillRect( (int) Math.round(info.posX - 2.5 - info.width / 2 + info.width * i), (int) Math.round(info.posY - 2.5 - info.height / 2 + (info.height * 0.75 + 2.5) * j), 5, (int) Math.round(info.height * 0.25 + 2.5)); } if (isDragging) { g.setColor(new Color(0, 128, 0)); g.drawRect( mouseStartX < mouseCurrX ? mouseStartX : mouseCurrX, mouseStartY < mouseCurrY ? mouseStartY : mouseCurrY, Math.abs(mouseCurrX - mouseStartX), Math.abs(mouseCurrY - mouseStartY)); } }
public void updateContent(int[] selectedIDs) { ChessBoardPanel panel = UIHandler.getInstance(null).getChessBoardPanel(); BufferedImage image = panel.getChessBoardImage(); Dimension d = panel.getChessBoardPreferredSize(); if (image == null) setBoardImage(d.width, d.height); else setBoardImage(image); pointList.clear(); selectedPointList.clear(); for (Point p : UIHandler.getInstance(null).getPointList()) { Point np = new Point(this, p.getId()); Point.InfoPack infoPack = p.getRelativeInformation(); np.setSizeByRelative(infoPack.posX, infoPack.posY, infoPack.width, infoPack.height); pointList.add(np); } for (Point p : UIHandler.getInstance(null).getPointList()) { Point np = findPointInListById(pointList, p.getId()); for (Point.EdgePointPair edgePointPair : p.getAllEdgePointPair()) { Point targetPoint = findPointInListById(pointList, edgePointPair.targetPoint.getId()); if (targetPoint != null) np.addEdgePointPairs(edgePointPair.direction, targetPoint); } } for (int id : selectedIDs) { for (Point p : pointList) { if (p.getId() == id) { selectedPointList.add(p); break; } } } }
@Override protected void updateAllPoints() { for (Point p : pointList) p.updatePixelByRelative(); repaint(); }