From 127ce4575f2b36c64b3ae0c223f9061c038644e4 Mon Sep 17 00:00:00 2001 From: tkellner Date: Wed, 10 Apr 2013 19:04:33 +0000 Subject: Add scrollbar to pdf preview git-svn-id: https://joinup.ec.europa.eu/svn/pdf-over/trunk@114 174cde9d-5d70-4d2a-aa98-46368bc2aaf7 --- .../gui/composites/PositioningComposite.java | 30 +++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'pdf-over-gui/src/main') 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 7d461772..9528dd1e 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 @@ -31,7 +31,12 @@ import org.eclipse.swt.awt.SWT_AWT; import org.eclipse.swt.events.KeyAdapter; import org.eclipse.swt.events.KeyEvent; import org.eclipse.swt.events.KeyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.ScrollBar; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -57,12 +62,14 @@ public class PositioningComposite extends StateComposite { private Frame frame = null; - int currentPage; + int currentPage = 0; - int numPages; + int numPages = 0; private SignaturePosition position = null; + ScrollBar scrollbar = null; + /** * Set the PDF Document to display * @param document document to display @@ -84,6 +91,7 @@ public class PositioningComposite extends StateComposite { else this.viewer.setDocument(this.pdf); this.numPages = this.pdf.getNumPages(); + this.scrollbar.setValues(1, 1, this.numPages + 1, 1, 1, 1); showPage(this.numPages); } @@ -94,11 +102,14 @@ public class PositioningComposite extends StateComposite { * @param state */ public PositioningComposite(Composite parent, int style, State state) { - super(parent, style | SWT.EMBEDDED, state); + super(parent, style | SWT.EMBEDDED | SWT.V_SCROLL, state); //this.setLayout(null); + this.setBounds(0, 0, 10, 10); + this.scrollbar = this.getVerticalBar(); this.frame = SWT_AWT.new_Frame(this); this.addKeyListener(this.keyListener); this.frame.addMouseWheelListener(this.mouseListener); + this.scrollbar.addSelectionListener(this.selectionListener); } private KeyListener keyListener = new KeyAdapter() { @@ -158,8 +169,21 @@ public class PositioningComposite extends StateComposite { } }; + private SelectionListener selectionListener = new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + PositioningComposite.this.showPage(PositioningComposite.this.scrollbar.getSelection()); + } + }; + void showPage(int page) { this.currentPage = page; + Display.getDefault().syncExec(new Runnable() { + @Override + public void run() { + PositioningComposite.this.scrollbar.setSelection(PositioningComposite.this.currentPage); + } + }); this.viewer.showPage(page); } -- cgit v1.2.3