Support for Distraction Free Mode

This commit is contained in:
Alexander Lobas
2016-04-14 12:40:04 +03:00
parent f9bd75aabc
commit 3a44a79c5a
5 changed files with 84 additions and 10 deletions
@@ -35,6 +35,7 @@ import com.intellij.ui.ClickListener;
import com.intellij.ui.JBColor;
import com.intellij.ui.LayeredIcon;
import com.intellij.ui.SimpleColoredComponent;
import com.intellij.util.ui.JBUI;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -191,7 +192,7 @@ public class IdeNotificationArea extends JLabel implements CustomStatusBarWidget
myStr = str;
myComponent = component;
myTextColor = textColor;
myFont = new Font(NotificationsUtil.getFontName(), Font.BOLD, 9);
myFont = new Font(NotificationsUtil.getFontName(), Font.BOLD, JBUI.scale(9));
myWidth = myComponent.getFontMetrics(myFont).stringWidth(myStr);
}
@@ -1121,7 +1121,11 @@ public class NotificationsManagerImpl extends NotificationsManager {
}
if (myCenteredComponent != null) {
myCenteredComponent.setBounds(0, top, width, centeredSize.height);
int centeredWidth = width;
if (!myLayoutData.showFullContent && !myLayoutData.showMinSize && myLayoutData.fullHeight != myLayoutData.maxScrollHeight) {
centeredWidth--;
}
myCenteredComponent.setBounds(0, top, centeredWidth, centeredSize.height);
myCenteredComponent.revalidate();
}
@@ -28,16 +28,16 @@ import com.intellij.openapi.progress.TaskInfo;
import com.intellij.openapi.progress.util.AbstractProgressIndicatorExBase;
import com.intellij.openapi.project.ProjectUtil;
import com.intellij.openapi.ui.MessageType;
import com.intellij.openapi.ui.popup.Balloon;
import com.intellij.openapi.ui.popup.BalloonHandler;
import com.intellij.openapi.ui.popup.JBPopupFactory;
import com.intellij.openapi.ui.popup.*;
import com.intellij.openapi.util.*;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.wm.CustomStatusBarWidget;
import com.intellij.openapi.wm.IdeFrame;
import com.intellij.openapi.wm.StatusBar;
import com.intellij.openapi.wm.StatusBarWidget;
import com.intellij.openapi.wm.ex.ProgressIndicatorEx;
import com.intellij.ui.BalloonLayoutImpl;
import com.intellij.ui.Gray;
import com.intellij.ui.TabbedPaneWrapper;
import com.intellij.ui.awt.RelativePoint;
@@ -389,8 +389,9 @@ public class InfoAndProgressPanel extends JPanel implements CustomStatusBarWidge
Disposer.register(inline, delegate);
Component anchor = getAnchor(pane);
final BalloonLayoutImpl balloonLayout = getBalloonLayout(pane);
JBPopupFactory.getInstance().createBalloonBuilder(panel.getProgressPanel())
final Balloon balloon = JBPopupFactory.getInstance().createBalloonBuilder(panel.getProgressPanel())
.setFadeoutTime(0)
.setFillColor(Gray.TRANSPARENT)
.setShowCallout(false)
@@ -404,15 +405,52 @@ public class InfoAndProgressPanel extends JPanel implements CustomStatusBarWidge
.setHideOnKeyOutside(false)
.setBlockClicksThroughBalloon(true)
.setHideOnAction(false)
.createBalloon().show(new PositionTracker<Balloon>(anchor) {
.createBalloon();
if (balloonLayout != null) {
class MyListener implements JBPopupListener, Runnable {
@Override
public void beforeShown(LightweightWindowEvent event) {
balloonLayout.addListener(this);
}
@Override
public void onClosed(LightweightWindowEvent event) {
balloonLayout.removeListener(this);
}
@Override
public void run() {
balloon.revalidate();
}
}
balloon.addListener(new MyListener());
}
balloon.show(new PositionTracker<Balloon>(anchor) {
@Override
public RelativePoint recalculateLocation(Balloon object) {
Component c = getAnchor(pane);
return new RelativePoint(c, new Point(c.getWidth() - 150, c.getHeight() - 45));
int y = c.getHeight() - 45;
if (balloonLayout != null) {
Component component = balloonLayout.getTopBalloonComponent();
if (component != null) {
y = SwingUtilities.convertPoint(component, 0, -45, c).y;
}
}
return new RelativePoint(c, new Point(c.getWidth() - 150, y));
}
}, Balloon.Position.above);
}
@Nullable
private static BalloonLayoutImpl getBalloonLayout(@NotNull JRootPane pane) {
Component parent = UIUtil.findUltimateParent(pane);
if (parent instanceof IdeFrame) {
return (BalloonLayoutImpl)((IdeFrame)parent).getBalloonLayout();
}
return null;
}
@NotNull
private static Component getAnchor(@NotNull JRootPane pane) {
Component tabWrapper = UIUtil.findComponentOfType(pane, TabbedPaneWrapper.TabWrapper.class);
@@ -666,6 +666,10 @@ public class BalloonImpl implements Balloon, IdeTooltip.Ui {
}
}
public Component getComponent() {
return myComp;
}
private void createComponent() {
myComp = new MyComponent(myContent, this, myShadowBorderProvider != null ? null :
myShowPointer ? myPosition.createBorder(this) : getPointlessBorder());
@@ -27,6 +27,7 @@ import com.intellij.openapi.util.registry.Registry;
import com.intellij.openapi.wm.impl.IdeRootPane;
import com.intellij.openapi.wm.impl.ToolWindowsPane;
import com.intellij.util.Alarm;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.ui.JBInsets;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;
@@ -44,8 +45,7 @@ import java.util.List;
import java.util.Map;
public class BalloonLayoutImpl implements BalloonLayout {
private final JLayeredPane myLayeredPane;
protected final JLayeredPane myLayeredPane;
private final Insets myInsets;
private final List<Balloon> myBalloons = new ArrayList<Balloon>();
@@ -56,6 +56,7 @@ public class BalloonLayoutImpl implements BalloonLayout {
private final Runnable myRelayoutRunnable = new Runnable() {
public void run() {
relayout();
fireRelayout();
}
};
private final JRootPane myParent;
@@ -72,11 +73,14 @@ public class BalloonLayoutImpl implements BalloonLayout {
public void run() {
calculateSize();
relayout();
fireRelayout();
}
};
private LafManagerListener myLafListener;
private final List<Runnable> myListeners = new ArrayList<>();
public BalloonLayoutImpl(@NotNull JRootPane parent, @NotNull Insets insets) {
myParent = parent;
myLayeredPane = parent.getLayeredPane();
@@ -98,6 +102,26 @@ public class BalloonLayoutImpl implements BalloonLayout {
});
}
public void addListener(Runnable listener) {
myListeners.add(listener);
}
public void removeListener(Runnable listener) {
myListeners.remove(listener);
}
private void fireRelayout() {
for (Runnable listener : myListeners) {
listener.run();
}
}
@Nullable
public Component getTopBalloonComponent() {
BalloonImpl balloon = (BalloonImpl)ContainerUtil.getLastItem(myBalloons);
return balloon == null ? null : balloon.getComponent();
}
@Override
public void add(@NotNull Balloon balloon) {
add(balloon, null);
@@ -165,6 +189,7 @@ public class BalloonLayoutImpl implements BalloonLayout {
calculateSize();
relayout();
balloon.show(myLayeredPane);
fireRelayout();
}
@Nullable
@@ -208,6 +233,7 @@ public class BalloonLayoutImpl implements BalloonLayout {
private void remove(@NotNull Balloon balloon) {
remove(balloon, false);
balloon.hide(true);
fireRelayout();
}
private void remove(@NotNull Balloon balloon, boolean hide) {
@@ -220,6 +246,7 @@ public class BalloonLayoutImpl implements BalloonLayout {
}
if (hide) {
balloon.hide();
fireRelayout();
}
}