List of usage examples for java.awt.event MouseEvent getPoint
public Point getPoint()
From source file: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;//from w w w . jav 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)); //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.anrisoftware.prefdialog.miscswing.lists.PopupMenuList.java
@SuppressWarnings("serial") private void setupPopup() { popup.setMouseFilter(new MouseFilter() { @Override//from w w w .j ava 2 s . c om public boolean allow(MouseEvent e) { if (selectedIndex == -1) { return false; } int mouseIndex = list.locationToIndex(e.getPoint()); return selectedIndex == mouseIndex && isRightMouseButton(e); } }); popup.setPopupMenuPosition(new PopupMenuPosition() { @Override public Point getPosition(Component c, Point mouseLocation) { return new Point(mouseLocation.x, mouseLocation.y); } }); }
From source file:de.fhg.igd.mapviewer.MapToolPainter.java
/** * @see MouseListener#mouseReleased(MouseEvent) *//*from w w w .j a v a 2 s .co m*/ @Override public void mouseReleased(MouseEvent me) { if (mapTool != null) { mapTool.mouseReleased(me, mapViewer.convertPointToGeoPosition(me.getPoint())); // reset cursor mapViewer.setCursor(mapTool.getCursor()); } }
From source file:peakmlviewer.dialog.timeseries.EditableChart.java
public void mouseDragged(MouseEvent event) { if (entity != null) { // calculate the new value Point curpoint = event.getPoint(); Rectangle2D plotrect = panel.getChartRenderingInfo().getPlotInfo().getPlotArea(); double value = (Double) dataset.getValue(entity.getRowKey(), entity.getColumnKey()); double newvalue = value - (curpoint.y - prevpoint.y) / plotrect.getHeight(); if (newvalue < 0) newvalue = 0;/*from w ww.j a va2s .c o m*/ else if (newvalue > 1) newvalue = 1; dataset.setValue(newvalue, entity.getRowKey(), entity.getColumnKey()); // set the prevpos to the curpos prevpoint = curpoint; } }
From source file:CheckBoxList.java
public CheckBoxList() { super();/*from w w w. java 2 s .com*/ setModel(new DefaultListModel()); setCellRenderer(new CheckboxCellRenderer()); addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { int index = locationToIndex(e.getPoint()); if (index != -1) { Object obj = getModel().getElementAt(index); if (obj instanceof JCheckBox) { JCheckBox checkbox = (JCheckBox) obj; checkbox.setSelected(!checkbox.isSelected()); repaint(); } } } } ); setSelectionMode(ListSelectionModel.SINGLE_SELECTION); }
From source file:org.kalypso.ogc.gml.widgets.base.PanToWidget.java
@Override public void mouseDragged(final MouseEvent e) { final IMapPanel mapPanel = getMapPanel(); if (mapPanel == null) return;/* w ww . ja va2s . c om*/ final Point point = e.getPoint(); if (m_world2screen != null && m_startPoint != null) { final GM_Position pixelPos = GeometryFactory.createGM_Position(point.getX(), point.getY()); m_endPoint = m_world2screen.getSourcePoint(pixelPos); final GM_Envelope panExtent = calcPanExtent(); mapPanel.setBoundingBox(panExtent, false, false); } }
From source file:it.unibas.spicygui.vista.listener.MyMouseEventListener.java
private void dispacciaEventoDrag(Component com, MouseEvent e, Point point, boolean draggedEvent) { Point componentPoint = SwingUtilities.convertPoint(component, e.getPoint(), com); if (com != null) { if (com instanceof JTree) { TreePath treePath = ((JTree) com).getPathForLocation(componentPoint.x, componentPoint.y); if (treePath == null || draggedEvent) { component.updateUI();/*from ww w .j ava 2 s . c o m*/ return; } } if ((!(com instanceof JScrollBar) && (tmp12 instanceof JScrollBar))) { jLayeredPane.moveToFront(component); component.updateUI(); return; } com.dispatchEvent(new MouseEvent(component, e.getID(), e.getWhen(), e.getModifiers(), componentPoint.x, componentPoint.y, e.getClickCount(), e.isPopupTrigger())); jLayeredPane.moveToFront(component); component.updateUI(); } jLayeredPane.moveToFront(component); component.updateUI(); }
From source file:org.broad.igv.ui.panel.PanTool.java
@Override public void mousePressed(final MouseEvent e) { if (e.isPopupTrigger()) { return;// ww w. jav a 2 s . c o m } lastMousePoint = e.getPoint(); cumulativeDeltaX = 0; cumulativeDeltaY = 0; }
From source file:JToggleButtonMenuItem.java
private void init() { updateUI();/* w ww . java 2 s . c o m*/ setRequestFocusEnabled(false); // Borrows heavily from BasicMenuUI MouseInputListener mouseInputListener = new MouseInputListener() { // If mouse released over this menu item, activate it public void mouseReleased(MouseEvent mouseEvent) { MenuSelectionManager menuSelectionManager = MenuSelectionManager.defaultManager(); Point point = mouseEvent.getPoint(); if ((point.x >= 0) && (point.x < getWidth()) && (point.y >= 0) && (point.y < getHeight())) { menuSelectionManager.clearSelectedPath(); // Component automatically handles "selection" at this point // doClick(0); // not necessary } else { menuSelectionManager.processMouseEvent(mouseEvent); } } // If mouse moves over menu item, add to selection path, so it becomes // armed public void mouseEntered(MouseEvent mouseEvent) { MenuSelectionManager menuSelectionManager = MenuSelectionManager.defaultManager(); menuSelectionManager.setSelectedPath(getPath()); } // When mouse moves away from menu item, disarm it and select something // else public void mouseExited(MouseEvent mouseEvent) { MenuSelectionManager menuSelectionManager = MenuSelectionManager.defaultManager(); MenuElement path[] = menuSelectionManager.getSelectedPath(); if (path.length > 1) { MenuElement newPath[] = new MenuElement[path.length - 1]; for (int i = 0, c = path.length - 1; i < c; i++) { newPath[i] = path[i]; } menuSelectionManager.setSelectedPath(newPath); } } // Pass along drag events public void mouseDragged(MouseEvent mouseEvent) { MenuSelectionManager.defaultManager().processMouseEvent(mouseEvent); } public void mouseClicked(MouseEvent mouseEvent) { } public void mousePressed(MouseEvent mouseEvent) { } public void mouseMoved(MouseEvent mouseEvent) { } }; addMouseListener(mouseInputListener); addMouseMotionListener(mouseInputListener); }
From source file:pcgen.gui2.converter.panel.CampaignPanel.java
/** * @see pcgen.gui2.converter.panel.ConvertSubPanel#setupDisplay(javax.swing.JPanel, pcgen.cdom.base.CDOMObject) *///from ww w .j a v a 2 s.c o m @Override public void setupDisplay(JPanel panel, final CDOMObject pc) { panel.setLayout(new GridBagLayout()); JLabel introLabel = new JLabel("Please select the Campaign(s) to Convert:"); GridBagConstraints gbc = new GridBagConstraints(); Utility.buildRelativeConstraints(gbc, GridBagConstraints.REMAINDER, 1, 1.0, 0, GridBagConstraints.HORIZONTAL, GridBagConstraints.NORTHWEST); gbc.insets = new Insets(25, 25, 5, 25); panel.add(introLabel, gbc); final CampaignTableModel model = new CampaignTableModel(gameModeCampaigns, folderName); final JTable table = new JTable(model) { //Implement table cell tool tips. @Override public String getToolTipText(MouseEvent e) { java.awt.Point p = e.getPoint(); int rowIndex = rowAtPoint(p); int colIndex = columnAtPoint(p); String tip = String.valueOf(getValueAt(rowIndex, colIndex)); return tip; } }; table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent event) { pc.removeListFor(ListKey.CAMPAIGN); int[] selRows = table.getSelectedRows(); if (selRows.length == 0) { saveSourceSelection(pc); fireProgressEvent(ProgressEvent.NOT_ALLOWED); } else { for (int row : selRows) { Campaign selCampaign = (Campaign) model.getValueAt(row, 0); pc.addToListFor(ListKey.CAMPAIGN, selCampaign); } saveSourceSelection(pc); fireProgressEvent(ProgressEvent.ALLOWED); } } }); JScrollPane listScroller = new JScrollPane(table); Utility.buildRelativeConstraints(gbc, GridBagConstraints.REMAINDER, GridBagConstraints.REMAINDER, 1.0, 1.0); gbc.fill = GridBagConstraints.BOTH; panel.add(listScroller, gbc); initSourceSelection(model, table); }