diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/TextPanel.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/TextPanel.java
index 83a400d1f9dd..f44066feb8f0 100644
--- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/TextPanel.java
+++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/TextPanel.java
@@ -30,16 +30,16 @@ public class TextPanel extends JComponent {
private boolean myDecorate = true;
private float myAlignment;
- TextPanel() {
+ protected TextPanel() {
this(null);
}
- TextPanel(final boolean decorate) {
+ protected TextPanel(final boolean decorate) {
this(null);
myDecorate = decorate;
}
- TextPanel(@Nullable final String maxPossibleString) {
+ protected TextPanel(@Nullable final String maxPossibleString) {
myMaxPossibleString = maxPossibleString;
setFont(SystemInfo.isMac ? UIUtil.getLabelFont().deriveFont(11.0f) : UIUtil.getLabelFont());
@@ -93,7 +93,7 @@ public class TextPanel extends JComponent {
final int y = UIUtil.getStringY(s, bounds, g2);
if (SystemInfo.isMac && myDecorate) {
g2.setColor(new Color(215, 215, 215));
- g2.drawString(s, x, y+1);
+ g2.drawString(s, x, y + 1);
}
g2.setColor(getForeground());
@@ -105,7 +105,7 @@ public class TextPanel extends JComponent {
myAlignment = alignment;
}
- private static String splitText(final JLabel label, final String text, final int widthLimit){
+ private static String splitText(final JLabel label, final String text, final int widthLimit) {
final FontMetrics fontMetrics = label.getFontMetrics(label.getFont());
final String[] lines = UIUtil.splitText(text, fontMetrics, widthLimit, ' ');
@@ -130,9 +130,10 @@ public class TextPanel extends JComponent {
return myText;
}
- public Dimension getPreferredSize(){
+ public Dimension getPreferredSize() {
int max = 0;
- if (myMaxPossibleString != null) max = getFontMetrics(getFont()).stringWidth(myMaxPossibleString);
+ String text = getTextForPreferredSize();
+ if (text != null) max = getFontMetrics(getFont()).stringWidth(text);
if (myPrefSize != null) {
return new Dimension(20 + max, myPrefSize.height);
@@ -140,4 +141,11 @@ public class TextPanel extends JComponent {
return new Dimension(20 + max, getMinimumSize().height);
}
+
+ /**
+ * @return the text that is used to calculate the preferred size
+ */
+ protected String getTextForPreferredSize() {
+ return myMaxPossibleString;
+ }
}
diff --git a/plugins/git4idea/src/git4idea/checkout/branches/GitBranchesWidget.java b/plugins/git4idea/src/git4idea/checkout/branches/GitBranchesWidget.java
index 9ff127fb247a..4513bf8c7ba3 100644
--- a/plugins/git4idea/src/git4idea/checkout/branches/GitBranchesWidget.java
+++ b/plugins/git4idea/src/git4idea/checkout/branches/GitBranchesWidget.java
@@ -37,6 +37,7 @@ import com.intellij.openapi.wm.CustomStatusBarWidget;
import com.intellij.openapi.wm.StatusBar;
import com.intellij.openapi.wm.ToolWindowManager;
import com.intellij.openapi.wm.WindowManager;
+import com.intellij.openapi.wm.impl.status.TextPanel;
import com.intellij.ui.awt.RelativePoint;
import com.intellij.util.ui.UIUtil;
import git4idea.GitUtil;
@@ -58,7 +59,11 @@ import java.util.Collection;
/**
* The git branches widget
*/
-public class GitBranchesWidget extends JLabel implements CustomStatusBarWidget {
+public class GitBranchesWidget extends TextPanel implements CustomStatusBarWidget {
+ /**
+ * The arrows icon
+ */
+ private static final Icon ARROWS_ICON = IconLoader.getIcon("/ide/statusbar_arrows.png");
/**
* The logger
*/
@@ -125,7 +130,6 @@ public class GitBranchesWidget extends JLabel implements CustomStatusBarWidget {
myDefaultForeground = getForeground();
myConfigurationsListener = new MyGitBranchConfigurationsListener();
myConfigurations.addConfigurationListener(myConfigurationsListener);
- setIcon(IconLoader.findIcon("/icons/branch.png", getClass()));
Disposer.register(myConfigurations, this);
addMouseListener(new MouseAdapter() {
@Override
@@ -241,12 +245,11 @@ public class GitBranchesWidget extends JLabel implements CustomStatusBarWidget {
final DataContext parent = DataManager.getInstance().getDataContext((Component)myStatusBar);
final DataContext dataContext = SimpleDataContext.getSimpleContext(PlatformDataKeys.PROJECT.getName(), myProject, parent);
myPopup = JBPopupFactory.getInstance()
- .createActionGroupPopup("Checkout", getPopupActionGroup(), dataContext, JBPopupFactory.ActionSelectionAid.SPEEDSEARCH, true,
+ .createActionGroupPopup(null, getPopupActionGroup(), dataContext, JBPopupFactory.ActionSelectionAid.SPEEDSEARCH, true,
new Runnable() {
@Override
public void run() {
myPopup = null;
-
}
}, 20);
final Dimension dimension = myPopup.getContent().getPreferredSize();
@@ -341,23 +344,32 @@ public class GitBranchesWidget extends JLabel implements CustomStatusBarWidget {
private void updateLabel() {
cancelPopup();
final GitBranchConfigurations.SpecialStatus status = myConfigurations.getSpecialStatus();
- String t;
+ String text;
myPopupEnabled = false;
+ Color color = Color.RED;
+ String tooltip;
switch (status) {
case CHECKOUT_IN_PROGRESS:
- t = "Checkout in progress...";
+ text = "Checkout...";
+ color = Color.BLUE;
+ tooltip = "A checkout operation is in progress.";
break;
case MERGING:
- t = "Merging...";
+ text = "Merging...";
+ tooltip = "Merge is in progress in some vcs roots.";
break;
case REBASING:
- t = "Rebasing...";
+ tooltip = "Rebase is in progress in some vcs roots.";
+ text = "Rebasing...";
break;
case NON_GIT:
- t = "Non-Git project";
+ tooltip = "No valid vcs roots are configuration for the project.";
+ text = "Non-Git project";
break;
case SUBMODULES:
- t = "Submodules unsupported";
+ tooltip =
+ "The submodules are unsupported in the current version.
It is possible to disable widget in Git Vcs settings.";
+ text = "Submodules unsupported";
break;
case NORMAL:
GitBranchConfiguration current;
@@ -368,18 +380,49 @@ public class GitBranchesWidget extends JLabel implements CustomStatusBarWidget {
current = null;
}
if (current == null) {
- t = "Detection in progress";
+ tooltip = "The branch configurations are not yet detected.";
+ text = "Detecting...";
}
else {
myPopupEnabled = true;
- t = current.getName();
+ text = current.getName();
+ tooltip = "The Git branch configuration " + text + " is selected.
Click to select other configuration.";
+ color = myDefaultForeground;
}
break;
default:
- t = "Unknown status: " + status;
+ tooltip = "Unknown status: " + status;
+ text = "Unknown status: " + status;
}
- setForeground(myPopupEnabled ? myDefaultForeground : Color.RED);
- setText(t);
+ if (!SystemInfo.isMac) {
+ setForeground(color);
+ }
+ setToolTipText(tooltip);
+ setText(text);
+ invalidate();
+ }
+
+ @Override
+ protected void paintComponent(@NotNull final Graphics g) {
+ super.paintComponent(g);
+
+ if (getText() != null && myPopupEnabled) {
+ final Rectangle r = getBounds();
+ final Insets insets = getInsets();
+ ARROWS_ICON
+ .paintIcon(this, g, r.width - insets.right - ARROWS_ICON.getIconWidth() - 2, r.height / 2 - ARROWS_ICON.getIconHeight() / 2);
+ }
+ }
+
+ @Override
+ public Dimension getPreferredSize() {
+ final Dimension preferredSize = super.getPreferredSize();
+ return new Dimension(preferredSize.width + ARROWS_ICON.getIconWidth() + 4, preferredSize.height);
+ }
+
+ @Override
+ protected String getTextForPreferredSize() {
+ return getText();
}
/**