Merge remote-tracking branch

'origin/GP-4983-dragonmacher-script-table-columns' (Closes #6918)
This commit is contained in:
Ryan Kurtz 2024-10-03 06:08:07 -04:00
commit 0c9e060b17

View File

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -216,20 +216,7 @@ public class GhidraScriptComponentProvider extends ComponentProviderAdapter {
scriptTable.setAccessibleNamePrefix("Scripts");
TableColumnModel columnModel = scriptTable.getColumnModel();
// 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;
}
}
updateColumnSizes();
JScrollPane scriptTableScroll = new JScrollPane(scriptTable);
buildFilter();
@ -255,6 +242,48 @@ public class GhidraScriptComponentProvider extends ComponentProviderAdapter {
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.
*
@ -968,13 +997,6 @@ public class GhidraScriptComponentProvider extends ComponentProviderAdapter {
return true;
}
private void initializeUnresizableColumn(TableColumn column, int width) {
column.setPreferredWidth(width);
column.setMinWidth(width);
column.setMaxWidth(width);
column.setResizable(false);
}
private void updateTitle() {
StringBuilder buffy = new StringBuilder();
int currentRowCount = tableFilterPanel.getRowCount();