/* * [USB2Header.java] * * Summary: Draw USB2 motherboad header male. * * Copyright: (c) 2013-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 2013-02-11 initial version. */ package com.mindprod.connectors; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Polygon; /** * Draw USB2 motherboad header male. * * @author Roedy Green, Canadian Mind Products * @version 1.0 2013-02-11 initial version. * @since 2013-02-11 */ class USB2Header extends ConnectorPanel { /** * height of connector */ private static final int CONNECTOR_HEIGHT = 300; /** * width of connector */ private static final int CONNECTOR_WIDTH = 750; /** * x of first pin on right */ private static final int FIRST_PIN; /** * y of first row */ private static final int FIRST_ROW; /** * inset from edge of image */ private static final int INSET = 10; /** * distance x between pins */ private static final int INTER_PIN_SPACING = 135; /** * distance y between pins */ private static final int INTER_ROW_SPACING = 135; /** * how many pins we draw */ private static final int LAST_PIN_NUMBER = 10; /** * width of circle around pins */ private static final int LINER = 10; /** * radius of pins */ private static final int PIN_RADIUS = 50; /** * rounding raius for connector corners */ private static final int ROUNDING_RADIUS = 80; /** * x centre of image */ private static final int X_CENTER = 500; /** * y centre of image */ private static final int Y_CENTER; /** * color used to draw the outline of a component */ private static final Color PIN_OUTLINE_COLOR = new Color( 0x003000 ); /** * colours for eachj of the pins */ private static final int[] pinColors = { 0xa0a0a0 /* pin 1 grey */, 0x000000 /* pin 2 black */, 0x66dd00 /* pin 3 green */, 0xffffff /* pin 4 white */, 0xff4040 /* pin 5 red */, 0xff4040 /* pin 6 red */, 0xffffff /* pin 7 white */, 0x66dd00 /* pin 8 green */, 0x000000 /* pin 9 black */, 0xfff0e0 /* pin 10 orange */ }; static { FIRST_PIN = X_CENTER + INTER_PIN_SPACING * 2; // on right Y_CENTER = ( CONNECTOR_HEIGHT / 2 ) + INSET; FIRST_ROW = Y_CENTER - INTER_ROW_SPACING / 2; } USB2Header() { super( 1000, 350 ); } /** * draw one pin * * @param g2d graphics context * @param pin pin number 1 to 9 * @param pinBackground background colour for the in */ private static void drawPin( Graphics2D g2d, int pin, Color pinBackground ) { int x; final int y; // 5 4 3 2 1 // 6 7 8 9 10 if ( pin >= 6 ) { x = -( LAST_PIN_NUMBER - pin ) * INTER_PIN_SPACING + FIRST_PIN; y = FIRST_ROW + INTER_ROW_SPACING; } else { x = -( pin - 1 ) * INTER_PIN_SPACING + FIRST_PIN; y = FIRST_ROW; } g2d.setColor( pinBackground ); g2d.fillOval( x - PIN_RADIUS, y - PIN_RADIUS, 2 * PIN_RADIUS, 2 * PIN_RADIUS ); g2d.setColor( PIN_OUTLINE_COLOR ); g2d.drawOval( x - PIN_RADIUS, y - PIN_RADIUS, 2 * PIN_RADIUS, 2 * PIN_RADIUS ); // tweak position if ( pin >= 10 ) { x -= 3; } if ( pinBackground.equals( Color.BLACK ) ) { g2d.setColor( Color.WHITE ); } drawCenteredString( g2d, Integer.toString( pin ), x, y ); } /** * draw aUSB2 motherboad header male * * @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. final int yTop = INSET; final int yBottom = CONNECTOR_HEIGHT + INSET; // whole stepped connector g2d.setColor( HOLE_COLOR ); g2d.setStroke( new BasicStroke( LINER ) ); // start bottom left and go counterclockwise Polygon outline = new Polygon( new int[] { X_CENTER - CONNECTOR_WIDTH / 2, X_CENTER + CONNECTOR_WIDTH / 2, X_CENTER + CONNECTOR_WIDTH / 2, X_CENTER - CONNECTOR_WIDTH / 2, } , new int[] { yBottom, yBottom, yTop, yTop, }, 4 ); RoundPolygon.fillRoundPolygon( g2d, outline, ROUNDING_RADIUS ); g2d.setColor( OUTLINE_COLOR ); RoundPolygon.drawRoundPolygon( g2d, outline, ROUNDING_RADIUS ); g2d.setFont( new Font( "dialog", Font.PLAIN, 60 ) ); g2d.setColor( OUTLINE_COLOR ); for ( int pin = 1; pin <= LAST_PIN_NUMBER; pin++ ) { drawPin( g2d, pin, new Color( pinColors[ pin - 1 ] ) ); } } }