GP-4983 - Updated the script table to have all resizable columns

This commit is contained in:
dragonmacher 2024-10-02 12:24:12 -04:00
parent 23b75ec040
commit aba954845c

View File

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -216,20 +216,7 @@ public class GhidraScriptComponentProvider extends ComponentProviderAdapter {
scriptTable.setAccessibleNamePrefix("Scripts"); scriptTable.setAccessibleNamePrefix("Scripts");
TableColumnModel columnModel = scriptTable.getColumnModel(); updateColumnSizes();
// Set default column sizes
for (int i = 0; i < columnModel.getColumnCount(); i++) {
TableColumn column = columnModel.getColumn(i);
String name = (String) column.getHeaderValue();
switch (name) {
case GhidraScriptTableModel.SCRIPT_ACTION_COLUMN_NAME:
initializeUnresizableColumn(column, 50);
break;
case GhidraScriptTableModel.SCRIPT_STATUS_COLUMN_NAME:
initializeUnresizableColumn(column, 50);
break;
}
}
JScrollPane scriptTableScroll = new JScrollPane(scriptTable); JScrollPane scriptTableScroll = new JScrollPane(scriptTable);
buildFilter(); buildFilter();
@ -255,6 +242,48 @@ public class GhidraScriptComponentProvider extends ComponentProviderAdapter {
component.add(dataDescriptionSplit, BorderLayout.CENTER); component.add(dataDescriptionSplit, BorderLayout.CENTER);
} }
private void updateColumnSizes() {
//
// Table column resize behavior is tough to control. When setting the column size here, we
// use the max width to keep the columns from being resizable. The effect of this is that
// the table will layout the columns by giving all extra space to the resizable columns.
// Any columns not marked resizable will be the exact requested size. This allows us to
// force small columns to take up the minimum amount of space. The downside of locking the
// columns is that users cannot change the size. So, we will set the size for the initial
// layout to get the size we desire, and then we will set the size again to make the columns
// resizable after the layout has taken place.
//
forceSmallColumns(true);
// call again after the sizes have been updated from the previous call
forceSmallColumns(false);
}
private void forceSmallColumns(boolean lock) {
int width = 50;
TableColumnModel columnModel = scriptTable.getColumnModel();
for (int i = 0; i < columnModel.getColumnCount(); i++) {
TableColumn column = columnModel.getColumn(i);
String name = (String) column.getHeaderValue();
switch (name) {
case GhidraScriptTableModel.SCRIPT_ACTION_COLUMN_NAME:
setColumnWidth(column, width, !lock);
break;
case GhidraScriptTableModel.SCRIPT_STATUS_COLUMN_NAME:
setColumnWidth(column, width, !lock);
break;
}
}
}
private void setColumnWidth(TableColumn column, int width, boolean resizable) {
column.setPreferredWidth(width);
column.setMinWidth(width);
column.setMaxWidth(resizable ? Integer.MAX_VALUE : width);
}
/** /**
* Restore state for bundles, user actions, and filter. * Restore state for bundles, user actions, and filter.
* *
@ -968,13 +997,6 @@ public class GhidraScriptComponentProvider extends ComponentProviderAdapter {
return true; return true;
} }
private void initializeUnresizableColumn(TableColumn column, int width) {
column.setPreferredWidth(width);
column.setMinWidth(width);
column.setMaxWidth(width);
column.setResizable(false);
}
private void updateTitle() { private void updateTitle() {
StringBuilder buffy = new StringBuilder(); StringBuilder buffy = new StringBuilder();
int currentRowCount = tableFilterPanel.getRowCount(); int currentRowCount = tableFilterPanel.getRowCount();