}
@Override
protected void paintComponent(Graphics g) {
if (circuitState != null) {
Circuit circuit = circuitState.getCircuit();
Bounds bds = circuit.getBounds(g);
Dimension size = getSize();
double scaleX = (double) (size.width - 2 * BORDER) / bds.getWidth();
double scaleY = (double) (size.height - 2 * BORDER) / bds.getHeight();
double scale = Math.min(1.0, Math.min(scaleX, scaleY));
Graphics gCopy = g.create();
int borderX = (int) ((size.width - bds.getWidth() * scale) / 2);
int borderY = (int) ((size.height - bds.getHeight() * scale) / 2);
gCopy.translate(borderX, borderY);
if (scale != 1.0 && g instanceof Graphics2D) {
((Graphics2D) gCopy).scale(scale, scale);
}
gCopy.translate(-bds.getX(), -bds.getY());
ComponentDrawContext context = new ComponentDrawContext(this, circuit,
circuitState, g, gCopy);
context.setShowState(false);
context.setShowColor(false);
circuit.draw(context, Collections.<Component>emptySet());
if (ports != null) {
gCopy.setColor(AppearancePort.COLOR);
int width = Math.max(4, (int) ((2 / scale) + 0.5));
GraphicsUtil.switchToWidth(gCopy, width);
for (Instance port : ports) {