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:lu.lippmann.cdb.common.gui.DragAndDroppablePieChartPanel.java

/**
 * {@inheritDoc}//from   www .ja va2  s . c o  m
 */
@Override
public void mouseReleased(MouseEvent e) {
    super.mouseReleased(e);
    final ChartEntity entity = getEntityForPoint(e.getX(), e.getY());
    if (entity instanceof PieSectionEntity) {
        final PieSectionEntity target = ((PieSectionEntity) entity);
        if (source != null) {
            if (target.getSectionIndex() != source.getSectionIndex()) {
                listener.onAction(new Integer[] { source.getSectionIndex(), target.getSectionIndex() });
            }
        }
    }
    released = true;
    repaint();
}

From source file:Main.java

public void mouseMoved(MouseEvent evt) {
    JTableHeader header = (JTableHeader) evt.getSource();
    JTable table = header.getTable();
    TableColumnModel colModel = table.getColumnModel();
    int vColIndex = colModel.getColumnIndexAtX(evt.getX());
    TableColumn col = null;/*from  w w  w . j a v  a  2  s .  c o  m*/
    if (vColIndex >= 0) {
        col = colModel.getColumn(vColIndex);
    }
    if (col != curCol) {
        header.setToolTipText((String) tips.get(col));
        curCol = col;
    }
}

From source file:Main.java

@Override
public boolean isCellEditable(final EventObject event) {
    Object source = event.getSource();
    if (!(source instanceof JTree) || !(event instanceof MouseEvent)) {
        return false;
    }//  w  w  w .  j  av  a 2s  .co m
    JTree tree = (JTree) source;
    MouseEvent mouseEvent = (MouseEvent) event;
    TreePath path = tree.getPathForLocation(mouseEvent.getX(), mouseEvent.getY());
    if (path == null) {
        return false;
    }
    Object node = path.getLastPathComponent();
    if (node == null || !(node instanceof DefaultMutableTreeNode)) {
        return false;
    }

    Rectangle r = tree.getPathBounds(path);
    if (r == null) {
        return false;
    }
    Dimension d = panel.getPreferredSize();
    r.setSize(new Dimension(d.width, r.height));
    if (r.contains(mouseEvent.getX(), mouseEvent.getY())) {
        Point pt = SwingUtilities.convertPoint(tree, mouseEvent.getPoint(), panel);
        Object o = SwingUtilities.getDeepestComponentAt(panel, pt.x, pt.y);
        if (o instanceof JComboBox) {
            comboBox.showPopup();
        } else if (o instanceof Component) {
            Object oo = SwingUtilities.getAncestorOfClass(JComboBox.class, (Component) o);
            if (oo instanceof JComboBox) {
                comboBox.showPopup();
            }
        }
        return true;
    }
    return delegate.isCellEditable(event);
}

From source file:com.vgi.mafscaling.MafChartPanel.java

public void mousePressed(MouseEvent e) {
    Insets insets = chartPanel.getInsets();
    int x = (int) ((e.getX() - insets.left) / chartPanel.getScaleX());
    int y = (int) ((e.getY() - insets.top) / chartPanel.getScaleY());
    ChartEntity entity = chartPanel.getChartRenderingInfo().getEntityCollection().getEntity(x, y);
    if (entity == null || !(entity instanceof XYItemEntity))
        return;//from   w  w w.java 2  s.  c  o m
    IsMovable = true;
    chartPanel.setCursor(new Cursor(Cursor.HAND_CURSOR));
    xyItemEntity = (XYItemEntity) entity;
    XYPlot plot = chartPanel.getChart().getXYPlot();
    Rectangle2D dataArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea();
    Point2D p = chartPanel.translateScreenToJava2D(e.getPoint());
    initialMovePointY = plot.getRangeAxis().java2DToValue(p.getY(), dataArea, plot.getRangeAxisEdge());
}

From source file:com.cburch.draw.tools.LineTool.java

@Override
public void mouseReleased(Canvas canvas, MouseEvent e) {
    if (active) {
        updateMouse(canvas, e.getX(), e.getY(), e.getModifiersEx());
        Location start = mouseStart;
        Location end = mouseEnd;//from   w w  w. ja v  a  2 s  . co  m
        CanvasObject add = null;
        if (!start.equals(end)) {
            active = false;
            CanvasModel model = canvas.getModel();
            Location[] ends = { start, end };
            List<Location> locs = UnmodifiableList.decorate(Arrays.asList(ends));
            add = attrs.applyTo(new Poly(false, locs));
            add.setValue(DrawAttr.PAINT_TYPE, DrawAttr.PAINT_STROKE);
            canvas.doAction(new ModelAddAction(model, add));
            repaintArea(canvas);
        }
        canvas.toolGestureComplete(this, add);
    }
}

From source file:Main.java

@Override
public boolean isCellEditable(EventObject e) {
    if (e instanceof MouseEvent && e.getSource() instanceof JTree) {
        MouseEvent me = (MouseEvent) e;
        JTree tree = (JTree) e.getSource();
        TreePath path = tree.getPathForLocation(me.getX(), me.getY());
        Rectangle r = tree.getPathBounds(path);
        if (r == null) {
            return false;
        }/*w  ww . j a  v a2  s  .c  om*/
        Dimension d = check.getPreferredSize();
        r.setSize(new Dimension(d.width, r.height));
        if (r.contains(me.getX(), me.getY())) {
            check.setBounds(new Rectangle(0, 0, d.width, r.height));
            return true;
        }
    }
    return false;
}

From source file:BezLab.java

public void mousePressed(MouseEvent e) {
    dragIndex = NOT_DRAGGING;//from   www. ja v  a2s.c om
    int minDistance = Integer.MAX_VALUE;
    int indexOfClosestPoint = -1;
    for (int i = 0; i < 4; i++) {
        int deltaX = xs[i] - e.getX();
        int deltaY = ys[i] - e.getY();
        int distance = (int) (Math.sqrt(deltaX * deltaX + deltaY * deltaY));
        if (distance < minDistance) {
            minDistance = distance;
            indexOfClosestPoint = i;
        }
    }
    if (minDistance > NEIGHBORHOOD)
        return;

    dragIndex = indexOfClosestPoint;
}

From source file:UndoableDrawingPanel.java

public UndoableDrawingPanel() {
    MouseListener mouseListener = new MouseAdapter() {
        public void mouseReleased(MouseEvent mouseEvent) {
            StateEdit stateEdit = new StateEdit(UndoableDrawingPanel.this);
            polygon.addPoint(mouseEvent.getX(), mouseEvent.getY());
            stateEdit.end();// w  w  w.  j  a v a2s .  com
            undoableEditSupport.postEdit(stateEdit);
            repaint();
        }
    };
    addMouseListener(mouseListener);
}

From source file:CheckBoxNodeTreeSample.java

public boolean isCellEditable(EventObject event) {
    boolean returnValue = false;
    if (event instanceof MouseEvent) {
        MouseEvent mouseEvent = (MouseEvent) event;
        TreePath path = tree.getPathForLocation(mouseEvent.getX(), mouseEvent.getY());
        if (path != null) {
            Object node = path.getLastPathComponent();
            if ((node != null) && (node instanceof DefaultMutableTreeNode)) {
                DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) node;
                Object userObject = treeNode.getUserObject();
                returnValue = ((treeNode.isLeaf()) && (userObject instanceof CheckBoxNode));
            }//from www .java2s.  c om
        }
    }
    return returnValue;
}

From source file:fi.smaa.jsmaa.gui.SMAA2GUIFactory.java

@Override
protected JButton buildToolBarAddCriterionButton() {
    JButton button = new JButton(ImageFactory.IMAGELOADER.getIcon(FileNames.ICON_ADDCRITERION));
    button.setToolTipText("Add criterion");
    final JPopupMenu addMenu = new JPopupMenu();
    addUtilityAddItemsToMenu(addMenu);//www. jav a  2s  . c o  m
    button.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent evt) {
            addMenu.show((Component) evt.getSource(), evt.getX(), evt.getY());
        }
    });
    return button;
}