/* * [Triangle.java] * * Summary: Draws green equilateral triangle. * * 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.Polygon; /** * Draws green equilateral triangle. * * @author Roedy Green, Canadian Mind Products * @version 1.0 2011-01-29 initial version. * @since 2011-01-29 */ class Triangle extends ConnectorPanel { private static final int HEIGHT = ( int ) Math.floor( Math.sqrt( 3 ) * 500 + .5 ); private static final int TOP_MARGIN = ( 1000 - HEIGHT ) / 2; /** * thickness of the outline around the slots. */ private static final int LINER = 10; private static final int SIDE_MARGIN = 10; private static final Color OUTLINE_COLOR = Color.BLACK; private final Color fillColor; Triangle( 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; // D connector contains three rows of pins, 1..15 with pin 9 missing. // start bottom left and go counterclockwise final Polygon outline = new Polygon( new int[] { SIDE_MARGIN, 500, 1000 - SIDE_MARGIN }, new int[] { HEIGHT + TOP_MARGIN, SIDE_MARGIN, HEIGHT + TOP_MARGIN }, 3 ); g2d.setColor( fillColor ); g2d.fillPolygon( outline ); g2d.setColor( OUTLINE_COLOR ); g2d.setStroke( new BasicStroke( LINER ) ); g2d.drawPolygon( outline ); } }