added panel border with title based on tab name

This commit is contained in:
bobbert committed 2025-04-03 14:18:33 +01:00
1 parent 3101374e43
commit 056a7a4e8d
3 files changed
+56 -12

No files matched your search

+1 -1
View File
@@ -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%%%%
1 Section,Sub-Section,Variants
3 User,Title,ms.,miss,Unknown
4 User,Email,strongshaz@bob.com,gmail_account@gmail.com,k2320390@kingston.ac.uk
5 Contact Information,Phone,07910582346,02083412275,Unknown
6 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%%%%
@@ -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;
+39 -11
View File
@@ -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 {
}
}