From fd092e84e59ff6cd2596b2c3585264a6184a6c91 Mon Sep 17 00:00:00 2001 From: Robin K Date: Fri, 24 Sep 2021 11:56:14 +0200 Subject: [PATCH] Almost back to normal --- .../com/romraider/editor/ecu/ECUEditor.java | 69 ++++++------------- .../java/com/romraider/maps/DataCell.java | 2 +- .../java/com/romraider/maps/DataCellView.java | 4 +- src/main/java/com/romraider/maps/Rom.java | 20 ++++-- src/main/java/com/romraider/maps/Table.java | 5 -- src/main/java/com/romraider/maps/Table1D.java | 7 ++ .../java/com/romraider/maps/Table1DView.java | 54 ++++++++------- src/main/java/com/romraider/maps/Table2D.java | 2 +- .../java/com/romraider/maps/Table2DView.java | 3 +- src/main/java/com/romraider/maps/Table3D.java | 4 +- .../java/com/romraider/maps/Table3DView.java | 28 +++----- .../java/com/romraider/maps/TableView.java | 13 ++-- .../java/com/romraider/swing/RomTree.java | 5 +- .../java/com/romraider/swing/TableFrame.java | 6 +- .../com/romraider/swing/TableToolBar.java | 3 + 15 files changed, 112 insertions(+), 113 deletions(-) diff --git a/src/main/java/com/romraider/editor/ecu/ECUEditor.java b/src/main/java/com/romraider/editor/ecu/ECUEditor.java index b4844527..54674c4e 100644 --- a/src/main/java/com/romraider/editor/ecu/ECUEditor.java +++ b/src/main/java/com/romraider/editor/ecu/ECUEditor.java @@ -113,7 +113,6 @@ public class ECUEditor extends AbstractFrame { private TableToolBar tableToolBar; private final JPanel toolBarPanel = new JPanel(); private OpenImageWorker openImageWorker; - private CloseImageWorker closeImageWorker; private SetUserLevelWorker setUserLevelWorker; private LaunchLoggerWorker launchLoggerWorker; private final ImageIcon editorIcon = new ImageIcon(getClass().getResource( @@ -388,11 +387,27 @@ public class ECUEditor extends AbstractFrame { refreshUI(); } - public void closeImage() { - setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); - closeImageWorker = new CloseImageWorker(getLastSelectedRom()); - closeImageWorker.addPropertyChangeListener(getStatusPanel()); - closeImageWorker.execute(); + public void closeImage() { + Rom rom = getLastSelectedRom(); + ECUEditor editor = ECUEditorManager.getECUEditor(); + RomTreeRootNode imageRoot = editor.getImageRoot(); + + rom.clearData(); + rom.removeFromParent(); + rom = null; + + if (imageRoot.getChildCount() > 0) { + editor.setLastSelectedRom((Rom) imageRoot.getChildAt(0)); + } else { + // no other images open + editor.setLastSelectedRom(null); + } + + editor.refreshTableCompareMenus(); + editor.getStatusPanel().setStatus(ECUEditor.rb.getString("STATUSREADY")); + editor.setCursor(null); + editor.refreshUI(); + System.gc(); } public void closeAllImages() { @@ -590,9 +605,8 @@ class LaunchLoggerWorker extends SwingWorker { } } +//Do we really need this? Cant be compute intensive class SetUserLevelWorker extends SwingWorker { - public SetUserLevelWorker() { - } @Override protected Void doInBackground() throws Exception { @@ -622,45 +636,6 @@ class SetUserLevelWorker extends SwingWorker { } } -class CloseImageWorker extends SwingWorker { - Rom rom; - - public CloseImageWorker(Rom romToRemove) { - this.rom = romToRemove; - } - - @Override - protected Void doInBackground() throws Exception { - ECUEditor editor = ECUEditorManager.getECUEditor(); - RomTreeRootNode imageRoot = editor.getImageRoot(); - - rom.clearData(); - rom.removeFromParent(); - rom = null; - - if (imageRoot.getChildCount() > 0) { - editor.setLastSelectedRom((Rom) imageRoot.getChildAt(0)); - } else { - // no other images open - editor.setLastSelectedRom(null); - } - - editor.refreshTableCompareMenus(); - - return null; - } - - @Override - public void done() { - ECUEditor editor = ECUEditorManager.getECUEditor(); - editor.getStatusPanel().setStatus(ECUEditor.rb.getString("STATUSREADY")); - setProgress(0); - editor.setCursor(null); - editor.refreshUI(); - System.gc(); - } -} - class OpenImageWorker extends SwingWorker { private final File inputFile; diff --git a/src/main/java/com/romraider/maps/DataCell.java b/src/main/java/com/romraider/maps/DataCell.java index 4510af18..f27eb784 100644 --- a/src/main/java/com/romraider/maps/DataCell.java +++ b/src/main/java/com/romraider/maps/DataCell.java @@ -294,7 +294,7 @@ public class DataCell { private void updateView() { if(view != null) - view.repaint(); + view.drawCell(); } public Table getTable() { diff --git a/src/main/java/com/romraider/maps/DataCellView.java b/src/main/java/com/romraider/maps/DataCellView.java index df663c0d..628cd1a6 100644 --- a/src/main/java/com/romraider/maps/DataCellView.java +++ b/src/main/java/com/romraider/maps/DataCellView.java @@ -81,6 +81,8 @@ public class DataCellView extends JLabel implements MouseListener, Serializable this.addMouseListener(this); cell.setDataView(this); + this.y = cell.getIndexInTable(); + this.setPreferredSize(getSettings().getCellSize()); } public DataCellView(DataCell cell, TableView view, int x, int y) { @@ -88,12 +90,12 @@ public class DataCellView extends JLabel implements MouseListener, Serializable this.x = x; this.y = y; - this.setPreferredSize(getSettings().getCellSize()); } public void setSelected(boolean selected) { if(!tableView.getTable().isStaticDataTable() && this.isSelected != selected) { this.isSelected = selected; + drawCell(); } } diff --git a/src/main/java/com/romraider/maps/Rom.java b/src/main/java/com/romraider/maps/Rom.java index 903e0083..084d333a 100644 --- a/src/main/java/com/romraider/maps/Rom.java +++ b/src/main/java/com/romraider/maps/Rom.java @@ -386,13 +386,21 @@ public class Rom extends DefaultMutableTreeNode implements Serializable { // Hide and dispose all frames. for(TableTreeNode tableTreeNode : tableNodes) { TableFrame frame = tableTreeNode.getFrame(); - frame.setVisible(false); - try { - frame.setClosed(true); - } catch (PropertyVetoException e) { - ; // Do nothing. + + if(frame != null) { + frame.getTableView().setVisible(false); + frame.setVisible(false); + + try { + frame.setClosed(true); + } catch (PropertyVetoException e) { + ; // Do nothing. + } + frame.dispose(); + + frame.getTableView().setTable(null); + frame.setTableView(null); } - frame.dispose(); } tableNodes.clear(); diff --git a/src/main/java/com/romraider/maps/Table.java b/src/main/java/com/romraider/maps/Table.java index a4113157..f4ed4af6 100644 --- a/src/main/java/com/romraider/maps/Table.java +++ b/src/main/java/com/romraider/maps/Table.java @@ -500,9 +500,6 @@ public abstract class Table implements Serializable { this.minCompare = minCompare; } - - - public void setRevertPoint() { for (DataCell cell : data) { cell.setRevertPoint(); @@ -632,8 +629,6 @@ public abstract class Table implements Serializable { public void setCurrentScale(Scale curScale) { this.curScale = curScale; - - if(tableView!=null) tableView.repaint(); } public Settings getSettings() diff --git a/src/main/java/com/romraider/maps/Table1D.java b/src/main/java/com/romraider/maps/Table1D.java index 423c68c1..c523ef87 100644 --- a/src/main/java/com/romraider/maps/Table1D.java +++ b/src/main/java/com/romraider/maps/Table1D.java @@ -43,6 +43,13 @@ public class Table1D extends Table { return axisParent; } + @Override + public void setCurrentScale(Scale curScale) { + this.curScale = curScale; + + if(tableView!=null) tableView.drawTable(); + } + @Override public byte[] saveFile(byte[] binData) { return binData; diff --git a/src/main/java/com/romraider/maps/Table1DView.java b/src/main/java/com/romraider/maps/Table1DView.java index d6bf3995..6d6d24c7 100644 --- a/src/main/java/com/romraider/maps/Table1DView.java +++ b/src/main/java/com/romraider/maps/Table1DView.java @@ -24,6 +24,7 @@ import java.awt.BorderLayout; import javax.swing.JLabel; import javax.swing.border.EmptyBorder; +import com.romraider.maps.Table.TableType; import com.romraider.util.NumberUtil; public class Table1DView extends TableView { @@ -34,6 +35,7 @@ public class Table1DView extends TableView { public Table1DView(Table1D table) { super(table); this.table = table; + populateTableVisual(); } @@ -48,36 +50,40 @@ public class Table1DView extends TableView { } @Override - public void populateTableVisual() { - centerLayout.setRows(1); - centerLayout.setColumns(table.getDataSize()); + public void populateTableVisual() { super.populateTableVisual(); - - // add to table - for (int i = 0; i < table.getDataSize(); i++) { - centerPanel.add(this.getDataCell(i)); - } - - if(null == table.name || table.name.isEmpty()) { - ;// Do not add label. - } else if(null == table.getCurrentScale () || "0x" == table.getCurrentScale().getUnit()) { - // static or no scale exists. - tableLabel = new JLabel(getName(), JLabel.CENTER); - add(tableLabel, BorderLayout.NORTH); - } else { - tableLabel = new JLabel(getName() + " (" + table.getCurrentScale().getUnit() + ")", JLabel.CENTER); - add(tableLabel, BorderLayout.NORTH); - } - if(tableLabel != null) - tableLabel.setBorder(new EmptyBorder(2, 4, 2, 4)); - - if(presetPanel != null) presetPanel.populatePanel(); + //Only populate the rest if we aren't an axis + if(table.getType() == TableType.TABLE_1D) { + centerLayout.setRows(1); + centerLayout.setColumns(table.getDataSize()); + + // add to table + for (int i = 0; i < table.getDataSize(); i++) { + centerPanel.add(this.getDataCell(i)); + } + + if(null == table.name || table.name.isEmpty()) { + ;// Do not add label. + } else if(null == table.getCurrentScale () || "0x" == table.getCurrentScale().getUnit()) { + // static or no scale exists. + tableLabel = new JLabel(getName(), JLabel.CENTER); + add(tableLabel, BorderLayout.NORTH); + } else { + tableLabel = new JLabel(getName() + " (" + table.getCurrentScale().getUnit() + ")", JLabel.CENTER); + add(tableLabel, BorderLayout.NORTH); + } + + if(tableLabel != null) + tableLabel.setBorder(new EmptyBorder(2, 4, 2, 4)); + + if(presetPanel != null) presetPanel.populatePanel(); + } } @Override public String toString() { - return super.toString() + " (1D)"; + return table.toString() + " View"; } @Override diff --git a/src/main/java/com/romraider/maps/Table2D.java b/src/main/java/com/romraider/maps/Table2D.java index f1278c2e..3179a234 100644 --- a/src/main/java/com/romraider/maps/Table2D.java +++ b/src/main/java/com/romraider/maps/Table2D.java @@ -164,7 +164,7 @@ public class Table2D extends Table { } this.curScale = curScale; - if(tableView != null) tableView.repaint(); + if(tableView != null) tableView.drawTable(); } @Override diff --git a/src/main/java/com/romraider/maps/Table2DView.java b/src/main/java/com/romraider/maps/Table2DView.java index 60ebe73e..7401c080 100644 --- a/src/main/java/com/romraider/maps/Table2DView.java +++ b/src/main/java/com/romraider/maps/Table2DView.java @@ -87,9 +87,10 @@ public class Table2DView extends TableView { @Override public void populateTableVisual(){ + super.populateTableVisual(); + centerLayout.setRows(2); centerLayout.setColumns(table.getDataSize()); - super.populateTableVisual(); // add to table for (int i = 0; i < axis.getTable().getDataSize(); i++) { diff --git a/src/main/java/com/romraider/maps/Table3D.java b/src/main/java/com/romraider/maps/Table3D.java index 746d4a71..fd595543 100644 --- a/src/main/java/com/romraider/maps/Table3D.java +++ b/src/main/java/com/romraider/maps/Table3D.java @@ -328,7 +328,9 @@ public class Table3D extends Table { } } } - this.curScale = curScale; + + this.curScale = curScale; + if(tableView!=null) tableView.drawTable(); } @Override diff --git a/src/main/java/com/romraider/maps/Table3DView.java b/src/main/java/com/romraider/maps/Table3DView.java index 79363815..c411a21b 100644 --- a/src/main/java/com/romraider/maps/Table3DView.java +++ b/src/main/java/com/romraider/maps/Table3DView.java @@ -85,7 +85,7 @@ public class Table3DView extends TableView { for(DataCellView[] column : data) { for(DataCellView cell : column) { if(null != cell) { - cell.repaint(); + cell.drawCell(); } } } @@ -95,34 +95,26 @@ public class Table3DView extends TableView { xAxis.drawTable(); if(yAxis!=null) - yAxis.drawTable(); + yAxis.drawTable(); } @Override + //TODO public void populateTableVisual() { // fill first empty cell centerPanel.add(new JLabel()); - centerLayout.setColumns(xAxis.getTable().getDataSize()); - centerLayout.setRows(yAxis.getTable().getDataSize()); + centerLayout.setColumns(table.getSizeX()+1); + centerLayout.setRows(table.getSizeY()+1); // temporarily remove lock boolean tempLock = table.locked; table.locked = false; - - // populate axes - try { - xAxis.populateTableVisual(); - yAxis.populateTableVisual(); - } catch (ArrayIndexOutOfBoundsException ex) { - throw new ArrayIndexOutOfBoundsException(); - } - + for (int x = 0; x < xAxis.getTable().getDataSize(); x++) { centerPanel.add(xAxis.getDataCell(x)); } - - data = new DataCellView[xAxis.getTable().getDataSize()][yAxis.getTable().getDataSize()]; + data = new DataCellView[table.getSizeX()][table.getSizeY()]; int iMax = table.getSwapXY() ? xAxis.getTable().getDataSize() : yAxis.getTable().getDataSize(); int jMax = table.getSwapXY() ? yAxis.getTable().getDataSize() : xAxis.getTable().getDataSize(); @@ -141,8 +133,7 @@ public class Table3DView extends TableView { if (tempLock) { data[x][y].setForeground(Color.GRAY); } - - + data[x][y] = new DataCellView(table.get3dData()[x][y], this, x,y); } } @@ -153,7 +144,7 @@ public class Table3DView extends TableView { centerPanel.add(data[x][y]); } } - + // reset locked status table.locked = tempLock; @@ -196,6 +187,7 @@ public class Table3DView extends TableView { xAxisLabel.setBorder(new EmptyBorder(2, 4, 2, 4)); if(presetPanel != null) presetPanel.populatePanel(); + drawTable(); } @Override diff --git a/src/main/java/com/romraider/maps/TableView.java b/src/main/java/com/romraider/maps/TableView.java index c9e612fa..338e200c 100644 --- a/src/main/java/com/romraider/maps/TableView.java +++ b/src/main/java/com/romraider/maps/TableView.java @@ -494,6 +494,10 @@ public abstract class TableView extends JPanel implements Serializable { return table.getTableFrame(); } + public void setTable(Table t) { + this.table = t; + } + public Table getTable() { return this.table; } @@ -566,11 +570,6 @@ public abstract class TableView extends JPanel implements Serializable { cell.setSelected(false); } } - - @Override - public void repaint() { - drawTable(); - } public void startHighlight(int x, int y) { this.highlightY = y; @@ -880,6 +879,10 @@ public abstract class TableView extends JPanel implements Serializable { } } + public String getName() { + return table.getName(); + } + public static void showBadScalePopup(Table table, Scale scale) { JPanel panel = new JPanel(); panel.setLayout(new GridLayout(4, 1)); diff --git a/src/main/java/com/romraider/swing/RomTree.java b/src/main/java/com/romraider/swing/RomTree.java index 086456e2..2b635e33 100644 --- a/src/main/java/com/romraider/swing/RomTree.java +++ b/src/main/java/com/romraider/swing/RomTree.java @@ -121,8 +121,9 @@ public class RomTree extends JTree implements MouseListener { v = new Table3DView((Table3D)node.getTable()); else return; - - f = new TableFrame("Title", v); + Rom rom = getRomNode(node); + + f = new TableFrame(node.getTable().getName() + " | " + rom.getFileName(), v); } getEditor().displayTable(f); } diff --git a/src/main/java/com/romraider/swing/TableFrame.java b/src/main/java/com/romraider/swing/TableFrame.java index 6a3329a6..efb3e83c 100644 --- a/src/main/java/com/romraider/swing/TableFrame.java +++ b/src/main/java/com/romraider/swing/TableFrame.java @@ -48,7 +48,7 @@ public class TableFrame extends JInternalFrame implements InternalFrameListener, private static final long serialVersionUID = -2651279694660392351L; private static final ResourceBundle rb = new ResourceUtil().getBundle( TableFrame.class.getName()); - private final TableView tableView; + private TableView tableView; private TableMenuBar tableMenuBar = null; public TableFrame(String title, TableView tableView) { @@ -120,6 +120,10 @@ public class TableFrame extends JInternalFrame implements InternalFrameListener, return tableView; } + public void setTableView(TableView v) { + tableView = v; + } + public ECUEditor getEditor() { return ECUEditorManager.getECUEditor(); } diff --git a/src/main/java/com/romraider/swing/TableToolBar.java b/src/main/java/com/romraider/swing/TableToolBar.java index 21b6a9ff..1879c547 100644 --- a/src/main/java/com/romraider/swing/TableToolBar.java +++ b/src/main/java/com/romraider/swing/TableToolBar.java @@ -348,6 +348,9 @@ public class TableToolBar extends JToolBar implements MouseListener, ItemListene } public void updateTableToolBar(Table selectedTable) { + //Select the parent Table always instead? + //if(selectedTable instanceof Table1D)selectedTable = ((Table1D)selectedTable).getAxisParent(); + if(selectedTable == null && this.selectedTable == null) { // Skip if the table is the same to avoid multiple updates return;