added panel border with title based on tab name
This commit is contained in:
1 parent
3101374e43
commit
056a7a4e8d
3 files changed
+56
-12
No files matched your search
+1
-1
@@ -3,4 +3,4 @@ User,Name,Scheherazade Taylor,SJ Taylor,Shaz Taylor
|
|||||||
User,Title,ms.,miss,Unknown
|
User,Title,ms.,miss,Unknown
|
||||||
User,Email,strongshaz@bob.com,gmail_account@gmail.com,k2320390@kingston.ac.uk
|
User,Email,strongshaz@bob.com,gmail_account@gmail.com,k2320390@kingston.ac.uk
|
||||||
Contact Information,Phone,07910582346,02083412275,Unknown
|
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%%%%
|
||||||
|
@@ -59,6 +59,22 @@ public class Address {
|
|||||||
return sb.toString();
|
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
|
// Getters and setters
|
||||||
public String getFlat() {
|
public String getFlat() {
|
||||||
return flat;
|
return flat;
|
||||||
|
|||||||
@@ -87,9 +87,15 @@ public class MainViewer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void populatePanel(JPanel panel) {
|
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));
|
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
|
||||||
ButtonGroup group = new ButtonGroup();
|
ButtonGroup group = new ButtonGroup();
|
||||||
String panelName = panel.getName();
|
|
||||||
|
|
||||||
// Add "Include in CSV" checkbox at the top - but NOT for name or email panels
|
// Add "Include in CSV" checkbox at the top - but NOT for name or email panels
|
||||||
if (!panelName.equalsIgnoreCase("name") && !panelName.equalsIgnoreCase("email")) {
|
if (!panelName.equalsIgnoreCase("name") && !panelName.equalsIgnoreCase("email")) {
|
||||||
@@ -124,13 +130,20 @@ public class MainViewer {
|
|||||||
User user = userGroup.getUsers().get(i);
|
User user = userGroup.getUsers().get(i);
|
||||||
String value = user.getUserAttribute(panelName);
|
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()) {
|
if (value != null && !value.isEmpty()) {
|
||||||
// Create a panel for each entry with radio button and action buttons
|
// Create a panel for each entry with radio button and action buttons
|
||||||
JPanel entryPanel = new JPanel();
|
JPanel entryPanel = new JPanel();
|
||||||
entryPanel.setLayout(new BoxLayout(entryPanel, BoxLayout.X_AXIS));
|
entryPanel.setLayout(new BoxLayout(entryPanel, BoxLayout.X_AXIS));
|
||||||
|
|
||||||
// Create radio button
|
// Create radio button with properly formatted display value
|
||||||
JRadioButton radioButton = new JRadioButton(value);
|
JRadioButton radioButton = new JRadioButton(displayValue);
|
||||||
group.add(radioButton);
|
group.add(radioButton);
|
||||||
entryPanel.add(radioButton);
|
entryPanel.add(radioButton);
|
||||||
|
|
||||||
@@ -157,8 +170,12 @@ public class MainViewer {
|
|||||||
case "address" -> user.setAddress(newValue);
|
case "address" -> user.setAddress(newValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the radio button label
|
// Update the radio button label with properly formatted value
|
||||||
radioButton.setText(newValue);
|
if (panelName.equalsIgnoreCase("address")) {
|
||||||
|
radioButton.setText(user.getAddress().getDisplayFormat());
|
||||||
|
} else {
|
||||||
|
radioButton.setText(newValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
entryPanel.add(editButton);
|
entryPanel.add(editButton);
|
||||||
@@ -293,7 +310,10 @@ public class MainViewer {
|
|||||||
JTextField addressLine2Field = new JTextField();
|
JTextField addressLine2Field = new JTextField();
|
||||||
JTextField postcodeField = new JTextField();
|
JTextField postcodeField = new JTextField();
|
||||||
|
|
||||||
|
// Use the Address class to parse the address string
|
||||||
Address address = new Address(initialValue);
|
Address address = new Address(initialValue);
|
||||||
|
|
||||||
|
// Set field values from the Address object
|
||||||
flatField.setText(address.getFlat());
|
flatField.setText(address.getFlat());
|
||||||
addressLine1Field.setText(address.getAddressLine1());
|
addressLine1Field.setText(address.getAddressLine1());
|
||||||
addressLine2Field.setText(address.getAddressLine2());
|
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);
|
int result = JOptionPane.showConfirmDialog(null, panel, title, JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
|
||||||
if (result == JOptionPane.OK_OPTION) {
|
if (result == JOptionPane.OK_OPTION) {
|
||||||
String flat = flatField.getText().trim();
|
String newFlat = flatField.getText().trim();
|
||||||
String addressLine1 = addressLine1Field.getText().trim();
|
String newAddressLine1 = addressLine1Field.getText().trim();
|
||||||
String addressLine2 = addressLine2Field.getText().trim();
|
String newAddressLine2 = addressLine2Field.getText().trim();
|
||||||
String postcode = postcodeField.getText().trim();
|
String newPostcode = postcodeField.getText().trim();
|
||||||
return (flat.isEmpty() ? "" : flat + "////") + addressLine1 + (addressLine2.isEmpty() ? "" : "%%%%" + addressLine2) + "%%%%" + postcode;
|
|
||||||
|
// 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;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -595,4 +624,3 @@ public class MainViewer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Reference in new issue
Block a user