From 64b12cc42149dfec9fd5f679ef475543c07c74aa Mon Sep 17 00:00:00 2001
From: Konstantin Bulenkov Factory class for creating panels of components. There are two different types of panels. 1) Component panel. It's essentially a this
- */
- ComponentPanelBuilder withLabel(@NotNull String labelText);
-
- /**
- * Move label on top of the owner component. Default position is on the left of the owner component.
- *
- * @return this
- */
- ComponentPanelBuilder moveLabelOnTop();
-
- /**
- * @param commentText help context styled text written below the owner component.
- *
- * @return this
- */
- ComponentPanelBuilder withComment(@NotNull String commentText);
-
- /**
- * Move comment to the right of the owner component. Default position is below the owner component.
- *
- * @return this
- */
- ComponentPanelBuilder moveCommentRight();
-
- /**
- * Enables the help tooltip icon on the right of the owner component and sets the description text for the tooltip.
- *
- * @param description help tooltip description.
- *
- * @return this
- */
- ComponentPanelBuilder withTooltip(@NotNull String description);
-
- /**
- * Sets optional help tooltip link and link action.
- *
- * @param linkText help tooltip link text.
- *
- * @param action help tooltip link action.
- *
- * @return this
- */
- ComponentPanelBuilder withTooltipLink(@NotNull String linkText, @NotNull Runnable action);
-}
diff --git a/platform/platform-api/src/com/intellij/openapi/ui/panel/JBPanelFactory.java b/platform/platform-api/src/com/intellij/openapi/ui/panel/JBPanelFactory.java
deleted file mode 100644
index 519ef88cb148..000000000000
--- a/platform/platform-api/src/com/intellij/openapi/ui/panel/JBPanelFactory.java
+++ /dev/null
@@ -1,98 +0,0 @@
-// Copyright 2000-2017 JetBrains s.r.o.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-package com.intellij.openapi.ui.panel;
-
-import com.intellij.openapi.components.ServiceManager;
-
-import javax.swing.*;
-
-/**
- * JComponent that can be decorated with:
- *
- *
- * For more information see {@link ComponentPanelBuilder}
2) ProgressBar panel. A panel containing JProgressBar that has specific layout
- * which is different from an arbitrary component panel. A progress bar panel can contain following items:
- *
Either of the mentioned panels can be grouped together in a grid. I.e. it's possible to create a grid of - * panels see {@link JBPanelFactory#grid()}. - * When using grid internal implementation makes sure all labels (if the are placed on the left) are located - * in the leftmost column and components/progress bars are in the second column expanding horizontally. - *
- * - *{@link PanelGridBuilder} has convenient {@link PanelGridBuilder#expandVertically()} method that allows rows to expand - * vertically when the grid is resized. By default all rows stick to the top of the grid and all available empty space is - * expanded below rows. - *
- * - *For concrete examples look ComponentPanelTestAction test action and class.
JComponent.
- * @param component is the central component
- *
- * @return a newly created instance of {@link ComponentPanelBuilder} for configuring the panel before
- * creation.
- */
- public static ComponentPanelBuilder panel(JComponent component) {
- return getInstance().createComponentPanelBuilder(component);
- }
-
- /**
- * Creates a panel builder for arbitrary JProgressBar.
- * @param progressBar is the central progressBar
- *
- * @return a newly created instance of {@link ProgressPanelBuilder} for configuring the panel before
- * creation.
- */
- public static ProgressPanelBuilder panel(JProgressBar progressBar) {
- return getInstance().createProgressPanelBuilder(progressBar);
- }
-
- /**
- * Creates a panel grid. Each grid should contain panels of the same type.
- *
- * @return a newly created {@link PanelGridBuilder}
- */
- public static PanelGridBuilder grid() {
- return getInstance().createPanelGridBuilder();
- }
-
- public abstract ComponentPanelBuilder createComponentPanelBuilder(JComponent component);
-
- public abstract ProgressPanelBuilder createProgressPanelBuilder(JProgressBar progressBar);
-
- public abstract PanelGridBuilder createPanelGridBuilder();
-}
diff --git a/platform/platform-api/src/com/intellij/openapi/ui/panel/PanelGridBuilder.java b/platform/platform-api/src/com/intellij/openapi/ui/panel/PanelGridBuilder.java
index 167373b8972e..cd86e94561b5 100644
--- a/platform/platform-api/src/com/intellij/openapi/ui/panel/PanelGridBuilder.java
+++ b/platform/platform-api/src/com/intellij/openapi/ui/panel/PanelGridBuilder.java
@@ -1,31 +1,27 @@
-// Copyright 2000-2017 JetBrains s.r.o.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
+// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.ui.panel;
+import com.intellij.util.ui.JBUI;
import org.jetbrains.annotations.NotNull;
-/**
- * Panel grid represents a series of panels of the same type laid out according to the
- * specific design specs (usually vertically).
- */
-public interface PanelGridBuilder extends PanelBuilder {
+import javax.swing.*;
+import java.awt.*;
+import java.util.ArrayList;
+import java.util.List;
+
+public class PanelGridBuilder implements PanelBuilder {
+ private boolean expand;
+ private final Listthis
*/
- PanelGridBuilder add(@NotNull PanelBuilder builder);
+ public PanelGridBuilder add(@NotNull PanelBuilder builder) {
+ builders.add((GridBagPanelBuilder)builder);
+ return this;
+ }
/**
* Turns on vertical resizing of grid rows when the panel is resized. Grid components
@@ -34,5 +30,41 @@ public interface PanelGridBuilder extends PanelBuilder {
*
* @return this
*/
- PanelGridBuilder expandVertically();
+ public PanelGridBuilder expandVertically() {
+ this.expand = true;
+ return this;
+ }
+
+
+ @NotNull
+ public JPanel createPanel() {
+ JPanel panel = new JPanel(new GridBagLayout());
+ GridBagConstraints gc = new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL,
+ null, 0, 0);
+
+ addToPanel(panel, gc);
+ return panel;
+ }
+
+ public boolean constrainsValid() {
+ return builders.stream().allMatch(b -> b.constrainsValid());
+ }
+
+ private int gridWidth() {
+ return builders.stream().map(b -> b.gridWidth()).max(Integer::compareTo).orElse(0);
+ }
+
+ private void addToPanel(JPanel panel, GridBagConstraints gc) {
+ builders.stream().filter(b -> b.constrainsValid()).forEach(b -> b.addToPanel(panel, gc));
+
+ if (!expand) {
+ gc.gridx = 0;
+ gc.anchor = GridBagConstraints.PAGE_END;
+ gc.fill = GridBagConstraints.BOTH;
+ gc.weighty = 1.0;
+ gc.insets = JBUI.insets(0);
+ gc.gridwidth = gridWidth();
+ panel.add(new JPanel(), gc);
+ }
+ }
}
diff --git a/platform/platform-api/src/com/intellij/openapi/ui/panel/ProgressPanelBuilder.java b/platform/platform-api/src/com/intellij/openapi/ui/panel/ProgressPanelBuilder.java
index 71de579da404..b606c4c3893b 100644
--- a/platform/platform-api/src/com/intellij/openapi/ui/panel/ProgressPanelBuilder.java
+++ b/platform/platform-api/src/com/intellij/openapi/ui/panel/ProgressPanelBuilder.java
@@ -1,98 +1,394 @@
-// Copyright 2000-2017 JetBrains s.r.o.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
+// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.ui.panel;
+import com.intellij.icons.AllIcons;
+import com.intellij.openapi.ui.popup.IconButton;
+import com.intellij.openapi.util.SystemInfo;
+import com.intellij.openapi.util.text.StringUtil;
+import com.intellij.ui.*;
+import com.intellij.util.ui.JBUI;
+import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;
-/**
- * Builder for standard progressbar panels.
- */
-public interface ProgressPanelBuilder extends PanelBuilder {
- /**
- * Set label text.
- *
- * @param text label text
- * @return this
- */
- ProgressPanelBuilder withLabel(@NotNull String text);
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+
+public class ProgressPanelBuilder implements GridBagPanelBuilder, PanelBuilder {
+ private static final Color SEPARATOR_COLOR = new JBColor(Gray.xC9, Gray.x55);
+
+ private final JProgressBar myProgressBar;
+ private String initialLabelText;
+ private boolean labelAbove = true;
+
+ private Runnable cancelAction;
+ private Runnable resumeAction;
+ private Runnable pauseAction;
+
+ private String cancelText = "Cancel";
+ private boolean cancelAsButton;
+ private boolean smallVariant;
+
+ private boolean commentEnabled = true;
+ private boolean topSeparatorEnabled;
+
+ private boolean valid = true;
+
+ public ProgressPanelBuilder(JProgressBar progressBar) {
+ myProgressBar = progressBar;
+ }
/**
- * Move comment to the left of the progress bar. Default position is above the progress bar.
- *
- * @return this
- */
- ProgressPanelBuilder moveLabelLeft();
+ * Set label text.
+ *
+ * @param text label text
+ * @return this
+ */
+ public ProgressPanelBuilder withLabel(@NotNull String text) {
+ initialLabelText = text;
+ return this;
+ }
/**
- * Enables cancel button and sets action for it. Can't coexist with play and pause actions.
- *
- * @param cancelAction Runnable action.
- * @return this
- */
- ProgressPanelBuilder withCancel(@NotNull Runnable cancelAction);
+ * Move comment to the left of the progress bar. Default position is above the progress bar.
+ *
+ * @return this
+ */
+ public ProgressPanelBuilder moveLabelLeft() {
+ labelAbove = false;
+ return this;
+ }
/**
- * Cancel button will look like an ordinary button rather than as icon. Default is icon styled cancel button.
- *
- * @return this
- */
- ProgressPanelBuilder andCancelAsButton();
+ * Enables cancel button and sets action for it. Can't coexist with play and pause actions.
+ *
+ * @param cancelAction Runnable action.
+ * @return this
+ */
+ public ProgressPanelBuilder withCancel(@NotNull Runnable cancelAction) {
+ this.cancelAction = cancelAction;
+ valid = resumeAction == null && pauseAction == null;
+ return this;
+ }
/**
- * If cancel button looks like a button (see {@link #andCancelAsButton()}) sets the text to be displayed on cancel button.
- * Otherwise sets the text to be displayed under the progressbar on mouse hover over the cancel icon.
- *
- * "Cancel" is the default text.
- *
- * @return this
- */
- ProgressPanelBuilder andCancelText(String cancelText);
+ * If cancel button looks like a button (see {@link #andCancelAsButton()}) sets the text to be displayed on cancel button.
+ * Otherwise sets the text to be displayed under the progressbar on mouse hover over the cancel icon.
+ *
+ * "Cancel" is the default text.
+ *
+ * @return this
+ */
+ public ProgressPanelBuilder andCancelText(String cancelText) {
+ this.cancelText = cancelText;
+ return this;
+ }
/**
- * Enables play button (icon styled) and sets action for it. Can't coexist with cancel action.
- *
- * @param playAction Runnable action.
- * @return this
- */
- ProgressPanelBuilder withResume(@NotNull Runnable playAction);
+ * Cancel button will look like an ordinary button rather than as icon. Default is icon styled cancel button.
+ *
+ * @return this
+ */
+ public ProgressPanelBuilder andCancelAsButton() {
+ this.cancelAsButton = true;
+ return this;
+ }
/**
- * Enables pause button (icon styled) and sets action for it. Can't coexist with cancel action.
- *
- * @param pauseAction Runnable action.
- * @return this
- */
- ProgressPanelBuilder withPause(@NotNull Runnable pauseAction);
+ * Enables play button (icon styled) and sets action for it. Can't coexist with cancel action.
+ *
+ * @param playAction Runnable action.
+ * @return this
+ */
+ public ProgressPanelBuilder withResume(@NotNull Runnable playAction) {
+ this.resumeAction = playAction;
+ valid = pauseAction != null && cancelAction == null;
+ return this;
+ }
/**
- * Switch to small icons version.
- *
- * @return this
- */
- ProgressPanelBuilder andSmallIcons();
+ * Enables pause button (icon styled) and sets action for it. Can't coexist with cancel action.
+ *
+ * @param pauseAction Runnable action.
+ * @return this
+ */
+ public ProgressPanelBuilder withPause(@NotNull Runnable pauseAction) {
+ this.pauseAction = pauseAction;
+ valid = resumeAction != null && cancelAction == null;
+ return this;
+ }
+
/**
- * Switch off the comment and don't reserve place for it in the layout. This makes overall panel height smaller.
- *
- * @return this
- */
- ProgressPanelBuilder withoutComment();
+ * Switch to small icons version.
+ *
+ * @return this
+ */
+ public ProgressPanelBuilder andSmallIcons() {
+ this.smallVariant = true;
+ return this;
+ }
/**
- * Enable separator on top of the panel.
- *
- * @return this
- */
- ProgressPanelBuilder withTopSeparator();
+ * Switch off the comment and don't reserve place for it in the layout. This makes overall panel height smaller.
+ *
+ * @return this
+ */
+ public ProgressPanelBuilder withoutComment() {
+ this.commentEnabled = false;
+ return this;
+ }
+
+ /**
+ * Enable separator on top of the panel.
+ *
+ * @return this
+ */
+ public ProgressPanelBuilder withTopSeparator() {
+ this.topSeparatorEnabled = true;
+ return this;
+ }
+
+ @Override
+ @NotNull
+ public JPanel createPanel() {
+ JPanel panel = new JPanel(new GridBagLayout());
+ GridBagConstraints gc = new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL,
+ null, 0, 0);
+ addToPanel(panel, gc);
+ return panel;
+ }
+
+ @Override
+ public boolean constrainsValid() {
+ return valid;
+ }
+
+ @Override
+ public void addToPanel(JPanel panel, GridBagConstraints gc) {
+ if (constrainsValid()) {
+ new LabeledPanelImpl().addToPanel(panel, gc);
+ }
+ }
+
+ @Override
+ public int gridWidth() {
+ int width = labelAbove ? 1 : 2;
+ width += (cancelAction != null || resumeAction != null && pauseAction != null) ? 1 : 0;
+ return width;
+ }
+
+ private class LabeledPanelImpl extends ProgressPanel {
+ private final JLabel label;
+ private final JLabel comment;
+
+ private String myCommentText = emptyComment();
+ private boolean myServiceComment = false;
+
+ private InplaceButton button;
+ private IconButton cancelIcon;
+ private IconButton resumeIcon;
+ private IconButton pauseIcon;
+
+ private SeparatorComponent mySeparatorComponent = new SeparatorComponent(SEPARATOR_COLOR, SeparatorOrientation.HORIZONTAL);
+
+ private State state = State.PLAYING;
+
+ private LabeledPanelImpl() {
+ label = new JLabel(StringUtil.isNotEmpty(initialLabelText) ? initialLabelText : "");
+
+ comment = new JLabel(myCommentText);
+ comment.setForeground(Gray.x78);
+ if (SystemInfo.isMac) {
+ Font font = comment.getFont();
+ float size = font.getSize2D();
+ Font smallFont = font.deriveFont(size - 2.0f);
+ comment.setFont(smallFont);
+ }
+
+ if (StringUtil.isNotEmpty(initialLabelText)) {
+ Dimension size = comment.getPreferredSize();
+ size.width = label.getMinimumSize().width;
+ comment.setMinimumSize(size);
+ }
+
+ cancelIcon = new IconButton(null,
+ smallVariant ? AllIcons.Process.StopSmall : AllIcons.Process.Stop,
+ smallVariant ? AllIcons.Process.StopSmallHovered : AllIcons.Process.StopHovered);
+ resumeIcon = new IconButton(null,
+ smallVariant ? AllIcons.Process.ProgressResumeSmall : AllIcons.Process.ProgressResume,
+ smallVariant ? AllIcons.Process.ProgressResumeSmallHover : AllIcons.Process.ProgressResumeHover);
+ pauseIcon = new IconButton(null,
+ smallVariant ? AllIcons.Process.ProgressPauseSmall : AllIcons.Process.ProgressPause,
+ smallVariant ? AllIcons.Process.ProgressPauseSmallHover : AllIcons.Process.ProgressPauseHover);
+ }
+
+ private String emptyComment() {
+ return commentEnabled ? " " : "";
+ }
+
+ @Override
+ public String getLabelText() {
+ return label.getText();
+ }
+
+ @Override
+ public void setLabelText(String labelText) {
+ label.setText(StringUtil.isNotEmpty(labelText) ? labelText : "");
+
+ if (StringUtil.isNotEmpty(labelText)) {
+ Dimension size = comment.getPreferredSize();
+ size.width = label.getMinimumSize().width;
+ comment.setMinimumSize(size);
+ }
+ }
+
+ @Override
+ public String getCommentText() {
+ return myServiceComment ? myCommentText : comment.getText();
+ }
+
+ @Override
+ public void setCommentText(String commentText) {
+ if (commentEnabled) {
+ setCommentText(commentText, false);
+ }
+ }
+
+ @Override
+ public void setSeparatorEnabled(boolean enabled) {
+ mySeparatorComponent.setVisible(enabled);
+ }
+
+ private void setCommentText(String commentText, boolean serviceComment) {
+ if (serviceComment) {
+ myServiceComment = commentText != null;
+ comment.setText(commentText == null ? myCommentText : commentText);
+ }
+ else if (!myServiceComment) {
+ myCommentText = StringUtil.isNotEmpty(commentText) ? commentText : emptyComment();
+ comment.setText(myCommentText);
+ }
+ }
+
+ @Override
+ public State getState() {
+ return state;
+ }
+
+ void addToPanel(JPanel panel, GridBagConstraints gc) {
+ gc.gridx = 0;
+ gc.anchor = GridBagConstraints.LINE_START;
+ gc.fill = GridBagConstraints.HORIZONTAL;
+
+ if (topSeparatorEnabled) {
+ gc.insets = JBUI.insets(14, 0, 10, 0);
+ gc.gridwidth = gridWidth();
+ gc.weightx = 1.0;
+ panel.add(mySeparatorComponent, gc);
+ gc.gridy++;
+ }
+
+ gc.weightx = 0.0;
+ gc.gridwidth = 1;
+ gc.insets = JBUI.insets(topSeparatorEnabled || smallVariant ? 0 : 12, 13, 0, labelAbove ? 13 : 0);
+ panel.add(label, gc);
+
+ if (labelAbove) {
+ gc.insets = JBUI.insets(4, 13, 4, 0);
+ gc.gridy++;
+ }
+ else {
+ gc.insets = JBUI.insets(topSeparatorEnabled || smallVariant ? 2 : 14, 12, 0, 0);
+ gc.gridx++;
+ }
+
+ gc.weightx = 1.0;
+ panel.add(myProgressBar, gc);
+ gc.gridx++;
+
+ myProgressBar.putClientProperty(LABELED_PANEL_PROPERTY, this);
+
+ gc.weightx = 0.0;
+ gc.insets = JBUI.insets(labelAbove || topSeparatorEnabled || smallVariant ? 1 : 14,
+ UIUtil.isUnderWin10LookAndFeel() ? 9 : 10,
+ 0, 13);
+
+ if (cancelAction != null) {
+ if (cancelAsButton) {
+ JButton cancelButton = new JButton(cancelText);
+ cancelButton.addActionListener((e) -> cancelAction.run());
+ panel.add(cancelButton, gc);
+ }
+ else {
+ button = new InplaceButton(cancelIcon, a -> {
+ button.setPainting(false);
+ state = State.CANCELLED;
+ cancelAction.run();
+ }).setFillBg(false);
+ }
+ }
+ else if (resumeAction != null && pauseAction != null) {
+ button = new InplaceButton(pauseIcon, a -> {
+ if (state == State.PLAYING) {
+ button.setIcons(resumeIcon);
+ state = State.PAUSED;
+ setCommentText("Paused", true);
+ pauseAction.run();
+ }
+ else {
+ button.setIcons(pauseIcon);
+ state = State.PLAYING;
+ setCommentText("Pause", true);
+ resumeAction.run();
+ }
+ }).setFillBg(false);
+ }
+
+ if (button != null) {
+ button.setMinimumSize(button.getPreferredSize());
+
+ if (commentEnabled) {
+ button.addMouseListener(new HoverListener());
+ }
+
+ gc.anchor = GridBagConstraints.EAST;
+ gc.fill = GridBagConstraints.NONE;
+ panel.add(button, gc);
+ }
+
+ if (commentEnabled) {
+ gc.gridy++;
+ gc.gridx = labelAbove ? 0 : 1;
+ gc.insets = labelAbove ? JBUI.insets(-1, 13, 0, 13) : JBUI.insets(-1, 12, 0, 13);
+ gc.weightx = 1.0;
+ gc.anchor = GridBagConstraints.LINE_START;
+ gc.fill = GridBagConstraints.HORIZONTAL;
+ panel.add(comment, gc);
+ }
+
+ gc.gridy++;
+ }
+
+ private class HoverListener extends MouseAdapter {
+ @Override
+ public void mouseEntered(MouseEvent e) {
+ if (cancelAction != null) {
+ setCommentText(cancelText, true);
+ }
+ else if (resumeAction != null && pauseAction != null) {
+ setCommentText(state == State.PLAYING ? "Pause" : "Resume", true);
+ }
+ else {
+ setCommentText(null, true);
+ }
+ }
+
+ @Override
+ public void mouseExited(MouseEvent e) {
+ setCommentText(state != State.PAUSED ? null : "Paused", true);
+ }
+ }
+ }
}
diff --git a/platform/platform-impl/src/com/intellij/ide/actions/project/convertModuleGroupsToQualifiedNames.kt b/platform/platform-impl/src/com/intellij/ide/actions/project/convertModuleGroupsToQualifiedNames.kt
index 6fe6d12f8c25..6bf8e4d9b5b1 100644
--- a/platform/platform-impl/src/com/intellij/ide/actions/project/convertModuleGroupsToQualifiedNames.kt
+++ b/platform/platform-impl/src/com/intellij/ide/actions/project/convertModuleGroupsToQualifiedNames.kt
@@ -1,6 +1,4 @@
-/*
- * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
- */
+// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.ide.actions.project
import com.intellij.CommonBundle
@@ -29,7 +27,6 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.project.ProjectBundle
import com.intellij.openapi.ui.DialogWrapper
import com.intellij.openapi.ui.Messages
-import com.intellij.openapi.ui.panel.JBPanelFactory
import com.intellij.openapi.util.text.StringUtil
import com.intellij.psi.PsiDocumentManager
import com.intellij.ui.*
@@ -98,7 +95,7 @@ class ConvertModuleGroupsToQualifiedNamesDialog(val project: Project) : DialogWr
override fun createCenterPanel(): JPanel {
val text = XmlStringUtil.wrapInHtml(ProjectBundle.message("convert.module.groups.description.text"))
- val recordPreviousNames = JBPanelFactory.panel(recordPreviousNamesCheckBox)
+ val recordPreviousNames = com.intellij.util.ui.UI.PanelFactory.panel(recordPreviousNamesCheckBox)
.withTooltip(ProjectBundle.message("convert.module.groups.record.previous.names.tooltip",
ApplicationNamesInfo.getInstance().fullProductName)).createPanel()
return JBUI.Panels.simplePanel(0, UIUtil.DEFAULT_VGAP)
diff --git a/platform/platform-impl/src/com/intellij/internal/inspector/UiInspectorAction.java b/platform/platform-impl/src/com/intellij/internal/inspector/UiInspectorAction.java
index a9ac8387d208..c291dfffdd73 100644
--- a/platform/platform-impl/src/com/intellij/internal/inspector/UiInspectorAction.java
+++ b/platform/platform-impl/src/com/intellij/internal/inspector/UiInspectorAction.java
@@ -1,4 +1,4 @@
-// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.internal.inspector;
import com.google.common.base.MoreObjects;
@@ -22,6 +22,7 @@ import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.ui.*;
+import com.intellij.ui.UI;
import com.intellij.ui.border.CustomLineBorder;
import com.intellij.ui.components.JBScrollPane;
import com.intellij.ui.components.JBTextField;
diff --git a/platform/platform-impl/src/com/intellij/internal/ui/ComponentPanelTestAction.java b/platform/platform-impl/src/com/intellij/internal/ui/ComponentPanelTestAction.java
index 13fcf1f94cfe..4beb5d535aa3 100644
--- a/platform/platform-impl/src/com/intellij/internal/ui/ComponentPanelTestAction.java
+++ b/platform/platform-impl/src/com/intellij/internal/ui/ComponentPanelTestAction.java
@@ -1,4 +1,4 @@
-// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.internal.ui;
import com.intellij.openapi.actionSystem.ActionManager;
@@ -8,7 +8,6 @@ import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.ComponentWithBrowseButton;
import com.intellij.openapi.ui.DialogWrapper;
-import com.intellij.openapi.ui.panel.JBPanelFactory;
import com.intellij.openapi.ui.panel.ProgressPanel;
import com.intellij.openapi.wm.IdeFocusManager;
import com.intellij.ui.ComboboxWithBrowseButton;
@@ -21,6 +20,7 @@ import com.intellij.ui.tabs.impl.JBEditorTabs;
import com.intellij.util.Alarm;
import com.intellij.util.ObjectUtils;
import com.intellij.util.ui.JBUI;
+import com.intellij.util.ui.UI;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.Nullable;
@@ -90,26 +90,26 @@ public class ComponentPanelTestAction extends DumbAwareAction {
Dimension d = text.getPreferredSize();
text.setPreferredSize(new Dimension(JBUI.scale(100), d.height));
- panel.add(JBPanelFactory.panel(text).
+ panel.add(UI.PanelFactory.panel(text).
withLabel("&Textfield:").
withComment("Textfield description").
moveCommentRight().createPanel());
- panel.add(JBPanelFactory.panel(new JTextField()).
+ panel.add(UI.PanelFactory.panel(new JTextField()).
withLabel("&Path:").createPanel());
- panel.add(JBPanelFactory.panel(new JCheckBox("This is a checkbox 1")).
+ panel.add(UI.PanelFactory.panel(new JCheckBox("This is a checkbox 1")).
withComment("My long long long long long long long long long long comment").
createPanel());
- panel.add(JBPanelFactory.panel(new JCheckBox("This is a checkbox 2")).
+ panel.add(UI.PanelFactory.panel(new JCheckBox("This is a checkbox 2")).
withTooltip("Help tooltip description").createPanel());
- panel.add(JBPanelFactory.panel(new JButton("Abracadabra")).
+ panel.add(UI.PanelFactory.panel(new JButton("Abracadabra")).
withComment("Abradabra comment").createPanel());
String[] items = new String[]{ "One", "Two", "Three", "Four", "Five", "Six" };
- panel.add(JBPanelFactory.panel(new JComboBox<>(items)).
+ panel.add(UI.PanelFactory.panel(new JComboBox<>(items)).
withComment("Combobox comment").createPanel());
String[] columns = { "First column", "Second column" };
@@ -130,7 +130,7 @@ public class ComponentPanelTestAction extends DumbAwareAction {
pane.setPreferredSize(JBUI.size(200, 100));
pane.putClientProperty(UIUtil.KEEP_BORDER_SIDES, SideBorder.ALL);
- panel.add(JBPanelFactory.panel(pane).
+ panel.add(UI.PanelFactory.panel(pane).
withLabel("Table label:").moveLabelOnTop().withComment("Table comment").createPanel());
panel.add(new Box.Filler(JBUI.size(100,20), JBUI.size(200,30), JBUI.size(Integer.MAX_VALUE, Integer.MAX_VALUE)));
@@ -144,26 +144,26 @@ public class ComponentPanelTestAction extends DumbAwareAction {
JBScrollPane pane = new JBScrollPane(new JTextArea(3, 40));
pane.putClientProperty(UIUtil.KEEP_BORDER_SIDES, SideBorder.ALL);
- JPanel p1 = JBPanelFactory.grid().
- add(JBPanelFactory.panel(new JTextField()).
+ JPanel p1 = UI.PanelFactory.grid().
+ add(UI.PanelFactory.panel(new JTextField()).
withLabel("&Port:").withComment("Port comment")).
- add(JBPanelFactory.panel(new JTextField()).
+ add(UI.PanelFactory.panel(new JTextField()).
withLabel("&Host:").withComment("Host comment")).
- add(JBPanelFactory.panel(new JComboBox<>(new String[]{"HTTP", "HTTPS", "FTP", "SSL"})).
+ add(UI.PanelFactory.panel(new JComboBox<>(new String[]{"HTTP", "HTTPS", "FTP", "SSL"})).
withLabel("P&rotocol:").withComment("Protocol comment").withTooltip("Protocol selection").
withTooltipLink("Check here for more info", ()-> System.out.println("More info"))).
- add(JBPanelFactory.panel(new ComponentWithBrowseButton<>(new JTextField(), (e) -> System.out.println("Browse for text"))).
+ add(UI.PanelFactory.panel(new ComponentWithBrowseButton<>(new JTextField(), (e) -> System.out.println("Browse for text"))).
withLabel("&Text field:").withComment("Text field comment")).
- add(JBPanelFactory.panel(cbb).
+ add(UI.PanelFactory.panel(cbb).
withLabel("&Combobox selection:")).
- add(JBPanelFactory.panel(new JCheckBox("Checkbox")).withComment("Checkbox comment text")).
+ add(UI.PanelFactory.panel(new JCheckBox("Checkbox")).withComment("Checkbox comment text")).
- add(JBPanelFactory.panel(pane).
+ add(UI.PanelFactory.panel(pane).
withLabel("Text area:").withComment("Text area comment").moveLabelOnTop()).
createPanel();
@@ -177,14 +177,14 @@ public class ComponentPanelTestAction extends DumbAwareAction {
bg.add(rb3);
rb1.setSelected(true);
- JPanel p2 = JBPanelFactory.grid().
- add(JBPanelFactory.panel(new JCheckBox("Checkbox 1")).withComment("Comment 1").moveCommentRight()).
- add(JBPanelFactory.panel(new JCheckBox("Checkbox 2")).withComment("Comment 2")).
- add(JBPanelFactory.panel(new JCheckBox("Checkbox 3")).withTooltip("Checkbox tooltip")).
+ JPanel p2 = UI.PanelFactory.grid().
+ add(UI.PanelFactory.panel(new JCheckBox("Checkbox 1")).withComment("Comment 1").moveCommentRight()).
+ add(UI.PanelFactory.panel(new JCheckBox("Checkbox 2")).withComment("Comment 2")).
+ add(UI.PanelFactory.panel(new JCheckBox("Checkbox 3")).withTooltip("Checkbox tooltip")).
- add(JBPanelFactory.panel(rb1).withComment("Comment 1").moveCommentRight()).
- add(JBPanelFactory.panel(rb2).withComment("Comment 2")).
- add(JBPanelFactory.panel(rb3).withTooltip("RadioButton tooltip")).
+ add(UI.PanelFactory.panel(rb1).withComment("Comment 1").moveCommentRight()).
+ add(UI.PanelFactory.panel(rb2).withComment("Comment 2")).
+ add(UI.PanelFactory.panel(rb3).withTooltip("RadioButton tooltip")).
createPanel();
@@ -242,12 +242,12 @@ public class ComponentPanelTestAction extends DumbAwareAction {
progressPanel.setCommentText(Integer.toString(0));
}
- panel.add(JBPanelFactory.grid().
- add(JBPanelFactory.panel(pb1).
+ panel.add(UI.PanelFactory.grid().
+ add(UI.PanelFactory.panel(pb1).
withLabel("Label 1.1").
withCancel(()-> myAlarm.cancelRequest(timerRequest)).
andCancelText("Stop")).
- add(JBPanelFactory.panel(pb2).
+ add(UI.PanelFactory.panel(pb2).
withLabel("Label 1.2").
withPause(()-> System.out.println("Pause action #2")).
withResume(()-> System.out.println("Resume action #2"))).
@@ -259,11 +259,11 @@ public class ComponentPanelTestAction extends DumbAwareAction {
JProgressBar pb3 = new JProgressBar(0, 100);
JProgressBar pb4 = new JProgressBar(0, 100);
- panel.add(JBPanelFactory.grid().
- add(JBPanelFactory.panel(pb3).
+ panel.add(UI.PanelFactory.grid().
+ add(UI.PanelFactory.panel(pb3).
withLabel("Label 2.1").moveLabelLeft().
withCancel(()-> System.out.println("Cancel action #3"))).
- add(JBPanelFactory.panel(pb4).
+ add(UI.PanelFactory.panel(pb4).
withTopSeparator().
withLabel("Label 2.2").moveLabelLeft().
withPause(()-> System.out.println("Pause action #4")).
@@ -274,8 +274,8 @@ public class ComponentPanelTestAction extends DumbAwareAction {
ObjectUtils.assertNotNull(ProgressPanel.forComponent(pb3)).setCommentText("Long long long long long long text");
ObjectUtils.assertNotNull(ProgressPanel.forComponent(pb4)).setCommentText("Short text");
- panel.add(JBPanelFactory.grid().
- add(JBPanelFactory.panel(new JProgressBar(0, 100)).
+ panel.add(UI.PanelFactory.grid().
+ add(UI.PanelFactory.panel(new JProgressBar(0, 100)).
withTopSeparator().withoutComment().
andCancelAsButton().
withCancel(()-> System.out.println("Cancel action #11"))).
diff --git a/platform/platform-impl/src/com/intellij/ui/panel/ComponentPanelBuilderImpl.java b/platform/platform-impl/src/com/intellij/ui/panel/ComponentPanelBuilder.java
similarity index 83%
rename from platform/platform-impl/src/com/intellij/ui/panel/ComponentPanelBuilderImpl.java
rename to platform/platform-impl/src/com/intellij/ui/panel/ComponentPanelBuilder.java
index 36625e263632..0cd4850765b6 100644
--- a/platform/platform-impl/src/com/intellij/ui/panel/ComponentPanelBuilderImpl.java
+++ b/platform/platform-impl/src/com/intellij/ui/panel/ComponentPanelBuilder.java
@@ -1,9 +1,8 @@
-// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.ui.panel;
import com.intellij.openapi.ui.ComponentWithBrowseButton;
import com.intellij.openapi.ui.LabeledComponent;
-import com.intellij.openapi.ui.panel.ComponentPanelBuilder;
import com.intellij.openapi.ui.panel.GridBagPanelBuilder;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.text.StringUtil;
@@ -17,7 +16,7 @@ import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.awt.*;
-public class ComponentPanelBuilderImpl implements ComponentPanelBuilder, GridBagPanelBuilder {
+public class ComponentPanelBuilder implements GridBagPanelBuilder {
private final JComponent myComponent;
@@ -30,43 +29,62 @@ public class ComponentPanelBuilderImpl implements ComponentPanelBuilder, GridBag
private Runnable myHTAction;
private boolean valid = true;
- ComponentPanelBuilderImpl(JComponent component) {
+ public ComponentPanelBuilder(JComponent component) {
myComponent = component;
}
- @Override
+ /**
+ * @param labelText text for the label.
+ * @return this
+ */
public ComponentPanelBuilder withLabel(@NotNull String labelText) {
myLabelText = labelText;
return this;
}
- @Override
+ /**
+ * Move label on top of the owner component. Default position is on the left of the owner component.
+ *
+ * @return this
+ */
public ComponentPanelBuilder moveLabelOnTop() {
myLabelOnTop = true;
return this;
}
- @Override
+ /**
+ * @param comment help context styled text written below the owner component.
+ * @return this
+ */
public ComponentPanelBuilder withComment(@NotNull String comment) {
myComment = comment;
valid = StringUtil.isNotEmpty(comment) && StringUtil.isEmpty(myHTDescription);
return this;
}
- @Override
+ /**
+ * Move comment to the right of the owner component. Default position is below the owner component.
+ *
+ * @return this
+ */
public ComponentPanelBuilder moveCommentRight() {
myCommentBelow = false;
return this;
}
- @Override
+ /**
+ * Enables the help tooltip icon on the right of the owner component and sets the description text for the tooltip.
+ *
+ * @param description help tooltip description.
+ * @return this
+ */
public ComponentPanelBuilder withTooltip(@NotNull String description) {
myHTDescription = description;
valid = StringUtil.isNotEmpty(description) && StringUtil.isEmpty(myComment);
return this;
}
- @Override
+
public ComponentPanelBuilder withTooltipLink(@NotNull String linkText, @NotNull Runnable action) {
myHTLinkText = linkText;
myHTAction = action;
@@ -171,7 +189,7 @@ public class ComponentPanelBuilderImpl implements ComponentPanelBuilder, GridBag
if (myComponent instanceof JRadioButton || myComponent instanceof JCheckBox) {
return isMacDefault ? 8 : 13;
}
- else if (myComponent instanceof JTextField || myComponent instanceof EditorTextField ||
+ else if (myComponent instanceof JTextField || myComponent instanceof EditorTextField ||//todo[kirill.kirichenko] provide markup interface for EditorTextField in platform-api
myComponent instanceof JComboBox || myComponent instanceof ComponentWithBrowseButton) {
return isMacDefault ? 13 : 14;
} else {
@@ -189,7 +207,7 @@ public class ComponentPanelBuilderImpl implements ComponentPanelBuilder, GridBag
left = isMacDefault ? 27 : isWin10 ? 17 : 24;
bottom = isWin10 ? 10 : isMacDefault ? 8 : 9;
}
- else if (myComponent instanceof JTextField || myComponent instanceof EditorTextField ||
+ else if (myComponent instanceof JTextField || myComponent instanceof EditorTextField || //todo[kirill.kirichenko] provide markup interface for EditorTextField in platform-api
myComponent instanceof JComboBox || myComponent instanceof ComponentWithBrowseButton) {
top = isWin10 ? 3 : 4;
left = isWin10 ? 2 : isMacDefault ? 5 : 4;
diff --git a/platform/platform-impl/src/com/intellij/ui/panel/PanelFactoryImpl.java b/platform/platform-impl/src/com/intellij/ui/panel/PanelFactoryImpl.java
deleted file mode 100644
index f2c737ea8567..000000000000
--- a/platform/platform-impl/src/com/intellij/ui/panel/PanelFactoryImpl.java
+++ /dev/null
@@ -1,26 +0,0 @@
-// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
-package com.intellij.ui.panel;
-
-import com.intellij.openapi.ui.panel.ComponentPanelBuilder;
-import com.intellij.openapi.ui.panel.JBPanelFactory;
-import com.intellij.openapi.ui.panel.PanelGridBuilder;
-import com.intellij.openapi.ui.panel.ProgressPanelBuilder;
-
-import javax.swing.*;
-
-public class PanelFactoryImpl extends JBPanelFactory {
- @Override
- public ComponentPanelBuilder createComponentPanelBuilder(JComponent component) {
- return new ComponentPanelBuilderImpl(component);
- }
-
- @Override
- public ProgressPanelBuilder createProgressPanelBuilder(JProgressBar progressBar) {
- return new ProgressPanelBuilderImpl(progressBar);
- }
-
- @Override
- public PanelGridBuilder createPanelGridBuilder() {
- return new PanelGridBuilderImpl();
- }
-}
diff --git a/platform/platform-impl/src/com/intellij/ui/panel/PanelGridBuilderImpl.java b/platform/platform-impl/src/com/intellij/ui/panel/PanelGridBuilderImpl.java
deleted file mode 100644
index d6a8a0ade3b8..000000000000
--- a/platform/platform-impl/src/com/intellij/ui/panel/PanelGridBuilderImpl.java
+++ /dev/null
@@ -1,64 +0,0 @@
-// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
-package com.intellij.ui.panel;
-
-import com.intellij.openapi.ui.panel.GridBagPanelBuilder;
-import com.intellij.openapi.ui.panel.PanelBuilder;
-import com.intellij.openapi.ui.panel.PanelGridBuilder;
-import com.intellij.util.ui.JBUI;
-import org.jetbrains.annotations.NotNull;
-
-import javax.swing.*;
-import java.awt.*;
-import java.util.ArrayList;
-import java.util.List;
-
-public class PanelGridBuilderImpl implements PanelGridBuilder {
- private boolean expand;
- private final ListJComponent.
+ *
+ * @param component is the central component
+ * @return a newly created instance of {@link ComponentPanelBuilder} for configuring the panel before
+ * creation.
+ */
+ public static ComponentPanelBuilder panel(JComponent component) {
+ return new ComponentPanelBuilder(component);
+ }
+
+ /**
+ * Creates a panel builder for arbitrary JProgressBar.
+ *
+ * @param progressBar is the central progressBar
+ * @return a newly created instance of {@link ProgressPanelBuilder} for configuring the panel before
+ * creation.
+ */
+ public static ProgressPanelBuilder panel(JProgressBar progressBar) {
+ return new ProgressPanelBuilder(progressBar);
+ }
+
+ /**
+ * Creates a panel grid. Each grid should contain panels of the same type.
+ *
+ * @return a newly created {@link PanelGridBuilder}
+ */
+ public static PanelGridBuilder grid() {
+ return new PanelGridBuilder();
+ }
+ }
+}
diff --git a/platform/platform-resources/src/META-INF/PlatformExtensions.xml b/platform/platform-resources/src/META-INF/PlatformExtensions.xml
index 2534f2bbeb9c..70d4bf0b21f6 100644
--- a/platform/platform-resources/src/META-INF/PlatformExtensions.xml
+++ b/platform/platform-resources/src/META-INF/PlatformExtensions.xml
@@ -58,8 +58,6 @@
serviceImplementation="com.intellij.ide.CopyPasteManagerEx"/>