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:org.gumtree.vis.awt.JChartPanel.java

@Override
public void mouseMoved(MouseEvent e) {
    //        if (isMaskingEnabled() && (e.getModifiers() & maskingKeyMask) != 0) {
    if (selectedTextWrapper == null && isMaskingEnabled()) {
        int cursorType = findCursorOnSelectedItem(e.getX(), e.getY());
        setCursor(Cursor.getPredefinedCursor(cursorType));
    } else {//from   ww  w  .  j  ava  2s  . c om
        Cursor newCursor = defaultCursor;
        if (selectedTextWrapper != null) {
            Point2D screenXY = ChartMaskingUtilities.translateChartPoint(
                    new Point2D.Double(selectedTextWrapper.getMinX(), selectedTextWrapper.getMinY()),
                    getScreenDataArea(), getChart());
            Rectangle2D screenRect = new Rectangle2D.Double(screenXY.getX(), screenXY.getY() - 15,
                    selectedTextWrapper.getWidth(), selectedTextWrapper.getHeight());
            if (screenRect.contains(e.getX(), e.getY())) {
                newCursor = Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR);
            }
        }
        if (newCursor != getCursor()) {
            setCursor(newCursor);
        }
    }
    Line2D oldSelection = selectedMarker;
    findSelectedMarker(e.getPoint());
    if (selectedMarker != oldSelection) {
        repaint();
    }
}

From source file:org.gumtree.vis.awt.JChartPanel.java

@Override
public void mouseClicked(MouseEvent e) {
    if ((e.getModifiers() & InputEvent.ALT_MASK) != 0) {
        double xNew = ChartMaskingUtilities.translateScreenX(e.getX(), getScreenDataArea(), getChart());
        double yNew = ChartMaskingUtilities.translateScreenY(e.getY(), getScreenDataArea(), getChart(), 0);
        addMarker(xNew, yNew, null);//  w w  w .ja  v a2 s . c  o  m
    } else if (isTextInputEnabled) {
        if (!textInputFlag) {
            boolean newTextEnabled = selectedTextWrapper == null;
            if (selectedTextWrapper != null) {
                Point2D screenXY = ChartMaskingUtilities.translateChartPoint(
                        new Point2D.Double(selectedTextWrapper.getMinX(), selectedTextWrapper.getMinY()),
                        getScreenDataArea(), getChart());
                Rectangle2D screenRect = new Rectangle2D.Double(screenXY.getX(), screenXY.getY() - 15,
                        selectedTextWrapper.getWidth(), selectedTextWrapper.getHeight());
                if (screenRect.contains(e.getX(), e.getY())) {
                    Point2D point = e.getPoint();
                    String inputText = textContentMap.get(selectedTextWrapper);
                    if (inputText == null) {
                        inputText = "";
                    }
                    String[] lines = inputText.split("\n", 100);
                    int cursorX = 0;
                    int charCount = 0;
                    int maxWidth = 0;
                    int pickX = -1;
                    FontMetrics fm = getGraphics().getFontMetrics();
                    for (int i = 0; i < lines.length; i++) {
                        int lineWidth = fm.stringWidth(lines[i]);
                        if (lineWidth > maxWidth) {
                            maxWidth = lineWidth;
                        }
                    }
                    if (maxWidth < 100) {
                        maxWidth = 100;
                    }
                    Point2D screenPoint = ChartMaskingUtilities.translateChartPoint(
                            new Point2D.Double(selectedTextWrapper.getX(), selectedTextWrapper.getY()),
                            getScreenDataArea(), getChart());
                    if (point.getX() <= screenPoint.getX() + 11 + maxWidth
                            && point.getY() <= screenPoint.getY() + lines.length * 15 - 15) {
                        textInputPoint = screenPoint;
                        textInputContent = inputText;
                        textInputFlag = true;
                        textContentMap.remove(selectedTextWrapper);
                        selectedTextWrapper = null;
                        textInputCursorIndex = 0;
                        for (int i = 0; i < lines.length; i++) {
                            if (point.getY() > screenPoint.getY() + i * 15 - 15
                                    && point.getY() <= screenPoint.getY() + i * 15) {
                                cursorX = fm.stringWidth(lines[i]);
                                if (point.getX() >= screenPoint.getX()
                                        && point.getX() <= screenPoint.getX() + 3 + cursorX) {
                                    if (point.getX() >= screenPoint.getX()
                                            && point.getX() < screenPoint.getX() + 3) {
                                        pickX = 0;
                                    }
                                    double lastEnd = screenPoint.getX() + 3;
                                    for (int j = 0; j < lines[i].length(); j++) {
                                        int size = fm.stringWidth(lines[i].substring(0, j + 1));
                                        double newEnd = screenPoint.getX() + 3 + size;
                                        if (point.getX() >= lastEnd
                                                && point.getX() < lastEnd + (newEnd - lastEnd) / 2) {
                                            pickX = j;
                                        } else if (point.getX() >= lastEnd + (newEnd - lastEnd) / 2
                                                && point.getX() < newEnd) {
                                            pickX = j + 1;
                                        }
                                        lastEnd = newEnd;
                                    }
                                    if (pickX >= 0) {
                                        textInputCursorIndex = charCount + pickX;
                                    }
                                } else {
                                    textInputCursorIndex = charCount + lines[i].length();
                                }
                                break;
                            }
                            charCount += lines[i].length() + 1;
                        }
                    }
                }
            }
            selectText(e.getX(), e.getY());
            if (selectedTextWrapper == null && !textInputFlag && newTextEnabled
                    && (e.getModifiers() & MouseEvent.BUTTON1_MASK) != 0) {
                textInputFlag = true;
                textInputPoint = e.getPoint();
            }
        } else {
            Point2D point = e.getPoint();
            boolean finishInput = false;
            //            if (point.getX() < textInputPoint.getX() || point.getY() < textInputPoint.getY() - 15) {
            //               finishInput = true;
            //            } else {
            String inputText = textInputContent;
            if (inputText == null) {
                inputText = "";
            }
            String[] lines = inputText.split("\n", 100);
            int cursorX = 0;
            int charCount = 0;
            int maxWidth = 0;
            int pickX = -1;
            FontMetrics fm = getGraphics().getFontMetrics();
            for (int i = 0; i < lines.length; i++) {
                int lineWidth = fm.stringWidth(lines[i]);
                if (lineWidth > maxWidth) {
                    maxWidth = lineWidth;
                }
            }
            if (maxWidth < 100) {
                maxWidth = 100;
            }
            if (point.getX() > textInputPoint.getX() + 11 + maxWidth
                    || point.getY() > textInputPoint.getY() + lines.length * 15 - 15
                    || point.getX() < textInputPoint.getX() || point.getY() < textInputPoint.getY() - 15) {
                finishInput = true;
            } else {
                for (int i = 0; i < lines.length; i++) {
                    if (point.getY() > textInputPoint.getY() + i * 15 - 15
                            && point.getY() <= textInputPoint.getY() + i * 15) {
                        cursorX = fm.stringWidth(lines[i]);
                        if (point.getX() >= textInputPoint.getX()
                                && point.getX() <= textInputPoint.getX() + 3 + cursorX) {
                            if (point.getX() >= textInputPoint.getX()
                                    && point.getX() < textInputPoint.getX() + 3) {
                                pickX = 0;
                            }
                            double lastEnd = textInputPoint.getX() + 3;
                            for (int j = 0; j < lines[i].length(); j++) {
                                int size = fm.stringWidth(lines[i].substring(0, j + 1));
                                double newEnd = textInputPoint.getX() + 3 + size;
                                if (point.getX() >= lastEnd
                                        && point.getX() < lastEnd + (newEnd - lastEnd) / 2) {
                                    pickX = j;
                                } else if (point.getX() >= lastEnd + (newEnd - lastEnd) / 2
                                        && point.getX() < newEnd) {
                                    pickX = j + 1;
                                }
                                lastEnd = newEnd;
                            }
                            if (pickX >= 0) {
                                textInputCursorIndex = charCount + pickX;
                            }
                        } else {
                            textInputCursorIndex = charCount + lines[i].length();
                        }
                        break;
                    }
                    charCount += lines[i].length() + 1;
                }
            }
            //            }

            if (finishInput) {
                if (textInputContent != null && textInputContent.length() > 0) {
                    double xNew = ChartMaskingUtilities.translateScreenX(textInputPoint.getX(),
                            getScreenDataArea(), getChart());
                    double yNew = ChartMaskingUtilities.translateScreenY(textInputPoint.getY(),
                            getScreenDataArea(), getChart(), 0);
                    textContentMap.put(new Rectangle2D.Double(xNew, yNew, maxWidth, lines.length * 15),
                            textInputContent);
                }
                textInputContent = null;
                textInputCursorIndex = 0;
                textInputFlag = false;
            }
        }
    }
}

From source file:base.BasePlayer.AminoTable.java

@Override

public void mousePressed(MouseEvent event) {

    switch (event.getModifiers()) {

    case InputEvent.BUTTON1_MASK: {

        if (!this.isEnabled()) {
            break;
        }//from w  w w .  ja  va 2  s. c o  m
        this.dragX = event.getX();
        if (headerHover > -1) {
            if (resizeColumn == -1) {
                if (sorter.ascending) {
                    sorter.ascending = false;
                } else {
                    sorter.ascending = true;
                }
                sorter.index = headerHover;
                Collections.sort(genearray, sorter);
                createPolygon();
            }
            repaint();
        }

    }

        if (hoverNode != null || hoverVar != null) {
            Main.chromDraw.repaint();
        }
    }

}

From source file:com.isti.traceview.common.TraceViewChartPanel.java

/**
 * Receives notification of mouse clicks on the panel. These are translated and passed on to any
 * registered chart mouse click listeners.
 * /*from  ww w .  j  a  va 2 s. c  om*/
 * @param event
 *            Information about the mouse event.
 */
public void mouseClicked(MouseEvent event) {
    Insets insets = getInsets();
    int x = (int) ((event.getX() - insets.left) / this.scaleX);
    int y = (int) ((event.getY() - insets.top) / this.scaleY);

    this.anchor = new Point2D.Double(x, y);
    if (this.chart == null) {
        return;
    }
    this.chart.setNotify(true); // force a redraw
    // new entity code...
    Object[] listeners = this.chartMouseListeners.getListeners(ChartMouseListener.class);
    if (listeners.length == 0) {
        return;
    }

    ChartEntity entity = null;
    if (this.info != null) {
        EntityCollection entities = this.info.getEntityCollection();
        if (entities != null) {
            entity = entities.getEntity(x, y);
        }
    }
    ChartMouseEvent chartEvent = new ChartMouseEvent(getChart(), event, entity);
    for (int i = listeners.length - 1; i >= 0; i -= 1) {
        ((ChartMouseListener) listeners[i]).chartMouseClicked(chartEvent);
    }
}

From source file:cfa.vo.sed.science.stacker.SedStackerFrame.java

private void sedsTableMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_sedsTableMousePressed
    if (evt.isPopupTrigger()) {
        JTable source = (JTable) evt.getSource();
        int row = source.rowAtPoint(evt.getPoint());
        int column = source.columnAtPoint(evt.getPoint());

        if (!source.isRowSelected(row))
            source.changeSelection(row, column, false, false);

        sedsTable.changeSelection(row, column, false, false);

        jPopupMenu2.show(evt.getComponent(), evt.getX(), evt.getY());
    }/*from w w  w.  j a  va 2  s.  c o m*/
}

From source file:com.isti.traceview.common.TraceViewChartPanel.java

/**
 * Handles a 'mouse pressed' event.//from  w  ww  .j a  v  a  2  s . c o m
 * <P>
 * This event is the popup trigger on Unix/Linux. For Windows, the popup trigger is the 'mouse
 * released' event.
 * 
 * @param e
 *            The mouse event.
 */
public void mousePressed(MouseEvent e) {
    if (this.zoomRectangle == null) {
        Rectangle2D screenDataArea = getScreenDataArea(e.getX(), e.getY());
        if (screenDataArea != null) {
            this.zoomPoint = getPointInRectangle(e.getX(), e.getY(), screenDataArea);
        } else {
            this.zoomPoint = null;
        }
        if (e.isPopupTrigger()) {
            if (this.popup != null) {
                displayPopupMenu(e.getX(), e.getY());
            }
        }
    }
}

From source file:net.sf.jabref.gui.MainTableSelectionListener.java

@Override
public void mouseClicked(MouseEvent e) {

    // First find the column on which the user has clicked.
    final int col = table.columnAtPoint(e.getPoint());
    final int row = table.rowAtPoint(e.getPoint());

    // A double click on an entry should open the entry's editor.
    if (e.getClickCount() == 2) {

        BibtexEntry toShow = tableRows.get(row);
        editSignalled(toShow);//from  w  w  w  .j a v a 2  s.c  om
    }

    // Check if the user has clicked on an icon cell to open url or pdf.
    final String[] iconType = table.getIconTypeForColumn(col);

    // Workaround for Windows. Right-click is not popup trigger on mousePressed, but
    // on mouseReleased. Therefore we need to avoid taking action at this point, because
    // action will be taken when the button is released:
    if (OS.WINDOWS && (iconType != null) && (e.getButton() != MouseEvent.BUTTON1)) {
        return;
    }

    if (iconType != null) {
        // left click on icon field
        SpecialField field = SpecialFieldsUtils.getSpecialFieldInstanceFromFieldName(iconType[0]);
        if ((e.getClickCount() == 1) && (field != null)) {
            // special field found
            if (field.isSingleValueField()) {
                // directly execute toggle action instead of showing a menu with one action
                field.getValues().get(0).getAction(panel.frame()).action();
            } else {
                JPopupMenu menu = new JPopupMenu();
                for (SpecialFieldValue val : field.getValues()) {
                    menu.add(val.getMenuAction(panel.frame()));
                }
                menu.show(table, e.getX(), e.getY());
            }
            return;
        }

        Object value = table.getValueAt(row, col);
        if (value == null) {
            return; // No icon here, so we do nothing.
        }

        final BibtexEntry entry = tableRows.get(row);

        // Get the icon type. Corresponds to the field name.
        int hasField = -1;
        for (int i = iconType.length - 1; i >= 0; i--) {
            if (entry.getField(iconType[i]) != null) {
                hasField = i;
            }
        }
        if (hasField == -1) {
            return;
        }
        final String fieldName = iconType[hasField];

        //If this is a file link field with specified file types,
        //we should also pass the types.
        String[] fileTypes = {};
        if ((hasField == 0) && iconType[hasField].equals(Globals.FILE_FIELD) && (iconType.length > 1)) {
            fileTypes = iconType;
        }
        final List<String> listOfFileTypes = Collections.unmodifiableList(Arrays.asList(fileTypes));

        // Open it now. We do this in a thread, so the program won't freeze during the wait.
        JabRefExecutorService.INSTANCE.execute(new Runnable() {

            @Override
            public void run() {
                panel.output(Localization.lang("External viewer called") + '.');

                Object link = entry.getField(fieldName);
                if (link == null) {
                    LOGGER.info("Error: no link to " + fieldName + '.');
                    return; // There is an icon, but the field is not set.
                }

                // See if this is a simple file link field, or if it is a file-list
                // field that can specify a list of links:
                if (fieldName.equals(Globals.FILE_FIELD)) {

                    // We use a FileListTableModel to parse the field content:
                    FileListTableModel fileList = new FileListTableModel();
                    fileList.setContent((String) link);

                    FileListEntry flEntry = null;
                    // If there are one or more links of the correct type,
                    // open the first one:
                    if (!listOfFileTypes.isEmpty()) {
                        for (int i = 0; i < fileList.getRowCount(); i++) {
                            flEntry = fileList.getEntry(i);
                            boolean correctType = false;
                            for (String listOfFileType : listOfFileTypes) {
                                if (flEntry.getType().toString().equals(listOfFileType)) {
                                    correctType = true;
                                }
                            }
                            if (correctType) {
                                break;
                            }
                            flEntry = null;
                        }
                    }
                    //If there are no file types specified, consider all files.
                    else if (fileList.getRowCount() > 0) {
                        flEntry = fileList.getEntry(0);
                    }
                    if (flEntry != null) {
                        //                            if (fileList.getRowCount() > 0) {
                        //                                FileListEntry flEntry = fileList.getEntry(0);

                        ExternalFileMenuItem item = new ExternalFileMenuItem(panel.frame(), entry, "",
                                flEntry.getLink(), flEntry.getType().getIcon(), panel.metaData(),
                                flEntry.getType());
                        boolean success = item.openLink();
                        if (!success) {
                            panel.output(Localization.lang("Unable to open link."));
                        }
                    }
                } else {
                    try {
                        JabRefDesktop.openExternalViewer(panel.metaData(), (String) link, fieldName);
                    } catch (IOException ex) {
                        panel.output(Localization.lang("Unable to open link."));
                    }

                    /*ExternalFileType type = Globals.prefs.getExternalFileTypeByMimeType("text/html");
                    ExternalFileMenuItem item = new ExternalFileMenuItem
                        (panel.frame(), entry, "",
                        (String)link, type.getIcon(),
                        panel.metaData(), type);
                    boolean success = item.openLink();
                    if (!success) {
                    panel.output(Localization.lang("Unable to open link."));
                    } */
                    //Util.openExternalViewer(panel.metaData(), (String)link, fieldName);
                }

                //catch (IOException ex) {
                //    panel.output(Globals.lang("Error") + ": " + ex.getMessage());
                //}
            }

        });
    }
}

From source file:com.isti.traceview.common.TraceViewChartPanel.java

/**
 * Implementation of the MouseMotionListener's method.
 * // ww  w  .  j ava 2s  .co m
 * @param e
 *            the event.
 */
public void mouseMoved(MouseEvent e) {
    Graphics2D g2 = (Graphics2D) getGraphics();
    if (this.horizontalAxisTrace) {
        drawHorizontalAxisTrace(g2, e.getX());
    }
    if (this.verticalAxisTrace) {
        drawVerticalAxisTrace(g2, e.getY());
    }
    g2.dispose();

    Object[] listeners = this.chartMouseListeners.getListeners(ChartMouseListener.class);
    if (listeners.length == 0) {
        return;
    }
    Insets insets = getInsets();
    int x = (int) ((e.getX() - insets.left) / this.scaleX);
    int y = (int) ((e.getY() - insets.top) / this.scaleY);

    ChartEntity entity = null;
    if (this.info != null) {
        EntityCollection entities = this.info.getEntityCollection();
        if (entities != null) {
            entity = entities.getEntity(x, y);
        }
    }

    // we can only generate events if the panel's chart is not null
    // (see bug report 1556951)
    if (this.chart != null) {
        ChartMouseEvent event = new ChartMouseEvent(getChart(), e, entity);
        for (int i = listeners.length - 1; i >= 0; i -= 1) {
            ((ChartMouseListener) listeners[i]).chartMouseMoved(event);
        }
    }

}

From source file:ExText.java

/**
 * Responds to a button1 event (press, release, or drag). On a press, the
 * method adds a wakeup criterion to the behavior's set, callling for the
 * behavior to be awoken on each frame. On a button prelease, this criterion
 * is removed from the set./*from w w  w. j  av  a  2 s  . c o m*/
 * 
 * @param mouseEvent
 *            the MouseEvent to respond to
 */
public void onButton1(MouseEvent mev) {
    if (subjectTransformGroup == null)
        return;

    int x = mev.getX();
    int y = mev.getY();

    if (mev.getID() == MouseEvent.MOUSE_PRESSED) {
        // Mouse button pressed: record position and change
        // the wakeup criterion to include elapsed time wakeups
        // so we can animate.
        previousX = x;
        previousY = y;
        initialX = x;
        initialY = y;

        // Swap criterion... parent class will not reschedule us
        mouseCriterion = mouseAndAnimationCriterion;

        // Change to a "move" cursor
        if (parentComponent != null) {
            savedCursor = parentComponent.getCursor();
            parentComponent.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        }
        return;
    }
    if (mev.getID() == MouseEvent.MOUSE_RELEASED) {
        // Mouse button released: restore original wakeup
        // criterion which only includes mouse activity, not
        // elapsed time
        mouseCriterion = savedMouseCriterion;

        // Switch the cursor back
        if (parentComponent != null)
            parentComponent.setCursor(savedCursor);
        return;
    }

    previousX = x;
    previousY = y;
}

From source file:br.com.atmatech.sac.view.ViewListaAtendimento.java

private void jTatendimentoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTatendimentoMouseClicked
    // TODO add your handling code here:
    if (new NivelAcesso().getAcesso("ViewAtendimento", "acessar")) {
        if (evt.getClickCount() == 2) {
            ViewAtendimento view = new ViewAtendimento(viewprincipal, this, clickAtendimento(),
                    new UsuarioLogadoBeans().getAlttecnico(), false);
            viewprincipal.jTaabas.getSelectedIndex();
            viewprincipal.jTaabas.setComponentAt(viewprincipal.jTaabas.getSelectedIndex(), view);

            if (!new UsuarioLogadoBeans().getBconsulta()) {
                if (constecnico.isAlive()) {
                    if (!constecnico.isInterrupted()) {
                        constecnico.stop();
                    }/* w  w w  . ja  va 2  s .  c  o  m*/
                }
                //constecnico.stop();
            }
        }
    }
    if (jTatendimento.getSelectedRow() >= 0) {
        if ((evt.getModifiers() & MouseEvent.BUTTON3_MASK) != 0) {
            jPopupMenu1.show(jTatendimento, evt.getX(), evt.getY());
        }
    }
}