diff --git a/extras/src/main/java/edu/umd/cs/piccolox/pswing/PSwing.java b/extras/src/main/java/edu/umd/cs/piccolox/pswing/PSwing.java index 23c08e4..a0037d5 100644 --- a/extras/src/main/java/edu/umd/cs/piccolox/pswing/PSwing.java +++ b/extras/src/main/java/edu/umd/cs/piccolox/pswing/PSwing.java @@ -364,43 +364,24 @@ * * @param g2 graphics context for rendering the JComponent */ - public void paint( Graphics2D g2 ) { - if( component.getBounds().isEmpty() ) { + public void paint(Graphics2D g2) { + if (component.getBounds().isEmpty()) { // The component has not been initialized yet. return; } - PSwingRepaintManager manager = (PSwingRepaintManager)RepaintManager.currentManager( component ); - manager.lockRepaint( component ); + PSwingRepaintManager manager = (PSwingRepaintManager) RepaintManager.currentManager(component); + manager.lockRepaint(component); + + RenderingHints oldHints = g2.getRenderingHints(); + + g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, + RenderingHints.VALUE_FRACTIONALMETRICS_OFF); + component.paint(g2); + + g2.setRenderingHints(oldHints); - Graphics2D bufferedGraphics = null; - if( !isBufferValid() ) { - // Get the graphics context associated with a new buffered image. - // Use TYPE_INT_ARGB_PRE so that transparent components look good on Windows. - buffer = new BufferedImage( component.getWidth(), component.getHeight(), BufferedImage.TYPE_INT_ARGB_PRE ); - bufferedGraphics = buffer.createGraphics(); - } - else { - // Use the graphics context associated with the existing buffered image - bufferedGraphics = buffer.createGraphics(); - // Clear the buffered image to prevent artifacts on Macintosh - bufferedGraphics.setBackground( BUFFER_BACKGROUND_COLOR ); - bufferedGraphics.clearRect( 0, 0, component.getWidth(), component.getHeight() ); - } - - // Start with the rendering hints from the provided graphics context - bufferedGraphics.setRenderingHints( g2.getRenderingHints() ); - - //PSwing sometimes causes JComponent text to render with "..." when fractional font metrics are enabled. These are now always disabled for the offscreen buffer. - bufferedGraphics.setRenderingHint( RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_OFF ); - - // Draw the component to the buffer - component.paint( bufferedGraphics ); - - // Draw the buffer to g2's associated drawing surface - g2.drawRenderedImage( buffer, IDENTITY_TRANSFORM ); - - manager.unlockRepaint( component ); + manager.unlockRepaint(component); } public void setVisible(boolean visible) {