use of chatty.gui.components.menus.ContextMenuListener in project chatty by chatty.
the class LiveStreamsList method addListeners.
private void addListeners() {
ComponentListener cl = new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
// Trick from kleopatra:
// https://stackoverflow.com/questions/7306295/swing-jlist-with-multiline-text-and-dynamic-height
// next line possible if list is of type JXList
// list.invalidateCellSizeCache();
// for core: force cache invalidation by temporarily setting fixed height
setFixedCellHeight(10);
setFixedCellHeight(-1);
}
};
addComponentListener(cl);
JListActionHelper.install(this, (a, l, s) -> {
if (a == Action.CONTEXT_MENU) {
StreamInfosContextMenu m = new StreamInfosContextMenu(s, true);
for (ContextMenuListener cml : contextMenuListeners) {
m.addContextMenuListener(cml);
}
lastContextMenu = m;
m.show(this, l.x, l.y);
} else if (a == Action.ENTER) {
List<String> channels = new ArrayList<>();
s.forEach(si -> channels.add(si.stream));
for (ContextMenuListener cml : contextMenuListeners) {
cml.streamsMenuItemClicked(new ActionEvent(s, 0, "join"), channels);
}
} else if (a == Action.DOUBLE_CLICK || a == Action.SPACE) {
StreamInfo info = getSelectedValue();
if (info != null && liveStreamListener != null) {
liveStreamListener.liveStreamClicked(info);
}
}
});
}
use of chatty.gui.components.menus.ContextMenuListener in project chatty by chatty.
the class LiveStreamsRemovedList method openContextMenu.
/**
* Open context menu for this user, if the event points at one.
*
* @param e
*/
private void openContextMenu(MouseEvent e) {
if (e.isPopupTrigger()) {
selectClicked(e, false);
List<RemovedListItem> selectedItems = list.getSelectedValuesList();
List<StreamInfo> selected = new ArrayList<>();
for (RemovedListItem item : selectedItems) {
selected.add(item.getStreamInfo());
}
StreamInfosContextMenu m = new StreamInfosContextMenu(selected, false);
for (ContextMenuListener cml : contextMenuListeners) {
m.addContextMenuListener(cml);
}
m.show(list, e.getX(), e.getY());
}
}
Aggregations