diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/CommonUiProperties.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/CommonUiProperties.java index 03ea115a680a..0dbe7aed74df 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/CommonUiProperties.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/CommonUiProperties.java @@ -39,14 +39,11 @@ public class CommonUiProperties { } } - public static int getColumnWidth(@NotNull VcsLogUiProperties properties, int column, int defaultWidth) { + public static int getColumnWidth(@NotNull VcsLogUiProperties properties, int column) { if (properties.exists(COLUMN_WIDTH.get(column))) { - Integer savedWidth = properties.get(COLUMN_WIDTH.get(column)); - if (savedWidth > defaultWidth) { - return savedWidth; - } + return properties.get(COLUMN_WIDTH.get(column)); } - return defaultWidth; + return -1; } public static class TableColumnProperty extends VcsLogUiProperty { diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsLogUiPropertiesImpl.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsLogUiPropertiesImpl.java index 9c0f678663ee..f8962e32d3e8 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsLogUiPropertiesImpl.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsLogUiPropertiesImpl.java @@ -262,7 +262,7 @@ public abstract class VcsLogUiPropertiesImpl implements PersistentStateComponent public abstract void onHighlighterChanged(); - public abstract void onColumnWidthChanged(); + public abstract void onColumnWidthChanged(int column); @Override public void onPropertyChanged(@NotNull VcsLogUiProperties.VcsLogUiProperty property) { @@ -291,7 +291,7 @@ public abstract class VcsLogUiPropertiesImpl implements PersistentStateComponent onHighlighterChanged(); } else if (property instanceof CommonUiProperties.TableColumnProperty) { - onColumnWidthChanged(); + onColumnWidthChanged(((CommonUiProperties.TableColumnProperty)property).getColumn()); } else { throw new UnsupportedOperationException("Property " + property + " does not exist"); diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/VcsLogUiImpl.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/VcsLogUiImpl.java index dff6d06f1f38..17417f706bdb 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/VcsLogUiImpl.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/VcsLogUiImpl.java @@ -185,8 +185,8 @@ public class VcsLogUiImpl extends AbstractVcsLogUi { } @Override - public void onColumnWidthChanged() { - myMainFrame.getGraphTable().onColumnWidthSettingChanged(); + public void onColumnWidthChanged(int column) { + myMainFrame.getGraphTable().forceReLayout(column); } @Override diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/history/FileHistoryUi.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/history/FileHistoryUi.java index eb98bc2643c7..33d40170566d 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/history/FileHistoryUi.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/history/FileHistoryUi.java @@ -255,7 +255,7 @@ public class FileHistoryUi extends AbstractVcsLogUi { updateFilter(); } else if (property instanceof CommonUiProperties.TableColumnProperty) { - getTable().onColumnWidthSettingChanged(); + getTable().forceReLayout(((CommonUiProperties.TableColumnProperty)property).getColumn()); } } } diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/table/VcsLogGraphTable.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/table/VcsLogGraphTable.java index 2b4436ebc1d2..062821af87cd 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/table/VcsLogGraphTable.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/table/VcsLogGraphTable.java @@ -99,7 +99,7 @@ public class VcsLogGraphTable extends TableWithProgress implements DataProvider, @NotNull private final GraphCommitCellRenderer myGraphCommitCellRenderer; @NotNull private final GraphTableController myController; @NotNull private final StringCellRenderer myStringCellRenderer; - private boolean myColumnsSizeInitialized = false; + private boolean myAuthorColumnInitialized = false; @Nullable private Selection mySelection = null; @@ -154,11 +154,6 @@ public class VcsLogGraphTable extends TableWithProgress implements DataProvider, setRootColumnSize(); - // all dates have nearly equal sizes - int dateSize = getFontMetrics(getTableFont().deriveFont(Font.BOLD)).stringWidth(DateFormatUtil.formatDateTime(new Date())) + - myStringCellRenderer.getHorizontalTextPadding(); - getColumnModel().getColumn(DATE_COLUMN).setMinWidth(dateSize); - for (int column = 0; column < getColumnCount(); column++) { getColumnModel().getColumn(column).setResizable(column != ROOT_COLUMN); } @@ -179,71 +174,89 @@ public class VcsLogGraphTable extends TableWithProgress implements DataProvider, } setPaintBusy(false); - reLayout(filtersChanged); + myAuthorColumnInitialized = myAuthorColumnInitialized && !filtersChanged; + reLayout(); } - public void reLayout(boolean forceRecalculateMinimumWidth) { - if (!myColumnsSizeInitialized || forceRecalculateMinimumWidth) { - myColumnsSizeInitialized = updateColumnsMinWidth(); - } + public void reLayout() { if (getTableHeader().getResizingColumn() == null) { - updateColumnsPreferredWidth(); + updateAuthorAndDataWidth(); + super.doLayout(); + repaint(); } - updateCommitColumnWidth(); - - super.doLayout(); } - public void onColumnWidthSettingChanged() { - if (getTableHeader().getResizingColumn() == null) { - reLayout(false); - } + public void forceReLayout(int column) { + if (column == AUTHOR_COLUMN) myAuthorColumnInitialized = false; + reLayout(); } @Override public void doLayout() { - reLayout(false); + if (getTableHeader().getResizingColumn() == null) { + updateAuthorAndDataWidth(); + } + super.doLayout(); } - private void updateColumnsPreferredWidth() { + private void updateAuthorAndDataWidth() { for (int i : new int[]{AUTHOR_COLUMN, DATE_COLUMN}) { - int width = CommonUiProperties.getColumnWidth(myUi.getProperties(), i, getColumnModel().getColumn(i).getMinWidth()); - getColumnModel().getColumn(i).setPreferredWidth(Math.min(width, getWidth())); + int width = CommonUiProperties.getColumnWidth(myUi.getProperties(), i); + if (width <= 0 || width > getWidth()) { + if (i != AUTHOR_COLUMN || !myAuthorColumnInitialized) { + width = getColumnWidthFromData(i); + } + else { + width = -1; + } + } + + if (width > 0 && width != getColumnModel().getColumn(i).getPreferredWidth()) { + getColumnModel().getColumn(i).setPreferredWidth(width); + } } + + updateCommitColumnWidth(); } - private boolean updateColumnsMinWidth() { + private int getColumnWidthFromData(int i) { Font tableFont = getTableFont(); + if (i == AUTHOR_COLUMN) { + int width = getColumnModel().getColumn(AUTHOR_COLUMN).getPreferredWidth(); - // detect author with the longest name - boolean sizeCalculated = false; - if (getModel().getRowCount() > 0) { - int maxRowsToCheck = Math.min(MAX_ROWS_TO_CALC_WIDTH, getRowCount()); - int maxAuthorWidth = 0; - int unloaded = 0; - for (int row = 0; row < maxRowsToCheck; row++) { - String value = getModel().getValueAt(row, AUTHOR_COLUMN).toString(); - if (value.isEmpty()) { - unloaded++; - continue; + // detect author with the longest name + if (getModel().getRowCount() > 0) { + int maxRowsToCheck = Math.min(MAX_ROWS_TO_CALC_WIDTH, getRowCount()); + int maxAuthorWidth = 0; + int unloaded = 0; + for (int row = 0; row < maxRowsToCheck; row++) { + String value = getModel().getValueAt(row, AUTHOR_COLUMN).toString(); + if (value.isEmpty()) { + unloaded++; + continue; + } + Font font = tableFont; + VcsLogHighlighter.TextStyle style = getStyle(row, AUTHOR_COLUMN, false, false).getTextStyle(); + if (BOLD.equals(style)) { + font = tableFont.deriveFont(Font.BOLD); + } + else if (ITALIC.equals(style)) { + font = tableFont.deriveFont(Font.ITALIC); + } + maxAuthorWidth = Math.max(getFontMetrics(font).stringWidth(value + "*"), maxAuthorWidth); } - Font font = tableFont; - VcsLogHighlighter.TextStyle style = getStyle(row, AUTHOR_COLUMN, false, false).getTextStyle(); - if (BOLD.equals(style)) { - font = tableFont.deriveFont(Font.BOLD); - } - else if (ITALIC.equals(style)) { - font = tableFont.deriveFont(Font.ITALIC); - } - maxAuthorWidth = Math.max(getFontMetrics(font).stringWidth(value + "*"), maxAuthorWidth); + + width = Math.min(maxAuthorWidth + myStringCellRenderer.getHorizontalTextPadding(), JBUI.scale(MAX_DEFAULT_AUTHOR_COLUMN_WIDTH)); + if (unloaded * 2 <= maxRowsToCheck) myAuthorColumnInitialized = true; } - int authorSize = - Math.min(maxAuthorWidth + myStringCellRenderer.getHorizontalTextPadding(), JBUI.scale(MAX_DEFAULT_AUTHOR_COLUMN_WIDTH)); - getColumnModel().getColumn(AUTHOR_COLUMN).setMinWidth(authorSize); - if (unloaded * 2 <= maxRowsToCheck) sizeCalculated = true; + return width; } - - return sizeCalculated; + else if (i == DATE_COLUMN) { + // all dates have nearly equal sizes + return getFontMetrics(getTableFont().deriveFont(Font.BOLD)).stringWidth(DateFormatUtil.formatDateTime(new Date())) + + myStringCellRenderer.getHorizontalTextPadding(); + } + throw new IllegalArgumentException("Can only calculate author or date columns width from data, yet given column " + i); } private static Font getTableFont() { @@ -288,7 +301,7 @@ public class VcsLogGraphTable extends TableWithProgress implements DataProvider, public void rootColumnUpdated() { setRootColumnSize(); - reLayout(false); + reLayout(); repaint(); } @@ -940,14 +953,12 @@ public class VcsLogGraphTable extends TableWithProgress implements DataProvider, if ("width".equals(evt.getPropertyName())) { TableColumn authorColumn = getColumn(AUTHOR_COLUMN); if (authorColumn.equals(evt.getSource())) { - CommonUiProperties.saveColumnWidth(myProperties, AUTHOR_COLUMN, - authorColumn.getMinWidth() == authorColumn.getWidth() ? -1 : authorColumn.getWidth()); + CommonUiProperties.saveColumnWidth(myProperties, AUTHOR_COLUMN, authorColumn.getWidth()); } else { TableColumn dateColumn = getColumn(DATE_COLUMN); if (dateColumn.equals(evt.getSource())) { - CommonUiProperties.saveColumnWidth(myProperties, DATE_COLUMN, - dateColumn.getMinWidth() == dateColumn.getWidth() ? -1 : dateColumn.getWidth()); + CommonUiProperties.saveColumnWidth(myProperties, DATE_COLUMN, dateColumn.getWidth()); } } } diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/util/VcsLogUiUtil.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/util/VcsLogUiUtil.java index 069148200a86..cc63ec62a257 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/util/VcsLogUiUtil.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/util/VcsLogUiUtil.java @@ -68,7 +68,7 @@ public class VcsLogUiUtil { @NotNull VcsLogData logData, @NotNull Disposable disposableParent) { Runnable miniDetailsLoadedListener = () -> { - graphTable.reLayout(false); + graphTable.reLayout(); graphTable.repaint(); }; Runnable containingBranchesListener = () -> {