private boolean setColumnPreferredSize() {
   boolean sizeCalculated = false;
   Font tableFont = UIManager.getFont("Table.font");
   for (int i = 0; i < getColumnCount(); i++) {
     TableColumn column = getColumnModel().getColumn(i);
     if (i == GraphTableModel.ROOT_COLUMN) { // thin stripe, or root name, or nothing
       setRootColumnSize(column);
     } else if (i
         == GraphTableModel.COMMIT_COLUMN) { // let commit message occupy as much as possible
       column.setPreferredWidth(Short.MAX_VALUE);
     } else if (i == GraphTableModel.AUTHOR_COLUMN) { // detect author with the longest name
       // to avoid querying the last row (it would lead to full graph loading)
       int maxRowsToCheck =
           Math.min(MAX_ROWS_TO_CALC_WIDTH, getRowCount() - MAX_ROWS_TO_CALC_OFFSET);
       if (maxRowsToCheck < 0) { // but if the log is small, check all of them
         maxRowsToCheck = getRowCount();
       }
       int maxWidth = 0;
       for (int row = 0; row < maxRowsToCheck; row++) {
         String value = getModel().getValueAt(row, i).toString();
         maxWidth = Math.max(getFontMetrics(tableFont).stringWidth(value), maxWidth);
         if (!value.isEmpty()) sizeCalculated = true;
       }
       column.setMinWidth(
           Math.min(maxWidth + UIUtil.DEFAULT_HGAP, MAX_DEFAULT_AUTHOR_COLUMN_WIDTH));
       column.setWidth(column.getMinWidth());
     } else if (i == GraphTableModel.DATE_COLUMN) { // all dates have nearly equal sizes
       column.setMinWidth(
           getFontMetrics(tableFont)
               .stringWidth("mm" + DateFormatUtil.formatDateTime(new Date())));
       column.setWidth(column.getMinWidth());
     }
   }
   return sizeCalculated;
 }
  private void setRootColumnSize(TableColumn column) {
    int rootWidth;
    if (!myUI.isMultipleRoots()) {
      rootWidth = 0;
    } else if (!myUI.isShowRootNames()) {
      rootWidth = ROOT_INDICATOR_WIDTH;
    } else {
      rootWidth = Math.min(calculateMaxRootWidth(), ROOT_NAME_MAX_WIDTH);
    }

    // NB: all further instructions and their order are important, otherwise the minimum size which
    // is less than 15 won't be applied
    column.setMinWidth(rootWidth);
    column.setMaxWidth(rootWidth);
    column.setPreferredWidth(rootWidth);
  }
  private ElementsChooser(@Nullable List<T> elements, boolean marked, boolean elementsCanBeMarked) {
    super(new BorderLayout());

    myTableModel = new MyTableModel(elementsCanBeMarked);
    myTable = new Table(myTableModel);
    myTable.setShowGrid(false);
    myTable.setIntercellSpacing(new Dimension(0, 0));
    myTable.setTableHeader(null);
    myTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
    myTable.setColumnSelectionAllowed(false);
    JScrollPane pane = ScrollPaneFactory.createScrollPane(myTable);
    pane.setPreferredSize(new Dimension(100, 155));
    int width = new JCheckBox().getPreferredSize().width;
    TableColumnModel columnModel = myTable.getColumnModel();

    if (elementsCanBeMarked) {
      TableColumn checkMarkColumn = columnModel.getColumn(myTableModel.CHECK_MARK_COLUM_INDEX);
      checkMarkColumn.setPreferredWidth(width);
      checkMarkColumn.setMaxWidth(width);
      checkMarkColumn.setCellRenderer(
          new CheckMarkColumnCellRenderer(myTable.getDefaultRenderer(Boolean.class)));
    }
    columnModel
        .getColumn(myTableModel.ELEMENT_COLUMN_INDEX)
        .setCellRenderer(new MyElementColumnCellRenderer());

    add(pane, BorderLayout.CENTER);
    myTable.registerKeyboardAction(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            final int[] selectedRows = myTable.getSelectedRows();
            boolean currentlyMarked = true;
            for (int selectedRow : selectedRows) {
              currentlyMarked = myTableModel.isElementMarked(selectedRow);
              if (!currentlyMarked) {
                break;
              }
            }
            myTableModel.setMarked(selectedRows, !currentlyMarked);
          }
        },
        KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0),
        JComponent.WHEN_FOCUSED);

    final SpeedSearchBase<JBTable> speedSearch =
        new SpeedSearchBase<JBTable>(myTable) {
          public int getSelectedIndex() {
            return myTable.getSelectedRow();
          }

          @Override
          protected int convertIndexToModel(int viewIndex) {
            return myTable.convertRowIndexToModel(viewIndex);
          }

          public Object[] getAllElements() {
            final int count = myTableModel.getRowCount();
            Object[] elements = new Object[count];
            for (int idx = 0; idx < count; idx++) {
              elements[idx] = myTableModel.getElementAt(idx);
            }
            return elements;
          }

          public String getElementText(Object element) {
            return getItemText((T) element);
          }

          public void selectElement(Object element, String selectedText) {
            final int count = myTableModel.getRowCount();
            for (int row = 0; row < count; row++) {
              if (element.equals(myTableModel.getElementAt(row))) {
                final int viewRow = myTable.convertRowIndexToView(row);
                myTable.getSelectionModel().setSelectionInterval(viewRow, viewRow);
                TableUtil.scrollSelectionToVisible(myTable);
                break;
              }
            }
          }
        };
    speedSearch.setComparator(new SpeedSearchBase.SpeedSearchComparator(false));
    setElements(elements, marked);
    installActions(myTable);
  }
 private int getXOffset() {
   TableColumn rootColumn = getColumnModel().getColumn(GraphTableModel.ROOT_COLUMN);
   return myLogDataHolder.isMultiRoot() ? rootColumn.getWidth() : 0;
 }