use of java.awt.event.KeyEvent in project intellij-community by JetBrains.
the class LayoutProjectCodeDialog method initFileTypeFilter.
private void initFileTypeFilter() {
FindDialog.initFileFilter(myFileFilter, myEnableFileNameFilterCb);
myEnableFileNameFilterCb.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
updateMaskWarning();
}
});
myFileFilter.getEditor().getEditorComponent().addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
updateMaskWarning();
}
});
}
use of java.awt.event.KeyEvent in project intellij-community by JetBrains.
the class ImageOrColorPreviewManager method registerListeners.
private void registerListeners(final Editor editor) {
if (editor.isOneLineMode()) {
return;
}
Project project = editor.getProject();
if (project == null || project.isDisposed()) {
return;
}
PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
if (psiFile == null || psiFile instanceof PsiCompiledElement || !isSupportedFile(psiFile)) {
return;
}
editor.addEditorMouseMotionListener(this);
KeyListener keyListener = new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_SHIFT && !editor.isOneLineMode()) {
PointerInfo pointerInfo = MouseInfo.getPointerInfo();
if (pointerInfo != null) {
Point location = pointerInfo.getLocation();
SwingUtilities.convertPointFromScreen(location, editor.getContentComponent());
alarm.cancelAllRequests();
alarm.addRequest(new PreviewRequest(location, editor, true), 100);
}
}
}
};
editor.getContentComponent().addKeyListener(keyListener);
EDITOR_LISTENER_ADDED.set(editor, keyListener);
}
use of java.awt.event.KeyEvent in project intellij-community by JetBrains.
the class OptionTreeWithPreviewPanel method createOptionsTree.
protected JTree createOptionsTree() {
DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode();
String groupName = "";
DefaultMutableTreeNode groupNode = null;
List<BooleanOptionKey> result = sortOptions(orderByGroup(myKeys));
for (BooleanOptionKey key : result) {
String newGroupName = key.groupName;
if (!newGroupName.equals(groupName) || groupNode == null) {
groupName = newGroupName;
groupNode = new DefaultMutableTreeNode(newGroupName);
rootNode.add(groupNode);
}
if (isOptionVisible(key)) {
groupNode.add(new MyToggleTreeNode(key, key.title));
}
}
DefaultTreeModel model = new DefaultTreeModel(rootNode);
final Tree optionsTree = new Tree(model);
new TreeSpeedSearch(optionsTree).setComparator(new SpeedSearchComparator(false));
TreeUtil.installActions(optionsTree);
optionsTree.setRootVisible(false);
UIUtil.setLineStyleAngled(optionsTree);
optionsTree.setShowsRootHandles(true);
optionsTree.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (!optionsTree.isEnabled())
return;
if (e.getKeyCode() == KeyEvent.VK_SPACE) {
TreePath treePath = optionsTree.getLeadSelectionPath();
selectCheckbox(treePath);
e.consume();
}
}
});
new ClickListener() {
@Override
public boolean onClick(@NotNull MouseEvent e, int clickCount) {
if (!optionsTree.isEnabled())
return false;
TreePath treePath = optionsTree.getPathForLocation(e.getX(), e.getY());
selectCheckbox(treePath);
return true;
}
}.installOn(optionsTree);
int row = 0;
while (row < optionsTree.getRowCount()) {
optionsTree.expandRow(row);
row++;
}
return optionsTree;
}
use of java.awt.event.KeyEvent in project intellij-community by JetBrains.
the class BaseExecuteBeforeRunDialog method createCenterPanel.
@Override
protected JComponent createCenterPanel() {
JPanel panel = new JPanel(new BorderLayout());
myRoot = buildNodes();
final Tree tree = new Tree(myRoot);
final MyTreeCellRenderer cellRenderer = new MyTreeCellRenderer();
tree.setCellRenderer(cellRenderer);
tree.setRootVisible(false);
tree.setShowsRootHandles(true);
tree.setLineStyleAngled();
TreeUtil.installActions(tree);
new TreeSpeedSearch(tree);
tree.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
int row = tree.getRowForLocation(e.getX(), e.getY());
if (row >= 0) {
Rectangle rowBounds = tree.getRowBounds(row);
cellRenderer.setBounds(rowBounds);
Rectangle checkBounds = cellRenderer.myCheckbox.getBounds();
checkBounds.setLocation(rowBounds.getLocation());
if (checkBounds.contains(e.getPoint())) {
toggleNode(tree, (DefaultMutableTreeNode) tree.getPathForRow(row).getLastPathComponent());
e.consume();
tree.setSelectionRow(row);
}
}
}
});
tree.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_SPACE) {
TreePath treePath = tree.getLeadSelectionPath();
DefaultMutableTreeNode node = (DefaultMutableTreeNode) treePath.getLastPathComponent();
toggleNode(tree, node);
e.consume();
}
}
});
expacndChecked(tree);
JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(tree);
scrollPane.setPreferredSize(JBUI.size(400, 400));
panel.add(scrollPane, BorderLayout.CENTER);
return panel;
}
use of java.awt.event.KeyEvent in project intellij-community by JetBrains.
the class AbstractProjectViewPSIPane method initTree.
private void initTree() {
myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
UIUtil.setLineStyleAngled(myTree);
myTree.setRootVisible(false);
myTree.setShowsRootHandles(true);
myTree.expandPath(new TreePath(myTree.getModel().getRoot()));
myTree.setSelectionPath(new TreePath(myTree.getModel().getRoot()));
EditSourceOnDoubleClickHandler.install(myTree);
ToolTipManager.sharedInstance().registerComponent(myTree);
TreeUtil.installActions(myTree);
myTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
fireTreeChangeListener();
}
});
myTree.getModel().addTreeModelListener(new TreeModelListener() {
@Override
public void treeNodesChanged(TreeModelEvent e) {
fireTreeChangeListener();
}
@Override
public void treeNodesInserted(TreeModelEvent e) {
fireTreeChangeListener();
}
@Override
public void treeNodesRemoved(TreeModelEvent e) {
fireTreeChangeListener();
}
@Override
public void treeStructureChanged(TreeModelEvent e) {
fireTreeChangeListener();
}
});
new MySpeedSearch(myTree);
myTree.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (KeyEvent.VK_ENTER == e.getKeyCode()) {
final DefaultMutableTreeNode selectedNode = ((ProjectViewTree) myTree).getSelectedNode();
if (selectedNode != null && !selectedNode.isLeaf()) {
return;
}
DataContext dataContext = DataManager.getInstance().getDataContext(myTree);
OpenSourceUtil.openSourcesFrom(dataContext, ScreenReader.isActive());
} else if (KeyEvent.VK_ESCAPE == e.getKeyCode()) {
if (e.isConsumed())
return;
PsiCopyPasteManager copyPasteManager = PsiCopyPasteManager.getInstance();
boolean[] isCopied = new boolean[1];
if (copyPasteManager.getElements(isCopied) != null && !isCopied[0]) {
copyPasteManager.clear();
e.consume();
}
}
}
});
CustomizationUtil.installPopupHandler(myTree, IdeActions.GROUP_PROJECT_VIEW_POPUP, ActionPlaces.PROJECT_VIEW_POPUP);
}
Aggregations