List of usage examples for java.awt.event MouseEvent getPoint
public Point getPoint()
From source file:com.igormaznitsa.jhexed.swing.editor.ui.MainForm.java
@Override public void mousePressed(final MouseEvent e) { final boolean ctrlPressed = (e.getModifiersEx() & MouseEvent.CTRL_DOWN_MASK) != 0; if (this.application == null) { if (!ctrlPressed && e.isPopupTrigger()) { final HexPosition hexNumber = this.hexMapPanel.getHexPosition(e.getPoint()); onPopup(e.getPoint(), hexNumber); } else {//ww w . j a va2s . c om switch (e.getButton()) { case MouseEvent.BUTTON1: { if (selectedToolType != null && this.selectedLayer != null) { addedUndoStep(new HexFieldLayer[] { this.selectedLayer }); final HexPosition hexNumber = this.hexMapPanel.getHexPosition(e.getPoint()); useCurrentToolAtPosition(hexNumber); } } break; case MouseEvent.BUTTON3: { if (ctrlPressed) { this.dragging = true; this.hexMapPanelDesktop.initDrag(e.getPoint()); } } break; } } } else if (!ctrlPressed && e.isPopupTrigger() && this.application.allowPopupTrigger()) { this.application.processHexAction(this.hexMapPanel, e, HexAction.POPUP_TRIGGER, this.hexMapPanel.getHexPosition(e.getPoint())); } else if (e.getButton() == MouseEvent.BUTTON3) { this.dragging = true; this.hexMapPanelDesktop.initDrag(e.getPoint()); } }
From source file:corelyzer.ui.CorelyzerGLCanvas.java
public void mouseClicked(final MouseEvent e) { Point prePos = e.getPoint(); float sp[] = { 0.0f, 0.0f }; this.convertMousePointToSceneSpace(prePos, scenePos); switch (e.getButton()) { case MouseEvent.BUTTON1: if (e.getClickCount() > 1) { // doubleclick zoom in/out Point mousePos = e.getPoint(); float[] cp = { 0.0f, 0.0f }; float[] sc = { 0.0f, 0.0f }; canvasLock.lock();/*from w w w .j a v a2 s .com*/ convertMousePointToSceneSpace(mousePos, cp); sc[0] = SceneGraph.getSceneCenterX(); sc[1] = SceneGraph.getSceneCenterY(); // alt down for zoom out?! float base; if (e.isAltDown()) { // zoom out base = 1.05f; } else { // zoom out base = 0.95f; } float scale = (float) Math.pow(base, 3); SceneGraph.scaleScene(scale); float ncp[] = { 0.0f, 0.0f }; this.convertMousePointToSceneSpace(mousePos, ncp); ncp[0] = ncp[0] - cp[0]; ncp[1] = ncp[1] - cp[1]; SceneGraph.panScene(-ncp[0], -ncp[1]); canvasLock.unlock(); CorelyzerApp.getApp().updateGLWindows(); return; } // measuring mode if (canvasMode == CorelyzerApp.APP_MEASURE_MODE) { int nPoint = SceneGraph.addMeasurePoint(scenePos[0], scenePos[1]); this.convertScenePointToAbsolute(scenePos, sp); if (nPoint == 1) { CorelyzerApp.getApp().getToolFrame().addMeasure(sp, 1); } else if (nPoint == 2) { CorelyzerApp.getApp().getToolFrame().addMeasure(sp, 2); } PAN_MODE = 0; return; } if (selectedFreeDraw > -1) { CorelyzerApp.getApp().getPluginManager().broadcastEventToPlugin( SceneGraph.getFreeDrawPluginID(selectedFreeDraw), CorelyzerPluginEvent.FREE_DRAW_SELECTED, "" + selectedFreeDraw); return; } selectedMarker = SceneGraph.accessPickedMarker(); if (selectedMarker < 0) { if (canvasMode == CorelyzerApp.APP_MARKER_MODE) { SceneGraph.setCoreSectionMarkerFocus(false); CorelyzerApp.getApp().updateGLWindows(); } return; } else { if (canvasMode == CorelyzerApp.APP_NORMAL_MODE) { AnnotationUtils.openAnnotation(getCanvas(), selectedTrack, selectedTrackSection, selectedMarker); } else { // marker mode // TODO do something if want to allow user adjust the // selected // TODO block, like sync to ClastInfo hash... if (selectedMarker != SceneGraph.focusedMarker || selectedTrackSection != SceneGraph.focusedTrackSection || selectedTrack != SceneGraph.focusedTrack) { SceneGraph.setCoreSectionMarkerFocus(false); SceneGraph.focusedTrack = selectedTrack; SceneGraph.focusedTrackSection = selectedTrackSection; SceneGraph.focusedMarker = selectedMarker; SceneGraph.setCoreSectionMarkerFocus(true); } } } break; case MouseEvent.BUTTON2: /* * System.out.println("---- Middle button clicked at: " + * prePos.x + ", " + prePos.y); * System.out.println("Converted to Scene Space: " + scenePos[0] * + ", " + scenePos[1]); */ break; case MouseEvent.BUTTON3: /* * System.out.println("---- Right button clicked at: " + * prePos.x + ", " + prePos.y); * System.out.println("Converted to Scene Space: " + scenePos[0] * + ", " + scenePos[1]); */ this.handleRightMouseClick(e); break; default: if (e.isPopupTrigger()) { this.handleRightMouseClick(e); } } }
From source file:cfa.vo.sed.science.stacker.SedStackerFrame.java
private void jList1MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jList1MousePressed if (evt.isPopupTrigger()) { jList1.setSelectedIndex(jList1.locationToIndex(evt.getPoint())); jPopupMenu1.show(jList1, evt.getX(), evt.getY()); }//from w w w . j a v a 2 s. co m }
From source file:cfa.vo.sed.science.stacker.SedStackerFrame.java
private void jList1MouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jList1MouseReleased if (evt.isPopupTrigger()) { jList1.setSelectedIndex(jList1.locationToIndex(evt.getPoint())); jPopupMenu1.show(jList1, evt.getX(), evt.getY()); }//from ww w. jav a2s .c om }
From source file:org.accada.reader.hal.impl.sim.GraphicSimulator.java
/** * creates the layered pane if it does not already exists * // w w w. j av a 2 s . c o m * @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 antennas String[] antennaIds = null; try { antennaIds = controller.getReadPointNames(); } catch (HardwareException ignored) { } for (int i = 0; i < antennaIds.length; i++) { createNewAntenna(antennaIds[i]); } jLayeredPane.add(getContextMenu()); jLayeredPane.add(getMgmtSimMenu()); // 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); mgmtSimMenu.setVisible(false); setActiveContextMenu(contextMenu); } else { contextMenu.setVisible(false); mgmtSimMenu.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:Clavis.Windows.WShedule.java
public synchronized void refreshTable(int val) { DefaultTableModel modelo = (DefaultTableModel) jTable1.getModel(); if (modelo.getRowCount() > 0) { int tam = modelo.getRowCount(); for (int h = 0; h < tam; h++) { modelo.removeRow(0);/*from w ww . j a v a 2s . co m*/ } } java.util.List<Keys.Request> requisicoes = new java.util.ArrayList<>(); if (DataBase.DataBase.testConnection(url)) { DataBase.DataBase db = new DataBase.DataBase(url); requisicoes = Clavis.RequestList .simplifyRequests(db.getRequestsByMaterialByDateInterval(mat, inicio, fim)); db.close(); } lista = new java.util.ArrayList<>(); andamento = 0; switch (val) { case 0: estado = lingua.translate("Todos"); for (Keys.Request req : requisicoes) { String[] multipla = req.getActivity().split(":::"); String saux; if (multipla.length > 1) { saux = multipla[0]; Components.PopUpMenu pop = new Components.PopUpMenu(multipla, lingua); pop.create(); jTable1.addMouseListener(new MouseAdapter() { int x = andamento; int y = 3; @Override public void mousePressed(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { int row = jTable1.rowAtPoint(e.getPoint()); int col = jTable1.columnAtPoint(e.getPoint()); if ((row == x) && (col == y)) { pop.show(e.getComponent(), e.getX(), e.getY()); } } } @Override public void mouseReleased(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { if (pop.isShowing()) { pop.setVisible(false); } } } }); } else { saux = req.getActivity(); } if (saux.equals("")) { saux = lingua.translate("Sem descrio"); } if (mat.getMaterialTypeID() == 1) { Object[] ob = { req.getPerson().getName(), req.getTimeBegin().toString(0) + " - " + req.getTimeEnd().toString(0), req.getBeginDate().toString(), saux, req.getSubject().getName() }; modelo.addRow(ob); } else { Object[] ob = { req.getPerson().getName(), req.getBeginDate().toString(), req.getEndDate().toString(), saux }; modelo.addRow(ob); } lista.add(req); andamento++; } break; case 1: estado = lingua.translate("terminado"); for (Keys.Request req : requisicoes) { if (req.isTerminated()) { String[] multipla = req.getActivity().split(":::"); String saux; if (multipla.length > 1) { saux = multipla[0]; Components.PopUpMenu pop = new Components.PopUpMenu(multipla, lingua); pop.create(); jTable1.addMouseListener(new MouseAdapter() { int x = andamento; int y = 3; @Override public void mousePressed(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { int row = jTable1.rowAtPoint(e.getPoint()); int col = jTable1.columnAtPoint(e.getPoint()); if ((row == x) && (col == y)) { pop.show(e.getComponent(), e.getX(), e.getY()); } } } @Override public void mouseReleased(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { if (pop.isShowing()) { pop.setVisible(false); } } } }); } else { saux = req.getActivity(); } if (saux.equals("")) { saux = lingua.translate("Sem descrio"); } if (mat.getMaterialTypeID() == 1) { Object[] ob = { req.getPerson().getName(), req.getTimeBegin().toString(0) + " - " + req.getTimeEnd().toString(0), req.getBeginDate().toString(), saux, req.getSubject().getName() }; modelo.addRow(ob); } else { Object[] ob = { req.getPerson().getName(), req.getBeginDate().toString(), req.getEndDate().toString(), saux }; modelo.addRow(ob); } lista.add(req); andamento++; } } break; case 2: estado = lingua.translate("no realizado"); for (Keys.Request req : requisicoes) { if ((!req.isActive()) && ((req.getEndDate().isBigger(new TimeDate.Date()) > 0) || ((req.getEndDate().isBigger(new TimeDate.Date()) == 0) && (req.getTimeEnd().compareTime(new TimeDate.Time()) > 0)))) { String[] multipla = req.getActivity().split(":::"); String saux; if (multipla.length > 1) { saux = multipla[0]; Components.PopUpMenu pop = new Components.PopUpMenu(multipla, lingua); pop.create(); jTable1.addMouseListener(new MouseAdapter() { int x = andamento; int y = 3; @Override public void mousePressed(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { int row = jTable1.rowAtPoint(e.getPoint()); int col = jTable1.columnAtPoint(e.getPoint()); if ((row == x) && (col == y)) { pop.show(e.getComponent(), e.getX(), e.getY()); } } } @Override public void mouseReleased(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { if (pop.isShowing()) { pop.setVisible(false); } } } }); } else { saux = req.getActivity(); } if (saux.equals("")) { saux = lingua.translate("Sem descrio"); } if (mat.getMaterialTypeID() == 1) { Object[] ob = { req.getPerson().getName(), req.getTimeBegin().toString(0) + " - " + req.getTimeEnd().toString(0), req.getBeginDate().toString(), saux, req.getSubject().getName() }; modelo.addRow(ob); } else { Object[] ob = { req.getPerson().getName(), req.getBeginDate().toString(), req.getEndDate().toString(), saux }; modelo.addRow(ob); } lista.add(req); andamento++; } } break; case 3: estado = lingua.translate("por realizar"); for (Keys.Request req : requisicoes) { if ((!req.isActive()) && (!req.isTerminated()) && ((req.getEndDate().isBigger(new TimeDate.Date()) < 0) || ((req.getEndDate().isBigger(new TimeDate.Date()) == 0) && (req.getTimeEnd().compareTime(new TimeDate.Time()) < 0)))) { String[] multipla = req.getActivity().split(":::"); String saux; if (multipla.length > 1) { saux = multipla[0]; Components.PopUpMenu pop = new Components.PopUpMenu(multipla, lingua); pop.create(); jTable1.addMouseListener(new MouseAdapter() { int x = andamento; int y = 3; @Override public void mousePressed(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { int row = jTable1.rowAtPoint(e.getPoint()); int col = jTable1.columnAtPoint(e.getPoint()); if ((row == x) && (col == y)) { pop.show(e.getComponent(), e.getX(), e.getY()); } } } @Override public void mouseReleased(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { if (pop.isShowing()) { pop.setVisible(false); } } } }); } else { saux = req.getActivity(); } if (saux.equals("")) { saux = lingua.translate("Sem descrio"); } if (mat.getMaterialTypeID() == 1) { Object[] ob = { req.getPerson().getName(), req.getTimeBegin().toString(0) + " - " + req.getTimeEnd().toString(0), req.getBeginDate().toString(), saux, req.getSubject().getName() }; modelo.addRow(ob); } else { Object[] ob = { req.getPerson().getName(), req.getBeginDate().toString(), req.getEndDate().toString(), saux }; modelo.addRow(ob); } lista.add(req); andamento++; } } break; } valores = new String[lista.size()][4]; for (int i = 0; i < lista.size(); i++) { String[] multipla = lista.get(i).getActivity().split(":::"); String saux = multipla[0]; if (saux.equals("")) { saux = lingua.translate("Sem descrio"); } if (mat.getMaterialTypeID() == 1) { valores[i][0] = lista.get(i).getPerson().getName(); valores[i][1] = lista.get(i).getTimeBegin().toString(0) + " - " + lista.get(i).getTimeEnd().toString(0); valores[i][2] = lista.get(i).getBeginDate().toString(); valores[i][3] = saux + " - " + lista.get(i).getSubject().getName(); } else { valores[i][0] = lista.get(i).getPerson().getName(); valores[i][1] = lista.get(i).getBeginDate().toString(); valores[i][2] = lista.get(i).getEndDate().toString(); valores[i][3] = saux; } } }
From source file:com.u2apple.tool.ui.MainFrame.java
private void initRowSelectionEvent() { deviceTable.getSelectionModel().addListSelectionListener((ListSelectionEvent e) -> { int row = deviceTable.getSelectedRow(); //When refresh table model data, row will be -1. if (row >= 0) { String vid = (String) deviceTable.getValueAt(row, 0); String model = (String) deviceTable.getValueAt(row, 1); String brand = (String) deviceTable.getValueAt(row, 2); vidTextField.setText(vid);//from w w w. j a va2s . c om modelTextField.setText(model); brandTextField.setText(brand); } //Auto fullfil device information. initDevice(); }); deviceTable.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent me) { JTable table = (JTable) me.getSource(); Point p = me.getPoint(); int row = table.rowAtPoint(p); if (me.getClickCount() == 2) { String vid = (String) deviceTable.getValueAt(row, 0); String model = (String) deviceTable.getValueAt(row, 1); String brand = (String) deviceTable.getValueAt(row, 2); AndroidDeviceRanking androidDevice = new AndroidDeviceRanking(); androidDevice.setVid(vid); androidDevice.setRoProductModel(model); androidDevice.setRoProductBrand(brand); androidDevice.setCheckDate(new Date()); try { DeviceCache.markDeviceChecked(androidDevice); } catch (JAXBException ex) { Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex); } DeviceTableModel tableModel = (DeviceTableModel) deviceTable.getModel(); tableModel.removeRow(row); } } }); }
From source file:corelyzer.ui.CorelyzerGLCanvas.java
/** * Handles mouse dragging events: panning, sliding sections, sliding tracks, * and trackpad based zooming./*from w ww.ja v a 2 s . c o m*/ */ public void mouseDragged(final MouseEvent e) { Point currentPos = e.getPoint(); int dX = currentPos.x - prePos.x; int dY = currentPos.y - prePos.y; float sx, sy; float w, h; canvasLock.lock(); w = SceneGraph.getCanvasWidth(canvasId); h = SceneGraph.getCanvasHeight(canvasId); sx = w / canvas.getWidth(); sy = h / canvas.getHeight(); this.convertMousePointToSceneSpace(currentPos, scenePos); // play a bit measuring test if (canvasMode == CorelyzerApp.APP_MEASURE_MODE) { SceneGraph.positionMouse(scenePos[0], scenePos[1]); // some work for panning // automatically pan mode canvas.setCursor(new Cursor(Cursor.MOVE_CURSOR)); SceneGraph.panScene(-dX * sx, -dY * sy); canvasLock.unlock(); prePos = currentPos; CorelyzerApp.getApp().updateGLWindows(); return; } else if (canvasMode == CorelyzerApp.APP_CLAST_MODE || canvasMode == CorelyzerApp.APP_CUT_MODE) { SceneGraph.positionMouse(scenePos[0], scenePos[1]); // Don't have a selected section, just pan if (selectedTrackSection == -1) { canvas.setCursor(new Cursor(Cursor.MOVE_CURSOR)); SceneGraph.panScene(-dX * sx, -dY * sy); } canvasLock.unlock(); prePos = currentPos; CorelyzerApp.getApp().updateGLWindows(); return; } // check focused marker manipulation if (MANIPULATE_MODE == 1) { float dx, dy; dx = scenePos[0] - prescenePos[0]; dy = scenePos[1] - prescenePos[1]; prescenePos[0] = scenePos[0]; prescenePos[1] = scenePos[1]; SceneGraph.manipulateMarker(canvasId, dx, dy); SceneGraph.positionMouse(scenePos[0], scenePos[1]); canvasLock.unlock(); prePos = currentPos; CorelyzerApp.getApp().updateGLWindows(); return; } else { if (e.isAltDown()) // slide track section { // TODO consider separate move of section image and graph // moveSectionImage & moveSectionGraph if (selectedTrack >= 0 && selectedTrackSection >= 0) { if (canvas.getCursor().getType() != Cursor.HAND_CURSOR) { canvas.setCursor(new Cursor(Cursor.HAND_CURSOR)); } // depth orientation float tX = SceneGraph.getDepthOrientation() ? dX * sx : dY * sy; // allow vertical movements? float tY = 0; // float tY = SceneGraph.getDepthOrientation() ? // (dY * sy) : (-dX * sx); if (selectedGraph >= 0) { // moving graph instead of whole section SceneGraph.moveSectionGraph(selectedTrack, selectedTrackSection, tX, tY); } else { Object[] sections = CorelyzerApp.getApp().getSectionList().getSelectedValues(); int[] secids = new int[sections.length]; for (int i = 0; i < sections.length; i++) { CoreSection cs = (CoreSection) sections[i]; secids[i] = (cs != null ? cs.getId() : -1); } SceneGraph.moveSections(selectedTrack, secids, tX, tY); } // broadcast event to plugins String msg = ""; msg = msg + selectedTrack + "\t" + selectedTrackSection; msg = msg + "\t" + dX * sx / SceneGraph.getCanvasDPIX(canvasId) + "\t0"; CorelyzerApp.getApp().getPluginManager() .broadcastEventToPlugins(CorelyzerPluginEvent.SECTION_MOVED, msg); } } else if (e.isShiftDown()) { // slide track if (selectedTrack >= 0) { if (canvas.getCursor().getType() != Cursor.HAND_CURSOR) { canvas.setCursor(new Cursor(Cursor.HAND_CURSOR)); } // fine tune allows depth movements if (isFineTune() && finetuneDialog != null) { // depth orientation if (SceneGraph.getDepthOrientation()) { // landscape SceneGraph.moveTrack(selectedTrack, dX * sx, dY * sy); } else { // Portrait SceneGraph.moveTrack(selectedTrack, dY * sy, -dX * sx); } float currentTrackPosX = SceneGraph.getTrackXPos(selectedTrack); float canvasDPIX = SceneGraph.getCanvasDPIX(0); JTextField fineTuneCoreADepthStatus = finetuneDialog.getCoreAAdjustedDepthTextField(); JTextField fineTuneCoreBDepthStatus = finetuneDialog.getCoreBAdjustedDepthTextField(); int coreANativeID = finetuneDialog.getCoreANativeID(); int coreBNativeID = finetuneDialog.getCoreBNativeID(); float coreAOrigDepth = finetuneDialog.getCoreAOrigDepth(); float coreBOrigDepth = finetuneDialog.getCoreBOrigDepth(); if (fineTuneCoreADepthStatus != null && coreANativeID == selectedTrack) { float depth = coreAOrigDepth + 2.54f * currentTrackPosX / (100 * canvasDPIX); fineTuneCoreADepthStatus.setText(String.valueOf(depth)); } if (fineTuneCoreBDepthStatus != null && coreBNativeID == selectedTrack) { float depth = coreBOrigDepth + 2.54f * currentTrackPosX / (100 * canvasDPIX); fineTuneCoreBDepthStatus.setText(String.valueOf(depth)); } } else { // normal // depth orientation if (SceneGraph.getDepthOrientation()) { SceneGraph.moveTrack(selectedTrack, 0.0f, dY * sy); } else { SceneGraph.moveTrack(selectedTrack, 0.0f, -dX * sx); } } // broadcast message to plugins String msg = ""; msg = msg + selectedTrack; msg = msg + "\t0\t" + dY * sx / SceneGraph.getCanvasDPIY(canvasId); CorelyzerApp.getApp().getPluginManager() .broadcastEventToPlugins(CorelyzerPluginEvent.TRACK_MOVED, msg); } } else if (e.isControlDown()) // zooming { sy = (float) dY / (float) canvas.getHeight(); SceneGraph.scaleScene(1.0f + sy); } else if (PAN_MODE == 1) { // automatically pan mode canvas.setCursor(new Cursor(Cursor.MOVE_CURSOR)); SceneGraph.panScene(-dX * sx, -dY * sy); } } // end of else (manipulation mode) SceneGraph.positionMouse(scenePos[0], scenePos[1]); canvasLock.unlock(); prePos = currentPos; CorelyzerApp.getApp().updateGLWindows(); }
From source file:org.accada.hal.impl.sim.GraphicSimulator.java
/** * creates the layered pane if it does not already exists * /*from w w w . j av a 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 antennas String[] antennaIds = null; antennaIds = controller.getReadPointNames(); for (int i = 0; i < antennaIds.length; i++) { createNewAntenna(antennaIds[i]); } jLayeredPane.add(getContextMenu()); jLayeredPane.add(getMgmtSimMenu()); // 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); mgmtSimMenu.setVisible(false); setActiveContextMenu(contextMenu); } else { contextMenu.setVisible(false); mgmtSimMenu.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:cfa.vo.sed.science.stacker.SedStackerFrame.java
private void sedsTableMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_sedsTableMousePressed if (evt.isPopupTrigger()) { JTable source = (JTable) evt.getSource(); int row = source.rowAtPoint(evt.getPoint()); int column = source.columnAtPoint(evt.getPoint()); if (!source.isRowSelected(row)) source.changeSelection(row, column, false, false); sedsTable.changeSelection(row, column, false, false); jPopupMenu2.show(evt.getComponent(), evt.getX(), evt.getY()); }/* w w w . ja va2 s . com*/ }