Search in sources :

Example 1 with ContextMenuListener

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);
            }
        }
    });
}
Also used : Color(java.awt.Color) Timer(java.util.Timer) ContextMenuListener(chatty.gui.components.menus.ContextMenuListener) Helper(chatty.Helper) ArrayList(java.util.ArrayList) Border(javax.swing.border.Border) HashSet(java.util.HashSet) SwingUtilities(javax.swing.SwingUtilities) ComponentListener(java.awt.event.ComponentListener) TitledBorder(javax.swing.border.TitledBorder) TimerTask(java.util.TimerTask) DefaultListCellRenderer(javax.swing.DefaultListCellRenderer) JPopupMenu(javax.swing.JPopupMenu) JList(javax.swing.JList) Set(java.util.Set) StreamInfo(chatty.util.api.StreamInfo) BorderFactory(javax.swing.BorderFactory) ComponentEvent(java.awt.event.ComponentEvent) StreamInfosContextMenu(chatty.gui.components.menus.StreamInfosContextMenu) Component(java.awt.Component) ActionEvent(java.awt.event.ActionEvent) ComponentAdapter(java.awt.event.ComponentAdapter) Action(chatty.gui.components.JListActionHelper.Action) List(java.util.List) DateTime(chatty.util.DateTime) JTextArea(javax.swing.JTextArea) Comparator(java.util.Comparator) ComponentListener(java.awt.event.ComponentListener) StreamInfosContextMenu(chatty.gui.components.menus.StreamInfosContextMenu) ActionEvent(java.awt.event.ActionEvent) ContextMenuListener(chatty.gui.components.menus.ContextMenuListener) StreamInfo(chatty.util.api.StreamInfo) ArrayList(java.util.ArrayList) JList(javax.swing.JList) List(java.util.List) ComponentEvent(java.awt.event.ComponentEvent) ComponentAdapter(java.awt.event.ComponentAdapter)

Example 2 with ContextMenuListener

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());
    }
}
Also used : StreamInfosContextMenu(chatty.gui.components.menus.StreamInfosContextMenu) StreamInfo(chatty.util.api.StreamInfo) ArrayList(java.util.ArrayList) ContextMenuListener(chatty.gui.components.menus.ContextMenuListener)

Aggregations

ContextMenuListener (chatty.gui.components.menus.ContextMenuListener)2 StreamInfosContextMenu (chatty.gui.components.menus.StreamInfosContextMenu)2 StreamInfo (chatty.util.api.StreamInfo)2 ArrayList (java.util.ArrayList)2 Helper (chatty.Helper)1 Action (chatty.gui.components.JListActionHelper.Action)1 DateTime (chatty.util.DateTime)1 Color (java.awt.Color)1 Component (java.awt.Component)1 ActionEvent (java.awt.event.ActionEvent)1 ComponentAdapter (java.awt.event.ComponentAdapter)1 ComponentEvent (java.awt.event.ComponentEvent)1 ComponentListener (java.awt.event.ComponentListener)1 Comparator (java.util.Comparator)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 Timer (java.util.Timer)1 TimerTask (java.util.TimerTask)1 BorderFactory (javax.swing.BorderFactory)1