/* * [Octagon.java] * * Summary: Draws octagon (stop sign). * * Copyright: (c) 2011-2017 Roedy Green, Canadian Mind Products, http://mindprod.com * * Licence: This software may be copied and used freely for any purpose but military. * http://mindprod.com/contact/nonmil.html * * Requires: JDK 1.8+ * * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/ * * Version History: * 1.0 2011-01-29 initial version. */ package com.mindprod.connectors; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Point; import java.awt.Polygon; /** * Draws octagon (stop sign). * * @author Roedy Green, Canadian Mind Products * @version 1.0 2011-01-29 initial version. * @since 2011-01-29 */ class Octagon extends ConnectorPanel { /** * thickness of the outline around the slots. */ private static final int LINER = 10; private static final int MARGIN = 10; private static final Color OUTLINE_COLOR = Color.BLACK; private static final Color RED = Color.RED; private final Color fillColor; Octagon( Color fillColor ) { super( 1000, 1000 ); this.fillColor = fillColor; } /** * draw a polygon, outlined. * * @param g where to paint */ public void paintComponent( Graphics g ) { super.paintComponent( g ); final Graphics2D g2d = ( Graphics2D ) g; final Polygon outline = new Polygon(); // start at 2:15 o'clock and work counterclockwise, in 1.5 hour increments. (8*1.5 = 12) for ( int i = 0; i < 8; i++ ) { final Point p = clockPoint( 500, 500, 500 - MARGIN, 2.25 - 1.5 * i ); outline.addPoint( p.x, p.y ); } g2d.setColor( fillColor ); g2d.fillPolygon( outline ); g2d.setColor( OUTLINE_COLOR ); g2d.setStroke( new BasicStroke( LINER ) ); g2d.drawPolygon( outline ); } }