Example usage for java.awt.event MouseEvent getX

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

Introduction

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

Prototype

public int getX() 

Source Link

Document

Returns the horizontal x position of the event relative to the source component.

Usage

From source file:Classes.MainForm.java

public void mainFrameMouseDragged(MouseEvent e) {//moving form with mouse
    int x = this.mainFrame.getLocationOnScreen().x;//main form actual x position
    int y = this.mainFrame.getLocationOnScreen().y;//main form actual y position
    this.mainFrame.setLocation(x + (e.getX()) - mouseInitX, y + (e.getY()) - mouseInitY);//moving form to new location of mouse
}

From source file:com.mirth.connect.client.ui.editors.filter.FilterPane.java

/**
 * Shows the popup menu when the trigger button (right-click) has been pushed.
 *///from w ww  .ja v  a 2 s  . c  om
private void checkSelectionAndPopupMenu(java.awt.event.MouseEvent evt) {
    int row = filterTable.rowAtPoint(new Point(evt.getX(), evt.getY()));

    if (evt.isPopupTrigger()) {
        if (row != -1) {
            filterTable.setRowSelectionInterval(row, row);
        }
        filterPopupMenu.show(evt.getComponent(), evt.getX(), evt.getY());
    }
}

From source file:com.mirth.connect.client.ui.browsers.event.EventBrowser.java

private void makeAttributesTable() {
    setEventAttributes(null, true);/*from  w  w w  .j  ava 2 s  .c  o m*/

    // listen for trigger button and double click to edit channel.
    eventAttributesTable.addMouseListener(new java.awt.event.MouseAdapter() {

        public void mouseClicked(java.awt.event.MouseEvent evt) {
            if (eventAttributesTable.rowAtPoint(new Point(evt.getX(), evt.getY())) == -1) {
                return;
            }

            if (evt.getClickCount() >= 2) {
                new ViewContentDialog((String) eventAttributesTable.getModel().getValueAt(
                        eventAttributesTable.getSelectedModelIndex(), ATTRIBUTES_VALUE_COLUMN_NUMBER));
            }
        }
    });

    eventAttributesTable.setSelectionMode(0);

    // Disable HTML in a column.
    DefaultTableCellRenderer noHTMLRenderer = new DefaultTableCellRenderer();
    noHTMLRenderer.putClientProperty("html.disable", Boolean.TRUE);
    eventAttributesTable.getColumnExt(ATTRIBUTES_VALUE_COLUMN_NAME).setCellRenderer(noHTMLRenderer);

    eventAttributesPane.setViewportView(eventAttributesTable);
}

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

public DesktopTree() {
    layout = new MigLayout("flowy, fill, insets 0", "", "[min!][fill]");
    panel = new JPanel(layout);

    topPanel = new JPanel(new BorderLayout());
    topPanel.setVisible(false);/* w w  w  .ja  v a  2  s.  c  o m*/
    panel.add(topPanel, "growx");

    impl = new JTree();
    treeView = new JScrollPane(impl);
    panel.add(treeView, "grow");

    impl.setRootVisible(false);
    impl.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    impl.setExpandsSelectedPaths(true);

    impl.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            showPopup(e);
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            showPopup(e);
        }

        private void showPopup(MouseEvent e) {
            if (e.isPopupTrigger()) {
                // select row
                Point p = e.getPoint();
                TreePath treePath = impl.getPathForLocation(p.x, p.y);
                if (treePath != null) {
                    TreeSelectionModel model = impl.getSelectionModel();
                    model.setSelectionPath(treePath);
                }
                // show popup menu
                createPopupMenu().show(e.getComponent(), e.getX(), e.getY());
            }
        }
    });

    impl.addKeyListener(new KeyAdapter() {
        protected static final int ENTER_CODE = 10;

        @Override
        public void keyPressed(KeyEvent e) {
            if (ENTER_CODE == e.getKeyCode() && e.getComponent() == DesktopTree.this.getComponent()) {
                if (enterPressAction != null) {
                    enterPressAction.actionPerform(DesktopTree.this);
                } else {
                    handleClickAction();
                }
            }
        }
    });
}

From source file:edu.ku.brc.af.ui.forms.ResultSetController.java

/**
 * Creates the UI for the controller.//w  w  w . j a  v a 2  s  . c  om
 * @param addNewBtn indicates it should include the "Add" (New Object) button
 * @param addDelBtn indicates it should include Delete button
 * @param objTitle the title of a single object in the controller (used for building tooltips)
 */
protected void buildRecordNavBar(final boolean addNewBtn, final boolean addDelBtn, final boolean addSearchBtn,
        final String objTitle) {
    String colDef = "p,2dlu,p,2dlu,max(50dlu;p):grow,2dlu,p,2dlu,p" + (addNewBtn ? ",12px,p" : "")
            + (addDelBtn ? ",2dlu,p" : "") + (addSearchBtn ? ",2dlu,p" : "");

    Insets insets = new Insets(1, 1, 1, 1);
    DefaultFormBuilder rowBuilder = new DefaultFormBuilder(new FormLayout(colDef, "p"));

    firstBtn = UIHelper.createIconBtn("FirstRec", null, null);
    prevBtn = UIHelper.createIconBtn("PrevRec", null, null);
    btnsHash.put(CommandType.Previous, prevBtn);
    btnsHash.put(CommandType.First, firstBtn);

    recDisp = createLabel("  ");
    recDisp.setHorizontalAlignment(SwingConstants.CENTER);
    recDisp.setOpaque(true);
    recDisp.setBackground(Color.WHITE);
    recDisp.setBorder(enabledBorder);
    recDisp.setFont(recDisp.getFont().deriveFont(recDisp.getFont().getSize2D() - 2));

    MouseListener mouseListener = new MouseAdapter() {
        private boolean showIfPopupTrigger(MouseEvent mouseEvent) {
            if (mouseEvent.isPopupTrigger()) {
                JPopupMenu popupMenu = createPopupMenu();
                if (popupMenu != null && popupMenu.getComponentCount() > 0) {
                    popupMenu.show(mouseEvent.getComponent(), mouseEvent.getX(), mouseEvent.getY());
                    return true;
                }
            }
            return false;
        }

        @Override
        public void mousePressed(MouseEvent mouseEvent) {
            showIfPopupTrigger(mouseEvent);
        }

        @Override
        public void mouseReleased(MouseEvent mouseEvent) {
            showIfPopupTrigger(mouseEvent);
        }

        /* (non-Javadoc)
         * @see java.awt.event.MouseAdapter#mouseClicked(java.awt.event.MouseEvent)
         */
        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
                if (numRecords == 1) {
                    UIRegistry.writeTimedSimpleGlassPaneMsg(getResourceString("OnlyOneRrecordInCon"));
                } else {
                    showGotoRecDlg();
                }
            }
        }
    };
    recDisp.addMouseListener(mouseListener);

    nextBtn = UIHelper.createIconBtn("NextRec", null, null);
    lastBtn = UIHelper.createIconBtn("LastRec", null, null);
    btnsHash.put(CommandType.Next, nextBtn);
    btnsHash.put(CommandType.Last, lastBtn);

    firstBtn.setToolTipText(createTooltip("GotoFirstRecordTT", objTitle));
    prevBtn.setToolTipText(createTooltip("GotoPreviousRecordTT", objTitle));
    nextBtn.setToolTipText(createTooltip("GotoNextRecordTT", objTitle));
    lastBtn.setToolTipText(createTooltip("GotoLastRecordTT", objTitle));

    firstBtn.setOpaque(false);
    prevBtn.setOpaque(false);
    nextBtn.setOpaque(false);
    lastBtn.setOpaque(false);

    CellConstraints cc = new CellConstraints();
    rowBuilder.add(firstBtn, cc.xy(1, 1));
    rowBuilder.add(prevBtn, cc.xy(3, 1));
    rowBuilder.add(recDisp, cc.xy(5, 1));
    rowBuilder.add(nextBtn, cc.xy(7, 1));
    rowBuilder.add(lastBtn, cc.xy(9, 1));
    int col = 11;

    if (addNewBtn) {
        if (false) {
            newRecBtn = new JButton("+") {
                public void setEnabled(boolean enable) {
                    //log.debug("newRecBtn - RS: "+ formValidator.getName() + " " + newRecBtn.hashCode() + " "+enable+"  isNewObj: "+isNewObj);
                    if (formValidator != null && formValidator.getName() != null
                            && formValidator.getName().equals("Collection Object")) {
                        int x = 0;
                        x++;
                        if (enable) {
                            int y = 0;
                            y++;
                        }
                    }
                    if (enable) {
                        int x = 0;
                        x++;
                    }
                    super.setEnabled(enable);
                }
            };
            setControlSize(newRecBtn);

            ActionListener l = new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    for (ResultSetControllerListener rscl : listeners) {
                        rscl.newRecordAdded();
                    }
                }
            };
            newRecBtn.addActionListener(l);

        } else {
            newRecBtn = UIHelper.createIconBtn("NewRecord", null, new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    for (ResultSetControllerListener rscl : listeners) {
                        rscl.newRecordAdded();
                    }
                }
            });
        }

        newRecBtn.setToolTipText(createTooltip("NewRecordTT", objTitle));
        newRecBtn.setEnabled(true);
        newRecBtn.setMargin(insets);
        btnsHash.put(CommandType.NewItem, newRecBtn);

        if (doLayoutBtns) {
            rowBuilder.add(newRecBtn, cc.xy(col, 1));
            col += 2;
        }
    }

    if (addDelBtn) {
        if (false) {
            delRecBtn = new JButton("-") {
                public void setEnabled(boolean enable) {
                    //log.debug("delRecBtn - RS: "+formValidator.getName() + " " + hashCode() + " "+enable);
                    if (formValidator != null && formValidator.getName() != null
                            && formValidator.getName().equals("Permit")) {
                        int x = 0;
                        x++;
                    }
                    if (!enable) {
                        int x = 0;
                        x++;
                    }
                    super.setEnabled(enable);
                }
            };
        } else {
            delRecBtn = UIHelper.createIconBtn("DeleteRecord", null, null);
        }
        delRecBtn.setToolTipText(createTooltip("DeleteRecordTT", objTitle));
        delRecBtn.setMargin(insets);
        btnsHash.put(CommandType.DelItem, delRecBtn);

        if (doLayoutBtns) {
            rowBuilder.add(delRecBtn, cc.xy(col, 1));
            col += 2;
        }
    }

    if (addSearchBtn) {
        searchRecBtn = UIHelper.createIconBtn("Search", IconManager.IconSize.Std16, null, null);
        searchRecBtn.setToolTipText(createTooltip("SearchForRecordTT", objTitle));
        searchRecBtn.setMargin(insets);

        if (doLayoutBtns) {
            rowBuilder.add(searchRecBtn, cc.xy(col, 1));
            col += 2;
        }
    }

    firstBtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            firstRecord();
        }
    });
    prevBtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            prevRecord();
        }
    });
    nextBtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            nextRecord();
        }
    });
    lastBtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            lastRecord();
        }
    });

    // Make sure it gets centered
    rowBuilder.getPanel().setOpaque(false);
    DefaultFormBuilder outerCenteredPanel = new DefaultFormBuilder(new FormLayout("c:p:g", "p"));
    outerCenteredPanel.add(rowBuilder.getPanel(), cc.xy(1, 1));
    panel = outerCenteredPanel.getPanel();
    panel.setOpaque(false);
}

From source file:com.mirth.connect.client.ui.editors.transformer.TransformerPane.java

/**
 * Shows the popup menu when the trigger button (right-click) has been pushed.
 *//*from   w w  w  .j av  a 2s . c o  m*/
private void checkSelectionAndPopupMenu(java.awt.event.MouseEvent evt) {
    int row = transformerTable.rowAtPoint(new Point(evt.getX(), evt.getY()));

    if (evt.isPopupTrigger()) {
        if (row != -1) {
            transformerTable.setRowSelectionInterval(row, row);
        }
        transformerPopupMenu.show(evt.getComponent(), evt.getX(), evt.getY());
    }
}

From source file:org.jax.maanova.test.gui.VolcanoPlotPanel.java

private void mouseMoved(MouseEvent e) {
    if (this.showTooltip) {
        Point2D chartPoint = this.chartPanel.toChartPoint(e.getPoint());

        // find the nearest probe
        XYProbeData xyProbeData = this.getXYData();
        double[][] xyData = new double[][] { xyProbeData.getXData(), xyProbeData.getYData() };
        int nearestDotIndex = PlotUtil.getNearestDataIndex(xyData, chartPoint.getX(), chartPoint.getY());

        if (nearestDotIndex == -1) {
            this.clearProbePopup();
        } else {/* w  ww. j a  v a 2 s  .  co m*/
            Point2D probeJava2DCoord = this.getJava2DCoordinates(xyData, nearestDotIndex);
            double java2DDist = probeJava2DCoord.distance(e.getX(), e.getY());

            // is the probe close enough to be worth showing (in pixel distance)
            if (java2DDist <= PlotUtil.SCATTER_PLOT_DOT_SIZE_PIXELS * 2) {
                this.showProbePopup(xyProbeData.getProbeIndices()[nearestDotIndex], e.getX(), e.getY());
            } else {
                this.clearProbePopup();
            }
        }
    }
}

From source file:com.jcraft.weirdx.DDXWindowImp.java

public void mouseExited(MouseEvent e) {
    if (window == null)
        return;//w  w w.  ja v a 2s  .  c  o m

    if (window.id == window.screen.rootId) {
        return;
    }

    int x = e.getX() + window.x;
    int y = e.getY() + window.y;

    XWindow.sprite.hot.x = x;
    XWindow.sprite.hot.y = y;

    int mod = e.getModifiers();
    int state = 0;
    if ((mod & InputEvent.BUTTON1_MASK) != 0)
        state |= (1 << 8);
    if ((mod & InputEvent.BUTTON2_MASK) != 0)
        state |= (1 << 9);
    if ((mod & InputEvent.BUTTON3_MASK) != 0)
        state |= (1 << 10);
    if ((mod & InputEvent.SHIFT_MASK) != 0)
        state |= 1;
    if ((mod & InputEvent.CTRL_MASK) != 0)
        state |= 4;
    // alt -> state|=8;
    Client client = window.client;
    if (client == null || client == serverClient)
        return;

    event.mkLeaveNotify(0, // Ancestor
            window.screen.rootId, window.id, 0, x, y, e.getX(), e.getY(), state, 0, // Normal
            0x1 | 0x02 // focus|same-screen
    );
    try {
        XWindow.sendDeviceEvent(window, event, XWindow.grab, null, 1);
    } catch (Exception ee) {
    }
}

From source file:edu.ku.brc.specify.tasks.RecordSetTask.java

/**
 * Adds the Context PopupMenu for the RecordSet.
 * @param roc the RolloverCommand btn to add the pop to
 */// w ww  .java2  s. co  m
public void addPopMenu(final RolloverCommand roc, final boolean isOKDelete, final boolean isOKModify) {
    if (roc.getLabelText() != null) {
        final JPopupMenu popupMenu = new JPopupMenu();

        if (isOKModify) {
            JMenuItem renameMenuItem = new JMenuItem(UIRegistry.getResourceString("Rename"));
            renameMenuItem.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent actionEvent) {
                    roc.startEditting(RecordSetTask.this);
                }
            });
            popupMenu.add(renameMenuItem);
        }

        if (isOKDelete) {
            JMenuItem delMenuItem = new JMenuItem(UIRegistry.getResourceString("Delete"));
            delMenuItem.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent actionEvent) {
                    CommandDispatcher.dispatch(new CommandAction(RECORD_SET, DELETE_CMD_ACT, roc));
                }
            });
            popupMenu.add(delMenuItem);
        }

        JMenuItem viewMenuItem = new JMenuItem(UIRegistry.getResourceString("View"));
        viewMenuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent actionEvent) {
                CommandAction cmdAction = new CommandAction("Express_Search", "ViewRecordSet", roc);
                cmdAction.setProperty("canModify", isOKDelete);
                CommandDispatcher.dispatch(cmdAction);
            }
        });
        popupMenu.add(viewMenuItem);

        MouseListener mouseListener = new MouseAdapter() {
            private boolean showIfPopupTrigger(MouseEvent mouseEvent) {
                if (roc.isEnabled() && mouseEvent.isPopupTrigger() && popupMenu.getComponentCount() > 0) {
                    popupMenu.show(mouseEvent.getComponent(), mouseEvent.getX(), mouseEvent.getY());
                    return true;
                }
                return false;
            }

            @Override
            public void mousePressed(MouseEvent mouseEvent) {
                if (roc.isEnabled()) {
                    showIfPopupTrigger(mouseEvent);
                }
            }

            @Override
            public void mouseReleased(MouseEvent mouseEvent) {
                if (roc.isEnabled()) {
                    showIfPopupTrigger(mouseEvent);
                }
            }
        };
        roc.addMouseListener(mouseListener);
    }
}

From source file:com.mirth.connect.client.ui.browsers.event.EventBrowser.java

public void initComponentsManual() {
    this.addMouseListener(new java.awt.event.MouseAdapter() {

        public void mousePressed(java.awt.event.MouseEvent evt) {
            if (evt.isPopupTrigger()) {
                parent.eventPopupMenu.show(evt.getComponent(), evt.getX(), evt.getY());
            }//from  w  w  w  .j av a 2s.  c  o  m
        }

        public void mouseReleased(java.awt.event.MouseEvent evt) {
            if (evt.isPopupTrigger()) {
                parent.eventPopupMenu.show(evt.getComponent(), evt.getX(), evt.getY());
            }
        }
    });

    pageSizeField.setDocument(new MirthFieldConstraints(3, false, false, true));
    pageNumberField.setDocument(new MirthFieldConstraints(7, false, false, true));

    LineBorder lineBorder = new LineBorder(new Color(0, 0, 0));
    TitledBorder titledBorder = new TitledBorder("Current Search");
    titledBorder.setBorder(lineBorder);

    lastSearchCriteriaPane.setBorder(titledBorder);
    lastSearchCriteriaPane.setBackground(Color.white);
    lastSearchCriteria.setBackground(Color.white);

    startDatePicker.addPropertyChangeListener(new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent arg0) {
            allDayCheckBox.setEnabled(startDatePicker.getDate() != null || endDatePicker.getDate() != null);
            startTimePicker.setEnabled(startDatePicker.getDate() != null && !allDayCheckBox.isSelected());
        }
    });

    endDatePicker.addPropertyChangeListener(new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent arg0) {
            allDayCheckBox.setEnabled(startDatePicker.getDate() != null || endDatePicker.getDate() != null);
            endTimePicker.setEnabled(endDatePicker.getDate() != null && !allDayCheckBox.isSelected());
        }
    });

    pageNumberField.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent arg0) {
            if (arg0.getKeyCode() == KeyEvent.VK_ENTER && pageGoButton.isEnabled()) {
                jumpToPageNumber();
            }
        }
    });

    updateCachedUserMap();

    advancedSearchPopup = new EventBrowserAdvancedFilter(parent, "Advanced Search Filter", true, userMapById);
    advancedSearchPopup.setVisible(false);

    eventSplitPane.setDividerLocation(0.8);

    this.addAncestorListener(new AncestorListener() {

        @Override
        public void ancestorAdded(AncestorEvent event) {
        }

        @Override
        public void ancestorMoved(AncestorEvent event) {
        }

        @Override
        public void ancestorRemoved(AncestorEvent event) {
            // Stop waiting for event browser requests when the event browser 
            // is no longer being displayed
            parent.mirthClient.getServerConnection().abort(getAbortOperations());
            // Clear the event cache when leaving the event browser.
            parent.eventBrowser.clearCache();
        }

    });
}