From d4258c302bbee7ae10a2c92433fc6a3e72e87961 Mon Sep 17 00:00:00 2001 From: GoldenGnu Date: Sun, 28 Apr 2024 23:48:40 +0200 Subject: [PATCH] Bug Fix: Stockpile target column sometimes truncate editable numbers (Again) Issue #431 --- .../gui/shared/table/JAutoColumnTable.java | 3 -- .../gui/shared/table/TableCellRenderers.java | 51 +++++++++++++++++++ .../gui/tabs/stockpile/JStockpileTable.java | 15 ++---- 3 files changed, 56 insertions(+), 13 deletions(-) diff --git a/src/main/java/net/nikr/eve/jeveasset/gui/shared/table/JAutoColumnTable.java b/src/main/java/net/nikr/eve/jeveasset/gui/shared/table/JAutoColumnTable.java index 249331574..4268c39d2 100644 --- a/src/main/java/net/nikr/eve/jeveasset/gui/shared/table/JAutoColumnTable.java +++ b/src/main/java/net/nikr/eve/jeveasset/gui/shared/table/JAutoColumnTable.java @@ -435,9 +435,6 @@ private int resizeColumn(final JTable jTable, final TableColumn column, final in continue; } component = renderer.getTableCellRendererComponent(jTable, jTable.getValueAt(rowIndex, columnIndex), false, false, rowIndex, columnIndex); - if (overwrite) { - component = prepareRenderer(renderer, rowIndex, columnIndex); - } int width = component.getPreferredSize().width; if (useCache) { rowsWidth.put(cellValue, width); diff --git a/src/main/java/net/nikr/eve/jeveasset/gui/shared/table/TableCellRenderers.java b/src/main/java/net/nikr/eve/jeveasset/gui/shared/table/TableCellRenderers.java index 7a4ab566f..3bbf5933b 100644 --- a/src/main/java/net/nikr/eve/jeveasset/gui/shared/table/TableCellRenderers.java +++ b/src/main/java/net/nikr/eve/jeveasset/gui/shared/table/TableCellRenderers.java @@ -21,6 +21,7 @@ package net.nikr.eve.jeveasset.gui.shared.table; +import ca.odell.glazedlists.swing.DefaultEventTableModel; import java.awt.Color; import java.awt.Component; import java.util.Date; @@ -36,8 +37,11 @@ import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.TableCellEditor; import net.nikr.eve.jeveasset.data.settings.tag.Tags; +import net.nikr.eve.jeveasset.gui.images.Images; import net.nikr.eve.jeveasset.gui.shared.Formatter; import net.nikr.eve.jeveasset.gui.shared.components.JButtonComparable; +import net.nikr.eve.jeveasset.gui.tabs.stockpile.Stockpile.StockpileItem; +import net.nikr.eve.jeveasset.gui.tabs.stockpile.StockpileTableFormat; public class TableCellRenderers { @@ -162,6 +166,53 @@ public void setValue(final Object value) { } } + public static class TargetCellRenderer extends DefaultTableCellRenderer { + + public static final int MINIMUM_ICON_TEXT_GAP = 10; + private final DefaultEventTableModel tableModel; + + public TargetCellRenderer(DefaultEventTableModel tableModel) { + this.tableModel = tableModel; + this.setHorizontalTextPosition(DefaultTableCellRenderer.RIGHT); + this.setHorizontalAlignment(DefaultTableCellRenderer.RIGHT); + } + + @Override + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { + String columnName = (String) table.getTableHeader().getColumnModel().getColumn(column).getHeaderValue(); + Object object = tableModel.getElementAt(row); + Component component = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); + if (component instanceof JLabel) { + JLabel jLabel = (JLabel) component; + jLabel.setIcon(null); + jLabel.setIconTextGap(0); + } + if (object instanceof StockpileItem) { + StockpileItem stockpileItem = (StockpileItem) object; + if (stockpileItem.isEditable() && columnName.equals(StockpileTableFormat.COUNT_MINIMUM.getColumnName())) { + if (component instanceof JLabel) { + JLabel jLabel = (JLabel) component; + jLabel.setIcon(Images.EDIT_EDIT_BACKGROUND.getIcon()); + jLabel.setHorizontalTextPosition(JLabel.TRAILING); + jLabel.setIconTextGap(MINIMUM_ICON_TEXT_GAP); + } + } + } + return component; + } + + @Override + public void setValue(final Object value) { + if (value == null) { + setText(""); + } else if (value instanceof Number) { + setText(Formatter.doubleFormat(value)); + } else { + setText(value.toString()); + } + } + } + public static class TagsCellRenderer extends DefaultTableCellRenderer { public TagsCellRenderer() { diff --git a/src/main/java/net/nikr/eve/jeveasset/gui/tabs/stockpile/JStockpileTable.java b/src/main/java/net/nikr/eve/jeveasset/gui/tabs/stockpile/JStockpileTable.java index e52f44dc3..897e5d291 100644 --- a/src/main/java/net/nikr/eve/jeveasset/gui/tabs/stockpile/JStockpileTable.java +++ b/src/main/java/net/nikr/eve/jeveasset/gui/tabs/stockpile/JStockpileTable.java @@ -35,9 +35,10 @@ import net.nikr.eve.jeveasset.data.settings.ColorEntry; import net.nikr.eve.jeveasset.data.settings.ColorSettings; import net.nikr.eve.jeveasset.data.settings.Settings; -import net.nikr.eve.jeveasset.gui.images.Images; import net.nikr.eve.jeveasset.gui.shared.InstantToolTip; +import net.nikr.eve.jeveasset.gui.shared.table.EnumTableFormatAdaptor.ResizeMode; import net.nikr.eve.jeveasset.gui.shared.table.JSeparatorTable; +import net.nikr.eve.jeveasset.gui.shared.table.TableCellRenderers.TargetCellRenderer; import net.nikr.eve.jeveasset.gui.tabs.stockpile.Stockpile.StockpileItem; import net.nikr.eve.jeveasset.gui.tabs.stockpile.Stockpile.StockpileTotal; import net.nikr.eve.jeveasset.gui.tabs.stockpile.Stockpile.SubpileItem; @@ -55,6 +56,7 @@ public JStockpileTable(final Program program, final DefaultEventTableModel