/* * [Pentagon.java] * * Summary: Draws pentagon. * * 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 pentagon. * * @author Roedy Green, Canadian Mind Products * @version 1.0 2011-01-29 initial version. * @since 2011-01-29 */ class Pentagon extends ConnectorPanel { /** * thickness of the outline around the slots. */ private static final int LINER = 20; private static final int SIDE_MARGIN = 10; private static final Color OUTLINE_COLOR = Color.BLACK; private final Color fillColor; Pentagon( Color fillColor ) { super( 1000, 1000 ); this.fillColor = fillColor; } /** * draw a green equilateral triangle, outlined. * * @param g where to paint */ public void paintComponent( Graphics g ) { super.paintComponent( g ); final Graphics2D g2d = ( Graphics2D ) g; // compute height final Point p0 = clockPoint( 500, 500, 500 - SIDE_MARGIN, 12 - 2.4 * 0 ); final Point p2 = clockPoint( 500, 500, 500 - SIDE_MARGIN, 12 - 2.4 * 2 ); final int height = p2.y - p0.y; final int topMargin = ( 1000 - height ) / 2 - SIDE_MARGIN; final Polygon outline = new Polygon(); // start at noon and work counterclockwise, in 2.4 hour increments. (5*2.4 = 12) for ( int i = 0; i < 5; i++ ) { final Point p = clockPoint( 500, 500 + topMargin, 500 - SIDE_MARGIN, 12 - 2.4 * 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 ); } }