List of usage examples for java.awt.event MouseEvent getPoint
public Point getPoint()
From source file:op.care.sysfiles.PnlFiles.java
private void tblFilesMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblFilesMousePressed Point p = evt.getPoint(); ListSelectionModel lsm = tblFiles.getSelectionModel(); Point p2 = evt.getPoint();/*from w ww .j a v a2 s .co m*/ SwingUtilities.convertPointToScreen(p2, tblFiles); final Point screenposition = p2; boolean singleRowSelected = lsm.getMaxSelectionIndex() == lsm.getMinSelectionIndex(); final int row = tblFiles.rowAtPoint(p); final int col = tblFiles.columnAtPoint(p); if (singleRowSelected) { lsm.setSelectionInterval(row, row); } final TMSYSFiles tm = (TMSYSFiles) tblFiles.getModel(); final SYSFiles sysfile = tm.getRow(tblFiles.convertRowIndexToModel(row)); if (SwingUtilities.isRightMouseButton(evt)) { SYSTools.unregisterListeners(menu); menu = new JPopupMenu(); // SELECT JMenuItem itemPopupShow = new JMenuItem(SYSTools.xx("misc.commands.show"), SYSConst.icon22magnify1); itemPopupShow.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { SYSFilesTools.handleFile(sysfile, Desktop.Action.OPEN); } }); menu.add(itemPopupShow); if (col == TMSYSFiles.COL_DESCRIPTION && OPDE.getAppInfo().isAllowedTo(InternalClassACL.UPDATE, internalClassID)) { final JMenuItem itemPopupEdit = new JMenuItem(SYSTools.xx("misc.commands.edit"), SYSConst.icon22edit3); itemPopupEdit.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { final JidePopup popup = new JidePopup(); popup.setMovable(false); popup.getContentPane() .setLayout(new BoxLayout(popup.getContentPane(), BoxLayout.LINE_AXIS)); final JComponent editor = new JTextArea(sysfile.getBeschreibung(), 10, 40); ((JTextArea) editor).setLineWrap(true); ((JTextArea) editor).setWrapStyleWord(true); ((JTextArea) editor).setEditable(true); popup.getContentPane().add(new JScrollPane(editor)); final JButton saveButton = new JButton(SYSConst.icon22apply); saveButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); popup.hidePopup(); SYSFiles mySysfile = em.merge(sysfile); mySysfile.setBeschreibung(((JTextArea) editor).getText().trim()); em.getTransaction().commit(); tm.setSYSFile(tblFiles.convertRowIndexToModel(row), mySysfile); } catch (Exception e) { em.getTransaction().rollback(); OPDE.fatal(e); } finally { em.close(); } } }); saveButton.setHorizontalAlignment(SwingConstants.RIGHT); JPanel pnl = new JPanel(new BorderLayout(10, 10)); JScrollPane pnlEditor = new JScrollPane(editor); pnl.add(pnlEditor, BorderLayout.CENTER); JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS)); buttonPanel.add(saveButton); pnl.setBorder(new EmptyBorder(10, 10, 10, 10)); pnl.add(buttonPanel, BorderLayout.SOUTH); popup.setOwner(tblFiles); popup.removeExcludedComponent(tblFiles); popup.getContentPane().add(pnl); popup.setDefaultFocusComponent(editor); popup.showPopup(screenposition.x, screenposition.y); } }); menu.add(itemPopupEdit); } if (OPDE.getAppInfo().isAllowedTo(InternalClassACL.DELETE, internalClassID)) { JMenuItem itemPopupDelete = new JMenuItem(SYSTools.xx("misc.commands.delete"), SYSConst.icon22delete); itemPopupDelete.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { new DlgYesNo( SYSTools.xx("misc.questions.delete1") + "<br/><b>" + sysfile.getFilename() + "</b><br/>" + SYSTools.xx("misc.questions.delete2"), new ImageIcon(getClass().getResource("/artwork/48x48/bw/trashcan_empty.png")), new Closure() { @Override public void execute(Object o) { if (o.equals(JOptionPane.YES_OPTION)) { SYSFilesTools.deleteFile(sysfile); reloadTable(); } } }); } }); menu.add(itemPopupDelete); itemPopupDelete.setEnabled(singleRowSelected); } menu.show(evt.getComponent(), (int) p.getX(), (int) p.getY()); } else if (evt.getClickCount() == 2) { SYSFilesTools.handleFile(sysfile, Desktop.Action.OPEN); } }
From source file:com.nbt.TileCanvas.java
public TileCanvas(final World world) { Validate.notNull(world, "world must not be null"); this.world = world; setFocusable(true);//from ww w . j a va 2s .c om addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { int tileWidth = calculateWidth(); setTileWidth(tileWidth); int tileHeight = calculateHeight(); setTileHeight(tileHeight); save(); } }); addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { TileCanvas.this.keyPressed(e); } }); addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { Point point = e.getPoint(); int x = pixelsToTile(point.x); int z = pixelsToTile(point.y); int tileX = x + getTileX(); int tileZ = z + getTileZ(); int y = getAltitude(); Block block = world.getBlock(tileX, y, tileZ); blockClicked(block); } }); addMouseWheelListener(new MouseWheelListener() { @Override public void mouseWheelMoved(MouseWheelEvent e) { int amount = e.getWheelRotation(); int altitude = getAltitude(); setAltitude(amount + altitude); updateXYZ(); doRepaint(); save(); } }); addMouseMotionListener(new MouseMotionAdapter() { @Override public void mouseMoved(MouseEvent e) { updateXYZ(); } }); new MouseDragAndDrop(this) { private int tileX, tileZ; @Override public void selected(MouseEvent e) { this.tileX = getTileX(); this.tileZ = getTileZ(); } @Override public void dragged(MouseEvent e) { MouseEvent startEvent = getStartEvent(); Point startPt = startEvent.getPoint(); Point releasePt = e.getPoint(); int x = tileX + (pixelsToTile(startPt.x) - pixelsToTile(releasePt.x)); int z = tileZ + (pixelsToTile(startPt.y) - pixelsToTile(releasePt.y)); setTileX(x); setTileZ(z); updateXYZ(); doRepaint(); } @Override public void dropped(MouseEvent press, MouseEvent release) { // Point startPt = press.getPoint(); // Point releasePt = release.getPoint(); // int x = getTileX() + pixelsToTile(startPt.x - releasePt.x); // int z = getTileZ() + pixelsToTile(startPt.y - releasePt.y); // setTileX(x); // setTileZ(z); // // updateXYZ(); // doRepaint(); save(); } }.install(); setLayout(null); hud = new HUD(); int width = 200, height = 200; hud.setSize(width, height); add(hud); }
From source file:pipeline.GUI_utils.JXTablePerColumnFiltering.java
@Override //Adapted from http://stackoverflow.com/questions/27102546/show-tooltips-in-jtable-only-when-column-is-cut-off public String getToolTipText(MouseEvent e) { Point p = e.getPoint(); int col = columnAtPoint(p); int row = rowAtPoint(p); if (row == -1 || col == -1) { return null; }//from w w w . ja va 2 s. c o m Rectangle bounds = getCellRect(row, col, false); Object value = getValueAt(row, col); Component comp = prepareRenderer(getCellRenderer(row, col), row, col); if (comp.getPreferredSize().width > bounds.width) { return (value.toString()); } else { return null; } }
From source file:org.jax.maanova.fit.gui.ResidualPlotPanel.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 nearestDistance = Double.POSITIVE_INFINITY; int nearestArrayIndex = -1; int nearestDotIndex = -1; for (int arrayIndex = 0; arrayIndex < xyProbeData.length; arrayIndex++) { double[] currXData = xyProbeData[arrayIndex].getXData(); double[] currYData = xyProbeData[arrayIndex].getYData(); for (int dotIndex = 0; dotIndex < currXData.length; dotIndex++) { double currDist = chartPoint.distanceSq(currXData[dotIndex], currYData[dotIndex]); if (currDist < nearestDistance) { nearestDistance = currDist; nearestArrayIndex = arrayIndex; nearestDotIndex = dotIndex; }/*from w w w. j a v a 2 s . c o m*/ } } if (nearestArrayIndex == -1) { this.clearProbePopup(); } else { XYProbeData nearestArrayData = xyProbeData[nearestArrayIndex]; Point2D probeJava2DCoord = this.getJava2DCoordinates(nearestArrayData.getXData()[nearestDotIndex], nearestArrayData.getYData()[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(nearestArrayIndex, nearestArrayData.getProbeIndices()[nearestDotIndex], nearestArrayData.getXData()[nearestDotIndex], nearestArrayData.getYData()[nearestDotIndex], e.getX(), e.getY()); } else { this.clearProbePopup(); } } } }
From source file:org.jax.maanova.madata.gui.ArrayScatterPlotPanel.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 nearestDistance = Double.POSITIVE_INFINITY; int nearestDotIndex = -1; double[] xData = xyProbeData.getXData(); double[] yData = xyProbeData.getYData(); for (int dotIndex = 0; dotIndex < xData.length; dotIndex++) { double currDist = chartPoint.distanceSq(xData[dotIndex], yData[dotIndex]); if (currDist < nearestDistance) { nearestDistance = currDist; nearestDotIndex = dotIndex; }//from w w w.ja v a 2 s. c o m } if (nearestDotIndex == -1) { this.clearProbePopup(); } else { Point2D probeJava2DCoord = this.getJava2DCoordinates(xData[nearestDotIndex], yData[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], xData[nearestDotIndex], yData[nearestDotIndex], e.getX(), e.getY()); } else { this.clearProbePopup(); } } } }
From source file:in.co.itasca.geu.Main.java
private void jTable2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable2MouseClicked // TODO add your handling code here: int row = jTable2.rowAtPoint(evt.getPoint()); String value = (String) jTable2.getValueAt(row, 0); PopularityGraphDM gt = (PopularityGraphDM) searchedPopularName.get(value); GraphData[] array = gt.getAsArray(); PieDataset dataset = createDataset(array); // based on the dataset we create the chart JFreeChart chart = createChart(dataset, "Name Popularity of " + value); ChartPanel chartPanel = new ChartPanel(chart); jTabbedPane1.add(chartPanel, value); }
From source file:net.sf.jabref.gui.maintable.MainTableSelectionListener.java
/** * Process general right-click events on the table. Show the table context menu at * the position where the user right-clicked. * @param e The mouse event defining the popup trigger. * @param row The row where the event occurred. *//*ww w . j a v a2 s . com*/ private void processPopupTrigger(MouseEvent e, int row) { int selRow = table.getSelectedRow(); if ((selRow == -1) || !table.isRowSelected(table.rowAtPoint(e.getPoint()))) { table.setRowSelectionInterval(row, row); } RightClickMenu rightClickMenu = new RightClickMenu(JabRefGUI.getMainFrame(), panel); rightClickMenu.show(table, e.getX(), e.getY()); }
From source file:net.sf.jabref.gui.maintable.MainTableSelectionListener.java
@Override public void mouseReleased(MouseEvent e) { // First find the column and row on which the user has clicked. final int col = table.columnAtPoint(e.getPoint()); final int row = table.rowAtPoint(e.getPoint()); // get the MainTableColumn which is currently visible at col int modelIndex = table.getColumnModel().getColumn(col).getModelIndex(); MainTableColumn modelColumn = table.getMainTableColumn(modelIndex); // Check if the user has right-clicked. If so, open the right-click menu. if (e.isPopupTrigger() || (e.getButton() == MouseEvent.BUTTON3)) { if ((modelColumn == null) || !modelColumn.isIconColumn()) { // show normal right click menu processPopupTrigger(e, row); } else {/*from w w w .j ava 2 s . c o m*/ // show right click menu for icon columns showIconRightClickMenu(e, row, modelColumn); } } }
From source file:VentanaPrincipal.java
private void listFicherosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_listFicherosMouseClicked if (evt.getClickCount() == 2) { String aux = listFicheros.getComponentAt(evt.getPoint()).toString(); String nom = aux.substring(aux.lastIndexOf("=") + 1, aux.lastIndexOf("-")); try {/*ww w. j a v a2s.c o m*/ cliente.changeWorkingDirectory(nom); lblRuta.setText(cliente.printWorkingDirectory()); listFicheros.removeAll(); FTPFile[] files = cliente.listFiles(); String tipos[] = { "Fichero", "Directorio", "Enlace simb." }; for (int i = 0; i < files.length; i++) { listFicheros.add(files[i].getName() + "- " + tipos[files[i].getType()]); } } catch (IOException ex) { Logger.getLogger(VentanaPrincipal.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:org.broad.igv.ui.panel.PanTool.java
@Override final public void mouseDragged(final MouseEvent e) { long currentTime = System.currentTimeMillis(); if ((currentTime - lastDragEventTime) < throttleTimeMS) { return;//from w ww . j a v a2 s . co m } //System.out.println("T=" + ctr); lastDragEventTime = currentTime; try { Component panel = (Component) e.getSource(); panel.setCursor(dragCursor); if (lastMousePoint == null) { lastMousePoint = e.getPoint(); return; } if (!isDragging && e.getPoint().distance(lastMousePoint) < 2) { return; } else { isDragging = true; int deltaX = lastMousePoint.x - e.getX(); int deltaY = lastMousePoint.y - e.getY(); cumulativeDeltaX += Math.abs(deltaX); cumulativeDeltaY += Math.abs(deltaY); // Test for horizontal vs vertical panning. if (cumulativeDeltaX > cumulativeDeltaY) { // Horizontal scrolling getReferenceFame().shiftOriginPixels(deltaX); } else { // Vertical Scrolling int totalYChange = (int) (lastMousePoint.getY() - e.getY()); if (totalYChange != 0) { // This section handles false drag direction changes int currentYDirection = 0; // Figure out the current drag direction currentYDirection = totalYChange / Math.abs(totalYChange); // If the previous direction is 0 we were not moving before if (previousYDirection != 0) { // See if we changed direction boolean changedYDirection = currentYDirection != previousYDirection; if (!changedYDirection) { // Don't save lastMousePressedPoint because may // be incorrect (this is the problem we are // solving with the direction flag) instead // we'll just check the next drag Point to be // sure of the correct direction. previousYDirection = currentYDirection; // If we have a vertical scrollbar use it to move if (verticalScrollBar != null) { int adjustedScrollbarValue = verticalScrollBar.getValue(); adjustedScrollbarValue += totalYChange; verticalScrollBar.setValue(adjustedScrollbarValue); } } } previousYDirection = currentYDirection; } } } } finally { lastMousePoint = e.getPoint(); // Always save the last Point } }