/* * [RS232C9Female.java] * * Summary: draw female 9-pin RS232C connector. * * 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.Font; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Polygon; /** * draw female 9-pin RS232C connector. * * @author Roedy Green, Canadian Mind Products * @version 1.0 2011-01-29 initial version. * @since 2011-01-29 */ class RS232C9Female extends ConnectorPanel { private static final int BOTTOM_BAR_LENGTH = 700; private static final int CONNECTOR_HEIGHT = 378; private static final int FIRST_PIN; private static final int FIRST_ROW; private static final int INSET = 10; private static final int INTER_PIN_SPACING = 150; private static final int INTER_ROW_SPACING = 180; private static final int LINER = 10; private static final int PIN_RADIUS = 50; private static final int ROUNDING_RADIUS = 80; private static final int TOP_BAR_LENGTH = 980; private static final int X_CENTER = 500; 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 ); private static final int[] pinColors = { 0xff9c00 /* pin 1 orange */, 0xff4040 /* pin 2 red */, 0xff4040 /* pin 3 red */, 0xff9c00 /* pin 4 orange */, 0x9acd32 /* pin 5 dull green */, 0xff9c00 /* pin 6 orange */, 0xff9c00 /* pin 7 orange */, 0xff9c00 /* pin 8 orange */, 0xff9c00 /* pin 9 orange */ }; static { FIRST_PIN = X_CENTER - INTER_PIN_SPACING * 2; Y_CENTER = ( CONNECTOR_HEIGHT / 2 ) + INSET; FIRST_ROW = Y_CENTER - INTER_ROW_SPACING / 2; } RS232C9Female() { super( 1000, 425 ); } /** * draw one pin * * @param g2d graphics context * @param pin pin number 1 to 16 * @param pinBackground background colour for the in */ private static void drawPin( Graphics2D g2d, int pin, Color pinBackground ) { int x; final int y; if ( pin >= 6 ) { x = ( 9 - pin ) * INTER_PIN_SPACING + INTER_PIN_SPACING / 2 + FIRST_PIN; y = FIRST_ROW + INTER_ROW_SPACING; } else { x = ( 5 - pin ) * 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; } drawCenteredString( g2d, Integer.toString( pin ), x, y ); } /** * draw a RS232C 9-pin female connector * * @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 - BOTTOM_BAR_LENGTH / 2, X_CENTER + BOTTOM_BAR_LENGTH / 2, X_CENTER + TOP_BAR_LENGTH / 2, X_CENTER - TOP_BAR_LENGTH / 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 <= 9; pin++ ) { drawPin( g2d, pin, new Color( pinColors[ pin - 1 ] ) ); } } }