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 all 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 @@ -4279,7 +4279,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 Down Expand Up @@ -47,7 +48,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 +57,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 +76,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 +91,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 +116,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_TYPE, 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 +168,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 +222,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 +242,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 +252,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 +269,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 @@ -25,7 +25,6 @@
import org.icepdf.ri.common.ViewModel;
import org.icepdf.ri.common.views.AbstractPageViewComponent;
import org.icepdf.ri.common.views.DocumentViewController;
import org.icepdf.ri.common.views.DocumentViewModel;
import org.icepdf.ri.common.views.annotations.AnnotationComponentFactory;
import org.icepdf.ri.common.views.annotations.MarkupAnnotationComponent;
import org.icepdf.ri.common.views.annotations.PopupAnnotationComponent;
Expand Down Expand Up @@ -229,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_TYPE, 0));

rectangle = null;
// clear the rectangle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,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_TYPE, 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 @@ -251,11 +251,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_TYPE, 0));
}

public static ArrayList<Shape> getSelectedTextBounds(AbstractPageViewComponent pageViewComponent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.icepdf.ri.common.ViewModel;
import org.icepdf.ri.common.views.AbstractPageViewComponent;
import org.icepdf.ri.common.views.DocumentViewController;
import org.icepdf.ri.common.views.DocumentViewModel;
import org.icepdf.ri.common.views.annotations.AnnotationComponentFactory;
import org.icepdf.ri.common.views.annotations.MarkupAnnotationComponent;
import org.icepdf.ri.common.views.annotations.PopupAnnotationComponent;
Expand Down Expand Up @@ -195,11 +194,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_TYPE, 0));

// clear the path
inkPath = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.icepdf.ri.common.views.AbstractPageViewComponent;
import org.icepdf.ri.common.views.AnnotationCallback;
import org.icepdf.ri.common.views.DocumentViewController;
import org.icepdf.ri.common.views.DocumentViewModel;
import org.icepdf.ri.common.views.annotations.AnnotationComponentFactory;
import org.icepdf.ri.common.views.annotations.MarkupAnnotationComponent;
import org.icepdf.ri.common.views.annotations.PopupAnnotationComponent;
Expand Down Expand Up @@ -230,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_TYPE, 0));

// clear the rectangle
clearRectangle(pageViewComponent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.icepdf.core.pobjects.annotations.AnnotationFactory;
import org.icepdf.ri.common.views.AbstractPageViewComponent;
import org.icepdf.ri.common.views.DocumentViewController;
import org.icepdf.ri.common.views.DocumentViewModel;
import org.icepdf.ri.common.views.annotations.AbstractAnnotationComponent;
import org.icepdf.ri.common.views.annotations.AnnotationComponentFactory;
import org.icepdf.ri.util.ViewerPropertiesManager;
Expand Down Expand Up @@ -92,11 +91,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_TYPE, 0));

// clear the rectangle
clearRectangle(pageViewComponent);
Expand Down
Loading