From 056a7a4e8d33e3eab554621a7b1a031dfc504a19 Mon Sep 17 00:00:00 2001 From: mudabbir-ahmad Date: Thu, 3 Apr 2025 14:18:33 +0100 Subject: [PATCH] added panel border with title based on tab name --- data/cv_repo_0.csv | 2 +- src/main/java/cvbuilder/model/Address.java | 16 +++++++ src/main/java/cvbuilder/view/MainViewer.java | 50 +++++++++++++++----- 3 files changed, 56 insertions(+), 12 deletions(-) diff --git a/data/cv_repo_0.csv b/data/cv_repo_0.csv index af5a42b..0d88de8 100644 --- a/data/cv_repo_0.csv +++ b/data/cv_repo_0.csv @@ -3,4 +3,4 @@ User,Name,Scheherazade Taylor,SJ Taylor,Shaz Taylor User,Title,ms.,miss,Unknown User,Email,strongshaz@bob.com,gmail_account@gmail.com,k2320390@kingston.ac.uk Contact Information,Phone,07910582346,02083412275,Unknown -Contact Information,Address,11 Rita Road%%%%London SW8 1ND,Flat 4//// Obnoxious House%%%%Rude Road%%%%London KT16 4RT,Unknown +Contact Information,Address,11 Rita Road%%%%London SW8 1ND,Flat 4//// Obnoxious House%%%%Rude Road%%%%London KT16 4RT,Unknown%%%% diff --git a/src/main/java/cvbuilder/model/Address.java b/src/main/java/cvbuilder/model/Address.java index ba7f19b..3757f8e 100644 --- a/src/main/java/cvbuilder/model/Address.java +++ b/src/main/java/cvbuilder/model/Address.java @@ -59,6 +59,22 @@ public class Address { return sb.toString(); } + public String getDisplayFormat() { + StringBuilder sb = new StringBuilder(); + + // If flat exists, add it as a separate line + if (!flat.isEmpty()) { + sb.append(flat).append("\n\n"); + } + + // Add the rest in a comma-separated format + sb.append(addressLine1); + if (!addressLine2.isEmpty()) sb.append(", ").append(addressLine2); + if (!postcode.isEmpty()) sb.append(", ").append(postcode); + + return sb.toString(); + } + // Getters and setters public String getFlat() { return flat; diff --git a/src/main/java/cvbuilder/view/MainViewer.java b/src/main/java/cvbuilder/view/MainViewer.java index 51ccc92..0fe4ff1 100644 --- a/src/main/java/cvbuilder/view/MainViewer.java +++ b/src/main/java/cvbuilder/view/MainViewer.java @@ -87,9 +87,15 @@ public class MainViewer { } private void populatePanel(JPanel panel) { + + String panelName = panel.getName(); + String titleName = panelName.substring(0, 1).toUpperCase() + panelName.substring(1); + panel.setBorder(BorderFactory.createTitledBorder( + BorderFactory.createEtchedBorder(), titleName + )); + panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); ButtonGroup group = new ButtonGroup(); - String panelName = panel.getName(); // Add "Include in CSV" checkbox at the top - but NOT for name or email panels if (!panelName.equalsIgnoreCase("name") && !panelName.equalsIgnoreCase("email")) { @@ -124,13 +130,20 @@ public class MainViewer { User user = userGroup.getUsers().get(i); String value = user.getUserAttribute(panelName); + // Format address display if this is the address panel + String displayValue = value; + if (panelName.equalsIgnoreCase("address")) { + Address address = user.getAddress(); + displayValue = address.getDisplayFormat(); + } + if (value != null && !value.isEmpty()) { // Create a panel for each entry with radio button and action buttons JPanel entryPanel = new JPanel(); entryPanel.setLayout(new BoxLayout(entryPanel, BoxLayout.X_AXIS)); - // Create radio button - JRadioButton radioButton = new JRadioButton(value); + // Create radio button with properly formatted display value + JRadioButton radioButton = new JRadioButton(displayValue); group.add(radioButton); entryPanel.add(radioButton); @@ -157,8 +170,12 @@ public class MainViewer { case "address" -> user.setAddress(newValue); } - // Update the radio button label - radioButton.setText(newValue); + // Update the radio button label with properly formatted value + if (panelName.equalsIgnoreCase("address")) { + radioButton.setText(user.getAddress().getDisplayFormat()); + } else { + radioButton.setText(newValue); + } } }); entryPanel.add(editButton); @@ -293,7 +310,10 @@ public class MainViewer { JTextField addressLine2Field = new JTextField(); JTextField postcodeField = new JTextField(); + // Use the Address class to parse the address string Address address = new Address(initialValue); + + // Set field values from the Address object flatField.setText(address.getFlat()); addressLine1Field.setText(address.getAddressLine1()); addressLine2Field.setText(address.getAddressLine2()); @@ -311,11 +331,20 @@ public class MainViewer { int result = JOptionPane.showConfirmDialog(null, panel, title, JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); if (result == JOptionPane.OK_OPTION) { - String flat = flatField.getText().trim(); - String addressLine1 = addressLine1Field.getText().trim(); - String addressLine2 = addressLine2Field.getText().trim(); - String postcode = postcodeField.getText().trim(); - return (flat.isEmpty() ? "" : flat + "////") + addressLine1 + (addressLine2.isEmpty() ? "" : "%%%%" + addressLine2) + "%%%%" + postcode; + String newFlat = flatField.getText().trim(); + String newAddressLine1 = addressLine1Field.getText().trim(); + String newAddressLine2 = addressLine2Field.getText().trim(); + String newPostcode = postcodeField.getText().trim(); + + // Create an Address object with the new values + Address newAddress = new Address(""); + newAddress.setFlat(newFlat); + newAddress.setAddressLine1(newAddressLine1); + newAddress.setAddressLine2(newAddressLine2); + newAddress.setPostcode(newPostcode); + + // Return the CSV format of the address + return newAddress.getCsvFormat(); } return null; } @@ -595,4 +624,3 @@ public class MainViewer { } } -