From 711615285eab05fb9c58cd5b016c6b3bf491aaf4 Mon Sep 17 00:00:00 2001 From: "Denis.Zhdanov" Date: Thu, 1 Nov 2012 15:00:03 +0400 Subject: [PATCH] IDEA-19061 Integrate the Rearranger-plugin into core-IDE Row index is located at the same baseline as condition text --- .../newui/ArrangementListRowDecorator.java | 16 +++++++++++++++- .../newui/ArrangementRuleIndexControl.java | 11 ++++++++--- .../newui/ArrangementSettingsPanel2.java | 1 - .../com/intellij/ui/SimpleColoredComponent.java | 2 +- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/newui/ArrangementListRowDecorator.java b/platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/newui/ArrangementListRowDecorator.java index 1e8300e76f0e..13d1deef5fb9 100644 --- a/platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/newui/ArrangementListRowDecorator.java +++ b/platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/newui/ArrangementListRowDecorator.java @@ -23,6 +23,7 @@ import com.intellij.openapi.actionSystem.Presentation; import com.intellij.openapi.actionSystem.impl.ActionButton; import com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchCondition; import com.intellij.ui.IdeBorderFactory; +import com.intellij.ui.SimpleColoredComponent; import com.intellij.util.ui.GridBag; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -67,13 +68,21 @@ public class ArrangementListRowDecorator extends JPanel implements ArrangementMa private void init() { setLayout(new GridBagLayout()); GridBag constraints = new GridBag().anchor(GridBagConstraints.CENTER) - .insets(0, ArrangementConstants.HORIZONTAL_PADDING, 0, ArrangementConstants.HORIZONTAL_PADDING * 3); + .insets(0, ArrangementConstants.HORIZONTAL_PADDING, 0, ArrangementConstants.HORIZONTAL_GAP * 2); add(myRowIndexControl, constraints); add(myDelegate.getUiComponent(), new GridBag().fillCellHorizontally().weightx(1).anchor(GridBagConstraints.WEST)); add(myEditButton, new GridBag().anchor(GridBagConstraints.EAST)); setBorder(IdeBorderFactory.createEmptyBorder(ArrangementConstants.VERTICAL_GAP)); } + @Override + protected void paintComponent(Graphics g) { + FontMetrics metrics = g.getFontMetrics(); + int baseLine = SimpleColoredComponent.getTextBaseLine(metrics, metrics.getHeight()); + myRowIndexControl.setBaseLine(baseLine + ArrangementConstants.VERTICAL_GAP + myDelegate.getUiComponent().getBounds().y - myRowIndexControl.getBounds().y); + super.paintComponent(g); + } + public void setRowIndex(int row) { myRowIndexControl.setIndex(row); } @@ -129,4 +138,9 @@ public class ArrangementListRowDecorator extends JPanel implements ArrangementMa public void onMouseExited() { myDelegate.onMouseExited(); } + + @Override + public String toString() { + return "list row decorator for " + myDelegate.toString(); + } } diff --git a/platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/newui/ArrangementRuleIndexControl.java b/platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/newui/ArrangementRuleIndexControl.java index 382555d0a7c0..8145f31a53a9 100644 --- a/platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/newui/ArrangementRuleIndexControl.java +++ b/platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/newui/ArrangementRuleIndexControl.java @@ -32,6 +32,7 @@ public class ArrangementRuleIndexControl extends JPanel { private int myIndex; private char[] myChars; private int myIndexWidth; + private int myBaseLine; public ArrangementRuleIndexControl(int diameter, int height) { myDiameter = diameter; @@ -77,9 +78,13 @@ public class ArrangementRuleIndexControl extends JPanel { g.setColor(UIUtil.getBorderColor()); Rectangle bounds = getBounds(); ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - g.drawOval(0, (bounds.height - myDiameter) / 2, myDiameter, myDiameter); + int y = Math.max(0, myBaseLine - myHeight - (myDiameter - myHeight) / 2); + g.drawOval(0, y, myDiameter, myDiameter); - int y = bounds.height - (bounds.height - myHeight) / 2; - g.drawChars(myChars, 0, myChars.length, (bounds.width - myIndexWidth) / 2, y); + g.drawChars(myChars, 0, myChars.length, (bounds.width - myIndexWidth) / 2, myBaseLine); + } + + public void setBaseLine(int baseLine) { + myBaseLine = baseLine; } } diff --git a/platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/newui/ArrangementSettingsPanel2.java b/platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/newui/ArrangementSettingsPanel2.java index d6634e7db7ab..fd156a80ac49 100644 --- a/platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/newui/ArrangementSettingsPanel2.java +++ b/platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/newui/ArrangementSettingsPanel2.java @@ -88,7 +88,6 @@ public abstract class ArrangementSettingsPanel2 extends CodeStyleAbstractPanel { @Nullable @Override protected EditorHighlighter createHighlighter(EditorColorsScheme scheme) { - // TODO den implement return null; } diff --git a/platform/platform-api/src/com/intellij/ui/SimpleColoredComponent.java b/platform/platform-api/src/com/intellij/ui/SimpleColoredComponent.java index 959e41c78255..a9cbdde8fea2 100644 --- a/platform/platform-api/src/com/intellij/ui/SimpleColoredComponent.java +++ b/platform/platform-api/src/com/intellij/ui/SimpleColoredComponent.java @@ -765,7 +765,7 @@ public class SimpleColoredComponent extends JComponent implements Accessible { myTransparentIconBackground = transparentIconBackground; } - private static int getTextBaseLine(FontMetrics metrics, final int height) { + public static int getTextBaseLine(FontMetrics metrics, final int height) { return (height - metrics.getHeight()) / 2 + metrics.getAscent(); }