Fix range calc; Add missing update call in presetPanel

This commit is contained in:
Robin K 2022-04-13 18:13:06 +02:00
parent 1cb41a3521
commit a7aaae3d86
6 changed files with 28 additions and 15 deletions

View File

@ -366,6 +366,10 @@ public class DataCell implements Serializable {
}
public void updateBinValueFromMemory() {
//We do this here because once we start populating all settings should be set
if(minAllowedBin == 0 && maxAllowedBin == 0)
calcValueRange();
this.binValue = getValueFromMemory();
updateView();
}
@ -379,8 +383,9 @@ public class DataCell implements Serializable {
}
private void updateView() {
if(view != null)
if(view != null) {
view.drawCell();
}
}
public Table getTable() {

View File

@ -82,10 +82,7 @@ public class DataCellView extends JLabel implements MouseListener, Serializable
cell.setDataView(this);
this.y = cell.getIndexInTable();
this.setPreferredSize(getSettings().getCellSize());
//Once we create a view of the datacell, it should be safe to calculate the value range
cell.calcValueRange();
this.setPreferredSize(getSettings().getCellSize());
}
public DataCellView(DataCell cell, TableView view, int x, int y) {
@ -107,13 +104,17 @@ public class DataCellView extends JLabel implements MouseListener, Serializable
return SettingsManager.getSettings();
}
public void updatePresetPanel() {
tableView.updatePresetPanel();
}
public void drawCell() {
if(tableView == null || tableView.isHidden()) {
// Table will be null in the static case.
return;
}
tableView.updatePresetPanel();
updatePresetPanel();
this.invalidate();
setFont(getSettings().getTableFont());
setText(getCellText());

View File

@ -35,6 +35,7 @@ public class PresetManager {
public class PresetEntry {
int dataCellOffset = 0;
String name;
boolean isBitMask;
LinkedList<Integer> data;
}
@ -90,11 +91,12 @@ public class PresetManager {
}
}
public void setPresetValues(String name, String data, int dataCellOffset) {
public void setPresetValues(String name, String data, int dataCellOffset, boolean isBitMask) {
PresetEntry entry = new PresetEntry();
entry.name = name;
entry.data = new LinkedList<Integer>();
entry.dataCellOffset = dataCellOffset;
entry.isBitMask = isBitMask;
data = data.trim();

View File

@ -89,7 +89,7 @@ public class PresetPanel extends JPanel {
button.setFont(x.deriveFont(x.getStyle(), 15));
}
button.addActionListener(new PresetListener(entry));
button.addActionListener(new PresetListener(entry, table));
buttonGroup.add(button);
radioPanel.add(button);
}
@ -144,7 +144,7 @@ public class PresetPanel extends JPanel {
PresetEntry entry;
public PresetButton(PresetEntry entry) {
this.entry = entry;
this.entry = entry;
}
public void checkIfActive() {
@ -154,9 +154,11 @@ public class PresetPanel extends JPanel {
class PresetListener implements ActionListener{
PresetEntry entry;
TableView view;
public PresetListener(PresetEntry entry) {
public PresetListener(PresetEntry entry, TableView view) {
this.entry = entry;
this.view = view;
}
@Override
@ -164,9 +166,12 @@ public class PresetPanel extends JPanel {
if (((PresetButton) (event.getSource())).isSelected()) {
manager.applyPreset(entry);
}
else {
else if(entry.isBitMask){
manager.clearPreset(entry);
}
}
//Make sure we update all other checkboxes
view.updatePresetPanel();
}
}
}

View File

@ -500,12 +500,13 @@ public abstract class Table implements Serializable {
abstract public byte[] saveFile(byte[] binData);
public void setPresetValues(String name, String value) {
setPresetValues(name, value, 0);
if(presetManager == null) presetManager = new PresetManager(this);
presetManager.setPresetValues(name, value, 0, false);
}
public void setPresetValues(String name, String value, int dataCellOffset) {
if(presetManager == null) presetManager = new PresetManager(this);
presetManager.setPresetValues(name, value, dataCellOffset);
presetManager.setPresetValues(name, value, dataCellOffset, true);
}
public boolean isBeforeRam() {

View File

@ -575,7 +575,6 @@ public abstract class TableView extends JPanel implements Serializable {
}
}
protected void addPresetPanel(PresetManager m) {
presetPanel = new PresetPanel(this, m);
}