Search in sources :

Example 41 with MouseListener

use of java.awt.event.MouseListener in project com.revolsys.open by revolsys.

the class ShowMenuMouseListener method addMenuListener.

@SuppressWarnings("rawtypes")
private boolean addMenuListener(final JComponent component) {
    if (component != null) {
        for (final MouseListener listener : component.getMouseListeners()) {
            if (listener instanceof ShowMenuMouseListener) {
                this.previousListener = (ShowMenuMouseListener) listener;
                component.removeMouseListener(listener);
            }
        }
        component.addMouseListener(this);
        if (component instanceof JComboBox) {
            final JComboBox comboBox = (JComboBox) component;
            final ComboBoxEditor editor = comboBox.getEditor();
            final Component editorComponent = editor.getEditorComponent();
            addMenuListener((JComponent) editorComponent);
        } else if (component instanceof JTextComponent) {
            this.textComponent = (JTextComponent) component;
            this.textComponent.setDragEnabled(true);
        }
    }
    return true;
}
Also used : BaseMouseListener(com.revolsys.swing.listener.BaseMouseListener) MouseListener(java.awt.event.MouseListener) JComboBox(javax.swing.JComboBox) JTextComponent(javax.swing.text.JTextComponent) JComponent(javax.swing.JComponent) Component(java.awt.Component) JTextComponent(javax.swing.text.JTextComponent) ComboBoxEditor(javax.swing.ComboBoxEditor)

Example 42 with MouseListener

use of java.awt.event.MouseListener in project com.revolsys.open by revolsys.

the class BaseTreeListener method mouseClicked.

@Override
public void mouseClicked(final MouseEvent e) {
    final int x = e.getX();
    final int y = e.getY();
    final TreePath path = this.tree.getPathForLocation(x, y);
    if (path != null) {
        final Object node = path.getLastPathComponent();
        if (node instanceof MouseListener) {
            final MouseListener listener = (MouseListener) node;
            Object userObject = null;
            if (node instanceof BaseTreeNode) {
                final BaseTreeNode treeNode = (BaseTreeNode) node;
                userObject = treeNode.getUserObject();
            }
            if (userObject == null) {
                MenuFactory.setMenuSource(userObject);
            } else {
                MenuFactory.setMenuSource(node);
            }
            listener.mouseClicked(e);
        }
    }
}
Also used : MouseListener(java.awt.event.MouseListener) TreePath(javax.swing.tree.TreePath)

Example 43 with MouseListener

use of java.awt.event.MouseListener in project lotro-companion by dmorcellet.

the class BuffEditionPanelController method buildBuffController.

private BuffIconController buildBuffController(BuffInstance buff) {
    BuffIconController controller = new BuffIconController(buff, _toon);
    JLabel label = controller.getLabel();
    MouseListener popupListener = buildRightClickListener();
    label.addMouseListener(popupListener);
    MouseListener listener = buildLeftClickListener();
    label.addMouseListener(listener);
    return controller;
}
Also used : MouseListener(java.awt.event.MouseListener) JLabel(javax.swing.JLabel)

Example 44 with MouseListener

use of java.awt.event.MouseListener in project org.alloytools.alloy by AlloyTools.

the class SwingLogPanel method logLink.

/**
 * Write a clickable link into the log window.
 */
public void logLink(final String link, final String linkDestination) {
    if (log == null || link.length() == 0)
        return;
    if (linkDestination == null || linkDestination.length() == 0) {
        log(link);
        return;
    }
    clearError();
    StyledDocument doc = log.getStyledDocument();
    Style linkStyle = doc.addStyle("link", styleRegular);
    final JLabel label = OurUtil.make(OurAntiAlias.label(link), new Font(fontName, Font.BOLD, fontSize), linkColor);
    label.setAlignmentY(0.8f);
    label.setMaximumSize(label.getPreferredSize());
    label.addMouseListener(new MouseListener() {

        @Override
        public final void mousePressed(MouseEvent e) {
            if (handler != null)
                handler.doVisualize(linkDestination);
        }

        @Override
        public final void mouseClicked(MouseEvent e) {
        }

        @Override
        public final void mouseReleased(MouseEvent e) {
        }

        @Override
        public final void mouseEntered(MouseEvent e) {
            label.setForeground(hoverColor);
        }

        @Override
        public final void mouseExited(MouseEvent e) {
            label.setForeground(linkColor);
        }
    });
    StyleConstants.setComponent(linkStyle, label);
    links.add(label);
    // Any character would do; the "." will be
    reallyLog(".", linkStyle);
    // replaced by the JLabel
    log.setCaretPosition(doc.getLength());
    lastSize = doc.getLength();
}
Also used : MouseListener(java.awt.event.MouseListener) MouseEvent(java.awt.event.MouseEvent) StyledDocument(javax.swing.text.StyledDocument) Style(javax.swing.text.Style) JLabel(javax.swing.JLabel) Font(java.awt.Font)

Example 45 with MouseListener

use of java.awt.event.MouseListener in project CodenameOne by codenameone.

the class CodenameOneImageRenderer method mouseClicked.

public void mouseClicked(MouseEvent e) {
    Timeline t = (Timeline) image;
    AnimationObject selection = t.getAnimationAt(e.getX(), e.getY());
    // editing
    if (selection == null) {
        animationObjectList.clearSelection();
    } else {
        if (e.getClickCount() == 2) {
            selectValue(selection);
            MouseListener[] ls = animationObjectList.getListeners(MouseListener.class);
            for (MouseListener l : ls) {
                l.mouseClicked(e);
            }
        } else {
            // selection
            selectValue(selection);
        }
    }
    repaint();
}
Also used : Timeline(com.codename1.ui.animations.Timeline) MouseListener(java.awt.event.MouseListener) AnimationObject(com.codename1.ui.animations.AnimationObject)

Aggregations

MouseListener (java.awt.event.MouseListener)104 MouseEvent (java.awt.event.MouseEvent)67 Dimension (java.awt.Dimension)21 JLabel (javax.swing.JLabel)20 MouseAdapter (java.awt.event.MouseAdapter)19 JPanel (javax.swing.JPanel)16 Component (java.awt.Component)14 JComponent (javax.swing.JComponent)14 ActionEvent (java.awt.event.ActionEvent)13 ActionListener (java.awt.event.ActionListener)11 MouseMotionListener (java.awt.event.MouseMotionListener)11 JButton (javax.swing.JButton)11 JScrollPane (javax.swing.JScrollPane)11 Insets (java.awt.Insets)8 BorderLayout (java.awt.BorderLayout)7 Color (java.awt.Color)7 Point (java.awt.Point)7 File (java.io.File)7 ImageIcon (javax.swing.ImageIcon)6 JCheckBox (javax.swing.JCheckBox)6