Example usage for java.awt.event MouseEvent getClickCount

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

Introduction

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

Prototype

public int getClickCount() 

Source Link

Document

Returns the number of mouse clicks associated with this event.

Usage

From source file:Main.java

/**
 * Return the MouseEvent's click count, possibly reduced by the value of
 * the component's {@code SKIP_CLICK_COUNT} client property. Clears
 * the {@code SKIP_CLICK_COUNT} property if the mouse event's click count
 * is 1. In order for clearing of the property to work correctly, there
 * must be a mousePressed implementation on the caller with this
 * call as the first line.//from  ww w .  j av a  2  s  .co m
 */
public static int getAdjustedClickCount(JTextComponent comp, MouseEvent e) {
    int cc = e.getClickCount();

    if (cc == 1) {
        comp.putClientProperty(SKIP_CLICK_COUNT, null);
    } else {
        Integer sub = (Integer) comp.getClientProperty(SKIP_CLICK_COUNT);
        if (sub != null) {
            return cc - sub;
        }
    }

    return cc;
}

From source file:Main.java

public static void addDoubleClickEvent(JList list) {
    list.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            JList source = (JList) e.getSource();
            if (e.getClickCount() == 2) {
                ListSelectionListener[] listeners = source.getListSelectionListeners();
                for (int i = 0; i < listeners.length; i++) {
                    listeners[i].valueChanged(new ListSelectionEvent(source, source.getSelectedIndex(),
                            source.getSelectedIndex(), false));
                }//from w w w.jav  a2  s .c o m
            }
        }
    });
}

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:org.bitbucket.mlopatkin.android.logviewer.widgets.UiHelper.java

public static void addDoubleClickListener(JComponent component, final DoubleClickListener listener) {
    assert listener != null;
    component.addMouseListener(new MouseAdapter() {
        @Override/*  w  ww  . j  a va  2s .  c om*/
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == DOUBLE_CLICK_COUNT && e.getButton() == MouseEvent.BUTTON1) {
                listener.mouseClicked(e);
            }
        }
    });
}

From source file:org.bitbucket.mlopatkin.android.logviewer.widgets.UiHelper.java

public static void addDoubleClickAction(JComponent component, final Action action) {
    component.addMouseListener(new MouseAdapter() {
        @Override/*from   w  w w.  ja  v a 2 s . c om*/
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == DOUBLE_CLICK_COUNT && e.getButton() == MouseEvent.BUTTON1) {
                action.actionPerformed(new ActionEvent(e.getSource(), ActionEvent.ACTION_PERFORMED,
                        (String) action.getValue(Action.ACTION_COMMAND_KEY), e.getWhen(), e.getModifiers()));
            }
        }
    });
}

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;/*from  w w  w  .  j  a  va2  s .  com*/
        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:ec.util.chart.swing.Charts.java

public static boolean isDoubleClick(@Nonnull MouseEvent e) {
    return e.getClickCount() > 1;
}

From source file:com.intuit.tank.tools.debugger.PanelBuilder.java

/**
 * @param debuggerActions/*  w  w w.j  av a  2 s.com*/
 * @return
 */
static Component createContentPanel(final AgentDebuggerFrame frame) {
    JSplitPane pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true);
    pane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
    final RSyntaxTextArea scriptEditorTA = new RSyntaxTextArea();
    frame.setScriptEditorTA(scriptEditorTA);
    scriptEditorTA.setSelectionColor(scriptEditorTA.getCurrentLineHighlightColor());
    scriptEditorTA.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_NONE);
    scriptEditorTA.setHyperlinksEnabled(false);
    scriptEditorTA.setEditable(false);
    scriptEditorTA.setEnabled(false);
    scriptEditorTA.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            scriptEditorTA.grabFocus();
            try {
                int offs = scriptEditorTA.viewToModel(e.getPoint());
                if (offs > -1) {
                    int line = scriptEditorTA.getLineOfOffset(offs);
                    if (frame.getSteps().size() > line) {

                        frame.fireStepChanged(line);
                        if (e.getClickCount() == 2 && !e.isPopupTrigger()) {
                            // show step xml
                            try {
                                DebugStep debugStep = frame.getSteps().get(line);
                                String text = JaxbUtil.marshall(debugStep.getStepRun());
                                StepDialog dlg = new StepDialog(frame, text, SyntaxConstants.SYNTAX_STYLE_XML);
                                dlg.setVisible(true);
                            } catch (JAXBException e1) {
                                frame.showError("Error showing step xml: " + e);
                            }
                        }
                    }
                }
            } catch (BadLocationException ble) {
                ble.printStackTrace(); // Never happens
            }
        }
    });
    RTextScrollPane scriptEditorScrollPane = new RTextScrollPane(scriptEditorTA);
    frame.setScriptEditorScrollPane(scriptEditorScrollPane);
    scriptEditorScrollPane.setIconRowHeaderEnabled(true);
    scriptEditorScrollPane.getGutter()
            .setBookmarkIcon(ActionProducer.getIcon("bullet_blue.png", IconSize.SMALL));
    scriptEditorScrollPane.getGutter()
            .setCurrentLineIcon(ActionProducer.getIcon("current_line.png", IconSize.SMALL));
    scriptEditorScrollPane.getGutter().setBookmarkingEnabled(true);
    pane.setLeftComponent(scriptEditorScrollPane);

    pane.setRightComponent(createRightPanel(frame));
    pane.setDividerLocation(300);
    pane.setResizeWeight(0.4D);
    return pane;
}

From source file:Main.java

public void mouseClicked(MouseEvent evt) {
    if (evt.getClickCount() == 3) {
        System.out.println("triple-click");
    } else if (evt.getClickCount() == 2) {
        System.out.println("double-click");
    }/*from  w  w w.  j a v  a2  s . c  o m*/
}