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:gtu._work.ui.TextScanUI.java

private void jList1MouseClicked(MouseEvent evt) {
    if (evt.getClickCount() == 2) {
        String value = (String) matchList.getModel().getElementAt(matchList.getLeadSelectionIndex());
        JOptionPaneUtil.newInstance().iconInformationMessage().showMessageDialog(appendLineSep(value),
                "");
        ClipboardUtil.getInstance().setContents(value);
    }/*w w w .  jav a  2 s . c o  m*/
}

From source file:Main.java

public Main() {
    setSize(300, 300);/*from www  .  j av a  2 s.co m*/
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    final JTextArea textArea = new JTextArea();
    textArea.setText("Click Me!");

    textArea.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            if (e.getButton() == MouseEvent.NOBUTTON) {
                textArea.setText("No button clicked...");
            } else if (e.getButton() == MouseEvent.BUTTON1) {
                textArea.setText("Button 1 clicked...");
            } else if (e.getButton() == MouseEvent.BUTTON2) {
                textArea.setText("Button 2 clicked...");
            } else if (e.getButton() == MouseEvent.BUTTON3) {
                textArea.setText("Button 3 clicked...");
            }

            System.out.println("Number of click: " + e.getClickCount());
            System.out.println("Click position (X, Y):  " + e.getX() + ", " + e.getY());
        }
    });

    getContentPane().add(textArea);
}

From source file:ca.phon.app.session.editor.view.session_information.SessionInfoEditorView.java

private void init() {
    setLayout(new BorderLayout());

    contentPanel = new TierDataLayoutPanel();

    dateField = createDateField();//from w  w  w. java  2 s.  c  om
    dateField.getTextField().setColumns(10);
    dateField.setBackground(Color.white);

    mediaLocationField = new MediaSelectionField(getEditor().getProject());
    mediaLocationField.setEditor(getEditor());
    mediaLocationField.getTextField().setColumns(10);
    mediaLocationField.addPropertyChangeListener(FileSelectionField.FILE_PROP, mediaLocationListener);

    participantTable = new JXTable();
    participantTable.setVisibleRowCount(3);

    ComponentInputMap participantTableInputMap = new ComponentInputMap(participantTable);
    ActionMap participantTableActionMap = new ActionMap();

    ImageIcon deleteIcon = IconManager.getInstance().getIcon("actions/delete_user", IconSize.SMALL);
    final PhonUIAction deleteAction = new PhonUIAction(this, "deleteParticipant");
    deleteAction.putValue(PhonUIAction.SHORT_DESCRIPTION, "Delete selected participant");
    deleteAction.putValue(PhonUIAction.SMALL_ICON, deleteIcon);
    participantTableActionMap.put("DELETE_PARTICIPANT", deleteAction);
    participantTableInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), "DELETE_PARTICIPANT");
    participantTableInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0), "DELETE_PARTICIPANT");

    removeParticipantButton = new JButton(deleteAction);

    participantTable.setInputMap(WHEN_FOCUSED, participantTableInputMap);
    participantTable.setActionMap(participantTableActionMap);

    addParticipantButton = new JButton(new NewParticipantAction(getEditor(), this));
    addParticipantButton.setFocusable(false);

    ImageIcon editIcon = IconManager.getInstance().getIcon("actions/edit_user", IconSize.SMALL);
    final PhonUIAction editParticipantAct = new PhonUIAction(this, "editParticipant");
    editParticipantAct.putValue(PhonUIAction.NAME, "Edit participant...");
    editParticipantAct.putValue(PhonUIAction.SHORT_DESCRIPTION, "Edit selected participant...");
    editParticipantAct.putValue(PhonUIAction.SMALL_ICON, editIcon);
    editParticipantButton = new JButton(editParticipantAct);
    editParticipantButton.setFocusable(false);

    final CellConstraints cc = new CellConstraints();
    FormLayout participantLayout = new FormLayout("fill:pref:grow, pref, pref, pref", "pref, pref, pref:grow");
    JPanel participantPanel = new JPanel(participantLayout);
    participantPanel.setBackground(Color.white);
    participantPanel.add(new JScrollPane(participantTable), cc.xywh(1, 2, 3, 2));
    participantPanel.add(addParticipantButton, cc.xy(2, 1));
    participantPanel.add(editParticipantButton, cc.xy(3, 1));
    participantPanel.add(removeParticipantButton, cc.xy(4, 2));
    participantTable.addMouseListener(new MouseInputAdapter() {

        @Override
        public void mouseClicked(MouseEvent arg0) {
            if (arg0.getClickCount() == 2 && arg0.getButton() == MouseEvent.BUTTON1) {
                editParticipantAct.actionPerformed(new ActionEvent(arg0.getSource(), arg0.getID(), "edit"));
            }
        }

    });

    languageField = new LanguageField();
    languageField.getDocument().addDocumentListener(languageFieldListener);

    int rowIdx = 0;
    final JLabel dateLbl = new JLabel("Session Date");
    dateLbl.setHorizontalAlignment(SwingConstants.RIGHT);
    contentPanel.add(dateLbl, new TierDataConstraint(TierDataConstraint.TIER_LABEL_COLUMN, rowIdx));
    contentPanel.add(dateField, new TierDataConstraint(TierDataConstraint.FLAT_TIER_COLUMN, rowIdx++));

    final JLabel mediaLbl = new JLabel("Media");
    mediaLbl.setHorizontalAlignment(SwingConstants.RIGHT);
    contentPanel.add(mediaLbl, new TierDataConstraint(TierDataConstraint.TIER_LABEL_COLUMN, rowIdx));
    contentPanel.add(mediaLocationField, new TierDataConstraint(TierDataConstraint.FLAT_TIER_COLUMN, rowIdx++));

    final JLabel partLbl = new JLabel("Participants");
    partLbl.setHorizontalAlignment(SwingConstants.RIGHT);
    contentPanel.add(partLbl, new TierDataConstraint(TierDataConstraint.TIER_LABEL_COLUMN, rowIdx));
    contentPanel.add(participantPanel, new TierDataConstraint(TierDataConstraint.FLAT_TIER_COLUMN, rowIdx++));

    final JLabel langLbl = new JLabel("Language");
    langLbl.setHorizontalAlignment(SwingConstants.RIGHT);
    contentPanel.add(langLbl, new TierDataConstraint(TierDataConstraint.TIER_LABEL_COLUMN, rowIdx));
    contentPanel.add(languageField, new TierDataConstraint(TierDataConstraint.FLAT_TIER_COLUMN, rowIdx++));

    add(new JScrollPane(contentPanel), BorderLayout.CENTER);

    update();
}

From source file:EventTestPane.java

/**
 * Display mouse moved and dragged mouse event. Note that MouseEvent is the
 * only event type that has two methods, two EventListener interfaces and
 * two adapter classes to handle two distinct categories of events. Also, as
 * seen in init(), mouse motion events must be requested separately from
 * other mouse event types./*from   www. j  a  va2  s  . co  m*/
 */
public void processMouseMotionEvent(MouseEvent e) {
    String type = null;
    switch (e.getID()) {
    case MouseEvent.MOUSE_MOVED:
        type = "MOUSE_MOVED";
        break;
    case MouseEvent.MOUSE_DRAGGED:
        type = "MOUSE_DRAGGED";
        break;
    }
    showLine(mousemods(e) + type + ": [" + e.getX() + "," + e.getY() + "] " + "num clicks = "
            + e.getClickCount() + (e.isPopupTrigger() ? "; is popup trigger" : ""));
}

From source file:net.sf.mzmine.modules.visualization.neutralloss.NeutralLossPlot.java

/**
 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
 *///from  w ww.j av  a 2 s  .c  om
public void mouseClicked(MouseEvent event) {

    // let the parent handle the event (selection etc.)
    super.mouseClicked(event);

    // request focus to receive key events
    requestFocus();

    // if user double-clicked left button, place a request to open a
    // spectrum
    if ((event.getButton() == MouseEvent.BUTTON1) && (event.getClickCount() == 2)) {
        showSpectrumRequest = true;
    }

}

From source file:br.com.utfpr.pb.view.PedidoCompraView.java

private void jTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTableMouseClicked
    // TODO add your handling code here:
    tableEvent();//  w ww.j  av  a  2s.  co  m
    if (evt.getClickCount() == 2 && !evt.isConsumed()) {
        evt.consume();
        //handle double click event.
        openModal();
    }
}

From source file:com.android.tools.idea.structure.gradle.MavenDependencyLookupDialog.java

public MavenDependencyLookupDialog(@NotNull Project project, @Nullable Module module) {
    super(project, true);
    myAndroidModule = module != null && AndroidFacet.getInstance(module) != null;
    myProgressIcon.suspend();//  w  w w  . j a v a 2s  . c  o  m

    mySearchField.setButtonIcon(AllIcons.Actions.Menu_find);
    mySearchField.getButton().addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            startSearch();
        }
    });

    mySearchTextField = mySearchField.getTextField();
    mySearchTextField.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            if (StringUtil.isEmpty(mySearchField.getText())) {
                return;
            }
            if (!isValidCoordinateSelected()) {
                startSearch();
            } else {
                close(OK_EXIT_CODE);
            }
        }
    });

    boolean preview = false;
    if (module != null) {
        AndroidFacet facet = AndroidFacet.getInstance(module);
        if (facet != null) {
            IdeaAndroidProject androidProject = facet.getIdeaAndroidProject();
            if (androidProject != null) {
                ApiVersion minSdkVersion = androidProject.getSelectedVariant().getMergedFlavor()
                        .getMinSdkVersion();
                if (minSdkVersion != null) {
                    preview = new AndroidVersion(minSdkVersion.getApiLevel(), minSdkVersion.getCodename())
                            .isPreview();
                }
            }
        }
    }

    RepositoryUrlManager manager = RepositoryUrlManager.get();
    for (String libraryId : RepositoryUrlManager.EXTRAS_REPOSITORY.keySet()) {
        String libraryCoordinate = manager.getLibraryCoordinate(libraryId, null, preview);
        if (libraryCoordinate != null) {
            Artifact artifact = Artifact.fromCoordinate(libraryCoordinate, libraryId);
            if (artifact != null) {
                myAndroidSdkLibraries.add(libraryCoordinate);
                myShownItems.add(artifact);
            }
        }
    }
    myShownItems.addAll(COMMON_LIBRARIES);
    myResultList.setModel(new CollectionComboBoxModel(myShownItems, null));
    myResultList.addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent listSelectionEvent) {
            Artifact value = (Artifact) myResultList.getSelectedValue();
            if (value != null) {
                mySearchTextField.setText(value.getCoordinates());
            }
        }
    });
    myResultList.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent mouseEvent) {
            if (mouseEvent.getClickCount() == 2 && isValidCoordinateSelected()) {
                close(OK_EXIT_CODE);
            }
        }
    });

    myOKAction = new OkAction() {
        @Override
        protected void doAction(ActionEvent e) {
            String text = mySearchField.getText();
            if (text != null && !hasVersion(text)
                    && RepositoryUrlManager.EXTRAS_REPOSITORY.containsKey(getArtifact(text))) {
                // If it's a known library that doesn't exist in the local repository, we don't display the version for it. Add it back so that
                // final string is a valid gradle coordinate.
                mySearchField.setText(text + ':' + REVISION_ANY);
            }
            super.doAction(e);
        }
    };
    init();
}

From source file:uk.nhs.cfh.dsp.yasb.searchpanel.SearchPanel.java

/**
 * a method that initalises the components.
 *///from w  ww.  ja  v  a2 s . c o  m
public synchronized void initComponents() {

    JPanel mainPanel = new JPanel(new BorderLayout());
    mainPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), "Search"));
    mainPanel.setName("searchPanelMainPanel");

    searchField = new JTextField();
    if (org.jdesktop.swingx.util.OS.isMacOSX()) {
        searchField.putClientProperty("JTextField.variant", "search");
    }
    searchField.setName("searchField");
    searchField.addActionListener(new AbstractAction() {

        public void actionPerformed(ActionEvent arg0) {
            doSearch();

        }
    });

    // create controls panel
    createControlPanel();

    // create button panel
    createButtonPanel();

    // create busy label
    createBusyLabel();

    JPanel panel = new JPanel(new BorderLayout());
    panel.add(searchField, BorderLayout.CENTER);
    panel.add(busyStatusLabel, BorderLayout.EAST);
    JPanel searchPanel = new JPanel(new BorderLayout());
    searchPanel.add(panel, BorderLayout.NORTH);
    searchPanel.add(buttonsPanel, BorderLayout.CENTER);
    searchPanel.add(controlsPane, BorderLayout.SOUTH);

    listModel = new SearchResultsListModel();
    resultsList = new JList(listModel);
    resultsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    renderer = new SearchResultListCellRenderer();
    resultsList.setCellRenderer(renderer);
    // add mouse listener to resultsList
    resultsList.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            // check if double click and get selected object
            if (e.getClickCount() == 2) {
                Object selectedObject = resultsList.getSelectedValue();
                if (selectedObject instanceof Document) {
                    Document document = (Document) selectedObject;
                    String conceptId = document.get("CONCEPTID");
                    SnomedConcept concept = checkAndReturnConceptForID(conceptId);
                    // set focus concept if concept is not null
                    if (concept != null) {
                        // publish as selection
                        selectionService.objectSelected(concept, SearchPanel.this);
                    }
                }
            }
        }
    });

    // add components to main panel
    mainPanel.add(searchPanel, BorderLayout.NORTH);
    mainPanel.add(new JScrollPane(resultsList), BorderLayout.CENTER);

    // add main panel to search panel
    setLayout(new BorderLayout());
    add(mainPanel, BorderLayout.CENTER);
}

From source file:com.floreantpos.bo.ui.explorer.MenuItemExplorer.java

public MenuItemExplorer() {
    tableModel = new BeanTableModel<MenuItem>(MenuItem.class);
    tableModel.addColumn(POSConstants.ID.toUpperCase(), "id"); //$NON-NLS-1$
    tableModel.addColumn(POSConstants.NAME.toUpperCase(), "name"); //$NON-NLS-1$
    tableModel.addColumn(POSConstants.TRANSLATED_NAME.toUpperCase(), "translatedName"); //$NON-NLS-1$
    tableModel.addColumn(POSConstants.PRICE.toUpperCase() + " (" + CurrencyUtil.getCurrencySymbol() + ")", //$NON-NLS-1$//$NON-NLS-2$
            "price"); //$NON-NLS-1$
    tableModel.addColumn(Messages.getString("MenuItemExplorer.16"), "stockAmount"); //$NON-NLS-1$ //$NON-NLS-2$
    tableModel.addColumn(POSConstants.VISIBLE.toUpperCase(), "visible"); //$NON-NLS-1$
    tableModel.addColumn(POSConstants.FOOD_GROUP.toUpperCase(), "parent"); //$NON-NLS-1$
    tableModel.addColumn(POSConstants.TAX.toUpperCase(), "tax"); //$NON-NLS-1$
    tableModel.addColumn(Messages.getString("MenuItemExplorer.21"), "sortOrder"); //$NON-NLS-1$ //$NON-NLS-2$
    tableModel.addColumn(Messages.getString("MenuItemExplorer.23"), "buttonColor"); //$NON-NLS-1$ //$NON-NLS-2$
    tableModel.addColumn(Messages.getString("MenuItemExplorer.25"), "textColor"); //$NON-NLS-1$ //$NON-NLS-2$
    tableModel.addColumn(POSConstants.IMAGE.toUpperCase(), "imageData"); //$NON-NLS-1$

    List<MenuItem> findAll = MenuItemDAO.getInstance().getMenuItems();
    tableModel.addRows(findAll);//from  w w w  . jav a  2  s  . c o  m
    table = new JXTable(tableModel);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    table.setDefaultRenderer(Object.class, new CustomCellRenderer());
    table.setRowHeight(60);

    setLayout(new BorderLayout(5, 5));
    add(new JScrollPane(table));

    add(createButtonPanel(), BorderLayout.SOUTH);
    add(buildSearchForm(), BorderLayout.NORTH);
    resizeColumnWidth(table);

    table.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent me) {
            if (me.getClickCount() == 2) {
                doEditSelectedMenuItem();
            }
        }
    });
}

From source file:net.sf.jabref.gui.maintable.MainTableSelectionListener.java

/**
 * Method to handle a single left click on one the special fields (e.g., ranking, quality, ...)
 * Shows either a popup to select/clear a value or simply toggles the functionality to set/unset the special field
 *
 * @param e MouseEvent used to determine the position of the popups
 * @param columnName the name of the specialfield column
 *///w ww  .j ava  2 s.  c o  m
private void handleSpecialFieldLeftClick(MouseEvent e, String columnName) {
    if ((e.getClickCount() == 1)) {
        SpecialFieldsUtils.getSpecialFieldInstanceFromFieldName(columnName).ifPresent(field -> {
            // special field found
            if (field.isSingleValueField()) {
                // directly execute toggle action instead of showing a menu with one action
                field.getValues().get(0).getAction(panel.frame()).action();
            } else {
                JPopupMenu menu = new JPopupMenu();
                for (SpecialFieldValue val : field.getValues()) {
                    menu.add(val.getMenuAction(panel.frame()));
                }
                menu.show(table, e.getX(), e.getY());
            }
        });
    }
}