/* * [MidiDinMale.java] * * Summary: draw Midi DIN pinout. * * 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.Graphics; import java.awt.Graphics2D; import java.awt.Point; import java.awt.Rectangle; import java.awt.Shape; import java.awt.geom.Area; import java.awt.geom.Ellipse2D; /** * draw Midi DIN pinout. * * @author Roedy Green, Canadian Mind Products * @version 1.0 2011-01-29 initial version. * @since 2011-01-29 */ class MidiDinMale extends ConnectorPanel { private static final int INNER_DIAMETER = 700; private static final int NOTCH_DEPTH = 100; private static final int OUTER_DIAMETER = 980; private static final int SHELL = 20; MidiDinMale() { super( 1000, 1000 ); } /** * draw a Midi DIN pinout * * @param g where to paint */ public void paintComponent( Graphics g ) { super.paintComponent( g ); // make a clone so we don't disturb clip region of caller final Graphics2D g2d = ( Graphics2D ) g.create(); final int xCenter = 500; final int yCenter = 500; final Point notchleft = clockPoint( xCenter, yCenter, OUTER_DIAMETER / 2, 6.25 ); final Point notchRight = clockPoint( xCenter, yCenter, OUTER_DIAMETER / 2, 5.75 ); // protect the notch from being painted, with a square drop cloth a notch bitten // out of the bottom middle of it. // We still get artifacts. Why? final Shape currentClip = g2d.getClip(); final Area dropCloth = currentClip == null ? new Area( new Rectangle( 0, 0, this.imageWidth, this.imageHeight ) ) : new Area( currentClip ); dropCloth.subtract( new Area( new Rectangle( notchleft.x + SHELL / 2 + 1, notchleft.y - NOTCH_DEPTH + SHELL / 2 + 1, notchRight.x - notchleft.x - SHELL, NOTCH_DEPTH * 2 ) ) ); // notch rectangle g2d.clip( dropCloth ); // .clip intersects dropCloth with and existing clip region. // it sometimes has artifacts which disappear with repaint. // I don't understand why these are happening. // See com.mindprod.example.PacMan for other techniques to handle making the notch transparent. g2d.setColor( HOLE_COLOR ); g2d.fillOval( 10, 10, OUTER_DIAMETER, OUTER_DIAMETER ); g2d.setColor( OUTLINE_COLOR ); Shape circle = new Ellipse2D.Float( 10, 10, OUTER_DIAMETER, OUTER_DIAMETER ); g2d.setStroke( new BasicStroke( SHELL ) ); // Set line width for drawing outside shell. g2d.draw( circle ); g2d.setColor( OUTLINE_COLOR ); // x, y is top left corner Shape notch = new Rectangle( notchleft.x, notchleft.y - NOTCH_DEPTH, notchRight.x - notchleft.x, NOTCH_DEPTH ); // we don't want the bottom bar. Clip region suppresses it g2d.draw( notch ); // 1=unused 2=shield 3=unused 4=positive 5=negative final int radius = INNER_DIAMETER / 2; g2d.setColor( UNCONNECTED_COLOR ); Point p = clockPoint( xCenter, yCenter, radius, 3 ); drawCenteredString( g2d, "\u2776" /* "\u2460" *//* white 1 */, p.x, p.y ); g2d.setColor( GROUND_COLOR ); p = clockPoint( xCenter, yCenter, radius, 0 ); drawCenteredString( g2d, "\u2777" /* black 2 */, p.x, p.y ); g2d.setColor( UNCONNECTED_COLOR ); p = clockPoint( xCenter, yCenter, radius, 9 ); drawCenteredString( g2d, "\u2778" /*"\u2462"*/ /* white 3 */, p.x, p.y ); g2d.setColor( POSITIVE_COLOR ); p = clockPoint( xCenter, yCenter, radius, 1.5 ); drawCenteredString( g2d, "\u2779" /* black 4 */, p.x, p.y ); g2d.setColor( NEGATIVE_COLOR ); p = clockPoint( xCenter, yCenter, radius, 10.5 ); drawCenteredString( g2d, "\u277a" /* black 5 */, p.x, p.y ); } }