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:inflor.core.utils.ChartUtils.java

public static Point2D getPlotCoordinates(MouseEvent e, FCSChartPanel panel) {
    Point2D p = panel.translateScreenToJava2D(e.getPoint());
    Rectangle2D plotArea = panel.getScreenDataArea();
    XYPlot plot = panel.getChart().getXYPlot();
    double x = plot.getDomainAxis().java2DToValue(p.getX(), plotArea, plot.getDomainAxisEdge());
    double y = plot.getRangeAxis().java2DToValue(p.getY(), plotArea, plot.getRangeAxisEdge());
    return new Point2D.Double(x, y);
}

From source file:Main.java

public static MouseEvent adaptEventToDescendent(MouseEvent e, JComponent descendentTarget) {
    Point trans = new Point();
    Component source = e.getComponent();

    Component current = descendentTarget;
    while (current != source) {
        Rectangle b = current.getBounds();
        trans.x += b.x;//  ww  w .java 2 s.  co m
        trans.y += b.y;
        current = current.getParent();
    }
    Point point = e.getPoint();

    return new MouseEvent(descendentTarget, e.getID(), e.getWhen(), e.getModifiers(), point.x + trans.x,
            point.y + trans.y, e.getClickCount(), e.isPopupTrigger(), e.getButton());
}

From source file:com.intuit.tank.tools.debugger.PanelBuilder.java

/**
 * @param debuggerActions//w  w  w.jav  a 2  s. c  o  m
 * @return
 */
static Component createContentPanel(final AgentDebuggerFrame frame) {
    JSplitPane pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true);
    pane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
    final RSyntaxTextArea scriptEditorTA = new RSyntaxTextArea();
    frame.setScriptEditorTA(scriptEditorTA);
    scriptEditorTA.setSelectionColor(scriptEditorTA.getCurrentLineHighlightColor());
    scriptEditorTA.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_NONE);
    scriptEditorTA.setHyperlinksEnabled(false);
    scriptEditorTA.setEditable(false);
    scriptEditorTA.setEnabled(false);
    scriptEditorTA.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            scriptEditorTA.grabFocus();
            try {
                int offs = scriptEditorTA.viewToModel(e.getPoint());
                if (offs > -1) {
                    int line = scriptEditorTA.getLineOfOffset(offs);
                    if (frame.getSteps().size() > line) {

                        frame.fireStepChanged(line);
                        if (e.getClickCount() == 2 && !e.isPopupTrigger()) {
                            // show step xml
                            try {
                                DebugStep debugStep = frame.getSteps().get(line);
                                String text = JaxbUtil.marshall(debugStep.getStepRun());
                                StepDialog dlg = new StepDialog(frame, text, SyntaxConstants.SYNTAX_STYLE_XML);
                                dlg.setVisible(true);
                            } catch (JAXBException e1) {
                                frame.showError("Error showing step xml: " + e);
                            }
                        }
                    }
                }
            } catch (BadLocationException ble) {
                ble.printStackTrace(); // Never happens
            }
        }
    });
    RTextScrollPane scriptEditorScrollPane = new RTextScrollPane(scriptEditorTA);
    frame.setScriptEditorScrollPane(scriptEditorScrollPane);
    scriptEditorScrollPane.setIconRowHeaderEnabled(true);
    scriptEditorScrollPane.getGutter()
            .setBookmarkIcon(ActionProducer.getIcon("bullet_blue.png", IconSize.SMALL));
    scriptEditorScrollPane.getGutter()
            .setCurrentLineIcon(ActionProducer.getIcon("current_line.png", IconSize.SMALL));
    scriptEditorScrollPane.getGutter().setBookmarkingEnabled(true);
    pane.setLeftComponent(scriptEditorScrollPane);

    pane.setRightComponent(createRightPanel(frame));
    pane.setDividerLocation(300);
    pane.setResizeWeight(0.4D);
    return pane;
}

From source file:org.wso2.greg.plugin.Utils.java

/**
 * This method is used to create the Resources List UI from the given list of Resources(s).
 *
 * @param resourceInfos The list of Resources that the table is constructed.
 * @return ResourceSelectionResult which contains all the selected APIs and whether test suites and load
 * are needed to be generated./*from   w  ww  . jav  a  2s. c  o m*/
 */
public static ResourceSelectionResult showSelectAPIDefDialog(List<ResourceInfo> resourceInfos) {

    final XFormDialog dialog = ADialogBuilder.buildDialog(ResourceModel.class);
    final Object[][] tableData = convertToTableData(resourceInfos);

    // --------------- start of API List table population section ------------------
    // We create a table model here with the converted data.
    TableModel tableModel = new AbstractTableModel() {
        Object[][] data = tableData;
        String[] columnNames = { "Name", "Version", "Provider", "Description" };

        @Override
        public int getRowCount() {
            return data.length;
        }

        @Override
        public int getColumnCount() {
            // We have a hardcoded set of columns
            return columnNames.length;
        }

        @Override
        public Object getValueAt(int rowIndex, int columnIndex) {
            return data[rowIndex][columnIndex];
        }

        @Override
        public String getColumnName(int column) {
            return columnNames[column];
        }
    };

    // We get the table that was ghttps://youtu.be/Vycy3GxbxUYenerated in the form and we set
    // some properties there.
    XFormField resourcesListFormField = dialog.getFormField(ResourceModel.RESOURCE_LIST);
    final JXTable table = ((JTableFormField) resourcesListFormField).getTable();
    table.setCellSelectionEnabled(false);
    table.setColumnSelectionAllowed(false);
    table.setRowSelectionAllowed(true);
    table.setFillsViewportHeight(true);

    // We set the preferred size of all the parent forms until we get to the JScrollPane
    table.setPreferredScrollableViewportSize(new Dimension(600, 200));
    table.getParent().setPreferredSize(new Dimension(600, 200));
    table.getParent().getParent().setPreferredSize(new Dimension(600, 200));

    // Setting the table model
    table.setModel(tableModel);

    // This is to show a toolTip when hovering over the table cells. We need this because there could be long
    // descriptions and api names.
    table.addMouseMotionListener(new MouseMotionAdapter() {
        @Override
        public void mouseMoved(MouseEvent e) {
            Point p = e.getPoint();
            int row = table.rowAtPoint(p);
            int col = table.columnAtPoint(p);

            if (row == -1 || col == -1) {
                return;
            }
            table.setToolTipText(tableData[row][col].toString());
        }
    });

    // The purpose of this validator is the check whether there are at least one API selected from the table.
    resourcesListFormField.addFormFieldValidator(new XFormFieldValidator() {
        @Override
        public ValidationMessage[] validateField(XFormField xFormField) {
            if (table.getSelectedRowCount() <= 0) {
                return new ValidationMessage[] {
                        new ValidationMessage(HelpMessageConstants.API_SELECTION_VALIDATION_MSG,
                                dialog.getFormField(ResourceModel.RESOURCE_LIST)) };
            }
            return new ValidationMessage[0];
        }
    });
    // --
    // ----------------- End of Resource(s) List Table population section ----------------------

    // We get the radio button group and add a listener there. The purpose of the listener is to 'enable',
    // 'disable' the Load test radio button group based on the selected value of this group.
    // The reason is that, there is no meaning to create a Load test without a test suite.
    XFormRadioGroup testSuiteSelection = (XFormRadioGroup) dialog.getFormField(ResourceModel.TEST_SUITE);
    testSuiteSelection.setValue(ResourceConstants.RADIO_BUTTON_OPTIONS_NO);
    testSuiteSelection.setToolTip(HelpMessageConstants.TEST_SUITE_TOOLTIP_TEXT);

    testSuiteSelection.addFormFieldListener(new XFormFieldListener() {
        @Override
        public void valueChanged(XFormField xFormField, String newValue, String oldValue) {
            XFormRadioGroup loadTestSelection = (XFormRadioGroup) dialog.getFormField(ResourceModel.LOAD_TEST);
            if (ResourceConstants.RADIO_BUTTON_OPTIONS_YES.equals(newValue)) {
                loadTestSelection.setEnabled(true);
            } else if (ResourceConstants.RADIO_BUTTON_OPTIONS_NO.equals(newValue)) {
                loadTestSelection.setEnabled(false);
            }
        }
    });

    XFormRadioGroup loadTestSelection = (XFormRadioGroup) dialog.getFormField(ResourceModel.LOAD_TEST);
    loadTestSelection.setToolTip(HelpMessageConstants.LOAD_TEST_TOOLTIP_TEXT);
    loadTestSelection.setValue(ResourceConstants.RADIO_BUTTON_OPTIONS_NO);

    if (dialog.show()) {
        int[] selected = table.getSelectedRows();
        ArrayList<ResourceInfo> selectedAPIs = new ArrayList<ResourceInfo>();
        for (int no : selected) {
            selectedAPIs.add(resourceInfos.get(no));
        }
        ResourceSelectionResult selectionResult = new ResourceSelectionResult();
        selectionResult.setResourceInfoList(selectedAPIs);
        selectionResult.setTestSuiteSelected(
                ResourceConstants.RADIO_BUTTON_OPTIONS_YES.equals(testSuiteSelection.getValue()));
        selectionResult.setLoadTestSelected(
                ResourceConstants.RADIO_BUTTON_OPTIONS_YES.equals(loadTestSelection.getValue()));

        return selectionResult;
    } else {
        return null;
    }

}

From source file:com.bwc.ora.OraUtils.java

/**
 * Create the anchor LRP. Does this by creating the LRP model and then adds
 * it to the LRP collections used by the application for storing LRPs for
 * analysis and display//from w w  w  .  j a  v a  2s  . co  m
 *
 * @param assisted use fovea finding algorithm or manual click to identify
 *                 fovea
 */
public static void generateAnchorLrp(boolean assisted, JButton buttonToEnable) {
    OCTDisplayPanel octDisplayPanel = OCTDisplayPanel.getInstance();
    LrpSettings lrpSettings = ModelsCollection.getInstance().getLrpSettings();
    DisplaySettings displaySettings = ModelsCollection.getInstance().getDisplaySettings();

    if (assisted) {
        JOptionPane.showMessageDialog(null, "Click and drag a window on the OCT which\n"
                + "contains the foveal pit, some of the vitrious,\n"
                + "and some of the Bruch's membrane and choroid.\n"
                + "ORA will the place a LRP at what it believes is\n" + "the center of the foveal pit.\n" + "\n"
                + "Use the arrow keys to move the LRP if desired after placement.\n"
                + "If any setting are adjusted while in this mode\n"
                + "you'll have to click the mouse on the OCT to regain\n"
                + "the ability to move the LRP with the arrow keys.", "Draw foveal pit window",
                JOptionPane.INFORMATION_MESSAGE);

        //allow the user to select region on screen where fovea should be found
        OctWindowSelector octWindowSelector = ModelsCollection.getInstance().getOctWindowSelector();

        MouseInputAdapter selectorMouseListener = new MouseInputAdapter() {
            Point firstPoint = null;
            Point secondPoint = null;
            Point lastWindowPoint = null;

            @Override
            public void mousePressed(MouseEvent e) {
                Collections.getInstance().getOctDrawnLineCollection().clear();
                Collections.getInstance().getLrpCollection().clearLrps();
                if ((firstPoint = octDisplayPanel.convertPanelPointToOctPoint(e.getPoint())) != null) {
                    octWindowSelector.setDisplay(true);
                    displaySettings.setDisplaySelectorWindow(true);
                }
            }

            @Override
            public void mouseReleased(MouseEvent e) {
                secondPoint = octDisplayPanel.convertPanelPointToOctPoint(e.getPoint());
                octWindowSelector.setDisplay(false);
                displaySettings.setDisplaySelectorWindow(false);
                octDisplayPanel.removeMouseListener(this);
                octDisplayPanel.removeMouseMotionListener(this);
                OctPolyLine ilm = ILMsegmenter.segmentILM(firstPoint,
                        secondPoint == null ? lastWindowPoint : secondPoint);
                Collections.getInstance().getOctDrawnLineCollection().add(ilm);
                //use ILM segmented line to find local minima and place LRP
                Point maxYPoint = ilm.stream().max(Comparator.comparingInt(p -> p.y)).orElse(ilm.get(0));
                int fovealCenterX = (int) Math.round(ilm.stream().filter(p -> p.y == maxYPoint.y)
                        .mapToInt(p -> p.x).average().getAsDouble());

                Lrp newLrp;
                try {
                    newLrp = new Lrp("Fovea", fovealCenterX, Oct.getInstance().getImageHeight() / 2,
                            lrpSettings.getLrpWidth(), lrpSettings.getLrpHeight(), LrpType.FOVEAL);
                    lrpCollection.setLrps(Arrays.asList(newLrp));
                    octDisplayPanel.removeMouseListener(this);
                    if (buttonToEnable != null) {
                        buttonToEnable.setEnabled(true);
                    }
                } catch (LRPBoundaryViolationException e1) {
                    JOptionPane.showMessageDialog(null, e1.getMessage() + " Try again.", "LRP generation error",
                            JOptionPane.ERROR_MESSAGE);
                    return;
                }
            }

            @Override
            public void mouseDragged(MouseEvent e) {
                Point dragPoint;
                if ((dragPoint = octDisplayPanel.convertPanelPointToOctPoint(e.getPoint())) != null) {
                    lastWindowPoint = dragPoint;
                    int minX = Math.min(firstPoint.x, dragPoint.x);
                    int minY = Math.min(firstPoint.y, dragPoint.y);
                    int width = Math.max(firstPoint.x, dragPoint.x) - minX;
                    int height = Math.max(firstPoint.y, dragPoint.y) - minY;
                    octWindowSelector.setRect(minX, minY, width, height);
                    displaySettings.setDisplaySelectorWindow(false);
                    displaySettings.setDisplaySelectorWindow(true);
                }
            }
        };

        octDisplayPanel.addMouseListener(selectorMouseListener);
        octDisplayPanel.addMouseMotionListener(selectorMouseListener);
    } else {
        JOptionPane.showMessageDialog(null,
                "Click on the OCT where the anchor LRP should go.\n" + "Use the arrow keys to move the LRP.\n"
                        + "If any setting are adjusted while in this mode\n"
                        + "you'll have to click the mouse on the OCT to regain\n"
                        + "the ability to move the LRP with the arrow keys.",
                "Click anchor point", JOptionPane.INFORMATION_MESSAGE);
        //listen for the location on the screen where the user clicks, create LRP at location
        octDisplayPanel.addMouseListener(new MouseInputAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                Point clickPoint;
                if ((clickPoint = octDisplayPanel.convertPanelPointToOctPoint(e.getPoint())) != null) {
                    Lrp newLrp;
                    try {
                        newLrp = new Lrp("Fovea", clickPoint.x, clickPoint.y, lrpSettings.getLrpWidth(),
                                lrpSettings.getLrpHeight(), LrpType.FOVEAL);
                        lrpCollection.setLrps(Arrays.asList(newLrp));
                        octDisplayPanel.removeMouseListener(this);
                        if (buttonToEnable != null) {
                            buttonToEnable.setEnabled(true);
                        }
                    } catch (LRPBoundaryViolationException e1) {
                        JOptionPane.showMessageDialog(null, e1.getMessage() + " Try again.",
                                "LRP generation error", JOptionPane.ERROR_MESSAGE);
                        return;
                    }

                }
            }
        });

    }
}

From source file:Main.java

public String getToolTipText(MouseEvent event) {
    Point p = event.getPoint();
    int location = locationToIndex(p);
    String tip = (String) getModel().getElementAt(location);
    return tip;//from w  w w.  j  a va  2 s. co m
}

From source file:MouseMotionEventDemo.java

public void mouseMoved(MouseEvent me) {
    mX = (int) me.getPoint().getX();
    mY = (int) me.getPoint().getY();
    repaint();/*from  w  w  w.java  2s  .  c o m*/
}

From source file:Main.java

public void mouseMoved(MouseEvent evt) {
    System.out.println("moved:" + evt.getPoint());
}

From source file:Main.java

public void mouseDragged(MouseEvent evt) {

    System.out.println("dragged:" + evt.getPoint());
}

From source file:Main.java

public Main() {
    setLayout(null);//from  w  w w  .  ja va  2s .  c  om
    add(button);
    button.setSize(button.getPreferredSize());
    button.setLocation(20, 20);
    addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent event) {
            System.out.println(event.getPoint());
        }
    });
}