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:com.anrisoftware.prefdialog.miscswing.lists.RubberBandingList.java

private void init() {
    this.srcPoint = new Point();
    this.selectionColor = createSelectionColor();
    this.rubberBandMouseListener = new MouseAdapter() {
        @Override/*w w  w.j a v  a2  s  . c o  m*/
        public void mousePressed(MouseEvent e) {
            int index = locationToIndex(e.getPoint());
            Rectangle rect = getCellBounds(index, index);
            if (!rect.contains(e.getPoint())) {
                clearSelection();
                getSelectionModel().setAnchorSelectionIndex(-1);
                getSelectionModel().setLeadSelectionIndex(-1);
                setFocusable(false);
            } else {
                setFocusable(true);
            }
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            setFocusable(true);
            rubberBand = null;
            repaint();
        }
    };
    this.rubberBandMouseMotionListener = new MouseMotionAdapter() {
        @Override
        public void mouseDragged(MouseEvent e) {
            setFocusable(true);
            if (rubberBand == null) {
                srcPoint.setLocation(e.getPoint());
            }
            Point destPoint = e.getPoint();
            rubberBand = new Path2D.Double();
            rubberBand.moveTo(srcPoint.x, srcPoint.y);
            rubberBand.lineTo(destPoint.x, srcPoint.y);
            rubberBand.lineTo(destPoint.x, destPoint.y);
            rubberBand.lineTo(srcPoint.x, destPoint.y);
            rubberBand.closePath();
            setSelectedIndices(getIntersectsIdices(rubberBand));
            repaint();
        }
    };
    addMouseListener(rubberBandMouseListener);
    addMouseMotionListener(rubberBandMouseMotionListener);
}

From source file:org.jets3t.gui.JHtmlLabel.java

/**
 * Changes the mouse cursor to a hand to indicate when the mouse moves over a clickable
 * HTML link.//from   ww w .j  a v  a  2  s  .c o  m
 *
 * @param e event
 */
public void mouseMoved(MouseEvent e) {
    AccessibleJLabel acc = (AccessibleJLabel) getAccessibleContext();
    int stringIndexAtPoint = acc.getIndexAtPoint(e.getPoint());
    if (stringIndexAtPoint < 0) {
        return;
    }
    javax.swing.text.AttributeSet attr = acc.getCharacterAttribute(stringIndexAtPoint);
    if (attr.getAttribute(HTML.Tag.A) == null) {
        setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    } else {
        setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    }
}

From source file:org.jcurl.demo.smack.RosterSimpleSwingBean.java

public RosterSimpleSwingBean() {
    setLayout(new BorderLayout());
    l = new JList(data);
    // see/*from w  w  w .j av a2 s.  c  o  m*/
    // http://java.sun.com/products/jfc/tsc/tech_topics/jlist_1/jlist.html:
    final MouseListener mouseListener = new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
                final int index = l.locationToIndex(e.getPoint());
                final Object o = l.getModel().getElementAt(index);
                if (o != null && getChatManager() != null)
                    getChatManager().createChat(s2a.get(o).toString(), null);
            }
        }
    };
    l.addMouseListener(mouseListener);
    add(l, BorderLayout.CENTER);
}

From source file:org.jets3t.gui.JHtmlLabel.java

/**
 * Triggers the listener to follow an HTML href link that has been clicked.
 *
 * @param e event/*www . java2 s  .c  om*/
 */
public void mouseClicked(MouseEvent e) {
    AccessibleJLabel acc = (AccessibleJLabel) getAccessibleContext();
    int stringIndexAtPoint = acc.getIndexAtPoint(e.getPoint());
    if (stringIndexAtPoint < 0) {
        return;
    }
    AttributeSet attr = (AttributeSet) acc.getCharacterAttribute(acc.getIndexAtPoint(e.getPoint()))
            .getAttribute(HTML.Tag.A);
    if (attr != null) {
        String href = (String) attr.getAttribute(HTML.Attribute.HREF);
        String target = (String) attr.getAttribute(HTML.Attribute.TARGET);
        try {
            if (listener == null) {
                log.warn("No HyperlinkActivatedListener available to follow HTML link for label: " + getText());
            } else {
                listener.followHyperlink(new URL(href), target);
            }
        } catch (Exception ex) {
            log.error("Unable to load URL: " + href, ex);
        }
    }
}

From source file:ScreenCapture.java

public ImageArea() {
    addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            if (image == null)
                return;
            startPoint = endPoint = e.getPoint();
            repaint();/*from w  ww.j  ava 2s . co m*/
        }
    });

    addMouseMotionListener(new MouseMotionAdapter() {
        public void mouseDragged(MouseEvent e) {
            if (image == null)
                return;

            endPoint = e.getPoint();
            repaint();
        }
    });
}

From source file:Main.java

public Main() {
    super(new GridLayout(1, 0));

    JTable table = new JTable(new MyTableModel()) {

        //Implement table cell tool tips.
        public String getToolTipText(MouseEvent e) {
            String tip = null;/*from w  w  w .  j  a  v a2 s .c  om*/
            java.awt.Point p = e.getPoint();
            int rowIndex = rowAtPoint(p);
            int colIndex = columnAtPoint(p);
            int realColumnIndex = convertColumnIndexToModel(colIndex);

            if (realColumnIndex == 2) { //Sport column
                tip = "This person's favorite sport to " + "participate in is: "
                        + getValueAt(rowIndex, colIndex);
            } else if (realColumnIndex == 4) { //Veggie column
                TableModel model = getModel();
                String firstName = (String) model.getValueAt(rowIndex, 0);
                String lastName = (String) model.getValueAt(rowIndex, 1);
                Boolean veggie = (Boolean) model.getValueAt(rowIndex, 4);
                if (Boolean.TRUE.equals(veggie)) {
                    tip = firstName + " " + lastName + " is a vegetarian";
                } else {
                    tip = firstName + " " + lastName + " is not a vegetarian";
                }
            } else {
                //You can omit this part if you know you don't 
                //have any renderers that supply their own tool 
                //tips.
                tip = super.getToolTipText(e);
            }
            return tip;
        }

        //Implement table header tool tips. 
        protected JTableHeader createDefaultTableHeader() {
            return new JTableHeader(columnModel) {
                public String getToolTipText(MouseEvent e) {
                    String tip = null;
                    java.awt.Point p = e.getPoint();
                    int index = columnModel.getColumnIndexAtX(p.x);
                    int realIndex = columnModel.getColumn(index).getModelIndex();
                    return columnToolTips[realIndex];
                }
            };
        }
    };

    table.setPreferredScrollableViewportSize(new Dimension(500, 70));
    table.setFillsViewportHeight(true);

    //Create the scroll pane and add the table to it.
    JScrollPane scrollPane = new JScrollPane(table);

    //Add the scroll pane to this panel.
    add(scrollPane);
}

From source file:components.TableToolTipsDemo.java

public TableToolTipsDemo() {
    super(new GridLayout(1, 0));

    JTable table = new JTable(new MyTableModel()) {

        //Implement table cell tool tips.
        public String getToolTipText(MouseEvent e) {
            String tip = null;/*w w w  . ja v a 2 s .  c o  m*/
            java.awt.Point p = e.getPoint();
            int rowIndex = rowAtPoint(p);
            int colIndex = columnAtPoint(p);
            int realColumnIndex = convertColumnIndexToModel(colIndex);

            if (realColumnIndex == 2) { //Sport column
                tip = "This person's favorite sport to " + "participate in is: "
                        + getValueAt(rowIndex, colIndex);
            } else if (realColumnIndex == 4) { //Veggie column
                TableModel model = getModel();
                String firstName = (String) model.getValueAt(rowIndex, 0);
                String lastName = (String) model.getValueAt(rowIndex, 1);
                Boolean veggie = (Boolean) model.getValueAt(rowIndex, 4);
                if (Boolean.TRUE.equals(veggie)) {
                    tip = firstName + " " + lastName + " is a vegetarian";
                } else {
                    tip = firstName + " " + lastName + " is not a vegetarian";
                }
            } else {
                //You can omit this part if you know you don't 
                //have any renderers that supply their own tool 
                //tips.
                tip = super.getToolTipText(e);
            }
            return tip;
        }

        //Implement table header tool tips. 
        protected JTableHeader createDefaultTableHeader() {
            return new JTableHeader(columnModel) {
                public String getToolTipText(MouseEvent e) {
                    String tip = null;
                    java.awt.Point p = e.getPoint();
                    int index = columnModel.getColumnIndexAtX(p.x);
                    int realIndex = columnModel.getColumn(index).getModelIndex();
                    return columnToolTips[realIndex];
                }
            };
        }
    };

    table.setPreferredScrollableViewportSize(new Dimension(500, 70));
    table.setFillsViewportHeight(true);

    //Create the scroll pane and add the table to it.
    JScrollPane scrollPane = new JScrollPane(table);

    //Add the scroll pane to this panel.
    add(scrollPane);
}

From source file:com.emental.mindraider.ui.outline.OutlineSorterJPanel.java

protected JTableHeader createDefaultTableHeader() {
    return new JTableHeader() {
        public String getToolTipText(MouseEvent e) {
            java.awt.Point p = e.getPoint();
            int index = columnModel.getColumnIndexAtX(p.x);
            int realIndex = columnModel.getColumn(index).getModelIndex();
            return columnNames[realIndex];
        }//from   w  w w. ja v  a 2 s. c  o  m

        private static final long serialVersionUID = -3219707005673982727L;
    };
}

From source file:de.fhg.igd.mapviewer.MapToolPainter.java

/**
 * @see MouseListener#mouseClicked(MouseEvent)
 *///from ww w  .j av  a  2 s . co  m
@Override
public void mouseClicked(MouseEvent me) {
    if (mapTool != null) {
        mapTool.mouseClicked(me, mapViewer.convertPointToGeoPosition(me.getPoint()));
    }
}

From source file:de.fhg.igd.mapviewer.MapToolPainter.java

/**
 * @see MouseListener#mousePressed(MouseEvent)
 *//*from   w w  w . j a v a 2  s.c  om*/
@Override
public void mousePressed(MouseEvent me) {
    if (mapTool != null) {
        mapTool.mousePressed(me, mapViewer.convertPointToGeoPosition(me.getPoint()));
    }
}