diff options
Diffstat (limited to 'platform/platform-impl/src/com/intellij/ui')
15 files changed, 194 insertions, 100 deletions
diff --git a/platform/platform-impl/src/com/intellij/ui/AbstractExpandableItemsHandler.java b/platform/platform-impl/src/com/intellij/ui/AbstractExpandableItemsHandler.java index 7226ee84e0c6..4e65063e7939 100644 --- a/platform/platform-impl/src/com/intellij/ui/AbstractExpandableItemsHandler.java +++ b/platform/platform-impl/src/com/intellij/ui/AbstractExpandableItemsHandler.java @@ -54,6 +54,16 @@ public abstract class AbstractExpandableItemsHandler<KeyType, ComponentType exte myTipComponent = new TipComponent(); + myTipComponent.addMouseListener(new MouseAdapter() { + @Override + public void mouseExited(MouseEvent e) { + // don't hide the hint if mouse exited to myComponent + if (myComponent.getMousePosition() == null) { + hideHint(); + } + } + }); + myComponent.addMouseListener( new MouseListener() { @Override @@ -63,7 +73,10 @@ public abstract class AbstractExpandableItemsHandler<KeyType, ComponentType exte @Override public void mouseExited(MouseEvent e) { - hideHint(); + // don't hide the hint if mouse exited to it + if (myTipComponent.getMousePosition() == null) { + hideHint(); + } } @Override @@ -319,7 +332,7 @@ public abstract class AbstractExpandableItemsHandler<KeyType, ComponentType exte g.setClip(null); doFillBackground(height, width, g); g.translate(-(visibleRect.x + visibleRect.width - cellBounds.x), 0); - doPaintTooltipImage(renderer, cellBounds, height, g, key); + doPaintTooltipImage(renderer, cellBounds, g, key); if (isPaintBorder()) { g.translate(visibleRect.x + visibleRect.width - cellBounds.x, 0); @@ -354,8 +367,8 @@ public abstract class AbstractExpandableItemsHandler<KeyType, ComponentType exte g.fillRect(0, 0, width, height); } - protected void doPaintTooltipImage(Component rComponent, Rectangle cellBounds, int height, Graphics2D g, KeyType key) { - myRendererPane.paintComponent(g, rComponent, myComponent, 0, 0, cellBounds.width, height, true); + protected void doPaintTooltipImage(Component rComponent, Rectangle cellBounds, Graphics2D g, KeyType key) { + myRendererPane.paintComponent(g, rComponent, myComponent, 0, 0, cellBounds.width, cellBounds.height, true); } protected Rectangle getVisibleRect(KeyType key) { diff --git a/platform/platform-impl/src/com/intellij/ui/CellRendererPanel.java b/platform/platform-impl/src/com/intellij/ui/CellRendererPanel.java index 2c33b7cd1b61..653aba26dae8 100644 --- a/platform/platform-impl/src/com/intellij/ui/CellRendererPanel.java +++ b/platform/platform-impl/src/com/intellij/ui/CellRendererPanel.java @@ -25,6 +25,9 @@ import java.awt.*; * @author gregsh */ public class CellRendererPanel extends JPanel { + public CellRendererPanel() { + super(null); // we do the layout ourselves + } // property change support ---------------- protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) { @@ -46,7 +49,10 @@ public class CellRendererPanel extends JPanel { @Override public void doLayout() { if (getComponentCount() != 1) return; - getComponent(0).setBounds(0, 0, getWidth(), getHeight()); + Insets insets = getInsets(); + getComponent(0).setBounds(insets.left, insets.top, + getWidth() - insets.left - insets.right, + getHeight() - insets.top - insets.bottom); } @Override diff --git a/platform/platform-impl/src/com/intellij/ui/ColorChooserServiceImpl.java b/platform/platform-impl/src/com/intellij/ui/ColorChooserServiceImpl.java index 4bc4213a78ec..355c2a8de3e3 100644 --- a/platform/platform-impl/src/com/intellij/ui/ColorChooserServiceImpl.java +++ b/platform/platform-impl/src/com/intellij/ui/ColorChooserServiceImpl.java @@ -15,10 +15,11 @@ */ package com.intellij.ui; -import com.intellij.psi.PsiElement; import org.jetbrains.annotations.Nullable; import java.awt.*; +import java.util.Arrays; +import java.util.List; /** * @author Konstantin Bulenkov @@ -31,7 +32,7 @@ public class ColorChooserServiceImpl extends ColorChooserService { Color preselectedColor, boolean enableOpacity, ColorPickerListener[] listeners) { - return ColorPicker.showDialog(parent, caption, preselectedColor, enableOpacity, listeners, false); + return showDialog(parent, caption, preselectedColor, enableOpacity, Arrays.asList(listeners), false); } @Nullable @@ -42,6 +43,17 @@ public class ColorChooserServiceImpl extends ColorChooserService { boolean enableOpacity, ColorPickerListener[] listeners, boolean opacityInPercent) { + return showDialog(parent, caption, preselectedColor, enableOpacity, Arrays.asList(listeners), opacityInPercent); + } + + @Nullable + @Override + public Color showDialog(Component parent, + String caption, + Color preselectedColor, + boolean enableOpacity, + List<ColorPickerListener> listeners, + boolean opacityInPercent) { return ColorPicker.showDialog(parent, caption, preselectedColor, enableOpacity, listeners, opacityInPercent); } } diff --git a/platform/platform-impl/src/com/intellij/ui/ColorPicker.java b/platform/platform-impl/src/com/intellij/ui/ColorPicker.java index d78e68137df1..e7b93684ace8 100644 --- a/platform/platform-impl/src/com/intellij/ui/ColorPicker.java +++ b/platform/platform-impl/src/com/intellij/ui/ColorPicker.java @@ -46,6 +46,7 @@ import java.awt.image.ImageObserver; import java.awt.image.MemoryImageSource; import java.text.ParseException; import java.util.ArrayList; +import java.util.Collections; import java.util.List; /** @@ -64,7 +65,7 @@ public class ColorPicker extends JPanel implements ColorListener, DocumentListen private final JTextField myBlue; private final JTextField myHex; private final Alarm myUpdateQueue; - private final ColorPickerListener[] myExternalListeners; + private final List<ColorPickerListener> myExternalListeners; private final boolean myOpacityInPercent; @@ -88,13 +89,13 @@ public class ColorPicker extends JPanel implements ColorListener, DocumentListen }; public ColorPicker(@NotNull Disposable parent, @Nullable Color color, boolean enableOpacity) { - this(parent, color, true, enableOpacity, new ColorPickerListener[0], false); + this(parent, color, true, enableOpacity, Collections.<ColorPickerListener>emptyList(), false); } private ColorPicker(Disposable parent, @Nullable Color color, boolean restoreColors, boolean enableOpacity, - ColorPickerListener[] listeners, boolean opacityInPercent) { + List<ColorPickerListener> listeners, boolean opacityInPercent) { myUpdateQueue = new Alarm(Alarm.ThreadToUse.SWING_THREAD, parent); myRed = createColorField(false); myGreen = createColorField(false); @@ -332,7 +333,7 @@ public class ColorPicker extends JPanel implements ColorListener, DocumentListen String caption, Color preselectedColor, boolean enableOpacity, - ColorPickerListener[] listeners, + List<ColorPickerListener> listeners, boolean opacityInPercent) { final ColorPickerDialog dialog = new ColorPickerDialog(parent, caption, preselectedColor, enableOpacity, listeners, opacityInPercent); dialog.show(); @@ -884,7 +885,7 @@ public class ColorPicker extends JPanel implements ColorListener, DocumentListen static class ColorPickerDialog extends DialogWrapper { private final Color myPreselectedColor; - private final ColorPickerListener[] myListeners; + private final List<ColorPickerListener> myListeners; private ColorPicker myColorPicker; private final boolean myEnableOpacity; private ColorPipette myPicker; @@ -894,7 +895,7 @@ public class ColorPicker extends JPanel implements ColorListener, DocumentListen String caption, @Nullable Color preselectedColor, boolean enableOpacity, - ColorPickerListener[] listeners, + List<ColorPickerListener> listeners, boolean opacityInPercent) { super(parent, true); myListeners = listeners; diff --git a/platform/platform-impl/src/com/intellij/ui/ColorPickerListenerFactory.java b/platform/platform-impl/src/com/intellij/ui/ColorPickerListenerFactory.java index 6f1c0479eeca..dbed5e5abb24 100644 --- a/platform/platform-impl/src/com/intellij/ui/ColorPickerListenerFactory.java +++ b/platform/platform-impl/src/com/intellij/ui/ColorPickerListenerFactory.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. @@ -17,29 +17,32 @@ package com.intellij.ui; import com.intellij.openapi.extensions.ExtensionPointName; import com.intellij.psi.PsiElement; -import com.intellij.util.Function; +import com.intellij.util.SmartList; import com.intellij.util.containers.ContainerUtil; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.List; -/** - * User: ksafonov - */ public abstract class ColorPickerListenerFactory { private static final ExtensionPointName<ColorPickerListenerFactory> EP_NAME = ExtensionPointName.create("com.intellij.colorPickerListenerFactory"); - public static ColorPickerListener[] createListenersFor(@Nullable final PsiElement element) { - final List<ColorPickerListener> listeners = - ContainerUtil.mapNotNull(EP_NAME.getExtensions(), new Function<ColorPickerListenerFactory, ColorPickerListener>() { - @Override - public ColorPickerListener fun(ColorPickerListenerFactory factory) { - return factory.createListener(element); + @NotNull + public static List<ColorPickerListener> createListenersFor(@Nullable PsiElement element) { + List<ColorPickerListener> listeners = null; + for (ColorPickerListenerFactory factory : EP_NAME.getExtensions()) { + ColorPickerListener listener = factory.createListener(element); + if (listener != null) { + if (listeners == null) { + listeners = new SmartList<ColorPickerListener>(); } - }); - return listeners.toArray(new ColorPickerListener[listeners.size()]); + listeners.add(listener); + } + } + return ContainerUtil.notNullize(listeners); } + @Nullable public abstract ColorPickerListener createListener(@Nullable PsiElement element); } diff --git a/platform/platform-impl/src/com/intellij/ui/EditorTextFieldCellRenderer.java b/platform/platform-impl/src/com/intellij/ui/EditorTextFieldCellRenderer.java index e803fa5fd63d..d11e990f8dba 100644 --- a/platform/platform-impl/src/com/intellij/ui/EditorTextFieldCellRenderer.java +++ b/platform/platform-impl/src/com/intellij/ui/EditorTextFieldCellRenderer.java @@ -57,39 +57,39 @@ public abstract class EditorTextFieldCellRenderer implements TableCellRenderer, protected abstract EditorColorsScheme getColorScheme(); - protected abstract String getText(JTable table, Object value, int row, int column); + protected abstract String getText(FontMetrics fontMetrics, JTable table, Object value, int row, int column); protected void customizeEditor(EditorEx editor, Object value, boolean selected, int row, int col) { } @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { - String text = getText(table, value, row, column); MyPanel panel = getEditorPanel(table); EditorEx editor = panel.editor; int tableFontSize = table.getFont().getSize(); if (editor.getColorsScheme().getEditorFontSize() != tableFontSize) { editor.getColorsScheme().setEditorFontSize(tableFontSize); } - setText(editor, text); - - if (isSelected) { - ((EditorImpl)editor).setPaintSelection(true); - editor.getColorsScheme().setColor(EditorColors.SELECTION_BACKGROUND_COLOR, table.getSelectionBackground()); - editor.getColorsScheme().setColor(EditorColors.SELECTION_FOREGROUND_COLOR, table.getSelectionForeground()); - editor.getSelectionModel().setSelection(0, editor.getDocument().getTextLength()); - editor.setBackgroundColor(table.getSelectionBackground()); - } - else { - ((EditorImpl)editor).setPaintSelection(false); - editor.getSelectionModel().setSelection(0, 0); - boolean selectedRow = table.getSelectedRowCount() > 0 && table.getSelectedRows()[table.getSelectedRowCount() - 1] == row; - editor.setBackgroundColor(!selectedRow ? table.getBackground() : getColorScheme().getColor(EditorColors.CARET_ROW_COLOR)); - } + setText(editor, getText(((EditorImpl)editor).getFontMetrics(Font.PLAIN), table, value, row, column)); + + ((EditorImpl)editor).setPaintSelection(isSelected); + editor.getSelectionModel().setSelection(0, isSelected ? editor.getDocument().getTextLength() : 0); + editor.getColorsScheme().setColor(EditorColors.SELECTION_BACKGROUND_COLOR, table.getSelectionBackground()); + editor.getColorsScheme().setColor(EditorColors.SELECTION_FOREGROUND_COLOR, table.getSelectionForeground()); + editor.setBackgroundColor(getCellBackgroundColor(getColorScheme(), table, isSelected, row)); + + panel.setBorder(null); // prevents double border painting when ExtendedItemRendererComponentWrapper is used + customizeEditor(editor, value, isSelected, row, column); return panel; } + public static Color getCellBackgroundColor(EditorColorsScheme colorsScheme, JTable table, boolean isSelected, int row) { + return isSelected ? table.getSelectionBackground() : + table.getSelectionModel().getLeadSelectionIndex() == row ? colorsScheme.getColor(EditorColors.CARET_ROW_COLOR) : + table.getBackground(); + } + @NotNull private MyPanel getEditorPanel(JTable table) { MyPanel panel = (MyPanel)table.getClientProperty(MY_PANEL_PROPERTY); @@ -142,6 +142,16 @@ public abstract class EditorTextFieldCellRenderer implements TableCellRenderer, } @Override + protected void paintComponent(Graphics g) { + if (getBorder() == null) return; + Color oldColor = g.getColor(); + Rectangle clip = g.getClipBounds(); + g.setColor(editor.getBackgroundColor()); + g.fillRect(clip.x, clip.y, clip.width, clip.height); + g.setColor(oldColor); + } + + @Override public void dispose() { EditorFactory.getInstance().releaseEditor(editor); } diff --git a/platform/platform-impl/src/com/intellij/ui/ShowColorPickerAction.java b/platform/platform-impl/src/com/intellij/ui/ShowColorPickerAction.java index 95f4b7e33861..5327c84c3c8d 100644 --- a/platform/platform-impl/src/com/intellij/ui/ShowColorPickerAction.java +++ b/platform/platform-impl/src/com/intellij/ui/ShowColorPickerAction.java @@ -18,12 +18,12 @@ package com.intellij.ui; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.CommonDataKeys; -import com.intellij.openapi.actionSystem.LangDataKeys; import com.intellij.openapi.project.Project; import com.intellij.openapi.wm.IdeFrame; import com.intellij.openapi.wm.WindowManager; import javax.swing.*; +import java.util.List; /** * @author Konstantin Bulenkov @@ -34,9 +34,8 @@ public class ShowColorPickerAction extends AnAction { final Project project = e.getProject(); JComponent root = rootComponent(project); if (root != null) { - ColorPickerListener[] listeners = ColorPickerListenerFactory.createListenersFor(e.getData(CommonDataKeys.PSI_ELEMENT)); - final ColorPicker.ColorPickerDialog picker = - new ColorPicker.ColorPickerDialog(root, "Color Picker", null, true, listeners, true); + List<ColorPickerListener> listeners = ColorPickerListenerFactory.createListenersFor(e.getData(CommonDataKeys.PSI_ELEMENT)); + ColorPicker.ColorPickerDialog picker = new ColorPicker.ColorPickerDialog(root, "Color Picker", null, true, listeners, true); picker.setModal(false); picker.show(); } diff --git a/platform/platform-impl/src/com/intellij/ui/Splash.java b/platform/platform-impl/src/com/intellij/ui/Splash.java index 0f4147f61753..023cef7bac06 100644 --- a/platform/platform-impl/src/com/intellij/ui/Splash.java +++ b/platform/platform-impl/src/com/intellij/ui/Splash.java @@ -44,6 +44,7 @@ import java.util.List; */ public class Splash extends JDialog implements StartupProgress { @Nullable public static Rectangle BOUNDS; + private final Icon myImage; private int myProgressHeight = 2; private Color myProgressColor = null; @@ -84,8 +85,16 @@ public class Splash extends JDialog implements StartupProgress { } private void setLocationInTheCenterOfScreen() { - Rectangle deviceBounds = getGraphicsConfiguration().getBounds(); - setLocation((deviceBounds.width - getWidth()) / 2, (deviceBounds.height - getHeight()) / 2); + Rectangle bounds = getGraphicsConfiguration().getBounds(); + if (SystemInfo.isWindows) { + Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(getGraphicsConfiguration()); + int x = insets.left + (bounds.width - insets.left - insets.right - getWidth()) / 2; + int y = insets.top + (bounds.height - insets.top - insets.bottom - getHeight()) / 2; + setLocation(x, y); + } + else { + setLocation((bounds.width - getWidth()) / 2, (bounds.height - getHeight()) / 2); + } } public Splash(ApplicationInfoEx info) { diff --git a/platform/platform-impl/src/com/intellij/ui/TableExpandableItemsHandler.java b/platform/platform-impl/src/com/intellij/ui/TableExpandableItemsHandler.java index af4707c60ec3..b7704a687441 100644 --- a/platform/platform-impl/src/com/intellij/ui/TableExpandableItemsHandler.java +++ b/platform/platform-impl/src/com/intellij/ui/TableExpandableItemsHandler.java @@ -106,22 +106,12 @@ public class TableExpandableItemsHandler extends AbstractExpandableItemsHandler< } public Pair<Component, Rectangle> getCellRendererAndBounds(TableCell key) { - Rectangle cellRect = getCellRect(key); - - int modelColumnIndex = myComponent.convertColumnIndexToModel(key.column); - final int modelRowIndex = myComponent.convertRowIndexToModel(key.row); - TableModel model = myComponent.getModel(); - if (key.row < 0 || key.row >= model.getRowCount() || key.column < 0 || key.column >= model.getColumnCount()) { + if (key.row < 0 || key.row >= myComponent.getRowCount() || key.column < 0 || key.column >= myComponent.getColumnCount()) { return null; } - Component renderer = myComponent - .getCellRenderer(key.row, key.column) - .getTableCellRendererComponent(myComponent, - model.getValueAt(modelRowIndex, modelColumnIndex), - myComponent.getSelectionModel().isSelectedIndex(key.row), - myComponent.hasFocus(), - key.row, key.column); + Rectangle cellRect = getCellRect(key); + Component renderer = myComponent.prepareRenderer(myComponent.getCellRenderer(key.row, key.column), key.row, key.column); cellRect.width = renderer.getPreferredSize().width; return Pair.create(renderer, cellRect); diff --git a/platform/platform-impl/src/com/intellij/ui/TableSpeedSearch.java b/platform/platform-impl/src/com/intellij/ui/TableSpeedSearch.java index 93a9d9390d33..b596204e6ad2 100644 --- a/platform/platform-impl/src/com/intellij/ui/TableSpeedSearch.java +++ b/platform/platform-impl/src/com/intellij/ui/TableSpeedSearch.java @@ -55,7 +55,9 @@ public class TableSpeedSearch extends SpeedSearchBase<JTable> { @Override protected boolean isSpeedSearchEnabled() { - return !getComponent().isEditing() && super.isSpeedSearchEnabled(); + JTable table = getComponent(); + boolean tableIsNotEmpty = table.getRowCount() != 0 && table.getColumnCount() != 0; + return tableIsNotEmpty && !table.isEditing() && super.isSpeedSearchEnabled(); } @Override diff --git a/platform/platform-impl/src/com/intellij/ui/TreeExpandableItemsHandler.java b/platform/platform-impl/src/com/intellij/ui/TreeExpandableItemsHandler.java index ad5466267dba..b24e10b943f4 100644 --- a/platform/platform-impl/src/com/intellij/ui/TreeExpandableItemsHandler.java +++ b/platform/platform-impl/src/com/intellij/ui/TreeExpandableItemsHandler.java @@ -148,7 +148,6 @@ public class TreeExpandableItemsHandler extends AbstractExpandableItemsHandler<I @Override protected void doPaintTooltipImage(final Component rComponent, final Rectangle cellBounds, - final int height, final Graphics2D g, Integer key) { final boolean opaque = rComponent.isOpaque(); @@ -169,7 +168,7 @@ public class TreeExpandableItemsHandler extends AbstractExpandableItemsHandler<I rComponent.setBackground(bg); } - super.doPaintTooltipImage(rComponent, cellBounds, height, g, key); + super.doPaintTooltipImage(rComponent, cellBounds, g, key); if (rComponent instanceof JComponent) { ((JComponent)rComponent).setOpaque(opaque); diff --git a/platform/platform-impl/src/com/intellij/ui/messages/JBMacMessages.java b/platform/platform-impl/src/com/intellij/ui/messages/JBMacMessages.java index 6ce0375e75aa..2a70b61c6e8a 100644 --- a/platform/platform-impl/src/com/intellij/ui/messages/JBMacMessages.java +++ b/platform/platform-impl/src/com/intellij/ui/messages/JBMacMessages.java @@ -73,10 +73,14 @@ public class JBMacMessages extends MacMessagesEmulation { Icon icon = errorStyle ? UIUtil.getErrorIcon() : UIUtil.getInformationIcon(); - focusedOptionIndex = (defaultOptionIndex == focusedOptionIndex) ? buttons.length - 1 : focusedOptionIndex; + if (focusedOptionIndex != -1) { + focusedOptionIndex = (defaultOptionIndex == focusedOptionIndex) ? buttons.length - 1 : focusedOptionIndex; + } + + final String defaultOptionTitle = defaultOptionIndex == -1 ? null : buttons[defaultOptionIndex]; + final String focusedButtonTitle = focusedOptionIndex == -1 ? null : buttons[focusedOptionIndex]; - SheetMessage sheetMessage = new SheetMessage(window, title, message, icon, buttons, doNotAskDialogOption, buttons[defaultOptionIndex], - buttons[focusedOptionIndex]); + final SheetMessage sheetMessage = new SheetMessage(window, title, message, icon, buttons, doNotAskDialogOption, defaultOptionTitle, focusedButtonTitle); String result = sheetMessage.getResult(); for (int i = 0; i < buttons.length; i++) { if (result.equals(buttons[i])) { diff --git a/platform/platform-impl/src/com/intellij/ui/popup/AbstractPopup.java b/platform/platform-impl/src/com/intellij/ui/popup/AbstractPopup.java index e1c326d33cd8..78802ccdf6bb 100644 --- a/platform/platform-impl/src/com/intellij/ui/popup/AbstractPopup.java +++ b/platform/platform-impl/src/com/intellij/ui/popup/AbstractPopup.java @@ -337,7 +337,7 @@ public class AbstractPopup implements JBPopup { } public void setShowHints(boolean show) { - final Window ancestor = SwingUtilities.getWindowAncestor(myComponent); + final Window ancestor = getContentWindow(myComponent); if (ancestor instanceof RootPaneContainer) { final JRootPane rootPane = ((RootPaneContainer)ancestor).getRootPane(); if (rootPane != null) { @@ -757,7 +757,33 @@ public class AbstractPopup implements JBPopup { PopupComponent.Factory factory = getFactory(myForcedHeavyweight || myResizable, forcedDialog); myNativePopup = factory.isNativePopup(); - myPopup = factory.getPopup(myOwner, myContent, targetBounds.x, targetBounds.y, this); + Component popupOwner = myOwner; + if (popupOwner instanceof RootPaneContainer) { + // JDK uses cached heavyweight popup for a window ancestor + RootPaneContainer root = (RootPaneContainer)popupOwner; + popupOwner = root.getRootPane(); + } + if (LOG.isDebugEnabled()) { + LOG.debug("expected preferred size: " + myContent.getPreferredSize()); + } + myPopup = factory.getPopup(popupOwner, myContent, targetBounds.x, targetBounds.y, this); + if (LOG.isDebugEnabled()) { + LOG.debug(" actual preferred size: " + myContent.getPreferredSize()); + } + if ((targetBounds.width != myContent.getWidth()) || (targetBounds.height != myContent.getHeight())) { + // JDK uses cached heavyweight popup that is not initialized properly + LOG.debug("the expected size is not equal to the actual size"); + Window popup = myPopup.getWindow(); + if (popup != null) { + popup.setSize(targetBounds.width, targetBounds.height); + if (myContent.getParent().getComponentCount() != 1) { + LOG.debug("unexpected count of components in heavy-weight popup"); + } + } + else { + LOG.debug("cannot fix size for non-heavy-weight popup"); + } + } if (myResizable) { final JRootPane root = myContent.getRootPane(); @@ -799,13 +825,10 @@ public class AbstractPopup implements JBPopup { listener.beforeShown(new LightweightWindowEvent(this)); } - // can be improved by moving in myPopup code - myPopup.getWindow().setSize(myContent.getSize()); - myPopup.setRequestFocus(myRequestFocus); myPopup.show(); - final Window window = SwingUtilities.getWindowAncestor(myContent); + final Window window = getContentWindow(myContent); myWindow = window; @@ -1185,14 +1208,17 @@ public class AbstractPopup implements JBPopup { size = computeWindowSize(size); - final Window window = SwingUtilities.getWindowAncestor(myContent); - window.setSize(size); + final Window window = getContentWindow(myContent); + if (window != null) { + window.setSize(size); + } } public void pack() { - final Window window = SwingUtilities.getWindowAncestor(myContent); - - window.pack(); + final Window window = getContentWindow(myContent); + if (window != null) { + window.pack(); + } } public JComponent getComponent() { @@ -1211,6 +1237,10 @@ public class AbstractPopup implements JBPopup { } myDisposed = true; + if (LOG.isDebugEnabled()) { + LOG.debug("start disposing " + myContent); + } + Disposer.dispose(this, false); ApplicationManager.getApplication().assertIsDispatchThread(); @@ -1257,6 +1287,10 @@ public class AbstractPopup implements JBPopup { IdeFocusManager.getInstance(myProject).typeAheadUntil(typeAheadDone); getFocusManager().doWhenFocusSettlesDown(runFinal); } + + if (LOG.isDebugEnabled()) { + LOG.debug("stop disposing content"); + } } private void resetWindow() { @@ -1385,15 +1419,27 @@ public class AbstractPopup implements JBPopup { } public static Window moveTo(JComponent content, Point screenPoint, final Dimension headerCorrectionSize) { - setDefaultCursor(content); - final Window wnd = SwingUtilities.getWindowAncestor(content); - if (headerCorrectionSize != null) { - screenPoint.y -= headerCorrectionSize.height; + final Window wnd = getContentWindow(content); + if (wnd != null) { + wnd.setCursor(Cursor.getDefaultCursor()); + if (headerCorrectionSize != null) { + screenPoint.y -= headerCorrectionSize.height; + } + wnd.setLocation(screenPoint); } - wnd.setLocation(screenPoint); return wnd; } + private static Window getContentWindow(Component content) { + Window window = SwingUtilities.getWindowAncestor(content); + if (window == null) { + if (LOG.isDebugEnabled()) { + LOG.debug("no window ancestor for " + content); + } + } + return window; + } + @Override public Point getLocationOnScreen() { Dimension headerCorrectionSize = myLocateByContent ? myHeaderPanel.getPreferredSize() : null; @@ -1467,7 +1513,7 @@ public class AbstractPopup implements JBPopup { } public static void setDefaultCursor(JComponent content) { - final Window wnd = SwingUtilities.getWindowAncestor(content); + final Window wnd = getContentWindow(content); if (wnd != null) { wnd.setCursor(Cursor.getDefaultCursor()); } diff --git a/platform/platform-impl/src/com/intellij/ui/popup/PopupFactoryImpl.java b/platform/platform-impl/src/com/intellij/ui/popup/PopupFactoryImpl.java index c7194ca5b4c4..2d7a8e3fb276 100644 --- a/platform/platform-impl/src/com/intellij/ui/popup/PopupFactoryImpl.java +++ b/platform/platform-impl/src/com/intellij/ui/popup/PopupFactoryImpl.java @@ -227,8 +227,11 @@ public class PopupFactoryImpl extends JBPopupFactory { Presentation presentation = new Presentation(); presentation.setDescription(action.getTemplatePresentation().getDescription()); final String actualActionPlace = actionPlace == null ? ActionPlaces.UNKNOWN : actionPlace; - action.update(new AnActionEvent(null, DataManager.getInstance().getDataContext(myComponent), actualActionPlace, presentation, - ActionManager.getInstance(), 0)); + final AnActionEvent actionEvent = + new AnActionEvent(null, DataManager.getInstance().getDataContext(myComponent), actualActionPlace, presentation, + ActionManager.getInstance(), 0); + actionEvent.setInjectedContext(action.isInInjectedContext()); + action.update(actionEvent); ActionMenu.showDescriptionInStatusBar(true, myComponent, presentation.getDescription()); } }); @@ -730,7 +733,10 @@ public class PopupFactoryImpl extends JBPopupFactory { myFinalRunnable = new Runnable() { @Override public void run() { - action.actionPerformed(new AnActionEvent(null, dataContext, ActionPlaces.UNKNOWN, action.getTemplatePresentation().clone(), ActionManager.getInstance(), eventModifiers)); + final AnActionEvent event = new AnActionEvent(null, dataContext, ActionPlaces.UNKNOWN, action.getTemplatePresentation().clone(), + ActionManager.getInstance(), eventModifiers); + event.setInjectedContext(action.isInInjectedContext()); + action.actionPerformed(event); } }; return FINAL_CHOICE; @@ -879,7 +885,10 @@ public class PopupFactoryImpl extends JBPopupFactory { @NotNull private AnActionEvent createActionEvent(@NotNull AnAction actionGroup) { - return new AnActionEvent(null, myDataContext, myActionPlace, getPresentation(actionGroup), ActionManager.getInstance(), 0); + final AnActionEvent actionEvent = + new AnActionEvent(null, myDataContext, myActionPlace, getPresentation(actionGroup), ActionManager.getInstance(), 0); + actionEvent.setInjectedContext(actionGroup.isInInjectedContext()); + return actionEvent; } private void appendActionsFromGroup(@NotNull ActionGroup actionGroup) { diff --git a/platform/platform-impl/src/com/intellij/ui/popup/list/GroupedItemsListRenderer.java b/platform/platform-impl/src/com/intellij/ui/popup/list/GroupedItemsListRenderer.java index 72f2e1dc3b37..9383f5c3f08e 100644 --- a/platform/platform-impl/src/com/intellij/ui/popup/list/GroupedItemsListRenderer.java +++ b/platform/platform-impl/src/com/intellij/ui/popup/list/GroupedItemsListRenderer.java @@ -18,9 +18,7 @@ package com.intellij.ui.popup.list; import com.intellij.openapi.ui.popup.ListItemDescriptor; import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.util.text.StringUtil; -import com.intellij.ui.EngravedLabel; import com.intellij.ui.ErrorLabel; -import com.intellij.ui.Gray; import com.intellij.ui.GroupedElementsRenderer; import com.intellij.ui.components.panels.OpaquePanel; @@ -58,15 +56,8 @@ public class GroupedItemsListRenderer extends GroupedElementsRenderer.List imple @Override protected JComponent createItemComponent() { - if (Registry.is("ide.new.project.settings")) { - myTextLabel = new EngravedLabel(); - myTextLabel.setFont(myTextLabel.getFont().deriveFont(Font.BOLD)); - myTextLabel.setForeground(Gray._240); - } else { - myTextLabel = new ErrorLabel(); - myTextLabel.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); - } - + myTextLabel = new ErrorLabel(); + myTextLabel.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); myTextLabel.setOpaque(true); return layoutComponent(myTextLabel); } |