Example usage for javax.swing SwingUtilities convertMouseEvent

List of usage examples for javax.swing SwingUtilities convertMouseEvent

Introduction

In this page you can find the example usage for javax.swing SwingUtilities convertMouseEvent.

Prototype

@SuppressWarnings("deprecation")
public static MouseEvent convertMouseEvent(Component source, MouseEvent sourceEvent, Component destination) 

Source Link

Document

Returns a MouseEvent similar to sourceEvent except that its x and y members have been converted to destination's coordinate system.

Usage

From source file:Main.java

public static void showPopMenu(JPopupMenu popupMenu, MouseEvent e, Component source, Component destination) {
    final MouseEvent event = SwingUtilities.convertMouseEvent(source, e, destination);
    popupMenu.show(destination, event.getX(), event.getY());
}

From source file:com.haulmont.cuba.desktop.sys.DesktopWindowManager.java

protected void initTabContextMenu(JComponent tabComponent) {
    tabComponent.addMouseListener(new MouseAdapter() {
        @Override//w w w. j  a  v  a 2  s.co m
        public void mousePressed(MouseEvent e) {
            dispatchToParent(e);
            if (e.isPopupTrigger()) {
                showTabPopup(e);
            }
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            dispatchToParent(e);
            if (e.isPopupTrigger()) {
                showTabPopup(e);
            }
        }

        @Override
        public void mouseEntered(MouseEvent e) {
            dispatchToParent(e);
        }

        @Override
        public void mouseMoved(MouseEvent e) {
            dispatchToParent(e);
        }

        @Override
        public void mouseDragged(MouseEvent e) {
            dispatchToParent(e);
        }

        @Override
        public void mouseWheelMoved(MouseWheelEvent e) {
            dispatchToParent(e);
        }

        @Override
        public void mouseExited(MouseEvent e) {
            dispatchToParent(e);
        }

        @Override
        public void mouseClicked(MouseEvent e) {
            dispatchToParent(e);
        }

        public void dispatchToParent(MouseEvent e) {
            tabsPane.dispatchEvent(SwingUtilities.convertMouseEvent(e.getComponent(), e, tabsPane));
        }
    });
}

From source file:net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeBigDecimal.java

/**
 * Return a JTextField usable in a CellEditor.
 *///  www  .  ja va 2s.c  o m
public JTextField getJTextField() {
    _textComponent = new RestorableJTextField();

    // special handling of operations while editing this data type
    ((RestorableJTextField) _textComponent).addKeyListener(new KeyTextHandler());

    //
    // handle mouse events for double-click creation of popup dialog.
    // This happens only in the JTextField, not the JTextArea, so we can
    // make this an inner class within this method rather than a separate
    // inner class as is done with the KeyTextHandler class.
    //
    ((RestorableJTextField) _textComponent).addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent evt) {
            if (evt.getClickCount() == 2) {
                MouseEvent tableEvt = SwingUtilities.convertMouseEvent(
                        (RestorableJTextField) DataTypeBigDecimal.this._textComponent, evt,
                        DataTypeBigDecimal.this._table);
                CellDataPopup.showDialog(DataTypeBigDecimal.this._table, DataTypeBigDecimal.this._colDef,
                        tableEvt, true);
            }
        }
    }); // end of mouse listener

    return (JTextField) _textComponent;
}

From source file:org.datacleaner.widgets.table.DCTableCellRenderer.java

@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
        int row, int column) {
    logger.debug("getTableCellRendererComponent({},{})", row, column);

    if (value != null) {
        if (value.getClass().isArray()) {
            // arrays are printed nicely this way
            value = ArrayUtils.toString(value);
        }//from  www .  j  ava  2s. c  o m
    }

    // icons are displayed as labels
    if (value instanceof Icon) {
        final JLabel label = new JLabel((Icon) value);
        label.setOpaque(true);
        value = label;
    }

    final Component result;

    // render components directly
    if (value instanceof JComponent) {
        final JComponent component = (JComponent) value;

        component.setOpaque(true);

        if (component.getMouseListeners().length == 0) {
            component.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    MouseEvent newEvent = SwingUtilities.convertMouseEvent(component, e, _table);
                    _table.consumeMouseClick(newEvent);
                }
            });
        }

        result = component;
    } else {
        result = _delegate.getTableCellRendererComponent(_table, value, isSelected, hasFocus, row, column);
        assert result instanceof JLabel;
    }

    // alignment is applied to all labels or panels (with flowlayout)
    Alignment alignment = _alignmentOverrides.get(column);
    if (alignment == null) {
        alignment = Alignment.LEFT;
    }

    // set alignment
    if (value instanceof JPanel) {
        final LayoutManager layout = ((JPanel) value).getLayout();
        if (layout instanceof FlowLayout) {
            final FlowLayout flowLayout = (FlowLayout) layout;
            flowLayout.setAlignment(alignment.getFlowLayoutAlignment());
        }
    } else if (result instanceof JLabel) {
        final JLabel label = (JLabel) result;
        label.setHorizontalAlignment(alignment.getSwingContstantsAlignment());

        WidgetUtils.setAppropriateFont(label);
    }

    return result;
}