public double getAngle(double angle) { int n = this.slots.size(); double rotStep = Math.PI * 2 / n; for (int i = 0; i < slots.size(); i++) { EyeSlot slot = slots.elementAt(i); if (slot.isSelected(angle)) { angle = -rotStep * i - rotStep / 2; break; } } return angle; }
public EyeSlot selectSlot(double angle) { selectedSlot = null; int n = this.slots.size(); for (int i = 0; i < slots.size(); i++) { EyeSlot slot = slots.elementAt(i); if (slot.isSelected(angle)) { selectedSlot = slot; break; } } if (selectedSlot != null) { this.selector.describeRelation(selectedSlot); } return selectedSlot; }
public void draw(Graphics2D g2, int w, int h, double angle) { int n = this.slots.size(); double rotStep = Math.PI * 2 / n; int cx = w / 2; int cy = h / 2; int slotW = 10; int slotH = 12; // angle = getAngle(angle); int _w = Math.min(w, h); int _h = _w; int marginX = Math.max(0, (w - _w) / 2); int marginY = Math.max(0, (h - _h) / 2); g2.setPaint(Color.gray); BasicStroke stroke = new BasicStroke(2.0f); g2.setStroke(stroke); // Ellipse2D e1 = new Ellipse2D.Double(marginX, marginY, _w , _h); // g2.draw(e1); // g2.rotate(angle, cx, cy); g2.translate(-marginX, -marginY); // g2.drawOval(marginX, marginY, _w, _h); AffineTransform affine = g2.getTransform(); for (int i = 0; i < slots.size(); i++) { EyeSlot slot = slots.elementAt(i); double a = angle + rotStep * i; while (a < 0) { a += Math.PI * 2; } while (a > Math.PI * 2) { a -= Math.PI * 2; } slot.angle = a; g2.translate(marginX, marginY); g2.rotate(a, cx, cy); g2.translate(marginX + _w, marginY + _h / 2); slot.draw(g2, slotW, slotH); Point2D pt = g2.getTransform().transform(new Point(-EyeSlot.offset, slotH / 2), null); slot.x = (int) pt.getX(); slot.y = (int) pt.getY(); g2.setTransform(affine); } g2.translate(marginX, marginY); stroke = new BasicStroke(1.0f); g2.setStroke(stroke); for (int i = 0; i < slots.size(); i++) { EyeSlot slot = slots.elementAt(i); for (EyeSlot rs : slot.relatedSlots) { if (selectedSlot != null && (slot == selectedSlot || rs == selectedSlot)) { g2.setColor(selectedSlot.backgroundColor); g2.setStroke(new BasicStroke(1.5f)); } else { g2.setColor(new Color(100, 100, 100, 100)); g2.setStroke(new BasicStroke(1.0f)); } QuadCurve2D shape = new QuadCurve2D.Float(slot.x, slot.y, cx, cy, rs.x, rs.y); g2.draw(shape); } } }