From 1eaaff7b1ce37949acdbcb8e863dc4092df48ef5 Mon Sep 17 00:00:00 2001 From: Vassiliy Date: Mon, 28 Oct 2013 17:50:52 +0400 Subject: [PATCH] Lens improvements --- .../openapi/ui/popup/BalloonBuilder.java | 3 + .../src/com/intellij/ide/IdeTooltip.java | 10 +++ .../com/intellij/ide/IdeTooltipManager.java | 1 + .../editor/impl/EditorMarkupModelImpl.java | 83 ++++++++++--------- .../src/com/intellij/ui/BalloonImpl.java | 30 ++++--- .../src/com/intellij/ui/HintHint.java | 13 ++- .../src/com/intellij/ui/LightweightHint.java | 1 + .../ui/popup/BalloonPopupBuilderImpl.java | 9 +- .../testSrc/com/intellij/ui/BalloonTest.java | 2 +- 9 files changed, 100 insertions(+), 52 deletions(-) diff --git a/platform/platform-api/src/com/intellij/openapi/ui/popup/BalloonBuilder.java b/platform/platform-api/src/com/intellij/openapi/ui/popup/BalloonBuilder.java index b72cc37ead17..b460350b1257 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/popup/BalloonBuilder.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/popup/BalloonBuilder.java @@ -34,6 +34,9 @@ public interface BalloonBuilder { @NotNull BalloonBuilder setBorderColor(@NotNull Color color); + @NotNull + BalloonBuilder setBorderInsets(@Nullable Insets insets); + @NotNull BalloonBuilder setFillColor(@NotNull Color color); diff --git a/platform/platform-impl/src/com/intellij/ide/IdeTooltip.java b/platform/platform-impl/src/com/intellij/ide/IdeTooltip.java index 44224ed6f10e..ee0c9ceadac8 100644 --- a/platform/platform-impl/src/com/intellij/ide/IdeTooltip.java +++ b/platform/platform-impl/src/com/intellij/ide/IdeTooltip.java @@ -40,6 +40,7 @@ public class IdeTooltip extends ComparableObject.Impl { private Color myTextBackground; private Color myTextForeground; private Color myBorderColor; + private Insets myBorderInsets; private Font myFont; private int myCalloutShift = 4; @@ -159,6 +160,11 @@ public class IdeTooltip extends ComparableObject.Impl { myBorderColor = borderColor; return this; } + public IdeTooltip setBorderInsets(Insets insets) { + myBorderInsets = insets; + return this; + } + public Color getTextBackground() { return myTextBackground; @@ -176,6 +182,10 @@ public class IdeTooltip extends ComparableObject.Impl { return myBorderColor; } + public Insets getBorderInsets() { + return myBorderInsets; + } + public IdeTooltip setFont(Font font) { myFont = font; return this; diff --git a/platform/platform-impl/src/com/intellij/ide/IdeTooltipManager.java b/platform/platform-impl/src/com/intellij/ide/IdeTooltipManager.java index f6f266c02b36..53a5918451e0 100644 --- a/platform/platform-impl/src/com/intellij/ide/IdeTooltipManager.java +++ b/platform/platform-impl/src/com/intellij/ide/IdeTooltipManager.java @@ -302,6 +302,7 @@ public class IdeTooltipManager implements ApplicationComponent, AWTEventListener BalloonBuilder builder = myPopupFactory.createBalloonBuilder(tooltip.getTipComponent()) .setFillColor(bg) .setBorderColor(border) + .setBorderInsets(tooltip.getBorderInsets()) .setAnimationCycle(animationEnabled ? Registry.intValue("ide.tooltip.animationCycle") : 0) .setShowCallout(true) .setCalloutShift(small && tooltip.getCalloutShift() == 0 ? 2 : tooltip.getCalloutShift()) diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorMarkupModelImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorMarkupModelImpl.java index c8183ff91ebe..03a72ec2cb37 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorMarkupModelImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorMarkupModelImpl.java @@ -66,6 +66,7 @@ import java.awt.event.*; import java.awt.geom.AffineTransform; import java.awt.geom.Area; import java.awt.geom.Ellipse2D; +import java.awt.geom.RoundRectangle2D; import java.awt.image.BufferedImage; import java.util.*; import java.util.List; @@ -182,8 +183,7 @@ public class EditorMarkupModelImpl extends MarkupModelImpl implements EditorMark e.isPopupTrigger()); bigRenderer = myTooltipRendererProvider.calcTooltipRenderer(highlighters); if (bigRenderer != null) { - HintHint hint = new HintHint(me).setAwtTooltip(true).setPreferredPosition(Balloon.Position.atLeft).setShowImmediately(true).setAnimationEnabled(false); - showTooltip(me, bigRenderer, hint); + showTooltip(me, bigRenderer, createHint(me)); return true; } return false; @@ -197,13 +197,16 @@ public class EditorMarkupModelImpl extends MarkupModelImpl implements EditorMark visualLine, highlighters); myEditorFragmentRenderer.update(visualLine, highlighters, me.isAltDown()); - HintHint hint = new HintHint(me).setAwtTooltip(true).setPreferredPosition(Balloon.Position.atLeft).setShowImmediately(true) - .setAnimationEnabled(false); - myEditorFragmentRenderer.show(myEditor, me.getPoint(), true, ERROR_STRIPE_TOOLTIP_GROUP, hint); + myEditorFragmentRenderer.show(myEditor, me.getPoint(), true, ERROR_STRIPE_TOOLTIP_GROUP, createHint(me)); return true; } } + private static HintHint createHint(MouseEvent me) { + return new HintHint(me).setAwtTooltip(true).setPreferredPosition(Balloon.Position.atLeft).setBorderInsets(new Insets(1, 1, 1, 1)) + .setShowImmediately(true).setAnimationEnabled(false); + } + private int getVisualLineByEvent(MouseEvent e) { return fitLineToEditor(myEditor.offsetToVisualLine(yPositionToOffset(e.getY() + myWheelAccumulator, true))); } @@ -1192,28 +1195,34 @@ public class EditorMarkupModelImpl extends MarkupModelImpl implements EditorMark } isDirty = false; } - UIUtil.drawImage(g, myCacheLevel1, 0, 0, this); - if (UIUtil.isUnderDarcula()) { - //Add glass effect - GraphicsUtil.setupAAPainting(g); - Shape s = new Rectangle(0, 0, size.width, size.height); - Graphics2D g2 = (Graphics2D)g; - double cx = size.width / 2; - double cy = 0; - double rx = size.width / 10; - int ry = myEditor.getLineHeight() * 3 / 2; - g2.setPaint(new GradientPaint(0, 0, new Color(255, 255, 255, 135), 0, ry, new Color(255, 255, 255, 40))); - double pseudoMajorAxis = size.width - rx * 9 / 5; - Shape topShape1 = new Ellipse2D.Double(cx - rx - pseudoMajorAxis / 2, cy - ry, 2 * rx, 2 * ry); - Shape topShape2 = new Ellipse2D.Double(cx - rx + pseudoMajorAxis / 2, cy - ry, 2 * rx, 2 * ry); - Area topArea = new Area(topShape1); - topArea.add(new Area(topShape2)); - topArea.add(new Area(new Rectangle.Double(cx - pseudoMajorAxis / 2, cy, pseudoMajorAxis, ry))); - g2.fill(topArea); - Area bottomArea = new Area(s); - bottomArea.subtract(topArea); - g2.setPaint(new GradientPaint(0, size.height - ry, new Color(0, 0, 0, 10), 0, size.height, new Color(255, 255, 255, 30))); - g2.fill(bottomArea); + Graphics2D g2 = (Graphics2D)g.create(); + try { + GraphicsUtil.setupAAPainting(g2); + g2.setClip(new RoundRectangle2D.Double(0, 0, size.width-.5, size.height-.5, 2, 2)); + UIUtil.drawImage(g2, myCacheLevel1, 0, 0, this); + if (UIUtil.isUnderDarcula()) { + //Add glass effect + Shape s = new Rectangle(0, 0, size.width, size.height); + double cx = size.width / 2; + double cy = 0; + double rx = size.width / 10; + int ry = myEditor.getLineHeight() * 3 / 2; + g2.setPaint(new GradientPaint(0, 0, new Color(255, 255, 255, 75), 0, ry, new Color(255, 255, 255, 10))); + double pseudoMajorAxis = size.width - rx * 9 / 5; + Shape topShape1 = new Ellipse2D.Double(cx - rx - pseudoMajorAxis / 2, cy - ry, 2 * rx, 2 * ry); + Shape topShape2 = new Ellipse2D.Double(cx - rx + pseudoMajorAxis / 2, cy - ry, 2 * rx, 2 * ry); + Area topArea = new Area(topShape1); + topArea.add(new Area(topShape2)); + topArea.add(new Area(new Rectangle.Double(cx - pseudoMajorAxis / 2, cy, pseudoMajorAxis, ry))); + g2.fill(topArea); + Area bottomArea = new Area(s); + bottomArea.subtract(topArea); + g2.setPaint(new GradientPaint(0, size.height - ry, new Color(0, 0, 0, 10), 0, size.height, new Color(255, 255, 255, 30))); + g2.fill(bottomArea); + } + } + finally { + g2.dispose(); } } }; @@ -1246,25 +1255,21 @@ public class EditorMarkupModelImpl extends MarkupModelImpl implements EditorMark @Override public void run() { if (myEditorPreviewHint == null || !myDelayed) return; - hintManager.showEditorHint(myEditorPreviewHint, myEditor, myPointHolder.get(), HintManager.HIDE_BY_ANY_KEY | - HintManager.HIDE_BY_TEXT_CHANGE | - HintManager.HIDE_BY_MOUSEOVER | - HintManager.HIDE_BY_ESCAPE | - HintManager.HIDE_BY_SCROLLING, 0, false, - myHintHolder.get()); + showEditorHint(hintManager, myPointHolder.get(), myHintHolder.get()); myDelayed = false; } }, Registry.intValue("ide.tooltip.initialDelay")); } else if (!myDelayed) { - hintManager.showEditorHint(myEditorPreviewHint, myEditor, point, HintManager.HIDE_BY_ANY_KEY | - HintManager.HIDE_BY_TEXT_CHANGE | - HintManager.HIDE_BY_MOUSEOVER | - HintManager.HIDE_BY_ESCAPE | - HintManager.HIDE_BY_SCROLLING, 0, false, - hintInfo); + showEditorHint(hintManager, point, hintInfo); } return myEditorPreviewHint; } + + private void showEditorHint(HintManagerImpl hintManager, Point point, HintHint hintInfo) { + int flags = HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_MOUSEOVER | + HintManager.HIDE_BY_ESCAPE | HintManager.HIDE_BY_SCROLLING; + hintManager.showEditorHint(myEditorPreviewHint, myEditor, point, flags, 0, false, hintInfo); + } } } diff --git a/platform/platform-impl/src/com/intellij/ui/BalloonImpl.java b/platform/platform-impl/src/com/intellij/ui/BalloonImpl.java index 6534dd6cadb7..e658729072e9 100644 --- a/platform/platform-impl/src/com/intellij/ui/BalloonImpl.java +++ b/platform/platform-impl/src/com/intellij/ui/BalloonImpl.java @@ -89,6 +89,7 @@ public class BalloonImpl implements Balloon, IdeTooltip.Ui, SwingConstants { private final boolean myHideOnLinkClick; private final Color myBorderColor; + private final Insets myBorderInsets; private final Color myFillColor; private final Insets myContainerInsets; @@ -238,6 +239,7 @@ public class BalloonImpl implements Balloon, IdeTooltip.Ui, SwingConstants { public BalloonImpl(JComponent content, Color borderColor, + Insets borderInsets, Color fillColor, boolean hideOnMouse, boolean hideOnKey, @@ -261,6 +263,7 @@ public class BalloonImpl implements Balloon, IdeTooltip.Ui, SwingConstants { boolean blockClicks, Layer layer) { myBorderColor = borderColor; + myBorderInsets = borderInsets != null ? borderInsets : new Insets(3, 3, 3, 3); myFillColor = fillColor; myContent = content; myHideOnMouse = hideOnMouse; @@ -378,6 +381,9 @@ public class BalloonImpl implements Balloon, IdeTooltip.Ui, SwingConstants { show(tracker, pos); } + private Insets getInsetsCopy() { + return new Insets(myBorderInsets.top, myBorderInsets.left, myBorderInsets.bottom, myBorderInsets.right); + } private void show(RelativePoint target, AbstractPosition position) { show(new PositionTracker.Static(target), position); @@ -628,8 +634,8 @@ public class BalloonImpl implements Balloon, IdeTooltip.Ui, SwingConstants { } - private static EmptyBorder getPointlessBorder() { - return new EmptyBorder(getNormalInset(), getNormalInset(), getNormalInset(), getNormalInset()); + private EmptyBorder getPointlessBorder() { + return new EmptyBorder(myBorderInsets); } public void revalidate() { @@ -1023,8 +1029,9 @@ public class BalloonImpl implements Balloon, IdeTooltip.Ui, SwingConstants { } EmptyBorder createBorder(final BalloonImpl balloon) { - final int inset = getNormalInset(); - return new EmptyBorder(balloon.getPointerLength(this) + inset, inset, inset, inset); + Insets insets = balloon.getInsetsCopy(); + insets.top += balloon.getPointerLength(this); + return new EmptyBorder(insets); } @Override @@ -1076,8 +1083,9 @@ public class BalloonImpl implements Balloon, IdeTooltip.Ui, SwingConstants { } EmptyBorder createBorder(final BalloonImpl balloon) { - final int inset = getNormalInset(); - return new EmptyBorder(inset, inset, balloon.getPointerLength(this), inset); + Insets insets = balloon.getInsetsCopy(); + insets.bottom = balloon.getPointerLength(this); + return new EmptyBorder(insets); } @Override @@ -1131,8 +1139,9 @@ public class BalloonImpl implements Balloon, IdeTooltip.Ui, SwingConstants { } EmptyBorder createBorder(final BalloonImpl balloon) { - final int inset = getNormalInset(); - return new EmptyBorder(inset, balloon.getPointerLength(this) + inset, inset, inset); + Insets insets = balloon.getInsetsCopy(); + insets.left += balloon.getPointerLength(this); + return new EmptyBorder(insets); } @Override @@ -1185,8 +1194,9 @@ public class BalloonImpl implements Balloon, IdeTooltip.Ui, SwingConstants { } EmptyBorder createBorder(final BalloonImpl balloon) { - final int inset = getNormalInset(); - return new EmptyBorder(inset, inset, inset, balloon.getPointerLength(this) + inset); + Insets insets = balloon.getInsetsCopy(); + insets.right += balloon.getPointerLength(this); + return new EmptyBorder(insets); } @Override diff --git a/platform/platform-impl/src/com/intellij/ui/HintHint.java b/platform/platform-impl/src/com/intellij/ui/HintHint.java index 26d2fd75e940..8969a5bca8c5 100644 --- a/platform/platform-impl/src/com/intellij/ui/HintHint.java +++ b/platform/platform-impl/src/com/intellij/ui/HintHint.java @@ -41,10 +41,11 @@ public class HintHint { private Color myTextFg; private Color myTextBg; private Color myBorderColor; + private Insets myBorderInsets; private Font myFont; private int myCalloutShift; - private boolean myExplicitClose; + private boolean myExplicitClose; private int myPositionChangeX; private int myPositionChangeY; private boolean myShowImmediately = false; @@ -125,6 +126,10 @@ public class HintHint { return myBorderColor != null ? myBorderColor : getTooltipManager().getBorderColor(myAwtTooltip); } + public Insets getBorderInsets() { + return myBorderInsets; + } + public boolean isOpaqueAllowed() { return getTooltipManager().isOpaqueAllowed(myAwtTooltip); } @@ -215,6 +220,12 @@ public class HintHint { return this; } + public HintHint setBorderInsets(Insets insets) { + myBorderInsets = insets; + return this; + } + + public int getCalloutShift() { return myCalloutShift; } diff --git a/platform/platform-impl/src/com/intellij/ui/LightweightHint.java b/platform/platform-impl/src/com/intellij/ui/LightweightHint.java index e8cac7864e97..2f4841f13236 100644 --- a/platform/platform-impl/src/com/intellij/ui/LightweightHint.java +++ b/platform/platform-impl/src/com/intellij/ui/LightweightHint.java @@ -171,6 +171,7 @@ public class LightweightHint extends UserDataHolderBase implements Hint { .setTextForeground(hintHint.getTextForeground()) .setTextBackground(hintHint.getTextBackground()) .setBorderColor(hintHint.getBorderColor()) + .setBorderInsets(hintHint.getBorderInsets()) .setFont(hintHint.getTextFont()) .setCalloutShift(hintHint.getCalloutShift()) .setPositionChangeShift(hintHint.getPositionChangeX(), hintHint.getPositionChangeY()) diff --git a/platform/platform-impl/src/com/intellij/ui/popup/BalloonPopupBuilderImpl.java b/platform/platform-impl/src/com/intellij/ui/popup/BalloonPopupBuilderImpl.java index 74c7086c9543..c721abc13cd2 100644 --- a/platform/platform-impl/src/com/intellij/ui/popup/BalloonPopupBuilderImpl.java +++ b/platform/platform-impl/src/com/intellij/ui/popup/BalloonPopupBuilderImpl.java @@ -42,6 +42,7 @@ public class BalloonPopupBuilderImpl implements BalloonBuilder { private JComponent myContent; private Color myBorder = new JBColor(JBColor.GRAY, Gray._200); + @Nullable private Insets myBorderInsets = null; private Color myFill = MessageType.INFO.getPopupBackground(); private boolean myHideOnMouseOutside = true; private boolean myHideOnKeyOutside = true; @@ -105,6 +106,12 @@ public class BalloonPopupBuilderImpl implements BalloonBuilder { return this; } + @Override + public BalloonBuilder setBorderInsets(@Nullable Insets insets) { + myBorderInsets = insets; + return this; + } + @NotNull @Override public BalloonBuilder setFillColor(@NotNull final Color color) { @@ -250,7 +257,7 @@ public class BalloonPopupBuilderImpl implements BalloonBuilder { @Override public Balloon createBalloon() { final BalloonImpl result = new BalloonImpl( - myContent, myBorder, myFill, myHideOnMouseOutside, myHideOnKeyOutside, myHideOnAction, myShowCallout, myCloseButtonEnabled, + myContent, myBorder, myBorderInsets, myFill, myHideOnMouseOutside, myHideOnKeyOutside, myHideOnAction, myShowCallout, myCloseButtonEnabled, myFadeoutTime, myHideOnFrameResize, myHideOnLinkClick, myClickHandler, myCloseOnClick, myAnimationCycle, myCalloutShift, myPositionChangeXShift, myPositionChangeYShift, myDialogMode, myTitle, myContentInsets, myShadow, mySmallVariant, myBlockClicks, myLayer); diff --git a/platform/platform-tests/testSrc/com/intellij/ui/BalloonTest.java b/platform/platform-tests/testSrc/com/intellij/ui/BalloonTest.java index 7e1d5ad88509..e240bb0cbd41 100644 --- a/platform/platform-tests/testSrc/com/intellij/ui/BalloonTest.java +++ b/platform/platform-tests/testSrc/com/intellij/ui/BalloonTest.java @@ -59,7 +59,7 @@ public class BalloonTest { //pane.setBorder(new LineBorder(Color.blue)); balloon.set(new BalloonImpl( - new JLabel("Content"), Color.black, MessageType.ERROR.getPopupBackground(), true, true, true, true, true, 0, true, false, null, + new JLabel("Content"), Color.black, null , MessageType.ERROR.getPopupBackground(), true, true, true, true, true, 0, true, false, null, false, 500, 25, 0, 0, false, "This is the title", new Insets(2, 2, 2, 2), true, false, false, Balloon.Layer.normal)); balloon.get().setShowPointer(true);