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.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 {//from  ww  w .  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:VASSAL.build.module.map.LOS_Thread.java

public void mousePressed(MouseEvent e) {
    initializing = false;/*from   w ww. j ava2 s .  c  o m*/
    if (visible && !persisting && !mirroring) {
        Point p = e.getPoint();
        if (Boolean.TRUE.equals(GameModule.getGameModule().getPrefs().getValue(SNAP_LOS)) || snapStart) {
            p = map.snapTo(p);
        }
        anchor = p;
        anchorLocation = map.localizedLocationName(anchor);
        lastLocation = anchorLocation;
        lastRange = "";
        checkList.clear();
        ctrlWhenClick = e.isControlDown();
    }
}

From source file:androhashcheck.MainFrame.java

/**
 * Creates new form MainFrame/*from   ww w.  jav a 2 s. com*/
 * @param logInFrame
 */
public MainFrame(JFrame logInFrame) {
    initComponents();
    this.logInFrame = logInFrame;
    jList5.setModel(listModel);
    dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
    displayApkFolder();
    //mouse listner - when clicked on uploaded package to show details
    jList3.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent evt) {
            JList list = (JList) evt.getSource();
            if (evt.getClickCount() == 2) {
                int index = list.locationToIndex(evt.getPoint());
                final TaskObject taskObject = taskList.get(index);
                java.awt.EventQueue.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        new TaskFrame(taskObject).setVisible(true);
                    }
                });
            }
        }
    });
    shouldCheckTasks = true;
    startThreadForTaskUpdatesChecking();
}

From source file:com.qspin.qtaste.ui.xmleditor.TestRequirementEditor.java

private void genUI() {
    getActionMap().put("Save", new SaveAction());
    getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
            .put(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK), "Save");
    m_TestRequirementTable = new JTable() {

        @Override/*w  w w  .ja v a2  s.  c  o m*/
        public String getToolTipText(MouseEvent e) {
            Point p = e.getPoint();
            int rowIndex = rowAtPoint(p);
            int colIndex = columnAtPoint(p);
            if (colIndex < 0) {
                return null;
            }
            return convertObjectToToolTip(getValueAt(rowIndex, colIndex));
        }

        // overwrite cell content when typing on a selected cell
        @Override
        public Component prepareEditor(TableCellEditor editor, int row, int column) {
            Component c = super.prepareEditor(editor, row, column);

            if (c instanceof JTextComponent) {
                ((JTextField) c).selectAll();
            }

            return c;
        }

        // select entire rows when selecting first column (row id)
        @Override
        public void columnSelectionChanged(ListSelectionEvent e) {
            if (e.getFirstIndex() == 0 && e.getValueIsAdjusting()) {
                setColumnSelectionInterval(1, getColumnCount() - 1);
            } else {
                super.columnSelectionChanged(e);
            }
        }
    };
    m_TestRequirementTable.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);

    m_TestRequirementModel = new TestRequirementTableModel();

    m_TestRequirementTable.setModel(m_TestRequirementModel);

    m_TableColumnModelListener = new MyTableColumnModelListener();
    m_TestRequirementTable.setSurrendersFocusOnKeystroke(true);
    m_TestRequirementTable.setColumnSelectionAllowed(true);
    m_TestRequirementTable.addMouseListener(new TableMouseListener(m_TestRequirementTable));
    m_TestRequirementTable.getTableHeader().addMouseListener(new TableMouseListener(m_TestRequirementTable));
    m_TestRequirementTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    m_TestRequirementTable.getActionMap().put("Save", new SaveAction());
    m_TestRequirementTable.setDefaultEditor(String.class, new TestDataTableCellEditor());
    m_TestRequirementTable.setDefaultEditor(Integer.class, new TestDataTableCellEditor());
    m_TestRequirementTable.getTableHeader().getInputMap()
            .put(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK), "Save");
    m_TestRequirementTable.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK),
            "Save");
    m_TestRequirementTable.setRowHeight(ROW_HEIGHT);

    m_TestRequirementTable.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            //
            if (e.getKeyCode() == KeyEvent.VK_UP) {
                // check if previous line is empty
            }
            if (e.getKeyCode() == KeyEvent.VK_DOWN) {
                // if current row is the last one
                if (m_TestRequirementTable.getSelectedRow() == m_TestRequirementTable.getRowCount() - 1) {
                    addNewRow();
                }
            }
            if ((e.getKeyCode() == KeyEvent.VK_S) && (e.isControlDown())) {
                save();
            }
            if ((e.getKeyCode() == KeyEvent.VK_C) && (e.isControlDown())) {
                copySelectionToClipboard();
            }
            if ((e.getKeyCode() == KeyEvent.VK_V) && (e.isControlDown())) {
                if (m_TestRequirementTable.getSelectedColumn() != 0) {
                    pasteSelectionFromClipboard();
                }
            }
        }
    });

    tableListener = new TableModelListener() {

        public void tableChanged(TableModelEvent e) {
            // build the test data
            if (e.getType() == TableModelEvent.UPDATE) {
                if (e.getFirstRow() >= 0) {
                    setModified(true);
                }
            }
        }
    };
    m_TestRequirementModel.addTableModelListener(tableListener);

    JScrollPane sp = new JScrollPane(m_TestRequirementTable);
    sp.addMouseListener(new TableMouseListener(null));
    add(sp);
}

From source file:HelloUniverse.java

public void mousePressed(MouseEvent e) {
    if (yArea.contains(e.getPoint())) {
        mode = SLIDE_Y;//from   www.  java  2  s  .  c o m
        oldMousePos = e.getPoint();
    } else if (xArea.contains(e.getPoint())) {
        mode = SLIDE_X;
        oldMousePos = e.getPoint();
    } else if (zArea.contains(e.getPoint())) {
        mode = SLIDE_Z;
        oldMousePos = e.getPoint();
    }
}

From source file:org.openconcerto.task.TodoListPanel.java

public TodoListPanel() {
    this.setOpaque(false);
    this.iconTache = new ImageIcon(TodoListPanel.class.getResource("tache.png"));
    this.iconPriorite = new ImageIcon(TodoListPanel.class.getResource("priorite.png"));
    this.userTableCellRenderer = new UserTableCellRenderer();
    this.timestampTableCellRendererCreated = new TimestampTableCellRenderer();
    this.timestampTableCellRendererDone = new TimestampTableCellRenderer();
    this.timestampTableCellRendererDeadLine = new TimestampTableCellRenderer(true);
    this.timestampTableCellEditorCreated = new TimestampTableCellEditor();
    this.timestampTableCellEditorDone = new TimestampTableCellEditor();
    this.timestampTableCellEditorDeadLine = new TimestampTableCellEditor();
    // Icon renderer
    List<URL> l = new Vector<URL>();
    l.add(TodoListPanel.class.getResource("empty.png"));
    l.add(TodoListPanel.class.getResource("high.png"));
    l.add(TodoListPanel.class.getResource("normal.png"));
    l.add(TodoListPanel.class.getResource("low.png"));
    this.iconEditor = new IconTableCellRenderer(l);
    this.iconRenderer = new IconTableCellRenderer(l);

    final User currentUser = UserManager.getInstance().getCurrentUser();
    this.model = new TodoListModel(currentUser);
    this.sorter = new TableSorter(this.model);
    this.t = new LightEventJTable(this.sorter) {
        public JToolTip createToolTip() {
            return new JMultiLineToolTip();
        }//w w w  .  j av  a2  s .  c  o  m

        @Override
        public String getToolTipText(MouseEvent event) {
            String r = null;
            TodoListElement task = getTaskAt(event.getPoint());

            if (task != null && task.getCreatorId() > 1) {
                final String comment = task.getComment();
                if (comment != null) {
                    r = comment;
                    r += "\n\n";
                } else {
                    r = "";
                }
                r += getTM().trM("assignedBy", "user",
                        UserManager.getInstance().getUser(task.getCreatorId()).getFullName(), "date",
                        task.getDate());
            }

            return r;
        }

    };
    this.sorter.setTableHeader(this.t.getTableHeader());

    this.model.setTable(this.t);

    this.comboUser = new JMenu(TM.tr("showTaskAssignedTo"));
    initViewableUsers(currentUser);

    // L'utilisateur courant doit voir ses taches + toutes les taches dont il a les droits
    this.model.addIdListenerSilently(Integer.valueOf(currentUser.getId()));

    final int size = this.users.size();
    for (int i = 0; i < size; i++) {
        Integer id = Integer.valueOf((this.users.get(i)).getId());
        if (this.model.listenToId(id)) {
            ((JCheckBoxMenuItem) this.comboUser.getMenuComponent(i)).setState(true);
        } else {
            ((JCheckBoxMenuItem) this.comboUser.getMenuComponent(i)).setState(false);
        }
    }

    this.addButton = new JButton(TM.tr("addTask"));
    this.removeButton = new JButton();
    this.removeButton.setOpaque(false);
    updateDeleteBtn();
    this.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.insets = new Insets(2, 2, 1, 2);
    c.fill = GridBagConstraints.HORIZONTAL;
    c.gridx = 0;
    c.gridy = 0;
    c.weightx = 1;
    c.weighty = 0;
    c.gridwidth = 6;
    // SEP
    TitledSeparator sep = new TitledSeparator(
            currentUser.getFirstName() + " " + currentUser.getName().toUpperCase());
    this.add(sep, c);

    c.gridwidth = 1;
    c.gridx = 0;
    c.gridy++;
    c.weightx = 0;
    this.add(this.addButton, c);
    c.gridx++;
    this.add(this.removeButton, c);

    c.anchor = GridBagConstraints.EAST;
    c.gridx++;
    final JMenuBar b = new JMenuBar();
    b.setOpaque(false);
    b.setBorderPainted(false);
    b.add(this.comboUser);
    // Pour que le menu ne disparaisse pas quand on rapetisse trop la fenetre en bas
    b.setMinimumSize(b.getPreferredSize());
    this.add(b, c);

    c.gridx++;
    c.weightx = 1;
    this.detailCheckBox = new JCheckBox(TM.tr("showDetails"));
    this.detailCheckBox.setOpaque(false);
    this.detailCheckBox.setSelected(false);
    this.add(this.detailCheckBox, c);

    //
    c.gridx++;
    this.hideOldCheckBox = new JCheckBox(TM.tr("hideHistory"));
    this.hideOldCheckBox.setOpaque(false);
    this.hideOldCheckBox.setSelected(true);
    this.add(this.hideOldCheckBox, c);

    c.gridx++;

    c.weightx = 0;
    c.anchor = GridBagConstraints.EAST;
    this.reloadPanel.setOpaque(false);
    this.add(this.reloadPanel, c);

    // Table
    c.gridwidth = 6;
    c.gridx = 0;
    c.gridy++;
    c.fill = GridBagConstraints.BOTH;
    c.weighty = 1;
    c.weightx = 1;
    initPopUp();
    initTable(TodoListModel.SIMPLE_MODE);
    this.add(new JScrollPane(this.t), c);

    initListeners();

    this.model.asynchronousFill();
}

From source file:de.unibayreuth.bayeos.goat.panels.timeseries.JPanelChart.java

public void mousePressed(MouseEvent event) {
    try {//  w w  w  .j  a v  a  2  s  .c  o m
        if (chartPanButton.isSelected()
                || chartPanButton.isEnabled() && SwingUtilities.isRightMouseButton(event)) {
            Rectangle2D dataArea = this.chartPanel.getScaledDataArea();
            Point2D point = event.getPoint();
            if (dataArea.contains(point)) {
                setPanMode(true);
                panStartPoint = point;
            }
        }
    } catch (Exception e) {
        MsgBox.error(e.getMessage());
    }
}

From source file:net.sf.firemox.clickable.target.card.VirtualCard.java

public void mouseDragged(MouseEvent e) {
    if (card.getParent() instanceof MZone && ((MZone) card.getParent()).dragAndDropComponent == card) {
        isAutoAlign = false;//  w  w w. j  av  a2s  .  c  o  m
        Point mousePoint = ((MZone) card.getParent()).mousePoint;
        Point drag = e.getPoint();
        Point cardLocation = (Point) card.getLocation().clone();
        card.setLocation(cardLocation.x + drag.x - mousePoint.x, cardLocation.y + drag.y - mousePoint.y);
    }
}

From source file:VASSAL.build.module.map.LOS_Thread.java

public void mouseDragged(MouseEvent e) {
    if (visible && !persisting && !mirroring) {
        retainAfterRelease = true;//from  ww  w  . j  a v a 2  s . c om

        Point p = e.getPoint();

        map.scrollAtEdge(p, 15);

        if (Boolean.TRUE.equals(GameModule.getGameModule().getPrefs().getValue(SNAP_LOS)) || snapEnd) {
            p = map.componentCoordinates(map.snapTo(map.mapCoordinates(p)));
        }
        arrow = map.mapCoordinates(p);

        String location = map.localizedLocationName(arrow);
        if (!checkList.contains(location) && !location.equals(anchorLocation)) {
            checkList.add(location);
            lastLocation = location;
        }

        Point mapAnchor = map.mapCoordinates(lastAnchor);
        Point mapArrow = map.mapCoordinates(lastArrow);
        int fudge = (int) (1.0 / map.getZoom() * 2);
        Rectangle r = new Rectangle(Math.min(mapAnchor.x, mapArrow.x) - fudge,
                Math.min(mapAnchor.y, mapArrow.y) - fudge, Math.abs(mapAnchor.x - mapArrow.x) + 1 + fudge * 2,
                Math.abs(mapAnchor.y - mapArrow.y) + 1 + fudge * 2);
        map.repaint(r);

        if (drawRange) {
            r = new Rectangle(lastRangeRect);
            r.width += (int) (r.width / map.getZoom()) + 1;
            r.height += (int) (r.height / map.getZoom()) + 1;
            map.repaint(r);
        }
    }
}

From source file:gdt.jgui.entity.fields.JFieldsEditor.java

/**
 * Create a new facet renderer./*ww  w. j a  v  a 2 s .c  o m*/
 * @param console the main console.
 * @param locator$ the locator string.
 * @return the fields editor.
 */
@Override
public JFacetRenderer instantiate(JMainConsole console, String locator$) {
    try {
        //System.out.println("FieldsEditor.instantiate:begin");
        this.console = console;
        Properties locator = Locator.toProperties(locator$);
        entihome$ = locator.getProperty(Entigrator.ENTIHOME);
        entityKey$ = locator.getProperty(EntityHandler.ENTITY_KEY);

        requesterResponseLocator$ = locator.getProperty(JRequester.REQUESTER_RESPONSE_LOCATOR);
        table = new JTable();
        DefaultTableModel model = new DefaultTableModel(null, new String[] { "Name", "Value" });
        entigrator = console.getEntigrator(entihome$);
        entity = entigrator.getEntityAtKey(entityKey$);
        entityLabel$ = entity.getProperty("label");
        Core[] ca = entity.elementGet("field");
        if (ca != null)
            for (Core aCa : ca) {
                model.addRow(new String[] { aCa.name, aCa.value });

            }
        table.setModel(model);
        scrollPane.setViewportView(table);
        table.getTableHeader().setDefaultRenderer(new SimpleHeaderRenderer());
        table.getTableHeader().addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                int col = table.columnAtPoint(e.getPoint());
                String name = table.getColumnName(col);
                // System.out.println("Column index selected " + col + " " + name);
                sort(name);
            }
        });
    } catch (Exception e) {
        LOGGER.severe(e.toString());

    }
    return this;

}