List of usage examples for java.awt.event MouseEvent getPoint
public Point getPoint()
From source file:org.isatools.isacreator.spreadsheet.Spreadsheet.java
public void mouseReleased(MouseEvent event) { if (SwingUtilities.isLeftMouseButton(event) && (table.rowAtPoint(event.getPoint()) - startRow) > 1) { SwingUtilities.convertPointFromScreen(event.getPoint(), table); spreadsheetPopups.dragCellPopupMenu(table, event.getX(), event.getY()); }/*from w w w . j a v a2 s . c om*/ }
From source file:org.gumtree.vis.plot1d.Plot1DPanel.java
private void makeNewMask(MouseEvent e) { Point2D screenPoint = translateScreenToJava2D(e.getPoint()); if (Double.isNaN(maskPoint) || Math.abs(screenPoint.getX() - maskPoint) < minMaskWidth) { return;/*from www .ja v a 2 s . co m*/ } Graphics2D g2 = (Graphics2D) getGraphics(); // erase the previous zoom rectangle (if any). We only need to do // this is we are using XOR mode, which we do when we're not using // the buffer (if there is a buffer, then at the end of this method we // just trigger a repaint) if (!isDoubleBuffered()) { // drawZoomRectangle(g2, true); ChartMaskingUtilities.drawMasks(g2, getScreenDataArea(), getMaskMap(), getSelectedMask(), getChart()); } // boolean hZoom = false; // boolean vZoom = false; // if (this.orientation == PlotOrientation.HORIZONTAL) { // hZoom = this.rangeZoomable; // vZoom = this.domainZoomable; // } // else { // hZoom = this.domainZoomable; // vZoom = this.rangeZoomable; // } Rectangle2D scaledDataArea = getScreenDataArea(); // (int) this.maskPoint.getX(), (int) this.maskPoint.getY()); // Working on the current mask. Only create one new mask per drag-drawing. if (currentMaskRectangle == null) { boolean isInclusive = (e.getModifiers() & maskingExclusiveMask) == 0; currentMaskRectangle = new RangeMask(isInclusive); // currentMaskRectangle.setFillColor(getNextMaskColor(isInclusive)); // getMasks().add(currentMaskRectangle); addMask(currentMaskRectangle); } // selected rectangle shouldn't extend outside the data area... double xmax = Math.min(e.getX(), scaledDataArea.getMaxX()); // Update the current mask. Insets insets = getInsets(); double startX = ChartMaskingUtilities.translateScreenX((maskPoint - insets.left) / getScaleX(), getScreenDataArea(), getChart()); double endX = ChartMaskingUtilities.translateScreenX((xmax - insets.left) / getScaleX(), getScreenDataArea(), getChart()); updateCurrentDomainMask(startX, endX); // Draw the new zoom rectangle... if (isDoubleBuffered()) { repaint(); } else { // with no buffer, we use XOR to draw the rectangle "over" the // chart... ChartMaskingUtilities.drawMasks(g2, getScreenDataArea(), getMaskMap(), getSelectedMask(), getChart()); } g2.dispose(); }
From source file:org.gumtree.vis.plot1d.Plot1DPanel.java
private void changeSelectedMask(MouseEvent e) { // TODO Auto-generated method stub Point2D screenPoint = translateScreenToJava2D(e.getPoint()); //TODO: resize the mask Rectangle2D screenArea = getScreenDataArea(); if (screenArea.contains(screenPoint)) { // Point2D chartPoint = translateScreenToChart(screenPoint); changeSelectedMask(/*ww w .java 2s . c o m*/ ChartMaskingUtilities.translateScreenX(screenPoint.getX(), getScreenDataArea(), getChart())); repaint(); } }
From source file:org.gumtree.vis.hist2d.Hist2DPanel.java
private void changeSelectedMask(MouseEvent e, EntityCollection entities) { // Do masking service // if no initial masking point was set, ignore dragging... Rectangle2D screenArea = getScreenDataArea(); Point2D screenPoint = translateScreenToJava2D(e.getPoint()); // System.out.println("screen point is [" + screenPoint.getX() + ", " + // screenPoint.getY() + "]"); if (screenArea.contains(screenPoint)) { Point2D chartPoint = translateScreenToChart(screenPoint); if (chartPoint != null) { // System.out.println("chart point is [" + chartPoint.getX() + ", " + // chartPoint.getY() + "]"); changeSelectedMask(chartPoint); repaint();//from w w w .j av a 2 s . c o m } } }
From source file:org.gumtree.vis.plot1d.Plot1DPanel.java
private void changeInternalLegend(MouseEvent e) { // TODO Auto-generated method stub Point2D screenPoint = translateScreenToJava2D(e.getPoint()); //TODO: resize the mask Rectangle2D screenArea = getScreenDataArea(); if (screenArea.contains(screenPoint)) { // Point2D chartPoint = translateScreenToChart(screenPoint); // changeSelectedMask(ChartMaskingUtilities.translateScreenX( // screenPoint.getX(), getScreenDataArea(), getChart())); int cursorType = findCursorOnSelectedItem(e.getX(), e.getY()); switch (cursorType) { case Cursor.MOVE_CURSOR: moveLegend(e.getPoint());//from w w w. jav a2 s . c o m break; case Cursor.W_RESIZE_CURSOR: changeLegendX(e.getPoint()); break; case Cursor.E_RESIZE_CURSOR: changeLegendWidth(e.getPoint()); break; default: break; } repaint(); } }
From source file:edmondskarp.Gui.EdmondsKarpGui.java
private void myPanelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_myPanelMouseClicked if (evt.getButton() == MouseEvent.BUTTON1) { if (MODE == ERASE) { eraseShape(evt.getPoint()); } else if (MODE == DRAW) { if (isSecond) { Circle circ = getSelectedCircle(evt.getPoint()); if (circ != null && circ != shapeTmp) { addArrow(circ);/*from ww w .j a v a 2 s.c om*/ shapeTmp.setSelect(false); isSecond = false; update(); return; } } else { Circle circ = getSelectedCircle(evt.getPoint()); if (circ != null) { shapeTmp = circ; shapeTmp.setSelect(true); isSecond = true; update(); return; } } if (getSelectedCircle(evt.getPoint()) == null && !isSecond) { addCircle(evt.getPoint()); } else { isSecond = false; shapeTmp.setSelect(false); update(); } } } else if (evt.getButton() == MouseEvent.BUTTON3) { if (getSelectedCircle(evt.getPoint()) != null) { pointTmp.setLocation(evt.getPoint().getX(), evt.getPoint().getY()); jPopupMenu1.show(myPanel, evt.getX(), evt.getY()); } else if (getSelectedArrow(evt.getPoint()) != null) { pointTmp.setLocation(evt.getPoint().getX(), evt.getPoint().getY()); jPopupMenu2.show(myPanel, evt.getX(), evt.getY()); } } }
From source file:com.igormaznitsa.jhexed.swing.editor.ui.MainForm.java
@Override public void mouseDragged(final MouseEvent e) { if (SwingUtilities.isLeftMouseButton(e)) { final HexPosition hexNumber = this.hexMapPanel.getHexPosition(e.getPoint()); useCurrentToolAtPosition(hexNumber); } else if (this.dragging) { this.hexMapPanelDesktop.processDrag(e.getPoint()); }/* ww w . ja v a2 s . c o m*/ }
From source file:net.java.sip.communicator.impl.gui.main.chat.ChatConversationPanel.java
/** * When a right button click is performed in the editor pane, a popup menu * is opened.// ww w . jav a 2s.c o m * In case of the Scheme being internal, it won't open the Browser but * instead it will trigger the forwarded action. * * @param e The MouseEvent. */ public void mouseClicked(MouseEvent e) { Point p = e.getPoint(); SwingUtilities.convertPointToScreen(p, e.getComponent()); if ((e.getModifiers() & InputEvent.BUTTON3_MASK) != 0 || (e.isControlDown() && !e.isMetaDown())) { openContextMenu(p); } else if ((e.getModifiers() & InputEvent.BUTTON1_MASK) != 0 && currentHref != null && currentHref.length() != 0) { URI uri; try { uri = new URI(currentHref); } catch (URISyntaxException e1) { logger.error( "Failed to open hyperlink in chat window. " + "Error was: Invalid URL - " + currentHref); return; } if ("jitsi".equals(uri.getScheme())) { for (ChatLinkClickedListener l : chatLinkClickedListeners) { l.chatLinkClicked(uri); } } else GuiActivator.getBrowserLauncher().openURL(currentHref); // after opening the link remove the currentHref to avoid // clicking on the window to gain focus to open the link again this.currentHref = ""; } }
From source file:org.accada.hal.impl.sim.multi.GraphicSimulatorServer.java
/** * creates the layered pane if it does not already exists * /*from w ww . ja va 2s.c om*/ * @return layered pane */ private JLayeredPane getJLayeredPane() { if (jLayeredPane == null) { jLayeredPane = new JLayeredPane(); jLayeredPane.setLayout(null); jLayeredPane.setOpaque(true); jLayeredPane.setBackground(Color.WHITE); //jLayeredPane.add(getReader(), new Integer(0)); // add readers createReaders(controller.getReaderIds()); // add context menu jLayeredPane.add(getContextMenu()); // add mouse listener jLayeredPane.addMouseListener(new MouseAdapter() { // context menu public void mouseReleased(MouseEvent e) { hideActiveContextMenuAndSelection(); if (e.getButton() == MouseEvent.BUTTON3) { Point posOnScreen = getJLayeredPane().getLocationOnScreen(); contextMenu.setLocation(posOnScreen.x + e.getX(), posOnScreen.y + e.getY()); contextMenu.setVisible(true); setActiveContextMenu(contextMenu); } else { contextMenu.setVisible(false); if (e.getButton() == MouseEvent.BUTTON1) { selection.select(tags); } } } // selection public void mousePressed(final MouseEvent e) { hideActiveContextMenuAndSelection(); if (e.getButton() == MouseEvent.BUTTON1) { selection.setBounds(0, 0, getProperty("WindowWidth"), getProperty("WindowHeight")); selection.setStartPoint(e.getPoint()); jLayeredPane.add(selection, new Integer(2)); } } }); // add drag listener jLayeredPane.addMouseMotionListener(new MouseMotionAdapter() { public void mouseDragged(MouseEvent e) { if (selection.isActive()) { selection.setCurrentPoint(e.getPoint()); } } }); } return jLayeredPane; }
From source file:display.containers.FileManager.java
public Container getPane() { //if (gui==null) { fileSystemView = FileSystemView.getFileSystemView(); desktop = Desktop.getDesktop(); JPanel detailView = new JPanel(new BorderLayout(3, 3)); //fileTableModel = new FileTableModel(); table = new JTable(); table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); table.setAutoCreateRowSorter(true);/*from w ww .j a va 2s . co m*/ table.setShowVerticalLines(false); table.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { if (e.getClickCount() >= 2) { Point p = e.getPoint(); int row = table.convertRowIndexToModel(table.rowAtPoint(p)); int column = table.convertColumnIndexToModel(table.columnAtPoint(p)); if (row >= 0 && column >= 0) { mouseDblClicked(row, column); } } } }); table.addKeyListener(new KeyListener() { @Override public void keyTyped(KeyEvent arg0) { } @Override public void keyReleased(KeyEvent arg0) { if (KeyEvent.VK_DELETE == arg0.getKeyCode()) { if (mode != 2) { parentFrame.setLock(true); parentFrame.getProgressBarPanel().setVisible(true); Thread t = new Thread(new Runnable() { @Override public void run() { try { deleteSelectedFiles(); } catch (IOException e) { JOptionPane.showMessageDialog(parentFrame, "Error during the deletion.", "Deletion error", JOptionPane.ERROR_MESSAGE); WindowManager.mwLogger.log(Level.SEVERE, "Error during the deletion.", e); } finally { parentFrame.setLock(false); refresh(); parentFrame.getProgressBarPanel().setVisible(false); } } }); t.start(); } else { if (UserProfile.CURRENT_USER.getLevel() == 3) { parentFrame.setLock(true); parentFrame.getProgressBarPanel().setVisible(true); Thread delThread = new Thread(new Runnable() { @Override public void run() { int[] rows = table.getSelectedRows(); int[] columns = table.getSelectedColumns(); for (int i = 0; i < rows.length; i++) { if (!continueAction) { continueAction = true; return; } int row = table.convertRowIndexToModel(rows[i]); try { deleteServerFile(row); } catch (Exception e) { WindowManager.mwLogger.log(Level.SEVERE, "Error during the deletion.", e); } } refresh(); parentFrame.setLock(false); parentFrame.getProgressBarPanel().setVisible(false); } }); delThread.start(); } } } } @Override public void keyPressed(KeyEvent arg0) { // TODO Auto-generated method stub } }); table.getSelectionModel().addListSelectionListener(listSelectionListener); JScrollPane tableScroll = new JScrollPane(table); Dimension d = tableScroll.getPreferredSize(); tableScroll.setPreferredSize(new Dimension((int) d.getWidth(), (int) d.getHeight() / 2)); detailView.add(tableScroll, BorderLayout.CENTER); // the File tree DefaultMutableTreeNode root = new DefaultMutableTreeNode(); treeModel = new DefaultTreeModel(root); table.getRowSorter().addRowSorterListener(new RowSorterListener() { @Override public void sorterChanged(RowSorterEvent e) { ((FileTableModel) table.getModel()).fireTableDataChanged(); } }); // show the file system roots. File[] roots = fileSystemView.getRoots(); for (File fileSystemRoot : roots) { DefaultMutableTreeNode node = new DefaultMutableTreeNode(fileSystemRoot); root.add(node); //showChildren(node); // File[] files = fileSystemView.getFiles(fileSystemRoot, true); for (File file : files) { if (file.isDirectory()) { node.add(new DefaultMutableTreeNode(file)); } } // } JScrollPane treeScroll = new JScrollPane(); Dimension preferredSize = treeScroll.getPreferredSize(); Dimension widePreferred = new Dimension(200, (int) preferredSize.getHeight()); treeScroll.setPreferredSize(widePreferred); JPanel fileView = new JPanel(new BorderLayout(3, 3)); detailView.add(fileView, BorderLayout.SOUTH); JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, treeScroll, detailView); JPanel simpleOutput = new JPanel(new BorderLayout(3, 3)); progressBar = new JProgressBar(); simpleOutput.add(progressBar, BorderLayout.EAST); progressBar.setVisible(false); showChildren(getCurrentDir().toPath()); //table.setDragEnabled(true); table.setColumnSelectionAllowed(false); // Menu popup Pmenu = new JPopupMenu(); changeProjectitem = new JMenuItem("Reassign"); renameProjectitem = new JMenuItem("Rename"); twitem = new JMenuItem("To workspace"); tlitem = new JMenuItem("To local"); processitem = new JMenuItem("Select for process"); switch (mode) { case 0: Pmenu.add(twitem); twitem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { parentFrame.getBtnlocalTowork().doClick(); } }); break; case 1: Pmenu.add(tlitem); Pmenu.add(processitem); tlitem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { parentFrame.getBtnWorkTolocal().doClick(); } }); processitem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { SwingUtilities.invokeLater(new Runnable() { public void run() { // Recupere les lignes selectionnees int[] indices = table.getSelectedRows(); // On recupere les fichiers correspondants ArrayList<File> files = new ArrayList<File>(); for (int i = 0; i < indices.length; i++) { int row = table.convertRowIndexToModel(indices[i]); File fi = ((FileTableModel) table.getModel()).getFile(row); if (fi.isDirectory()) files.add(fi); } ImageProcessingFrame imf = new ImageProcessingFrame(files); } }); } }); break; case 2: if (UserProfile.CURRENT_USER.getLevel() == 3) { Pmenu.add(changeProjectitem); Pmenu.add(renameProjectitem); } Pmenu.add(twitem); twitem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { parentFrame.getBtndistToWorkspace().doClick(); } }); Pmenu.add(tlitem); tlitem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { parentFrame.getBtndistToLocal().doClick(); } }); break; } changeProjectitem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { table.setEnabled(false); File from = ((FileTableModel) table.getModel()) .getFile(table.convertRowIndexToModel(table.getSelectedRows()[0])); ReassignProjectPanel reas = new ReassignProjectPanel(from.toPath()); // mode creation de liens Popup popup = PopupFactory.getSharedInstance().getPopup(WindowManager.MAINWINDOW, reas, (int) WindowManager.MAINWINDOW.getX() + 200, (int) WindowManager.MAINWINDOW.getY() + 150); reas.setPopupWindow(popup); popup.show(); table.setEnabled(true); } }); renameProjectitem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { table.setEnabled(false); final File from = ((FileTableModel) table.getModel()) .getFile(table.convertRowIndexToModel(table.getSelectedRows()[0])); JDialog.setDefaultLookAndFeelDecorated(true); String s = (String) JOptionPane.showInputDialog(WindowManager.MAINWINDOW, "New project name ?", "Rename project", JOptionPane.PLAIN_MESSAGE, null, null, from.getName()); //If a string was returned, say so. if ((s != null) && (s.length() > 0)) { ProjectDAO pdao = new MySQLProjectDAO(); if (new File(from.getParent() + File.separator + s).exists()) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JDialog.setDefaultLookAndFeelDecorated(true); JOptionPane.showMessageDialog(WindowManager.MAINWINDOW, "Couldn't rename " + from.getName() + " (A file with this filename already exists)", "Renaming error", JOptionPane.ERROR_MESSAGE); } }); WindowManager.mwLogger.log(Level.SEVERE, "Error during file project renaming (" + from.getName() + "). [Duplication error]"); } else { try { boolean succeed = pdao.renameProject(from.getName(), s); if (!succeed) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JDialog.setDefaultLookAndFeelDecorated(true); JOptionPane.showMessageDialog(WindowManager.MAINWINDOW, "Couldn't rename " + from.getName() + " (no project with this name)", "Renaming error", JOptionPane.ERROR_MESSAGE); } }); } else { from.renameTo(new File(from.getParent() + File.separator + s)); // on renomme le repertoire nifti ou dicom correspondant si il existe switch (from.getParentFile().getName()) { case ServerInfo.NRI_ANALYSE_NAME: if (new File(from.getAbsolutePath().replaceAll(ServerInfo.NRI_ANALYSE_NAME, ServerInfo.NRI_DICOM_NAME)).exists()) try { Files.move(Paths.get(from.getAbsolutePath().replaceAll( ServerInfo.NRI_ANALYSE_NAME, ServerInfo.NRI_DICOM_NAME)), Paths.get(from.getParent().replaceAll( ServerInfo.NRI_ANALYSE_NAME, ServerInfo.NRI_DICOM_NAME) + File.separator + s)); } catch (IOException e) { e.printStackTrace(); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JDialog.setDefaultLookAndFeelDecorated(true); JOptionPane.showMessageDialog(WindowManager.MAINWINDOW, "Couldn't rename " + from.getName() + " (error with file system)", "Renaming error", JOptionPane.ERROR_MESSAGE); } }); WindowManager.mwLogger.log(Level.SEVERE, "Error during file project renaming (" + from.getName() + ")", e); } //from.renameTo(new File(from.getParent().replaceAll(ServerInfo.NRI_ANALYSE_NAME, ServerInfo.NRI_DICOM_NAME)+File.separator+s)); break; case ServerInfo.NRI_DICOM_NAME: if (new File(from.getAbsolutePath().replaceAll(ServerInfo.NRI_DICOM_NAME, ServerInfo.NRI_ANALYSE_NAME)).exists()) try { Files.move(Paths.get(from.getAbsolutePath().replaceAll( ServerInfo.NRI_DICOM_NAME, ServerInfo.NRI_ANALYSE_NAME)), Paths.get(from.getParent().replaceAll(ServerInfo.NRI_DICOM_NAME, ServerInfo.NRI_ANALYSE_NAME) + File.separator + s)); } catch (IOException e) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JDialog.setDefaultLookAndFeelDecorated(true); JOptionPane.showMessageDialog(WindowManager.MAINWINDOW, "Couldn't rename " + from.getName() + " (error with file system)", "Renaming error", JOptionPane.ERROR_MESSAGE); } }); e.printStackTrace(); WindowManager.mwLogger.log(Level.SEVERE, "Error during file project renaming (" + from.getName() + ")", e); } //from.renameTo(new File(from.getParent().replaceAll(ServerInfo.NRI_DICOM_NAME, ServerInfo.NRI_ANALYSE_NAME)+File.separator+s)); break; } refresh(); } } catch (final SQLException e) { WindowManager.mwLogger.log(Level.SEVERE, "Error during SQL project renaming", e); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JDialog.setDefaultLookAndFeelDecorated(true); JOptionPane.showMessageDialog(WindowManager.MAINWINDOW, "Exception : " + e.toString(), "Openning error", JOptionPane.ERROR_MESSAGE); } }); } } } table.setEnabled(true); } }); table.addMouseListener(new MouseListener() { public void mouseClicked(MouseEvent me) { } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void mousePressed(MouseEvent e) { } public void mouseReleased(MouseEvent me) { if (me.getButton() == 3 && table.getSelectedRowCount() > 0) { int row = table.convertRowIndexToModel(table.rowAtPoint(me.getPoint())); changeProjectitem.setVisible(isPatient(((FileTableModel) table.getModel()).getFile(row))); renameProjectitem.setVisible(isProject(((FileTableModel) table.getModel()).getFile(row))); Pmenu.show(me.getComponent(), me.getX(), me.getY()); } } }); // //} return tableScroll; }