/* * [RS232C25Female.java] * * Summary: draw female 25-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 25-pin RS232C connector. * * @author Roedy Green, Canadian Mind Products * @version 1.0 2011-01-29 initial version. * @since 2011-01-29 */ class RS232C25Female extends ConnectorPanel { private static final int BOTTOM_BAR_LENGTH = 700; private static final int CONNECTOR_HEIGHT = 200; 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 = 60; private static final int INTER_ROW_SPACING = 70; private static final int LEFT_TWEAK = -115; private static final int LINER = 2; private static final int PIN_RADIUS = 15; private static final int RIGHT_TWEAK = 50; private static final int ROUNDING_RADIUS = 60; 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[] PIN_COLORS = { 0x9acd32 /* pin 1 dull green */, 0xff4040 /* pin 2 red */, 0xff4040 /* pin 3 red */, 0xff9c00 /* pin 4 orange */, 0xff9c00 /* pin 5 orange */, 0xff9c00 /* pin 6 orange */, 0xff9c00 /* pin 7 orange */, 0x9acd32 /* pin 8 dull green */, 0xa0a0a0 /* pin 9 dark gray */, 0xd0d0d0 /* pin 10 light gray */, 0xfff0e0 /* pin 11 unused */, 0xffcc00 /* pin 12 pale orange */, 0xffcc00 /* pin 13 pale orange */, 0xff8080 /* pin 14 pale red */, 0xff9c00 /* pin 15 orange */, 0xff8080 /* pin 16 pale red */, 0xff9c00 /* pin 17 orange */, 0xfff0e0 /* pin 18 unused */, 0xffcc00 /* pin 19 pale orange */, 0xff9c00 /* pin 20 orange */, 0xff9c00 /* pin 21 orange */, 0xff9c00 /* pin 22 orange */, 0xff9c00 /* pin 23 orange */, 0xff9c00 /* pin 24 orange */, 0xfff0e0 /* pin 25 unused */ }; static { FIRST_PIN = X_CENTER - INTER_PIN_SPACING * 6; Y_CENTER = ( CONNECTOR_HEIGHT / 2 ) + INSET; FIRST_ROW = Y_CENTER - INTER_ROW_SPACING / 2; } RS232C25Female() { super( 1000, 475 ); } /** * draw one pin * * @param g2d graphics context * @param pin pin number 1 to 16 * @param pinBackground background colour for the pin */ private static void drawPin( Graphics2D g2d, int pin, Color pinBackground ) { int x; final int y; if ( pin >= 14 ) { x = ( 25 - pin ) * INTER_PIN_SPACING + FIRST_PIN + INTER_PIN_SPACING / 2; y = FIRST_ROW + INTER_ROW_SPACING; } else { x = ( 13 - 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 ); } /** * draw a RS232C 25-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.setColor( OUTLINE_COLOR ); for ( int pin = 1; pin <= 25; pin++ ) { drawPin( g2d, pin, new Color( PIN_COLORS[ pin - 1 ] ) ); } g2d.setColor( OUTLINE_COLOR ); g2d.setFont( new Font( "dialog", Font.PLAIN, 40 ) ); drawCenteredString( g2d, "13", FIRST_PIN + LEFT_TWEAK, FIRST_ROW ); drawCenteredString( g2d, "1", FIRST_PIN + INTER_PIN_SPACING * 13 + RIGHT_TWEAK, FIRST_ROW ); drawCenteredString( g2d, "25", FIRST_PIN + LEFT_TWEAK, FIRST_ROW + INTER_ROW_SPACING * 2 ); drawCenteredString( g2d, "14", FIRST_PIN + INTER_PIN_SPACING * 13 + RIGHT_TWEAK, FIRST_ROW + INTER_ROW_SPACING * 2 ); } }