Created buffered Reader, edited it so that it uses the first two parts of a line to determine which section it is to be in.
This commit is contained in:
1 parent
e48e5305f3
commit
faeab294c0
3 files changed
+51
-21
No files matched your search
@@ -1,5 +1,7 @@
|
||||
package cvbuilder;
|
||||
|
||||
import cvbuilder.model.User;
|
||||
import cvbuilder.model.UserGroup;
|
||||
import cvbuilder.view.MainViewer;
|
||||
|
||||
import java.io.*;
|
||||
@@ -7,22 +9,39 @@ import java.io.*;
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
String file = "data/cv_repo_0.csv";
|
||||
// Buffered Reader:
|
||||
UserGroup userGroup = UserGroup.getInstance();
|
||||
|
||||
try (BufferedReader r = new BufferedReader(new FileReader(file))) {
|
||||
while (r.ready()) {
|
||||
String line = r.readLine();
|
||||
String[] split = line.split(",");
|
||||
// Skip the first line (Section,Sub-Section,Variants)
|
||||
r.readLine();
|
||||
|
||||
// Read all lines into memory so we can process by column
|
||||
String[] lines = r.lines().toArray(String[]::new);
|
||||
|
||||
// Parse each line
|
||||
for (int lineIndex = 0; lineIndex < lines.length; lineIndex++) {
|
||||
String[] parts = lines[lineIndex].split(",");
|
||||
|
||||
// Process each user column (starting from column 2, index 2)
|
||||
for (int colIndex = 2; colIndex < parts.length; colIndex++) {
|
||||
int userIndex = colIndex - 2; // User index starts from 0
|
||||
User user = userGroup.getUser(userIndex);
|
||||
|
||||
// Assign attribute based on line content
|
||||
String sectionType = parts[0] + "," + parts[1];
|
||||
switch (sectionType) {
|
||||
case "User,Name" -> user.setName(parts[colIndex]);
|
||||
case "User,Title" -> user.setTitle(parts[colIndex]);
|
||||
case "User,Email" -> user.setEmail(parts[colIndex]);
|
||||
case "Contact Information,Phone" -> user.setPhone(parts[colIndex]);
|
||||
case "Contact Information,Address" -> user.setAddress(parts[colIndex]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
System.out.print(e);
|
||||
}
|
||||
|
||||
// code outside buffered reader
|
||||
|
||||
new MainViewer();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -27,9 +27,10 @@ public class UserGroup {
|
||||
}
|
||||
|
||||
public User getUser(int index) {
|
||||
if (index >= 0 && index < users.size()) {
|
||||
return users.get(index);
|
||||
// Expand the list if necessary to accommodate the requested index
|
||||
while (index >= users.size()) {
|
||||
users.add(new User());
|
||||
}
|
||||
return null;
|
||||
return users.get(index);
|
||||
}
|
||||
}
|
||||
@@ -12,17 +12,22 @@ public class MainViewer {
|
||||
public MainViewer() {
|
||||
userGroup = UserGroup.getInstance();
|
||||
|
||||
// Create the main frame
|
||||
JFrame viewer = new JFrame("CV Builder");
|
||||
viewer.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
viewer.setSize(800, 500);
|
||||
viewer.setVisible(true);
|
||||
|
||||
// Create menu bar
|
||||
JMenuBar menuBar = new JMenuBar();
|
||||
JMenu menu = new JMenu("File");
|
||||
JMenu menu = new JMenu("Menu");
|
||||
menuBar.add(menu);
|
||||
viewer.setJMenuBar(menuBar);
|
||||
|
||||
// Add content to the frame
|
||||
populateMainPanel(viewer);
|
||||
|
||||
// Make the frame visible after all content is added
|
||||
viewer.setVisible(true);
|
||||
}
|
||||
|
||||
public void populateMainPanel(JFrame viewer) {
|
||||
@@ -60,7 +65,8 @@ public class MainViewer {
|
||||
contactT.addTab("Address", address);
|
||||
outer.addTab("Contact", contactT);
|
||||
|
||||
viewer.add(outer);
|
||||
viewer.getContentPane().add(outer);
|
||||
viewer.revalidate();
|
||||
}
|
||||
|
||||
private void populatePanel(JPanel panel) {
|
||||
@@ -68,14 +74,18 @@ public class MainViewer {
|
||||
ButtonGroup group = new ButtonGroup();
|
||||
String panelName = panel.getName();
|
||||
|
||||
if (userGroup.getUsers().isEmpty()) {
|
||||
panel.add(new JLabel("No users available"));
|
||||
return;
|
||||
}
|
||||
|
||||
for (User user : userGroup.getUsers()) {
|
||||
JRadioButton radioButton = new JRadioButton(user.getUserAttribute(panelName));
|
||||
group.add(radioButton);
|
||||
panel.add(radioButton);
|
||||
String value = user.getUserAttribute(panelName);
|
||||
if (value != null && !value.isEmpty()) {
|
||||
JRadioButton radioButton = new JRadioButton(value);
|
||||
group.add(radioButton);
|
||||
panel.add(radioButton);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SwingUtilities.invokeLater(MainViewer::new);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user