use of java.awt.event.MouseEvent in project intellij-community by JetBrains.
the class ShowUsagesAction method prepareTable.
@NotNull
private Runnable prepareTable(final MyTable table, final Editor editor, final RelativePoint popupPosition, final FindUsagesHandler handler, final int maxUsages, @NotNull final FindUsagesOptions options, final boolean previewMode) {
SpeedSearchBase<JTable> speedSearch = new MySpeedSearch(table);
speedSearch.setComparator(new SpeedSearchComparator(false));
table.setRowHeight(PlatformIcons.CLASS_ICON.getIconHeight() + 2);
table.setShowGrid(false);
table.setShowVerticalLines(false);
table.setShowHorizontalLines(false);
table.setTableHeader(null);
table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
table.setIntercellSpacing(new Dimension(0, 0));
final AtomicReference<List<Object>> selectedUsages = new AtomicReference<>();
final AtomicBoolean moreUsagesSelected = new AtomicBoolean();
final AtomicBoolean outsideScopeUsagesSelected = new AtomicBoolean();
table.getSelectionModel().addListSelectionListener(e -> {
selectedUsages.set(null);
outsideScopeUsagesSelected.set(false);
moreUsagesSelected.set(false);
List<Object> usages = null;
for (int i : table.getSelectedRows()) {
Object value = table.getValueAt(i, 0);
if (value instanceof UsageNode) {
Usage usage = ((UsageNode) value).getUsage();
if (usage == USAGES_OUTSIDE_SCOPE_SEPARATOR) {
outsideScopeUsagesSelected.set(true);
usages = null;
break;
} else if (usage == MORE_USAGES_SEPARATOR) {
moreUsagesSelected.set(true);
usages = null;
break;
} else {
if (usages == null)
usages = new ArrayList<>();
usages.add(usage instanceof UsageInfo2UsageAdapter ? ((UsageInfo2UsageAdapter) usage).getUsageInfo().copy() : usage);
}
}
}
selectedUsages.set(usages);
});
final Runnable itemChosenCallback = () -> {
if (moreUsagesSelected.get()) {
appendMoreUsages(editor, popupPosition, handler, maxUsages, options);
return;
}
if (outsideScopeUsagesSelected.get()) {
options.searchScope = GlobalSearchScope.projectScope(handler.getProject());
showElementUsages(editor, popupPosition, handler, maxUsages, options);
return;
}
List<Object> usages = selectedUsages.get();
if (usages != null) {
for (Object usage : usages) {
if (usage instanceof UsageInfo) {
UsageViewUtil.navigateTo((UsageInfo) usage, true);
} else if (usage instanceof Navigatable) {
((Navigatable) usage).navigate(true);
}
}
}
};
if (previewMode) {
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseReleased(MouseEvent e) {
if (UIUtil.isActionClick(e, MouseEvent.MOUSE_RELEASED) && !UIUtil.isSelectionButtonDown(e) && !e.isConsumed()) {
itemChosenCallback.run();
}
}
});
table.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
itemChosenCallback.run();
}
}
});
}
return itemChosenCallback;
}
use of java.awt.event.MouseEvent in project intellij-community by JetBrains.
the class VariantsCompletionAction method actionPerformed.
@Override
public void actionPerformed(final AnActionEvent e) {
final Editor editor = e.getData(CommonDataKeys.EDITOR_EVEN_IF_INACTIVE);
if (editor == null)
return;
final String prefix = myTextField.getText().substring(0, myTextField.getCaretPosition());
if (StringUtil.isEmpty(prefix))
return;
final String[] array = calcWords(prefix, editor);
if (array.length == 0) {
return;
}
FeatureUsageTracker.getInstance().triggerFeatureUsed("find.completion");
final JList list = new JBList(array) {
@Override
protected void paintComponent(final Graphics g) {
GraphicsUtil.setupAntialiasing(g);
super.paintComponent(g);
}
};
list.setBackground(new JBColor(new Color(235, 244, 254), new Color(0x4C4F51)));
list.setFont(editor.getColorsScheme().getFont(EditorFontType.PLAIN));
Utils.showCompletionPopup(e.getInputEvent() instanceof MouseEvent ? myTextField : null, list, null, myTextField, null);
}
use of java.awt.event.MouseEvent in project intellij-community by JetBrains.
the class AbstractTreeClassChooserDialog method createCenterPanel.
@Override
protected JComponent createCenterPanel() {
final DefaultTreeModel model = new DefaultTreeModel(new DefaultMutableTreeNode());
myTree = new Tree(model);
ProjectAbstractTreeStructureBase treeStructure = new AbstractProjectTreeStructure(myProject) {
@Override
public boolean isFlattenPackages() {
return false;
}
@Override
public boolean isShowMembers() {
return myIsShowMembers;
}
@Override
public boolean isHideEmptyMiddlePackages() {
return true;
}
@Override
public boolean isAbbreviatePackageNames() {
return false;
}
@Override
public boolean isShowLibraryContents() {
return myIsShowLibraryContents;
}
@Override
public boolean isShowModules() {
return false;
}
};
myBuilder = new ProjectTreeBuilder(myProject, myTree, model, AlphaComparator.INSTANCE, treeStructure);
myTree.setRootVisible(false);
myTree.setShowsRootHandles(true);
myTree.expandRow(0);
myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
myTree.setCellRenderer(new NodeRenderer());
UIUtil.setLineStyleAngled(myTree);
JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTree);
scrollPane.setPreferredSize(JBUI.size(500, 300));
myTree.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (KeyEvent.VK_ENTER == e.getKeyCode()) {
doOKAction();
}
}
});
new DoubleClickListener() {
@Override
protected boolean onDoubleClick(MouseEvent event) {
TreePath path = myTree.getPathForLocation(event.getX(), event.getY());
if (path != null && myTree.isPathSelected(path)) {
doOKAction();
return true;
}
return false;
}
}.installOn(myTree);
myTree.addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
handleSelectionChanged();
}
});
new TreeSpeedSearch(myTree);
myTabbedPane = new TabbedPaneWrapper(getDisposable());
final JPanel dummyPanel = new JPanel(new BorderLayout());
String name = null;
/*
if (myInitialClass != null) {
name = myInitialClass.getName();
}
*/
myGotoByNamePanel = new ChooseByNamePanel(myProject, createChooseByNameModel(), name, myScope.isSearchInLibraries(), getContext()) {
@Override
protected void showTextFieldPanel() {
}
@Override
protected void close(boolean isOk) {
super.close(isOk);
if (isOk) {
doOKAction();
} else {
doCancelAction();
}
}
@NotNull
@Override
protected Set<Object> filter(@NotNull Set<Object> elements) {
return doFilter(elements);
}
@Override
protected void initUI(ChooseByNamePopupComponent.Callback callback, ModalityState modalityState, boolean allowMultipleSelection) {
super.initUI(callback, modalityState, allowMultipleSelection);
dummyPanel.add(myGotoByNamePanel.getPanel(), BorderLayout.CENTER);
IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
IdeFocusManager.getGlobalInstance().requestFocus(IdeFocusTraversalPolicy.getPreferredFocusedComponent(myGotoByNamePanel.getPanel()), true);
});
}
@Override
protected void showList() {
super.showList();
if (myInitialClass != null && myList.getModel().getSize() > 0) {
myList.setSelectedValue(myInitialClass, true);
myInitialClass = null;
}
}
@Override
protected void chosenElementMightChange() {
handleSelectionChanged();
}
};
Disposer.register(myDisposable, myGotoByNamePanel);
myTabbedPane.addTab(IdeBundle.message("tab.chooser.search.by.name"), dummyPanel);
myTabbedPane.addTab(IdeBundle.message("tab.chooser.project"), scrollPane);
myGotoByNamePanel.invoke(new MyCallback(), getModalityState(), false);
myTabbedPane.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
handleSelectionChanged();
}
});
return myTabbedPane.getComponent();
}
use of java.awt.event.MouseEvent in project intellij-community by JetBrains.
the class ExternalSystemKeymapExtension method createGroup.
public KeymapGroup createGroup(Condition<AnAction> condition, final Project project) {
KeymapGroup result = KeymapGroupFactory.getInstance().createGroup(ExternalSystemBundle.message("external.system.keymap.group"), ExternalSystemIcons.TaskGroup);
AnAction[] externalSystemActions = ActionsTreeUtil.getActions("ExternalSystem.Actions");
for (AnAction action : externalSystemActions) {
ActionsTreeUtil.addAction(result, action, condition);
}
if (project == null)
return result;
MultiMap<ProjectSystemId, String> projectToActionsMapping = MultiMap.create();
for (ExternalSystemManager<?, ?, ?, ?, ?> manager : ExternalSystemApiUtil.getAllManagers()) {
projectToActionsMapping.putValues(manager.getSystemId(), ContainerUtil.<String>emptyList());
}
ActionManager actionManager = ActionManager.getInstance();
if (actionManager != null) {
for (String eachId : actionManager.getActionIds(getActionPrefix(project, null))) {
AnAction eachAction = actionManager.getAction(eachId);
if (!(eachAction instanceof MyExternalSystemAction))
continue;
if (condition != null && !condition.value(actionManager.getActionOrStub(eachId)))
continue;
MyExternalSystemAction taskAction = (MyExternalSystemAction) eachAction;
projectToActionsMapping.putValue(taskAction.getSystemId(), eachId);
}
}
Map<ProjectSystemId, KeymapGroup> keymapGroupMap = ContainerUtil.newHashMap();
for (ProjectSystemId systemId : projectToActionsMapping.keySet()) {
if (!keymapGroupMap.containsKey(systemId)) {
final Icon projectIcon = ExternalSystemUiUtil.getUiAware(systemId).getProjectIcon();
KeymapGroup group = KeymapGroupFactory.getInstance().createGroup(systemId.getReadableName(), projectIcon);
keymapGroupMap.put(systemId, group);
}
}
for (Map.Entry<ProjectSystemId, Collection<String>> each : projectToActionsMapping.entrySet()) {
Collection<String> tasks = each.getValue();
final ProjectSystemId systemId = each.getKey();
final KeymapGroup systemGroup = keymapGroupMap.get(systemId);
if (systemGroup == null)
continue;
for (String actionId : tasks) {
systemGroup.addActionId(actionId);
}
if (systemGroup instanceof Group) {
Icon icon = SystemInfoRt.isMac ? AllIcons.ToolbarDecorator.Mac.Add : AllIcons.ToolbarDecorator.Add;
((Group) systemGroup).addHyperlink(new Hyperlink(icon, "Choose a task to assign a shortcut") {
@Override
public void onClick(MouseEvent e) {
SelectExternalTaskDialog dialog = new SelectExternalTaskDialog(systemId, project);
if (dialog.showAndGet() && dialog.getResult() != null) {
TaskData taskData = dialog.getResult().second;
String ownerModuleName = dialog.getResult().first;
ExternalSystemTaskAction externalSystemAction = (ExternalSystemTaskAction) getOrRegisterAction(project, ownerModuleName, taskData);
ApplicationManager.getApplication().getMessageBus().syncPublisher(KeymapListener.CHANGE_TOPIC).processCurrentKeymapChanged();
Settings allSettings = Settings.KEY.getData(DataManager.getInstance().getDataContext(e.getComponent()));
KeymapPanel keymapPanel = allSettings != null ? allSettings.find(KeymapPanel.class) : null;
if (keymapPanel != null) {
// clear actions filter
keymapPanel.showOption("");
keymapPanel.selectAction(externalSystemAction.myId);
}
}
}
});
}
}
for (KeymapGroup keymapGroup : keymapGroupMap.values()) {
if (isGroupFiltered(condition, keymapGroup)) {
result.addGroup(keymapGroup);
}
}
for (ActionsProvider extension : ActionsProvider.EP_NAME.getExtensions()) {
KeymapGroup keymapGroup = extension.createGroup(condition, project);
if (isGroupFiltered(condition, keymapGroup)) {
result.addGroup(keymapGroup);
}
}
return result;
}
use of java.awt.event.MouseEvent in project intellij-community by JetBrains.
the class LookupImpl method addListeners.
private void addListeners() {
myEditor.getDocument().addDocumentListener(new DocumentAdapter() {
@Override
public void documentChanged(DocumentEvent e) {
if (!myChangeGuard && !myFinishing) {
hideLookup(false);
}
}
}, this);
final CaretListener caretListener = new CaretAdapter() {
@Override
public void caretPositionChanged(CaretEvent e) {
if (!myChangeGuard && !myFinishing) {
hideLookup(false);
}
}
};
final SelectionListener selectionListener = new SelectionListener() {
@Override
public void selectionChanged(final SelectionEvent e) {
if (!myChangeGuard && !myFinishing) {
hideLookup(false);
}
}
};
final EditorMouseListener mouseListener = new EditorMouseAdapter() {
@Override
public void mouseClicked(EditorMouseEvent e) {
e.consume();
hideLookup(false);
}
};
myEditor.getCaretModel().addCaretListener(caretListener);
myEditor.getSelectionModel().addSelectionListener(selectionListener);
myEditor.addEditorMouseListener(mouseListener);
Disposer.register(this, new Disposable() {
@Override
public void dispose() {
myEditor.getCaretModel().removeCaretListener(caretListener);
myEditor.getSelectionModel().removeSelectionListener(selectionListener);
myEditor.removeEditorMouseListener(mouseListener);
}
});
JComponent editorComponent = myEditor.getContentComponent();
if (editorComponent.isShowing()) {
Disposer.register(this, new UiNotifyConnector(editorComponent, new Activatable() {
@Override
public void showNotify() {
}
@Override
public void hideNotify() {
hideLookup(false);
}
}));
}
myList.addListSelectionListener(new ListSelectionListener() {
private LookupElement oldItem = null;
@Override
public void valueChanged(@NotNull ListSelectionEvent e) {
if (!myUpdating) {
final LookupElement item = getCurrentItem();
fireCurrentItemChanged(oldItem, item);
oldItem = item;
}
}
});
new ClickListener() {
@Override
public boolean onClick(@NotNull MouseEvent e, int clickCount) {
setFocusDegree(FocusDegree.FOCUSED);
markSelectionTouched();
if (clickCount == 2) {
CommandProcessor.getInstance().executeCommand(myProject, () -> finishLookup(NORMAL_SELECT_CHAR), "", null);
}
return true;
}
}.installOn(myList);
}
Aggregations