Prettify content entries configurables

- allow to create content entries editor with borders and enable border in
configurables
- remove redundant borders around splitter
- move delete icons to 3px right
- replace Insets with JBUI.insets
This commit is contained in:
Alexander Zolotov
2016-12-06 19:35:58 +03:00
parent 81da26178f
commit a39d42f401
7 changed files with 55 additions and 30 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -42,8 +42,8 @@ import com.intellij.ui.OnePixelSplitter;
import com.intellij.ui.ScrollPaneFactory;
import com.intellij.ui.border.CustomLineBorder;
import com.intellij.ui.roots.ToolbarPanel;
import com.intellij.util.Consumer;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.ui.JBUI;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -79,14 +79,17 @@ public class CommonContentEntriesEditor extends ModuleElementsEditor {
private VirtualFile myLastSelectedDir = null;
private final String myModuleName;
private final ModulesProvider myModulesProvider;
private final boolean myWithBorders;
private final ModuleConfigurationState myState;
private final List<ModuleSourceRootEditHandler<?>> myEditHandlers = new ArrayList<>();
public CommonContentEntriesEditor(String moduleName, final ModuleConfigurationState state, JpsModuleSourceRootType<?>... rootTypes) {
public CommonContentEntriesEditor(String moduleName, final ModuleConfigurationState state, boolean withBorders,
JpsModuleSourceRootType<?>... rootTypes) {
super(state);
myState = state;
myModuleName = moduleName;
myModulesProvider = state.getModulesProvider();
myWithBorders = withBorders;
for (JpsModuleSourceRootType<?> type : rootTypes) {
ContainerUtil.addIfNotNull(myEditHandlers, ModuleSourceRootEditHandler.getEditHandler(type));
}
@@ -113,6 +116,10 @@ public class CommonContentEntriesEditor extends ModuleElementsEditor {
});
}
public CommonContentEntriesEditor(String moduleName, final ModuleConfigurationState state, JpsModuleSourceRootType<?>... rootTypes) {
this(moduleName, state, false, rootTypes);
}
@Override
protected ModifiableRootModel getModel() {
return myState.getRootModel();
@@ -153,8 +160,6 @@ public class CommonContentEntriesEditor extends ModuleElementsEditor {
addAdditionalSettingsToPanel(mainPanel);
final JPanel entriesPanel = new JPanel(new BorderLayout());
final DefaultActionGroup group = new DefaultActionGroup();
final AddContentEntryAction action = new AddContentEntryAction();
action.registerCustomShortcutSet(KeyEvent.VK_C, InputEvent.ALT_DOWN_MASK, mainPanel);
@@ -164,8 +169,8 @@ public class CommonContentEntriesEditor extends ModuleElementsEditor {
myEditorsPanel.setBackground(BACKGROUND_COLOR);
JScrollPane myScrollPane = ScrollPaneFactory.createScrollPane(myEditorsPanel, true);
final ToolbarPanel toolbarPanel = new ToolbarPanel(myScrollPane, group);
toolbarPanel.setBorder(new CustomLineBorder(1, 0, 0, 0));
entriesPanel.add(toolbarPanel, BorderLayout.CENTER);
int border = myWithBorders ? 1 : 0;
toolbarPanel.setBorder(new CustomLineBorder(1, 0, border, border));
final JBSplitter splitter = new OnePixelSplitter(false);
splitter.setProportion(0.6f);
@@ -173,20 +178,20 @@ public class CommonContentEntriesEditor extends ModuleElementsEditor {
myRootTreeEditor = createContentEntryTreeEditor(project);
final JComponent component = myRootTreeEditor.createComponent();
component.setBorder(new CustomLineBorder(1, 0, 0, 0));
component.setBorder(new CustomLineBorder(1, border, border, 0));
splitter.setFirstComponent(component);
splitter.setSecondComponent(entriesPanel);
splitter.setSecondComponent(toolbarPanel);
JPanel contentPanel = new JPanel(new GridBagLayout());
final ActionToolbar actionToolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, myRootTreeEditor.getEditingActionsGroup(), true);
contentPanel.add(new JLabel("Mark as:"),
new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.WEST, 0, new Insets(0, 10, 0, 10), 0, 0));
new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.WEST, 0, JBUI.insets(0, 10), 0, 0));
contentPanel.add(actionToolbar.getComponent(),
new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
new Insets(0, 0, 0, 0), 0, 0));
JBUI.emptyInsets(), 0, 0));
contentPanel.add(splitter,
new GridBagConstraints(0, GridBagConstraints.RELATIVE, 2, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH,
new Insets(0, 0, 0, 0), 0, 0));
JBUI.emptyInsets(), 0, 0));
mainPanel.add(contentPanel, BorderLayout.CENTER);
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -89,7 +89,7 @@ public class ContentEntryTreeEditor {
new TreeSpeedSearch(myTree);
myTreePanel = new MyPanel(new BorderLayout());
final JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTree);
final JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTree, true);
myTreePanel.add(scrollPane, BorderLayout.CENTER);
myTreePanel.setVisible(false);
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -37,6 +37,7 @@ import com.intellij.ui.roots.ResizingWrapper;
import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;
import com.intellij.util.containers.MultiMap;
import com.intellij.util.ui.JBUI;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -92,13 +93,15 @@ public abstract class ContentRootPanel extends JPanel {
public void initUI() {
myHeader = createHeader();
myHeader.setBorder(new EmptyBorder(0, 8, 0, 0));
this.add(myHeader, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 8, 0), 0, 0));
this.add(myHeader, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL,
JBUI.insetsBottom(8), 0, 0));
addFolderGroupComponents();
myBottom = new JPanel(new BorderLayout());
myBottom.add(Box.createVerticalStrut(3), BorderLayout.NORTH);
this.add(myBottom, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 1.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
this.add(myBottom, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 1.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
JBUI.emptyInsets(), 0, 0));
setSelected(false);
}
@@ -112,7 +115,7 @@ public abstract class ContentRootPanel extends JPanel {
}
}
Insets insets = new Insets(0, 0, 10, 0);
Insets insets = JBUI.insetsBottom(10);
GridBagConstraints constraints = new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, insets, 0, 0);
for (ModuleSourceRootEditHandler<?> editor : myModuleSourceRootEditHandlers) {
Collection<SourceFolder> folders = folderByType.get(editor.getRootType());
@@ -145,8 +148,10 @@ public abstract class ContentRootPanel extends JPanel {
ProjectBundle.message("module.paths.remove.content.tooltip"),
() -> myCallback.deleteContentEntry());
final ResizingWrapper wrapper = new ResizingWrapper(headerLabel);
panel.add(wrapper, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 2, 0, 0), 0, 0));
panel.add(deleteIconComponent, new GridBagConstraints(1, GridBagConstraints.RELATIVE, 1, 1, 0.0, 1.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 2), 0, 0));
panel.add(wrapper, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL,
JBUI.insetsLeft(2), 0, 0));
panel.add(deleteIconComponent, new GridBagConstraints(1, GridBagConstraints.RELATIVE, 1, 1, 0.0, 1.0, GridBagConstraints.EAST, GridBagConstraints.NONE,
JBUI.insetsRight(5), 0, 0));
FilePathClipper.install(headerLabel, wrapper);
return panel;
}
@@ -155,7 +160,7 @@ public abstract class ContentRootPanel extends JPanel {
ContentFolder[] folders,
Color foregroundColor,
@Nullable ModuleSourceRootEditHandler<?> editor) {
final JPanel panel = new JPanel(new GridLayoutManager(folders.length, 3, new Insets(1, 17, 0, 2), 0, 1));
final JPanel panel = new JPanel(new GridLayoutManager(folders.length, 3, JBUI.insets(1, 17, 0, 5), 0, 1));
panel.setOpaque(false);
for (int idx = 0; idx < folders.length; idx++) {
@@ -1,3 +1,18 @@
/*
* Copyright 2000-2016 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.roots.ui.configuration;
import com.intellij.facet.impl.DefaultFacetsProvider;
@@ -68,7 +83,7 @@ public class PlatformContentEntriesConfigurable implements Configurable {
return DefaultFacetsProvider.INSTANCE;
}
};
myEditor = new CommonContentEntriesEditor(myModule.getName(), moduleConfigurationState, myRootTypes) {
myEditor = new CommonContentEntriesEditor(myModule.getName(), moduleConfigurationState, true, myRootTypes) {
@Override
protected List<ContentEntry> addContentEntries(VirtualFile[] files) {
List<ContentEntry> entries = super.addContentEntries(files);
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -35,8 +35,8 @@ public class PythonModuleConfigurationEditorProvider implements ModuleConfigurat
if (!(ModuleType.get(module) instanceof PythonModuleType)) return ModuleConfigurationEditor.EMPTY;
final DefaultModuleConfigurationEditorFactory editorFactory = DefaultModuleConfigurationEditorFactory.getInstance();
final List<ModuleConfigurationEditor> editors = new ArrayList<>();
editors.add(new PyContentEntriesEditor(module, state, JavaSourceRootType.SOURCE));
editors.add(new PyContentEntriesEditor(module, state, false, JavaSourceRootType.SOURCE));
editors.add(editorFactory.createClasspathEditor(state));
return editors.toArray(new ModuleConfigurationEditor[editors.size()]);
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -93,7 +93,7 @@ public class PyContentEntriesModuleConfigurable extends SearchableConfigurable.P
}
protected PyContentEntriesEditor createEditor(@NotNull Module module, @NotNull ModuleConfigurationStateImpl state) {
return new PyContentEntriesEditor(module, state, JavaSourceRootType.SOURCE);
return new PyContentEntriesEditor(module, state, true, JavaSourceRootType.SOURCE);
}
@Override
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -53,8 +53,8 @@ public class PyContentEntriesEditor extends CommonContentEntriesEditor {
private FacetErrorPanel myWarningPanel;
public PyContentEntriesEditor(Module module, ModuleConfigurationState moduleConfigurationState,
JpsModuleSourceRootType<?>... rootTypes) {
super(module.getName(), moduleConfigurationState, rootTypes);
boolean withBorders, JpsModuleSourceRootType<?>... rootTypes) {
super(module.getName(), moduleConfigurationState, withBorders, rootTypes);
myRootTypeProviders = Extensions.getExtensions(PyRootTypeProvider.EP_NAME);
myModule = module;
myWarningPanel = new FacetErrorPanel();