From ee2cf019f06c82b0d7387824be7ef4aa329faae9 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Fri, 4 Mar 2005 20:23:35 +0300 Subject: [PATCH] add icons to ctrl-n-like dialogs --- .../ide/ui/AppearanceConfigurable.java | 6 + .../com/intellij/ide/ui/AppearancePanel.form | 60 ++++++---- source/com/intellij/ide/ui/UISettings.java | 1 + .../util/NavigationItemListCellRenderer.java | 99 ++++++++++----- .../ide/util/PsiElementListCellRenderer.java | 113 ++++++++++++------ .../ide/util/PsiElementModuleRenderer.java | 91 ++++++++++++++ .../ide/util/TreeClassChooserDialog.java | 28 +++-- 7 files changed, 295 insertions(+), 103 deletions(-) create mode 100644 source/com/intellij/ide/util/PsiElementModuleRenderer.java diff --git a/source/com/intellij/ide/ui/AppearanceConfigurable.java b/source/com/intellij/ide/ui/AppearanceConfigurable.java index 21fb66c8b8d6..3090d827e1e5 100644 --- a/source/com/intellij/ide/ui/AppearanceConfigurable.java +++ b/source/com/intellij/ide/ui/AppearanceConfigurable.java @@ -158,6 +158,9 @@ public class AppearanceConfigurable extends BaseConfigurable implements Applicat update |= hide != settings.HIDE_KNOWN_EXTENSION_IN_TABS; settings.HIDE_KNOWN_EXTENSION_IN_TABS = hide; + update |= settings.SHOW_ICONS_IN_QUICK_NAVIGATION != myComponent.myHideIconsInQuickNavigation.isSelected(); + settings.SHOW_ICONS_IN_QUICK_NAVIGATION = myComponent.myHideIconsInQuickNavigation.isSelected(); + boolean shouldRepaintUI = false; if ( settings.ANTIALIASING_IN_EDITOR != myComponent.myAntialiasingInEditorCheckBox.isSelected() @@ -219,6 +222,7 @@ public class AppearanceConfigurable extends BaseConfigurable implements Applicat myComponent.myScrollTabLayoutInEditorCheckBox.setSelected(settings.SCROLL_TAB_LAYOUT_IN_EDITOR); myComponent.myEditorTabPlacement.setSelectedItem(new Integer(settings.EDITOR_TAB_PLACEMENT)); myComponent.myHideKnownExtensions.setSelected(settings.HIDE_KNOWN_EXTENSION_IN_TABS); + myComponent.myHideIconsInQuickNavigation.setSelected(settings.SHOW_ICONS_IN_QUICK_NAVIGATION); myComponent.myAntialiasingInEditorCheckBox.setSelected(settings.ANTIALIASING_IN_EDITOR); myComponent.myMoveMouseOnDefaultButtonCheckBox.setSelected(settings.MOVE_MOUSE_ON_DEFAULT_BUTTON); myComponent.myLafComboBox.setSelectedItem(LafManager.getInstance().getCurrentLookAndFeel()); @@ -259,6 +263,7 @@ public class AppearanceConfigurable extends BaseConfigurable implements Applicat int tabPlacement = ((Integer)myComponent.myEditorTabPlacement.getSelectedItem()).intValue(); isModified |= tabPlacement != settings.EDITOR_TAB_PLACEMENT; isModified |= myComponent.myHideKnownExtensions.isSelected() != settings.HIDE_KNOWN_EXTENSION_IN_TABS; + isModified |= myComponent.myHideIconsInQuickNavigation.isSelected() != settings.SHOW_ICONS_IN_QUICK_NAVIGATION; isModified |= myComponent.myAntialiasingInEditorCheckBox.isSelected() != settings.ANTIALIASING_IN_EDITOR; isModified |= myComponent.myMoveMouseOnDefaultButtonCheckBox.isSelected() != settings.MOVE_MOUSE_ON_DEFAULT_BUTTON; @@ -360,6 +365,7 @@ public class AppearanceConfigurable extends BaseConfigurable implements Applicat private JCheckBox myOverrideLAFFonts; private JLabel myIDEALafFont; private JCheckBox myHideKnownExtensions; + private JCheckBox myHideIconsInQuickNavigation; public MyComponent() { ActionListener updater = new ActionListener() { diff --git a/source/com/intellij/ide/ui/AppearancePanel.form b/source/com/intellij/ide/ui/AppearancePanel.form index 132da178eb7b..dd86710fa2ca 100644 --- a/source/com/intellij/ide/ui/AppearancePanel.form +++ b/source/com/intellij/ide/ui/AppearancePanel.form @@ -11,14 +11,14 @@ - + - + @@ -26,7 +26,7 @@ - + @@ -37,7 +37,7 @@ - + @@ -48,7 +48,7 @@ - + @@ -59,7 +59,7 @@ - + @@ -70,7 +70,7 @@ - + @@ -84,7 +84,7 @@ - + @@ -92,7 +92,7 @@ - + @@ -101,7 +101,7 @@ - + @@ -110,7 +110,7 @@ - + @@ -120,14 +120,14 @@ - + - + @@ -140,10 +140,10 @@ - + - + @@ -151,8 +151,8 @@ - - + + @@ -161,8 +161,8 @@ - - + + @@ -212,8 +212,8 @@ - - + + @@ -242,8 +242,8 @@ - - + + @@ -308,8 +308,8 @@ - - + + @@ -344,6 +344,16 @@ + + + + + + + + + + diff --git a/source/com/intellij/ide/ui/UISettings.java b/source/com/intellij/ide/ui/UISettings.java index 22eb2f48a1b0..8d0b2d8927f3 100644 --- a/source/com/intellij/ide/ui/UISettings.java +++ b/source/com/intellij/ide/ui/UISettings.java @@ -28,6 +28,7 @@ public class UISettings implements NamedJDOMExternalizable, ApplicationComponent public boolean SCROLL_TAB_LAYOUT_IN_EDITOR = false; public int EDITOR_TAB_PLACEMENT = 1; public boolean HIDE_KNOWN_EXTENSION_IN_TABS = false; + public boolean SHOW_ICONS_IN_QUICK_NAVIGATION = true; public boolean CLOSE_NON_MODIFIED_FILES_FIRST = false; public boolean ANTIALIASING_IN_EDITOR; public boolean MOVE_MOUSE_ON_DEFAULT_BUTTON = false; diff --git a/source/com/intellij/ide/util/NavigationItemListCellRenderer.java b/source/com/intellij/ide/util/NavigationItemListCellRenderer.java index 42c1a0a2d3ad..16131a49a9da 100644 --- a/source/com/intellij/ide/util/NavigationItemListCellRenderer.java +++ b/source/com/intellij/ide/util/NavigationItemListCellRenderer.java @@ -32,6 +32,7 @@ package com.intellij.ide.util; import com.intellij.ide.IconUtilEx; +import com.intellij.ide.ui.UISettings; import com.intellij.ide.util.treeView.NodeRenderer; import com.intellij.navigation.ItemPresentation; import com.intellij.navigation.NavigationItem; @@ -44,57 +45,89 @@ import javax.swing.*; import java.awt.*; import java.util.Comparator; -public class NavigationItemListCellRenderer extends ColoredListCellRenderer{ - protected void customizeCellRenderer( +public class NavigationItemListCellRenderer extends JPanel implements ListCellRenderer { + public NavigationItemListCellRenderer() { + super(new BorderLayout()); + } + + public Component getListCellRendererComponent( JList list, Object value, int index, - boolean selected, - boolean hasFocus - ){ - if (value instanceof NavigationItem) { - NavigationItem element = (NavigationItem)value; - ItemPresentation presentation = element.getPresentation(); - String name = presentation.getPresentableText(); - Color color = list.getForeground(); - FileStatus status = element.getFileStatus(); - if (status != FileStatus.NOT_CHANGED) { - color = status.getColor(); - } - - final SimpleTextAttributes simpleTextAttributes = NodeRenderer.getSimpleTextAttributes(presentation); - final TextAttributes textAttributes = simpleTextAttributes.toTextAttributes(); - textAttributes.setForegroundColor(color); - append(name,SimpleTextAttributes.fromTextAttributes(textAttributes)); - setIcon(presentation.getIcon(false)); - - String containerText = presentation.getLocationString(); - - if (containerText != null && containerText.length() > 0){ - append(" " + containerText, new SimpleTextAttributes(Font.PLAIN, Color.GRAY)); - } + boolean isSelected, + boolean cellHasFocus) { + removeAll(); + final Component leftCellRendererComponent = + new LeftRenderer().getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); + add(leftCellRendererComponent, BorderLayout.WEST); + if (UISettings.getInstance().SHOW_ICONS_IN_QUICK_NAVIGATION){ + final Component rightCellRendererComponent = + new PsiElementModuleRenderer().getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); + add(rightCellRendererComponent, BorderLayout.EAST); + final JPanel spacer = new JPanel(); + final Dimension size = rightCellRendererComponent.getSize(); + spacer.setSize(new Dimension((int)(size.width * 0.015 + leftCellRendererComponent.getSize().width * 0.015), size.height)); + spacer.setBackground(UIManager.getColor(isSelected ? "List.selectionBackground" : "List.background")); + add(spacer, BorderLayout.CENTER); } - else { - setIcon(IconUtilEx.getEmptyIcon(false)); - append(value == null ? "" : value.toString(), new SimpleTextAttributes(Font.PLAIN, list.getForeground())); + setBackground(UIManager.getColor(isSelected ? "List.selectionBackground" : "List.background")); + return this; + } + + private class LeftRenderer extends ColoredListCellRenderer { + protected void customizeCellRenderer( + JList list, + Object value, + int index, + boolean selected, + boolean hasFocus + ) { + if (value instanceof NavigationItem) { + NavigationItem element = (NavigationItem)value; + ItemPresentation presentation = element.getPresentation(); + String name = presentation.getPresentableText(); + Color color = list.getForeground(); + FileStatus status = element.getFileStatus(); + if (status != FileStatus.NOT_CHANGED) { + color = status.getColor(); + } + + final SimpleTextAttributes simpleTextAttributes = NodeRenderer.getSimpleTextAttributes(presentation); + final TextAttributes textAttributes = simpleTextAttributes.toTextAttributes(); + textAttributes.setForegroundColor(color); + append(name, SimpleTextAttributes.fromTextAttributes(textAttributes)); + setIcon(presentation.getIcon(false)); + + String containerText = presentation.getLocationString(); + + if (containerText != null && containerText.length() > 0) { + append(" " + containerText, new SimpleTextAttributes(Font.PLAIN, Color.GRAY)); + } + } + else { + setIcon(IconUtilEx.getEmptyIcon(false)); + append(value == null ? "" : value.toString(), new SimpleTextAttributes(Font.PLAIN, list.getForeground())); + } + setPaintFocusBorder(false); + setBackground(UIManager.getColor(selected ? "List.selectionBackground" : "List.background")); } } - public Comparator getComparator(){ + public Comparator getComparator() { return new Comparator() { public int compare(Object o1, Object o2) { return getText(o1).compareTo(getText(o2)); } - private String getText(Object o){ - if (o instanceof NavigationItem){ + private String getText(Object o) { + if (o instanceof NavigationItem) { NavigationItem element = (NavigationItem)o; ItemPresentation presentation = element.getPresentation(); String elementText = presentation.getLocationString(); String containerText = presentation.getLocationString(); return containerText != null ? elementText + " " + containerText : elementText; } - else{ + else { return o.toString(); } } diff --git a/source/com/intellij/ide/util/PsiElementListCellRenderer.java b/source/com/intellij/ide/util/PsiElementListCellRenderer.java index e40bc860a09b..402e7922dc92 100644 --- a/source/com/intellij/ide/util/PsiElementListCellRenderer.java +++ b/source/com/intellij/ide/util/PsiElementListCellRenderer.java @@ -1,6 +1,7 @@ package com.intellij.ide.util; import com.intellij.ide.IconUtilEx; +import com.intellij.ide.ui.UISettings; import com.intellij.openapi.vcs.FileStatus; import com.intellij.openapi.vcs.FileStatusManager; import com.intellij.openapi.vfs.VirtualFile; @@ -14,40 +15,76 @@ import javax.swing.*; import java.awt.*; import java.util.Comparator; -public abstract class PsiElementListCellRenderer extends ColoredListCellRenderer{ - protected void customizeCellRenderer( - JList list, - Object value, - int index, - boolean selected, - boolean hasFocus - ){ - if (value instanceof PsiElement){ - PsiElement element = (PsiElement)value; - String name = getElementText(element); - Color color = list.getForeground(); - PsiFile psiFile = element.getContainingFile(); - if (psiFile != null) { - VirtualFile vFile = psiFile.getVirtualFile(); - if (vFile != null) { - FileStatus status = FileStatusManager.getInstance(psiFile.getProject()).getStatus(vFile); - color = status.getColor(); +public abstract class PsiElementListCellRenderer extends JPanel implements ListCellRenderer { + private boolean myAddLocation = true; + protected PsiElementListCellRenderer() { + super(new BorderLayout()); + } + + public void setAddLocation(final boolean addLocation) { + myAddLocation = addLocation; + } + + private class LeftRenderer extends ColoredListCellRenderer { + protected void customizeCellRenderer( + JList list, + Object value, + int index, + boolean selected, + boolean hasFocus + ) { + if (value instanceof PsiElement) { + PsiElement element = (PsiElement)value; + String name = getElementText(element); + Color color = list.getForeground(); + PsiFile psiFile = element.getContainingFile(); + if (psiFile != null) { + VirtualFile vFile = psiFile.getVirtualFile(); + if (vFile != null) { + FileStatus status = FileStatusManager.getInstance(psiFile.getProject()).getStatus(vFile); + color = status.getColor(); + } + } + append(name, new SimpleTextAttributes(Font.PLAIN, color)); + setIcon(element.getIcon(getIconFlags())); + + String containerText = getContainerText(element); + if (containerText != null) { + append(" " + containerText, new SimpleTextAttributes(Font.PLAIN, Color.GRAY)); } } - append(name,new SimpleTextAttributes(Font.PLAIN, color)); - setIcon(element.getIcon(getIconFlags())); - - String containerText = getContainerText(element); - if (containerText != null){ - append(" " + containerText, new SimpleTextAttributes(Font.PLAIN, Color.GRAY)); + else { + setIcon(IconUtilEx.getEmptyIcon(false)); + append(value == null ? "" : value.toString(), new SimpleTextAttributes(Font.PLAIN, list.getForeground())); } - } - else{ - setIcon(IconUtilEx.getEmptyIcon(false)); - append(value == null ? "" : value.toString(), new SimpleTextAttributes(Font.PLAIN, list.getForeground())); + setPaintFocusBorder(false); + setBackground(UIManager.getColor(selected ? "List.selectionBackground" : "List.background")); } } + public Component getListCellRendererComponent( + JList list, + Object value, + int index, + boolean isSelected, + boolean cellHasFocus) { + removeAll(); + final Component leftCellRendererComponent = + new LeftRenderer().getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); + add(leftCellRendererComponent, BorderLayout.WEST); + if (myAddLocation && UISettings.getInstance().SHOW_ICONS_IN_QUICK_NAVIGATION){ + final Component rightCellRendererComponent = + new PsiElementModuleRenderer().getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); + add(rightCellRendererComponent, BorderLayout.EAST); + final JPanel spacer = new JPanel(); + final Dimension size = rightCellRendererComponent.getSize(); + spacer.setSize(new Dimension((int)(size.width * 0.015 + leftCellRendererComponent.getSize().width * 0.015), size.height)); + spacer.setBackground(UIManager.getColor(isSelected ? "List.selectionBackground" : "List.background")); + add(spacer, BorderLayout.CENTER); + } + setBackground(UIManager.getColor(isSelected ? "List.selectionBackground" : "List.background")); + return this; + } public abstract String getElementText(PsiElement element); @@ -55,37 +92,37 @@ public abstract class PsiElementListCellRenderer extends ColoredListCellRenderer protected abstract int getIconFlags(); - protected Icon getIcon(PsiElement element){ + protected Icon getIcon(PsiElement element) { return element.getIcon(getIconFlags()); } - public Comparator getComparator(){ + public Comparator getComparator() { return new Comparator() { public int compare(Object o1, Object o2) { return getText(o1).compareTo(getText(o2)); } - private String getText(Object o){ - if (o instanceof PsiElement){ + private String getText(Object o) { + if (o instanceof PsiElement) { PsiElement element = (PsiElement)o; String elementText = getElementText(element); String containerText = getContainerText(element); return containerText != null ? elementText + " " + containerText : elementText; } - else{ + else { return o.toString(); } } }; } - public void installSpeedSearch(JList list){ - new ListSpeedSearch(list){ - protected String getElementText(Object o){ - if (o instanceof PsiElement){ + public void installSpeedSearch(JList list) { + new ListSpeedSearch(list) { + protected String getElementText(Object o) { + if (o instanceof PsiElement) { return PsiElementListCellRenderer.this.getElementText((PsiElement)o); } - else{ + else { return o.toString(); } } diff --git a/source/com/intellij/ide/util/PsiElementModuleRenderer.java b/source/com/intellij/ide/util/PsiElementModuleRenderer.java new file mode 100644 index 000000000000..b9ec4ec0c8e2 --- /dev/null +++ b/source/com/intellij/ide/util/PsiElementModuleRenderer.java @@ -0,0 +1,91 @@ +package com.intellij.ide.util; + +import com.intellij.ide.IconUtilEx; +import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.impl.ModuleUtil; +import com.intellij.openapi.roots.*; +import com.intellij.openapi.util.IconLoader; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiFile; + +import javax.swing.*; +import java.awt.*; + +public class PsiElementModuleRenderer extends DefaultListCellRenderer{ + private static final Icon TEST_ICON = IconLoader.getIcon("/nodes/testSourceFolder.png"); + private static final Icon LIB_ICON = IconLoader.getIcon("/nodes/ppLibClosed.png"); + + public Component getListCellRendererComponent( + JList list, + Object value, + int index, + boolean isSelected, + boolean cellHasFocus) { + final Component listCellRendererComponent = super.getListCellRendererComponent(list, value, index, isSelected, + cellHasFocus); + customizeCellRenderer(list, value, index, isSelected, cellHasFocus); + return listCellRendererComponent; + } + + protected void customizeCellRenderer( + JList list, + Object value, + int index, + boolean selected, + boolean hasFocus + ) { + if (value instanceof PsiElement) { + PsiElement element = (PsiElement)value; + PsiFile psiFile = element.getContainingFile(); + Module module = ModuleUtil.findModuleForPsiElement(element); + final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(element.getProject()).getFileIndex(); + if (module != null) { + boolean inTestSource = false; + if (psiFile != null) { + VirtualFile vFile = psiFile.getVirtualFile(); + if (vFile != null) { + inTestSource = fileIndex.isInTestSourceContent(vFile); + } + } + setText(module.getName()); + if (inTestSource) { + setIcon(TEST_ICON); + } + else { + setIcon(module.getModuleType().getNodeIcon(false)); + } + } else { + if (psiFile != null) { + VirtualFile vFile = psiFile.getVirtualFile(); + if (vFile != null) { + final boolean isInLibraries = fileIndex.isInLibrarySource(vFile) || fileIndex.isInLibraryClasses(vFile); + if (isInLibraries){ + setIcon(LIB_ICON); + OrderEntry[] orders = fileIndex.getOrderEntriesForFile(vFile); + for (int i = 0; i < orders.length; i++) { + OrderEntry order = orders[i]; + if (order instanceof LibraryOrderEntry || order instanceof JdkOrderEntry){ + setText(order.getPresentableName()); + break; + } + } + } else { + setIcon(IconUtilEx.getEmptyIcon(false)); + setText(value.toString()); + } + } + } + } + } + else { + setIcon(IconUtilEx.getEmptyIcon(false)); + setText(value == null ? "" : value.toString()); + } + setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 2)); + setHorizontalTextPosition(SwingConstants.LEFT); + setBackground(UIManager.getColor(selected ? "List.selectionBackground" : "List.background")); + setFont(UIManager.getFont("List.font")); + setForeground(selected ? UIManager.getColor("List.selectionForeground") : UIManager.getColor("textInactiveText")); + } +} diff --git a/source/com/intellij/ide/util/TreeClassChooserDialog.java b/source/com/intellij/ide/util/TreeClassChooserDialog.java index 0163d95236c1..a9fb25aa9b6b 100644 --- a/source/com/intellij/ide/util/TreeClassChooserDialog.java +++ b/source/com/intellij/ide/util/TreeClassChooserDialog.java @@ -6,10 +6,13 @@ import com.intellij.ide.projectView.impl.AbstractProjectTreeStructure; import com.intellij.ide.projectView.impl.ProjectAbstractTreeStructureBase; import com.intellij.ide.projectView.impl.ProjectTreeBuilder; import com.intellij.ide.projectView.impl.nodes.ClassTreeNode; -import com.intellij.ide.util.gotoByName.*; +import com.intellij.ide.util.gotoByName.ChooseByNamePanel; +import com.intellij.ide.util.gotoByName.ChooseByNamePopup; +import com.intellij.ide.util.gotoByName.ChooseByNamePopupComponent; +import com.intellij.ide.util.gotoByName.GotoClassModel; import com.intellij.ide.util.treeView.AlphaComparator; import com.intellij.ide.util.treeView.NodeRenderer; -import com.intellij.ide.actions.GotoClassAction; +import com.intellij.navigation.NavigationItem; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.project.Project; @@ -24,7 +27,6 @@ import com.intellij.ui.TreeSpeedSearch; import com.intellij.util.containers.FilteringIterator; import com.intellij.util.ui.Tree; import com.intellij.util.ui.tree.TreeUtil; -import com.intellij.navigation.NavigationItem; import javax.swing.*; import javax.swing.event.ChangeEvent; @@ -55,7 +57,7 @@ public class TreeClassChooserDialog extends DialogWrapper implements TreeClassCh private TreeClassChooser.ClassFilter myClassFilter; private final PsiClass myInitialClass; private final PsiClassChildrenSource myClassChildrens; - + private boolean myAddLocation = true; @@ -120,6 +122,10 @@ public class TreeClassChooserDialog extends DialogWrapper implements TreeClassCh }); } + public void setAddLocation(final boolean addLocation) { + myAddLocation = addLocation; + } + protected JComponent createCenterPanel() { myModel = new DefaultTreeModel(new DefaultMutableTreeNode()); myTree = new Tree(myModel); @@ -203,7 +209,7 @@ public class TreeClassChooserDialog extends DialogWrapper implements TreeClassCh if (myInitialClass != null) { name = myInitialClass.getName(); } - myGotoByNamePanel = new ChooseByNamePanel(myProject, new MyGotoClassModel(), name) { + myGotoByNamePanel = new ChooseByNamePanel(myProject, new MyGotoClassModel(myAddLocation), name) { protected void close(boolean isOk) { super.close(isOk); @@ -272,7 +278,7 @@ public class TreeClassChooserDialog extends DialogWrapper implements TreeClassCh } public void showPopup() { - ChooseByNamePopup popup = ChooseByNamePopup.createPopup(myProject, new MyGotoClassModel()); + ChooseByNamePopup popup = ChooseByNamePopup.createPopup(myProject, new MyGotoClassModel(myAddLocation)); popup.invoke(new ChooseByNamePopupComponent.Callback() { public void onClose () { @@ -342,8 +348,10 @@ public class TreeClassChooserDialog extends DialogWrapper implements TreeClassCh } private class MyGotoClassModel extends GotoClassModel { - public MyGotoClassModel() { + private boolean myAddLocation; + public MyGotoClassModel(final boolean addLocation) { super(myProject); + myAddLocation = addLocation; } public Object[] getElementsByName(final String name, final boolean checkBoxState) { @@ -362,6 +370,12 @@ public class TreeClassChooserDialog extends DialogWrapper implements TreeClassCh public String getPromptText() { return null; } + + public PsiElementListCellRenderer getListCellRenderer() { + final PsiElementListCellRenderer listCellRenderer = super.getListCellRenderer(); + listCellRenderer.setAddLocation(myAddLocation); + return listCellRenderer; + } } private class MyCallback extends ChooseByNamePopupComponent.Callback {