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:com.dnsoft.inmobiliaria.controllers.ConsultaCCPropietariosController.java

final void configuraTblPropietarios() {
    ((DefaultTableCellRenderer) view.tblPropietario.getTableHeader().getDefaultRenderer())
            .setHorizontalAlignment(SwingConstants.CENTER);

    listPropietarios = new ArrayList<>();

    tableModelPropietarios = new PropietariosTableModel(listPropietarios);
    view.tblPropietario.setModel(tableModelPropietarios);
    view.tblPropietario.setRowHeight(25);
    view.tblPropietario.getColumn("Activo").setMaxWidth(0);
    view.tblPropietario.getColumn("Activo").setMinWidth(0);
    view.tblPropietario.getColumn("Activo").setPreferredWidth(0);
    view.tblPropietario.getColumn("Activo").setWidth(0);
    view.tblPropietario.setDefaultRenderer(Object.class, new TableRendererColorActivo(2));
    ListSelectionModel listModel = view.tblPropietario.getSelectionModel();
    listModel.addListSelectionListener(new ListSelectionListener() {
        @Override/* w  w w.  j a va  2 s.  c  o  m*/
        public void valueChanged(ListSelectionEvent lse) {
            if (view.tblPropietario.getSelectedRow() != -1) {
                view.btnCuenta.setEnabled(true);
                view.btnPropietario.setEnabled(true);
            } else {
                view.btnCuenta.setEnabled(false);
                view.btnPropietario.setEnabled(false);
            }
        }
    });

    view.tblPropietario.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent me) {

            if (me.getClickCount() == 2) {
                detallesCCPropietario();
            }
        }
    });

}

From source file:org.pentaho.ui.xul.swing.tags.SwingListbox.java

public void setCommand(final String command) {
    this.command = command;
    listBox.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent event) {
            if (event.getClickCount() == 2) {
                invoke(command);//from w  w  w.j  ava2s.c  o m
            }
        }
    });
}

From source file:uk.nhs.cfh.dsp.srth.desktop.modules.resultexplanationpanel.ResultsExplanationPanel.java

/**
 * Inits the components.//from w  w w. j a v a2  s  .  c o  m
 */
public synchronized void initComponents() {

    while (activeFrame == null) {
        if (applicationService != null && applicationService.getFrameView() != null) {
            activeFrame = applicationService.getFrameView().getActiveFrame();
        }
    }
    // create collections dialog
    createCollectionsDialog();
    tableModel = new ReportingEngineExplanationTreeTableModel(queryService.getActiveQuery(), statsMap);
    treeTable = new JXTreeTable(tableModel);
    treeTable.setTreeCellRenderer(new SQLResultsExplanationTreeCellRenderer(queryExpressionHTMLRenderer));
    // add mouse listeners
    treeTable.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
                // get value at selection
                int row = treeTable.rowAtPoint(e.getPoint());
                if (row > -1) {
                    TreePath path = treeTable.getPathForLocation(e.getX(), e.getY());
                    // get node
                    Object node = path.getLastPathComponent();
                    if (node instanceof QueryExpression) {
                        QueryExpression expression = (QueryExpression) node;
                        // get collection for selected expression
                        QueryStatisticsCollection collection = statsMap.get(expression);
                        // set expression in collection panel
                        collectionPanel.setCollection(collection);
                        collectionPanel.revalidate();
                        // show collections dialog
                        collectionDialog.setVisible(true);
                    }
                }
            }
        }
    });

    // add components to this object
    setLayout(new BorderLayout());
    //      add(label, BorderLayout.NORTH);
    add(new JScrollPane(treeTable), BorderLayout.CENTER);

}

From source file:FillViewportHeightDemo.java

public FillViewportHeightDemo() {
    super("Empty Table DnD Demo");

    tableModel = getDefaultTableModel();
    table = new JTable(tableModel);
    table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    table.setDropMode(DropMode.INSERT_ROWS);

    table.setTransferHandler(new TransferHandler() {

        public boolean canImport(TransferSupport support) {
            // for the demo, we'll only support drops (not clipboard paste)
            if (!support.isDrop()) {
                return false;
            }/*from  w w  w. j  a  v  a 2 s.co  m*/

            // we only import Strings
            if (!support.isDataFlavorSupported(DataFlavor.stringFlavor)) {
                return false;
            }

            return true;
        }

        public boolean importData(TransferSupport support) {
            // if we can't handle the import, say so
            if (!canImport(support)) {
                return false;
            }

            // fetch the drop location
            JTable.DropLocation dl = (JTable.DropLocation) support.getDropLocation();

            int row = dl.getRow();

            // fetch the data and bail if this fails
            String data;
            try {
                data = (String) support.getTransferable().getTransferData(DataFlavor.stringFlavor);
            } catch (UnsupportedFlavorException e) {
                return false;
            } catch (IOException e) {
                return false;
            }

            String[] rowData = data.split(",");
            tableModel.insertRow(row, rowData);

            Rectangle rect = table.getCellRect(row, 0, false);
            if (rect != null) {
                table.scrollRectToVisible(rect);
            }

            // demo stuff - remove for blog
            model.removeAllElements();
            model.insertElementAt(getNextString(count++), 0);
            // end demo stuff

            return true;
        }
    });

    JList dragFrom = new JList(model);
    dragFrom.setFocusable(false);
    dragFrom.setPrototypeCellValue(getNextString(100));
    model.insertElementAt(getNextString(count++), 0);
    dragFrom.setDragEnabled(true);
    dragFrom.setBorder(BorderFactory.createLoweredBevelBorder());

    dragFrom.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent me) {
            if (SwingUtilities.isLeftMouseButton(me) && me.getClickCount() % 2 == 0) {
                String text = (String) model.getElementAt(0);
                String[] rowData = text.split(",");
                tableModel.insertRow(table.getRowCount(), rowData);
                model.removeAllElements();
                model.insertElementAt(getNextString(count++), 0);
            }
        }
    });

    JPanel p = new JPanel();
    p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
    JPanel wrap = new JPanel();
    wrap.add(new JLabel("Drag from here:"));
    wrap.add(dragFrom);
    p.add(Box.createHorizontalStrut(4));
    p.add(Box.createGlue());
    p.add(wrap);
    p.add(Box.createGlue());
    p.add(Box.createHorizontalStrut(4));
    getContentPane().add(p, BorderLayout.NORTH);

    JScrollPane sp = new JScrollPane(table);
    getContentPane().add(sp, BorderLayout.CENTER);
    fillBox = new JCheckBoxMenuItem("Fill Viewport Height");
    fillBox.addActionListener(this);

    JMenuBar mb = new JMenuBar();
    JMenu options = new JMenu("Options");
    mb.add(options);
    setJMenuBar(mb);

    JMenuItem clear = new JMenuItem("Reset");
    clear.addActionListener(this);
    options.add(clear);
    options.add(fillBox);

    getContentPane().setPreferredSize(new Dimension(260, 180));
}

From source file:se.trixon.jota.client.ui.editor.module.DualListPanel.java

private void initListeners() {
    availableListPanel.getList().addMouseListener(new MouseAdapter() {
        @Override//from  w  w  w.j av  a 2  s. com
        public void mouseClicked(MouseEvent evt) {
            if (evt.getButton() == MouseEvent.BUTTON1 && evt.getClickCount() == 2) {
                activate();
            }
        }
    });

    selectedListPanel.getList().addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent evt) {
            if (evt.getButton() == MouseEvent.BUTTON1 && evt.getClickCount() == 2) {
                deactivate();
            }
        }
    });
}

From source file:com.a544jh.kanamemory.ui.ProfileChooserPanel.java

private void profilesListMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_profilesListMouseClicked
    // Also respond to double click
    if (evt.getClickCount() == 2) {
        loadSelectedProfile();/*from  ww w.  j av  a2  s .c om*/
    }
}

From source file:de.jakop.ngcalsync.application.TrayStarter.java

private MouseAdapter createLogMouseListener(final JFrame logWindow) {
    return new MouseAdapter() {

        @Override//from w w w .  j a  va2 s.  c o  m
        public void mouseClicked(final MouseEvent e) {
            if (e.getClickCount() == 1 && e.getButton() == MouseEvent.BUTTON1) {
                logWindow.setVisible(!logWindow.isVisible());
            }
        }

    };
}

From source file:qic.ui.ManualPanel.java

@SuppressWarnings("serial")
public ManualPanel(Main main) {
    super(new BorderLayout(5, 5));

    table.setDoubleBuffered(true);/*from w  w  w  . j  a  v a  2 s. c om*/

    JTextField searchTf = new JTextField(100);
    JButton runBtn = new JButton("Run");
    runBtn.setPreferredSize(new Dimension(200, 10));
    JLabel invalidTermsLblLbl = new JLabel();
    invalidTermsLblLbl.setFont(invalidTermsLblLbl.getFont().deriveFont(Font.BOLD));
    JLabel invalidTermsLbl = new JLabel();
    invalidTermsLbl.setForeground(Color.RED);
    JPanel northPanel = new JPanel();
    northPanel.setLayout(new BoxLayout(northPanel, BoxLayout.X_AXIS));
    JLabel searchLbl = new JLabel(" Search: ");
    searchLbl.setFont(searchLbl.getFont().deriveFont(Font.BOLD));
    northPanel.add(searchLbl);
    northPanel.add(searchTf);
    northPanel.add(invalidTermsLblLbl);
    northPanel.add(invalidTermsLbl);
    northPanel.add(runBtn);
    this.add(northPanel, BorderLayout.NORTH);

    List<String> searchList = Util.loadSearchList(MANUAL_TXT_FILENAME);
    searchList.stream().forEach(searchJListModel::addElement);
    searchJList.setModel(searchJListModel);

    searchJList.addListSelectionListener(e -> {
        if (e.getValueIsAdjusting()) {
            searchTf.setText(trimToEmpty(searchJList.getSelectedValue()));
        }
    });
    searchJList.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent evt) {
            if (evt.getClickCount() == 2) {
                int index = searchJList.locationToIndex(evt.getPoint());
                if (index != -1) {
                    String search = trimToEmpty(searchJListModel.getElementAt(index));
                    searchTf.setText(search);
                    runBtn.doClick();
                }
            }
        }
    });

    searchJList.getInputMap().put(KeyStroke.getKeyStroke("DELETE"), "doSomething");
    searchJList.getActionMap().put("doSomething", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            int selectedIndex = searchJList.getSelectedIndex();
            if (selectedIndex != -1) {
                searchJListModel.remove(selectedIndex);
            }
        }
    });

    ActionListener runCommand = e -> {
        String tfText = searchTf.getText().trim();
        if (!tfText.isEmpty()) {
            Worker<Command> worker = new Worker<Command>(() -> {
                runBtn.setEnabled(false);
                Command result = null;
                try {
                    result = runQuery(main, tfText);
                } catch (Exception ex) {
                    runBtn.setEnabled(true);
                    SwingUtil.showError(ex);
                }
                return result;
            }, command -> {
                if (command != null) {
                    if (command.invalidSearchTerms.isEmpty()) {
                        addDataToTable(command);
                        saveSearchToList(tfText);
                        invalidTermsLbl.setText("");
                        invalidTermsLblLbl.setText("");
                        if (getBooleanProperty(MANUAL_AUTO_VERIFY, false)) {
                            long sleep = Config.getLongProperty(Config.MANUAL_AUTO_VERIFY_SLEEP, 5000);
                            table.runAutoVerify(sleep);
                        }
                    } else {
                        String invalidTermsStr = command.invalidSearchTerms.stream().collect(joining(", "));
                        invalidTermsLbl.setText(invalidTermsStr + " ");
                        invalidTermsLblLbl.setText(" Invalid: ");
                    }
                }
                runBtn.setEnabled(true);
            });
            worker.execute();
        }
    };

    searchTf.addActionListener(runCommand);
    runBtn.addActionListener(runCommand);

    splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(table),
            new JScrollPane(searchJList));

    this.add(splitPane, BorderLayout.CENTER);
}

From source file:au.org.ala.delta.intkey.ui.MultiStateInputDialog.java

/**
 * ctor/*from  w  w  w. ja v  a  2s  . c o m*/
 * 
 * @param owner
 *            Owner frame of dialog
 * @param ch
 *            the character whose states are being set
 * @param initialSelectedStates
 *            initial states that should be selected in the dialog. In
 *            general this should be any states already set for the
 *            character. In the case that this is a controlling character
 *            being set before its dependent character, all states that make
 *            the dependent character applicable should be selected.
 * @param dependentCharacter
 *            the dependent character - if the dialog is being used to set a
 *            controlling character before its dependent character, this
 *            argument should be a reference to the dependent character. In
 *            all other cases it should be null.
 * @param imageSettings
 *            image settings
 * @param displayNumbering
 *            true if numbering should be displayed
 * @param enableImagesButton
 *            the if the images button should be enabled
 * @param imagesStartScaled
 *            true if images should start scaled.
 */
public MultiStateInputDialog(Frame owner, MultiStateCharacter ch, Set<Integer> initialSelectedStates,
        au.org.ala.delta.model.Character dependentCharacter, ImageSettings imageSettings,
        boolean displayNumbering, boolean enableImagesButton, boolean imagesStartScaled, boolean advancedMode) {
    super(owner, ch, imageSettings, displayNumbering, enableImagesButton, imagesStartScaled, advancedMode);

    ResourceMap resourceMap = Application.getInstance().getContext()
            .getResourceMap(MultiStateInputDialog.class);
    resourceMap.injectFields(this);

    setTitle(title);
    setPreferredSize(new Dimension(600, 350));

    if (dependentCharacter != null) {
        _pnlControllingCharacterMessage = new JPanel();
        _pnlControllingCharacterMessage.setFocusable(false);
        _pnlControllingCharacterMessage.setBorder(new EmptyBorder(5, 0, 0, 0));
        _pnlMain.add(_pnlControllingCharacterMessage, BorderLayout.SOUTH);
        _pnlControllingCharacterMessage.setLayout(new BorderLayout(0, 0));

        _lblWarningIcon = new JLabel("");
        _lblWarningIcon.setFocusable(false);
        _lblWarningIcon.setIcon(UIManager.getIcon("OptionPane.warningIcon"));
        _pnlControllingCharacterMessage.add(_lblWarningIcon, BorderLayout.WEST);

        _txtControllingCharacterMessage = new JTextArea();
        _txtControllingCharacterMessage.setText(MessageFormat.format(setControllingCharacterMessage,
                _formatter.formatCharacterDescription(dependentCharacter),
                _formatter.formatCharacterDescription(ch)));
        _txtControllingCharacterMessage.setFocusable(false);
        _txtControllingCharacterMessage.setBorder(new EmptyBorder(0, 5, 0, 0));
        _txtControllingCharacterMessage.setEditable(false);
        _pnlControllingCharacterMessage.add(_txtControllingCharacterMessage);
        _txtControllingCharacterMessage.setWrapStyleWord(true);
        _txtControllingCharacterMessage.setFont(UIManager.getFont("Button.font"));
        _txtControllingCharacterMessage.setLineWrap(true);
        _txtControllingCharacterMessage.setBackground(SystemColor.control);
    }

    _scrollPane = new JScrollPane();
    _pnlMain.add(_scrollPane, BorderLayout.CENTER);

    _list = new JList();
    _scrollPane.setViewportView(_list);

    _listModel = new DefaultListModel();
    for (int i = 0; i < ch.getNumberOfStates(); i++) {
        _listModel.addElement(_formatter.formatState(ch, i + 1));
    }

    _list.setModel(_listModel);

    _list.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() > 1) {
                // Treat double click on a list item as the ok button being
                // pressed.
                _okPressed = true;
                handleBtnOKClicked();
            }
        }

    });

    // Select the list items that correspond to the initial selected states.
    if (initialSelectedStates != null) {
        List<Integer> listIndiciesToSelect = new ArrayList<Integer>();
        for (int stateNumber : new ArrayList<Integer>(initialSelectedStates)) {
            listIndiciesToSelect.add(stateNumber - 1);
        }

        Integer[] wrappedPrimitivesList = listIndiciesToSelect
                .toArray(new Integer[initialSelectedStates.size()]);
        _list.setSelectedIndices(ArrayUtils.toPrimitive(wrappedPrimitivesList));
    }

    _inputData = new HashSet<Integer>();

}