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.ac.lkl.cram.ui.ModuleFrame.java

private JXTaskPane createLearningExperienceChartPane() {
    JXTaskPane experienceChartPane = new JXTaskPane();
    experienceChartPane.setScrollOnExpand(true);
    experienceChartPane.setTitle("Learning Experiences");
    final LearningExperienceChartMaker maker = new LearningExperienceChartMaker(module);
    final ChartPanel chartPanel = maker.getChartPanel();
    //Add a mouselistener, listening for a double click on a bar of the stacked bar
    chartPanel.addChartMouseListener(new ChartMouseListener() {
        @Override//from   w  ww  . j ava2 s.c o m
        public void chartMouseClicked(ChartMouseEvent cme) {
            //Get the mouse event
            MouseEvent trigger = cme.getTrigger();
            //Test if the mouse event is a left-button
            if (trigger.getButton() == MouseEvent.BUTTON1 && trigger.getClickCount() == 2) {
                //Get the selected segment of the pie
                CategoryItemEntity bar = (CategoryItemEntity) cme.getEntity();
                //Get the row key that corresponds to that segment--this is a learning experience
                String key = bar.getRowKey().toString();
                //Get the set of tlalineitems whose activity contains that learning type
                Set<TLALineItem> relevantTLAs = maker.getLearningExperienceMap().get(key);
                //Create a pop up dialog containing that set of tlalineitems
                LearningExperiencePopupDialog popup = new LearningExperiencePopupDialog(
                        (Frame) SwingUtilities.getWindowAncestor(chartPanel), true, relevantTLAs);
                //Set the title of the popup to indicate which learning type was selected
                popup.setTitle("Activities with \'" + key + "\'");
                //Centre the popup at the location of the mouse click
                Point location = trigger.getLocationOnScreen();
                int w = popup.getWidth();
                int h = popup.getHeight();
                popup.setLocation(location.x - w / 2, location.y - h / 2);
                popup.setVisible(true);
                int returnStatus = popup.getReturnStatus();
                if (returnStatus == LearningTypePopupDialog.RET_OK) {
                    modifyTLALineItem(popup.getSelectedTLALineItem(), 0);
                }
            }
        }

        @Override
        public void chartMouseMoved(ChartMouseEvent cme) {
            //Set the cursor shape according to the location of the cursor
            if (cme.getEntity() instanceof CategoryItemEntity) {
                chartPanel.setCursor(HAND);
            } else {
                chartPanel.setCursor(Cursor.getDefaultCursor());
            }
        }
    });
    chartPanel.setPreferredSize(new Dimension(125, 75));
    chartPanel.setMinimumDrawHeight(75);
    experienceChartPane.add(chartPanel);
    return experienceChartPane;
}

From source file:uk.ac.lkl.cram.ui.ModuleFrame.java

private JXTaskPane createLearningTypeChartPane() {
    JXTaskPane typeChartPane = new JXTaskPane();
    typeChartPane.setTitle("Learning Types");
    typeChartPane.setScrollOnExpand(true);
    final LearningTypeChartMaker maker = new LearningTypeChartMaker(module);
    final ChartPanel chartPanel = maker.getChartPanel();
    //Add a mouse listener to the chart
    chartPanel.addChartMouseListener(new ChartMouseListener() {
        @Override//w  w  w.  jav  a 2  s.  co  m
        public void chartMouseClicked(ChartMouseEvent cme) {
            //Get the mouse event
            MouseEvent trigger = cme.getTrigger();
            //Test if the mouse event is a left-button
            if (trigger.getButton() == MouseEvent.BUTTON1 && trigger.getClickCount() == 2) {
                //Check that the mouse click is on a segment of the pie
                if (cme.getEntity() instanceof PieSectionEntity) {
                    //Get the selected segment of the pie
                    PieSectionEntity pieSection = (PieSectionEntity) cme.getEntity();
                    //Get the key that corresponds to that segment--this is a learning type
                    String key = pieSection.getSectionKey().toString();
                    //Get the set of tlalineitems whose activity contains that learning type
                    Set<TLALineItem> relevantTLAs = maker.getLearningTypeMap().get(key);
                    //Create a pop up dialog containing that set of tlalineitems
                    LearningTypePopupDialog popup = new LearningTypePopupDialog(
                            (Frame) SwingUtilities.getWindowAncestor(chartPanel), true, relevantTLAs, key);
                    //Set the title of the popup to indicate which learning type was selected
                    popup.setTitle("Activities with \'" + key + "\'");
                    //Centre the popup at the location of the mouse click
                    Point location = trigger.getLocationOnScreen();
                    int w = popup.getWidth();
                    int h = popup.getHeight();
                    popup.setLocation(location.x - w / 2, location.y - h / 2);
                    popup.setVisible(true);
                    int returnStatus = popup.getReturnStatus();
                    if (returnStatus == LearningTypePopupDialog.RET_OK) {
                        modifyTLALineItem(popup.getSelectedTLALineItem(), 0);
                    }
                }
            }
        }

        @Override
        public void chartMouseMoved(ChartMouseEvent cme) {
            //Set the cursor shape according to the location of the cursor
            if (cme.getEntity() instanceof PieSectionEntity) {
                chartPanel.setCursor(HAND);
            } else {
                chartPanel.setCursor(Cursor.getDefaultCursor());
            }
        }
    });
    chartPanel.setPreferredSize(new Dimension(150, 200));
    typeChartPane.add(chartPanel);
    return typeChartPane;
}

From source file:streamme.visuals.Main.java

public void loadTray() {
    if (SystemTray.isSupported()) {
        tray = SystemTray.getSystemTray();

        PopupMenu popup = new PopupMenu();
        MenuItem exitItem = new MenuItem("Exit");
        exitItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                dispose();//from   w  w  w.j  a  v  a  2 s .  c o  m
            }
        });

        MenuItem openItem = new MenuItem("Open");
        openItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                minimizeToTray(false);
            }
        });

        popup.add(openItem);
        popup.add(exitItem);
        trayIcon = new TrayIcon(
                Toolkit.getDefaultToolkit().getImage(getClass().getClassLoader().getResource("res/icon16.png")),
                "StreamMe", popup);
        trayIcon.setImageAutoSize(true);
        trayIcon.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent evt) {
                if (evt.getClickCount() == 2) {
                    //minimizeToTray(false);
                    return;
                }
                if (evt.getButton() == 1) {
                    minimizeToTray(!isMinimizedToTray());
                }
            }
        });

        addWindowStateListener(new WindowStateListener() {
            public void windowStateChanged(WindowEvent e) {
                if (e.getNewState() == ICONIFIED || e.getNewState() == 7) {
                    minimizeToTray(true);
                }
            }
        });

        addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                minimizeToTray(true);
            }
        });
        try {
            tray.add(trayIcon);
        } catch (AWTException ex) {
            System.out.println("Error adding icon to tray");
        }
    }
}

From source file:com.vectionvr.jort.gui.MainFrame.java

private void jLabelLinkMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabelLinkMouseClicked
    if (evt.getClickCount() > 0) {
        if (isDesktopSupported()) {
            try {
                URI uri = new URI("http://www.vectionvr.com");
                getDesktop().browse(uri);
            } catch (IOException ex) {
            } catch (URISyntaxException ex) {
            }/*w w w .  j a  v a 2s. c  o  m*/
        } else {
        }
    }
}

From source file:savant.view.dialog.PluginRepositoryDialog.java

public final Component getCenterPanel(List<TreeBrowserEntry> roots) {
    table = new TreeTable(new TreeBrowserModel(roots) {
        @Override/*from  w  ww  .java2 s.  c om*/
        public String[] getColumnNames() {
            return new String[] { "Name", "Description", "Web Site" };
        }

        @Override
        public CellStyle getCellStyleAt(int rowIndex, int columnIndex) {
            return null;
        }
    });
    table.setSortable(true);
    table.setRespectRenderPreferredHeight(true);

    // configure the TreeTable
    table.setExpandAllAllowed(true);
    table.setShowTreeLines(false);
    table.setSortingEnabled(false);
    table.setRowHeight(18);
    table.setShowGrid(false);
    table.setIntercellSpacing(new Dimension(0, 0));
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    //table.expandAll();
    table.expandFirstLevel();
    table.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            int col = table.columnAtPoint(e.getPoint());
            if (col == 2) {
                Object o = table.getModel().getValueAt(table.rowAtPoint(e.getPoint()), col);
                if (o != null && (o instanceof URL)) {
                    System.out.println(o.toString());
                    try {
                        Desktop.getDesktop().browse(((URL) o).toURI());
                    } catch (Exception x) {
                        LOG.error("Unable to open link for " + o, x);
                    }
                    return;
                }
            }
            if (e.getClickCount() == 2) {
                downloadSelectedItem(true);
            }
        }
    });

    // do not select row when expanding a row.
    table.setSelectRowWhenToggling(false);

    table.getColumnModel().getColumn(0).setPreferredWidth(200);
    table.getColumnModel().getColumn(1).setPreferredWidth(520);
    table.getColumnModel().getColumn(2).setPreferredWidth(80);

    table.getColumnModel().getColumn(0).setCellRenderer(new FileRowCellRenderer());
    table.getColumnModel().getColumn(2).setCellRenderer(new WebLinkRenderer());

    // add searchable feature
    TableSearchable searchable = new TableSearchable(table) {

        @Override
        protected String convertElementToString(Object item) {
            if (item instanceof TreeBrowserEntry) {
                return ((TreeBrowserEntry) item).getType();
            }
            return super.convertElementToString(item);
        }
    };
    searchable.setMainIndex(0); // only search for name column

    JScrollPane scrollPane = new JScrollPane(table);

    JPanel panel = new JPanel(new BorderLayout(6, 6));
    panel.add(scrollPane, BorderLayout.CENTER);
    panel.setPreferredSize(new Dimension(800, 500));
    return panel;
}

From source file:uk.ac.lkl.cram.ui.ModuleFrame.java

/**
 * Creates new form ModuleFrame/*  ww w . j  a  va 2s  .c  o m*/
 * @param module the module that this window displays
 * @param file  
 */
public ModuleFrame(final Module module, File file) {
    this.module = module;
    this.moduleFile = file;
    this.setTitle(module.getModuleName());
    initComponents();
    //Add undo mechanism
    undoHandler = new UndoHandler();
    JMenuItem undoMI = editMenu.add(undoHandler.getUndoAction());
    JMenuItem redoMI = editMenu.add(undoHandler.getRedoAction());
    //Listen to the undo handler for when there is something to undo
    undoHandler.addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            //We're assuming there's only one property
            //If the new value is true, then there's something to undo
            //And thus the save menu item should be enabled
            Boolean newValue = (Boolean) evt.getNewValue();
            if (moduleFile != null) {
                saveMI.setEnabled(newValue);
            }
        }
    });
    editMenu.addSeparator();
    //Add cut, copy & paste menu items
    JMenuItem cutMI = editMenu.add(new JMenuItem(new DefaultEditorKit.CutAction()));
    cutMI.setText("Cut");
    JMenuItem copyMI = editMenu.add(new JMenuItem(new DefaultEditorKit.CopyAction()));
    copyMI.setText("Copy");
    JMenuItem pasteMI = editMenu.add(new JMenuItem(new DefaultEditorKit.PasteAction()));
    pasteMI.setText("Paste");

    //Listen for changes to the shared selection model
    sharedSelectionModel.addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            //Update the menu items
            modifyLineItemMI.setEnabled(evt.getNewValue() != null);
            removeLineItemMI.setEnabled(evt.getNewValue() != null);
        }
    });

    doubleClickListener = new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            //If the user double clicks, then treat this as a shortcut to modify the selected line item
            if (e.getClickCount() == 2) {
                modifySelectedLineItem();
            }
        }
    };

    //Set Accelerator keys
    undoMI.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_Z, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    redoMI.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_Y, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    cutMI.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_X, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    copyMI.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_C, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    pasteMI.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_V, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    newMI.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_N, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    openMI.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_O, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    saveMI.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    quitMI.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_Q, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    //Remove quit menu item and separator from file menu on Mac
    if (Utilities.isMac()) {
        fileMenu.remove(quitSeparator);
        fileMenu.remove(quitMI);
    }

    leftTaskPaneContainer.add(createCourseDataPane());
    leftTaskPaneContainer.add(createLineItemPane());
    leftTaskPaneContainer.add(createTutorHoursPane());
    leftTaskPaneContainer.add(createTutorCostPane());
    rightTaskPaneContainer.add(createLearningTypeChartPane());
    rightTaskPaneContainer.add(createLearningExperienceChartPane());
    rightTaskPaneContainer.add(createLearnerFeedbackChartPane());
    rightTaskPaneContainer.add(createHoursChartPane());
    rightTaskPaneContainer.add(createTotalCostsPane());
}

From source file:org.eclipse.jubula.rc.swing.listener.RecordActions.java

/**
 * creates CAP for Click on Graphics Component
 * @param id IComponentIdentifier/*from www. j  a  v a  2  s  .  c  o  m*/
 * @param me MouseEvent
 * @param source Component
 */
protected void clickGraphComp(IComponentIdentifier id, MouseEvent me, Component source) {
    if ((source instanceof JTable || source instanceof JList || source instanceof JTree
            || source instanceof JTabbedPane)) {
        clickInComponent(id, me, source);
    } else {
        int clickcount = me.getClickCount();
        if (clickcount < 1) {
            clickcount = 1;
        }
        String clCount = (new Integer(clickcount).toString());
        String mbutton = (new Integer(me.getButton()).toString());
        Action a = m_recordHelper.compSysToAction(id, "CompSystem.Click"); //$NON-NLS-1$
        List parValues = new LinkedList();
        parValues.add(clCount);
        parValues.add(mbutton);

        String logName = createLogicalName(source, id);

        createCAP(a, id, parValues, logName);
    }
}

From source file:org.pmedv.core.components.RelativeImageView.java

/**
 * On double-click, open image properties dialog.
 * /*from  w  w w .java 2 s.  c o m*/
 * @param me
 *            MouseEvent to handle
 */
public void mouseClicked(MouseEvent me) {

    if (me.getClickCount() == 2) {
        // TODO: IMPLEMENT MOUSECLICKED method
    }
}

From source file:it.unibas.spicygui.vista.listener.MyMouseEventListener.java

private void dispacciaEventoDrag(Component com, MouseEvent e, Point point, boolean draggedEvent) {
    Point componentPoint = SwingUtilities.convertPoint(component, e.getPoint(), com);
    if (com != null) {
        if (com instanceof JTree) {
            TreePath treePath = ((JTree) com).getPathForLocation(componentPoint.x, componentPoint.y);
            if (treePath == null || draggedEvent) {
                component.updateUI();/*from  w w  w .  j  av a  2  s .co  m*/
                return;
            }
        }
        if ((!(com instanceof JScrollBar) && (tmp12 instanceof JScrollBar))) {
            jLayeredPane.moveToFront(component);
            component.updateUI();
            return;
        }

        com.dispatchEvent(new MouseEvent(component, e.getID(), e.getWhen(), e.getModifiers(), componentPoint.x,
                componentPoint.y, e.getClickCount(), e.isPopupTrigger()));
        jLayeredPane.moveToFront(component);
        component.updateUI();

    }
    jLayeredPane.moveToFront(component);
    component.updateUI();
}

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

@Override
public void mouseClicked(MouseEvent e) {

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

    // A double click on an entry should open the entry's editor.
    if (e.getClickCount() == 2) {

        BibtexEntry toShow = tableRows.get(row);
        editSignalled(toShow);//from   w  ww . j  av a  2 s  .com
    }

    // Check if the user has clicked on an icon cell to open url or pdf.
    final String[] iconType = table.getIconTypeForColumn(col);

    // 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 && (iconType != null) && (e.getButton() != MouseEvent.BUTTON1)) {
        return;
    }

    if (iconType != null) {
        // left click on icon field
        SpecialField field = SpecialFieldsUtils.getSpecialFieldInstanceFromFieldName(iconType[0]);
        if ((e.getClickCount() == 1) && (field != null)) {
            // 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());
            }
            return;
        }

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

        final BibtexEntry entry = tableRows.get(row);

        // Get the icon type. Corresponds to the field name.
        int hasField = -1;
        for (int i = iconType.length - 1; i >= 0; i--) {
            if (entry.getField(iconType[i]) != null) {
                hasField = i;
            }
        }
        if (hasField == -1) {
            return;
        }
        final String fieldName = iconType[hasField];

        //If this is a file link field with specified file types,
        //we should also pass the types.
        String[] fileTypes = {};
        if ((hasField == 0) && iconType[hasField].equals(Globals.FILE_FIELD) && (iconType.length > 1)) {
            fileTypes = iconType;
        }
        final List<String> listOfFileTypes = Collections.unmodifiableList(Arrays.asList(fileTypes));

        // Open it now. We do this in a thread, so the program won't freeze during the wait.
        JabRefExecutorService.INSTANCE.execute(new Runnable() {

            @Override
            public void run() {
                panel.output(Localization.lang("External viewer called") + '.');

                Object link = entry.getField(fieldName);
                if (link == null) {
                    LOGGER.info("Error: no link to " + fieldName + '.');
                    return; // There is an icon, but the field is not set.
                }

                // 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(Globals.FILE_FIELD)) {

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

                    FileListEntry flEntry = null;
                    // If there are one or more links of the correct type,
                    // open the first one:
                    if (!listOfFileTypes.isEmpty()) {
                        for (int i = 0; i < fileList.getRowCount(); i++) {
                            flEntry = fileList.getEntry(i);
                            boolean correctType = false;
                            for (String listOfFileType : listOfFileTypes) {
                                if (flEntry.getType().toString().equals(listOfFileType)) {
                                    correctType = true;
                                }
                            }
                            if (correctType) {
                                break;
                            }
                            flEntry = null;
                        }
                    }
                    //If there are no file types specified, consider all files.
                    else if (fileList.getRowCount() > 0) {
                        flEntry = fileList.getEntry(0);
                    }
                    if (flEntry != null) {
                        //                            if (fileList.getRowCount() > 0) {
                        //                                FileListEntry flEntry = fileList.getEntry(0);

                        ExternalFileMenuItem item = new ExternalFileMenuItem(panel.frame(), entry, "",
                                flEntry.getLink(), flEntry.getType().getIcon(), panel.metaData(),
                                flEntry.getType());
                        boolean success = item.openLink();
                        if (!success) {
                            panel.output(Localization.lang("Unable to open link."));
                        }
                    }
                } else {
                    try {
                        JabRefDesktop.openExternalViewer(panel.metaData(), (String) link, fieldName);
                    } catch (IOException ex) {
                        panel.output(Localization.lang("Unable to open link."));
                    }

                    /*ExternalFileType type = Globals.prefs.getExternalFileTypeByMimeType("text/html");
                    ExternalFileMenuItem item = new ExternalFileMenuItem
                        (panel.frame(), entry, "",
                        (String)link, type.getIcon(),
                        panel.metaData(), type);
                    boolean success = item.openLink();
                    if (!success) {
                    panel.output(Localization.lang("Unable to open link."));
                    } */
                    //Util.openExternalViewer(panel.metaData(), (String)link, fieldName);
                }

                //catch (IOException ex) {
                //    panel.output(Globals.lang("Error") + ": " + ex.getMessage());
                //}
            }

        });
    }
}