List of usage examples for java.awt Graphics2D setXORMode
public abstract void setXORMode(Color c1);
From source file:org.eurocarbdb.application.glycoworkbench.plugin.SpectraPanel.java
public void mouseDragged(MouseEvent e) { if (mouse_start_point != null && theDocument.getNoScans() > 0) { if (is_moving) { // moving double mz_delta = screenToDataX(mouse_start_point.getX() - e.getPoint().getX()); if (mz_delta > 0.) { double old_upper_bound = thePlot.getDomainAxis().getUpperBound(); double old_lower_bound = thePlot.getDomainAxis().getLowerBound(); double new_upper_bound = Math.min(old_upper_bound + mz_delta, theDocument.getPeakDataAt(current_ind).getMaxMZ()); double new_lower_bound = old_lower_bound + new_upper_bound - old_upper_bound; thePlot.getDomainAxis().setRange(new Range(new_lower_bound, new_upper_bound)); } else { double old_upper_bound = thePlot.getDomainAxis().getUpperBound(); double old_lower_bound = thePlot.getDomainAxis().getLowerBound(); double new_lower_bound = Math.max(old_lower_bound + mz_delta, theDocument.getPeakDataAt(current_ind).getMinMZ()); double new_upper_bound = old_upper_bound + new_lower_bound - old_lower_bound; thePlot.getDomainAxis().setRange(new Range(new_lower_bound, new_upper_bound)); }//from w w w . j a va2s . co m mouse_start_point = e.getPoint(); } else { // zooming Graphics2D g2 = (Graphics2D) theChartPanel.getGraphics(); g2.setXORMode(java.awt.Color.gray); // delete old rectangle if (zoom_rectangle != null) g2.draw(zoom_rectangle); // create new rectangle double start_x = Math.min(e.getX(), mouse_start_point.getX()); double end_x = Math.max(e.getX(), mouse_start_point.getX()); Rectangle2D data_area = theChartPanel.getScreenDataArea((int) start_x, (int) mouse_start_point.getY()); double xmax = Math.min(end_x, data_area.getMaxX()); zoom_rectangle = new Rectangle2D.Double(start_x, data_area.getMinY(), xmax - start_x, data_area.getHeight()); // draw new rectangle g2.draw(zoom_rectangle); g2.dispose(); } } }
From source file:org.gvsig.remotesensing.scatterplot.chart.ScatterPlotDiagram.java
/** * * Pinta el rectangulo sombreado mientras se realiza la seleccin * @param g2 the graphics device. /*ww w . j av a 2 s .co m*/ */ private void drawRectangle(Graphics2D g2) { // Set XOR mode to draw the zoom rectangle g2.setXORMode(Color.gray); if (this.zoomRectangle != null) { if (this.fillZoomRectangle) { g2.fill(this.zoomRectangle); } else { g2.draw(this.zoomRectangle); } } // Reset to the default 'overwrite' mode g2.setPaintMode(); }
From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.link_and_brush.LinkAndBrushChartPanel.java
/** * Draws zoom rectangle (if present). The drawing is performed in XOR mode, therefore when this * method is called twice in a row, the second call will completely restore the state of the * canvas.//from w ww . ja v a2 s.c om * * @param g2 * the graphics device. * @param xor * use XOR for drawing? */ private void drawZoomRectangle(Graphics2D g2, boolean xor) { Rectangle2D zoomRectangle = (Rectangle2D) getChartFieldValueByName("zoomRectangle"); if (zoomRectangle != null) { // fix rectangle parameters when chart is transformed zoomRectangle = coordinateTransformation.transformRectangle(zoomRectangle, this); if (!(coordinateTransformation instanceof NullCoordinateTransformation)) { g2 = coordinateTransformation.getTransformedGraphics(this); } if (xor) { // Set XOR mode to draw the zoom rectangle g2.setXORMode(Color.gray); } if ((Boolean) getChartFieldValueByName("fillZoomRectangle")) { g2.setPaint((Paint) getChartFieldValueByName("zoomFillPaint")); g2.fill(zoomRectangle); } else { g2.setPaint((Paint) getChartFieldValueByName("zoomOutlinePaint")); g2.draw(zoomRectangle); } if (xor) { // Reset to the default 'overwrite' mode g2.setPaintMode(); } } }
From source file:HelloUniverse.java
private void drawXPip(Graphics2D g2, float angle) { AffineTransform trans = new AffineTransform(); int y;// w w w . j av a2 s.c om int xOrig = margin + diameter + space; int yOrig = margin; Color origColor = g2.getColor(); if (angle <= Math.PI) { y = yOrig + diameter - (int) ((Math.abs(angle - Math.PI / 2) / (Math.PI / 2)) * diameter / 2); } else y = yOrig + (int) ((Math.abs((angle - Math.PI * 1.5)) / (Math.PI / 2)) * diameter / 2); if (angle < Math.PI / 2 || angle > Math.PI * 1.5) g2.setColor(Color.red); // Infront of wheel else { g2.setColor(Color.black); // Behind Wheel g2.setClip(xBackClip); } g2.setXORMode(getBackground()); trans.setToTranslation(xOrig + pipOffset, y); g2.setTransform(trans); g2.fillPolygon(xPip); // Reset graphics context trans.setToIdentity(); g2.setTransform(trans); g2.setColor(origColor); g2.setPaintMode(); }
From source file:HelloUniverse.java
private void drawYPip(Graphics2D g2, float angle) { AffineTransform trans = new AffineTransform(); int x;/*w w w .j av a 2 s . c om*/ int xOrig = margin; int yOrig = margin + diameter + space; Color origColor = g2.getColor(); if (angle <= Math.PI) { x = xOrig + diameter - (int) ((Math.abs(angle - Math.PI / 2) / (Math.PI / 2)) * diameter / 2); } else x = xOrig + (int) ((Math.abs((angle - Math.PI * 1.5)) / (Math.PI / 2)) * diameter / 2); if (angle < Math.PI / 2 || angle > Math.PI * 1.5) g2.setColor(Color.red); // Infront on wheel else { g2.setColor(Color.black); // Behind Wheel g2.setClip(yBackClip); } g2.setXORMode(getBackground()); trans.setToTranslation(x, yOrig + pipOffset); g2.setTransform(trans); g2.fillPolygon(yPip); // Reset graphics context trans.setToIdentity(); g2.setTransform(trans); g2.setColor(origColor); g2.setPaintMode(); }
From source file:org.tsho.dmc2.core.chart.jfree.DmcChartPanel.java
/** * Handles a 'mouse exited' event./*from w ww . j a va 2 s . co m*/ * <P> * This method does nothing, but is required for implementation of the MouseListener * interface. * * @param e the mouse event. */ public void mouseExited(MouseEvent e) { Graphics2D g2 = (Graphics2D) getGraphics(); Rectangle2D dataArea = getScaledDataArea(); g2.setXORMode(java.awt.Color.orange); if (verticalTraceLine != null) { g2.draw(verticalTraceLine); verticalTraceLine = null; } if (horizontalTraceLine != null) { g2.draw(horizontalTraceLine); horizontalTraceLine = null; } }
From source file:org.tsho.dmc2.core.chart.jfree.DmcChartPanel.java
/** * Handles a 'mouse released' event./*from w w w.j a v a2s . c o m*/ * <P> * On Windows, we need to check if this is a popup trigger, but only if we * haven't already been tracking a zoom rectangle. * * @param e Information about the event. */ public void mouseReleased(MouseEvent e) { if (zoomRectangle != null) { // if (Math.abs(e.getX() - zoomPoint.getX()) >= MINIMUM_DRAG_ZOOM_SIZE) { if (Math.abs(e.getX() - zoomPoint.getX()) >= 7) { if (e.getX() < zoomPoint.getX() || e.getY() < zoomPoint.getY()) { autoRangeBoth(); } else { double x, y, w, h; Rectangle2D scaledDataArea = getScaledDataArea(); //for a mouseReleased event, (horizontalZoom || verticalZoom) //will be true, so we can just test for either being false; //otherwise both are true if (!verticalZoom) { x = zoomPoint.getX(); y = scaledDataArea.getMinY(); w = Math.min(zoomRectangle.getWidth(), scaledDataArea.getMaxX() - zoomPoint.getX()); h = scaledDataArea.getHeight(); } else if (!horizontalZoom) { x = scaledDataArea.getMinX(); y = zoomPoint.getY(); w = scaledDataArea.getWidth(); h = Math.min(zoomRectangle.getHeight(), scaledDataArea.getMaxY() - zoomPoint.getY()); } else { x = zoomPoint.getX(); y = zoomPoint.getY(); w = Math.min(zoomRectangle.getWidth(), scaledDataArea.getMaxX() - zoomPoint.getX()); h = Math.min(zoomRectangle.getHeight(), scaledDataArea.getMaxY() - zoomPoint.getY()); } Rectangle2D zoomArea = new Rectangle2D.Double(x, y, w, h); zoom(zoomArea); } this.zoomPoint = null; this.zoomRectangle = null; } else { Graphics2D g2 = (Graphics2D) getGraphics(); g2.setXORMode(java.awt.Color.gray); if (fillZoomRectangle) { g2.fill(zoomRectangle); } else { g2.draw(zoomRectangle); } g2.dispose(); this.zoomRectangle = null; } // notify a redraw event CoreStatusEvent ev = new CoreStatusEvent(this); ev.setType(CoreStatusEvent.REDRAW); ((AbstractDmcPlot) chart.getPlot()).notifyCoreStatusListeners(ev); } else if (e.isPopupTrigger()) { if (popup != null) { displayPopupMenu(e.getX(), e.getY()); } } }
From source file:org.tsho.dmc2.core.chart.jfree.DmcChartPanel.java
/** * Draws a vertical line used to trace the mouse position to the horizontal axis. * * @param x the x-coordinate of the trace line. *///from w w w . jav a 2 s . c o m private void drawHorizontalAxisTrace(int x) { Graphics2D g2 = (Graphics2D) getGraphics(); Rectangle2D dataArea = getScaledDataArea(); g2.setXORMode(java.awt.Color.orange); if (((int) dataArea.getMinX() < x) && (x < (int) dataArea.getMaxX())) { if (verticalTraceLine != null) { g2.draw(verticalTraceLine); verticalTraceLine.setLine(x, (int) dataArea.getMinY(), x, (int) dataArea.getMaxY()); } else { verticalTraceLine = new Line2D.Float(x, (int) dataArea.getMinY(), x, (int) dataArea.getMaxY()); } g2.draw(verticalTraceLine); } else { if (horizontalTraceLine != null) { g2.draw(horizontalTraceLine); horizontalTraceLine = null; } if (verticalTraceLine != null) { g2.draw(verticalTraceLine); verticalTraceLine = null; } } }
From source file:org.tsho.dmc2.core.chart.jfree.DmcChartPanel.java
/** * Draws a horizontal line used to trace the mouse position to the vertical axis. * * @param y the y-coordinate of the trace line. *///w ww.j ava 2 s . co m private void drawVerticalAxisTrace(int y) { Graphics2D g2 = (Graphics2D) getGraphics(); Rectangle2D dataArea = getScaledDataArea(); g2.setXORMode(java.awt.Color.orange); if (((int) dataArea.getMinY() < y) && (y < (int) dataArea.getMaxY())) { if (horizontalTraceLine != null) { g2.draw(horizontalTraceLine); horizontalTraceLine.setLine((int) dataArea.getMinX(), y, (int) dataArea.getMaxX(), y); } else { horizontalTraceLine = new Line2D.Float((int) dataArea.getMinX(), y, (int) dataArea.getMaxX(), y); } g2.draw(horizontalTraceLine); } else { if (verticalTraceLine != null) { g2.draw(verticalTraceLine); verticalTraceLine = null; } if (horizontalTraceLine != null) { g2.draw(horizontalTraceLine); horizontalTraceLine = null; } } }
From source file:org.tsho.dmc2.core.chart.jfree.DmcChartPanel.java
/** * Handles a 'mouse dragged' event./*from w w w . j av a 2s . c om*/ * * @param e the mouse event. */ public void mouseDragged(MouseEvent e) { if (this.zoomingEnabled) { // if the popup menu has already been triggered, then ignore dragging... if (popup != null && popup.isShowing()) { return; } Graphics2D g2 = (Graphics2D) getGraphics(); // use XOR to erase the previous zoom rectangle (if any)... g2.setXORMode(java.awt.Color.gray); if (zoomRectangle != null) { if (fillZoomRectangle) { g2.fill(zoomRectangle); } else { g2.draw(zoomRectangle); } } Rectangle2D scaledDataArea = getScaledDataArea(); if (this.horizontalZoom && this.verticalZoom) { // 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()); zoomRectangle = new Rectangle2D.Double(zoomPoint.getX(), zoomPoint.getY(), xmax - zoomPoint.getX(), ymax - zoomPoint.getY()); } else if (this.horizontalZoom) { double xmax = Math.min(e.getX(), scaledDataArea.getMaxX()); zoomRectangle = new Rectangle2D.Double(zoomPoint.getX(), scaledDataArea.getMinY(), xmax - zoomPoint.getX(), scaledDataArea.getHeight()); } else if (this.verticalZoom) { double ymax = Math.min(e.getY(), scaledDataArea.getMaxY()); zoomRectangle = new Rectangle2D.Double(scaledDataArea.getMinX(), zoomPoint.getY(), scaledDataArea.getWidth(), ymax - zoomPoint.getY()); } if (zoomRectangle != null) { // use XOR to draw the new zoom rectangle... if (fillZoomRectangle) { g2.fill(zoomRectangle); } else { g2.draw(zoomRectangle); } } g2.dispose(); } }