diff options
author | tkellner <tkellner@3a0b52a2-8410-0410-bc02-ff6273a87459> | 2012-08-24 17:06:14 +0000 |
---|---|---|
committer | tkellner <tkellner@3a0b52a2-8410-0410-bc02-ff6273a87459> | 2012-08-24 17:06:14 +0000 |
commit | 10de5d4e81aec570993762979a6c0017752c2f21 (patch) | |
tree | 4e606e8eed5061f3e3fcd0b44e620160c985b910 /trunk | |
parent | 55290a62b6eaecc4cf0554c196862a6fe24d894e (diff) | |
download | pdf-over-10de5d4e81aec570993762979a6c0017752c2f21.tar.gz pdf-over-10de5d4e81aec570993762979a6c0017752c2f21.tar.bz2 pdf-over-10de5d4e81aec570993762979a6c0017752c2f21.zip |
Test display of signature composite
git-svn-id: https://svn.iaik.tugraz.at/svn/egiz/prj/current/12PDF-OVER-4.0@12412 3a0b52a2-8410-0410-bc02-ff6273a87459
Diffstat (limited to 'trunk')
2 files changed, 74 insertions, 40 deletions
diff --git a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/PositioningComposite.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/PositioningComposite.java index 559c6b26..0b50f0bb 100644 --- a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/PositioningComposite.java +++ b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/PositioningComposite.java @@ -20,13 +20,22 @@ import java.io.File; import java.io.IOException; import org.eclipse.swt.SWT; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.PaintEvent; +import org.eclipse.swt.events.PaintListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Canvas; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; import org.icepdf.core.exceptions.PDFException; import org.icepdf.core.exceptions.PDFSecurityException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import at.asit.pdfover.gui.workflow.states.State; import at.asit.pdfover.signator.SignaturePosition; @@ -36,43 +45,18 @@ import at.asit.pdfover.signator.SignaturePosition; * */ public class PositioningComposite extends StateComposite { - - private PDFViewerComposite viewer = null; - /** - * Set the PDF Document to display - * @param document document to display - * @throws PDFException Error parsing PDF document - * @throws PDFSecurityException Error decrypting PDF document (not supported) - * @throws IOException I/O Error - */ - public void displayDocument(File document) throws PDFException, PDFSecurityException, IOException { - if (this.viewer == null) - this.viewer = new PDFViewerComposite(this, SWT.EMBEDDED | SWT.NO_BACKGROUND, document); - else - this.viewer.setDocument(document); - } + * SFL4J Logger instance + **/ + static final Logger log = LoggerFactory + .getLogger(PositioningComposite.class); - /** - * Selection listener when position was fixed - */ - private final class PositionSelectedListener extends SelectionAdapter { - /** - * Empty constructor - */ - public PositionSelectedListener() { - } + PDFViewerComposite viewer = null; - @Override - public void widgetSelected(SelectionEvent e) { - // TODO: FIX to get real position - PositioningComposite.this.setPosition(new SignaturePosition()); // Setting auto position for testing - PositioningComposite.this.state.updateStateMachine(); - } - } + private Canvas signature = null; private SignaturePosition position = null; - + /** * Gets the position of the signature * @return the SignaturePosition @@ -90,6 +74,32 @@ public class PositioningComposite extends StateComposite { } /** + * Set the PDF Document to display + * @param document document to display + * @throws PDFException Error parsing PDF document + * @throws PDFSecurityException Error decrypting PDF document (not supported) + * @throws IOException I/O Error + */ + public void displayDocument(File document) throws PDFException, PDFSecurityException, IOException { + if (this.viewer == null) + { + this.viewer = new PDFViewerComposite(this, SWT.EMBEDDED | SWT.NO_BACKGROUND, document); + resizeViewer(); + } + else + this.viewer.setDocument(document); + } + + void resizeViewer() + { + Rectangle clientArea = this.getClientArea(); + log.debug("Resizing to 0,0," + clientArea.width + "," + clientArea.height); + this.viewer.setBounds(0, 0, clientArea.width, clientArea.height); + + this.signature.setBounds(clientArea.width - 250, clientArea.height -200, 150, 40); + } + + /** * Create the composite. * @param parent * @param style @@ -97,12 +107,36 @@ public class PositioningComposite extends StateComposite { */ public PositioningComposite(Composite parent, int style, State state) { super(parent, style, state); - this.setLayout(new FillLayout()); + this.setLayout(null); + + this.addListener(SWT.Resize, new Listener() { + @Override + public void handleEvent(Event arg0) { + if (PositioningComposite.this.viewer != null) + resizeViewer(); + } + }); -// Button btn_position = new Button(this, SWT.NATIVE | SWT.RESIZE); -// btn_position.setBounds(10, 50, 100, 30); -// btn_position.setText("FAKE Position"); -// btn_position.addSelectionListener(new PositionSelectedListener()); + this.signature = new Canvas(this, SWT.NO_BACKGROUND); + this.signature.addPaintListener(new PaintListener() { + @Override + public void paintControl(PaintEvent e) { + PositioningComposite.this.viewer.redraw(); + Rectangle r = ((Canvas) e.widget).getBounds(); + e.gc.setForeground(e.display.getSystemColor(SWT.COLOR_RED)); +// e.gc.setB + e.gc.drawFocus(5, 5, r.width - 10, r.height - 10); + e.gc.drawText("Position Signature", 10, 10); + } + }); + this.signature.addMouseListener(new MouseAdapter() { + @Override + public void mouseDown(MouseEvent e) { + // TODO: FIX to get real position + PositioningComposite.this.setPosition(new SignaturePosition()); // Setting auto position for testing + PositioningComposite.this.state.updateStateMachine(); + } + }); } @Override @@ -115,6 +149,7 @@ public class PositioningComposite extends StateComposite { */ @Override public void doLayout() { + this.layout(true, true); } } diff --git a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PositioningState.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PositioningState.java index 1c45b2b5..b595d9e1 100644 --- a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PositioningState.java +++ b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PositioningState.java @@ -45,7 +45,6 @@ public class PositioningState extends State { /** * SFL4J Logger instance **/ - @SuppressWarnings("unused") private static final Logger log = LoggerFactory .getLogger(PositioningState.class); @@ -55,7 +54,7 @@ public class PositioningState extends State { if (this.positionComposite == null) { this.positionComposite = this.stateMachine.getGUIProvider().createComposite(PositioningComposite.class, SWT.RESIZE, this); - log.debug("Displaying " + stateMachine.getStatus().getDocument()); + log.debug("Displaying " + this.stateMachine.getStatus().getDocument()); this.positionComposite.displayDocument(this.stateMachine.getStatus().getDocument()); } |