/* * [ACOutlet.java] * * Summary: draw 115V AC outlet female. * * 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; import java.awt.Shape; import java.awt.geom.Path2D; /** * draw 115V AC outlet female. * * @author Roedy Green, Canadian Mind Products * @version 1.0 2011-01-29 initial version. * @since 2011-01-29 */ class ACOutlet extends ConnectorPanel { /** * degree the sides of the pumpkin outline bow out */ private static final int BOWING = 430; /** * how much space above the big neutral connector to the top */ private static final int CLEARANCE = 125; /** * height of the house-shaped ground hole */ private static final int HOUSE_HEIGHT = 180; /** * width of the house-shaped ground hole */ private static final int HOUSE_WIDTH = 200; /** * thickness of the outline around the slots. */ private static final int LINER = 10; /** * how far from center the prongs are */ private static final int PRONG_SPREAD = 220; /** * how far from center the corners of the pumpkin outline shape are */ private static final int PUMPKIN_SPREAD = 270; /** * how wide the hot and neutral slots are */ private static final int slotWidth = 20; /** * colour to represent an AC ground */ private static final Color AC_GROUND_COLOR = new Color( 0x458b00 ); // dull green /** * colour to represent a HOT pin */ private static final Color AC_HOT_COLOR = new Color( 0x802222 ); // blackish red /** * colour to represent a neutral AC pin */ private static final Color AC_NEUTRAL_COLOR = Color.WHITE; ACOutlet() { super( 1000, 1000 ); } /** * draw a 115V AC outlet female * * @param g where to paint */ public void paintComponent( Graphics g ) { super.paintComponent( g ); final Graphics2D g2d = ( Graphics2D ) g; final int xCenter = 500; final int yCenter = 500; final int yTop = 0; final int yBottom = 1000; g2d.setStroke( new BasicStroke( slotWidth ) ); // Set line width for drawing outside slotWidth. // outline of outlet looks a bit like a pumpkin with flat top and bottom and bulging sides. Path2D pumpkin = new Path2D.Double(); pumpkin.moveTo( xCenter - PUMPKIN_SPREAD, yTop ); pumpkin.quadTo( xCenter - PUMPKIN_SPREAD - BOWING, yCenter, xCenter - PUMPKIN_SPREAD, yBottom ); pumpkin.lineTo( xCenter + PUMPKIN_SPREAD, yBottom ); pumpkin.quadTo( xCenter + PUMPKIN_SPREAD + BOWING, yCenter, xCenter + PUMPKIN_SPREAD, yTop ); pumpkin.lineTo( xCenter - PUMPKIN_SPREAD, yTop ); g2d.setColor( HOLE_COLOR ); g2d.fill( pumpkin ); g2d.setColor( OUTLINE_COLOR ); g2d.draw( pumpkin ); // draw big neutral Slot g2d.setColor( AC_NEUTRAL_COLOR ); g2d.fillRoundRect( xCenter - PRONG_SPREAD - slotWidth * 3 / 2, CLEARANCE, slotWidth * 3, yCenter - CLEARANCE, 30, 30 ); g2d.setStroke( new BasicStroke( LINER ) ); g2d.setColor( OUTLINE_COLOR ); g2d.drawRoundRect( xCenter - PRONG_SPREAD - slotWidth * 3 / 2, CLEARANCE, slotWidth * 3, yCenter - CLEARANCE, 30, 30 ); // draw small hot slot g2d.setColor( AC_HOT_COLOR ); g2d.fillRoundRect( xCenter + PRONG_SPREAD - slotWidth * 3 / 2, CLEARANCE + 25, slotWidth * 3, yCenter - CLEARANCE - 25 * 2, 30, 30 ); g2d.setStroke( new BasicStroke( LINER ) ); g2d.setColor( OUTLINE_COLOR ); g2d.drawRoundRect( xCenter + PRONG_SPREAD - slotWidth * 3 / 2, CLEARANCE + 25, slotWidth * 3, yCenter - CLEARANCE - 25 * 2, 30, 30 ); // draw the ground hole shaped like a house g2d.setColor( AC_GROUND_COLOR ); Shape house = new Polygon( new int[] { xCenter - HOUSE_WIDTH / 2, xCenter - HOUSE_WIDTH / 2, xCenter - 30, xCenter + 30, xCenter + HOUSE_WIDTH / 2, xCenter + HOUSE_WIDTH / 2 }, new int[] { yBottom - CLEARANCE, yBottom - CLEARANCE - HOUSE_HEIGHT, yBottom - CLEARANCE - HOUSE_HEIGHT * 120 / 100, yBottom - CLEARANCE - HOUSE_HEIGHT * 120 / 100, yBottom - CLEARANCE - HOUSE_HEIGHT, yBottom - CLEARANCE } , 6 ); g2d.fill( house ); g2d.setStroke( new BasicStroke( LINER ) ); g2d.setColor( OUTLINE_COLOR ); g2d.draw( house ); } }