mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
remove factory classes and interfaces for Panel Builders
This commit is contained in:
+8
-10
@@ -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.codeInsight.daemon.impl.quickfix;
|
||||
|
||||
import com.intellij.codeInsight.daemon.QuickFixBundle;
|
||||
@@ -14,7 +12,6 @@ import com.intellij.openapi.module.impl.scopes.ModulesScope;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.ComboBoxWithWidePopup;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.ui.panel.JBPanelFactory;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
|
||||
@@ -22,6 +19,7 @@ import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.ui.components.JBRadioButton;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import com.intellij.util.ui.UI;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -196,14 +194,14 @@ public class CreateServiceImplementationClassFix extends CreateServiceClassFixBa
|
||||
@Nullable
|
||||
@Override
|
||||
protected JComponent createNorthPanel() {
|
||||
JPanel radioButtons = JBPanelFactory.grid()
|
||||
.add(JBPanelFactory.panel(mySubclassButton))
|
||||
.add(JBPanelFactory.panel(myProviderButton))
|
||||
JPanel radioButtons = UI.PanelFactory.grid()
|
||||
.add(UI.PanelFactory.panel(mySubclassButton))
|
||||
.add(UI.PanelFactory.panel(myProviderButton))
|
||||
.createPanel();
|
||||
|
||||
return JBPanelFactory.grid()
|
||||
.add(JBPanelFactory.panel(radioButtons).withLabel("Implementation:"))
|
||||
.add(JBPanelFactory.panel(myRootDirCombo).withLabel("Source root:"))
|
||||
return UI.PanelFactory.grid()
|
||||
.add(UI.PanelFactory.panel(radioButtons).withLabel("Implementation:"))
|
||||
.add(UI.PanelFactory.panel(myRootDirCombo).withLabel("Source root:"))
|
||||
.createPanel();
|
||||
}
|
||||
|
||||
|
||||
+7
-9
@@ -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.codeInsight.daemon.impl.quickfix;
|
||||
|
||||
import com.intellij.codeInsight.daemon.QuickFixBundle;
|
||||
@@ -13,7 +11,6 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.ProjectFileIndex;
|
||||
import com.intellij.openapi.ui.ComboBoxWithWidePopup;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.ui.panel.JBPanelFactory;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
@@ -22,6 +19,7 @@ import com.intellij.ui.ListCellRendererWrapper;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.PlatformIcons;
|
||||
import com.intellij.util.ui.UI;
|
||||
import one.util.streamex.StreamEx;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -194,11 +192,11 @@ public class CreateServiceInterfaceOrClassFix extends CreateServiceClassFixBase
|
||||
protected JComponent createNorthPanel() {
|
||||
JTextField nameTextField = new JTextField(myInterfaceName);
|
||||
nameTextField.setEditable(false);
|
||||
return JBPanelFactory.grid()
|
||||
.add(JBPanelFactory.panel(nameTextField).withLabel("Name:"))
|
||||
.add(JBPanelFactory.panel(myModuleCombo).withLabel("Module:"))
|
||||
.add(JBPanelFactory.panel(myRootDirCombo).withLabel("Source root:"))
|
||||
.add(JBPanelFactory.panel(myKindCombo).withLabel("Kind:"))
|
||||
return UI.PanelFactory.grid()
|
||||
.add(UI.PanelFactory.panel(nameTextField).withLabel("Name:"))
|
||||
.add(UI.PanelFactory.panel(myModuleCombo).withLabel("Module:"))
|
||||
.add(UI.PanelFactory.panel(myRootDirCombo).withLabel("Source root:"))
|
||||
.add(UI.PanelFactory.panel(myKindCombo).withLabel("Kind:"))
|
||||
.createPanel();
|
||||
}
|
||||
|
||||
|
||||
+6
-8
@@ -1,6 +1,4 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
// 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.codeInsight.intention.impl;
|
||||
|
||||
import com.intellij.codeInsight.daemon.impl.quickfix.CreateClassKind;
|
||||
@@ -18,7 +16,6 @@ import com.intellij.openapi.roots.JavaProjectRootsUtil;
|
||||
import com.intellij.openapi.ui.ComboBoxWithWidePopup;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.ui.ValidationInfo;
|
||||
import com.intellij.openapi.ui.panel.JBPanelFactory;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
@@ -29,6 +26,7 @@ import com.intellij.refactoring.util.CommonRefactoringUtil;
|
||||
import com.intellij.ui.components.JBTextField;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.PlatformIcons;
|
||||
import com.intellij.util.ui.UI;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -174,11 +172,11 @@ public class CreateClassInPackageInModuleFix implements IntentionAction {
|
||||
@Nullable
|
||||
@Override
|
||||
protected JComponent createNorthPanel() {
|
||||
return JBPanelFactory.grid()
|
||||
.add(JBPanelFactory.panel(myNameTextField).withLabel("Name:")
|
||||
return UI.PanelFactory.grid()
|
||||
.add(UI.PanelFactory.panel(myNameTextField).withLabel("Name:")
|
||||
.withComment("The class will be created in the package '" + myPackageName + "'"))
|
||||
.add(JBPanelFactory.panel(myRootDirCombo).withLabel("Source root:"))
|
||||
.add(JBPanelFactory.panel(myKindCombo).withLabel("Kind:"))
|
||||
.add(UI.PanelFactory.panel(myRootDirCombo).withLabel("Source root:"))
|
||||
.add(UI.PanelFactory.panel(myKindCombo).withLabel("Kind:"))
|
||||
.createPanel();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,67 +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 org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface ComponentPanelBuilder extends PanelBuilder {
|
||||
|
||||
/**
|
||||
* @param labelText text for the label.
|
||||
*
|
||||
* @return <code>this</code>
|
||||
*/
|
||||
ComponentPanelBuilder withLabel(@NotNull String labelText);
|
||||
|
||||
/**
|
||||
* Move label on top of the owner component. Default position is on the left of the owner component.
|
||||
*
|
||||
* @return <code>this</code>
|
||||
*/
|
||||
ComponentPanelBuilder moveLabelOnTop();
|
||||
|
||||
/**
|
||||
* @param commentText help context styled text written below the owner component.
|
||||
*
|
||||
* @return <code>this</code>
|
||||
*/
|
||||
ComponentPanelBuilder withComment(@NotNull String commentText);
|
||||
|
||||
/**
|
||||
* Move comment to the right of the owner component. Default position is below the owner component.
|
||||
*
|
||||
* @return <code>this</code>
|
||||
*/
|
||||
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 <code>this</code>
|
||||
*/
|
||||
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 <code>this</code>
|
||||
*/
|
||||
ComponentPanelBuilder withTooltipLink(@NotNull String linkText, @NotNull Runnable action);
|
||||
}
|
||||
@@ -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.*;
|
||||
|
||||
/**
|
||||
* <p>Factory class for creating panels of components. There are two different types of panels.</p>
|
||||
*
|
||||
* <p>1) Component panel. It's essentially a <code>JComponent</code> that can be decorated with:
|
||||
* <ul>
|
||||
* <li> a label that's located on the right of the component</li>
|
||||
* <li> a help context label that's located on the left or below of the component</li>
|
||||
* <li> an icon with a question mark that show a popup with more information which is show on the left</li>
|
||||
* </ul>
|
||||
* For more information see {@link ComponentPanelBuilder}</p>
|
||||
*
|
||||
* <p>2) ProgressBar panel. A panel containing <code>JProgressBar</code> that has specific layout
|
||||
* which is different from an arbitrary component panel. A progress bar panel can contain following items:
|
||||
* <ul>
|
||||
* <li> a label that' located above or on the left of the progress bar</li>
|
||||
* <li> a comment label that's located below the progress bar</li>
|
||||
* <li> Cancel, Play, Pause buttons with assignable actions</li>
|
||||
* </ul>
|
||||
* For more information see {@link ProgressPanelBuilder}</p>
|
||||
*
|
||||
* <p>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.
|
||||
* </p>
|
||||
*
|
||||
* <p>{@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.
|
||||
* </p>
|
||||
*
|
||||
* <p>For concrete examples look <code>ComponentPanelTestAction</code> test action and class.</p>
|
||||
*/
|
||||
|
||||
public abstract class JBPanelFactory {
|
||||
/**
|
||||
* @return the popup factory instance.
|
||||
*/
|
||||
public static JBPanelFactory getInstance() {
|
||||
return ServiceManager.getService(JBPanelFactory.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a panel builder for arbitrary <code>JComponent</code>.
|
||||
* @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 <code>JProgressBar</code>.
|
||||
* @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();
|
||||
}
|
||||
@@ -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 List<GridBagPanelBuilder> builders = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Adds a single panel builder to grid.
|
||||
* @param builder single row panel builder
|
||||
* @return <code>this</code>
|
||||
*/
|
||||
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 <code>this</code>
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+371
-75
@@ -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 <code>this</code>
|
||||
*/
|
||||
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 <code>this</code>
|
||||
*/
|
||||
ProgressPanelBuilder moveLabelLeft();
|
||||
* Set label text.
|
||||
*
|
||||
* @param text label text
|
||||
* @return <code>this</code>
|
||||
*/
|
||||
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 <code>Runnable</code> action.
|
||||
* @return <code>this</code>
|
||||
*/
|
||||
ProgressPanelBuilder withCancel(@NotNull Runnable cancelAction);
|
||||
* Move comment to the left of the progress bar. Default position is above the progress bar.
|
||||
*
|
||||
* @return <code>this</code>
|
||||
*/
|
||||
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 <code>this</code>
|
||||
*/
|
||||
ProgressPanelBuilder andCancelAsButton();
|
||||
* Enables cancel button and sets action for it. Can't coexist with play and pause actions.
|
||||
*
|
||||
* @param cancelAction <code>Runnable</code> action.
|
||||
* @return <code>this</code>
|
||||
*/
|
||||
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 <code>this</code>
|
||||
*/
|
||||
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 <code>this</code>
|
||||
*/
|
||||
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 <code>Runnable</code> action.
|
||||
* @return <code>this</code>
|
||||
*/
|
||||
ProgressPanelBuilder withResume(@NotNull Runnable playAction);
|
||||
* Cancel button will look like an ordinary button rather than as icon. Default is icon styled cancel button.
|
||||
*
|
||||
* @return <code>this</code>
|
||||
*/
|
||||
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 <code>Runnable</code> action.
|
||||
* @return <code>this</code>
|
||||
*/
|
||||
ProgressPanelBuilder withPause(@NotNull Runnable pauseAction);
|
||||
* Enables play button (icon styled) and sets action for it. Can't coexist with cancel action.
|
||||
*
|
||||
* @param playAction <code>Runnable</code> action.
|
||||
* @return <code>this</code>
|
||||
*/
|
||||
public ProgressPanelBuilder withResume(@NotNull Runnable playAction) {
|
||||
this.resumeAction = playAction;
|
||||
valid = pauseAction != null && cancelAction == null;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Switch to small icons version.
|
||||
*
|
||||
* @return <code>this</code>
|
||||
*/
|
||||
ProgressPanelBuilder andSmallIcons();
|
||||
* Enables pause button (icon styled) and sets action for it. Can't coexist with cancel action.
|
||||
*
|
||||
* @param pauseAction <code>Runnable</code> action.
|
||||
* @return <code>this</code>
|
||||
*/
|
||||
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 <code>this</code>
|
||||
*/
|
||||
ProgressPanelBuilder withoutComment();
|
||||
* Switch to small icons version.
|
||||
*
|
||||
* @return <code>this</code>
|
||||
*/
|
||||
public ProgressPanelBuilder andSmallIcons() {
|
||||
this.smallVariant = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable separator on top of the panel.
|
||||
*
|
||||
* @return <code>this</code>
|
||||
*/
|
||||
ProgressPanelBuilder withTopSeparator();
|
||||
* Switch off the comment and don't reserve place for it in the layout. This makes overall panel height smaller.
|
||||
*
|
||||
* @return <code>this</code>
|
||||
*/
|
||||
public ProgressPanelBuilder withoutComment() {
|
||||
this.commentEnabled = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable separator on top of the panel.
|
||||
*
|
||||
* @return <code>this</code>
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-5
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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"))).
|
||||
|
||||
+30
-12
@@ -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 <code>this</code>
|
||||
*/
|
||||
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 <code>this</code>
|
||||
*/
|
||||
public ComponentPanelBuilder moveLabelOnTop() {
|
||||
myLabelOnTop = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* @param comment help context styled text written below the owner component.
|
||||
* @return <code>this</code>
|
||||
*/
|
||||
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 <code>this</code>
|
||||
*/
|
||||
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 <code>this</code>
|
||||
*/
|
||||
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;
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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 List<GridBagPanelBuilder> builders = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public PanelGridBuilder add(@NotNull PanelBuilder builder) {
|
||||
builders.add((GridBagPanelBuilder)builder);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PanelGridBuilder expandVertically() {
|
||||
this.expand = 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 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,350 +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.icons.AllIcons;
|
||||
import com.intellij.openapi.ui.panel.GridBagPanelBuilder;
|
||||
import com.intellij.openapi.ui.panel.ProgressPanel;
|
||||
import com.intellij.openapi.ui.panel.ProgressPanelBuilder;
|
||||
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;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
public class ProgressPanelBuilderImpl implements ProgressPanelBuilder, GridBagPanelBuilder {
|
||||
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;
|
||||
|
||||
ProgressPanelBuilderImpl(JProgressBar progressBar) {
|
||||
myProgressBar = progressBar;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProgressPanelBuilder withLabel(@NotNull String text) {
|
||||
initialLabelText = text;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProgressPanelBuilder moveLabelLeft() {
|
||||
labelAbove = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProgressPanelBuilder withCancel(@NotNull Runnable cancelAction) {
|
||||
this.cancelAction = cancelAction;
|
||||
valid = resumeAction == null && pauseAction == null;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProgressPanelBuilder andCancelText(String cancelText) {
|
||||
this.cancelText = cancelText;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProgressPanelBuilder andCancelAsButton() {
|
||||
this.cancelAsButton = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProgressPanelBuilder withResume(@NotNull Runnable playAction) {
|
||||
this.resumeAction = playAction;
|
||||
valid = pauseAction != null && cancelAction == null;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProgressPanelBuilder withPause(@NotNull Runnable pauseAction) {
|
||||
this.pauseAction = pauseAction;
|
||||
valid = resumeAction != null && cancelAction == null;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ProgressPanelBuilder andSmallIcons() {
|
||||
this.smallVariant = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProgressPanelBuilder withoutComment() {
|
||||
this.commentEnabled = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
// 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.util.ui;
|
||||
|
||||
import com.intellij.openapi.ui.panel.PanelGridBuilder;
|
||||
import com.intellij.openapi.ui.panel.ProgressPanelBuilder;
|
||||
import com.intellij.ui.panel.ComponentPanelBuilder;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
public class UI extends JBUI {
|
||||
|
||||
public static class PanelFactory {
|
||||
|
||||
/**
|
||||
* Creates a panel builder for arbitrary <code>JComponent</code>.
|
||||
*
|
||||
* @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 <code>JProgressBar</code>.
|
||||
*
|
||||
* @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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -58,8 +58,6 @@
|
||||
serviceImplementation="com.intellij.ide.CopyPasteManagerEx"/>
|
||||
<applicationService serviceInterface="com.intellij.openapi.ui.popup.JBPopupFactory"
|
||||
serviceImplementation="com.intellij.ui.popup.PopupFactoryImpl"/>
|
||||
<applicationService serviceInterface="com.intellij.openapi.ui.panel.JBPanelFactory"
|
||||
serviceImplementation="com.intellij.ui.panel.PanelFactoryImpl"/>
|
||||
<applicationService serviceInterface="com.intellij.openapi.fileEditor.ex.FileEditorProviderManager"
|
||||
serviceImplementation="com.intellij.openapi.fileEditor.impl.FileEditorProviderManagerImpl"/>
|
||||
<applicationService serviceInterface="com.intellij.ide.ui.search.SearchableOptionsRegistrar"
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
// 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.util.ui;
|
||||
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
|
||||
import com.intellij.openapi.ui.panel.JBPanelFactory;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vcs.VcsBundle;
|
||||
import com.intellij.ui.components.JBCheckBox;
|
||||
@@ -44,9 +43,9 @@ public class VcsExecutablePathSelector {
|
||||
myProjectPathCheckbox = new JBCheckBox(VcsBundle.getString("executable.project.override"));
|
||||
myProjectPathCheckbox.addActionListener(e -> handleProjectOverrideStateChanged());
|
||||
|
||||
myMainPanel = JBPanelFactory.grid()
|
||||
.add(JBPanelFactory.panel(panel).withLabel(VcsBundle.getString("executable.select.label")))
|
||||
.add(JBPanelFactory.panel(myProjectPathCheckbox))
|
||||
myMainPanel = UI.PanelFactory.grid()
|
||||
.add(UI.PanelFactory.panel(panel).withLabel(VcsBundle.getString("executable.select.label")))
|
||||
.add(UI.PanelFactory.panel(myProjectPathCheckbox))
|
||||
.createPanel();
|
||||
}
|
||||
|
||||
|
||||
@@ -19,10 +19,10 @@ import com.intellij.openapi.options.ConfigurableUi;
|
||||
import com.intellij.openapi.progress.util.BackgroundTaskUtil;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.ui.panel.JBPanelFactory;
|
||||
import com.intellij.ui.components.JBCheckBox;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import com.intellij.util.ui.JBUI;
|
||||
import com.intellij.util.ui.UI;
|
||||
import com.intellij.util.ui.VcsExecutablePathSelector;
|
||||
import com.intellij.util.ui.components.BorderLayoutPanel;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -52,13 +52,13 @@ public class HgConfigurationProjectPanel implements ConfigurableUi<HgProjectConf
|
||||
panel.add(myExecutablePathSelector.getMainPanel());
|
||||
|
||||
myCheckIncomingOutgoingCbx = new JBCheckBox(HgVcsMessages.message("hg4idea.configuration.check.incoming.outgoing"));
|
||||
panel.add(JBPanelFactory.panel(myCheckIncomingOutgoingCbx).createPanel());
|
||||
panel.add(UI.PanelFactory.panel(myCheckIncomingOutgoingCbx).createPanel());
|
||||
|
||||
myIgnoredWhitespacesInAnnotationsCbx = new JBCheckBox(HgVcsMessages.message("hg4idea.configuration.ignore.whitespace.in.annotate"));
|
||||
panel.add(JBPanelFactory.panel(myIgnoredWhitespacesInAnnotationsCbx).createPanel());
|
||||
panel.add(UI.PanelFactory.panel(myIgnoredWhitespacesInAnnotationsCbx).createPanel());
|
||||
|
||||
mySyncControl = new JBCheckBox(DvcsBundle.getString("sync.setting"));
|
||||
JPanel mySyncControlPanel = ObjectUtils.notNull(JBPanelFactory.panel(mySyncControl)
|
||||
JPanel mySyncControlPanel = ObjectUtils.notNull(UI.PanelFactory.panel(mySyncControl)
|
||||
.withTooltip(DvcsBundle.message("sync.setting.description", "Mercurial"))
|
||||
.createPanel());
|
||||
if (!project.isDefault()) {
|
||||
|
||||
Reference in New Issue
Block a user