From b0b3d5e20859073097d95cefa92da52f7e620d8d Mon Sep 17 00:00:00 2001 From: tkellner Date: Wed, 31 Oct 2012 16:36:41 +0000 Subject: Make sig placeholder transparent git-svn-id: https://svn.iaik.tugraz.at/svn/egiz/prj/current/12PDF-OVER-4.0@12708 3a0b52a2-8410-0410-bc02-ff6273a87459 --- .../pdfover/gui/composites/SignaturePanel.java | 35 ++++++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) (limited to 'trunk/pdf-over-gui/src') diff --git a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/SignaturePanel.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/SignaturePanel.java index f4e4f240..7fee3021 100644 --- a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/SignaturePanel.java +++ b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/SignaturePanel.java @@ -27,6 +27,7 @@ import java.awt.geom.AffineTransform; import java.awt.geom.NoninvertibleTransformException; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; +import java.awt.image.BufferedImage; import javax.swing.JPanel; @@ -49,6 +50,9 @@ public class SignaturePanel extends JPanel { /** Default serial version ID */ private static final long serialVersionUID = 1L; + /** Signature transparency (0-255) */ + private static final int SIG_TRANSPARENCY = 170; + /** The PDF file being displayed */ private PDFFile pdf = null; /** The image of the rendered PDF page being displayed */ @@ -69,6 +73,8 @@ public class SignaturePanel extends JPanel { Point2D sigScreenPos = null; /** The signature placeholder image */ private Image sigPlaceholder = null; + /** Current scaled signature placeholder image */ + BufferedImage sigPlaceholderScaled = null; /** Width of the signature placeholder in page space */ private int sigPageWidth = 0; /** Height of the signature placeholder in page space */ @@ -77,6 +83,10 @@ public class SignaturePanel extends JPanel { int sigScreenWidth = 0; /** Height of the signature placeholder in screen space */ int sigScreenHeight = 0; + /** Previous Width of the signature placeholder in screen space */ + int prevSigScreenWidth = 0; + /** Previous Height of the signature placeholder in screen space */ + int prevSigScreenHeight = 0; /** * Create a new PagePanel, with a default size of 800 by 600 pixels. @@ -242,9 +252,28 @@ public class SignaturePanel extends JPanel { g.drawRect(sigX, sigY, 100, 40); } else { - Image placeholder = this.sigPlaceholder.getScaledInstance( - this.sigScreenWidth, this.sigScreenHeight, Image.SCALE_SMOOTH); - g.drawImage(placeholder, sigX, sigY, null); + if ((this.sigScreenWidth != this.prevSigScreenWidth) + || (this.sigScreenHeight != this.prevSigScreenHeight)) + { + this.prevSigScreenWidth = this.sigScreenWidth; + this.prevSigScreenHeight = this.sigScreenHeight; + Image placeholder = this.sigPlaceholder.getScaledInstance( + this.sigScreenWidth, this.sigScreenHeight, Image.SCALE_SMOOTH); + this.sigPlaceholderScaled = new BufferedImage(this.sigScreenWidth, this.sigScreenHeight, BufferedImage.TYPE_INT_ARGB); + Graphics g2 = this.sigPlaceholderScaled.getGraphics(); + g2.drawImage(placeholder, 0, 0, null); + int[] phpixels = new int[this.sigScreenWidth * this.sigScreenHeight]; + phpixels = this.sigPlaceholderScaled.getRGB(0, 0, this.sigScreenWidth, this.sigScreenHeight, phpixels, 0, this.sigScreenWidth); + for (int i = 0; i < phpixels.length; ++i) { + Color c = new Color(phpixels[i]); + c = new Color(c.getRed(), c.getGreen(), c.getBlue(), SIG_TRANSPARENCY); + phpixels[i] = c.getRGB(); + } + this.sigPlaceholderScaled.setRGB(0, 0, this.sigScreenWidth, this.sigScreenHeight, phpixels, 0, this.sigScreenWidth); + } + g.drawImage(this.sigPlaceholderScaled, sigX, sigY, null); + g.setColor(Color.BLUE); + g.drawRect(sigX, sigY, this.sigScreenWidth, this.sigScreenHeight); } } else { -- cgit v1.2.3