Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
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.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
import java.util.HashSet;
import java.util.Locale;
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 @@ -161,6 +163,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 @@ -406,4 +410,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 @@ -224,6 +224,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 @@ -1233,6 +1234,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 @@ -1698,6 +1718,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 @@ -1224,7 +1224,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 @@ -1587,7 +1587,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 @@ -1638,6 +1638,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 @@ -1654,7 +1658,6 @@ public JToolBar buildAnnotationlToolBar() {
ViewerPropertiesManager.PROPERTY_SHOW_TOOLBAR_ANNOTATION_PREVIEW)) {
addToToolBar(toolbar, buildAnnotationPreviewButton(iconSize));
}

return toolbar;
}

Expand Down Expand Up @@ -1768,6 +1771,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 @@ -15,6 +15,7 @@
*/
package org.icepdf.ri.common.utility.annotation.properties;

import org.icepdf.core.pobjects.annotations.MarkupAnnotation;
import org.icepdf.ri.common.EscapeJDialog;
import org.icepdf.ri.common.SwingController;
import org.icepdf.ri.common.views.AnnotationComponent;
Expand Down Expand Up @@ -131,7 +132,9 @@ public void setAnnotationComponent(AnnotationComponent annotation) {
}

// disable the component if the annotation is readonly.
if (annotation.getAnnotation().getFlagReadOnly()) {
if (annotation.getAnnotation().getFlagReadOnly() ||
(annotation.getAnnotation() instanceof MarkupAnnotation &&
!((MarkupAnnotation) annotation.getAnnotation()).isCurrentUserOwner())) {
if (annotationPropertyPanel != null) annotationPropertyPanel.setEnabled(false);
actionsPanel.setEnabled(false);
borderPanel.setEnabled(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.icepdf.ri.common.utility.annotation.properties;

import org.icepdf.core.pobjects.annotations.Annotation;
import org.icepdf.core.pobjects.annotations.MarkupAnnotation;
import org.icepdf.ri.common.views.AnnotationComponent;
import org.icepdf.ri.common.views.Controller;

Expand Down Expand Up @@ -101,9 +102,8 @@ public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
noRotateComboBox.setEnabled(enabled);
noZoomComboBox.setEnabled(enabled);
// leaving this always enabled just so users can change it back in editor mode.
// does this make sense? not sure could argue either way.
readOnlyComboBox.setEnabled(true);
boolean canModify = ((MarkupAnnotation) currentAnnotationComponent.getAnnotation()).isCurrentUserOwner();
readOnlyComboBox.setEnabled(canModify);
printableComboBox.setEnabled(enabled);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import org.icepdf.core.SecurityCallback;
import org.icepdf.core.pobjects.*;
import org.icepdf.core.pobjects.annotations.MarkupAnnotation;
import org.icepdf.core.search.DocumentSearchController;
import org.icepdf.core.util.Library;
import org.icepdf.core.util.PropertyConstants;
Expand Down Expand Up @@ -1305,7 +1306,9 @@ public void addPropertyChangeListener(PropertyChangeListener l) {
public void deleteCurrentAnnotation() {
AbstractAnnotationComponent annotationComponent = (AbstractAnnotationComponent)
documentViewModel.getCurrentAnnotation();
if (annotationComponent != null && !(annotationComponent instanceof PopupAnnotationComponent)) {
if (annotationComponent != null && !(annotationComponent instanceof PopupAnnotationComponent) &&
(!(annotationComponent.getAnnotation() instanceof MarkupAnnotation) ||
((MarkupAnnotation) annotationComponent.getAnnotation()).isCurrentUserOwner())) {
deleteAnnotation(annotationComponent);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,23 +92,24 @@ public MarkupAnnotationPopupMenu(MarkupAnnotationComponent markupAnnotationCompo
public void buildGui() {
ViewerPropertiesManager propertiesManager = ViewerPropertiesManager.getInstance();
boolean modifyDocument = controller.havePermissionToModifyDocument();

boolean hasEditRights = annotationComponent != null && ((MarkupAnnotation) annotationComponent.getAnnotation()).isCurrentUserOwner();
boolean canModify = modifyDocument && hasEditRights;
// status change commands.
statusNoneMenuItem = new JMenuItem(
messageBundle.getString("viewer.annotation.popup.status.none.label"));
statusNoneMenuItem.setEnabled(modifyDocument);
statusNoneMenuItem.setEnabled(canModify);
statusAcceptedItem = new JMenuItem(
messageBundle.getString("viewer.annotation.popup.status.accepted.label"));
statusAcceptedItem.setEnabled(modifyDocument);
statusAcceptedItem.setEnabled(canModify);
statusCancelledMenuItem = new JMenuItem(
messageBundle.getString("viewer.annotation.popup.status.cancelled.label"));
statusCancelledMenuItem.setEnabled(modifyDocument);
statusCancelledMenuItem.setEnabled(canModify);
statusCompletedMenuItem = new JMenuItem(
messageBundle.getString("viewer.annotation.popup.status.completed.label"));
statusCompletedMenuItem.setEnabled(modifyDocument);
statusCompletedMenuItem.setEnabled(canModify);
statusRejectedMenuItem = new JMenuItem(
messageBundle.getString("viewer.annotation.popup.status.rejected.label"));
statusRejectedMenuItem.setEnabled(modifyDocument);
statusRejectedMenuItem.setEnabled(canModify);
// generic commands, open/minimize all
openAllMenuItem = new JMenuItem(
messageBundle.getString("viewer.annotation.popup.openAll.label"));
Expand All @@ -122,23 +123,23 @@ public void buildGui() {
// annotation creation menus.
addDestinationMenuItem = new JMenuItem(
messageBundle.getString("viewer.utilityPane.view.selectionTool.contextMenu.addDestination.label"));
addDestinationMenuItem.setEnabled(modifyDocument);
addDestinationMenuItem.setEnabled(canModify);
addDestinationMenuItem.addActionListener(this);
addDestinationMenuItem.setIcon(new ImageIcon(Images.get("destination_20.png")));
addFreeTextMenuItem1 = new JMenuItem(
messageBundle.getString("viewer.annotation.popup.addAnnotation.freeText.label"));
addFreeTextMenuItem1.setEnabled(modifyDocument);
addFreeTextMenuItem1.setEnabled(canModify);
addFreeTextMenuItem1.setIcon(new ImageIcon(Images.get("freetext_annot_a_20.png")));
addFreeTextMenuItem1.addActionListener(this);
addFreeTextMenuItem2 = new JMenuItem(
messageBundle.getString("viewer.annotation.popup.addAnnotation.freeText.label"));
addFreeTextMenuItem2.setEnabled(modifyDocument);
addFreeTextMenuItem2.setEnabled(canModify);
addFreeTextMenuItem2.setIcon(new ImageIcon(Images.get("freetext_annot_a_20.png")));
addFreeTextMenuItem2.addActionListener(this);
// addition of set status menu
JMenu submenu = new JMenu(
messageBundle.getString("viewer.annotation.popup.addAnnotation.label"));
addDestinationMenuItem.setEnabled(modifyDocument);
addDestinationMenuItem.setEnabled(canModify);
submenu.add(addDestinationMenuItem);
submenu.addSeparator();
submenu.add(addFreeTextMenuItem2);
Expand Down Expand Up @@ -195,7 +196,7 @@ public void buildGui() {
submenu.add(setAllPublicMenuItem);
add(submenu);
addSeparator();
submenu.setEnabled(modifyDocument);
submenu.setEnabled(canModify);
}

// generic commands, open/minimize all
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ private void buildGUI() {
textArea.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(PopupAnnotation.BORDER_COLOR),
BorderFactory.createEmptyBorder(2, 2, 2, 2)));

textArea.setEditable(selectedMarkupAnnotation.isCurrentUserOwner());
textArea.setLineWrap(true);
textArea.getDocument().addDocumentListener(this);
if (!disableSpellCheck) {
Expand Down Expand Up @@ -763,13 +764,15 @@ public void valueChanged(TreeSelectionEvent e) {
public void refreshPopupState() {
if (textArea != null) {
// update the private/public button.
privateToggleButton.setVisible(selectedMarkupAnnotation.isCurrentUserOwner());
if (privateToggleButton.isVisible()) {
privateToggleButton.setSelected(selectedMarkupAnnotation.getFlagPrivateContents());
}
// update the text
textArea.getDocument().removeDocumentListener(this);
textArea.setText(selectedMarkupAnnotation.getContents());
textArea.getDocument().addDocumentListener(this);
textArea.setEditable(selectedMarkupAnnotation.isCurrentUserOwner());
}
refreshCreationLabel();
}
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