Skip to content

Commit

Permalink
pcorlessGH-252 Implements delete all annotations button
Browse files Browse the repository at this point in the history
  • Loading branch information
gtache committed Feb 13, 2023
1 parent d18f8fe commit 5754431
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
import org.icepdf.core.pobjects.*;
import org.icepdf.core.pobjects.graphics.GraphicsState;
import org.icepdf.core.util.Library;
import org.icepdf.core.util.SystemProperties;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern;

/**
* As mentioned in 12.5.2, "Annotation Dictionaries," the meaning of an
Expand Down Expand Up @@ -158,6 +160,8 @@ public abstract class MarkupAnnotation extends Annotation {
*/
public static final Name EXT_GSTATE_NAME = new Name("ip1");

private static final Pattern REPLY_PATTERN = Pattern.compile("(?:Re: ?)+");

protected String titleText;
protected PopupAnnotation popupAnnotation;
protected float opacity = 1.0f;
Expand Down Expand Up @@ -375,4 +379,8 @@ public void setSubject(String subject) {
public String toString() {
return getPObjectReference() + " - " + getTitleText() + " - " + getContents();
}

public boolean isCurrentUserOwner() {
return REPLY_PATTERN.matcher(getTitleText()).replaceAll("").equals(SystemProperties.USER_NAME);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ public class SwingController extends ComponentAdapter
private JToggleButton zoomDynamicToolButton;
private JToggleButton selectToolButton;
// main annotation toolbar
private JButton deleteAllAnnotationsButton;
private AnnotationColorToggleButton highlightAnnotationToolButton;
private JToggleButton linkAnnotationToolButton;
private AnnotationColorToggleButton strikeOutAnnotationToolButton;
Expand Down Expand Up @@ -1227,6 +1228,25 @@ public void setAnnotationEditingModeToolButton(JToggleButton btn) {
btn.addActionListener(this);
}

/**
* Called by SwingViewerBuilder, so that Controller can setup event handling
*
* @param btn button to assign
*/
public void setDeleteAllButton(final JButton btn) {
deleteAllAnnotationsButton = btn;
btn.addActionListener(e -> {
documentViewController.getDocumentViewModel().getPageComponents().forEach(pvc -> {
final List<AbstractAnnotationComponent> comps = ((PageViewComponentImpl) pvc).getAnnotationComponents();
if (comps != null) {
final Set<AbstractAnnotationComponent> toDelete = comps.stream().filter(comp -> comp instanceof MarkupAnnotationComponent
&& ((MarkupAnnotation) comp.getAnnotation()).isCurrentUserOwner()).collect(Collectors.toSet());
toDelete.forEach(documentViewController::deleteAnnotation);
}
});
});
}

/**
* Called by SwingViewerBuilder, so that Controller can setup event handling
*
Expand Down Expand Up @@ -1691,6 +1711,7 @@ protected void reflectStateInComponents() {
setEnabled(zoomDynamicToolButton, opened && !pdfCollection);
setEnabled(textSelectToolButton, opened && canExtract && !pdfCollection);
setEnabled(selectToolButton, opened && canModify && !pdfCollection);
setEnabled(deleteAllAnnotationsButton, opened && canModify && !pdfCollection && !IS_READONLY);
setEnabled(highlightAnnotationToolButton, opened && canModify && !pdfCollection && !IS_READONLY);
setEnabled(strikeOutAnnotationToolButton, opened && canModify && !pdfCollection && !IS_READONLY);
setEnabled(underlineAnnotationToolButton, opened && canModify && !pdfCollection && !IS_READONLY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1213,7 +1213,7 @@ public JToolBar buildCompleteToolBar(boolean embeddableComponent) {
if (propertiesManager.checkAndStoreBooleanProperty(ViewerPropertiesManager.PROPERTY_SHOW_TOOLBAR_TOOL))
addToToolBar(toolbar, buildToolToolBar());
if (propertiesManager.checkAndStoreBooleanProperty(ViewerPropertiesManager.PROPERTY_SHOW_TOOLBAR_ANNOTATION))
addToToolBar(toolbar, buildAnnotationlToolBar());
addToToolBar(toolbar, buildAnnotationToolBar());
if (propertiesManager.checkAndStoreBooleanProperty(ViewerPropertiesManager.PROPERTY_SHOW_TOOLBAR_FORMS))
addToToolBar(toolbar, buildFormsToolBar());
if (propertiesManager.checkAndStoreBooleanProperty(ViewerPropertiesManager.PROPERTY_SHOW_TOOLBAR_SEARCH))
Expand Down Expand Up @@ -1576,7 +1576,7 @@ public JToolBar buildToolToolBar() {
return toolbar;
}

public JToolBar buildAnnotationlToolBar() {
public JToolBar buildAnnotationToolBar() {
JToolBar toolbar = new JToolBar();
commonToolBarSetup(toolbar, false);
if (propertiesManager.checkAndStoreBooleanProperty(
Expand Down Expand Up @@ -1627,6 +1627,10 @@ public JToolBar buildAnnotationlToolBar() {
ViewerPropertiesManager.PROPERTY_SHOW_TOOLBAR_ANNOTATION_TEXT)) {
addToToolBar(toolbar, buildTextAnnotationToolButton(iconSize));
}
if (propertiesManager.checkAndStoreBooleanProperty(
ViewerPropertiesManager.PROPERTY_SHOW_TOOLBAR_ANNOTATION_DELETE)) {
addToToolBar(toolbar, buildDeleteAllAnnotationsButton(iconSize));
}
if (SystemProperties.PRIVATE_PROPERTY_ENABLED && propertiesManager.checkAndStoreBooleanProperty(
ViewerPropertiesManager.PROPERTY_SHOW_TOOLBAR_ANNOTATION_PERMISSION)) {
addToToolBar(toolbar, buildAnnotationPermissionCombBox());
Expand All @@ -1643,7 +1647,6 @@ public JToolBar buildAnnotationlToolBar() {
ViewerPropertiesManager.PROPERTY_SHOW_TOOLBAR_ANNOTATION_PREVIEW)) {
addToToolBar(toolbar, buildAnnotationPreviewButton(iconSize));
}

return toolbar;
}

Expand Down Expand Up @@ -1757,6 +1760,17 @@ public JToggleButton buildSelectToolButton(final String imageSize) {
return btn;
}

public JButton buildDeleteAllAnnotationsButton(final String imageSize) {
final JButton btn = makeToolbarButton(
messageBundle.getString("viewer.toolbar.tool.delete.all.label"),
messageBundle.getString("viewer.toolbar.tool.delete.all.tooltip"),
"delete_all_annotations", imageSize, buttonFont);
if (viewerController != null && btn != null) {
viewerController.setDeleteAllButton(btn);
}
return btn;
}

public AbstractButton buildHighlightAnnotationToolButton(final String imageSize) {
AnnotationColorToggleButton btn = makeAnnotationToggleButton(
messageBundle.getString("viewer.toolbar.tool.highlight.label"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ public final class ViewerPropertiesManager {
public static final String PROPERTY_ANNOTATION_EDITING_MODE_ENABLED = "application.annotation.editing.mode.enabled";
// Individual controls for the annotation toolbar button commands
public static final String PROPERTY_SHOW_TOOLBAR_ANNOTATION_SELECTION = "application.toolbar.annotation.selection.enabled";
public static final String PROPERTY_SHOW_TOOLBAR_ANNOTATION_DELETE = "application.toolbar.annotation.delete.enabled";
public static final String PROPERTY_SHOW_TOOLBAR_ANNOTATION_HIGHLIGHT = "application.toolbar.annotation.highlight.enabled";
public static final String PROPERTY_SHOW_TOOLBAR_ANNOTATION_UNDERLINE = "application.toolbar.annotation.underline.enabled";
public static final String PROPERTY_SHOW_TOOLBAR_ANNOTATION_STRIKE_OUT = "application.toolbar.annotation.strikeout.enabled";
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ viewer.toolbar.tool.text.label=
viewer.toolbar.tool.text.tooltip=Text Select Tool
viewer.toolbar.tool.select.label=
viewer.toolbar.tool.select.tooltip=Select Tool
viewer.toolbar.tool.delete.all.label=Delete
viewer.toolbar.tool.delete.all.tooltip=Delete all annotations
viewer.toolbar.tool.link.label=
viewer.toolbar.tool.link.tooltip=Link Annotation Tool
viewer.toolbar.tool.highlight.label=Highlight
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -517,4 +517,6 @@ viewer.annotation.signature.properties.dialog.revocation.failure=- Revokations\u
viewer.annotation.signature.properties.dialog.certificateExpired.failure=- Signaturzertifikat ist abgelaufen.
viewer.annotation.signature.properties.dialog.showCertificates.label=Signaturzertifikat...
viewer.annotation.signature.properties.dialog.validity.title=G\u00FCltigkeitszusammenfassung
viewer.annotation.signature.properties.dialog.signerInfo.title=Unterzeichnerinformationen
viewer.annotation.signature.properties.dialog.signerInfo.title=Unterzeichnerinformationen
viewer.toolbar.tool.delete.all.label=L\u00F6schen
viewer.toolbar.tool.delete.all.tooltip=Alle Notizen l\u00F6schen
Original file line number Diff line number Diff line change
Expand Up @@ -508,4 +508,6 @@ viewer.annotation.signature.properties.dialog.revocation.failure=- Aucune v\u00E
viewer.annotation.signature.properties.dialog.certificateExpired.failure=- Le certificat du signataire est \u00E9chu.
viewer.annotation.signature.properties.dialog.showCertificates.label=Certificat du signataire...
viewer.annotation.signature.properties.dialog.validity.title=R\u00E9sum\u00E9 de la validation
viewer.annotation.signature.properties.dialog.signerInfo.title=Informations sur le signataire
viewer.annotation.signature.properties.dialog.signerInfo.title=Informations sur le signataire
viewer.toolbar.tool.delete.all.label=Supprimer
viewer.toolbar.tool.delete.all.tooltip=Supprimer toutes les annotations

0 comments on commit 5754431

Please sign in to comment.