in src/main/java/org/apache/log4j/chainsaw/LogPanel.java [2928:3011]
private void loadDefaultColumnSettings(LoadSettingsEvent event) {
String columnOrder = event.getSetting(TABLE_COLUMN_ORDER);
TableColumnModel columnModel = table.getColumnModel();
TableColumnModel searchColumnModel = searchTable.getColumnModel();
Map<String, TableColumn> columnNameMap = new HashMap<>();
Map<String, TableColumn> searchColumnNameMap = new HashMap<>();
for (int i = 0; i < columnModel.getColumnCount(); i++) {
columnNameMap.put(table.getColumnName(i).toUpperCase(), columnModel.getColumn(i));
}
for (int i = 0; i < searchColumnModel.getColumnCount(); i++) {
searchColumnNameMap.put(searchTable.getColumnName(i).toUpperCase(), searchColumnModel.getColumn(i));
}
int index;
StringTokenizer tok = new StringTokenizer(columnOrder, ",");
List<TableColumn> sortedColumnList = new ArrayList<>();
/*
remove all columns from the table that exist in the model
and add in the correct order to a new arraylist
(may be a subset of possible columns)
**/
while (tok.hasMoreElements()) {
String element = tok.nextElement().toString().trim().toUpperCase();
TableColumn column = columnNameMap.get(element);
if (column != null) {
sortedColumnList.add(column);
table.removeColumn(column);
searchTable.removeColumn(column);
}
}
preferenceModel.setDetailPaneVisible(event.asBoolean("detailPaneVisible"));
preferenceModel.setLogTreePanelVisible(event.asBoolean("logTreePanelVisible"));
preferenceModel.setHighlightSearchMatchText(event.asBoolean("highlightSearchMatchText"));
preferenceModel.setWrapMessage(event.asBoolean("wrapMessage"));
preferenceModel.setSearchResultsVisible(event.asBoolean("searchResultsVisible"));
//re-add columns to the table in the order provided from the list
for (Object aSortedColumnList : sortedColumnList) {
TableColumn element = (TableColumn) aSortedColumnList;
if (preferenceModel.addColumn(element)) {
if (!applicationPreferenceModel.isDefaultColumnsSet() || applicationPreferenceModel.isDefaultColumnsSet() &&
applicationPreferenceModel.getDefaultColumnNames().contains(element.getHeaderValue())) {
table.addColumn(element);
searchTable.addColumn(element);
preferenceModel.setColumnVisible(element.getHeaderValue().toString(), true);
}
}
}
String columnWidths = event.getSetting(TABLE_COLUMN_WIDTHS);
tok = new StringTokenizer(columnWidths, ",");
index = 0;
while (tok.hasMoreElements()) {
String element = (String) tok.nextElement();
try {
int width = Integer.parseInt(element);
if (index > (columnModel.getColumnCount() - 1)) {
logger.warn(
"loadsettings - failed attempt to set width for index " + index
+ ", width " + element);
} else {
columnModel.getColumn(index).setPreferredWidth(width);
searchColumnModel.getColumn(index).setPreferredWidth(width);
}
index++;
} catch (NumberFormatException e) {
logger.error("Error decoding a Table width", e);
}
}
undockedFrame.setSize(getSize());
undockedFrame.setLocation(getBounds().x, getBounds().y);
repaint();
}