Skip to content

Commit

Permalink
Bug Fix: Stockpile target column sometimes truncate editable numbers
Browse files Browse the repository at this point in the history
Merge Master
  • Loading branch information
GoldenGnu committed Apr 28, 2024
2 parents 94d1f84 + d4258c3 commit bb2d045
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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<StockpileItem> tableModel;

public TargetCellRenderer(DefaultEventTableModel<StockpileItem> 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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -55,6 +56,7 @@ public JStockpileTable(final Program program, final DefaultEventTableModel<Stock
super(program, tableModel, separatorList);
this.tableModel = tableModel;
InstantToolTip.install(this);
this.setDefaultRenderer(Double.class, new TargetCellRenderer(tableModel));
final Cursor cursor = getCursor();
addMouseMotionListener(new MouseMotionListener() {
@Override
Expand Down Expand Up @@ -101,11 +103,6 @@ public Component prepareRenderer(final TableCellRenderer renderer, final int row
Object object = tableModel.getElementAt(row);
String columnName = (String) this.getTableHeader().getColumnModel().getColumn(column).getHeaderValue();

if (component instanceof JLabel) {
JLabel jLabel = (JLabel) component;
jLabel.setIcon(null);
jLabel.setIconTextGap(0);
}
if (object instanceof StockpileItem) {
StockpileItem stockpileItem = (StockpileItem) object;
//Background
Expand Down Expand Up @@ -138,11 +135,9 @@ public Component prepareRenderer(final TableCellRenderer renderer, final int row
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);
int columnWidth = getColumnModel().getColumn(column).getWidth() - 2;
int columnWidth = getColumnModel().getColumn(column).getWidth() - 2 + TargetCellRenderer.MINIMUM_ICON_TEXT_GAP;
int jLabelWidth = jLabel.getMinimumSize().width;
jLabel.setIconTextGap(Math.max(0, columnWidth - jLabelWidth));
jLabel.setIconTextGap(Math.max(TargetCellRenderer.MINIMUM_ICON_TEXT_GAP, columnWidth - jLabelWidth));
}
} else if (columnName.equals(StockpileTableFormat.NAME.getColumnName())) {
if (Settings.get().isStockpileHalfColors()) {
Expand Down

0 comments on commit bb2d045

Please sign in to comment.