use of com.intellij.ui.PopupHandler in project intellij-community by JetBrains.
the class RepositoryBrowserDialog method createBrowserComponent.
public JComponent createBrowserComponent(final boolean toolWindow) {
JPanel panel = new JPanel();
panel.setLayout(new GridBagLayout());
GridBagConstraints gc = new GridBagConstraints();
gc.gridx = 0;
gc.gridwidth = 1;
gc.gridy = 0;
gc.gridheight = 1;
gc.gridx = 0;
gc.gridwidth = 2;
gc.gridy += 1;
gc.gridheight = 1;
gc.weightx = 1;
gc.weighty = 1;
gc.fill = GridBagConstraints.BOTH;
gc.anchor = GridBagConstraints.WEST;
panel.add(getRepositoryBrowser(), gc);
gc.gridy += 1;
gc.weighty = 0;
gc.fill = GridBagConstraints.HORIZONTAL;
panel.add(new JLabel(), gc);
Collection<String> urls = SvnApplicationSettings.getInstance().getCheckoutURLs();
ArrayList<SVNURL> svnURLs = new ArrayList<>();
for (final String url : urls) {
try {
svnURLs.add(SVNURL.parseURIEncoded(url));
} catch (SVNException e) {
//
}
}
getRepositoryBrowser().setRepositoryURLs(svnURLs.toArray(new SVNURL[svnURLs.size()]), myShowFiles);
getRepositoryBrowser().getRepositoryTree().addMouseListener(new PopupHandler() {
@Override
public void invokePopup(Component comp, int x, int y) {
JTree tree = getRepositoryBrowser().getRepositoryTree();
int row = tree.getRowForLocation(x, y);
if (row >= 0) {
tree.setSelectionRow(row);
}
JPopupMenu popupMenu = createPopup(toolWindow);
if (popupMenu != null) {
popupMenu.show(comp, x, y);
}
}
});
return panel;
}
use of com.intellij.ui.PopupHandler in project intellij-community by JetBrains.
the class CustomizationUtil method installPopupHandler.
public static MouseListener installPopupHandler(JComponent component, @NotNull final String groupId, final String place) {
if (ApplicationManager.getApplication() == null)
return new MouseAdapter() {
};
PopupHandler popupHandler = new PopupHandler() {
@Override
public void invokePopup(Component comp, int x, int y) {
ActionGroup group = (ActionGroup) CustomActionsSchema.getInstance().getCorrectedAction(groupId);
final ActionPopupMenu popupMenu = ActionManager.getInstance().createActionPopupMenu(place, group);
popupMenu.getComponent().show(comp, x, y);
}
};
component.addMouseListener(popupHandler);
return popupHandler;
}
use of com.intellij.ui.PopupHandler in project intellij-community by JetBrains.
the class NewRecentProjectPanel method createList.
@Override
protected JBList createList(AnAction[] recentProjectActions, Dimension size) {
final JBList list = super.createList(recentProjectActions, size);
list.setBackground(FlatWelcomeFrame.getProjectsBackground());
list.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
Object selected = list.getSelectedValue();
final ProjectGroup group;
if (selected instanceof ProjectGroupActionGroup) {
group = ((ProjectGroupActionGroup) selected).getGroup();
} else {
group = null;
}
int keyCode = e.getKeyCode();
if (keyCode == KeyEvent.VK_RIGHT) {
if (group != null) {
if (!group.isExpanded()) {
group.setExpanded(true);
ListModel model = ((NameFilteringListModel) list.getModel()).getOriginalModel();
int index = list.getSelectedIndex();
RecentProjectsWelcomeScreenActionBase.rebuildRecentProjectDataModel((DefaultListModel) model);
list.setSelectedIndex(group.getProjects().isEmpty() ? index : index + 1);
}
} else {
FlatWelcomeFrame frame = UIUtil.getParentOfType(FlatWelcomeFrame.class, list);
if (frame != null) {
FocusTraversalPolicy policy = frame.getFocusTraversalPolicy();
if (policy != null) {
Component next = policy.getComponentAfter(frame, list);
if (next != null) {
IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
IdeFocusManager.getGlobalInstance().requestFocus(next, true);
});
}
}
}
}
} else if (keyCode == KeyEvent.VK_LEFT) {
if (group != null && group.isExpanded()) {
group.setExpanded(false);
int index = list.getSelectedIndex();
ListModel model = ((NameFilteringListModel) list.getModel()).getOriginalModel();
RecentProjectsWelcomeScreenActionBase.rebuildRecentProjectDataModel((DefaultListModel) model);
list.setSelectedIndex(index);
}
}
}
});
list.addMouseListener(new PopupHandler() {
@Override
public void invokePopup(Component comp, int x, int y) {
final int index = list.locationToIndex(new Point(x, y));
if (index != -1 && Arrays.binarySearch(list.getSelectedIndices(), index) < 0) {
list.setSelectedIndex(index);
}
final ActionGroup group = (ActionGroup) ActionManager.getInstance().getAction("WelcomeScreenRecentProjectActionGroup");
if (group != null) {
ActionManager.getInstance().createActionPopupMenu(ActionPlaces.WELCOME_SCREEN, group).getComponent().show(comp, x, y);
}
}
});
return list;
}
use of com.intellij.ui.PopupHandler in project intellij-community by JetBrains.
the class TreeView method createPanel.
private JPanel createPanel() {
createModel();
myTree = new MyTree();
myTree.setLineStyleAngled();
myTree.setRootVisible(false);
myTree.setShowsRootHandles(true);
myTree.updateUI();
myTree.setLargeModel(true);
myTree.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
OpenSourceUtil.openSourcesFrom(DataManager.getInstance().getDataContext(myTree), false);
}
}
});
myTree.addMouseListener(new PopupHandler() {
public void invokePopup(Component comp, int x, int y) {
popupInvoked(comp, x, y);
}
});
EditSourceOnDoubleClickHandler.install(myTree);
myAutoScrollToSourceHandler.install(myTree);
myOccurenceNavigatorSupport = new OccurenceNavigatorSupport(myTree) {
protected Navigatable createDescriptorForNode(DefaultMutableTreeNode node) {
if (!(node instanceof MessageNode)) {
return null;
}
MessageNode messageNode = (MessageNode) node;
AntBuildMessageView.MessageType type = messageNode.getType();
if (type != AntBuildMessageView.MessageType.MESSAGE && type != AntBuildMessageView.MessageType.ERROR) {
return null;
}
if (!isValid(messageNode.getFile())) {
return null;
}
return new OpenFileDescriptor(myProject, messageNode.getFile(), messageNode.getOffset());
}
@Nullable
public String getNextOccurenceActionName() {
return AntBundle.message("ant.execution.next.error.warning.action.name");
}
@Nullable
public String getPreviousOccurenceActionName() {
return AntBundle.message("ant.execution.previous.error.warning.action.name");
}
};
return JBUI.Panels.simplePanel(MessageTreeRenderer.install(myTree));
}
use of com.intellij.ui.PopupHandler in project intellij-community by JetBrains.
the class ToolWindowContentUi method initMouseListeners.
public static void initMouseListeners(final JComponent c, final ToolWindowContentUi ui) {
if (c.getClientProperty(ui) != null)
return;
final Point[] myLastPoint = new Point[1];
c.addMouseMotionListener(new MouseMotionAdapter() {
public void mouseDragged(final MouseEvent e) {
if (myLastPoint[0] == null)
return;
final Window window = SwingUtilities.windowForComponent(c);
if (window instanceof IdeFrame)
return;
final Point windowLocation = window.getLocationOnScreen();
PointerInfo info = MouseInfo.getPointerInfo();
if (info == null)
return;
final Point newPoint = info.getLocation();
Point p = myLastPoint[0];
windowLocation.translate(newPoint.x - p.x, newPoint.y - p.y);
window.setLocation(windowLocation);
myLastPoint[0] = newPoint;
}
});
c.addMouseListener(new MouseAdapter() {
public void mousePressed(final MouseEvent e) {
PointerInfo info = MouseInfo.getPointerInfo();
myLastPoint[0] = info != null ? info.getLocation() : e.getLocationOnScreen();
if (!e.isPopupTrigger()) {
if (!UIUtil.isCloseClick(e)) {
ui.myWindow.fireActivated();
}
}
}
@Override
public void mouseReleased(MouseEvent e) {
if (!e.isPopupTrigger()) {
if (UIUtil.isCloseClick(e, MouseEvent.MOUSE_RELEASED)) {
ui.processHide(e);
}
}
}
});
c.addMouseListener(new PopupHandler() {
public void invokePopup(final Component comp, final int x, final int y) {
final Content content = c instanceof BaseLabel ? ((BaseLabel) c).getContent() : null;
ui.showContextMenu(comp, x, y, ui.myWindow.getPopupGroup(), content);
}
});
c.putClientProperty(ui, Boolean.TRUE);
}
Aggregations