Skip to content

Commit

Permalink
Copy transcript (#58)
Browse files Browse the repository at this point in the history
* Refactor constructor of Fragment

* Add copy to clipboard menu in transcript
  • Loading branch information
Thykof committed May 4, 2021
1 parent 4833353 commit 8e8e47a
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 41 deletions.
@@ -1,10 +1,8 @@
package components.interviewPanel.ContextMenus;

import components.interviewPanel.appCommands.InterviewTextCommandFactory;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.IndexRange;
import javafx.scene.control.Menu;
import javafx.scene.control.SeparatorMenuItem;
import javafx.collections.ObservableList;
import javafx.scene.control.*;
import models.Annotation;
import models.AnnotationColor;
import models.Descripteme;
Expand All @@ -22,66 +20,71 @@ public ContextMenuFactory(InterviewTextCommandFactory interviewPanelCommandFacto
this.annotationColorList = annotationColorList;
}

public ContextMenu getContextMenuSelection(IndexRange selection) {
public ContextMenu getContextMenuSelection(String selectedText, IndexRange selection) {
ContextMenu menu = new ContextMenu();
menu.getItems().add(menuItemFactory.getCatch(selection));
menu.getItems().add(new SeparatorMenuItem());
annotationColorList.forEach(annotationColor -> {
menu.getItems().add(menuItemFactory.getAnnotate(annotationColor, selection));
});
addMenuAnnotationColorList(menu.getItems(), selection);
addMenuCopyToClipboard(menu, selectedText);
return menu;
}

public ContextMenu getContextMenuAnnotation(Annotation annotation) {
public ContextMenu getContextMenuAnnotation(String selectedText, Annotation annotation) {
ContextMenu menu = new ContextMenu();
menu.getItems().add(menuItemFactory.getCatch(annotation.getIndexRange()));
menu.getItems().add(new SeparatorMenuItem());
for (AnnotationColor annotationColor : annotationColorList) {
menu.getItems().add(menuItemFactory.getAnnotate(annotationColor, annotation.getIndexRange()));
}
addMenuAnnotationColorList(menu.getItems(), annotation.getIndexRange());
menu.getItems().add(new SeparatorMenuItem());
menu.getItems().add(menuItemFactory.getEraser(annotation));
addMenuCopyToClipboard(menu, selectedText);
return menu;
}

public ContextMenu getContextMenuDescriptemeAndAnnotation(ArrayList<Descripteme> descriptemes, Annotation annotation) {
public ContextMenu getContextMenuDescriptemeAndAnnotation(String selectedText, ArrayList<Descripteme> descriptemes, Annotation annotation) {
ContextMenu menu = new ContextMenu();

// For descriptemes
for (Descripteme descripteme : descriptemes) {
Menu subMenu = new Menu(descripteme.getCroppedFragmentText());
subMenu.getItems().add(menuItemFactory.getReveal(descripteme));
subMenu.getItems().add(new SeparatorMenuItem());
for (AnnotationColor annotationColor : annotationColorList) {
subMenu.getItems().add(menuItemFactory.getAnnotate(annotationColor, descripteme.getIndexRange()));
}
menu.getItems().add(subMenu);
}
addMenuDescripteme(menu, descriptemes);

menu.getItems().add(new SeparatorMenuItem());

// For the annotation
menu.getItems().add(menuItemFactory.getCatch(annotation.getIndexRange()));
menu.getItems().add(new SeparatorMenuItem());
for (AnnotationColor annotationColor : annotationColorList) {
menu.getItems().add(menuItemFactory.getAnnotate(annotationColor, annotation.getIndexRange()));
}
addMenuAnnotationColorList(menu.getItems(), annotation.getIndexRange());
menu.getItems().add(new SeparatorMenuItem());
menu.getItems().add(menuItemFactory.getEraser(annotation));

addMenuCopyToClipboard(menu, selectedText);
return menu;
}

public ContextMenu getContextMenuDescripteme(ArrayList<Descripteme> descriptemes) {
public ContextMenu getContextMenuDescripteme(String selectedText, ArrayList<Descripteme> descriptemes) {
ContextMenu menu = new ContextMenu();
addMenuDescripteme(menu, descriptemes);
addMenuCopyToClipboard(menu, selectedText);
return menu;
}

private void addMenuDescripteme(ContextMenu menu, ArrayList<Descripteme> descriptemes) {
for (Descripteme descripteme : descriptemes) {
Menu subMenu = new Menu(descripteme.getCroppedFragmentText());
subMenu.getItems().add(menuItemFactory.getReveal(descripteme));
subMenu.getItems().add(new SeparatorMenuItem());
for (AnnotationColor annotationColor: annotationColorList) {
subMenu.getItems().add(menuItemFactory.getAnnotate(annotationColor, descripteme.getIndexRange()));
}
addMenuAnnotationColorList(subMenu.getItems(), descripteme.getIndexRange());
menu.getItems().add(subMenu);
}
return menu;
}

private void addMenuAnnotationColorList(ObservableList<MenuItem> menuItems, IndexRange selection) {
annotationColorList.forEach(annotationColor -> {
menuItems.add(menuItemFactory.getAnnotate(annotationColor, selection));
});
}

private void addMenuCopyToClipboard(ContextMenu menu, String selectedText) {
if (!selectedText.isEmpty()) {
menu.getItems().add(new SeparatorMenuItem());
menu.getItems().add(menuItemFactory.getCopyToClipboard(selectedText));
}
}
}
Expand Up @@ -47,4 +47,12 @@ public MenuItem getReveal(Descripteme descripteme) {
});
return item;
}

public MenuItem getCopyToClipboard(String selectedText) {
MenuItem item = new MenuItem(Configuration.langBundle.getString("copy_to_clipboard"));
item.setOnAction(event -> {
interviewPanelCommandFactory.getCopyToClipboardCommand(selectedText).execute();
});
return item;
}
}
Expand Up @@ -96,7 +96,6 @@ private void setUpClick() {
}

public void bind() {
System.out.println(100);
// Two listeners that update the view (highlight and underline)
this.interviewText.getAnnotationsProperty().addListener((ListChangeListener.Change<? extends Annotation> c) -> {
while (c.next()) {
Expand Down Expand Up @@ -313,16 +312,29 @@ public void updateContextMenu() {
Annotation annotation = interviewText.getAnnotationByIndex(area.getCaretPosition());
ArrayList<Descripteme> descriptemes = interviewText.getDescriptemesByIndex(area.getCaretPosition());
if (annotation != null && !descriptemes.isEmpty()) {
area.setContextMenu(contextMenuFactory.getContextMenuDescriptemeAndAnnotation(descriptemes, annotation));
area.setContextMenu(contextMenuFactory.getContextMenuDescriptemeAndAnnotation(
area.getSelectedText(),
descriptemes,
annotation)
);
}
else if (annotation != null) {
area.setContextMenu(contextMenuFactory.getContextMenuAnnotation(annotation));
area.setContextMenu(contextMenuFactory.getContextMenuAnnotation(
area.getSelectedText(),
annotation)
);
}
else if (!descriptemes.isEmpty()) {
area.setContextMenu(contextMenuFactory.getContextMenuDescripteme(descriptemes));
area.setContextMenu(contextMenuFactory.getContextMenuDescripteme(
area.getSelectedText(),
descriptemes)
);
}
else if (!area.getSelectedText().isEmpty()) {
area.setContextMenu(contextMenuFactory.getContextMenuSelection(area.getSelection()));
area.setContextMenu(contextMenuFactory.getContextMenuSelection(
area.getSelectedText(),
area.getSelection())
);
}
}
}
@@ -0,0 +1,24 @@
package components.interviewPanel.appCommands;

import utils.command.Executable;

import java.awt.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;


public class CopyToClipboardCommand implements Executable<Void> {
String selectedText;

public CopyToClipboardCommand(String selectedText) {
this.selectedText = selectedText;
}

@Override
public Void execute() {
StringSelection selection = new StringSelection(selectedText);
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(selection, selection);
return null;
}
}
Expand Up @@ -44,4 +44,8 @@ public RemoveAnnotationCommand getRemoveAnnotationCommand(Annotation annotation)
public RevealDescriptemeCommand getRevealDescriptemeCommand(Descripteme descripteme) {
return new RevealDescriptemeCommand(descripteme);
}

public CopyToClipboardCommand getCopyToClipboardCommand(String selectedText) {
return new CopyToClipboardCommand(selectedText);
}
}
4 changes: 2 additions & 2 deletions src/main/java/models/Annotation.java
Expand Up @@ -15,12 +15,12 @@ public Annotation(InterviewText interviewText, int startIndex, int endIndex, Col
}

public Annotation(Fragment fragment, Color color) {
super(fragment.interviewText, fragment.getStartIndex(), fragment.getEndIndex());
super(fragment.interviewText, fragment.getIndexRange());
this.color = color;
}

public Annotation(Annotation annotation) {
super(annotation.interviewText, annotation.getStartIndex(), annotation.getEndIndex());
super(annotation.interviewText, annotation.getIndexRange());
this.color = annotation.color;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/models/Descripteme.java
Expand Up @@ -23,7 +23,7 @@ public Descripteme(InterviewText interviewText, int startIndex, int endIndex){
}

public Descripteme(Annotation a) {
super(a.getInterviewText(), a.getStartIndex(),a.getEndIndex());
super(a.getInterviewText(), a.getIndexRange());
descripteme = new SimpleStringProperty();
descripteme.set(getSelection());
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/models/Fragment.java
Expand Up @@ -19,6 +19,12 @@ public Fragment(InterviewText interviewText, int startIndex, int endIndex) {
this.interviewText = interviewText;
}

public Fragment(InterviewText interviewText, IndexRange indexRange) {
this.startIndex = new SimpleIntegerProperty(indexRange.getStart());
this.endIndex = new SimpleIntegerProperty(indexRange.getEnd());
this.interviewText = interviewText;
}

public int getStartIndex() { return startIndex.getValue(); }
public IntegerProperty startIndexProperty() { return startIndex; }
public int getEndIndex() { return endIndex.getValue(); }
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/bundles/Lang_en.properties
Expand Up @@ -179,4 +179,5 @@ catch = Catch
delete_annotation = Delete annotation
scroll_on_reveal = Auto scroll on hover
collapse_all_moments = Collapse all moments
open_all_moments = Open all moments
open_all_moments = Open all moments
copy_to_clipboard = Copy to clipboard
3 changes: 2 additions & 1 deletion src/main/resources/bundles/Lang_fr.properties
Expand Up @@ -181,4 +181,5 @@ catch = Attraper
delete_annotation = Supprimer l'annotation
scroll_on_reveal = Centrer au survol
collapse_all_moments = Collapse tous les moments
open_all_moments = Ouvrir tous les moments
open_all_moments = Ouvrir tous les moments
copy_to_clipboard = Copier dans le presse-papiers

0 comments on commit 8e8e47a

Please sign in to comment.