private void setColumnPreferredSize() { for (int i = 0; i < getColumnCount(); i++) { TableColumn column = getColumnModel().getColumn(i); if (i == AbstractVcsLogTableModel.ROOT_COLUMN) { // thin stripe or nothing int rootWidth = myUI.getColorManager().isMultipleRoots() ? ROOT_INDICATOR_WIDTH : 0; // 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); } else if (i == AbstractVcsLogTableModel .COMMIT_COLUMN) { // let commit message occupy as much as possible column.setPreferredWidth(Short.MAX_VALUE); } else if (i == AbstractVcsLogTableModel.AUTHOR_COLUMN) { // detect author with the longest name int contentWidth = calcMaxContentColumnWidth(i, 1000); column.setMinWidth(Math.min(contentWidth, MAX_DEFAULT_AUTHOR_COLUMN_WIDTH)); column.setWidth(column.getMinWidth()); } else if (i == AbstractVcsLogTableModel.DATE_COLUMN) { // all dates have nearly equal sizes Font tableFont = UIManager.getFont("Table.font"); column.setMinWidth( getFontMetrics(tableFont) .stringWidth("mm" + DateFormatUtil.formatDateTime(new Date()))); column.setWidth(column.getMinWidth()); } } }
@Override public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { if (value instanceof VirtualFile) { myColor = myUi.getColorManager().getRootColor((VirtualFile) value); } else { myColor = UIUtil.getTableBackground(isSelected); } return this; }
@Override protected void paintComponent(Graphics g) { g.setColor(myColor); g.fillRect(0, 0, ROOT_INDICATOR_WIDTH - 1, HEIGHT_CELL); UIUtil.drawLine( (Graphics2D) g, ROOT_INDICATOR_WIDTH - 1, 0, ROOT_INDICATOR_WIDTH - 1, HEIGHT_CELL, null, myUi.getColorManager().getRootIndicatorBorder()); }
public VcsLogGraphTable(@NotNull VcsLogUI UI, final VcsLogDataHolder logDataHolder) { super(); myUI = UI; myGraphPainter = new SimpleGraphCellPainter(logDataHolder.isMultiRoot()); setDefaultRenderer(VirtualFile.class, new RootCellRenderer(myUI)); setDefaultRenderer( GraphCommitCell.class, new GraphCommitCellRender(myGraphPainter, logDataHolder, myUI.getColorManager())); setDefaultRenderer( CommitCell.class, new CommitCellRender(myUI.getColorManager(), logDataHolder.getProject())); setDefaultRenderer(String.class, new StringCellRenderer()); setRowHeight(HEIGHT_CELL); setShowHorizontalLines(false); setIntercellSpacing(new Dimension(0, 0)); getSelectionModel() .addListSelectionListener( new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { int selectedRow = getSelectedRow(); if (selectedRow >= 0) { myUI.click(selectedRow); } } }); MouseAdapter mouseAdapter = new MyMouseAdapter(); addMouseMotionListener(mouseAdapter); addMouseListener(mouseAdapter); PopupHandler.installPopupHandler( this, VcsLogUI.POPUP_ACTION_GROUP, VcsLogUI.VCS_LOG_TABLE_PLACE); getColumnModel() .addColumnModelListener( new TableColumnModelListener() { @Override public void columnAdded(TableColumnModelEvent e) { if (e.getToIndex() == AbstractVcsLogTableModel.ROOT_COLUMN) { myGraphPainter.setRootColumn( getColumnModel().getColumn(AbstractVcsLogTableModel.ROOT_COLUMN)); } } @Override public void columnRemoved(TableColumnModelEvent e) {} @Override public void columnMoved(TableColumnModelEvent e) {} @Override public void columnMarginChanged(ChangeEvent e) {} @Override public void columnSelectionChanged(ListSelectionEvent e) {} }); }