diff options
Diffstat (limited to 'java/idea-ui/src/com/intellij/openapi/roots/ui/configuration')
4 files changed, 397 insertions, 16 deletions
diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ErrorPaneConfigurable.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ErrorPaneConfigurable.java new file mode 100644 index 000000000000..77ccbe6cbdff --- /dev/null +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ErrorPaneConfigurable.java @@ -0,0 +1,217 @@ +/* + * Copyright 2000-2014 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.openapi.Disposable; +import com.intellij.openapi.options.Configurable; +import com.intellij.openapi.options.ConfigurationException; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext; +import com.intellij.openapi.util.Disposer; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.ui.*; +import com.intellij.ui.awt.RelativePoint; +import com.intellij.util.Alarm; +import com.intellij.util.ui.UIUtil; +import org.jetbrains.annotations.Nls; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; +import javax.swing.event.HyperlinkEvent; +import javax.swing.text.Element; +import java.awt.*; +import java.awt.event.MouseEvent; +import java.net.URL; +import java.util.ArrayList; + +/** + * @author Konstantin Bulenkov + */ +public class ErrorPaneConfigurable extends JPanel implements Configurable, Disposable, ConfigurationErrors { + private final Alarm myAlarm; + private final ArrayList<ConfigurationError> myErrors = new ArrayList<ConfigurationError>(); + private final JTextPane myContent = new JTextPane(); + private Runnable myOnErrorsChanged; + + public ErrorPaneConfigurable(final Project project, StructureConfigurableContext context, Runnable onErrorsChanged) { + super(new BorderLayout()); + myOnErrorsChanged = onErrorsChanged; + myContent.setEditorKit(UIUtil.getHTMLEditorKit()); + myContent.setEditable(false); + myContent.setBackground(UIUtil.getListBackground()); + final JScrollPane pane = ScrollPaneFactory.createScrollPane(myContent, true); + pane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); + add(pane); + myAlarm = new Alarm(this); + project.getMessageBus().connect(this).subscribe(ConfigurationErrors.TOPIC, this); + myContent.addHyperlinkListener(new HyperlinkAdapter() { + @Override + public void hyperlinkActivated(HyperlinkEvent e) { + final URL url = e.getURL(); + final AWTEvent awtEvent = EventQueue.getCurrentEvent(); + if (!(awtEvent instanceof MouseEvent)) { + return; + } + final MouseEvent me = (MouseEvent)awtEvent; + + if (url != null) { + ConfigurationError error = null; + Element element = e.getSourceElement(); + while (element != null) { + if ("li".equals(element.getName())) { + final Element ol = element.getParentElement(); + for (int i = 0; i < ol.getElementCount(); i++) { + if (ol.getElement(i) == element) { + error = myErrors.get(i); + } + } + break; + } + element = element.getParentElement(); + } + if (error == null) return; + final String host = url.getHost(); + String path = url.getPath(); + if (path != null && path.startsWith("/")) { + path = StringUtil.unescapeXml(path.substring(1)); + } + if (path != null) { + if ("fix".equals(host)) { + final MouseEvent mouseEvent = new MouseEvent(me.getComponent(), me.getID(), me.getWhen(), me.getModifiers(), + me.getX() - 15, me.getY() + 10, me.getClickCount(), me.isPopupTrigger()); + error.fix(myContent, new RelativePoint(mouseEvent)); + } else { + error.navigate(); + } + } + } + } + }); + + refresh(); + } + + public void refresh() { + myAlarm.cancelAllRequests(); + myAlarm.addRequest(new Runnable() { + @Override + public void run() { + String html = "<html>" + + "<header><style type='text/css'>" + + "body {" + + " color: #" + ColorUtil.toHex(new JBColor(Gray.x33, UIUtil.getLabelForeground())) + ";" + + " font-family: '" + UIUtil.getLabelFont().getName() + ",serif';" + + " font-size: " + UIUtil.getLabelFont().getSize() + ";" + + "}" + + "li {" + + " margin-bottom: 5;" + + "}" + + "ol {" + + "}" + + "a {" + + " text-decoration: none;" + + "}" + + "</style>" + + "</header>" + + "<body>"; + int i = 0; + html += "<ol>"; + for (ConfigurationError error : myErrors) { + i++; + String description = error.getDescription(); + if (description.startsWith("<html>") && description.endsWith("</html>")) { + description = description.substring(6, description.length() - 7); + } + if (description.startsWith("Module '")) { + final int start = 8; + final int end = description.indexOf("'", 9); + final String moduleName = description.substring(start, end); + description = "Module <a href='http://module/" + StringUtil.escapeXml(moduleName) + "'>" + StringUtil.escapeXml(moduleName) + "</a> " + description.substring( + end + 1); + } + if (error.canBeFixed()) { + description += " <a href='http://fix/" + i + "'>[Fix]</a>"; + } + html+= "<li>" + description + "</li>"; + } + html += "</ol></body></html>"; + myContent.setText(html); + if (myOnErrorsChanged != null) { + myOnErrorsChanged.run(); + } + } + }, 100); + } + + @Nls + @Override + public String getDisplayName() { + return "Problems"; + } + + @Nullable + @Override + public String getHelpTopic() { + return null; + } + + @Nullable + @Override + public JComponent createComponent() { + return this; + } + + @Override + public boolean isModified() { + return false; + } + + @Override + public void apply() throws ConfigurationException { + + } + + @Override + public void reset() { + + } + + @Override + public void disposeUIResources() { + Disposer.dispose(this); + } + + @Override + public void dispose() { + } + + @Override + public void addError(@NotNull ConfigurationError error) { + myErrors.add(error); + refresh(); + } + + @Override + public void removeError(@NotNull ConfigurationError error) { + myErrors.remove(error); + refresh(); + } + + public int getErrorsCount() { + return myErrors.size(); + } +} diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ProjectStructureConfigurable.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ProjectStructureConfigurable.java index d007c3650642..bf083f92c66c 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ProjectStructureConfigurable.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ProjectStructureConfigurable.java @@ -43,7 +43,6 @@ import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.wm.ex.IdeFocusTraversalPolicy; import com.intellij.packaging.artifacts.Artifact; -import com.intellij.ui.Gray; import com.intellij.ui.JBSplitter; import com.intellij.ui.components.panels.Wrapper; import com.intellij.ui.navigation.BackAction; @@ -179,11 +178,7 @@ public class ProjectStructureConfigurable extends BaseConfigurable implements Se mySplitter.setSplitterProportionKey("ProjectStructure.TopLevelElements"); mySplitter.setHonorComponentsMinimumSize(true); if (Registry.is("ide.new.project.settings")) { - mySplitter.setDividerWidth(1); - mySplitter.setShowDividerIcon(false); - mySplitter.getDivider().setBackground(Gray._153.withAlpha(128)); - mySplitter.setShowDividerControls(false); - mySplitter.setOrientation(mySplitter.getOrientation()); + mySplitter.setOnePixelMode(); } initSidePanel(); @@ -203,7 +198,7 @@ public class ProjectStructureConfigurable extends BaseConfigurable implements Se toolbar.setTargetComponent(myComponent); myToolbarComponent = toolbar.getComponent(); if (Registry.is("ide.new.project.settings")) { - left.setBackground(new Color(0xD2D6DD)); + left.setBackground(UIUtil.getSidePanelColor()); } else { left.add(myToolbarComponent, BorderLayout.NORTH); } @@ -214,7 +209,9 @@ public class ProjectStructureConfigurable extends BaseConfigurable implements Se myComponent.add(mySplitter, BorderLayout.CENTER); myErrorsComponent = new ConfigurationErrorsComponent(myProject); - myComponent.add(myErrorsComponent, BorderLayout.SOUTH); + if (!Registry.is("ide.new.project.settings")) { + myComponent.add(myErrorsComponent, BorderLayout.SOUTH); + } myUiInitialized = true; @@ -253,6 +250,11 @@ public class ProjectStructureConfigurable extends BaseConfigurable implements Se addConfigurable(configurable, true); } } + + if (Registry.is("ide.new.project.settings")) { + mySidePanel.addSeparator("--"); + addErrorPane(); + } } private void addArtifactsConfig() { @@ -299,6 +301,15 @@ public class ProjectStructureConfigurable extends BaseConfigurable implements Se addConfigurable(myProjectLibrariesConfig, ConfigurableId.PROJECT_LIBRARIES); } + private void addErrorPane() { + addConfigurable(new ErrorPaneConfigurable(myProject, myContext, new Runnable() { + @Override + public void run() { + mySidePanel.getList().repaint(); + } + }), true); + } + private void addGlobalLibrariesConfig() { addConfigurable(myGlobalLibrariesConfig, ConfigurableId.GLOBAL_LIBRARIES); } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/SidePanel.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/SidePanel.java index a2d1e4e0489d..290f35e561b5 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/SidePanel.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/SidePanel.java @@ -16,17 +16,23 @@ package com.intellij.openapi.roots.ui.configuration; import com.intellij.openapi.actionSystem.Presentation; +import com.intellij.openapi.ui.GraphicsConfig; import com.intellij.openapi.ui.popup.ListItemDescriptor; import com.intellij.openapi.util.registry.Registry; -import com.intellij.ui.ScrollPaneFactory; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.ui.*; import com.intellij.ui.components.JBList; +import com.intellij.ui.components.panels.NonOpaquePanel; import com.intellij.ui.navigation.History; import com.intellij.ui.navigation.Place; import com.intellij.ui.popup.list.GroupedItemsListRenderer; import com.intellij.util.ui.EmptyIcon; +import com.intellij.util.ui.GraphicsUtil; +import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; import javax.swing.*; +import javax.swing.border.Border; import javax.swing.border.EmptyBorder; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; @@ -36,6 +42,9 @@ import java.util.Collection; import java.util.HashMap; import java.util.Map; +import static javax.swing.SwingConstants.CENTER; +import static javax.swing.SwingConstants.LEFT; + public class SidePanel extends JPanel { private final JList myList; @@ -56,7 +65,7 @@ public class SidePanel extends JPanel { myModel = new DefaultListModel(); myList = new JBList(myModel); if (Registry.is("ide.new.project.settings")) { - myList.setBackground(new Color(0xD2D6DD)); + myList.setBackground(UIUtil.getSidePanelColor()); myList.setBorder(new EmptyBorder(5, 0, 0, 0)); } final ListItemDescriptor descriptor = new ListItemDescriptor() { @@ -84,18 +93,100 @@ public class SidePanel extends JPanel { @Override public String getCaptionAboveOf(final Object value) { - String text = myIndex2Separator.get(myPlaces.indexOf(value)); - return text != null && Registry.is("ide.new.project.settings") ? text.toUpperCase() : text; + return myIndex2Separator.get(myPlaces.indexOf(value)); } }; myList.setCellRenderer(new GroupedItemsListRenderer(descriptor) { + JPanel myExtraPanel; + CountLabel myCountLabel; { mySeparatorComponent.setCaptionCentered(false); } + + @Override + protected Color getForeground() { + return Registry.is("ide.new.project.settings") ? new JBColor(Gray._60, Gray._140) : super.getForeground(); + } + + @Override + protected SeparatorWithText createSeparator() { + return new SeparatorWithText() { + @Override + protected void paintComponent(Graphics g) { + if (Registry.is("ide.new.project.settings")) { + g.setColor(new JBColor(POPUP_SEPARATOR_FOREGROUND, Gray._80)); + if ("--".equals(getCaption())) { + g.drawLine(0, getHeight()/ 2, getWidth(), getHeight() /2); + return; + } + Rectangle viewR = new Rectangle(0, getVgap(), getWidth() - 1, getHeight() - getVgap() - 1); + Rectangle iconR = new Rectangle(); + Rectangle textR = new Rectangle(); + String s = SwingUtilities + .layoutCompoundLabel(g.getFontMetrics(), getCaption(), null, CENTER, + LEFT, + CENTER, + LEFT, + viewR, iconR, textR, 0); + GraphicsUtil.setupAAPainting(g); + g.setColor(new JBColor(Gray._255.withAlpha(80), Gray._0.withAlpha(80))); + g.drawString(s, textR.x + 10, textR.y + 1 + g.getFontMetrics().getAscent()); + g.setColor(new JBColor(new Color(0x5F6D7B), Gray._120)); + g.drawString(s, textR.x + 10, textR.y + g.getFontMetrics().getAscent()); + } + else { + super.paintComponent(g); + } + } + }; + } + + @Override + protected void layout() { + if (Registry.is("ide.new.project.settings")) { + myRendererComponent.add(mySeparatorComponent, BorderLayout.NORTH); + myExtraPanel.add(myComponent, BorderLayout.CENTER); + myExtraPanel.add(myCountLabel, BorderLayout.EAST); + myRendererComponent.add(myExtraPanel, BorderLayout.CENTER); + } else { + super.layout(); + } + } + + @Override + public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { + myCountLabel.setText(""); + final Component component = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); + if ("Problems".equals(descriptor.getTextFor(value))) { + final ErrorPaneConfigurable errorPane = (ErrorPaneConfigurable)((Place)value).getPath("category"); + if (errorPane != null && errorPane.getErrorsCount() > 0) { + myCountLabel.setSelected(isSelected); + myCountLabel.setText(String.valueOf(errorPane.getErrorsCount())); + } + } + return component; + } + + @Override + protected JComponent createItemComponent() { + myExtraPanel = new NonOpaquePanel(new BorderLayout()); + myCountLabel = new CountLabel(); + + + if (Registry.is("ide.new.project.settings")) { + myTextLabel = new EngravedLabel(); + myTextLabel.setFont(myTextLabel.getFont().deriveFont(Font.BOLD)); + myTextLabel.setForeground(Gray._240); + myTextLabel.setOpaque(true); + return layoutComponent(myTextLabel); + } + return super.createItemComponent(); + } + @Override protected Color getBackground() { - return Registry.is("ide.new.project.settings") ? new Color(0xD2D6DD) : super.getBackground(); + return Registry.is("ide.new.project.settings") ? UIUtil.getSidePanelColor() : super.getBackground(); } }); @@ -114,6 +205,10 @@ public class SidePanel extends JPanel { }); } + public JList getList() { + return myList; + } + public void addPlace(Place place, @NotNull Presentation presentation) { myModel.addElement(place); myPlaces.add(place); @@ -133,4 +228,51 @@ public class SidePanel extends JPanel { public void select(final Place place) { myList.setSelectedValue(place, true); } + + private static class CountLabel extends JLabel { + private boolean mySelected; + + public CountLabel() { + super(); + setBorder(new Border() { + @Override + public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { + } + + @Override + public Insets getBorderInsets(Component c) { + return StringUtil.isEmpty(getText()) ? new Insets(0,0,0,0) : new Insets(2, 6, 2, 6 + 6); + } + + @Override + public boolean isBorderOpaque() { + return false; + } + }); + setFont(UIUtil.getListFont().deriveFont(Font.BOLD)); + } + + public boolean isSelected() { + return mySelected; + } + + public void setSelected(boolean selected) { + mySelected = selected; + } + + @Override + protected void paintComponent(Graphics g) { + g.setColor(isSelected() ? UIUtil.getListSelectionBackground() : UIUtil.getSidePanelColor()); + g.fillRect(0, 0, getWidth(), getHeight()); + if (StringUtil.isEmpty(getText())) return; + final JBColor deepBlue = new JBColor(new Color(0x97A4B2), new Color(92, 98, 113)); + g.setColor(isSelected() ? Gray._255.withAlpha(UIUtil.isUnderDarcula() ? 100 : 220) : deepBlue); + final GraphicsConfig config = GraphicsUtil.setupAAPainting(g); + g.fillRoundRect(0, 3, getWidth() - 6 -1, getHeight()-6 , (getHeight() - 6), (getHeight() - 6)); + config.restore(); + setForeground(isSelected() ? deepBlue.darker() : UIUtil.getListForeground(true)); + + super.paintComponent(g); + } + } } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/daemon/LibraryProjectStructureElement.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/daemon/LibraryProjectStructureElement.java index 1fc3dbd66162..7af12e978190 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/daemon/LibraryProjectStructureElement.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/daemon/LibraryProjectStructureElement.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -34,6 +34,7 @@ import com.intellij.openapi.roots.ui.configuration.projectRoot.LibraryConfigurab import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext; import com.intellij.openapi.ui.NamedConfigurable; import com.intellij.openapi.util.ActionCallback; +import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.PathUtil; import com.intellij.xml.util.XmlStringUtil; @@ -95,7 +96,14 @@ public class LibraryProjectStructureElement extends ProjectStructureElement { private static String createInvalidRootsDescription(List<String> invalidClasses, String rootName, String libraryName) { StringBuilder buffer = new StringBuilder(); - buffer.append("Library '").append(StringUtil.escapeXml(libraryName)).append("' has broken " + rootName + " " + StringUtil.pluralize("path", invalidClasses.size()) + ":"); + final String name = StringUtil.escapeXml(libraryName); + buffer.append("Library "); + if (Registry.is("ide.new.project.settings")) { + buffer.append("<a href='http://library/").append(name).append("'>").append(name).append("</a>"); + } else { + buffer.append("'").append(name).append("'"); + } + buffer.append(" has broken " + rootName + " " + StringUtil.pluralize("path", invalidClasses.size()) + ":"); for (String url : invalidClasses) { buffer.append("<br> "); buffer.append(PathUtil.toPresentableUrl(url)); @@ -150,7 +158,10 @@ public class LibraryProjectStructureElement extends ProjectStructureElement { @Override public ProjectStructureProblemDescription createUnusedElementWarning() { final List<ConfigurationErrorQuickFix> fixes = Arrays.asList(new AddLibraryToDependenciesFix(), new RemoveLibraryFix(), new RemoveAllUnusedLibrariesFix()); - return new ProjectStructureProblemDescription("Library '" + StringUtil.escapeXml(myLibrary.getName()) + "'" + " is not used", null, createPlace(), + final String name = StringUtil.escapeXml(myLibrary.getName()); + String libraryName = Registry.is("ide.new.project.settings") ? "<a href='http://library/" + name + "'>" + name + "</a>" + : "'" + name + "'"; + return new ProjectStructureProblemDescription("Library " + libraryName + " is not used", null, createPlace(), ProjectStructureProblemType.unused("unused-library"), ProjectStructureProblemDescription.ProblemLevel.PROJECT, fixes, false); } |