Skip to content

Commit 1eed078

Browse files
paodbmlopezFC
authored andcommitted
feat: allow to add buttons to rotate document to toolbar-button
Close #66
1 parent ca231aa commit 1eed078

File tree

2 files changed

+83
-1
lines changed

2 files changed

+83
-1
lines changed

vcf-pdf-viewer/src/main/java/com/vaadin/componentfactory/pdfviewer/PdfViewer.java

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ public class PdfViewer extends Div {
5656
private boolean addPrintButton = false;
5757
private Button printButton;
5858

59+
/* Indicates if Rotate Clockwise button is added to toolbar or not */
60+
private boolean addRotateClockwiseButton = false;
61+
private Button rotateClockwiseButton;
62+
63+
/* Indicates if Rotate Counterclockwise button is added to toolbar or not */
64+
private boolean addRotateCounterClockwiseButton = false;
65+
private Button rotateCounterClockwiseButton;
66+
5967
public PdfViewer() {}
6068

6169
/**
@@ -266,6 +274,46 @@ public void setRenderInteractiveForms(boolean renderInteractiveForms) {
266274
public void hideZoom(boolean hideZoom) {
267275
this.getElement().setProperty("hideZoom", hideZoom);
268276
}
277+
278+
/**
279+
* Returns whether Rotate Clockwise button is added to the toolbar or not.
280+
*
281+
* @return true if the button is added to toolbar
282+
*/
283+
public boolean isAddRotateClockwiseButton() {
284+
return addRotateClockwiseButton;
285+
}
286+
287+
/**
288+
* <p>Sets the flag to indicate if Rotate Clockwise button should be added to toolbar or not.
289+
* By default the flag is set to false, so, by default the button is not added to the toolbar. </p>
290+
* <p>This flag should be set on pdf viewer initialization time.</p>
291+
*
292+
* @param addRotateClockwiseButton true if rotate clockwise button should be added to toolbar
293+
*/
294+
public void setAddRotateClockwiseButton(boolean addRotateClockwiseButton) {
295+
this.addRotateClockwiseButton = addRotateClockwiseButton;
296+
}
297+
298+
/**
299+
* Returns whether Rotate Counterclockwise button is added to the toolbar or not.
300+
*
301+
* @return true if the button is added to toolbar
302+
*/
303+
public boolean isAddRotateCounterClockwiseButton() {
304+
return addRotateCounterClockwiseButton;
305+
}
306+
307+
/**
308+
* <p>Sets the flag to indicate if Rotate Counterclockwise button should be added to toolbar or not.
309+
* By default the flag is set to false, so, by default the button is not added to the toolbar. </p>
310+
* <p>This flag should be set on pdf viewer initialization time.</p>
311+
*
312+
* @param addRotateCounterClockwiseButton true if rotate counterclockwise button should be added to toolbar
313+
*/
314+
public void setAddRotateCounterClockwiseButton(boolean addRotateCounterClockwiseButton) {
315+
this.addRotateCounterClockwiseButton = addRotateCounterClockwiseButton;
316+
}
269317

270318
@Override
271319
protected void onAttach(AttachEvent attachEvent) {
@@ -276,6 +324,12 @@ protected void onAttach(AttachEvent attachEvent) {
276324
if(addPrintButton){
277325
addPrintButton();
278326
}
327+
if(addRotateClockwiseButton){
328+
addRotateClockwiseButton();
329+
}
330+
if(addRotateCounterClockwiseButton){
331+
addRotateCounterClockwiseButton();
332+
}
279333
}
280334

281335
@Override
@@ -287,6 +341,12 @@ protected void onDetach(DetachEvent detachEvent) {
287341
if(addPrintButton){
288342
this.getElement().removeChild(printButton.getElement());
289343
}
344+
if(addRotateClockwiseButton){
345+
this.getElement().removeChild(rotateClockwiseButton.getElement());
346+
}
347+
if(addRotateCounterClockwiseButton){
348+
this.getElement().removeChild(rotateCounterClockwiseButton.getElement());
349+
}
290350
}
291351

292352
/**
@@ -333,4 +393,26 @@ private void addPrintButton() {
333393
printButton.addClickListener(e -> this.getElement().executeJs("printPdf.printPdf($0)", this.getSrc()));
334394
}
335395

396+
/**
397+
* Adds button to rotate pdf file clockwise.
398+
*/
399+
private void addRotateClockwiseButton() {
400+
rotateClockwiseButton = new Button(new Icon(VaadinIcon.ROTATE_RIGHT));
401+
rotateClockwiseButton.getElement().setAttribute("aria-label", "Rotate clockwise");
402+
rotateClockwiseButton.setThemeName("rotate-button");
403+
getElement().appendChild(rotateClockwiseButton.getElement());
404+
rotateClockwiseButton.addClickListener(e -> this.getElement().executeJs("this.rotateCw()"));
405+
}
406+
407+
/**
408+
* Adds button to rotate pdf file counterclockwise.
409+
*/
410+
private void addRotateCounterClockwiseButton() {
411+
rotateCounterClockwiseButton = new Button(new Icon(VaadinIcon.ROTATE_LEFT));
412+
rotateCounterClockwiseButton.getElement().setAttribute("aria-label", "Rotate counterclockwise");
413+
rotateCounterClockwiseButton.setThemeName("rotate-button");
414+
getElement().appendChild(rotateCounterClockwiseButton.getElement());
415+
rotateCounterClockwiseButton.addClickListener(e -> this.getElement().executeJs("this.rotateCcw()"));
416+
}
417+
336418
}

vcf-pdf-viewer/src/main/resources/META-INF/resources/frontend/styles/toolbar-button.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
:host([theme~="download-button"]), :host([theme~="print-button"]) {
1+
:host([theme~="download-button"]), :host([theme~="print-button"]), :host([theme~="rotate-button"]) {
22
background: transparent;
33
color: var(--lumo-contrast-80pct);
44
min-width: 0;

0 commit comments

Comments
 (0)