use of com.intellij.ui.awt.RelativeRectangle in project intellij-community by JetBrains.
the class DnDManagerImpl method showHighlighter.
void showHighlighter(JLayeredPane layeredPane, final RelativeRectangle rectangle, final int aType, final DnDEvent event) {
final Rectangle bounds = rectangle.getRectangleOn(layeredPane);
showHighlighter(layeredPane, event, bounds, aType);
}
use of com.intellij.ui.awt.RelativeRectangle 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 com.intellij.ui.awt.RelativeRectangle in project intellij-community by JetBrains.
the class ChangesDnDSupport method update.
@Override
public boolean update(DnDEvent aEvent) {
aEvent.hideHighlighter();
aEvent.setDropPossible(false, "");
Object attached = aEvent.getAttachedObject();
if (!(attached instanceof ChangeListDragBean))
return false;
final ChangeListDragBean dragBean = (ChangeListDragBean) attached;
if (dragBean.getSourceComponent() != myTree)
return false;
dragBean.setTargetNode(null);
RelativePoint dropPoint = aEvent.getRelativePoint();
Point onTree = dropPoint.getPoint(myTree);
final TreePath dropPath = myTree.getPathForLocation(onTree.x, onTree.y);
if (dropPath == null)
return false;
ChangesBrowserNode dropNode = (ChangesBrowserNode) dropPath.getLastPathComponent();
while (!((ChangesBrowserNode) dropNode.getParent()).isRoot()) {
dropNode = (ChangesBrowserNode) dropNode.getParent();
}
if (!dropNode.canAcceptDrop(dragBean)) {
return false;
}
final Rectangle tableCellRect = myTree.getPathBounds(new TreePath(dropNode.getPath()));
if (fitsInBounds(tableCellRect)) {
aEvent.setHighlighting(new RelativeRectangle(myTree, tableCellRect), DnDEvent.DropTargetHighlightingType.RECTANGLE);
}
aEvent.setDropPossible(true);
dragBean.setTargetNode(dropNode);
return false;
}
use of com.intellij.ui.awt.RelativeRectangle in project intellij-community by JetBrains.
the class LayoutTreeComponent method update.
@Override
public boolean update(DnDEvent aEvent) {
aEvent.setDropPossible(false);
aEvent.hideHighlighter();
final Object object = aEvent.getAttachedObject();
if (object instanceof PackagingElementDraggingObject) {
final DefaultMutableTreeNode parent = findParentCompositeElementNode(aEvent.getRelativePoint().getPoint(myTree));
if (parent != null) {
final PackagingElementDraggingObject draggingObject = (PackagingElementDraggingObject) object;
final PackagingElementNode node = getNode(parent);
if (node != null && draggingObject.canDropInto(node)) {
final PackagingElement element = node.getFirstElement();
if (element instanceof CompositePackagingElement) {
draggingObject.setTargetNode(node);
draggingObject.setTargetElement((CompositePackagingElement<?>) element);
final Rectangle bounds = myTree.getPathBounds(TreeUtil.getPathFromRoot(parent));
aEvent.setHighlighting(new RelativeRectangle(myTree, bounds), DnDEvent.DropTargetHighlightingType.RECTANGLE);
aEvent.setDropPossible(true);
}
}
}
}
return false;
}
use of com.intellij.ui.awt.RelativeRectangle in project intellij-community by JetBrains.
the class FavoritesPanel method highlight.
private void highlight(FavoritesListNode node, DnDEvent event) {
int pathCount = 0;
Object object = event.getAttachedObject();
if (object instanceof TreePath) {
pathCount = ((TreePath) object).getPathCount();
}
if (node != null) {
TreePath pathToList = myTree.getPath(node);
while (pathToList != null) {
final Object pathObj = pathToList.getLastPathComponent();
if (pathObj instanceof DefaultMutableTreeNode) {
final Object userObject = ((DefaultMutableTreeNode) pathObj).getUserObject();
if (userObject instanceof FavoritesTreeNodeDescriptor) {
if (((FavoritesTreeNodeDescriptor) userObject).getElement() == node) {
break;
}
}
}
pathToList = pathToList.getParentPath();
}
if (pathToList != null) {
Rectangle bounds = myTree.getPathBounds(pathToList);
if (bounds != null) {
if (pathCount == 2) {
FavoritesListNode pathToReorder = FavoritesTreeViewPanel.getListNodeFromPath((TreePath) object);
FavoritesListNode anchorPath = FavoritesTreeViewPanel.getListNodeFromPath(pathToList);
boolean below = event.getPoint().y >= bounds.y + bounds.height / 2;
if (pathToReorder == null || anchorPath == null || !FavoritesManager.getInstance(myProject).canReorder(pathToReorder.getValue(), anchorPath.getValue(), !below)) {
event.hideHighlighter();
return;
}
if (below) {
bounds.y += bounds.height - 2;
}
bounds.height = 2;
event.setHighlighting(new RelativeRectangle(myTree, bounds), DnDEvent.DropTargetHighlightingType.RECTANGLE);
} else {
event.setHighlighting(new RelativeRectangle(myTree, bounds), DnDEvent.DropTargetHighlightingType.RECTANGLE);
}
}
}
} else {
event.hideHighlighter();
}
}
Aggregations