Example usage for java.awt.event MouseEvent getPoint

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

Introduction

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

Prototype

public Point getPoint() 

Source Link

Document

Returns the x,y position of the event relative to the source component.

Usage

From source file:org.eurocarbdb.application.glycoworkbench.plugin.reporting.AnnotationReportCanvas.java

public void mouseClicked(MouseEvent e) {
    AnnotationObject a = getAnnotationAtPoint(e.getPoint());
    if (a == null)
        a = getConnectionAtPoint(e.getPoint());

    if (a != null) {
        if (MouseUtils.isAddSelectTrigger(e) || MouseUtils.isSelectAllTrigger(e))
            addSelection(a);//  w w  w .j a  v  a  2  s.c  o m
        else if (MouseUtils.isSelectTrigger(e))
            setSelection(a);
    } else
        resetSelection();
}

From source file:org.processmining.analysis.performance.advanceddottedchartanalysis.ui.DottedChartPanel.java

public void mousePressed(MouseEvent e) {
    clicked = true;// www.  ja  v  a2  s. co m
    if (clicked && dcop.getMouseMode().equals(ST_DRAG)) {
        p3 = e.getPoint();
        p4 = dca.getScrollPane().getViewport().getViewPosition();
        dca.reDrawBoxOnOverview();
    } else if (dcop.getMouseMode().equals(ST_SELECT)) {
        p1 = e.getPoint();
        p2 = e.getPoint();
        if (p3 != null && p4 != null)
            makeTooltip(p3, p4);
        repaint();
        p3 = e.getPoint();
    } else if (dcop.getMouseMode().equals(ST_ZOOMIN)) {
        p1 = e.getPoint();
        p2 = e.getPoint();
        repaint();
    }
}

From source file:org.processmining.analysis.performance.advanceddottedchartanalysis.ui.DottedChartPanel.java

public void mouseReleased(MouseEvent e) {
    clicked = false;/*w  ww. java2  s  .  c om*/
    if (dcop.getMouseMode().equals(ST_ZOOMIN)) {
        p2 = e.getPoint();
        if (p1 != null) {
            if (p2.x < p1.x && p2.y < p1.y) {
                dcop.zoomOut();
                p1 = null;
                p2 = null;
            } else {
                setViewportZoomIn();
                dca.reDrawBoxOnOverview();
            }
        }
    } else if (dcop.getMouseMode().equals(ST_SELECT)) {
        p2 = e.getPoint();
        p4 = e.getPoint();
        if (p1 != null) {
            makeTooltip(p1, e.getPoint());
        }
        p1 = null;
        p2 = null;
        repaint();
    } else if (dcop.getMouseMode().equals(ST_DRAG)) {
        dca.reDrawBoxOnOverview();
    }
}

From source file:org.zaproxy.zap.extension.multiFuzz.impl.http.HttpFuzzerContentPanel.java

public JXTreeTable getFuzzResultTable() {
    if (fuzzResultTable == null) {
        resetFuzzResultTable();/* w  w w  .java  2s  .  c om*/
        fuzzResultTable = new JXTreeTable(getResultsModel());
        fuzzResultTable.setName("HttpFuzzResultTable");
        fuzzResultTable.setDoubleBuffered(true);
        fuzzResultTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);
        fuzzResultTable.setFont(new java.awt.Font("Default", java.awt.Font.PLAIN, 12));
        fuzzResultTable.setDefaultRenderer(Pair.class, new IconTableCellRenderer());

        int[] widths = { 10, 25, 550, 30, 85, 55, 40, 70 };
        for (int i = 0, count = widths.length; i < count; i++) {
            TableColumn column = fuzzResultTable.getColumnModel().getColumn(i);
            column.setPreferredWidth(widths[i]);
        }
        fuzzResultTable.addMouseListener(new java.awt.event.MouseAdapter() {
            @Override
            public void mousePressed(java.awt.event.MouseEvent e) {
                showPopupMenuIfTriggered(e);
            }

            @Override
            public void mouseReleased(java.awt.event.MouseEvent e) {
                showPopupMenuIfTriggered(e);
            }

            private void showPopupMenuIfTriggered(java.awt.event.MouseEvent e) {
                if (e.isPopupTrigger() && SwingUtilities.isRightMouseButton(e)) {
                    // Select list item on right click
                    JTable table = (JTable) e.getSource();
                    int row = table.rowAtPoint(e.getPoint());

                    if (!table.isRowSelected(row)) {
                        table.changeSelection(row, 0, false, false);
                    }
                    View.getSingleton().getPopupMenu().show(e.getComponent(), e.getX(), e.getY());
                }
            }

        });

        fuzzResultTable.getSelectionModel()
                .addListSelectionListener(new javax.swing.event.ListSelectionListener() {

                    @Override
                    public void valueChanged(javax.swing.event.ListSelectionEvent e) {
                        if (!e.getValueIsAdjusting()) {
                            if (fuzzResultTable.getSelectedRowCount() == 0) {
                                return;
                            }
                            final int row = fuzzResultTable.getSelectedRow();
                            if (getEntry(row) instanceof HttpFuzzRequestRecord) {
                                final HistoryReference historyReference = ((HttpFuzzRequestRecord) getEntry(
                                        row)).getHistory();
                                try {
                                    displayMessage(historyReference.getHttpMessage());
                                } catch (HttpMalformedHeaderException | SQLException ex) {
                                    logger.error(ex.getMessage(), ex);
                                }
                            }
                        }
                    }
                });
        fuzzResultTable.getTableHeader().addMouseListener(new MouseListener() {
            int sortedOn = -1;

            @Override
            public void mouseReleased(MouseEvent arg0) {
            }

            @Override
            public void mousePressed(MouseEvent arg0) {
            }

            @Override
            public void mouseExited(MouseEvent arg0) {
            }

            @Override
            public void mouseEntered(MouseEvent arg0) {
            }

            @Override
            public void mouseClicked(MouseEvent e) {
                int index = fuzzResultTable.columnAtPoint(e.getPoint());
                List<HttpFuzzRecord> list = getResultsModel().getEntries();
                if (list.size() == 0) {
                    return;
                }
                HttpFuzzRecordComparator comp = new HttpFuzzRecordComparator();
                comp.setFeature(index);
                if (index == sortedOn) {
                    Collections.sort(list, comp);
                    Collections.reverse(list);
                    sortedOn = -1;
                } else {
                    Collections.sort(list, comp);
                    sortedOn = index;
                }
                fuzzResultTable.updateUI();
            }
        });
        fuzzResultTable.setRootVisible(false);
        fuzzResultTable.setVisible(true);
    }
    return fuzzResultTable;
}

From source file:com.joey.software.regionSelectionToolkit.controlers.ImageProfileTool.java

@Override
public void mousePressed(MouseEvent e) {

    processMouse(e.getPoint(), e.getButton());

}

From source file:com.joey.software.regionSelectionToolkit.controlers.ImageProfileTool.java

@Override
public void mouseReleased(MouseEvent e) {

    processMouse(e.getPoint(), e.getButton());

}

From source file:org.eurocarbdb.application.glycoworkbench.plugin.reporting.AnnotationReportCanvas.java

private void dragAndScroll(MouseEvent e) {
    // move view if near borders                
    Point point = e.getPoint();
    JViewport view = theScrollPane.getViewport();
    Rectangle inner = view.getViewRect();
    inner.grow(-10, -10);/*from w  ww. j a  va2 s. c  o  m*/

    if (!inner.contains(point)) {
        Point orig = view.getViewPosition();
        if (point.x < inner.x)
            orig.x -= 10;
        else if (point.x > (inner.x + inner.width))
            orig.x += 10;
        if (point.y < inner.y)
            orig.y -= 10;
        else if (point.y > (inner.y + inner.height))
            orig.y += 10;

        int maxx = getBounds().width - view.getViewRect().width;
        int maxy = getBounds().height - view.getViewRect().height;
        if (orig.x < 0)
            orig.x = 0;
        if (orig.x > maxx)
            orig.x = maxx;
        if (orig.y < 0)
            orig.y = 0;
        if (orig.y > maxy)
            orig.y = maxy;

        view.setViewPosition(orig);
    }
}

From source file:es.emergya.ui.plugins.AdminPanel.java

/**
 * //from  www .j  a  va 2s .  c o m
 * @param columnNames
 *            nombres de las columnas de la tabla
 * @param filterOptions
 *            lista de opciones de un combobox. Si esta vacio entonces es un
 *            textfield
 * @param noFiltrarAction
 * @param filtrarAction
 */
public void generateTable(String[] columnNames, Object[][] filterOptions,
        AdminPanel.NoFiltrarAction noFiltrarAction, AdminPanel.FiltrarAction filtrarAction) {

    if (columnNames == null) {
        columnNames = new String[] {};
    }
    if (filterOptions == null) {
        filterOptions = new Object[][] {};
    }

    String filterString = "[";
    for (Object[] o : filterOptions) {
        filterString += Arrays.toString(o) + " ";
    }
    filterString += "]";

    log.debug("generateTable( columnNames = " + Arrays.toString(columnNames) + ", filterOptions = "
            + filterString + ")");

    tablePanel.removeAll();
    int columnNamesLength = columnNames.length;
    if (!getCanDelete())
        columnNamesLength++;
    MyTableModel dataModel = new MyTableModel(1, columnNamesLength + 2) {

        private static final long serialVersionUID = 1348355328684460769L;

        @Override
        public boolean isCellEditable(int row, int column) {
            return column != 0 && !invisibleFilterCols.contains(column);
        }
    };
    filters = new JTable(dataModel) {

        private static final long serialVersionUID = -8266991359840905405L;

        @Override
        public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
            Component c = super.prepareRenderer(renderer, row, column);

            if (isCellEditable(row, column) && column != getColumnCount() - 1) {
                if (c instanceof JTextField) {
                    ((JTextField) c).setBorder(new MatteBorder(1, 1, 1, 1, Color.BLACK));
                } else if (c instanceof JComboBox) {
                    ((JComboBox) c).setBorder(new MatteBorder(1, 1, 1, 1, Color.BLACK));
                } else if (c instanceof JLabel) {
                    ((JLabel) c).setBorder(new MatteBorder(1, 1, 1, 1, Color.BLACK));
                }
            }
            return c;
        }
    };
    filters.setSurrendersFocusOnKeystroke(true);
    filters.setShowGrid(false);
    filters.setRowHeight(22);
    filters.setOpaque(false);

    for (Integer i = 0; i < filterOptions.length; i++) {
        final Object[] items = filterOptions[i];
        if (items != null && items.length > 1) {
            setComboBoxEditor(i, items);
        } else {
            final DefaultCellEditor defaultCellEditor = new DefaultCellEditor(new JTextField());
            defaultCellEditor.setClickCountToStart(1);
            filters.getColumnModel().getColumn(i + 1).setCellEditor(defaultCellEditor);
        }
    }

    filters.setRowSelectionAllowed(false);
    filters.setDragEnabled(false);
    filters.setColumnSelectionAllowed(false);
    filters.setDefaultEditor(JButton.class, new JButtonCellEditor());

    filters.setDefaultRenderer(Object.class, new DefaultTableRenderer() {
        private static final long serialVersionUID = -4811729559786534118L;

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                boolean hasFocus, int row, int column) {
            Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
            if (invisibleFilterCols.contains(column))
                c = new JLabel("");
            return c;
        }

    });

    filters.setDefaultRenderer(JButton.class, new TableCellRenderer() {

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                boolean hasFocus, int row, int column) {
            JButton b = (JButton) value;
            b.setBorderPainted(false);
            b.setContentAreaFilled(false);
            return b;
        }
    });
    filters.setDefaultRenderer(JLabel.class, new TableCellRenderer() {

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                boolean hasFocus, int row, int column) {
            return (JLabel) value;
        }
    });
    filters.setDefaultEditor(JButton.class, new JButtonCellEditor());
    filters.getModel().setValueAt(new JLabel(""), 0, 0);
    JButton jButton2 = new JButton(noFiltrarAction);
    JButton jButton = new JButton(filtrarAction);
    jButton.setBorderPainted(false);
    jButton2.setBorderPainted(false);
    jButton.setContentAreaFilled(false);
    jButton2.setContentAreaFilled(false);
    if (jButton.getIcon() != null)
        jButton.setPreferredSize(
                new Dimension(jButton.getIcon().getIconWidth(), jButton.getIcon().getIconHeight()));
    if (jButton2.getIcon() != null)
        jButton2.setPreferredSize(
                new Dimension(jButton2.getIcon().getIconWidth(), jButton2.getIcon().getIconHeight()));

    filters.getModel().setValueAt(jButton, 0, columnNamesLength - 1);
    filters.getColumnModel().getColumn(columnNamesLength - 1).setMinWidth(jButton.getWidth() + 24);
    filters.getModel().setValueAt(jButton2, 0, columnNamesLength);
    filters.getColumnModel().getColumn(columnNamesLength).setMinWidth(jButton2.getWidth() + 14);
    cuenta.setHorizontalAlignment(JLabel.CENTER);
    cuenta.setText("?/?");
    filters.getModel().setValueAt(cuenta, 0, columnNamesLength + 1);

    tablePanel.add(filters, BorderLayout.NORTH);

    Vector<String> headers = new Vector<String>();
    headers.add("");
    headers.addAll(Arrays.asList(columnNames));
    MyTableModel model = new MyTableModel(headers, 0);
    table = new JTable(model) {

        private static final long serialVersionUID = 949284378605881770L;
        private int highLightedRow = -1;
        private Rectangle dirtyRegion = null;

        public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
            Component c = super.prepareRenderer(renderer, row, column);
            try {
                if (AdminPanel.this.myRendererColoring != null)
                    c.setBackground(AdminPanel.this.myRendererColoring
                            .getColor(AdminPanel.this.table.getValueAt(row, 1)));
            } catch (Throwable t) {
                log.error("Error al colorear la celda: " + t);
            }
            return c;
        }

        @Override
        protected void processMouseMotionEvent(MouseEvent e) {
            try {
                int row = rowAtPoint(e.getPoint());
                Graphics g = getGraphics();
                if (row == -1) {
                    highLightedRow = -1;
                }

                // row changed
                if (highLightedRow != row) {
                    if (null != dirtyRegion) {
                        paintImmediately(dirtyRegion);
                    }
                    for (int j = 0; j < getRowCount(); j++) {
                        if (row == j) {
                            // highlight
                            Rectangle firstRowRect = getCellRect(row, 0, false);
                            Rectangle lastRowRect = getCellRect(row, getColumnCount() - 1, false);
                            dirtyRegion = firstRowRect.union(lastRowRect);
                            g.setColor(new Color(0xff, 0xff, 0, 100));
                            g.fillRect((int) dirtyRegion.getX(), (int) dirtyRegion.getY(),
                                    (int) dirtyRegion.getWidth(), (int) dirtyRegion.getHeight());
                            highLightedRow = row;
                        }

                    }
                }
            } catch (Exception ex) {
            }
            super.processMouseMotionEvent(e);
        }
    };

    table.setRowHeight(22);

    table.setOpaque(false);
    // table.setAutoCreateRowSorter(true);

    table.setDragEnabled(false);
    table.getTableHeader().setReorderingAllowed(false);
    table.getTableHeader().setResizingAllowed(false);

    table.setDefaultEditor(JButton.class, new JButtonCellEditor());
    table.setDefaultRenderer(JButton.class, new TableCellRenderer() {

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                boolean hasFocus, int row, int column) {
            JButton b = (JButton) value;
            if (b != null) {
                b.setBorderPainted(false);
                b.setContentAreaFilled(false);
            }
            return b;
        }
    });

    JScrollPane jScrollPane = new JScrollPane(table);
    jScrollPane.setOpaque(false);
    jScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    jScrollPane.getViewport().setOpaque(false);
    tablePanel.add(jScrollPane, BorderLayout.CENTER);
}

From source file:org.openehealth.coms.cc.consent_applet.applet.ConsentApplet.java

/**
 * MouseListener used to select items from the list of Rule descriptions, allows for deletion of Rules
 * /*from   w  ww. j  av  a2  s. c om*/
 * @return
 */
private MouseListener getRuleListMouseAdapter() {

    return new MouseListener() {

        private JList list;

        public void mousePressed(MouseEvent e) {
            if (SwingUtilities.isRightMouseButton(e)) {
                list = ((JList) e.getSource());
                list.setSelectedIndex(getRow(e.getPoint()));

                JPopupMenu menu = new JPopupMenu();
                menu.add(new RemoveRule(list));

                Point pt = SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), list);
                menu.show(list, pt.x, pt.y);
            }
        }

        private int getRow(Point point) {
            return list.locationToIndex(point);
        }

        public void mouseClicked(MouseEvent arg0) {

        }

        public void mouseEntered(MouseEvent arg0) {

        }

        public void mouseExited(MouseEvent arg0) {

        }

        public void mouseReleased(MouseEvent arg0) {

        }
    };
}

From source file:org.openmicroscopy.shoola.agents.treeviewer.view.ToolBar.java

/**
 * Brings up the <code>Available Scripts</code> on top of the specified
 * component at the specified location.//from www . j a va 2  s  .co m
 * 
 * @param c The component that requested the pop-pup menu.
 * @param p The point at which to display the menu, relative to the
 *          <code>component</code>'s coordinates.
 */
void showAvailableScriptsMenu(Component c, Point p) {
    if (p == null)
        return;
    if (c == null) {
        c = scriptButton;
    }
    IconManager icons = IconManager.getInstance();
    Collection<ScriptObject> scripts = model.getAvailableScripts();
    if (CollectionUtils.isEmpty(scripts))
        return;
    if (scriptsMenu == null) {
        scriptsMenu = new JPopupMenu();
        JMenuItem refresh = new JMenuItem(icons.getIcon(IconManager.REFRESH));
        refresh.setText("Reload Scripts");
        refresh.setToolTipText("Reloads the existing scripts.");
        refresh.addMouseListener(new MouseAdapter() {

            /**
             * Launches the dialog when the user releases the mouse.
             * MouseAdapter#mouseReleased(MouseEvent)
             */
            public void mouseReleased(MouseEvent e) {
                model.setAvailableScripts(null);
                scriptsMenu = null;
                controller.reloadAvailableScripts(e.getPoint());
            }
        });
        scriptsMenu.add(refresh);
        scriptsMenu.add(new JSeparator());

        ScriptObject so;
        Map<String, JMenu> menus = new HashMap<String, JMenu>();
        String path;

        Icon icon = icons.getIcon(IconManager.ANALYSIS);
        Icon largeIcon = icons.getIcon(IconManager.ANALYSIS_48);
        ActionListener listener = new ActionListener() {

            /** 
             * Listens to the selection of a script.
             * @see ActionListener#actionPerformed(ActionEvent)
             */
            public void actionPerformed(ActionEvent e) {
                ScriptMenuItem item = (ScriptMenuItem) e.getSource();
                controller.handleScriptSelection(item.getScript());
            }
        };
        String name = "";
        //loop twice to check if we need to add the first element
        String refString = null;
        int count = 0;
        Iterator<ScriptObject> i = scripts.iterator();
        String sep;
        String[] values;
        String value;
        while (i.hasNext()) {
            so = i.next();
            value = "";
            path = so.getPath();
            if (path != null) {
                sep = FilenameUtils.getPrefix(path);
                if (path.startsWith(sep))
                    path = path.substring(1, path.length());
                values = UIUtilities.splitString(path);
                if (values != null && values.length > 0)
                    value = values[0];
            }

            if (refString == null) {
                refString = value;
                count++;
            } else if (refString.equals(value))
                count++;
        }
        int index = 0;
        if (scripts.size() == count)
            index++;
        i = scripts.iterator();
        List<JMenuItem> topMenus = new ArrayList<JMenuItem>();
        JMenu ref = null;
        while (i.hasNext()) {
            so = i.next();
            path = so.getPath();
            if (path != null) {
                sep = FilenameUtils.getPrefix(path);
                if (path.startsWith(sep))
                    path = path.substring(1, path.length());
                values = UIUtilities.splitString(path);
                if (values != null) {
                    for (int j = index; j < values.length; j++) {
                        value = values[j];
                        JMenu v;
                        String text = name + value;
                        if (menus.containsKey(text)) {
                            v = menus.get(text);
                        } else {
                            value = value.replace(ScriptObject.PARAMETER_SEPARATOR,
                                    ScriptObject.PARAMETER_UI_SEPARATOR);
                            v = new JMenu(value);
                        }
                        if (ref == null)
                            topMenus.add(v);
                        else
                            ref.add(v);
                        ref = v;
                        name += values[j];
                        menus.put(name, v);
                    }
                }
            }
            ScriptMenuItem item = new ScriptMenuItem(so);
            item.addActionListener(listener);
            if (ref != null)
                ref.add(item);
            else
                topMenus.add(item);
            name = "";
            ref = null;
            if (so.getIcon() == null) {
                so.setIcon(icon);
                so.setIconLarge(largeIcon);
            }
        }
        Iterator<JMenuItem> j = topMenus.iterator();
        while (j.hasNext()) {
            scriptsMenu.add(j.next());
        }
    }
    scriptsMenu.show(c, p.x, p.y);
}