JComponent () { myMultiLineCheckBox = new JCheckBox(IdeBundle.message("label.todo.multiline")); myPatternsTable = new JBTable(myPatternsModel); myPatternsTable.setShowGrid(false); myPatternsTable.getEmptyText().setText(IdeBundle.message("text.todo.no.patterns")); TableColumn typeColumn = myPatternsTable.getColumnModel().getColumn(0); JTableHeader tableHeader = myPatternsTable.getTableHeader(); FontMetrics headerFontMetrics = tableHeader.getFontMetrics(tableHeader.getFont()); int typeColumnWidth = headerFontMetrics.stringWidth(myPatternsTable.getColumnName(0) + HEADER_GAP); typeColumn.setPreferredWidth(typeColumnWidth); typeColumn.setMinWidth(typeColumnWidth); typeColumn.setCellRenderer(new IconTableCellRenderer<Icon>() { @NotNull @Override protected Icon getIcon(@NotNull Icon value, JTable table, int row) { return value; } @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean selected, boolean focus, int row, int column) { super.getTableCellRendererComponent(table, value, selected, focus, row, column); setText(""); return this; } @Override protected boolean isCenterAlignment() { return true; } }); // Column "Case Sensitive" TableColumn todoCaseSensitiveColumn = myPatternsTable.getColumnModel().getColumn(1); int caseSensitiveColumnWidth = headerFontMetrics.stringWidth(myPatternsTable.getColumnName(1)) + HEADER_GAP; todoCaseSensitiveColumn.setPreferredWidth(caseSensitiveColumnWidth); todoCaseSensitiveColumn.setMinWidth(caseSensitiveColumnWidth); todoCaseSensitiveColumn.setCellRenderer(new BooleanTableCellRenderer()); todoCaseSensitiveColumn.setCellEditor(new BooleanTableCellEditor()); // Column "Pattern" TodoPatternTableCellRenderer todoPatternRenderer = new TodoPatternTableCellRenderer(myPatterns); TableColumn patternColumn = myPatternsTable.getColumnModel().getColumn(2); patternColumn.setCellRenderer(todoPatternRenderer); patternColumn.setPreferredWidth(patternColumn.getMaxWidth()); JPanel patternsPanel = new JPanel(new BorderLayout()); patternsPanel.setBorder(IdeBorderFactory.createTitledBorder(IdeBundle.message("label.todo.patterns"), false, JBUI.insetsTop(8)).setShowLine(false)); patternsPanel.add(ToolbarDecorator.createDecorator(myPatternsTable) .setAddAction(new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { stopEditing(); TodoPattern pattern = new TodoPattern(TodoAttributesUtil.createDefault()); PatternDialog dialog = new PatternDialog(myPanel, pattern, -1, myPatterns); if (!dialog.showAndGet()) { return; } myPatterns.add(pattern); int index = myPatterns.size() - 1; myPatternsModel.fireTableRowsInserted(index, index); myPatternsTable.getSelectionModel().setSelectionInterval(index, index); myPatternsTable.scrollRectToVisible(myPatternsTable.getCellRect(index, 0, true)); } }) .setEditAction(new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { editSelectedPattern(); } }) .setRemoveAction(new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { stopEditing(); int selectedIndex = myPatternsTable.getSelectedRow(); if (selectedIndex < 0 || selectedIndex >= myPatternsModel.getRowCount()) { return; } TodoPattern patternToBeRemoved = myPatterns.get(selectedIndex); TableUtil.removeSelectedItems(myPatternsTable); for (int i = 0; i < myFilters.size(); i++) { TodoFilter filter = myFilters.get(i); if (filter.contains(patternToBeRemoved)) { filter.removeTodoPattern(patternToBeRemoved); myFiltersModel.fireTableRowsUpdated(i, i); } } } }) .disableUpDownActions().createPanel(), BorderLayout.CENTER); // double click in "Patterns" table should also start editing of selected pattern new DoubleClickListener() { @Override protected boolean onDoubleClick(@NotNull MouseEvent e) { editSelectedPattern(); return true; } }.installOn(myPatternsTable); // Panel with filters myFiltersTable = new JBTable(myFiltersModel); myFiltersTable.setShowGrid(false); myFiltersTable.getEmptyText().setText(IdeBundle.message("text.todo.no.filters")); // Column "Name" TableColumn nameColumn = myFiltersTable.getColumnModel().getColumn(0); int nameColumnWidth = caseSensitiveColumnWidth + typeColumnWidth; nameColumn.setPreferredWidth(nameColumnWidth); nameColumn.setMinWidth(nameColumnWidth); nameColumn.setCellRenderer(new MyFilterNameTableCellRenderer()); TableColumn patternsColumn = myFiltersTable.getColumnModel().getColumn(1); patternsColumn.setPreferredWidth(patternsColumn.getMaxWidth()); JPanel filtersPanel = new JPanel(new BorderLayout()); filtersPanel.setBorder(IdeBorderFactory.createTitledBorder(IdeBundle.message("label.todo.filters"), false, JBUI.insetsTop(13)) .setShowLine(false)); filtersPanel.add(ToolbarDecorator.createDecorator(myFiltersTable) .setAddAction(new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { stopEditing(); TodoFilter filter = new TodoFilter(); FilterDialog dialog = new FilterDialog(myPanel, filter, -1, myFilters, myPatterns); if (dialog.showAndGet()) { myFilters.add(filter); int index = myFilters.size() - 1; myFiltersModel.fireTableRowsInserted(index, index); myFiltersTable.getSelectionModel().setSelectionInterval(index, index); myFiltersTable.scrollRectToVisible(myFiltersTable.getCellRect(index, 0, true)); } } }) .setEditAction(new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { editSelectedFilter(); } }) .setRemoveAction(new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { stopEditing(); TableUtil.removeSelectedItems(myFiltersTable); } }).disableUpDownActions().createPanel()); new DoubleClickListener() { @Override protected boolean onDoubleClick(@NotNull MouseEvent e) { editSelectedFilter(); return true; } }.installOn(myFiltersTable); myPanel = FormBuilder.createFormBuilder() .addComponent(myMultiLineCheckBox) .addComponentFillVertically(patternsPanel, 0) .addComponentFillVertically(filtersPanel, 0) .getPanel(); return myPanel; }