use of java.awt.event.ComponentEvent in project intellij-community by JetBrains.
the class ActionToolbarImpl method showAutoPopup.
private void showAutoPopup() {
if (isPopupShowing())
return;
final ActionGroup group;
if (myOrientation == SwingConstants.HORIZONTAL) {
group = myActionGroup;
} else {
final DefaultActionGroup outside = new DefaultActionGroup();
for (int i = myFirstOutsideIndex; i < myVisibleActions.size(); i++) {
outside.add(myVisibleActions.get(i));
}
group = outside;
}
PopupToolbar popupToolbar = new PopupToolbar(myPlace, group, true, myDataManager, myActionManager, myUpdater.getKeymapManager(), this) {
@Override
protected void onOtherActionPerformed() {
hidePopup();
}
@Override
protected DataContext getDataContext() {
return ActionToolbarImpl.this.getDataContext();
}
};
popupToolbar.setLayoutPolicy(NOWRAP_LAYOUT_POLICY);
popupToolbar.updateActionsImmediately();
Point location;
if (myOrientation == SwingConstants.HORIZONTAL) {
location = getLocationOnScreen();
} else {
location = getLocationOnScreen();
location.y = location.y + getHeight() - popupToolbar.getPreferredSize().height;
}
final ComponentPopupBuilder builder = JBPopupFactory.getInstance().createComponentPopupBuilder(popupToolbar, null);
builder.setResizable(false).setMovable(// fit the screen automatically
true).setRequestFocus(false).setTitle(null).setCancelOnClickOutside(true).setCancelOnOtherWindowOpen(true).setCancelCallback(() -> {
final boolean toClose = myActionManager.isActionPopupStackEmpty();
if (toClose) {
myUpdater.updateActions(false, true);
}
return toClose;
}).setCancelOnMouseOutCallback(new MouseChecker() {
@Override
public boolean check(final MouseEvent event) {
return myAutoPopupRec != null && myActionManager.isActionPopupStackEmpty() && !new RelativeRectangle(ActionToolbarImpl.this, myAutoPopupRec).contains(new RelativePoint(event));
}
});
builder.addListener(new JBPopupAdapter() {
@Override
public void onClosed(LightweightWindowEvent event) {
processClosed();
}
});
myPopup = builder.createPopup();
final AnActionListener.Adapter listener = new AnActionListener.Adapter() {
@Override
public void afterActionPerformed(AnAction action, DataContext dataContext, AnActionEvent event) {
final JBPopup popup = myPopup;
if (popup != null && !popup.isDisposed() && popup.isVisible()) {
popup.cancel();
}
}
};
ActionManager.getInstance().addAnActionListener(listener);
Disposer.register(myPopup, popupToolbar);
Disposer.register(popupToolbar, new Disposable() {
@Override
public void dispose() {
ActionManager.getInstance().removeAnActionListener(listener);
}
});
myPopup.showInScreenCoordinates(this, location);
final Window window = SwingUtilities.getWindowAncestor(this);
if (window != null) {
final ComponentAdapter componentAdapter = new ComponentAdapter() {
@Override
public void componentResized(final ComponentEvent e) {
hidePopup();
}
@Override
public void componentMoved(final ComponentEvent e) {
hidePopup();
}
@Override
public void componentShown(final ComponentEvent e) {
hidePopup();
}
@Override
public void componentHidden(final ComponentEvent e) {
hidePopup();
}
};
window.addComponentListener(componentAdapter);
Disposer.register(popupToolbar, new Disposable() {
@Override
public void dispose() {
window.removeComponentListener(componentAdapter);
}
});
}
}
use of java.awt.event.ComponentEvent in project intellij-community by JetBrains.
the class AdjustComponentWhenShown method install.
public void install(final Component component) {
final ComponentListener listener = new ComponentListener() {
@Override
public void componentResized(ComponentEvent e) {
impl();
}
private void impl() {
if (canExecute()) {
if (init()) {
component.removeComponentListener(this);
myIsAdjusted = true;
}
}
}
@Override
public void componentMoved(ComponentEvent e) {
}
@Override
public void componentShown(ComponentEvent e) {
impl();
}
@Override
public void componentHidden(ComponentEvent e) {
}
};
component.addComponentListener(listener);
}
use of java.awt.event.ComponentEvent in project intellij-community by JetBrains.
the class MultilineTreeCellRenderer method installRenderer.
public static JScrollPane installRenderer(final JTree tree, final MultilineTreeCellRenderer renderer) {
final TreeCellRenderer defaultRenderer = tree.getCellRenderer();
JScrollPane scrollpane = new JBScrollPane(tree) {
private int myAddRemoveCounter = 0;
private boolean myShouldResetCaches = false;
public void setSize(Dimension d) {
boolean isChanged = getWidth() != d.width || myShouldResetCaches;
super.setSize(d);
if (isChanged)
resetCaches();
}
public void reshape(int x, int y, int w, int h) {
boolean isChanged = w != getWidth() || myShouldResetCaches;
super.reshape(x, y, w, h);
if (isChanged)
resetCaches();
}
private void resetCaches() {
resetHeightCache(tree, defaultRenderer, renderer);
myShouldResetCaches = false;
}
public void addNotify() {
//To change body of overriden methods use Options | File Templates.
super.addNotify();
if (myAddRemoveCounter == 0)
myShouldResetCaches = true;
myAddRemoveCounter++;
}
public void removeNotify() {
//To change body of overriden methods use Options | File Templates.
super.removeNotify();
myAddRemoveCounter--;
}
};
scrollpane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollpane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
tree.setCellRenderer(renderer);
scrollpane.addComponentListener(new ComponentAdapter() {
public void componentResized(ComponentEvent e) {
resetHeightCache(tree, defaultRenderer, renderer);
}
public void componentShown(ComponentEvent e) {
// componentResized not called when adding to opened tool window.
// Seems to be BUG#4765299, however I failed to create same code to reproduce it.
// To reproduce it with IDEA: 1. remove this method, 2. Start any Ant task, 3. Keep message window open 4. start Ant task again.
resetHeightCache(tree, defaultRenderer, renderer);
}
});
return scrollpane;
}
use of java.awt.event.ComponentEvent in project intellij-community by JetBrains.
the class ConsoleGutterComponent method updateSize.
public void updateSize(int start, int end) {
int oldAnnotationsWidth = maxContentWidth;
computeMaxAnnotationWidth(start, end);
if (oldAnnotationsWidth != maxContentWidth || myLastPreferredHeight != editor.getPreferredHeight()) {
processComponentEvent(new ComponentEvent(this, ComponentEvent.COMPONENT_RESIZED));
}
repaint();
}
use of java.awt.event.ComponentEvent in project intellij-community by JetBrains.
the class EditConfigurationsDialog method addRunConfiguration.
public void addRunConfiguration(@NotNull final ConfigurationFactory factory) {
final RunConfigurable configurable = (RunConfigurable) getConfigurable();
final SingleConfigurationConfigurable<RunConfiguration> configuration = configurable.createNewConfiguration(factory);
if (!isVisible()) {
getContentPanel().addComponentListener(new ComponentAdapter() {
@Override
public void componentShown(ComponentEvent e) {
if (configuration != null) {
configurable.updateRightPanel(configuration);
getContentPanel().removeComponentListener(this);
}
}
});
}
}
Aggregations