From ee80e6672414409500a8f24b24ad22a526b00750 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20N=C3=A4rhi?= Date: Fri, 8 Jan 2021 16:32:12 +0200 Subject: [PATCH 1/2] Control clicking exercise opens submit window --- .../cs/apluscourses/ui/base/TreeView.java | 19 +++++++++++-------- .../ui/exercise/ExercisesView.java | 5 +++++ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main/java/fi/aalto/cs/apluscourses/ui/base/TreeView.java b/src/main/java/fi/aalto/cs/apluscourses/ui/base/TreeView.java index e6f959f24..433bf7d19 100644 --- a/src/main/java/fi/aalto/cs/apluscourses/ui/base/TreeView.java +++ b/src/main/java/fi/aalto/cs/apluscourses/ui/base/TreeView.java @@ -10,8 +10,8 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.Collections; +import java.util.HashMap; import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; import java.util.stream.Stream; import javax.swing.SwingUtilities; @@ -34,7 +34,7 @@ public class TreeView extends com.intellij.ui.treeStructure.Tree { } }; - private final transient Set nodeAppliedListeners = ConcurrentHashMap.newKeySet(); + private final transient HashMap nodeAppliedListeners = new HashMap<>(); @NotNull public static SelectableNodeViewModel getViewModel(Object node) { @@ -98,12 +98,12 @@ private void update() { restoreExpandedState(expandedState); } - public void addNodeAppliedListener(ActionListener listener) { - nodeAppliedListeners.add(listener); + public void addNodeAppliedListener(String key, ActionListener listener) { + nodeAppliedListeners.put(key, listener); } - public void removeNodeAppliedListener(ActionListener listener) { - nodeAppliedListeners.remove(listener); + public void removeNodeAppliedListener(String key) { + nodeAppliedListeners.remove(key); } @NotNull @@ -151,9 +151,12 @@ protected class TreeMouseListener extends MouseAdapter { @Override public void mouseClicked(@NotNull MouseEvent e) { - if (e.getClickCount() == 2 && selectedItem != null) { + if (e.getClickCount() == 1 && e.isControlDown() && selectedItem != null) { ActionEvent actionEvent = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, null); - nodeAppliedListeners.forEach(listener -> listener.actionPerformed(actionEvent)); + nodeAppliedListeners.get("submitExercise").actionPerformed(actionEvent); + } else if (e.getClickCount() == 2 && selectedItem != null) { + ActionEvent actionEvent = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, null); + nodeAppliedListeners.get("openSubmission").actionPerformed(actionEvent); } } } diff --git a/src/main/java/fi/aalto/cs/apluscourses/ui/exercise/ExercisesView.java b/src/main/java/fi/aalto/cs/apluscourses/ui/exercise/ExercisesView.java index cfa609879..a08f08da7 100644 --- a/src/main/java/fi/aalto/cs/apluscourses/ui/exercise/ExercisesView.java +++ b/src/main/java/fi/aalto/cs/apluscourses/ui/exercise/ExercisesView.java @@ -4,6 +4,7 @@ import com.intellij.openapi.application.ModalityState; import fi.aalto.cs.apluscourses.intellij.actions.ActionUtil; import fi.aalto.cs.apluscourses.intellij.actions.OpenSubmissionAction; +import fi.aalto.cs.apluscourses.intellij.actions.SubmitExerciseAction; import fi.aalto.cs.apluscourses.presentation.exercise.ExercisesTreeViewModel; import fi.aalto.cs.apluscourses.ui.GuiObject; import fi.aalto.cs.apluscourses.ui.base.TreeView; @@ -43,7 +44,11 @@ private void createUIComponents() { exerciseGroupsTree = new TreeView(); exerciseGroupsTree.setCellRenderer(new ExercisesTreeRenderer()); exerciseGroupsTree.addNodeAppliedListener( + "openSubmission", ActionUtil.createOnEventLauncher(OpenSubmissionAction.ACTION_ID, exerciseGroupsTree)); + exerciseGroupsTree.addNodeAppliedListener( + "submitExercise", + ActionUtil.createOnEventLauncher(SubmitExerciseAction.ACTION_ID, exerciseGroupsTree)); } public TreeView getExerciseGroupsTree() { From f3cb13381ef88c92815e9063aab03c74cc544e05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20N=C3=A4rhi?= Date: Fri, 8 Jan 2021 18:08:14 +0200 Subject: [PATCH 2/2] Separate listener sets for different clicks --- .../cs/apluscourses/ui/base/TreeView.java | 25 +++++++++++++------ .../ui/exercise/ExercisesView.java | 6 ++--- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/main/java/fi/aalto/cs/apluscourses/ui/base/TreeView.java b/src/main/java/fi/aalto/cs/apluscourses/ui/base/TreeView.java index 433bf7d19..72ac7a469 100644 --- a/src/main/java/fi/aalto/cs/apluscourses/ui/base/TreeView.java +++ b/src/main/java/fi/aalto/cs/apluscourses/ui/base/TreeView.java @@ -10,8 +10,8 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.Collections; -import java.util.HashMap; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; import java.util.stream.Stream; import javax.swing.SwingUtilities; @@ -34,7 +34,8 @@ public class TreeView extends com.intellij.ui.treeStructure.Tree { } }; - private final transient HashMap nodeAppliedListeners = new HashMap<>(); + private final transient Set ctrlClickListeners = ConcurrentHashMap.newKeySet(); + private final transient Set doubleClickListeners = ConcurrentHashMap.newKeySet(); @NotNull public static SelectableNodeViewModel getViewModel(Object node) { @@ -98,12 +99,20 @@ private void update() { restoreExpandedState(expandedState); } - public void addNodeAppliedListener(String key, ActionListener listener) { - nodeAppliedListeners.put(key, listener); + public void addDoubleClickListener(ActionListener listener) { + doubleClickListeners.add(listener); } - public void removeNodeAppliedListener(String key) { - nodeAppliedListeners.remove(key); + public void removeDoubleClickListener(ActionListener listener) { + doubleClickListeners.remove(listener); + } + + public void addCtrlClickListener(ActionListener listener) { + ctrlClickListeners.add(listener); + } + + public void removeCtrlClickListener(ActionListener listener) { + ctrlClickListeners.remove(listener); } @NotNull @@ -153,10 +162,10 @@ protected class TreeMouseListener extends MouseAdapter { public void mouseClicked(@NotNull MouseEvent e) { if (e.getClickCount() == 1 && e.isControlDown() && selectedItem != null) { ActionEvent actionEvent = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, null); - nodeAppliedListeners.get("submitExercise").actionPerformed(actionEvent); + ctrlClickListeners.forEach(listener -> listener.actionPerformed(actionEvent)); } else if (e.getClickCount() == 2 && selectedItem != null) { ActionEvent actionEvent = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, null); - nodeAppliedListeners.get("openSubmission").actionPerformed(actionEvent); + doubleClickListeners.forEach(listener -> listener.actionPerformed(actionEvent)); } } } diff --git a/src/main/java/fi/aalto/cs/apluscourses/ui/exercise/ExercisesView.java b/src/main/java/fi/aalto/cs/apluscourses/ui/exercise/ExercisesView.java index a08f08da7..e84024b2c 100644 --- a/src/main/java/fi/aalto/cs/apluscourses/ui/exercise/ExercisesView.java +++ b/src/main/java/fi/aalto/cs/apluscourses/ui/exercise/ExercisesView.java @@ -43,11 +43,9 @@ public void viewModelChanged(@Nullable ExercisesTreeViewModel viewModel) { private void createUIComponents() { exerciseGroupsTree = new TreeView(); exerciseGroupsTree.setCellRenderer(new ExercisesTreeRenderer()); - exerciseGroupsTree.addNodeAppliedListener( - "openSubmission", + exerciseGroupsTree.addDoubleClickListener( ActionUtil.createOnEventLauncher(OpenSubmissionAction.ACTION_ID, exerciseGroupsTree)); - exerciseGroupsTree.addNodeAppliedListener( - "submitExercise", + exerciseGroupsTree.addCtrlClickListener( ActionUtil.createOnEventLauncher(SubmitExerciseAction.ACTION_ID, exerciseGroupsTree)); }