List of usage examples for java.awt.event MouseEvent getPoint
public Point getPoint()
From source file:latexstudio.editor.DropboxRevisionsTopComponent.java
private void jTable1MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MousePressed if (evt.getClickCount() == 2) { // Resolving which row has been double-clicked Point point = evt.getPoint(); JTable table = (JTable) evt.getSource(); int row = table.rowAtPoint(point); // Finding revision using information from the clicked row Object revisionNumber = table.getValueAt(row, REVISION_COLUMN); if (revisionNumber != null) { loadRevision(revisionNumber.toString()); }/*from w ww. j av a 2 s . c o m*/ } }
From source file:qic.ui.ManualPanel.java
@SuppressWarnings("serial") public ManualPanel(Main main) { super(new BorderLayout(5, 5)); table.setDoubleBuffered(true);/* w w w . j a v a 2 s. c o m*/ JTextField searchTf = new JTextField(100); JButton runBtn = new JButton("Run"); runBtn.setPreferredSize(new Dimension(200, 10)); JLabel invalidTermsLblLbl = new JLabel(); invalidTermsLblLbl.setFont(invalidTermsLblLbl.getFont().deriveFont(Font.BOLD)); JLabel invalidTermsLbl = new JLabel(); invalidTermsLbl.setForeground(Color.RED); JPanel northPanel = new JPanel(); northPanel.setLayout(new BoxLayout(northPanel, BoxLayout.X_AXIS)); JLabel searchLbl = new JLabel(" Search: "); searchLbl.setFont(searchLbl.getFont().deriveFont(Font.BOLD)); northPanel.add(searchLbl); northPanel.add(searchTf); northPanel.add(invalidTermsLblLbl); northPanel.add(invalidTermsLbl); northPanel.add(runBtn); this.add(northPanel, BorderLayout.NORTH); List<String> searchList = Util.loadSearchList(MANUAL_TXT_FILENAME); searchList.stream().forEach(searchJListModel::addElement); searchJList.setModel(searchJListModel); searchJList.addListSelectionListener(e -> { if (e.getValueIsAdjusting()) { searchTf.setText(trimToEmpty(searchJList.getSelectedValue())); } }); searchJList.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { if (evt.getClickCount() == 2) { int index = searchJList.locationToIndex(evt.getPoint()); if (index != -1) { String search = trimToEmpty(searchJListModel.getElementAt(index)); searchTf.setText(search); runBtn.doClick(); } } } }); searchJList.getInputMap().put(KeyStroke.getKeyStroke("DELETE"), "doSomething"); searchJList.getActionMap().put("doSomething", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { int selectedIndex = searchJList.getSelectedIndex(); if (selectedIndex != -1) { searchJListModel.remove(selectedIndex); } } }); ActionListener runCommand = e -> { String tfText = searchTf.getText().trim(); if (!tfText.isEmpty()) { Worker<Command> worker = new Worker<Command>(() -> { runBtn.setEnabled(false); Command result = null; try { result = runQuery(main, tfText); } catch (Exception ex) { runBtn.setEnabled(true); SwingUtil.showError(ex); } return result; }, command -> { if (command != null) { if (command.invalidSearchTerms.isEmpty()) { addDataToTable(command); saveSearchToList(tfText); invalidTermsLbl.setText(""); invalidTermsLblLbl.setText(""); if (getBooleanProperty(MANUAL_AUTO_VERIFY, false)) { long sleep = Config.getLongProperty(Config.MANUAL_AUTO_VERIFY_SLEEP, 5000); table.runAutoVerify(sleep); } } else { String invalidTermsStr = command.invalidSearchTerms.stream().collect(joining(", ")); invalidTermsLbl.setText(invalidTermsStr + " "); invalidTermsLblLbl.setText(" Invalid: "); } } runBtn.setEnabled(true); }); worker.execute(); } }; searchTf.addActionListener(runCommand); runBtn.addActionListener(runCommand); splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(table), new JScrollPane(searchJList)); this.add(splitPane, BorderLayout.CENTER); }
From source file:Simulator.java
private void AddMouseListeners() { map().addMouseListener(new MouseAdapter() { @Override//w w w .ja v a 2 s.c o m public void mouseClicked(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { map().getAttribution().handleAttribution(e.getPoint(), true); } } }); map().addMouseMotionListener(new MouseAdapter() { @Override public void mouseMoved(MouseEvent e) { Point p = e.getPoint(); boolean cursorHand = map().getAttribution().handleAttributionCursor(p); if (cursorHand) { map().setCursor(new Cursor(Cursor.HAND_CURSOR)); } else { map().setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); } } }); }
From source file:uk.co.modularaudio.util.swing.dndtable.layeredpane.LayeredPaneDndTableMouseListener.java
@Override public void mouseDragged(final MouseEvent e) { try {//w w w .ja v a2 s . c o m final State curState = dndState.getCurrentState(); final Point tablePoint = e.getPoint(); // log.debug("Mouse dragged point: " + tablePoint); final boolean foundIt = table.getComponentAtWithLocalPoint(tablePoint, componentAndLocalPoint); Point localPoint = null; C component = null; if (foundIt) { localPoint = componentAndLocalPoint.getHead(); component = componentAndLocalPoint.getTail(); } switch (curState) { case DURING_DRAG: decorationManager.setMouseLocation(tablePoint); if (dndPolicy.isValidDragTarget(table, component, localPoint, tablePoint)) { // log.debug("Is over valid drag!"); } else { // log.debug("Is not over valid drag!"); } break; case MOUSE_OVER_DRAGGABLE_AREA: log.error("Found browsing or over draggable area during a drag - but we shouldn't receive these."); // Reset the state dndState.changeTo(State.BROWSING); break; case BROWSING: // Do nothing. default: break; } } catch (final Exception e1) { final String msg = "Exception caught during mouse drag processing: " + e1.toString(); log.error(msg, e1); } }
From source file:uk.co.modularaudio.util.swing.dndtable.layeredpane.LayeredPaneDndTableMouseListener.java
@Override public void mousePressed(final MouseEvent e) { // Popup test if (e.isPopupTrigger()) { final Point dragStartPoint = e.getPoint(); final boolean foundIt = table.getComponentAtWithLocalPoint(dragStartPoint, componentAndLocalPoint); Point localPoint = null;/* w w w . j a va 2s . c o m*/ C component = null; if (foundIt) { localPoint = componentAndLocalPoint.getHead(); component = componentAndLocalPoint.getTail(); } if (dndPolicy.isMouseOverPopupSource(table, component, localPoint, dragStartPoint)) { try { dndState.changeTo(State.POPUP); dndPolicy.doPopup(table, component, localPoint, dragStartPoint); dndState.changeTo(State.BROWSING); } catch (final BadStateTransitionException bste) { final String msg = "Bad state transition attempting to perform popup"; log.error(msg, bste); } } } else { // log.debug(e); try { final State currentState = dndState.getCurrentState(); switch (currentState) { case MOUSE_OVER_DRAGGABLE_AREA: // Begin a drag final Point dragStartPoint = e.getPoint(); final boolean foundIt = table.getComponentAtWithLocalPoint(dragStartPoint, componentAndLocalPoint); Point localPoint = null; C component = null; if (foundIt) { localPoint = componentAndLocalPoint.getHead(); component = componentAndLocalPoint.getTail(); dndPolicy.startDrag(table, component, localPoint, dragStartPoint); dndState.changeTo(State.DURING_DRAG); decorationManager.setMouseLocation(dragStartPoint); } else { log.error("Failed to find drag source when clicked over a drag area."); dndState.changeTo(State.BROWSING); } break; default: break; } } catch (final Exception e1) { final String msg = "Exception caught processing mouse press: " + e1.toString(); log.error(msg, e1); } } }
From source file:it.unibas.spicygui.vista.listener.MyMouseEventListener.java
private void dispacciaEvento(Component com, MouseEvent e, Point point, boolean draggedEvent) { if (com == null) { com = SwingUtilities.getDeepestComponentAt(pannelloPrincipale, point.x, point.y); }//from www. j a va 2 s .co m 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) { jLayeredPane.moveToFront(component); component.updateUI(); if (e.getButton() == MouseEvent.BUTTON3) { return; } } } com.dispatchEvent(new MouseEvent(com, 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:lu.lippmann.cdb.graph.mouse.CadralEditingGraphMousePlugin.java
/** * When we are editing the graph : publish an event to select the node if * we right click on an existing node (to edit its properties) *//*from w w w . jav a 2s .c o m*/ @SuppressWarnings("unchecked") @Override public void mouseClicked(MouseEvent e) { if (e.getButton() == 3) { //right click final VisualizationViewer<CNode, CEdge> vv = (VisualizationViewer<CNode, CEdge>) e.getSource(); final Point2D p = e.getPoint(); final Layout<CNode, CEdge> layout = vv.getModel().getGraphLayout(); final GraphElementAccessor<CNode, CEdge> pickSupport = vv.getPickSupport(); if (pickSupport != null) { final CNode vertex = pickSupport.getVertex(layout, p.getX(), p.getY()); if (vertex != null) { commandDispatcher.dispatch(new SelectNodeCommand(vertex, 2)); } else { final CEdge edge = pickSupport.getEdge(layout, p.getX(), p.getY()); if (edge != null) { commandDispatcher.dispatch(new SelectEdgeCommand(edge, 2)); } } } } }
From source file:uk.co.modularaudio.util.swing.dndtable.layeredpane.LayeredPaneDndTableMouseListener.java
@Override public void mouseMoved(final MouseEvent e) { try {/*from w ww .j ava2s .c o m*/ final State curState = dndState.getCurrentState(); final Point tablePoint = e.getPoint(); // log.debug("Mouse moved point: " + tablePoint); decorationManager.setMouseLocation(tablePoint); final boolean foundIt = table.getComponentAtWithLocalPoint(tablePoint, componentAndLocalPoint); Point point = null; C component = null; if (foundIt) { point = componentAndLocalPoint.getHead(); component = componentAndLocalPoint.getTail(); } switch (curState) { case BROWSING: if (dndPolicy.isMouseOverDndSource(table, component, point, tablePoint)) { dndState.changeTo(State.MOUSE_OVER_DRAGGABLE_AREA); } break; case MOUSE_OVER_DRAGGABLE_AREA: if (!dndPolicy.isMouseOverDndSource(table, component, point, tablePoint)) { dndState.changeTo(State.BROWSING); } break; case DURING_DRAG: // Probably a bit of mouse movement after releasing a drag // but we haven't processed the drag end yet. if (!point.equals(OFFSCREEN_MOUSE_MOVE_POINT)) { log.error("Got a 'during_drag' state but we shouldn't receive these."); // Reset the state dndState.changeTo(State.BROWSING); } else { // It's okay, expected "clearUpDecorations" } break; default: break; } } catch (final Exception e1) { final String msg = "Exception caught during mouse movement processing: " + e1.toString(); log.error(msg, e1); } }
From source file:uk.nhs.cfh.dsp.srth.desktop.modules.resultexplanationpanel.ResultsExplanationPanel.java
/** * Inits the components./*w ww .j a va 2 s . com*/ */ public synchronized void initComponents() { while (activeFrame == null) { if (applicationService != null && applicationService.getFrameView() != null) { activeFrame = applicationService.getFrameView().getActiveFrame(); } } // create collections dialog createCollectionsDialog(); tableModel = new ReportingEngineExplanationTreeTableModel(queryService.getActiveQuery(), statsMap); treeTable = new JXTreeTable(tableModel); treeTable.setTreeCellRenderer(new SQLResultsExplanationTreeCellRenderer(queryExpressionHTMLRenderer)); // add mouse listeners treeTable.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { // get value at selection int row = treeTable.rowAtPoint(e.getPoint()); if (row > -1) { TreePath path = treeTable.getPathForLocation(e.getX(), e.getY()); // get node Object node = path.getLastPathComponent(); if (node instanceof QueryExpression) { QueryExpression expression = (QueryExpression) node; // get collection for selected expression QueryStatisticsCollection collection = statsMap.get(expression); // set expression in collection panel collectionPanel.setCollection(collection); collectionPanel.revalidate(); // show collections dialog collectionDialog.setVisible(true); } } } } }); // add components to this object setLayout(new BorderLayout()); // add(label, BorderLayout.NORTH); add(new JScrollPane(treeTable), BorderLayout.CENTER); }
From source file:savant.thousandgenomes.FTPBrowser.java
public FTPBrowser(URL rootURL) throws IOException { setRoot(rootURL);/*from w ww.ja v a2 s . c o m*/ setLayout(new BorderLayout()); addressField = new JTextField(); addressField.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { try { setRoot(new URL(addressField.getText())); updateDirectory(); } catch (Exception x) { DialogUtils.displayException("1000 Genomes Plugin", "Unable to change root directory", x); } } }); add(addressField, BorderLayout.NORTH); table = new JTable(); updateDirectory(); table.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent evt) { if (evt.getClickCount() == 2) { int row = table.rowAtPoint(evt.getPoint()); try { FTPFile f = ((FTPTableModel) table.getModel()).getEntry(row); if (f == null) { // Going up a directory. curDir = curDir.getParentFile(); updateDirectory(); } else if (f.isDirectory()) { curDir = new File(curDir, f.getName()); updateDirectory(); } else { TrackUtils.createTrack(new URI( "ftp://" + host + new File(curDir, f.getName()).getPath().replace("\\", "/"))); } } catch (Throwable x) { DialogUtils.displayException("FTP Error", "Unable to process FTP request.", x); } } } }); JScrollPane scrollPane = new JScrollPane(table); scrollPane.getViewport().setBackground(Color.WHITE); scrollPane.setPreferredSize(new Dimension(800, 500)); add(scrollPane, BorderLayout.CENTER); this.setPreferredSize(new Dimension(800, 500)); }