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:gdsc.smlm.ij.plugins.SpotInspector.java

public void mouseClicked(MouseEvent e) {
    if (id != currentId)
        return;/*  ww w .j av  a  2  s  .com*/
    // Show the result that was double clicked in the result table
    if (e.getClickCount() > 1) {
        int rank = textPanel.getSelectionStart() + 1;

        // Show the spot that was double clicked
        ImagePlus imp = WindowManager.getImage(TITLE);
        if (imp != null && rank > 0 && rank <= imp.getStackSize()) {
            imp.setSlice(rank);
            if (imp.getWindow() != null)
                imp.getWindow().toFront();

            // Add an ROI to to the image containing all the spots in that part of the frame
            PeakResult r = rankedResults.get(rank - 1).peakResult;

            final int x = (int) (r.params[Gaussian2DFunction.X_POSITION]);
            final int y = (int) (r.params[Gaussian2DFunction.Y_POSITION]);

            // Find bounds
            int minX = x - radius;
            int minY = y - radius;
            int maxX = x + radius + 1;
            int maxY = y + radius + 1;

            // Create ROIs
            ArrayList<float[]> spots = new ArrayList<float[]>();
            for (PeakResult peak : results.getResults()) {
                if (peak.getXPosition() > minX && peak.getXPosition() < maxX && peak.getYPosition() > minY
                        && peak.getYPosition() < maxY) {
                    // Use only unique points
                    final float xPosition = peak.getXPosition() - minX;
                    final float yPosition = peak.getYPosition() - minY;
                    if (contains(spots, xPosition, yPosition))
                        continue;
                    spots.add(new float[] { xPosition, yPosition });
                }
            }

            int points = spots.size();
            float[] ox = new float[points];
            float[] oy = new float[points];
            for (int i = 0; i < points; i++) {
                ox[i] = spots.get(i)[0];
                oy[i] = spots.get(i)[1];
            }
            imp.setRoi(new PointRoi(ox, oy, points));
        }
    }
}

From source file:br.org.acessobrasil.ases.ferramentas_de_reparo.vista.corretor_eventos.PanelCorretorEventos.java

public void mouseClicked(MouseEvent e) {
    if (e.getClickCount() >= 2) {
        int row = this.tabelaDeErros.getSelectedRow();
        if (row == -1)
            return;
        int linhaToGo = Integer.parseInt(tabelaDeErros.getValueAt(row, 0).toString());
        if (linhaToGo == 0)
            return;
        System.out.println(linhaToGo);
        textAreaSourceCode.goToLine(linhaToGo);
        textAreaSourceCode.selectLine(linhaToGo);
        erroAtual = row;//from  ww  w.ja  va 2s  .  c om
        btnAplicar.setEnabled(true);
        RegrasHardCodedEmag regra = new RegrasHardCodedEmag();
        String evento[] = controle.getEventoErro(erroAtual);
        texto.setText(regra.getAtributo(controle.getTag(erroAtual), evento[1]));
        lbl_texto.setText(evento[0] + ": ");
    }
}

From source file:br.org.acessobrasil.ases.ferramentas_de_reparo.vista.links_redundantes.PanelLinkRedundante.java

public void mouseClicked(MouseEvent e) {
    if (e.getClickCount() >= 2) {
        int row = this.tabelaDeErros.getSelectedRow();
        if (row == -1)
            return;
        int linhaToGo = Integer.parseInt(tabelaDeErros.getValueAt(row, 0).toString());
        if (linhaToGo == 0)
            return;
        textAreaSourceCode.goToLine(linhaToGo);
        textAreaSourceCode.selectLine(linhaToGo);
        erroAtual = row;/*www. j  av  a 2s .c  o  m*/
        btnAplicar.setEnabled(true);
        RegrasHardCodedEmag regra = new RegrasHardCodedEmag();
        texto.setText(regra.getAtributo(controle.getTag(erroAtual), "alt"));
    }
}

From source file:net.sourceforge.entrainer.gui.socket.EntrainerSocketConnector.java

private void init() {
    initConnector();//from  w  w  w . j av a2  s .  co  m
    initListeners();
    wireSliders();
    initGui();

    addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            if (e.isControlDown() && e.getClickCount() == 1) {
                openBrowser(getLocalDocAddress());
            }
        }
    });
}

From source file:com.haulmont.cuba.desktop.gui.components.DesktopTree.java

@Override
public void setLookupSelectHandler(Runnable selectHandler) {
    impl.addMouseListener(new MouseAdapter() {
        @Override//from   w  w w .ja va2 s . co  m
        public void mousePressed(MouseEvent e) {
            if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) {
                int rowForLocation = impl.getRowForLocation(e.getX(), e.getY());
                TreePath pathForLocation = impl.getPathForRow(rowForLocation);
                if (pathForLocation != null) {
                    CollectionDatasource treeCds = getDatasource();
                    if (treeCds != null) {
                        TreeModelAdapter.Node treeItem = (TreeModelAdapter.Node) pathForLocation
                                .getLastPathComponent();
                        if (treeItem != null) {
                            treeCds.setItem(treeItem.getEntity());
                            selectHandler.run();
                        }
                    }
                }
            }
        }
    });
}

From source file:com.intuit.tank.proxy.ProxyApp.java

private JPanel getTransactionTable() {
    JPanel frame = new JPanel(new BorderLayout());
    model = new TransactionTableModel();
    final JTable table = new TransactionTable(model);
    final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model);
    table.setRowSorter(sorter);/*from  ww  w .  ja  va 2  s .co  m*/
    final JPopupMenu pm = new JPopupMenu();
    JMenuItem item = new JMenuItem("Delete Selected");
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            int[] selectedRows = table.getSelectedRows();
            if (selectedRows.length != 0) {
                int response = JOptionPane.showConfirmDialog(ProxyApp.this,
                        "Are you sure you want to delete " + selectedRows.length + " Transactions?",
                        "Confirm Delete", JOptionPane.YES_NO_OPTION);
                if (response == JOptionPane.YES_OPTION) {
                    int[] correctedRows = new int[selectedRows.length];
                    for (int i = selectedRows.length; --i >= 0;) {
                        int row = selectedRows[i];
                        int index = (Integer) table.getValueAt(row, 0) - 1;
                        correctedRows[i] = index;
                    }
                    Arrays.sort(correctedRows);
                    for (int i = correctedRows.length; --i >= 0;) {
                        int row = correctedRows[i];
                        Transaction transaction = model.getTransactionForIndex(row);
                        if (transaction != null) {
                            model.removeTransaction(transaction, row);
                            isDirty = true;
                            saveAction.setEnabled(isDirty && !stopAction.isEnabled());
                        }
                    }
                }
            }
        }
    });
    pm.add(item);
    table.add(pm);

    table.addMouseListener(new MouseAdapter() {
        boolean pressed = false;

        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
                Point p = e.getPoint();
                int row = table.rowAtPoint(p);
                int index = (Integer) table.getValueAt(row, 0) - 1;
                Transaction transaction = model.getTransactionForIndex(index);
                if (transaction != null) {
                    detailsTF.setText(transaction.toString());
                    detailsTF.setCaretPosition(0);
                    detailsDialog.setVisible(true);
                }
            }
        }

        /**
         * @{inheritDoc
         */
        @Override
        public void mousePressed(MouseEvent e) {
            if (e.isPopupTrigger()) {
                pressed = true;
                int[] selectedRows = table.getSelectedRows();
                if (selectedRows.length != 0) {
                    pm.show(e.getComponent(), e.getX(), e.getY());
                }
            }
        }

        /**
         * @{inheritDoc
         */
        @Override
        public void mouseReleased(MouseEvent e) {
            if (!pressed && e.isPopupTrigger()) {
                int[] selectedRows = table.getSelectedRows();
                if (selectedRows.length != 0) {
                    pm.show(e.getComponent(), e.getX(), e.getY());
                }
            }
        }

    });

    JScrollPane pane = new JScrollPane(table);
    frame.add(pane, BorderLayout.CENTER);
    JPanel panel = new JPanel(new BorderLayout());
    JLabel label = new JLabel("Filter: ");
    panel.add(label, BorderLayout.WEST);
    final JLabel countLabel = new JLabel(" Count: 0 ");
    panel.add(countLabel, BorderLayout.EAST);
    final JTextField filterText = new JTextField("");
    filterText.addKeyListener(new KeyAdapter() {
        public void keyTyped(KeyEvent e) {
            String text = filterText.getText();
            if (text.length() == 0) {
                sorter.setRowFilter(null);
            } else {
                try {
                    sorter.setRowFilter(RowFilter.regexFilter(text));
                    countLabel.setText(" Count: " + sorter.getViewRowCount() + " ");
                } catch (PatternSyntaxException pse) {
                    System.err.println("Bad regex pattern");
                }
            }
        }
    });
    panel.add(filterText, BorderLayout.CENTER);

    frame.add(panel, BorderLayout.NORTH);
    return frame;
}

From source file:org.openmicroscopy.shoola.agents.measurement.view.ObjectInspector.java

/** Initializes the component composing the display. */
private void initComponents() {
    infoLabel = new JLabel(MAGNIFICATION + " is " + model.getDrawingView().getScaleFactor());
    //create the table
    fieldTable = new FigureTable(new FigureTableModel(attributeFields, COLUMN_NAMES));
    fieldTable.getTableHeader().setReorderingAllowed(false);
    fieldTable.setRowHeight(26);/*  ww w  . ja v  a  2s  .co m*/
    fieldTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    fieldTable.setCellSelectionEnabled(true);
    fieldTable.setColumnSelectionAllowed(true);
    fieldTable.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {

            int col = fieldTable.getSelectedColumn();
            int row = fieldTable.getSelectedRow();
            Object value = fieldTable.getValueAt(row, col);
            if (e.getClickCount() == 1) {
                if (value instanceof Boolean) {
                    toggleValue();
                }
            } else if (e.getClickCount() > 1) {
                e.consume();
                if (value instanceof Color) {
                    //Only if the figure is not read only.
                    FigureTableModel ftm = (FigureTableModel) fieldTable.getModel();
                    ROIFigure figure = ftm.getFigure();
                    if (figure != null && !figure.isReadOnly())
                        if (figure.canEdit())
                            controller.showColorPicker((Color) value);
                } else if (value instanceof Boolean) {
                    toggleValue();
                }
            }
        }
    });
    fieldTable.addPropertyChangeListener(new PropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent evt) {
            String name = evt.getPropertyName();
            if (FigureTable.VALUE_CHANGED_PROPERTY.equals(name)) {
                handleValueChanged((String) evt.getNewValue());
            }
        }
    });
}

From source file:com.diversityarrays.kdxplore.curate.TraitsAndInstancesPanel2.java

public TraitsAndInstancesPanel2(CurationContext cc, Font smallFont, TIStatsTableModel tistm,
        boolean anyInstanceNumbers, int nInvalidRules, String tAndIpanelLabel,
        CurationMenuProvider curationMenuProvider, Consumer<List<OutlierSelection>> outlierConsumer) {
    super(new BorderLayout());

    this.curationContext = cc;
    this.outlierConsumer = outlierConsumer;
    this.curationMenuProvider = curationMenuProvider;

    this.tiStatsModel = tistm;

    curationContext.addPropertyChangeListener(propertyChangeListener);

    traitInstanceStatsTable = new TraitInstanceStatsTable(tiStatsModel);

    traitInstanceStatsTable.addPropertyChangeListener("rowSorter", rowSorterChangeListener);
    traitInstanceStatsTable.setAutoCreateRowSorter(true);

    traitInstanceStatsTable.addMouseListener(new MouseAdapter() {
        @Override//from   w w  w .ja va 2 s . c o m
        public void mouseClicked(MouseEvent me) {
            int clickCount = me.getClickCount();

            if (SwingUtilities.isRightMouseButton(me) && 1 == clickCount) {
                me.consume();
                showContextMenu(me);
            } else if (SwingUtilities.isLeftMouseButton(me) && 2 == clickCount) {
                showTraitInstanceInfo(me);
            }
        }
    });

    Map<String, TableColumn[]> tableColumnsByChoice = createInstanceTableColumnsByChoice();
    TableColumnSelectionButton tcsb = new TableColumnSelectionButton(traitInstanceStatsTable,
            tableColumnsByChoice);

    StringCellRenderer scRenderer = new StringCellRenderer();
    scRenderer.setHorizontalAlignment(SwingConstants.CENTER);

    statDetailRenderer.setHorizontalAlignment(SwingConstants.CENTER);

    traitInstanceStatsTable.setDefaultRenderer(String.class, scRenderer);
    Transformer<TraitInstance, String> instanceNameTransformer = new Transformer<TraitInstance, String>() {
        @Override
        public String transform(TraitInstance ti) {
            return curationContext.makeTraitInstanceName(ti);
        }
    };
    TraitInstanceCellRenderer tiRenderer = new TraitInstanceCellRenderer(
            curationContext.getTraitColorProvider(), instanceNameTransformer);
    tiRenderer.setName("FOR-STATS-TABLE"); //$NON-NLS-1$
    traitInstanceStatsTable.setDefaultRenderer(TraitInstance.class, tiRenderer);
    traitInstanceStatsTable.setDefaultRenderer(Comparable.class, statDetailRenderer);

    TableColumnModel tcm = traitInstanceStatsTable.getColumnModel();
    Integer viewColumnIndex = tistm.getViewColumnIndex();
    if (viewColumnIndex != null) {
        TableColumn viewColumn = tcm.getColumn(viewColumnIndex);
        viewColumn.setMaxWidth(40);
        viewColumn.setCellRenderer(new OptionalCheckboxRenderer("No Values"));
    }

    if (nInvalidRules <= 0) {
        // Hide that column!
        int columnIndex = tistm.getValRuleErrorColumnIndex();
        columnIndex = traitInstanceStatsTable.convertColumnIndexToView(columnIndex);
        if (columnIndex >= 0) {
            TableColumn c = tcm.getColumn(columnIndex);
            tcm.removeColumn(c);
        }
    }

    TableColumn dataTypeTableColumn = traitInstanceStatsTable.getColumnModel()
            .getColumn(tistm.getTraitInstanceDatatypeColumnIndex());
    dataTypeTableColumn.setCellRenderer(new TraitDataTypeRenderer());

    Function<JTable, JScrollPane> scrollMaker = new Function<JTable, JScrollPane>() {
        @Override
        public JScrollPane apply(JTable t) {
            return new PromptScrollPane(t, "Select Trait in the Panel: " + tAndIpanelLabel);
        }
    };
    TitledTablePanelWithResizeControls ttp = new TitledTablePanelWithResizeControls("Trait Instances",
            traitInstanceStatsTable, smallFont, scrollMaker);
    ttp.scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    ttp.scrollPane.setCorner(JScrollPane.UPPER_RIGHT_CORNER, tcsb);

    new CurationContextOptionsPopup(curationContext, ttp.separator);

    if (anyInstanceNumbers) {
        tcsb.setSelectedColumns(SimpleStatistics.GROUP_BASIC_STATS);
    } else {
        Set<Object> headerValues = new HashSet<>();
        for (TableColumn tc : tableColumnsByChoice.get(SimpleStatistics.GROUP_BASIC_STATS)) {
            headerValues.add(tc.getHeaderValue());
        }
        headerValues.remove(tistm.getInstanceHeading());
        tcsb.initialiseSelectedColumns(new Predicate<Object>() {
            @Override
            public boolean evaluate(Object hvalue) {
                return headerValues.contains(hvalue);
            }
        });
    }

    add(ttp, BorderLayout.CENTER);
}

From source file:edu.ku.brc.ui.ChooseFromListDlg.java

/**
 * Create the UI for the dialog.//from  ww  w  .j av  a  2  s.c  o  m
 * 
 * @param altName title for dialog
 * @param desc the list to be selected from
 * @param includeCancelBtn  indicates whether to create and display a cancel btn
 * @param includeHelpBtn indicates whether to create and display a help btn
 * @param helpContext help context identifier
 * @param titleArg title for dialog
 * @param desc the list to be selected from
 * @param includeCancelBtn indicates whether to create and display a cancel btn
 */
public void createUI() {
    setTitle(title);

    boolean hasDesc = StringUtils.isNotEmpty(desc);
    PanelBuilder builder = new PanelBuilder(
            new FormLayout("f:max(300px;p):g", "p," + (hasDesc ? "2px,p," : "") + "5px,p"));
    CellConstraints cc = new CellConstraints();
    //builder.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 10));
    builder.setDefaultDialogBorder();

    int y = 1;
    if (hasDesc) {
        JLabel lbl = createLabel(desc, SwingConstants.CENTER);
        builder.add(lbl, cc.xy(1, y));
        y += 2;
    }

    try {
        ListModel listModel = new AbstractListModel() {
            public int getSize() {
                return items.size();
            }

            public Object getElementAt(int index) {
                return items.get(index).toString();
            }
        };

        list = new JList(listModel);
        if (icon != null) {
            list.setCellRenderer(getListCellRenderer()); // icon comes from the base
            // class (it's probably size
            // 16)
        }
        list.setSelectionMode(isMultiSelect ? ListSelectionModel.MULTIPLE_INTERVAL_SELECTION
                : ListSelectionModel.SINGLE_SELECTION);
        list.setVisibleRowCount(10);

        if (selectedIndices != null) {
            list.setSelectedIndices(selectedIndices);
        }

        list.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                if (e.getClickCount() == 2) {
                    okBtn.doClick(); // emulate button click
                }
            }
        });
        list.addListSelectionListener(new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent e) {
                if (!e.getValueIsAdjusting()) {
                    updateUIState();
                }
            }
        });
        JScrollPane listScroller = new JScrollPane(list);
        builder.add(listScroller, cc.xy(1, y));
        y += 2;

        // Bottom Button UI
        okBtn = createButton(StringUtils.isNotEmpty(okLabel) ? okLabel : getResourceString("OK"));
        okBtn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                isCancelled = false;
                btnPressed = OK_BTN;
                setVisible(false);
            }
        });
        getRootPane().setDefaultButton(okBtn);

        if ((whichBtns & CANCEL_BTN) == CANCEL_BTN) {
            cancelBtn = createButton(
                    StringUtils.isNotEmpty(cancelLabel) ? cancelLabel : getResourceString("CANCEL"));
            cancelBtn.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    isCancelled = true;
                    btnPressed = CANCEL_BTN;
                    setVisible(false);
                }
            });
        }

        if ((whichBtns & HELP_BTN) == HELP_BTN) {
            helpBtn = createButton(
                    StringUtils.isNotEmpty(cancelLabel) ? cancelLabel : getResourceString("HELP"));
            if (StringUtils.isNotEmpty(helpContext)) {
                HelpMgr.registerComponent(helpBtn, helpContext);
            } else {
                helpBtn.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent ae) {
                        btnPressed = HELP_BTN;
                    }
                });
            }
        }

        if ((whichBtns & APPLY_BTN) == APPLY_BTN) {
            applyBtn = createButton(
                    StringUtils.isNotEmpty(applyLabel) ? applyLabel : getResourceString("Apply"));
            applyBtn.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    btnPressed = APPLY_BTN;
                    if (isCloseOnApply) {
                        isCancelled = false;
                        setVisible(false);
                    }
                }
            });
        }

        JPanel bb;
        if (whichBtns == OK_BTN) {
            bb = ButtonBarFactory.buildOKBar(okBtn);

        } else if (whichBtns == OKCANCEL) {
            bb = ButtonBarFactory.buildOKCancelBar(okBtn, cancelBtn);

        } else if (whichBtns == OKCANCELAPPLY) {
            bb = ButtonBarFactory.buildOKCancelApplyBar(okBtn, cancelBtn, applyBtn);

        } else if (whichBtns == OKHELP) {
            bb = ButtonBarFactory.buildOKHelpBar(okBtn, helpBtn);

        } else if (whichBtns == OKCANCELHELP) {
            bb = ButtonBarFactory.buildOKCancelHelpBar(okBtn, cancelBtn, helpBtn);

        } else if (whichBtns == OKCANCELAPPLYHELP) {
            bb = ButtonBarFactory.buildOKCancelApplyHelpBar(okBtn, cancelBtn, applyBtn, helpBtn);

        } else {
            bb = ButtonBarFactory.buildOKBar(okBtn);
        }

        builder.add(bb, cc.xy(1, y));
        y += 2;

        updateUIState();

    } catch (Exception ex) {
        edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
        edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ChooseFromListDlg.class, ex);
        log.error(ex);
    }

    setContentPane(builder.getPanel());
    pack();
    // setLocationRelativeTo(locationComp);
}

From source file:org.apache.syncope.ide.netbeans.view.ResourceExplorerTopComponent.java

private void resourceExplorerTreeMouseClicked(final java.awt.event.MouseEvent evt) {
    if (evt.getButton() == MouseEvent.BUTTON1 && evt.getClickCount() == 2) {
        DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) resourceExplorerTree
                .getLastSelectedPathComponent();
        DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) selectedNode.getParent();
        String parentNodeName = parentNode == null ? null : String.valueOf(parentNode.getUserObject());
        if (selectedNode.isLeaf() && StringUtils.isNotBlank(parentNodeName)) {
            String leafNodeName = (String) selectedNode.getUserObject();
            try {
                if (PluginConstants.MAIL_TEMPLATES.equals(parentNodeName)) {
                    openMailEditor(leafNodeName);
                } else if (PluginConstants.REPORT_XSLTS.equals(parentNodeName)) {
                    openReportEditor(leafNodeName);
                }/* w  ww . ja  v  a 2 s . com*/
            } catch (IOException e) {
                Exceptions.printStackTrace(e);
            }
        }
    } else if (evt.getButton() == MouseEvent.BUTTON3 && evt.getClickCount() == 1) {
        DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) resourceExplorerTree
                .getLastSelectedPathComponent();
        String selectedNodeName = (String) selectedNode.getUserObject();
        if (selectedNode.isLeaf() && !PluginConstants.ROOT_NAME.equals(selectedNodeName)
                && !PluginConstants.MAIL_TEMPLATES.equals(selectedNodeName)
                && !PluginConstants.REPORT_XSLTS.equals(selectedNodeName)) {
            leafRightClickAction(evt, selectedNode);
        } else if (PluginConstants.MAIL_TEMPLATES.equals(selectedNodeName)) {
            folderRightClickAction(evt, mailTemplates);
        } else if (PluginConstants.REPORT_XSLTS.equals(selectedNodeName)) {
            folderRightClickAction(evt, reportXslts);
        } else if (PluginConstants.ROOT_NAME.equals(selectedNodeName)) {
            rootRightClickAction(evt);
        }
    }
}