use of java.awt.event.ActionEvent in project EnrichmentMapApp by BaderLab.
the class SwingUtil method createOnlineHelpButton.
public static JButton createOnlineHelpButton(String url, String toolTipText, CyServiceRegistrar serviceRegistrar) {
JButton btn = new JButton();
btn.setToolTipText(toolTipText);
btn.addActionListener((ActionEvent evt) -> {
serviceRegistrar.getService(OpenBrowser.class).openURL(url);
});
if (LookAndFeelUtil.isAquaLAF()) {
btn.putClientProperty("JButton.buttonType", "help");
} else {
btn.setFont(serviceRegistrar.getService(IconManager.class).getIconFont(22.0f));
btn.setText(IconManager.ICON_QUESTION_CIRCLE);
btn.setBorderPainted(false);
btn.setContentAreaFilled(false);
btn.setFocusPainted(false);
btn.setBorder(BorderFactory.createEmptyBorder());
btn.setMinimumSize(new Dimension(22, 22));
}
return btn;
}
use of java.awt.event.ActionEvent in project intellij-community by JetBrains.
the class ProjectSpecificSettingsStep method addInterpreterButton.
private void addInterpreterButton(final JPanel locationPanel, final LabeledComponent<TextFieldWithBrowseButton> location) {
final JButton interpreterButton = new FixedSizeButton(location);
if (SystemInfo.isMac && !UIUtil.isUnderDarcula()) {
interpreterButton.putClientProperty("JButton.buttonType", null);
}
interpreterButton.setIcon(PythonIcons.Python.Python);
interpreterButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
final DialogBuilder builder = new DialogBuilder();
final JPanel panel = new JPanel();
final LabeledComponent<PythonSdkChooserCombo> interpreterCombo = createInterpreterCombo();
if (mySdk != null) {
mySdkCombo.getComboBox().setSelectedItem(mySdk);
}
panel.add(interpreterCombo);
builder.setCenterPanel(panel);
builder.setTitle("Select Python Interpreter");
if (builder.showAndGet()) {
mySdk = (Sdk) mySdkCombo.getComboBox().getSelectedItem();
}
}
});
locationPanel.add(interpreterButton, BorderLayout.EAST);
}
use of java.awt.event.ActionEvent in project intellij-community by JetBrains.
the class DynamicToolWindowWrapper method createTable.
private JScrollPane createTable(final MutableTreeNode myTreeRoot) {
ColumnInfo[] columnInfos = { new ClassColumnInfo(myColumnNames[CLASS_OR_ELEMENT_NAME_COLUMN]), new PropertyTypeColumnInfo(myColumnNames[TYPE_COLUMN]) };
myTreeTableModel = new ListTreeTableModelOnColumns(myTreeRoot, columnInfos);
myTreeTable = new MyTreeTable(myTreeTableModel);
new TreeTableSpeedSearch(myTreeTable, new Convertor<TreePath, String>() {
@Override
public String convert(TreePath o) {
final Object node = o.getLastPathComponent();
if (node instanceof DefaultMutableTreeNode) {
final Object object = ((DefaultMutableTreeNode) node).getUserObject();
if (object instanceof DNamedElement) {
return ((DNamedElement) object).getName();
}
}
return "";
}
});
DefaultActionGroup group = new DefaultActionGroup();
group.add(ActionManager.getInstance().getAction(RemoveDynamicAction.GROOVY_DYNAMIC_REMOVE));
PopupHandler.installUnknownPopupHandler(myTreeTable, group, ActionManager.getInstance());
final MyColoredTreeCellRenderer treeCellRenderer = new MyColoredTreeCellRenderer();
myTreeTable.setDefaultRenderer(String.class, new TableCellRenderer() {
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
if (value instanceof String) {
try {
final PsiType type = JavaPsiFacade.getElementFactory(myProject).createTypeFromText((String) value, null);
String shortName = type.getPresentableText();
return new JLabel(shortName);
} catch (IncorrectOperationException e) {
LOG.debug("Type cannot be created", e);
}
return new JLabel(QuickfixUtil.shortenType((String) value));
}
return new JLabel();
}
});
myTreeTable.setTreeCellRenderer(treeCellRenderer);
myTreeTable.setRootVisible(false);
myTreeTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
final MyPropertyTypeCellEditor typeCellEditor = new MyPropertyTypeCellEditor();
typeCellEditor.addCellEditorListener(new CellEditorListener() {
@Override
public void editingStopped(ChangeEvent e) {
final TreeTableTree tree = getTree();
String newTypeValue = ((MyPropertyTypeCellEditor) e.getSource()).getCellEditorValue();
if (newTypeValue == null || tree == null) {
myTreeTable.editingStopped(e);
return;
}
try {
final PsiType type = JavaPsiFacade.getElementFactory(myProject).createTypeFromText(newTypeValue, null);
String canonical = type.getCanonicalText();
if (canonical != null)
newTypeValue = canonical;
} catch (IncorrectOperationException ex) {
//do nothing in case bad string is entered
}
final TreePath editingTypePath = tree.getSelectionPath();
if (editingTypePath == null)
return;
final TreePath editingClassPath = editingTypePath.getParentPath();
Object oldTypeValue = myTreeTable.getValueAt(tree.getRowForPath(editingTypePath), TYPE_COLUMN);
if (!(oldTypeValue instanceof String)) {
myTreeTable.editingStopped(e);
return;
}
final Object editingPropertyObject = myTreeTable.getValueAt(tree.getRowForPath(editingTypePath), CLASS_OR_ELEMENT_NAME_COLUMN);
final Object editingClassObject = myTreeTable.getValueAt(tree.getRowForPath(editingClassPath), CLASS_OR_ELEMENT_NAME_COLUMN);
if (!(editingPropertyObject instanceof DItemElement) || !(editingClassObject instanceof DClassElement)) {
myTreeTable.editingStopped(e);
return;
}
final DItemElement dynamicElement = (DItemElement) editingPropertyObject;
final String name = dynamicElement.getName();
final String className = ((DClassElement) editingClassObject).getName();
if (dynamicElement instanceof DPropertyElement) {
DynamicManager.getInstance(myProject).replaceDynamicPropertyType(className, name, (String) oldTypeValue, newTypeValue);
} else if (dynamicElement instanceof DMethodElement) {
final List<ParamInfo> myPairList = ((DMethodElement) dynamicElement).getPairs();
DynamicManager.getInstance(myProject).replaceDynamicMethodType(className, name, myPairList, (String) oldTypeValue, newTypeValue);
}
}
@Override
public void editingCanceled(ChangeEvent e) {
myTreeTable.editingCanceled(e);
}
});
RefactoringListenerManager.getInstance(myProject).addListenerProvider(new RefactoringElementListenerProvider() {
@Override
@Nullable
public RefactoringElementListener getListener(final PsiElement element) {
if (element instanceof PsiClass) {
final String qualifiedName = ((PsiClass) element).getQualifiedName();
return new RefactoringElementListener() {
@Override
public void elementMoved(@NotNull PsiElement newElement) {
renameElement(qualifiedName, newElement);
}
@Override
public void elementRenamed(@NotNull PsiElement newElement) {
renameElement(qualifiedName, newElement);
}
private void renameElement(String oldClassName, PsiElement newElement) {
if (newElement instanceof PsiClass) {
final String newClassName = ((PsiClass) newElement).getQualifiedName();
final DRootElement rootElement = DynamicManager.getInstance(myProject).getRootElement();
final DClassElement oldClassElement = rootElement.getClassElement(oldClassName);
final TreeNode oldClassNode = TreeUtil.findNodeWithObject((DefaultMutableTreeNode) myTreeRoot, oldClassElement);
DynamicManager.getInstance(myProject).replaceClassName(oldClassElement, newClassName);
myTreeTableModel.nodeChanged(oldClassNode);
}
}
};
}
return null;
}
});
myTreeTable.setDefaultEditor(String.class, typeCellEditor);
myTreeTable.registerKeyboardAction(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
final int selectionRow = myTreeTable.getTree().getLeadSelectionRow();
myTreeTable.editCellAt(selectionRow, CLASS_OR_ELEMENT_NAME_COLUMN, event);
}
}, KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0), JComponent.WHEN_FOCUSED);
myTreeTable.registerKeyboardAction(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
final int selectionRow = myTreeTable.getTree().getLeadSelectionRow();
myTreeTable.editCellAt(selectionRow, TYPE_COLUMN, event);
}
}, KeyStroke.getKeyStroke(KeyEvent.VK_F2, InputEvent.CTRL_MASK), JComponent.WHEN_FOCUSED);
myTreeTable.getTree().setShowsRootHandles(true);
myTreeTable.getTableHeader().setReorderingAllowed(false);
myTreeTable.setPreferredScrollableViewportSize(new Dimension(300, myTreeTable.getRowHeight() * 10));
myTreeTable.getColumn(myColumnNames[CLASS_OR_ELEMENT_NAME_COLUMN]).setPreferredWidth(200);
myTreeTable.getColumn(myColumnNames[TYPE_COLUMN]).setPreferredWidth(160);
JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTreeTable);
scrollPane.setPreferredSize(JBUI.size(600, 400));
return scrollPane;
}
use of java.awt.event.ActionEvent in project intellij-community by JetBrains.
the class SwitchTaskAction method createPopup.
private static ListPopupImpl createPopup(final DataContext dataContext, @Nullable final Runnable onDispose, boolean withTitle) {
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
final Ref<Boolean> shiftPressed = Ref.create(false);
final Ref<JComponent> componentRef = Ref.create();
List<TaskListItem> items = project == null ? Collections.<TaskListItem>emptyList() : createPopupActionGroup(project, shiftPressed, PlatformDataKeys.CONTEXT_COMPONENT.getData(dataContext));
final String title = withTitle ? "Switch to Task" : null;
ListPopupStep<TaskListItem> step = new MultiSelectionListPopupStep<TaskListItem>(title, items) {
@Override
public PopupStep<?> onChosen(List<TaskListItem> selectedValues, boolean finalChoice) {
if (finalChoice) {
selectedValues.get(0).select();
return FINAL_CHOICE;
}
ActionGroup group = createActionsStep(selectedValues, project, shiftPressed);
return JBPopupFactory.getInstance().createActionsStep(group, DataManager.getInstance().getDataContext(componentRef.get()), false, false, null, null, true);
}
@Override
public Icon getIconFor(TaskListItem aValue) {
return aValue.getIcon();
}
@NotNull
@Override
public String getTextFor(TaskListItem value) {
return value.getText();
}
@Nullable
@Override
public ListSeparator getSeparatorAbove(TaskListItem value) {
return value.getSeparator() == null ? null : new ListSeparator(value.getSeparator());
}
@Override
public boolean hasSubstep(List<TaskListItem> selectedValues) {
return selectedValues.size() > 1 || selectedValues.get(0).getTask() != null;
}
};
final ListPopupImpl popup = (ListPopupImpl) JBPopupFactory.getInstance().createListPopup(step);
if (onDispose != null) {
Disposer.register(popup, new Disposable() {
@Override
public void dispose() {
onDispose.run();
}
});
}
componentRef.set(popup.getComponent());
if (items.size() <= 2) {
return popup;
}
popup.setAdText("Press SHIFT to merge with current context");
popup.registerAction("shiftPressed", KeyStroke.getKeyStroke("shift pressed SHIFT"), new AbstractAction() {
public void actionPerformed(ActionEvent e) {
shiftPressed.set(true);
popup.setCaption("Merge with Current Context");
}
});
popup.registerAction("shiftReleased", KeyStroke.getKeyStroke("released SHIFT"), new AbstractAction() {
public void actionPerformed(ActionEvent e) {
shiftPressed.set(false);
popup.setCaption("Switch to Task");
}
});
popup.registerAction("invoke", KeyStroke.getKeyStroke("shift ENTER"), new AbstractAction() {
public void actionPerformed(ActionEvent e) {
popup.handleSelect(true);
}
});
return popup;
}
use of java.awt.event.ActionEvent in project intellij-community by JetBrains.
the class GotoTaskAction method perform.
void perform(final Project project) {
final Ref<Boolean> shiftPressed = Ref.create(false);
final ChooseByNamePopup popup = createPopup(project, new GotoTaskPopupModel(project), new TaskItemProvider(project));
popup.setShowListForEmptyPattern(true);
popup.setSearchInAnyPlace(true);
popup.setAlwaysHasMore(true);
popup.setAdText("<html>Press SHIFT to merge with current context<br/>" + "Pressing " + KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction(IdeActions.ACTION_QUICK_JAVADOC)) + " would show task description and comments</html>");
popup.registerAction("shiftPressed", KeyStroke.getKeyStroke("shift pressed SHIFT"), new AbstractAction() {
public void actionPerformed(ActionEvent e) {
shiftPressed.set(true);
}
});
popup.registerAction("shiftReleased", KeyStroke.getKeyStroke("released SHIFT"), new AbstractAction() {
public void actionPerformed(ActionEvent e) {
shiftPressed.set(false);
}
});
final DefaultActionGroup group = new DefaultActionGroup(new ConfigureServersAction() {
@Override
protected void serversChanged() {
popup.rebuildList(true);
}
});
final ActionToolbar actionToolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, group, true);
actionToolbar.setLayoutPolicy(ActionToolbar.NOWRAP_LAYOUT_POLICY);
actionToolbar.updateActionsImmediately();
actionToolbar.getComponent().setFocusable(false);
actionToolbar.getComponent().setBorder(null);
popup.setToolArea(actionToolbar.getComponent());
popup.setMaximumListSizeLimit(PAGE_SIZE);
popup.setListSizeIncreasing(PAGE_SIZE);
showNavigationPopup(new GotoActionCallback<Object>() {
@Override
public void elementChosen(ChooseByNamePopup popup, Object element) {
TaskManager taskManager = TaskManager.getManager(project);
if (element instanceof TaskPsiElement) {
Task task = ((TaskPsiElement) element).getTask();
LocalTask localTask = taskManager.findTask(task.getId());
if (localTask != null) {
taskManager.activateTask(localTask, !shiftPressed.get());
} else {
showOpenTaskDialog(project, task);
}
} else if (element == CREATE_NEW_TASK_ACTION) {
LocalTask localTask = taskManager.createLocalTask(CREATE_NEW_TASK_ACTION.getTaskName());
showOpenTaskDialog(project, localTask);
}
}
}, null, popup);
}
Aggregations