• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

edoardof01 / sessionBuilder / 153

23 Jun 2025 05:46PM UTC coverage: 52.558% (-47.4%) from 100.0%
153

push

github

edoardof01
correzioni

188 of 282 branches covered (66.67%)

Branch coverage included in aggregate %.

449 of 930 relevant lines covered (48.28%)

0.48 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/sessionBuilder/sessionBuilder-swing/src/main/java/com/sessionBuilder/swing/SessionPanel.java
1
package com.sessionBuilder.swing;
2

3

4
import java.awt.BorderLayout;
5
import java.awt.Color;
6
import java.awt.Dimension;
7
import java.awt.FlowLayout;
8
import java.awt.Font;
9
import java.awt.event.KeyAdapter;
10
import java.awt.event.KeyEvent;
11
import java.time.Instant;
12
import java.time.LocalDate;
13
import java.time.ZoneId;
14
import java.util.ArrayList;
15
import java.util.Date;
16
import java.util.List;
17

18
import javax.swing.Box;
19
import javax.swing.BoxLayout;
20
import javax.swing.DefaultListModel;
21
import javax.swing.JButton;
22
import javax.swing.JLabel;
23
import javax.swing.JList;
24
import javax.swing.JPanel;
25
import javax.swing.JScrollPane;
26
import javax.swing.JTextField;
27
import javax.swing.SwingConstants;
28
import javax.swing.border.EmptyBorder;
29

30
import com.sessionBuilder.core.StudySession;
31
import com.sessionBuilder.core.StudySessionController;
32
import com.sessionBuilder.core.Topic;
33
import com.toedter.calendar.JDateChooser;
34

35
public class SessionPanel extends JPanel {
36

37
        private static final long serialVersionUID = 3L;
38
        private DefaultListModel<Topic> topicModel;
39
        private JLabel errorLbl;
40
        private JDateChooser dateChooser;
41
        private JList<Topic> sessionPaneltopicList;
42
        private transient StudySessionController sessionController;
43
        private TopicAndSessionManager managerView;
44
        
45
        private static final String FONT = "Dialog";
46
        
47
        public SessionPanel () {
×
48
                
49
                setBorder(new EmptyBorder(5,5,5,5));
×
50
                setLayout(new BorderLayout());
×
51
                
52
                JPanel formPanel = new JPanel();
×
53
                formPanel.setLayout(new BoxLayout(formPanel, BoxLayout.Y_AXIS));
×
54
                
55
                JPanel datePanel = new JPanel(new BorderLayout(5,5));
×
56
                JLabel dateLbl = new JLabel("Date:");
×
57
                dateLbl.setPreferredSize(new Dimension(90, 20));
×
58
                dateLbl.setHorizontalAlignment(SwingConstants.RIGHT);
×
59
                dateLbl.setFont(new Font(FONT, Font.BOLD, 14));
×
60
                dateChooser = new JDateChooser();
×
61
                dateChooser.setName("dateChooser");
×
62
                datePanel.add(dateLbl, BorderLayout.WEST);
×
63
                datePanel.add(dateChooser, BorderLayout.CENTER);
×
64
                
65
                JPanel durationPanel = new JPanel(new BorderLayout(5,0));
×
66
                JLabel durationLbl = new JLabel("Duration:");
×
67
                
68
                durationLbl.setPreferredSize(new Dimension(90, 20));
×
69
                durationLbl.setHorizontalAlignment(SwingConstants.RIGHT);
×
70
                durationLbl.setFont(new Font(FONT, Font.BOLD, 14));
×
71
                durationLbl.setName("durationLbl");
×
72
                JTextField durationField = new JTextField();
×
73
                durationField.setName("durationField");
×
74
                durationPanel.add(durationLbl, BorderLayout.WEST);
×
75
                durationPanel.add(durationField, BorderLayout.CENTER);
×
76
                
77
                JPanel notePanel = new JPanel(new BorderLayout(5,0));
×
78
                JLabel noteLabel = new JLabel("Note:");
×
79
                noteLabel.setHorizontalAlignment(SwingConstants.RIGHT);
×
80
                noteLabel.setFont(new Font(FONT, Font.BOLD, 14));
×
81
                noteLabel.setName("difficultyLbl");
×
82
                noteLabel.setPreferredSize(new Dimension(90, 20));
×
83
                noteLabel.setHorizontalAlignment(SwingConstants.RIGHT);
×
84
                JTextField noteField = new JTextField();
×
85
                noteField.setName("noteField");
×
86
                notePanel.add(noteLabel, BorderLayout.WEST);
×
87
                notePanel.add(noteField, BorderLayout.CENTER);
×
88
                
89
                formPanel.add(datePanel);
×
90
                formPanel.add(Box.createVerticalStrut(15));
×
91
                formPanel.add(durationPanel);
×
92
                formPanel.add(Box.createVerticalStrut(15));
×
93
                formPanel.add(notePanel);
×
94
                formPanel.add(Box.createVerticalStrut(7));
×
95
                
96
                JLabel topicLabel = new JLabel("Topics:");
×
97
                topicLabel.setName("topicLbl");
×
98
                topicLabel.setFont(topicLabel.getFont().deriveFont(Font.BOLD, 16f));
×
99
                
100
                topicModel = new DefaultListModel<>();
×
101
                sessionPaneltopicList = new JList<>(topicModel);
×
102
                sessionPaneltopicList.setName("sessionPanelTopicList");
×
103
                
104
                JScrollPane topics = new JScrollPane(sessionPaneltopicList);
×
105
                JPanel topicPanel = new JPanel(new BorderLayout());
×
106
                topicPanel.add(topicLabel, BorderLayout.NORTH);
×
107
                topicPanel.add(topics, BorderLayout.CENTER);
×
108
                
109
                JPanel bottomPanel = new JPanel(new BorderLayout());
×
110
                JPanel errorPanel = new JPanel();
×
111
                errorLbl = new JLabel();
×
112
                errorLbl.setForeground(Color.red);
×
113
                errorLbl.setName("sessionErrorMessage");
×
114
                errorPanel.add(errorLbl);
×
115
                
116
                JButton addSessionButton = new JButton("add");
×
117
                addSessionButton.setName("addSessionButton");
×
118
                JPanel sessionButtonPanel = new JPanel(new FlowLayout());
×
119
                sessionButtonPanel.add(addSessionButton);
×
120
                addSessionButton.setEnabled(false);
×
121
                
122
                sessionPaneltopicList.addListSelectionListener(e -> {
×
123
                        if (!e.getValueIsAdjusting()) {
×
124
                                addSessionButton.setEnabled(dateChooser.getDate() != null &&
×
125
                                        !durationField.getText().trim().isEmpty() && 
×
126
                                        !noteField.getText().trim().isEmpty() && 
×
127
                                        sessionPaneltopicList.getSelectedIndex() != -1);
×
128
                        }
129
                });
×
130
                
131
                bottomPanel.add(errorPanel, BorderLayout.NORTH);
×
132
                bottomPanel.add(sessionButtonPanel, BorderLayout.CENTER);
×
133
                
134
                JButton backSessionButton = new JButton("Back");
×
135
                backSessionButton.setName("backSessionButton");
×
136
                backSessionButton.addActionListener(e -> {
×
137
                        if (managerView != null) {
×
138
                                managerView.showMainView();
×
139
                        }
140
                });
×
141
                JPanel backSessionButtonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
×
142
                backSessionButtonPanel.add(backSessionButton);
×
143
                bottomPanel.add(backSessionButtonPanel, BorderLayout.SOUTH);
×
144
                
145
                add(formPanel, BorderLayout.NORTH);
×
146
                add(topicPanel, BorderLayout.CENTER);
×
147
                add(bottomPanel, BorderLayout.SOUTH);
×
148
                
149
                dateChooser.addPropertyChangeListener("date", e -> {
×
150
                        if (dateChooser.getDate() != null) {
×
151
                                addSessionButton.setEnabled(
×
152
                                        !durationField.getText().trim().isEmpty() && 
×
153
                                        !noteField.getText().trim().isEmpty() && 
×
154
                                        sessionPaneltopicList.getSelectedIndex() != -1
×
155
                                );
156
                        } else {
157
                                addSessionButton.setEnabled(false);
×
158
                        }
159
                });
×
160

161
                KeyAdapter btnAddEnabler = new KeyAdapter() {
×
162
                    @Override
163
                    public void keyReleased(KeyEvent e) {
164
                        addSessionButton.setEnabled(dateChooser.getDate() != null &&
165
                            !durationField.getText().trim().isEmpty() && 
166
                            !noteField.getText().trim().isEmpty() && sessionPaneltopicList.getSelectedIndex()!=-1);
167
                    }
168
                };
169

170
                durationField.addKeyListener(btnAddEnabler);
×
171
                noteField.addKeyListener(btnAddEnabler);
×
172
                
173
                addSessionButton.addActionListener(e -> {
×
174
                    if (sessionController != null) {
×
175
                        Date date = dateChooser.getDate();
×
176
                        Instant instant = date.toInstant();
×
177
                        ZoneId zoneId = ZoneId.systemDefault();
×
178
                        LocalDate localDate = instant.atZone(zoneId).toLocalDate();
×
179
                        List<Topic> selectedTopics = sessionPaneltopicList.getSelectedValuesList();
×
180
                        try {
181
                                sessionController.handleCreateSession(localDate, Integer.parseInt(durationField.getText()), 
×
182
                                        noteField.getText(), new ArrayList<>(selectedTopics));
×
183
                                errorLbl.setText("");
×
184
                        } catch (Exception ex) {
×
185
                                showGeneralError("Errore nel salvare la sessione: " + ex.getMessage());
×
186
                        }
×
187
                    }
188
                });
×
189
                
190
        }
×
191
        
192
        public DefaultListModel<Topic> getTopicModel() {
193
                return topicModel;
×
194
        }
195
        
196
        public void setSessionController(StudySessionController sessionController) {
197
                this.sessionController = sessionController;
×
198
        }
×
199

200
        public void showSessionError(String message, StudySession session) {
201
                errorLbl.setText(message + ": " + session);
×
202
        }
×
203
        
204
        public void showGeneralError(String error) {
205
                errorLbl.setText(error);
×
206
        }
×
207
        
208
        public void setManagerView(TopicAndSessionManager managerView) {
209
                this.managerView = managerView;
×
210
        }
×
211
        
212
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc