use of javax.swing.event.ListSelectionEvent in project intellij-community by JetBrains.
the class FinderRecursivePanel method createList.
protected JBList<T> createList() {
final JBList<T> list = new JBList<>(myListModel);
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.setEmptyText(getListEmptyText());
list.setCellRenderer(createListCellRenderer());
installListActions(list);
list.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent event) {
if (event.getValueIsAdjusting())
return;
if (isMergeListItemsRunning())
return;
if (myUpdateSelectedPathModeActive.get())
return;
updateRightComponent(true);
}
});
ScrollingUtil.installActions(list);
// installSpeedSearch(list); // TODO
installEditOnDoubleClick(list);
return list;
}
use of javax.swing.event.ListSelectionEvent in project intellij-community by JetBrains.
the class AttachToLocalProcessAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final Project project = getEventProject(e);
if (project == null)
return;
XLocalAttachDebuggerProvider[] providers = Extensions.getExtensions(XLocalAttachDebuggerProvider.EP);
new Task.Backgroundable(project, XDebuggerBundle.message("xdebugger.attach.toLocal.action.collectingProcesses"), true, PerformInBackgroundOption.DEAF) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
ProcessInfo[] processList = OSProcessUtil.getProcessList();
List<AttachItem> items = collectAttachItems(project, processList, indicator, providers);
ApplicationManager.getApplication().invokeLater(() -> {
if (project.isDisposed()) {
return;
}
ProcessListStep step = new ProcessListStep(items, project);
final ListPopup popup = JBPopupFactory.getInstance().createListPopup(step);
final JList mainList = ((ListPopupImpl) popup).getList();
ListSelectionListener listener = event -> {
if (event.getValueIsAdjusting())
return;
Object item = ((JList) event.getSource()).getSelectedValue();
if (item == null) {
item = mainList.getSelectedValue();
}
if (item instanceof AttachItem) {
String debuggerName = ((AttachItem) item).getSelectedDebugger().getDebuggerDisplayName();
debuggerName = StringUtil.shortenTextWithEllipsis(debuggerName, 50, 0);
((ListPopupImpl) popup).setCaption(XDebuggerBundle.message("xdebugger.attach.toLocal.popup.title", debuggerName));
}
};
popup.addListSelectionListener(listener);
// force first valueChanged event
listener.valueChanged(new ListSelectionEvent(mainList, mainList.getMinSelectionIndex(), mainList.getMaxSelectionIndex(), false));
popup.showCenteredInCurrentWindow(project);
});
}
}.queue();
}
use of javax.swing.event.ListSelectionEvent in project intellij-community by JetBrains.
the class RevisionsList method addSelectionListener.
private void addSelectionListener(SelectionListener listener) {
final SelectionListener l = listener;
table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
private int mySelectedRow1 = 0;
private int mySelectedRow2 = 0;
private final SelectionListener mySelectionListener = l;
public void valueChanged(ListSelectionEvent e) {
if (e.getValueIsAdjusting())
return;
ListSelectionModel sm = table.getSelectionModel();
mySelectedRow1 = sm.getMinSelectionIndex();
mySelectedRow2 = sm.getMaxSelectionIndex();
mySelectionListener.revisionsSelected(mySelectedRow1, mySelectedRow2);
}
});
}
use of javax.swing.event.ListSelectionEvent in project intellij-community by JetBrains.
the class ContentChooser method createCenterPanel.
@Override
protected JComponent createCenterPanel() {
final int selectionMode = myAllowMultipleSelections ? ListSelectionModel.MULTIPLE_INTERVAL_SELECTION : ListSelectionModel.SINGLE_SELECTION;
myList.setSelectionMode(selectionMode);
if (myUseIdeaEditor) {
EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
myList.setFont(scheme.getFont(EditorFontType.PLAIN));
Color fg = ObjectUtils.chooseNotNull(scheme.getDefaultForeground(), new JBColor(UIUtil::getListForeground));
Color bg = ObjectUtils.chooseNotNull(scheme.getDefaultBackground(), new JBColor(UIUtil::getListBackground));
myList.setForeground(fg);
myList.setBackground(bg);
}
new DoubleClickListener() {
@Override
protected boolean onDoubleClick(MouseEvent e) {
close(OK_EXIT_CODE);
return true;
}
}.installOn(myList);
MyListCellRenderer renderer = new MyListCellRenderer();
myList.setCellRenderer(renderer);
myList.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_DELETE) {
int newSelectionIndex = -1;
for (Object o : myList.getSelectedValuesList()) {
int i = ((Item) o).index;
removeContentAt(myAllContents.get(i));
if (newSelectionIndex < 0) {
newSelectionIndex = i;
}
}
rebuildListContent();
if (myAllContents.isEmpty()) {
close(CANCEL_EXIT_CODE);
return;
}
newSelectionIndex = Math.min(newSelectionIndex, myAllContents.size() - 1);
myList.setSelectedIndex(newSelectionIndex);
} else if (e.getKeyCode() == KeyEvent.VK_ENTER) {
doOKAction();
} else {
SpeedSearchSupply supply = SpeedSearchSupply.getSupply(myList);
if (supply != null && supply.isPopupActive())
return;
char aChar = e.getKeyChar();
if (aChar >= '0' && aChar <= '9') {
int idx = aChar == '0' ? 9 : aChar - '1';
if (idx < myAllContents.size()) {
myList.setSelectedIndex(idx);
e.consume();
doOKAction();
}
}
}
}
});
mySplitter.setFirstComponent(ListWithFilter.wrap(myList, ScrollPaneFactory.createScrollPane(myList), o -> o.getShortText(renderer.previewChars)));
mySplitter.setSecondComponent(new JPanel());
mySplitter.getFirstComponent().addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
FontMetrics metrics = myList.getFontMetrics(myList.getFont());
int charWidth = metrics.charWidth('m');
renderer.previewChars = myList.getParent().getParent().getWidth() / charWidth + 10;
}
});
rebuildListContent();
ScrollingUtil.installActions(myList);
ScrollingUtil.ensureSelectionExists(myList);
updateViewerForSelection();
myList.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
if (myUpdateAlarm.isDisposed())
return;
myUpdateAlarm.cancelAllRequests();
myUpdateAlarm.addRequest(() -> updateViewerForSelection(), 100);
}
});
mySplitter.setPreferredSize(JBUI.size(500, 500));
SplitterProportionsData d = new SplitterProportionsDataImpl();
d.externalizeToDimensionService(getClass().getName());
d.restoreSplitterProportions(mySplitter);
return mySplitter;
}
use of javax.swing.event.ListSelectionEvent in project intellij-community by JetBrains.
the class SaveMetaTargetDialog method createCenterPanel.
protected JComponent createCenterPanel() {
final JPanel panel = new JPanel(new GridBagLayout());
final JLabel nameLabel = new JLabel(AntBundle.message("save.meta.data.name.label"));
panel.add(nameLabel, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, JBUI.emptyInsets(), 0, 0));
myTfName = new JTextField(myInitialEvent.getPresentableName());
nameLabel.setLabelFor(myTfName);
myTfName.selectAll();
panel.add(myTfName, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, JBUI.insetsTop(4), 0, 0));
final DefaultListModel dataModel = new DefaultListModel();
myTargetList = new JBList(dataModel);
final String[] targetNames = myInitialEvent.getTargetNames();
for (String name : targetNames) {
dataModel.addElement(name);
}
panel.add(new JLabel(AntBundle.message("save.meta.data.targets.label")), new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, JBUI.insetsTop(6), 0, 0));
panel.add(ScrollPaneFactory.createScrollPane(myTargetList), new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 2, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, JBUI.insetsTop(4), 0, 0));
final JButton upButton = new JButton(AntBundle.message("button.move.up"));
panel.add(upButton, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, JBUI.insets(6, 6, 0, 0), 0, 0));
final JButton downButton = new JButton(AntBundle.message("button.move.down"));
panel.add(downButton, new GridBagConstraints(1, 4, 1, GridBagConstraints.REMAINDER, 0.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, JBUI.insetsLeft(6), 0, 0));
class UpdateAction implements ActionListener {
public void actionPerformed(ActionEvent e) {
upButton.setEnabled(ListUtil.canMoveSelectedItemsUp(myTargetList));
downButton.setEnabled(ListUtil.canMoveSelectedItemsDown(myTargetList));
}
}
upButton.addActionListener(new UpdateAction() {
public void actionPerformed(ActionEvent e) {
ListUtil.moveSelectedItemsUp(myTargetList);
super.actionPerformed(e);
}
});
downButton.addActionListener(new UpdateAction() {
public void actionPerformed(ActionEvent e) {
ListUtil.moveSelectedItemsDown(myTargetList);
super.actionPerformed(e);
}
});
myTargetList.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
upButton.setEnabled(ListUtil.canMoveSelectedItemsUp(myTargetList));
downButton.setEnabled(ListUtil.canMoveSelectedItemsDown(myTargetList));
}
});
myTargetList.setSelectedIndex(0);
return panel;
}
Aggregations