Example usage for java.awt.event MouseEvent getWhen

List of usage examples for java.awt.event MouseEvent getWhen

Introduction

In this page you can find the example usage for java.awt.event MouseEvent getWhen.

Prototype

public long getWhen() 

Source Link

Document

Returns the difference in milliseconds between the timestamp of when this event occurred and midnight, January 1, 1970 UTC.

Usage

From source file:Main.java

public static void main(String[] args) {
    String[] items = { "Sun", "Mon", "Tues", "Wed", "Thurs", "Fri", "Sat" };
    JList<String> myJList = new JList(items) {
        @Override//from w ww . jav a2s . co m
        protected void processMouseEvent(MouseEvent e) {
            int modifiers = e.getModifiers() | InputEvent.CTRL_MASK;
            int modifiersEx = e.getModifiersEx() | InputEvent.CTRL_MASK;
            MouseEvent myME = new MouseEvent((Component) e.getSource(), e.getID(), e.getWhen(), modifiers,
                    e.getX(), e.getY(), e.getXOnScreen(), e.getYOnScreen(), e.getClickCount(),
                    e.isPopupTrigger(), e.getButton());
            super.processMouseEvent(myME);
        }
    };
    JFrame f = new JFrame();
    f.add(new JScrollPane(myJList));
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.pack();
    f.setLocationRelativeTo(null);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    final JTabbedPane jTabbedPane = new JTabbedPane();
    jTabbedPane.addTab("Red", new JLabel("Roses"));
    jTabbedPane.addTab("Blue", new JLabel("Skies"));
    jTabbedPane.addTab("Green", new JLabel("Grass"));

    for (int i = 0; i < jTabbedPane.getTabCount(); i++) {
        final JLabel tabComponent = new JLabel(jTabbedPane.getTitleAt(i));

        tabComponent.addMouseMotionListener(new MouseMotionAdapter() {
            @Override// w ww .j  a v a  2  s  .c  om
            public void mouseDragged(MouseEvent e) {
                System.out.println("tabComponent dragging");
            }
        });

        tabComponent.addMouseListener(new MouseAdapter() {
            @Override
            public void mousePressed(MouseEvent e) {
                int x = tabComponent.getLocationOnScreen().x - jTabbedPane.getLocationOnScreen().x;
                int y = tabComponent.getLocationOnScreen().y - jTabbedPane.getLocationOnScreen().y;
                MouseEvent me = new MouseEvent((JLabel) e.getSource(), e.getID(), e.getWhen(), e.getModifiers(),
                        x, y, e.getLocationOnScreen().x, e.getLocationOnScreen().y, e.getClickCount(),
                        e.isPopupTrigger(), e.getButton());
                jTabbedPane.getMouseListeners()[0].mousePressed(me);
                System.out.println("tabComponent mousePressed e=" + e);
            }
        });
        jTabbedPane.setTabComponentAt(i, tabComponent);
    }
    JFrame jFrame = new JFrame();
    jFrame.add(jTabbedPane);
    jFrame.setSize(400, 500);
    jFrame.setVisible(true);
    jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

From source file:Main.java

public static MouseEvent newMouseEvent(Component comp, int id, MouseEvent e) {
    return new MouseEvent(comp, id, e.getWhen(), e.getModifiers() | e.getModifiersEx(), e.getX(), e.getY(),
            e.getClickCount(), e.isPopupTrigger());
}

From source file:Main.java

public static MouseEvent convertMouseEvent(MouseEvent e, Component newSource, Point newPoint) {
    return new MouseEvent(newSource, e.getID(), e.getWhen(), e.getModifiersEx(), newPoint.x, newPoint.y,
            e.getClickCount(), e.isPopupTrigger(), e.getButton());
}

From source file:Main.java

public static MouseEvent adaptEventToDescendent(MouseEvent e, JComponent descendentTarget) {
    Point trans = new Point();
    Component source = e.getComponent();

    Component current = descendentTarget;
    while (current != source) {
        Rectangle b = current.getBounds();
        trans.x += b.x;//w ww.jav  a 2  s. c om
        trans.y += b.y;
        current = current.getParent();
    }
    Point point = e.getPoint();

    return new MouseEvent(descendentTarget, e.getID(), e.getWhen(), e.getModifiers(), point.x + trans.x,
            point.y + trans.y, e.getClickCount(), e.isPopupTrigger(), e.getButton());
}

From source file:Main.java

public static MouseEvent convertMouseEvent(Component source, MouseEvent sourceEvent, Component destination) {
    Point p = SwingUtilities.convertPoint(source, new Point(sourceEvent.getX(), sourceEvent.getY()),
            destination);//from w ww . j a  v a 2 s. co m
    Component newSource;

    if (destination != null)
        newSource = destination;
    else
        newSource = source;

    MouseEvent newEvent;
    if (sourceEvent instanceof MouseWheelEvent) {
        MouseWheelEvent sourceWheelEvent = (MouseWheelEvent) sourceEvent;
        newEvent = new MouseWheelEvent(newSource, sourceWheelEvent.getID(), sourceWheelEvent.getWhen(),
                sourceEvent.getModifiers() | sourceEvent.getModifiersEx(), p.x, p.y,
                sourceWheelEvent.getClickCount(), sourceWheelEvent.isPopupTrigger(),
                sourceWheelEvent.getScrollType(), sourceWheelEvent.getScrollAmount(),
                sourceWheelEvent.getWheelRotation());
    } else if (sourceEvent instanceof MenuDragMouseEvent) {
        MenuDragMouseEvent sourceMenuDragEvent = (MenuDragMouseEvent) sourceEvent;
        newEvent = new MenuDragMouseEvent(newSource, sourceMenuDragEvent.getID(), sourceMenuDragEvent.getWhen(),
                sourceEvent.getModifiers() | sourceEvent.getModifiersEx(), p.x, p.y,
                sourceMenuDragEvent.getClickCount(), sourceMenuDragEvent.isPopupTrigger(),
                sourceMenuDragEvent.getPath(), sourceMenuDragEvent.getMenuSelectionManager());
    } else {
        newEvent = new MouseEvent(newSource, sourceEvent.getID(), sourceEvent.getWhen(),
                sourceEvent.getModifiers() | sourceEvent.getModifiersEx(), p.x, p.y,
                sourceEvent.getClickCount(), sourceEvent.isPopupTrigger(), sourceEvent.getButton());
    }
    return newEvent;
}

From source file:com.limegroup.gnutella.gui.tables.ActionIconAndNameEditor.java

public Component getTableCellEditorComponent(final JTable table, Object value, boolean isSelected, int row,
        int column) {
    ActionIconAndNameHolder in = (ActionIconAndNameHolder) value;
    action = in.getAction();//from  w ww.  j a  v  a  2 s  .c  o  m

    final Component component = new ActionIconAndNameRenderer().getTableCellRendererComponent(table, value,
            isSelected, true, row, column);
    component.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON1) {
                if (actionRegion == null) {
                    component_mousePressed(e);
                } else {
                    if (actionRegion.contains(e.getPoint())) {
                        component_mousePressed(e);
                    } else {
                        if (e.getClickCount() >= 2) {
                            Toolkit.getDefaultToolkit().getSystemEventQueue()
                                    .postEvent(new MouseEvent(table, MouseEvent.MOUSE_CLICKED, e.getWhen(),
                                            e.getModifiers(), component.getX() + e.getX(),
                                            component.getY() + e.getY(), e.getClickCount(), false));
                        }
                    }
                }
            } else if (e.getButton() == MouseEvent.BUTTON3) {
                Toolkit.getDefaultToolkit().getSystemEventQueue()
                        .postEvent(new MouseEvent(table, e.getID(), e.getWhen(), e.getModifiers(),
                                component.getX() + e.getX(), component.getY() + e.getY(), e.getClickCount(),
                                true));
            }
        }
    });

    return component;
}

From source file:org.adempiere.apps.graph.PerformanceIndicator.java

/**
 * Notifies all listeners that have registered interest for
 * notification on this event type.  The event instance 
 * is lazily created using the <code>event</code> 
 * parameter./*  w  w w.  j a v  a 2s .  c om*/
 *
 * @param event  the <code>ActionEvent</code> object
 * @see EventListenerList
 */
protected void fireActionPerformed(MouseEvent event) {
    // Guaranteed to return a non-null array
    ActionListener[] listeners = getActionListeners();
    ActionEvent e = null;
    // Process the listeners first to last
    for (int i = 0; i < listeners.length; i++) {
        //   Lazily create the event:
        if (e == null)
            e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "pi", event.getWhen(),
                    event.getModifiers());
        listeners[i].actionPerformed(e);
    }
}

From source file:it.unibas.spicygui.vista.listener.MyMouseEventListener.java

private void dispacciaEventoDrag(Component com, MouseEvent e, Point point, boolean draggedEvent) {
    Point componentPoint = SwingUtilities.convertPoint(component, e.getPoint(), com);
    if (com != null) {
        if (com instanceof JTree) {
            TreePath treePath = ((JTree) com).getPathForLocation(componentPoint.x, componentPoint.y);
            if (treePath == null || draggedEvent) {
                component.updateUI();//from  w  w w  .j a  v a  2s .co  m
                return;
            }
        }
        if ((!(com instanceof JScrollBar) && (tmp12 instanceof JScrollBar))) {
            jLayeredPane.moveToFront(component);
            component.updateUI();
            return;
        }

        com.dispatchEvent(new MouseEvent(component, e.getID(), e.getWhen(), e.getModifiers(), componentPoint.x,
                componentPoint.y, e.getClickCount(), e.isPopupTrigger()));
        jLayeredPane.moveToFront(component);
        component.updateUI();

    }
    jLayeredPane.moveToFront(component);
    component.updateUI();
}

From source file:it.unibas.spicygui.vista.listener.MyMouseEventListener.java

private void dispacciaEvento(Component com, MouseEvent e, Point point, boolean draggedEvent) {
    if (com == null) {
        com = SwingUtilities.getDeepestComponentAt(pannelloPrincipale, point.x, point.y);
    }/*from   w  w  w .  j  a  v  a 2  s . c o  m*/
    Point componentPoint = SwingUtilities.convertPoint(component, e.getPoint(), com);
    if (com != null) {
        if (com instanceof JTree) {
            TreePath treePath = ((JTree) com).getPathForLocation(componentPoint.x, componentPoint.y);
            if (treePath == null || draggedEvent) {
                jLayeredPane.moveToFront(component);
                component.updateUI();
                if (e.getButton() == MouseEvent.BUTTON3) {
                    return;
                }
            }
        }
        com.dispatchEvent(new MouseEvent(com, e.getID(), e.getWhen(), e.getModifiers(), componentPoint.x,
                componentPoint.y, e.getClickCount(), e.isPopupTrigger()));

        jLayeredPane.moveToFront(component);
        component.updateUI();

    }
    jLayeredPane.moveToFront(component);
    component.updateUI();

}