Example usage for java.awt.event MouseEvent getButton

List of usage examples for java.awt.event MouseEvent getButton

Introduction

In this page you can find the example usage for java.awt.event MouseEvent getButton.

Prototype

public int getButton() 

Source Link

Document

Returns which, if any, of the mouse buttons has changed state.

Usage

From source file:se.trixon.mapollage.ui.MainFrame.java

private void menuButtonMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_menuButtonMousePressed
    if (evt == null || evt.getButton() == MouseEvent.BUTTON1) {
        if (mPopupMenu.isVisible()) {
            mPopupMenu.setVisible(false);
        } else {//from   ww w . j  a v  a  2  s  .  co m
            mPopupMenu.show(menuButton, menuButton.getWidth() - mPopupMenu.getWidth(), mPopupMenu.getHeight());

            int x = menuButton.getLocationOnScreen().x + menuButton.getWidth() - mPopupMenu.getWidth();
            int y = menuButton.getLocationOnScreen().y + menuButton.getHeight();

            mPopupMenu.setLocation(x, y);
        }
    }
}

From source file:org.nuclos.client.ui.collect.searcheditor.SearchEditorController.java

/**
 * event: a mouse event occured on a node in the <code>view</code>
 * @param selPath the path of the node where the mouse event occured.
 * @param ev//from  w  ww. j  a  va 2s . c om
 */
private void mouseEventOnNode(TreePath selPath, MouseEvent ev) {
    final SearchConditionTreeNode node = (SearchConditionTreeNode) selPath.getLastPathComponent();
    final JTree tree = (JTree) ev.getComponent();

    // select the node:
    tree.setSelectionPath(selPath);

    if (ev.isPopupTrigger()) {
        // show popup menu:
        final JPopupMenu popupMenu = this.getPopupMenu(node, tree);
        if (popupMenu != null) {
            popupMenu.show(ev.getComponent(), ev.getX(), ev.getY());
        }
    } else if (ev.getID() == MouseEvent.MOUSE_CLICKED) {
        if (ev.getButton() == MouseEvent.BUTTON1) {
            if (ev.getClickCount() == 2) {
                if (this.clctfproviderfactory == null) {
                    throw new IllegalStateException(
                            "No CollectableFieldsProviderFactory was defined for the search editor.");
                }
                // perform the node's default action:
                final Action actDefault = node.getDefaultTreeNodeAction(tree, this.clcteRoot,
                        this.clctfproviderfactory, this.additionalFields);
                if (actDefault != null) {
                    actDefault.actionPerformed(null);
                }
            }
        }
    }
}

From source file:maltcms.ui.fileHandles.csv.CSVTableView.java

/**
 *
 * @param tm//from  w ww .java2  s.  c  o  m
 */
public void setTableModel(TableModel tm) {
    if (tm == null) {
        Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "Received table model was null!");
        return;
    }
    this.jTable1.setModel(tm);
    //default column model
    for (int i = 0; i < tm.getColumnCount(); i++) {
        this.jTable1.getColumnModel().getColumn(i).setCellRenderer(
                new ColorColumnRenderer(new Color(255, 255, 255, 255), jTable1.getSelectedRows()));
    }
    JTableCustomizer.changeComparators(this.jTable1);
    JTableCustomizer.fitAllColumnWidth(this.jTable1);
    this.jTable1.getTableHeader().addMouseListener(new MouseAdapter() {

        @Override
        public void mouseReleased(MouseEvent e) {
            if (e.getButton() == 3) {
                activeColumn = jTable1.getTableHeader().columnAtPoint(e.getPoint());
                int[] selectedRows = jTable1.getSelectedRows();
                int minRow = 0;//
                int maxRow = jTable1.getRowCount() - 1;//
                int[] selectedColumns = jTable1.getSelectedColumns();
                int minCol = 0;
                int maxCol = jTable1.getColumnCount() - 1;
                if (cellSelection) {
                    jTable1.setRowSelectionAllowed(true);
                    minRow = MathTools.min(selectedRows);
                    maxRow = MathTools.max(selectedRows);
                    minCol = MathTools.min(selectedColumns);
                    maxCol = MathTools.min(selectedColumns);
                } else {
                }

                jTable1.setColumnSelectionInterval(activeColumn, activeColumn);
                jTable1.setRowSelectionInterval(minRow, maxRow);
                createAndShowPopupMenu(e);
            }
        }
    });
}

From source file:org.accada.hal.impl.sim.multi.GraphicSimulatorServer.java

/**
 * creates the layered pane if it does not already exists
 * /*from   ww w.ja  v  a2 s .co m*/
 * @return layered pane
 */
private JLayeredPane getJLayeredPane() {
    if (jLayeredPane == null) {
        jLayeredPane = new JLayeredPane();
        jLayeredPane.setLayout(null);
        jLayeredPane.setOpaque(true);
        jLayeredPane.setBackground(Color.WHITE);
        //jLayeredPane.add(getReader(), new Integer(0));

        // add readers
        createReaders(controller.getReaderIds());

        // add context menu
        jLayeredPane.add(getContextMenu());

        // add mouse listener
        jLayeredPane.addMouseListener(new MouseAdapter() {

            // context menu
            public void mouseReleased(MouseEvent e) {
                hideActiveContextMenuAndSelection();
                if (e.getButton() == MouseEvent.BUTTON3) {
                    Point posOnScreen = getJLayeredPane().getLocationOnScreen();
                    contextMenu.setLocation(posOnScreen.x + e.getX(), posOnScreen.y + e.getY());
                    contextMenu.setVisible(true);
                    setActiveContextMenu(contextMenu);
                } else {
                    contextMenu.setVisible(false);
                    if (e.getButton() == MouseEvent.BUTTON1) {
                        selection.select(tags);
                    }
                }
            }

            // selection
            public void mousePressed(final MouseEvent e) {
                hideActiveContextMenuAndSelection();
                if (e.getButton() == MouseEvent.BUTTON1) {
                    selection.setBounds(0, 0, getProperty("WindowWidth"), getProperty("WindowHeight"));
                    selection.setStartPoint(e.getPoint());
                    jLayeredPane.add(selection, new Integer(2));
                }
            }
        });

        // add drag listener
        jLayeredPane.addMouseMotionListener(new MouseMotionAdapter() {
            public void mouseDragged(MouseEvent e) {
                if (selection.isActive()) {
                    selection.setCurrentPoint(e.getPoint());
                }
            }
        });
    }
    return jLayeredPane;
}

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

private JXTaskPane createLearnerFeedbackChartPane() {
    JXTaskPane feedbackChartPane = new JXTaskPane();
    feedbackChartPane.setScrollOnExpand(true);
    feedbackChartPane.setTitle("Learner Feedback");
    FeedbackChartMaker maker = new FeedbackChartMaker(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  w w  . ja v  a 2s . 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) {

                //Create a pop up dialog containing that the tlalineitems
                FeedbackPopupDialog popup = new FeedbackPopupDialog(
                        (Frame) SwingUtilities.getWindowAncestor(chartPanel), true, module.getTLALineItems());
                //Set the title of the popup 
                popup.setTitle("All Activities");
                //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(), 1);
                }
            }
        }

        @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(150, 200));
    feedbackChartPane.add(chartPanel);
    return feedbackChartPane;
}

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   ww w .  ja v  a  2  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  . ja v  a  2s. 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) {
                //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:org.accada.reader.hal.impl.sim.GraphicSimulator.java

/**
 * creates the layered pane if it does not already exists
 * /* w w  w .j  a  v  a2s.  c  om*/
 * @return layered pane
 */
private JLayeredPane getJLayeredPane() {
    if (jLayeredPane == null) {
        jLayeredPane = new JLayeredPane();
        jLayeredPane.setLayout(null);
        jLayeredPane.setOpaque(true);
        jLayeredPane.setBackground(Color.WHITE);
        jLayeredPane.add(getReader(), new Integer(0));

        // add antennas
        String[] antennaIds = null;
        try {
            antennaIds = controller.getReadPointNames();
        } catch (HardwareException ignored) {
        }
        for (int i = 0; i < antennaIds.length; i++) {
            createNewAntenna(antennaIds[i]);
        }
        jLayeredPane.add(getContextMenu());
        jLayeredPane.add(getMgmtSimMenu());

        // add mouse listener
        jLayeredPane.addMouseListener(new MouseAdapter() {

            // context menu
            public void mouseReleased(MouseEvent e) {
                hideActiveContextMenuAndSelection();
                if (e.getButton() == MouseEvent.BUTTON3) {
                    Point posOnScreen = getJLayeredPane().getLocationOnScreen();
                    contextMenu.setLocation(posOnScreen.x + e.getX(), posOnScreen.y + e.getY());
                    contextMenu.setVisible(true);
                    mgmtSimMenu.setVisible(false);
                    setActiveContextMenu(contextMenu);
                } else {
                    contextMenu.setVisible(false);
                    mgmtSimMenu.setVisible(false);
                    if (e.getButton() == MouseEvent.BUTTON1) {
                        selection.select(tags);
                    }
                }
            }

            // selection
            public void mousePressed(final MouseEvent e) {
                hideActiveContextMenuAndSelection();
                if (e.getButton() == MouseEvent.BUTTON1) {
                    selection.setBounds(0, 0, getProperty("WindowWidth"), getProperty("WindowHeight"));
                    selection.setStartPoint(e.getPoint());
                    jLayeredPane.add(selection, new Integer(2));
                }
            }
        });

        // add drag listener
        jLayeredPane.addMouseMotionListener(new MouseMotionAdapter() {
            public void mouseDragged(MouseEvent e) {
                if (selection.isActive()) {
                    selection.setCurrentPoint(e.getPoint());
                }
            }
        });
    }
    return jLayeredPane;
}

From source file:maltcms.ui.fileHandles.csv.CSVTableView.java

private void createAndShowPopupMenu(MouseEvent me) {
    if (me.getButton() == MouseEvent.BUTTON3 && this.jTable1.getSelectedRowCount() > 0 && this.jfctc != null) {

        JPopupMenu jpm = new JPopupMenu();

        //more than one column selected
        if (jTable1.getSelectedColumnCount() > 0) {
            jpm.add(new AbstractAction("Add as y-values") {

                @Override//www .  j a va  2s .co m
                public void actionPerformed(ActionEvent ae) {
                    for (int col : jTable1.getSelectedColumns()) {
                        columnsToPlot.add(col);
                        jTable1.getColumnModel().getColumn(col).setCellRenderer(new ColorColumnRenderer(
                                new Color(238, 187, 0, 255), jTable1.getSelectedRows()));
                    }
                    jfctc.setChart(
                            buildChart(labelColumn, domainColumn, columnsToPlot, jTable1.getSelectedRows()));
                }
            });
            //selected rows
            for (final int col : jTable1.getSelectedColumns()) {
                if (columnsToPlot.contains(col)) {
                    jpm.add(new AbstractAction("Remove y-values from chart") {

                        @Override
                        public void actionPerformed(ActionEvent ae) {
                            jTable1.getColumnModel().getColumn(col).setCellRenderer(
                                    new ColorColumnRenderer(Color.WHITE, jTable1.getSelectedRows()));
                            columnsToPlot.remove(col);
                            jfctc.setChart(buildChart(labelColumn, domainColumn, columnsToPlot,
                                    jTable1.getSelectedRows()));
                        }
                    });
                    break;
                }
            }
            jpm.add(new JPopupMenu.Separator());
            jpm.add(new AbstractAction("Log10 transform") {

                @Override
                public void actionPerformed(ActionEvent ae) {
                    final int[] cols = jTable1.getSelectedColumns();
                    for (int i = 0; i < jTable1.getSelectedColumnCount(); i++) {
                        logTransformColumn(cols[i], 10.0d);
                    }

                }
            });
            jpm.add(new AbstractAction("Inverse Log10 transform") {

                @Override
                public void actionPerformed(ActionEvent ae) {
                    final int[] cols = jTable1.getSelectedColumns();
                    for (int i = 0; i < jTable1.getSelectedColumnCount(); i++) {
                        inverseLogTransformColumn(cols[i], 10.0d);
                    }

                }
            });
        }
        jpm.add(new JPopupMenu.Separator());
        //exactly one selected column, no domain column
        if (jTable1.getSelectedColumnCount() == 1 && domainColumn == -1) {
            jpm.add(new AbstractAction("Set as x-values") {

                @Override
                public void actionPerformed(ActionEvent ae) {
                    domainColumn = jTable1.getSelectedColumn();
                    jTable1.getColumnModel().getColumn(domainColumn).setCellRenderer(
                            new ColorColumnRenderer(new Color(255, 0, 0, 255), jTable1.getSelectedRows()));
                    jfctc.setChart(
                            buildChart(labelColumn, domainColumn, columnsToPlot, jTable1.getSelectedRows()));
                }
            });

        }
        //one domainColumn
        if (domainColumn != -1) {
            jpm.add(new AbstractAction("Reset x-axis values") {

                @Override
                public void actionPerformed(ActionEvent ae) {
                    jTable1.getColumnModel().getColumn(domainColumn).setCellRenderer(
                            new ColorColumnRenderer(new Color(255, 255, 255, 255), jTable1.getSelectedRows()));
                    domainColumn = -1;
                    jfctc.setChart(
                            buildChart(labelColumn, domainColumn, columnsToPlot, jTable1.getSelectedRows()));
                }
            });
        }
        jpm.add(new JPopupMenu.Separator());
        if (jTable1.getSelectedColumnCount() == 1 && labelColumn == -1) {
            jpm.add(new AbstractAction("Set as series labels") {

                @Override
                public void actionPerformed(ActionEvent ae) {
                    labelColumn = jTable1.getSelectedColumn();
                    jTable1.getColumnModel().getColumn(labelColumn).setCellRenderer(
                            new ColorColumnRenderer(new Color(255, 255, 0, 255), jTable1.getSelectedRows()));
                    jfctc.setChart(
                            buildChart(labelColumn, domainColumn, columnsToPlot, jTable1.getSelectedRows()));
                }
            });
        }

        if (jTable1.getSelectedColumnCount() == 1 && labelColumn != -1) {
            jpm.add(new AbstractAction("Reset series labels") {

                @Override
                public void actionPerformed(ActionEvent ae) {
                    jTable1.getColumnModel().getColumn(labelColumn).setCellRenderer(
                            new ColorColumnRenderer(new Color(255, 255, 255, 255), jTable1.getSelectedRows()));
                    labelColumn = -1;
                    jfctc.setChart(
                            buildChart(labelColumn, domainColumn, columnsToPlot, jTable1.getSelectedRows()));
                }
            });
        }

        jpm.show(me.getComponent(), me.getX(), me.getY());
    }
}

From source file:ru.goodfil.catalog.ui.forms.OePanel.java

private void lstOesMouseClicked(MouseEvent e) {
    if (e.getButton() == MouseEvent.BUTTON3) {
        if (oes.size() > 0) {
            popupMenu1.show(lstOes, e.getX(), e.getY());
        }/*from   w  ww.ja v a 2s  . c  om*/
    }
}