List of usage examples for java.awt.event MouseEvent getModifiers
@Deprecated(since = "9") public int getModifiers()
From source file:org.gumtree.vis.awt.JChartPanel.java
@Override public void mouseReleased(MouseEvent e) { if ((e.getModifiers() & InputEvent.BUTTON3_MASK) != 0) { double xNew = ChartMaskingUtilities.translateScreenX(e.getX(), getScreenDataArea(), getChart()); double yNew = ChartMaskingUtilities.translateScreenY(e.getY(), getScreenDataArea(), getChart(), 0); mouseRightClickLocation = new Point2D.Double(xNew, yNew); }// ww w .j av a 2 s . c o m textMovePoint = null; super.mouseReleased(e); }
From source file:base.BasePlayer.AminoTable.java
@Override public void mousePressed(MouseEvent event) { switch (event.getModifiers()) { case InputEvent.BUTTON1_MASK: { if (!this.isEnabled()) { break; }/*from w w w . j a v a 2 s. c o m*/ this.dragX = event.getX(); if (headerHover > -1) { if (resizeColumn == -1) { if (sorter.ascending) { sorter.ascending = false; } else { sorter.ascending = true; } sorter.index = headerHover; Collections.sort(genearray, sorter); createPolygon(); } repaint(); } } if (hoverNode != null || hoverVar != null) { Main.chromDraw.repaint(); } } }
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 w ww .j a va2 s. com } 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(); }/*from ww w .j av a 2s.c om*/ } //constecnico.stop(); } } } if (jTatendimento.getSelectedRow() >= 0) { if ((evt.getModifiers() & MouseEvent.BUTTON3_MASK) != 0) { jPopupMenu1.show(jTatendimento, evt.getX(), evt.getY()); } } }
From source file:base.BasePlayer.AminoTable.java
@Override public void mouseClicked(MouseEvent event) { switch (event.getModifiers()) { case InputEvent.BUTTON1_MASK: { if (!this.isEnabled()) { break; }/* w w w. j a va 2s . c om*/ if (this.headerHover == -1) { if (event.getClickCount() == 2) { if (Draw.variantcalculator) { return; } FileRead.novars = true; if (hoverSample > -1) { Main.drawCanvas.drawVariables.visiblestart = (short) (hoverSample); Main.drawCanvas.drawVariables.visiblesamples = (short) (1); Main.drawCanvas.resizeCanvas(Main.drawScroll.getViewport().getWidth(), (int) (Main.samples * Main.drawCanvas.drawVariables.sampleHeight)); Draw.setScrollbar((int) (hoverSample * Main.drawCanvas.drawVariables.sampleHeight)); } else { Main.drawCanvas.drawVariables.visiblestart = (short) (0); Main.drawCanvas.drawVariables.visiblesamples = (short) (Main.samples); Main.drawCanvas.resizeCanvas(Main.drawScroll.getViewport().getWidth(), (int) (Main.samples * Main.drawCanvas.drawVariables.sampleHeight)); Draw.setScrollbar(0); } if (hoverVar != null) { FileRead.search = true; VarNode searchHead = hoverVar; while (searchHead.getPrev() != null) { /*if(searchHead.getPrev().getPosition() == 0) { searchHead.getPrev().putNext(searchHead); }*/ if (searchHead.getPrev().getChrom() == null || !searchHead.getPrev().getChrom().equals(hoverVar.getChrom())) { if (searchHead.getPrev().getNext() == null) { searchHead.getPrev().putNext(searchHead); } FileRead.head = searchHead.getPrev(); break; } searchHead = searchHead.getPrev(); } searchHead = null; Main.drawCanvas.current = hoverVar; if (hoverVar.getExons() != null) { Main.drawCanvas.gotoPos(hoverVar.getChrom(), hoverVar.getPosition() + 1 - 50, hoverVar.getPosition() + 1 + 50); } else { if (hoverVar.getTranscripts().size() > 0) { Main.drawCanvas.gotoPos(hoverVar.getChrom(), hoverVar.getPosition() + 1 - 50, hoverVar.getPosition() + 1 + 50); } } } else if (hoverNode != null) { FileRead.search = true; if (hoverNode.varnodes.get(0).getTranscripts() != null && hoverNode.varnodes.get(0).getTranscripts().size() == 2) { Main.drawCanvas.gotoPos(hoverNode.getChrom(), hoverNode.getEnd(), hoverNode.varnodes.get(0).getTranscripts().get(1).getGene().getStart()); } else { VarNode searchHead = hoverNode.varnodes.get(0); /*while(searchHead.getPrev() != null) { if(searchHead.getPrev().getPosition() == 0) { searchHead.getPrev().putNext(searchHead); } searchHead = searchHead.getPrev(); }*/ while (searchHead.getPrev() != null) { /*if(searchHead.getPrev().getPosition() == 0) { searchHead.getPrev().putNext(searchHead); }*/ if (searchHead.getPrev().getChrom() == null || !searchHead.getPrev().getChrom().equals(searchHead.getChrom())) { FileRead.head = searchHead.getPrev(); break; } searchHead = searchHead.getPrev(); } //FileRead.head = searchHead; searchHead = null; Main.drawCanvas.current = hoverNode.varnodes.get(0); Main.drawCanvas.gotoPos(hoverNode.getChrom(), hoverNode.getStart(), hoverNode.getEnd()); } } Main.chromDraw.updateExons = true; Main.chromDraw.repaint(); break; } else if (event.getClickCount() == 1) { /* if(hoverVar != null && selectedNode.equals(selectedVar)) { selectedString = hoverString; } else*/ //MethodLibrary.showVariantMenu(this, varOverLap, sampleOverLap, moveX+(int)selectedSplit.pixel, moveY); if (hoverVar != null && (selectedVar == null || !selectedVar.equals(hoverVar))) { selectedVar = hoverVar; selectedString = hoverString; if (selectedVar.isRscode() != null) { hoverString[4] = selectedVar.rscode; } //MethodLibrary.showVariantMenu(this, hoverVar, null, mouseX+(int)Main.defaultFontSize*2, mouseY,hoverBase); /* if(hoverBase != null) { MethodLibrary.showVariantMenu(this, hoverVar, null, 0, mouseY-Main.defaultFontSize*6,hoverBase); } */ repaint(); this.setPreferredSize(new Dimension(this.getWidth(), (this.getTableSize() + 2 + samplecount + Integer.parseInt(selectedString[1])) * rowHeight)); this.revalidate(); } else if (hoverVar != null && selectedVar.equals(hoverVar)) { if (hoverSample == -1) { selectedVar = null; repaint(); this.setPreferredSize(new Dimension(this.getWidth(), (this.getTableSize() + 2 + samplecount) * rowHeight)); this.revalidate(); } else { if (hoverSampleNode != null) { MethodLibrary.showVariantMenu(this, hoverVar, hoverSampleNode, mouseX + (int) Main.defaultFontSize * 2, mouseY, hoverBase); } } } else { if (hoverVar != null && selectedNode != null && hoverNode.equals(selectedNode)) { selectedString = hoverString; samplecount = 0; repaint(); } else { if (hoverSample == -1) { if (hoverNode != null) { if (selectedNode != null && selectedNode.equals(hoverNode)) { selectedString = null; selectedNode = null; hoverVar = null; selectedVar = null; aminoarray.clear(); this.setPreferredSize(new Dimension(this.getWidth(), (this.getTableSize() + 2) * rowHeight)); this.revalidate(); repaint(); break; } selectedNode = hoverNode; selectedString = hoverString; // samplecount = selectedNode.mutations; samplecount = selectedNode.varnodes.size(); if (VariantHandler.tabs.getSelectedIndex() == 0) { this.setPreferredSize(new Dimension(this.getWidth(), (this.getTableSize() + 2 + samplecount) * rowHeight)); this.revalidate(); getAminos(selectedNode); this.repaint(); } else { this.setPreferredSize(new Dimension(this.getWidth(), (this.getTableSize() + 2 + samplecount) * rowHeight)); this.revalidate(); getAminos(selectedNode); repaint(); } } } } } } } break; } case InputEvent.BUTTON3_MASK: { selectedString = null; selectedNode = null; hoverVar = null; selectedVar = null; aminoarray.clear(); this.setPreferredSize(new Dimension(this.getWidth(), (this.getTableSize() + 2) * rowHeight)); this.revalidate(); repaint(); } } }
From source file:graph.eventhandlers.MyEditingGraphMousePlugin.java
/** * If the mouse is pressed in an empty area, create a new vertex there. If * the mouse is pressed on an existing vertex, prepare to create an edge * from that vertex to another//from w ww . j a va2 s . c om */ public void mousePressed(MouseEvent e) { pw = graphInstance.getPathway(); if (checkModifiers(e)) { final VisualizationViewer<BiologicalNodeAbstract, BiologicalEdgeAbstract> vv = (VisualizationViewer<BiologicalNodeAbstract, BiologicalEdgeAbstract>) e .getSource(); // final Point2D p = vv.inverseViewTransform(e.getPoint()); // System.out.println("Points: "+e.getPoint().getX()+", "+e.getPoint().getY()); final Point2D p = vv.getRenderContext().getMultiLayerTransformer().inverseTransform(e.getPoint()); // System.out.println(e.getPoint()+ " "+p); // System.out.println("Points: "+p.getX()+", "+p.getY()); // final Point2D p = e.getPoint(); GraphElementAccessor<BiologicalNodeAbstract, BiologicalEdgeAbstract> pickSupport = vv.getPickSupport(); // System.out.println("Click: "+p); // System.out.println("regul: "+e.getPoint()); Iterator<BiologicalNodeAbstract> it = pw.getGraph().getAllVertices().iterator(); // while(it.hasNext()){ // System.out.println(pw.getGraph().getVertexLocation(it.next())); // } // System.out.println(pw.getGraph().getAllEdges().size()); // System.out.println(pickSupport.g); BiologicalNodeAbstract vertex = null; vertex = (BiologicalNodeAbstract) pickSupport.getVertex(vv.getGraphLayout(), e.getPoint().getX(), e.getPoint().getY()); // System.out.println(vertex); if (vertex != null) { // get ready to make an edge // System.out.println(vertex); startVertex = vertex; super.down = e.getPoint(); transformEdgeShape(down, down); vv.addPostRenderPaintable(edgePaintable); if ((e.getModifiers() & InputEvent.SHIFT_MASK) != 0) { edgeIsDirected = true; transformArrowShape(down, e.getPoint()); vv.addPostRenderPaintable(arrowPaintable); } } else { // make a new vertex Graph<BiologicalNodeAbstract, BiologicalEdgeAbstract> graph = vv.getGraphLayout().getGraph(); // BiologicalNodeAbstract newVertex = new BiologicalNodeAbstract( // "label", "name"); // vertexLocations.put(newVertex, p); Layout<BiologicalNodeAbstract, BiologicalEdgeAbstract> layout = vv.getGraphLayout(); // System.out.println("size V: "+layout.getGraph().getVertices().size()); // System.out.println("size E: "+layout.getGraph().getEdges().size()); // graph.addVertex(newVertex); /* * Object key = (((AggregateLayout) * layout).getDelegate()).getBaseKey(); Object datum = new * Coordinates(vv.inverseTransform( e.getPoint()).getX(), * vv.inverseTransform( e.getPoint()).getY()); * newVertex.setUserDatum(key, datum, new CopyAction.Clone()); */ for (Iterator<BiologicalNodeAbstract> iterator = graph.getVertices().iterator(); iterator .hasNext();) { layout.lock(iterator.next(), true); } if (con.isPetriView()) { // System.out.println("is petri"); PetriNetVertexDialog dialog = new PetriNetVertexDialog(con.getPetriNetEditingMode()); BiologicalNodeAbstract bna = dialog.getAnswer(p); // System.out.println(); if (bna != null) { // BiologicalNodeAbstract ba = new // BiologicalNodeAbstract( // answers[0], "", newVertex); // ba.setBiologicalElement(answers[1]); // ba.setCompartment(answers[2]); // graphInstance.getPathway().addElement(ba); // graph.addVertex(newVertex); // vv.getModel().restart(); //System.out.println("update"); if (pw instanceof BiologicalNodeAbstract) { bna.setParentNode((BiologicalNodeAbstract) pw); } MainWindowSingleton.getInstance().updateElementTree(); MainWindowSingleton.getInstance().updatePathwayTree(); //MainWindowSingelton.getInstance().updateAllGuiElements(); //MainWindowSingelton.getInstance().updateOptionPanel(); // MainWindowSingelton.getInstance() // .updateTheoryProperties(); // Pathway pw = graphInstance.getPathway(); } } else { // System.out.println("not petri"); VertexDialog dialog = new VertexDialog(); String[] answers = dialog.getAnswer(); if (answers != null) { // BiologicalNodeAbstract ba = new // BiologicalNodeAbstract( // answers[0], ""); String name = answers[0]; String label = answers[0]; String element = answers[1]; String compartment = answers[2]; // newVertex.setBiologicalElement(answers[1]); // newVertex.setCompartment(answers[2]); // graphInstance.getPathway().addElement(newVertex); // graph.addVertex(newVertex); BiologicalNodeAbstract newVertex = pw.addVertex(name, label, element, compartment, p); if (pw instanceof BiologicalNodeAbstract) { newVertex.setParentNode((BiologicalNodeAbstract) pw); } //pw.addVertex(newVertex, p); if (graph.getVertices().size() > 1) { // System.exit(0); } // pw.getGraph().setVertexLocation(newVertex, p); // layout.setLocation(newVertex, p); // vv.getModel().restart(); MainWindowSingleton.getInstance().updateElementTree(); // MainWindowSingelton.getInstance() // .updateTheoryProperties(); for (Iterator<BiologicalNodeAbstract> iterator = graph.getVertices().iterator(); iterator .hasNext();) { layout.lock(iterator.next(), false); } } } if (pw instanceof BiologicalNodeAbstract) { } } vv.repaint(); } }
From source file:ExText.java
/** * Process a new wakeup. Interpret mouse button presses, releases, and mouse * drags.//w w w . ja v a 2s . co m * * @param criteria * The wakeup criteria causing the behavior wakeup. */ public void processStimulus(Enumeration criteria) { WakeupCriterion wakeup = null; AWTEvent[] event = null; int whichButton = BUTTONNONE; // Process all pending wakeups while (criteria.hasMoreElements()) { wakeup = (WakeupCriterion) criteria.nextElement(); if (wakeup instanceof WakeupOnAWTEvent) { event = ((WakeupOnAWTEvent) wakeup).getAWTEvent(); // Process all pending events for (int i = 0; i < event.length; i++) { if (event[i].getID() != MouseEvent.MOUSE_PRESSED && event[i].getID() != MouseEvent.MOUSE_RELEASED && event[i].getID() != MouseEvent.MOUSE_DRAGGED) // Ignore uninteresting mouse events continue; // // Regretably, Java event handling (or perhaps // underlying OS event handling) doesn't always // catch button bounces (redundant presses and // releases), or order events so that the last // drag event is delivered before a release. // This means we can get stray events that we // filter out here. // if (event[i].getID() == MouseEvent.MOUSE_PRESSED && buttonPressed != BUTTONNONE) // Ignore additional button presses until a release continue; if (event[i].getID() == MouseEvent.MOUSE_RELEASED && buttonPressed == BUTTONNONE) // Ignore additional button releases until a press continue; if (event[i].getID() == MouseEvent.MOUSE_DRAGGED && buttonPressed == BUTTONNONE) // Ignore drags until a press continue; MouseEvent mev = (MouseEvent) event[i]; int modifiers = mev.getModifiers(); // // Unfortunately, the underlying event handling // doesn't do a "grab" operation when a mouse button // is pressed. This means that once a button is // pressed, if another mouse button or a keyboard // modifier key is pressed, the delivered mouse event // will show that a different button is being held // down. For instance: // // Action Event // Button 1 press Button 1 press // Drag with button 1 down Button 1 drag // ALT press - // Drag with ALT & button 1 down Button 2 drag // Button 1 release Button 2 release // // The upshot is that we can get a button press // without a matching release, and the button // associated with a drag can change mid-drag. // // To fix this, we watch for an initial button // press, and thenceforth consider that button // to be the one held down, even if additional // buttons get pressed, and despite what is // reported in the event. Only when a button is // released, do we end such a grab. // if (buttonPressed == BUTTONNONE) { // No button is pressed yet, figure out which // button is down now and how to direct events if (((modifiers & InputEvent.BUTTON3_MASK) != 0) || (((modifiers & InputEvent.BUTTON1_MASK) != 0) && ((modifiers & InputEvent.CTRL_MASK) == InputEvent.CTRL_MASK))) { // Button 3 activity (META or CTRL down) whichButton = BUTTON3; } else if ((modifiers & InputEvent.BUTTON2_MASK) != 0) { // Button 2 activity (ALT down) whichButton = BUTTON2; } else { // Button 1 activity (no modifiers down) whichButton = BUTTON1; } // If the event is to press a button, then // record that that button is now down if (event[i].getID() == MouseEvent.MOUSE_PRESSED) buttonPressed = whichButton; } else { // Otherwise a button was pressed earlier and // hasn't been released yet. Assign all further // events to it, even if ALT, META, CTRL, or // another button has been pressed as well. whichButton = buttonPressed; } // Distribute the event switch (whichButton) { case BUTTON1: onButton1(mev); break; case BUTTON2: onButton2(mev); break; case BUTTON3: onButton3(mev); break; default: break; } // If the event is to release a button, then // record that that button is now up if (event[i].getID() == MouseEvent.MOUSE_RELEASED) buttonPressed = BUTTONNONE; } continue; } if (wakeup instanceof WakeupOnElapsedFrames) { onElapsedFrames((WakeupOnElapsedFrames) wakeup); continue; } } // Reschedule us for another wakeup wakeupOn(mouseCriterion); }
From source file:org.gumtree.vis.awt.time.TimePlotPanel.java
@Override public void mouseClicked(MouseEvent event) { Insets insets = getInsets();//from www. j a v a2 s. c o m int x = (int) ((event.getX() - insets.left) / getScaleX()); int y = (int) ((event.getY() - insets.top) / getScaleY()); setAnchor(new Point2D.Double(x, y)); if (getChart() == null) { return; } // getChart().setNotify(true); // force a redraw // new entity code... // if (listeners.length == 0) { // return; // } ChartEntity entity = null; if (getChartRenderingInfo() != null) { EntityCollection entities = getChartRenderingInfo().getEntityCollection(); if (entities != null) { entity = entities.getEntity(x, y); if (entity instanceof XYItemEntity) { XYItemEntity xyEntity = (XYItemEntity) entity; // XYDataset dataset = xyEntity.getDataset(); // int item = ((XYItemEntity) entity).getItem(); // chartX = dataset.getXValue(xyEntity.getSeriesIndex(), item); // chartY = dataset.getYValue(xyEntity.getSeriesIndex(), item); // Point2D screenPoint = ChartMaskingUtilities.translateChartPoint( // new Point2D.Double(chartX, chartY), getScreenDataArea(), getChart()); // if (getHorizontalAxisTrace()) { // horizontalTraceLocation = (int) screenPoint.getX(); // } // if (getVerticalAxisTrace()) { // verticalTraceLocation = (int) screenPoint.getY(); // } if ((event.getModifiers() & seriesSelectionEventMask) != 0 && (event.getModifiers() & MouseEvent.BUTTON1_MASK) != 0) { XYDataset dataset = xyEntity.getDataset(); if (dataset instanceof IDataset) { selectSeries((IDataset) xyEntity.getDataset(), xyEntity.getSeriesIndex()); } } else if ((event.getModifiers() & maskingSelectionMask) == 0 && (event.getModifiers() & MouseEvent.BUTTON1_MASK) != 0) { if (selectedSeriesIndex != xyEntity.getSeriesIndex()) { selectSeries(null, -1); } } } else { if (selectedSeriesIndex >= 0) { if ((event.getModifiers() & seriesSelectionEventMask) != 0 && (event.getModifiers() & maskingSelectionMask) == 0 && (event.getModifiers() & MouseEvent.BUTTON1_MASK) != 0) { selectSeries(null, -1); } } } } } if ((event.getModifiers() & MouseEvent.BUTTON1_MASK) != 0) { double chartX = ChartMaskingUtilities.translateScreenX(x, getScreenDataArea(), getChart()); int selectedDatasetIndex = 0; if (selectedDataset != null) { selectedDatasetIndex = getXYPlot().indexOf(selectedDataset); } double chartY = ChartMaskingUtilities.translateScreenY(y, getScreenDataArea(), getChart(), selectedDatasetIndex); setHorizontalTraceLocation(x); setVerticalTraceLocation(y); setChartX(chartX); setChartY(chartY); repaint(); } XYChartMouseEvent chartEvent = new XYChartMouseEvent(getChart(), event, entity); chartEvent.setXY(getChartX(), getChartY()); Object[] listeners = getListeners(ChartMouseListener.class); for (int i = listeners.length - 1; i >= 0; i -= 1) { ((ChartMouseListener) listeners[i]).chartMouseClicked(chartEvent); } System.out.println("chartX = " + getChartX() + ", chartY = " + getChartY()); }
From source file:org.gumtree.vis.hist2d.Hist2DPanel.java
private void makeNewMask(MouseEvent e, EntityCollection entities) { if (this.maskPoint == null) { return;/* www. ja va 2 s .c om*/ } 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; boolean isEllipse = (e.getModifiers() & MouseEvent.BUTTON3_MASK) != 0; if (isEllipse) { currentMaskRectangle = new EllipseMask(isInclusive); } else { currentMaskRectangle = new RectangleMask(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()); double ymax = Math.min(e.getY(), scaledDataArea.getMaxY()); // Update the current mask. ChartEntity startEntity = null; ChartEntity endEntity = null; boolean isMaskUpdated = false; if (entities != null) { // EntityCollection entities = this.info.getEntityCollection(); // if (entities != null) { Insets insets = getInsets(); double screenX = (maskPoint.getX() - insets.left) / getScaleX(); double screenY = (maskPoint.getY() - insets.top) / getScaleY(); startEntity = entities.getEntity(screenX, screenY); screenX = (xmax - insets.left) / getScaleX(); screenY = (ymax - insets.top) / getScaleY(); if (screenX >= scaledDataArea.getMaxX()) { screenX = scaledDataArea.getMaxX() - 0.001; } if (screenY >= scaledDataArea.getMaxY()) { screenY = scaledDataArea.getMaxY() - 0.001; } endEntity = entities.getEntity(screenX, screenY); // System.out.println("Try to update mask"); if (startEntity instanceof XYItemEntity && endEntity instanceof XYItemEntity) { isMaskUpdated = updateCurrentMaskRectangle((XYItemEntity) startEntity, (XYItemEntity) endEntity); } // } } if (!isMaskUpdated) { currentMaskRectangle.setRectangleFrame(new Rectangle2D.Double(maskPoint.getX(), this.maskPoint.getY(), xmax - this.maskPoint.getX(), ymax - this.maskPoint.getY())); } // 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:com.rapidminer.gui.plotter.charts.AbstractChartPanel.java
/** * Handles a 'mouse pressed' event./*w w w. j a v a 2s . c om*/ * <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. */ @Override public void mousePressed(MouseEvent e) { if (this.chart == null) { return; } Plot plot = this.chart.getPlot(); int mods = e.getModifiers(); if ((mods & this.panMask) == this.panMask) { // can we pan this plot? if (plot instanceof Pannable) { Rectangle2D screenDataArea = getScreenDataArea(e.getX(), e.getY()); if (screenDataArea != null && screenDataArea.contains(e.getPoint())) { this.panW = screenDataArea.getWidth(); this.panH = screenDataArea.getHeight(); this.panLast = e.getPoint(); setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); } } } else if (this.selectionRectangle == 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()); } } } }