Skip to content

Commit 86f88a1

Browse files
OAarneRedande
authored andcommitted
Add double click functionality to organization and course selection
1 parent 40dcc78 commit 86f88a1

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

tmc-plugin/src/fi/helsinki/cs/tmc/ui/CourseListWindow.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import java.awt.Dimension;
1313
import java.awt.event.ActionEvent;
1414
import java.awt.event.ActionListener;
15+
import java.awt.event.MouseAdapter;
16+
import java.awt.event.MouseEvent;
1517
import java.util.List;
1618
import javax.swing.JButton;
1719
import javax.swing.JFrame;
@@ -30,6 +32,7 @@ public class CourseListWindow extends JPanel {
3032
private static JFrame frame;
3133
private final JList<CourseCard> courses;
3234
private PreferencesPanel prefPanel;
35+
private final JButton button;
3336

3437
public CourseListWindow(List<Course> courses, PreferencesPanel prefPanel) {
3538
this.prefPanel = prefPanel;
@@ -40,8 +43,8 @@ public CourseListWindow(List<Course> courses, PreferencesPanel prefPanel) {
4043
this.courses = new JList<>(courseCards);
4144
this.courses.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
4245
setLayout(new BorderLayout());
43-
JButton button = new JButton("Select");
44-
button.addActionListener(new SelectCourseListener(this));
46+
this.button = new JButton("Select");
47+
this.button.addActionListener(new SelectCourseListener(this));
4548

4649
this.courses.setCellRenderer(new CourseCellRenderer());
4750
this.courses.setVisibleRowCount(4);
@@ -53,9 +56,16 @@ public CourseListWindow(List<Course> courses, PreferencesPanel prefPanel) {
5356
this.courses.setBackground(new Color(242, 241, 240));
5457

5558
this.courses.setSelectedIndex(setDefaultSelectedIndex());
56-
59+
this.courses.addMouseListener(new MouseAdapter() {
60+
@Override
61+
public void mouseClicked(MouseEvent event) {
62+
if (event.getClickCount() >= 2) {
63+
button.doClick();
64+
}
65+
}
66+
});
5767
add(pane, BorderLayout.NORTH);
58-
add(button, BorderLayout.SOUTH);
68+
add(this.button, BorderLayout.SOUTH);
5969
}
6070

6171
public static void display(PreferencesPanel prefPanel) throws Exception {

tmc-plugin/src/fi/helsinki/cs/tmc/ui/OrganizationListWindow.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import java.awt.Dimension;
1212
import java.awt.event.ActionEvent;
1313
import java.awt.event.ActionListener;
14+
import java.awt.event.MouseAdapter;
15+
import java.awt.event.MouseEvent;
1416
import java.util.List;
1517
import javax.swing.JButton;
1618
import javax.swing.JFrame;
@@ -29,6 +31,7 @@ public class OrganizationListWindow extends JPanel {
2931

3032
private static JFrame frame;
3133
private final JList<OrganizationCard> organizations;
34+
private final JButton button;
3235

3336
public OrganizationListWindow(List<Organization> organizations) {
3437
OrganizationCard[] organizationCards = new OrganizationCard[organizations.size()];
@@ -37,9 +40,10 @@ public OrganizationListWindow(List<Organization> organizations) {
3740
}
3841
this.organizations = new JList<>(organizationCards);
3942
this.organizations.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
43+
4044
setLayout(new BorderLayout());
41-
JButton button = new JButton("Select");
42-
button.addActionListener(new SelectOrganizationListener(this));
45+
this.button = new JButton("Select");
46+
this.button.addActionListener(new SelectOrganizationListener(this));
4347

4448
this.organizations.setCellRenderer(new OrganizationCellRenderer());
4549
this.organizations.setVisibleRowCount(4);
@@ -51,9 +55,18 @@ public OrganizationListWindow(List<Organization> organizations) {
5155
this.organizations.setBackground(new Color(242, 241, 240));
5256

5357
this.organizations.setSelectedIndex(setDefaultSelectedIndex());
54-
58+
59+
this.organizations.addMouseListener(new MouseAdapter() {
60+
@Override
61+
public void mouseClicked(MouseEvent event) {
62+
if (event.getClickCount() >= 2) {
63+
button.doClick();
64+
}
65+
}
66+
});
67+
5568
add(pane, BorderLayout.NORTH);
56-
add(button, BorderLayout.SOUTH);
69+
add(this.button, BorderLayout.SOUTH);
5770
}
5871

5972
public static void display() throws Exception {

0 commit comments

Comments
 (0)