List of usage examples for java.awt Graphics2D setXORMode
public abstract void setXORMode(Color c1);
From source file:XORRectangles.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; // using white as the XOR color. g2.setXORMode(Color.white); // Paint a red rectangle. Rectangle2D r = new Rectangle2D.Double(50, 50, 150, 100); g2.setPaint(Color.red);/*from ww w .ja v a 2s .c o m*/ g2.fill(r); g2.transform(AffineTransform.getTranslateInstance(25, 25)); // Draw a blue rectangle. g2.setPaint(Color.blue); g2.fill(r); }
From source file:dbseer.gui.panel.DBSeerExplainChartPanel.java
private void drawSelectRectangle(Graphics2D g2) { if (selectRectangle != null) { g2.setXORMode(Color.GRAY); g2.fill(this.selectRectangle); g2.setPaintMode();/*from w w w . java 2 s. c o m*/ } }
From source file:org.fhcrc.cpl.toolbox.gui.chart.ChartMouseAndMotionListener.java
/** * Draws zoom rectangle (if present)./*from w w w.java2s.com*/ * 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. * * @param selectedRegion * @param stroke * @param fillColor */ protected void drawSelectedRegion(Rectangle2D selectedRegion, Stroke stroke, Color fillColor, boolean xorMode, Graphics2D g2) { // Set XOR mode to draw the zoom rectangle if (g2 == null) return; Paint origColor = g2.getPaint(); if (selectedRegion != null) { if (xorMode) { g2.setXORMode(fillColor); } else g2.setPaint(fillColor); g2.fill(selectedRegion); g2.setPaint(Color.black); g2.setStroke(stroke); if (xorMode) g2.setPaint(Color.white); else g2.setPaint(Color.black); g2.draw(selectedRegion); g2.setPaintMode(); g2.setPaint(origColor); } }
From source file:MWC.GUI.JFreeChart.StepperXYPlot.java
/** * draw the new stepper line into the plot * //from ww w .j a va2 s . com * @param g2 * @param linePosition * @param dataArea */ protected void plotStepperLine(final Graphics2D g2, final double linePosition, final Rectangle2D dataArea) { // prepare to draw final Stroke oldStroke = g2.getStroke(); g2.setXORMode(Color.darkGray); // thicken up the line g2.setStroke(new BasicStroke(3)); if (this.getOrientation() == PlotOrientation.VERTICAL) { // draw the line g2.drawLine((int) linePosition - 1, (int) dataArea.getY() + 1, (int) linePosition - 1, (int) dataArea.getY() + (int) dataArea.getHeight() - 1); } else { // draw the line g2.drawLine((int) dataArea.getY() + 1, (int) linePosition - 1, (int) dataArea.getY() + (int) dataArea.getHeight() - 1, (int) linePosition - 1); } // and restore everything g2.setStroke(oldStroke); g2.setPaintMode(); }
From source file:org.fhcrc.cpl.viewer.mrm.utilities.MRMerMouseListener.java
/** * Draws zoom rectangle (if present).// w ww . j a va2 s. c om * 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. * * @param g2 the graphics device. */ private void drawCoElutionRegion(Graphics2D g2) { // Set XOR mode to draw the zoom rectangle if (g2 == null) return; Paint origColor = g2.getPaint(); // g2.setXORMode(Color.gray); g2.setXORMode(new Color(30, 10, 30, 5)); if (this.coElutionRegion != null) { g2.fill(this.coElutionRegion); g2.setPaint(Color.white); g2.setStroke(new BasicStroke(3.0f)); g2.draw(this.coElutionRegion); } g2.setPaintMode(); g2.setPaint(origColor); }
From source file:com.projity.pm.graphic.graph.GraphInteractor.java
protected Graphics2D initGraphics() { Graph graph = getGraph();/*ww w . j a v a2 s . c o m*/ Graphics2D g = (Graphics2D) graph.getGraphics(); g.setColor(graph.getForeground()); g.setXORMode(graph.getBackground().darker()); return g; }
From source file:org.eurocarbdb.application.glycoworkbench.plugin.PeakListChartPanel.java
public void mouseReleased(MouseEvent e) { if (MouseUtils.isPopupTrigger(e)) { // clear all if (zoom_rectangle != null) { Graphics2D g2 = (Graphics2D) getGraphics(); g2.setXORMode(java.awt.Color.gray); g2.draw(zoom_rectangle);//from w ww. j av a 2s . c om g2.dispose(); } mouse_start_point = null; zoom_rectangle = null; // open popup current_peak = findPeakAt(e.getPoint()); enforceSelection(current_peak); createPopupMenu(current_peak != null).show(theChartPanel, e.getX(), e.getY()); } else { if (zoom_rectangle != null && mouse_start_point != null) { if (Math.abs(e.getX() - mouse_start_point.getX()) > 10) { //if( e.getX() < mouse_start_point.getX() ) { // unzoom all // onZoomNone(); //} //else { // zoom area 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 new_lower_bound = screenToDataCoordX(start_x); double new_upper_bound = screenToDataCoordX(Math.min(end_x, data_area.getMaxX())); thePlot.getDomainAxis().setRange(new Range(new_lower_bound, new_upper_bound)); } else { // clear rectangle Graphics2D g2 = (Graphics2D) getGraphics(); g2.setXORMode(java.awt.Color.gray); g2.draw(zoom_rectangle); g2.dispose(); } } // restore zooming if (!was_moving && is_moving) onActivateZooming(); zoom_rectangle = null; mouse_start_point = null; } }
From source file:org.eurocarbdb.application.glycoworkbench.plugin.PeakListChartPanel.java
public void mouseDragged(MouseEvent e) { if (mouse_start_point != null && theDocument.size() > 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.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.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 av a 2s . 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:HelloUniverse.java
private void drawZPip(Graphics2D g2, float zAngle) { AffineTransform trans = new AffineTransform(); Color origColor = g2.getColor(); trans.translate(margin, margin);/*from w w w . j a v a 2s .c o m*/ trans.rotate(zAngle, diameter / 2, diameter / 2); g2.setXORMode(getBackground()); g2.setTransform(trans); g2.setColor(Color.red); g2.fillPolygon(zPip); // Reset graphics context trans.setToIdentity(); g2.setTransform(trans); g2.setColor(origColor); g2.setPaintMode(); }
From source file:org.eurocarbdb.application.glycoworkbench.plugin.SpectraPanel.java
public void mouseReleased(MouseEvent e) { if (MouseUtils.isPopupTrigger(e)) { // clear all if (zoom_rectangle != null) { Graphics2D g2 = (Graphics2D) getGraphics(); g2.setXORMode(java.awt.Color.gray); g2.draw(zoom_rectangle);/* w w w . j a va2s . c om*/ g2.dispose(); } mouse_start_point = null; zoom_rectangle = null; // open popup current_peak = findPeakAt(e.getPoint()); enforceSelection(current_peak); createPopupMenu(current_peak != null).show(theChartPanel, e.getX(), e.getY()); } else { if (zoom_rectangle != null && mouse_start_point != null) { if (Math.abs(e.getX() - mouse_start_point.getX()) > 10) { //if( e.getX() < mouse_start_point.getX() ) { // unzoom all // onZoomNone(); //} //else { // zoom area 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 new_lower_bound = screenToDataCoordX(start_x); double new_upper_bound = screenToDataCoordX(Math.min(end_x, data_area.getMaxX())); thePlot.getDomainAxis().setRange(new Range(new_lower_bound, new_upper_bound)); } else { // clear rectangle Graphics2D g2 = (Graphics2D) getGraphics(); g2.setXORMode(java.awt.Color.gray); g2.draw(zoom_rectangle); g2.dispose(); } } // restore zooming if (!was_moving && is_moving) onActivateZooming(); zoom_rectangle = null; mouse_start_point = null; } }