Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Choose which tool to autoselect #122

Merged
merged 19 commits into from
Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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 @@ -376,6 +376,13 @@ public WindowManagementCallback getWindowManagementCallback() {
*/
public void setPropertiesManager(ViewerPropertiesManager propertiesManager) {
this.propertiesManager = propertiesManager;
//Migrate old boolean property to new int property
Copy link
Owner

@pcorless pcorless Mar 31, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, never really had to think about migrating properties before. How did you decide on PROPERTY_ANNOTATION_INK_SELECTION_ENABLED as the property to set off of? What I might suggest as an alternative is changing the properties keys. The next release is going to be major so we can break anything we can get our hands on api wise. Perhaps change the keys ICEpdfDEfault.properties and similarly in ViewerPropertiesManager to something like this:

application.annotation.highlight.selection.enabled -> application.annotation.highlight.selection.type

Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, if I remember well I just picked one of them at random, assuming that most people would have the same value for every option.
That'd be cleaner to do that indeed, I think it's a good idea. But I'm wondering if it makes sense to have a property for each annotation tool or if one for all of them would be sufficient?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original implementation was a separate setting for each tool. I guess this could still be done but it's going to get messy in the properties panel. Perhaps separate properties but still unify as one in the properties panel so they could be tweaked at a later date. I'll leave it up to you as you have good understanding of what your users need.

final String property = propertiesManager.getPreferences().get(PROPERTY_ANNOTATION_INK_SELECTION_ENABLED, "false");
if (property.equals("true")) {
ALL_SELECTION_PROPERTIES.forEach(p -> propertiesManager.setInt(p, DocumentViewModel.DISPLAY_TOOL_SELECTION));
} else if (property.equals("false")) {
ALL_SELECTION_PROPERTIES.forEach(p -> propertiesManager.setInt(p, 0));
}
}

/**
Expand Down Expand Up @@ -4322,7 +4329,7 @@ public void setPageViewMode(final int viewMode, boolean refresh) {

public void setDocumentToolMode(final int toolType) {
// nothing to do tool should already be setup.
if (documentViewController.isToolModeSelected(toolType))
if (toolType == 0 || documentViewController.isToolModeSelected(toolType))
return;

// set the tool mode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.icepdf.ri.common.ColorChooserButton;
import org.icepdf.ri.common.DragDropColorList;
import org.icepdf.ri.common.SwingController;
import org.icepdf.ri.common.views.DocumentViewModel;
import org.icepdf.ri.util.ViewerPropertiesManager;

import javax.swing.*;
Expand All @@ -31,6 +32,7 @@
import java.awt.event.ActionListener;
import java.util.Arrays;
import java.util.ResourceBundle;
import java.util.logging.Logger;
import java.util.prefs.Preferences;

/**
Expand All @@ -47,7 +49,7 @@
public class AnnotationPreferencesPanel extends JPanel implements ListSelectionListener, ActionListener {

// layouts constraint
private GridBagConstraints constraints;
private final GridBagConstraints constraints;

private DragDropColorList dragDropColorList;
private JButton addNamedColorButton;
Expand All @@ -56,11 +58,11 @@ public class AnnotationPreferencesPanel extends JPanel implements ListSelectionL
private ColorChooserButton colorButton;
private JTextField colorLabelTextField;

private SwingController swingController;
private Preferences preferences;
private final SwingController swingController;
private final Preferences preferences;

public AnnotationPreferencesPanel(SwingController controller, ViewerPropertiesManager propertiesManager,
ResourceBundle messageBundle) {
public AnnotationPreferencesPanel(final SwingController controller, final ViewerPropertiesManager propertiesManager,
final ResourceBundle messageBundle) {

this.swingController = controller;
preferences = propertiesManager.getPreferences();
Expand All @@ -75,7 +77,7 @@ public AnnotationPreferencesPanel(SwingController controller, ViewerPropertiesMa
constraints.anchor = GridBagConstraints.NORTH;
constraints.insets = new Insets(5, 5, 5, 5);

JPanel namedColorsPanel = new JPanel(new GridBagLayout());
final JPanel namedColorsPanel = new JPanel(new GridBagLayout());
namedColorsPanel.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED),
messageBundle.getString("viewer.dialog.viewerPreferences.section.annotations.named.border.label"),
TitledBorder.LEFT,
Expand All @@ -90,22 +92,23 @@ public AnnotationPreferencesPanel(SwingController controller, ViewerPropertiesMa
constraints.anchor = GridBagConstraints.NORTH;
constraints.insets = new Insets(5, 5, 5, 5);

JPanel recentColorsPanel = new JPanel(new GridBagLayout());
final JPanel recentColorsPanel = new JPanel(new GridBagLayout());
recentColorsPanel.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED),
messageBundle.getString("viewer.dialog.viewerPreferences.section.annotations.recent.border.label"),
TitledBorder.LEFT,
TitledBorder.DEFAULT_POSITION));
addGB(recentColorsPanel, new JLabel(messageBundle.getString(
"viewer.dialog.viewerPreferences.section.annotations.recent.colors.label")),
0, 0, 1, 1);
JButton resetResentColorsButton = new JButton(messageBundle.getString(
final JButton resetResentColorsButton = new JButton(messageBundle.getString(
"viewer.dialog.viewerPreferences.section.annotations.recent.colors.button"));
resetResentColorsButton.addActionListener(e -> {
// clear the preferences for recent colours.
preferences.put(ViewerPropertiesManager.PROPERTY_ANNOTATION_RECENT_COLORS, "");
// rebuild the annotation drop down panels.
firePropertyChange(PropertyConstants.ANNOTATION_COLOR_PROPERTY_PANEL_CHANGE, null, true);
});

constraints.anchor = GridBagConstraints.WEST;
constraints.fill = GridBagConstraints.NONE;
constraints.weightx = 0;
Expand All @@ -114,36 +117,41 @@ public AnnotationPreferencesPanel(SwingController controller, ViewerPropertiesMa
"viewer.dialog.viewerPreferences.section.annotations.recent.colors.label")),
0, 0, 1, 1);
addGB(recentColorsPanel, resetResentColorsButton, 1, 0, 1, 1);

constraints.fill = GridBagConstraints.BOTH;
constraints.weightx = 1.0;
constraints.weighty = 1.0;
constraints.anchor = GridBagConstraints.NORTH;
constraints.insets = new Insets(5, 5, 5, 5);
JPanel miscSettingsPanel = new JPanel(new GridBagLayout());
miscSettingsPanel.setBorder(new TitledBorder(
new EtchedBorder(EtchedBorder.LOWERED),

final JPanel miscSettingsPanel = new JPanel(new GridBagLayout());
miscSettingsPanel.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED),
messageBundle.getString("viewer.dialog.viewerPreferences.section.annotations.misc.border.label"),
TitledBorder.LEFT,
TitledBorder.DEFAULT_POSITION));
JCheckBox autoselectBox = new JCheckBox(messageBundle.getString(
"viewer.dialog.viewerPreferences.section.annotations.misc.autoselect.checkbox"));
autoselectBox.setSelected(ViewerPropertiesManager.getInstance().getPreferences().
getBoolean(ViewerPropertiesManager.PROPERTY_ANNOTATION_INK_SELECTION_ENABLED, false));
autoselectBox.addActionListener(actionEvent -> {
JCheckBox box = (JCheckBox) actionEvent.getSource();
boolean selected = box.isSelected();
String[] allProperties = {
ViewerPropertiesManager.PROPERTY_ANNOTATION_CIRCLE_SELECTION_ENABLED,
ViewerPropertiesManager.PROPERTY_ANNOTATION_HIGHLIGHT_SELECTION_ENABLED,
ViewerPropertiesManager.PROPERTY_ANNOTATION_INK_SELECTION_ENABLED,
ViewerPropertiesManager.PROPERTY_ANNOTATION_LINE_SELECTION_ENABLED,
ViewerPropertiesManager.PROPERTY_ANNOTATION_LINK_SELECTION_ENABLED,
ViewerPropertiesManager.PROPERTY_ANNOTATION_SQUARE_SELECTION_ENABLED,
ViewerPropertiesManager.PROPERTY_ANNOTATION_TEXT_SELECTION_ENABLED,
ViewerPropertiesManager.PROPERTY_ANNOTATION_FREE_TEXT_SELECTION_ENABLED};
Arrays.stream(allProperties).forEach(p -> ViewerPropertiesManager.getInstance().getPreferences().putBoolean(p, selected));
TitledBorder.LEFT, TitledBorder.DEFAULT_POSITION));
final ToolItem[] tools = {
new ToolItem(0,
messageBundle.getString("viewer.dialog.viewerPreferences.section.annotations.misc.autoselect.none")),
new ToolItem(DocumentViewModel.DISPLAY_TOOL_SELECTION,
messageBundle.getString("viewer.toolbar.tool.select.tooltip")),
new ToolItem(DocumentViewModel.DISPLAY_TOOL_TEXT_SELECTION,
messageBundle.getString("viewer.toolbar.tool.text.tooltip")),
new ToolItem(DocumentViewModel.DISPLAY_TOOL_PAN,
messageBundle.getString("viewer.toolbar.tool.pan.tooltip"))
};
final JComboBox<ToolItem> autoselectCbb = new JComboBox<>(tools);
final JLabel autoselectLabel = new JLabel(
messageBundle.getString("viewer.dialog.viewerPreferences.section.annotations.misc.autoselect.label"));
final int toolIdx = ViewerPropertiesManager.getInstance().getPreferences()
.getInt(ViewerPropertiesManager.PROPERTY_ANNOTATION_INK_SELECTION_ENABLED, 0);
autoselectCbb.setSelectedItem(Arrays.stream(tools).filter(t -> t.toolIdx == toolIdx).findAny().orElse(tools[0]));
autoselectCbb.addActionListener(actionEvent -> {
final JComboBox<ToolItem> box = (JComboBox<ToolItem>) actionEvent.getSource();
final ToolItem selected = box.getItemAt(box.getSelectedIndex());
ViewerPropertiesManager.ALL_SELECTION_PROPERTIES.forEach(p ->
ViewerPropertiesManager.getInstance().getPreferences().putInt(p, selected.toolIdx));
});
addGB(miscSettingsPanel, autoselectBox, 0, 0, 1, 1);
addGB(miscSettingsPanel, autoselectLabel, 0, 0, 1, 1);
addGB(miscSettingsPanel, autoselectCbb, 1, 0, 1, 1);

// add the panels.
constraints.fill = GridBagConstraints.BOTH;
Expand All @@ -161,12 +169,12 @@ public AnnotationPreferencesPanel(SwingController controller, ViewerPropertiesMa
addGB(this, new Label(" "), 0, 3, 1, 1);
}

private void buildNamedColors(JPanel panel, ResourceBundle messageBundle) {
private void buildNamedColors(final JPanel panel, final ResourceBundle messageBundle) {
// build out named color model
dragDropColorList = new DragDropColorList(swingController, preferences);

// create current list of colours
JScrollPane scrollPane = new JScrollPane(dragDropColorList);
final JScrollPane scrollPane = new JScrollPane(dragDropColorList);
addGB(panel, scrollPane, 0, 0, 5, 1);

dragDropColorList.addListSelectionListener(this);
Expand Down Expand Up @@ -215,8 +223,8 @@ private void buildNamedColors(JPanel panel, ResourceBundle messageBundle) {
}

@Override
public void valueChanged(ListSelectionEvent e) {
DragDropColorList colorList = (DragDropColorList) e.getSource();
public void valueChanged(final ListSelectionEvent e) {
final DragDropColorList colorList = (DragDropColorList) e.getSource();
if (colorList.isSelectionEmpty()) {
// disable all but the add controls.
updateNamedColorButton.setEnabled(false);
Expand All @@ -235,8 +243,8 @@ public void valueChanged(ListSelectionEvent e) {
colorLabelTextField.setEnabled(true);
colorButton.setEnabled(true);

int selectedIndex = colorList.getSelectedIndex();
DragDropColorList.ColorLabel colorLabel = colorList.getModel().getElementAt(selectedIndex);
final int selectedIndex = colorList.getSelectedIndex();
final DragDropColorList.ColorLabel colorLabel = colorList.getModel().getElementAt(selectedIndex);

colorLabelTextField.setText(colorLabel.getLabel());
ColorChooserButton.setButtonBackgroundColor(colorLabel.getColor(), colorButton);
Expand All @@ -245,8 +253,8 @@ public void valueChanged(ListSelectionEvent e) {
}

@Override
public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
public void actionPerformed(final ActionEvent e) {
final Object source = e.getSource();
if (source == addNamedColorButton) {
dragDropColorList.addNamedColor(colorButton.getBackground(), colorLabelTextField.getText());
// clear the label
Expand All @@ -262,13 +270,28 @@ public void actionPerformed(ActionEvent e) {
firePropertyChange(PropertyConstants.ANNOTATION_COLOR_PROPERTY_PANEL_CHANGE, null, true);
}

private void addGB(JPanel layout, Component component,
int x, int y,
int rowSpan, int colSpan) {
private void addGB(final JPanel layout, final Component component,
final int x, final int y,
final int rowSpan, final int colSpan) {
constraints.gridx = x;
constraints.gridy = y;
constraints.gridwidth = rowSpan;
constraints.gridheight = colSpan;
layout.add(component, constraints);
}

private static class ToolItem {
private final int toolIdx;
private final String toolName;

private ToolItem(final int toolIdx, final String toolName) {
this.toolIdx = toolIdx;
this.toolName = toolName;
}

@Override
public String toString() {
return toolName;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,9 @@ public void mouseReleased(MouseEvent e) {
popupAnnotationComponent.getAnnotation().setOpen(false);


// set the annotation tool to he select tool
if (preferences.getBoolean(ViewerPropertiesManager.PROPERTY_ANNOTATION_CIRCLE_SELECTION_ENABLED, false)) {
documentViewController.getParentController().setDocumentToolMode(
DocumentViewModel.DISPLAY_TOOL_SELECTION);
}
// set the annotation tool to the given tool
documentViewController.getParentController().setDocumentToolMode(
preferences.getInt(ViewerPropertiesManager.PROPERTY_ANNOTATION_CIRCLE_SELECTION_ENABLED, 0));

rectangle = null;
// clear the rectangle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,9 @@ public void createFreeTextAnnotation(int x, int y, boolean setSelectionTool) {
// add them to the container, using absolute positioning.
documentViewController.addNewAnnotation(comp);

// set the annotation tool to he select tool
if (setSelectionTool && preferences.getBoolean(ViewerPropertiesManager.PROPERTY_ANNOTATION_FREE_TEXT_SELECTION_ENABLED, false)) {
documentViewController.getParentController().setDocumentToolMode(DocumentViewModel.DISPLAY_TOOL_SELECTION);
}
// set the annotation tool to the given tool
documentViewController.getParentController().setDocumentToolMode(
preferences.getInt(ViewerPropertiesManager.PROPERTY_ANNOTATION_FREE_TEXT_SELECTION_ENABLED, 0));

// request focus so that editing can take place.
((FreeTextAnnotationComponent) comp).requestTextAreaFocus();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,9 @@ protected void createMarkupAnnotationFromTextSelection(MouseEvent e) {
// create the text markup annotation.
createTextMarkupAnnotation(highlightBounds);

// set the annotation tool to he select tool
if (preferences.getBoolean(ViewerPropertiesManager.PROPERTY_ANNOTATION_HIGHLIGHT_SELECTION_ENABLED, false)) {
documentViewController.getParentController().setDocumentToolMode(
DocumentViewModel.DISPLAY_TOOL_SELECTION);
}
// set the annotation tool to the given tool
documentViewController.getParentController().setDocumentToolMode(
preferences.getInt(ViewerPropertiesManager.PROPERTY_ANNOTATION_HIGHLIGHT_SELECTION_ENABLED, 0));
}

public static ArrayList<Shape> getSelectedTextBounds(AbstractPageViewComponent pageViewComponent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,9 @@ public void mouseReleased(MouseEvent e) {
popupAnnotationComponent.setVisible(false);
popupAnnotationComponent.getAnnotation().setOpen(false);

// set the annotation tool to he select tool
if (preferences.getBoolean(ViewerPropertiesManager.PROPERTY_ANNOTATION_INK_SELECTION_ENABLED, false)) {
documentViewController.getParentController().setDocumentToolMode(
DocumentViewModel.DISPLAY_TOOL_SELECTION);
}
// set the annotation tool to the given tool
documentViewController.getParentController().setDocumentToolMode(
preferences.getInt(ViewerPropertiesManager.PROPERTY_ANNOTATION_INK_SELECTION_ENABLED, 0));

// clear the path
inkPath = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,9 @@ public void mouseReleased(MouseEvent e) {
popupAnnotationComponent.setVisible(false);
popupAnnotationComponent.getAnnotation().setOpen(false);

// set the annotation tool to he select tool
if (preferences.getBoolean(ViewerPropertiesManager.PROPERTY_ANNOTATION_LINE_SELECTION_ENABLED, false)) {
documentViewController.getParentController().setDocumentToolMode(
DocumentViewModel.DISPLAY_TOOL_SELECTION);
}
// set the annotation tool to the given tool
documentViewController.getParentController().setDocumentToolMode(
preferences.getInt(ViewerPropertiesManager.PROPERTY_ANNOTATION_LINE_SELECTION_ENABLED, 0));

// clear the rectangle
clearRectangle(pageViewComponent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,9 @@ public void mouseReleased(MouseEvent e) {
// add them to the container, using absolute positioning.
documentViewController.addNewAnnotation(comp);

// set the annotation tool to he select tool
if (preferences.getBoolean(ViewerPropertiesManager.PROPERTY_ANNOTATION_LINK_SELECTION_ENABLED, false)) {
documentViewController.getParentController().setDocumentToolMode(
DocumentViewModel.DISPLAY_TOOL_SELECTION);
}
// set the annotation tool to the given tool
documentViewController.getParentController().setDocumentToolMode(
preferences.getInt(ViewerPropertiesManager.PROPERTY_ANNOTATION_LINK_SELECTION_ENABLED, 0));

// clear the rectangle
clearRectangle(pageViewComponent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,9 @@ public void mouseReleased(MouseEvent e) {
popupAnnotationComponent.setVisible(false);
popupAnnotationComponent.getAnnotation().setOpen(false);

// set the annotation tool to he select tool
if (preferences.getBoolean(ViewerPropertiesManager.PROPERTY_ANNOTATION_SQUARE_SELECTION_ENABLED, false)) {
documentViewController.getParentController().setDocumentToolMode(
DocumentViewModel.DISPLAY_TOOL_SELECTION);
}
// set the annotation tool to the given tool
documentViewController.getParentController().setDocumentToolMode(
preferences.getInt(ViewerPropertiesManager.PROPERTY_ANNOTATION_SQUARE_SELECTION_ENABLED, 0));

rectangle = null;
// clear the rectangle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,9 @@ public void mouseReleased(MouseEvent e) {
popupAnnotationComponent.setVisible(true);
popupAnnotationComponent.getAnnotation().setOpen(true);
popupAnnotationComponent.focusTextArea();
// set the annotation tool to he select tool
if (preferences.getBoolean(ViewerPropertiesManager.PROPERTY_ANNOTATION_TEXT_SELECTION_ENABLED, false)) {
documentViewController.getParentController().setDocumentToolMode(
DocumentViewModel.DISPLAY_TOOL_SELECTION);
}
// set the annotation tool to the given tool
documentViewController.getParentController().setDocumentToolMode(
preferences.getInt(ViewerPropertiesManager.PROPERTY_ANNOTATION_TEXT_SELECTION_ENABLED, 0));
}

protected void checkAndApplyPreferences() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public interface DocumentViewModel {
*/
int DISPLAY_TOOL_TEXT_SELECTION = 5;
/**
* Display tool constant for adding a text selection tool.
* Display tool constant for adding a selection tool.
*/
int DISPLAY_TOOL_SELECTION = 6;
/**
Expand Down
Loading