Example usage for java.awt.event MouseEvent getModifiers

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

Introduction

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

Prototype

@Deprecated(since = "9")
public int getModifiers() 

Source Link

Document

Returns the modifier mask for this event.

Usage

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 w  w  .  j av a 2s  . co m*/
        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  w w.ja 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:Main.java

public void mouseClicked(MouseEvent evt) {
    if ((evt.getModifiers() & InputEvent.BUTTON1_MASK) != 0) {
        System.out.println("left" + (evt.getPoint()));
    }//from  w  w w . j  av a  2  s .c om
    if ((evt.getModifiers() & InputEvent.BUTTON2_MASK) != 0) {
        System.out.println("middle" + (evt.getPoint()));
    }
    if ((evt.getModifiers() & InputEvent.BUTTON3_MASK) != 0) {
        System.out.println("right" + (evt.getPoint()));
    }
}

From source file:Main.java

public Main(JTree jt) {
    super();/*w ww.j  ava 2  s. com*/
    tree = jt;
    getContentPane().add(tree);
    tree.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent event) {
            if (((event.getModifiers() & InputEvent.BUTTON3_MASK) != 0) && (tree.getSelectionCount() > 0)) {
                showMenu(event.getX(), event.getY());
            }
        }
    });
}

From source file:Main.java

public Main() {
    setLayout(null);//from ww w  .  jav  a 2  s .  c  o  m
    add(button);
    button.setSize(button.getPreferredSize());
    button.setLocation(20, 20);
    addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent event) {
            System.out.println(MouseEvent.getMouseModifiersText(event.getModifiers()));
        }
    });
}

From source file:PopupDemo.java

String getMods(MouseEvent e) {
    return getMods(e.getModifiers());
}

From source file:com.tag.MouseDragAndDrop.java

protected void prepare(MouseEvent e) {
    int mod = e.getModifiers();
    if ((mod & MouseEvent.BUTTON1_MASK) == 0)
        e.consume();/*  w  w w . j a va 2s  .  c o m*/
}

From source file:edu.uci.ics.jung.visualization.control.LabelEditingGraphMousePlugin.java

/**
 * For primary modifiers (default, MouseButton1):
 * pick a single Vertex or Edge that/*from   www  . j  a  v  a  2 s . c o m*/
  * is under the mouse pointer. If no Vertex or edge is under
  * the pointer, unselect all picked Vertices and edges, and
  * set up to draw a rectangle for multiple selection
  * of contained Vertices.
  * For additional selection (default Shift+MouseButton1):
  * Add to the selection, a single Vertex or Edge that is
  * under the mouse pointer. If a previously picked Vertex
  * or Edge is under the pointer, it is un-picked.
  * If no vertex or Edge is under the pointer, set up
  * to draw a multiple selection rectangle (as above)
  * but do not unpick previously picked elements.
 * 
 * @param e the event
 */
@SuppressWarnings("unchecked")
public void mouseClicked(MouseEvent e) {
    if (e.getModifiers() == modifiers && e.getClickCount() == 2) {
        VisualizationViewer<V, E> vv = (VisualizationViewer) e.getSource();
        GraphElementAccessor<V, E> pickSupport = vv.getPickSupport();
        if (pickSupport != null) {
            Transformer<V, String> vs = vv.getRenderContext().getVertexLabelTransformer();
            if (vs instanceof MapTransformer) {
                Map<V, String> map = ((MapTransformer) vs).getMap();
                Layout<V, E> layout = vv.getGraphLayout();
                // p is the screen point for the mouse event
                Point2D p = e.getPoint();

                V vertex = pickSupport.getVertex(layout, p.getX(), p.getY());
                if (vertex != null) {
                    String newLabel = vs.transform(vertex);
                    newLabel = JOptionPane.showInputDialog("New Vertex Label for " + vertex);
                    if (newLabel != null) {
                        map.put(vertex, newLabel);
                        vv.repaint();
                    }
                    return;
                }
            }
            Transformer<E, String> es = vv.getRenderContext().getEdgeLabelTransformer();
            if (es instanceof MapTransformer) {
                Map<E, String> map = ((MapTransformer) es).getMap();
                Layout<V, E> layout = vv.getGraphLayout();
                // p is the screen point for the mouse event
                Point2D p = e.getPoint();
                // take away the view transform
                Point2D ip = vv.getRenderContext().getMultiLayerTransformer().inverseTransform(Layer.VIEW, p);
                E edge = pickSupport.getEdge(layout, ip.getX(), ip.getY());
                if (edge != null) {
                    String newLabel = JOptionPane.showInputDialog("New Edge Label for " + edge);
                    if (newLabel != null) {
                        map.put(edge, newLabel);
                        vv.repaint();
                    }
                    return;
                }
            }
        }
        e.consume();
    }
}

From source file:EventTestPane.java

/**
 * Return a string representation of the modifiers for a MouseEvent. Note
 * that the methods called here are inherited from InputEvent.
 *//*  w w w  .  ja v a2  s. c  om*/
protected String mousemods(MouseEvent e) {
    int mods = e.getModifiers();
    String s = "";
    if (e.isShiftDown())
        s += "Shift ";
    if (e.isControlDown())
        s += "Ctrl ";
    if ((mods & InputEvent.BUTTON1_MASK) != 0)
        s += "Button 1 ";
    if ((mods & InputEvent.BUTTON2_MASK) != 0)
        s += "Button 2 ";
    if ((mods & InputEvent.BUTTON3_MASK) != 0)
        s += "Button 3 ";
    return s;
}

From source file:edu.umn.ecology.populus.plot.BasicPlotCanvas.java

private void jbInit() throws Exception {
    /*/*from w ww.  j av  a 2s .co  m*/
    if( info != null ) {
       mainCaption = new HTMLLabel( info.getMainCaption() );
       xCaption = new HTMLLabel( info.getXCaptions()[0] );
       yCaption = new HTMLLabel( info.getYCaptions()[0] );
       yCaption.setDirection( HTMLLabel.DOWN_TO_UP );
    } else {
       mainCaption = new HTMLLabel( "Main Caption" );
       xCaption = new HTMLLabel( "X Caption" );
       yCaption = new HTMLLabel( "Y Caption" );
    }
     */
    //*
    if (info != null) {
        mainCaption = new HTMLMultiLabel(info.getMainCaption());
        xCaption = new HTMLMultiLabel(info.getXCaptions());
        yCaption = new HTMLMultiLabel(info.getYCaptions());
        yCaption.setDirection(HTMLLabel.DOWN_TO_UP);
    } else {
        mainCaption = new HTMLMultiLabel("Main Caption");
        xCaption = new HTMLMultiLabel("X Caption");
        yCaption = new HTMLMultiLabel("Y Caption");
        yCaption.setDirection(HTMLLabel.DOWN_TO_UP);
    }
    setLayout(borderLayout1);
    if (PopPreferencesStorage.isUseJFreeClass()) {
        NumberAxis yAxis = new NumberAxis(null);
        NumberAxis xAxis = new NumberAxis(null);
        xAxis.setAutoRangeIncludesZero(false);

        AbstractXYItemRenderer renderer = null;
        if (info.isBarChart) {
            renderer = new XYBarRenderer();
        } else {
            renderer = new XYLineAndShapeRenderer(true, false);
        }

        XYPlot plot = new XYPlot(null, xAxis, yAxis, renderer);
        plot.setOrientation(PlotOrientation.VERTICAL);

        JFreeChart jfchart = new JFreeChart(null, null, plot, false);
        jfchartpanel = new ChartPanel(jfchart);
        plot.setBackgroundPaint(ColorScheme.bG);

        info.styleJFree(jfchart);
        add(jfchartpanel, MacroLayout.CENTER);
    } else {
        chart = new JCChart(JCChart.PLOT);
        info.styleJC(chart);
        chart.setBackground(ColorScheme.bG);
        chart.setAllowUserChanges(true);
        chart.setTrigger(0, new EventTrigger(InputEvent.SHIFT_MASK, EventTrigger.CUSTOMIZE));
        chart.setTrigger(1, new EventTrigger(InputEvent.BUTTON1_MASK, EventTrigger.ZOOM));
        chart.setResetKey('r');
        chart.addMouseListener(new java.awt.event.MouseAdapter() {

            public void mouseClicked(java.awt.event.MouseEvent e) {
                if ((e.getModifiers() & InputEvent.META_MASK) != 0) {
                    info.setAxis(chart);
                    chart.reset();
                }
            }
        });
        chart.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
        chart.setWarningDialog(false);
        add(chart, MacroLayout.CENTER);
    }
    setBGColor();
    add(mainCaption, MacroLayout.NORTH);
    add(xCaption, MacroLayout.SOUTH);
    add(yCaption, MacroLayout.WEST);
}