[vcs-log] fix root label behavior in "branches expanded" mode

In "branches expanded" mode details have a horisontal scrollbar. That means root label has to be carefully drawn not in the corner of the panel but rather in the corner of the viewport.
1. Location of the root label is now calculated carefully using viewport location and vertical scrollbar width.
2. myMainContentPanel is not automatially resized to fit the viewport in this mode, so its width is manually calculated in order it to fill the whole viewport.
This commit is contained in:
Julia Beliaeva
2016-09-07 20:03:48 +03:00
parent 41fe666f1c
commit acc8a3c22e
2 changed files with 37 additions and 16 deletions
@@ -26,6 +26,7 @@ import com.intellij.ui.ColorUtil;
import com.intellij.ui.UI;
import com.intellij.ui.components.JBLabel;
import com.intellij.ui.components.JBPanel;
import com.intellij.ui.components.JBScrollPane;
import com.intellij.ui.components.panels.Wrapper;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.text.DateFormatUtil;
@@ -87,17 +88,7 @@ class CommitPanel extends JBPanel {
myDataPanel = new DataPanel(myLogData.getProject());
myBranchesPanel = new BranchesPanel();
JBPanel rootPanel = new JBPanel(new FlowLayout(FlowLayout.RIGHT, 0, 0)) {
@Override
public Color getBackground() {
return getCommitDetailsBackground();
}
};
rootPanel.setOpaque(false);
rootPanel.setBorder(JBUI.Borders.emptyRight(5));
rootPanel.add(myRootPanel);
add(rootPanel);
add(myRootPanel);
add(myDataPanel);
add(myReferencesPanel);
add(myBranchesPanel);
@@ -582,6 +573,7 @@ class CommitPanel extends JBPanel {
}
private static class RootPanel extends JPanel {
private static final int RIGHT_BORDER = 5;
@NotNull private final TextLabelPainter myLabelPainter;
@NotNull private String myText = "";
@NotNull private Color myColor = getCommitDetailsBackground();
@@ -620,7 +612,22 @@ class CommitPanel extends JBPanel {
@Override
protected void paintComponent(Graphics g) {
if (!myText.isEmpty()) {
myLabelPainter.paint((Graphics2D)g, myText, 0, 0, myColor);
Dimension painterSize = myLabelPainter.calculateSize(myText, getFontMetrics(getLabelFont()));
JBScrollPane scrollPane = UIUtil.getParentOfType(JBScrollPane.class, this);
int width;
if (scrollPane == null) {
width = getWidth();
}
else {
Rectangle rect = scrollPane.getViewport().getViewRect();
JScrollBar verticalScrollBar = scrollPane.getVerticalScrollBar();
width = rect.x + rect.width;
if (verticalScrollBar.isVisible()) {
width -= verticalScrollBar.getWidth();
}
}
getWidth();
myLabelPainter.paint((Graphics2D)g, myText, width - painterSize.width - JBUI.scale(RIGHT_BORDER), 0, myColor);
}
}
@@ -629,10 +636,16 @@ class CommitPanel extends JBPanel {
return getCommitDetailsBackground();
}
@Override
public Dimension getMinimumSize() {
return getPreferredSize();
}
@Override
public Dimension getPreferredSize() {
if (myText.isEmpty()) return new JBDimension(0, TOP_BORDER);
return myLabelPainter.calculateSize(myText, getFontMetrics(getLabelFont()));
Dimension size = myLabelPainter.calculateSize(myText, getFontMetrics(getLabelFont()));
return new Dimension(size.width + JBUI.scale(RIGHT_BORDER), size.height);
}
@Override
@@ -23,6 +23,7 @@ import com.intellij.openapi.editor.colors.EditorColorsScheme;
import com.intellij.openapi.progress.util.ProgressWindow;
import com.intellij.openapi.roots.ui.componentsList.components.ScrollablePanel;
import com.intellij.openapi.ui.OnePixelDivider;
import com.intellij.openapi.ui.VerticalFlowLayout;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vcs.history.VcsHistoryUtil;
import com.intellij.ui.IdeBorderFactory;
@@ -33,10 +34,10 @@ import com.intellij.ui.components.JBScrollPane;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.ui.JBUI;
import com.intellij.util.ui.StatusText;
import com.intellij.util.ui.UIUtil;
import com.intellij.vcs.log.VcsFullCommitDetails;
import com.intellij.vcs.log.VcsRef;
import com.intellij.vcs.log.data.VcsLogData;
import com.intellij.vcs.log.data.VisiblePack;
import com.intellij.vcs.log.ui.VcsLogColorManager;
import org.jetbrains.annotations.NotNull;
@@ -88,7 +89,14 @@ class DetailsPanel extends JPanel implements EditorColorsListener {
@Override
public Dimension getPreferredSize() {
Dimension preferredSize = super.getPreferredSize();
return new Dimension(preferredSize.width, Math.max(preferredSize.height, myScrollPane.getViewport().getHeight()));
int height = Math.max(preferredSize.height, myScrollPane.getViewport().getHeight());
JBScrollPane scrollPane = UIUtil.getParentOfType(JBScrollPane.class, this);
if (scrollPane == null || getScrollableTracksViewportWidth()) {
return new Dimension(preferredSize.width, height);
}
else {
return new Dimension(Math.max(preferredSize.width, scrollPane.getViewport().getWidth()), height);
}
}
@Override
@@ -112,7 +120,7 @@ class DetailsPanel extends JPanel implements EditorColorsListener {
return StringUtil.isNotEmpty(getText());
}
};
myMainContentPanel.setLayout(new BoxLayout(myMainContentPanel, BoxLayout.Y_AXIS));
myMainContentPanel.setLayout(new VerticalFlowLayout(VerticalFlowLayout.TOP, 0, 0, true, false));
myMainContentPanel.setOpaque(false);
myScrollPane.setViewportView(myMainContentPanel);