• 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/TopicPanel.java
1
package com.sessionBuilder.swing;
2

3
import java.awt.BorderLayout;
4
import java.awt.Color;
5
import java.awt.Dimension;
6
import java.awt.FlowLayout;
7
import java.awt.event.KeyAdapter;
8
import java.awt.event.KeyEvent;
9
import java.util.ArrayList;
10
import java.util.List;
11
import java.awt.Font;
12
import javax.swing.Box;
13
import javax.swing.JScrollPane;
14
import javax.swing.JTextField;
15
import javax.swing.SwingConstants;
16
import javax.swing.BoxLayout;
17
import javax.swing.DefaultListModel;
18
import javax.swing.JButton;
19
import javax.swing.JLabel;
20
import javax.swing.JList;
21
import javax.swing.JPanel;
22
import javax.swing.border.EmptyBorder;
23
import com.sessionBuilder.core.StudySession;
24
import com.sessionBuilder.core.Topic;
25
import com.sessionBuilder.core.TopicController;
26

27
public class TopicPanel extends JPanel {
28
        
29
        private static final long serialVersionUID = 2L;
30
        private DefaultListModel<StudySession> sessionModel;
31
        private JLabel errorLbl;
32
        private transient TopicController topicController;
33
        private TopicAndSessionManager managerView;
34
        
35
        private static final String FONT = "Dialog";
36
        
37
        public TopicPanel() {
×
38
                setBorder(new EmptyBorder(5,5,5,5));
×
39
                setLayout(new BorderLayout());
×
40
                
41
                JPanel formPanel = new JPanel();
×
42
                formPanel.setLayout(new BoxLayout(formPanel, BoxLayout.Y_AXIS));
×
43
                
44
                // Name panel
45
                JPanel namePanel = new JPanel((new BorderLayout(5,0)));
×
46
                JLabel nameLabel = new JLabel("Name:");
×
47
                nameLabel.setPreferredSize(new Dimension(90, 20));
×
48
                nameLabel.setHorizontalAlignment(SwingConstants.RIGHT);
×
49
                nameLabel.setFont(new Font(FONT, Font.BOLD, 14));
×
50
                nameLabel.setName("nameLbl");
×
51
                JTextField nameField = new JTextField();
×
52
                nameField.setName("nameField");
×
53
                namePanel.add(nameLabel, BorderLayout.WEST);
×
54
                namePanel.add(nameField, BorderLayout.CENTER);
×
55
                
56
                JPanel descriptionPanel = new JPanel(new BorderLayout(5,0));
×
57
                JLabel descriptionLabel = new JLabel("Description:");
×
58
                
59
                descriptionLabel.setPreferredSize(new Dimension(90, 20));
×
60
                descriptionLabel.setHorizontalAlignment(SwingConstants.RIGHT);
×
61
                descriptionLabel.setFont(new Font(FONT, Font.BOLD, 14));
×
62
                descriptionLabel.setName("descriptionLbl");
×
63
                JTextField descriptionField = new JTextField();
×
64
                descriptionField.setName("descriptionField");
×
65
                descriptionPanel.add(descriptionLabel, BorderLayout.WEST);
×
66
                descriptionPanel.add(descriptionField, BorderLayout.CENTER);
×
67
                
68
                JPanel difficultyPanel = new JPanel(new BorderLayout(5,0));
×
69
                JLabel difficultyLabel = new JLabel("Difficulty:");
×
70
                
71
                difficultyLabel.setHorizontalAlignment(SwingConstants.RIGHT);
×
72
                difficultyLabel.setFont(new Font(FONT, Font.BOLD, 14));
×
73
                difficultyLabel.setName("difficultyLbl");
×
74
                difficultyLabel.setPreferredSize(new Dimension(90, 20));
×
75
                difficultyLabel.setHorizontalAlignment(SwingConstants.RIGHT);
×
76
                JTextField difficultyField = new JTextField();
×
77
                difficultyField.setName("difficultyField");
×
78
                difficultyPanel.add(difficultyLabel, BorderLayout.WEST);
×
79
                difficultyPanel.add(difficultyField, BorderLayout.CENTER);
×
80
                
81
                
82
                formPanel.add(namePanel);
×
83
                formPanel.add(Box.createVerticalStrut(15));
×
84
                formPanel.add(descriptionPanel);
×
85
                formPanel.add(Box.createVerticalStrut(15));
×
86
                formPanel.add(difficultyPanel);
×
87
                formPanel.add(Box.createVerticalStrut(7));
×
88
                
89
                // Sessions
90
                JLabel sessionLabel = new JLabel("Sessions:");
×
91
                sessionLabel.setName("sessionLbl");
×
92
                sessionLabel.setFont(sessionLabel.getFont().deriveFont(Font.BOLD, 16f));
×
93
                
94
                sessionModel = new DefaultListModel<>();
×
95
                JList<StudySession> sessionList = new JList<>(sessionModel);
×
96
                sessionList.setName("topicPanelSessionList");
×
97
                JScrollPane sessions = new JScrollPane(sessionList);
×
98
                
99
                JPanel sessionPanel = new JPanel(new BorderLayout());
×
100
                sessionPanel.add(sessionLabel, BorderLayout.NORTH);
×
101
                sessionPanel.add(sessions, BorderLayout.CENTER);
×
102
                
103
                JPanel bottomPanel = new JPanel(new BorderLayout());
×
104
                JButton addTopicButton = new JButton("add");
×
105
                addTopicButton.setName("addTopicButton");
×
106
                JPanel topicButtonPanel = new JPanel(new FlowLayout());
×
107
                topicButtonPanel.add(addTopicButton);
×
108
                addTopicButton.setEnabled(false);
×
109
                errorLbl = new JLabel();
×
110
                errorLbl.setName("errorTopicPanelLbl");
×
111
                errorLbl.setForeground(Color.red);
×
112
                difficultyLabel.setFont(new Font(FONT, Font.BOLD, 14));
×
113
                JPanel errorPanel = new JPanel();
×
114
                errorPanel.add(errorLbl);
×
115
                bottomPanel.add(topicButtonPanel, BorderLayout.CENTER);
×
116
                bottomPanel.add(errorPanel, BorderLayout.NORTH);
×
117
                
118
                JButton backButton = new JButton("Back");
×
119
                backButton.setName("backButton");
×
120
                backButton.addActionListener(e -> {
×
121
                        if (managerView != null) {
×
122
                                managerView.showMainView();
×
123
                        }
124
                });
×
125
                JPanel backButtonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
×
126
                backButtonPanel.add(backButton);
×
127
                bottomPanel.add(backButtonPanel, BorderLayout.SOUTH);
×
128
                
129
                add(formPanel, BorderLayout.NORTH);
×
130
                add(sessionPanel, BorderLayout.CENTER);
×
131
                add(bottomPanel, BorderLayout.SOUTH);
×
132
                
133
                KeyAdapter btnAddEnabler = new KeyAdapter() {
×
134
                        @Override
135
                        public void keyReleased(KeyEvent e) {
136
                                addTopicButton.setEnabled( !nameField.getText().trim().isEmpty() &&
137
                                                !descriptionField.getText().trim().isEmpty() && !difficultyField.getText().trim().isEmpty());
138
                        }
139
                };
140
                nameField.addKeyListener(btnAddEnabler);
×
141
                descriptionField.addKeyListener(btnAddEnabler);
×
142
                difficultyField.addKeyListener(btnAddEnabler);
×
143
                
144
                addTopicButton.addActionListener( e -> {
×
145
                        if (topicController != null) {
×
146
                                List<StudySession> selectedSessions = sessionList.getSelectedValuesList();
×
147
                                try {
148
                                        topicController.handleCreateTopic(nameField.getText(), descriptionField.getText() , 
×
149
                                                        Integer.parseInt(difficultyField.getText()), new ArrayList<>(selectedSessions));
×
150
                                        errorLbl.setText(" ");
×
151
                                } catch (Exception ex) {
×
152
                                        showGeneralError("Errore nel salvare il topic: " + ex.getMessage());
×
153
                                }
×
154
                        }
155
                });
×
156
                
157
        }
×
158
        
159
        public void setManagerView (TopicAndSessionManager managerView) {
160
                this.managerView = managerView;
×
161
        }
×
162
        
163
        public DefaultListModel<StudySession> getSessionModel(){
164
                return sessionModel;
×
165
        }
166
        
167
        public void showTopicError(String message, Topic topic) {
168
                errorLbl.setText(message + ": " + topic);
×
169
        }
×
170

171
        public void showGeneralError(String string) {
172
                errorLbl.setText(string);
×
173
        }
×
174
        
175
        public void setTopicController(TopicController controller) {
176
                this.topicController = controller;
×
177
        }
×
178
        
179
        
180
        
181
        
182
}
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