From a4c17eef83b8598a24b01374f0c02574131f2964 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Wed, 29 Dec 2010 15:06:49 +0300 Subject: [PATCH] error sign instead of error border --- platform/icons/src/ide/errorPoint.png | Bin 0 -> 182 bytes platform/icons/src/ide/errorSign.png | Bin 0 -> 705 bytes .../intellij/openapi/ui/DialogWrapper.java | 152 +++++++++--------- 3 files changed, 78 insertions(+), 74 deletions(-) create mode 100644 platform/icons/src/ide/errorPoint.png create mode 100644 platform/icons/src/ide/errorSign.png diff --git a/platform/icons/src/ide/errorPoint.png b/platform/icons/src/ide/errorPoint.png new file mode 100644 index 0000000000000000000000000000000000000000..2a08c2ff37638f81adeca12044cc4d2abcd651c1 GIT binary patch literal 182 zcmeAS@N?(olHy`uVBq!ia0vp^Y#_`5A|IT2?*XJ((j9#r85q`|FlX(03FJ$bxJHx& z=ckpFCl;kLIHu$$r7C#lCZ?wbr6#6S7M@JC0V?wFba4!+xRvzh`~ign2M#1~A34S& zP$1U9&&(pg9dep!U}5IsWRTr_oVQ`~HdH@8^#Ue}PVC_yxp2zcVm@{>s4k2I%!qpBZF- z{Q-rWDoh_h0Ko$h6ksfW|1$o5_W>A^K>YbT!~fUM7#RQlVPO3Ai-F<$X9k9E-x=6H z|6yd{VvvC80|+3v0pEb3&F~ed@fQoj|M%}0Sb#P&zIX)W{{jaj!?!;S41a+5KO;)4 z0R#}-0HCrLzhAu+W8h?GWO?y|f%)rq28MU985n*8W&ZvJ(m+Lj{xkf9MB59PK7as% z8}O6y|LqsIZfVKLOR_S31Zo5Z+|#repvfRxL7@dCSQ!}}v;6}KFx-ae0|+1_0~pR< zxp>2n_t$p?p+7&F8GwG5e((b<_f(7-?1Hzy|Np(l$^c3O=VAH)0th7`0pnLel7}-y zlap0}>G@Yy_MiX2wu7jD+>F1kG5>$?g5f_(LIMaNM)b@CO(cfUsDg#|3#hZt12v;0 nWq<%;q%=1I1Q5l!5g@<-DCX!c)C^G+00000NkvXXu0mjfNX|Cu literal 0 HcmV?d00001 diff --git a/platform/platform-api/src/com/intellij/openapi/ui/DialogWrapper.java b/platform/platform-api/src/com/intellij/openapi/ui/DialogWrapper.java index 7c1ff707c62e..1a9a6810b74e 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/DialogWrapper.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/DialogWrapper.java @@ -25,6 +25,8 @@ import com.intellij.openapi.help.HelpManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.popup.StackingPopupDispatcher; import com.intellij.openapi.util.*; +import com.intellij.openapi.wm.IdeGlassPaneUtil; +import com.intellij.openapi.wm.impl.content.GraphicsConfig; import com.intellij.ui.IdeBorderFactory; import com.intellij.ui.UIBundle; import com.intellij.util.Alarm; @@ -33,6 +35,7 @@ import com.intellij.util.ui.AwtVisitor; import com.intellij.util.ui.DialogUtil; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; @@ -193,11 +196,11 @@ public abstract class DialogWrapper { //validation private final Alarm myValidationAlarm = new Alarm(myDisposable); private int myValidationDelay = 300; - private static final String OLD_BORDER = "OLD_BORDER"; - private JComponent myLastErrorComponent = null; private boolean myDisposed = false; - private Boolean myLastPaintButtonBorder = null; private boolean myValidationStarted = false; + private Icon ERROR_POINT = IconLoader.getIcon("/ide/errorPoint.png"); + private Icon ERROR_SIGN = IconLoader.getIcon("/ide/errorSign.png"); + private final ErrorPainter myErrorPainter = new ErrorPainter(); /** * Allows to postpone first start of validation @@ -219,80 +222,30 @@ public abstract class DialogWrapper { return null; } - /** - * Controls components highlighting - * - * @return true for problem components highlighting. false otherwise. - */ - protected boolean isShowErrorBorder() { - return true; - } - - /** - * Specifies border color for error highlighting - * - * @return color for error highlighting - */ - protected Color getErrorColor() { - return Color.RED; - } - public void setValidationDelay(int delay) { myValidationDelay = delay; } - private void reportProblem(final String message, final JComponent comp) { + private void reportProblem(final ValidationInfo info) { + myErrorPainter.setValidationInfo(info); + if (! info.message.equals(myErrorText.myLabel.getText())) { SwingUtilities.invokeLater(new Runnable() { public void run() { - if (myDisposed) return; - if (isShowErrorBorder()) { - if (myLastErrorComponent != comp) { - if (myLastErrorComponent != null) { - myLastErrorComponent.setBorder((Border)myLastErrorComponent.getClientProperty(OLD_BORDER)); - if (myLastErrorComponent instanceof AbstractButton && myLastPaintButtonBorder != null) { - ((AbstractButton)myLastErrorComponent).setBorderPainted(myLastPaintButtonBorder); - } - } - myLastErrorComponent = comp; - if (comp != null) { - if (comp instanceof AbstractButton) { - myLastPaintButtonBorder = ((AbstractButton)comp).isBorderPainted(); - ((AbstractButton)comp).setBorderPainted(true); - } - final Object border = comp.getClientProperty(OLD_BORDER); - if (border == null) { - comp.putClientProperty(OLD_BORDER, comp.getBorder()); - } - comp.setBorder(BorderFactory.createLineBorder(getErrorColor(), 1)); - } - } - } - setErrorText(message); + setErrorText(info.message); + myPeer.getRootPane().getGlassPane().repaint(); getOKAction().setEnabled(false); } - }); } - + } private void clearProblems() { + myErrorPainter.setValidationInfo(null); SwingUtilities.invokeLater(new Runnable() { public void run() { - if (myDisposed) return; setErrorText(null); + myPeer.getRootPane().getGlassPane().repaint(); getOKAction().setEnabled(true); - //if (myLastPeerSize != null) { - // myPeer.setSize(myLastPeerSize.width, myLastPeerSize.height); - // myLastPeerSize = null; - //} - if (myLastErrorComponent != null) { - myLastErrorComponent.setBorder((Border)myLastErrorComponent.getClientProperty(OLD_BORDER)); - if (myLastPaintButtonBorder != null && myLastErrorComponent instanceof AbstractButton) { - ((AbstractButton)myLastErrorComponent).setBorderPainted(myLastPaintButtonBorder); - } - myLastErrorComponent = null; - myLastPaintButtonBorder = null; - } } }); } @@ -924,7 +877,9 @@ public abstract class DialogWrapper { final JComponent c = createCenterPanel(); if (c != null) { - centerSection.add(wrap(c, isCenterStrictedToPreferredSize()), BorderLayout.CENTER); + final JComponent wrap = wrap(c, isCenterStrictedToPreferredSize()); + centerSection.add(wrap, BorderLayout.CENTER); + IdeGlassPaneUtil.installPainter(wrap, myErrorPainter, myDisposable); } final JPanel southSection = new JPanel(new BorderLayout()); @@ -961,7 +916,7 @@ public abstract class DialogWrapper { if (result == null) { clearProblems(); } else { - reportProblem(result.message, result.component); + reportProblem(result); } if (!myDisposed) { @@ -971,17 +926,6 @@ public abstract class DialogWrapper { }, myValidationDelay, ModalityState.current()); } - public static final class ValidationInfo { - public final String message; - public final JComponent component; - - public ValidationInfo(String message, JComponent component) { - this.message = message; - this.component = component; - } - } - - private static JComponent wrap(final JComponent c, boolean strict) { if (!strict) return c; @@ -1521,4 +1465,64 @@ public abstract class DialogWrapper { String getDoNotShowMessage(); } + + private ErrorPaintingType getErrorPaintingType() { + return ErrorPaintingType.SIGN; + } + + private class ErrorPainter extends AbstractPainter { + private ValidationInfo myInfo; + + @Override + public void executePaint(Component component, Graphics2D g) { + if (myInfo != null && myInfo.component != null) { + final JComponent comp = myInfo.component; + final int w = comp.getWidth(); + final int h = comp.getHeight(); + Point p; + switch (getErrorPaintingType()) { + case DOT: + p = SwingUtilities.convertPoint(comp, 2, h/2 , component); + ERROR_POINT.paintIcon(component, g, p.x, p.y); + break; + case SIGN: + p = SwingUtilities.convertPoint(comp, w, 0, component); + ERROR_SIGN.paintIcon(component, g, p.x - 8, p.y - 8); + break; + case LINE: + p = SwingUtilities.convertPoint(comp, 0, h, component); + final GraphicsConfig config = new GraphicsConfig(g); + g.setColor(new Color(255, 0, 0 , 100)); + g.fillRoundRect(p.x, p.y-2, w, 4, 2, 2); + config.restore(); + break; + } + } + } + + @Override + public boolean needsRepaint() { + return true; + } + + public void setValidationInfo(ValidationInfo info) { + myInfo = info; + } + } + + private static enum ErrorPaintingType {DOT, SIGN, LINE} + + public static final class ValidationInfo { + public final String message; + public final JComponent component; + + public ValidationInfo(@NotNull String message, JComponent component) { + this.message = message; + this.component = component; + } + + public ValidationInfo(@NotNull String message) { + this(message, null); + } + } }