Skip to content

Commit cbd5984

Browse files
committed
Add table filter box
1 parent 1b5e86c commit cbd5984

File tree

5 files changed

+150
-13
lines changed

5 files changed

+150
-13
lines changed

i18n/com/romraider/maps/Rom.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ CHKSUMINVALID = One or more ROM image Checksums is invalid. Calculate new Checks
99
CHECKSUMFIX = Checksum Fix
1010
INVLAIDCHKSUM = Checksum is invalid.\nThe ROM image may be corrupt or it has been hex edited manually.\nThe checksum can be corrected when the ROM is saved if you trust it is not corrupt.
1111
CHKSUMFAIL = ERROR - Checksum Failed
12+
NOMATCHES = No table name matches the current filter...
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
LBLFILTER = Filter:
2+
LBLTOOLTIP = Type to filter tables...

src/main/java/com/romraider/editor/ecu/ECUEditor.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* RomRaider Open-Source Tuning, Logging and Reflashing
3-
* Copyright (C) 2006-2022 RomRaider.com
3+
* Copyright (C) 2006-2025 RomRaider.com
44
*
55
* This program is free software; you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -99,6 +99,7 @@
9999
import com.romraider.swing.ECUEditorToolBar;
100100
import com.romraider.swing.JProgressPane;
101101
import com.romraider.swing.MDIDesktopPane;
102+
import com.romraider.swing.RomFilterPanel;
102103
import com.romraider.swing.RomTree;
103104
import com.romraider.swing.RomTreeRootNode;
104105
import com.romraider.swing.TableFrame;
@@ -149,11 +150,16 @@ public ECUEditor() {
149150

150151
rightScrollPane = new JScrollPane(rightPanel,
151152
VERTICAL_SCROLLBAR_AS_NEEDED, HORIZONTAL_SCROLLBAR_AS_NEEDED);
153+
152154
leftScrollPane = new JScrollPane(imageList,
153155
VERTICAL_SCROLLBAR_AS_NEEDED, HORIZONTAL_SCROLLBAR_AS_NEEDED);
154156

157+
JPanel leftAreaWithFilterBox = new JPanel(new BorderLayout());
158+
leftAreaWithFilterBox.add(leftScrollPane, BorderLayout.CENTER);
159+
leftAreaWithFilterBox.add(new RomFilterPanel(imageRoot, imageList), BorderLayout.SOUTH);
160+
155161
splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
156-
leftScrollPane, rightScrollPane);
162+
leftAreaWithFilterBox, rightScrollPane);
157163
splitPane.setDividerSize(3);
158164
splitPane.setDividerLocation(settings.getSplitPaneLocation());
159165
splitPane.addPropertyChangeListener(this);
@@ -167,7 +173,7 @@ public ECUEditor() {
167173

168174
//set remaining window properties
169175
setIconImage(editorIcon.getImage());
170-
176+
171177
setDefaultCloseOperation(EXIT_ON_CLOSE);
172178
addWindowListener(this);
173179
setTitle(titleText);

src/main/java/com/romraider/maps/Rom.java

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* RomRaider Open-Source Tuning, Logging and Reflashing
3-
* Copyright (C) 2006-2022 RomRaider.com
3+
* Copyright (C) 2006-2025 RomRaider.com
44
*
55
* This program is free software; you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -42,11 +42,13 @@
4242
import java.util.List;
4343
import java.util.ResourceBundle;
4444
import java.util.Vector;
45+
import java.util.regex.PatternSyntaxException;
4546

4647
import javax.swing.JOptionPane;
4748
import javax.swing.SwingUtilities;
4849
import javax.swing.tree.DefaultMutableTreeNode;
4950
import javax.swing.tree.TreeNode;
51+
import javax.swing.tree.TreePath;
5052

5153
import org.apache.log4j.Logger;
5254
import org.w3c.dom.Document;
@@ -128,24 +130,46 @@ else if(settings.isTableTreeSorted() &&
128130
currentParent.add(newNode);
129131
}
130132
}
131-
132-
public void refreshDisplayedTables() {
133-
// Remove all nodes from the ROM tree node.
133+
134+
public List<TreePath> refreshDisplayedTables() {
135+
return refreshDisplayedTables(null);
136+
}
137+
138+
/*
139+
* Refreshes the list of tables for a rom. Takes a regex (or null) as input for filtering.
140+
* Outputs a list of paths that should be expanded based on the filter.
141+
*/
142+
public List<TreePath> refreshDisplayedTables(String filterText) {
134143
super.removeAllChildren();
135144

136145
Settings settings = SettingsManager.getSettings();
146+
boolean shouldFilter = filterText != null && !filterText.isEmpty();
147+
boolean anyTablesAdded = false;
148+
149+
// Collect TreePaths for expansion
150+
List<TreePath> pathsToExpand = new ArrayList<TreePath>();
137151

138-
// Add nodes to ROM tree.
139152
for (TableTreeNode tableTreeNode : tableNodes.values()) {
140153
Table table = tableTreeNode.getTable();
141154

155+
boolean addToTree = true;
156+
if (shouldFilter) {
157+
try {
158+
addToTree = table.getName().toLowerCase().contains(filterText.toLowerCase());
159+
} catch (PatternSyntaxException exception) {
160+
addToTree = false;
161+
}
162+
}
163+
164+
if (!addToTree) continue;
165+
anyTablesAdded = true;
166+
142167
String[] categories = table.getCategory().split("//");
143168

144169
if (settings.isDisplayHighTables() || settings.getUserLevel() >= table.getUserLevel()) {
145-
146170
DefaultMutableTreeNode currentParent = this;
147171

148-
for(int i=0; i < categories.length; i++) {
172+
for (int i = 0; i < categories.length; i++) {
149173
boolean categoryExists = false;
150174

151175
for (int j = 0; j < currentParent.getChildCount(); j++) {
@@ -156,18 +180,29 @@ public void refreshDisplayedTables() {
156180
}
157181
}
158182

159-
if(!categoryExists) {
183+
if (!categoryExists) {
160184
CategoryTreeNode categoryNode = new CategoryTreeNode(categories[i]);
161-
sortedAdd(currentParent,categoryNode);
185+
sortedAdd(currentParent, categoryNode);
162186
currentParent = categoryNode;
163187
}
164188

165-
if(i == categories.length - 1){
189+
// Only add last category in path for expansion
190+
if (shouldFilter) {
191+
pathsToExpand.add(new TreePath(currentParent.getPath()));
192+
}
193+
194+
if (i == categories.length - 1) {
166195
sortedAdd(currentParent, tableTreeNode);
167196
}
168197
}
169198
}
170199
}
200+
201+
if (!anyTablesAdded && shouldFilter) {
202+
sortedAdd(this, new DefaultMutableTreeNode(rb.getString("NOMATCHES")));
203+
}
204+
205+
return pathsToExpand;
171206
}
172207

173208
public void addTableByName(Table table) {
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* RomRaider Open-Source Tuning, Logging and Reflashing
3+
* Copyright (C) 2006-2025 RomRaider.com
4+
*
5+
* This program is free software; you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation; either version 2 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License along
16+
* with this program; if not, write to the Free Software Foundation, Inc.,
17+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*/
19+
20+
package com.romraider.swing;
21+
22+
import javax.swing.BorderFactory;
23+
import javax.swing.JLabel;
24+
import javax.swing.JPanel;
25+
import javax.swing.JTextField;
26+
import javax.swing.event.DocumentEvent;
27+
import javax.swing.event.DocumentListener;
28+
import javax.swing.tree.DefaultMutableTreeNode;
29+
import javax.swing.tree.DefaultTreeModel;
30+
import javax.swing.tree.TreePath;
31+
32+
import java.awt.*;
33+
import java.util.Enumeration;
34+
import java.util.List;
35+
import java.util.ResourceBundle;
36+
37+
import com.romraider.maps.Rom;
38+
import com.romraider.swing.RomTree;
39+
import com.romraider.util.ResourceUtil;
40+
41+
public class RomFilterPanel extends JPanel {
42+
43+
private static final long serialVersionUID = 1L;
44+
45+
private static final ResourceBundle rb = new ResourceUtil().getBundle(
46+
RomFilterPanel.class.getName());
47+
48+
public RomFilterPanel(final DefaultMutableTreeNode imageRoot, final RomTree imageList) {
49+
super(new BorderLayout());
50+
51+
final JTextField filterField;
52+
53+
JLabel label = new JLabel(rb.getString("LBLFILTER"));
54+
label.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0));
55+
filterField = new JTextField(20);
56+
filterField.setToolTipText(rb.getString("LBLTOOLTIP"));
57+
58+
add(label, BorderLayout.WEST);
59+
add(filterField, BorderLayout.CENTER);
60+
61+
filterField.getDocument().addDocumentListener(new DocumentListener() {
62+
@Override
63+
public void insertUpdate(DocumentEvent e) { filter(); }
64+
@Override
65+
public void removeUpdate(DocumentEvent e) { filter(); }
66+
@Override
67+
public void changedUpdate(DocumentEvent e) { filter(); }
68+
69+
private void filter() {
70+
String text = filterField.getText().trim();
71+
72+
final Enumeration<?> children = imageRoot.children();
73+
while (children.hasMoreElements()) {
74+
Object child = children.nextElement();
75+
if (child instanceof Rom) {
76+
Rom rom = (Rom) child;
77+
List<TreePath> pathsToExpand = rom.refreshDisplayedTables(text);
78+
79+
DefaultTreeModel model = (DefaultTreeModel) imageList.getModel();
80+
model.reload(rom);
81+
82+
for (TreePath path : pathsToExpand) {
83+
imageList.expandPath(path);
84+
}
85+
86+
}
87+
}
88+
89+
imageList.repaint();
90+
}
91+
});
92+
}
93+
}

0 commit comments

Comments
 (0)