diff options
author | tkellner <tkellner@174cde9d-5d70-4d2a-aa98-46368bc2aaf7> | 2013-04-10 18:56:05 +0000 |
---|---|---|
committer | tkellner <tkellner@174cde9d-5d70-4d2a-aa98-46368bc2aaf7> | 2013-04-10 18:56:05 +0000 |
commit | e93486731f269d48f83f816291f3fa690809aee0 (patch) | |
tree | f79038b2a6f18c738484fe281271bf076724a292 | |
parent | 52be56b5efa84ec4ddd2499cf8724a076144c724 (diff) | |
download | pdf-over-e93486731f269d48f83f816291f3fa690809aee0.tar.gz pdf-over-e93486731f269d48f83f816291f3fa690809aee0.tar.bz2 pdf-over-e93486731f269d48f83f816291f3fa690809aee0.zip |
Test display of signature composite
git-svn-id: https://joinup.ec.europa.eu/svn/pdf-over/trunk@47 174cde9d-5d70-4d2a-aa98-46368bc2aaf7
-rw-r--r-- | pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/PositioningComposite.java | 111 | ||||
-rw-r--r-- | pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PositioningState.java | 3 |
2 files changed, 74 insertions, 40 deletions
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/PositioningComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/PositioningComposite.java index 559c6b26..0b50f0bb 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/PositioningComposite.java +++ b/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/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PositioningState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PositioningState.java index 1c45b2b5..b595d9e1 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PositioningState.java +++ b/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()); } |