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:uk.nhs.cfh.dsp.srth.desktop.modules.querycreationtreepanel.QueryComponentExpressionPanel.java

/**
 * Creates the additional constraints table panel.
 */// ww  w  .  j a v a  2 s.c om
private synchronized void createAdditionalConstraintsTablePanel() {

    constraintsTableModel = new ConstraintTableModel(constraints);
    constraintsTable = new JXTable(constraintsTableModel);
    constraintsTable.setPreferredScrollableViewportSize(new Dimension(400, 80));
    constraintsTable.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            // get row at click point
            int row = constraintsTable.rowAtPoint(e.getPoint());
            if (row > -1) {
                // check if double click
                if (e.getClickCount() == 2) {
                    // get term at row
                    Constraint constraint = constraintsTableModel.getConstraintAtRow(row);
                    // set as active constraint
                    activeAdditionalConstraint = constraint;
                    // show in active constraint dialog
                    constraintPanel.setConstraint(activeAdditionalConstraint);
                    // set editing tag to true
                    editingExisting = true;
                    constraintCollapsiblePane.setCollapsed(false);
                }
            }
        }
    });

    // add panel for editing excluded terms
    JideButton addConstraintButton = new JideButton(new AbstractAction("", addConstraintIcon) {

        public void actionPerformed(ActionEvent e) {
            constraintCollapsiblePane.setCollapsed(false);
            // disable editing tag
            editingExisting = false;
        }
    });
    addConstraintButton.setName("addConstraintButton");
    addConstraintButton.setBorderPainted(false);

    JideButton deleteConstraintButton = new JideButton(new AbstractAction("", deleteConstraintIcon) {

        public void actionPerformed(ActionEvent e) {
            final int row = constraintsTable.getSelectedRow();
            if (row > -1) {
                // get constraint at row
                Constraint cons = constraintsTableModel.getConstraintAtRow(row);
                // remove from subquery
                componentExpression.removeAdditionalConstraint(cons);
                Runnable runnable = new Runnable() {
                    public void run() {
                        // delete constraint at row
                        constraintsTableModel.deleteRow(row);
                        constraintsTable.revalidate();
                        QueryComponentExpressionPanel.this.revalidate();
                    }
                };
                SwingUtilities.invokeLater(runnable);
                // notify listeners of query change
                queryService.queryChanged(queryService.getActiveQuery(), QueryComponentExpressionPanel.this);
            }
        }
    });
    deleteConstraintButton.setName("deleteConstraintButton");
    deleteConstraintButton.setBorderPainted(false);

    JPanel buttonsPanel = new JPanel();
    buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.LINE_AXIS));
    buttonsPanel.add(new JLabel("Edit constraints"));
    buttonsPanel.add(Box.createHorizontalGlue());
    buttonsPanel.add(addConstraintButton);
    buttonsPanel.add(deleteConstraintButton);

    additionalConstraintsPanel = new JPanel(new BorderLayout());
    additionalConstraintsPanel.setBorder(BorderFactory.createTitledBorder("Additional Constraints"));
    additionalConstraintsPanel.add(buttonsPanel, BorderLayout.NORTH);
    additionalConstraintsPanel.add(new JScrollPane(constraintsTable), BorderLayout.CENTER);
    additionalConstraintsPanel.add(constraintCollapsiblePane, BorderLayout.SOUTH);

}

From source file:androhashcheck.MainFrame.java

/**
 * Creates new form MainFrame//  w  w  w .  j av  a  2s  .  c  om
 * @param logInFrame
 */
public MainFrame(JFrame logInFrame) {
    initComponents();
    this.logInFrame = logInFrame;
    jList5.setModel(listModel);
    dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
    displayApkFolder();
    //mouse listner - when clicked on uploaded package to show details
    jList3.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent evt) {
            JList list = (JList) evt.getSource();
            if (evt.getClickCount() == 2) {
                int index = list.locationToIndex(evt.getPoint());
                final TaskObject taskObject = taskList.get(index);
                java.awt.EventQueue.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        new TaskFrame(taskObject).setVisible(true);
                    }
                });
            }
        }
    });
    shouldCheckTasks = true;
    startThreadForTaskUpdatesChecking();
}

From source file:cl.almejo.vsim.gui.SimWindow.java

@Override
public void mouseClicked(MouseEvent event) {
    if (SwingUtilities.isRightMouseButton(event)) {
        _toolHelper.rightClicked(this, event);
        return;/*from   w  w  w  . j ava  2 s.  c  om*/
    }

    if (event.getClickCount() >= 2) {
        _toolHelper.mouseDoubleClicked(this, event);
        return;
    }
    _toolHelper.mouseClicked(this, event);
}

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

@Override
public void mouseClicked(MouseEvent e) {

    // First find the column on which the user has clicked.
    final int row = table.rowAtPoint(e.getPoint());

    // A double click on an entry should open the entry's editor.
    if (e.getClickCount() == 2) {
        BibEntry toShow = tableRows.get(row);
        editSignalled(toShow);/* w  w  w  . jav a 2s.  c om*/
        return;
    }

    final int col = table.columnAtPoint(e.getPoint());
    // get the MainTableColumn which is currently visible at col
    int modelIndex = table.getColumnModel().getColumn(col).getModelIndex();
    MainTableColumn modelColumn = table.getMainTableColumn(modelIndex);

    // Workaround for Windows. Right-click is not popup trigger on mousePressed, but
    // on mouseReleased. Therefore we need to avoid taking action at this point, because
    // action will be taken when the button is released:
    if (OS.WINDOWS && (modelColumn.isIconColumn()) && (e.getButton() != MouseEvent.BUTTON1)) {
        return;
    }

    // Check if the clicked colum is a specialfield column
    if (modelColumn.isIconColumn() && (SpecialFieldsUtils.isSpecialField(modelColumn.getColumnName()))) {
        // handle specialfield
        handleSpecialFieldLeftClick(e, modelColumn.getColumnName());
    } else if (modelColumn.isIconColumn()) { // left click on icon field

        Object value = table.getValueAt(row, col);
        if (value == null) {
            return; // No icon here, so we do nothing.
        }

        final BibEntry entry = tableRows.get(row);

        final List<String> fieldNames = modelColumn.getBibtexFields();

        // Open it now. We do this in a thread, so the program won't freeze during the wait.
        JabRefExecutorService.INSTANCE.execute(() -> {
            panel.output(Localization.lang("External viewer called") + '.');
            // check for all field names whether a link is present
            // (is relevant for combinations such as "url/doi")
            for (String fieldName : fieldNames) {
                // Check if field is present, if not skip this field
                if (entry.hasField(fieldName)) {
                    String link = entry.getFieldOptional(fieldName).get();

                    // See if this is a simple file link field, or if it is a file-list
                    // field that can specify a list of links:
                    if (fieldName.equals(FieldName.FILE)) {

                        // We use a FileListTableModel to parse the field content:
                        FileListTableModel fileList = new FileListTableModel();
                        fileList.setContent(link);

                        FileListEntry flEntry = null;
                        // If there are one or more links of the correct type, open the first one:
                        if (modelColumn.isFileFilter()) {
                            for (int i = 0; i < fileList.getRowCount(); i++) {
                                if (fileList.getEntry(i).type.toString().equals(modelColumn.getColumnName())) {
                                    flEntry = fileList.getEntry(i);
                                    break;
                                }
                            }
                        } else if (fileList.getRowCount() > 0) {
                            //If there are no file types specified open the first file
                            flEntry = fileList.getEntry(0);
                        }
                        if (flEntry != null) {
                            ExternalFileMenuItem item = new ExternalFileMenuItem(panel.frame(), entry, "",
                                    flEntry.link, flEntry.type.get().getIcon(), panel.getBibDatabaseContext(),
                                    flEntry.type);
                            boolean success = item.openLink();
                            if (!success) {
                                panel.output(Localization.lang("Unable to open link."));
                            }
                        }
                    } else {
                        try {
                            JabRefDesktop.openExternalViewer(panel.getBibDatabaseContext(), link, fieldName);
                        } catch (IOException ex) {
                            panel.output(Localization.lang("Unable to open link."));
                            LOGGER.info("Unable to open link", ex);
                        }
                    }
                    break; // only open the first link
                }
            }
        });
    } else if (modelColumn.getBibtexFields().contains(FieldName.CROSSREF)) { // Clicking on crossref column
        tableRows.get(row).getFieldOptional(FieldName.CROSSREF).ifPresent(crossref -> panel.getDatabase()
                .getEntryByKey(crossref).ifPresent(entry -> panel.highlightEntry(entry)));
    }
}

From source file:com.sec.ose.osi.ui.frm.tray.JTrayIconApp.java

private void initTray() {
    Image image = new ImageIcon(WindowUtil.class.getResource("icon.png")).getImage();

    mTrayIcon = new TrayIcon(image, mTrayTitle, createPopupMenu(BEFORE_LOGIN_STATE));
    mTrayIcon.setImageAutoSize(true);/*from ww  w  . j  a v  a2s  . c o m*/
    mTrayIcon.addMouseListener(new java.awt.event.MouseAdapter() {

        public void mousePressed(java.awt.event.MouseEvent e) {
            log.debug("mousePressed()");
            int state = 0;
            currentFrame = UISharedData.getInstance().getCurrentFrame();

            if (currentFrame == null)
                return;
            if (currentFrame.getClass().equals(JFrmLogin.class)) {
                state = BEFORE_LOGIN_STATE;
            } else {
                state = AFTER_LOGIN_STATE;
            }

            if (SwingUtilities.isRightMouseButton(e)) {
                mTrayIcon.setPopupMenu(createPopupMenu(state));
            }

            if (e.getClickCount() >= DOUBLE_CLICK && !e.isConsumed()) {
                currentFrame.setVisible(true);
            }
        }
    });

    try {
        mSystemTray.add(mTrayIcon);
    } catch (AWTException e1) {
        log.warn(e1.getMessage());
    }
}

From source file:com.ibm.soatf.gui.SOATestingFrameworkGUI.java

/**
 * initialization stuff like models, listeners, ... for GUI components and configuration initialization
 *//*from  w w w .  ja  v  a2 s.  c o  m*/
private void setupGUIComponents() {
    //called asynchronuously so that the GUI shows up much sooner while the initialization is going on in background
    //why is it in the AWT invokeLater? because AsyncWorker tasks have to be called from within the EventDispatch thread
    java.awt.EventQueue.invokeLater(new Runnable() {
        @Override
        public void run() {
            AsyncWorker.post(new AdditionalInitAsyncTask());
        }
    });

    //table with operation results
    jtResults.setModel(jtResultsModel);
    jtResults.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() > 1) {
                displayResultDetails();
            }
        }
    });
    //middle panel, with the interface details (tree)
    jtInterfaceDetails.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
}

From source file:com.openbravo.pos.sales.JTicketLines.java

/** Creates new form JLinesTicket */
public JTicketLines(AppView app, String propertyRowHeight, String propertyFontsize, String ticketline) {
    this.m_App = app;
    initComponents();// w  ww .jav a2s. c o  m

    m_jTicketTable.m_App = app;
    m_jTicketTable.propertyRowHeight = propertyRowHeight;

    ColumnTicket[] acolumns = new ColumnTicket[0];

    if (ticketline != null) {
        try {
            if (m_sp == null) {
                SAXParserFactory spf = SAXParserFactory.newInstance();
                m_sp = spf.newSAXParser();
            }
            ColumnsHandler columnshandler = new ColumnsHandler();
            m_sp.parse(new InputSource(new StringReader(ticketline)), columnshandler);
            acolumns = columnshandler.getColumns();

        } catch (ParserConfigurationException ePC) {
            logger.log(Level.WARNING, LocalRes.getIntString("exception.parserconfig"), ePC);
        } catch (SAXException eSAX) {
            logger.log(Level.WARNING, LocalRes.getIntString("exception.xmlfile"), eSAX);
        } catch (IOException eIO) {
            logger.log(Level.WARNING, LocalRes.getIntString("exception.iofile"), eIO);
        }
    }

    Map<String, Integer> widths = PropertyUtil.getTicketLineWidths(m_App);
    for (ColumnTicket acolumn : acolumns) {
        Integer width = widths.get(acolumn.name);
        if (width == null) {
            continue;
        }
        acolumn.width = width;
    }

    m_jTableModel = new TicketTableModel(acolumns);
    m_jTicketTable.setModel(m_jTableModel);

    m_jTicketTable.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);
    TableColumnModel jColumns = m_jTicketTable.getColumnModel();
    for (int i = 0; i < acolumns.length; i++) {
        jColumns.getColumn(i).setPreferredWidth(acolumns[i].width);
        jColumns.getColumn(i).setResizable(true);
    }

    PropertyUtil.ScaleScrollbar(m_App, m_jScrollTableTicket);

    m_jTicketTable.getTableHeader().setReorderingAllowed(false);
    // m_jTicketTable.setDefaultRenderer(Object.class, new
    // TicketCellRenderer(app, acolumns, propertyFontsize));
    m_jTicketTable.setDefaultRenderer(Object.class,
            new RowHeightCellRenderer(app, acolumns, propertyFontsize, propertyRowHeight));

    PropertyUtil.ScaleTableColumnFontsize(m_App, m_jTicketTable, "sales-tablecolumn-fontsize", "14");

    m_jTicketTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    m_jTicketTable.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent me) {
            JTable table = (JTable) me.getSource();
            Point p = me.getPoint();
            int row = table.rowAtPoint(p);
            if (me.getClickCount() == 2) {
                // your valueChanged overridden method
                listDoubleClickListener.valueChanged(new ListSelectionEvent(m_jTicketTable, row, row, false));
            }
        }
    });
    // reseteo la tabla...
    m_jTableModel.clear();
}

From source file:nz.govt.natlib.ndha.manualdeposit.customizemetadata.CustomizeMetaDataForm.java

private void initComponents() {

    pnlButtons = new javax.swing.JPanel();
    btnClose = new javax.swing.JButton();
    btnSaveAndClose = new javax.swing.JButton();
    btnOpen = new javax.swing.JButton();
    scrlMetaDataList = new javax.swing.JScrollPane();
    tblMetaDataList = new javax.swing.JTable();

    setTitle("MetaData Customization");
    setName("CustomizeMetaDataForm"); // NOI18N
    addWindowListener(new java.awt.event.WindowAdapter() {
        public void windowClosing(java.awt.event.WindowEvent evt) {
            formWindowClosing(evt);//from   w w w. j  ava2 s.c  o  m
        }

        public void windowOpened(java.awt.event.WindowEvent evt) {
            formWindowOpened(evt);
        }
    });

    btnClose.setText("Close");
    btnClose.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            btnCloseActionPerformed(evt);
        }
    });

    btnSaveAndClose.setText("Save and Close");
    btnSaveAndClose.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            btnSaveAndCloseActionPerformed(evt);
        }
    });

    btnOpen.setText("Open");
    btnOpen.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            btnOpenActionPerformed(evt);
        }
    });

    tblMetaDataList.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            if (tblMetaDataList.getSelectedColumnCount() == 0 || tblMetaDataList.getSelectedColumnCount() > 1) {
                btnOpen.setEnabled(false);
            } else if (tblMetaDataList.getSelectedRowCount() > 1) {
                btnOpen.setEnabled(false);
            } else if (tblMetaDataList.getSelectedColumn() == 0) {
                btnOpen.setEnabled(true);
                if (e.getClickCount() == 2) {
                    btnOpenActionPerformed(null);
                }
            } else {
                btnOpen.setEnabled(false);
            }
        }
    });

    javax.swing.GroupLayout pnlButtonsLayout = new javax.swing.GroupLayout(pnlButtons);
    pnlButtonsLayout.setHorizontalGroup(pnlButtonsLayout.createParallelGroup(Alignment.LEADING)
            .addGroup(pnlButtonsLayout.createSequentialGroup().addContainerGap().addComponent(btnClose)
                    .addPreferredGap(ComponentPlacement.UNRELATED).addComponent(btnSaveAndClose).addGap(48)
                    .addComponent(btnOpen).addContainerGap(560, Short.MAX_VALUE)));
    pnlButtonsLayout.setVerticalGroup(pnlButtonsLayout.createParallelGroup(Alignment.LEADING)
            .addGroup(pnlButtonsLayout.createSequentialGroup().addContainerGap()
                    .addGroup(pnlButtonsLayout.createParallelGroup(Alignment.BASELINE).addComponent(btnClose)
                            .addComponent(btnSaveAndClose).addComponent(btnOpen))
                    .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
    pnlButtons.setLayout(pnlButtonsLayout);

    tblMetaDataList
            .setModel(new javax.swing.table.DefaultTableModel(
                    new Object[][] { { null, null, null, null }, { null, null, null, null },
                            { null, null, null, null }, { null, null, null, null } },
                    new String[] { "Title 1", "Title 2", "Title 3", "Title 4" }));
    scrlMetaDataList.setViewportView(tblMetaDataList);
    tblMetaDataList.setCellSelectionEnabled(true);
    // Add Copy/Paste/Delete functionality to the Customize Meta Data table.
    CustomizeExcelAdapter copyPastFunct = new CustomizeExcelAdapter(tblMetaDataList);

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pnlButtons, javax.swing.GroupLayout.DEFAULT_SIZE,
                    javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(scrlMetaDataList, javax.swing.GroupLayout.DEFAULT_SIZE, 853, Short.MAX_VALUE));
    layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                    .addComponent(scrlMetaDataList, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
                    .addGap(8, 8, 8).addComponent(pnlButtons, javax.swing.GroupLayout.PREFERRED_SIZE,
                            javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)));

    pack();
}

From source file:EventTestPane.java

/**
 * Display mouse events that don't involve mouse motion. The mousemods()
 * method prints modifiers, and is defined below. The other methods return
 * additional information about the mouse event. showLine() displays a line
 * of text in the window. It is defined at the end of this class, along with
 * the paintComponent() method./*from  w ww  .j  a v  a  2 s .c  om*/
 */
public void processMouseEvent(MouseEvent e) {
    String type = null;
    switch (e.getID()) {
    case MouseEvent.MOUSE_PRESSED:
        type = "MOUSE_PRESSED";
        break;
    case MouseEvent.MOUSE_RELEASED:
        type = "MOUSE_RELEASED";
        break;
    case MouseEvent.MOUSE_CLICKED:
        type = "MOUSE_CLICKED";
        break;
    case MouseEvent.MOUSE_ENTERED:
        type = "MOUSE_ENTERED";
        break;
    case MouseEvent.MOUSE_EXITED:
        type = "MOUSE_EXITED";
        break;
    }
    showLine(mousemods(e) + type + ": [" + e.getX() + "," + e.getY() + "] " + "num clicks = "
            + e.getClickCount() + (e.isPopupTrigger() ? "; is popup trigger" : ""));

    // When the mouse enters the component, request keyboard focus so
    // we can receive and respond to keyboard events
    if (e.getID() == MouseEvent.MOUSE_ENTERED)
        requestFocus();
}

From source file:Main.java

/**
 * Display mouse events that don't involve mouse motion. The mousemods()
 * method prints modifiers, and is defined below. The other methods return
 * additional information about the mouse event. showLine() displays a line
 * of text in the window. It is defined at the end of this class, along with
 * the paintComponent() method./* w  w w .java2  s. com*/
 */
public void processMouseEvent(MouseEvent e) {
    String type = null;
    switch (e.getID()) {
    case MouseEvent.MOUSE_DRAGGED:
        type = "MOUSE_DRAGGED";
        break;
    case MouseEvent.MOUSE_RELEASED:
        type = "MOUSE_RELEASED";
        break;
    case MouseEvent.MOUSE_CLICKED:
        type = "MOUSE_CLICKED";
        break;
    case MouseEvent.MOUSE_ENTERED:
        type = "MOUSE_ENTERED";
        break;
    case MouseEvent.MOUSE_EXITED:
        type = "MOUSE_EXITED";
        break;
    }
    showLine(mousemods(e) + type + ": [" + e.getX() + "," + e.getY() + "] " + "num clicks = "
            + e.getClickCount() + (e.isPopupTrigger() ? "; is popup trigger" : ""));

    // When the mouse enters the component, request keyboard focus so
    // we can receive and respond to keyboard events
    if (e.getID() == MouseEvent.MOUSE_ENTERED)
        requestFocus();
}