List of usage examples for java.awt.event MouseEvent isShiftDown
public boolean isShiftDown()
From source file:net.bioclipse.model.ScatterPlotMouseHandler.java
@Override public void mousePressed(MouseEvent e) { super.mousePressed(e); ChartPanel chartPanel = getChartPanel(e); startX = e.getX();/*from w w w. j a va2s .c o m*/ startY = e.getY(); if (!e.isShiftDown()) { ((ScatterPlotRenderer) ((XYPlot) chartPanel.getChart().getPlot()).getRenderer()).clearMarkedPoints(); currentSelection = new ChartSelection(); chartPanel.getChart().plotChanged(new PlotChangeEvent(chartPanel.getChart().getPlot())); } else { ((ScatterPlotRenderer) ((XYPlot) chartPanel.getChart().getPlot()).getRenderer()) .removeMarkedPoint(null); } if (currentSelection == null) { currentSelection = new ChartSelection(); } mouseDragSelection = new ChartSelection(); currentSelection.setDescriptor(ChartUtils.getChartDescriptor(chartPanel.getChart())); }
From source file:ucar.unidata.idv.control.chart.RangeFilter.java
/** * Set the position from the mouse/*from w w w .j a v a 2 s .c om*/ * * @param event mouse event */ public void setPosition(MouseEvent event) { int diff = event.getY() - y; setPosition(event.getX(), event.getY()); if ((attached != null) && event.isShiftDown()) { attached.setPosition(event.getX(), attached.y + diff); } }
From source file:TransferableScribblePane.java
/** * This method is called on mouse button events. It begins a new line or tries * to select an existing line./* w w w . j ava2 s . com*/ */ public void processMouseEvent(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { // Left mouse button if (e.getID() == MouseEvent.MOUSE_PRESSED) { // Pressed down if (e.isShiftDown()) { // with Shift key // If the shift key is down, try to select a line int x = e.getX(); int y = e.getY(); // Loop through the lines checking to see if we hit one PolyLine selection = null; int numlines = lines.size(); for (int i = 0; i < numlines; i++) { PolyLine line = (PolyLine) lines.get(i); if (line.intersects(x - 2, y - 2, 4, 4)) { selection = line; e.consume(); break; } } // If we found an intersecting line, save it and repaint if (selection != selectedLine) { // If selection changed selectedLine = selection; // remember which is selected repaint(); // will make selection dashed } } else if (!e.isControlDown()) { // no shift key or ctrl key // Start a new line on mouse down without shift or ctrl currentLine = new PolyLine(e.getX(), e.getY()); lines.add(currentLine); e.consume(); } } else if (e.getID() == MouseEvent.MOUSE_RELEASED) {// Left Button Up // End the line on mouse up if (currentLine != null) { currentLine = null; e.consume(); } } } // The superclass method dispatches to registered event listeners super.processMouseEvent(e); }
From source file:com.hexidec.ekit.component.RelativeImageView.java
/** Resize image if initial click was in grow-box: */ public void mouseDragged(MouseEvent e) { if (fGrowBase != null) { Point loc = fComponent.getLocationOnScreen(); int width = Math.max(2, loc.x + e.getX() - fGrowBase.x); int height = Math.max(2, loc.y + e.getY() - fGrowBase.y); if (e.isShiftDown() && fImage != null) { // Make sure size is proportional to actual image size float imgWidth = fImage.getWidth(this); float imgHeight = fImage.getHeight(this); if ((imgWidth > 0) && (imgHeight > 0)) { float prop = imgHeight / imgWidth; float pwidth = height / prop; float pheight = width * prop; if (pwidth > width) { width = (int) pwidth; } else { height = (int) pheight; }// w ww.j a v a 2 s .c om } } resize(width, height); } }
From source file:com.hexidec.ekit.component.RelativeImageView.java
/** Select or grow image when clicked. *//*from w w w . j a v a 2 s . co m*/ public void mousePressed(MouseEvent e) { Dimension size = fComponent.getSize(); if ((e.getX() >= (size.width - 7)) && (e.getY() >= (size.height - 7)) && (getSelectionState() == 2)) { // Click in selected grow-box: Point loc = fComponent.getLocationOnScreen(); fGrowBase = new Point(loc.x + e.getX() - fWidth, loc.y + e.getY() - fHeight); fGrowProportionally = e.isShiftDown(); } else { // Else select image: fGrowBase = null; JTextComponent comp = (JTextComponent) fContainer; int start = fElement.getStartOffset(); int end = fElement.getEndOffset(); int mark = comp.getCaret().getMark(); int dot = comp.getCaret().getDot(); if (e.isShiftDown()) { // extend selection if shift key down: if (mark <= start) { comp.moveCaretPosition(end); } else { comp.moveCaretPosition(start); } } else { // just select image, without shift: if (mark != start) { comp.setCaretPosition(start); } if (dot != end) { comp.moveCaretPosition(end); } } } }
From source file:lu.lippmann.cdb.graph.mouse.CadralGraphMouse.java
/** * {@inheritDoc}/*from w w w . j av a 2s . c o m*/ * Mode.PICKING : Move node & edge * Mode.EDITING : Add node & edge * Mode.TRANSFORMING : Move graph layout */ @Override public void mousePressed(MouseEvent e) { before.clear(); //System.out.println("Before map cleared"); if (!mode.equals(Mode.EDITING)) { @SuppressWarnings("unchecked") 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()); final CEdge edge = pickSupport.getEdge(layout, p.getX(), p.getY()); if (mode.equals(Mode.TRANSFORMING)) { if (vertex != null || edge != null) { setMode(Mode.PICKING); vv.setCursor(Cursor.getPredefinedCursor(12)); } if ((vertex == null && edge == null) && (e.isShiftDown())) { setMode(Mode.PICKING); vv.setCursor(Cursor.getPredefinedCursor(12)); } } else if (mode.equals(Mode.PICKING) && !e.isShiftDown()) { if (vertex == null && edge == null) { setMode(Mode.TRANSFORMING); } } //Final choosen mode is transforming ! -> Deselect all nodes if (mode.equals(Mode.TRANSFORMING)) { commandDispatcher.dispatch(new DeselectAllCommand()); } //Save initial positions if (mode.equals(Mode.PICKING)) { if (vertex != null) { saveInitialPositionOfPickedNodes(vv); } } } } //will call either : // - CadralEditingGraphMousePlugin.mousePressed(e) // - CadralPickingGraphMousePlugin.mousePressed(e) super.mousePressed(e); //System.out.println("Coords clicked : " + e.getPoint()); }
From source file:net.bioclipse.model.ScatterPlotMouseHandler.java
public void mouseClicked(MouseEvent me) { Point2D p = null;/*from ww w . j a va2 s . c om*/ ChartDescriptor cd = null; int[] indices = null; JFreeChart selectedChart = null; ChartPanel chartPanel = getChartPanel(me); p = chartPanel.translateScreenToJava2D(new Point(me.getX(), me.getY())); selectedChart = chartPanel.getChart(); cd = ChartUtils.getChartDescriptor(selectedChart); indices = cd.getSourceIndices(); XYPlot plot = (XYPlot) chartPanel.getChart().getPlot(); XYItemRenderer plotRenderer = plot.getRenderer(); if (!(plotRenderer instanceof ScatterPlotRenderer)) { throw new IllegalStateException( "Charts using ScatterPlotMouseHandler must use ScatterPlotRenderer as their renderer"); } renderer = (ScatterPlotRenderer) plot.getRenderer(); // now convert the Java2D coordinate to axis coordinates... Number xx = getDomainX(chartPanel, plot, p); Number yy = getRangeY(chartPanel, plot, p); //Find the selected point in the dataset //If shift is down, save old selections if (!me.isShiftDown() || currentSelection == null) { currentSelection = new ChartSelection(); } for (int j = 0; j < plot.getDataset().getItemCount(plot.getDataset().getSeriesCount() - 1); j++) { for (int i = 0; i < plot.getDataset().getSeriesCount(); i++) { Number xK = plot.getDataset().getX(i, j); Number yK = plot.getDataset().getY(i, j); Number xKCheck = xK.doubleValue() - xx.doubleValue(); Number yKCheck = yK.doubleValue() - yy.doubleValue(); Number xxCheck = xKCheck.doubleValue() * xKCheck.doubleValue(); Number yyCheck = yKCheck.doubleValue() * yKCheck.doubleValue(); //Check distance from click and point, don't want to mark points that are too far from the click if (Math.sqrt(xxCheck.doubleValue()) <= 0.1 && Math.sqrt(yyCheck.doubleValue()) <= 0.1) { //Create a new selection PlotPointData cp = new PlotPointData(indices[j], cd.getXLabel(), cd.getYLabel()); cp.setDataPoint(j, i); currentSelection.addPoint(cp); if (!me.isShiftDown()) renderer.clearMarkedPoints(); renderer.addMarkedPoint(j, i); selectedChart.plotChanged(new PlotChangeEvent(plot)); } } } currentSelection.setDescriptor(cd); ChartUtils.updateSelection(currentSelection); }
From source file:org.fhcrc.cpl.viewer.mrm.utilities.MRMerMouseListener.java
public void mouseClicked(MouseEvent e) { if (e.getSource() instanceof ChartPanel && ((e.getButton() == MouseEvent.BUTTON2) || (e.getButton() == MouseEvent.BUTTON1) && ((e.getModifiers() & InputEvent.CTRL_MASK) != 0))) { CenterZoomNumberAxis czna = (CenterZoomNumberAxis) _cp.getChart().getXYPlot().getDomainAxis(); NumberAxis range = (NumberAxis) _cp.getChart().getXYPlot().getRangeAxis(); Rectangle2D screenDataArea = _cp.getScreenDataArea(e.getX(), e.getY()); double y1 = czna.getLowerBound(); double y2 = czna.getUpperBound(); double x1 = screenDataArea.getX(); double x2 = x1 + screenDataArea.getWidth(); double transformedx = (((y2 - y1) / (x2 - x1)) * (e.getX() - x1)) + y1; MRMDialog mrmd = (MRMDialog) MRMAncestor(); PeaksTableModel model = (PeaksTableModel) mrmd.peaksTable.getModel(); MRMTransition mrt = mrmd.transitionOnPlot; mrt.setCalcXatMaxYAllDaughters(transformedx); mrt.setCalcMaxYAllDaughters(//from w w w . j av a 2 s . c o m range.getLowerBound() + 0.95 * (range.getUpperBound() - range.getLowerBound())); model.setValueAt(new Float(mrt.getCalcXatMaxYAllDaughters()), mrt.getTableRow(), MRMDialog.peaksData.MidTime.colno); for (MRMDaughter d : mrt.getDaughters().values()) { model.setValueAt(new Float(mrt.getCalcXatMaxYAllDaughters()), d.getElutionDataTableRow(), MRMDialog.peaksData.MidTime.colno); } mrmd.updateChartsAndFields(false); } if ((e.isShiftDown() || e.getButton() == MouseEvent.BUTTON3) || shifted) { _cp.mouseClicked(e); } else { _cp.mouseClicked(e); } }
From source file:ucar.unidata.idv.control.chart.TimeSeriesChartWrapper.java
/** * Handle event in chart/* w w w . j a va2s . co m*/ * * @param event The event * * @return Did we handle this event */ public boolean chartPanelMouseDragged(MouseEvent event) { if (SwingUtilities.isRightMouseButton(event)) { return EVENT_DONTPASSON; } closestAnnotation = null; //Ignore shift down drag. if (event.isShiftDown()) { return EVENT_PASSON; } if (dragging && (draggedAnnotation == null)) { return EVENT_PASSON; } dragging = true; if (draggedAnnotation == null) { draggedAnnotation = findClosestAnnotation(getAllAnnotations(), event.getX(), event.getY(), true, event.isShiftDown()); } if (draggedAnnotation == null) { return EVENT_PASSON; } draggedAnnotation.setPosition(event); if (draggedAnnotation instanceof RangeFilter) { rangeFiltersChanged(); } if ((draggedAnnotation instanceof WayPoint) || (draggedAnnotation instanceof TrackSegment)) { Rectangle2D r = getChartPanel().getScreenDataArea(); if (event.getX() < r.getX()) { panPlot(false, 0.02); } else if (event.getX() > r.getX() + r.getWidth()) { panPlot(true, 0.02); } } signalChartChanged(); try { setLocationPositions(); } catch (Exception exc) { LogUtil.logException("Setting locations", exc); } return EVENT_DONTPASSON; }
From source file:it.cnr.icar.eric.client.ui.swing.graph.JBGraph.java
protected EdgeView createEdgeView(Edge e, CellMapper cm) { // Return Custom EdgeView return new EdgeView(e, this, cm) { /**//from w ww . j a v a 2 s .c o m * */ private static final long serialVersionUID = 6394582242914834862L; // Override Superclass Method public boolean isAddPointEvent(MouseEvent event) { // Points are Added using Shift-Click return event.isShiftDown(); } // Override Superclass Method public boolean isRemovePointEvent(MouseEvent event) { // Points are Removed using Shift-Click return event.isShiftDown(); } }; }