List of usage examples for java.awt.event MouseEvent getY
public int getY()
From source file:org.gvsig.remotesensing.scatterplot.chart.ScatterPlotDiagram.java
/** * Handles a 'mouse dragged' event.//from w w w . ja v a2s . co m * * @param e the mouse event. */ public void mouseDragged(MouseEvent e) { // if the popup menu has already been triggered, then ignore dragging... if (this.popup != null && this.popup.isShowing()) { return; } // if no initial zoom point was set, ignore dragging... if (this.zoomPoint == null) { return; } Graphics2D g2 = (Graphics2D) getGraphics(); // Erase the previous zoom rectangle (if any)... drawRectangle(g2); 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.zoomPoint.getX(), (int) this.zoomPoint.getY()); if (hZoom && vZoom) { // selected rectangle shouldn't extend outside the data area... double xmax = Math.min(e.getX(), scaledDataArea.getMaxX()); double ymax = Math.min(e.getY(), scaledDataArea.getMaxY()); this.zoomRectangle = new Rectangle2D.Double(this.zoomPoint.getX(), this.zoomPoint.getY(), xmax - this.zoomPoint.getX(), ymax - this.zoomPoint.getY()); } else if (hZoom) { double xmax = Math.min(e.getX(), scaledDataArea.getMaxX()); this.zoomRectangle = new Rectangle2D.Double(this.zoomPoint.getX(), scaledDataArea.getMinY(), xmax - this.zoomPoint.getX(), scaledDataArea.getHeight()); } else if (vZoom) { double ymax = Math.min(e.getY(), scaledDataArea.getMaxY()); this.zoomRectangle = new Rectangle2D.Double(scaledDataArea.getMinX(), this.zoomPoint.getY(), scaledDataArea.getWidth(), ymax - this.zoomPoint.getY()); } // Draw the new zoom rectangle... drawRectangle(g2); g2.dispose(); }
From source file:ireport_5_6_0.view.JRViewer.java
void pnlLinksMouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pnlLinksMouseDragged // Add your handling code here: Container container = pnlInScroll.getParent(); if (container instanceof JViewport) { JViewport viewport = (JViewport) container; Point point = viewport.getViewPosition(); int newX = point.x - (evt.getX() - downX); int newY = point.y - (evt.getY() - downY); int maxX = pnlInScroll.getWidth() - viewport.getWidth(); int maxY = pnlInScroll.getHeight() - viewport.getHeight(); if (newX < 0) { newX = 0;// ww w. j a v a2 s . c om } if (newX > maxX) { newX = maxX; } if (newY < 0) { newY = 0; } if (newY > maxY) { newY = maxY; } viewport.setViewPosition(new Point(newX, newY)); } }
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 . j a va 2s . c om*/ }
From source file:com.isti.traceview.common.TraceViewChartPanel.java
/** * Handles a 'mouse pressed' event.//from ww w . j a v a 2s. c o m * <P> * This event is the popup trigger on Unix/Linux. For Windows, the popup trigger is the 'mouse * released' event. * * @param e * The mouse event. */ public void mousePressed(MouseEvent e) { if (this.zoomRectangle == null) { Rectangle2D screenDataArea = getScreenDataArea(e.getX(), e.getY()); if (screenDataArea != null) { this.zoomPoint = getPointInRectangle(e.getX(), e.getY(), screenDataArea); } else { this.zoomPoint = null; } if (e.isPopupTrigger()) { if (this.popup != null) { displayPopupMenu(e.getX(), e.getY()); } } } }
From source file:net.sf.jabref.gui.MainTableSelectionListener.java
@Override public void mouseClicked(MouseEvent e) { // First find the column on which the user has clicked. final int col = table.columnAtPoint(e.getPoint()); final int row = table.rowAtPoint(e.getPoint()); // A double click on an entry should open the entry's editor. if (e.getClickCount() == 2) { BibtexEntry toShow = tableRows.get(row); editSignalled(toShow);//w ww .ja va 2 s. c om } // Check if the user has clicked on an icon cell to open url or pdf. final String[] iconType = table.getIconTypeForColumn(col); // Workaround for Windows. Right-click is not popup trigger on mousePressed, but // on mouseReleased. Therefore we need to avoid taking action at this point, because // action will be taken when the button is released: if (OS.WINDOWS && (iconType != null) && (e.getButton() != MouseEvent.BUTTON1)) { return; } if (iconType != null) { // left click on icon field SpecialField field = SpecialFieldsUtils.getSpecialFieldInstanceFromFieldName(iconType[0]); if ((e.getClickCount() == 1) && (field != null)) { // special field found if (field.isSingleValueField()) { // directly execute toggle action instead of showing a menu with one action field.getValues().get(0).getAction(panel.frame()).action(); } else { JPopupMenu menu = new JPopupMenu(); for (SpecialFieldValue val : field.getValues()) { menu.add(val.getMenuAction(panel.frame())); } menu.show(table, e.getX(), e.getY()); } return; } Object value = table.getValueAt(row, col); if (value == null) { return; // No icon here, so we do nothing. } final BibtexEntry entry = tableRows.get(row); // Get the icon type. Corresponds to the field name. int hasField = -1; for (int i = iconType.length - 1; i >= 0; i--) { if (entry.getField(iconType[i]) != null) { hasField = i; } } if (hasField == -1) { return; } final String fieldName = iconType[hasField]; //If this is a file link field with specified file types, //we should also pass the types. String[] fileTypes = {}; if ((hasField == 0) && iconType[hasField].equals(Globals.FILE_FIELD) && (iconType.length > 1)) { fileTypes = iconType; } final List<String> listOfFileTypes = Collections.unmodifiableList(Arrays.asList(fileTypes)); // Open it now. We do this in a thread, so the program won't freeze during the wait. JabRefExecutorService.INSTANCE.execute(new Runnable() { @Override public void run() { panel.output(Localization.lang("External viewer called") + '.'); Object link = entry.getField(fieldName); if (link == null) { LOGGER.info("Error: no link to " + fieldName + '.'); return; // There is an icon, but the field is not set. } // See if this is a simple file link field, or if it is a file-list // field that can specify a list of links: if (fieldName.equals(Globals.FILE_FIELD)) { // We use a FileListTableModel to parse the field content: FileListTableModel fileList = new FileListTableModel(); fileList.setContent((String) link); FileListEntry flEntry = null; // If there are one or more links of the correct type, // open the first one: if (!listOfFileTypes.isEmpty()) { for (int i = 0; i < fileList.getRowCount(); i++) { flEntry = fileList.getEntry(i); boolean correctType = false; for (String listOfFileType : listOfFileTypes) { if (flEntry.getType().toString().equals(listOfFileType)) { correctType = true; } } if (correctType) { break; } flEntry = null; } } //If there are no file types specified, consider all files. else if (fileList.getRowCount() > 0) { flEntry = fileList.getEntry(0); } if (flEntry != null) { // if (fileList.getRowCount() > 0) { // FileListEntry flEntry = fileList.getEntry(0); ExternalFileMenuItem item = new ExternalFileMenuItem(panel.frame(), entry, "", flEntry.getLink(), flEntry.getType().getIcon(), panel.metaData(), flEntry.getType()); boolean success = item.openLink(); if (!success) { panel.output(Localization.lang("Unable to open link.")); } } } else { try { JabRefDesktop.openExternalViewer(panel.metaData(), (String) link, fieldName); } catch (IOException ex) { panel.output(Localization.lang("Unable to open link.")); } /*ExternalFileType type = Globals.prefs.getExternalFileTypeByMimeType("text/html"); ExternalFileMenuItem item = new ExternalFileMenuItem (panel.frame(), entry, "", (String)link, type.getIcon(), panel.metaData(), type); boolean success = item.openLink(); if (!success) { panel.output(Localization.lang("Unable to open link.")); } */ //Util.openExternalViewer(panel.metaData(), (String)link, fieldName); } //catch (IOException ex) { // panel.output(Globals.lang("Error") + ": " + ex.getMessage()); //} } }); } }
From source file:com.isti.traceview.common.TraceViewChartPanel.java
/** * Receives notification of mouse clicks on the panel. These are translated and passed on to any * registered chart mouse click listeners. * //w w w . j av a 2 s.c om * @param event * Information about the mouse event. */ public void mouseClicked(MouseEvent event) { Insets insets = getInsets(); int x = (int) ((event.getX() - insets.left) / this.scaleX); int y = (int) ((event.getY() - insets.top) / this.scaleY); this.anchor = new Point2D.Double(x, y); if (this.chart == null) { return; } this.chart.setNotify(true); // force a redraw // new entity code... Object[] listeners = this.chartMouseListeners.getListeners(ChartMouseListener.class); if (listeners.length == 0) { return; } ChartEntity entity = null; if (this.info != null) { EntityCollection entities = this.info.getEntityCollection(); if (entities != null) { entity = entities.getEntity(x, y); } } ChartMouseEvent chartEvent = new ChartMouseEvent(getChart(), event, entity); for (int i = listeners.length - 1; i >= 0; i -= 1) { ((ChartMouseListener) listeners[i]).chartMouseClicked(chartEvent); } }
From source file:org.gumtree.vis.awt.JChartPanel.java
@Override public void mouseClicked(MouseEvent e) { if ((e.getModifiers() & InputEvent.ALT_MASK) != 0) { double xNew = ChartMaskingUtilities.translateScreenX(e.getX(), getScreenDataArea(), getChart()); double yNew = ChartMaskingUtilities.translateScreenY(e.getY(), getScreenDataArea(), getChart(), 0); addMarker(xNew, yNew, null);//from ww w .j a va 2 s. co m } else if (isTextInputEnabled) { if (!textInputFlag) { boolean newTextEnabled = selectedTextWrapper == null; if (selectedTextWrapper != null) { Point2D screenXY = ChartMaskingUtilities.translateChartPoint( new Point2D.Double(selectedTextWrapper.getMinX(), selectedTextWrapper.getMinY()), getScreenDataArea(), getChart()); Rectangle2D screenRect = new Rectangle2D.Double(screenXY.getX(), screenXY.getY() - 15, selectedTextWrapper.getWidth(), selectedTextWrapper.getHeight()); if (screenRect.contains(e.getX(), e.getY())) { Point2D point = e.getPoint(); String inputText = textContentMap.get(selectedTextWrapper); if (inputText == null) { inputText = ""; } String[] lines = inputText.split("\n", 100); int cursorX = 0; int charCount = 0; int maxWidth = 0; int pickX = -1; FontMetrics fm = getGraphics().getFontMetrics(); for (int i = 0; i < lines.length; i++) { int lineWidth = fm.stringWidth(lines[i]); if (lineWidth > maxWidth) { maxWidth = lineWidth; } } if (maxWidth < 100) { maxWidth = 100; } Point2D screenPoint = ChartMaskingUtilities.translateChartPoint( new Point2D.Double(selectedTextWrapper.getX(), selectedTextWrapper.getY()), getScreenDataArea(), getChart()); if (point.getX() <= screenPoint.getX() + 11 + maxWidth && point.getY() <= screenPoint.getY() + lines.length * 15 - 15) { textInputPoint = screenPoint; textInputContent = inputText; textInputFlag = true; textContentMap.remove(selectedTextWrapper); selectedTextWrapper = null; textInputCursorIndex = 0; for (int i = 0; i < lines.length; i++) { if (point.getY() > screenPoint.getY() + i * 15 - 15 && point.getY() <= screenPoint.getY() + i * 15) { cursorX = fm.stringWidth(lines[i]); if (point.getX() >= screenPoint.getX() && point.getX() <= screenPoint.getX() + 3 + cursorX) { if (point.getX() >= screenPoint.getX() && point.getX() < screenPoint.getX() + 3) { pickX = 0; } double lastEnd = screenPoint.getX() + 3; for (int j = 0; j < lines[i].length(); j++) { int size = fm.stringWidth(lines[i].substring(0, j + 1)); double newEnd = screenPoint.getX() + 3 + size; if (point.getX() >= lastEnd && point.getX() < lastEnd + (newEnd - lastEnd) / 2) { pickX = j; } else if (point.getX() >= lastEnd + (newEnd - lastEnd) / 2 && point.getX() < newEnd) { pickX = j + 1; } lastEnd = newEnd; } if (pickX >= 0) { textInputCursorIndex = charCount + pickX; } } else { textInputCursorIndex = charCount + lines[i].length(); } break; } charCount += lines[i].length() + 1; } } } } selectText(e.getX(), e.getY()); if (selectedTextWrapper == null && !textInputFlag && newTextEnabled && (e.getModifiers() & MouseEvent.BUTTON1_MASK) != 0) { textInputFlag = true; textInputPoint = e.getPoint(); } } else { Point2D point = e.getPoint(); boolean finishInput = false; // if (point.getX() < textInputPoint.getX() || point.getY() < textInputPoint.getY() - 15) { // finishInput = true; // } else { String inputText = textInputContent; if (inputText == null) { inputText = ""; } String[] lines = inputText.split("\n", 100); int cursorX = 0; int charCount = 0; int maxWidth = 0; int pickX = -1; FontMetrics fm = getGraphics().getFontMetrics(); for (int i = 0; i < lines.length; i++) { int lineWidth = fm.stringWidth(lines[i]); if (lineWidth > maxWidth) { maxWidth = lineWidth; } } if (maxWidth < 100) { maxWidth = 100; } if (point.getX() > textInputPoint.getX() + 11 + maxWidth || point.getY() > textInputPoint.getY() + lines.length * 15 - 15 || point.getX() < textInputPoint.getX() || point.getY() < textInputPoint.getY() - 15) { finishInput = true; } else { for (int i = 0; i < lines.length; i++) { if (point.getY() > textInputPoint.getY() + i * 15 - 15 && point.getY() <= textInputPoint.getY() + i * 15) { cursorX = fm.stringWidth(lines[i]); if (point.getX() >= textInputPoint.getX() && point.getX() <= textInputPoint.getX() + 3 + cursorX) { if (point.getX() >= textInputPoint.getX() && point.getX() < textInputPoint.getX() + 3) { pickX = 0; } double lastEnd = textInputPoint.getX() + 3; for (int j = 0; j < lines[i].length(); j++) { int size = fm.stringWidth(lines[i].substring(0, j + 1)); double newEnd = textInputPoint.getX() + 3 + size; if (point.getX() >= lastEnd && point.getX() < lastEnd + (newEnd - lastEnd) / 2) { pickX = j; } else if (point.getX() >= lastEnd + (newEnd - lastEnd) / 2 && point.getX() < newEnd) { pickX = j + 1; } lastEnd = newEnd; } if (pickX >= 0) { textInputCursorIndex = charCount + pickX; } } else { textInputCursorIndex = charCount + lines[i].length(); } break; } charCount += lines[i].length() + 1; } } // } if (finishInput) { if (textInputContent != null && textInputContent.length() > 0) { double xNew = ChartMaskingUtilities.translateScreenX(textInputPoint.getX(), getScreenDataArea(), getChart()); double yNew = ChartMaskingUtilities.translateScreenY(textInputPoint.getY(), getScreenDataArea(), getChart(), 0); textContentMap.put(new Rectangle2D.Double(xNew, yNew, maxWidth, lines.length * 15), textInputContent); } textInputContent = null; textInputCursorIndex = 0; textInputFlag = false; } } } }
From source file:br.com.atmatech.sac.view.ViewListaAtendimento.java
private void jTatendimentoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTatendimentoMouseClicked // TODO add your handling code here: if (new NivelAcesso().getAcesso("ViewAtendimento", "acessar")) { if (evt.getClickCount() == 2) { ViewAtendimento view = new ViewAtendimento(viewprincipal, this, clickAtendimento(), new UsuarioLogadoBeans().getAlttecnico(), false); viewprincipal.jTaabas.getSelectedIndex(); viewprincipal.jTaabas.setComponentAt(viewprincipal.jTaabas.getSelectedIndex(), view); if (!new UsuarioLogadoBeans().getBconsulta()) { if (constecnico.isAlive()) { if (!constecnico.isInterrupted()) { constecnico.stop(); }// w w w . j a v a2s. com } //constecnico.stop(); } } } if (jTatendimento.getSelectedRow() >= 0) { if ((evt.getModifiers() & MouseEvent.BUTTON3_MASK) != 0) { jPopupMenu1.show(jTatendimento, evt.getX(), evt.getY()); } } }
From source file:canreg.client.gui.dataentry.PDSEditorInternalFrame.java
private void pdsTableMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pdsTableMousePressed if (evt.isPopupTrigger()) { copyMenuItem.setEnabled(!pdsTable.getSelectionModel().isSelectionEmpty()); Transferable contents = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(this); pasteMenuItem.setEnabled(contents.isDataFlavorSupported(DataFlavor.stringFlavor)); tablePopupMenu.show(evt.getComponent(), evt.getX(), evt.getY()); }/*from ww w . j a va 2 s .co m*/ }
From source file:canreg.client.gui.dataentry.PDSEditorInternalFrame.java
private void pdsTableMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pdsTableMouseReleased if (evt.isPopupTrigger()) { copyMenuItem.setEnabled(!pdsTable.getSelectionModel().isSelectionEmpty()); Transferable contents = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(this); pasteMenuItem.setEnabled(contents.isDataFlavorSupported(DataFlavor.stringFlavor)); tablePopupMenu.show(evt.getComponent(), evt.getX(), evt.getY()); }//from w w w. jav a 2 s. c o m }