in src/main/java/org/apache/log4j/chainsaw/color/ColorPanel.java [97:274]
public ColorPanel(final RuleColorizer globalColorizer,
final FilterModel filterModel,
final Map<String, RuleColorizer> allLogPanelColorizers,
final LogPanel parent) {
super(new BorderLayout());
AbstractConfiguration configuration = SettingsManager.getInstance().getGlobalConfiguration();
this.filterModel = filterModel;
this.allLogPanelColorizers = allLogPanelColorizers;
this.m_globalColorizer = globalColorizer;
this.m_parentLogPanel = parent;
m_parentLogPanel.getCurrentRuleColorizer().addPropertyChangeListener(
"colorrule",
evt -> updateColors());
rulesTableModel = new RulesTableModel();
rulesTable = new JTable(rulesTableModel);
rulesTable.setRowHeight(ChainsawConstants.DEFAULT_ROW_HEIGHT);
rulesTable.getColumnModel().getColumn(0)
.setCellEditor(new RulesTableCellEditor());
searchTableModel = new DefaultTableModel();
searchTable = new JTable(searchTableModel);
searchTable.setRowHeight(ChainsawConstants.DEFAULT_ROW_HEIGHT);
searchTable.setPreferredScrollableViewportSize(new Dimension(30, 30));
alternatingColorTableModel = new DefaultTableModel();
alternatingColorTable = new JTable(alternatingColorTableModel);
alternatingColorTable.setRowHeight(ChainsawConstants.DEFAULT_ROW_HEIGHT);
alternatingColorTable.setPreferredScrollableViewportSize(new Dimension(30, 30));
columns = new Vector<>();
columns.add("Expression");
columns.add("Background");
columns.add("Foreground");
searchColumns = new Vector<>();
searchColumns.add("Background");
searchColumns.add("Foreground");
alternatingColorColumns = new Vector<>();
alternatingColorColumns.add("Background");
alternatingColorColumns.add("Foreground");
//searchtable contains only a single-entry vector containing a two-item vector (foreground, background)
searchDataVector = new Vector<>();
searchDataVectorEntry = new Vector<>();
searchDataVectorEntry.add(configuration.get(Color.class, "searchBackgroundColor", ChainsawConstants.FIND_LOGGER_BACKGROUND));
searchDataVectorEntry.add(configuration.get(Color.class, "searchForegroundColor", ChainsawConstants.FIND_LOGGER_FOREGROUND));
searchDataVector.add(searchDataVectorEntry);
searchTableModel.setDataVector(searchDataVector, searchColumns);
alternatingColorDataVector = new Vector<>();
alternatingColorDataVectorEntry = new Vector<>();
alternatingColorDataVectorEntry.add(configuration.get(Color.class, "alternatingColorBackground", ChainsawConstants.COLOR_ODD_ROW_BACKGROUND));
alternatingColorDataVectorEntry.add(configuration.get(Color.class, "alternatingColorForeground", ChainsawConstants.COLOR_ODD_ROW_FOREGROUND));
alternatingColorDataVector.add(alternatingColorDataVectorEntry);
alternatingColorTableModel.setDataVector(alternatingColorDataVector, alternatingColorColumns);
rulesTable.setPreferredScrollableViewportSize(new Dimension(525, 200));
tableScrollPane = new JScrollPane(rulesTable);
rulesTable.sizeColumnsToFit(0);
rulesTable.getColumnModel().getColumn(1).setPreferredWidth(80);
rulesTable.getColumnModel().getColumn(2).setPreferredWidth(80);
rulesTable.getColumnModel().getColumn(1).setMaxWidth(80);
rulesTable.getColumnModel().getColumn(2).setMaxWidth(80);
searchTable.sizeColumnsToFit(0);
searchTable.getColumnModel().getColumn(0).setPreferredWidth(80);
searchTable.getColumnModel().getColumn(1).setPreferredWidth(80);
searchTable.getColumnModel().getColumn(0).setMaxWidth(80);
searchTable.getColumnModel().getColumn(1).setMaxWidth(80);
//building color choosers needs to be done on the EDT
SwingHelper.invokeOnEDT(() -> configureSingleEntryColorTable(searchTable));
alternatingColorTable.sizeColumnsToFit(0);
alternatingColorTable.getColumnModel().getColumn(0).setPreferredWidth(80);
alternatingColorTable.getColumnModel().getColumn(1).setPreferredWidth(80);
alternatingColorTable.getColumnModel().getColumn(0).setMaxWidth(80);
alternatingColorTable.getColumnModel().getColumn(1).setMaxWidth(80);
//building color choosers needs to be done on the EDT
SwingHelper.invokeOnEDT(() -> configureSingleEntryColorTable(alternatingColorTable));
configureTable();
statusBar = new JLabel(DEFAULT_STATUS);
rulesPanel = buildRulesPanel();
rulesPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
JPanel rightPanel = new JPanel(new BorderLayout());
JPanel rightOuterPanel = new JPanel();
rightOuterPanel.setLayout(
new BoxLayout(rightOuterPanel, BoxLayout.X_AXIS));
rightOuterPanel.add(Box.createHorizontalStrut(10));
JPanel southPanel = new JPanel();
southPanel.setLayout(new BoxLayout(southPanel, BoxLayout.Y_AXIS));
southPanel.add(Box.createVerticalStrut(5));
southPanel.add(Box.createVerticalStrut(5));
JPanel searchAndAlternatingColorPanel = buildSearchAndAlternatingColorPanel();
JPanel bypassSearchColorsPanel = buildBypassSearchColorsPanel();
bypassSearchColorsCheckBox.setSelected(configuration.getBoolean("bypassSearchColors", false));
JPanel globalLabelPanel = new JPanel();
globalLabelPanel.setLayout(new BoxLayout(globalLabelPanel, BoxLayout.X_AXIS));
JLabel globalLabel = new JLabel("Global colors:");
globalLabelPanel.add(globalLabel);
globalLabelPanel.add(Box.createHorizontalGlue());
southPanel.add(globalLabelPanel);
southPanel.add(searchAndAlternatingColorPanel);
southPanel.add(bypassSearchColorsPanel);
southPanel.add(Box.createVerticalStrut(5));
JPanel closePanel = buildClosePanel();
southPanel.add(closePanel);
JPanel statusPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
statusPanel.add(statusBar);
southPanel.add(statusPanel);
rightPanel.add(rulesPanel, BorderLayout.CENTER);
rightPanel.add(southPanel, BorderLayout.SOUTH);
rightOuterPanel.add(rightPanel);
JPanel topPanel = new JPanel();
topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.X_AXIS));
JLabel selectText = new JLabel("Apply a tab's colors");
topPanel.add(selectText);
topPanel.add(Box.createHorizontalStrut(5));
logPanelColorizersModel = new DefaultComboBoxModel();
final JComboBox loadPanelColorizersComboBox = new JComboBox(logPanelColorizersModel);
loadLogPanelColorizers();
topPanel.add(loadPanelColorizersComboBox);
topPanel.add(Box.createHorizontalStrut(5));
final Action copyRulesAction = new AbstractAction() {
public void actionPerformed(ActionEvent e) {
rulesTableModel.clear();
Object selectedItem = loadPanelColorizersComboBox.getSelectedItem();
if (selectedItem != null) {
RuleColorizer sourceColorizer = allLogPanelColorizers.get(selectedItem.toString());
RuleColorizer newColorizer = new RuleColorizer();
newColorizer.setRules(sourceColorizer.getRules());
parent.setRuleColorizer(newColorizer);
updateColors();
m_parentLogPanel.getCurrentRuleColorizer().addPropertyChangeListener(
"colorrule",
evt -> updateColors());
}
}
};
loadPanelColorizersComboBox.addActionListener(e -> {
Object selectedItem = loadPanelColorizersComboBox.getSelectedItem();
if (selectedItem != null) {
String selectedColorizerName = selectedItem.toString();
copyRulesAction.setEnabled(!(noTab.equals(selectedColorizerName)));
}
});
copyRulesAction.putValue(Action.NAME, "Copy color rules");
copyRulesAction.setEnabled(!(noTab.equals(loadPanelColorizersComboBox.getSelectedItem())));
JButton copyRulesButton = new JButton(copyRulesAction);
topPanel.add(copyRulesButton);
add(topPanel, BorderLayout.NORTH);
add(rightOuterPanel, BorderLayout.CENTER);
if (rulesTable.getRowCount() > 0) {
rulesTable.getSelectionModel().setSelectionInterval(0, 0);
}
}