Formatting body of enum type
Answered
I'm struggling to find formatting settings suitable for some moderately complex enum types.
In particular, I use enum types to define JTable columns:
public enum PurchaseVatTableColumns {
COL1("Voucher ID - Line", String.class, true, VatData::getVoucherId, false, null, new DefaultTableCellRenderer(), (VatData vd) -> new DefaultCellEditor(new JTextField()), SwingConstants.LEFT, null, null),
COL2("Invoice Date", Date.class, true, VatData::getInvoiceDate, true, (VatData vd, Object value) -> vd.setInvoiceDate((Date)value), new FormattedCellRenderer(new SimpleDateFormat("dd-MMM-yyyy")), (VatData vd) -> initDateCellEditor(vd), JLabel.LEFT, (VatData vd) -> showInvoiceDateTooltip(vd), (VatData vd) -> showInvoiceDateCellStyle(vd)),
COL3("Invoice ID", String.class, true, VatData::getInvoiceId, false, null, new DefaultTableCellRenderer(), (VatData vd) -> new DefaultCellEditor(new JTextField()), SwingConstants.LEFT, null, null),
COL3A("Original Inv", String.class, true, VatData::getOriginalInvoice, true, (VatData vd, Object value) -> {
vd.setOriginalInvoice((String) value);
}, new DefaultTableCellRenderer(), (VatData vd) -> new DefaultCellEditor(new JTextField() {
@Override
public Dimension getPreferredSize() {
Dimension dim = super.getPreferredSize();
dim.height *= 2;
return dim;
}
}), SwingConstants.LEFT, null, null),
COL4("Reference", String.class, true, VatData::getReference, false, null, new DefaultTableCellRenderer(), (VatData vd) -> new DefaultCellEditor(new JTextField()), SwingConstants.LEFT, null, null),
COL5("Type", String.class, true, VatData::getType, false, null, new DefaultTableCellRenderer(), (VatData vd) -> new DefaultCellEditor(new JTextField()), SwingConstants.CENTER, null, null),
COL6("VAT No", String.class, true, VatData::getVatRegistration, false, null, new DefaultTableCellRenderer(), (VatData vd) -> new DefaultCellEditor(new JTextField()), SwingConstants.LEFT, null, null),
COL7("Supplier Name", String.class, true, VatData::getName, false, null, new DefaultTableCellRenderer(), (VatData vd) -> new DefaultCellEditor(new JTextField()), SwingConstants.LEFT, null, null),
COL7A("Supplier id", String.class, true, VatData::getVendorId, false, null, new DefaultTableCellRenderer(), (VatData vd) -> new DefaultCellEditor(new JTextField()), SwingConstants.LEFT, null, null);
PurchaseVatTableColumns(String columnTitle, Class<?> columnClass, boolean visible, PurchaseVatDataGetter columnGetter, boolean editable, PurchaseVatDataSetter columnSetter, TableCellRenderer renderer, VatDataEditor editor, int alignment, PurchaseVatTooltipGetter tooltip, PurchaseVatCellStyle cellStyle) {
this.columnTitle = columnTitle;
this.columnClass = columnClass;
this.visible = visible;
this.columnGetter = columnGetter;
this.editable = editable;
this.columnSetter = columnSetter;
this.renderer = renderer;
this.editor = editor;
this.alignment = alignment;
this.tooltip = tooltip;
this.cellStyle = cellStyle;
}
... remainder excluded...
Using an enum in this way allows me to greatly simplify the table model class by referencing the interface used to get/set column values rather than using the more usual lengthy switch statements.
The problem is that I can't find any formatting settings that will nicely format the enum body.
Ideally, I'd like to see something the following where each parameter is on a new line:
COL1("Voucher ID - Line",
String.class,
true,
VatData::getVoucherId,
false,
null,
new DefaultTableCellRenderer(),
(VatData vd) -> new DefaultCellEditor(new JTextField()),
SwingConstants.LEFT,
null,
null),
COL2("Invoice Date",
Date.class,
true,
VatData::getInvoiceDate,
true,
(VatData vd, Object value) -> vd.setInvoiceDate((Date)value),
new FormattedCellRenderer(new SimpleDateFormat("dd-MMM-yyyy")),
(VatData vd) -> initDateCellEditor(vd),
JLabel.LEFT,
(VatData vd) -> showInvoiceDateTooltip(vd),
(VatData vd) -> showInvoiceDateCellStyle(vd)),
Any suggestions greatly welcome!
db
Please sign in to leave a comment.
Hi, David. Try setting Preferences | Editor | Code Style | Java | Method call arguments to "Wrap always" and "Align multiline".
Also set Enum constants to "Wrap allways"
Peter
Excellent - just what I wanted :-)
Now all I need is to figure out why parameter name hints don't show for all parameters...
db
In the Settings/Preferences dialog (⌘,), go to Editor | General | Appearance.
Next, to the Show parameter name hints option, click Configure.